blob: f6e29a975e4e844db85b1ad052ef37b8fada02c4 [file] [log] [blame]
Ben Hutchings8127d662013-08-29 19:19:29 +01001/****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2012-2013 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include "net_driver.h"
11#include "ef10_regs.h"
12#include "io.h"
13#include "mcdi.h"
14#include "mcdi_pcol.h"
15#include "nic.h"
16#include "workarounds.h"
Jon Cooper74cd60a2013-09-16 14:18:51 +010017#include "selftest.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010018#include "ef10_sriov.h"
Ben Hutchings8127d662013-08-29 19:19:29 +010019#include <linux/in.h>
20#include <linux/jhash.h>
21#include <linux/wait.h>
22#include <linux/workqueue.h>
23
24/* Hardware control for EF10 architecture including 'Huntington'. */
25
26#define EFX_EF10_DRVGEN_EV 7
27enum {
28 EFX_EF10_TEST = 1,
29 EFX_EF10_REFILL,
30};
31
32/* The reserved RSS context value */
33#define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
Jon Cooper267c0152015-05-06 00:59:38 +010034/* The maximum size of a shared RSS context */
35/* TODO: this should really be from the mcdi protocol export */
36#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
Ben Hutchings8127d662013-08-29 19:19:29 +010037
38/* The filter table(s) are managed by firmware and we have write-only
39 * access. When removing filters we must identify them to the
40 * firmware by a 64-bit handle, but this is too wide for Linux kernel
41 * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
42 * be able to tell in advance whether a requested insertion will
43 * replace an existing filter. Therefore we maintain a software hash
44 * table, which should be at least as large as the hardware hash
45 * table.
46 *
47 * Huntington has a single 8K filter table shared between all filter
48 * types and both ports.
49 */
50#define HUNT_FILTER_TBL_ROWS 8192
51
Edward Cree12fb0da2015-07-21 15:11:00 +010052#define EFX_EF10_FILTER_ID_INVALID 0xffff
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010053
54#define EFX_EF10_FILTER_DEV_UC_MAX 32
55#define EFX_EF10_FILTER_DEV_MC_MAX 256
56
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010057/* VLAN list entry */
58struct efx_ef10_vlan {
59 struct list_head list;
60 u16 vid;
61};
62
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010063/* Per-VLAN filters information */
64struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010065 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010066 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010067 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
68 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
69 u16 ucdef;
70 u16 bcast;
71 u16 mcdef;
72};
73
Daniel Pieczko822b96f2015-07-21 15:10:27 +010074struct efx_ef10_dev_addr {
75 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010076};
77
Ben Hutchings8127d662013-08-29 19:19:29 +010078struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010079/* The MCDI match masks supported by this fw & hw, in order of priority */
80 u32 rx_match_mcdi_flags[
Ben Hutchings8127d662013-08-29 19:19:29 +010081 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
82 unsigned int rx_match_count;
83
84 struct {
85 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000086/* BUSY flag indicates that an update is in progress. AUTO_OLD is
87 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +010088 */
89#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000090#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +010091#define EFX_EF10_FILTER_FLAGS 3UL
92 u64 handle; /* firmware handle */
93 } *entry;
94 wait_queue_head_t waitq;
95/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +010096 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
97 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +010098 int dev_uc_count;
99 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100100 bool uc_promisc;
101 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100102/* Whether in multicast promiscuous mode when last changed */
103 bool mc_promisc_last;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100104 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100105 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100106};
107
108/* An arbitrary search limit for the software hash table */
109#define EFX_EF10_FILTER_SEARCH_LIMIT 200
110
Ben Hutchings8127d662013-08-29 19:19:29 +0100111static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
112static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100113static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
114static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
115 struct efx_ef10_filter_vlan *vlan);
116static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Ben Hutchings8127d662013-08-29 19:19:29 +0100117
118static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
119{
120 efx_dword_t reg;
121
122 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
123 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
124 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
125}
126
127static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
128{
Shradha Shah02246a72015-05-06 00:58:14 +0100129 int bar;
130
131 bar = efx->type->mem_bar;
132 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100133}
134
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100135static bool efx_ef10_is_vf(struct efx_nic *efx)
136{
137 return efx->type->is_vf;
138}
139
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100140static int efx_ef10_get_pf_index(struct efx_nic *efx)
141{
142 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
143 struct efx_ef10_nic_data *nic_data = efx->nic_data;
144 size_t outlen;
145 int rc;
146
147 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
148 sizeof(outbuf), &outlen);
149 if (rc)
150 return rc;
151 if (outlen < sizeof(outbuf))
152 return -EIO;
153
154 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
155 return 0;
156}
157
Shradha Shah88a37de2015-05-20 11:09:15 +0100158#ifdef CONFIG_SFC_SRIOV
159static int efx_ef10_get_vf_index(struct efx_nic *efx)
160{
161 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
162 struct efx_ef10_nic_data *nic_data = efx->nic_data;
163 size_t outlen;
164 int rc;
165
166 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
167 sizeof(outbuf), &outlen);
168 if (rc)
169 return rc;
170 if (outlen < sizeof(outbuf))
171 return -EIO;
172
173 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
174 return 0;
175}
176#endif
177
Ben Hutchingse5a25382013-09-05 22:50:59 +0100178static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100179{
Bert Kenwardca889a02016-08-11 13:01:35 +0100180 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +0100181 struct efx_ef10_nic_data *nic_data = efx->nic_data;
182 size_t outlen;
183 int rc;
184
185 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
186
187 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
188 outbuf, sizeof(outbuf), &outlen);
189 if (rc)
190 return rc;
Bert Kenwardca889a02016-08-11 13:01:35 +0100191 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
Ben Hutchingse5a25382013-09-05 22:50:59 +0100192 netif_err(efx, drv, efx->net_dev,
193 "unable to read datapath firmware capabilities\n");
194 return -EIO;
195 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100196
Ben Hutchingse5a25382013-09-05 22:50:59 +0100197 nic_data->datapath_caps =
198 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
199
Bert Kenwardca889a02016-08-11 13:01:35 +0100200 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)
201 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
202 GET_CAPABILITIES_V2_OUT_FLAGS2);
203 else
204 nic_data->datapath_caps2 = 0;
205
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100206 /* record the DPCPU firmware IDs to determine VEB vswitching support.
207 */
208 nic_data->rx_dpcpu_fw_id =
209 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
210 nic_data->tx_dpcpu_fw_id =
211 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
212
Ben Hutchingse5a25382013-09-05 22:50:59 +0100213 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100214 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
215 netif_err(efx, probe, efx->net_dev,
216 "current firmware does not support an RX prefix\n");
217 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100218 }
219
220 return 0;
221}
222
223static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
224{
225 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
226 int rc;
227
228 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
229 outbuf, sizeof(outbuf), NULL);
230 if (rc)
231 return rc;
232 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
233 return rc > 0 ? rc : -ERANGE;
234}
235
Bert Kenwardd95e3292016-08-11 13:02:36 +0100236static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
237{
238 struct efx_ef10_nic_data *nic_data = efx->nic_data;
239 unsigned int implemented;
240 unsigned int enabled;
241 int rc;
242
243 nic_data->workaround_35388 = false;
244 nic_data->workaround_61265 = false;
245
246 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
247
248 if (rc == -ENOSYS) {
249 /* Firmware without GET_WORKAROUNDS - not a problem. */
250 rc = 0;
251 } else if (rc == 0) {
252 /* Bug61265 workaround is always enabled if implemented. */
253 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
254 nic_data->workaround_61265 = true;
255
256 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
257 nic_data->workaround_35388 = true;
258 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
259 /* Workaround is implemented but not enabled.
260 * Try to enable it.
261 */
262 rc = efx_mcdi_set_workaround(efx,
263 MC_CMD_WORKAROUND_BUG35388,
264 true, NULL);
265 if (rc == 0)
266 nic_data->workaround_35388 = true;
267 /* If we failed to set the workaround just carry on. */
268 rc = 0;
269 }
270 }
271
272 netif_dbg(efx, probe, efx->net_dev,
273 "workaround for bug 35388 is %sabled\n",
274 nic_data->workaround_35388 ? "en" : "dis");
275 netif_dbg(efx, probe, efx->net_dev,
276 "workaround for bug 61265 is %sabled\n",
277 nic_data->workaround_61265 ? "en" : "dis");
278
279 return rc;
280}
281
282static void efx_ef10_process_timer_config(struct efx_nic *efx,
283 const efx_dword_t *data)
284{
285 unsigned int max_count;
286
287 if (EFX_EF10_WORKAROUND_61265(efx)) {
288 efx->timer_quantum_ns = MCDI_DWORD(data,
289 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
290 efx->timer_max_ns = MCDI_DWORD(data,
291 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
292 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
293 efx->timer_quantum_ns = MCDI_DWORD(data,
294 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
295 max_count = MCDI_DWORD(data,
296 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
297 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
298 } else {
299 efx->timer_quantum_ns = MCDI_DWORD(data,
300 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
301 max_count = MCDI_DWORD(data,
302 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
303 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
304 }
305
306 netif_dbg(efx, probe, efx->net_dev,
307 "got timer properties from MC: quantum %u ns; max %u ns\n",
308 efx->timer_quantum_ns, efx->timer_max_ns);
309}
310
311static int efx_ef10_get_timer_config(struct efx_nic *efx)
312{
313 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
314 int rc;
315
316 rc = efx_ef10_get_timer_workarounds(efx);
317 if (rc)
318 return rc;
319
320 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
321 outbuf, sizeof(outbuf), NULL);
322
323 if (rc == 0) {
324 efx_ef10_process_timer_config(efx, outbuf);
325 } else if (rc == -ENOSYS || rc == -EPERM) {
326 /* Not available - fall back to Huntington defaults. */
327 unsigned int quantum;
328
329 rc = efx_ef10_get_sysclk_freq(efx);
330 if (rc < 0)
331 return rc;
332
333 quantum = 1536000 / rc; /* 1536 cycles */
334 efx->timer_quantum_ns = quantum;
335 efx->timer_max_ns = efx->type->timer_period_max * quantum;
336 rc = 0;
337 } else {
338 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
339 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
340 NULL, 0, rc);
341 }
342
343 return rc;
344}
345
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100346static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100347{
348 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
349 size_t outlen;
350 int rc;
351
352 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
353
354 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
355 outbuf, sizeof(outbuf), &outlen);
356 if (rc)
357 return rc;
358 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
359 return -EIO;
360
Edward Creecd84ff42014-03-07 18:27:41 +0000361 ether_addr_copy(mac_address,
362 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100363 return 0;
364}
365
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100366static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
367{
368 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
369 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
370 size_t outlen;
371 int num_addrs, rc;
372
373 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
374 EVB_PORT_ID_ASSIGNED);
375 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
376 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
377
378 if (rc)
379 return rc;
380 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
381 return -EIO;
382
383 num_addrs = MCDI_DWORD(outbuf,
384 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
385
386 WARN_ON(num_addrs != 1);
387
388 ether_addr_copy(mac_address,
389 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
390
391 return 0;
392}
393
Shradha Shah0f5c0842015-06-02 11:37:58 +0100394static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
395 struct device_attribute *attr,
396 char *buf)
397{
398 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
399
400 return sprintf(buf, "%d\n",
401 ((efx->mcdi->fn_flags) &
402 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
403 ? 1 : 0);
404}
405
406static ssize_t efx_ef10_show_primary_flag(struct device *dev,
407 struct device_attribute *attr,
408 char *buf)
409{
410 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
411
412 return sprintf(buf, "%d\n",
413 ((efx->mcdi->fn_flags) &
414 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
415 ? 1 : 0);
416}
417
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100418static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
419{
420 struct efx_ef10_nic_data *nic_data = efx->nic_data;
421 struct efx_ef10_vlan *vlan;
422
423 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
424
425 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
426 if (vlan->vid == vid)
427 return vlan;
428 }
429
430 return NULL;
431}
432
433static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
434{
435 struct efx_ef10_nic_data *nic_data = efx->nic_data;
436 struct efx_ef10_vlan *vlan;
437 int rc;
438
439 mutex_lock(&nic_data->vlan_lock);
440
441 vlan = efx_ef10_find_vlan(efx, vid);
442 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100443 /* We add VID 0 on init. 8021q adds it on module init
444 * for all interfaces with VLAN filtring feature.
445 */
446 if (vid == 0)
447 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100448 netif_warn(efx, drv, efx->net_dev,
449 "VLAN %u already added\n", vid);
450 rc = -EALREADY;
451 goto fail_exist;
452 }
453
454 rc = -ENOMEM;
455 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
456 if (!vlan)
457 goto fail_alloc;
458
459 vlan->vid = vid;
460
461 list_add_tail(&vlan->list, &nic_data->vlan_list);
462
463 if (efx->filter_state) {
464 mutex_lock(&efx->mac_lock);
465 down_write(&efx->filter_sem);
466 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
467 up_write(&efx->filter_sem);
468 mutex_unlock(&efx->mac_lock);
469 if (rc)
470 goto fail_filter_add_vlan;
471 }
472
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100473done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100474 mutex_unlock(&nic_data->vlan_lock);
475 return 0;
476
477fail_filter_add_vlan:
478 list_del(&vlan->list);
479 kfree(vlan);
480fail_alloc:
481fail_exist:
482 mutex_unlock(&nic_data->vlan_lock);
483 return rc;
484}
485
486static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
487 struct efx_ef10_vlan *vlan)
488{
489 struct efx_ef10_nic_data *nic_data = efx->nic_data;
490
491 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
492
493 if (efx->filter_state) {
494 down_write(&efx->filter_sem);
495 efx_ef10_filter_del_vlan(efx, vlan->vid);
496 up_write(&efx->filter_sem);
497 }
498
499 list_del(&vlan->list);
500 kfree(vlan);
501}
502
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100503static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
504{
505 struct efx_ef10_nic_data *nic_data = efx->nic_data;
506 struct efx_ef10_vlan *vlan;
507 int rc = 0;
508
509 /* 8021q removes VID 0 on module unload for all interfaces
510 * with VLAN filtering feature. We need to keep it to receive
511 * untagged traffic.
512 */
513 if (vid == 0)
514 return 0;
515
516 mutex_lock(&nic_data->vlan_lock);
517
518 vlan = efx_ef10_find_vlan(efx, vid);
519 if (!vlan) {
520 netif_err(efx, drv, efx->net_dev,
521 "VLAN %u to be deleted not found\n", vid);
522 rc = -ENOENT;
523 } else {
524 efx_ef10_del_vlan_internal(efx, vlan);
525 }
526
527 mutex_unlock(&nic_data->vlan_lock);
528
529 return rc;
530}
531
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100532static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
533{
534 struct efx_ef10_nic_data *nic_data = efx->nic_data;
535 struct efx_ef10_vlan *vlan, *next_vlan;
536
537 mutex_lock(&nic_data->vlan_lock);
538 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
539 efx_ef10_del_vlan_internal(efx, vlan);
540 mutex_unlock(&nic_data->vlan_lock);
541}
542
Shradha Shah0f5c0842015-06-02 11:37:58 +0100543static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
544 NULL);
545static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
546
Ben Hutchings8127d662013-08-29 19:19:29 +0100547static int efx_ef10_probe(struct efx_nic *efx)
548{
549 struct efx_ef10_nic_data *nic_data;
550 int i, rc;
551
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000552 /* We can have one VI for each 8K region. However, until we
553 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100554 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100555 efx->max_channels = min_t(unsigned int,
556 EFX_MAX_CHANNELS,
557 efx_ef10_mem_map_size(efx) /
558 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
559 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000560 if (WARN_ON(efx->max_channels == 0))
561 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100562
563 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
564 if (!nic_data)
565 return -ENOMEM;
566 efx->nic_data = nic_data;
567
Edward Cree75aba2a2015-05-27 13:13:54 +0100568 /* we assume later that we can copy from this buffer in dwords */
569 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
570
Ben Hutchings8127d662013-08-29 19:19:29 +0100571 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
572 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
573 if (rc)
574 goto fail1;
575
576 /* Get the MC's warm boot count. In case it's rebooting right
577 * now, be prepared to retry.
578 */
579 i = 0;
580 for (;;) {
581 rc = efx_ef10_get_warm_boot_count(efx);
582 if (rc >= 0)
583 break;
584 if (++i == 5)
585 goto fail2;
586 ssleep(1);
587 }
588 nic_data->warm_boot_count = rc;
589
590 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
591
Daniel Pieczko45b24492015-05-06 00:57:14 +0100592 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
593
Ben Hutchings8127d662013-08-29 19:19:29 +0100594 /* In case we're recovering from a crash (kexec), we want to
595 * cancel any outstanding request by the previous user of this
596 * function. We send a special message using the least
597 * significant bits of the 'high' (doorbell) register.
598 */
599 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
600
601 rc = efx_mcdi_init(efx);
602 if (rc)
603 goto fail2;
604
605 /* Reset (most) configuration for this function */
606 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
607 if (rc)
608 goto fail3;
609
610 /* Enable event logging */
611 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
612 if (rc)
613 goto fail3;
614
Shradha Shah0f5c0842015-06-02 11:37:58 +0100615 rc = device_create_file(&efx->pci_dev->dev,
616 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100617 if (rc)
618 goto fail3;
619
Shradha Shah0f5c0842015-06-02 11:37:58 +0100620 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
621 if (rc)
622 goto fail4;
623
624 rc = efx_ef10_get_pf_index(efx);
625 if (rc)
626 goto fail5;
627
Ben Hutchingse5a25382013-09-05 22:50:59 +0100628 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100629 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100630 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100631
632 efx->rx_packet_len_offset =
633 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
634
Ben Hutchings8127d662013-08-29 19:19:29 +0100635 rc = efx_mcdi_port_get_number(efx);
636 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100637 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100638 efx->port_num = rc;
639
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100640 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100641 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100642 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100643
Bert Kenwardd95e3292016-08-11 13:02:36 +0100644 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100645 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100646 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100647
Ben Hutchings8127d662013-08-29 19:19:29 +0100648 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100649 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100650 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100651
Ben Hutchings9aecda92013-12-05 21:28:42 +0000652 efx_ptp_probe(efx, NULL);
653
Shradha Shah1d051e02015-06-02 11:38:16 +0100654#ifdef CONFIG_SFC_SRIOV
655 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
656 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
657 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
658
659 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
660 } else
661#endif
662 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
663
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100664 INIT_LIST_HEAD(&nic_data->vlan_list);
665 mutex_init(&nic_data->vlan_lock);
666
667 /* Add unspecified VID to support VLAN filtering being disabled */
668 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
669 if (rc)
670 goto fail_add_vid_unspec;
671
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100672 /* If VLAN filtering is enabled, we need VID 0 to get untagged
673 * traffic. It is added automatically if 8021q module is loaded,
674 * but we can't rely on it since module may be not loaded.
675 */
676 rc = efx_ef10_add_vlan(efx, 0);
677 if (rc)
678 goto fail_add_vid_0;
679
Ben Hutchings8127d662013-08-29 19:19:29 +0100680 return 0;
681
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100682fail_add_vid_0:
683 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100684fail_add_vid_unspec:
685 mutex_destroy(&nic_data->vlan_lock);
686 efx_ptp_remove(efx);
687 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100688fail5:
689 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
690fail4:
691 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100692fail3:
693 efx_mcdi_fini(efx);
694fail2:
695 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
696fail1:
697 kfree(nic_data);
698 efx->nic_data = NULL;
699 return rc;
700}
701
702static int efx_ef10_free_vis(struct efx_nic *efx)
703{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100704 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100705 size_t outlen;
706 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
707 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100708
709 /* -EALREADY means nothing to free, so ignore */
710 if (rc == -EALREADY)
711 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100712 if (rc)
713 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
714 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100715 return rc;
716}
717
Ben Hutchings183233b2013-06-28 21:47:12 +0100718#ifdef EFX_USE_PIO
719
720static void efx_ef10_free_piobufs(struct efx_nic *efx)
721{
722 struct efx_ef10_nic_data *nic_data = efx->nic_data;
723 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
724 unsigned int i;
725 int rc;
726
727 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
728
729 for (i = 0; i < nic_data->n_piobufs; i++) {
730 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
731 nic_data->piobuf_handle[i]);
732 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
733 NULL, 0, NULL);
734 WARN_ON(rc);
735 }
736
737 nic_data->n_piobufs = 0;
738}
739
740static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
741{
742 struct efx_ef10_nic_data *nic_data = efx->nic_data;
743 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
744 unsigned int i;
745 size_t outlen;
746 int rc = 0;
747
748 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
749
750 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000751 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
752 outbuf, sizeof(outbuf), &outlen);
753 if (rc) {
754 /* Don't display the MC error if we didn't have space
755 * for a VF.
756 */
757 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
758 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
759 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100760 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000761 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100762 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
763 rc = -EIO;
764 break;
765 }
766 nic_data->piobuf_handle[i] =
767 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
768 netif_dbg(efx, probe, efx->net_dev,
769 "allocated PIO buffer %u handle %x\n", i,
770 nic_data->piobuf_handle[i]);
771 }
772
773 nic_data->n_piobufs = i;
774 if (rc)
775 efx_ef10_free_piobufs(efx);
776 return rc;
777}
778
779static int efx_ef10_link_piobufs(struct efx_nic *efx)
780{
781 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100782 _MCDI_DECLARE_BUF(inbuf,
783 max(MC_CMD_LINK_PIOBUF_IN_LEN,
784 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100785 struct efx_channel *channel;
786 struct efx_tx_queue *tx_queue;
787 unsigned int offset, index;
788 int rc;
789
790 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
791 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
792
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100793 memset(inbuf, 0, sizeof(inbuf));
794
Ben Hutchings183233b2013-06-28 21:47:12 +0100795 /* Link a buffer to each VI in the write-combining mapping */
796 for (index = 0; index < nic_data->n_piobufs; ++index) {
797 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
798 nic_data->piobuf_handle[index]);
799 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
800 nic_data->pio_write_vi_base + index);
801 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
802 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
803 NULL, 0, NULL);
804 if (rc) {
805 netif_err(efx, drv, efx->net_dev,
806 "failed to link VI %u to PIO buffer %u (%d)\n",
807 nic_data->pio_write_vi_base + index, index,
808 rc);
809 goto fail;
810 }
811 netif_dbg(efx, probe, efx->net_dev,
812 "linked VI %u to PIO buffer %u\n",
813 nic_data->pio_write_vi_base + index, index);
814 }
815
816 /* Link a buffer to each TX queue */
817 efx_for_each_channel(channel, efx) {
818 efx_for_each_channel_tx_queue(tx_queue, channel) {
819 /* We assign the PIO buffers to queues in
820 * reverse order to allow for the following
821 * special case.
822 */
823 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
824 tx_queue->channel->channel - 1) *
825 efx_piobuf_size);
826 index = offset / ER_DZ_TX_PIOBUF_SIZE;
827 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
828
829 /* When the host page size is 4K, the first
830 * host page in the WC mapping may be within
831 * the same VI page as the last TX queue. We
832 * can only link one buffer to each VI.
833 */
834 if (tx_queue->queue == nic_data->pio_write_vi_base) {
835 BUG_ON(index != 0);
836 rc = 0;
837 } else {
838 MCDI_SET_DWORD(inbuf,
839 LINK_PIOBUF_IN_PIOBUF_HANDLE,
840 nic_data->piobuf_handle[index]);
841 MCDI_SET_DWORD(inbuf,
842 LINK_PIOBUF_IN_TXQ_INSTANCE,
843 tx_queue->queue);
844 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
845 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
846 NULL, 0, NULL);
847 }
848
849 if (rc) {
850 /* This is non-fatal; the TX path just
851 * won't use PIO for this queue
852 */
853 netif_err(efx, drv, efx->net_dev,
854 "failed to link VI %u to PIO buffer %u (%d)\n",
855 tx_queue->queue, index, rc);
856 tx_queue->piobuf = NULL;
857 } else {
858 tx_queue->piobuf =
859 nic_data->pio_write_base +
860 index * EFX_VI_PAGE_SIZE + offset;
861 tx_queue->piobuf_offset = offset;
862 netif_dbg(efx, probe, efx->net_dev,
863 "linked VI %u to PIO buffer %u offset %x addr %p\n",
864 tx_queue->queue, index,
865 tx_queue->piobuf_offset,
866 tx_queue->piobuf);
867 }
868 }
869 }
870
871 return 0;
872
873fail:
874 while (index--) {
875 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
876 nic_data->pio_write_vi_base + index);
877 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
878 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
879 NULL, 0, NULL);
880 }
881 return rc;
882}
883
Edward Creec0795bf2016-05-24 18:53:36 +0100884static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
885{
886 struct efx_channel *channel;
887 struct efx_tx_queue *tx_queue;
888
889 /* All our existing PIO buffers went away */
890 efx_for_each_channel(channel, efx)
891 efx_for_each_channel_tx_queue(tx_queue, channel)
892 tx_queue->piobuf = NULL;
893}
894
Ben Hutchings183233b2013-06-28 21:47:12 +0100895#else /* !EFX_USE_PIO */
896
897static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
898{
899 return n == 0 ? 0 : -ENOBUFS;
900}
901
902static int efx_ef10_link_piobufs(struct efx_nic *efx)
903{
904 return 0;
905}
906
907static void efx_ef10_free_piobufs(struct efx_nic *efx)
908{
909}
910
Edward Creec0795bf2016-05-24 18:53:36 +0100911static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
912{
913}
914
Ben Hutchings183233b2013-06-28 21:47:12 +0100915#endif /* EFX_USE_PIO */
916
Ben Hutchings8127d662013-08-29 19:19:29 +0100917static void efx_ef10_remove(struct efx_nic *efx)
918{
919 struct efx_ef10_nic_data *nic_data = efx->nic_data;
920 int rc;
921
Shradha Shahf1122a32015-05-20 11:09:46 +0100922#ifdef CONFIG_SFC_SRIOV
923 struct efx_ef10_nic_data *nic_data_pf;
924 struct pci_dev *pci_dev_pf;
925 struct efx_nic *efx_pf;
926 struct ef10_vf *vf;
927
928 if (efx->pci_dev->is_virtfn) {
929 pci_dev_pf = efx->pci_dev->physfn;
930 if (pci_dev_pf) {
931 efx_pf = pci_get_drvdata(pci_dev_pf);
932 nic_data_pf = efx_pf->nic_data;
933 vf = nic_data_pf->vf + nic_data->vf_index;
934 vf->efx = NULL;
935 } else
936 netif_info(efx, drv, efx->net_dev,
937 "Could not get the PF id from VF\n");
938 }
939#endif
940
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100941 efx_ef10_cleanup_vlans(efx);
942 mutex_destroy(&nic_data->vlan_lock);
943
Ben Hutchings9aecda92013-12-05 21:28:42 +0000944 efx_ptp_remove(efx);
945
Ben Hutchings8127d662013-08-29 19:19:29 +0100946 efx_mcdi_mon_remove(efx);
947
Ben Hutchings8127d662013-08-29 19:19:29 +0100948 efx_ef10_rx_free_indir_table(efx);
949
Ben Hutchings183233b2013-06-28 21:47:12 +0100950 if (nic_data->wc_membase)
951 iounmap(nic_data->wc_membase);
952
Ben Hutchings8127d662013-08-29 19:19:29 +0100953 rc = efx_ef10_free_vis(efx);
954 WARN_ON(rc != 0);
955
Ben Hutchings183233b2013-06-28 21:47:12 +0100956 if (!nic_data->must_restore_piobufs)
957 efx_ef10_free_piobufs(efx);
958
Shradha Shah0f5c0842015-06-02 11:37:58 +0100959 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
960 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
961
Ben Hutchings8127d662013-08-29 19:19:29 +0100962 efx_mcdi_fini(efx);
963 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
964 kfree(nic_data);
965}
966
Shradha Shah88a37de2015-05-20 11:09:15 +0100967static int efx_ef10_probe_pf(struct efx_nic *efx)
968{
969 return efx_ef10_probe(efx);
970}
971
Andrew Rybchenko38d27f32016-06-15 17:52:08 +0100972int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
973 u32 *port_flags, u32 *vadaptor_flags,
974 unsigned int *vlan_tags)
975{
976 struct efx_ef10_nic_data *nic_data = efx->nic_data;
977 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
978 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
979 size_t outlen;
980 int rc;
981
982 if (nic_data->datapath_caps &
983 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
984 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
985 port_id);
986
987 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
988 outbuf, sizeof(outbuf), &outlen);
989 if (rc)
990 return rc;
991
992 if (outlen < sizeof(outbuf)) {
993 rc = -EIO;
994 return rc;
995 }
996 }
997
998 if (port_flags)
999 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1000 if (vadaptor_flags)
1001 *vadaptor_flags =
1002 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1003 if (vlan_tags)
1004 *vlan_tags =
1005 MCDI_DWORD(outbuf,
1006 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1007
1008 return 0;
1009}
1010
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001011int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1012{
1013 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1014
1015 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1016 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1017 NULL, 0, NULL);
1018}
1019
1020int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1021{
1022 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1023
1024 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1025 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1026 NULL, 0, NULL);
1027}
1028
1029int efx_ef10_vport_add_mac(struct efx_nic *efx,
1030 unsigned int port_id, u8 *mac)
1031{
1032 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1033
1034 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1035 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1036
1037 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1038 sizeof(inbuf), NULL, 0, NULL);
1039}
1040
1041int efx_ef10_vport_del_mac(struct efx_nic *efx,
1042 unsigned int port_id, u8 *mac)
1043{
1044 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1045
1046 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1047 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1048
1049 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1050 sizeof(inbuf), NULL, 0, NULL);
1051}
1052
Shradha Shah88a37de2015-05-20 11:09:15 +01001053#ifdef CONFIG_SFC_SRIOV
1054static int efx_ef10_probe_vf(struct efx_nic *efx)
1055{
1056 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001057 struct pci_dev *pci_dev_pf;
1058
1059 /* If the parent PF has no VF data structure, it doesn't know about this
1060 * VF so fail probe. The VF needs to be re-created. This can happen
1061 * if the PF driver is unloaded while the VF is assigned to a guest.
1062 */
1063 pci_dev_pf = efx->pci_dev->physfn;
1064 if (pci_dev_pf) {
1065 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1066 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1067
1068 if (!nic_data_pf->vf) {
1069 netif_info(efx, drv, efx->net_dev,
1070 "The VF cannot link to its parent PF; "
1071 "please destroy and re-create the VF\n");
1072 return -EBUSY;
1073 }
1074 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001075
1076 rc = efx_ef10_probe(efx);
1077 if (rc)
1078 return rc;
1079
1080 rc = efx_ef10_get_vf_index(efx);
1081 if (rc)
1082 goto fail;
1083
Shradha Shahf1122a32015-05-20 11:09:46 +01001084 if (efx->pci_dev->is_virtfn) {
1085 if (efx->pci_dev->physfn) {
1086 struct efx_nic *efx_pf =
1087 pci_get_drvdata(efx->pci_dev->physfn);
1088 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1089 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1090
1091 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001092 nic_data_p->vf[nic_data->vf_index].pci_dev =
1093 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001094 } else
1095 netif_info(efx, drv, efx->net_dev,
1096 "Could not get the PF id from VF\n");
1097 }
1098
Shradha Shah88a37de2015-05-20 11:09:15 +01001099 return 0;
1100
1101fail:
1102 efx_ef10_remove(efx);
1103 return rc;
1104}
1105#else
1106static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1107{
1108 return 0;
1109}
1110#endif
1111
Ben Hutchings8127d662013-08-29 19:19:29 +01001112static int efx_ef10_alloc_vis(struct efx_nic *efx,
1113 unsigned int min_vis, unsigned int max_vis)
1114{
1115 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1116 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1117 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1118 size_t outlen;
1119 int rc;
1120
1121 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1122 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1123 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1124 outbuf, sizeof(outbuf), &outlen);
1125 if (rc != 0)
1126 return rc;
1127
1128 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1129 return -EIO;
1130
1131 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1132 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1133
1134 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1135 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1136 return 0;
1137}
1138
Ben Hutchings183233b2013-06-28 21:47:12 +01001139/* Note that the failure path of this function does not free
1140 * resources, as this will be done by efx_ef10_remove().
1141 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001142static int efx_ef10_dimension_resources(struct efx_nic *efx)
1143{
Ben Hutchings183233b2013-06-28 21:47:12 +01001144 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1145 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001146 unsigned int min_vis = max(EFX_TXQ_TYPES,
1147 efx_separate_tx_channels ? 2 : 1);
1148 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001149 void __iomem *membase;
1150 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001151
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001152 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001153
1154#ifdef EFX_USE_PIO
1155 /* Try to allocate PIO buffers if wanted and if the full
1156 * number of PIO buffers would be sufficient to allocate one
1157 * copy-buffer per TX channel. Failure is non-fatal, as there
1158 * are only a small number of PIO buffers shared between all
1159 * functions of the controller.
1160 */
1161 if (efx_piobuf_size != 0 &&
1162 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1163 efx->n_tx_channels) {
1164 unsigned int n_piobufs =
1165 DIV_ROUND_UP(efx->n_tx_channels,
1166 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
1167
1168 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1169 if (rc)
1170 netif_err(efx, probe, efx->net_dev,
1171 "failed to allocate PIO buffers (%d)\n", rc);
1172 else
1173 netif_dbg(efx, probe, efx->net_dev,
1174 "allocated %u PIO buffers\n", n_piobufs);
1175 }
1176#else
1177 nic_data->n_piobufs = 0;
1178#endif
1179
1180 /* PIO buffers should be mapped with write-combining enabled,
1181 * and we want to make single UC and WC mappings rather than
1182 * several of each (in fact that's the only option if host
1183 * page size is >4K). So we may allocate some extra VIs just
1184 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001185 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001186 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001187 * first half of the next VI. Then the WC mapping begins with
1188 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001189 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001190 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001191 ER_DZ_TX_PIOBUF);
1192 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001193 /* pio_write_vi_base rounds down to give the number of complete
1194 * VIs inside the UC mapping.
1195 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001196 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1197 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1198 nic_data->n_piobufs) *
1199 EFX_VI_PAGE_SIZE) -
1200 uc_mem_map_size);
1201 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1202 } else {
1203 pio_write_vi_base = 0;
1204 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001205 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001206 }
1207
1208 /* In case the last attached driver failed to free VIs, do it now */
1209 rc = efx_ef10_free_vis(efx);
1210 if (rc != 0)
1211 return rc;
1212
1213 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1214 if (rc != 0)
1215 return rc;
1216
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001217 if (nic_data->n_allocated_vis < channel_vis) {
1218 netif_info(efx, drv, efx->net_dev,
1219 "Could not allocate enough VIs to satisfy RSS"
1220 " requirements. Performance may not be optimal.\n");
1221 /* We didn't get the VIs to populate our channels.
1222 * We could keep what we got but then we'd have more
1223 * interrupts than we need.
1224 * Instead calculate new max_channels and restart
1225 */
1226 efx->max_channels = nic_data->n_allocated_vis;
1227 efx->max_tx_channels =
1228 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1229
1230 efx_ef10_free_vis(efx);
1231 return -EAGAIN;
1232 }
1233
Ben Hutchings183233b2013-06-28 21:47:12 +01001234 /* If we didn't get enough VIs to map all the PIO buffers, free the
1235 * PIO buffers
1236 */
1237 if (nic_data->n_piobufs &&
1238 nic_data->n_allocated_vis <
1239 pio_write_vi_base + nic_data->n_piobufs) {
1240 netif_dbg(efx, probe, efx->net_dev,
1241 "%u VIs are not sufficient to map %u PIO buffers\n",
1242 nic_data->n_allocated_vis, nic_data->n_piobufs);
1243 efx_ef10_free_piobufs(efx);
1244 }
1245
1246 /* Shrink the original UC mapping of the memory BAR */
1247 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1248 if (!membase) {
1249 netif_err(efx, probe, efx->net_dev,
1250 "could not shrink memory BAR to %x\n",
1251 uc_mem_map_size);
1252 return -ENOMEM;
1253 }
1254 iounmap(efx->membase);
1255 efx->membase = membase;
1256
1257 /* Set up the WC mapping if needed */
1258 if (wc_mem_map_size) {
1259 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1260 uc_mem_map_size,
1261 wc_mem_map_size);
1262 if (!nic_data->wc_membase) {
1263 netif_err(efx, probe, efx->net_dev,
1264 "could not allocate WC mapping of size %x\n",
1265 wc_mem_map_size);
1266 return -ENOMEM;
1267 }
1268 nic_data->pio_write_vi_base = pio_write_vi_base;
1269 nic_data->pio_write_base =
1270 nic_data->wc_membase +
1271 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1272 uc_mem_map_size);
1273
1274 rc = efx_ef10_link_piobufs(efx);
1275 if (rc)
1276 efx_ef10_free_piobufs(efx);
1277 }
1278
1279 netif_dbg(efx, probe, efx->net_dev,
1280 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1281 &efx->membase_phys, efx->membase, uc_mem_map_size,
1282 nic_data->wc_membase, wc_mem_map_size);
1283
1284 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001285}
1286
1287static int efx_ef10_init_nic(struct efx_nic *efx)
1288{
1289 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1290 int rc;
1291
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001292 if (nic_data->must_check_datapath_caps) {
1293 rc = efx_ef10_init_datapath_caps(efx);
1294 if (rc)
1295 return rc;
1296 nic_data->must_check_datapath_caps = false;
1297 }
1298
Ben Hutchings8127d662013-08-29 19:19:29 +01001299 if (nic_data->must_realloc_vis) {
1300 /* We cannot let the number of VIs change now */
1301 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1302 nic_data->n_allocated_vis);
1303 if (rc)
1304 return rc;
1305 nic_data->must_realloc_vis = false;
1306 }
1307
Ben Hutchings183233b2013-06-28 21:47:12 +01001308 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1309 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1310 if (rc == 0) {
1311 rc = efx_ef10_link_piobufs(efx);
1312 if (rc)
1313 efx_ef10_free_piobufs(efx);
1314 }
1315
1316 /* Log an error on failure, but this is non-fatal */
1317 if (rc)
1318 netif_err(efx, drv, efx->net_dev,
1319 "failed to restore PIO buffers (%d)\n", rc);
1320 nic_data->must_restore_piobufs = false;
1321 }
1322
Jon Cooper267c0152015-05-06 00:59:38 +01001323 /* don't fail init if RSS setup doesn't work */
Edward Cree4fdda952017-01-04 15:10:56 +00001324 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1325 efx->rss_active = (rc == 0);
Jon Cooper267c0152015-05-06 00:59:38 +01001326
Ben Hutchings8127d662013-08-29 19:19:29 +01001327 return 0;
1328}
1329
Jon Cooper3e336262014-01-17 19:48:06 +00001330static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1331{
1332 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001333#ifdef CONFIG_SFC_SRIOV
1334 unsigned int i;
1335#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001336
1337 /* All our allocations have been reset */
1338 nic_data->must_realloc_vis = true;
1339 nic_data->must_restore_filters = true;
1340 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001341 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001342 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001343
1344 /* Driver-created vswitches and vports must be re-created */
1345 nic_data->must_probe_vswitching = true;
1346 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1347#ifdef CONFIG_SFC_SRIOV
1348 if (nic_data->vf)
1349 for (i = 0; i < efx->vf_count; i++)
1350 nic_data->vf[i].vport_id = 0;
1351#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001352}
1353
Jon Cooper087e9022015-05-20 11:11:35 +01001354static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1355{
1356 if (reason == RESET_TYPE_MC_FAILURE)
1357 return RESET_TYPE_DATAPATH;
1358
1359 return efx_mcdi_map_reset_reason(reason);
1360}
1361
Ben Hutchings8127d662013-08-29 19:19:29 +01001362static int efx_ef10_map_reset_flags(u32 *flags)
1363{
1364 enum {
1365 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1366 ETH_RESET_SHARED_SHIFT),
1367 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1368 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1369 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1370 ETH_RESET_SHARED_SHIFT)
1371 };
1372
1373 /* We assume for now that our PCI function is permitted to
1374 * reset everything.
1375 */
1376
1377 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1378 *flags &= ~EF10_RESET_MC;
1379 return RESET_TYPE_WORLD;
1380 }
1381
1382 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1383 *flags &= ~EF10_RESET_PORT;
1384 return RESET_TYPE_ALL;
1385 }
1386
1387 /* no invisible reset implemented */
1388
1389 return -EINVAL;
1390}
1391
Jon Cooper3e336262014-01-17 19:48:06 +00001392static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1393{
1394 int rc = efx_mcdi_reset(efx, reset_type);
1395
Daniel Pieczko27324822015-07-31 11:14:54 +01001396 /* Unprivileged functions return -EPERM, but need to return success
1397 * here so that the datapath is brought back up.
1398 */
1399 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1400 rc = 0;
1401
Jon Cooper3e336262014-01-17 19:48:06 +00001402 /* If it was a port reset, trigger reallocation of MC resources.
1403 * Note that on an MC reset nothing needs to be done now because we'll
1404 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001405 * For an FLR, we never get an MC reset event, but the MC has reset all
1406 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001407 */
Edward Creee2835462014-04-16 19:27:48 +01001408 if ((reset_type == RESET_TYPE_ALL ||
1409 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001410 efx_ef10_reset_mc_allocations(efx);
1411 return rc;
1412}
1413
Ben Hutchings8127d662013-08-29 19:19:29 +01001414#define EF10_DMA_STAT(ext_name, mcdi_name) \
1415 [EF10_STAT_ ## ext_name] = \
1416 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1417#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1418 [EF10_STAT_ ## int_name] = \
1419 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1420#define EF10_OTHER_STAT(ext_name) \
1421 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001422#define GENERIC_SW_STAT(ext_name) \
1423 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001424
1425static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001426 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1427 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1428 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1429 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1430 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1431 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1432 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1433 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1434 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1435 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1436 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1437 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1438 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1439 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1440 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1441 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1442 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1443 EF10_OTHER_STAT(port_rx_good_bytes),
1444 EF10_OTHER_STAT(port_rx_bad_bytes),
1445 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1446 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1447 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1448 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1449 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1450 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1451 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1452 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1453 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1454 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1455 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1456 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1457 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1458 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1459 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1460 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1461 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1462 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1463 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1464 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1465 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1466 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001467 GENERIC_SW_STAT(rx_nodesc_trunc),
1468 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001469 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1470 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1471 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1472 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1473 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1474 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1475 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1476 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1477 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1478 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1479 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1480 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001481 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1482 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1483 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1484 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1485 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1486 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1487 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1488 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1489 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1490 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1491 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1492 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1493 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1494 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1495 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1496 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1497 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1498 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001499};
1500
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001501#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1502 (1ULL << EF10_STAT_port_tx_packets) | \
1503 (1ULL << EF10_STAT_port_tx_pause) | \
1504 (1ULL << EF10_STAT_port_tx_unicast) | \
1505 (1ULL << EF10_STAT_port_tx_multicast) | \
1506 (1ULL << EF10_STAT_port_tx_broadcast) | \
1507 (1ULL << EF10_STAT_port_rx_bytes) | \
1508 (1ULL << \
1509 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1510 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1511 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1512 (1ULL << EF10_STAT_port_rx_packets) | \
1513 (1ULL << EF10_STAT_port_rx_good) | \
1514 (1ULL << EF10_STAT_port_rx_bad) | \
1515 (1ULL << EF10_STAT_port_rx_pause) | \
1516 (1ULL << EF10_STAT_port_rx_control) | \
1517 (1ULL << EF10_STAT_port_rx_unicast) | \
1518 (1ULL << EF10_STAT_port_rx_multicast) | \
1519 (1ULL << EF10_STAT_port_rx_broadcast) | \
1520 (1ULL << EF10_STAT_port_rx_lt64) | \
1521 (1ULL << EF10_STAT_port_rx_64) | \
1522 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1523 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1524 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1525 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1526 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1527 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1528 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1529 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1530 (1ULL << EF10_STAT_port_rx_overflow) | \
1531 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001532 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1533 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001534
Edward Cree69b365c2016-08-26 15:12:41 +01001535/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1536 * For a 10G/40G switchable port we do not expose these because they might
1537 * not include all the packets they should.
1538 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001539 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001540#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1541 (1ULL << EF10_STAT_port_tx_lt64) | \
1542 (1ULL << EF10_STAT_port_tx_64) | \
1543 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1544 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1545 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1546 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1547 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1548 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001549
1550/* These statistics are only provided by the 40G MAC. For a 10G/40G
1551 * switchable port we do expose these because the errors will otherwise
1552 * be silent.
1553 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001554#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1555 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001556
Edward Cree568d7a02013-09-25 17:32:09 +01001557/* These statistics are only provided if the firmware supports the
1558 * capability PM_AND_RXDP_COUNTERS.
1559 */
1560#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001561 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1562 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1563 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1564 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1565 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1566 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1567 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1568 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1569 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1570 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1571 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1572 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001573
Edward Cree4bae9132013-09-27 18:52:49 +01001574static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001575{
Edward Cree4bae9132013-09-27 18:52:49 +01001576 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001577 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001578 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001579
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001580 if (!(efx->mcdi->fn_flags &
1581 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1582 return 0;
1583
Edward Cree69b365c2016-08-26 15:12:41 +01001584 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001585 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001586 /* 8000 series have everything even at 40G */
1587 if (nic_data->datapath_caps2 &
1588 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1589 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1590 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001591 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001592 }
Edward Cree568d7a02013-09-25 17:32:09 +01001593
1594 if (nic_data->datapath_caps &
1595 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1596 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1597
Edward Cree4bae9132013-09-27 18:52:49 +01001598 return raw_mask;
1599}
1600
1601static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1602{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001603 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001604 u64 raw_mask[2];
1605
1606 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1607
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001608 /* Only show vadaptor stats when EVB capability is present */
1609 if (nic_data->datapath_caps &
1610 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1611 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1612 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1613 } else {
1614 raw_mask[1] = 0;
1615 }
Edward Cree4bae9132013-09-27 18:52:49 +01001616
1617#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001618 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001619 mask[0] = raw_mask[0];
1620 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001621#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001622 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001623 mask[0] = raw_mask[0] & 0xffffffff;
1624 mask[1] = raw_mask[0] >> 32;
1625 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001626#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001627}
1628
1629static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1630{
Edward Cree4bae9132013-09-27 18:52:49 +01001631 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1632
1633 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001634 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001635 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001636}
1637
Daniel Pieczkod7788192015-06-02 11:39:20 +01001638static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1639 struct rtnl_link_stats64 *core_stats)
1640{
1641 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1642 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1643 u64 *stats = nic_data->stats;
1644 size_t stats_count = 0, index;
1645
1646 efx_ef10_get_stat_mask(efx, mask);
1647
1648 if (full_stats) {
1649 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1650 if (efx_ef10_stat_desc[index].name) {
1651 *full_stats++ = stats[index];
1652 ++stats_count;
1653 }
1654 }
1655 }
1656
Bert Kenwardfbe43072015-08-26 16:39:03 +01001657 if (!core_stats)
1658 return stats_count;
1659
1660 if (nic_data->datapath_caps &
1661 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1662 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001663 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1664 stats[EF10_STAT_rx_multicast] +
1665 stats[EF10_STAT_rx_broadcast];
1666 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1667 stats[EF10_STAT_tx_multicast] +
1668 stats[EF10_STAT_tx_broadcast];
1669 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1670 stats[EF10_STAT_rx_multicast_bytes] +
1671 stats[EF10_STAT_rx_broadcast_bytes];
1672 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1673 stats[EF10_STAT_tx_multicast_bytes] +
1674 stats[EF10_STAT_tx_broadcast_bytes];
1675 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001676 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001677 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1678 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1679 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1680 core_stats->rx_errors = core_stats->rx_crc_errors;
1681 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001682 } else {
1683 /* Use port stats. */
1684 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1685 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1686 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1687 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1688 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1689 stats[GENERIC_STAT_rx_nodesc_trunc] +
1690 stats[GENERIC_STAT_rx_noskb_drops];
1691 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1692 core_stats->rx_length_errors =
1693 stats[EF10_STAT_port_rx_gtjumbo] +
1694 stats[EF10_STAT_port_rx_length_error];
1695 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1696 core_stats->rx_frame_errors =
1697 stats[EF10_STAT_port_rx_align_error];
1698 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1699 core_stats->rx_errors = (core_stats->rx_length_errors +
1700 core_stats->rx_crc_errors +
1701 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001702 }
1703
1704 return stats_count;
1705}
1706
1707static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001708{
1709 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001710 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001711 __le64 generation_start, generation_end;
1712 u64 *stats = nic_data->stats;
1713 __le64 *dma_stats;
1714
Edward Cree4bae9132013-09-27 18:52:49 +01001715 efx_ef10_get_stat_mask(efx, mask);
1716
Ben Hutchings8127d662013-08-29 19:19:29 +01001717 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001718
1719 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1720 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1721 return 0;
1722 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001723 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001724 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001725 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001726 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1727 if (generation_end != generation_start)
1728 return -EAGAIN;
1729
1730 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001731 efx_nic_fix_nodesc_drop_stat(efx,
1732 &stats[EF10_STAT_port_rx_nodesc_drops]);
1733 stats[EF10_STAT_port_rx_good_bytes] =
1734 stats[EF10_STAT_port_rx_bytes] -
1735 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1736 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1737 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001738 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001739 return 0;
1740}
1741
1742
Daniel Pieczkod7788192015-06-02 11:39:20 +01001743static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1744 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001745{
Ben Hutchings8127d662013-08-29 19:19:29 +01001746 int retry;
1747
1748 /* If we're unlucky enough to read statistics during the DMA, wait
1749 * up to 10ms for it to finish (typically takes <500us)
1750 */
1751 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001752 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001753 break;
1754 udelay(100);
1755 }
1756
Daniel Pieczkod7788192015-06-02 11:39:20 +01001757 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1758}
1759
1760static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1761{
1762 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1763 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1764 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1765 __le64 generation_start, generation_end;
1766 u64 *stats = nic_data->stats;
1767 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1768 struct efx_buffer stats_buf;
1769 __le64 *dma_stats;
1770 int rc;
1771
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001772 spin_unlock_bh(&efx->stats_lock);
1773
1774 if (in_interrupt()) {
1775 /* If in atomic context, cannot update stats. Just update the
1776 * software stats and return so the caller can continue.
1777 */
1778 spin_lock_bh(&efx->stats_lock);
1779 efx_update_sw_stats(efx, stats);
1780 return 0;
1781 }
1782
Daniel Pieczkod7788192015-06-02 11:39:20 +01001783 efx_ef10_get_stat_mask(efx, mask);
1784
1785 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001786 if (rc) {
1787 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001788 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001789 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001790
1791 dma_stats = stats_buf.addr;
1792 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1793
1794 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1795 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001796 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001797 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1798 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1799
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001800 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1801 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001802 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001803 if (rc) {
1804 /* Expect ENOENT if DMA queues have not been set up */
1805 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1806 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1807 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001808 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001809 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001810
1811 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001812 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1813 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001814 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001815 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001816 rmb();
1817 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1818 stats, stats_buf.addr, false);
1819 rmb();
1820 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1821 if (generation_end != generation_start) {
1822 rc = -EAGAIN;
1823 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001824 }
1825
Daniel Pieczkod7788192015-06-02 11:39:20 +01001826 efx_update_sw_stats(efx, stats);
1827out:
1828 efx_nic_free_buffer(efx, &stats_buf);
1829 return rc;
1830}
Ben Hutchings8127d662013-08-29 19:19:29 +01001831
Daniel Pieczkod7788192015-06-02 11:39:20 +01001832static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1833 struct rtnl_link_stats64 *core_stats)
1834{
1835 if (efx_ef10_try_update_nic_stats_vf(efx))
1836 return 0;
1837
1838 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001839}
1840
1841static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1842{
1843 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001844 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001845 efx_dword_t timer_cmd;
1846
Bert Kenward539de7c2016-08-11 13:02:09 +01001847 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001848 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001849 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001850 } else {
1851 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001852 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001853 }
1854
Bert Kenward539de7c2016-08-11 13:02:09 +01001855 if (EFX_EF10_WORKAROUND_61265(efx)) {
1856 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1857 unsigned int ns = usecs * 1000;
1858
1859 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1860 channel->channel);
1861 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1862 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1863 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1864
1865 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1866 inbuf, sizeof(inbuf), 0, NULL, 0);
1867 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1868 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1869
Ben Hutchings8127d662013-08-29 19:19:29 +01001870 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1871 EFE_DD_EVQ_IND_TIMER_FLAGS,
1872 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001873 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001874 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1875 channel->channel);
1876 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001877 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1878
Ben Hutchings8127d662013-08-29 19:19:29 +01001879 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001880 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001881 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1882 channel->channel);
1883 }
1884}
1885
Shradha Shah02246a72015-05-06 00:58:14 +01001886static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1887 struct ethtool_wolinfo *wol) {}
1888
1889static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1890{
1891 return -EOPNOTSUPP;
1892}
1893
Ben Hutchings8127d662013-08-29 19:19:29 +01001894static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1895{
1896 wol->supported = 0;
1897 wol->wolopts = 0;
1898 memset(&wol->sopass, 0, sizeof(wol->sopass));
1899}
1900
1901static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1902{
1903 if (type != 0)
1904 return -EINVAL;
1905 return 0;
1906}
1907
1908static void efx_ef10_mcdi_request(struct efx_nic *efx,
1909 const efx_dword_t *hdr, size_t hdr_len,
1910 const efx_dword_t *sdu, size_t sdu_len)
1911{
1912 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1913 u8 *pdu = nic_data->mcdi_buf.addr;
1914
1915 memcpy(pdu, hdr, hdr_len);
1916 memcpy(pdu + hdr_len, sdu, sdu_len);
1917 wmb();
1918
1919 /* The hardware provides 'low' and 'high' (doorbell) registers
1920 * for passing the 64-bit address of an MCDI request to
1921 * firmware. However the dwords are swapped by firmware. The
1922 * least significant bits of the doorbell are then 0 for all
1923 * MCDI requests due to alignment.
1924 */
1925 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1926 ER_DZ_MC_DB_LWRD);
1927 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1928 ER_DZ_MC_DB_HWRD);
1929}
1930
1931static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1932{
1933 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1934 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1935
1936 rmb();
1937 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1938}
1939
1940static void
1941efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1942 size_t offset, size_t outlen)
1943{
1944 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1945 const u8 *pdu = nic_data->mcdi_buf.addr;
1946
1947 memcpy(outbuf, pdu + offset, outlen);
1948}
1949
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001950static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1951{
1952 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1953
1954 /* All our allocations have been reset */
1955 efx_ef10_reset_mc_allocations(efx);
1956
1957 /* The datapath firmware might have been changed */
1958 nic_data->must_check_datapath_caps = true;
1959
1960 /* MAC statistics have been cleared on the NIC; clear the local
1961 * statistic that we update with efx_update_diff_stat().
1962 */
1963 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1964}
1965
Ben Hutchings8127d662013-08-29 19:19:29 +01001966static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1967{
1968 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1969 int rc;
1970
1971 rc = efx_ef10_get_warm_boot_count(efx);
1972 if (rc < 0) {
1973 /* The firmware is presumably in the process of
1974 * rebooting. However, we are supposed to report each
1975 * reboot just once, so we must only do that once we
1976 * can read and store the updated warm boot count.
1977 */
1978 return 0;
1979 }
1980
1981 if (rc == nic_data->warm_boot_count)
1982 return 0;
1983
1984 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001985 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01001986
Ben Hutchings8127d662013-08-29 19:19:29 +01001987 return -EIO;
1988}
1989
1990/* Handle an MSI interrupt
1991 *
1992 * Handle an MSI hardware interrupt. This routine schedules event
1993 * queue processing. No interrupt acknowledgement cycle is necessary.
1994 * Also, we never need to check that the interrupt is for us, since
1995 * MSI interrupts cannot be shared.
1996 */
1997static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1998{
1999 struct efx_msi_context *context = dev_id;
2000 struct efx_nic *efx = context->efx;
2001
2002 netif_vdbg(efx, intr, efx->net_dev,
2003 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2004
2005 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2006 /* Note test interrupts */
2007 if (context->index == efx->irq_level)
2008 efx->last_irq_cpu = raw_smp_processor_id();
2009
2010 /* Schedule processing of the channel */
2011 efx_schedule_channel_irq(efx->channel[context->index]);
2012 }
2013
2014 return IRQ_HANDLED;
2015}
2016
2017static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2018{
2019 struct efx_nic *efx = dev_id;
2020 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2021 struct efx_channel *channel;
2022 efx_dword_t reg;
2023 u32 queues;
2024
2025 /* Read the ISR which also ACKs the interrupts */
2026 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2027 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2028
2029 if (queues == 0)
2030 return IRQ_NONE;
2031
2032 if (likely(soft_enabled)) {
2033 /* Note test interrupts */
2034 if (queues & (1U << efx->irq_level))
2035 efx->last_irq_cpu = raw_smp_processor_id();
2036
2037 efx_for_each_channel(channel, efx) {
2038 if (queues & 1)
2039 efx_schedule_channel_irq(channel);
2040 queues >>= 1;
2041 }
2042 }
2043
2044 netif_vdbg(efx, intr, efx->net_dev,
2045 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2046 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2047
2048 return IRQ_HANDLED;
2049}
2050
Jon Cooper942e2982016-08-26 15:13:30 +01002051static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002052{
2053 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2054
Jon Cooper942e2982016-08-26 15:13:30 +01002055 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2056 NULL) == 0)
2057 return -ENOTSUPP;
2058
Ben Hutchings8127d662013-08-29 19:19:29 +01002059 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2060
2061 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002062 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002063 inbuf, sizeof(inbuf), NULL, 0, NULL);
2064}
2065
2066static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2067{
2068 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2069 (tx_queue->ptr_mask + 1) *
2070 sizeof(efx_qword_t),
2071 GFP_KERNEL);
2072}
2073
2074/* This writes to the TX_DESC_WPTR and also pushes data */
2075static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2076 const efx_qword_t *txd)
2077{
2078 unsigned int write_ptr;
2079 efx_oword_t reg;
2080
2081 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2082 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2083 reg.qword[0] = *txd;
2084 efx_writeo_page(tx_queue->efx, &reg,
2085 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2086}
2087
Bert Kenwarde9117e52016-11-17 10:51:54 +00002088/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2089 */
2090static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2091 struct sk_buff *skb,
2092 bool *data_mapped)
2093{
2094 struct efx_tx_buffer *buffer;
2095 struct tcphdr *tcp;
2096 struct iphdr *ip;
2097
2098 u16 ipv4_id;
2099 u32 seqnum;
2100 u32 mss;
2101
Edward Creee01b16a2016-12-02 15:51:33 +00002102 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002103
2104 mss = skb_shinfo(skb)->gso_size;
2105
2106 if (unlikely(mss < 4)) {
2107 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2108 return -EINVAL;
2109 }
2110
2111 ip = ip_hdr(skb);
2112 if (ip->version == 4) {
2113 /* Modify IPv4 header if needed. */
2114 ip->tot_len = 0;
2115 ip->check = 0;
2116 ipv4_id = ip->id;
2117 } else {
2118 /* Modify IPv6 header if needed. */
2119 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2120
2121 ipv6->payload_len = 0;
2122 ipv4_id = 0;
2123 }
2124
2125 tcp = tcp_hdr(skb);
2126 seqnum = ntohl(tcp->seq);
2127
2128 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2129
2130 buffer->flags = EFX_TX_BUF_OPTION;
2131 buffer->len = 0;
2132 buffer->unmap_len = 0;
2133 EFX_POPULATE_QWORD_5(buffer->option,
2134 ESF_DZ_TX_DESC_IS_OPT, 1,
2135 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2136 ESF_DZ_TX_TSO_OPTION_TYPE,
2137 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2138 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2139 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2140 );
2141 ++tx_queue->insert_count;
2142
2143 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2144
2145 buffer->flags = EFX_TX_BUF_OPTION;
2146 buffer->len = 0;
2147 buffer->unmap_len = 0;
2148 EFX_POPULATE_QWORD_4(buffer->option,
2149 ESF_DZ_TX_DESC_IS_OPT, 1,
2150 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2151 ESF_DZ_TX_TSO_OPTION_TYPE,
2152 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2153 ESF_DZ_TX_TSO_TCP_MSS, mss
2154 );
2155 ++tx_queue->insert_count;
2156
2157 return 0;
2158}
2159
Edward Cree46d1efd2016-11-17 10:52:36 +00002160static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2161{
2162 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2163 u32 tso_versions = 0;
2164
2165 if (nic_data->datapath_caps &
2166 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2167 tso_versions |= BIT(1);
2168 if (nic_data->datapath_caps2 &
2169 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2170 tso_versions |= BIT(2);
2171 return tso_versions;
2172}
2173
Ben Hutchings8127d662013-08-29 19:19:29 +01002174static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2175{
2176 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2177 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002178 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2179 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2180 struct efx_channel *channel = tx_queue->channel;
2181 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002182 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002183 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002184 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002185 dma_addr_t dma_addr;
2186 efx_qword_t *txd;
2187 int rc;
2188 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002189 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002190
Bert Kenwarde9117e52016-11-17 10:51:54 +00002191 /* TSOv2 is a limited resource that can only be configured on a limited
2192 * number of queues. TSO without checksum offload is not really a thing,
2193 * so we only enable it for those queues.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002194 */
2195 if (csum_offload && (nic_data->datapath_caps2 &
2196 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2197 tso_v2 = true;
2198 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2199 channel->channel);
2200 }
2201
Ben Hutchings8127d662013-08-29 19:19:29 +01002202 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2203 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2204 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2205 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002206 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002207 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002208
2209 dma_addr = tx_queue->txd.buf.dma_addr;
2210
2211 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2212 tx_queue->queue, entries, (u64)dma_addr);
2213
2214 for (i = 0; i < entries; ++i) {
2215 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2216 dma_addr += EFX_BUF_SIZE;
2217 }
2218
2219 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2220
Edward Creee638ee12016-11-17 10:52:07 +00002221 do {
2222 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2223 /* This flag was removed from mcdi_pcol.h for
2224 * the non-_EXT version of INIT_TXQ. However,
2225 * firmware still honours it.
2226 */
2227 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2228 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2229 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2230
2231 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2232 NULL, 0, NULL);
2233 if (rc == -ENOSPC && tso_v2) {
2234 /* Retry without TSOv2 if we're short on contexts. */
2235 tso_v2 = false;
2236 netif_warn(efx, probe, efx->net_dev,
2237 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2238 } else if (rc) {
2239 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2240 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2241 NULL, 0, rc);
2242 goto fail;
2243 }
2244 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002245
2246 /* A previous user of this TX queue might have set us up the
2247 * bomb by writing a descriptor to the TX push collector but
2248 * not the doorbell. (Each collector belongs to a port, not a
2249 * queue or function, so cannot easily be reset.) We must
2250 * attempt to push a no-op descriptor in its place.
2251 */
2252 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2253 tx_queue->insert_count = 1;
2254 txd = efx_tx_desc(tx_queue, 0);
2255 EFX_POPULATE_QWORD_4(*txd,
2256 ESF_DZ_TX_DESC_IS_OPT, true,
2257 ESF_DZ_TX_OPTION_TYPE,
2258 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2259 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2260 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2261 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002262
Bert Kenwarde9117e52016-11-17 10:51:54 +00002263 if (tso_v2) {
2264 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2265 tx_queue->tso_version = 2;
2266 } else if (nic_data->datapath_caps &
2267 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002268 tx_queue->tso_version = 1;
2269 }
2270
Ben Hutchings8127d662013-08-29 19:19:29 +01002271 wmb();
2272 efx_ef10_push_tx_desc(tx_queue, txd);
2273
2274 return;
2275
2276fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002277 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2278 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002279}
2280
2281static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2282{
2283 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002284 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002285 struct efx_nic *efx = tx_queue->efx;
2286 size_t outlen;
2287 int rc;
2288
2289 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2290 tx_queue->queue);
2291
Edward Cree1e0b8122013-05-31 18:36:12 +01002292 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002293 outbuf, sizeof(outbuf), &outlen);
2294
2295 if (rc && rc != -EALREADY)
2296 goto fail;
2297
2298 return;
2299
2300fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002301 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2302 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002303}
2304
2305static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2306{
2307 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2308}
2309
2310/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2311static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2312{
2313 unsigned int write_ptr;
2314 efx_dword_t reg;
2315
2316 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2317 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2318 efx_writed_page(tx_queue->efx, &reg,
2319 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2320}
2321
Bert Kenwarde9117e52016-11-17 10:51:54 +00002322#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2323
2324static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2325 dma_addr_t dma_addr, unsigned int len)
2326{
2327 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2328 /* If we need to break across multiple descriptors we should
2329 * stop at a page boundary. This assumes the length limit is
2330 * greater than the page size.
2331 */
2332 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2333
2334 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2335 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2336 }
2337
2338 return len;
2339}
2340
Ben Hutchings8127d662013-08-29 19:19:29 +01002341static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2342{
2343 unsigned int old_write_count = tx_queue->write_count;
2344 struct efx_tx_buffer *buffer;
2345 unsigned int write_ptr;
2346 efx_qword_t *txd;
2347
Martin Habetsb2663a42015-11-02 12:51:31 +00002348 tx_queue->xmit_more_available = false;
2349 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2350 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002351
2352 do {
2353 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2354 buffer = &tx_queue->buffer[write_ptr];
2355 txd = efx_tx_desc(tx_queue, write_ptr);
2356 ++tx_queue->write_count;
2357
2358 /* Create TX descriptor ring entry */
2359 if (buffer->flags & EFX_TX_BUF_OPTION) {
2360 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002361 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2362 /* PIO descriptor */
2363 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002364 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002365 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002366 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2367 EFX_POPULATE_QWORD_3(
2368 *txd,
2369 ESF_DZ_TX_KER_CONT,
2370 buffer->flags & EFX_TX_BUF_CONT,
2371 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2372 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2373 }
2374 } while (tx_queue->write_count != tx_queue->insert_count);
2375
2376 wmb(); /* Ensure descriptors are written before they are fetched */
2377
2378 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2379 txd = efx_tx_desc(tx_queue,
2380 old_write_count & tx_queue->ptr_mask);
2381 efx_ef10_push_tx_desc(tx_queue, txd);
2382 ++tx_queue->pushes;
2383 } else {
2384 efx_ef10_notify_tx_desc(tx_queue);
2385 }
2386}
2387
Edward Creea33a4c72016-11-03 22:12:27 +00002388#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2389 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2390#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2391 1 << RSS_MODE_HASH_DST_PORT_LBN)
2392#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2393 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2394 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2395 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2396 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2397 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2398 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2399 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2400 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2401 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2402
2403static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2404{
2405 /* Firmware had a bug (sfc bug 61952) where it would not actually
2406 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2407 * This meant that it would always contain whatever was previously
2408 * in the MCDI buffer. Fortunately, all firmware versions with
2409 * this bug have the same default flags value for a newly-allocated
2410 * RSS context, and the only time we want to get the flags is just
2411 * after allocating. Moreover, the response has a 32-bit hole
2412 * where the context ID would be in the request, so we can use an
2413 * overlength buffer in the request and pre-fill the flags field
2414 * with what we believe the default to be. Thus if the firmware
2415 * has the bug, it will leave our pre-filled value in the flags
2416 * field of the response, and we will get the right answer.
2417 *
2418 * However, this does mean that this function should NOT be used if
2419 * the RSS context flags might not be their defaults - it is ONLY
2420 * reliably correct for a newly-allocated RSS context.
2421 */
2422 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2423 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2424 size_t outlen;
2425 int rc;
2426
2427 /* Check we have a hole for the context ID */
2428 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2429 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2430 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2431 RSS_CONTEXT_FLAGS_DEFAULT);
2432 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2433 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2434 if (rc == 0) {
2435 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2436 rc = -EIO;
2437 else
2438 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2439 }
2440 return rc;
2441}
2442
2443/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2444 * If we fail, we just leave the RSS context at its default hash settings,
2445 * which is safe but may slightly reduce performance.
2446 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2447 * just need to set the UDP ports flags (for both IP versions).
2448 */
2449static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2450{
2451 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2452 u32 flags;
2453
2454 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2455
2456 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2457 return;
2458 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2459 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2460 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2461 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002462 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2463 NULL, 0, NULL))
2464 /* Succeeded, so UDP 4-tuple is now enabled */
2465 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002466}
2467
Jon Cooper267c0152015-05-06 00:59:38 +01002468static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2469 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002470{
2471 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2472 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002473 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002474 size_t outlen;
2475 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002476 u32 alloc_type = exclusive ?
2477 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2478 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2479 unsigned rss_spread = exclusive ?
2480 efx->rss_spread :
2481 min(rounddown_pow_of_two(efx->rss_spread),
2482 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2483
2484 if (!exclusive && rss_spread == 1) {
2485 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2486 if (context_size)
2487 *context_size = 1;
2488 return 0;
2489 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002490
Jon Cooperdcb41232016-04-25 16:51:00 +01002491 if (nic_data->datapath_caps &
2492 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2493 return -EOPNOTSUPP;
2494
Ben Hutchings8127d662013-08-29 19:19:29 +01002495 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002496 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002497 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2498 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002499
2500 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2501 outbuf, sizeof(outbuf), &outlen);
2502 if (rc != 0)
2503 return rc;
2504
2505 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2506 return -EIO;
2507
2508 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2509
Jon Cooper267c0152015-05-06 00:59:38 +01002510 if (context_size)
2511 *context_size = rss_spread;
2512
Edward Creea33a4c72016-11-03 22:12:27 +00002513 if (nic_data->datapath_caps &
2514 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2515 efx_ef10_set_rss_flags(efx, *context);
2516
Ben Hutchings8127d662013-08-29 19:19:29 +01002517 return 0;
2518}
2519
2520static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2521{
2522 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2523 int rc;
2524
2525 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2526 context);
2527
2528 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2529 NULL, 0, NULL);
2530 WARN_ON(rc != 0);
2531}
2532
Jon Cooper267c0152015-05-06 00:59:38 +01002533static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2534 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002535{
2536 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2537 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2538 int i, rc;
2539
2540 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2541 context);
2542 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2543 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2544
2545 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2546 MCDI_PTR(tablebuf,
2547 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002548 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002549
2550 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2551 sizeof(tablebuf), NULL, 0, NULL);
2552 if (rc != 0)
2553 return rc;
2554
2555 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2556 context);
2557 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2558 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2559 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2560 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2561 efx->rx_hash_key[i];
2562
2563 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2564 sizeof(keybuf), NULL, 0, NULL);
2565}
2566
2567static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2568{
2569 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2570
2571 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2572 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2573 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2574}
2575
Jon Cooper267c0152015-05-06 00:59:38 +01002576static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2577 unsigned *context_size)
2578{
2579 u32 new_rx_rss_context;
2580 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2581 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2582 false, context_size);
2583
2584 if (rc != 0)
2585 return rc;
2586
2587 nic_data->rx_rss_context = new_rx_rss_context;
2588 nic_data->rx_rss_context_exclusive = false;
2589 efx_set_default_rx_indir_table(efx);
2590 return 0;
2591}
2592
2593static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2594 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002595{
2596 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2597 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002598 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002599
Jon Cooper267c0152015-05-06 00:59:38 +01002600 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2601 !nic_data->rx_rss_context_exclusive) {
2602 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2603 true, NULL);
2604 if (rc == -EOPNOTSUPP)
2605 return rc;
2606 else if (rc != 0)
2607 goto fail1;
2608 } else {
2609 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002610 }
2611
Jon Cooper267c0152015-05-06 00:59:38 +01002612 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2613 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002614 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002615 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002616
Jon Cooper267c0152015-05-06 00:59:38 +01002617 if (nic_data->rx_rss_context != new_rx_rss_context)
2618 efx_ef10_rx_free_indir_table(efx);
2619 nic_data->rx_rss_context = new_rx_rss_context;
2620 nic_data->rx_rss_context_exclusive = true;
2621 if (rx_indir_table != efx->rx_indir_table)
2622 memcpy(efx->rx_indir_table, rx_indir_table,
2623 sizeof(efx->rx_indir_table));
2624 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002625
Jon Cooper267c0152015-05-06 00:59:38 +01002626fail2:
2627 if (new_rx_rss_context != nic_data->rx_rss_context)
2628 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2629fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002630 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002631 return rc;
2632}
2633
2634static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2635 const u32 *rx_indir_table)
2636{
2637 int rc;
2638
2639 if (efx->rss_spread == 1)
2640 return 0;
2641
2642 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2643
2644 if (rc == -ENOBUFS && !user) {
2645 unsigned context_size;
2646 bool mismatch = false;
2647 size_t i;
2648
2649 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2650 i++)
2651 mismatch = rx_indir_table[i] !=
2652 ethtool_rxfh_indir_default(i, efx->rss_spread);
2653
2654 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2655 if (rc == 0) {
2656 if (context_size != efx->rss_spread)
2657 netif_warn(efx, probe, efx->net_dev,
2658 "Could not allocate an exclusive RSS"
2659 " context; allocated a shared one of"
2660 " different size."
2661 " Wanted %u, got %u.\n",
2662 efx->rss_spread, context_size);
2663 else if (mismatch)
2664 netif_warn(efx, probe, efx->net_dev,
2665 "Could not allocate an exclusive RSS"
2666 " context; allocated a shared one but"
2667 " could not apply custom"
2668 " indirection.\n");
2669 else
2670 netif_info(efx, probe, efx->net_dev,
2671 "Could not allocate an exclusive RSS"
2672 " context; allocated a shared one.\n");
2673 }
2674 }
2675 return rc;
2676}
2677
2678static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2679 const u32 *rx_indir_table
2680 __attribute__ ((unused)))
2681{
2682 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2683
2684 if (user)
2685 return -EOPNOTSUPP;
2686 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2687 return 0;
2688 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002689}
2690
2691static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2692{
2693 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2694 (rx_queue->ptr_mask + 1) *
2695 sizeof(efx_qword_t),
2696 GFP_KERNEL);
2697}
2698
2699static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2700{
2701 MCDI_DECLARE_BUF(inbuf,
2702 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2703 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002704 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2705 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2706 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002707 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002708 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002709 dma_addr_t dma_addr;
2710 int rc;
2711 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002712 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002713
2714 rx_queue->scatter_n = 0;
2715 rx_queue->scatter_len = 0;
2716
2717 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2718 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2719 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2720 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2721 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002722 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2723 INIT_RXQ_IN_FLAG_PREFIX, 1,
2724 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002725 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002726 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002727
2728 dma_addr = rx_queue->rxd.buf.dma_addr;
2729
2730 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2731 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2732
2733 for (i = 0; i < entries; ++i) {
2734 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2735 dma_addr += EFX_BUF_SIZE;
2736 }
2737
2738 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2739
2740 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002741 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002742 if (rc)
2743 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2744 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002745}
2746
2747static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2748{
2749 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002750 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002751 struct efx_nic *efx = rx_queue->efx;
2752 size_t outlen;
2753 int rc;
2754
2755 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2756 efx_rx_queue_index(rx_queue));
2757
Edward Cree1e0b8122013-05-31 18:36:12 +01002758 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002759 outbuf, sizeof(outbuf), &outlen);
2760
2761 if (rc && rc != -EALREADY)
2762 goto fail;
2763
2764 return;
2765
2766fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002767 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2768 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002769}
2770
2771static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2772{
2773 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2774}
2775
2776/* This creates an entry in the RX descriptor queue */
2777static inline void
2778efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2779{
2780 struct efx_rx_buffer *rx_buf;
2781 efx_qword_t *rxd;
2782
2783 rxd = efx_rx_desc(rx_queue, index);
2784 rx_buf = efx_rx_buffer(rx_queue, index);
2785 EFX_POPULATE_QWORD_2(*rxd,
2786 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2787 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2788}
2789
2790static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2791{
2792 struct efx_nic *efx = rx_queue->efx;
2793 unsigned int write_count;
2794 efx_dword_t reg;
2795
2796 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2797 write_count = rx_queue->added_count & ~7;
2798 if (rx_queue->notified_count == write_count)
2799 return;
2800
2801 do
2802 efx_ef10_build_rx_desc(
2803 rx_queue,
2804 rx_queue->notified_count & rx_queue->ptr_mask);
2805 while (++rx_queue->notified_count != write_count);
2806
2807 wmb();
2808 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2809 write_count & rx_queue->ptr_mask);
2810 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2811 efx_rx_queue_index(rx_queue));
2812}
2813
2814static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2815
2816static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2817{
2818 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2819 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2820 efx_qword_t event;
2821
2822 EFX_POPULATE_QWORD_2(event,
2823 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2824 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2825
2826 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2827
2828 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2829 * already swapped the data to little-endian order.
2830 */
2831 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2832 sizeof(efx_qword_t));
2833
2834 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2835 inbuf, sizeof(inbuf), 0,
2836 efx_ef10_rx_defer_refill_complete, 0);
2837}
2838
2839static void
2840efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2841 int rc, efx_dword_t *outbuf,
2842 size_t outlen_actual)
2843{
2844 /* nothing to do */
2845}
2846
2847static int efx_ef10_ev_probe(struct efx_channel *channel)
2848{
2849 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2850 (channel->eventq_mask + 1) *
2851 sizeof(efx_qword_t),
2852 GFP_KERNEL);
2853}
2854
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002855static void efx_ef10_ev_fini(struct efx_channel *channel)
2856{
2857 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2858 MCDI_DECLARE_BUF_ERR(outbuf);
2859 struct efx_nic *efx = channel->efx;
2860 size_t outlen;
2861 int rc;
2862
2863 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2864
2865 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2866 outbuf, sizeof(outbuf), &outlen);
2867
2868 if (rc && rc != -EALREADY)
2869 goto fail;
2870
2871 return;
2872
2873fail:
2874 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2875 outbuf, outlen, rc);
2876}
2877
Ben Hutchings8127d662013-08-29 19:19:29 +01002878static int efx_ef10_ev_init(struct efx_channel *channel)
2879{
2880 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002881 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2882 EFX_BUF_SIZE));
2883 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002884 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2885 struct efx_nic *efx = channel->efx;
2886 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002887 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002888 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002889 dma_addr_t dma_addr;
2890 int rc;
2891 int i;
2892
2893 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002894
2895 /* Fill event queue with all ones (i.e. empty events) */
2896 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2897
2898 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2899 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2900 /* INIT_EVQ expects index in vector table, not absolute */
2901 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002902 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2903 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2904 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2905 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2906 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2907 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2908 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2909
Bert Kenwarda9955602016-08-11 13:01:54 +01002910 if (nic_data->datapath_caps2 &
2911 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2912 /* Use the new generic approach to specifying event queue
2913 * configuration, requesting lower latency or higher throughput.
2914 * The options that actually get used appear in the output.
2915 */
2916 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2917 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2918 INIT_EVQ_V2_IN_FLAG_TYPE,
2919 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2920 } else {
2921 bool cut_thru = !(nic_data->datapath_caps &
2922 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2923
2924 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2925 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2926 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2927 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2928 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2929 }
2930
Ben Hutchings8127d662013-08-29 19:19:29 +01002931 dma_addr = channel->eventq.buf.dma_addr;
2932 for (i = 0; i < entries; ++i) {
2933 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2934 dma_addr += EFX_BUF_SIZE;
2935 }
2936
2937 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2938
2939 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2940 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01002941
2942 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2943 netif_dbg(efx, drv, efx->net_dev,
2944 "Channel %d using event queue flags %08x\n",
2945 channel->channel,
2946 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2947
Ben Hutchings8127d662013-08-29 19:19:29 +01002948 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002949 if (channel->channel || rc)
2950 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002951
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002952 /* Successfully created event queue on channel 0 */
2953 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002954 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01002955 /* GET_WORKAROUNDS was implemented before this workaround,
2956 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01002957 */
2958 nic_data->workaround_26807 = false;
2959 rc = 0;
2960 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002961 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002962 } else {
2963 nic_data->workaround_26807 =
2964 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002965
Edward Cree832dc9e2015-07-21 15:09:31 +01002966 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2967 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002968 unsigned int flags;
2969
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002970 rc = efx_mcdi_set_workaround(efx,
2971 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002972 true, &flags);
2973
2974 if (!rc) {
2975 if (flags &
2976 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2977 netif_info(efx, drv, efx->net_dev,
2978 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002979
2980 /* With MCFW v4.6.x and earlier, the
2981 * boot count will have incremented,
2982 * so re-read the warm_boot_count
2983 * value now to ensure this function
2984 * doesn't think it has changed next
2985 * time it checks.
2986 */
2987 rc = efx_ef10_get_warm_boot_count(efx);
2988 if (rc >= 0) {
2989 nic_data->warm_boot_count = rc;
2990 rc = 0;
2991 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002992 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002993 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002994 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002995 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002996 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002997 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002998 }
2999
3000 if (!rc)
3001 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003002
3003fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003004 efx_ef10_ev_fini(channel);
3005 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003006}
3007
3008static void efx_ef10_ev_remove(struct efx_channel *channel)
3009{
3010 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3011}
3012
3013static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3014 unsigned int rx_queue_label)
3015{
3016 struct efx_nic *efx = rx_queue->efx;
3017
3018 netif_info(efx, hw, efx->net_dev,
3019 "rx event arrived on queue %d labeled as queue %u\n",
3020 efx_rx_queue_index(rx_queue), rx_queue_label);
3021
3022 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3023}
3024
3025static void
3026efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3027 unsigned int actual, unsigned int expected)
3028{
3029 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3030 struct efx_nic *efx = rx_queue->efx;
3031
3032 netif_info(efx, hw, efx->net_dev,
3033 "dropped %d events (index=%d expected=%d)\n",
3034 dropped, actual, expected);
3035
3036 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3037}
3038
3039/* partially received RX was aborted. clean up. */
3040static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3041{
3042 unsigned int rx_desc_ptr;
3043
Ben Hutchings8127d662013-08-29 19:19:29 +01003044 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3045 "scattered RX aborted (dropping %u buffers)\n",
3046 rx_queue->scatter_n);
3047
3048 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3049
3050 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3051 0, EFX_RX_PKT_DISCARD);
3052
3053 rx_queue->removed_count += rx_queue->scatter_n;
3054 rx_queue->scatter_n = 0;
3055 rx_queue->scatter_len = 0;
3056 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3057}
3058
3059static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3060 const efx_qword_t *event)
3061{
3062 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
3063 unsigned int n_descs, n_packets, i;
3064 struct efx_nic *efx = channel->efx;
3065 struct efx_rx_queue *rx_queue;
3066 bool rx_cont;
3067 u16 flags = 0;
3068
3069 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3070 return 0;
3071
3072 /* Basic packet information */
3073 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3074 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3075 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3076 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3077 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3078
Ben Hutchings48ce5632013-11-01 16:42:44 +00003079 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3080 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3081 EFX_QWORD_FMT "\n",
3082 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003083
3084 rx_queue = efx_channel_get_rx_queue(channel);
3085
3086 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3087 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3088
3089 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3090 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3091
3092 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003093 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3094
Ben Hutchings8127d662013-08-29 19:19:29 +01003095 /* detect rx abort */
3096 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003097 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3098 netdev_WARN(efx->net_dev,
3099 "invalid RX abort: scatter_n=%u event="
3100 EFX_QWORD_FMT "\n",
3101 rx_queue->scatter_n,
3102 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003103 efx_ef10_handle_rx_abort(rx_queue);
3104 return 0;
3105 }
3106
Ben Hutchings92a04162013-09-24 23:21:57 +01003107 /* Check that RX completion merging is valid, i.e.
3108 * the current firmware supports it and this is a
3109 * non-scattered packet.
3110 */
3111 if (!(nic_data->datapath_caps &
3112 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3113 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003114 efx_ef10_handle_rx_bad_lbits(
3115 rx_queue, next_ptr_lbits,
3116 (rx_queue->removed_count +
3117 rx_queue->scatter_n + 1) &
3118 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3119 return 0;
3120 }
3121
3122 /* Merged completion for multiple non-scattered packets */
3123 rx_queue->scatter_n = 1;
3124 rx_queue->scatter_len = 0;
3125 n_packets = n_descs;
3126 ++channel->n_rx_merge_events;
3127 channel->n_rx_merge_packets += n_packets;
3128 flags |= EFX_RX_PKT_PREFIX_LEN;
3129 } else {
3130 ++rx_queue->scatter_n;
3131 rx_queue->scatter_len += rx_bytes;
3132 if (rx_cont)
3133 return 0;
3134 n_packets = 1;
3135 }
3136
3137 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
3138 flags |= EFX_RX_PKT_DISCARD;
3139
3140 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
3141 channel->n_rx_ip_hdr_chksum_err += n_packets;
3142 } else if (unlikely(EFX_QWORD_FIELD(*event,
3143 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
3144 channel->n_rx_tcp_udp_chksum_err += n_packets;
3145 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3146 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
3147 flags |= EFX_RX_PKT_CSUMMED;
3148 }
3149
3150 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3151 flags |= EFX_RX_PKT_TCP;
3152
3153 channel->irq_mod_score += 2 * n_packets;
3154
3155 /* Handle received packet(s) */
3156 for (i = 0; i < n_packets; i++) {
3157 efx_rx_packet(rx_queue,
3158 rx_queue->removed_count & rx_queue->ptr_mask,
3159 rx_queue->scatter_n, rx_queue->scatter_len,
3160 flags);
3161 rx_queue->removed_count += rx_queue->scatter_n;
3162 }
3163
3164 rx_queue->scatter_n = 0;
3165 rx_queue->scatter_len = 0;
3166
3167 return n_packets;
3168}
3169
3170static int
3171efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3172{
3173 struct efx_nic *efx = channel->efx;
3174 struct efx_tx_queue *tx_queue;
3175 unsigned int tx_ev_desc_ptr;
3176 unsigned int tx_ev_q_label;
3177 int tx_descs = 0;
3178
3179 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3180 return 0;
3181
3182 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3183 return 0;
3184
3185 /* Transmit completion */
3186 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3187 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3188 tx_queue = efx_channel_get_tx_queue(channel,
3189 tx_ev_q_label % EFX_TXQ_TYPES);
3190 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3191 tx_queue->ptr_mask);
3192 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3193
3194 return tx_descs;
3195}
3196
3197static void
3198efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3199{
3200 struct efx_nic *efx = channel->efx;
3201 int subcode;
3202
3203 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3204
3205 switch (subcode) {
3206 case ESE_DZ_DRV_TIMER_EV:
3207 case ESE_DZ_DRV_WAKE_UP_EV:
3208 break;
3209 case ESE_DZ_DRV_START_UP_EV:
3210 /* event queue init complete. ok. */
3211 break;
3212 default:
3213 netif_err(efx, hw, efx->net_dev,
3214 "channel %d unknown driver event type %d"
3215 " (data " EFX_QWORD_FMT ")\n",
3216 channel->channel, subcode,
3217 EFX_QWORD_VAL(*event));
3218
3219 }
3220}
3221
3222static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3223 efx_qword_t *event)
3224{
3225 struct efx_nic *efx = channel->efx;
3226 u32 subcode;
3227
3228 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3229
3230 switch (subcode) {
3231 case EFX_EF10_TEST:
3232 channel->event_test_cpu = raw_smp_processor_id();
3233 break;
3234 case EFX_EF10_REFILL:
3235 /* The queue must be empty, so we won't receive any rx
3236 * events, so efx_process_channel() won't refill the
3237 * queue. Refill it here
3238 */
Jon Coopercce28792013-10-02 11:04:14 +01003239 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003240 break;
3241 default:
3242 netif_err(efx, hw, efx->net_dev,
3243 "channel %d unknown driver event type %u"
3244 " (data " EFX_QWORD_FMT ")\n",
3245 channel->channel, (unsigned) subcode,
3246 EFX_QWORD_VAL(*event));
3247 }
3248}
3249
3250static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3251{
3252 struct efx_nic *efx = channel->efx;
3253 efx_qword_t event, *p_event;
3254 unsigned int read_ptr;
3255 int ev_code;
3256 int tx_descs = 0;
3257 int spent = 0;
3258
Eric W. Biederman75363a42014-03-14 18:11:22 -07003259 if (quota <= 0)
3260 return spent;
3261
Ben Hutchings8127d662013-08-29 19:19:29 +01003262 read_ptr = channel->eventq_read_ptr;
3263
3264 for (;;) {
3265 p_event = efx_event(channel, read_ptr);
3266 event = *p_event;
3267
3268 if (!efx_event_present(&event))
3269 break;
3270
3271 EFX_SET_QWORD(*p_event);
3272
3273 ++read_ptr;
3274
3275 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3276
3277 netif_vdbg(efx, drv, efx->net_dev,
3278 "processing event on %d " EFX_QWORD_FMT "\n",
3279 channel->channel, EFX_QWORD_VAL(event));
3280
3281 switch (ev_code) {
3282 case ESE_DZ_EV_CODE_MCDI_EV:
3283 efx_mcdi_process_event(channel, &event);
3284 break;
3285 case ESE_DZ_EV_CODE_RX_EV:
3286 spent += efx_ef10_handle_rx_event(channel, &event);
3287 if (spent >= quota) {
3288 /* XXX can we split a merged event to
3289 * avoid going over-quota?
3290 */
3291 spent = quota;
3292 goto out;
3293 }
3294 break;
3295 case ESE_DZ_EV_CODE_TX_EV:
3296 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3297 if (tx_descs > efx->txq_entries) {
3298 spent = quota;
3299 goto out;
3300 } else if (++spent == quota) {
3301 goto out;
3302 }
3303 break;
3304 case ESE_DZ_EV_CODE_DRIVER_EV:
3305 efx_ef10_handle_driver_event(channel, &event);
3306 if (++spent == quota)
3307 goto out;
3308 break;
3309 case EFX_EF10_DRVGEN_EV:
3310 efx_ef10_handle_driver_generated_event(channel, &event);
3311 break;
3312 default:
3313 netif_err(efx, hw, efx->net_dev,
3314 "channel %d unknown event type %d"
3315 " (data " EFX_QWORD_FMT ")\n",
3316 channel->channel, ev_code,
3317 EFX_QWORD_VAL(event));
3318 }
3319 }
3320
3321out:
3322 channel->eventq_read_ptr = read_ptr;
3323 return spent;
3324}
3325
3326static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3327{
3328 struct efx_nic *efx = channel->efx;
3329 efx_dword_t rptr;
3330
3331 if (EFX_EF10_WORKAROUND_35388(efx)) {
3332 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3333 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3334 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3335 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3336
3337 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3338 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3339 ERF_DD_EVQ_IND_RPTR,
3340 (channel->eventq_read_ptr &
3341 channel->eventq_mask) >>
3342 ERF_DD_EVQ_IND_RPTR_WIDTH);
3343 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3344 channel->channel);
3345 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3346 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3347 ERF_DD_EVQ_IND_RPTR,
3348 channel->eventq_read_ptr &
3349 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3350 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3351 channel->channel);
3352 } else {
3353 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3354 channel->eventq_read_ptr &
3355 channel->eventq_mask);
3356 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3357 }
3358}
3359
3360static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3361{
3362 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3363 struct efx_nic *efx = channel->efx;
3364 efx_qword_t event;
3365 int rc;
3366
3367 EFX_POPULATE_QWORD_2(event,
3368 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3369 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3370
3371 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3372
3373 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3374 * already swapped the data to little-endian order.
3375 */
3376 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3377 sizeof(efx_qword_t));
3378
3379 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3380 NULL, 0, NULL);
3381 if (rc != 0)
3382 goto fail;
3383
3384 return;
3385
3386fail:
3387 WARN_ON(true);
3388 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3389}
3390
3391void efx_ef10_handle_drain_event(struct efx_nic *efx)
3392{
3393 if (atomic_dec_and_test(&efx->active_queues))
3394 wake_up(&efx->flush_wq);
3395
3396 WARN_ON(atomic_read(&efx->active_queues) < 0);
3397}
3398
3399static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3400{
3401 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3402 struct efx_channel *channel;
3403 struct efx_tx_queue *tx_queue;
3404 struct efx_rx_queue *rx_queue;
3405 int pending;
3406
3407 /* If the MC has just rebooted, the TX/RX queues will have already been
3408 * torn down, but efx->active_queues needs to be set to zero.
3409 */
3410 if (nic_data->must_realloc_vis) {
3411 atomic_set(&efx->active_queues, 0);
3412 return 0;
3413 }
3414
3415 /* Do not attempt to write to the NIC during EEH recovery */
3416 if (efx->state != STATE_RECOVERY) {
3417 efx_for_each_channel(channel, efx) {
3418 efx_for_each_channel_rx_queue(rx_queue, channel)
3419 efx_ef10_rx_fini(rx_queue);
3420 efx_for_each_channel_tx_queue(tx_queue, channel)
3421 efx_ef10_tx_fini(tx_queue);
3422 }
3423
3424 wait_event_timeout(efx->flush_wq,
3425 atomic_read(&efx->active_queues) == 0,
3426 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3427 pending = atomic_read(&efx->active_queues);
3428 if (pending) {
3429 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3430 pending);
3431 return -ETIMEDOUT;
3432 }
3433 }
3434
3435 return 0;
3436}
3437
Edward Creee2835462014-04-16 19:27:48 +01003438static void efx_ef10_prepare_flr(struct efx_nic *efx)
3439{
3440 atomic_set(&efx->active_queues, 0);
3441}
3442
Ben Hutchings8127d662013-08-29 19:19:29 +01003443static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3444 const struct efx_filter_spec *right)
3445{
3446 if ((left->match_flags ^ right->match_flags) |
3447 ((left->flags ^ right->flags) &
3448 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3449 return false;
3450
3451 return memcmp(&left->outer_vid, &right->outer_vid,
3452 sizeof(struct efx_filter_spec) -
3453 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3454}
3455
3456static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3457{
3458 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3459 return jhash2((const u32 *)&spec->outer_vid,
3460 (sizeof(struct efx_filter_spec) -
3461 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3462 0);
3463 /* XXX should we randomise the initval? */
3464}
3465
3466/* Decide whether a filter should be exclusive or else should allow
3467 * delivery to additional recipients. Currently we decide that
3468 * filters for specific local unicast MAC and IP addresses are
3469 * exclusive.
3470 */
3471static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3472{
3473 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3474 !is_multicast_ether_addr(spec->loc_mac))
3475 return true;
3476
3477 if ((spec->match_flags &
3478 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3479 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3480 if (spec->ether_type == htons(ETH_P_IP) &&
3481 !ipv4_is_multicast(spec->loc_host[0]))
3482 return true;
3483 if (spec->ether_type == htons(ETH_P_IPV6) &&
3484 ((const u8 *)spec->loc_host)[0] != 0xff)
3485 return true;
3486 }
3487
3488 return false;
3489}
3490
3491static struct efx_filter_spec *
3492efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3493 unsigned int filter_idx)
3494{
3495 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3496 ~EFX_EF10_FILTER_FLAGS);
3497}
3498
3499static unsigned int
3500efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3501 unsigned int filter_idx)
3502{
3503 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3504}
3505
3506static void
3507efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3508 unsigned int filter_idx,
3509 const struct efx_filter_spec *spec,
3510 unsigned int flags)
3511{
3512 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3513}
3514
3515static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3516 const struct efx_filter_spec *spec,
3517 efx_dword_t *inbuf, u64 handle,
3518 bool replacing)
3519{
3520 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003521 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003522
3523 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3524
Jon Cooperdcb41232016-04-25 16:51:00 +01003525 /* Remove RSS flag if we don't have an RSS context. */
3526 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3527 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3528 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3529 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3530
Ben Hutchings8127d662013-08-29 19:19:29 +01003531 if (replacing) {
3532 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3533 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3534 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3535 } else {
3536 u32 match_fields = 0;
3537
3538 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3539 efx_ef10_filter_is_exclusive(spec) ?
3540 MC_CMD_FILTER_OP_IN_OP_INSERT :
3541 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3542
3543 /* Convert match flags and values. Unlike almost
3544 * everything else in MCDI, these fields are in
3545 * network byte order.
3546 */
3547 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3548 match_fields |=
3549 is_multicast_ether_addr(spec->loc_mac) ?
3550 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3551 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3552#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3553 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3554 match_fields |= \
3555 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3556 mcdi_field ## _LBN; \
3557 BUILD_BUG_ON( \
3558 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3559 sizeof(spec->gen_field)); \
3560 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3561 &spec->gen_field, sizeof(spec->gen_field)); \
3562 }
3563 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3564 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3565 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3566 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3567 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3568 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3569 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3570 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3571 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3572 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3573#undef COPY_FIELD
3574 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3575 match_fields);
3576 }
3577
Daniel Pieczko45b24492015-05-06 00:57:14 +01003578 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003579 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3580 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3581 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3582 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003583 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003584 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3585 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003586 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3587 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3588 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003589 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003590 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003591 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3592 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003593 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003594 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3595 spec->rss_context !=
3596 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3597 spec->rss_context : nic_data->rx_rss_context);
3598}
3599
3600static int efx_ef10_filter_push(struct efx_nic *efx,
3601 const struct efx_filter_spec *spec,
3602 u64 *handle, bool replacing)
3603{
3604 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3605 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3606 int rc;
3607
3608 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3609 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3610 outbuf, sizeof(outbuf), NULL);
3611 if (rc == 0)
3612 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003613 if (rc == -ENOSPC)
3614 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003615 return rc;
3616}
3617
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003618static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003619{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003620 unsigned int match_flags = spec->match_flags;
3621 u32 mcdi_flags = 0;
3622
3623 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3624 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3625 mcdi_flags |=
3626 is_multicast_ether_addr(spec->loc_mac) ?
3627 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3628 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3629 }
3630
3631#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3632 unsigned int old_match_flags = match_flags; \
3633 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3634 if (match_flags != old_match_flags) \
3635 mcdi_flags |= \
3636 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3637 mcdi_field ## _LBN); \
3638 }
3639 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3640 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3641 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3642 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3643 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3644 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3645 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3646 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3647 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3648 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3649#undef MAP_FILTER_TO_MCDI_FLAG
3650
3651 /* Did we map them all? */
3652 WARN_ON_ONCE(match_flags);
3653
3654 return mcdi_flags;
3655}
3656
3657static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3658 const struct efx_filter_spec *spec)
3659{
3660 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003661 unsigned int match_pri;
3662
3663 for (match_pri = 0;
3664 match_pri < table->rx_match_count;
3665 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003666 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003667 return match_pri;
3668
3669 return -EPROTONOSUPPORT;
3670}
3671
3672static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3673 struct efx_filter_spec *spec,
3674 bool replace_equal)
3675{
3676 struct efx_ef10_filter_table *table = efx->filter_state;
3677 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3678 struct efx_filter_spec *saved_spec;
3679 unsigned int match_pri, hash;
3680 unsigned int priv_flags;
3681 bool replacing = false;
3682 int ins_index = -1;
3683 DEFINE_WAIT(wait);
3684 bool is_mc_recip;
3685 s32 rc;
3686
3687 /* For now, only support RX filters */
3688 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3689 EFX_FILTER_FLAG_RX)
3690 return -EINVAL;
3691
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003692 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003693 if (rc < 0)
3694 return rc;
3695 match_pri = rc;
3696
3697 hash = efx_ef10_filter_hash(spec);
3698 is_mc_recip = efx_filter_is_mc_recipient(spec);
3699 if (is_mc_recip)
3700 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3701
3702 /* Find any existing filters with the same match tuple or
3703 * else a free slot to insert at. If any of them are busy,
3704 * we have to wait and retry.
3705 */
3706 for (;;) {
3707 unsigned int depth = 1;
3708 unsigned int i;
3709
3710 spin_lock_bh(&efx->filter_lock);
3711
3712 for (;;) {
3713 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3714 saved_spec = efx_ef10_filter_entry_spec(table, i);
3715
3716 if (!saved_spec) {
3717 if (ins_index < 0)
3718 ins_index = i;
3719 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3720 if (table->entry[i].spec &
3721 EFX_EF10_FILTER_FLAG_BUSY)
3722 break;
3723 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003724 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003725 rc = -EPERM;
3726 goto out_unlock;
3727 }
3728 if (!is_mc_recip) {
3729 /* This is the only one */
3730 if (spec->priority ==
3731 saved_spec->priority &&
3732 !replace_equal) {
3733 rc = -EEXIST;
3734 goto out_unlock;
3735 }
3736 ins_index = i;
3737 goto found;
3738 } else if (spec->priority >
3739 saved_spec->priority ||
3740 (spec->priority ==
3741 saved_spec->priority &&
3742 replace_equal)) {
3743 if (ins_index < 0)
3744 ins_index = i;
3745 else
3746 __set_bit(depth, mc_rem_map);
3747 }
3748 }
3749
3750 /* Once we reach the maximum search depth, use
3751 * the first suitable slot or return -EBUSY if
3752 * there was none
3753 */
3754 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3755 if (ins_index < 0) {
3756 rc = -EBUSY;
3757 goto out_unlock;
3758 }
3759 goto found;
3760 }
3761
3762 ++depth;
3763 }
3764
3765 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3766 spin_unlock_bh(&efx->filter_lock);
3767 schedule();
3768 }
3769
3770found:
3771 /* Create a software table entry if necessary, and mark it
3772 * busy. We might yet fail to insert, but any attempt to
3773 * insert a conflicting filter while we're waiting for the
3774 * firmware must find the busy entry.
3775 */
3776 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3777 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003778 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3779 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003780 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003781 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3782 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003783 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003784 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003785 rc = ins_index;
3786 goto out_unlock;
3787 }
3788 replacing = true;
3789 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3790 } else {
3791 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3792 if (!saved_spec) {
3793 rc = -ENOMEM;
3794 goto out_unlock;
3795 }
3796 *saved_spec = *spec;
3797 priv_flags = 0;
3798 }
3799 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3800 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3801
3802 /* Mark lower-priority multicast recipients busy prior to removal */
3803 if (is_mc_recip) {
3804 unsigned int depth, i;
3805
3806 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3807 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3808 if (test_bit(depth, mc_rem_map))
3809 table->entry[i].spec |=
3810 EFX_EF10_FILTER_FLAG_BUSY;
3811 }
3812 }
3813
3814 spin_unlock_bh(&efx->filter_lock);
3815
3816 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3817 replacing);
3818
3819 /* Finalise the software table entry */
3820 spin_lock_bh(&efx->filter_lock);
3821 if (rc == 0) {
3822 if (replacing) {
3823 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003824 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3825 saved_spec->flags |=
3826 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003827 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003828 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003829 saved_spec->flags |= spec->flags;
3830 saved_spec->rss_context = spec->rss_context;
3831 saved_spec->dmaq_id = spec->dmaq_id;
3832 }
3833 } else if (!replacing) {
3834 kfree(saved_spec);
3835 saved_spec = NULL;
3836 }
3837 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3838
3839 /* Remove and finalise entries for lower-priority multicast
3840 * recipients
3841 */
3842 if (is_mc_recip) {
3843 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3844 unsigned int depth, i;
3845
3846 memset(inbuf, 0, sizeof(inbuf));
3847
3848 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3849 if (!test_bit(depth, mc_rem_map))
3850 continue;
3851
3852 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3853 saved_spec = efx_ef10_filter_entry_spec(table, i);
3854 priv_flags = efx_ef10_filter_entry_flags(table, i);
3855
3856 if (rc == 0) {
3857 spin_unlock_bh(&efx->filter_lock);
3858 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3859 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3860 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3861 table->entry[i].handle);
3862 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3863 inbuf, sizeof(inbuf),
3864 NULL, 0, NULL);
3865 spin_lock_bh(&efx->filter_lock);
3866 }
3867
3868 if (rc == 0) {
3869 kfree(saved_spec);
3870 saved_spec = NULL;
3871 priv_flags = 0;
3872 } else {
3873 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3874 }
3875 efx_ef10_filter_set_entry(table, i, saved_spec,
3876 priv_flags);
3877 }
3878 }
3879
3880 /* If successful, return the inserted filter ID */
3881 if (rc == 0)
3882 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3883
3884 wake_up_all(&table->waitq);
3885out_unlock:
3886 spin_unlock_bh(&efx->filter_lock);
3887 finish_wait(&table->waitq, &wait);
3888 return rc;
3889}
3890
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003891static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003892{
3893 /* no need to do anything here on EF10 */
3894}
3895
3896/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003897 * If !by_index, remove by ID
3898 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003899 * Filter ID may come from userland and must be range-checked.
3900 */
3901static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003902 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003903 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003904{
3905 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3906 struct efx_ef10_filter_table *table = efx->filter_state;
3907 MCDI_DECLARE_BUF(inbuf,
3908 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3909 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3910 struct efx_filter_spec *spec;
3911 DEFINE_WAIT(wait);
3912 int rc;
3913
3914 /* Find the software table entry and mark it busy. Don't
3915 * remove it yet; any attempt to update while we're waiting
3916 * for the firmware must find the busy entry.
3917 */
3918 for (;;) {
3919 spin_lock_bh(&efx->filter_lock);
3920 if (!(table->entry[filter_idx].spec &
3921 EFX_EF10_FILTER_FLAG_BUSY))
3922 break;
3923 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3924 spin_unlock_bh(&efx->filter_lock);
3925 schedule();
3926 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003927
Ben Hutchings8127d662013-08-29 19:19:29 +01003928 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003929 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003930 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003931 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003932 filter_id / HUNT_FILTER_TBL_ROWS)) {
3933 rc = -ENOENT;
3934 goto out_unlock;
3935 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003936
3937 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003938 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003939 /* Just remove flags */
3940 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003941 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003942 rc = 0;
3943 goto out_unlock;
3944 }
3945
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003946 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003947 rc = -ENOENT;
3948 goto out_unlock;
3949 }
3950
Ben Hutchings8127d662013-08-29 19:19:29 +01003951 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3952 spin_unlock_bh(&efx->filter_lock);
3953
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003954 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003955 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003956
3957 struct efx_filter_spec new_spec = *spec;
3958
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003959 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003960 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003961 (efx_rss_enabled(efx) ?
3962 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003963 new_spec.dmaq_id = 0;
3964 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3965 rc = efx_ef10_filter_push(efx, &new_spec,
3966 &table->entry[filter_idx].handle,
3967 true);
3968
3969 spin_lock_bh(&efx->filter_lock);
3970 if (rc == 0)
3971 *spec = new_spec;
3972 } else {
3973 /* Really remove the filter */
3974
3975 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3976 efx_ef10_filter_is_exclusive(spec) ?
3977 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3978 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3979 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3980 table->entry[filter_idx].handle);
3981 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3982 inbuf, sizeof(inbuf), NULL, 0, NULL);
3983
3984 spin_lock_bh(&efx->filter_lock);
3985 if (rc == 0) {
3986 kfree(spec);
3987 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3988 }
3989 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003990
Ben Hutchings8127d662013-08-29 19:19:29 +01003991 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3992 wake_up_all(&table->waitq);
3993out_unlock:
3994 spin_unlock_bh(&efx->filter_lock);
3995 finish_wait(&table->waitq, &wait);
3996 return rc;
3997}
3998
3999static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4000 enum efx_filter_priority priority,
4001 u32 filter_id)
4002{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004003 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4004 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004005}
4006
Edward Cree12fb0da2015-07-21 15:11:00 +01004007static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
4008{
4009 return filter_id % HUNT_FILTER_TBL_ROWS;
4010}
4011
Edward Cree8c915622016-06-15 17:49:05 +01004012static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4013 enum efx_filter_priority priority,
4014 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004015{
Edward Cree8c915622016-06-15 17:49:05 +01004016 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4017 return;
4018 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004019}
4020
Ben Hutchings8127d662013-08-29 19:19:29 +01004021static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4022 enum efx_filter_priority priority,
4023 u32 filter_id, struct efx_filter_spec *spec)
4024{
4025 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4026 struct efx_ef10_filter_table *table = efx->filter_state;
4027 const struct efx_filter_spec *saved_spec;
4028 int rc;
4029
4030 spin_lock_bh(&efx->filter_lock);
4031 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4032 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004033 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004034 filter_id / HUNT_FILTER_TBL_ROWS) {
4035 *spec = *saved_spec;
4036 rc = 0;
4037 } else {
4038 rc = -ENOENT;
4039 }
4040 spin_unlock_bh(&efx->filter_lock);
4041 return rc;
4042}
4043
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004044static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004045 enum efx_filter_priority priority)
4046{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004047 unsigned int priority_mask;
4048 unsigned int i;
4049 int rc;
4050
4051 priority_mask = (((1U << (priority + 1)) - 1) &
4052 ~(1U << EFX_FILTER_PRI_AUTO));
4053
4054 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4055 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4056 i, true);
4057 if (rc && rc != -ENOENT)
4058 return rc;
4059 }
4060
4061 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004062}
4063
4064static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4065 enum efx_filter_priority priority)
4066{
4067 struct efx_ef10_filter_table *table = efx->filter_state;
4068 unsigned int filter_idx;
4069 s32 count = 0;
4070
4071 spin_lock_bh(&efx->filter_lock);
4072 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4073 if (table->entry[filter_idx].spec &&
4074 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4075 priority)
4076 ++count;
4077 }
4078 spin_unlock_bh(&efx->filter_lock);
4079 return count;
4080}
4081
4082static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4083{
4084 struct efx_ef10_filter_table *table = efx->filter_state;
4085
4086 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4087}
4088
4089static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4090 enum efx_filter_priority priority,
4091 u32 *buf, u32 size)
4092{
4093 struct efx_ef10_filter_table *table = efx->filter_state;
4094 struct efx_filter_spec *spec;
4095 unsigned int filter_idx;
4096 s32 count = 0;
4097
4098 spin_lock_bh(&efx->filter_lock);
4099 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4100 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4101 if (spec && spec->priority == priority) {
4102 if (count == size) {
4103 count = -EMSGSIZE;
4104 break;
4105 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004106 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004107 HUNT_FILTER_TBL_ROWS +
4108 filter_idx);
4109 }
4110 }
4111 spin_unlock_bh(&efx->filter_lock);
4112 return count;
4113}
4114
4115#ifdef CONFIG_RFS_ACCEL
4116
4117static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4118
4119static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4120 struct efx_filter_spec *spec)
4121{
4122 struct efx_ef10_filter_table *table = efx->filter_state;
4123 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4124 struct efx_filter_spec *saved_spec;
4125 unsigned int hash, i, depth = 1;
4126 bool replacing = false;
4127 int ins_index = -1;
4128 u64 cookie;
4129 s32 rc;
4130
4131 /* Must be an RX filter without RSS and not for a multicast
4132 * destination address (RFS only works for connected sockets).
4133 * These restrictions allow us to pass only a tiny amount of
4134 * data through to the completion function.
4135 */
4136 EFX_WARN_ON_PARANOID(spec->flags !=
4137 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4138 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4139 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4140
4141 hash = efx_ef10_filter_hash(spec);
4142
4143 spin_lock_bh(&efx->filter_lock);
4144
4145 /* Find any existing filter with the same match tuple or else
4146 * a free slot to insert at. If an existing filter is busy,
4147 * we have to give up.
4148 */
4149 for (;;) {
4150 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4151 saved_spec = efx_ef10_filter_entry_spec(table, i);
4152
4153 if (!saved_spec) {
4154 if (ins_index < 0)
4155 ins_index = i;
4156 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4157 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4158 rc = -EBUSY;
4159 goto fail_unlock;
4160 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004161 if (spec->priority < saved_spec->priority) {
4162 rc = -EPERM;
4163 goto fail_unlock;
4164 }
4165 ins_index = i;
4166 break;
4167 }
4168
4169 /* Once we reach the maximum search depth, use the
4170 * first suitable slot or return -EBUSY if there was
4171 * none
4172 */
4173 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4174 if (ins_index < 0) {
4175 rc = -EBUSY;
4176 goto fail_unlock;
4177 }
4178 break;
4179 }
4180
4181 ++depth;
4182 }
4183
4184 /* Create a software table entry if necessary, and mark it
4185 * busy. We might yet fail to insert, but any attempt to
4186 * insert a conflicting filter while we're waiting for the
4187 * firmware must find the busy entry.
4188 */
4189 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4190 if (saved_spec) {
4191 replacing = true;
4192 } else {
4193 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4194 if (!saved_spec) {
4195 rc = -ENOMEM;
4196 goto fail_unlock;
4197 }
4198 *saved_spec = *spec;
4199 }
4200 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4201 EFX_EF10_FILTER_FLAG_BUSY);
4202
4203 spin_unlock_bh(&efx->filter_lock);
4204
4205 /* Pack up the variables needed on completion */
4206 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4207
4208 efx_ef10_filter_push_prep(efx, spec, inbuf,
4209 table->entry[ins_index].handle, replacing);
4210 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4211 MC_CMD_FILTER_OP_OUT_LEN,
4212 efx_ef10_filter_rfs_insert_complete, cookie);
4213
4214 return ins_index;
4215
4216fail_unlock:
4217 spin_unlock_bh(&efx->filter_lock);
4218 return rc;
4219}
4220
4221static void
4222efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4223 int rc, efx_dword_t *outbuf,
4224 size_t outlen_actual)
4225{
4226 struct efx_ef10_filter_table *table = efx->filter_state;
4227 unsigned int ins_index, dmaq_id;
4228 struct efx_filter_spec *spec;
4229 bool replacing;
4230
4231 /* Unpack the cookie */
4232 replacing = cookie >> 31;
4233 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4234 dmaq_id = cookie & 0xffff;
4235
4236 spin_lock_bh(&efx->filter_lock);
4237 spec = efx_ef10_filter_entry_spec(table, ins_index);
4238 if (rc == 0) {
4239 table->entry[ins_index].handle =
4240 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4241 if (replacing)
4242 spec->dmaq_id = dmaq_id;
4243 } else if (!replacing) {
4244 kfree(spec);
4245 spec = NULL;
4246 }
4247 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4248 spin_unlock_bh(&efx->filter_lock);
4249
4250 wake_up_all(&table->waitq);
4251}
4252
4253static void
4254efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4255 unsigned long filter_idx,
4256 int rc, efx_dword_t *outbuf,
4257 size_t outlen_actual);
4258
4259static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4260 unsigned int filter_idx)
4261{
4262 struct efx_ef10_filter_table *table = efx->filter_state;
4263 struct efx_filter_spec *spec =
4264 efx_ef10_filter_entry_spec(table, filter_idx);
4265 MCDI_DECLARE_BUF(inbuf,
4266 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4267 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4268
4269 if (!spec ||
4270 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4271 spec->priority != EFX_FILTER_PRI_HINT ||
4272 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4273 flow_id, filter_idx))
4274 return false;
4275
4276 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4277 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4278 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4279 table->entry[filter_idx].handle);
4280 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4281 efx_ef10_filter_rfs_expire_complete, filter_idx))
4282 return false;
4283
4284 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4285 return true;
4286}
4287
4288static void
4289efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4290 unsigned long filter_idx,
4291 int rc, efx_dword_t *outbuf,
4292 size_t outlen_actual)
4293{
4294 struct efx_ef10_filter_table *table = efx->filter_state;
4295 struct efx_filter_spec *spec =
4296 efx_ef10_filter_entry_spec(table, filter_idx);
4297
4298 spin_lock_bh(&efx->filter_lock);
4299 if (rc == 0) {
4300 kfree(spec);
4301 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4302 }
4303 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4304 wake_up_all(&table->waitq);
4305 spin_unlock_bh(&efx->filter_lock);
4306}
4307
4308#endif /* CONFIG_RFS_ACCEL */
4309
4310static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4311{
4312 int match_flags = 0;
4313
4314#define MAP_FLAG(gen_flag, mcdi_field) { \
4315 u32 old_mcdi_flags = mcdi_flags; \
4316 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4317 mcdi_field ## _LBN); \
4318 if (mcdi_flags != old_mcdi_flags) \
4319 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4320 }
4321 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4322 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4323 MAP_FLAG(REM_HOST, SRC_IP);
4324 MAP_FLAG(LOC_HOST, DST_IP);
4325 MAP_FLAG(REM_MAC, SRC_MAC);
4326 MAP_FLAG(REM_PORT, SRC_PORT);
4327 MAP_FLAG(LOC_MAC, DST_MAC);
4328 MAP_FLAG(LOC_PORT, DST_PORT);
4329 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4330 MAP_FLAG(INNER_VID, INNER_VLAN);
4331 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4332 MAP_FLAG(IP_PROTO, IP_PROTO);
4333#undef MAP_FLAG
4334
4335 /* Did we map them all? */
4336 if (mcdi_flags)
4337 return -EINVAL;
4338
4339 return match_flags;
4340}
4341
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004342static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4343{
4344 struct efx_ef10_filter_table *table = efx->filter_state;
4345 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4346
4347 /* See comment in efx_ef10_filter_table_remove() */
4348 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4349 return;
4350
4351 if (!table)
4352 return;
4353
4354 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4355 efx_ef10_filter_del_vlan_internal(efx, vlan);
4356}
4357
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004358static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4359 enum efx_filter_match_flags match_flags)
4360{
4361 unsigned int match_pri;
4362 int mf;
4363
4364 for (match_pri = 0;
4365 match_pri < table->rx_match_count;
4366 match_pri++) {
4367 mf = efx_ef10_filter_match_flags_from_mcdi(
4368 table->rx_match_mcdi_flags[match_pri]);
4369 if (mf == match_flags)
4370 return true;
4371 }
4372
4373 return false;
4374}
4375
Ben Hutchings8127d662013-08-29 19:19:29 +01004376static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4377{
4378 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4379 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004380 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004381 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004382 unsigned int pd_match_pri, pd_match_count;
4383 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004384 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004385 size_t outlen;
4386 int rc;
4387
Edward Creedd987082016-06-15 17:43:43 +01004388 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4389 return -EINVAL;
4390
4391 if (efx->filter_state) /* already probed */
4392 return 0;
4393
Ben Hutchings8127d662013-08-29 19:19:29 +01004394 table = kzalloc(sizeof(*table), GFP_KERNEL);
4395 if (!table)
4396 return -ENOMEM;
4397
4398 /* Find out which RX filter types are supported, and their priorities */
4399 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4400 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4401 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4402 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4403 &outlen);
4404 if (rc)
4405 goto fail;
4406 pd_match_count = MCDI_VAR_ARRAY_LEN(
4407 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4408 table->rx_match_count = 0;
4409
4410 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4411 u32 mcdi_flags =
4412 MCDI_ARRAY_DWORD(
4413 outbuf,
4414 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4415 pd_match_pri);
4416 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4417 if (rc < 0) {
4418 netif_dbg(efx, probe, efx->net_dev,
4419 "%s: fw flags %#x pri %u not supported in driver\n",
4420 __func__, mcdi_flags, pd_match_pri);
4421 } else {
4422 netif_dbg(efx, probe, efx->net_dev,
4423 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4424 __func__, mcdi_flags, pd_match_pri,
4425 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004426 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4427 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004428 }
4429 }
4430
Martin Habetse4478ad2016-06-15 17:51:07 +01004431 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4432 !(efx_ef10_filter_match_supported(table,
4433 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4434 efx_ef10_filter_match_supported(table,
4435 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4436 netif_info(efx, probe, net_dev,
4437 "VLAN filters are not supported in this firmware variant\n");
4438 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4439 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4440 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4441 }
4442
Ben Hutchings8127d662013-08-29 19:19:29 +01004443 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4444 if (!table->entry) {
4445 rc = -ENOMEM;
4446 goto fail;
4447 }
4448
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004449 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004450 table->vlan_filter =
4451 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004452 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004453
Ben Hutchings8127d662013-08-29 19:19:29 +01004454 efx->filter_state = table;
4455 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004456
4457 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4458 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4459 if (rc)
4460 goto fail_add_vlan;
4461 }
4462
Ben Hutchings8127d662013-08-29 19:19:29 +01004463 return 0;
4464
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004465fail_add_vlan:
4466 efx_ef10_filter_cleanup_vlans(efx);
4467 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004468fail:
4469 kfree(table);
4470 return rc;
4471}
4472
Edward Cree0d322412015-05-20 11:10:03 +01004473/* Caller must hold efx->filter_sem for read if race against
4474 * efx_ef10_filter_table_remove() is possible
4475 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004476static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4477{
4478 struct efx_ef10_filter_table *table = efx->filter_state;
4479 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4480 struct efx_filter_spec *spec;
4481 unsigned int filter_idx;
4482 bool failed = false;
4483 int rc;
4484
Edward Cree0d322412015-05-20 11:10:03 +01004485 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4486
Ben Hutchings8127d662013-08-29 19:19:29 +01004487 if (!nic_data->must_restore_filters)
4488 return;
4489
Edward Cree0d322412015-05-20 11:10:03 +01004490 if (!table)
4491 return;
4492
Ben Hutchings8127d662013-08-29 19:19:29 +01004493 spin_lock_bh(&efx->filter_lock);
4494
4495 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4496 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4497 if (!spec)
4498 continue;
4499
4500 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4501 spin_unlock_bh(&efx->filter_lock);
4502
4503 rc = efx_ef10_filter_push(efx, spec,
4504 &table->entry[filter_idx].handle,
4505 false);
4506 if (rc)
4507 failed = true;
4508
4509 spin_lock_bh(&efx->filter_lock);
4510 if (rc) {
4511 kfree(spec);
4512 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4513 } else {
4514 table->entry[filter_idx].spec &=
4515 ~EFX_EF10_FILTER_FLAG_BUSY;
4516 }
4517 }
4518
4519 spin_unlock_bh(&efx->filter_lock);
4520
4521 if (failed)
4522 netif_err(efx, hw, efx->net_dev,
4523 "unable to restore all filters\n");
4524 else
4525 nic_data->must_restore_filters = false;
4526}
4527
4528static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4529{
4530 struct efx_ef10_filter_table *table = efx->filter_state;
4531 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4532 struct efx_filter_spec *spec;
4533 unsigned int filter_idx;
4534 int rc;
4535
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004536 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004537 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004538 /* If we were called without locking, then it's not safe to free
4539 * the table as others might be using it. So we just WARN, leak
4540 * the memory, and potentially get an inconsistent filter table
4541 * state.
4542 * This should never actually happen.
4543 */
4544 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4545 return;
4546
Edward Cree0d322412015-05-20 11:10:03 +01004547 if (!table)
4548 return;
4549
Ben Hutchings8127d662013-08-29 19:19:29 +01004550 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4551 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4552 if (!spec)
4553 continue;
4554
4555 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4556 efx_ef10_filter_is_exclusive(spec) ?
4557 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4558 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4559 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4560 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004561 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4562 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004563 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004564 netif_info(efx, drv, efx->net_dev,
4565 "%s: filter %04x remove failed\n",
4566 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004567 kfree(spec);
4568 }
4569
4570 vfree(table->entry);
4571 kfree(table);
4572}
4573
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004574static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4575{
4576 struct efx_ef10_filter_table *table = efx->filter_state;
4577 unsigned int filter_idx;
4578
4579 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4580 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4581 if (!table->entry[filter_idx].spec)
4582 netif_dbg(efx, drv, efx->net_dev,
4583 "marked null spec old %04x:%04x\n", *id,
4584 filter_idx);
4585 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4586 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004587 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004588}
4589
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004590/* Mark old per-VLAN filters that may need to be removed */
4591static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4592 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004593{
4594 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004595 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004596
Edward Cree12fb0da2015-07-21 15:11:00 +01004597 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004598 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004599 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004600 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4601 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4602 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4603 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004604}
4605
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004606/* Mark old filters that may need to be removed.
4607 * Caller must hold efx->filter_sem for read if race against
4608 * efx_ef10_filter_table_remove() is possible
4609 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004610static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4611{
4612 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004613 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004614
4615 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004616 list_for_each_entry(vlan, &table->vlan_list, list)
4617 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004618 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004619}
Ben Hutchings8127d662013-08-29 19:19:29 +01004620
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004621static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004622{
4623 struct efx_ef10_filter_table *table = efx->filter_state;
4624 struct net_device *net_dev = efx->net_dev;
4625 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004626 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004627 unsigned int i;
4628
Edward Cree12fb0da2015-07-21 15:11:00 +01004629 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004630 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004631 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004632 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4633 i = 1;
4634 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004635 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004636 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004637 break;
4638 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004639 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4640 i++;
4641 }
4642}
4643
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004644static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004645{
4646 struct efx_ef10_filter_table *table = efx->filter_state;
4647 struct net_device *net_dev = efx->net_dev;
4648 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004649 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004650
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004651 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004652
Edward Cree12fb0da2015-07-21 15:11:00 +01004653 addr_count = netdev_mc_count(net_dev);
4654 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004655 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004656 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004657 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004658 break;
4659 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004660 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4661 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004662 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004663
4664 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004665}
Ben Hutchings8127d662013-08-29 19:19:29 +01004666
Edward Cree12fb0da2015-07-21 15:11:00 +01004667static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004668 struct efx_ef10_filter_vlan *vlan,
4669 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004670{
4671 struct efx_ef10_filter_table *table = efx->filter_state;
4672 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004673 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004674 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004675 u8 baddr[ETH_ALEN];
4676 unsigned int i, j;
4677 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004678 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004679 int rc;
4680
4681 if (multicast) {
4682 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004683 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004684 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004685 } else {
4686 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004687 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004688 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004689 }
4690
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004691 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4692
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004693 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004694 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004695 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004696 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004697 rc = efx_ef10_filter_insert(efx, &spec, true);
4698 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004699 if (rollback) {
4700 netif_info(efx, drv, efx->net_dev,
4701 "efx_ef10_filter_insert failed rc=%d\n",
4702 rc);
4703 /* Fall back to promiscuous */
4704 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004705 efx_ef10_filter_remove_unsafe(
4706 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004707 ids[j]);
4708 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004709 }
4710 return rc;
4711 } else {
4712 /* mark as not inserted, and carry on */
4713 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004714 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004715 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004716 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004717 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004718
Edward Cree12fb0da2015-07-21 15:11:00 +01004719 if (multicast && rollback) {
4720 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004721 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004722 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004723 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004724 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004725 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004726 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004727 "Broadcast filter insert failed rc=%d\n", rc);
4728 /* Fall back to promiscuous */
4729 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004730 efx_ef10_filter_remove_unsafe(
4731 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004732 ids[j]);
4733 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004734 }
4735 return rc;
4736 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004737 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004738 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004739 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004740 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004741 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004742
4743 return 0;
4744}
4745
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004746static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4747 struct efx_ef10_filter_vlan *vlan,
4748 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004749{
Edward Cree12fb0da2015-07-21 15:11:00 +01004750 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004751 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004752 struct efx_filter_spec spec;
4753 u8 baddr[ETH_ALEN];
4754 int rc;
4755
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004756 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4757
4758 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004759
4760 if (multicast)
4761 efx_filter_set_mc_def(&spec);
4762 else
4763 efx_filter_set_uc_def(&spec);
4764
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004765 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4766 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4767
Edward Cree12fb0da2015-07-21 15:11:00 +01004768 rc = efx_ef10_filter_insert(efx, &spec, true);
4769 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004770 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4771 efx->net_dev,
4772 "%scast mismatch filter insert failed rc=%d\n",
4773 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004774 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004775 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4776 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004777 if (!nic_data->workaround_26807) {
4778 /* Also need an Ethernet broadcast filter */
4779 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004780 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004781 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004782 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004783 rc = efx_ef10_filter_insert(efx, &spec, true);
4784 if (rc < 0) {
4785 netif_warn(efx, drv, efx->net_dev,
4786 "Broadcast filter insert failed rc=%d\n",
4787 rc);
4788 if (rollback) {
4789 /* Roll back the mc_def filter */
4790 efx_ef10_filter_remove_unsafe(
4791 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004792 vlan->mcdef);
4793 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004794 return rc;
4795 }
4796 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004797 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004798 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004799 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004800 }
4801 }
4802 rc = 0;
4803 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004804 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4805 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004806 rc = 0;
4807 }
4808 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004809}
4810
4811/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4812 * flag or removes these filters, we don't need to hold the filter_lock while
4813 * scanning for these filters.
4814 */
4815static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4816{
4817 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004818 int remove_failed = 0;
4819 int remove_noent = 0;
4820 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004821 int i;
4822
Ben Hutchings8127d662013-08-29 19:19:29 +01004823 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4824 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004825 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004826 rc = efx_ef10_filter_remove_internal(efx,
4827 1U << EFX_FILTER_PRI_AUTO, i, true);
4828 if (rc == -ENOENT)
4829 remove_noent++;
4830 else if (rc)
4831 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004832 }
4833 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004834
4835 if (remove_failed)
4836 netif_info(efx, drv, efx->net_dev,
4837 "%s: failed to remove %d filters\n",
4838 __func__, remove_failed);
4839 if (remove_noent)
4840 netif_info(efx, drv, efx->net_dev,
4841 "%s: failed to remove %d non-existent filters\n",
4842 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004843}
4844
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004845static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4846{
4847 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4848 u8 mac_old[ETH_ALEN];
4849 int rc, rc2;
4850
4851 /* Only reconfigure a PF-created vport */
4852 if (is_zero_ether_addr(nic_data->vport_mac))
4853 return 0;
4854
4855 efx_device_detach_sync(efx);
4856 efx_net_stop(efx->net_dev);
4857 down_write(&efx->filter_sem);
4858 efx_ef10_filter_table_remove(efx);
4859 up_write(&efx->filter_sem);
4860
4861 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4862 if (rc)
4863 goto restore_filters;
4864
4865 ether_addr_copy(mac_old, nic_data->vport_mac);
4866 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4867 nic_data->vport_mac);
4868 if (rc)
4869 goto restore_vadaptor;
4870
4871 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4872 efx->net_dev->dev_addr);
4873 if (!rc) {
4874 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4875 } else {
4876 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4877 if (rc2) {
4878 /* Failed to add original MAC, so clear vport_mac */
4879 eth_zero_addr(nic_data->vport_mac);
4880 goto reset_nic;
4881 }
4882 }
4883
4884restore_vadaptor:
4885 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4886 if (rc2)
4887 goto reset_nic;
4888restore_filters:
4889 down_write(&efx->filter_sem);
4890 rc2 = efx_ef10_filter_table_probe(efx);
4891 up_write(&efx->filter_sem);
4892 if (rc2)
4893 goto reset_nic;
4894
4895 rc2 = efx_net_open(efx->net_dev);
4896 if (rc2)
4897 goto reset_nic;
4898
4899 netif_device_attach(efx->net_dev);
4900
4901 return rc;
4902
4903reset_nic:
4904 netif_err(efx, drv, efx->net_dev,
4905 "Failed to restore when changing MAC address - scheduling reset\n");
4906 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4907
4908 return rc ? rc : rc2;
4909}
4910
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004911/* Caller must hold efx->filter_sem for read if race against
4912 * efx_ef10_filter_table_remove() is possible
4913 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004914static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4915 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004916{
4917 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004918 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004919
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004920 /* Do not install unspecified VID if VLAN filtering is enabled.
4921 * Do not install all specified VIDs if VLAN filtering is disabled.
4922 */
4923 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4924 return;
4925
Edward Cree12fb0da2015-07-21 15:11:00 +01004926 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004927 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004928 efx_ef10_filter_insert_def(efx, vlan, false, false);
4929 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004930 } else {
4931 /* If any of the filters failed to insert, fall back to
4932 * promiscuous mode - add in the uc_def filter. But keep
4933 * our individual unicast filters.
4934 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004935 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4936 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004937 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004938
Edward Cree12fb0da2015-07-21 15:11:00 +01004939 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004940 /* If changing promiscuous state with cascaded multicast filters, remove
4941 * old filters first, so that packets are dropped rather than duplicated
4942 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004943 if (nic_data->workaround_26807 &&
4944 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004945 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004946 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004947 if (nic_data->workaround_26807) {
4948 /* If we failed to insert promiscuous filters, rollback
4949 * and fall back to individual multicast filters
4950 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004951 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004952 /* Changing promisc state, so remove old filters */
4953 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004954 efx_ef10_filter_insert_addr_list(efx, vlan,
4955 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004956 }
4957 } else {
4958 /* If we failed to insert promiscuous filters, don't
4959 * rollback. Regardless, also insert the mc_list
4960 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004961 efx_ef10_filter_insert_def(efx, vlan, true, false);
4962 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004963 }
4964 } else {
4965 /* If any filters failed to insert, rollback and fall back to
4966 * promiscuous mode - mc_def filter and maybe broadcast. If
4967 * that fails, roll back again and insert as many of our
4968 * individual multicast filters as we can.
4969 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004970 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004971 /* Changing promisc state, so remove old filters */
4972 if (nic_data->workaround_26807)
4973 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004974 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4975 efx_ef10_filter_insert_addr_list(efx, vlan,
4976 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004977 }
4978 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004979}
4980
4981/* Caller must hold efx->filter_sem for read if race against
4982 * efx_ef10_filter_table_remove() is possible
4983 */
4984static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4985{
4986 struct efx_ef10_filter_table *table = efx->filter_state;
4987 struct net_device *net_dev = efx->net_dev;
4988 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004989 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004990
4991 if (!efx_dev_registered(efx))
4992 return;
4993
4994 if (!table)
4995 return;
4996
4997 efx_ef10_filter_mark_old(efx);
4998
4999 /* Copy/convert the address lists; add the primary station
5000 * address and broadcast address
5001 */
5002 netif_addr_lock_bh(net_dev);
5003 efx_ef10_filter_uc_addr_list(efx);
5004 efx_ef10_filter_mc_addr_list(efx);
5005 netif_addr_unlock_bh(net_dev);
5006
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005007 /* If VLAN filtering changes, all old filters are finally removed.
5008 * Do it in advance to avoid conflicts for unicast untagged and
5009 * VLAN 0 tagged filters.
5010 */
5011 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5012 if (table->vlan_filter != vlan_filter) {
5013 table->vlan_filter = vlan_filter;
5014 efx_ef10_filter_remove_old(efx);
5015 }
5016
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005017 list_for_each_entry(vlan, &table->vlan_list, list)
5018 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005019
5020 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005021 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005022}
5023
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005024static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5025{
5026 struct efx_ef10_filter_table *table = efx->filter_state;
5027 struct efx_ef10_filter_vlan *vlan;
5028
5029 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5030
5031 list_for_each_entry(vlan, &table->vlan_list, list) {
5032 if (vlan->vid == vid)
5033 return vlan;
5034 }
5035
5036 return NULL;
5037}
5038
5039static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5040{
5041 struct efx_ef10_filter_table *table = efx->filter_state;
5042 struct efx_ef10_filter_vlan *vlan;
5043 unsigned int i;
5044
5045 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5046 return -EINVAL;
5047
5048 vlan = efx_ef10_filter_find_vlan(efx, vid);
5049 if (WARN_ON(vlan)) {
5050 netif_err(efx, drv, efx->net_dev,
5051 "VLAN %u already added\n", vid);
5052 return -EALREADY;
5053 }
5054
5055 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5056 if (!vlan)
5057 return -ENOMEM;
5058
5059 vlan->vid = vid;
5060
5061 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5062 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5063 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5064 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5065 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
5066 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
5067 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
5068
5069 list_add_tail(&vlan->list, &table->vlan_list);
5070
5071 if (efx_dev_registered(efx))
5072 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5073
5074 return 0;
5075}
5076
5077static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5078 struct efx_ef10_filter_vlan *vlan)
5079{
5080 unsigned int i;
5081
5082 /* See comment in efx_ef10_filter_table_remove() */
5083 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5084 return;
5085
5086 list_del(&vlan->list);
5087
Edward Cree8c915622016-06-15 17:49:05 +01005088 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005089 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005090 vlan->uc[i]);
5091 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005092 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005093 vlan->mc[i]);
5094 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
5095 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
5096 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005097
5098 kfree(vlan);
5099}
5100
5101static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5102{
5103 struct efx_ef10_filter_vlan *vlan;
5104
5105 /* See comment in efx_ef10_filter_table_remove() */
5106 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5107 return;
5108
5109 vlan = efx_ef10_filter_find_vlan(efx, vid);
5110 if (!vlan) {
5111 netif_err(efx, drv, efx->net_dev,
5112 "VLAN %u not found in filter state\n", vid);
5113 return;
5114 }
5115
5116 efx_ef10_filter_del_vlan_internal(efx, vlan);
5117}
5118
Shradha Shah910c8782015-05-20 11:12:48 +01005119static int efx_ef10_set_mac_address(struct efx_nic *efx)
5120{
5121 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5122 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5123 bool was_enabled = efx->port_enabled;
5124 int rc;
5125
5126 efx_device_detach_sync(efx);
5127 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005128
5129 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005130 down_write(&efx->filter_sem);
5131 efx_ef10_filter_table_remove(efx);
5132
5133 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5134 efx->net_dev->dev_addr);
5135 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5136 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005137 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5138 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005139
5140 efx_ef10_filter_table_probe(efx);
5141 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005142 mutex_unlock(&efx->mac_lock);
5143
Shradha Shah910c8782015-05-20 11:12:48 +01005144 if (was_enabled)
5145 efx_net_open(efx->net_dev);
5146 netif_device_attach(efx->net_dev);
5147
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005148#ifdef CONFIG_SFC_SRIOV
5149 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005150 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5151
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005152 if (rc == -EPERM) {
5153 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005154
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005155 /* Switch to PF and change MAC address on vport */
5156 efx_pf = pci_get_drvdata(pci_dev_pf);
5157
5158 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005159 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005160 efx->net_dev->dev_addr);
5161 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005162 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5163 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5164 unsigned int i;
5165
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005166 /* MAC address successfully changed by VF (with MAC
5167 * spoofing) so update the parent PF if possible.
5168 */
Shradha Shah910c8782015-05-20 11:12:48 +01005169 for (i = 0; i < efx_pf->vf_count; ++i) {
5170 struct ef10_vf *vf = nic_data->vf + i;
5171
5172 if (vf->efx == efx) {
5173 ether_addr_copy(vf->mac,
5174 efx->net_dev->dev_addr);
5175 return 0;
5176 }
5177 }
5178 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005179 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005180#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005181 if (rc == -EPERM) {
5182 netif_err(efx, drv, efx->net_dev,
5183 "Cannot change MAC address; use sfboot to enable"
5184 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005185 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5186 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5187 * fall-back to the method of changing the MAC address on the
5188 * vport. This only applies to PFs because such versions of
5189 * MCFW do not support VFs.
5190 */
5191 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005192 } else {
5193 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5194 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005195 }
5196
Shradha Shah910c8782015-05-20 11:12:48 +01005197 return rc;
5198}
5199
Ben Hutchings8127d662013-08-29 19:19:29 +01005200static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5201{
5202 efx_ef10_filter_sync_rx_mode(efx);
5203
5204 return efx_mcdi_set_mac(efx);
5205}
5206
Shradha Shah862f8942015-05-20 11:08:56 +01005207static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5208{
5209 efx_ef10_filter_sync_rx_mode(efx);
5210
5211 return 0;
5212}
5213
Jon Cooper74cd60a2013-09-16 14:18:51 +01005214static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5215{
5216 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5217
5218 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5219 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5220 NULL, 0, NULL);
5221}
5222
5223/* MC BISTs follow a different poll mechanism to phy BISTs.
5224 * The BIST is done in the poll handler on the MC, and the MCDI command
5225 * will block until the BIST is done.
5226 */
5227static int efx_ef10_poll_bist(struct efx_nic *efx)
5228{
5229 int rc;
5230 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5231 size_t outlen;
5232 u32 result;
5233
5234 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5235 outbuf, sizeof(outbuf), &outlen);
5236 if (rc != 0)
5237 return rc;
5238
5239 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5240 return -EIO;
5241
5242 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5243 switch (result) {
5244 case MC_CMD_POLL_BIST_PASSED:
5245 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5246 return 0;
5247 case MC_CMD_POLL_BIST_TIMEOUT:
5248 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5249 return -EIO;
5250 case MC_CMD_POLL_BIST_FAILED:
5251 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5252 return -EIO;
5253 default:
5254 netif_err(efx, hw, efx->net_dev,
5255 "BIST returned unknown result %u", result);
5256 return -EIO;
5257 }
5258}
5259
5260static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5261{
5262 int rc;
5263
5264 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5265
5266 rc = efx_ef10_start_bist(efx, bist_type);
5267 if (rc != 0)
5268 return rc;
5269
5270 return efx_ef10_poll_bist(efx);
5271}
5272
5273static int
5274efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5275{
5276 int rc, rc2;
5277
5278 efx_reset_down(efx, RESET_TYPE_WORLD);
5279
5280 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5281 NULL, 0, NULL, 0, NULL);
5282 if (rc != 0)
5283 goto out;
5284
5285 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5286 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5287
5288 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5289
5290out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005291 if (rc == -EPERM)
5292 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005293 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5294 return rc ? rc : rc2;
5295}
5296
Ben Hutchings8127d662013-08-29 19:19:29 +01005297#ifdef CONFIG_SFC_MTD
5298
5299struct efx_ef10_nvram_type_info {
5300 u16 type, type_mask;
5301 u8 port;
5302 const char *name;
5303};
5304
5305static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5306 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5307 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5308 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5309 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5310 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5311 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5312 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5313 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5314 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005315 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005316 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5317};
5318
5319static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5320 struct efx_mcdi_mtd_partition *part,
5321 unsigned int type)
5322{
5323 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5324 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5325 const struct efx_ef10_nvram_type_info *info;
5326 size_t size, erase_size, outlen;
5327 bool protected;
5328 int rc;
5329
5330 for (info = efx_ef10_nvram_types; ; info++) {
5331 if (info ==
5332 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5333 return -ENODEV;
5334 if ((type & ~info->type_mask) == info->type)
5335 break;
5336 }
5337 if (info->port != efx_port_num(efx))
5338 return -ENODEV;
5339
5340 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5341 if (rc)
5342 return rc;
5343 if (protected)
5344 return -ENODEV; /* hide it */
5345
5346 part->nvram_type = type;
5347
5348 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5349 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5350 outbuf, sizeof(outbuf), &outlen);
5351 if (rc)
5352 return rc;
5353 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5354 return -EIO;
5355 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5356 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5357 part->fw_subtype = MCDI_DWORD(outbuf,
5358 NVRAM_METADATA_OUT_SUBTYPE);
5359
5360 part->common.dev_type_name = "EF10 NVRAM manager";
5361 part->common.type_name = info->name;
5362
5363 part->common.mtd.type = MTD_NORFLASH;
5364 part->common.mtd.flags = MTD_CAP_NORFLASH;
5365 part->common.mtd.size = size;
5366 part->common.mtd.erasesize = erase_size;
5367
5368 return 0;
5369}
5370
5371static int efx_ef10_mtd_probe(struct efx_nic *efx)
5372{
5373 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5374 struct efx_mcdi_mtd_partition *parts;
5375 size_t outlen, n_parts_total, i, n_parts;
5376 unsigned int type;
5377 int rc;
5378
5379 ASSERT_RTNL();
5380
5381 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5382 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5383 outbuf, sizeof(outbuf), &outlen);
5384 if (rc)
5385 return rc;
5386 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5387 return -EIO;
5388
5389 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5390 if (n_parts_total >
5391 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5392 return -EIO;
5393
5394 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5395 if (!parts)
5396 return -ENOMEM;
5397
5398 n_parts = 0;
5399 for (i = 0; i < n_parts_total; i++) {
5400 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5401 i);
5402 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5403 if (rc == 0)
5404 n_parts++;
5405 else if (rc != -ENODEV)
5406 goto fail;
5407 }
5408
5409 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5410fail:
5411 if (rc)
5412 kfree(parts);
5413 return rc;
5414}
5415
5416#endif /* CONFIG_SFC_MTD */
5417
5418static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5419{
5420 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5421}
5422
Shradha Shah02246a72015-05-06 00:58:14 +01005423static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5424 u32 host_time) {}
5425
Jon Cooperbd9a2652013-11-18 12:54:41 +00005426static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5427 bool temp)
5428{
5429 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5430 int rc;
5431
5432 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5433 channel->sync_events_state == SYNC_EVENTS_VALID ||
5434 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5435 return 0;
5436 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5437
5438 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5439 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5440 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5441 channel->channel);
5442
5443 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5444 inbuf, sizeof(inbuf), NULL, 0, NULL);
5445
5446 if (rc != 0)
5447 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5448 SYNC_EVENTS_DISABLED;
5449
5450 return rc;
5451}
5452
5453static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5454 bool temp)
5455{
5456 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5457 int rc;
5458
5459 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5460 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5461 return 0;
5462 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5463 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5464 return 0;
5465 }
5466 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5467 SYNC_EVENTS_DISABLED;
5468
5469 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5470 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5471 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5472 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5473 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5474 channel->channel);
5475
5476 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5477 inbuf, sizeof(inbuf), NULL, 0, NULL);
5478
5479 return rc;
5480}
5481
5482static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5483 bool temp)
5484{
5485 int (*set)(struct efx_channel *channel, bool temp);
5486 struct efx_channel *channel;
5487
5488 set = en ?
5489 efx_ef10_rx_enable_timestamping :
5490 efx_ef10_rx_disable_timestamping;
5491
5492 efx_for_each_channel(channel, efx) {
5493 int rc = set(channel, temp);
5494 if (en && rc != 0) {
5495 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5496 return rc;
5497 }
5498 }
5499
5500 return 0;
5501}
5502
Shradha Shah02246a72015-05-06 00:58:14 +01005503static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5504 struct hwtstamp_config *init)
5505{
5506 return -EOPNOTSUPP;
5507}
5508
Jon Cooperbd9a2652013-11-18 12:54:41 +00005509static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5510 struct hwtstamp_config *init)
5511{
5512 int rc;
5513
5514 switch (init->rx_filter) {
5515 case HWTSTAMP_FILTER_NONE:
5516 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5517 /* if TX timestamping is still requested then leave PTP on */
5518 return efx_ptp_change_mode(efx,
5519 init->tx_type != HWTSTAMP_TX_OFF, 0);
5520 case HWTSTAMP_FILTER_ALL:
5521 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5522 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5523 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5524 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5525 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5526 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5527 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5528 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5529 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5530 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5531 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5532 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5533 init->rx_filter = HWTSTAMP_FILTER_ALL;
5534 rc = efx_ptp_change_mode(efx, true, 0);
5535 if (!rc)
5536 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5537 if (rc)
5538 efx_ptp_change_mode(efx, false, 0);
5539 return rc;
5540 default:
5541 return -ERANGE;
5542 }
5543}
5544
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005545static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
5546 struct netdev_phys_item_id *ppid)
5547{
5548 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5549
5550 if (!is_valid_ether_addr(nic_data->port_id))
5551 return -EOPNOTSUPP;
5552
5553 ppid->id_len = ETH_ALEN;
5554 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
5555
5556 return 0;
5557}
5558
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005559static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5560{
5561 if (proto != htons(ETH_P_8021Q))
5562 return -EINVAL;
5563
5564 return efx_ef10_add_vlan(efx, vid);
5565}
5566
5567static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5568{
5569 if (proto != htons(ETH_P_8021Q))
5570 return -EINVAL;
5571
5572 return efx_ef10_del_vlan(efx, vid);
5573}
5574
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005575#define EF10_OFFLOAD_FEATURES \
5576 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005577 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005578 NETIF_F_IPV6_CSUM | \
5579 NETIF_F_RXHASH | \
5580 NETIF_F_NTUPLE)
5581
Shradha Shah02246a72015-05-06 00:58:14 +01005582const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005583 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005584 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005585 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005586 .probe = efx_ef10_probe_vf,
5587 .remove = efx_ef10_remove,
5588 .dimension_resources = efx_ef10_dimension_resources,
5589 .init = efx_ef10_init_nic,
5590 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005591 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005592 .map_reset_flags = efx_ef10_map_reset_flags,
5593 .reset = efx_ef10_reset,
5594 .probe_port = efx_mcdi_port_probe,
5595 .remove_port = efx_mcdi_port_remove,
5596 .fini_dmaq = efx_ef10_fini_dmaq,
5597 .prepare_flr = efx_ef10_prepare_flr,
5598 .finish_flr = efx_port_dummy_op_void,
5599 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005600 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005601 .start_stats = efx_port_dummy_op_void,
5602 .pull_stats = efx_port_dummy_op_void,
5603 .stop_stats = efx_port_dummy_op_void,
5604 .set_id_led = efx_mcdi_set_id_led,
5605 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005606 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005607 .check_mac_fault = efx_mcdi_mac_check_fault,
5608 .reconfigure_port = efx_mcdi_port_reconfigure,
5609 .get_wol = efx_ef10_get_wol_vf,
5610 .set_wol = efx_ef10_set_wol_vf,
5611 .resume_wol = efx_port_dummy_op_void,
5612 .mcdi_request = efx_ef10_mcdi_request,
5613 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5614 .mcdi_read_response = efx_ef10_mcdi_read_response,
5615 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005616 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005617 .irq_enable_master = efx_port_dummy_op_void,
5618 .irq_test_generate = efx_ef10_irq_test_generate,
5619 .irq_disable_non_ev = efx_port_dummy_op_void,
5620 .irq_handle_msi = efx_ef10_msi_interrupt,
5621 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5622 .tx_probe = efx_ef10_tx_probe,
5623 .tx_init = efx_ef10_tx_init,
5624 .tx_remove = efx_ef10_tx_remove,
5625 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005626 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005627 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005628 .rx_probe = efx_ef10_rx_probe,
5629 .rx_init = efx_ef10_rx_init,
5630 .rx_remove = efx_ef10_rx_remove,
5631 .rx_write = efx_ef10_rx_write,
5632 .rx_defer_refill = efx_ef10_rx_defer_refill,
5633 .ev_probe = efx_ef10_ev_probe,
5634 .ev_init = efx_ef10_ev_init,
5635 .ev_fini = efx_ef10_ev_fini,
5636 .ev_remove = efx_ef10_ev_remove,
5637 .ev_process = efx_ef10_ev_process,
5638 .ev_read_ack = efx_ef10_ev_read_ack,
5639 .ev_test_generate = efx_ef10_ev_test_generate,
5640 .filter_table_probe = efx_ef10_filter_table_probe,
5641 .filter_table_restore = efx_ef10_filter_table_restore,
5642 .filter_table_remove = efx_ef10_filter_table_remove,
5643 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5644 .filter_insert = efx_ef10_filter_insert,
5645 .filter_remove_safe = efx_ef10_filter_remove_safe,
5646 .filter_get_safe = efx_ef10_filter_get_safe,
5647 .filter_clear_rx = efx_ef10_filter_clear_rx,
5648 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5649 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5650 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5651#ifdef CONFIG_RFS_ACCEL
5652 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5653 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5654#endif
5655#ifdef CONFIG_SFC_MTD
5656 .mtd_probe = efx_port_dummy_op_int,
5657#endif
5658 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5659 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005660 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5661 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005662#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005663 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5664 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5665 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005666#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005667 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005668 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005669
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005670 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005671 .revision = EFX_REV_HUNT_A0,
5672 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5673 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5674 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5675 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5676 .can_rx_scatter = true,
5677 .always_rx_scatter = true,
5678 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5679 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005680 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005681 .mcdi_max_ver = 2,
5682 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5683 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5684 1 << HWTSTAMP_FILTER_ALL,
5685};
5686
5687const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005688 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005689 .mem_bar = EFX_MEM_BAR,
5690 .mem_map_size = efx_ef10_mem_map_size,
5691 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005692 .remove = efx_ef10_remove,
5693 .dimension_resources = efx_ef10_dimension_resources,
5694 .init = efx_ef10_init_nic,
5695 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005696 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005697 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005698 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005699 .probe_port = efx_mcdi_port_probe,
5700 .remove_port = efx_mcdi_port_remove,
5701 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005702 .prepare_flr = efx_ef10_prepare_flr,
5703 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005704 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005705 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005706 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005707 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005708 .stop_stats = efx_mcdi_mac_stop_stats,
5709 .set_id_led = efx_mcdi_set_id_led,
5710 .push_irq_moderation = efx_ef10_push_irq_moderation,
5711 .reconfigure_mac = efx_ef10_mac_reconfigure,
5712 .check_mac_fault = efx_mcdi_mac_check_fault,
5713 .reconfigure_port = efx_mcdi_port_reconfigure,
5714 .get_wol = efx_ef10_get_wol,
5715 .set_wol = efx_ef10_set_wol,
5716 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005717 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005718 .test_nvram = efx_mcdi_nvram_test_all,
5719 .mcdi_request = efx_ef10_mcdi_request,
5720 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5721 .mcdi_read_response = efx_ef10_mcdi_read_response,
5722 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005723 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005724 .irq_enable_master = efx_port_dummy_op_void,
5725 .irq_test_generate = efx_ef10_irq_test_generate,
5726 .irq_disable_non_ev = efx_port_dummy_op_void,
5727 .irq_handle_msi = efx_ef10_msi_interrupt,
5728 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5729 .tx_probe = efx_ef10_tx_probe,
5730 .tx_init = efx_ef10_tx_init,
5731 .tx_remove = efx_ef10_tx_remove,
5732 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005733 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005734 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005735 .rx_probe = efx_ef10_rx_probe,
5736 .rx_init = efx_ef10_rx_init,
5737 .rx_remove = efx_ef10_rx_remove,
5738 .rx_write = efx_ef10_rx_write,
5739 .rx_defer_refill = efx_ef10_rx_defer_refill,
5740 .ev_probe = efx_ef10_ev_probe,
5741 .ev_init = efx_ef10_ev_init,
5742 .ev_fini = efx_ef10_ev_fini,
5743 .ev_remove = efx_ef10_ev_remove,
5744 .ev_process = efx_ef10_ev_process,
5745 .ev_read_ack = efx_ef10_ev_read_ack,
5746 .ev_test_generate = efx_ef10_ev_test_generate,
5747 .filter_table_probe = efx_ef10_filter_table_probe,
5748 .filter_table_restore = efx_ef10_filter_table_restore,
5749 .filter_table_remove = efx_ef10_filter_table_remove,
5750 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5751 .filter_insert = efx_ef10_filter_insert,
5752 .filter_remove_safe = efx_ef10_filter_remove_safe,
5753 .filter_get_safe = efx_ef10_filter_get_safe,
5754 .filter_clear_rx = efx_ef10_filter_clear_rx,
5755 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5756 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5757 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5758#ifdef CONFIG_RFS_ACCEL
5759 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5760 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5761#endif
5762#ifdef CONFIG_SFC_MTD
5763 .mtd_probe = efx_ef10_mtd_probe,
5764 .mtd_rename = efx_mcdi_mtd_rename,
5765 .mtd_read = efx_mcdi_mtd_read,
5766 .mtd_erase = efx_mcdi_mtd_erase,
5767 .mtd_write = efx_mcdi_mtd_write,
5768 .mtd_sync = efx_mcdi_mtd_sync,
5769#endif
5770 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005771 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5772 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005773 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5774 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005775#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005776 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005777 .sriov_init = efx_ef10_sriov_init,
5778 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005779 .sriov_wanted = efx_ef10_sriov_wanted,
5780 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005781 .sriov_flr = efx_ef10_sriov_flr,
5782 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5783 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5784 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5785 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005786 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005787 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5788 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5789 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005790#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005791 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005792 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00005793 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01005794
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005795 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01005796 .revision = EFX_REV_HUNT_A0,
5797 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5798 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5799 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005800 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005801 .can_rx_scatter = true,
5802 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00005803 .option_descriptors = true,
Ben Hutchings8127d662013-08-29 19:19:29 +01005804 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5805 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005806 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005807 .mcdi_max_ver = 2,
5808 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005809 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5810 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005811};