blob: bcbaba330fb5cfde1a5041f634bde0c85f19f9f1 [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};
Jon Cooper267c0152015-05-06 00:59:38 +010031/* The maximum size of a shared RSS context */
32/* TODO: this should really be from the mcdi protocol export */
33#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
Ben Hutchings8127d662013-08-29 19:19:29 +010034
35/* The filter table(s) are managed by firmware and we have write-only
36 * access. When removing filters we must identify them to the
37 * firmware by a 64-bit handle, but this is too wide for Linux kernel
38 * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
39 * be able to tell in advance whether a requested insertion will
40 * replace an existing filter. Therefore we maintain a software hash
41 * table, which should be at least as large as the hardware hash
42 * table.
43 *
44 * Huntington has a single 8K filter table shared between all filter
45 * types and both ports.
46 */
47#define HUNT_FILTER_TBL_ROWS 8192
48
Edward Cree12fb0da2015-07-21 15:11:00 +010049#define EFX_EF10_FILTER_ID_INVALID 0xffff
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010050
51#define EFX_EF10_FILTER_DEV_UC_MAX 32
52#define EFX_EF10_FILTER_DEV_MC_MAX 256
53
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010054/* VLAN list entry */
55struct efx_ef10_vlan {
56 struct list_head list;
57 u16 vid;
58};
59
Edward Cree9b410802017-01-27 15:02:52 +000060enum efx_ef10_default_filters {
61 EFX_EF10_BCAST,
62 EFX_EF10_UCDEF,
63 EFX_EF10_MCDEF,
64 EFX_EF10_VXLAN4_UCDEF,
65 EFX_EF10_VXLAN4_MCDEF,
66 EFX_EF10_VXLAN6_UCDEF,
67 EFX_EF10_VXLAN6_MCDEF,
68 EFX_EF10_NVGRE4_UCDEF,
69 EFX_EF10_NVGRE4_MCDEF,
70 EFX_EF10_NVGRE6_UCDEF,
71 EFX_EF10_NVGRE6_MCDEF,
72 EFX_EF10_GENEVE4_UCDEF,
73 EFX_EF10_GENEVE4_MCDEF,
74 EFX_EF10_GENEVE6_UCDEF,
75 EFX_EF10_GENEVE6_MCDEF,
76
77 EFX_EF10_NUM_DEFAULT_FILTERS
78};
79
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010080/* Per-VLAN filters information */
81struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010082 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010083 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010084 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
85 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree9b410802017-01-27 15:02:52 +000086 u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS];
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010087};
88
Daniel Pieczko822b96f2015-07-21 15:10:27 +010089struct efx_ef10_dev_addr {
90 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010091};
92
Ben Hutchings8127d662013-08-29 19:19:29 +010093struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010094/* The MCDI match masks supported by this fw & hw, in order of priority */
95 u32 rx_match_mcdi_flags[
Edward Cree9b410802017-01-27 15:02:52 +000096 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
Ben Hutchings8127d662013-08-29 19:19:29 +010097 unsigned int rx_match_count;
98
99 struct {
100 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000101/* BUSY flag indicates that an update is in progress. AUTO_OLD is
102 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +0100103 */
104#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000105#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +0100106#define EFX_EF10_FILTER_FLAGS 3UL
107 u64 handle; /* firmware handle */
108 } *entry;
109 wait_queue_head_t waitq;
110/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +0100111 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
112 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +0100113 int dev_uc_count;
114 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100115 bool uc_promisc;
116 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100117/* Whether in multicast promiscuous mode when last changed */
118 bool mc_promisc_last;
Edward Cree148cbab2017-04-04 17:02:49 +0100119 bool mc_overflow; /* Too many MC addrs; should always imply mc_promisc */
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100120 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100121 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100122};
123
124/* An arbitrary search limit for the software hash table */
125#define EFX_EF10_FILTER_SEARCH_LIMIT 200
126
Ben Hutchings8127d662013-08-29 19:19:29 +0100127static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
128static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100129static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
130static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
131 struct efx_ef10_filter_vlan *vlan);
132static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Jon Coopere5fbd972017-02-08 16:52:10 +0000133static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading);
Ben Hutchings8127d662013-08-29 19:19:29 +0100134
Jon Cooper0ccb9982017-02-17 15:49:13 +0000135static u32 efx_ef10_filter_get_unsafe_id(u32 filter_id)
136{
137 WARN_ON_ONCE(filter_id == EFX_EF10_FILTER_ID_INVALID);
138 return filter_id & (HUNT_FILTER_TBL_ROWS - 1);
139}
140
141static unsigned int efx_ef10_filter_get_unsafe_pri(u32 filter_id)
142{
143 return filter_id / (HUNT_FILTER_TBL_ROWS * 2);
144}
145
146static u32 efx_ef10_make_filter_id(unsigned int pri, u16 idx)
147{
148 return pri * HUNT_FILTER_TBL_ROWS * 2 + idx;
149}
150
Ben Hutchings8127d662013-08-29 19:19:29 +0100151static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
152{
153 efx_dword_t reg;
154
155 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
156 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
157 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
158}
159
Edward Cree03714bb2017-12-18 16:55:50 +0000160/* On all EF10s up to and including SFC9220 (Medford1), all PFs use BAR 0 for
161 * I/O space and BAR 2(&3) for memory. On SFC9250 (Medford2), there is no I/O
162 * bar; PFs use BAR 0/1 for memory.
163 */
164static unsigned int efx_ef10_pf_mem_bar(struct efx_nic *efx)
165{
166 switch (efx->pci_dev->device) {
167 case 0x0b03: /* SFC9250 PF */
168 return 0;
169 default:
170 return 2;
171 }
172}
173
174/* All VFs use BAR 0/1 for memory */
175static unsigned int efx_ef10_vf_mem_bar(struct efx_nic *efx)
176{
177 return 0;
178}
179
Ben Hutchings8127d662013-08-29 19:19:29 +0100180static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
181{
Shradha Shah02246a72015-05-06 00:58:14 +0100182 int bar;
183
Edward Cree03714bb2017-12-18 16:55:50 +0000184 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +0100185 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100186}
187
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100188static bool efx_ef10_is_vf(struct efx_nic *efx)
189{
190 return efx->type->is_vf;
191}
192
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100193static int efx_ef10_get_pf_index(struct efx_nic *efx)
194{
195 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
196 struct efx_ef10_nic_data *nic_data = efx->nic_data;
197 size_t outlen;
198 int rc;
199
200 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
201 sizeof(outbuf), &outlen);
202 if (rc)
203 return rc;
204 if (outlen < sizeof(outbuf))
205 return -EIO;
206
207 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
208 return 0;
209}
210
Shradha Shah88a37de2015-05-20 11:09:15 +0100211#ifdef CONFIG_SFC_SRIOV
212static int efx_ef10_get_vf_index(struct efx_nic *efx)
213{
214 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
215 struct efx_ef10_nic_data *nic_data = efx->nic_data;
216 size_t outlen;
217 int rc;
218
219 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
220 sizeof(outbuf), &outlen);
221 if (rc)
222 return rc;
223 if (outlen < sizeof(outbuf))
224 return -EIO;
225
226 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
227 return 0;
228}
229#endif
230
Ben Hutchingse5a25382013-09-05 22:50:59 +0100231static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100232{
Edward Creec1be4822017-12-21 09:00:26 +0000233 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +0100234 struct efx_ef10_nic_data *nic_data = efx->nic_data;
235 size_t outlen;
236 int rc;
237
238 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
239
240 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
241 outbuf, sizeof(outbuf), &outlen);
242 if (rc)
243 return rc;
Bert Kenwardca889a02016-08-11 13:01:35 +0100244 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
Ben Hutchingse5a25382013-09-05 22:50:59 +0100245 netif_err(efx, drv, efx->net_dev,
246 "unable to read datapath firmware capabilities\n");
247 return -EIO;
248 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100249
Ben Hutchingse5a25382013-09-05 22:50:59 +0100250 nic_data->datapath_caps =
251 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
252
Edward Creec6347002017-01-13 21:20:29 +0000253 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
Bert Kenwardca889a02016-08-11 13:01:35 +0100254 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
255 GET_CAPABILITIES_V2_OUT_FLAGS2);
Edward Creec6347002017-01-13 21:20:29 +0000256 nic_data->piobuf_size = MCDI_WORD(outbuf,
257 GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
258 } else {
Bert Kenwardca889a02016-08-11 13:01:35 +0100259 nic_data->datapath_caps2 = 0;
Edward Creec6347002017-01-13 21:20:29 +0000260 nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
261 }
Bert Kenwardca889a02016-08-11 13:01:35 +0100262
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100263 /* record the DPCPU firmware IDs to determine VEB vswitching support.
264 */
265 nic_data->rx_dpcpu_fw_id =
266 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
267 nic_data->tx_dpcpu_fw_id =
268 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
269
Ben Hutchingse5a25382013-09-05 22:50:59 +0100270 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100271 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
272 netif_err(efx, probe, efx->net_dev,
273 "current firmware does not support an RX prefix\n");
274 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100275 }
276
Edward Cree71827442017-12-18 16:56:19 +0000277 if (outlen >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
278 u8 vi_window_mode = MCDI_BYTE(outbuf,
279 GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
280
281 switch (vi_window_mode) {
282 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
283 efx->vi_stride = 8192;
284 break;
285 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
286 efx->vi_stride = 16384;
287 break;
288 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
289 efx->vi_stride = 65536;
290 break;
291 default:
292 netif_err(efx, probe, efx->net_dev,
293 "Unrecognised VI window mode %d\n",
294 vi_window_mode);
295 return -EIO;
296 }
297 netif_dbg(efx, probe, efx->net_dev, "vi_stride = %u\n",
298 efx->vi_stride);
299 } else {
300 /* keep default VI stride */
301 netif_dbg(efx, probe, efx->net_dev,
302 "firmware did not report VI window mode, assuming vi_stride = %u\n",
303 efx->vi_stride);
304 }
305
Edward Creec1be4822017-12-21 09:00:26 +0000306 if (outlen >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
307 efx->num_mac_stats = MCDI_WORD(outbuf,
308 GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
309 netif_dbg(efx, probe, efx->net_dev,
310 "firmware reports num_mac_stats = %u\n",
311 efx->num_mac_stats);
312 } else {
313 /* leave num_mac_stats as the default value, MC_CMD_MAC_NSTATS */
314 netif_dbg(efx, probe, efx->net_dev,
315 "firmware did not report num_mac_stats, assuming %u\n",
316 efx->num_mac_stats);
317 }
318
Ben Hutchings8127d662013-08-29 19:19:29 +0100319 return 0;
320}
321
Martin Habets50663fe2018-01-25 17:25:33 +0000322static void efx_ef10_read_licensed_features(struct efx_nic *efx)
323{
324 MCDI_DECLARE_BUF(inbuf, MC_CMD_LICENSING_V3_IN_LEN);
325 MCDI_DECLARE_BUF(outbuf, MC_CMD_LICENSING_V3_OUT_LEN);
326 struct efx_ef10_nic_data *nic_data = efx->nic_data;
327 size_t outlen;
328 int rc;
329
330 MCDI_SET_DWORD(inbuf, LICENSING_V3_IN_OP,
331 MC_CMD_LICENSING_V3_IN_OP_REPORT_LICENSE);
332 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_LICENSING_V3, inbuf, sizeof(inbuf),
333 outbuf, sizeof(outbuf), &outlen);
334 if (rc || (outlen < MC_CMD_LICENSING_V3_OUT_LEN))
335 return;
336
337 nic_data->licensed_features = MCDI_QWORD(outbuf,
338 LICENSING_V3_OUT_LICENSED_FEATURES);
339}
340
Ben Hutchings8127d662013-08-29 19:19:29 +0100341static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
342{
343 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
344 int rc;
345
346 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
347 outbuf, sizeof(outbuf), NULL);
348 if (rc)
349 return rc;
350 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
351 return rc > 0 ? rc : -ERANGE;
352}
353
Bert Kenwardd95e3292016-08-11 13:02:36 +0100354static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
355{
356 struct efx_ef10_nic_data *nic_data = efx->nic_data;
357 unsigned int implemented;
358 unsigned int enabled;
359 int rc;
360
361 nic_data->workaround_35388 = false;
362 nic_data->workaround_61265 = false;
363
364 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
365
366 if (rc == -ENOSYS) {
367 /* Firmware without GET_WORKAROUNDS - not a problem. */
368 rc = 0;
369 } else if (rc == 0) {
370 /* Bug61265 workaround is always enabled if implemented. */
371 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
372 nic_data->workaround_61265 = true;
373
374 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
375 nic_data->workaround_35388 = true;
376 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
377 /* Workaround is implemented but not enabled.
378 * Try to enable it.
379 */
380 rc = efx_mcdi_set_workaround(efx,
381 MC_CMD_WORKAROUND_BUG35388,
382 true, NULL);
383 if (rc == 0)
384 nic_data->workaround_35388 = true;
385 /* If we failed to set the workaround just carry on. */
386 rc = 0;
387 }
388 }
389
390 netif_dbg(efx, probe, efx->net_dev,
391 "workaround for bug 35388 is %sabled\n",
392 nic_data->workaround_35388 ? "en" : "dis");
393 netif_dbg(efx, probe, efx->net_dev,
394 "workaround for bug 61265 is %sabled\n",
395 nic_data->workaround_61265 ? "en" : "dis");
396
397 return rc;
398}
399
400static void efx_ef10_process_timer_config(struct efx_nic *efx,
401 const efx_dword_t *data)
402{
403 unsigned int max_count;
404
405 if (EFX_EF10_WORKAROUND_61265(efx)) {
406 efx->timer_quantum_ns = MCDI_DWORD(data,
407 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
408 efx->timer_max_ns = MCDI_DWORD(data,
409 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
410 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
411 efx->timer_quantum_ns = MCDI_DWORD(data,
412 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
413 max_count = MCDI_DWORD(data,
414 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
415 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
416 } else {
417 efx->timer_quantum_ns = MCDI_DWORD(data,
418 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
419 max_count = MCDI_DWORD(data,
420 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
421 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
422 }
423
424 netif_dbg(efx, probe, efx->net_dev,
425 "got timer properties from MC: quantum %u ns; max %u ns\n",
426 efx->timer_quantum_ns, efx->timer_max_ns);
427}
428
429static int efx_ef10_get_timer_config(struct efx_nic *efx)
430{
431 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
432 int rc;
433
434 rc = efx_ef10_get_timer_workarounds(efx);
435 if (rc)
436 return rc;
437
438 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
439 outbuf, sizeof(outbuf), NULL);
440
441 if (rc == 0) {
442 efx_ef10_process_timer_config(efx, outbuf);
443 } else if (rc == -ENOSYS || rc == -EPERM) {
444 /* Not available - fall back to Huntington defaults. */
445 unsigned int quantum;
446
447 rc = efx_ef10_get_sysclk_freq(efx);
448 if (rc < 0)
449 return rc;
450
451 quantum = 1536000 / rc; /* 1536 cycles */
452 efx->timer_quantum_ns = quantum;
453 efx->timer_max_ns = efx->type->timer_period_max * quantum;
454 rc = 0;
455 } else {
456 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
457 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
458 NULL, 0, rc);
459 }
460
461 return rc;
462}
463
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100464static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100465{
466 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
467 size_t outlen;
468 int rc;
469
470 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
471
472 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
473 outbuf, sizeof(outbuf), &outlen);
474 if (rc)
475 return rc;
476 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
477 return -EIO;
478
Edward Creecd84ff42014-03-07 18:27:41 +0000479 ether_addr_copy(mac_address,
480 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100481 return 0;
482}
483
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100484static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
485{
486 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
487 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
488 size_t outlen;
489 int num_addrs, rc;
490
491 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
492 EVB_PORT_ID_ASSIGNED);
493 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
494 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
495
496 if (rc)
497 return rc;
498 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
499 return -EIO;
500
501 num_addrs = MCDI_DWORD(outbuf,
502 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
503
504 WARN_ON(num_addrs != 1);
505
506 ether_addr_copy(mac_address,
507 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
508
509 return 0;
510}
511
Shradha Shah0f5c0842015-06-02 11:37:58 +0100512static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
513 struct device_attribute *attr,
514 char *buf)
515{
516 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
517
518 return sprintf(buf, "%d\n",
519 ((efx->mcdi->fn_flags) &
520 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
521 ? 1 : 0);
522}
523
524static ssize_t efx_ef10_show_primary_flag(struct device *dev,
525 struct device_attribute *attr,
526 char *buf)
527{
528 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
529
530 return sprintf(buf, "%d\n",
531 ((efx->mcdi->fn_flags) &
532 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
533 ? 1 : 0);
534}
535
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100536static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
537{
538 struct efx_ef10_nic_data *nic_data = efx->nic_data;
539 struct efx_ef10_vlan *vlan;
540
541 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
542
543 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
544 if (vlan->vid == vid)
545 return vlan;
546 }
547
548 return NULL;
549}
550
551static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
552{
553 struct efx_ef10_nic_data *nic_data = efx->nic_data;
554 struct efx_ef10_vlan *vlan;
555 int rc;
556
557 mutex_lock(&nic_data->vlan_lock);
558
559 vlan = efx_ef10_find_vlan(efx, vid);
560 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100561 /* We add VID 0 on init. 8021q adds it on module init
562 * for all interfaces with VLAN filtring feature.
563 */
564 if (vid == 0)
565 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100566 netif_warn(efx, drv, efx->net_dev,
567 "VLAN %u already added\n", vid);
568 rc = -EALREADY;
569 goto fail_exist;
570 }
571
572 rc = -ENOMEM;
573 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
574 if (!vlan)
575 goto fail_alloc;
576
577 vlan->vid = vid;
578
579 list_add_tail(&vlan->list, &nic_data->vlan_list);
580
581 if (efx->filter_state) {
582 mutex_lock(&efx->mac_lock);
583 down_write(&efx->filter_sem);
584 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
585 up_write(&efx->filter_sem);
586 mutex_unlock(&efx->mac_lock);
587 if (rc)
588 goto fail_filter_add_vlan;
589 }
590
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100591done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100592 mutex_unlock(&nic_data->vlan_lock);
593 return 0;
594
595fail_filter_add_vlan:
596 list_del(&vlan->list);
597 kfree(vlan);
598fail_alloc:
599fail_exist:
600 mutex_unlock(&nic_data->vlan_lock);
601 return rc;
602}
603
604static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
605 struct efx_ef10_vlan *vlan)
606{
607 struct efx_ef10_nic_data *nic_data = efx->nic_data;
608
609 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
610
611 if (efx->filter_state) {
612 down_write(&efx->filter_sem);
613 efx_ef10_filter_del_vlan(efx, vlan->vid);
614 up_write(&efx->filter_sem);
615 }
616
617 list_del(&vlan->list);
618 kfree(vlan);
619}
620
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100621static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
622{
623 struct efx_ef10_nic_data *nic_data = efx->nic_data;
624 struct efx_ef10_vlan *vlan;
625 int rc = 0;
626
627 /* 8021q removes VID 0 on module unload for all interfaces
628 * with VLAN filtering feature. We need to keep it to receive
629 * untagged traffic.
630 */
631 if (vid == 0)
632 return 0;
633
634 mutex_lock(&nic_data->vlan_lock);
635
636 vlan = efx_ef10_find_vlan(efx, vid);
637 if (!vlan) {
638 netif_err(efx, drv, efx->net_dev,
639 "VLAN %u to be deleted not found\n", vid);
640 rc = -ENOENT;
641 } else {
642 efx_ef10_del_vlan_internal(efx, vlan);
643 }
644
645 mutex_unlock(&nic_data->vlan_lock);
646
647 return rc;
648}
649
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100650static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
651{
652 struct efx_ef10_nic_data *nic_data = efx->nic_data;
653 struct efx_ef10_vlan *vlan, *next_vlan;
654
655 mutex_lock(&nic_data->vlan_lock);
656 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
657 efx_ef10_del_vlan_internal(efx, vlan);
658 mutex_unlock(&nic_data->vlan_lock);
659}
660
Shradha Shah0f5c0842015-06-02 11:37:58 +0100661static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
662 NULL);
663static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
664
Ben Hutchings8127d662013-08-29 19:19:29 +0100665static int efx_ef10_probe(struct efx_nic *efx)
666{
667 struct efx_ef10_nic_data *nic_data;
668 int i, rc;
669
Ben Hutchings8127d662013-08-29 19:19:29 +0100670 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
671 if (!nic_data)
672 return -ENOMEM;
673 efx->nic_data = nic_data;
674
Edward Cree75aba2a2015-05-27 13:13:54 +0100675 /* we assume later that we can copy from this buffer in dwords */
676 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
677
Ben Hutchings8127d662013-08-29 19:19:29 +0100678 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
679 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
680 if (rc)
681 goto fail1;
682
683 /* Get the MC's warm boot count. In case it's rebooting right
684 * now, be prepared to retry.
685 */
686 i = 0;
687 for (;;) {
688 rc = efx_ef10_get_warm_boot_count(efx);
689 if (rc >= 0)
690 break;
691 if (++i == 5)
692 goto fail2;
693 ssleep(1);
694 }
695 nic_data->warm_boot_count = rc;
696
Edward Cree42356d92018-03-08 15:45:17 +0000697 efx->rss_context.context_id = EFX_EF10_RSS_CONTEXT_INVALID;
Ben Hutchings8127d662013-08-29 19:19:29 +0100698
Daniel Pieczko45b24492015-05-06 00:57:14 +0100699 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
700
Ben Hutchings8127d662013-08-29 19:19:29 +0100701 /* In case we're recovering from a crash (kexec), we want to
702 * cancel any outstanding request by the previous user of this
703 * function. We send a special message using the least
704 * significant bits of the 'high' (doorbell) register.
705 */
706 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
707
708 rc = efx_mcdi_init(efx);
709 if (rc)
710 goto fail2;
711
Jon Coopere5fbd972017-02-08 16:52:10 +0000712 mutex_init(&nic_data->udp_tunnels_lock);
713
Ben Hutchings8127d662013-08-29 19:19:29 +0100714 /* Reset (most) configuration for this function */
715 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
716 if (rc)
717 goto fail3;
718
719 /* Enable event logging */
720 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
721 if (rc)
722 goto fail3;
723
Shradha Shah0f5c0842015-06-02 11:37:58 +0100724 rc = device_create_file(&efx->pci_dev->dev,
725 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100726 if (rc)
727 goto fail3;
728
Shradha Shah0f5c0842015-06-02 11:37:58 +0100729 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
730 if (rc)
731 goto fail4;
732
733 rc = efx_ef10_get_pf_index(efx);
734 if (rc)
735 goto fail5;
736
Ben Hutchingse5a25382013-09-05 22:50:59 +0100737 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100738 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100739 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100740
Martin Habets50663fe2018-01-25 17:25:33 +0000741 efx_ef10_read_licensed_features(efx);
742
Edward Cree71827442017-12-18 16:56:19 +0000743 /* We can have one VI for each vi_stride-byte region.
744 * However, until we use TX option descriptors we need two TX queues
745 * per channel.
746 */
747 efx->max_channels = min_t(unsigned int,
748 EFX_MAX_CHANNELS,
749 efx_ef10_mem_map_size(efx) /
750 (efx->vi_stride * EFX_TXQ_TYPES));
751 efx->max_tx_channels = efx->max_channels;
752 if (WARN_ON(efx->max_channels == 0)) {
753 rc = -EIO;
754 goto fail5;
755 }
756
Ben Hutchings8127d662013-08-29 19:19:29 +0100757 efx->rx_packet_len_offset =
758 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
759
Edward Cree69787292017-10-31 14:29:47 +0000760 if (nic_data->datapath_caps &
761 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
762 efx->net_dev->hw_features |= NETIF_F_RXFCS;
763
Ben Hutchings8127d662013-08-29 19:19:29 +0100764 rc = efx_mcdi_port_get_number(efx);
765 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100766 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100767 efx->port_num = rc;
768
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100769 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100770 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100771 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100772
Bert Kenwardd95e3292016-08-11 13:02:36 +0100773 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100774 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100775 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100776
Ben Hutchings8127d662013-08-29 19:19:29 +0100777 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100778 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100779 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100780
Martin Habets23418dc2018-01-25 17:25:15 +0000781 efx_ptp_defer_probe_with_channel(efx);
Ben Hutchings9aecda92013-12-05 21:28:42 +0000782
Shradha Shah1d051e02015-06-02 11:38:16 +0100783#ifdef CONFIG_SFC_SRIOV
784 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
785 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
786 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
787
788 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
789 } else
790#endif
791 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
792
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100793 INIT_LIST_HEAD(&nic_data->vlan_list);
794 mutex_init(&nic_data->vlan_lock);
795
796 /* Add unspecified VID to support VLAN filtering being disabled */
797 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
798 if (rc)
799 goto fail_add_vid_unspec;
800
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100801 /* If VLAN filtering is enabled, we need VID 0 to get untagged
802 * traffic. It is added automatically if 8021q module is loaded,
803 * but we can't rely on it since module may be not loaded.
804 */
805 rc = efx_ef10_add_vlan(efx, 0);
806 if (rc)
807 goto fail_add_vid_0;
808
Ben Hutchings8127d662013-08-29 19:19:29 +0100809 return 0;
810
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100811fail_add_vid_0:
812 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100813fail_add_vid_unspec:
814 mutex_destroy(&nic_data->vlan_lock);
815 efx_ptp_remove(efx);
816 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100817fail5:
818 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
819fail4:
820 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100821fail3:
Jon Coopere5fbd972017-02-08 16:52:10 +0000822 efx_mcdi_detach(efx);
823
824 mutex_lock(&nic_data->udp_tunnels_lock);
825 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
826 (void)efx_ef10_set_udp_tnl_ports(efx, true);
827 mutex_unlock(&nic_data->udp_tunnels_lock);
828 mutex_destroy(&nic_data->udp_tunnels_lock);
829
Ben Hutchings8127d662013-08-29 19:19:29 +0100830 efx_mcdi_fini(efx);
831fail2:
832 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
833fail1:
834 kfree(nic_data);
835 efx->nic_data = NULL;
836 return rc;
837}
838
839static int efx_ef10_free_vis(struct efx_nic *efx)
840{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100841 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100842 size_t outlen;
843 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
844 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100845
846 /* -EALREADY means nothing to free, so ignore */
847 if (rc == -EALREADY)
848 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100849 if (rc)
850 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
851 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100852 return rc;
853}
854
Ben Hutchings183233b2013-06-28 21:47:12 +0100855#ifdef EFX_USE_PIO
856
857static void efx_ef10_free_piobufs(struct efx_nic *efx)
858{
859 struct efx_ef10_nic_data *nic_data = efx->nic_data;
860 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
861 unsigned int i;
862 int rc;
863
864 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
865
866 for (i = 0; i < nic_data->n_piobufs; i++) {
867 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
868 nic_data->piobuf_handle[i]);
869 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
870 NULL, 0, NULL);
871 WARN_ON(rc);
872 }
873
874 nic_data->n_piobufs = 0;
875}
876
877static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
878{
879 struct efx_ef10_nic_data *nic_data = efx->nic_data;
880 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
881 unsigned int i;
882 size_t outlen;
883 int rc = 0;
884
885 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
886
887 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000888 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
889 outbuf, sizeof(outbuf), &outlen);
890 if (rc) {
891 /* Don't display the MC error if we didn't have space
892 * for a VF.
893 */
894 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
895 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
896 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100897 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000898 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100899 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
900 rc = -EIO;
901 break;
902 }
903 nic_data->piobuf_handle[i] =
904 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
905 netif_dbg(efx, probe, efx->net_dev,
906 "allocated PIO buffer %u handle %x\n", i,
907 nic_data->piobuf_handle[i]);
908 }
909
910 nic_data->n_piobufs = i;
911 if (rc)
912 efx_ef10_free_piobufs(efx);
913 return rc;
914}
915
916static int efx_ef10_link_piobufs(struct efx_nic *efx)
917{
918 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Creed0346b02017-03-03 15:22:09 +0000919 MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
Ben Hutchings183233b2013-06-28 21:47:12 +0100920 struct efx_channel *channel;
921 struct efx_tx_queue *tx_queue;
922 unsigned int offset, index;
923 int rc;
924
925 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
926 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
927
928 /* Link a buffer to each VI in the write-combining mapping */
929 for (index = 0; index < nic_data->n_piobufs; ++index) {
930 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
931 nic_data->piobuf_handle[index]);
932 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
933 nic_data->pio_write_vi_base + index);
934 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
935 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
936 NULL, 0, NULL);
937 if (rc) {
938 netif_err(efx, drv, efx->net_dev,
939 "failed to link VI %u to PIO buffer %u (%d)\n",
940 nic_data->pio_write_vi_base + index, index,
941 rc);
942 goto fail;
943 }
944 netif_dbg(efx, probe, efx->net_dev,
945 "linked VI %u to PIO buffer %u\n",
946 nic_data->pio_write_vi_base + index, index);
947 }
948
949 /* Link a buffer to each TX queue */
950 efx_for_each_channel(channel, efx) {
Edward Cree2935e3c2018-01-25 17:26:06 +0000951 /* Extra channels, even those with TXQs (PTP), do not require
952 * PIO resources.
953 */
954 if (!channel->type->want_pio)
955 continue;
Ben Hutchings183233b2013-06-28 21:47:12 +0100956 efx_for_each_channel_tx_queue(tx_queue, channel) {
957 /* We assign the PIO buffers to queues in
958 * reverse order to allow for the following
959 * special case.
960 */
961 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
962 tx_queue->channel->channel - 1) *
963 efx_piobuf_size);
Edward Creec6347002017-01-13 21:20:29 +0000964 index = offset / nic_data->piobuf_size;
965 offset = offset % nic_data->piobuf_size;
Ben Hutchings183233b2013-06-28 21:47:12 +0100966
967 /* When the host page size is 4K, the first
968 * host page in the WC mapping may be within
969 * the same VI page as the last TX queue. We
970 * can only link one buffer to each VI.
971 */
972 if (tx_queue->queue == nic_data->pio_write_vi_base) {
973 BUG_ON(index != 0);
974 rc = 0;
975 } else {
976 MCDI_SET_DWORD(inbuf,
977 LINK_PIOBUF_IN_PIOBUF_HANDLE,
978 nic_data->piobuf_handle[index]);
979 MCDI_SET_DWORD(inbuf,
980 LINK_PIOBUF_IN_TXQ_INSTANCE,
981 tx_queue->queue);
982 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
983 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
984 NULL, 0, NULL);
985 }
986
987 if (rc) {
988 /* This is non-fatal; the TX path just
989 * won't use PIO for this queue
990 */
991 netif_err(efx, drv, efx->net_dev,
992 "failed to link VI %u to PIO buffer %u (%d)\n",
993 tx_queue->queue, index, rc);
994 tx_queue->piobuf = NULL;
995 } else {
996 tx_queue->piobuf =
997 nic_data->pio_write_base +
Edward Cree71827442017-12-18 16:56:19 +0000998 index * efx->vi_stride + offset;
Ben Hutchings183233b2013-06-28 21:47:12 +0100999 tx_queue->piobuf_offset = offset;
1000 netif_dbg(efx, probe, efx->net_dev,
1001 "linked VI %u to PIO buffer %u offset %x addr %p\n",
1002 tx_queue->queue, index,
1003 tx_queue->piobuf_offset,
1004 tx_queue->piobuf);
1005 }
1006 }
1007 }
1008
1009 return 0;
1010
1011fail:
Edward Creed0346b02017-03-03 15:22:09 +00001012 /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
1013 * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
1014 */
1015 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
Ben Hutchings183233b2013-06-28 21:47:12 +01001016 while (index--) {
1017 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
1018 nic_data->pio_write_vi_base + index);
1019 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
1020 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
1021 NULL, 0, NULL);
1022 }
1023 return rc;
1024}
1025
Edward Creec0795bf2016-05-24 18:53:36 +01001026static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1027{
1028 struct efx_channel *channel;
1029 struct efx_tx_queue *tx_queue;
1030
1031 /* All our existing PIO buffers went away */
1032 efx_for_each_channel(channel, efx)
1033 efx_for_each_channel_tx_queue(tx_queue, channel)
1034 tx_queue->piobuf = NULL;
1035}
1036
Ben Hutchings183233b2013-06-28 21:47:12 +01001037#else /* !EFX_USE_PIO */
1038
1039static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
1040{
1041 return n == 0 ? 0 : -ENOBUFS;
1042}
1043
1044static int efx_ef10_link_piobufs(struct efx_nic *efx)
1045{
1046 return 0;
1047}
1048
1049static void efx_ef10_free_piobufs(struct efx_nic *efx)
1050{
1051}
1052
Edward Creec0795bf2016-05-24 18:53:36 +01001053static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1054{
1055}
1056
Ben Hutchings183233b2013-06-28 21:47:12 +01001057#endif /* EFX_USE_PIO */
1058
Ben Hutchings8127d662013-08-29 19:19:29 +01001059static void efx_ef10_remove(struct efx_nic *efx)
1060{
1061 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1062 int rc;
1063
Shradha Shahf1122a32015-05-20 11:09:46 +01001064#ifdef CONFIG_SFC_SRIOV
1065 struct efx_ef10_nic_data *nic_data_pf;
1066 struct pci_dev *pci_dev_pf;
1067 struct efx_nic *efx_pf;
1068 struct ef10_vf *vf;
1069
1070 if (efx->pci_dev->is_virtfn) {
1071 pci_dev_pf = efx->pci_dev->physfn;
1072 if (pci_dev_pf) {
1073 efx_pf = pci_get_drvdata(pci_dev_pf);
1074 nic_data_pf = efx_pf->nic_data;
1075 vf = nic_data_pf->vf + nic_data->vf_index;
1076 vf->efx = NULL;
1077 } else
1078 netif_info(efx, drv, efx->net_dev,
1079 "Could not get the PF id from VF\n");
1080 }
1081#endif
1082
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01001083 efx_ef10_cleanup_vlans(efx);
1084 mutex_destroy(&nic_data->vlan_lock);
1085
Ben Hutchings9aecda92013-12-05 21:28:42 +00001086 efx_ptp_remove(efx);
1087
Ben Hutchings8127d662013-08-29 19:19:29 +01001088 efx_mcdi_mon_remove(efx);
1089
Ben Hutchings8127d662013-08-29 19:19:29 +01001090 efx_ef10_rx_free_indir_table(efx);
1091
Ben Hutchings183233b2013-06-28 21:47:12 +01001092 if (nic_data->wc_membase)
1093 iounmap(nic_data->wc_membase);
1094
Ben Hutchings8127d662013-08-29 19:19:29 +01001095 rc = efx_ef10_free_vis(efx);
1096 WARN_ON(rc != 0);
1097
Ben Hutchings183233b2013-06-28 21:47:12 +01001098 if (!nic_data->must_restore_piobufs)
1099 efx_ef10_free_piobufs(efx);
1100
Shradha Shah0f5c0842015-06-02 11:37:58 +01001101 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
1102 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
1103
Jon Coopere5fbd972017-02-08 16:52:10 +00001104 efx_mcdi_detach(efx);
1105
1106 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
1107 mutex_lock(&nic_data->udp_tunnels_lock);
1108 (void)efx_ef10_set_udp_tnl_ports(efx, true);
1109 mutex_unlock(&nic_data->udp_tunnels_lock);
1110
1111 mutex_destroy(&nic_data->udp_tunnels_lock);
1112
Ben Hutchings8127d662013-08-29 19:19:29 +01001113 efx_mcdi_fini(efx);
1114 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
1115 kfree(nic_data);
1116}
1117
Shradha Shah88a37de2015-05-20 11:09:15 +01001118static int efx_ef10_probe_pf(struct efx_nic *efx)
1119{
1120 return efx_ef10_probe(efx);
1121}
1122
Andrew Rybchenko38d27f32016-06-15 17:52:08 +01001123int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
1124 u32 *port_flags, u32 *vadaptor_flags,
1125 unsigned int *vlan_tags)
1126{
1127 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1128 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
1129 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
1130 size_t outlen;
1131 int rc;
1132
1133 if (nic_data->datapath_caps &
1134 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
1135 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
1136 port_id);
1137
1138 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
1139 outbuf, sizeof(outbuf), &outlen);
1140 if (rc)
1141 return rc;
1142
1143 if (outlen < sizeof(outbuf)) {
1144 rc = -EIO;
1145 return rc;
1146 }
1147 }
1148
1149 if (port_flags)
1150 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1151 if (vadaptor_flags)
1152 *vadaptor_flags =
1153 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1154 if (vlan_tags)
1155 *vlan_tags =
1156 MCDI_DWORD(outbuf,
1157 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1158
1159 return 0;
1160}
1161
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001162int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1163{
1164 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1165
1166 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1167 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1168 NULL, 0, NULL);
1169}
1170
1171int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1172{
1173 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1174
1175 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1176 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1177 NULL, 0, NULL);
1178}
1179
1180int efx_ef10_vport_add_mac(struct efx_nic *efx,
1181 unsigned int port_id, u8 *mac)
1182{
1183 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1184
1185 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1186 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1187
1188 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1189 sizeof(inbuf), NULL, 0, NULL);
1190}
1191
1192int efx_ef10_vport_del_mac(struct efx_nic *efx,
1193 unsigned int port_id, u8 *mac)
1194{
1195 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1196
1197 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1198 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1199
1200 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1201 sizeof(inbuf), NULL, 0, NULL);
1202}
1203
Shradha Shah88a37de2015-05-20 11:09:15 +01001204#ifdef CONFIG_SFC_SRIOV
1205static int efx_ef10_probe_vf(struct efx_nic *efx)
1206{
1207 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001208 struct pci_dev *pci_dev_pf;
1209
1210 /* If the parent PF has no VF data structure, it doesn't know about this
1211 * VF so fail probe. The VF needs to be re-created. This can happen
1212 * if the PF driver is unloaded while the VF is assigned to a guest.
1213 */
1214 pci_dev_pf = efx->pci_dev->physfn;
1215 if (pci_dev_pf) {
1216 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1217 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1218
1219 if (!nic_data_pf->vf) {
1220 netif_info(efx, drv, efx->net_dev,
1221 "The VF cannot link to its parent PF; "
1222 "please destroy and re-create the VF\n");
1223 return -EBUSY;
1224 }
1225 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001226
1227 rc = efx_ef10_probe(efx);
1228 if (rc)
1229 return rc;
1230
1231 rc = efx_ef10_get_vf_index(efx);
1232 if (rc)
1233 goto fail;
1234
Shradha Shahf1122a32015-05-20 11:09:46 +01001235 if (efx->pci_dev->is_virtfn) {
1236 if (efx->pci_dev->physfn) {
1237 struct efx_nic *efx_pf =
1238 pci_get_drvdata(efx->pci_dev->physfn);
1239 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1240 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1241
1242 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001243 nic_data_p->vf[nic_data->vf_index].pci_dev =
1244 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001245 } else
1246 netif_info(efx, drv, efx->net_dev,
1247 "Could not get the PF id from VF\n");
1248 }
1249
Shradha Shah88a37de2015-05-20 11:09:15 +01001250 return 0;
1251
1252fail:
1253 efx_ef10_remove(efx);
1254 return rc;
1255}
1256#else
1257static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1258{
1259 return 0;
1260}
1261#endif
1262
Ben Hutchings8127d662013-08-29 19:19:29 +01001263static int efx_ef10_alloc_vis(struct efx_nic *efx,
1264 unsigned int min_vis, unsigned int max_vis)
1265{
1266 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1267 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1268 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1269 size_t outlen;
1270 int rc;
1271
1272 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1273 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1274 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1275 outbuf, sizeof(outbuf), &outlen);
1276 if (rc != 0)
1277 return rc;
1278
1279 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1280 return -EIO;
1281
1282 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1283 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1284
1285 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1286 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1287 return 0;
1288}
1289
Ben Hutchings183233b2013-06-28 21:47:12 +01001290/* Note that the failure path of this function does not free
1291 * resources, as this will be done by efx_ef10_remove().
1292 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001293static int efx_ef10_dimension_resources(struct efx_nic *efx)
1294{
Ben Hutchings183233b2013-06-28 21:47:12 +01001295 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1296 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001297 unsigned int min_vis = max(EFX_TXQ_TYPES,
1298 efx_separate_tx_channels ? 2 : 1);
1299 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001300 void __iomem *membase;
1301 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001302
Edward Cree2935e3c2018-01-25 17:26:06 +00001303 channel_vis = max(efx->n_channels,
1304 (efx->n_tx_channels + efx->n_extra_tx_channels) *
1305 EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001306
1307#ifdef EFX_USE_PIO
1308 /* Try to allocate PIO buffers if wanted and if the full
1309 * number of PIO buffers would be sufficient to allocate one
1310 * copy-buffer per TX channel. Failure is non-fatal, as there
1311 * are only a small number of PIO buffers shared between all
1312 * functions of the controller.
1313 */
1314 if (efx_piobuf_size != 0 &&
Edward Creec6347002017-01-13 21:20:29 +00001315 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
Ben Hutchings183233b2013-06-28 21:47:12 +01001316 efx->n_tx_channels) {
1317 unsigned int n_piobufs =
1318 DIV_ROUND_UP(efx->n_tx_channels,
Edward Creec6347002017-01-13 21:20:29 +00001319 nic_data->piobuf_size / efx_piobuf_size);
Ben Hutchings183233b2013-06-28 21:47:12 +01001320
1321 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001322 if (rc == -ENOSPC)
1323 netif_dbg(efx, probe, efx->net_dev,
1324 "out of PIO buffers; cannot allocate more\n");
1325 else if (rc == -EPERM)
1326 netif_dbg(efx, probe, efx->net_dev,
1327 "not permitted to allocate PIO buffers\n");
1328 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001329 netif_err(efx, probe, efx->net_dev,
1330 "failed to allocate PIO buffers (%d)\n", rc);
1331 else
1332 netif_dbg(efx, probe, efx->net_dev,
1333 "allocated %u PIO buffers\n", n_piobufs);
1334 }
1335#else
1336 nic_data->n_piobufs = 0;
1337#endif
1338
1339 /* PIO buffers should be mapped with write-combining enabled,
1340 * and we want to make single UC and WC mappings rather than
1341 * several of each (in fact that's the only option if host
1342 * page size is >4K). So we may allocate some extra VIs just
1343 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001344 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001345 * The UC mapping contains (channel_vis - 1) complete VIs and the
Edward Cree71827442017-12-18 16:56:19 +00001346 * first 4K of the next VI. Then the WC mapping begins with
1347 * the remainder of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001348 */
Edward Cree71827442017-12-18 16:56:19 +00001349 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
Ben Hutchings183233b2013-06-28 21:47:12 +01001350 ER_DZ_TX_PIOBUF);
1351 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001352 /* pio_write_vi_base rounds down to give the number of complete
1353 * VIs inside the UC mapping.
1354 */
Edward Cree71827442017-12-18 16:56:19 +00001355 pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
Ben Hutchings183233b2013-06-28 21:47:12 +01001356 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1357 nic_data->n_piobufs) *
Edward Cree71827442017-12-18 16:56:19 +00001358 efx->vi_stride) -
Ben Hutchings183233b2013-06-28 21:47:12 +01001359 uc_mem_map_size);
1360 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1361 } else {
1362 pio_write_vi_base = 0;
1363 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001364 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001365 }
1366
1367 /* In case the last attached driver failed to free VIs, do it now */
1368 rc = efx_ef10_free_vis(efx);
1369 if (rc != 0)
1370 return rc;
1371
1372 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1373 if (rc != 0)
1374 return rc;
1375
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001376 if (nic_data->n_allocated_vis < channel_vis) {
1377 netif_info(efx, drv, efx->net_dev,
1378 "Could not allocate enough VIs to satisfy RSS"
1379 " requirements. Performance may not be optimal.\n");
1380 /* We didn't get the VIs to populate our channels.
1381 * We could keep what we got but then we'd have more
1382 * interrupts than we need.
1383 * Instead calculate new max_channels and restart
1384 */
1385 efx->max_channels = nic_data->n_allocated_vis;
1386 efx->max_tx_channels =
1387 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1388
1389 efx_ef10_free_vis(efx);
1390 return -EAGAIN;
1391 }
1392
Ben Hutchings183233b2013-06-28 21:47:12 +01001393 /* If we didn't get enough VIs to map all the PIO buffers, free the
1394 * PIO buffers
1395 */
1396 if (nic_data->n_piobufs &&
1397 nic_data->n_allocated_vis <
1398 pio_write_vi_base + nic_data->n_piobufs) {
1399 netif_dbg(efx, probe, efx->net_dev,
1400 "%u VIs are not sufficient to map %u PIO buffers\n",
1401 nic_data->n_allocated_vis, nic_data->n_piobufs);
1402 efx_ef10_free_piobufs(efx);
1403 }
1404
1405 /* Shrink the original UC mapping of the memory BAR */
1406 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1407 if (!membase) {
1408 netif_err(efx, probe, efx->net_dev,
1409 "could not shrink memory BAR to %x\n",
1410 uc_mem_map_size);
1411 return -ENOMEM;
1412 }
1413 iounmap(efx->membase);
1414 efx->membase = membase;
1415
1416 /* Set up the WC mapping if needed */
1417 if (wc_mem_map_size) {
1418 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1419 uc_mem_map_size,
1420 wc_mem_map_size);
1421 if (!nic_data->wc_membase) {
1422 netif_err(efx, probe, efx->net_dev,
1423 "could not allocate WC mapping of size %x\n",
1424 wc_mem_map_size);
1425 return -ENOMEM;
1426 }
1427 nic_data->pio_write_vi_base = pio_write_vi_base;
1428 nic_data->pio_write_base =
1429 nic_data->wc_membase +
Edward Cree71827442017-12-18 16:56:19 +00001430 (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
Ben Hutchings183233b2013-06-28 21:47:12 +01001431 uc_mem_map_size);
1432
1433 rc = efx_ef10_link_piobufs(efx);
1434 if (rc)
1435 efx_ef10_free_piobufs(efx);
1436 }
1437
1438 netif_dbg(efx, probe, efx->net_dev,
1439 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1440 &efx->membase_phys, efx->membase, uc_mem_map_size,
1441 nic_data->wc_membase, wc_mem_map_size);
1442
1443 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001444}
1445
1446static int efx_ef10_init_nic(struct efx_nic *efx)
1447{
1448 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1449 int rc;
1450
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001451 if (nic_data->must_check_datapath_caps) {
1452 rc = efx_ef10_init_datapath_caps(efx);
1453 if (rc)
1454 return rc;
1455 nic_data->must_check_datapath_caps = false;
1456 }
1457
Ben Hutchings8127d662013-08-29 19:19:29 +01001458 if (nic_data->must_realloc_vis) {
1459 /* We cannot let the number of VIs change now */
1460 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1461 nic_data->n_allocated_vis);
1462 if (rc)
1463 return rc;
1464 nic_data->must_realloc_vis = false;
1465 }
1466
Ben Hutchings183233b2013-06-28 21:47:12 +01001467 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1468 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1469 if (rc == 0) {
1470 rc = efx_ef10_link_piobufs(efx);
1471 if (rc)
1472 efx_ef10_free_piobufs(efx);
1473 }
1474
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001475 /* Log an error on failure, but this is non-fatal.
1476 * Permission errors are less important - we've presumably
1477 * had the PIO buffer licence removed.
1478 */
1479 if (rc == -EPERM)
1480 netif_dbg(efx, drv, efx->net_dev,
1481 "not permitted to restore PIO buffers\n");
1482 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001483 netif_err(efx, drv, efx->net_dev,
1484 "failed to restore PIO buffers (%d)\n", rc);
1485 nic_data->must_restore_piobufs = false;
1486 }
1487
Jon Cooper267c0152015-05-06 00:59:38 +01001488 /* don't fail init if RSS setup doesn't work */
Edward Cree42356d92018-03-08 15:45:17 +00001489 rc = efx->type->rx_push_rss_config(efx, false,
1490 efx->rss_context.rx_indir_table, NULL);
Jon Cooper267c0152015-05-06 00:59:38 +01001491
Ben Hutchings8127d662013-08-29 19:19:29 +01001492 return 0;
1493}
1494
Jon Cooper3e336262014-01-17 19:48:06 +00001495static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1496{
1497 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001498#ifdef CONFIG_SFC_SRIOV
1499 unsigned int i;
1500#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001501
1502 /* All our allocations have been reset */
1503 nic_data->must_realloc_vis = true;
1504 nic_data->must_restore_filters = true;
1505 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001506 efx_ef10_forget_old_piobufs(efx);
Edward Cree42356d92018-03-08 15:45:17 +00001507 efx->rss_context.context_id = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001508
1509 /* Driver-created vswitches and vports must be re-created */
1510 nic_data->must_probe_vswitching = true;
1511 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1512#ifdef CONFIG_SFC_SRIOV
1513 if (nic_data->vf)
1514 for (i = 0; i < efx->vf_count; i++)
1515 nic_data->vf[i].vport_id = 0;
1516#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001517}
1518
Jon Cooper087e9022015-05-20 11:11:35 +01001519static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1520{
1521 if (reason == RESET_TYPE_MC_FAILURE)
1522 return RESET_TYPE_DATAPATH;
1523
1524 return efx_mcdi_map_reset_reason(reason);
1525}
1526
Ben Hutchings8127d662013-08-29 19:19:29 +01001527static int efx_ef10_map_reset_flags(u32 *flags)
1528{
1529 enum {
1530 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1531 ETH_RESET_SHARED_SHIFT),
1532 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1533 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1534 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1535 ETH_RESET_SHARED_SHIFT)
1536 };
1537
1538 /* We assume for now that our PCI function is permitted to
1539 * reset everything.
1540 */
1541
1542 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1543 *flags &= ~EF10_RESET_MC;
1544 return RESET_TYPE_WORLD;
1545 }
1546
1547 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1548 *flags &= ~EF10_RESET_PORT;
1549 return RESET_TYPE_ALL;
1550 }
1551
1552 /* no invisible reset implemented */
1553
1554 return -EINVAL;
1555}
1556
Jon Cooper3e336262014-01-17 19:48:06 +00001557static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1558{
1559 int rc = efx_mcdi_reset(efx, reset_type);
1560
Daniel Pieczko27324822015-07-31 11:14:54 +01001561 /* Unprivileged functions return -EPERM, but need to return success
1562 * here so that the datapath is brought back up.
1563 */
1564 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1565 rc = 0;
1566
Jon Cooper3e336262014-01-17 19:48:06 +00001567 /* If it was a port reset, trigger reallocation of MC resources.
1568 * Note that on an MC reset nothing needs to be done now because we'll
1569 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001570 * For an FLR, we never get an MC reset event, but the MC has reset all
1571 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001572 */
Edward Creee2835462014-04-16 19:27:48 +01001573 if ((reset_type == RESET_TYPE_ALL ||
1574 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001575 efx_ef10_reset_mc_allocations(efx);
1576 return rc;
1577}
1578
Ben Hutchings8127d662013-08-29 19:19:29 +01001579#define EF10_DMA_STAT(ext_name, mcdi_name) \
1580 [EF10_STAT_ ## ext_name] = \
1581 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1582#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1583 [EF10_STAT_ ## int_name] = \
1584 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1585#define EF10_OTHER_STAT(ext_name) \
1586 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001587#define GENERIC_SW_STAT(ext_name) \
1588 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001589
1590static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001591 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1592 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1593 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1594 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1595 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1596 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1597 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1598 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1599 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1600 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1601 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1602 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1603 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1604 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1605 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1606 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1607 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1608 EF10_OTHER_STAT(port_rx_good_bytes),
1609 EF10_OTHER_STAT(port_rx_bad_bytes),
1610 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1611 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1612 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1613 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1614 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1615 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1616 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1617 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1618 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1619 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1620 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1621 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1622 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1623 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1624 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1625 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1626 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1627 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1628 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1629 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1630 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1631 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001632 GENERIC_SW_STAT(rx_nodesc_trunc),
1633 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001634 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1635 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1636 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1637 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1638 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1639 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1640 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1641 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1642 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1643 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1644 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1645 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001646 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1647 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1648 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1649 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1650 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1651 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1652 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1653 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1654 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1655 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1656 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1657 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1658 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1659 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1660 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1661 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1662 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1663 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Edward Creef411b542017-12-21 09:00:36 +00001664 EF10_DMA_STAT(fec_uncorrected_errors, FEC_UNCORRECTED_ERRORS),
1665 EF10_DMA_STAT(fec_corrected_errors, FEC_CORRECTED_ERRORS),
1666 EF10_DMA_STAT(fec_corrected_symbols_lane0, FEC_CORRECTED_SYMBOLS_LANE0),
1667 EF10_DMA_STAT(fec_corrected_symbols_lane1, FEC_CORRECTED_SYMBOLS_LANE1),
1668 EF10_DMA_STAT(fec_corrected_symbols_lane2, FEC_CORRECTED_SYMBOLS_LANE2),
1669 EF10_DMA_STAT(fec_corrected_symbols_lane3, FEC_CORRECTED_SYMBOLS_LANE3),
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001670 EF10_DMA_STAT(ctpio_dmabuf_start, CTPIO_DMABUF_START),
1671 EF10_DMA_STAT(ctpio_vi_busy_fallback, CTPIO_VI_BUSY_FALLBACK),
1672 EF10_DMA_STAT(ctpio_long_write_success, CTPIO_LONG_WRITE_SUCCESS),
1673 EF10_DMA_STAT(ctpio_missing_dbell_fail, CTPIO_MISSING_DBELL_FAIL),
1674 EF10_DMA_STAT(ctpio_overflow_fail, CTPIO_OVERFLOW_FAIL),
1675 EF10_DMA_STAT(ctpio_underflow_fail, CTPIO_UNDERFLOW_FAIL),
1676 EF10_DMA_STAT(ctpio_timeout_fail, CTPIO_TIMEOUT_FAIL),
1677 EF10_DMA_STAT(ctpio_noncontig_wr_fail, CTPIO_NONCONTIG_WR_FAIL),
1678 EF10_DMA_STAT(ctpio_frm_clobber_fail, CTPIO_FRM_CLOBBER_FAIL),
1679 EF10_DMA_STAT(ctpio_invalid_wr_fail, CTPIO_INVALID_WR_FAIL),
1680 EF10_DMA_STAT(ctpio_vi_clobber_fallback, CTPIO_VI_CLOBBER_FALLBACK),
1681 EF10_DMA_STAT(ctpio_unqualified_fallback, CTPIO_UNQUALIFIED_FALLBACK),
1682 EF10_DMA_STAT(ctpio_runt_fallback, CTPIO_RUNT_FALLBACK),
1683 EF10_DMA_STAT(ctpio_success, CTPIO_SUCCESS),
1684 EF10_DMA_STAT(ctpio_fallback, CTPIO_FALLBACK),
1685 EF10_DMA_STAT(ctpio_poison, CTPIO_POISON),
1686 EF10_DMA_STAT(ctpio_erase, CTPIO_ERASE),
Ben Hutchings8127d662013-08-29 19:19:29 +01001687};
1688
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001689#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1690 (1ULL << EF10_STAT_port_tx_packets) | \
1691 (1ULL << EF10_STAT_port_tx_pause) | \
1692 (1ULL << EF10_STAT_port_tx_unicast) | \
1693 (1ULL << EF10_STAT_port_tx_multicast) | \
1694 (1ULL << EF10_STAT_port_tx_broadcast) | \
1695 (1ULL << EF10_STAT_port_rx_bytes) | \
1696 (1ULL << \
1697 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1698 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1699 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1700 (1ULL << EF10_STAT_port_rx_packets) | \
1701 (1ULL << EF10_STAT_port_rx_good) | \
1702 (1ULL << EF10_STAT_port_rx_bad) | \
1703 (1ULL << EF10_STAT_port_rx_pause) | \
1704 (1ULL << EF10_STAT_port_rx_control) | \
1705 (1ULL << EF10_STAT_port_rx_unicast) | \
1706 (1ULL << EF10_STAT_port_rx_multicast) | \
1707 (1ULL << EF10_STAT_port_rx_broadcast) | \
1708 (1ULL << EF10_STAT_port_rx_lt64) | \
1709 (1ULL << EF10_STAT_port_rx_64) | \
1710 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1711 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1712 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1713 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1714 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1715 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1716 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1717 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1718 (1ULL << EF10_STAT_port_rx_overflow) | \
1719 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001720 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1721 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001722
Edward Cree69b365c2016-08-26 15:12:41 +01001723/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1724 * For a 10G/40G switchable port we do not expose these because they might
1725 * not include all the packets they should.
1726 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001727 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001728#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1729 (1ULL << EF10_STAT_port_tx_lt64) | \
1730 (1ULL << EF10_STAT_port_tx_64) | \
1731 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1732 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1733 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1734 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1735 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1736 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001737
1738/* These statistics are only provided by the 40G MAC. For a 10G/40G
1739 * switchable port we do expose these because the errors will otherwise
1740 * be silent.
1741 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001742#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1743 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001744
Edward Cree568d7a02013-09-25 17:32:09 +01001745/* These statistics are only provided if the firmware supports the
1746 * capability PM_AND_RXDP_COUNTERS.
1747 */
1748#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001749 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1750 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1751 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1752 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1753 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1754 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1755 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1756 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1757 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1758 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1759 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1760 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001761
Edward Creef411b542017-12-21 09:00:36 +00001762/* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V2,
1763 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V2 in
1764 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1765 * These bits are in the second u64 of the raw mask.
1766 */
1767#define EF10_FEC_STAT_MASK ( \
1768 (1ULL << (EF10_STAT_fec_uncorrected_errors - 64)) | \
1769 (1ULL << (EF10_STAT_fec_corrected_errors - 64)) | \
1770 (1ULL << (EF10_STAT_fec_corrected_symbols_lane0 - 64)) | \
1771 (1ULL << (EF10_STAT_fec_corrected_symbols_lane1 - 64)) | \
1772 (1ULL << (EF10_STAT_fec_corrected_symbols_lane2 - 64)) | \
1773 (1ULL << (EF10_STAT_fec_corrected_symbols_lane3 - 64)))
1774
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001775/* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V3,
1776 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V3 in
1777 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1778 * These bits are in the second u64 of the raw mask.
1779 */
1780#define EF10_CTPIO_STAT_MASK ( \
1781 (1ULL << (EF10_STAT_ctpio_dmabuf_start - 64)) | \
1782 (1ULL << (EF10_STAT_ctpio_vi_busy_fallback - 64)) | \
1783 (1ULL << (EF10_STAT_ctpio_long_write_success - 64)) | \
1784 (1ULL << (EF10_STAT_ctpio_missing_dbell_fail - 64)) | \
1785 (1ULL << (EF10_STAT_ctpio_overflow_fail - 64)) | \
1786 (1ULL << (EF10_STAT_ctpio_underflow_fail - 64)) | \
1787 (1ULL << (EF10_STAT_ctpio_timeout_fail - 64)) | \
1788 (1ULL << (EF10_STAT_ctpio_noncontig_wr_fail - 64)) | \
1789 (1ULL << (EF10_STAT_ctpio_frm_clobber_fail - 64)) | \
1790 (1ULL << (EF10_STAT_ctpio_invalid_wr_fail - 64)) | \
1791 (1ULL << (EF10_STAT_ctpio_vi_clobber_fallback - 64)) | \
1792 (1ULL << (EF10_STAT_ctpio_unqualified_fallback - 64)) | \
1793 (1ULL << (EF10_STAT_ctpio_runt_fallback - 64)) | \
1794 (1ULL << (EF10_STAT_ctpio_success - 64)) | \
1795 (1ULL << (EF10_STAT_ctpio_fallback - 64)) | \
1796 (1ULL << (EF10_STAT_ctpio_poison - 64)) | \
1797 (1ULL << (EF10_STAT_ctpio_erase - 64)))
1798
Edward Cree4bae9132013-09-27 18:52:49 +01001799static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001800{
Edward Cree4bae9132013-09-27 18:52:49 +01001801 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001802 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001803 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001804
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001805 if (!(efx->mcdi->fn_flags &
1806 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1807 return 0;
1808
Edward Cree69b365c2016-08-26 15:12:41 +01001809 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001810 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001811 /* 8000 series have everything even at 40G */
1812 if (nic_data->datapath_caps2 &
1813 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1814 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1815 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001816 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001817 }
Edward Cree568d7a02013-09-25 17:32:09 +01001818
1819 if (nic_data->datapath_caps &
1820 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1821 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1822
Edward Cree4bae9132013-09-27 18:52:49 +01001823 return raw_mask;
1824}
1825
1826static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1827{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001828 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001829 u64 raw_mask[2];
1830
1831 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1832
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001833 /* Only show vadaptor stats when EVB capability is present */
1834 if (nic_data->datapath_caps &
1835 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1836 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
Edward Creef411b542017-12-21 09:00:36 +00001837 raw_mask[1] = (1ULL << (EF10_STAT_V1_COUNT - 64)) - 1;
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001838 } else {
1839 raw_mask[1] = 0;
1840 }
Edward Creef411b542017-12-21 09:00:36 +00001841 /* Only show FEC stats when NIC supports MC_CMD_MAC_STATS_V2 */
1842 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V2)
1843 raw_mask[1] |= EF10_FEC_STAT_MASK;
Edward Cree4bae9132013-09-27 18:52:49 +01001844
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001845 /* CTPIO stats appear in V3. Only show them on devices that actually
1846 * support CTPIO. Although this driver doesn't use CTPIO others might,
1847 * and we may be reporting the stats for the underlying port.
1848 */
1849 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V3 &&
1850 (nic_data->datapath_caps2 &
1851 (1 << MC_CMD_GET_CAPABILITIES_V4_OUT_CTPIO_LBN)))
1852 raw_mask[1] |= EF10_CTPIO_STAT_MASK;
1853
Edward Cree4bae9132013-09-27 18:52:49 +01001854#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001855 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001856 mask[0] = raw_mask[0];
1857 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001858#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001859 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001860 mask[0] = raw_mask[0] & 0xffffffff;
1861 mask[1] = raw_mask[0] >> 32;
1862 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001863#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001864}
1865
1866static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1867{
Edward Cree4bae9132013-09-27 18:52:49 +01001868 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1869
1870 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001871 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001872 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001873}
1874
Daniel Pieczkod7788192015-06-02 11:39:20 +01001875static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1876 struct rtnl_link_stats64 *core_stats)
1877{
1878 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1879 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1880 u64 *stats = nic_data->stats;
1881 size_t stats_count = 0, index;
1882
1883 efx_ef10_get_stat_mask(efx, mask);
1884
1885 if (full_stats) {
1886 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1887 if (efx_ef10_stat_desc[index].name) {
1888 *full_stats++ = stats[index];
1889 ++stats_count;
1890 }
1891 }
1892 }
1893
Bert Kenwardfbe43072015-08-26 16:39:03 +01001894 if (!core_stats)
1895 return stats_count;
1896
1897 if (nic_data->datapath_caps &
1898 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1899 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001900 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1901 stats[EF10_STAT_rx_multicast] +
1902 stats[EF10_STAT_rx_broadcast];
1903 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1904 stats[EF10_STAT_tx_multicast] +
1905 stats[EF10_STAT_tx_broadcast];
1906 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1907 stats[EF10_STAT_rx_multicast_bytes] +
1908 stats[EF10_STAT_rx_broadcast_bytes];
1909 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1910 stats[EF10_STAT_tx_multicast_bytes] +
1911 stats[EF10_STAT_tx_broadcast_bytes];
1912 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001913 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001914 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1915 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1916 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1917 core_stats->rx_errors = core_stats->rx_crc_errors;
1918 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001919 } else {
1920 /* Use port stats. */
1921 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1922 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1923 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1924 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1925 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1926 stats[GENERIC_STAT_rx_nodesc_trunc] +
1927 stats[GENERIC_STAT_rx_noskb_drops];
1928 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1929 core_stats->rx_length_errors =
1930 stats[EF10_STAT_port_rx_gtjumbo] +
1931 stats[EF10_STAT_port_rx_length_error];
1932 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1933 core_stats->rx_frame_errors =
1934 stats[EF10_STAT_port_rx_align_error];
1935 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1936 core_stats->rx_errors = (core_stats->rx_length_errors +
1937 core_stats->rx_crc_errors +
1938 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001939 }
1940
1941 return stats_count;
1942}
1943
1944static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001945{
1946 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001947 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001948 __le64 generation_start, generation_end;
1949 u64 *stats = nic_data->stats;
1950 __le64 *dma_stats;
1951
Edward Cree4bae9132013-09-27 18:52:49 +01001952 efx_ef10_get_stat_mask(efx, mask);
1953
Ben Hutchings8127d662013-08-29 19:19:29 +01001954 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001955
Edward Creec1be4822017-12-21 09:00:26 +00001956 generation_end = dma_stats[efx->num_mac_stats - 1];
Ben Hutchings8127d662013-08-29 19:19:29 +01001957 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1958 return 0;
1959 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001960 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001961 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001962 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001963 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1964 if (generation_end != generation_start)
1965 return -EAGAIN;
1966
1967 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001968 efx_nic_fix_nodesc_drop_stat(efx,
1969 &stats[EF10_STAT_port_rx_nodesc_drops]);
1970 stats[EF10_STAT_port_rx_good_bytes] =
1971 stats[EF10_STAT_port_rx_bytes] -
1972 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1973 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1974 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001975 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001976 return 0;
1977}
1978
1979
Daniel Pieczkod7788192015-06-02 11:39:20 +01001980static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1981 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001982{
Ben Hutchings8127d662013-08-29 19:19:29 +01001983 int retry;
1984
1985 /* If we're unlucky enough to read statistics during the DMA, wait
1986 * up to 10ms for it to finish (typically takes <500us)
1987 */
1988 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001989 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001990 break;
1991 udelay(100);
1992 }
1993
Daniel Pieczkod7788192015-06-02 11:39:20 +01001994 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1995}
1996
1997static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1998{
1999 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
2000 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2001 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
2002 __le64 generation_start, generation_end;
2003 u64 *stats = nic_data->stats;
Edward Creec1be4822017-12-21 09:00:26 +00002004 u32 dma_len = efx->num_mac_stats * sizeof(u64);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002005 struct efx_buffer stats_buf;
2006 __le64 *dma_stats;
2007 int rc;
2008
Daniel Pieczkof00bf232015-06-02 11:40:18 +01002009 spin_unlock_bh(&efx->stats_lock);
2010
2011 if (in_interrupt()) {
2012 /* If in atomic context, cannot update stats. Just update the
2013 * software stats and return so the caller can continue.
2014 */
2015 spin_lock_bh(&efx->stats_lock);
2016 efx_update_sw_stats(efx, stats);
2017 return 0;
2018 }
2019
Daniel Pieczkod7788192015-06-02 11:39:20 +01002020 efx_ef10_get_stat_mask(efx, mask);
2021
2022 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01002023 if (rc) {
2024 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002025 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01002026 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002027
2028 dma_stats = stats_buf.addr;
Edward Creec1be4822017-12-21 09:00:26 +00002029 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
Daniel Pieczkod7788192015-06-02 11:39:20 +01002030
2031 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
2032 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002033 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002034 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
2035 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
2036
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002037 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
2038 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002039 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002040 if (rc) {
2041 /* Expect ENOENT if DMA queues have not been set up */
2042 if (rc != -ENOENT || atomic_read(&efx->active_queues))
2043 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
2044 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002045 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002046 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002047
Edward Creec1be4822017-12-21 09:00:26 +00002048 generation_end = dma_stats[efx->num_mac_stats - 1];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002049 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
2050 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002051 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002052 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002053 rmb();
2054 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
2055 stats, stats_buf.addr, false);
2056 rmb();
2057 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
2058 if (generation_end != generation_start) {
2059 rc = -EAGAIN;
2060 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01002061 }
2062
Daniel Pieczkod7788192015-06-02 11:39:20 +01002063 efx_update_sw_stats(efx, stats);
2064out:
2065 efx_nic_free_buffer(efx, &stats_buf);
2066 return rc;
2067}
Ben Hutchings8127d662013-08-29 19:19:29 +01002068
Daniel Pieczkod7788192015-06-02 11:39:20 +01002069static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
2070 struct rtnl_link_stats64 *core_stats)
2071{
2072 if (efx_ef10_try_update_nic_stats_vf(efx))
2073 return 0;
2074
2075 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01002076}
2077
2078static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
2079{
2080 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01002081 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01002082 efx_dword_t timer_cmd;
2083
Bert Kenward539de7c2016-08-11 13:02:09 +01002084 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002085 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01002086 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01002087 } else {
2088 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01002089 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002090 }
2091
Bert Kenward539de7c2016-08-11 13:02:09 +01002092 if (EFX_EF10_WORKAROUND_61265(efx)) {
2093 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
2094 unsigned int ns = usecs * 1000;
2095
2096 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
2097 channel->channel);
2098 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
2099 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
2100 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
2101
2102 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
2103 inbuf, sizeof(inbuf), 0, NULL, 0);
2104 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
2105 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2106
Ben Hutchings8127d662013-08-29 19:19:29 +01002107 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
2108 EFE_DD_EVQ_IND_TIMER_FLAGS,
2109 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01002110 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002111 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
2112 channel->channel);
2113 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01002114 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2115
Bert Kenward0bc959a2017-12-18 16:57:41 +00002116 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
2117 ERF_DZ_TC_TIMER_VAL, ticks,
2118 ERF_FZ_TC_TMR_REL_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002119 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
2120 channel->channel);
2121 }
2122}
2123
Shradha Shah02246a72015-05-06 00:58:14 +01002124static void efx_ef10_get_wol_vf(struct efx_nic *efx,
2125 struct ethtool_wolinfo *wol) {}
2126
2127static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
2128{
2129 return -EOPNOTSUPP;
2130}
2131
Ben Hutchings8127d662013-08-29 19:19:29 +01002132static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
2133{
2134 wol->supported = 0;
2135 wol->wolopts = 0;
2136 memset(&wol->sopass, 0, sizeof(wol->sopass));
2137}
2138
2139static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
2140{
2141 if (type != 0)
2142 return -EINVAL;
2143 return 0;
2144}
2145
2146static void efx_ef10_mcdi_request(struct efx_nic *efx,
2147 const efx_dword_t *hdr, size_t hdr_len,
2148 const efx_dword_t *sdu, size_t sdu_len)
2149{
2150 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2151 u8 *pdu = nic_data->mcdi_buf.addr;
2152
2153 memcpy(pdu, hdr, hdr_len);
2154 memcpy(pdu + hdr_len, sdu, sdu_len);
2155 wmb();
2156
2157 /* The hardware provides 'low' and 'high' (doorbell) registers
2158 * for passing the 64-bit address of an MCDI request to
2159 * firmware. However the dwords are swapped by firmware. The
2160 * least significant bits of the doorbell are then 0 for all
2161 * MCDI requests due to alignment.
2162 */
2163 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
2164 ER_DZ_MC_DB_LWRD);
2165 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
2166 ER_DZ_MC_DB_HWRD);
2167}
2168
2169static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
2170{
2171 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2172 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
2173
2174 rmb();
2175 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
2176}
2177
2178static void
2179efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
2180 size_t offset, size_t outlen)
2181{
2182 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2183 const u8 *pdu = nic_data->mcdi_buf.addr;
2184
2185 memcpy(outbuf, pdu + offset, outlen);
2186}
2187
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002188static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
2189{
2190 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2191
2192 /* All our allocations have been reset */
2193 efx_ef10_reset_mc_allocations(efx);
2194
2195 /* The datapath firmware might have been changed */
2196 nic_data->must_check_datapath_caps = true;
2197
2198 /* MAC statistics have been cleared on the NIC; clear the local
2199 * statistic that we update with efx_update_diff_stat().
2200 */
2201 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
2202}
2203
Ben Hutchings8127d662013-08-29 19:19:29 +01002204static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2205{
2206 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2207 int rc;
2208
2209 rc = efx_ef10_get_warm_boot_count(efx);
2210 if (rc < 0) {
2211 /* The firmware is presumably in the process of
2212 * rebooting. However, we are supposed to report each
2213 * reboot just once, so we must only do that once we
2214 * can read and store the updated warm boot count.
2215 */
2216 return 0;
2217 }
2218
2219 if (rc == nic_data->warm_boot_count)
2220 return 0;
2221
2222 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002223 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01002224
Ben Hutchings8127d662013-08-29 19:19:29 +01002225 return -EIO;
2226}
2227
2228/* Handle an MSI interrupt
2229 *
2230 * Handle an MSI hardware interrupt. This routine schedules event
2231 * queue processing. No interrupt acknowledgement cycle is necessary.
2232 * Also, we never need to check that the interrupt is for us, since
2233 * MSI interrupts cannot be shared.
2234 */
2235static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2236{
2237 struct efx_msi_context *context = dev_id;
2238 struct efx_nic *efx = context->efx;
2239
2240 netif_vdbg(efx, intr, efx->net_dev,
2241 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2242
Mark Rutland6aa7de02017-10-23 14:07:29 -07002243 if (likely(READ_ONCE(efx->irq_soft_enabled))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002244 /* Note test interrupts */
2245 if (context->index == efx->irq_level)
2246 efx->last_irq_cpu = raw_smp_processor_id();
2247
2248 /* Schedule processing of the channel */
2249 efx_schedule_channel_irq(efx->channel[context->index]);
2250 }
2251
2252 return IRQ_HANDLED;
2253}
2254
2255static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2256{
2257 struct efx_nic *efx = dev_id;
Mark Rutland6aa7de02017-10-23 14:07:29 -07002258 bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
Ben Hutchings8127d662013-08-29 19:19:29 +01002259 struct efx_channel *channel;
2260 efx_dword_t reg;
2261 u32 queues;
2262
2263 /* Read the ISR which also ACKs the interrupts */
2264 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2265 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2266
2267 if (queues == 0)
2268 return IRQ_NONE;
2269
2270 if (likely(soft_enabled)) {
2271 /* Note test interrupts */
2272 if (queues & (1U << efx->irq_level))
2273 efx->last_irq_cpu = raw_smp_processor_id();
2274
2275 efx_for_each_channel(channel, efx) {
2276 if (queues & 1)
2277 efx_schedule_channel_irq(channel);
2278 queues >>= 1;
2279 }
2280 }
2281
2282 netif_vdbg(efx, intr, efx->net_dev,
2283 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2284 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2285
2286 return IRQ_HANDLED;
2287}
2288
Jon Cooper942e2982016-08-26 15:13:30 +01002289static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002290{
2291 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2292
Jon Cooper942e2982016-08-26 15:13:30 +01002293 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2294 NULL) == 0)
2295 return -ENOTSUPP;
2296
Ben Hutchings8127d662013-08-29 19:19:29 +01002297 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2298
2299 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002300 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002301 inbuf, sizeof(inbuf), NULL, 0, NULL);
2302}
2303
2304static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2305{
2306 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2307 (tx_queue->ptr_mask + 1) *
2308 sizeof(efx_qword_t),
2309 GFP_KERNEL);
2310}
2311
2312/* This writes to the TX_DESC_WPTR and also pushes data */
2313static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2314 const efx_qword_t *txd)
2315{
2316 unsigned int write_ptr;
2317 efx_oword_t reg;
2318
2319 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2320 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2321 reg.qword[0] = *txd;
2322 efx_writeo_page(tx_queue->efx, &reg,
2323 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2324}
2325
Bert Kenwarde9117e52016-11-17 10:51:54 +00002326/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2327 */
2328static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2329 struct sk_buff *skb,
2330 bool *data_mapped)
2331{
2332 struct efx_tx_buffer *buffer;
2333 struct tcphdr *tcp;
2334 struct iphdr *ip;
2335
2336 u16 ipv4_id;
2337 u32 seqnum;
2338 u32 mss;
2339
Edward Creee01b16a2016-12-02 15:51:33 +00002340 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002341
2342 mss = skb_shinfo(skb)->gso_size;
2343
2344 if (unlikely(mss < 4)) {
2345 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2346 return -EINVAL;
2347 }
2348
2349 ip = ip_hdr(skb);
2350 if (ip->version == 4) {
2351 /* Modify IPv4 header if needed. */
2352 ip->tot_len = 0;
2353 ip->check = 0;
Edward Cree6d431312017-03-03 15:22:27 +00002354 ipv4_id = ntohs(ip->id);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002355 } else {
2356 /* Modify IPv6 header if needed. */
2357 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2358
2359 ipv6->payload_len = 0;
2360 ipv4_id = 0;
2361 }
2362
2363 tcp = tcp_hdr(skb);
2364 seqnum = ntohl(tcp->seq);
2365
2366 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2367
2368 buffer->flags = EFX_TX_BUF_OPTION;
2369 buffer->len = 0;
2370 buffer->unmap_len = 0;
2371 EFX_POPULATE_QWORD_5(buffer->option,
2372 ESF_DZ_TX_DESC_IS_OPT, 1,
2373 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2374 ESF_DZ_TX_TSO_OPTION_TYPE,
2375 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2376 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2377 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2378 );
2379 ++tx_queue->insert_count;
2380
2381 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2382
2383 buffer->flags = EFX_TX_BUF_OPTION;
2384 buffer->len = 0;
2385 buffer->unmap_len = 0;
2386 EFX_POPULATE_QWORD_4(buffer->option,
2387 ESF_DZ_TX_DESC_IS_OPT, 1,
2388 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2389 ESF_DZ_TX_TSO_OPTION_TYPE,
2390 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2391 ESF_DZ_TX_TSO_TCP_MSS, mss
2392 );
2393 ++tx_queue->insert_count;
2394
2395 return 0;
2396}
2397
Edward Cree46d1efd2016-11-17 10:52:36 +00002398static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2399{
2400 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2401 u32 tso_versions = 0;
2402
2403 if (nic_data->datapath_caps &
2404 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2405 tso_versions |= BIT(1);
2406 if (nic_data->datapath_caps2 &
2407 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2408 tso_versions |= BIT(2);
2409 return tso_versions;
2410}
2411
Ben Hutchings8127d662013-08-29 19:19:29 +01002412static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2413{
2414 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2415 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002416 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2417 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2418 struct efx_channel *channel = tx_queue->channel;
2419 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002420 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002421 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002422 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002423 dma_addr_t dma_addr;
2424 efx_qword_t *txd;
2425 int rc;
2426 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002427 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002428
Martin Habets50663fe2018-01-25 17:25:33 +00002429 /* Only attempt to enable TX timestamping if we have the license for it,
2430 * otherwise TXQ init will fail
2431 */
2432 if (!(nic_data->licensed_features &
Martin Habets6aa47c82018-01-25 17:26:31 +00002433 (1 << LICENSED_V3_FEATURES_TX_TIMESTAMPS_LBN))) {
Martin Habets50663fe2018-01-25 17:25:33 +00002434 tx_queue->timestamping = false;
Martin Habets6aa47c82018-01-25 17:26:31 +00002435 /* Disable sync events on this channel. */
2436 if (efx->type->ptp_set_ts_sync_events)
2437 efx->type->ptp_set_ts_sync_events(efx, false, false);
2438 }
Martin Habets50663fe2018-01-25 17:25:33 +00002439
Bert Kenwarde9117e52016-11-17 10:51:54 +00002440 /* TSOv2 is a limited resource that can only be configured on a limited
2441 * number of queues. TSO without checksum offload is not really a thing,
2442 * so we only enable it for those queues.
Martin Habetsb9b603d42018-01-25 17:24:43 +00002443 * TSOv2 cannot be used with Hardware timestamping.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002444 */
2445 if (csum_offload && (nic_data->datapath_caps2 &
Martin Habetsb9b603d42018-01-25 17:24:43 +00002446 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) &&
2447 !tx_queue->timestamping) {
Bert Kenwarde9117e52016-11-17 10:51:54 +00002448 tso_v2 = true;
2449 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2450 channel->channel);
2451 }
2452
Ben Hutchings8127d662013-08-29 19:19:29 +01002453 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2454 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2455 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2456 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002457 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002458 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002459
2460 dma_addr = tx_queue->txd.buf.dma_addr;
2461
2462 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2463 tx_queue->queue, entries, (u64)dma_addr);
2464
2465 for (i = 0; i < entries; ++i) {
2466 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2467 dma_addr += EFX_BUF_SIZE;
2468 }
2469
2470 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2471
Edward Creee638ee12016-11-17 10:52:07 +00002472 do {
Martin Habetsb9b603d42018-01-25 17:24:43 +00002473 MCDI_POPULATE_DWORD_4(inbuf, INIT_TXQ_IN_FLAGS,
Edward Creee638ee12016-11-17 10:52:07 +00002474 /* This flag was removed from mcdi_pcol.h for
2475 * the non-_EXT version of INIT_TXQ. However,
2476 * firmware still honours it.
2477 */
2478 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2479 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
Martin Habetsb9b603d42018-01-25 17:24:43 +00002480 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload,
2481 INIT_TXQ_EXT_IN_FLAG_TIMESTAMP,
2482 tx_queue->timestamping);
Edward Creee638ee12016-11-17 10:52:07 +00002483
2484 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2485 NULL, 0, NULL);
2486 if (rc == -ENOSPC && tso_v2) {
2487 /* Retry without TSOv2 if we're short on contexts. */
2488 tso_v2 = false;
2489 netif_warn(efx, probe, efx->net_dev,
2490 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2491 } else if (rc) {
2492 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2493 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2494 NULL, 0, rc);
2495 goto fail;
2496 }
2497 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002498
2499 /* A previous user of this TX queue might have set us up the
2500 * bomb by writing a descriptor to the TX push collector but
2501 * not the doorbell. (Each collector belongs to a port, not a
2502 * queue or function, so cannot easily be reset.) We must
2503 * attempt to push a no-op descriptor in its place.
2504 */
2505 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2506 tx_queue->insert_count = 1;
2507 txd = efx_tx_desc(tx_queue, 0);
Martin Habetsb9b603d42018-01-25 17:24:43 +00002508 EFX_POPULATE_QWORD_5(*txd,
Ben Hutchings8127d662013-08-29 19:19:29 +01002509 ESF_DZ_TX_DESC_IS_OPT, true,
2510 ESF_DZ_TX_OPTION_TYPE,
2511 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2512 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
Martin Habetsb9b603d42018-01-25 17:24:43 +00002513 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload,
2514 ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
Ben Hutchings8127d662013-08-29 19:19:29 +01002515 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002516
Bert Kenwarde9117e52016-11-17 10:51:54 +00002517 if (tso_v2) {
2518 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2519 tx_queue->tso_version = 2;
2520 } else if (nic_data->datapath_caps &
2521 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002522 tx_queue->tso_version = 1;
2523 }
2524
Ben Hutchings8127d662013-08-29 19:19:29 +01002525 wmb();
2526 efx_ef10_push_tx_desc(tx_queue, txd);
2527
2528 return;
2529
2530fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002531 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2532 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002533}
2534
2535static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2536{
2537 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002538 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002539 struct efx_nic *efx = tx_queue->efx;
2540 size_t outlen;
2541 int rc;
2542
2543 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2544 tx_queue->queue);
2545
Edward Cree1e0b8122013-05-31 18:36:12 +01002546 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002547 outbuf, sizeof(outbuf), &outlen);
2548
2549 if (rc && rc != -EALREADY)
2550 goto fail;
2551
2552 return;
2553
2554fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002555 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2556 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002557}
2558
2559static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2560{
2561 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2562}
2563
2564/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2565static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2566{
2567 unsigned int write_ptr;
2568 efx_dword_t reg;
2569
2570 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2571 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2572 efx_writed_page(tx_queue->efx, &reg,
2573 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2574}
2575
Bert Kenwarde9117e52016-11-17 10:51:54 +00002576#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2577
2578static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2579 dma_addr_t dma_addr, unsigned int len)
2580{
2581 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2582 /* If we need to break across multiple descriptors we should
2583 * stop at a page boundary. This assumes the length limit is
2584 * greater than the page size.
2585 */
2586 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2587
2588 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2589 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2590 }
2591
2592 return len;
2593}
2594
Ben Hutchings8127d662013-08-29 19:19:29 +01002595static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2596{
2597 unsigned int old_write_count = tx_queue->write_count;
2598 struct efx_tx_buffer *buffer;
2599 unsigned int write_ptr;
2600 efx_qword_t *txd;
2601
Martin Habetsb2663a42015-11-02 12:51:31 +00002602 tx_queue->xmit_more_available = false;
2603 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2604 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002605
2606 do {
2607 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2608 buffer = &tx_queue->buffer[write_ptr];
2609 txd = efx_tx_desc(tx_queue, write_ptr);
2610 ++tx_queue->write_count;
2611
2612 /* Create TX descriptor ring entry */
2613 if (buffer->flags & EFX_TX_BUF_OPTION) {
2614 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002615 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2616 /* PIO descriptor */
2617 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002618 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002619 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002620 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2621 EFX_POPULATE_QWORD_3(
2622 *txd,
2623 ESF_DZ_TX_KER_CONT,
2624 buffer->flags & EFX_TX_BUF_CONT,
2625 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2626 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2627 }
2628 } while (tx_queue->write_count != tx_queue->insert_count);
2629
2630 wmb(); /* Ensure descriptors are written before they are fetched */
2631
2632 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2633 txd = efx_tx_desc(tx_queue,
2634 old_write_count & tx_queue->ptr_mask);
2635 efx_ef10_push_tx_desc(tx_queue, txd);
2636 ++tx_queue->pushes;
2637 } else {
2638 efx_ef10_notify_tx_desc(tx_queue);
2639 }
2640}
2641
Edward Creea33a4c72016-11-03 22:12:27 +00002642#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2643 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2644#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2645 1 << RSS_MODE_HASH_DST_PORT_LBN)
2646#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2647 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2648 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2649 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2650 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2651 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2652 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2653 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2654 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2655 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2656
2657static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2658{
2659 /* Firmware had a bug (sfc bug 61952) where it would not actually
2660 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2661 * This meant that it would always contain whatever was previously
2662 * in the MCDI buffer. Fortunately, all firmware versions with
2663 * this bug have the same default flags value for a newly-allocated
2664 * RSS context, and the only time we want to get the flags is just
2665 * after allocating. Moreover, the response has a 32-bit hole
2666 * where the context ID would be in the request, so we can use an
2667 * overlength buffer in the request and pre-fill the flags field
2668 * with what we believe the default to be. Thus if the firmware
2669 * has the bug, it will leave our pre-filled value in the flags
2670 * field of the response, and we will get the right answer.
2671 *
2672 * However, this does mean that this function should NOT be used if
2673 * the RSS context flags might not be their defaults - it is ONLY
2674 * reliably correct for a newly-allocated RSS context.
2675 */
2676 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2677 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2678 size_t outlen;
2679 int rc;
2680
2681 /* Check we have a hole for the context ID */
2682 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2683 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2684 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2685 RSS_CONTEXT_FLAGS_DEFAULT);
2686 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2687 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2688 if (rc == 0) {
2689 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2690 rc = -EIO;
2691 else
2692 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2693 }
2694 return rc;
2695}
2696
2697/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2698 * If we fail, we just leave the RSS context at its default hash settings,
2699 * which is safe but may slightly reduce performance.
2700 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2701 * just need to set the UDP ports flags (for both IP versions).
2702 */
Edward Cree42356d92018-03-08 15:45:17 +00002703static void efx_ef10_set_rss_flags(struct efx_nic *efx,
2704 struct efx_rss_context *ctx)
Edward Creea33a4c72016-11-03 22:12:27 +00002705{
2706 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2707 u32 flags;
2708
2709 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2710
Edward Cree42356d92018-03-08 15:45:17 +00002711 if (efx_ef10_get_rss_flags(efx, ctx->context_id, &flags) != 0)
Edward Creea33a4c72016-11-03 22:12:27 +00002712 return;
Edward Cree42356d92018-03-08 15:45:17 +00002713 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID,
2714 ctx->context_id);
Edward Creea33a4c72016-11-03 22:12:27 +00002715 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2716 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2717 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002718 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2719 NULL, 0, NULL))
2720 /* Succeeded, so UDP 4-tuple is now enabled */
Edward Cree42356d92018-03-08 15:45:17 +00002721 ctx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002722}
2723
Edward Cree42356d92018-03-08 15:45:17 +00002724static int efx_ef10_alloc_rss_context(struct efx_nic *efx, bool exclusive,
2725 struct efx_rss_context *ctx,
2726 unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002727{
2728 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2729 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002730 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002731 size_t outlen;
2732 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002733 u32 alloc_type = exclusive ?
2734 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2735 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2736 unsigned rss_spread = exclusive ?
2737 efx->rss_spread :
2738 min(rounddown_pow_of_two(efx->rss_spread),
2739 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2740
2741 if (!exclusive && rss_spread == 1) {
Edward Cree42356d92018-03-08 15:45:17 +00002742 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
Jon Cooper267c0152015-05-06 00:59:38 +01002743 if (context_size)
2744 *context_size = 1;
2745 return 0;
2746 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002747
Jon Cooperdcb41232016-04-25 16:51:00 +01002748 if (nic_data->datapath_caps &
2749 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2750 return -EOPNOTSUPP;
2751
Ben Hutchings8127d662013-08-29 19:19:29 +01002752 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002753 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002754 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2755 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002756
2757 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2758 outbuf, sizeof(outbuf), &outlen);
2759 if (rc != 0)
2760 return rc;
2761
2762 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2763 return -EIO;
2764
Edward Cree42356d92018-03-08 15:45:17 +00002765 ctx->context_id = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
Ben Hutchings8127d662013-08-29 19:19:29 +01002766
Jon Cooper267c0152015-05-06 00:59:38 +01002767 if (context_size)
2768 *context_size = rss_spread;
2769
Edward Creea33a4c72016-11-03 22:12:27 +00002770 if (nic_data->datapath_caps &
2771 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
Edward Cree42356d92018-03-08 15:45:17 +00002772 efx_ef10_set_rss_flags(efx, ctx);
Edward Creea33a4c72016-11-03 22:12:27 +00002773
Ben Hutchings8127d662013-08-29 19:19:29 +01002774 return 0;
2775}
2776
Edward Cree42356d92018-03-08 15:45:17 +00002777static int efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
Ben Hutchings8127d662013-08-29 19:19:29 +01002778{
2779 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002780
2781 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2782 context);
Edward Cree42356d92018-03-08 15:45:17 +00002783 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002784 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002785}
2786
Jon Cooper267c0152015-05-06 00:59:38 +01002787static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
Edward Creef74d1992017-01-17 12:01:53 +00002788 const u32 *rx_indir_table, const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002789{
2790 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2791 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2792 int i, rc;
2793
2794 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2795 context);
Edward Cree42356d92018-03-08 15:45:17 +00002796 BUILD_BUG_ON(ARRAY_SIZE(efx->rss_context.rx_indir_table) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01002797 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2798
Edward Cree42356d92018-03-08 15:45:17 +00002799 /* This iterates over the length of efx->rss_context.rx_indir_table, but
2800 * copies bytes from rx_indir_table. That's because the latter is a
2801 * pointer rather than an array, but should have the same length.
2802 * The efx->rss_context.rx_hash_key loop below is similar.
Edward Creef74d1992017-01-17 12:01:53 +00002803 */
Edward Cree42356d92018-03-08 15:45:17 +00002804 for (i = 0; i < ARRAY_SIZE(efx->rss_context.rx_indir_table); ++i)
Ben Hutchings8127d662013-08-29 19:19:29 +01002805 MCDI_PTR(tablebuf,
2806 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002807 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002808
2809 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2810 sizeof(tablebuf), NULL, 0, NULL);
2811 if (rc != 0)
2812 return rc;
2813
2814 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2815 context);
Edward Cree42356d92018-03-08 15:45:17 +00002816 BUILD_BUG_ON(ARRAY_SIZE(efx->rss_context.rx_hash_key) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01002817 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
Edward Cree42356d92018-03-08 15:45:17 +00002818 for (i = 0; i < ARRAY_SIZE(efx->rss_context.rx_hash_key); ++i)
Edward Creef74d1992017-01-17 12:01:53 +00002819 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002820
2821 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2822 sizeof(keybuf), NULL, 0, NULL);
2823}
2824
2825static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2826{
Edward Cree42356d92018-03-08 15:45:17 +00002827 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002828
Edward Cree42356d92018-03-08 15:45:17 +00002829 if (efx->rss_context.context_id != EFX_EF10_RSS_CONTEXT_INVALID) {
2830 rc = efx_ef10_free_rss_context(efx, efx->rss_context.context_id);
2831 WARN_ON(rc != 0);
2832 }
2833 efx->rss_context.context_id = EFX_EF10_RSS_CONTEXT_INVALID;
Ben Hutchings8127d662013-08-29 19:19:29 +01002834}
2835
Jon Cooper267c0152015-05-06 00:59:38 +01002836static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2837 unsigned *context_size)
2838{
Jon Cooper267c0152015-05-06 00:59:38 +01002839 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree42356d92018-03-08 15:45:17 +00002840 int rc = efx_ef10_alloc_rss_context(efx, false, &efx->rss_context,
2841 context_size);
Jon Cooper267c0152015-05-06 00:59:38 +01002842
2843 if (rc != 0)
2844 return rc;
2845
Jon Cooper267c0152015-05-06 00:59:38 +01002846 nic_data->rx_rss_context_exclusive = false;
Edward Cree42356d92018-03-08 15:45:17 +00002847 efx_set_default_rx_indir_table(efx, &efx->rss_context);
Jon Cooper267c0152015-05-06 00:59:38 +01002848 return 0;
2849}
2850
2851static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
Edward Creef74d1992017-01-17 12:01:53 +00002852 const u32 *rx_indir_table,
2853 const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002854{
Edward Cree42356d92018-03-08 15:45:17 +00002855 u32 old_rx_rss_context = efx->rss_context.context_id;
Ben Hutchings8127d662013-08-29 19:19:29 +01002856 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2857 int rc;
2858
Edward Cree42356d92018-03-08 15:45:17 +00002859 if (efx->rss_context.context_id == EFX_EF10_RSS_CONTEXT_INVALID ||
Jon Cooper267c0152015-05-06 00:59:38 +01002860 !nic_data->rx_rss_context_exclusive) {
Edward Cree42356d92018-03-08 15:45:17 +00002861 rc = efx_ef10_alloc_rss_context(efx, true, &efx->rss_context,
2862 NULL);
Jon Cooper267c0152015-05-06 00:59:38 +01002863 if (rc == -EOPNOTSUPP)
2864 return rc;
2865 else if (rc != 0)
2866 goto fail1;
Ben Hutchings8127d662013-08-29 19:19:29 +01002867 }
2868
Edward Cree42356d92018-03-08 15:45:17 +00002869 rc = efx_ef10_populate_rss_table(efx, efx->rss_context.context_id,
Edward Creef74d1992017-01-17 12:01:53 +00002870 rx_indir_table, key);
Ben Hutchings8127d662013-08-29 19:19:29 +01002871 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002872 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002873
Edward Cree42356d92018-03-08 15:45:17 +00002874 if (efx->rss_context.context_id != old_rx_rss_context &&
2875 old_rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2876 WARN_ON(efx_ef10_free_rss_context(efx, old_rx_rss_context) != 0);
Jon Cooper267c0152015-05-06 00:59:38 +01002877 nic_data->rx_rss_context_exclusive = true;
Edward Cree42356d92018-03-08 15:45:17 +00002878 if (rx_indir_table != efx->rss_context.rx_indir_table)
2879 memcpy(efx->rss_context.rx_indir_table, rx_indir_table,
2880 sizeof(efx->rss_context.rx_indir_table));
2881 if (key != efx->rss_context.rx_hash_key)
2882 memcpy(efx->rss_context.rx_hash_key, key,
2883 efx->type->rx_hash_key_size);
Edward Creef74d1992017-01-17 12:01:53 +00002884
Jon Cooper267c0152015-05-06 00:59:38 +01002885 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002886
Jon Cooper267c0152015-05-06 00:59:38 +01002887fail2:
Edward Cree42356d92018-03-08 15:45:17 +00002888 if (old_rx_rss_context != efx->rss_context.context_id) {
2889 WARN_ON(efx_ef10_free_rss_context(efx, efx->rss_context.context_id) != 0);
2890 efx->rss_context.context_id = old_rx_rss_context;
2891 }
Jon Cooper267c0152015-05-06 00:59:38 +01002892fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002893 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002894 return rc;
2895}
2896
Edward Cree42356d92018-03-08 15:45:17 +00002897static int efx_ef10_rx_push_rss_context_config(struct efx_nic *efx,
2898 struct efx_rss_context *ctx,
2899 const u32 *rx_indir_table,
2900 const u8 *key)
Edward Creea707d182017-01-17 12:02:12 +00002901{
Edward Cree42356d92018-03-08 15:45:17 +00002902 int rc;
2903
2904 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
2905 rc = efx_ef10_alloc_rss_context(efx, true, ctx, NULL);
2906 if (rc)
2907 return rc;
2908 }
2909
2910 if (!rx_indir_table) /* Delete this context */
2911 return efx_ef10_free_rss_context(efx, ctx->context_id);
2912
2913 rc = efx_ef10_populate_rss_table(efx, ctx->context_id,
2914 rx_indir_table, key);
2915 if (rc)
2916 return rc;
2917
2918 memcpy(ctx->rx_indir_table, rx_indir_table,
2919 sizeof(efx->rss_context.rx_indir_table));
2920 memcpy(ctx->rx_hash_key, key, efx->type->rx_hash_key_size);
2921
2922 return 0;
2923}
2924
2925static int efx_ef10_rx_pull_rss_context_config(struct efx_nic *efx,
2926 struct efx_rss_context *ctx)
2927{
Edward Creea707d182017-01-17 12:02:12 +00002928 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2929 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2930 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2931 size_t outlen;
2932 int rc, i;
2933
2934 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2935 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2936
Edward Cree42356d92018-03-08 15:45:17 +00002937 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID)
Edward Creea707d182017-01-17 12:02:12 +00002938 return -ENOENT;
2939
2940 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
Edward Cree42356d92018-03-08 15:45:17 +00002941 ctx->context_id);
2942 BUILD_BUG_ON(ARRAY_SIZE(ctx->rx_indir_table) !=
Edward Creea707d182017-01-17 12:02:12 +00002943 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2944 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2945 tablebuf, sizeof(tablebuf), &outlen);
2946 if (rc != 0)
2947 return rc;
2948
2949 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2950 return -EIO;
2951
Edward Cree42356d92018-03-08 15:45:17 +00002952 for (i = 0; i < ARRAY_SIZE(ctx->rx_indir_table); i++)
2953 ctx->rx_indir_table[i] = MCDI_PTR(tablebuf,
Edward Creea707d182017-01-17 12:02:12 +00002954 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2955
2956 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
Edward Cree42356d92018-03-08 15:45:17 +00002957 ctx->context_id);
2958 BUILD_BUG_ON(ARRAY_SIZE(ctx->rx_hash_key) !=
Edward Creea707d182017-01-17 12:02:12 +00002959 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2960 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2961 keybuf, sizeof(keybuf), &outlen);
2962 if (rc != 0)
2963 return rc;
2964
2965 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2966 return -EIO;
2967
Edward Cree42356d92018-03-08 15:45:17 +00002968 for (i = 0; i < ARRAY_SIZE(ctx->rx_hash_key); ++i)
2969 ctx->rx_hash_key[i] = MCDI_PTR(
Edward Creea707d182017-01-17 12:02:12 +00002970 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2971
2972 return 0;
2973}
2974
Edward Cree42356d92018-03-08 15:45:17 +00002975static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2976{
2977 return efx_ef10_rx_pull_rss_context_config(efx, &efx->rss_context);
2978}
2979
2980static void efx_ef10_rx_restore_rss_contexts(struct efx_nic *efx)
2981{
2982 struct efx_rss_context *ctx;
2983 int rc;
2984
2985 list_for_each_entry(ctx, &efx->rss_context.list, list) {
2986 /* previous NIC RSS context is gone */
2987 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
2988 /* so try to allocate a new one */
2989 rc = efx_ef10_rx_push_rss_context_config(efx, ctx,
2990 ctx->rx_indir_table,
2991 ctx->rx_hash_key);
2992 if (rc)
2993 netif_warn(efx, probe, efx->net_dev,
2994 "failed to restore RSS context %u, rc=%d"
2995 "; RSS filters may fail to be applied\n",
2996 ctx->user_id, rc);
2997 }
2998}
2999
Jon Cooper267c0152015-05-06 00:59:38 +01003000static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
Edward Creef74d1992017-01-17 12:01:53 +00003001 const u32 *rx_indir_table,
3002 const u8 *key)
Jon Cooper267c0152015-05-06 00:59:38 +01003003{
3004 int rc;
3005
3006 if (efx->rss_spread == 1)
3007 return 0;
3008
Edward Creef74d1992017-01-17 12:01:53 +00003009 if (!key)
Edward Cree42356d92018-03-08 15:45:17 +00003010 key = efx->rss_context.rx_hash_key;
Edward Creef74d1992017-01-17 12:01:53 +00003011
3012 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
Jon Cooper267c0152015-05-06 00:59:38 +01003013
3014 if (rc == -ENOBUFS && !user) {
3015 unsigned context_size;
3016 bool mismatch = false;
3017 size_t i;
3018
Edward Cree42356d92018-03-08 15:45:17 +00003019 for (i = 0;
3020 i < ARRAY_SIZE(efx->rss_context.rx_indir_table) && !mismatch;
Jon Cooper267c0152015-05-06 00:59:38 +01003021 i++)
3022 mismatch = rx_indir_table[i] !=
3023 ethtool_rxfh_indir_default(i, efx->rss_spread);
3024
3025 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
3026 if (rc == 0) {
3027 if (context_size != efx->rss_spread)
3028 netif_warn(efx, probe, efx->net_dev,
3029 "Could not allocate an exclusive RSS"
3030 " context; allocated a shared one of"
3031 " different size."
3032 " Wanted %u, got %u.\n",
3033 efx->rss_spread, context_size);
3034 else if (mismatch)
3035 netif_warn(efx, probe, efx->net_dev,
3036 "Could not allocate an exclusive RSS"
3037 " context; allocated a shared one but"
3038 " could not apply custom"
3039 " indirection.\n");
3040 else
3041 netif_info(efx, probe, efx->net_dev,
3042 "Could not allocate an exclusive RSS"
3043 " context; allocated a shared one.\n");
3044 }
3045 }
3046 return rc;
3047}
3048
3049static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
3050 const u32 *rx_indir_table
Edward Creef74d1992017-01-17 12:01:53 +00003051 __attribute__ ((unused)),
3052 const u8 *key
Jon Cooper267c0152015-05-06 00:59:38 +01003053 __attribute__ ((unused)))
3054{
Jon Cooper267c0152015-05-06 00:59:38 +01003055 if (user)
3056 return -EOPNOTSUPP;
Edward Cree42356d92018-03-08 15:45:17 +00003057 if (efx->rss_context.context_id != EFX_EF10_RSS_CONTEXT_INVALID)
Jon Cooper267c0152015-05-06 00:59:38 +01003058 return 0;
3059 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01003060}
3061
3062static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
3063{
3064 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
3065 (rx_queue->ptr_mask + 1) *
3066 sizeof(efx_qword_t),
3067 GFP_KERNEL);
3068}
3069
3070static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
3071{
3072 MCDI_DECLARE_BUF(inbuf,
3073 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
3074 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01003075 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3076 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
3077 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01003078 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003079 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01003080 dma_addr_t dma_addr;
3081 int rc;
3082 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003083 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003084
3085 rx_queue->scatter_n = 0;
3086 rx_queue->scatter_len = 0;
3087
3088 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
3089 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
3090 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
3091 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
3092 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00003093 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
3094 INIT_RXQ_IN_FLAG_PREFIX, 1,
3095 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01003096 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01003097 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003098
3099 dma_addr = rx_queue->rxd.buf.dma_addr;
3100
3101 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
3102 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
3103
3104 for (i = 0; i < entries; ++i) {
3105 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
3106 dma_addr += EFX_BUF_SIZE;
3107 }
3108
3109 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
3110
3111 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003112 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003113 if (rc)
3114 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
3115 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01003116}
3117
3118static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
3119{
3120 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003121 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01003122 struct efx_nic *efx = rx_queue->efx;
3123 size_t outlen;
3124 int rc;
3125
3126 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
3127 efx_rx_queue_index(rx_queue));
3128
Edward Cree1e0b8122013-05-31 18:36:12 +01003129 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01003130 outbuf, sizeof(outbuf), &outlen);
3131
3132 if (rc && rc != -EALREADY)
3133 goto fail;
3134
3135 return;
3136
3137fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01003138 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
3139 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01003140}
3141
3142static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
3143{
3144 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
3145}
3146
3147/* This creates an entry in the RX descriptor queue */
3148static inline void
3149efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
3150{
3151 struct efx_rx_buffer *rx_buf;
3152 efx_qword_t *rxd;
3153
3154 rxd = efx_rx_desc(rx_queue, index);
3155 rx_buf = efx_rx_buffer(rx_queue, index);
3156 EFX_POPULATE_QWORD_2(*rxd,
3157 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
3158 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
3159}
3160
3161static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
3162{
3163 struct efx_nic *efx = rx_queue->efx;
3164 unsigned int write_count;
3165 efx_dword_t reg;
3166
3167 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
3168 write_count = rx_queue->added_count & ~7;
3169 if (rx_queue->notified_count == write_count)
3170 return;
3171
3172 do
3173 efx_ef10_build_rx_desc(
3174 rx_queue,
3175 rx_queue->notified_count & rx_queue->ptr_mask);
3176 while (++rx_queue->notified_count != write_count);
3177
3178 wmb();
3179 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
3180 write_count & rx_queue->ptr_mask);
3181 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
3182 efx_rx_queue_index(rx_queue));
3183}
3184
3185static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
3186
3187static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
3188{
3189 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3190 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3191 efx_qword_t event;
3192
3193 EFX_POPULATE_QWORD_2(event,
3194 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3195 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
3196
3197 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3198
3199 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3200 * already swapped the data to little-endian order.
3201 */
3202 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3203 sizeof(efx_qword_t));
3204
3205 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
3206 inbuf, sizeof(inbuf), 0,
3207 efx_ef10_rx_defer_refill_complete, 0);
3208}
3209
3210static void
3211efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
3212 int rc, efx_dword_t *outbuf,
3213 size_t outlen_actual)
3214{
3215 /* nothing to do */
3216}
3217
3218static int efx_ef10_ev_probe(struct efx_channel *channel)
3219{
3220 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
3221 (channel->eventq_mask + 1) *
3222 sizeof(efx_qword_t),
3223 GFP_KERNEL);
3224}
3225
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003226static void efx_ef10_ev_fini(struct efx_channel *channel)
3227{
3228 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
3229 MCDI_DECLARE_BUF_ERR(outbuf);
3230 struct efx_nic *efx = channel->efx;
3231 size_t outlen;
3232 int rc;
3233
3234 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
3235
3236 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
3237 outbuf, sizeof(outbuf), &outlen);
3238
3239 if (rc && rc != -EALREADY)
3240 goto fail;
3241
3242 return;
3243
3244fail:
3245 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
3246 outbuf, outlen, rc);
3247}
3248
Ben Hutchings8127d662013-08-29 19:19:29 +01003249static int efx_ef10_ev_init(struct efx_channel *channel)
3250{
3251 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01003252 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
3253 EFX_BUF_SIZE));
3254 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003255 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
3256 struct efx_nic *efx = channel->efx;
3257 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003258 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003259 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01003260 dma_addr_t dma_addr;
3261 int rc;
3262 int i;
3263
3264 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003265
3266 /* Fill event queue with all ones (i.e. empty events) */
3267 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
3268
3269 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
3270 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
3271 /* INIT_EVQ expects index in vector table, not absolute */
3272 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01003273 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3274 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3275 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3276 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3277 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3278 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3279 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3280
Bert Kenwarda9955602016-08-11 13:01:54 +01003281 if (nic_data->datapath_caps2 &
3282 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3283 /* Use the new generic approach to specifying event queue
3284 * configuration, requesting lower latency or higher throughput.
3285 * The options that actually get used appear in the output.
3286 */
3287 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3288 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3289 INIT_EVQ_V2_IN_FLAG_TYPE,
3290 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3291 } else {
3292 bool cut_thru = !(nic_data->datapath_caps &
3293 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3294
3295 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3296 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3297 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3298 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3299 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3300 }
3301
Ben Hutchings8127d662013-08-29 19:19:29 +01003302 dma_addr = channel->eventq.buf.dma_addr;
3303 for (i = 0; i < entries; ++i) {
3304 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3305 dma_addr += EFX_BUF_SIZE;
3306 }
3307
3308 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3309
3310 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3311 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01003312
3313 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3314 netif_dbg(efx, drv, efx->net_dev,
3315 "Channel %d using event queue flags %08x\n",
3316 channel->channel,
3317 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3318
Ben Hutchings8127d662013-08-29 19:19:29 +01003319 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003320 if (channel->channel || rc)
3321 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003322
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003323 /* Successfully created event queue on channel 0 */
3324 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01003325 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01003326 /* GET_WORKAROUNDS was implemented before this workaround,
3327 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01003328 */
3329 nic_data->workaround_26807 = false;
3330 rc = 0;
3331 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003332 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01003333 } else {
3334 nic_data->workaround_26807 =
3335 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01003336
Edward Cree832dc9e2015-07-21 15:09:31 +01003337 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3338 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003339 unsigned int flags;
3340
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01003341 rc = efx_mcdi_set_workaround(efx,
3342 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003343 true, &flags);
3344
3345 if (!rc) {
3346 if (flags &
3347 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3348 netif_info(efx, drv, efx->net_dev,
3349 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00003350
3351 /* With MCFW v4.6.x and earlier, the
3352 * boot count will have incremented,
3353 * so re-read the warm_boot_count
3354 * value now to ensure this function
3355 * doesn't think it has changed next
3356 * time it checks.
3357 */
3358 rc = efx_ef10_get_warm_boot_count(efx);
3359 if (rc >= 0) {
3360 nic_data->warm_boot_count = rc;
3361 rc = 0;
3362 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003363 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003364 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003365 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01003366 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003367 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003368 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003369 }
3370
3371 if (!rc)
3372 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003373
3374fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003375 efx_ef10_ev_fini(channel);
3376 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003377}
3378
3379static void efx_ef10_ev_remove(struct efx_channel *channel)
3380{
3381 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3382}
3383
3384static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3385 unsigned int rx_queue_label)
3386{
3387 struct efx_nic *efx = rx_queue->efx;
3388
3389 netif_info(efx, hw, efx->net_dev,
3390 "rx event arrived on queue %d labeled as queue %u\n",
3391 efx_rx_queue_index(rx_queue), rx_queue_label);
3392
3393 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3394}
3395
3396static void
3397efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3398 unsigned int actual, unsigned int expected)
3399{
3400 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3401 struct efx_nic *efx = rx_queue->efx;
3402
3403 netif_info(efx, hw, efx->net_dev,
3404 "dropped %d events (index=%d expected=%d)\n",
3405 dropped, actual, expected);
3406
3407 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3408}
3409
3410/* partially received RX was aborted. clean up. */
3411static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3412{
3413 unsigned int rx_desc_ptr;
3414
Ben Hutchings8127d662013-08-29 19:19:29 +01003415 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3416 "scattered RX aborted (dropping %u buffers)\n",
3417 rx_queue->scatter_n);
3418
3419 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3420
3421 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3422 0, EFX_RX_PKT_DISCARD);
3423
3424 rx_queue->removed_count += rx_queue->scatter_n;
3425 rx_queue->scatter_n = 0;
3426 rx_queue->scatter_len = 0;
3427 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3428}
3429
Jon Coopera0ee3542017-02-08 16:50:40 +00003430static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3431 unsigned int n_packets,
3432 unsigned int rx_encap_hdr,
3433 unsigned int rx_l3_class,
3434 unsigned int rx_l4_class,
3435 const efx_qword_t *event)
3436{
3437 struct efx_nic *efx = channel->efx;
Edward Cree69787292017-10-31 14:29:47 +00003438 bool handled = false;
Jon Coopera0ee3542017-02-08 16:50:40 +00003439
3440 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
Edward Cree69787292017-10-31 14:29:47 +00003441 if (!(efx->net_dev->features & NETIF_F_RXALL)) {
3442 if (!efx->loopback_selftest)
3443 channel->n_rx_eth_crc_err += n_packets;
3444 return EFX_RX_PKT_DISCARD;
3445 }
3446 handled = true;
Jon Coopera0ee3542017-02-08 16:50:40 +00003447 }
3448 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3449 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3450 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3451 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3452 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3453 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3454 netdev_WARN(efx->net_dev,
3455 "invalid class for RX_IPCKSUM_ERR: event="
3456 EFX_QWORD_FMT "\n",
3457 EFX_QWORD_VAL(*event));
3458 if (!efx->loopback_selftest)
3459 *(rx_encap_hdr ?
3460 &channel->n_rx_outer_ip_hdr_chksum_err :
3461 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3462 return 0;
3463 }
3464 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3465 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3466 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3467 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003468 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3469 rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
Jon Coopera0ee3542017-02-08 16:50:40 +00003470 netdev_WARN(efx->net_dev,
3471 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3472 EFX_QWORD_FMT "\n",
3473 EFX_QWORD_VAL(*event));
3474 if (!efx->loopback_selftest)
3475 *(rx_encap_hdr ?
3476 &channel->n_rx_outer_tcp_udp_chksum_err :
3477 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3478 return 0;
3479 }
3480 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3481 if (unlikely(!rx_encap_hdr))
3482 netdev_WARN(efx->net_dev,
3483 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3484 EFX_QWORD_FMT "\n",
3485 EFX_QWORD_VAL(*event));
3486 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3487 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3488 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3489 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3490 netdev_WARN(efx->net_dev,
3491 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3492 EFX_QWORD_FMT "\n",
3493 EFX_QWORD_VAL(*event));
3494 if (!efx->loopback_selftest)
3495 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3496 return 0;
3497 }
3498 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3499 if (unlikely(!rx_encap_hdr))
3500 netdev_WARN(efx->net_dev,
3501 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3502 EFX_QWORD_FMT "\n",
3503 EFX_QWORD_VAL(*event));
3504 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3505 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003506 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3507 rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
Jon Coopera0ee3542017-02-08 16:50:40 +00003508 netdev_WARN(efx->net_dev,
3509 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3510 EFX_QWORD_FMT "\n",
3511 EFX_QWORD_VAL(*event));
3512 if (!efx->loopback_selftest)
3513 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3514 return 0;
3515 }
3516
Edward Cree69787292017-10-31 14:29:47 +00003517 WARN_ON(!handled); /* No error bits were recognised */
Jon Coopera0ee3542017-02-08 16:50:40 +00003518 return 0;
3519}
3520
Ben Hutchings8127d662013-08-29 19:19:29 +01003521static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3522 const efx_qword_t *event)
3523{
Jon Coopera0ee3542017-02-08 16:50:40 +00003524 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3525 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
Ben Hutchings8127d662013-08-29 19:19:29 +01003526 unsigned int n_descs, n_packets, i;
3527 struct efx_nic *efx = channel->efx;
Jon Coopera0ee3542017-02-08 16:50:40 +00003528 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003529 struct efx_rx_queue *rx_queue;
Jon Coopera0ee3542017-02-08 16:50:40 +00003530 efx_qword_t errors;
Ben Hutchings8127d662013-08-29 19:19:29 +01003531 bool rx_cont;
3532 u16 flags = 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 /* Basic packet information */
3538 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3539 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3540 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
Jon Coopera0ee3542017-02-08 16:50:40 +00003541 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003542 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003543 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
Jon Coopera0ee3542017-02-08 16:50:40 +00003544 rx_encap_hdr =
3545 nic_data->datapath_caps &
3546 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3547 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3548 ESE_EZ_ENCAP_HDR_NONE;
Ben Hutchings8127d662013-08-29 19:19:29 +01003549
Ben Hutchings48ce5632013-11-01 16:42:44 +00003550 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3551 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3552 EFX_QWORD_FMT "\n",
3553 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003554
3555 rx_queue = efx_channel_get_rx_queue(channel);
3556
3557 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3558 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3559
3560 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3561 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3562
3563 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003564 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3565
Ben Hutchings8127d662013-08-29 19:19:29 +01003566 /* detect rx abort */
3567 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003568 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3569 netdev_WARN(efx->net_dev,
3570 "invalid RX abort: scatter_n=%u event="
3571 EFX_QWORD_FMT "\n",
3572 rx_queue->scatter_n,
3573 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003574 efx_ef10_handle_rx_abort(rx_queue);
3575 return 0;
3576 }
3577
Ben Hutchings92a04162013-09-24 23:21:57 +01003578 /* Check that RX completion merging is valid, i.e.
3579 * the current firmware supports it and this is a
3580 * non-scattered packet.
3581 */
3582 if (!(nic_data->datapath_caps &
3583 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3584 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003585 efx_ef10_handle_rx_bad_lbits(
3586 rx_queue, next_ptr_lbits,
3587 (rx_queue->removed_count +
3588 rx_queue->scatter_n + 1) &
3589 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3590 return 0;
3591 }
3592
3593 /* Merged completion for multiple non-scattered packets */
3594 rx_queue->scatter_n = 1;
3595 rx_queue->scatter_len = 0;
3596 n_packets = n_descs;
3597 ++channel->n_rx_merge_events;
3598 channel->n_rx_merge_packets += n_packets;
3599 flags |= EFX_RX_PKT_PREFIX_LEN;
3600 } else {
3601 ++rx_queue->scatter_n;
3602 rx_queue->scatter_len += rx_bytes;
3603 if (rx_cont)
3604 return 0;
3605 n_packets = 1;
3606 }
3607
Jon Coopera0ee3542017-02-08 16:50:40 +00003608 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3609 ESF_DZ_RX_IPCKSUM_ERR, 1,
3610 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3611 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3612 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3613 EFX_AND_QWORD(errors, *event, errors);
3614 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3615 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
Edward Cree90d2ea92017-02-10 17:34:59 +00003616 rx_encap_hdr,
Jon Coopera0ee3542017-02-08 16:50:40 +00003617 rx_l3_class, rx_l4_class,
Edward Cree90d2ea92017-02-10 17:34:59 +00003618 event);
Jon Coopera0ee3542017-02-08 16:50:40 +00003619 } else {
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003620 bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
3621 rx_l4_class == ESE_FZ_L4_CLASS_UDP;
Jon Cooperda50ae22017-02-08 16:51:02 +00003622
3623 switch (rx_encap_hdr) {
3624 case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
3625 flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
3626 if (tcpudp)
3627 flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
3628 break;
3629 case ESE_EZ_ENCAP_HDR_GRE:
3630 case ESE_EZ_ENCAP_HDR_NONE:
3631 if (tcpudp)
3632 flags |= EFX_RX_PKT_CSUMMED;
3633 break;
3634 default:
3635 netdev_WARN(efx->net_dev,
3636 "unknown encapsulation type: event="
3637 EFX_QWORD_FMT "\n",
3638 EFX_QWORD_VAL(*event));
3639 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003640 }
3641
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003642 if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
Ben Hutchings8127d662013-08-29 19:19:29 +01003643 flags |= EFX_RX_PKT_TCP;
3644
3645 channel->irq_mod_score += 2 * n_packets;
3646
3647 /* Handle received packet(s) */
3648 for (i = 0; i < n_packets; i++) {
3649 efx_rx_packet(rx_queue,
3650 rx_queue->removed_count & rx_queue->ptr_mask,
3651 rx_queue->scatter_n, rx_queue->scatter_len,
3652 flags);
3653 rx_queue->removed_count += rx_queue->scatter_n;
3654 }
3655
3656 rx_queue->scatter_n = 0;
3657 rx_queue->scatter_len = 0;
3658
3659 return n_packets;
3660}
3661
Martin Habetsb9b603d42018-01-25 17:24:43 +00003662static u32 efx_ef10_extract_event_ts(efx_qword_t *event)
3663{
3664 u32 tstamp;
3665
3666 tstamp = EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_HI);
3667 tstamp <<= 16;
3668 tstamp |= EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_LO);
3669
3670 return tstamp;
3671}
3672
Bert Kenward5227ecc2018-01-25 17:24:20 +00003673static void
Ben Hutchings8127d662013-08-29 19:19:29 +01003674efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3675{
3676 struct efx_nic *efx = channel->efx;
3677 struct efx_tx_queue *tx_queue;
3678 unsigned int tx_ev_desc_ptr;
3679 unsigned int tx_ev_q_label;
Martin Habetsb9b603d42018-01-25 17:24:43 +00003680 unsigned int tx_ev_type;
3681 u64 ts_part;
Ben Hutchings8127d662013-08-29 19:19:29 +01003682
Mark Rutland6aa7de02017-10-23 14:07:29 -07003683 if (unlikely(READ_ONCE(efx->reset_pending)))
Bert Kenward5227ecc2018-01-25 17:24:20 +00003684 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01003685
3686 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
Bert Kenward5227ecc2018-01-25 17:24:20 +00003687 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01003688
Martin Habetsb9b603d42018-01-25 17:24:43 +00003689 /* Get the transmit queue */
Ben Hutchings8127d662013-08-29 19:19:29 +01003690 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3691 tx_queue = efx_channel_get_tx_queue(channel,
3692 tx_ev_q_label % EFX_TXQ_TYPES);
Martin Habetsb9b603d42018-01-25 17:24:43 +00003693
3694 if (!tx_queue->timestamping) {
3695 /* Transmit completion */
3696 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3697 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3698 return;
3699 }
3700
3701 /* Transmit timestamps are only available for 8XXX series. They result
3702 * in three events per packet. These occur in order, and are:
3703 * - the normal completion event
3704 * - the low part of the timestamp
3705 * - the high part of the timestamp
3706 *
3707 * Each part of the timestamp is itself split across two 16 bit
3708 * fields in the event.
3709 */
3710 tx_ev_type = EFX_QWORD_FIELD(*event, ESF_EZ_TX_SOFT1);
3711
3712 switch (tx_ev_type) {
3713 case TX_TIMESTAMP_EVENT_TX_EV_COMPLETION:
3714 /* In case of Queue flush or FLR, we might have received
3715 * the previous TX completion event but not the Timestamp
3716 * events.
3717 */
3718 if (tx_queue->completed_desc_ptr != tx_queue->ptr_mask)
3719 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3720
3721 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event,
3722 ESF_DZ_TX_DESCR_INDX);
3723 tx_queue->completed_desc_ptr =
3724 tx_ev_desc_ptr & tx_queue->ptr_mask;
3725 break;
3726
3727 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_LO:
3728 ts_part = efx_ef10_extract_event_ts(event);
3729 tx_queue->completed_timestamp_minor = ts_part;
3730 break;
3731
3732 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_HI:
3733 ts_part = efx_ef10_extract_event_ts(event);
3734 tx_queue->completed_timestamp_major = ts_part;
3735
3736 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3737 tx_queue->completed_desc_ptr = tx_queue->ptr_mask;
3738 break;
3739
3740 default:
3741 netif_err(efx, hw, efx->net_dev,
3742 "channel %d unknown tx event type %d (data "
3743 EFX_QWORD_FMT ")\n",
3744 channel->channel, tx_ev_type,
3745 EFX_QWORD_VAL(*event));
3746 break;
3747 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003748}
3749
3750static void
3751efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3752{
3753 struct efx_nic *efx = channel->efx;
3754 int subcode;
3755
3756 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3757
3758 switch (subcode) {
3759 case ESE_DZ_DRV_TIMER_EV:
3760 case ESE_DZ_DRV_WAKE_UP_EV:
3761 break;
3762 case ESE_DZ_DRV_START_UP_EV:
3763 /* event queue init complete. ok. */
3764 break;
3765 default:
3766 netif_err(efx, hw, efx->net_dev,
3767 "channel %d unknown driver event type %d"
3768 " (data " EFX_QWORD_FMT ")\n",
3769 channel->channel, subcode,
3770 EFX_QWORD_VAL(*event));
3771
3772 }
3773}
3774
3775static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3776 efx_qword_t *event)
3777{
3778 struct efx_nic *efx = channel->efx;
3779 u32 subcode;
3780
3781 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3782
3783 switch (subcode) {
3784 case EFX_EF10_TEST:
3785 channel->event_test_cpu = raw_smp_processor_id();
3786 break;
3787 case EFX_EF10_REFILL:
3788 /* The queue must be empty, so we won't receive any rx
3789 * events, so efx_process_channel() won't refill the
3790 * queue. Refill it here
3791 */
Jon Coopercce28792013-10-02 11:04:14 +01003792 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003793 break;
3794 default:
3795 netif_err(efx, hw, efx->net_dev,
3796 "channel %d unknown driver event type %u"
3797 " (data " EFX_QWORD_FMT ")\n",
3798 channel->channel, (unsigned) subcode,
3799 EFX_QWORD_VAL(*event));
3800 }
3801}
3802
3803static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3804{
3805 struct efx_nic *efx = channel->efx;
3806 efx_qword_t event, *p_event;
3807 unsigned int read_ptr;
3808 int ev_code;
Ben Hutchings8127d662013-08-29 19:19:29 +01003809 int spent = 0;
3810
Eric W. Biederman75363a42014-03-14 18:11:22 -07003811 if (quota <= 0)
3812 return spent;
3813
Ben Hutchings8127d662013-08-29 19:19:29 +01003814 read_ptr = channel->eventq_read_ptr;
3815
3816 for (;;) {
3817 p_event = efx_event(channel, read_ptr);
3818 event = *p_event;
3819
3820 if (!efx_event_present(&event))
3821 break;
3822
3823 EFX_SET_QWORD(*p_event);
3824
3825 ++read_ptr;
3826
3827 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3828
3829 netif_vdbg(efx, drv, efx->net_dev,
3830 "processing event on %d " EFX_QWORD_FMT "\n",
3831 channel->channel, EFX_QWORD_VAL(event));
3832
3833 switch (ev_code) {
3834 case ESE_DZ_EV_CODE_MCDI_EV:
3835 efx_mcdi_process_event(channel, &event);
3836 break;
3837 case ESE_DZ_EV_CODE_RX_EV:
3838 spent += efx_ef10_handle_rx_event(channel, &event);
3839 if (spent >= quota) {
3840 /* XXX can we split a merged event to
3841 * avoid going over-quota?
3842 */
3843 spent = quota;
3844 goto out;
3845 }
3846 break;
3847 case ESE_DZ_EV_CODE_TX_EV:
Bert Kenward5227ecc2018-01-25 17:24:20 +00003848 efx_ef10_handle_tx_event(channel, &event);
Ben Hutchings8127d662013-08-29 19:19:29 +01003849 break;
3850 case ESE_DZ_EV_CODE_DRIVER_EV:
3851 efx_ef10_handle_driver_event(channel, &event);
3852 if (++spent == quota)
3853 goto out;
3854 break;
3855 case EFX_EF10_DRVGEN_EV:
3856 efx_ef10_handle_driver_generated_event(channel, &event);
3857 break;
3858 default:
3859 netif_err(efx, hw, efx->net_dev,
3860 "channel %d unknown event type %d"
3861 " (data " EFX_QWORD_FMT ")\n",
3862 channel->channel, ev_code,
3863 EFX_QWORD_VAL(event));
3864 }
3865 }
3866
3867out:
3868 channel->eventq_read_ptr = read_ptr;
3869 return spent;
3870}
3871
3872static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3873{
3874 struct efx_nic *efx = channel->efx;
3875 efx_dword_t rptr;
3876
3877 if (EFX_EF10_WORKAROUND_35388(efx)) {
3878 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3879 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3880 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3881 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3882
3883 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3884 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3885 ERF_DD_EVQ_IND_RPTR,
3886 (channel->eventq_read_ptr &
3887 channel->eventq_mask) >>
3888 ERF_DD_EVQ_IND_RPTR_WIDTH);
3889 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3890 channel->channel);
3891 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3892 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3893 ERF_DD_EVQ_IND_RPTR,
3894 channel->eventq_read_ptr &
3895 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3896 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3897 channel->channel);
3898 } else {
3899 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3900 channel->eventq_read_ptr &
3901 channel->eventq_mask);
3902 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3903 }
3904}
3905
3906static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3907{
3908 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3909 struct efx_nic *efx = channel->efx;
3910 efx_qword_t event;
3911 int rc;
3912
3913 EFX_POPULATE_QWORD_2(event,
3914 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3915 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3916
3917 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3918
3919 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3920 * already swapped the data to little-endian order.
3921 */
3922 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3923 sizeof(efx_qword_t));
3924
3925 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3926 NULL, 0, NULL);
3927 if (rc != 0)
3928 goto fail;
3929
3930 return;
3931
3932fail:
3933 WARN_ON(true);
3934 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3935}
3936
3937void efx_ef10_handle_drain_event(struct efx_nic *efx)
3938{
3939 if (atomic_dec_and_test(&efx->active_queues))
3940 wake_up(&efx->flush_wq);
3941
3942 WARN_ON(atomic_read(&efx->active_queues) < 0);
3943}
3944
3945static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3946{
3947 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3948 struct efx_channel *channel;
3949 struct efx_tx_queue *tx_queue;
3950 struct efx_rx_queue *rx_queue;
3951 int pending;
3952
3953 /* If the MC has just rebooted, the TX/RX queues will have already been
3954 * torn down, but efx->active_queues needs to be set to zero.
3955 */
3956 if (nic_data->must_realloc_vis) {
3957 atomic_set(&efx->active_queues, 0);
3958 return 0;
3959 }
3960
3961 /* Do not attempt to write to the NIC during EEH recovery */
3962 if (efx->state != STATE_RECOVERY) {
3963 efx_for_each_channel(channel, efx) {
3964 efx_for_each_channel_rx_queue(rx_queue, channel)
3965 efx_ef10_rx_fini(rx_queue);
3966 efx_for_each_channel_tx_queue(tx_queue, channel)
3967 efx_ef10_tx_fini(tx_queue);
3968 }
3969
3970 wait_event_timeout(efx->flush_wq,
3971 atomic_read(&efx->active_queues) == 0,
3972 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3973 pending = atomic_read(&efx->active_queues);
3974 if (pending) {
3975 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3976 pending);
3977 return -ETIMEDOUT;
3978 }
3979 }
3980
3981 return 0;
3982}
3983
Edward Creee2835462014-04-16 19:27:48 +01003984static void efx_ef10_prepare_flr(struct efx_nic *efx)
3985{
3986 atomic_set(&efx->active_queues, 0);
3987}
3988
Ben Hutchings8127d662013-08-29 19:19:29 +01003989static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3990 const struct efx_filter_spec *right)
3991{
3992 if ((left->match_flags ^ right->match_flags) |
3993 ((left->flags ^ right->flags) &
3994 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3995 return false;
3996
3997 return memcmp(&left->outer_vid, &right->outer_vid,
3998 sizeof(struct efx_filter_spec) -
3999 offsetof(struct efx_filter_spec, outer_vid)) == 0;
4000}
4001
4002static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
4003{
4004 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
4005 return jhash2((const u32 *)&spec->outer_vid,
4006 (sizeof(struct efx_filter_spec) -
4007 offsetof(struct efx_filter_spec, outer_vid)) / 4,
4008 0);
4009 /* XXX should we randomise the initval? */
4010}
4011
4012/* Decide whether a filter should be exclusive or else should allow
4013 * delivery to additional recipients. Currently we decide that
4014 * filters for specific local unicast MAC and IP addresses are
4015 * exclusive.
4016 */
4017static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
4018{
4019 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
4020 !is_multicast_ether_addr(spec->loc_mac))
4021 return true;
4022
4023 if ((spec->match_flags &
4024 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
4025 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
4026 if (spec->ether_type == htons(ETH_P_IP) &&
4027 !ipv4_is_multicast(spec->loc_host[0]))
4028 return true;
4029 if (spec->ether_type == htons(ETH_P_IPV6) &&
4030 ((const u8 *)spec->loc_host)[0] != 0xff)
4031 return true;
4032 }
4033
4034 return false;
4035}
4036
4037static struct efx_filter_spec *
4038efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
4039 unsigned int filter_idx)
4040{
4041 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
4042 ~EFX_EF10_FILTER_FLAGS);
4043}
4044
4045static unsigned int
4046efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
4047 unsigned int filter_idx)
4048{
4049 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
4050}
4051
4052static void
4053efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
4054 unsigned int filter_idx,
4055 const struct efx_filter_spec *spec,
4056 unsigned int flags)
4057{
4058 table->entry[filter_idx].spec = (unsigned long)spec | flags;
4059}
4060
Edward Cree9b410802017-01-27 15:02:52 +00004061static void
4062efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
4063 const struct efx_filter_spec *spec,
4064 efx_dword_t *inbuf)
4065{
4066 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
4067 u32 match_fields = 0, uc_match, mc_match;
4068
4069 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4070 efx_ef10_filter_is_exclusive(spec) ?
4071 MC_CMD_FILTER_OP_IN_OP_INSERT :
4072 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
4073
4074 /* Convert match flags and values. Unlike almost
4075 * everything else in MCDI, these fields are in
4076 * network byte order.
4077 */
4078#define COPY_VALUE(value, mcdi_field) \
4079 do { \
4080 match_fields |= \
4081 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4082 mcdi_field ## _LBN; \
4083 BUILD_BUG_ON( \
4084 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
4085 sizeof(value)); \
4086 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
4087 &value, sizeof(value)); \
4088 } while (0)
4089#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
4090 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
4091 COPY_VALUE(spec->gen_field, mcdi_field); \
4092 }
4093 /* Handle encap filters first. They will always be mismatch
4094 * (unknown UC or MC) filters
4095 */
4096 if (encap_type) {
4097 /* ether_type and outer_ip_proto need to be variables
4098 * because COPY_VALUE wants to memcpy them
4099 */
4100 __be16 ether_type =
4101 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
4102 ETH_P_IPV6 : ETH_P_IP);
4103 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
4104 u8 outer_ip_proto;
4105
4106 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
4107 case EFX_ENCAP_TYPE_VXLAN:
4108 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
4109 /* fallthrough */
4110 case EFX_ENCAP_TYPE_GENEVE:
4111 COPY_VALUE(ether_type, ETHER_TYPE);
4112 outer_ip_proto = IPPROTO_UDP;
4113 COPY_VALUE(outer_ip_proto, IP_PROTO);
4114 /* We always need to set the type field, even
4115 * though we're not matching on the TNI.
4116 */
4117 MCDI_POPULATE_DWORD_1(inbuf,
4118 FILTER_OP_EXT_IN_VNI_OR_VSID,
4119 FILTER_OP_EXT_IN_VNI_TYPE,
4120 vni_type);
4121 break;
4122 case EFX_ENCAP_TYPE_NVGRE:
4123 COPY_VALUE(ether_type, ETHER_TYPE);
4124 outer_ip_proto = IPPROTO_GRE;
4125 COPY_VALUE(outer_ip_proto, IP_PROTO);
4126 break;
4127 default:
4128 WARN_ON(1);
4129 }
4130
4131 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4132 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4133 } else {
4134 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4135 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4136 }
4137
4138 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
4139 match_fields |=
4140 is_multicast_ether_addr(spec->loc_mac) ?
4141 1 << mc_match :
4142 1 << uc_match;
4143 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
4144 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
4145 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
4146 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
4147 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
4148 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
4149 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
4150 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
4151 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
4152 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
4153#undef COPY_FIELD
4154#undef COPY_VALUE
4155 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
4156 match_fields);
4157}
4158
Ben Hutchings8127d662013-08-29 19:19:29 +01004159static void efx_ef10_filter_push_prep(struct efx_nic *efx,
4160 const struct efx_filter_spec *spec,
4161 efx_dword_t *inbuf, u64 handle,
Edward Cree42356d92018-03-08 15:45:17 +00004162 struct efx_rss_context *ctx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004163 bool replacing)
4164{
4165 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01004166 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01004167
Edward Cree9b410802017-01-27 15:02:52 +00004168 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004169
Edward Cree42356d92018-03-08 15:45:17 +00004170 /* If RSS filter, caller better have given us an RSS context */
4171 if (flags & EFX_FILTER_FLAG_RX_RSS) {
4172 /* We don't have the ability to return an error, so we'll just
4173 * log a warning and disable RSS for the filter.
4174 */
4175 if (WARN_ON_ONCE(!ctx))
4176 flags &= ~EFX_FILTER_FLAG_RX_RSS;
4177 else if (WARN_ON_ONCE(ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID))
4178 flags &= ~EFX_FILTER_FLAG_RX_RSS;
4179 }
Jon Cooperdcb41232016-04-25 16:51:00 +01004180
Ben Hutchings8127d662013-08-29 19:19:29 +01004181 if (replacing) {
4182 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4183 MC_CMD_FILTER_OP_IN_OP_REPLACE);
4184 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
4185 } else {
Edward Cree9b410802017-01-27 15:02:52 +00004186 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01004187 }
4188
Daniel Pieczko45b24492015-05-06 00:57:14 +01004189 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004190 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
4191 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4192 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
4193 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01004194 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01004195 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
4196 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00004197 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
4198 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4199 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004200 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01004201 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01004202 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
4203 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01004204 if (flags & EFX_FILTER_FLAG_RX_RSS)
Edward Cree42356d92018-03-08 15:45:17 +00004205 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, ctx->context_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004206}
4207
4208static int efx_ef10_filter_push(struct efx_nic *efx,
Edward Cree42356d92018-03-08 15:45:17 +00004209 const struct efx_filter_spec *spec, u64 *handle,
4210 struct efx_rss_context *ctx, bool replacing)
Ben Hutchings8127d662013-08-29 19:19:29 +01004211{
Edward Cree9b410802017-01-27 15:02:52 +00004212 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4213 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004214 int rc;
4215
Edward Cree42356d92018-03-08 15:45:17 +00004216 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, ctx, replacing);
Ben Hutchings8127d662013-08-29 19:19:29 +01004217 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4218 outbuf, sizeof(outbuf), NULL);
4219 if (rc == 0)
4220 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01004221 if (rc == -ENOSPC)
4222 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01004223 return rc;
4224}
4225
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004226static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01004227{
Edward Cree9b410802017-01-27 15:02:52 +00004228 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004229 unsigned int match_flags = spec->match_flags;
Edward Cree9b410802017-01-27 15:02:52 +00004230 unsigned int uc_match, mc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004231 u32 mcdi_flags = 0;
4232
Edward Cree9b410802017-01-27 15:02:52 +00004233#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
4234 unsigned int old_match_flags = match_flags; \
4235 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
4236 if (match_flags != old_match_flags) \
4237 mcdi_flags |= \
4238 (1 << ((encap) ? \
4239 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
4240 mcdi_field ## _LBN : \
4241 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
4242 mcdi_field ## _LBN)); \
4243 }
4244 /* inner or outer based on encap type */
4245 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
4246 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
4247 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
4248 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
4249 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
4250 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
4251 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
4252 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
4253 /* always outer */
4254 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
4255 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
4256#undef MAP_FILTER_TO_MCDI_FLAG
4257
4258 /* special handling for encap type, and mismatch */
4259 if (encap_type) {
4260 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
4261 mcdi_flags |=
4262 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4263 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4264
4265 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4266 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4267 } else {
4268 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4269 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4270 }
4271
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004272 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
4273 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
4274 mcdi_flags |=
4275 is_multicast_ether_addr(spec->loc_mac) ?
Edward Cree9b410802017-01-27 15:02:52 +00004276 1 << mc_match :
4277 1 << uc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004278 }
4279
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004280 /* Did we map them all? */
4281 WARN_ON_ONCE(match_flags);
4282
4283 return mcdi_flags;
4284}
4285
4286static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
4287 const struct efx_filter_spec *spec)
4288{
4289 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004290 unsigned int match_pri;
4291
4292 for (match_pri = 0;
4293 match_pri < table->rx_match_count;
4294 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004295 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004296 return match_pri;
4297
4298 return -EPROTONOSUPPORT;
4299}
4300
4301static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4302 struct efx_filter_spec *spec,
4303 bool replace_equal)
4304{
4305 struct efx_ef10_filter_table *table = efx->filter_state;
4306 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4307 struct efx_filter_spec *saved_spec;
Edward Cree42356d92018-03-08 15:45:17 +00004308 struct efx_rss_context *ctx = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004309 unsigned int match_pri, hash;
4310 unsigned int priv_flags;
4311 bool replacing = false;
4312 int ins_index = -1;
4313 DEFINE_WAIT(wait);
4314 bool is_mc_recip;
4315 s32 rc;
4316
4317 /* For now, only support RX filters */
4318 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4319 EFX_FILTER_FLAG_RX)
4320 return -EINVAL;
4321
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004322 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004323 if (rc < 0)
4324 return rc;
4325 match_pri = rc;
4326
4327 hash = efx_ef10_filter_hash(spec);
4328 is_mc_recip = efx_filter_is_mc_recipient(spec);
4329 if (is_mc_recip)
4330 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4331
Edward Cree42356d92018-03-08 15:45:17 +00004332 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
4333 if (spec->rss_context)
4334 ctx = efx_find_rss_context_entry(spec->rss_context,
4335 &efx->rss_context.list);
4336 else
4337 ctx = &efx->rss_context;
4338 if (!ctx)
4339 return -ENOENT;
4340 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID)
4341 return -EOPNOTSUPP;
4342 }
4343
Ben Hutchings8127d662013-08-29 19:19:29 +01004344 /* Find any existing filters with the same match tuple or
4345 * else a free slot to insert at. If any of them are busy,
4346 * we have to wait and retry.
4347 */
4348 for (;;) {
4349 unsigned int depth = 1;
4350 unsigned int i;
4351
4352 spin_lock_bh(&efx->filter_lock);
4353
4354 for (;;) {
4355 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4356 saved_spec = efx_ef10_filter_entry_spec(table, i);
4357
4358 if (!saved_spec) {
4359 if (ins_index < 0)
4360 ins_index = i;
4361 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4362 if (table->entry[i].spec &
4363 EFX_EF10_FILTER_FLAG_BUSY)
4364 break;
4365 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004366 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004367 rc = -EPERM;
4368 goto out_unlock;
4369 }
4370 if (!is_mc_recip) {
4371 /* This is the only one */
4372 if (spec->priority ==
4373 saved_spec->priority &&
4374 !replace_equal) {
4375 rc = -EEXIST;
4376 goto out_unlock;
4377 }
4378 ins_index = i;
4379 goto found;
4380 } else if (spec->priority >
4381 saved_spec->priority ||
4382 (spec->priority ==
4383 saved_spec->priority &&
4384 replace_equal)) {
4385 if (ins_index < 0)
4386 ins_index = i;
4387 else
4388 __set_bit(depth, mc_rem_map);
4389 }
4390 }
4391
4392 /* Once we reach the maximum search depth, use
4393 * the first suitable slot or return -EBUSY if
4394 * there was none
4395 */
4396 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4397 if (ins_index < 0) {
4398 rc = -EBUSY;
4399 goto out_unlock;
4400 }
4401 goto found;
4402 }
4403
4404 ++depth;
4405 }
4406
4407 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4408 spin_unlock_bh(&efx->filter_lock);
4409 schedule();
4410 }
4411
4412found:
4413 /* Create a software table entry if necessary, and mark it
4414 * busy. We might yet fail to insert, but any attempt to
4415 * insert a conflicting filter while we're waiting for the
4416 * firmware must find the busy entry.
4417 */
4418 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4419 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004420 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4421 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004422 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004423 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4424 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004425 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004426 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01004427 rc = ins_index;
4428 goto out_unlock;
4429 }
4430 replacing = true;
4431 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4432 } else {
4433 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4434 if (!saved_spec) {
4435 rc = -ENOMEM;
4436 goto out_unlock;
4437 }
4438 *saved_spec = *spec;
4439 priv_flags = 0;
4440 }
4441 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4442 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4443
4444 /* Mark lower-priority multicast recipients busy prior to removal */
4445 if (is_mc_recip) {
4446 unsigned int depth, i;
4447
4448 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4449 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4450 if (test_bit(depth, mc_rem_map))
4451 table->entry[i].spec |=
4452 EFX_EF10_FILTER_FLAG_BUSY;
4453 }
4454 }
4455
4456 spin_unlock_bh(&efx->filter_lock);
4457
4458 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
Edward Cree42356d92018-03-08 15:45:17 +00004459 ctx, replacing);
Ben Hutchings8127d662013-08-29 19:19:29 +01004460
4461 /* Finalise the software table entry */
4462 spin_lock_bh(&efx->filter_lock);
4463 if (rc == 0) {
4464 if (replacing) {
4465 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004466 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4467 saved_spec->flags |=
4468 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004469 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004470 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004471 saved_spec->flags |= spec->flags;
4472 saved_spec->rss_context = spec->rss_context;
4473 saved_spec->dmaq_id = spec->dmaq_id;
4474 }
4475 } else if (!replacing) {
4476 kfree(saved_spec);
4477 saved_spec = NULL;
4478 }
4479 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4480
4481 /* Remove and finalise entries for lower-priority multicast
4482 * recipients
4483 */
4484 if (is_mc_recip) {
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004485 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004486 unsigned int depth, i;
4487
4488 memset(inbuf, 0, sizeof(inbuf));
4489
4490 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4491 if (!test_bit(depth, mc_rem_map))
4492 continue;
4493
4494 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4495 saved_spec = efx_ef10_filter_entry_spec(table, i);
4496 priv_flags = efx_ef10_filter_entry_flags(table, i);
4497
4498 if (rc == 0) {
4499 spin_unlock_bh(&efx->filter_lock);
4500 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4501 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4502 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4503 table->entry[i].handle);
4504 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4505 inbuf, sizeof(inbuf),
4506 NULL, 0, NULL);
4507 spin_lock_bh(&efx->filter_lock);
4508 }
4509
4510 if (rc == 0) {
4511 kfree(saved_spec);
4512 saved_spec = NULL;
4513 priv_flags = 0;
4514 } else {
4515 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4516 }
4517 efx_ef10_filter_set_entry(table, i, saved_spec,
4518 priv_flags);
4519 }
4520 }
4521
4522 /* If successful, return the inserted filter ID */
4523 if (rc == 0)
Jon Cooper0ccb9982017-02-17 15:49:13 +00004524 rc = efx_ef10_make_filter_id(match_pri, ins_index);
Ben Hutchings8127d662013-08-29 19:19:29 +01004525
4526 wake_up_all(&table->waitq);
4527out_unlock:
4528 spin_unlock_bh(&efx->filter_lock);
4529 finish_wait(&table->waitq, &wait);
4530 return rc;
4531}
4532
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08004533static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01004534{
4535 /* no need to do anything here on EF10 */
4536}
4537
4538/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004539 * If !by_index, remove by ID
4540 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01004541 * Filter ID may come from userland and must be range-checked.
4542 */
4543static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004544 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004545 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01004546{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004547 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004548 struct efx_ef10_filter_table *table = efx->filter_state;
4549 MCDI_DECLARE_BUF(inbuf,
4550 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4551 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4552 struct efx_filter_spec *spec;
4553 DEFINE_WAIT(wait);
4554 int rc;
4555
4556 /* Find the software table entry and mark it busy. Don't
4557 * remove it yet; any attempt to update while we're waiting
4558 * for the firmware must find the busy entry.
4559 */
4560 for (;;) {
4561 spin_lock_bh(&efx->filter_lock);
4562 if (!(table->entry[filter_idx].spec &
4563 EFX_EF10_FILTER_FLAG_BUSY))
4564 break;
4565 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4566 spin_unlock_bh(&efx->filter_lock);
4567 schedule();
4568 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004569
Ben Hutchings8127d662013-08-29 19:19:29 +01004570 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004571 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004572 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004573 efx_ef10_filter_pri(table, spec) !=
Jon Cooper0ccb9982017-02-17 15:49:13 +00004574 efx_ef10_filter_get_unsafe_pri(filter_id))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004575 rc = -ENOENT;
4576 goto out_unlock;
4577 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004578
4579 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004580 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004581 /* Just remove flags */
4582 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004583 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004584 rc = 0;
4585 goto out_unlock;
4586 }
4587
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004588 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004589 rc = -ENOENT;
4590 goto out_unlock;
4591 }
4592
Ben Hutchings8127d662013-08-29 19:19:29 +01004593 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4594 spin_unlock_bh(&efx->filter_lock);
4595
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004596 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004597 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01004598
4599 struct efx_filter_spec new_spec = *spec;
4600
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004601 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004602 new_spec.flags = (EFX_FILTER_FLAG_RX |
Edward Cree42356d92018-03-08 15:45:17 +00004603 (efx_rss_active(&efx->rss_context) ?
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004604 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01004605 new_spec.dmaq_id = 0;
Edward Cree42356d92018-03-08 15:45:17 +00004606 new_spec.rss_context = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004607 rc = efx_ef10_filter_push(efx, &new_spec,
4608 &table->entry[filter_idx].handle,
Edward Cree42356d92018-03-08 15:45:17 +00004609 &efx->rss_context,
Ben Hutchings8127d662013-08-29 19:19:29 +01004610 true);
4611
4612 spin_lock_bh(&efx->filter_lock);
4613 if (rc == 0)
4614 *spec = new_spec;
4615 } else {
4616 /* Really remove the filter */
4617
4618 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4619 efx_ef10_filter_is_exclusive(spec) ?
4620 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4621 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4622 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4623 table->entry[filter_idx].handle);
Bert Kenward105eac62017-02-17 15:50:12 +00004624 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4625 inbuf, sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01004626
4627 spin_lock_bh(&efx->filter_lock);
Bert Kenward105eac62017-02-17 15:50:12 +00004628 if ((rc == 0) || (rc == -ENOENT)) {
4629 /* Filter removed OK or didn't actually exist */
Ben Hutchings8127d662013-08-29 19:19:29 +01004630 kfree(spec);
4631 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
Bert Kenward105eac62017-02-17 15:50:12 +00004632 } else {
4633 efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004634 MC_CMD_FILTER_OP_EXT_IN_LEN,
Bert Kenward105eac62017-02-17 15:50:12 +00004635 NULL, 0, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004636 }
4637 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004638
Ben Hutchings8127d662013-08-29 19:19:29 +01004639 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4640 wake_up_all(&table->waitq);
4641out_unlock:
4642 spin_unlock_bh(&efx->filter_lock);
4643 finish_wait(&table->waitq, &wait);
4644 return rc;
4645}
4646
4647static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4648 enum efx_filter_priority priority,
4649 u32 filter_id)
4650{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004651 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4652 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004653}
4654
Edward Cree8c915622016-06-15 17:49:05 +01004655static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4656 enum efx_filter_priority priority,
4657 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004658{
Edward Cree8c915622016-06-15 17:49:05 +01004659 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4660 return;
4661 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004662}
4663
Ben Hutchings8127d662013-08-29 19:19:29 +01004664static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4665 enum efx_filter_priority priority,
4666 u32 filter_id, struct efx_filter_spec *spec)
4667{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004668 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004669 struct efx_ef10_filter_table *table = efx->filter_state;
4670 const struct efx_filter_spec *saved_spec;
4671 int rc;
4672
4673 spin_lock_bh(&efx->filter_lock);
4674 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4675 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004676 efx_ef10_filter_pri(table, saved_spec) ==
Jon Cooper0ccb9982017-02-17 15:49:13 +00004677 efx_ef10_filter_get_unsafe_pri(filter_id)) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004678 *spec = *saved_spec;
4679 rc = 0;
4680 } else {
4681 rc = -ENOENT;
4682 }
4683 spin_unlock_bh(&efx->filter_lock);
4684 return rc;
4685}
4686
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004687static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004688 enum efx_filter_priority priority)
4689{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004690 unsigned int priority_mask;
4691 unsigned int i;
4692 int rc;
4693
4694 priority_mask = (((1U << (priority + 1)) - 1) &
4695 ~(1U << EFX_FILTER_PRI_AUTO));
4696
4697 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4698 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4699 i, true);
4700 if (rc && rc != -ENOENT)
4701 return rc;
4702 }
4703
4704 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004705}
4706
4707static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4708 enum efx_filter_priority priority)
4709{
4710 struct efx_ef10_filter_table *table = efx->filter_state;
4711 unsigned int filter_idx;
4712 s32 count = 0;
4713
4714 spin_lock_bh(&efx->filter_lock);
4715 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4716 if (table->entry[filter_idx].spec &&
4717 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4718 priority)
4719 ++count;
4720 }
4721 spin_unlock_bh(&efx->filter_lock);
4722 return count;
4723}
4724
4725static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4726{
4727 struct efx_ef10_filter_table *table = efx->filter_state;
4728
Jon Cooper0ccb9982017-02-17 15:49:13 +00004729 return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
Ben Hutchings8127d662013-08-29 19:19:29 +01004730}
4731
4732static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4733 enum efx_filter_priority priority,
4734 u32 *buf, u32 size)
4735{
4736 struct efx_ef10_filter_table *table = efx->filter_state;
4737 struct efx_filter_spec *spec;
4738 unsigned int filter_idx;
4739 s32 count = 0;
4740
4741 spin_lock_bh(&efx->filter_lock);
4742 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4743 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4744 if (spec && spec->priority == priority) {
4745 if (count == size) {
4746 count = -EMSGSIZE;
4747 break;
4748 }
Jon Cooper0ccb9982017-02-17 15:49:13 +00004749 buf[count++] =
4750 efx_ef10_make_filter_id(
4751 efx_ef10_filter_pri(table, spec),
Ben Hutchings8127d662013-08-29 19:19:29 +01004752 filter_idx);
4753 }
4754 }
4755 spin_unlock_bh(&efx->filter_lock);
4756 return count;
4757}
4758
4759#ifdef CONFIG_RFS_ACCEL
4760
Ben Hutchings8127d662013-08-29 19:19:29 +01004761static void
4762efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4763 unsigned long filter_idx,
4764 int rc, efx_dword_t *outbuf,
4765 size_t outlen_actual);
4766
4767static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4768 unsigned int filter_idx)
4769{
4770 struct efx_ef10_filter_table *table = efx->filter_state;
Edward Cree3af0f342018-03-27 17:41:59 +01004771 struct efx_filter_spec *spec;
Ben Hutchings8127d662013-08-29 19:19:29 +01004772 MCDI_DECLARE_BUF(inbuf,
4773 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4774 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
Edward Cree3af0f342018-03-27 17:41:59 +01004775 bool ret = true;
Ben Hutchings8127d662013-08-29 19:19:29 +01004776
Edward Cree3af0f342018-03-27 17:41:59 +01004777 spin_lock_bh(&efx->filter_lock);
4778 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004779 if (!spec ||
4780 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4781 spec->priority != EFX_FILTER_PRI_HINT ||
4782 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
Edward Cree3af0f342018-03-27 17:41:59 +01004783 flow_id, filter_idx)) {
4784 ret = false;
4785 goto out_unlock;
4786 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004787
4788 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4789 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4790 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4791 table->entry[filter_idx].handle);
4792 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4793 efx_ef10_filter_rfs_expire_complete, filter_idx))
Edward Cree3af0f342018-03-27 17:41:59 +01004794 ret = false;
4795 else
4796 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4797out_unlock:
4798 spin_unlock_bh(&efx->filter_lock);
4799 return ret;
Ben Hutchings8127d662013-08-29 19:19:29 +01004800}
4801
4802static void
4803efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4804 unsigned long filter_idx,
4805 int rc, efx_dword_t *outbuf,
4806 size_t outlen_actual)
4807{
4808 struct efx_ef10_filter_table *table = efx->filter_state;
4809 struct efx_filter_spec *spec =
4810 efx_ef10_filter_entry_spec(table, filter_idx);
4811
4812 spin_lock_bh(&efx->filter_lock);
4813 if (rc == 0) {
4814 kfree(spec);
4815 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4816 }
4817 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4818 wake_up_all(&table->waitq);
4819 spin_unlock_bh(&efx->filter_lock);
4820}
4821
4822#endif /* CONFIG_RFS_ACCEL */
4823
Edward Cree9b410802017-01-27 15:02:52 +00004824static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004825{
4826 int match_flags = 0;
4827
Edward Cree9b410802017-01-27 15:02:52 +00004828#define MAP_FLAG(gen_flag, mcdi_field) do { \
Ben Hutchings8127d662013-08-29 19:19:29 +01004829 u32 old_mcdi_flags = mcdi_flags; \
Edward Cree9b410802017-01-27 15:02:52 +00004830 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4831 mcdi_field ## _LBN); \
Ben Hutchings8127d662013-08-29 19:19:29 +01004832 if (mcdi_flags != old_mcdi_flags) \
4833 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
Edward Cree9b410802017-01-27 15:02:52 +00004834 } while (0)
4835
4836 if (encap) {
4837 /* encap filters must specify encap type */
4838 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4839 /* and imply ethertype and ip proto */
4840 mcdi_flags &=
4841 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4842 mcdi_flags &=
4843 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4844 /* VLAN tags refer to the outer packet */
4845 MAP_FLAG(INNER_VID, INNER_VLAN);
4846 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4847 /* everything else refers to the inner packet */
4848 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4849 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4850 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4851 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4852 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4853 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4854 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4855 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4856 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4857 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4858 } else {
4859 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4860 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4861 MAP_FLAG(REM_HOST, SRC_IP);
4862 MAP_FLAG(LOC_HOST, DST_IP);
4863 MAP_FLAG(REM_MAC, SRC_MAC);
4864 MAP_FLAG(REM_PORT, SRC_PORT);
4865 MAP_FLAG(LOC_MAC, DST_MAC);
4866 MAP_FLAG(LOC_PORT, DST_PORT);
4867 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4868 MAP_FLAG(INNER_VID, INNER_VLAN);
4869 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4870 MAP_FLAG(IP_PROTO, IP_PROTO);
Ben Hutchings8127d662013-08-29 19:19:29 +01004871 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004872#undef MAP_FLAG
4873
4874 /* Did we map them all? */
4875 if (mcdi_flags)
4876 return -EINVAL;
4877
4878 return match_flags;
4879}
4880
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004881static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4882{
4883 struct efx_ef10_filter_table *table = efx->filter_state;
4884 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4885
4886 /* See comment in efx_ef10_filter_table_remove() */
4887 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4888 return;
4889
4890 if (!table)
4891 return;
4892
4893 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4894 efx_ef10_filter_del_vlan_internal(efx, vlan);
4895}
4896
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004897static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
Edward Cree9b410802017-01-27 15:02:52 +00004898 bool encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004899 enum efx_filter_match_flags match_flags)
4900{
4901 unsigned int match_pri;
4902 int mf;
4903
4904 for (match_pri = 0;
4905 match_pri < table->rx_match_count;
4906 match_pri++) {
Edward Cree9b410802017-01-27 15:02:52 +00004907 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004908 table->rx_match_mcdi_flags[match_pri]);
4909 if (mf == match_flags)
4910 return true;
4911 }
4912
4913 return false;
4914}
4915
Edward Cree9b410802017-01-27 15:02:52 +00004916static int
4917efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4918 struct efx_ef10_filter_table *table,
4919 bool encap)
Ben Hutchings8127d662013-08-29 19:19:29 +01004920{
4921 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4922 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4923 unsigned int pd_match_pri, pd_match_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01004924 size_t outlen;
4925 int rc;
4926
Ben Hutchings8127d662013-08-29 19:19:29 +01004927 /* Find out which RX filter types are supported, and their priorities */
4928 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
Edward Cree9b410802017-01-27 15:02:52 +00004929 encap ?
4930 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
Ben Hutchings8127d662013-08-29 19:19:29 +01004931 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4932 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4933 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4934 &outlen);
4935 if (rc)
Edward Cree9b410802017-01-27 15:02:52 +00004936 return rc;
4937
Ben Hutchings8127d662013-08-29 19:19:29 +01004938 pd_match_count = MCDI_VAR_ARRAY_LEN(
4939 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
Ben Hutchings8127d662013-08-29 19:19:29 +01004940
4941 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4942 u32 mcdi_flags =
4943 MCDI_ARRAY_DWORD(
4944 outbuf,
4945 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4946 pd_match_pri);
Edward Cree9b410802017-01-27 15:02:52 +00004947 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
Ben Hutchings8127d662013-08-29 19:19:29 +01004948 if (rc < 0) {
4949 netif_dbg(efx, probe, efx->net_dev,
4950 "%s: fw flags %#x pri %u not supported in driver\n",
4951 __func__, mcdi_flags, pd_match_pri);
4952 } else {
4953 netif_dbg(efx, probe, efx->net_dev,
4954 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4955 __func__, mcdi_flags, pd_match_pri,
4956 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004957 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4958 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004959 }
4960 }
4961
Edward Cree9b410802017-01-27 15:02:52 +00004962 return 0;
4963}
4964
4965static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4966{
4967 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4968 struct net_device *net_dev = efx->net_dev;
4969 struct efx_ef10_filter_table *table;
4970 struct efx_ef10_vlan *vlan;
4971 int rc;
4972
4973 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4974 return -EINVAL;
4975
4976 if (efx->filter_state) /* already probed */
4977 return 0;
4978
4979 table = kzalloc(sizeof(*table), GFP_KERNEL);
4980 if (!table)
4981 return -ENOMEM;
4982
4983 table->rx_match_count = 0;
4984 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
4985 if (rc)
4986 goto fail;
4987 if (nic_data->datapath_caps &
4988 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
4989 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
4990 if (rc)
4991 goto fail;
Martin Habetse4478ad2016-06-15 17:51:07 +01004992 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
Edward Cree9b410802017-01-27 15:02:52 +00004993 !(efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004994 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
Edward Cree9b410802017-01-27 15:02:52 +00004995 efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004996 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4997 netif_info(efx, probe, net_dev,
4998 "VLAN filters are not supported in this firmware variant\n");
4999 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5000 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5001 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5002 }
5003
Ben Hutchings8127d662013-08-29 19:19:29 +01005004 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
5005 if (!table->entry) {
5006 rc = -ENOMEM;
5007 goto fail;
5008 }
5009
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01005010 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005011 table->vlan_filter =
5012 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005013 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01005014
Ben Hutchings8127d662013-08-29 19:19:29 +01005015 efx->filter_state = table;
5016 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005017
5018 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
5019 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
5020 if (rc)
5021 goto fail_add_vlan;
5022 }
5023
Ben Hutchings8127d662013-08-29 19:19:29 +01005024 return 0;
5025
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005026fail_add_vlan:
5027 efx_ef10_filter_cleanup_vlans(efx);
5028 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01005029fail:
5030 kfree(table);
5031 return rc;
5032}
5033
Edward Cree0d322412015-05-20 11:10:03 +01005034/* Caller must hold efx->filter_sem for read if race against
5035 * efx_ef10_filter_table_remove() is possible
5036 */
Ben Hutchings8127d662013-08-29 19:19:29 +01005037static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5038{
5039 struct efx_ef10_filter_table *table = efx->filter_state;
5040 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005041 unsigned int invalid_filters = 0, failed = 0;
5042 struct efx_ef10_filter_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01005043 struct efx_filter_spec *spec;
Edward Cree42356d92018-03-08 15:45:17 +00005044 struct efx_rss_context *ctx;
Ben Hutchings8127d662013-08-29 19:19:29 +01005045 unsigned int filter_idx;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005046 u32 mcdi_flags;
5047 int match_pri;
Edward Cree9b410802017-01-27 15:02:52 +00005048 int rc, i;
Ben Hutchings8127d662013-08-29 19:19:29 +01005049
Edward Cree0d322412015-05-20 11:10:03 +01005050 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5051
Ben Hutchings8127d662013-08-29 19:19:29 +01005052 if (!nic_data->must_restore_filters)
5053 return;
5054
Edward Cree0d322412015-05-20 11:10:03 +01005055 if (!table)
5056 return;
5057
Ben Hutchings8127d662013-08-29 19:19:29 +01005058 spin_lock_bh(&efx->filter_lock);
5059
5060 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5061 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5062 if (!spec)
5063 continue;
5064
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005065 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
5066 match_pri = 0;
5067 while (match_pri < table->rx_match_count &&
5068 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
5069 ++match_pri;
5070 if (match_pri >= table->rx_match_count) {
5071 invalid_filters++;
5072 goto not_restored;
5073 }
Edward Cree42356d92018-03-08 15:45:17 +00005074 if (spec->rss_context)
5075 ctx = efx_find_rss_context_entry(spec->rss_context,
5076 &efx->rss_context.list);
5077 else
5078 ctx = &efx->rss_context;
5079 if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
5080 if (!ctx) {
5081 netif_warn(efx, drv, efx->net_dev,
5082 "Warning: unable to restore a filter with nonexistent RSS context %u.\n",
5083 spec->rss_context);
5084 invalid_filters++;
5085 goto not_restored;
5086 }
5087 if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
5088 netif_warn(efx, drv, efx->net_dev,
5089 "Warning: unable to restore a filter with RSS context %u as it was not created.\n",
5090 spec->rss_context);
5091 invalid_filters++;
5092 goto not_restored;
5093 }
5094 }
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005095
Ben Hutchings8127d662013-08-29 19:19:29 +01005096 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
5097 spin_unlock_bh(&efx->filter_lock);
5098
5099 rc = efx_ef10_filter_push(efx, spec,
5100 &table->entry[filter_idx].handle,
Edward Cree42356d92018-03-08 15:45:17 +00005101 ctx, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01005102 if (rc)
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005103 failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005104 spin_lock_bh(&efx->filter_lock);
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005105
Ben Hutchings8127d662013-08-29 19:19:29 +01005106 if (rc) {
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005107not_restored:
Edward Cree9b410802017-01-27 15:02:52 +00005108 list_for_each_entry(vlan, &table->vlan_list, list)
5109 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
5110 if (vlan->default_filters[i] == filter_idx)
5111 vlan->default_filters[i] =
5112 EFX_EF10_FILTER_ID_INVALID;
5113
Ben Hutchings8127d662013-08-29 19:19:29 +01005114 kfree(spec);
5115 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
5116 } else {
5117 table->entry[filter_idx].spec &=
5118 ~EFX_EF10_FILTER_FLAG_BUSY;
5119 }
5120 }
5121
5122 spin_unlock_bh(&efx->filter_lock);
5123
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005124 /* This can happen validly if the MC's capabilities have changed, so
5125 * is not an error.
5126 */
5127 if (invalid_filters)
5128 netif_dbg(efx, drv, efx->net_dev,
5129 "Did not restore %u filters that are now unsupported.\n",
5130 invalid_filters);
5131
Ben Hutchings8127d662013-08-29 19:19:29 +01005132 if (failed)
5133 netif_err(efx, hw, efx->net_dev,
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005134 "unable to restore %u filters\n", failed);
Ben Hutchings8127d662013-08-29 19:19:29 +01005135 else
5136 nic_data->must_restore_filters = false;
5137}
5138
5139static void efx_ef10_filter_table_remove(struct efx_nic *efx)
5140{
5141 struct efx_ef10_filter_table *table = efx->filter_state;
Martin Habetsbb53f4d2017-06-22 10:50:41 +01005142 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01005143 struct efx_filter_spec *spec;
5144 unsigned int filter_idx;
5145 int rc;
5146
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005147 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01005148 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01005149 /* If we were called without locking, then it's not safe to free
5150 * the table as others might be using it. So we just WARN, leak
5151 * the memory, and potentially get an inconsistent filter table
5152 * state.
5153 * This should never actually happen.
5154 */
5155 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5156 return;
5157
Edward Cree0d322412015-05-20 11:10:03 +01005158 if (!table)
5159 return;
5160
Ben Hutchings8127d662013-08-29 19:19:29 +01005161 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5162 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5163 if (!spec)
5164 continue;
5165
5166 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
5167 efx_ef10_filter_is_exclusive(spec) ?
5168 MC_CMD_FILTER_OP_IN_OP_REMOVE :
5169 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
5170 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
5171 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00005172 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
5173 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00005174 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00005175 netif_info(efx, drv, efx->net_dev,
5176 "%s: filter %04x remove failed\n",
5177 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01005178 kfree(spec);
5179 }
5180
5181 vfree(table->entry);
5182 kfree(table);
5183}
5184
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005185static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5186{
5187 struct efx_ef10_filter_table *table = efx->filter_state;
5188 unsigned int filter_idx;
5189
5190 if (*id != EFX_EF10_FILTER_ID_INVALID) {
Jon Cooper0ccb9982017-02-17 15:49:13 +00005191 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005192 if (!table->entry[filter_idx].spec)
5193 netif_dbg(efx, drv, efx->net_dev,
5194 "marked null spec old %04x:%04x\n", *id,
5195 filter_idx);
5196 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
5197 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005198 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005199}
5200
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005201/* Mark old per-VLAN filters that may need to be removed */
5202static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
5203 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01005204{
5205 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005206 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01005207
Edward Cree12fb0da2015-07-21 15:11:00 +01005208 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005209 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01005210 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005211 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005212 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5213 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005214}
5215
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005216/* Mark old filters that may need to be removed.
5217 * Caller must hold efx->filter_sem for read if race against
5218 * efx_ef10_filter_table_remove() is possible
5219 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005220static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5221{
5222 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005223 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005224
5225 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005226 list_for_each_entry(vlan, &table->vlan_list, list)
5227 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01005228 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005229}
Ben Hutchings8127d662013-08-29 19:19:29 +01005230
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005231static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005232{
5233 struct efx_ef10_filter_table *table = efx->filter_state;
5234 struct net_device *net_dev = efx->net_dev;
5235 struct netdev_hw_addr *uc;
5236 unsigned int i;
5237
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005238 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005239 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
5240 i = 1;
5241 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005242 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005243 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005244 break;
5245 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005246 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
5247 i++;
5248 }
Bert Kenwardc70d6812017-07-12 17:19:41 +01005249
5250 table->dev_uc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005251}
5252
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005253static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005254{
5255 struct efx_ef10_filter_table *table = efx->filter_state;
5256 struct net_device *net_dev = efx->net_dev;
5257 struct netdev_hw_addr *mc;
Bert Kenwardc70d6812017-07-12 17:19:41 +01005258 unsigned int i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005259
Edward Cree148cbab2017-04-04 17:02:49 +01005260 table->mc_overflow = false;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005261 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005262
Edward Cree12fb0da2015-07-21 15:11:00 +01005263 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005264 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005265 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005266 table->mc_promisc = true;
Edward Cree148cbab2017-04-04 17:02:49 +01005267 table->mc_overflow = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005268 break;
5269 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005270 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5271 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005272 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005273
5274 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005275}
Ben Hutchings8127d662013-08-29 19:19:29 +01005276
Edward Cree12fb0da2015-07-21 15:11:00 +01005277static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005278 struct efx_ef10_filter_vlan *vlan,
5279 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005280{
5281 struct efx_ef10_filter_table *table = efx->filter_state;
5282 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005283 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005284 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01005285 u8 baddr[ETH_ALEN];
5286 unsigned int i, j;
5287 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005288 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005289 int rc;
5290
5291 if (multicast) {
5292 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005293 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005294 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005295 } else {
5296 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005297 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005298 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005299 }
5300
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005301 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5302
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005303 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01005304 for (i = 0; i < addr_count; i++) {
Edward Creed58299a2017-06-29 16:50:06 +01005305 EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005306 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005307 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01005308 rc = efx_ef10_filter_insert(efx, &spec, true);
5309 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005310 if (rollback) {
5311 netif_info(efx, drv, efx->net_dev,
5312 "efx_ef10_filter_insert failed rc=%d\n",
5313 rc);
5314 /* Fall back to promiscuous */
5315 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005316 efx_ef10_filter_remove_unsafe(
5317 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005318 ids[j]);
5319 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005320 }
5321 return rc;
5322 } else {
Edward Creed58299a2017-06-29 16:50:06 +01005323 /* keep invalid ID, and carry on */
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005324 }
Edward Creed58299a2017-06-29 16:50:06 +01005325 } else {
5326 ids[i] = efx_ef10_filter_get_unsafe_id(rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01005327 }
5328 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005329
Edward Cree12fb0da2015-07-21 15:11:00 +01005330 if (multicast && rollback) {
5331 /* Also need an Ethernet broadcast filter */
Edward Cree9b410802017-01-27 15:02:52 +00005332 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5333 EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005334 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005335 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005336 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005337 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01005338 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005339 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01005340 "Broadcast filter insert failed rc=%d\n", rc);
5341 /* Fall back to promiscuous */
5342 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005343 efx_ef10_filter_remove_unsafe(
5344 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005345 ids[j]);
5346 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005347 }
5348 return rc;
5349 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005350 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005351 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005352 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005353 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005354
5355 return 0;
5356}
5357
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005358static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5359 struct efx_ef10_filter_vlan *vlan,
Edward Cree9b410802017-01-27 15:02:52 +00005360 enum efx_encap_type encap_type,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005361 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01005362{
Edward Cree12fb0da2015-07-21 15:11:00 +01005363 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005364 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01005365 struct efx_filter_spec spec;
5366 u8 baddr[ETH_ALEN];
5367 int rc;
Edward Cree9b410802017-01-27 15:02:52 +00005368 u16 *id;
Edward Cree12fb0da2015-07-21 15:11:00 +01005369
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005370 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5371
5372 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005373
5374 if (multicast)
5375 efx_filter_set_mc_def(&spec);
5376 else
5377 efx_filter_set_uc_def(&spec);
5378
Edward Cree9b410802017-01-27 15:02:52 +00005379 if (encap_type) {
5380 if (nic_data->datapath_caps &
5381 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5382 efx_filter_set_encap_type(&spec, encap_type);
5383 else
5384 /* don't insert encap filters on non-supporting
5385 * platforms. ID will be left as INVALID.
5386 */
5387 return 0;
5388 }
5389
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005390 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5391 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5392
Edward Cree12fb0da2015-07-21 15:11:00 +01005393 rc = efx_ef10_filter_insert(efx, &spec, true);
5394 if (rc < 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005395 const char *um = multicast ? "Multicast" : "Unicast";
5396 const char *encap_name = "";
5397 const char *encap_ipv = "";
5398
5399 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5400 EFX_ENCAP_TYPE_VXLAN)
5401 encap_name = "VXLAN ";
5402 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5403 EFX_ENCAP_TYPE_NVGRE)
5404 encap_name = "NVGRE ";
5405 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5406 EFX_ENCAP_TYPE_GENEVE)
5407 encap_name = "GENEVE ";
5408 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5409 encap_ipv = "IPv6 ";
5410 else if (encap_type)
5411 encap_ipv = "IPv4 ";
5412
5413 /* unprivileged functions can't insert mismatch filters
5414 * for encapsulated or unicast traffic, so downgrade
5415 * those warnings to debug.
5416 */
Jon Cooper34e7aef2017-01-27 15:02:39 +00005417 netif_cond_dbg(efx, drv, efx->net_dev,
Edward Cree9b410802017-01-27 15:02:52 +00005418 rc == -EPERM && (encap_type || !multicast), warn,
5419 "%s%s%s mismatch filter insert failed rc=%d\n",
5420 encap_name, encap_ipv, um, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005421 } else if (multicast) {
Edward Cree9b410802017-01-27 15:02:52 +00005422 /* mapping from encap types to default filter IDs (multicast) */
5423 static enum efx_ef10_default_filters map[] = {
5424 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5425 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5426 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5427 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5428 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5429 EFX_EF10_VXLAN6_MCDEF,
5430 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5431 EFX_EF10_NVGRE6_MCDEF,
5432 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5433 EFX_EF10_GENEVE6_MCDEF,
5434 };
5435
5436 /* quick bounds check (BCAST result impossible) */
5437 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Colin Ian Kinge9904992017-01-31 16:30:02 +00005438 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005439 WARN_ON(1);
5440 return -EINVAL;
5441 }
5442 /* then follow map */
5443 id = &vlan->default_filters[map[encap_type]];
5444
5445 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
Jon Cooper0ccb9982017-02-17 15:49:13 +00005446 *id = efx_ef10_filter_get_unsafe_id(rc);
Edward Cree9b410802017-01-27 15:02:52 +00005447 if (!nic_data->workaround_26807 && !encap_type) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005448 /* Also need an Ethernet broadcast filter */
5449 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005450 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005451 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005452 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01005453 rc = efx_ef10_filter_insert(efx, &spec, true);
5454 if (rc < 0) {
5455 netif_warn(efx, drv, efx->net_dev,
5456 "Broadcast filter insert failed rc=%d\n",
5457 rc);
5458 if (rollback) {
5459 /* Roll back the mc_def filter */
5460 efx_ef10_filter_remove_unsafe(
5461 efx, EFX_FILTER_PRI_AUTO,
Edward Cree9b410802017-01-27 15:02:52 +00005462 *id);
5463 *id = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005464 return rc;
5465 }
5466 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005467 EFX_WARN_ON_PARANOID(
5468 vlan->default_filters[EFX_EF10_BCAST] !=
5469 EFX_EF10_FILTER_ID_INVALID);
5470 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005471 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005472 }
5473 }
5474 rc = 0;
5475 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005476 /* mapping from encap types to default filter IDs (unicast) */
5477 static enum efx_ef10_default_filters map[] = {
5478 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5479 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5480 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5481 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5482 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5483 EFX_EF10_VXLAN6_UCDEF,
5484 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5485 EFX_EF10_NVGRE6_UCDEF,
5486 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5487 EFX_EF10_GENEVE6_UCDEF,
5488 };
5489
5490 /* quick bounds check (BCAST result impossible) */
5491 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Dan Carpenteree467fb2017-02-07 10:44:31 +03005492 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005493 WARN_ON(1);
5494 return -EINVAL;
5495 }
5496 /* then follow map */
5497 id = &vlan->default_filters[map[encap_type]];
5498 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5499 *id = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01005500 rc = 0;
5501 }
5502 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005503}
5504
5505/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5506 * flag or removes these filters, we don't need to hold the filter_lock while
5507 * scanning for these filters.
5508 */
5509static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5510{
5511 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005512 int remove_failed = 0;
5513 int remove_noent = 0;
5514 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005515 int i;
5516
Ben Hutchings8127d662013-08-29 19:19:29 +01005517 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07005518 if (READ_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00005519 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00005520 rc = efx_ef10_filter_remove_internal(efx,
5521 1U << EFX_FILTER_PRI_AUTO, i, true);
5522 if (rc == -ENOENT)
5523 remove_noent++;
5524 else if (rc)
5525 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005526 }
5527 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00005528
5529 if (remove_failed)
5530 netif_info(efx, drv, efx->net_dev,
5531 "%s: failed to remove %d filters\n",
5532 __func__, remove_failed);
5533 if (remove_noent)
5534 netif_info(efx, drv, efx->net_dev,
5535 "%s: failed to remove %d non-existent filters\n",
5536 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01005537}
5538
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005539static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5540{
5541 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5542 u8 mac_old[ETH_ALEN];
5543 int rc, rc2;
5544
5545 /* Only reconfigure a PF-created vport */
5546 if (is_zero_ether_addr(nic_data->vport_mac))
5547 return 0;
5548
5549 efx_device_detach_sync(efx);
5550 efx_net_stop(efx->net_dev);
5551 down_write(&efx->filter_sem);
5552 efx_ef10_filter_table_remove(efx);
5553 up_write(&efx->filter_sem);
5554
5555 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5556 if (rc)
5557 goto restore_filters;
5558
5559 ether_addr_copy(mac_old, nic_data->vport_mac);
5560 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5561 nic_data->vport_mac);
5562 if (rc)
5563 goto restore_vadaptor;
5564
5565 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5566 efx->net_dev->dev_addr);
5567 if (!rc) {
5568 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5569 } else {
5570 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5571 if (rc2) {
5572 /* Failed to add original MAC, so clear vport_mac */
5573 eth_zero_addr(nic_data->vport_mac);
5574 goto reset_nic;
5575 }
5576 }
5577
5578restore_vadaptor:
5579 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5580 if (rc2)
5581 goto reset_nic;
5582restore_filters:
5583 down_write(&efx->filter_sem);
5584 rc2 = efx_ef10_filter_table_probe(efx);
5585 up_write(&efx->filter_sem);
5586 if (rc2)
5587 goto reset_nic;
5588
5589 rc2 = efx_net_open(efx->net_dev);
5590 if (rc2)
5591 goto reset_nic;
5592
Peter Dunning9c568fd2017-02-17 15:50:43 +00005593 efx_device_attach_if_not_resetting(efx);
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005594
5595 return rc;
5596
5597reset_nic:
5598 netif_err(efx, drv, efx->net_dev,
5599 "Failed to restore when changing MAC address - scheduling reset\n");
5600 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5601
5602 return rc ? rc : rc2;
5603}
5604
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005605/* Caller must hold efx->filter_sem for read if race against
5606 * efx_ef10_filter_table_remove() is possible
5607 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005608static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5609 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005610{
5611 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005612 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005613
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005614 /* Do not install unspecified VID if VLAN filtering is enabled.
5615 * Do not install all specified VIDs if VLAN filtering is disabled.
5616 */
5617 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5618 return;
5619
Edward Cree12fb0da2015-07-21 15:11:00 +01005620 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005621 if (table->uc_promisc) {
Edward Cree9b410802017-01-27 15:02:52 +00005622 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5623 false, false);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005624 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005625 } else {
5626 /* If any of the filters failed to insert, fall back to
5627 * promiscuous mode - add in the uc_def filter. But keep
5628 * our individual unicast filters.
5629 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005630 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
Edward Cree9b410802017-01-27 15:02:52 +00005631 efx_ef10_filter_insert_def(efx, vlan,
5632 EFX_ENCAP_TYPE_NONE,
5633 false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005634 }
Edward Cree9b410802017-01-27 15:02:52 +00005635 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5636 false, false);
5637 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5638 EFX_ENCAP_FLAG_IPV6,
5639 false, false);
5640 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5641 false, false);
5642 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5643 EFX_ENCAP_FLAG_IPV6,
5644 false, false);
5645 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5646 false, false);
5647 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5648 EFX_ENCAP_FLAG_IPV6,
5649 false, false);
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005650
Edward Cree12fb0da2015-07-21 15:11:00 +01005651 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005652 /* If changing promiscuous state with cascaded multicast filters, remove
5653 * old filters first, so that packets are dropped rather than duplicated
5654 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005655 if (nic_data->workaround_26807 &&
5656 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005657 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005658 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005659 if (nic_data->workaround_26807) {
5660 /* If we failed to insert promiscuous filters, rollback
5661 * and fall back to individual multicast filters
5662 */
Edward Cree9b410802017-01-27 15:02:52 +00005663 if (efx_ef10_filter_insert_def(efx, vlan,
5664 EFX_ENCAP_TYPE_NONE,
5665 true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005666 /* Changing promisc state, so remove old filters */
5667 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005668 efx_ef10_filter_insert_addr_list(efx, vlan,
5669 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005670 }
5671 } else {
5672 /* If we failed to insert promiscuous filters, don't
Edward Cree148cbab2017-04-04 17:02:49 +01005673 * rollback. Regardless, also insert the mc_list,
5674 * unless it's incomplete due to overflow
Edward Cree12fb0da2015-07-21 15:11:00 +01005675 */
Edward Cree9b410802017-01-27 15:02:52 +00005676 efx_ef10_filter_insert_def(efx, vlan,
5677 EFX_ENCAP_TYPE_NONE,
5678 true, false);
Edward Cree148cbab2017-04-04 17:02:49 +01005679 if (!table->mc_overflow)
5680 efx_ef10_filter_insert_addr_list(efx, vlan,
5681 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005682 }
5683 } else {
5684 /* If any filters failed to insert, rollback and fall back to
5685 * promiscuous mode - mc_def filter and maybe broadcast. If
5686 * that fails, roll back again and insert as many of our
5687 * individual multicast filters as we can.
5688 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005689 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005690 /* Changing promisc state, so remove old filters */
5691 if (nic_data->workaround_26807)
5692 efx_ef10_filter_remove_old(efx);
Edward Cree9b410802017-01-27 15:02:52 +00005693 if (efx_ef10_filter_insert_def(efx, vlan,
5694 EFX_ENCAP_TYPE_NONE,
5695 true, true))
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005696 efx_ef10_filter_insert_addr_list(efx, vlan,
5697 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005698 }
5699 }
Edward Cree9b410802017-01-27 15:02:52 +00005700 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5701 true, false);
5702 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5703 EFX_ENCAP_FLAG_IPV6,
5704 true, false);
5705 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5706 true, false);
5707 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5708 EFX_ENCAP_FLAG_IPV6,
5709 true, false);
5710 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5711 true, false);
5712 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5713 EFX_ENCAP_FLAG_IPV6,
5714 true, false);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005715}
5716
5717/* Caller must hold efx->filter_sem for read if race against
5718 * efx_ef10_filter_table_remove() is possible
5719 */
5720static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5721{
5722 struct efx_ef10_filter_table *table = efx->filter_state;
5723 struct net_device *net_dev = efx->net_dev;
5724 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005725 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005726
5727 if (!efx_dev_registered(efx))
5728 return;
5729
5730 if (!table)
5731 return;
5732
5733 efx_ef10_filter_mark_old(efx);
5734
5735 /* Copy/convert the address lists; add the primary station
5736 * address and broadcast address
5737 */
5738 netif_addr_lock_bh(net_dev);
5739 efx_ef10_filter_uc_addr_list(efx);
5740 efx_ef10_filter_mc_addr_list(efx);
5741 netif_addr_unlock_bh(net_dev);
5742
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005743 /* If VLAN filtering changes, all old filters are finally removed.
5744 * Do it in advance to avoid conflicts for unicast untagged and
5745 * VLAN 0 tagged filters.
5746 */
5747 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5748 if (table->vlan_filter != vlan_filter) {
5749 table->vlan_filter = vlan_filter;
5750 efx_ef10_filter_remove_old(efx);
5751 }
5752
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005753 list_for_each_entry(vlan, &table->vlan_list, list)
5754 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005755
5756 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005757 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005758}
5759
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005760static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5761{
5762 struct efx_ef10_filter_table *table = efx->filter_state;
5763 struct efx_ef10_filter_vlan *vlan;
5764
5765 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5766
5767 list_for_each_entry(vlan, &table->vlan_list, list) {
5768 if (vlan->vid == vid)
5769 return vlan;
5770 }
5771
5772 return NULL;
5773}
5774
5775static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5776{
5777 struct efx_ef10_filter_table *table = efx->filter_state;
5778 struct efx_ef10_filter_vlan *vlan;
5779 unsigned int i;
5780
5781 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5782 return -EINVAL;
5783
5784 vlan = efx_ef10_filter_find_vlan(efx, vid);
5785 if (WARN_ON(vlan)) {
5786 netif_err(efx, drv, efx->net_dev,
5787 "VLAN %u already added\n", vid);
5788 return -EALREADY;
5789 }
5790
5791 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5792 if (!vlan)
5793 return -ENOMEM;
5794
5795 vlan->vid = vid;
5796
5797 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5798 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5799 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5800 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree9b410802017-01-27 15:02:52 +00005801 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5802 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005803
5804 list_add_tail(&vlan->list, &table->vlan_list);
5805
5806 if (efx_dev_registered(efx))
5807 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5808
5809 return 0;
5810}
5811
5812static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5813 struct efx_ef10_filter_vlan *vlan)
5814{
5815 unsigned int i;
5816
5817 /* See comment in efx_ef10_filter_table_remove() */
5818 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5819 return;
5820
5821 list_del(&vlan->list);
5822
Edward Cree8c915622016-06-15 17:49:05 +01005823 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005824 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005825 vlan->uc[i]);
5826 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005827 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005828 vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005829 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5830 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5831 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5832 vlan->default_filters[i]);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005833
5834 kfree(vlan);
5835}
5836
5837static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5838{
5839 struct efx_ef10_filter_vlan *vlan;
5840
5841 /* See comment in efx_ef10_filter_table_remove() */
5842 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5843 return;
5844
5845 vlan = efx_ef10_filter_find_vlan(efx, vid);
5846 if (!vlan) {
5847 netif_err(efx, drv, efx->net_dev,
5848 "VLAN %u not found in filter state\n", vid);
5849 return;
5850 }
5851
5852 efx_ef10_filter_del_vlan_internal(efx, vlan);
5853}
5854
Shradha Shah910c8782015-05-20 11:12:48 +01005855static int efx_ef10_set_mac_address(struct efx_nic *efx)
5856{
5857 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5858 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5859 bool was_enabled = efx->port_enabled;
5860 int rc;
5861
5862 efx_device_detach_sync(efx);
5863 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005864
5865 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005866 down_write(&efx->filter_sem);
5867 efx_ef10_filter_table_remove(efx);
5868
5869 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5870 efx->net_dev->dev_addr);
5871 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5872 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005873 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5874 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005875
5876 efx_ef10_filter_table_probe(efx);
5877 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005878 mutex_unlock(&efx->mac_lock);
5879
Shradha Shah910c8782015-05-20 11:12:48 +01005880 if (was_enabled)
5881 efx_net_open(efx->net_dev);
Peter Dunning9c568fd2017-02-17 15:50:43 +00005882 efx_device_attach_if_not_resetting(efx);
Shradha Shah910c8782015-05-20 11:12:48 +01005883
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005884#ifdef CONFIG_SFC_SRIOV
5885 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005886 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5887
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005888 if (rc == -EPERM) {
5889 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005890
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005891 /* Switch to PF and change MAC address on vport */
5892 efx_pf = pci_get_drvdata(pci_dev_pf);
5893
5894 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005895 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005896 efx->net_dev->dev_addr);
5897 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005898 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5899 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5900 unsigned int i;
5901
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005902 /* MAC address successfully changed by VF (with MAC
5903 * spoofing) so update the parent PF if possible.
5904 */
Shradha Shah910c8782015-05-20 11:12:48 +01005905 for (i = 0; i < efx_pf->vf_count; ++i) {
5906 struct ef10_vf *vf = nic_data->vf + i;
5907
5908 if (vf->efx == efx) {
5909 ether_addr_copy(vf->mac,
5910 efx->net_dev->dev_addr);
5911 return 0;
5912 }
5913 }
5914 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005915 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005916#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005917 if (rc == -EPERM) {
5918 netif_err(efx, drv, efx->net_dev,
5919 "Cannot change MAC address; use sfboot to enable"
5920 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005921 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5922 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5923 * fall-back to the method of changing the MAC address on the
5924 * vport. This only applies to PFs because such versions of
5925 * MCFW do not support VFs.
5926 */
5927 rc = efx_ef10_vport_set_mac_address(efx);
Robert Stonehousecbad52e2017-11-07 17:30:30 +00005928 } else if (rc) {
Daniel Pieczko535a6172015-07-07 11:37:33 +01005929 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5930 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005931 }
5932
Shradha Shah910c8782015-05-20 11:12:48 +01005933 return rc;
5934}
5935
Ben Hutchings8127d662013-08-29 19:19:29 +01005936static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5937{
5938 efx_ef10_filter_sync_rx_mode(efx);
5939
5940 return efx_mcdi_set_mac(efx);
5941}
5942
Shradha Shah862f8942015-05-20 11:08:56 +01005943static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5944{
5945 efx_ef10_filter_sync_rx_mode(efx);
5946
5947 return 0;
5948}
5949
Jon Cooper74cd60a2013-09-16 14:18:51 +01005950static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5951{
5952 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5953
5954 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5955 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5956 NULL, 0, NULL);
5957}
5958
5959/* MC BISTs follow a different poll mechanism to phy BISTs.
5960 * The BIST is done in the poll handler on the MC, and the MCDI command
5961 * will block until the BIST is done.
5962 */
5963static int efx_ef10_poll_bist(struct efx_nic *efx)
5964{
5965 int rc;
5966 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5967 size_t outlen;
5968 u32 result;
5969
5970 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5971 outbuf, sizeof(outbuf), &outlen);
5972 if (rc != 0)
5973 return rc;
5974
5975 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5976 return -EIO;
5977
5978 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5979 switch (result) {
5980 case MC_CMD_POLL_BIST_PASSED:
5981 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5982 return 0;
5983 case MC_CMD_POLL_BIST_TIMEOUT:
5984 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5985 return -EIO;
5986 case MC_CMD_POLL_BIST_FAILED:
5987 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5988 return -EIO;
5989 default:
5990 netif_err(efx, hw, efx->net_dev,
5991 "BIST returned unknown result %u", result);
5992 return -EIO;
5993 }
5994}
5995
5996static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5997{
5998 int rc;
5999
6000 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
6001
6002 rc = efx_ef10_start_bist(efx, bist_type);
6003 if (rc != 0)
6004 return rc;
6005
6006 return efx_ef10_poll_bist(efx);
6007}
6008
6009static int
6010efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
6011{
6012 int rc, rc2;
6013
6014 efx_reset_down(efx, RESET_TYPE_WORLD);
6015
6016 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
6017 NULL, 0, NULL, 0, NULL);
6018 if (rc != 0)
6019 goto out;
6020
6021 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
6022 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
6023
6024 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
6025
6026out:
Daniel Pieczko27324822015-07-31 11:14:54 +01006027 if (rc == -EPERM)
6028 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01006029 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
6030 return rc ? rc : rc2;
6031}
6032
Ben Hutchings8127d662013-08-29 19:19:29 +01006033#ifdef CONFIG_SFC_MTD
6034
6035struct efx_ef10_nvram_type_info {
6036 u16 type, type_mask;
6037 u8 port;
6038 const char *name;
6039};
6040
6041static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
6042 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
6043 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
6044 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
6045 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
6046 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
6047 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
6048 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
6049 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
6050 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01006051 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01006052 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
6053};
6054
6055static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
6056 struct efx_mcdi_mtd_partition *part,
6057 unsigned int type)
6058{
6059 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
6060 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
6061 const struct efx_ef10_nvram_type_info *info;
6062 size_t size, erase_size, outlen;
6063 bool protected;
6064 int rc;
6065
6066 for (info = efx_ef10_nvram_types; ; info++) {
6067 if (info ==
6068 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
6069 return -ENODEV;
6070 if ((type & ~info->type_mask) == info->type)
6071 break;
6072 }
6073 if (info->port != efx_port_num(efx))
6074 return -ENODEV;
6075
6076 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
6077 if (rc)
6078 return rc;
6079 if (protected)
6080 return -ENODEV; /* hide it */
6081
6082 part->nvram_type = type;
6083
6084 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
6085 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
6086 outbuf, sizeof(outbuf), &outlen);
6087 if (rc)
6088 return rc;
6089 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
6090 return -EIO;
6091 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
6092 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
6093 part->fw_subtype = MCDI_DWORD(outbuf,
6094 NVRAM_METADATA_OUT_SUBTYPE);
6095
6096 part->common.dev_type_name = "EF10 NVRAM manager";
6097 part->common.type_name = info->name;
6098
6099 part->common.mtd.type = MTD_NORFLASH;
6100 part->common.mtd.flags = MTD_CAP_NORFLASH;
6101 part->common.mtd.size = size;
6102 part->common.mtd.erasesize = erase_size;
6103
6104 return 0;
6105}
6106
6107static int efx_ef10_mtd_probe(struct efx_nic *efx)
6108{
6109 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
6110 struct efx_mcdi_mtd_partition *parts;
6111 size_t outlen, n_parts_total, i, n_parts;
6112 unsigned int type;
6113 int rc;
6114
6115 ASSERT_RTNL();
6116
6117 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
6118 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
6119 outbuf, sizeof(outbuf), &outlen);
6120 if (rc)
6121 return rc;
6122 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
6123 return -EIO;
6124
6125 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
6126 if (n_parts_total >
6127 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
6128 return -EIO;
6129
6130 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
6131 if (!parts)
6132 return -ENOMEM;
6133
6134 n_parts = 0;
6135 for (i = 0; i < n_parts_total; i++) {
6136 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
6137 i);
6138 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
6139 if (rc == 0)
6140 n_parts++;
6141 else if (rc != -ENODEV)
6142 goto fail;
6143 }
6144
6145 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
6146fail:
6147 if (rc)
6148 kfree(parts);
6149 return rc;
6150}
6151
6152#endif /* CONFIG_SFC_MTD */
6153
6154static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
6155{
6156 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
6157}
6158
Shradha Shah02246a72015-05-06 00:58:14 +01006159static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
6160 u32 host_time) {}
6161
Jon Cooperbd9a2652013-11-18 12:54:41 +00006162static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
6163 bool temp)
6164{
6165 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
6166 int rc;
6167
6168 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
6169 channel->sync_events_state == SYNC_EVENTS_VALID ||
6170 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
6171 return 0;
6172 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
6173
6174 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
6175 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6176 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
6177 channel->channel);
6178
6179 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6180 inbuf, sizeof(inbuf), NULL, 0, NULL);
6181
6182 if (rc != 0)
6183 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6184 SYNC_EVENTS_DISABLED;
6185
6186 return rc;
6187}
6188
6189static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
6190 bool temp)
6191{
6192 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
6193 int rc;
6194
6195 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
6196 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
6197 return 0;
6198 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
6199 channel->sync_events_state = SYNC_EVENTS_DISABLED;
6200 return 0;
6201 }
6202 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6203 SYNC_EVENTS_DISABLED;
6204
6205 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
6206 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6207 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
6208 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
6209 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
6210 channel->channel);
6211
6212 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6213 inbuf, sizeof(inbuf), NULL, 0, NULL);
6214
6215 return rc;
6216}
6217
6218static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
6219 bool temp)
6220{
6221 int (*set)(struct efx_channel *channel, bool temp);
6222 struct efx_channel *channel;
6223
6224 set = en ?
6225 efx_ef10_rx_enable_timestamping :
6226 efx_ef10_rx_disable_timestamping;
6227
Edward Cree2935e3c2018-01-25 17:26:06 +00006228 channel = efx_ptp_channel(efx);
6229 if (channel) {
Jon Cooperbd9a2652013-11-18 12:54:41 +00006230 int rc = set(channel, temp);
6231 if (en && rc != 0) {
6232 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
6233 return rc;
6234 }
6235 }
6236
6237 return 0;
6238}
6239
Shradha Shah02246a72015-05-06 00:58:14 +01006240static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
6241 struct hwtstamp_config *init)
6242{
6243 return -EOPNOTSUPP;
6244}
6245
Jon Cooperbd9a2652013-11-18 12:54:41 +00006246static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
6247 struct hwtstamp_config *init)
6248{
6249 int rc;
6250
6251 switch (init->rx_filter) {
6252 case HWTSTAMP_FILTER_NONE:
6253 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
6254 /* if TX timestamping is still requested then leave PTP on */
6255 return efx_ptp_change_mode(efx,
6256 init->tx_type != HWTSTAMP_TX_OFF, 0);
6257 case HWTSTAMP_FILTER_ALL:
6258 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6259 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6260 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6261 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6262 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6263 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6264 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6265 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6266 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6267 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6268 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6269 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Miroslav Lichvare3412572017-05-19 17:52:36 +02006270 case HWTSTAMP_FILTER_NTP_ALL:
Jon Cooperbd9a2652013-11-18 12:54:41 +00006271 init->rx_filter = HWTSTAMP_FILTER_ALL;
6272 rc = efx_ptp_change_mode(efx, true, 0);
6273 if (!rc)
6274 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6275 if (rc)
6276 efx_ptp_change_mode(efx, false, 0);
6277 return rc;
6278 default:
6279 return -ERANGE;
6280 }
6281}
6282
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006283static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6284 struct netdev_phys_item_id *ppid)
6285{
6286 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6287
6288 if (!is_valid_ether_addr(nic_data->port_id))
6289 return -EOPNOTSUPP;
6290
6291 ppid->id_len = ETH_ALEN;
6292 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6293
6294 return 0;
6295}
6296
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006297static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6298{
6299 if (proto != htons(ETH_P_8021Q))
6300 return -EINVAL;
6301
6302 return efx_ef10_add_vlan(efx, vid);
6303}
6304
6305static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6306{
6307 if (proto != htons(ETH_P_8021Q))
6308 return -EINVAL;
6309
6310 return efx_ef10_del_vlan(efx, vid);
6311}
6312
Jon Coopere5fbd972017-02-08 16:52:10 +00006313/* We rely on the MCDI wiping out our TX rings if it made any changes to the
6314 * ports table, ensuring that any TSO descriptors that were made on a now-
6315 * removed tunnel port will be blown away and won't break things when we try
6316 * to transmit them using the new ports table.
6317 */
6318static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
6319{
6320 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6321 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
6322 MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
6323 bool will_reset = false;
6324 size_t num_entries = 0;
6325 size_t inlen, outlen;
6326 size_t i;
6327 int rc;
6328 efx_dword_t flags_and_num_entries;
6329
6330 WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
6331
6332 nic_data->udp_tunnels_dirty = false;
6333
6334 if (!(nic_data->datapath_caps &
6335 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
Peter Dunning9c568fd2017-02-17 15:50:43 +00006336 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006337 return 0;
6338 }
6339
6340 BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
6341 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
6342
6343 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6344 if (nic_data->udp_tunnels[i].count &&
6345 nic_data->udp_tunnels[i].port) {
6346 efx_dword_t entry;
6347
6348 EFX_POPULATE_DWORD_2(entry,
6349 TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
6350 ntohs(nic_data->udp_tunnels[i].port),
6351 TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
6352 nic_data->udp_tunnels[i].type);
6353 *_MCDI_ARRAY_DWORD(inbuf,
6354 SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
6355 num_entries++) = entry;
6356 }
6357 }
6358
6359 BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
6360 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
6361 EFX_WORD_1_LBN);
6362 BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
6363 EFX_WORD_1_WIDTH);
6364 EFX_POPULATE_DWORD_2(flags_and_num_entries,
6365 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
6366 !!unloading,
6367 EFX_WORD_1, num_entries);
6368 *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
6369 flags_and_num_entries;
6370
6371 inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
6372
6373 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
6374 inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
6375 if (rc == -EIO) {
6376 /* Most likely the MC rebooted due to another function also
6377 * setting its tunnel port list. Mark the tunnel port list as
6378 * dirty, so it will be pushed upon coming up from the reboot.
6379 */
6380 nic_data->udp_tunnels_dirty = true;
6381 return 0;
6382 }
6383
6384 if (rc) {
6385 /* expected not available on unprivileged functions */
6386 if (rc != -EPERM)
6387 netif_warn(efx, drv, efx->net_dev,
6388 "Unable to set UDP tunnel ports; rc=%d.\n", rc);
6389 } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
6390 (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
6391 netif_info(efx, drv, efx->net_dev,
6392 "Rebooting MC due to UDP tunnel port list change\n");
6393 will_reset = true;
6394 if (unloading)
6395 /* Delay for the MC reset to complete. This will make
6396 * unloading other functions a bit smoother. This is a
6397 * race, but the other unload will work whichever way
6398 * it goes, this just avoids an unnecessary error
6399 * message.
6400 */
6401 msleep(100);
6402 }
6403 if (!will_reset && !unloading) {
6404 /* The caller will have detached, relying on the MC reset to
6405 * trigger a re-attach. Since there won't be an MC reset, we
6406 * have to do the attach ourselves.
6407 */
Peter Dunning9c568fd2017-02-17 15:50:43 +00006408 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006409 }
6410
6411 return rc;
6412}
6413
6414static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
6415{
6416 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6417 int rc = 0;
6418
6419 mutex_lock(&nic_data->udp_tunnels_lock);
6420 if (nic_data->udp_tunnels_dirty) {
6421 /* Make sure all TX are stopped while we modify the table, else
6422 * we might race against an efx_features_check().
6423 */
6424 efx_device_detach_sync(efx);
6425 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6426 }
6427 mutex_unlock(&nic_data->udp_tunnels_lock);
6428 return rc;
6429}
6430
6431static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
6432 __be16 port)
6433{
6434 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6435 size_t i;
6436
6437 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6438 if (!nic_data->udp_tunnels[i].count)
6439 continue;
6440 if (nic_data->udp_tunnels[i].port == port)
6441 return &nic_data->udp_tunnels[i];
6442 }
6443 return NULL;
6444}
6445
6446static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
6447 struct efx_udp_tunnel tnl)
6448{
6449 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6450 struct efx_udp_tunnel *match;
6451 char typebuf[8];
6452 size_t i;
6453 int rc;
6454
6455 if (!(nic_data->datapath_caps &
6456 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6457 return 0;
6458
6459 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6460 netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
6461 typebuf, ntohs(tnl.port));
6462
6463 mutex_lock(&nic_data->udp_tunnels_lock);
6464 /* Make sure all TX are stopped while we add to the table, else we
6465 * might race against an efx_features_check().
6466 */
6467 efx_device_detach_sync(efx);
6468
6469 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6470 if (match != NULL) {
6471 if (match->type == tnl.type) {
6472 netif_dbg(efx, drv, efx->net_dev,
6473 "Referencing existing tunnel entry\n");
6474 match->count++;
6475 /* No need to cause an MCDI update */
6476 rc = 0;
6477 goto unlock_out;
6478 }
6479 efx_get_udp_tunnel_type_name(match->type,
6480 typebuf, sizeof(typebuf));
6481 netif_dbg(efx, drv, efx->net_dev,
6482 "UDP port %d is already in use by %s\n",
6483 ntohs(tnl.port), typebuf);
6484 rc = -EEXIST;
6485 goto unlock_out;
6486 }
6487
6488 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
6489 if (!nic_data->udp_tunnels[i].count) {
6490 nic_data->udp_tunnels[i] = tnl;
6491 nic_data->udp_tunnels[i].count = 1;
6492 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6493 goto unlock_out;
6494 }
6495
6496 netif_dbg(efx, drv, efx->net_dev,
6497 "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
6498 typebuf, ntohs(tnl.port));
6499
6500 rc = -ENOMEM;
6501
6502unlock_out:
6503 mutex_unlock(&nic_data->udp_tunnels_lock);
6504 return rc;
6505}
6506
6507/* Called under the TX lock with the TX queue running, hence no-one can be
6508 * in the middle of updating the UDP tunnels table. However, they could
6509 * have tried and failed the MCDI, in which case they'll have set the dirty
6510 * flag before dropping their locks.
6511 */
6512static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
6513{
6514 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6515
6516 if (!(nic_data->datapath_caps &
6517 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6518 return false;
6519
6520 if (nic_data->udp_tunnels_dirty)
6521 /* SW table may not match HW state, so just assume we can't
6522 * use any UDP tunnel offloads.
6523 */
6524 return false;
6525
6526 return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
6527}
6528
6529static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
6530 struct efx_udp_tunnel tnl)
6531{
6532 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6533 struct efx_udp_tunnel *match;
6534 char typebuf[8];
6535 int rc;
6536
6537 if (!(nic_data->datapath_caps &
6538 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6539 return 0;
6540
6541 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6542 netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
6543 typebuf, ntohs(tnl.port));
6544
6545 mutex_lock(&nic_data->udp_tunnels_lock);
6546 /* Make sure all TX are stopped while we remove from the table, else we
6547 * might race against an efx_features_check().
6548 */
6549 efx_device_detach_sync(efx);
6550
6551 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6552 if (match != NULL) {
6553 if (match->type == tnl.type) {
6554 if (--match->count) {
6555 /* Port is still in use, so nothing to do */
6556 netif_dbg(efx, drv, efx->net_dev,
6557 "UDP tunnel port %d remains active\n",
6558 ntohs(tnl.port));
6559 rc = 0;
6560 goto out_unlock;
6561 }
6562 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6563 goto out_unlock;
6564 }
6565 efx_get_udp_tunnel_type_name(match->type,
6566 typebuf, sizeof(typebuf));
6567 netif_warn(efx, drv, efx->net_dev,
6568 "UDP port %d is actually in use by %s, not removing\n",
6569 ntohs(tnl.port), typebuf);
6570 }
6571 rc = -ENOENT;
6572
6573out_unlock:
6574 mutex_unlock(&nic_data->udp_tunnels_lock);
6575 return rc;
6576}
6577
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006578#define EF10_OFFLOAD_FEATURES \
6579 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006580 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006581 NETIF_F_IPV6_CSUM | \
6582 NETIF_F_RXHASH | \
6583 NETIF_F_NTUPLE)
6584
Shradha Shah02246a72015-05-06 00:58:14 +01006585const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006586 .is_vf = true,
Edward Cree03714bb2017-12-18 16:55:50 +00006587 .mem_bar = efx_ef10_vf_mem_bar,
Ben Hutchings8127d662013-08-29 19:19:29 +01006588 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01006589 .probe = efx_ef10_probe_vf,
6590 .remove = efx_ef10_remove,
6591 .dimension_resources = efx_ef10_dimension_resources,
6592 .init = efx_ef10_init_nic,
6593 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006594 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01006595 .map_reset_flags = efx_ef10_map_reset_flags,
6596 .reset = efx_ef10_reset,
6597 .probe_port = efx_mcdi_port_probe,
6598 .remove_port = efx_mcdi_port_remove,
6599 .fini_dmaq = efx_ef10_fini_dmaq,
6600 .prepare_flr = efx_ef10_prepare_flr,
6601 .finish_flr = efx_port_dummy_op_void,
6602 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006603 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006604 .start_stats = efx_port_dummy_op_void,
6605 .pull_stats = efx_port_dummy_op_void,
6606 .stop_stats = efx_port_dummy_op_void,
6607 .set_id_led = efx_mcdi_set_id_led,
6608 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01006609 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006610 .check_mac_fault = efx_mcdi_mac_check_fault,
6611 .reconfigure_port = efx_mcdi_port_reconfigure,
6612 .get_wol = efx_ef10_get_wol_vf,
6613 .set_wol = efx_ef10_set_wol_vf,
6614 .resume_wol = efx_port_dummy_op_void,
6615 .mcdi_request = efx_ef10_mcdi_request,
6616 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6617 .mcdi_read_response = efx_ef10_mcdi_read_response,
6618 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006619 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01006620 .irq_enable_master = efx_port_dummy_op_void,
6621 .irq_test_generate = efx_ef10_irq_test_generate,
6622 .irq_disable_non_ev = efx_port_dummy_op_void,
6623 .irq_handle_msi = efx_ef10_msi_interrupt,
6624 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6625 .tx_probe = efx_ef10_tx_probe,
6626 .tx_init = efx_ef10_tx_init,
6627 .tx_remove = efx_ef10_tx_remove,
6628 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006629 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006630 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006631 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01006632 .rx_probe = efx_ef10_rx_probe,
6633 .rx_init = efx_ef10_rx_init,
6634 .rx_remove = efx_ef10_rx_remove,
6635 .rx_write = efx_ef10_rx_write,
6636 .rx_defer_refill = efx_ef10_rx_defer_refill,
6637 .ev_probe = efx_ef10_ev_probe,
6638 .ev_init = efx_ef10_ev_init,
6639 .ev_fini = efx_ef10_ev_fini,
6640 .ev_remove = efx_ef10_ev_remove,
6641 .ev_process = efx_ef10_ev_process,
6642 .ev_read_ack = efx_ef10_ev_read_ack,
6643 .ev_test_generate = efx_ef10_ev_test_generate,
6644 .filter_table_probe = efx_ef10_filter_table_probe,
6645 .filter_table_restore = efx_ef10_filter_table_restore,
6646 .filter_table_remove = efx_ef10_filter_table_remove,
6647 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6648 .filter_insert = efx_ef10_filter_insert,
6649 .filter_remove_safe = efx_ef10_filter_remove_safe,
6650 .filter_get_safe = efx_ef10_filter_get_safe,
6651 .filter_clear_rx = efx_ef10_filter_clear_rx,
6652 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6653 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6654 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6655#ifdef CONFIG_RFS_ACCEL
Shradha Shah02246a72015-05-06 00:58:14 +01006656 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6657#endif
6658#ifdef CONFIG_SFC_MTD
6659 .mtd_probe = efx_port_dummy_op_int,
6660#endif
6661 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6662 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006663 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6664 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01006665#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006666 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6667 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6668 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006669#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006670 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01006671 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006672
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006673 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01006674 .revision = EFX_REV_HUNT_A0,
6675 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6676 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6677 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6678 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6679 .can_rx_scatter = true,
6680 .always_rx_scatter = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006681 .min_interrupt_mode = EFX_INT_MODE_MSIX,
Shradha Shah02246a72015-05-06 00:58:14 +01006682 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6683 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006684 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01006685 .mcdi_max_ver = 2,
6686 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6687 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6688 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006689 .rx_hash_key_size = 40,
Shradha Shah02246a72015-05-06 00:58:14 +01006690};
6691
6692const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006693 .is_vf = false,
Edward Cree03714bb2017-12-18 16:55:50 +00006694 .mem_bar = efx_ef10_pf_mem_bar,
Shradha Shah02246a72015-05-06 00:58:14 +01006695 .mem_map_size = efx_ef10_mem_map_size,
6696 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006697 .remove = efx_ef10_remove,
6698 .dimension_resources = efx_ef10_dimension_resources,
6699 .init = efx_ef10_init_nic,
6700 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006701 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01006702 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00006703 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01006704 .probe_port = efx_mcdi_port_probe,
6705 .remove_port = efx_mcdi_port_remove,
6706 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01006707 .prepare_flr = efx_ef10_prepare_flr,
6708 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01006709 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006710 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006711 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01006712 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01006713 .stop_stats = efx_mcdi_mac_stop_stats,
6714 .set_id_led = efx_mcdi_set_id_led,
6715 .push_irq_moderation = efx_ef10_push_irq_moderation,
6716 .reconfigure_mac = efx_ef10_mac_reconfigure,
6717 .check_mac_fault = efx_mcdi_mac_check_fault,
6718 .reconfigure_port = efx_mcdi_port_reconfigure,
6719 .get_wol = efx_ef10_get_wol,
6720 .set_wol = efx_ef10_set_wol,
6721 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01006722 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01006723 .test_nvram = efx_mcdi_nvram_test_all,
6724 .mcdi_request = efx_ef10_mcdi_request,
6725 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6726 .mcdi_read_response = efx_ef10_mcdi_read_response,
6727 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006728 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01006729 .irq_enable_master = efx_port_dummy_op_void,
6730 .irq_test_generate = efx_ef10_irq_test_generate,
6731 .irq_disable_non_ev = efx_port_dummy_op_void,
6732 .irq_handle_msi = efx_ef10_msi_interrupt,
6733 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6734 .tx_probe = efx_ef10_tx_probe,
6735 .tx_init = efx_ef10_tx_init,
6736 .tx_remove = efx_ef10_tx_remove,
6737 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006738 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006739 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006740 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Edward Cree42356d92018-03-08 15:45:17 +00006741 .rx_push_rss_context_config = efx_ef10_rx_push_rss_context_config,
6742 .rx_pull_rss_context_config = efx_ef10_rx_pull_rss_context_config,
6743 .rx_restore_rss_contexts = efx_ef10_rx_restore_rss_contexts,
Ben Hutchings8127d662013-08-29 19:19:29 +01006744 .rx_probe = efx_ef10_rx_probe,
6745 .rx_init = efx_ef10_rx_init,
6746 .rx_remove = efx_ef10_rx_remove,
6747 .rx_write = efx_ef10_rx_write,
6748 .rx_defer_refill = efx_ef10_rx_defer_refill,
6749 .ev_probe = efx_ef10_ev_probe,
6750 .ev_init = efx_ef10_ev_init,
6751 .ev_fini = efx_ef10_ev_fini,
6752 .ev_remove = efx_ef10_ev_remove,
6753 .ev_process = efx_ef10_ev_process,
6754 .ev_read_ack = efx_ef10_ev_read_ack,
6755 .ev_test_generate = efx_ef10_ev_test_generate,
6756 .filter_table_probe = efx_ef10_filter_table_probe,
6757 .filter_table_restore = efx_ef10_filter_table_restore,
6758 .filter_table_remove = efx_ef10_filter_table_remove,
6759 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6760 .filter_insert = efx_ef10_filter_insert,
6761 .filter_remove_safe = efx_ef10_filter_remove_safe,
6762 .filter_get_safe = efx_ef10_filter_get_safe,
6763 .filter_clear_rx = efx_ef10_filter_clear_rx,
6764 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6765 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6766 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6767#ifdef CONFIG_RFS_ACCEL
Ben Hutchings8127d662013-08-29 19:19:29 +01006768 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6769#endif
6770#ifdef CONFIG_SFC_MTD
6771 .mtd_probe = efx_ef10_mtd_probe,
6772 .mtd_rename = efx_mcdi_mtd_rename,
6773 .mtd_read = efx_mcdi_mtd_read,
6774 .mtd_erase = efx_mcdi_mtd_erase,
6775 .mtd_write = efx_mcdi_mtd_write,
6776 .mtd_sync = efx_mcdi_mtd_sync,
6777#endif
6778 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006779 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6780 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006781 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6782 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Jon Coopere5fbd972017-02-08 16:52:10 +00006783 .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
6784 .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
6785 .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
6786 .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006787#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01006788 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006789 .sriov_init = efx_ef10_sriov_init,
6790 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006791 .sriov_wanted = efx_ef10_sriov_wanted,
6792 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006793 .sriov_flr = efx_ef10_sriov_flr,
6794 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6795 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6796 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6797 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01006798 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006799 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6800 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6801 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006802#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006803 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01006804 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00006805 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01006806
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006807 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01006808 .revision = EFX_REV_HUNT_A0,
6809 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6810 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6811 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006812 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01006813 .can_rx_scatter = true,
6814 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00006815 .option_descriptors = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006816 .min_interrupt_mode = EFX_INT_MODE_LEGACY,
Ben Hutchings8127d662013-08-29 19:19:29 +01006817 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6818 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006819 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01006820 .mcdi_max_ver = 2,
6821 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006822 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6823 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006824 .rx_hash_key_size = 40,
Ben Hutchings8127d662013-08-29 19:19:29 +01006825};