blob: 352ca43a7395a15d37cc86c4fa0365ef18a00965 [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),
Ben Hutchings8127d662013-08-29 19:19:29 +01001652};
1653
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001654#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1655 (1ULL << EF10_STAT_port_tx_packets) | \
1656 (1ULL << EF10_STAT_port_tx_pause) | \
1657 (1ULL << EF10_STAT_port_tx_unicast) | \
1658 (1ULL << EF10_STAT_port_tx_multicast) | \
1659 (1ULL << EF10_STAT_port_tx_broadcast) | \
1660 (1ULL << EF10_STAT_port_rx_bytes) | \
1661 (1ULL << \
1662 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1663 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1664 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1665 (1ULL << EF10_STAT_port_rx_packets) | \
1666 (1ULL << EF10_STAT_port_rx_good) | \
1667 (1ULL << EF10_STAT_port_rx_bad) | \
1668 (1ULL << EF10_STAT_port_rx_pause) | \
1669 (1ULL << EF10_STAT_port_rx_control) | \
1670 (1ULL << EF10_STAT_port_rx_unicast) | \
1671 (1ULL << EF10_STAT_port_rx_multicast) | \
1672 (1ULL << EF10_STAT_port_rx_broadcast) | \
1673 (1ULL << EF10_STAT_port_rx_lt64) | \
1674 (1ULL << EF10_STAT_port_rx_64) | \
1675 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1676 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1677 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1678 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1679 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1680 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1681 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1682 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1683 (1ULL << EF10_STAT_port_rx_overflow) | \
1684 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001685 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1686 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001687
Edward Cree69b365c2016-08-26 15:12:41 +01001688/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1689 * For a 10G/40G switchable port we do not expose these because they might
1690 * not include all the packets they should.
1691 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001692 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001693#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1694 (1ULL << EF10_STAT_port_tx_lt64) | \
1695 (1ULL << EF10_STAT_port_tx_64) | \
1696 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1697 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1698 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1699 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1700 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1701 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001702
1703/* These statistics are only provided by the 40G MAC. For a 10G/40G
1704 * switchable port we do expose these because the errors will otherwise
1705 * be silent.
1706 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001707#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1708 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001709
Edward Cree568d7a02013-09-25 17:32:09 +01001710/* These statistics are only provided if the firmware supports the
1711 * capability PM_AND_RXDP_COUNTERS.
1712 */
1713#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001714 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1715 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1716 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1717 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1718 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1719 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1720 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1721 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1722 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1723 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1724 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1725 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001726
Edward Creef411b542017-12-21 09:00:36 +00001727/* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V2,
1728 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V2 in
1729 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1730 * These bits are in the second u64 of the raw mask.
1731 */
1732#define EF10_FEC_STAT_MASK ( \
1733 (1ULL << (EF10_STAT_fec_uncorrected_errors - 64)) | \
1734 (1ULL << (EF10_STAT_fec_corrected_errors - 64)) | \
1735 (1ULL << (EF10_STAT_fec_corrected_symbols_lane0 - 64)) | \
1736 (1ULL << (EF10_STAT_fec_corrected_symbols_lane1 - 64)) | \
1737 (1ULL << (EF10_STAT_fec_corrected_symbols_lane2 - 64)) | \
1738 (1ULL << (EF10_STAT_fec_corrected_symbols_lane3 - 64)))
1739
Edward Cree4bae9132013-09-27 18:52:49 +01001740static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001741{
Edward Cree4bae9132013-09-27 18:52:49 +01001742 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001743 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001744 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001745
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001746 if (!(efx->mcdi->fn_flags &
1747 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1748 return 0;
1749
Edward Cree69b365c2016-08-26 15:12:41 +01001750 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001751 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001752 /* 8000 series have everything even at 40G */
1753 if (nic_data->datapath_caps2 &
1754 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1755 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1756 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001757 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001758 }
Edward Cree568d7a02013-09-25 17:32:09 +01001759
1760 if (nic_data->datapath_caps &
1761 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1762 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1763
Edward Cree4bae9132013-09-27 18:52:49 +01001764 return raw_mask;
1765}
1766
1767static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1768{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001769 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001770 u64 raw_mask[2];
1771
1772 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1773
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001774 /* Only show vadaptor stats when EVB capability is present */
1775 if (nic_data->datapath_caps &
1776 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1777 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
Edward Creef411b542017-12-21 09:00:36 +00001778 raw_mask[1] = (1ULL << (EF10_STAT_V1_COUNT - 64)) - 1;
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001779 } else {
1780 raw_mask[1] = 0;
1781 }
Edward Creef411b542017-12-21 09:00:36 +00001782 /* Only show FEC stats when NIC supports MC_CMD_MAC_STATS_V2 */
1783 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V2)
1784 raw_mask[1] |= EF10_FEC_STAT_MASK;
Edward Cree4bae9132013-09-27 18:52:49 +01001785
1786#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001787 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001788 mask[0] = raw_mask[0];
1789 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001790#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001791 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001792 mask[0] = raw_mask[0] & 0xffffffff;
1793 mask[1] = raw_mask[0] >> 32;
1794 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001795#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001796}
1797
1798static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1799{
Edward Cree4bae9132013-09-27 18:52:49 +01001800 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1801
1802 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001803 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001804 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001805}
1806
Daniel Pieczkod7788192015-06-02 11:39:20 +01001807static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1808 struct rtnl_link_stats64 *core_stats)
1809{
1810 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1811 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1812 u64 *stats = nic_data->stats;
1813 size_t stats_count = 0, index;
1814
1815 efx_ef10_get_stat_mask(efx, mask);
1816
1817 if (full_stats) {
1818 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1819 if (efx_ef10_stat_desc[index].name) {
1820 *full_stats++ = stats[index];
1821 ++stats_count;
1822 }
1823 }
1824 }
1825
Bert Kenwardfbe43072015-08-26 16:39:03 +01001826 if (!core_stats)
1827 return stats_count;
1828
1829 if (nic_data->datapath_caps &
1830 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1831 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001832 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1833 stats[EF10_STAT_rx_multicast] +
1834 stats[EF10_STAT_rx_broadcast];
1835 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1836 stats[EF10_STAT_tx_multicast] +
1837 stats[EF10_STAT_tx_broadcast];
1838 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1839 stats[EF10_STAT_rx_multicast_bytes] +
1840 stats[EF10_STAT_rx_broadcast_bytes];
1841 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1842 stats[EF10_STAT_tx_multicast_bytes] +
1843 stats[EF10_STAT_tx_broadcast_bytes];
1844 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001845 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001846 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1847 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1848 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1849 core_stats->rx_errors = core_stats->rx_crc_errors;
1850 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001851 } else {
1852 /* Use port stats. */
1853 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1854 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1855 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1856 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1857 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1858 stats[GENERIC_STAT_rx_nodesc_trunc] +
1859 stats[GENERIC_STAT_rx_noskb_drops];
1860 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1861 core_stats->rx_length_errors =
1862 stats[EF10_STAT_port_rx_gtjumbo] +
1863 stats[EF10_STAT_port_rx_length_error];
1864 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1865 core_stats->rx_frame_errors =
1866 stats[EF10_STAT_port_rx_align_error];
1867 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1868 core_stats->rx_errors = (core_stats->rx_length_errors +
1869 core_stats->rx_crc_errors +
1870 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001871 }
1872
1873 return stats_count;
1874}
1875
1876static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001877{
1878 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001879 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001880 __le64 generation_start, generation_end;
1881 u64 *stats = nic_data->stats;
1882 __le64 *dma_stats;
1883
Edward Cree4bae9132013-09-27 18:52:49 +01001884 efx_ef10_get_stat_mask(efx, mask);
1885
Ben Hutchings8127d662013-08-29 19:19:29 +01001886 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001887
Edward Creec1be4822017-12-21 09:00:26 +00001888 generation_end = dma_stats[efx->num_mac_stats - 1];
Ben Hutchings8127d662013-08-29 19:19:29 +01001889 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1890 return 0;
1891 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001892 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001893 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001894 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001895 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1896 if (generation_end != generation_start)
1897 return -EAGAIN;
1898
1899 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001900 efx_nic_fix_nodesc_drop_stat(efx,
1901 &stats[EF10_STAT_port_rx_nodesc_drops]);
1902 stats[EF10_STAT_port_rx_good_bytes] =
1903 stats[EF10_STAT_port_rx_bytes] -
1904 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1905 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1906 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001907 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001908 return 0;
1909}
1910
1911
Daniel Pieczkod7788192015-06-02 11:39:20 +01001912static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1913 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001914{
Ben Hutchings8127d662013-08-29 19:19:29 +01001915 int retry;
1916
1917 /* If we're unlucky enough to read statistics during the DMA, wait
1918 * up to 10ms for it to finish (typically takes <500us)
1919 */
1920 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001921 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001922 break;
1923 udelay(100);
1924 }
1925
Daniel Pieczkod7788192015-06-02 11:39:20 +01001926 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1927}
1928
1929static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1930{
1931 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1932 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1933 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1934 __le64 generation_start, generation_end;
1935 u64 *stats = nic_data->stats;
Edward Creec1be4822017-12-21 09:00:26 +00001936 u32 dma_len = efx->num_mac_stats * sizeof(u64);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001937 struct efx_buffer stats_buf;
1938 __le64 *dma_stats;
1939 int rc;
1940
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001941 spin_unlock_bh(&efx->stats_lock);
1942
1943 if (in_interrupt()) {
1944 /* If in atomic context, cannot update stats. Just update the
1945 * software stats and return so the caller can continue.
1946 */
1947 spin_lock_bh(&efx->stats_lock);
1948 efx_update_sw_stats(efx, stats);
1949 return 0;
1950 }
1951
Daniel Pieczkod7788192015-06-02 11:39:20 +01001952 efx_ef10_get_stat_mask(efx, mask);
1953
1954 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001955 if (rc) {
1956 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001957 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001958 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001959
1960 dma_stats = stats_buf.addr;
Edward Creec1be4822017-12-21 09:00:26 +00001961 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
Daniel Pieczkod7788192015-06-02 11:39:20 +01001962
1963 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1964 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001965 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001966 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1967 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1968
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001969 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1970 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001971 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001972 if (rc) {
1973 /* Expect ENOENT if DMA queues have not been set up */
1974 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1975 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1976 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001977 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001978 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001979
Edward Creec1be4822017-12-21 09:00:26 +00001980 generation_end = dma_stats[efx->num_mac_stats - 1];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001981 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1982 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001983 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001984 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001985 rmb();
1986 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1987 stats, stats_buf.addr, false);
1988 rmb();
1989 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1990 if (generation_end != generation_start) {
1991 rc = -EAGAIN;
1992 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001993 }
1994
Daniel Pieczkod7788192015-06-02 11:39:20 +01001995 efx_update_sw_stats(efx, stats);
1996out:
1997 efx_nic_free_buffer(efx, &stats_buf);
1998 return rc;
1999}
Ben Hutchings8127d662013-08-29 19:19:29 +01002000
Daniel Pieczkod7788192015-06-02 11:39:20 +01002001static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
2002 struct rtnl_link_stats64 *core_stats)
2003{
2004 if (efx_ef10_try_update_nic_stats_vf(efx))
2005 return 0;
2006
2007 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01002008}
2009
2010static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
2011{
2012 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01002013 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01002014 efx_dword_t timer_cmd;
2015
Bert Kenward539de7c2016-08-11 13:02:09 +01002016 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002017 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01002018 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01002019 } else {
2020 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01002021 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002022 }
2023
Bert Kenward539de7c2016-08-11 13:02:09 +01002024 if (EFX_EF10_WORKAROUND_61265(efx)) {
2025 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
2026 unsigned int ns = usecs * 1000;
2027
2028 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
2029 channel->channel);
2030 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
2031 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
2032 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
2033
2034 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
2035 inbuf, sizeof(inbuf), 0, NULL, 0);
2036 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
2037 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2038
Ben Hutchings8127d662013-08-29 19:19:29 +01002039 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
2040 EFE_DD_EVQ_IND_TIMER_FLAGS,
2041 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01002042 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002043 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
2044 channel->channel);
2045 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01002046 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2047
Bert Kenward0bc959a2017-12-18 16:57:41 +00002048 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
2049 ERF_DZ_TC_TIMER_VAL, ticks,
2050 ERF_FZ_TC_TMR_REL_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002051 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
2052 channel->channel);
2053 }
2054}
2055
Shradha Shah02246a72015-05-06 00:58:14 +01002056static void efx_ef10_get_wol_vf(struct efx_nic *efx,
2057 struct ethtool_wolinfo *wol) {}
2058
2059static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
2060{
2061 return -EOPNOTSUPP;
2062}
2063
Ben Hutchings8127d662013-08-29 19:19:29 +01002064static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
2065{
2066 wol->supported = 0;
2067 wol->wolopts = 0;
2068 memset(&wol->sopass, 0, sizeof(wol->sopass));
2069}
2070
2071static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
2072{
2073 if (type != 0)
2074 return -EINVAL;
2075 return 0;
2076}
2077
2078static void efx_ef10_mcdi_request(struct efx_nic *efx,
2079 const efx_dword_t *hdr, size_t hdr_len,
2080 const efx_dword_t *sdu, size_t sdu_len)
2081{
2082 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2083 u8 *pdu = nic_data->mcdi_buf.addr;
2084
2085 memcpy(pdu, hdr, hdr_len);
2086 memcpy(pdu + hdr_len, sdu, sdu_len);
2087 wmb();
2088
2089 /* The hardware provides 'low' and 'high' (doorbell) registers
2090 * for passing the 64-bit address of an MCDI request to
2091 * firmware. However the dwords are swapped by firmware. The
2092 * least significant bits of the doorbell are then 0 for all
2093 * MCDI requests due to alignment.
2094 */
2095 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
2096 ER_DZ_MC_DB_LWRD);
2097 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
2098 ER_DZ_MC_DB_HWRD);
2099}
2100
2101static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
2102{
2103 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2104 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
2105
2106 rmb();
2107 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
2108}
2109
2110static void
2111efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
2112 size_t offset, size_t outlen)
2113{
2114 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2115 const u8 *pdu = nic_data->mcdi_buf.addr;
2116
2117 memcpy(outbuf, pdu + offset, outlen);
2118}
2119
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002120static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
2121{
2122 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2123
2124 /* All our allocations have been reset */
2125 efx_ef10_reset_mc_allocations(efx);
2126
2127 /* The datapath firmware might have been changed */
2128 nic_data->must_check_datapath_caps = true;
2129
2130 /* MAC statistics have been cleared on the NIC; clear the local
2131 * statistic that we update with efx_update_diff_stat().
2132 */
2133 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
2134}
2135
Ben Hutchings8127d662013-08-29 19:19:29 +01002136static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2137{
2138 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2139 int rc;
2140
2141 rc = efx_ef10_get_warm_boot_count(efx);
2142 if (rc < 0) {
2143 /* The firmware is presumably in the process of
2144 * rebooting. However, we are supposed to report each
2145 * reboot just once, so we must only do that once we
2146 * can read and store the updated warm boot count.
2147 */
2148 return 0;
2149 }
2150
2151 if (rc == nic_data->warm_boot_count)
2152 return 0;
2153
2154 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002155 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01002156
Ben Hutchings8127d662013-08-29 19:19:29 +01002157 return -EIO;
2158}
2159
2160/* Handle an MSI interrupt
2161 *
2162 * Handle an MSI hardware interrupt. This routine schedules event
2163 * queue processing. No interrupt acknowledgement cycle is necessary.
2164 * Also, we never need to check that the interrupt is for us, since
2165 * MSI interrupts cannot be shared.
2166 */
2167static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2168{
2169 struct efx_msi_context *context = dev_id;
2170 struct efx_nic *efx = context->efx;
2171
2172 netif_vdbg(efx, intr, efx->net_dev,
2173 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2174
Mark Rutland6aa7de02017-10-23 14:07:29 -07002175 if (likely(READ_ONCE(efx->irq_soft_enabled))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002176 /* Note test interrupts */
2177 if (context->index == efx->irq_level)
2178 efx->last_irq_cpu = raw_smp_processor_id();
2179
2180 /* Schedule processing of the channel */
2181 efx_schedule_channel_irq(efx->channel[context->index]);
2182 }
2183
2184 return IRQ_HANDLED;
2185}
2186
2187static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2188{
2189 struct efx_nic *efx = dev_id;
Mark Rutland6aa7de02017-10-23 14:07:29 -07002190 bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
Ben Hutchings8127d662013-08-29 19:19:29 +01002191 struct efx_channel *channel;
2192 efx_dword_t reg;
2193 u32 queues;
2194
2195 /* Read the ISR which also ACKs the interrupts */
2196 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2197 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2198
2199 if (queues == 0)
2200 return IRQ_NONE;
2201
2202 if (likely(soft_enabled)) {
2203 /* Note test interrupts */
2204 if (queues & (1U << efx->irq_level))
2205 efx->last_irq_cpu = raw_smp_processor_id();
2206
2207 efx_for_each_channel(channel, efx) {
2208 if (queues & 1)
2209 efx_schedule_channel_irq(channel);
2210 queues >>= 1;
2211 }
2212 }
2213
2214 netif_vdbg(efx, intr, efx->net_dev,
2215 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2216 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2217
2218 return IRQ_HANDLED;
2219}
2220
Jon Cooper942e2982016-08-26 15:13:30 +01002221static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002222{
2223 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2224
Jon Cooper942e2982016-08-26 15:13:30 +01002225 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2226 NULL) == 0)
2227 return -ENOTSUPP;
2228
Ben Hutchings8127d662013-08-29 19:19:29 +01002229 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2230
2231 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002232 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002233 inbuf, sizeof(inbuf), NULL, 0, NULL);
2234}
2235
2236static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2237{
2238 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2239 (tx_queue->ptr_mask + 1) *
2240 sizeof(efx_qword_t),
2241 GFP_KERNEL);
2242}
2243
2244/* This writes to the TX_DESC_WPTR and also pushes data */
2245static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2246 const efx_qword_t *txd)
2247{
2248 unsigned int write_ptr;
2249 efx_oword_t reg;
2250
2251 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2252 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2253 reg.qword[0] = *txd;
2254 efx_writeo_page(tx_queue->efx, &reg,
2255 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2256}
2257
Bert Kenwarde9117e52016-11-17 10:51:54 +00002258/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2259 */
2260static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2261 struct sk_buff *skb,
2262 bool *data_mapped)
2263{
2264 struct efx_tx_buffer *buffer;
2265 struct tcphdr *tcp;
2266 struct iphdr *ip;
2267
2268 u16 ipv4_id;
2269 u32 seqnum;
2270 u32 mss;
2271
Edward Creee01b16a2016-12-02 15:51:33 +00002272 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002273
2274 mss = skb_shinfo(skb)->gso_size;
2275
2276 if (unlikely(mss < 4)) {
2277 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2278 return -EINVAL;
2279 }
2280
2281 ip = ip_hdr(skb);
2282 if (ip->version == 4) {
2283 /* Modify IPv4 header if needed. */
2284 ip->tot_len = 0;
2285 ip->check = 0;
Edward Cree6d431312017-03-03 15:22:27 +00002286 ipv4_id = ntohs(ip->id);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002287 } else {
2288 /* Modify IPv6 header if needed. */
2289 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2290
2291 ipv6->payload_len = 0;
2292 ipv4_id = 0;
2293 }
2294
2295 tcp = tcp_hdr(skb);
2296 seqnum = ntohl(tcp->seq);
2297
2298 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2299
2300 buffer->flags = EFX_TX_BUF_OPTION;
2301 buffer->len = 0;
2302 buffer->unmap_len = 0;
2303 EFX_POPULATE_QWORD_5(buffer->option,
2304 ESF_DZ_TX_DESC_IS_OPT, 1,
2305 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2306 ESF_DZ_TX_TSO_OPTION_TYPE,
2307 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2308 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2309 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2310 );
2311 ++tx_queue->insert_count;
2312
2313 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2314
2315 buffer->flags = EFX_TX_BUF_OPTION;
2316 buffer->len = 0;
2317 buffer->unmap_len = 0;
2318 EFX_POPULATE_QWORD_4(buffer->option,
2319 ESF_DZ_TX_DESC_IS_OPT, 1,
2320 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2321 ESF_DZ_TX_TSO_OPTION_TYPE,
2322 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2323 ESF_DZ_TX_TSO_TCP_MSS, mss
2324 );
2325 ++tx_queue->insert_count;
2326
2327 return 0;
2328}
2329
Edward Cree46d1efd2016-11-17 10:52:36 +00002330static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2331{
2332 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2333 u32 tso_versions = 0;
2334
2335 if (nic_data->datapath_caps &
2336 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2337 tso_versions |= BIT(1);
2338 if (nic_data->datapath_caps2 &
2339 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2340 tso_versions |= BIT(2);
2341 return tso_versions;
2342}
2343
Ben Hutchings8127d662013-08-29 19:19:29 +01002344static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2345{
2346 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2347 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002348 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2349 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2350 struct efx_channel *channel = tx_queue->channel;
2351 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002352 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002353 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002354 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002355 dma_addr_t dma_addr;
2356 efx_qword_t *txd;
2357 int rc;
2358 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002359 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002360
Bert Kenwarde9117e52016-11-17 10:51:54 +00002361 /* TSOv2 is a limited resource that can only be configured on a limited
2362 * number of queues. TSO without checksum offload is not really a thing,
2363 * so we only enable it for those queues.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002364 */
2365 if (csum_offload && (nic_data->datapath_caps2 &
2366 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2367 tso_v2 = true;
2368 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2369 channel->channel);
2370 }
2371
Ben Hutchings8127d662013-08-29 19:19:29 +01002372 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2373 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2374 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2375 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002376 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002377 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002378
2379 dma_addr = tx_queue->txd.buf.dma_addr;
2380
2381 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2382 tx_queue->queue, entries, (u64)dma_addr);
2383
2384 for (i = 0; i < entries; ++i) {
2385 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2386 dma_addr += EFX_BUF_SIZE;
2387 }
2388
2389 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2390
Edward Creee638ee12016-11-17 10:52:07 +00002391 do {
2392 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2393 /* This flag was removed from mcdi_pcol.h for
2394 * the non-_EXT version of INIT_TXQ. However,
2395 * firmware still honours it.
2396 */
2397 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2398 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2399 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2400
2401 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2402 NULL, 0, NULL);
2403 if (rc == -ENOSPC && tso_v2) {
2404 /* Retry without TSOv2 if we're short on contexts. */
2405 tso_v2 = false;
2406 netif_warn(efx, probe, efx->net_dev,
2407 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2408 } else if (rc) {
2409 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2410 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2411 NULL, 0, rc);
2412 goto fail;
2413 }
2414 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002415
2416 /* A previous user of this TX queue might have set us up the
2417 * bomb by writing a descriptor to the TX push collector but
2418 * not the doorbell. (Each collector belongs to a port, not a
2419 * queue or function, so cannot easily be reset.) We must
2420 * attempt to push a no-op descriptor in its place.
2421 */
2422 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2423 tx_queue->insert_count = 1;
2424 txd = efx_tx_desc(tx_queue, 0);
2425 EFX_POPULATE_QWORD_4(*txd,
2426 ESF_DZ_TX_DESC_IS_OPT, true,
2427 ESF_DZ_TX_OPTION_TYPE,
2428 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2429 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2430 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2431 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002432
Bert Kenwarde9117e52016-11-17 10:51:54 +00002433 if (tso_v2) {
2434 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2435 tx_queue->tso_version = 2;
2436 } else if (nic_data->datapath_caps &
2437 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002438 tx_queue->tso_version = 1;
2439 }
2440
Ben Hutchings8127d662013-08-29 19:19:29 +01002441 wmb();
2442 efx_ef10_push_tx_desc(tx_queue, txd);
2443
2444 return;
2445
2446fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002447 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2448 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002449}
2450
2451static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2452{
2453 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002454 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002455 struct efx_nic *efx = tx_queue->efx;
2456 size_t outlen;
2457 int rc;
2458
2459 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2460 tx_queue->queue);
2461
Edward Cree1e0b8122013-05-31 18:36:12 +01002462 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002463 outbuf, sizeof(outbuf), &outlen);
2464
2465 if (rc && rc != -EALREADY)
2466 goto fail;
2467
2468 return;
2469
2470fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002471 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2472 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002473}
2474
2475static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2476{
2477 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2478}
2479
2480/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2481static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2482{
2483 unsigned int write_ptr;
2484 efx_dword_t reg;
2485
2486 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2487 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2488 efx_writed_page(tx_queue->efx, &reg,
2489 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2490}
2491
Bert Kenwarde9117e52016-11-17 10:51:54 +00002492#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2493
2494static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2495 dma_addr_t dma_addr, unsigned int len)
2496{
2497 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2498 /* If we need to break across multiple descriptors we should
2499 * stop at a page boundary. This assumes the length limit is
2500 * greater than the page size.
2501 */
2502 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2503
2504 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2505 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2506 }
2507
2508 return len;
2509}
2510
Ben Hutchings8127d662013-08-29 19:19:29 +01002511static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2512{
2513 unsigned int old_write_count = tx_queue->write_count;
2514 struct efx_tx_buffer *buffer;
2515 unsigned int write_ptr;
2516 efx_qword_t *txd;
2517
Martin Habetsb2663a42015-11-02 12:51:31 +00002518 tx_queue->xmit_more_available = false;
2519 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2520 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002521
2522 do {
2523 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2524 buffer = &tx_queue->buffer[write_ptr];
2525 txd = efx_tx_desc(tx_queue, write_ptr);
2526 ++tx_queue->write_count;
2527
2528 /* Create TX descriptor ring entry */
2529 if (buffer->flags & EFX_TX_BUF_OPTION) {
2530 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002531 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2532 /* PIO descriptor */
2533 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002534 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002535 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002536 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2537 EFX_POPULATE_QWORD_3(
2538 *txd,
2539 ESF_DZ_TX_KER_CONT,
2540 buffer->flags & EFX_TX_BUF_CONT,
2541 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2542 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2543 }
2544 } while (tx_queue->write_count != tx_queue->insert_count);
2545
2546 wmb(); /* Ensure descriptors are written before they are fetched */
2547
2548 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2549 txd = efx_tx_desc(tx_queue,
2550 old_write_count & tx_queue->ptr_mask);
2551 efx_ef10_push_tx_desc(tx_queue, txd);
2552 ++tx_queue->pushes;
2553 } else {
2554 efx_ef10_notify_tx_desc(tx_queue);
2555 }
2556}
2557
Edward Creea33a4c72016-11-03 22:12:27 +00002558#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2559 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2560#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2561 1 << RSS_MODE_HASH_DST_PORT_LBN)
2562#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2563 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2564 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2565 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2566 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2567 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2568 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2569 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2570 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2571 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2572
2573static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2574{
2575 /* Firmware had a bug (sfc bug 61952) where it would not actually
2576 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2577 * This meant that it would always contain whatever was previously
2578 * in the MCDI buffer. Fortunately, all firmware versions with
2579 * this bug have the same default flags value for a newly-allocated
2580 * RSS context, and the only time we want to get the flags is just
2581 * after allocating. Moreover, the response has a 32-bit hole
2582 * where the context ID would be in the request, so we can use an
2583 * overlength buffer in the request and pre-fill the flags field
2584 * with what we believe the default to be. Thus if the firmware
2585 * has the bug, it will leave our pre-filled value in the flags
2586 * field of the response, and we will get the right answer.
2587 *
2588 * However, this does mean that this function should NOT be used if
2589 * the RSS context flags might not be their defaults - it is ONLY
2590 * reliably correct for a newly-allocated RSS context.
2591 */
2592 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2593 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2594 size_t outlen;
2595 int rc;
2596
2597 /* Check we have a hole for the context ID */
2598 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2599 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2600 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2601 RSS_CONTEXT_FLAGS_DEFAULT);
2602 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2603 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2604 if (rc == 0) {
2605 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2606 rc = -EIO;
2607 else
2608 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2609 }
2610 return rc;
2611}
2612
2613/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2614 * If we fail, we just leave the RSS context at its default hash settings,
2615 * which is safe but may slightly reduce performance.
2616 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2617 * just need to set the UDP ports flags (for both IP versions).
2618 */
2619static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2620{
2621 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2622 u32 flags;
2623
2624 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2625
2626 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2627 return;
2628 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2629 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2630 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2631 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002632 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2633 NULL, 0, NULL))
2634 /* Succeeded, so UDP 4-tuple is now enabled */
2635 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002636}
2637
Jon Cooper267c0152015-05-06 00:59:38 +01002638static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2639 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002640{
2641 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2642 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002643 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002644 size_t outlen;
2645 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002646 u32 alloc_type = exclusive ?
2647 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2648 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2649 unsigned rss_spread = exclusive ?
2650 efx->rss_spread :
2651 min(rounddown_pow_of_two(efx->rss_spread),
2652 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2653
2654 if (!exclusive && rss_spread == 1) {
2655 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2656 if (context_size)
2657 *context_size = 1;
2658 return 0;
2659 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002660
Jon Cooperdcb41232016-04-25 16:51:00 +01002661 if (nic_data->datapath_caps &
2662 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2663 return -EOPNOTSUPP;
2664
Ben Hutchings8127d662013-08-29 19:19:29 +01002665 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002666 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002667 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2668 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002669
2670 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2671 outbuf, sizeof(outbuf), &outlen);
2672 if (rc != 0)
2673 return rc;
2674
2675 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2676 return -EIO;
2677
2678 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2679
Jon Cooper267c0152015-05-06 00:59:38 +01002680 if (context_size)
2681 *context_size = rss_spread;
2682
Edward Creea33a4c72016-11-03 22:12:27 +00002683 if (nic_data->datapath_caps &
2684 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2685 efx_ef10_set_rss_flags(efx, *context);
2686
Ben Hutchings8127d662013-08-29 19:19:29 +01002687 return 0;
2688}
2689
2690static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2691{
2692 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2693 int rc;
2694
2695 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2696 context);
2697
2698 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2699 NULL, 0, NULL);
2700 WARN_ON(rc != 0);
2701}
2702
Jon Cooper267c0152015-05-06 00:59:38 +01002703static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
Edward Creef74d1992017-01-17 12:01:53 +00002704 const u32 *rx_indir_table, const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002705{
2706 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2707 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2708 int i, rc;
2709
2710 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2711 context);
2712 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2713 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2714
Edward Creef74d1992017-01-17 12:01:53 +00002715 /* This iterates over the length of efx->rx_indir_table, but copies
2716 * bytes from rx_indir_table. That's because the latter is a pointer
2717 * rather than an array, but should have the same length.
2718 * The efx->rx_hash_key loop below is similar.
2719 */
Ben Hutchings8127d662013-08-29 19:19:29 +01002720 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2721 MCDI_PTR(tablebuf,
2722 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002723 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002724
2725 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2726 sizeof(tablebuf), NULL, 0, NULL);
2727 if (rc != 0)
2728 return rc;
2729
2730 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2731 context);
2732 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2733 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2734 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
Edward Creef74d1992017-01-17 12:01:53 +00002735 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002736
2737 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2738 sizeof(keybuf), NULL, 0, NULL);
2739}
2740
2741static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2742{
2743 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2744
2745 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2746 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2747 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2748}
2749
Jon Cooper267c0152015-05-06 00:59:38 +01002750static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2751 unsigned *context_size)
2752{
2753 u32 new_rx_rss_context;
2754 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2755 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2756 false, context_size);
2757
2758 if (rc != 0)
2759 return rc;
2760
2761 nic_data->rx_rss_context = new_rx_rss_context;
2762 nic_data->rx_rss_context_exclusive = false;
2763 efx_set_default_rx_indir_table(efx);
2764 return 0;
2765}
2766
2767static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
Edward Creef74d1992017-01-17 12:01:53 +00002768 const u32 *rx_indir_table,
2769 const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002770{
2771 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2772 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002773 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002774
Jon Cooper267c0152015-05-06 00:59:38 +01002775 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2776 !nic_data->rx_rss_context_exclusive) {
2777 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2778 true, NULL);
2779 if (rc == -EOPNOTSUPP)
2780 return rc;
2781 else if (rc != 0)
2782 goto fail1;
2783 } else {
2784 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002785 }
2786
Jon Cooper267c0152015-05-06 00:59:38 +01002787 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
Edward Creef74d1992017-01-17 12:01:53 +00002788 rx_indir_table, key);
Ben Hutchings8127d662013-08-29 19:19:29 +01002789 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002790 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002791
Jon Cooper267c0152015-05-06 00:59:38 +01002792 if (nic_data->rx_rss_context != new_rx_rss_context)
2793 efx_ef10_rx_free_indir_table(efx);
2794 nic_data->rx_rss_context = new_rx_rss_context;
2795 nic_data->rx_rss_context_exclusive = true;
2796 if (rx_indir_table != efx->rx_indir_table)
2797 memcpy(efx->rx_indir_table, rx_indir_table,
2798 sizeof(efx->rx_indir_table));
Edward Creef74d1992017-01-17 12:01:53 +00002799 if (key != efx->rx_hash_key)
2800 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2801
Jon Cooper267c0152015-05-06 00:59:38 +01002802 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002803
Jon Cooper267c0152015-05-06 00:59:38 +01002804fail2:
2805 if (new_rx_rss_context != nic_data->rx_rss_context)
2806 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2807fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002808 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002809 return rc;
2810}
2811
Edward Creea707d182017-01-17 12:02:12 +00002812static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2813{
2814 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2815 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2816 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2817 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2818 size_t outlen;
2819 int rc, i;
2820
2821 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2822 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2823
2824 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2825 return -ENOENT;
2826
2827 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2828 nic_data->rx_rss_context);
2829 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2830 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2831 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2832 tablebuf, sizeof(tablebuf), &outlen);
2833 if (rc != 0)
2834 return rc;
2835
2836 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2837 return -EIO;
2838
2839 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2840 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2841 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2842
2843 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2844 nic_data->rx_rss_context);
2845 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2846 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2847 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2848 keybuf, sizeof(keybuf), &outlen);
2849 if (rc != 0)
2850 return rc;
2851
2852 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2853 return -EIO;
2854
2855 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2856 efx->rx_hash_key[i] = MCDI_PTR(
2857 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2858
2859 return 0;
2860}
2861
Jon Cooper267c0152015-05-06 00:59:38 +01002862static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
Edward Creef74d1992017-01-17 12:01:53 +00002863 const u32 *rx_indir_table,
2864 const u8 *key)
Jon Cooper267c0152015-05-06 00:59:38 +01002865{
2866 int rc;
2867
2868 if (efx->rss_spread == 1)
2869 return 0;
2870
Edward Creef74d1992017-01-17 12:01:53 +00002871 if (!key)
2872 key = efx->rx_hash_key;
2873
2874 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
Jon Cooper267c0152015-05-06 00:59:38 +01002875
2876 if (rc == -ENOBUFS && !user) {
2877 unsigned context_size;
2878 bool mismatch = false;
2879 size_t i;
2880
2881 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2882 i++)
2883 mismatch = rx_indir_table[i] !=
2884 ethtool_rxfh_indir_default(i, efx->rss_spread);
2885
2886 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2887 if (rc == 0) {
2888 if (context_size != efx->rss_spread)
2889 netif_warn(efx, probe, efx->net_dev,
2890 "Could not allocate an exclusive RSS"
2891 " context; allocated a shared one of"
2892 " different size."
2893 " Wanted %u, got %u.\n",
2894 efx->rss_spread, context_size);
2895 else if (mismatch)
2896 netif_warn(efx, probe, efx->net_dev,
2897 "Could not allocate an exclusive RSS"
2898 " context; allocated a shared one but"
2899 " could not apply custom"
2900 " indirection.\n");
2901 else
2902 netif_info(efx, probe, efx->net_dev,
2903 "Could not allocate an exclusive RSS"
2904 " context; allocated a shared one.\n");
2905 }
2906 }
2907 return rc;
2908}
2909
2910static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2911 const u32 *rx_indir_table
Edward Creef74d1992017-01-17 12:01:53 +00002912 __attribute__ ((unused)),
2913 const u8 *key
Jon Cooper267c0152015-05-06 00:59:38 +01002914 __attribute__ ((unused)))
2915{
2916 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2917
2918 if (user)
2919 return -EOPNOTSUPP;
2920 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2921 return 0;
2922 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002923}
2924
2925static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2926{
2927 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2928 (rx_queue->ptr_mask + 1) *
2929 sizeof(efx_qword_t),
2930 GFP_KERNEL);
2931}
2932
2933static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2934{
2935 MCDI_DECLARE_BUF(inbuf,
2936 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2937 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002938 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2939 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2940 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002941 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002942 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002943 dma_addr_t dma_addr;
2944 int rc;
2945 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002946 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002947
2948 rx_queue->scatter_n = 0;
2949 rx_queue->scatter_len = 0;
2950
2951 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2952 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2953 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2954 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2955 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002956 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2957 INIT_RXQ_IN_FLAG_PREFIX, 1,
2958 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002959 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002960 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002961
2962 dma_addr = rx_queue->rxd.buf.dma_addr;
2963
2964 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2965 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2966
2967 for (i = 0; i < entries; ++i) {
2968 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2969 dma_addr += EFX_BUF_SIZE;
2970 }
2971
2972 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2973
2974 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002975 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002976 if (rc)
2977 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2978 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002979}
2980
2981static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2982{
2983 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002984 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002985 struct efx_nic *efx = rx_queue->efx;
2986 size_t outlen;
2987 int rc;
2988
2989 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2990 efx_rx_queue_index(rx_queue));
2991
Edward Cree1e0b8122013-05-31 18:36:12 +01002992 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002993 outbuf, sizeof(outbuf), &outlen);
2994
2995 if (rc && rc != -EALREADY)
2996 goto fail;
2997
2998 return;
2999
3000fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01003001 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
3002 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01003003}
3004
3005static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
3006{
3007 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
3008}
3009
3010/* This creates an entry in the RX descriptor queue */
3011static inline void
3012efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
3013{
3014 struct efx_rx_buffer *rx_buf;
3015 efx_qword_t *rxd;
3016
3017 rxd = efx_rx_desc(rx_queue, index);
3018 rx_buf = efx_rx_buffer(rx_queue, index);
3019 EFX_POPULATE_QWORD_2(*rxd,
3020 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
3021 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
3022}
3023
3024static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
3025{
3026 struct efx_nic *efx = rx_queue->efx;
3027 unsigned int write_count;
3028 efx_dword_t reg;
3029
3030 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
3031 write_count = rx_queue->added_count & ~7;
3032 if (rx_queue->notified_count == write_count)
3033 return;
3034
3035 do
3036 efx_ef10_build_rx_desc(
3037 rx_queue,
3038 rx_queue->notified_count & rx_queue->ptr_mask);
3039 while (++rx_queue->notified_count != write_count);
3040
3041 wmb();
3042 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
3043 write_count & rx_queue->ptr_mask);
3044 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
3045 efx_rx_queue_index(rx_queue));
3046}
3047
3048static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
3049
3050static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
3051{
3052 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3053 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3054 efx_qword_t event;
3055
3056 EFX_POPULATE_QWORD_2(event,
3057 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3058 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
3059
3060 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3061
3062 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3063 * already swapped the data to little-endian order.
3064 */
3065 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3066 sizeof(efx_qword_t));
3067
3068 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
3069 inbuf, sizeof(inbuf), 0,
3070 efx_ef10_rx_defer_refill_complete, 0);
3071}
3072
3073static void
3074efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
3075 int rc, efx_dword_t *outbuf,
3076 size_t outlen_actual)
3077{
3078 /* nothing to do */
3079}
3080
3081static int efx_ef10_ev_probe(struct efx_channel *channel)
3082{
3083 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
3084 (channel->eventq_mask + 1) *
3085 sizeof(efx_qword_t),
3086 GFP_KERNEL);
3087}
3088
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003089static void efx_ef10_ev_fini(struct efx_channel *channel)
3090{
3091 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
3092 MCDI_DECLARE_BUF_ERR(outbuf);
3093 struct efx_nic *efx = channel->efx;
3094 size_t outlen;
3095 int rc;
3096
3097 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
3098
3099 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
3100 outbuf, sizeof(outbuf), &outlen);
3101
3102 if (rc && rc != -EALREADY)
3103 goto fail;
3104
3105 return;
3106
3107fail:
3108 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
3109 outbuf, outlen, rc);
3110}
3111
Ben Hutchings8127d662013-08-29 19:19:29 +01003112static int efx_ef10_ev_init(struct efx_channel *channel)
3113{
3114 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01003115 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
3116 EFX_BUF_SIZE));
3117 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003118 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
3119 struct efx_nic *efx = channel->efx;
3120 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003121 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003122 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01003123 dma_addr_t dma_addr;
3124 int rc;
3125 int i;
3126
3127 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003128
3129 /* Fill event queue with all ones (i.e. empty events) */
3130 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
3131
3132 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
3133 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
3134 /* INIT_EVQ expects index in vector table, not absolute */
3135 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01003136 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3137 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3138 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3139 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3140 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3141 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3142 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3143
Bert Kenwarda9955602016-08-11 13:01:54 +01003144 if (nic_data->datapath_caps2 &
3145 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3146 /* Use the new generic approach to specifying event queue
3147 * configuration, requesting lower latency or higher throughput.
3148 * The options that actually get used appear in the output.
3149 */
3150 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3151 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3152 INIT_EVQ_V2_IN_FLAG_TYPE,
3153 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3154 } else {
3155 bool cut_thru = !(nic_data->datapath_caps &
3156 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3157
3158 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3159 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3160 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3161 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3162 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3163 }
3164
Ben Hutchings8127d662013-08-29 19:19:29 +01003165 dma_addr = channel->eventq.buf.dma_addr;
3166 for (i = 0; i < entries; ++i) {
3167 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3168 dma_addr += EFX_BUF_SIZE;
3169 }
3170
3171 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3172
3173 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3174 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01003175
3176 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3177 netif_dbg(efx, drv, efx->net_dev,
3178 "Channel %d using event queue flags %08x\n",
3179 channel->channel,
3180 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3181
Ben Hutchings8127d662013-08-29 19:19:29 +01003182 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003183 if (channel->channel || rc)
3184 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003185
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003186 /* Successfully created event queue on channel 0 */
3187 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01003188 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01003189 /* GET_WORKAROUNDS was implemented before this workaround,
3190 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01003191 */
3192 nic_data->workaround_26807 = false;
3193 rc = 0;
3194 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003195 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01003196 } else {
3197 nic_data->workaround_26807 =
3198 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01003199
Edward Cree832dc9e2015-07-21 15:09:31 +01003200 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3201 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003202 unsigned int flags;
3203
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01003204 rc = efx_mcdi_set_workaround(efx,
3205 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003206 true, &flags);
3207
3208 if (!rc) {
3209 if (flags &
3210 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3211 netif_info(efx, drv, efx->net_dev,
3212 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00003213
3214 /* With MCFW v4.6.x and earlier, the
3215 * boot count will have incremented,
3216 * so re-read the warm_boot_count
3217 * value now to ensure this function
3218 * doesn't think it has changed next
3219 * time it checks.
3220 */
3221 rc = efx_ef10_get_warm_boot_count(efx);
3222 if (rc >= 0) {
3223 nic_data->warm_boot_count = rc;
3224 rc = 0;
3225 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003226 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003227 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003228 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01003229 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003230 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003231 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003232 }
3233
3234 if (!rc)
3235 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003236
3237fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003238 efx_ef10_ev_fini(channel);
3239 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003240}
3241
3242static void efx_ef10_ev_remove(struct efx_channel *channel)
3243{
3244 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3245}
3246
3247static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3248 unsigned int rx_queue_label)
3249{
3250 struct efx_nic *efx = rx_queue->efx;
3251
3252 netif_info(efx, hw, efx->net_dev,
3253 "rx event arrived on queue %d labeled as queue %u\n",
3254 efx_rx_queue_index(rx_queue), rx_queue_label);
3255
3256 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3257}
3258
3259static void
3260efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3261 unsigned int actual, unsigned int expected)
3262{
3263 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3264 struct efx_nic *efx = rx_queue->efx;
3265
3266 netif_info(efx, hw, efx->net_dev,
3267 "dropped %d events (index=%d expected=%d)\n",
3268 dropped, actual, expected);
3269
3270 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3271}
3272
3273/* partially received RX was aborted. clean up. */
3274static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3275{
3276 unsigned int rx_desc_ptr;
3277
Ben Hutchings8127d662013-08-29 19:19:29 +01003278 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3279 "scattered RX aborted (dropping %u buffers)\n",
3280 rx_queue->scatter_n);
3281
3282 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3283
3284 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3285 0, EFX_RX_PKT_DISCARD);
3286
3287 rx_queue->removed_count += rx_queue->scatter_n;
3288 rx_queue->scatter_n = 0;
3289 rx_queue->scatter_len = 0;
3290 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3291}
3292
Jon Coopera0ee3542017-02-08 16:50:40 +00003293static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3294 unsigned int n_packets,
3295 unsigned int rx_encap_hdr,
3296 unsigned int rx_l3_class,
3297 unsigned int rx_l4_class,
3298 const efx_qword_t *event)
3299{
3300 struct efx_nic *efx = channel->efx;
Edward Cree69787292017-10-31 14:29:47 +00003301 bool handled = false;
Jon Coopera0ee3542017-02-08 16:50:40 +00003302
3303 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
Edward Cree69787292017-10-31 14:29:47 +00003304 if (!(efx->net_dev->features & NETIF_F_RXALL)) {
3305 if (!efx->loopback_selftest)
3306 channel->n_rx_eth_crc_err += n_packets;
3307 return EFX_RX_PKT_DISCARD;
3308 }
3309 handled = true;
Jon Coopera0ee3542017-02-08 16:50:40 +00003310 }
3311 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3312 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3313 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3314 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3315 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3316 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3317 netdev_WARN(efx->net_dev,
3318 "invalid class for RX_IPCKSUM_ERR: event="
3319 EFX_QWORD_FMT "\n",
3320 EFX_QWORD_VAL(*event));
3321 if (!efx->loopback_selftest)
3322 *(rx_encap_hdr ?
3323 &channel->n_rx_outer_ip_hdr_chksum_err :
3324 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3325 return 0;
3326 }
3327 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3328 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3329 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3330 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003331 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3332 rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
Jon Coopera0ee3542017-02-08 16:50:40 +00003333 netdev_WARN(efx->net_dev,
3334 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3335 EFX_QWORD_FMT "\n",
3336 EFX_QWORD_VAL(*event));
3337 if (!efx->loopback_selftest)
3338 *(rx_encap_hdr ?
3339 &channel->n_rx_outer_tcp_udp_chksum_err :
3340 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3341 return 0;
3342 }
3343 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3344 if (unlikely(!rx_encap_hdr))
3345 netdev_WARN(efx->net_dev,
3346 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3347 EFX_QWORD_FMT "\n",
3348 EFX_QWORD_VAL(*event));
3349 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3350 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3351 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3352 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3353 netdev_WARN(efx->net_dev,
3354 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3355 EFX_QWORD_FMT "\n",
3356 EFX_QWORD_VAL(*event));
3357 if (!efx->loopback_selftest)
3358 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3359 return 0;
3360 }
3361 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3362 if (unlikely(!rx_encap_hdr))
3363 netdev_WARN(efx->net_dev,
3364 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3365 EFX_QWORD_FMT "\n",
3366 EFX_QWORD_VAL(*event));
3367 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3368 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003369 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3370 rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
Jon Coopera0ee3542017-02-08 16:50:40 +00003371 netdev_WARN(efx->net_dev,
3372 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3373 EFX_QWORD_FMT "\n",
3374 EFX_QWORD_VAL(*event));
3375 if (!efx->loopback_selftest)
3376 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3377 return 0;
3378 }
3379
Edward Cree69787292017-10-31 14:29:47 +00003380 WARN_ON(!handled); /* No error bits were recognised */
Jon Coopera0ee3542017-02-08 16:50:40 +00003381 return 0;
3382}
3383
Ben Hutchings8127d662013-08-29 19:19:29 +01003384static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3385 const efx_qword_t *event)
3386{
Jon Coopera0ee3542017-02-08 16:50:40 +00003387 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3388 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
Ben Hutchings8127d662013-08-29 19:19:29 +01003389 unsigned int n_descs, n_packets, i;
3390 struct efx_nic *efx = channel->efx;
Jon Coopera0ee3542017-02-08 16:50:40 +00003391 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003392 struct efx_rx_queue *rx_queue;
Jon Coopera0ee3542017-02-08 16:50:40 +00003393 efx_qword_t errors;
Ben Hutchings8127d662013-08-29 19:19:29 +01003394 bool rx_cont;
3395 u16 flags = 0;
3396
Mark Rutland6aa7de02017-10-23 14:07:29 -07003397 if (unlikely(READ_ONCE(efx->reset_pending)))
Ben Hutchings8127d662013-08-29 19:19:29 +01003398 return 0;
3399
3400 /* Basic packet information */
3401 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3402 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3403 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
Jon Coopera0ee3542017-02-08 16:50:40 +00003404 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003405 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003406 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
Jon Coopera0ee3542017-02-08 16:50:40 +00003407 rx_encap_hdr =
3408 nic_data->datapath_caps &
3409 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3410 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3411 ESE_EZ_ENCAP_HDR_NONE;
Ben Hutchings8127d662013-08-29 19:19:29 +01003412
Ben Hutchings48ce5632013-11-01 16:42:44 +00003413 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3414 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3415 EFX_QWORD_FMT "\n",
3416 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003417
3418 rx_queue = efx_channel_get_rx_queue(channel);
3419
3420 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3421 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3422
3423 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3424 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3425
3426 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003427 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3428
Ben Hutchings8127d662013-08-29 19:19:29 +01003429 /* detect rx abort */
3430 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003431 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3432 netdev_WARN(efx->net_dev,
3433 "invalid RX abort: scatter_n=%u event="
3434 EFX_QWORD_FMT "\n",
3435 rx_queue->scatter_n,
3436 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003437 efx_ef10_handle_rx_abort(rx_queue);
3438 return 0;
3439 }
3440
Ben Hutchings92a04162013-09-24 23:21:57 +01003441 /* Check that RX completion merging is valid, i.e.
3442 * the current firmware supports it and this is a
3443 * non-scattered packet.
3444 */
3445 if (!(nic_data->datapath_caps &
3446 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3447 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003448 efx_ef10_handle_rx_bad_lbits(
3449 rx_queue, next_ptr_lbits,
3450 (rx_queue->removed_count +
3451 rx_queue->scatter_n + 1) &
3452 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3453 return 0;
3454 }
3455
3456 /* Merged completion for multiple non-scattered packets */
3457 rx_queue->scatter_n = 1;
3458 rx_queue->scatter_len = 0;
3459 n_packets = n_descs;
3460 ++channel->n_rx_merge_events;
3461 channel->n_rx_merge_packets += n_packets;
3462 flags |= EFX_RX_PKT_PREFIX_LEN;
3463 } else {
3464 ++rx_queue->scatter_n;
3465 rx_queue->scatter_len += rx_bytes;
3466 if (rx_cont)
3467 return 0;
3468 n_packets = 1;
3469 }
3470
Jon Coopera0ee3542017-02-08 16:50:40 +00003471 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3472 ESF_DZ_RX_IPCKSUM_ERR, 1,
3473 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3474 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3475 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3476 EFX_AND_QWORD(errors, *event, errors);
3477 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3478 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
Edward Cree90d2ea92017-02-10 17:34:59 +00003479 rx_encap_hdr,
Jon Coopera0ee3542017-02-08 16:50:40 +00003480 rx_l3_class, rx_l4_class,
Edward Cree90d2ea92017-02-10 17:34:59 +00003481 event);
Jon Coopera0ee3542017-02-08 16:50:40 +00003482 } else {
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003483 bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
3484 rx_l4_class == ESE_FZ_L4_CLASS_UDP;
Jon Cooperda50ae22017-02-08 16:51:02 +00003485
3486 switch (rx_encap_hdr) {
3487 case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
3488 flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
3489 if (tcpudp)
3490 flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
3491 break;
3492 case ESE_EZ_ENCAP_HDR_GRE:
3493 case ESE_EZ_ENCAP_HDR_NONE:
3494 if (tcpudp)
3495 flags |= EFX_RX_PKT_CSUMMED;
3496 break;
3497 default:
3498 netdev_WARN(efx->net_dev,
3499 "unknown encapsulation type: event="
3500 EFX_QWORD_FMT "\n",
3501 EFX_QWORD_VAL(*event));
3502 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003503 }
3504
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003505 if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
Ben Hutchings8127d662013-08-29 19:19:29 +01003506 flags |= EFX_RX_PKT_TCP;
3507
3508 channel->irq_mod_score += 2 * n_packets;
3509
3510 /* Handle received packet(s) */
3511 for (i = 0; i < n_packets; i++) {
3512 efx_rx_packet(rx_queue,
3513 rx_queue->removed_count & rx_queue->ptr_mask,
3514 rx_queue->scatter_n, rx_queue->scatter_len,
3515 flags);
3516 rx_queue->removed_count += rx_queue->scatter_n;
3517 }
3518
3519 rx_queue->scatter_n = 0;
3520 rx_queue->scatter_len = 0;
3521
3522 return n_packets;
3523}
3524
3525static int
3526efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3527{
3528 struct efx_nic *efx = channel->efx;
3529 struct efx_tx_queue *tx_queue;
3530 unsigned int tx_ev_desc_ptr;
3531 unsigned int tx_ev_q_label;
3532 int tx_descs = 0;
3533
Mark Rutland6aa7de02017-10-23 14:07:29 -07003534 if (unlikely(READ_ONCE(efx->reset_pending)))
Ben Hutchings8127d662013-08-29 19:19:29 +01003535 return 0;
3536
3537 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3538 return 0;
3539
3540 /* Transmit completion */
3541 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3542 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3543 tx_queue = efx_channel_get_tx_queue(channel,
3544 tx_ev_q_label % EFX_TXQ_TYPES);
3545 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3546 tx_queue->ptr_mask);
3547 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3548
3549 return tx_descs;
3550}
3551
3552static void
3553efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3554{
3555 struct efx_nic *efx = channel->efx;
3556 int subcode;
3557
3558 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3559
3560 switch (subcode) {
3561 case ESE_DZ_DRV_TIMER_EV:
3562 case ESE_DZ_DRV_WAKE_UP_EV:
3563 break;
3564 case ESE_DZ_DRV_START_UP_EV:
3565 /* event queue init complete. ok. */
3566 break;
3567 default:
3568 netif_err(efx, hw, efx->net_dev,
3569 "channel %d unknown driver event type %d"
3570 " (data " EFX_QWORD_FMT ")\n",
3571 channel->channel, subcode,
3572 EFX_QWORD_VAL(*event));
3573
3574 }
3575}
3576
3577static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3578 efx_qword_t *event)
3579{
3580 struct efx_nic *efx = channel->efx;
3581 u32 subcode;
3582
3583 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3584
3585 switch (subcode) {
3586 case EFX_EF10_TEST:
3587 channel->event_test_cpu = raw_smp_processor_id();
3588 break;
3589 case EFX_EF10_REFILL:
3590 /* The queue must be empty, so we won't receive any rx
3591 * events, so efx_process_channel() won't refill the
3592 * queue. Refill it here
3593 */
Jon Coopercce28792013-10-02 11:04:14 +01003594 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003595 break;
3596 default:
3597 netif_err(efx, hw, efx->net_dev,
3598 "channel %d unknown driver event type %u"
3599 " (data " EFX_QWORD_FMT ")\n",
3600 channel->channel, (unsigned) subcode,
3601 EFX_QWORD_VAL(*event));
3602 }
3603}
3604
3605static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3606{
3607 struct efx_nic *efx = channel->efx;
3608 efx_qword_t event, *p_event;
3609 unsigned int read_ptr;
3610 int ev_code;
3611 int tx_descs = 0;
3612 int spent = 0;
3613
Eric W. Biederman75363a42014-03-14 18:11:22 -07003614 if (quota <= 0)
3615 return spent;
3616
Ben Hutchings8127d662013-08-29 19:19:29 +01003617 read_ptr = channel->eventq_read_ptr;
3618
3619 for (;;) {
3620 p_event = efx_event(channel, read_ptr);
3621 event = *p_event;
3622
3623 if (!efx_event_present(&event))
3624 break;
3625
3626 EFX_SET_QWORD(*p_event);
3627
3628 ++read_ptr;
3629
3630 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3631
3632 netif_vdbg(efx, drv, efx->net_dev,
3633 "processing event on %d " EFX_QWORD_FMT "\n",
3634 channel->channel, EFX_QWORD_VAL(event));
3635
3636 switch (ev_code) {
3637 case ESE_DZ_EV_CODE_MCDI_EV:
3638 efx_mcdi_process_event(channel, &event);
3639 break;
3640 case ESE_DZ_EV_CODE_RX_EV:
3641 spent += efx_ef10_handle_rx_event(channel, &event);
3642 if (spent >= quota) {
3643 /* XXX can we split a merged event to
3644 * avoid going over-quota?
3645 */
3646 spent = quota;
3647 goto out;
3648 }
3649 break;
3650 case ESE_DZ_EV_CODE_TX_EV:
3651 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3652 if (tx_descs > efx->txq_entries) {
3653 spent = quota;
3654 goto out;
3655 } else if (++spent == quota) {
3656 goto out;
3657 }
3658 break;
3659 case ESE_DZ_EV_CODE_DRIVER_EV:
3660 efx_ef10_handle_driver_event(channel, &event);
3661 if (++spent == quota)
3662 goto out;
3663 break;
3664 case EFX_EF10_DRVGEN_EV:
3665 efx_ef10_handle_driver_generated_event(channel, &event);
3666 break;
3667 default:
3668 netif_err(efx, hw, efx->net_dev,
3669 "channel %d unknown event type %d"
3670 " (data " EFX_QWORD_FMT ")\n",
3671 channel->channel, ev_code,
3672 EFX_QWORD_VAL(event));
3673 }
3674 }
3675
3676out:
3677 channel->eventq_read_ptr = read_ptr;
3678 return spent;
3679}
3680
3681static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3682{
3683 struct efx_nic *efx = channel->efx;
3684 efx_dword_t rptr;
3685
3686 if (EFX_EF10_WORKAROUND_35388(efx)) {
3687 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3688 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3689 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3690 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3691
3692 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3693 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3694 ERF_DD_EVQ_IND_RPTR,
3695 (channel->eventq_read_ptr &
3696 channel->eventq_mask) >>
3697 ERF_DD_EVQ_IND_RPTR_WIDTH);
3698 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3699 channel->channel);
3700 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3701 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3702 ERF_DD_EVQ_IND_RPTR,
3703 channel->eventq_read_ptr &
3704 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3705 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3706 channel->channel);
3707 } else {
3708 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3709 channel->eventq_read_ptr &
3710 channel->eventq_mask);
3711 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3712 }
3713}
3714
3715static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3716{
3717 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3718 struct efx_nic *efx = channel->efx;
3719 efx_qword_t event;
3720 int rc;
3721
3722 EFX_POPULATE_QWORD_2(event,
3723 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3724 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3725
3726 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3727
3728 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3729 * already swapped the data to little-endian order.
3730 */
3731 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3732 sizeof(efx_qword_t));
3733
3734 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3735 NULL, 0, NULL);
3736 if (rc != 0)
3737 goto fail;
3738
3739 return;
3740
3741fail:
3742 WARN_ON(true);
3743 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3744}
3745
3746void efx_ef10_handle_drain_event(struct efx_nic *efx)
3747{
3748 if (atomic_dec_and_test(&efx->active_queues))
3749 wake_up(&efx->flush_wq);
3750
3751 WARN_ON(atomic_read(&efx->active_queues) < 0);
3752}
3753
3754static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3755{
3756 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3757 struct efx_channel *channel;
3758 struct efx_tx_queue *tx_queue;
3759 struct efx_rx_queue *rx_queue;
3760 int pending;
3761
3762 /* If the MC has just rebooted, the TX/RX queues will have already been
3763 * torn down, but efx->active_queues needs to be set to zero.
3764 */
3765 if (nic_data->must_realloc_vis) {
3766 atomic_set(&efx->active_queues, 0);
3767 return 0;
3768 }
3769
3770 /* Do not attempt to write to the NIC during EEH recovery */
3771 if (efx->state != STATE_RECOVERY) {
3772 efx_for_each_channel(channel, efx) {
3773 efx_for_each_channel_rx_queue(rx_queue, channel)
3774 efx_ef10_rx_fini(rx_queue);
3775 efx_for_each_channel_tx_queue(tx_queue, channel)
3776 efx_ef10_tx_fini(tx_queue);
3777 }
3778
3779 wait_event_timeout(efx->flush_wq,
3780 atomic_read(&efx->active_queues) == 0,
3781 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3782 pending = atomic_read(&efx->active_queues);
3783 if (pending) {
3784 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3785 pending);
3786 return -ETIMEDOUT;
3787 }
3788 }
3789
3790 return 0;
3791}
3792
Edward Creee2835462014-04-16 19:27:48 +01003793static void efx_ef10_prepare_flr(struct efx_nic *efx)
3794{
3795 atomic_set(&efx->active_queues, 0);
3796}
3797
Ben Hutchings8127d662013-08-29 19:19:29 +01003798static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3799 const struct efx_filter_spec *right)
3800{
3801 if ((left->match_flags ^ right->match_flags) |
3802 ((left->flags ^ right->flags) &
3803 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3804 return false;
3805
3806 return memcmp(&left->outer_vid, &right->outer_vid,
3807 sizeof(struct efx_filter_spec) -
3808 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3809}
3810
3811static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3812{
3813 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3814 return jhash2((const u32 *)&spec->outer_vid,
3815 (sizeof(struct efx_filter_spec) -
3816 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3817 0);
3818 /* XXX should we randomise the initval? */
3819}
3820
3821/* Decide whether a filter should be exclusive or else should allow
3822 * delivery to additional recipients. Currently we decide that
3823 * filters for specific local unicast MAC and IP addresses are
3824 * exclusive.
3825 */
3826static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3827{
3828 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3829 !is_multicast_ether_addr(spec->loc_mac))
3830 return true;
3831
3832 if ((spec->match_flags &
3833 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3834 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3835 if (spec->ether_type == htons(ETH_P_IP) &&
3836 !ipv4_is_multicast(spec->loc_host[0]))
3837 return true;
3838 if (spec->ether_type == htons(ETH_P_IPV6) &&
3839 ((const u8 *)spec->loc_host)[0] != 0xff)
3840 return true;
3841 }
3842
3843 return false;
3844}
3845
3846static struct efx_filter_spec *
3847efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3848 unsigned int filter_idx)
3849{
3850 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3851 ~EFX_EF10_FILTER_FLAGS);
3852}
3853
3854static unsigned int
3855efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3856 unsigned int filter_idx)
3857{
3858 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3859}
3860
3861static void
3862efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3863 unsigned int filter_idx,
3864 const struct efx_filter_spec *spec,
3865 unsigned int flags)
3866{
3867 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3868}
3869
Edward Cree9b410802017-01-27 15:02:52 +00003870static void
3871efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
3872 const struct efx_filter_spec *spec,
3873 efx_dword_t *inbuf)
3874{
3875 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
3876 u32 match_fields = 0, uc_match, mc_match;
3877
3878 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3879 efx_ef10_filter_is_exclusive(spec) ?
3880 MC_CMD_FILTER_OP_IN_OP_INSERT :
3881 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3882
3883 /* Convert match flags and values. Unlike almost
3884 * everything else in MCDI, these fields are in
3885 * network byte order.
3886 */
3887#define COPY_VALUE(value, mcdi_field) \
3888 do { \
3889 match_fields |= \
3890 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3891 mcdi_field ## _LBN; \
3892 BUILD_BUG_ON( \
3893 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3894 sizeof(value)); \
3895 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3896 &value, sizeof(value)); \
3897 } while (0)
3898#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3899 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3900 COPY_VALUE(spec->gen_field, mcdi_field); \
3901 }
3902 /* Handle encap filters first. They will always be mismatch
3903 * (unknown UC or MC) filters
3904 */
3905 if (encap_type) {
3906 /* ether_type and outer_ip_proto need to be variables
3907 * because COPY_VALUE wants to memcpy them
3908 */
3909 __be16 ether_type =
3910 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
3911 ETH_P_IPV6 : ETH_P_IP);
3912 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
3913 u8 outer_ip_proto;
3914
3915 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
3916 case EFX_ENCAP_TYPE_VXLAN:
3917 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
3918 /* fallthrough */
3919 case EFX_ENCAP_TYPE_GENEVE:
3920 COPY_VALUE(ether_type, ETHER_TYPE);
3921 outer_ip_proto = IPPROTO_UDP;
3922 COPY_VALUE(outer_ip_proto, IP_PROTO);
3923 /* We always need to set the type field, even
3924 * though we're not matching on the TNI.
3925 */
3926 MCDI_POPULATE_DWORD_1(inbuf,
3927 FILTER_OP_EXT_IN_VNI_OR_VSID,
3928 FILTER_OP_EXT_IN_VNI_TYPE,
3929 vni_type);
3930 break;
3931 case EFX_ENCAP_TYPE_NVGRE:
3932 COPY_VALUE(ether_type, ETHER_TYPE);
3933 outer_ip_proto = IPPROTO_GRE;
3934 COPY_VALUE(outer_ip_proto, IP_PROTO);
3935 break;
3936 default:
3937 WARN_ON(1);
3938 }
3939
3940 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
3941 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
3942 } else {
3943 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3944 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
3945 }
3946
3947 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3948 match_fields |=
3949 is_multicast_ether_addr(spec->loc_mac) ?
3950 1 << mc_match :
3951 1 << uc_match;
3952 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3953 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3954 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3955 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3956 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3957 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3958 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3959 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3960 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3961 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3962#undef COPY_FIELD
3963#undef COPY_VALUE
3964 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3965 match_fields);
3966}
3967
Ben Hutchings8127d662013-08-29 19:19:29 +01003968static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3969 const struct efx_filter_spec *spec,
3970 efx_dword_t *inbuf, u64 handle,
3971 bool replacing)
3972{
3973 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003974 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003975
Edward Cree9b410802017-01-27 15:02:52 +00003976 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003977
Jon Cooperdcb41232016-04-25 16:51:00 +01003978 /* Remove RSS flag if we don't have an RSS context. */
3979 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3980 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3981 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3982 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3983
Ben Hutchings8127d662013-08-29 19:19:29 +01003984 if (replacing) {
3985 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3986 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3987 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3988 } else {
Edward Cree9b410802017-01-27 15:02:52 +00003989 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01003990 }
3991
Daniel Pieczko45b24492015-05-06 00:57:14 +01003992 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003993 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3994 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3995 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3996 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003997 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003998 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3999 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00004000 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
4001 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4002 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004003 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01004004 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01004005 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
4006 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01004007 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01004008 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
4009 spec->rss_context !=
4010 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
4011 spec->rss_context : nic_data->rx_rss_context);
4012}
4013
4014static int efx_ef10_filter_push(struct efx_nic *efx,
4015 const struct efx_filter_spec *spec,
4016 u64 *handle, bool replacing)
4017{
Edward Cree9b410802017-01-27 15:02:52 +00004018 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4019 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004020 int rc;
4021
4022 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
4023 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4024 outbuf, sizeof(outbuf), NULL);
4025 if (rc == 0)
4026 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01004027 if (rc == -ENOSPC)
4028 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01004029 return rc;
4030}
4031
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004032static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01004033{
Edward Cree9b410802017-01-27 15:02:52 +00004034 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004035 unsigned int match_flags = spec->match_flags;
Edward Cree9b410802017-01-27 15:02:52 +00004036 unsigned int uc_match, mc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004037 u32 mcdi_flags = 0;
4038
Edward Cree9b410802017-01-27 15:02:52 +00004039#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
4040 unsigned int old_match_flags = match_flags; \
4041 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
4042 if (match_flags != old_match_flags) \
4043 mcdi_flags |= \
4044 (1 << ((encap) ? \
4045 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
4046 mcdi_field ## _LBN : \
4047 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
4048 mcdi_field ## _LBN)); \
4049 }
4050 /* inner or outer based on encap type */
4051 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
4052 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
4053 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
4054 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
4055 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
4056 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
4057 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
4058 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
4059 /* always outer */
4060 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
4061 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
4062#undef MAP_FILTER_TO_MCDI_FLAG
4063
4064 /* special handling for encap type, and mismatch */
4065 if (encap_type) {
4066 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
4067 mcdi_flags |=
4068 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4069 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4070
4071 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4072 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4073 } else {
4074 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4075 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4076 }
4077
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004078 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
4079 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
4080 mcdi_flags |=
4081 is_multicast_ether_addr(spec->loc_mac) ?
Edward Cree9b410802017-01-27 15:02:52 +00004082 1 << mc_match :
4083 1 << uc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004084 }
4085
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004086 /* Did we map them all? */
4087 WARN_ON_ONCE(match_flags);
4088
4089 return mcdi_flags;
4090}
4091
4092static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
4093 const struct efx_filter_spec *spec)
4094{
4095 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004096 unsigned int match_pri;
4097
4098 for (match_pri = 0;
4099 match_pri < table->rx_match_count;
4100 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004101 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004102 return match_pri;
4103
4104 return -EPROTONOSUPPORT;
4105}
4106
4107static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4108 struct efx_filter_spec *spec,
4109 bool replace_equal)
4110{
4111 struct efx_ef10_filter_table *table = efx->filter_state;
4112 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4113 struct efx_filter_spec *saved_spec;
4114 unsigned int match_pri, hash;
4115 unsigned int priv_flags;
4116 bool replacing = false;
4117 int ins_index = -1;
4118 DEFINE_WAIT(wait);
4119 bool is_mc_recip;
4120 s32 rc;
4121
4122 /* For now, only support RX filters */
4123 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4124 EFX_FILTER_FLAG_RX)
4125 return -EINVAL;
4126
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004127 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004128 if (rc < 0)
4129 return rc;
4130 match_pri = rc;
4131
4132 hash = efx_ef10_filter_hash(spec);
4133 is_mc_recip = efx_filter_is_mc_recipient(spec);
4134 if (is_mc_recip)
4135 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4136
4137 /* Find any existing filters with the same match tuple or
4138 * else a free slot to insert at. If any of them are busy,
4139 * we have to wait and retry.
4140 */
4141 for (;;) {
4142 unsigned int depth = 1;
4143 unsigned int i;
4144
4145 spin_lock_bh(&efx->filter_lock);
4146
4147 for (;;) {
4148 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4149 saved_spec = efx_ef10_filter_entry_spec(table, i);
4150
4151 if (!saved_spec) {
4152 if (ins_index < 0)
4153 ins_index = i;
4154 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4155 if (table->entry[i].spec &
4156 EFX_EF10_FILTER_FLAG_BUSY)
4157 break;
4158 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004159 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004160 rc = -EPERM;
4161 goto out_unlock;
4162 }
4163 if (!is_mc_recip) {
4164 /* This is the only one */
4165 if (spec->priority ==
4166 saved_spec->priority &&
4167 !replace_equal) {
4168 rc = -EEXIST;
4169 goto out_unlock;
4170 }
4171 ins_index = i;
4172 goto found;
4173 } else if (spec->priority >
4174 saved_spec->priority ||
4175 (spec->priority ==
4176 saved_spec->priority &&
4177 replace_equal)) {
4178 if (ins_index < 0)
4179 ins_index = i;
4180 else
4181 __set_bit(depth, mc_rem_map);
4182 }
4183 }
4184
4185 /* Once we reach the maximum search depth, use
4186 * the first suitable slot or return -EBUSY if
4187 * there was none
4188 */
4189 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4190 if (ins_index < 0) {
4191 rc = -EBUSY;
4192 goto out_unlock;
4193 }
4194 goto found;
4195 }
4196
4197 ++depth;
4198 }
4199
4200 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4201 spin_unlock_bh(&efx->filter_lock);
4202 schedule();
4203 }
4204
4205found:
4206 /* Create a software table entry if necessary, and mark it
4207 * busy. We might yet fail to insert, but any attempt to
4208 * insert a conflicting filter while we're waiting for the
4209 * firmware must find the busy entry.
4210 */
4211 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4212 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004213 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4214 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004215 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004216 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4217 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004218 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004219 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01004220 rc = ins_index;
4221 goto out_unlock;
4222 }
4223 replacing = true;
4224 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4225 } else {
4226 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4227 if (!saved_spec) {
4228 rc = -ENOMEM;
4229 goto out_unlock;
4230 }
4231 *saved_spec = *spec;
4232 priv_flags = 0;
4233 }
4234 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4235 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4236
4237 /* Mark lower-priority multicast recipients busy prior to removal */
4238 if (is_mc_recip) {
4239 unsigned int depth, i;
4240
4241 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4242 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4243 if (test_bit(depth, mc_rem_map))
4244 table->entry[i].spec |=
4245 EFX_EF10_FILTER_FLAG_BUSY;
4246 }
4247 }
4248
4249 spin_unlock_bh(&efx->filter_lock);
4250
4251 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4252 replacing);
4253
4254 /* Finalise the software table entry */
4255 spin_lock_bh(&efx->filter_lock);
4256 if (rc == 0) {
4257 if (replacing) {
4258 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004259 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4260 saved_spec->flags |=
4261 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004262 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004263 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004264 saved_spec->flags |= spec->flags;
4265 saved_spec->rss_context = spec->rss_context;
4266 saved_spec->dmaq_id = spec->dmaq_id;
4267 }
4268 } else if (!replacing) {
4269 kfree(saved_spec);
4270 saved_spec = NULL;
4271 }
4272 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4273
4274 /* Remove and finalise entries for lower-priority multicast
4275 * recipients
4276 */
4277 if (is_mc_recip) {
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004278 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004279 unsigned int depth, i;
4280
4281 memset(inbuf, 0, sizeof(inbuf));
4282
4283 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4284 if (!test_bit(depth, mc_rem_map))
4285 continue;
4286
4287 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4288 saved_spec = efx_ef10_filter_entry_spec(table, i);
4289 priv_flags = efx_ef10_filter_entry_flags(table, i);
4290
4291 if (rc == 0) {
4292 spin_unlock_bh(&efx->filter_lock);
4293 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4294 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4295 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4296 table->entry[i].handle);
4297 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4298 inbuf, sizeof(inbuf),
4299 NULL, 0, NULL);
4300 spin_lock_bh(&efx->filter_lock);
4301 }
4302
4303 if (rc == 0) {
4304 kfree(saved_spec);
4305 saved_spec = NULL;
4306 priv_flags = 0;
4307 } else {
4308 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4309 }
4310 efx_ef10_filter_set_entry(table, i, saved_spec,
4311 priv_flags);
4312 }
4313 }
4314
4315 /* If successful, return the inserted filter ID */
4316 if (rc == 0)
Jon Cooper0ccb9982017-02-17 15:49:13 +00004317 rc = efx_ef10_make_filter_id(match_pri, ins_index);
Ben Hutchings8127d662013-08-29 19:19:29 +01004318
4319 wake_up_all(&table->waitq);
4320out_unlock:
4321 spin_unlock_bh(&efx->filter_lock);
4322 finish_wait(&table->waitq, &wait);
4323 return rc;
4324}
4325
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08004326static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01004327{
4328 /* no need to do anything here on EF10 */
4329}
4330
4331/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004332 * If !by_index, remove by ID
4333 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01004334 * Filter ID may come from userland and must be range-checked.
4335 */
4336static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004337 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004338 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01004339{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004340 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004341 struct efx_ef10_filter_table *table = efx->filter_state;
4342 MCDI_DECLARE_BUF(inbuf,
4343 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4344 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4345 struct efx_filter_spec *spec;
4346 DEFINE_WAIT(wait);
4347 int rc;
4348
4349 /* Find the software table entry and mark it busy. Don't
4350 * remove it yet; any attempt to update while we're waiting
4351 * for the firmware must find the busy entry.
4352 */
4353 for (;;) {
4354 spin_lock_bh(&efx->filter_lock);
4355 if (!(table->entry[filter_idx].spec &
4356 EFX_EF10_FILTER_FLAG_BUSY))
4357 break;
4358 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4359 spin_unlock_bh(&efx->filter_lock);
4360 schedule();
4361 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004362
Ben Hutchings8127d662013-08-29 19:19:29 +01004363 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004364 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004365 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004366 efx_ef10_filter_pri(table, spec) !=
Jon Cooper0ccb9982017-02-17 15:49:13 +00004367 efx_ef10_filter_get_unsafe_pri(filter_id))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004368 rc = -ENOENT;
4369 goto out_unlock;
4370 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004371
4372 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004373 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004374 /* Just remove flags */
4375 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004376 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004377 rc = 0;
4378 goto out_unlock;
4379 }
4380
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004381 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004382 rc = -ENOENT;
4383 goto out_unlock;
4384 }
4385
Ben Hutchings8127d662013-08-29 19:19:29 +01004386 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4387 spin_unlock_bh(&efx->filter_lock);
4388
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004389 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004390 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01004391
4392 struct efx_filter_spec new_spec = *spec;
4393
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004394 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004395 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004396 (efx_rss_enabled(efx) ?
4397 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01004398 new_spec.dmaq_id = 0;
4399 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4400 rc = efx_ef10_filter_push(efx, &new_spec,
4401 &table->entry[filter_idx].handle,
4402 true);
4403
4404 spin_lock_bh(&efx->filter_lock);
4405 if (rc == 0)
4406 *spec = new_spec;
4407 } else {
4408 /* Really remove the filter */
4409
4410 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4411 efx_ef10_filter_is_exclusive(spec) ?
4412 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4413 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4414 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4415 table->entry[filter_idx].handle);
Bert Kenward105eac62017-02-17 15:50:12 +00004416 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4417 inbuf, sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01004418
4419 spin_lock_bh(&efx->filter_lock);
Bert Kenward105eac62017-02-17 15:50:12 +00004420 if ((rc == 0) || (rc == -ENOENT)) {
4421 /* Filter removed OK or didn't actually exist */
Ben Hutchings8127d662013-08-29 19:19:29 +01004422 kfree(spec);
4423 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
Bert Kenward105eac62017-02-17 15:50:12 +00004424 } else {
4425 efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004426 MC_CMD_FILTER_OP_EXT_IN_LEN,
Bert Kenward105eac62017-02-17 15:50:12 +00004427 NULL, 0, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004428 }
4429 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004430
Ben Hutchings8127d662013-08-29 19:19:29 +01004431 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4432 wake_up_all(&table->waitq);
4433out_unlock:
4434 spin_unlock_bh(&efx->filter_lock);
4435 finish_wait(&table->waitq, &wait);
4436 return rc;
4437}
4438
4439static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4440 enum efx_filter_priority priority,
4441 u32 filter_id)
4442{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004443 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4444 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004445}
4446
Edward Cree8c915622016-06-15 17:49:05 +01004447static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4448 enum efx_filter_priority priority,
4449 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004450{
Edward Cree8c915622016-06-15 17:49:05 +01004451 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4452 return;
4453 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004454}
4455
Ben Hutchings8127d662013-08-29 19:19:29 +01004456static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4457 enum efx_filter_priority priority,
4458 u32 filter_id, struct efx_filter_spec *spec)
4459{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004460 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004461 struct efx_ef10_filter_table *table = efx->filter_state;
4462 const struct efx_filter_spec *saved_spec;
4463 int rc;
4464
4465 spin_lock_bh(&efx->filter_lock);
4466 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4467 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004468 efx_ef10_filter_pri(table, saved_spec) ==
Jon Cooper0ccb9982017-02-17 15:49:13 +00004469 efx_ef10_filter_get_unsafe_pri(filter_id)) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004470 *spec = *saved_spec;
4471 rc = 0;
4472 } else {
4473 rc = -ENOENT;
4474 }
4475 spin_unlock_bh(&efx->filter_lock);
4476 return rc;
4477}
4478
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004479static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004480 enum efx_filter_priority priority)
4481{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004482 unsigned int priority_mask;
4483 unsigned int i;
4484 int rc;
4485
4486 priority_mask = (((1U << (priority + 1)) - 1) &
4487 ~(1U << EFX_FILTER_PRI_AUTO));
4488
4489 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4490 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4491 i, true);
4492 if (rc && rc != -ENOENT)
4493 return rc;
4494 }
4495
4496 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004497}
4498
4499static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4500 enum efx_filter_priority priority)
4501{
4502 struct efx_ef10_filter_table *table = efx->filter_state;
4503 unsigned int filter_idx;
4504 s32 count = 0;
4505
4506 spin_lock_bh(&efx->filter_lock);
4507 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4508 if (table->entry[filter_idx].spec &&
4509 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4510 priority)
4511 ++count;
4512 }
4513 spin_unlock_bh(&efx->filter_lock);
4514 return count;
4515}
4516
4517static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4518{
4519 struct efx_ef10_filter_table *table = efx->filter_state;
4520
Jon Cooper0ccb9982017-02-17 15:49:13 +00004521 return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
Ben Hutchings8127d662013-08-29 19:19:29 +01004522}
4523
4524static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4525 enum efx_filter_priority priority,
4526 u32 *buf, u32 size)
4527{
4528 struct efx_ef10_filter_table *table = efx->filter_state;
4529 struct efx_filter_spec *spec;
4530 unsigned int filter_idx;
4531 s32 count = 0;
4532
4533 spin_lock_bh(&efx->filter_lock);
4534 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4535 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4536 if (spec && spec->priority == priority) {
4537 if (count == size) {
4538 count = -EMSGSIZE;
4539 break;
4540 }
Jon Cooper0ccb9982017-02-17 15:49:13 +00004541 buf[count++] =
4542 efx_ef10_make_filter_id(
4543 efx_ef10_filter_pri(table, spec),
Ben Hutchings8127d662013-08-29 19:19:29 +01004544 filter_idx);
4545 }
4546 }
4547 spin_unlock_bh(&efx->filter_lock);
4548 return count;
4549}
4550
4551#ifdef CONFIG_RFS_ACCEL
4552
4553static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4554
4555static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4556 struct efx_filter_spec *spec)
4557{
4558 struct efx_ef10_filter_table *table = efx->filter_state;
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004559 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004560 struct efx_filter_spec *saved_spec;
4561 unsigned int hash, i, depth = 1;
4562 bool replacing = false;
4563 int ins_index = -1;
4564 u64 cookie;
4565 s32 rc;
4566
4567 /* Must be an RX filter without RSS and not for a multicast
4568 * destination address (RFS only works for connected sockets).
4569 * These restrictions allow us to pass only a tiny amount of
4570 * data through to the completion function.
4571 */
4572 EFX_WARN_ON_PARANOID(spec->flags !=
4573 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4574 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4575 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4576
4577 hash = efx_ef10_filter_hash(spec);
4578
4579 spin_lock_bh(&efx->filter_lock);
4580
4581 /* Find any existing filter with the same match tuple or else
4582 * a free slot to insert at. If an existing filter is busy,
4583 * we have to give up.
4584 */
4585 for (;;) {
4586 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4587 saved_spec = efx_ef10_filter_entry_spec(table, i);
4588
4589 if (!saved_spec) {
4590 if (ins_index < 0)
4591 ins_index = i;
4592 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4593 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4594 rc = -EBUSY;
4595 goto fail_unlock;
4596 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004597 if (spec->priority < saved_spec->priority) {
4598 rc = -EPERM;
4599 goto fail_unlock;
4600 }
4601 ins_index = i;
4602 break;
4603 }
4604
4605 /* Once we reach the maximum search depth, use the
4606 * first suitable slot or return -EBUSY if there was
4607 * none
4608 */
4609 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4610 if (ins_index < 0) {
4611 rc = -EBUSY;
4612 goto fail_unlock;
4613 }
4614 break;
4615 }
4616
4617 ++depth;
4618 }
4619
4620 /* Create a software table entry if necessary, and mark it
4621 * busy. We might yet fail to insert, but any attempt to
4622 * insert a conflicting filter while we're waiting for the
4623 * firmware must find the busy entry.
4624 */
4625 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4626 if (saved_spec) {
4627 replacing = true;
4628 } else {
4629 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4630 if (!saved_spec) {
4631 rc = -ENOMEM;
4632 goto fail_unlock;
4633 }
4634 *saved_spec = *spec;
4635 }
4636 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4637 EFX_EF10_FILTER_FLAG_BUSY);
4638
4639 spin_unlock_bh(&efx->filter_lock);
4640
4641 /* Pack up the variables needed on completion */
4642 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4643
4644 efx_ef10_filter_push_prep(efx, spec, inbuf,
4645 table->entry[ins_index].handle, replacing);
4646 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4647 MC_CMD_FILTER_OP_OUT_LEN,
4648 efx_ef10_filter_rfs_insert_complete, cookie);
4649
4650 return ins_index;
4651
4652fail_unlock:
4653 spin_unlock_bh(&efx->filter_lock);
4654 return rc;
4655}
4656
4657static void
4658efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4659 int rc, efx_dword_t *outbuf,
4660 size_t outlen_actual)
4661{
4662 struct efx_ef10_filter_table *table = efx->filter_state;
4663 unsigned int ins_index, dmaq_id;
4664 struct efx_filter_spec *spec;
4665 bool replacing;
4666
4667 /* Unpack the cookie */
4668 replacing = cookie >> 31;
4669 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4670 dmaq_id = cookie & 0xffff;
4671
4672 spin_lock_bh(&efx->filter_lock);
4673 spec = efx_ef10_filter_entry_spec(table, ins_index);
4674 if (rc == 0) {
4675 table->entry[ins_index].handle =
4676 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4677 if (replacing)
4678 spec->dmaq_id = dmaq_id;
4679 } else if (!replacing) {
4680 kfree(spec);
4681 spec = NULL;
4682 }
4683 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4684 spin_unlock_bh(&efx->filter_lock);
4685
4686 wake_up_all(&table->waitq);
4687}
4688
4689static void
4690efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4691 unsigned long filter_idx,
4692 int rc, efx_dword_t *outbuf,
4693 size_t outlen_actual);
4694
4695static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4696 unsigned int filter_idx)
4697{
4698 struct efx_ef10_filter_table *table = efx->filter_state;
4699 struct efx_filter_spec *spec =
4700 efx_ef10_filter_entry_spec(table, filter_idx);
4701 MCDI_DECLARE_BUF(inbuf,
4702 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4703 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4704
4705 if (!spec ||
4706 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4707 spec->priority != EFX_FILTER_PRI_HINT ||
4708 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4709 flow_id, filter_idx))
4710 return false;
4711
4712 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4713 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4714 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4715 table->entry[filter_idx].handle);
4716 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4717 efx_ef10_filter_rfs_expire_complete, filter_idx))
4718 return false;
4719
4720 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4721 return true;
4722}
4723
4724static void
4725efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4726 unsigned long filter_idx,
4727 int rc, efx_dword_t *outbuf,
4728 size_t outlen_actual)
4729{
4730 struct efx_ef10_filter_table *table = efx->filter_state;
4731 struct efx_filter_spec *spec =
4732 efx_ef10_filter_entry_spec(table, filter_idx);
4733
4734 spin_lock_bh(&efx->filter_lock);
4735 if (rc == 0) {
4736 kfree(spec);
4737 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4738 }
4739 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4740 wake_up_all(&table->waitq);
4741 spin_unlock_bh(&efx->filter_lock);
4742}
4743
4744#endif /* CONFIG_RFS_ACCEL */
4745
Edward Cree9b410802017-01-27 15:02:52 +00004746static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004747{
4748 int match_flags = 0;
4749
Edward Cree9b410802017-01-27 15:02:52 +00004750#define MAP_FLAG(gen_flag, mcdi_field) do { \
Ben Hutchings8127d662013-08-29 19:19:29 +01004751 u32 old_mcdi_flags = mcdi_flags; \
Edward Cree9b410802017-01-27 15:02:52 +00004752 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4753 mcdi_field ## _LBN); \
Ben Hutchings8127d662013-08-29 19:19:29 +01004754 if (mcdi_flags != old_mcdi_flags) \
4755 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
Edward Cree9b410802017-01-27 15:02:52 +00004756 } while (0)
4757
4758 if (encap) {
4759 /* encap filters must specify encap type */
4760 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4761 /* and imply ethertype and ip proto */
4762 mcdi_flags &=
4763 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4764 mcdi_flags &=
4765 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4766 /* VLAN tags refer to the outer packet */
4767 MAP_FLAG(INNER_VID, INNER_VLAN);
4768 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4769 /* everything else refers to the inner packet */
4770 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4771 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4772 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4773 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4774 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4775 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4776 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4777 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4778 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4779 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4780 } else {
4781 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4782 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4783 MAP_FLAG(REM_HOST, SRC_IP);
4784 MAP_FLAG(LOC_HOST, DST_IP);
4785 MAP_FLAG(REM_MAC, SRC_MAC);
4786 MAP_FLAG(REM_PORT, SRC_PORT);
4787 MAP_FLAG(LOC_MAC, DST_MAC);
4788 MAP_FLAG(LOC_PORT, DST_PORT);
4789 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4790 MAP_FLAG(INNER_VID, INNER_VLAN);
4791 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4792 MAP_FLAG(IP_PROTO, IP_PROTO);
Ben Hutchings8127d662013-08-29 19:19:29 +01004793 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004794#undef MAP_FLAG
4795
4796 /* Did we map them all? */
4797 if (mcdi_flags)
4798 return -EINVAL;
4799
4800 return match_flags;
4801}
4802
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004803static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4804{
4805 struct efx_ef10_filter_table *table = efx->filter_state;
4806 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4807
4808 /* See comment in efx_ef10_filter_table_remove() */
4809 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4810 return;
4811
4812 if (!table)
4813 return;
4814
4815 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4816 efx_ef10_filter_del_vlan_internal(efx, vlan);
4817}
4818
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004819static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
Edward Cree9b410802017-01-27 15:02:52 +00004820 bool encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004821 enum efx_filter_match_flags match_flags)
4822{
4823 unsigned int match_pri;
4824 int mf;
4825
4826 for (match_pri = 0;
4827 match_pri < table->rx_match_count;
4828 match_pri++) {
Edward Cree9b410802017-01-27 15:02:52 +00004829 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004830 table->rx_match_mcdi_flags[match_pri]);
4831 if (mf == match_flags)
4832 return true;
4833 }
4834
4835 return false;
4836}
4837
Edward Cree9b410802017-01-27 15:02:52 +00004838static int
4839efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4840 struct efx_ef10_filter_table *table,
4841 bool encap)
Ben Hutchings8127d662013-08-29 19:19:29 +01004842{
4843 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4844 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4845 unsigned int pd_match_pri, pd_match_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01004846 size_t outlen;
4847 int rc;
4848
Ben Hutchings8127d662013-08-29 19:19:29 +01004849 /* Find out which RX filter types are supported, and their priorities */
4850 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
Edward Cree9b410802017-01-27 15:02:52 +00004851 encap ?
4852 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
Ben Hutchings8127d662013-08-29 19:19:29 +01004853 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4854 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4855 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4856 &outlen);
4857 if (rc)
Edward Cree9b410802017-01-27 15:02:52 +00004858 return rc;
4859
Ben Hutchings8127d662013-08-29 19:19:29 +01004860 pd_match_count = MCDI_VAR_ARRAY_LEN(
4861 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
Ben Hutchings8127d662013-08-29 19:19:29 +01004862
4863 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4864 u32 mcdi_flags =
4865 MCDI_ARRAY_DWORD(
4866 outbuf,
4867 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4868 pd_match_pri);
Edward Cree9b410802017-01-27 15:02:52 +00004869 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
Ben Hutchings8127d662013-08-29 19:19:29 +01004870 if (rc < 0) {
4871 netif_dbg(efx, probe, efx->net_dev,
4872 "%s: fw flags %#x pri %u not supported in driver\n",
4873 __func__, mcdi_flags, pd_match_pri);
4874 } else {
4875 netif_dbg(efx, probe, efx->net_dev,
4876 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4877 __func__, mcdi_flags, pd_match_pri,
4878 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004879 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4880 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004881 }
4882 }
4883
Edward Cree9b410802017-01-27 15:02:52 +00004884 return 0;
4885}
4886
4887static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4888{
4889 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4890 struct net_device *net_dev = efx->net_dev;
4891 struct efx_ef10_filter_table *table;
4892 struct efx_ef10_vlan *vlan;
4893 int rc;
4894
4895 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4896 return -EINVAL;
4897
4898 if (efx->filter_state) /* already probed */
4899 return 0;
4900
4901 table = kzalloc(sizeof(*table), GFP_KERNEL);
4902 if (!table)
4903 return -ENOMEM;
4904
4905 table->rx_match_count = 0;
4906 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
4907 if (rc)
4908 goto fail;
4909 if (nic_data->datapath_caps &
4910 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
4911 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
4912 if (rc)
4913 goto fail;
Martin Habetse4478ad2016-06-15 17:51:07 +01004914 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
Edward Cree9b410802017-01-27 15:02:52 +00004915 !(efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004916 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
Edward Cree9b410802017-01-27 15:02:52 +00004917 efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004918 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4919 netif_info(efx, probe, net_dev,
4920 "VLAN filters are not supported in this firmware variant\n");
4921 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4922 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4923 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4924 }
4925
Ben Hutchings8127d662013-08-29 19:19:29 +01004926 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4927 if (!table->entry) {
4928 rc = -ENOMEM;
4929 goto fail;
4930 }
4931
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004932 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004933 table->vlan_filter =
4934 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004935 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004936
Ben Hutchings8127d662013-08-29 19:19:29 +01004937 efx->filter_state = table;
4938 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004939
4940 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4941 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4942 if (rc)
4943 goto fail_add_vlan;
4944 }
4945
Ben Hutchings8127d662013-08-29 19:19:29 +01004946 return 0;
4947
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004948fail_add_vlan:
4949 efx_ef10_filter_cleanup_vlans(efx);
4950 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004951fail:
4952 kfree(table);
4953 return rc;
4954}
4955
Edward Cree0d322412015-05-20 11:10:03 +01004956/* Caller must hold efx->filter_sem for read if race against
4957 * efx_ef10_filter_table_remove() is possible
4958 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004959static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4960{
4961 struct efx_ef10_filter_table *table = efx->filter_state;
4962 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004963 unsigned int invalid_filters = 0, failed = 0;
4964 struct efx_ef10_filter_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004965 struct efx_filter_spec *spec;
4966 unsigned int filter_idx;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004967 u32 mcdi_flags;
4968 int match_pri;
Edward Cree9b410802017-01-27 15:02:52 +00004969 int rc, i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004970
Edward Cree0d322412015-05-20 11:10:03 +01004971 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4972
Ben Hutchings8127d662013-08-29 19:19:29 +01004973 if (!nic_data->must_restore_filters)
4974 return;
4975
Edward Cree0d322412015-05-20 11:10:03 +01004976 if (!table)
4977 return;
4978
Ben Hutchings8127d662013-08-29 19:19:29 +01004979 spin_lock_bh(&efx->filter_lock);
4980
4981 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4982 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4983 if (!spec)
4984 continue;
4985
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004986 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4987 match_pri = 0;
4988 while (match_pri < table->rx_match_count &&
4989 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
4990 ++match_pri;
4991 if (match_pri >= table->rx_match_count) {
4992 invalid_filters++;
4993 goto not_restored;
4994 }
4995 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4996 spec->rss_context != nic_data->rx_rss_context)
4997 netif_warn(efx, drv, efx->net_dev,
4998 "Warning: unable to restore a filter with specific RSS context.\n");
4999
Ben Hutchings8127d662013-08-29 19:19:29 +01005000 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
5001 spin_unlock_bh(&efx->filter_lock);
5002
5003 rc = efx_ef10_filter_push(efx, spec,
5004 &table->entry[filter_idx].handle,
5005 false);
5006 if (rc)
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005007 failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005008 spin_lock_bh(&efx->filter_lock);
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005009
Ben Hutchings8127d662013-08-29 19:19:29 +01005010 if (rc) {
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005011not_restored:
Edward Cree9b410802017-01-27 15:02:52 +00005012 list_for_each_entry(vlan, &table->vlan_list, list)
5013 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
5014 if (vlan->default_filters[i] == filter_idx)
5015 vlan->default_filters[i] =
5016 EFX_EF10_FILTER_ID_INVALID;
5017
Ben Hutchings8127d662013-08-29 19:19:29 +01005018 kfree(spec);
5019 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
5020 } else {
5021 table->entry[filter_idx].spec &=
5022 ~EFX_EF10_FILTER_FLAG_BUSY;
5023 }
5024 }
5025
5026 spin_unlock_bh(&efx->filter_lock);
5027
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005028 /* This can happen validly if the MC's capabilities have changed, so
5029 * is not an error.
5030 */
5031 if (invalid_filters)
5032 netif_dbg(efx, drv, efx->net_dev,
5033 "Did not restore %u filters that are now unsupported.\n",
5034 invalid_filters);
5035
Ben Hutchings8127d662013-08-29 19:19:29 +01005036 if (failed)
5037 netif_err(efx, hw, efx->net_dev,
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005038 "unable to restore %u filters\n", failed);
Ben Hutchings8127d662013-08-29 19:19:29 +01005039 else
5040 nic_data->must_restore_filters = false;
5041}
5042
5043static void efx_ef10_filter_table_remove(struct efx_nic *efx)
5044{
5045 struct efx_ef10_filter_table *table = efx->filter_state;
Martin Habetsbb53f4d2017-06-22 10:50:41 +01005046 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01005047 struct efx_filter_spec *spec;
5048 unsigned int filter_idx;
5049 int rc;
5050
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005051 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01005052 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01005053 /* If we were called without locking, then it's not safe to free
5054 * the table as others might be using it. So we just WARN, leak
5055 * the memory, and potentially get an inconsistent filter table
5056 * state.
5057 * This should never actually happen.
5058 */
5059 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5060 return;
5061
Edward Cree0d322412015-05-20 11:10:03 +01005062 if (!table)
5063 return;
5064
Ben Hutchings8127d662013-08-29 19:19:29 +01005065 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5066 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5067 if (!spec)
5068 continue;
5069
5070 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
5071 efx_ef10_filter_is_exclusive(spec) ?
5072 MC_CMD_FILTER_OP_IN_OP_REMOVE :
5073 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
5074 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
5075 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00005076 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
5077 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00005078 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00005079 netif_info(efx, drv, efx->net_dev,
5080 "%s: filter %04x remove failed\n",
5081 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01005082 kfree(spec);
5083 }
5084
5085 vfree(table->entry);
5086 kfree(table);
5087}
5088
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005089static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5090{
5091 struct efx_ef10_filter_table *table = efx->filter_state;
5092 unsigned int filter_idx;
5093
5094 if (*id != EFX_EF10_FILTER_ID_INVALID) {
Jon Cooper0ccb9982017-02-17 15:49:13 +00005095 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005096 if (!table->entry[filter_idx].spec)
5097 netif_dbg(efx, drv, efx->net_dev,
5098 "marked null spec old %04x:%04x\n", *id,
5099 filter_idx);
5100 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
5101 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005102 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005103}
5104
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005105/* Mark old per-VLAN filters that may need to be removed */
5106static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
5107 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01005108{
5109 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005110 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01005111
Edward Cree12fb0da2015-07-21 15:11:00 +01005112 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005113 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01005114 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005115 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005116 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5117 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005118}
5119
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005120/* Mark old filters that may need to be removed.
5121 * Caller must hold efx->filter_sem for read if race against
5122 * efx_ef10_filter_table_remove() is possible
5123 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005124static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5125{
5126 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005127 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005128
5129 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005130 list_for_each_entry(vlan, &table->vlan_list, list)
5131 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01005132 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005133}
Ben Hutchings8127d662013-08-29 19:19:29 +01005134
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005135static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005136{
5137 struct efx_ef10_filter_table *table = efx->filter_state;
5138 struct net_device *net_dev = efx->net_dev;
5139 struct netdev_hw_addr *uc;
5140 unsigned int i;
5141
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005142 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005143 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
5144 i = 1;
5145 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005146 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005147 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005148 break;
5149 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005150 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
5151 i++;
5152 }
Bert Kenwardc70d6812017-07-12 17:19:41 +01005153
5154 table->dev_uc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005155}
5156
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005157static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005158{
5159 struct efx_ef10_filter_table *table = efx->filter_state;
5160 struct net_device *net_dev = efx->net_dev;
5161 struct netdev_hw_addr *mc;
Bert Kenwardc70d6812017-07-12 17:19:41 +01005162 unsigned int i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005163
Edward Cree148cbab2017-04-04 17:02:49 +01005164 table->mc_overflow = false;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005165 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005166
Edward Cree12fb0da2015-07-21 15:11:00 +01005167 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005168 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005169 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005170 table->mc_promisc = true;
Edward Cree148cbab2017-04-04 17:02:49 +01005171 table->mc_overflow = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005172 break;
5173 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005174 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5175 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005176 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005177
5178 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005179}
Ben Hutchings8127d662013-08-29 19:19:29 +01005180
Edward Cree12fb0da2015-07-21 15:11:00 +01005181static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005182 struct efx_ef10_filter_vlan *vlan,
5183 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005184{
5185 struct efx_ef10_filter_table *table = efx->filter_state;
5186 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005187 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005188 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01005189 u8 baddr[ETH_ALEN];
5190 unsigned int i, j;
5191 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005192 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005193 int rc;
5194
5195 if (multicast) {
5196 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005197 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005198 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005199 } else {
5200 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005201 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005202 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005203 }
5204
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005205 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5206
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005207 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01005208 for (i = 0; i < addr_count; i++) {
Edward Creed58299a2017-06-29 16:50:06 +01005209 EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005210 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005211 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01005212 rc = efx_ef10_filter_insert(efx, &spec, true);
5213 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005214 if (rollback) {
5215 netif_info(efx, drv, efx->net_dev,
5216 "efx_ef10_filter_insert failed rc=%d\n",
5217 rc);
5218 /* Fall back to promiscuous */
5219 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005220 efx_ef10_filter_remove_unsafe(
5221 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005222 ids[j]);
5223 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005224 }
5225 return rc;
5226 } else {
Edward Creed58299a2017-06-29 16:50:06 +01005227 /* keep invalid ID, and carry on */
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005228 }
Edward Creed58299a2017-06-29 16:50:06 +01005229 } else {
5230 ids[i] = efx_ef10_filter_get_unsafe_id(rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01005231 }
5232 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005233
Edward Cree12fb0da2015-07-21 15:11:00 +01005234 if (multicast && rollback) {
5235 /* Also need an Ethernet broadcast filter */
Edward Cree9b410802017-01-27 15:02:52 +00005236 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5237 EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005238 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005239 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005240 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005241 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01005242 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005243 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01005244 "Broadcast filter insert failed rc=%d\n", rc);
5245 /* Fall back to promiscuous */
5246 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005247 efx_ef10_filter_remove_unsafe(
5248 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005249 ids[j]);
5250 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005251 }
5252 return rc;
5253 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005254 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005255 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005256 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005257 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005258
5259 return 0;
5260}
5261
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005262static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5263 struct efx_ef10_filter_vlan *vlan,
Edward Cree9b410802017-01-27 15:02:52 +00005264 enum efx_encap_type encap_type,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005265 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01005266{
Edward Cree12fb0da2015-07-21 15:11:00 +01005267 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005268 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01005269 struct efx_filter_spec spec;
5270 u8 baddr[ETH_ALEN];
5271 int rc;
Edward Cree9b410802017-01-27 15:02:52 +00005272 u16 *id;
Edward Cree12fb0da2015-07-21 15:11:00 +01005273
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005274 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5275
5276 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005277
5278 if (multicast)
5279 efx_filter_set_mc_def(&spec);
5280 else
5281 efx_filter_set_uc_def(&spec);
5282
Edward Cree9b410802017-01-27 15:02:52 +00005283 if (encap_type) {
5284 if (nic_data->datapath_caps &
5285 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5286 efx_filter_set_encap_type(&spec, encap_type);
5287 else
5288 /* don't insert encap filters on non-supporting
5289 * platforms. ID will be left as INVALID.
5290 */
5291 return 0;
5292 }
5293
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005294 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5295 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5296
Edward Cree12fb0da2015-07-21 15:11:00 +01005297 rc = efx_ef10_filter_insert(efx, &spec, true);
5298 if (rc < 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005299 const char *um = multicast ? "Multicast" : "Unicast";
5300 const char *encap_name = "";
5301 const char *encap_ipv = "";
5302
5303 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5304 EFX_ENCAP_TYPE_VXLAN)
5305 encap_name = "VXLAN ";
5306 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5307 EFX_ENCAP_TYPE_NVGRE)
5308 encap_name = "NVGRE ";
5309 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5310 EFX_ENCAP_TYPE_GENEVE)
5311 encap_name = "GENEVE ";
5312 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5313 encap_ipv = "IPv6 ";
5314 else if (encap_type)
5315 encap_ipv = "IPv4 ";
5316
5317 /* unprivileged functions can't insert mismatch filters
5318 * for encapsulated or unicast traffic, so downgrade
5319 * those warnings to debug.
5320 */
Jon Cooper34e7aef2017-01-27 15:02:39 +00005321 netif_cond_dbg(efx, drv, efx->net_dev,
Edward Cree9b410802017-01-27 15:02:52 +00005322 rc == -EPERM && (encap_type || !multicast), warn,
5323 "%s%s%s mismatch filter insert failed rc=%d\n",
5324 encap_name, encap_ipv, um, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005325 } else if (multicast) {
Edward Cree9b410802017-01-27 15:02:52 +00005326 /* mapping from encap types to default filter IDs (multicast) */
5327 static enum efx_ef10_default_filters map[] = {
5328 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5329 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5330 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5331 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5332 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5333 EFX_EF10_VXLAN6_MCDEF,
5334 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5335 EFX_EF10_NVGRE6_MCDEF,
5336 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5337 EFX_EF10_GENEVE6_MCDEF,
5338 };
5339
5340 /* quick bounds check (BCAST result impossible) */
5341 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Colin Ian Kinge9904992017-01-31 16:30:02 +00005342 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005343 WARN_ON(1);
5344 return -EINVAL;
5345 }
5346 /* then follow map */
5347 id = &vlan->default_filters[map[encap_type]];
5348
5349 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
Jon Cooper0ccb9982017-02-17 15:49:13 +00005350 *id = efx_ef10_filter_get_unsafe_id(rc);
Edward Cree9b410802017-01-27 15:02:52 +00005351 if (!nic_data->workaround_26807 && !encap_type) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005352 /* Also need an Ethernet broadcast filter */
5353 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005354 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005355 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005356 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01005357 rc = efx_ef10_filter_insert(efx, &spec, true);
5358 if (rc < 0) {
5359 netif_warn(efx, drv, efx->net_dev,
5360 "Broadcast filter insert failed rc=%d\n",
5361 rc);
5362 if (rollback) {
5363 /* Roll back the mc_def filter */
5364 efx_ef10_filter_remove_unsafe(
5365 efx, EFX_FILTER_PRI_AUTO,
Edward Cree9b410802017-01-27 15:02:52 +00005366 *id);
5367 *id = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005368 return rc;
5369 }
5370 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005371 EFX_WARN_ON_PARANOID(
5372 vlan->default_filters[EFX_EF10_BCAST] !=
5373 EFX_EF10_FILTER_ID_INVALID);
5374 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005375 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005376 }
5377 }
5378 rc = 0;
5379 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005380 /* mapping from encap types to default filter IDs (unicast) */
5381 static enum efx_ef10_default_filters map[] = {
5382 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5383 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5384 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5385 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5386 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5387 EFX_EF10_VXLAN6_UCDEF,
5388 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5389 EFX_EF10_NVGRE6_UCDEF,
5390 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5391 EFX_EF10_GENEVE6_UCDEF,
5392 };
5393
5394 /* quick bounds check (BCAST result impossible) */
5395 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Dan Carpenteree467fb2017-02-07 10:44:31 +03005396 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005397 WARN_ON(1);
5398 return -EINVAL;
5399 }
5400 /* then follow map */
5401 id = &vlan->default_filters[map[encap_type]];
5402 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5403 *id = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01005404 rc = 0;
5405 }
5406 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005407}
5408
5409/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5410 * flag or removes these filters, we don't need to hold the filter_lock while
5411 * scanning for these filters.
5412 */
5413static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5414{
5415 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005416 int remove_failed = 0;
5417 int remove_noent = 0;
5418 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005419 int i;
5420
Ben Hutchings8127d662013-08-29 19:19:29 +01005421 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07005422 if (READ_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00005423 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00005424 rc = efx_ef10_filter_remove_internal(efx,
5425 1U << EFX_FILTER_PRI_AUTO, i, true);
5426 if (rc == -ENOENT)
5427 remove_noent++;
5428 else if (rc)
5429 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005430 }
5431 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00005432
5433 if (remove_failed)
5434 netif_info(efx, drv, efx->net_dev,
5435 "%s: failed to remove %d filters\n",
5436 __func__, remove_failed);
5437 if (remove_noent)
5438 netif_info(efx, drv, efx->net_dev,
5439 "%s: failed to remove %d non-existent filters\n",
5440 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01005441}
5442
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005443static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5444{
5445 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5446 u8 mac_old[ETH_ALEN];
5447 int rc, rc2;
5448
5449 /* Only reconfigure a PF-created vport */
5450 if (is_zero_ether_addr(nic_data->vport_mac))
5451 return 0;
5452
5453 efx_device_detach_sync(efx);
5454 efx_net_stop(efx->net_dev);
5455 down_write(&efx->filter_sem);
5456 efx_ef10_filter_table_remove(efx);
5457 up_write(&efx->filter_sem);
5458
5459 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5460 if (rc)
5461 goto restore_filters;
5462
5463 ether_addr_copy(mac_old, nic_data->vport_mac);
5464 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5465 nic_data->vport_mac);
5466 if (rc)
5467 goto restore_vadaptor;
5468
5469 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5470 efx->net_dev->dev_addr);
5471 if (!rc) {
5472 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5473 } else {
5474 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5475 if (rc2) {
5476 /* Failed to add original MAC, so clear vport_mac */
5477 eth_zero_addr(nic_data->vport_mac);
5478 goto reset_nic;
5479 }
5480 }
5481
5482restore_vadaptor:
5483 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5484 if (rc2)
5485 goto reset_nic;
5486restore_filters:
5487 down_write(&efx->filter_sem);
5488 rc2 = efx_ef10_filter_table_probe(efx);
5489 up_write(&efx->filter_sem);
5490 if (rc2)
5491 goto reset_nic;
5492
5493 rc2 = efx_net_open(efx->net_dev);
5494 if (rc2)
5495 goto reset_nic;
5496
Peter Dunning9c568fd2017-02-17 15:50:43 +00005497 efx_device_attach_if_not_resetting(efx);
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005498
5499 return rc;
5500
5501reset_nic:
5502 netif_err(efx, drv, efx->net_dev,
5503 "Failed to restore when changing MAC address - scheduling reset\n");
5504 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5505
5506 return rc ? rc : rc2;
5507}
5508
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005509/* Caller must hold efx->filter_sem for read if race against
5510 * efx_ef10_filter_table_remove() is possible
5511 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005512static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5513 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005514{
5515 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005516 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005517
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005518 /* Do not install unspecified VID if VLAN filtering is enabled.
5519 * Do not install all specified VIDs if VLAN filtering is disabled.
5520 */
5521 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5522 return;
5523
Edward Cree12fb0da2015-07-21 15:11:00 +01005524 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005525 if (table->uc_promisc) {
Edward Cree9b410802017-01-27 15:02:52 +00005526 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5527 false, false);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005528 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005529 } else {
5530 /* If any of the filters failed to insert, fall back to
5531 * promiscuous mode - add in the uc_def filter. But keep
5532 * our individual unicast filters.
5533 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005534 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
Edward Cree9b410802017-01-27 15:02:52 +00005535 efx_ef10_filter_insert_def(efx, vlan,
5536 EFX_ENCAP_TYPE_NONE,
5537 false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005538 }
Edward Cree9b410802017-01-27 15:02:52 +00005539 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5540 false, false);
5541 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5542 EFX_ENCAP_FLAG_IPV6,
5543 false, false);
5544 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5545 false, false);
5546 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5547 EFX_ENCAP_FLAG_IPV6,
5548 false, false);
5549 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5550 false, false);
5551 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5552 EFX_ENCAP_FLAG_IPV6,
5553 false, false);
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005554
Edward Cree12fb0da2015-07-21 15:11:00 +01005555 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005556 /* If changing promiscuous state with cascaded multicast filters, remove
5557 * old filters first, so that packets are dropped rather than duplicated
5558 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005559 if (nic_data->workaround_26807 &&
5560 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005561 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005562 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005563 if (nic_data->workaround_26807) {
5564 /* If we failed to insert promiscuous filters, rollback
5565 * and fall back to individual multicast filters
5566 */
Edward Cree9b410802017-01-27 15:02:52 +00005567 if (efx_ef10_filter_insert_def(efx, vlan,
5568 EFX_ENCAP_TYPE_NONE,
5569 true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005570 /* Changing promisc state, so remove old filters */
5571 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005572 efx_ef10_filter_insert_addr_list(efx, vlan,
5573 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005574 }
5575 } else {
5576 /* If we failed to insert promiscuous filters, don't
Edward Cree148cbab2017-04-04 17:02:49 +01005577 * rollback. Regardless, also insert the mc_list,
5578 * unless it's incomplete due to overflow
Edward Cree12fb0da2015-07-21 15:11:00 +01005579 */
Edward Cree9b410802017-01-27 15:02:52 +00005580 efx_ef10_filter_insert_def(efx, vlan,
5581 EFX_ENCAP_TYPE_NONE,
5582 true, false);
Edward Cree148cbab2017-04-04 17:02:49 +01005583 if (!table->mc_overflow)
5584 efx_ef10_filter_insert_addr_list(efx, vlan,
5585 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005586 }
5587 } else {
5588 /* If any filters failed to insert, rollback and fall back to
5589 * promiscuous mode - mc_def filter and maybe broadcast. If
5590 * that fails, roll back again and insert as many of our
5591 * individual multicast filters as we can.
5592 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005593 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005594 /* Changing promisc state, so remove old filters */
5595 if (nic_data->workaround_26807)
5596 efx_ef10_filter_remove_old(efx);
Edward Cree9b410802017-01-27 15:02:52 +00005597 if (efx_ef10_filter_insert_def(efx, vlan,
5598 EFX_ENCAP_TYPE_NONE,
5599 true, true))
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005600 efx_ef10_filter_insert_addr_list(efx, vlan,
5601 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005602 }
5603 }
Edward Cree9b410802017-01-27 15:02:52 +00005604 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5605 true, false);
5606 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5607 EFX_ENCAP_FLAG_IPV6,
5608 true, false);
5609 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5610 true, false);
5611 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5612 EFX_ENCAP_FLAG_IPV6,
5613 true, false);
5614 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5615 true, false);
5616 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5617 EFX_ENCAP_FLAG_IPV6,
5618 true, false);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005619}
5620
5621/* Caller must hold efx->filter_sem for read if race against
5622 * efx_ef10_filter_table_remove() is possible
5623 */
5624static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5625{
5626 struct efx_ef10_filter_table *table = efx->filter_state;
5627 struct net_device *net_dev = efx->net_dev;
5628 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005629 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005630
5631 if (!efx_dev_registered(efx))
5632 return;
5633
5634 if (!table)
5635 return;
5636
5637 efx_ef10_filter_mark_old(efx);
5638
5639 /* Copy/convert the address lists; add the primary station
5640 * address and broadcast address
5641 */
5642 netif_addr_lock_bh(net_dev);
5643 efx_ef10_filter_uc_addr_list(efx);
5644 efx_ef10_filter_mc_addr_list(efx);
5645 netif_addr_unlock_bh(net_dev);
5646
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005647 /* If VLAN filtering changes, all old filters are finally removed.
5648 * Do it in advance to avoid conflicts for unicast untagged and
5649 * VLAN 0 tagged filters.
5650 */
5651 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5652 if (table->vlan_filter != vlan_filter) {
5653 table->vlan_filter = vlan_filter;
5654 efx_ef10_filter_remove_old(efx);
5655 }
5656
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005657 list_for_each_entry(vlan, &table->vlan_list, list)
5658 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005659
5660 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005661 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005662}
5663
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005664static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5665{
5666 struct efx_ef10_filter_table *table = efx->filter_state;
5667 struct efx_ef10_filter_vlan *vlan;
5668
5669 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5670
5671 list_for_each_entry(vlan, &table->vlan_list, list) {
5672 if (vlan->vid == vid)
5673 return vlan;
5674 }
5675
5676 return NULL;
5677}
5678
5679static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5680{
5681 struct efx_ef10_filter_table *table = efx->filter_state;
5682 struct efx_ef10_filter_vlan *vlan;
5683 unsigned int i;
5684
5685 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5686 return -EINVAL;
5687
5688 vlan = efx_ef10_filter_find_vlan(efx, vid);
5689 if (WARN_ON(vlan)) {
5690 netif_err(efx, drv, efx->net_dev,
5691 "VLAN %u already added\n", vid);
5692 return -EALREADY;
5693 }
5694
5695 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5696 if (!vlan)
5697 return -ENOMEM;
5698
5699 vlan->vid = vid;
5700
5701 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5702 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5703 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5704 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree9b410802017-01-27 15:02:52 +00005705 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5706 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005707
5708 list_add_tail(&vlan->list, &table->vlan_list);
5709
5710 if (efx_dev_registered(efx))
5711 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5712
5713 return 0;
5714}
5715
5716static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5717 struct efx_ef10_filter_vlan *vlan)
5718{
5719 unsigned int i;
5720
5721 /* See comment in efx_ef10_filter_table_remove() */
5722 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5723 return;
5724
5725 list_del(&vlan->list);
5726
Edward Cree8c915622016-06-15 17:49:05 +01005727 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005728 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005729 vlan->uc[i]);
5730 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005731 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005732 vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005733 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5734 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5735 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5736 vlan->default_filters[i]);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005737
5738 kfree(vlan);
5739}
5740
5741static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5742{
5743 struct efx_ef10_filter_vlan *vlan;
5744
5745 /* See comment in efx_ef10_filter_table_remove() */
5746 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5747 return;
5748
5749 vlan = efx_ef10_filter_find_vlan(efx, vid);
5750 if (!vlan) {
5751 netif_err(efx, drv, efx->net_dev,
5752 "VLAN %u not found in filter state\n", vid);
5753 return;
5754 }
5755
5756 efx_ef10_filter_del_vlan_internal(efx, vlan);
5757}
5758
Shradha Shah910c8782015-05-20 11:12:48 +01005759static int efx_ef10_set_mac_address(struct efx_nic *efx)
5760{
5761 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5762 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5763 bool was_enabled = efx->port_enabled;
5764 int rc;
5765
5766 efx_device_detach_sync(efx);
5767 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005768
5769 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005770 down_write(&efx->filter_sem);
5771 efx_ef10_filter_table_remove(efx);
5772
5773 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5774 efx->net_dev->dev_addr);
5775 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5776 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005777 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5778 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005779
5780 efx_ef10_filter_table_probe(efx);
5781 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005782 mutex_unlock(&efx->mac_lock);
5783
Shradha Shah910c8782015-05-20 11:12:48 +01005784 if (was_enabled)
5785 efx_net_open(efx->net_dev);
Peter Dunning9c568fd2017-02-17 15:50:43 +00005786 efx_device_attach_if_not_resetting(efx);
Shradha Shah910c8782015-05-20 11:12:48 +01005787
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005788#ifdef CONFIG_SFC_SRIOV
5789 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005790 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5791
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005792 if (rc == -EPERM) {
5793 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005794
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005795 /* Switch to PF and change MAC address on vport */
5796 efx_pf = pci_get_drvdata(pci_dev_pf);
5797
5798 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005799 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005800 efx->net_dev->dev_addr);
5801 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005802 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5803 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5804 unsigned int i;
5805
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005806 /* MAC address successfully changed by VF (with MAC
5807 * spoofing) so update the parent PF if possible.
5808 */
Shradha Shah910c8782015-05-20 11:12:48 +01005809 for (i = 0; i < efx_pf->vf_count; ++i) {
5810 struct ef10_vf *vf = nic_data->vf + i;
5811
5812 if (vf->efx == efx) {
5813 ether_addr_copy(vf->mac,
5814 efx->net_dev->dev_addr);
5815 return 0;
5816 }
5817 }
5818 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005819 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005820#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005821 if (rc == -EPERM) {
5822 netif_err(efx, drv, efx->net_dev,
5823 "Cannot change MAC address; use sfboot to enable"
5824 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005825 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5826 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5827 * fall-back to the method of changing the MAC address on the
5828 * vport. This only applies to PFs because such versions of
5829 * MCFW do not support VFs.
5830 */
5831 rc = efx_ef10_vport_set_mac_address(efx);
Robert Stonehousecbad52e2017-11-07 17:30:30 +00005832 } else if (rc) {
Daniel Pieczko535a6172015-07-07 11:37:33 +01005833 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5834 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005835 }
5836
Shradha Shah910c8782015-05-20 11:12:48 +01005837 return rc;
5838}
5839
Ben Hutchings8127d662013-08-29 19:19:29 +01005840static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5841{
5842 efx_ef10_filter_sync_rx_mode(efx);
5843
5844 return efx_mcdi_set_mac(efx);
5845}
5846
Shradha Shah862f8942015-05-20 11:08:56 +01005847static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5848{
5849 efx_ef10_filter_sync_rx_mode(efx);
5850
5851 return 0;
5852}
5853
Jon Cooper74cd60a2013-09-16 14:18:51 +01005854static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5855{
5856 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5857
5858 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5859 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5860 NULL, 0, NULL);
5861}
5862
5863/* MC BISTs follow a different poll mechanism to phy BISTs.
5864 * The BIST is done in the poll handler on the MC, and the MCDI command
5865 * will block until the BIST is done.
5866 */
5867static int efx_ef10_poll_bist(struct efx_nic *efx)
5868{
5869 int rc;
5870 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5871 size_t outlen;
5872 u32 result;
5873
5874 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5875 outbuf, sizeof(outbuf), &outlen);
5876 if (rc != 0)
5877 return rc;
5878
5879 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5880 return -EIO;
5881
5882 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5883 switch (result) {
5884 case MC_CMD_POLL_BIST_PASSED:
5885 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5886 return 0;
5887 case MC_CMD_POLL_BIST_TIMEOUT:
5888 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5889 return -EIO;
5890 case MC_CMD_POLL_BIST_FAILED:
5891 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5892 return -EIO;
5893 default:
5894 netif_err(efx, hw, efx->net_dev,
5895 "BIST returned unknown result %u", result);
5896 return -EIO;
5897 }
5898}
5899
5900static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5901{
5902 int rc;
5903
5904 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5905
5906 rc = efx_ef10_start_bist(efx, bist_type);
5907 if (rc != 0)
5908 return rc;
5909
5910 return efx_ef10_poll_bist(efx);
5911}
5912
5913static int
5914efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5915{
5916 int rc, rc2;
5917
5918 efx_reset_down(efx, RESET_TYPE_WORLD);
5919
5920 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5921 NULL, 0, NULL, 0, NULL);
5922 if (rc != 0)
5923 goto out;
5924
5925 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5926 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5927
5928 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5929
5930out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005931 if (rc == -EPERM)
5932 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005933 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5934 return rc ? rc : rc2;
5935}
5936
Ben Hutchings8127d662013-08-29 19:19:29 +01005937#ifdef CONFIG_SFC_MTD
5938
5939struct efx_ef10_nvram_type_info {
5940 u16 type, type_mask;
5941 u8 port;
5942 const char *name;
5943};
5944
5945static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5946 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5947 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5948 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5949 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5950 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5951 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5952 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5953 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5954 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005955 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005956 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5957};
5958
5959static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5960 struct efx_mcdi_mtd_partition *part,
5961 unsigned int type)
5962{
5963 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5964 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5965 const struct efx_ef10_nvram_type_info *info;
5966 size_t size, erase_size, outlen;
5967 bool protected;
5968 int rc;
5969
5970 for (info = efx_ef10_nvram_types; ; info++) {
5971 if (info ==
5972 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5973 return -ENODEV;
5974 if ((type & ~info->type_mask) == info->type)
5975 break;
5976 }
5977 if (info->port != efx_port_num(efx))
5978 return -ENODEV;
5979
5980 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5981 if (rc)
5982 return rc;
5983 if (protected)
5984 return -ENODEV; /* hide it */
5985
5986 part->nvram_type = type;
5987
5988 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5989 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5990 outbuf, sizeof(outbuf), &outlen);
5991 if (rc)
5992 return rc;
5993 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5994 return -EIO;
5995 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5996 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5997 part->fw_subtype = MCDI_DWORD(outbuf,
5998 NVRAM_METADATA_OUT_SUBTYPE);
5999
6000 part->common.dev_type_name = "EF10 NVRAM manager";
6001 part->common.type_name = info->name;
6002
6003 part->common.mtd.type = MTD_NORFLASH;
6004 part->common.mtd.flags = MTD_CAP_NORFLASH;
6005 part->common.mtd.size = size;
6006 part->common.mtd.erasesize = erase_size;
6007
6008 return 0;
6009}
6010
6011static int efx_ef10_mtd_probe(struct efx_nic *efx)
6012{
6013 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
6014 struct efx_mcdi_mtd_partition *parts;
6015 size_t outlen, n_parts_total, i, n_parts;
6016 unsigned int type;
6017 int rc;
6018
6019 ASSERT_RTNL();
6020
6021 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
6022 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
6023 outbuf, sizeof(outbuf), &outlen);
6024 if (rc)
6025 return rc;
6026 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
6027 return -EIO;
6028
6029 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
6030 if (n_parts_total >
6031 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
6032 return -EIO;
6033
6034 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
6035 if (!parts)
6036 return -ENOMEM;
6037
6038 n_parts = 0;
6039 for (i = 0; i < n_parts_total; i++) {
6040 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
6041 i);
6042 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
6043 if (rc == 0)
6044 n_parts++;
6045 else if (rc != -ENODEV)
6046 goto fail;
6047 }
6048
6049 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
6050fail:
6051 if (rc)
6052 kfree(parts);
6053 return rc;
6054}
6055
6056#endif /* CONFIG_SFC_MTD */
6057
6058static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
6059{
6060 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
6061}
6062
Shradha Shah02246a72015-05-06 00:58:14 +01006063static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
6064 u32 host_time) {}
6065
Jon Cooperbd9a2652013-11-18 12:54:41 +00006066static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
6067 bool temp)
6068{
6069 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
6070 int rc;
6071
6072 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
6073 channel->sync_events_state == SYNC_EVENTS_VALID ||
6074 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
6075 return 0;
6076 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
6077
6078 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
6079 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6080 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
6081 channel->channel);
6082
6083 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6084 inbuf, sizeof(inbuf), NULL, 0, NULL);
6085
6086 if (rc != 0)
6087 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6088 SYNC_EVENTS_DISABLED;
6089
6090 return rc;
6091}
6092
6093static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
6094 bool temp)
6095{
6096 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
6097 int rc;
6098
6099 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
6100 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
6101 return 0;
6102 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
6103 channel->sync_events_state = SYNC_EVENTS_DISABLED;
6104 return 0;
6105 }
6106 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6107 SYNC_EVENTS_DISABLED;
6108
6109 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
6110 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6111 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
6112 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
6113 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
6114 channel->channel);
6115
6116 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6117 inbuf, sizeof(inbuf), NULL, 0, NULL);
6118
6119 return rc;
6120}
6121
6122static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
6123 bool temp)
6124{
6125 int (*set)(struct efx_channel *channel, bool temp);
6126 struct efx_channel *channel;
6127
6128 set = en ?
6129 efx_ef10_rx_enable_timestamping :
6130 efx_ef10_rx_disable_timestamping;
6131
6132 efx_for_each_channel(channel, efx) {
6133 int rc = set(channel, temp);
6134 if (en && rc != 0) {
6135 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
6136 return rc;
6137 }
6138 }
6139
6140 return 0;
6141}
6142
Shradha Shah02246a72015-05-06 00:58:14 +01006143static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
6144 struct hwtstamp_config *init)
6145{
6146 return -EOPNOTSUPP;
6147}
6148
Jon Cooperbd9a2652013-11-18 12:54:41 +00006149static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
6150 struct hwtstamp_config *init)
6151{
6152 int rc;
6153
6154 switch (init->rx_filter) {
6155 case HWTSTAMP_FILTER_NONE:
6156 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
6157 /* if TX timestamping is still requested then leave PTP on */
6158 return efx_ptp_change_mode(efx,
6159 init->tx_type != HWTSTAMP_TX_OFF, 0);
6160 case HWTSTAMP_FILTER_ALL:
6161 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6162 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6163 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6164 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6165 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6166 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6167 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6168 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6169 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6170 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6171 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6172 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Miroslav Lichvare3412572017-05-19 17:52:36 +02006173 case HWTSTAMP_FILTER_NTP_ALL:
Jon Cooperbd9a2652013-11-18 12:54:41 +00006174 init->rx_filter = HWTSTAMP_FILTER_ALL;
6175 rc = efx_ptp_change_mode(efx, true, 0);
6176 if (!rc)
6177 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6178 if (rc)
6179 efx_ptp_change_mode(efx, false, 0);
6180 return rc;
6181 default:
6182 return -ERANGE;
6183 }
6184}
6185
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006186static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6187 struct netdev_phys_item_id *ppid)
6188{
6189 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6190
6191 if (!is_valid_ether_addr(nic_data->port_id))
6192 return -EOPNOTSUPP;
6193
6194 ppid->id_len = ETH_ALEN;
6195 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6196
6197 return 0;
6198}
6199
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006200static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6201{
6202 if (proto != htons(ETH_P_8021Q))
6203 return -EINVAL;
6204
6205 return efx_ef10_add_vlan(efx, vid);
6206}
6207
6208static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6209{
6210 if (proto != htons(ETH_P_8021Q))
6211 return -EINVAL;
6212
6213 return efx_ef10_del_vlan(efx, vid);
6214}
6215
Jon Coopere5fbd972017-02-08 16:52:10 +00006216/* We rely on the MCDI wiping out our TX rings if it made any changes to the
6217 * ports table, ensuring that any TSO descriptors that were made on a now-
6218 * removed tunnel port will be blown away and won't break things when we try
6219 * to transmit them using the new ports table.
6220 */
6221static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
6222{
6223 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6224 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
6225 MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
6226 bool will_reset = false;
6227 size_t num_entries = 0;
6228 size_t inlen, outlen;
6229 size_t i;
6230 int rc;
6231 efx_dword_t flags_and_num_entries;
6232
6233 WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
6234
6235 nic_data->udp_tunnels_dirty = false;
6236
6237 if (!(nic_data->datapath_caps &
6238 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
Peter Dunning9c568fd2017-02-17 15:50:43 +00006239 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006240 return 0;
6241 }
6242
6243 BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
6244 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
6245
6246 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6247 if (nic_data->udp_tunnels[i].count &&
6248 nic_data->udp_tunnels[i].port) {
6249 efx_dword_t entry;
6250
6251 EFX_POPULATE_DWORD_2(entry,
6252 TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
6253 ntohs(nic_data->udp_tunnels[i].port),
6254 TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
6255 nic_data->udp_tunnels[i].type);
6256 *_MCDI_ARRAY_DWORD(inbuf,
6257 SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
6258 num_entries++) = entry;
6259 }
6260 }
6261
6262 BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
6263 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
6264 EFX_WORD_1_LBN);
6265 BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
6266 EFX_WORD_1_WIDTH);
6267 EFX_POPULATE_DWORD_2(flags_and_num_entries,
6268 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
6269 !!unloading,
6270 EFX_WORD_1, num_entries);
6271 *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
6272 flags_and_num_entries;
6273
6274 inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
6275
6276 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
6277 inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
6278 if (rc == -EIO) {
6279 /* Most likely the MC rebooted due to another function also
6280 * setting its tunnel port list. Mark the tunnel port list as
6281 * dirty, so it will be pushed upon coming up from the reboot.
6282 */
6283 nic_data->udp_tunnels_dirty = true;
6284 return 0;
6285 }
6286
6287 if (rc) {
6288 /* expected not available on unprivileged functions */
6289 if (rc != -EPERM)
6290 netif_warn(efx, drv, efx->net_dev,
6291 "Unable to set UDP tunnel ports; rc=%d.\n", rc);
6292 } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
6293 (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
6294 netif_info(efx, drv, efx->net_dev,
6295 "Rebooting MC due to UDP tunnel port list change\n");
6296 will_reset = true;
6297 if (unloading)
6298 /* Delay for the MC reset to complete. This will make
6299 * unloading other functions a bit smoother. This is a
6300 * race, but the other unload will work whichever way
6301 * it goes, this just avoids an unnecessary error
6302 * message.
6303 */
6304 msleep(100);
6305 }
6306 if (!will_reset && !unloading) {
6307 /* The caller will have detached, relying on the MC reset to
6308 * trigger a re-attach. Since there won't be an MC reset, we
6309 * have to do the attach ourselves.
6310 */
Peter Dunning9c568fd2017-02-17 15:50:43 +00006311 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006312 }
6313
6314 return rc;
6315}
6316
6317static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
6318{
6319 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6320 int rc = 0;
6321
6322 mutex_lock(&nic_data->udp_tunnels_lock);
6323 if (nic_data->udp_tunnels_dirty) {
6324 /* Make sure all TX are stopped while we modify the table, else
6325 * we might race against an efx_features_check().
6326 */
6327 efx_device_detach_sync(efx);
6328 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6329 }
6330 mutex_unlock(&nic_data->udp_tunnels_lock);
6331 return rc;
6332}
6333
6334static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
6335 __be16 port)
6336{
6337 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6338 size_t i;
6339
6340 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6341 if (!nic_data->udp_tunnels[i].count)
6342 continue;
6343 if (nic_data->udp_tunnels[i].port == port)
6344 return &nic_data->udp_tunnels[i];
6345 }
6346 return NULL;
6347}
6348
6349static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
6350 struct efx_udp_tunnel tnl)
6351{
6352 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6353 struct efx_udp_tunnel *match;
6354 char typebuf[8];
6355 size_t i;
6356 int rc;
6357
6358 if (!(nic_data->datapath_caps &
6359 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6360 return 0;
6361
6362 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6363 netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
6364 typebuf, ntohs(tnl.port));
6365
6366 mutex_lock(&nic_data->udp_tunnels_lock);
6367 /* Make sure all TX are stopped while we add to the table, else we
6368 * might race against an efx_features_check().
6369 */
6370 efx_device_detach_sync(efx);
6371
6372 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6373 if (match != NULL) {
6374 if (match->type == tnl.type) {
6375 netif_dbg(efx, drv, efx->net_dev,
6376 "Referencing existing tunnel entry\n");
6377 match->count++;
6378 /* No need to cause an MCDI update */
6379 rc = 0;
6380 goto unlock_out;
6381 }
6382 efx_get_udp_tunnel_type_name(match->type,
6383 typebuf, sizeof(typebuf));
6384 netif_dbg(efx, drv, efx->net_dev,
6385 "UDP port %d is already in use by %s\n",
6386 ntohs(tnl.port), typebuf);
6387 rc = -EEXIST;
6388 goto unlock_out;
6389 }
6390
6391 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
6392 if (!nic_data->udp_tunnels[i].count) {
6393 nic_data->udp_tunnels[i] = tnl;
6394 nic_data->udp_tunnels[i].count = 1;
6395 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6396 goto unlock_out;
6397 }
6398
6399 netif_dbg(efx, drv, efx->net_dev,
6400 "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
6401 typebuf, ntohs(tnl.port));
6402
6403 rc = -ENOMEM;
6404
6405unlock_out:
6406 mutex_unlock(&nic_data->udp_tunnels_lock);
6407 return rc;
6408}
6409
6410/* Called under the TX lock with the TX queue running, hence no-one can be
6411 * in the middle of updating the UDP tunnels table. However, they could
6412 * have tried and failed the MCDI, in which case they'll have set the dirty
6413 * flag before dropping their locks.
6414 */
6415static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
6416{
6417 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6418
6419 if (!(nic_data->datapath_caps &
6420 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6421 return false;
6422
6423 if (nic_data->udp_tunnels_dirty)
6424 /* SW table may not match HW state, so just assume we can't
6425 * use any UDP tunnel offloads.
6426 */
6427 return false;
6428
6429 return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
6430}
6431
6432static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
6433 struct efx_udp_tunnel tnl)
6434{
6435 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6436 struct efx_udp_tunnel *match;
6437 char typebuf[8];
6438 int rc;
6439
6440 if (!(nic_data->datapath_caps &
6441 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6442 return 0;
6443
6444 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6445 netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
6446 typebuf, ntohs(tnl.port));
6447
6448 mutex_lock(&nic_data->udp_tunnels_lock);
6449 /* Make sure all TX are stopped while we remove from the table, else we
6450 * might race against an efx_features_check().
6451 */
6452 efx_device_detach_sync(efx);
6453
6454 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6455 if (match != NULL) {
6456 if (match->type == tnl.type) {
6457 if (--match->count) {
6458 /* Port is still in use, so nothing to do */
6459 netif_dbg(efx, drv, efx->net_dev,
6460 "UDP tunnel port %d remains active\n",
6461 ntohs(tnl.port));
6462 rc = 0;
6463 goto out_unlock;
6464 }
6465 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6466 goto out_unlock;
6467 }
6468 efx_get_udp_tunnel_type_name(match->type,
6469 typebuf, sizeof(typebuf));
6470 netif_warn(efx, drv, efx->net_dev,
6471 "UDP port %d is actually in use by %s, not removing\n",
6472 ntohs(tnl.port), typebuf);
6473 }
6474 rc = -ENOENT;
6475
6476out_unlock:
6477 mutex_unlock(&nic_data->udp_tunnels_lock);
6478 return rc;
6479}
6480
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006481#define EF10_OFFLOAD_FEATURES \
6482 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006483 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006484 NETIF_F_IPV6_CSUM | \
6485 NETIF_F_RXHASH | \
6486 NETIF_F_NTUPLE)
6487
Shradha Shah02246a72015-05-06 00:58:14 +01006488const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006489 .is_vf = true,
Edward Cree03714bb2017-12-18 16:55:50 +00006490 .mem_bar = efx_ef10_vf_mem_bar,
Ben Hutchings8127d662013-08-29 19:19:29 +01006491 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01006492 .probe = efx_ef10_probe_vf,
6493 .remove = efx_ef10_remove,
6494 .dimension_resources = efx_ef10_dimension_resources,
6495 .init = efx_ef10_init_nic,
6496 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006497 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01006498 .map_reset_flags = efx_ef10_map_reset_flags,
6499 .reset = efx_ef10_reset,
6500 .probe_port = efx_mcdi_port_probe,
6501 .remove_port = efx_mcdi_port_remove,
6502 .fini_dmaq = efx_ef10_fini_dmaq,
6503 .prepare_flr = efx_ef10_prepare_flr,
6504 .finish_flr = efx_port_dummy_op_void,
6505 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006506 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006507 .start_stats = efx_port_dummy_op_void,
6508 .pull_stats = efx_port_dummy_op_void,
6509 .stop_stats = efx_port_dummy_op_void,
6510 .set_id_led = efx_mcdi_set_id_led,
6511 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01006512 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006513 .check_mac_fault = efx_mcdi_mac_check_fault,
6514 .reconfigure_port = efx_mcdi_port_reconfigure,
6515 .get_wol = efx_ef10_get_wol_vf,
6516 .set_wol = efx_ef10_set_wol_vf,
6517 .resume_wol = efx_port_dummy_op_void,
6518 .mcdi_request = efx_ef10_mcdi_request,
6519 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6520 .mcdi_read_response = efx_ef10_mcdi_read_response,
6521 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006522 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01006523 .irq_enable_master = efx_port_dummy_op_void,
6524 .irq_test_generate = efx_ef10_irq_test_generate,
6525 .irq_disable_non_ev = efx_port_dummy_op_void,
6526 .irq_handle_msi = efx_ef10_msi_interrupt,
6527 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6528 .tx_probe = efx_ef10_tx_probe,
6529 .tx_init = efx_ef10_tx_init,
6530 .tx_remove = efx_ef10_tx_remove,
6531 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006532 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006533 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006534 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01006535 .rx_probe = efx_ef10_rx_probe,
6536 .rx_init = efx_ef10_rx_init,
6537 .rx_remove = efx_ef10_rx_remove,
6538 .rx_write = efx_ef10_rx_write,
6539 .rx_defer_refill = efx_ef10_rx_defer_refill,
6540 .ev_probe = efx_ef10_ev_probe,
6541 .ev_init = efx_ef10_ev_init,
6542 .ev_fini = efx_ef10_ev_fini,
6543 .ev_remove = efx_ef10_ev_remove,
6544 .ev_process = efx_ef10_ev_process,
6545 .ev_read_ack = efx_ef10_ev_read_ack,
6546 .ev_test_generate = efx_ef10_ev_test_generate,
6547 .filter_table_probe = efx_ef10_filter_table_probe,
6548 .filter_table_restore = efx_ef10_filter_table_restore,
6549 .filter_table_remove = efx_ef10_filter_table_remove,
6550 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6551 .filter_insert = efx_ef10_filter_insert,
6552 .filter_remove_safe = efx_ef10_filter_remove_safe,
6553 .filter_get_safe = efx_ef10_filter_get_safe,
6554 .filter_clear_rx = efx_ef10_filter_clear_rx,
6555 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6556 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6557 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6558#ifdef CONFIG_RFS_ACCEL
6559 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6560 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6561#endif
6562#ifdef CONFIG_SFC_MTD
6563 .mtd_probe = efx_port_dummy_op_int,
6564#endif
6565 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6566 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006567 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6568 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01006569#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006570 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6571 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6572 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006573#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006574 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01006575 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006576
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006577 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01006578 .revision = EFX_REV_HUNT_A0,
6579 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6580 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6581 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6582 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6583 .can_rx_scatter = true,
6584 .always_rx_scatter = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006585 .min_interrupt_mode = EFX_INT_MODE_MSIX,
Shradha Shah02246a72015-05-06 00:58:14 +01006586 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6587 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006588 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01006589 .mcdi_max_ver = 2,
6590 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6591 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6592 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006593 .rx_hash_key_size = 40,
Shradha Shah02246a72015-05-06 00:58:14 +01006594};
6595
6596const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006597 .is_vf = false,
Edward Cree03714bb2017-12-18 16:55:50 +00006598 .mem_bar = efx_ef10_pf_mem_bar,
Shradha Shah02246a72015-05-06 00:58:14 +01006599 .mem_map_size = efx_ef10_mem_map_size,
6600 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006601 .remove = efx_ef10_remove,
6602 .dimension_resources = efx_ef10_dimension_resources,
6603 .init = efx_ef10_init_nic,
6604 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006605 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01006606 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00006607 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01006608 .probe_port = efx_mcdi_port_probe,
6609 .remove_port = efx_mcdi_port_remove,
6610 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01006611 .prepare_flr = efx_ef10_prepare_flr,
6612 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01006613 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006614 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006615 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01006616 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01006617 .stop_stats = efx_mcdi_mac_stop_stats,
6618 .set_id_led = efx_mcdi_set_id_led,
6619 .push_irq_moderation = efx_ef10_push_irq_moderation,
6620 .reconfigure_mac = efx_ef10_mac_reconfigure,
6621 .check_mac_fault = efx_mcdi_mac_check_fault,
6622 .reconfigure_port = efx_mcdi_port_reconfigure,
6623 .get_wol = efx_ef10_get_wol,
6624 .set_wol = efx_ef10_set_wol,
6625 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01006626 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01006627 .test_nvram = efx_mcdi_nvram_test_all,
6628 .mcdi_request = efx_ef10_mcdi_request,
6629 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6630 .mcdi_read_response = efx_ef10_mcdi_read_response,
6631 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006632 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01006633 .irq_enable_master = efx_port_dummy_op_void,
6634 .irq_test_generate = efx_ef10_irq_test_generate,
6635 .irq_disable_non_ev = efx_port_dummy_op_void,
6636 .irq_handle_msi = efx_ef10_msi_interrupt,
6637 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6638 .tx_probe = efx_ef10_tx_probe,
6639 .tx_init = efx_ef10_tx_init,
6640 .tx_remove = efx_ef10_tx_remove,
6641 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006642 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006643 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006644 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01006645 .rx_probe = efx_ef10_rx_probe,
6646 .rx_init = efx_ef10_rx_init,
6647 .rx_remove = efx_ef10_rx_remove,
6648 .rx_write = efx_ef10_rx_write,
6649 .rx_defer_refill = efx_ef10_rx_defer_refill,
6650 .ev_probe = efx_ef10_ev_probe,
6651 .ev_init = efx_ef10_ev_init,
6652 .ev_fini = efx_ef10_ev_fini,
6653 .ev_remove = efx_ef10_ev_remove,
6654 .ev_process = efx_ef10_ev_process,
6655 .ev_read_ack = efx_ef10_ev_read_ack,
6656 .ev_test_generate = efx_ef10_ev_test_generate,
6657 .filter_table_probe = efx_ef10_filter_table_probe,
6658 .filter_table_restore = efx_ef10_filter_table_restore,
6659 .filter_table_remove = efx_ef10_filter_table_remove,
6660 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6661 .filter_insert = efx_ef10_filter_insert,
6662 .filter_remove_safe = efx_ef10_filter_remove_safe,
6663 .filter_get_safe = efx_ef10_filter_get_safe,
6664 .filter_clear_rx = efx_ef10_filter_clear_rx,
6665 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6666 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6667 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6668#ifdef CONFIG_RFS_ACCEL
6669 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6670 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6671#endif
6672#ifdef CONFIG_SFC_MTD
6673 .mtd_probe = efx_ef10_mtd_probe,
6674 .mtd_rename = efx_mcdi_mtd_rename,
6675 .mtd_read = efx_mcdi_mtd_read,
6676 .mtd_erase = efx_mcdi_mtd_erase,
6677 .mtd_write = efx_mcdi_mtd_write,
6678 .mtd_sync = efx_mcdi_mtd_sync,
6679#endif
6680 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006681 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6682 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006683 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6684 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Jon Coopere5fbd972017-02-08 16:52:10 +00006685 .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
6686 .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
6687 .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
6688 .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006689#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01006690 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006691 .sriov_init = efx_ef10_sriov_init,
6692 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006693 .sriov_wanted = efx_ef10_sriov_wanted,
6694 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006695 .sriov_flr = efx_ef10_sriov_flr,
6696 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6697 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6698 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6699 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01006700 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006701 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6702 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6703 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006704#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006705 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01006706 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00006707 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01006708
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006709 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01006710 .revision = EFX_REV_HUNT_A0,
6711 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6712 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6713 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006714 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01006715 .can_rx_scatter = true,
6716 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00006717 .option_descriptors = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006718 .min_interrupt_mode = EFX_INT_MODE_LEGACY,
Ben Hutchings8127d662013-08-29 19:19:29 +01006719 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6720 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006721 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01006722 .mcdi_max_ver = 2,
6723 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006724 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6725 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006726 .rx_hash_key_size = 40,
Ben Hutchings8127d662013-08-29 19:19:29 +01006727};