blob: 4b69ed9e63362c624b86fc9717f20358459f54f5 [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;
Shradha Shah8be41322015-06-02 11:37:25 +0100550 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100551 int i, rc;
552
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000553 /* We can have one VI for each 8K region. However, until we
554 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100555 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100556 efx->max_channels = min_t(unsigned int,
557 EFX_MAX_CHANNELS,
558 efx_ef10_mem_map_size(efx) /
559 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
560 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000561 if (WARN_ON(efx->max_channels == 0))
562 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100563
564 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
565 if (!nic_data)
566 return -ENOMEM;
567 efx->nic_data = nic_data;
568
Edward Cree75aba2a2015-05-27 13:13:54 +0100569 /* we assume later that we can copy from this buffer in dwords */
570 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
571
Ben Hutchings8127d662013-08-29 19:19:29 +0100572 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
573 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
574 if (rc)
575 goto fail1;
576
577 /* Get the MC's warm boot count. In case it's rebooting right
578 * now, be prepared to retry.
579 */
580 i = 0;
581 for (;;) {
582 rc = efx_ef10_get_warm_boot_count(efx);
583 if (rc >= 0)
584 break;
585 if (++i == 5)
586 goto fail2;
587 ssleep(1);
588 }
589 nic_data->warm_boot_count = rc;
590
591 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
592
Daniel Pieczko45b24492015-05-06 00:57:14 +0100593 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
594
Ben Hutchings8127d662013-08-29 19:19:29 +0100595 /* In case we're recovering from a crash (kexec), we want to
596 * cancel any outstanding request by the previous user of this
597 * function. We send a special message using the least
598 * significant bits of the 'high' (doorbell) register.
599 */
600 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
601
602 rc = efx_mcdi_init(efx);
603 if (rc)
604 goto fail2;
605
606 /* Reset (most) configuration for this function */
607 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
608 if (rc)
609 goto fail3;
610
611 /* Enable event logging */
612 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
613 if (rc)
614 goto fail3;
615
Shradha Shah0f5c0842015-06-02 11:37:58 +0100616 rc = device_create_file(&efx->pci_dev->dev,
617 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100618 if (rc)
619 goto fail3;
620
Shradha Shah0f5c0842015-06-02 11:37:58 +0100621 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
622 if (rc)
623 goto fail4;
624
625 rc = efx_ef10_get_pf_index(efx);
626 if (rc)
627 goto fail5;
628
Ben Hutchingse5a25382013-09-05 22:50:59 +0100629 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100630 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100631 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100632
633 efx->rx_packet_len_offset =
634 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
635
Ben Hutchings8127d662013-08-29 19:19:29 +0100636 rc = efx_mcdi_port_get_number(efx);
637 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100638 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100639 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100640 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100641
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100642 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100643 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100644 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100645
Bert Kenwardd95e3292016-08-11 13:02:36 +0100646 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100647 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100648 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100649
Ben Hutchings8127d662013-08-29 19:19:29 +0100650 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100651 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100652 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100653
Ben Hutchings9aecda92013-12-05 21:28:42 +0000654 efx_ptp_probe(efx, NULL);
655
Shradha Shah1d051e02015-06-02 11:38:16 +0100656#ifdef CONFIG_SFC_SRIOV
657 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
658 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
659 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
660
661 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
662 } else
663#endif
664 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
665
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100666 INIT_LIST_HEAD(&nic_data->vlan_list);
667 mutex_init(&nic_data->vlan_lock);
668
669 /* Add unspecified VID to support VLAN filtering being disabled */
670 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
671 if (rc)
672 goto fail_add_vid_unspec;
673
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100674 /* If VLAN filtering is enabled, we need VID 0 to get untagged
675 * traffic. It is added automatically if 8021q module is loaded,
676 * but we can't rely on it since module may be not loaded.
677 */
678 rc = efx_ef10_add_vlan(efx, 0);
679 if (rc)
680 goto fail_add_vid_0;
681
Ben Hutchings8127d662013-08-29 19:19:29 +0100682 return 0;
683
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100684fail_add_vid_0:
685 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100686fail_add_vid_unspec:
687 mutex_destroy(&nic_data->vlan_lock);
688 efx_ptp_remove(efx);
689 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100690fail5:
691 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
692fail4:
693 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100694fail3:
695 efx_mcdi_fini(efx);
696fail2:
697 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
698fail1:
699 kfree(nic_data);
700 efx->nic_data = NULL;
701 return rc;
702}
703
704static int efx_ef10_free_vis(struct efx_nic *efx)
705{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100706 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100707 size_t outlen;
708 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
709 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100710
711 /* -EALREADY means nothing to free, so ignore */
712 if (rc == -EALREADY)
713 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100714 if (rc)
715 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
716 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100717 return rc;
718}
719
Ben Hutchings183233b2013-06-28 21:47:12 +0100720#ifdef EFX_USE_PIO
721
722static void efx_ef10_free_piobufs(struct efx_nic *efx)
723{
724 struct efx_ef10_nic_data *nic_data = efx->nic_data;
725 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
726 unsigned int i;
727 int rc;
728
729 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
730
731 for (i = 0; i < nic_data->n_piobufs; i++) {
732 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
733 nic_data->piobuf_handle[i]);
734 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
735 NULL, 0, NULL);
736 WARN_ON(rc);
737 }
738
739 nic_data->n_piobufs = 0;
740}
741
742static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
743{
744 struct efx_ef10_nic_data *nic_data = efx->nic_data;
745 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
746 unsigned int i;
747 size_t outlen;
748 int rc = 0;
749
750 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
751
752 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000753 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
754 outbuf, sizeof(outbuf), &outlen);
755 if (rc) {
756 /* Don't display the MC error if we didn't have space
757 * for a VF.
758 */
759 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
760 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
761 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100762 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000763 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100764 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
765 rc = -EIO;
766 break;
767 }
768 nic_data->piobuf_handle[i] =
769 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
770 netif_dbg(efx, probe, efx->net_dev,
771 "allocated PIO buffer %u handle %x\n", i,
772 nic_data->piobuf_handle[i]);
773 }
774
775 nic_data->n_piobufs = i;
776 if (rc)
777 efx_ef10_free_piobufs(efx);
778 return rc;
779}
780
781static int efx_ef10_link_piobufs(struct efx_nic *efx)
782{
783 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100784 _MCDI_DECLARE_BUF(inbuf,
785 max(MC_CMD_LINK_PIOBUF_IN_LEN,
786 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100787 struct efx_channel *channel;
788 struct efx_tx_queue *tx_queue;
789 unsigned int offset, index;
790 int rc;
791
792 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
793 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
794
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100795 memset(inbuf, 0, sizeof(inbuf));
796
Ben Hutchings183233b2013-06-28 21:47:12 +0100797 /* Link a buffer to each VI in the write-combining mapping */
798 for (index = 0; index < nic_data->n_piobufs; ++index) {
799 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
800 nic_data->piobuf_handle[index]);
801 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
802 nic_data->pio_write_vi_base + index);
803 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
804 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
805 NULL, 0, NULL);
806 if (rc) {
807 netif_err(efx, drv, efx->net_dev,
808 "failed to link VI %u to PIO buffer %u (%d)\n",
809 nic_data->pio_write_vi_base + index, index,
810 rc);
811 goto fail;
812 }
813 netif_dbg(efx, probe, efx->net_dev,
814 "linked VI %u to PIO buffer %u\n",
815 nic_data->pio_write_vi_base + index, index);
816 }
817
818 /* Link a buffer to each TX queue */
819 efx_for_each_channel(channel, efx) {
820 efx_for_each_channel_tx_queue(tx_queue, channel) {
821 /* We assign the PIO buffers to queues in
822 * reverse order to allow for the following
823 * special case.
824 */
825 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
826 tx_queue->channel->channel - 1) *
827 efx_piobuf_size);
828 index = offset / ER_DZ_TX_PIOBUF_SIZE;
829 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
830
831 /* When the host page size is 4K, the first
832 * host page in the WC mapping may be within
833 * the same VI page as the last TX queue. We
834 * can only link one buffer to each VI.
835 */
836 if (tx_queue->queue == nic_data->pio_write_vi_base) {
837 BUG_ON(index != 0);
838 rc = 0;
839 } else {
840 MCDI_SET_DWORD(inbuf,
841 LINK_PIOBUF_IN_PIOBUF_HANDLE,
842 nic_data->piobuf_handle[index]);
843 MCDI_SET_DWORD(inbuf,
844 LINK_PIOBUF_IN_TXQ_INSTANCE,
845 tx_queue->queue);
846 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
847 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
848 NULL, 0, NULL);
849 }
850
851 if (rc) {
852 /* This is non-fatal; the TX path just
853 * won't use PIO for this queue
854 */
855 netif_err(efx, drv, efx->net_dev,
856 "failed to link VI %u to PIO buffer %u (%d)\n",
857 tx_queue->queue, index, rc);
858 tx_queue->piobuf = NULL;
859 } else {
860 tx_queue->piobuf =
861 nic_data->pio_write_base +
862 index * EFX_VI_PAGE_SIZE + offset;
863 tx_queue->piobuf_offset = offset;
864 netif_dbg(efx, probe, efx->net_dev,
865 "linked VI %u to PIO buffer %u offset %x addr %p\n",
866 tx_queue->queue, index,
867 tx_queue->piobuf_offset,
868 tx_queue->piobuf);
869 }
870 }
871 }
872
873 return 0;
874
875fail:
876 while (index--) {
877 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
878 nic_data->pio_write_vi_base + index);
879 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
880 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
881 NULL, 0, NULL);
882 }
883 return rc;
884}
885
Edward Creec0795bf2016-05-24 18:53:36 +0100886static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
887{
888 struct efx_channel *channel;
889 struct efx_tx_queue *tx_queue;
890
891 /* All our existing PIO buffers went away */
892 efx_for_each_channel(channel, efx)
893 efx_for_each_channel_tx_queue(tx_queue, channel)
894 tx_queue->piobuf = NULL;
895}
896
Ben Hutchings183233b2013-06-28 21:47:12 +0100897#else /* !EFX_USE_PIO */
898
899static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
900{
901 return n == 0 ? 0 : -ENOBUFS;
902}
903
904static int efx_ef10_link_piobufs(struct efx_nic *efx)
905{
906 return 0;
907}
908
909static void efx_ef10_free_piobufs(struct efx_nic *efx)
910{
911}
912
Edward Creec0795bf2016-05-24 18:53:36 +0100913static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
914{
915}
916
Ben Hutchings183233b2013-06-28 21:47:12 +0100917#endif /* EFX_USE_PIO */
918
Ben Hutchings8127d662013-08-29 19:19:29 +0100919static void efx_ef10_remove(struct efx_nic *efx)
920{
921 struct efx_ef10_nic_data *nic_data = efx->nic_data;
922 int rc;
923
Shradha Shahf1122a32015-05-20 11:09:46 +0100924#ifdef CONFIG_SFC_SRIOV
925 struct efx_ef10_nic_data *nic_data_pf;
926 struct pci_dev *pci_dev_pf;
927 struct efx_nic *efx_pf;
928 struct ef10_vf *vf;
929
930 if (efx->pci_dev->is_virtfn) {
931 pci_dev_pf = efx->pci_dev->physfn;
932 if (pci_dev_pf) {
933 efx_pf = pci_get_drvdata(pci_dev_pf);
934 nic_data_pf = efx_pf->nic_data;
935 vf = nic_data_pf->vf + nic_data->vf_index;
936 vf->efx = NULL;
937 } else
938 netif_info(efx, drv, efx->net_dev,
939 "Could not get the PF id from VF\n");
940 }
941#endif
942
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100943 efx_ef10_cleanup_vlans(efx);
944 mutex_destroy(&nic_data->vlan_lock);
945
Ben Hutchings9aecda92013-12-05 21:28:42 +0000946 efx_ptp_remove(efx);
947
Ben Hutchings8127d662013-08-29 19:19:29 +0100948 efx_mcdi_mon_remove(efx);
949
Ben Hutchings8127d662013-08-29 19:19:29 +0100950 efx_ef10_rx_free_indir_table(efx);
951
Ben Hutchings183233b2013-06-28 21:47:12 +0100952 if (nic_data->wc_membase)
953 iounmap(nic_data->wc_membase);
954
Ben Hutchings8127d662013-08-29 19:19:29 +0100955 rc = efx_ef10_free_vis(efx);
956 WARN_ON(rc != 0);
957
Ben Hutchings183233b2013-06-28 21:47:12 +0100958 if (!nic_data->must_restore_piobufs)
959 efx_ef10_free_piobufs(efx);
960
Shradha Shah0f5c0842015-06-02 11:37:58 +0100961 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
962 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
963
Ben Hutchings8127d662013-08-29 19:19:29 +0100964 efx_mcdi_fini(efx);
965 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
966 kfree(nic_data);
967}
968
Shradha Shah88a37de2015-05-20 11:09:15 +0100969static int efx_ef10_probe_pf(struct efx_nic *efx)
970{
971 return efx_ef10_probe(efx);
972}
973
Andrew Rybchenko38d27f32016-06-15 17:52:08 +0100974int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
975 u32 *port_flags, u32 *vadaptor_flags,
976 unsigned int *vlan_tags)
977{
978 struct efx_ef10_nic_data *nic_data = efx->nic_data;
979 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
980 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
981 size_t outlen;
982 int rc;
983
984 if (nic_data->datapath_caps &
985 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
986 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
987 port_id);
988
989 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
990 outbuf, sizeof(outbuf), &outlen);
991 if (rc)
992 return rc;
993
994 if (outlen < sizeof(outbuf)) {
995 rc = -EIO;
996 return rc;
997 }
998 }
999
1000 if (port_flags)
1001 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1002 if (vadaptor_flags)
1003 *vadaptor_flags =
1004 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1005 if (vlan_tags)
1006 *vlan_tags =
1007 MCDI_DWORD(outbuf,
1008 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1009
1010 return 0;
1011}
1012
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001013int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1014{
1015 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1016
1017 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1018 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1019 NULL, 0, NULL);
1020}
1021
1022int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1023{
1024 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1025
1026 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1027 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1028 NULL, 0, NULL);
1029}
1030
1031int efx_ef10_vport_add_mac(struct efx_nic *efx,
1032 unsigned int port_id, u8 *mac)
1033{
1034 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1035
1036 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1037 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1038
1039 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1040 sizeof(inbuf), NULL, 0, NULL);
1041}
1042
1043int efx_ef10_vport_del_mac(struct efx_nic *efx,
1044 unsigned int port_id, u8 *mac)
1045{
1046 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1047
1048 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1049 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1050
1051 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1052 sizeof(inbuf), NULL, 0, NULL);
1053}
1054
Shradha Shah88a37de2015-05-20 11:09:15 +01001055#ifdef CONFIG_SFC_SRIOV
1056static int efx_ef10_probe_vf(struct efx_nic *efx)
1057{
1058 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001059 struct pci_dev *pci_dev_pf;
1060
1061 /* If the parent PF has no VF data structure, it doesn't know about this
1062 * VF so fail probe. The VF needs to be re-created. This can happen
1063 * if the PF driver is unloaded while the VF is assigned to a guest.
1064 */
1065 pci_dev_pf = efx->pci_dev->physfn;
1066 if (pci_dev_pf) {
1067 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1068 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1069
1070 if (!nic_data_pf->vf) {
1071 netif_info(efx, drv, efx->net_dev,
1072 "The VF cannot link to its parent PF; "
1073 "please destroy and re-create the VF\n");
1074 return -EBUSY;
1075 }
1076 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001077
1078 rc = efx_ef10_probe(efx);
1079 if (rc)
1080 return rc;
1081
1082 rc = efx_ef10_get_vf_index(efx);
1083 if (rc)
1084 goto fail;
1085
Shradha Shahf1122a32015-05-20 11:09:46 +01001086 if (efx->pci_dev->is_virtfn) {
1087 if (efx->pci_dev->physfn) {
1088 struct efx_nic *efx_pf =
1089 pci_get_drvdata(efx->pci_dev->physfn);
1090 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1091 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1092
1093 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001094 nic_data_p->vf[nic_data->vf_index].pci_dev =
1095 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001096 } else
1097 netif_info(efx, drv, efx->net_dev,
1098 "Could not get the PF id from VF\n");
1099 }
1100
Shradha Shah88a37de2015-05-20 11:09:15 +01001101 return 0;
1102
1103fail:
1104 efx_ef10_remove(efx);
1105 return rc;
1106}
1107#else
1108static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1109{
1110 return 0;
1111}
1112#endif
1113
Ben Hutchings8127d662013-08-29 19:19:29 +01001114static int efx_ef10_alloc_vis(struct efx_nic *efx,
1115 unsigned int min_vis, unsigned int max_vis)
1116{
1117 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1118 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1119 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1120 size_t outlen;
1121 int rc;
1122
1123 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1124 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1125 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1126 outbuf, sizeof(outbuf), &outlen);
1127 if (rc != 0)
1128 return rc;
1129
1130 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1131 return -EIO;
1132
1133 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1134 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1135
1136 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1137 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1138 return 0;
1139}
1140
Ben Hutchings183233b2013-06-28 21:47:12 +01001141/* Note that the failure path of this function does not free
1142 * resources, as this will be done by efx_ef10_remove().
1143 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001144static int efx_ef10_dimension_resources(struct efx_nic *efx)
1145{
Ben Hutchings183233b2013-06-28 21:47:12 +01001146 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1147 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001148 unsigned int min_vis = max(EFX_TXQ_TYPES,
1149 efx_separate_tx_channels ? 2 : 1);
1150 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001151 void __iomem *membase;
1152 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001153
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001154 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001155
1156#ifdef EFX_USE_PIO
1157 /* Try to allocate PIO buffers if wanted and if the full
1158 * number of PIO buffers would be sufficient to allocate one
1159 * copy-buffer per TX channel. Failure is non-fatal, as there
1160 * are only a small number of PIO buffers shared between all
1161 * functions of the controller.
1162 */
1163 if (efx_piobuf_size != 0 &&
1164 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1165 efx->n_tx_channels) {
1166 unsigned int n_piobufs =
1167 DIV_ROUND_UP(efx->n_tx_channels,
1168 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
1169
1170 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1171 if (rc)
1172 netif_err(efx, probe, efx->net_dev,
1173 "failed to allocate PIO buffers (%d)\n", rc);
1174 else
1175 netif_dbg(efx, probe, efx->net_dev,
1176 "allocated %u PIO buffers\n", n_piobufs);
1177 }
1178#else
1179 nic_data->n_piobufs = 0;
1180#endif
1181
1182 /* PIO buffers should be mapped with write-combining enabled,
1183 * and we want to make single UC and WC mappings rather than
1184 * several of each (in fact that's the only option if host
1185 * page size is >4K). So we may allocate some extra VIs just
1186 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001187 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001188 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001189 * first half of the next VI. Then the WC mapping begins with
1190 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001191 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001192 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001193 ER_DZ_TX_PIOBUF);
1194 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001195 /* pio_write_vi_base rounds down to give the number of complete
1196 * VIs inside the UC mapping.
1197 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001198 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1199 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1200 nic_data->n_piobufs) *
1201 EFX_VI_PAGE_SIZE) -
1202 uc_mem_map_size);
1203 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1204 } else {
1205 pio_write_vi_base = 0;
1206 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001207 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001208 }
1209
1210 /* In case the last attached driver failed to free VIs, do it now */
1211 rc = efx_ef10_free_vis(efx);
1212 if (rc != 0)
1213 return rc;
1214
1215 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1216 if (rc != 0)
1217 return rc;
1218
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001219 if (nic_data->n_allocated_vis < channel_vis) {
1220 netif_info(efx, drv, efx->net_dev,
1221 "Could not allocate enough VIs to satisfy RSS"
1222 " requirements. Performance may not be optimal.\n");
1223 /* We didn't get the VIs to populate our channels.
1224 * We could keep what we got but then we'd have more
1225 * interrupts than we need.
1226 * Instead calculate new max_channels and restart
1227 */
1228 efx->max_channels = nic_data->n_allocated_vis;
1229 efx->max_tx_channels =
1230 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1231
1232 efx_ef10_free_vis(efx);
1233 return -EAGAIN;
1234 }
1235
Ben Hutchings183233b2013-06-28 21:47:12 +01001236 /* If we didn't get enough VIs to map all the PIO buffers, free the
1237 * PIO buffers
1238 */
1239 if (nic_data->n_piobufs &&
1240 nic_data->n_allocated_vis <
1241 pio_write_vi_base + nic_data->n_piobufs) {
1242 netif_dbg(efx, probe, efx->net_dev,
1243 "%u VIs are not sufficient to map %u PIO buffers\n",
1244 nic_data->n_allocated_vis, nic_data->n_piobufs);
1245 efx_ef10_free_piobufs(efx);
1246 }
1247
1248 /* Shrink the original UC mapping of the memory BAR */
1249 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1250 if (!membase) {
1251 netif_err(efx, probe, efx->net_dev,
1252 "could not shrink memory BAR to %x\n",
1253 uc_mem_map_size);
1254 return -ENOMEM;
1255 }
1256 iounmap(efx->membase);
1257 efx->membase = membase;
1258
1259 /* Set up the WC mapping if needed */
1260 if (wc_mem_map_size) {
1261 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1262 uc_mem_map_size,
1263 wc_mem_map_size);
1264 if (!nic_data->wc_membase) {
1265 netif_err(efx, probe, efx->net_dev,
1266 "could not allocate WC mapping of size %x\n",
1267 wc_mem_map_size);
1268 return -ENOMEM;
1269 }
1270 nic_data->pio_write_vi_base = pio_write_vi_base;
1271 nic_data->pio_write_base =
1272 nic_data->wc_membase +
1273 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1274 uc_mem_map_size);
1275
1276 rc = efx_ef10_link_piobufs(efx);
1277 if (rc)
1278 efx_ef10_free_piobufs(efx);
1279 }
1280
1281 netif_dbg(efx, probe, efx->net_dev,
1282 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1283 &efx->membase_phys, efx->membase, uc_mem_map_size,
1284 nic_data->wc_membase, wc_mem_map_size);
1285
1286 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001287}
1288
1289static int efx_ef10_init_nic(struct efx_nic *efx)
1290{
1291 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1292 int rc;
1293
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001294 if (nic_data->must_check_datapath_caps) {
1295 rc = efx_ef10_init_datapath_caps(efx);
1296 if (rc)
1297 return rc;
1298 nic_data->must_check_datapath_caps = false;
1299 }
1300
Ben Hutchings8127d662013-08-29 19:19:29 +01001301 if (nic_data->must_realloc_vis) {
1302 /* We cannot let the number of VIs change now */
1303 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1304 nic_data->n_allocated_vis);
1305 if (rc)
1306 return rc;
1307 nic_data->must_realloc_vis = false;
1308 }
1309
Ben Hutchings183233b2013-06-28 21:47:12 +01001310 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1311 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1312 if (rc == 0) {
1313 rc = efx_ef10_link_piobufs(efx);
1314 if (rc)
1315 efx_ef10_free_piobufs(efx);
1316 }
1317
1318 /* Log an error on failure, but this is non-fatal */
1319 if (rc)
1320 netif_err(efx, drv, efx->net_dev,
1321 "failed to restore PIO buffers (%d)\n", rc);
1322 nic_data->must_restore_piobufs = false;
1323 }
1324
Jon Cooper267c0152015-05-06 00:59:38 +01001325 /* don't fail init if RSS setup doesn't work */
1326 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1327
Ben Hutchings8127d662013-08-29 19:19:29 +01001328 return 0;
1329}
1330
Jon Cooper3e336262014-01-17 19:48:06 +00001331static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1332{
1333 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001334#ifdef CONFIG_SFC_SRIOV
1335 unsigned int i;
1336#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001337
1338 /* All our allocations have been reset */
1339 nic_data->must_realloc_vis = true;
1340 nic_data->must_restore_filters = true;
1341 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001342 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001343 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001344
1345 /* Driver-created vswitches and vports must be re-created */
1346 nic_data->must_probe_vswitching = true;
1347 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1348#ifdef CONFIG_SFC_SRIOV
1349 if (nic_data->vf)
1350 for (i = 0; i < efx->vf_count; i++)
1351 nic_data->vf[i].vport_id = 0;
1352#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001353}
1354
Jon Cooper087e9022015-05-20 11:11:35 +01001355static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1356{
1357 if (reason == RESET_TYPE_MC_FAILURE)
1358 return RESET_TYPE_DATAPATH;
1359
1360 return efx_mcdi_map_reset_reason(reason);
1361}
1362
Ben Hutchings8127d662013-08-29 19:19:29 +01001363static int efx_ef10_map_reset_flags(u32 *flags)
1364{
1365 enum {
1366 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1367 ETH_RESET_SHARED_SHIFT),
1368 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1369 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1370 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1371 ETH_RESET_SHARED_SHIFT)
1372 };
1373
1374 /* We assume for now that our PCI function is permitted to
1375 * reset everything.
1376 */
1377
1378 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1379 *flags &= ~EF10_RESET_MC;
1380 return RESET_TYPE_WORLD;
1381 }
1382
1383 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1384 *flags &= ~EF10_RESET_PORT;
1385 return RESET_TYPE_ALL;
1386 }
1387
1388 /* no invisible reset implemented */
1389
1390 return -EINVAL;
1391}
1392
Jon Cooper3e336262014-01-17 19:48:06 +00001393static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1394{
1395 int rc = efx_mcdi_reset(efx, reset_type);
1396
Daniel Pieczko27324822015-07-31 11:14:54 +01001397 /* Unprivileged functions return -EPERM, but need to return success
1398 * here so that the datapath is brought back up.
1399 */
1400 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1401 rc = 0;
1402
Jon Cooper3e336262014-01-17 19:48:06 +00001403 /* If it was a port reset, trigger reallocation of MC resources.
1404 * Note that on an MC reset nothing needs to be done now because we'll
1405 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001406 * For an FLR, we never get an MC reset event, but the MC has reset all
1407 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001408 */
Edward Creee2835462014-04-16 19:27:48 +01001409 if ((reset_type == RESET_TYPE_ALL ||
1410 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001411 efx_ef10_reset_mc_allocations(efx);
1412 return rc;
1413}
1414
Ben Hutchings8127d662013-08-29 19:19:29 +01001415#define EF10_DMA_STAT(ext_name, mcdi_name) \
1416 [EF10_STAT_ ## ext_name] = \
1417 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1418#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1419 [EF10_STAT_ ## int_name] = \
1420 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1421#define EF10_OTHER_STAT(ext_name) \
1422 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001423#define GENERIC_SW_STAT(ext_name) \
1424 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001425
1426static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001427 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1428 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1429 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1430 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1431 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1432 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1433 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1434 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1435 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1436 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1437 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1438 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1439 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1440 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1441 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1442 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1443 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1444 EF10_OTHER_STAT(port_rx_good_bytes),
1445 EF10_OTHER_STAT(port_rx_bad_bytes),
1446 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1447 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1448 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1449 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1450 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1451 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1452 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1453 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1454 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1455 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1456 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1457 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1458 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1459 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1460 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1461 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1462 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1463 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1464 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1465 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1466 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1467 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001468 GENERIC_SW_STAT(rx_nodesc_trunc),
1469 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001470 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1471 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1472 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1473 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1474 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1475 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1476 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1477 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1478 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1479 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1480 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1481 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001482 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1483 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1484 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1485 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1486 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1487 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1488 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1489 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1490 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1491 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1492 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1493 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1494 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1495 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1496 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1497 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1498 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1499 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001500};
1501
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001502#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1503 (1ULL << EF10_STAT_port_tx_packets) | \
1504 (1ULL << EF10_STAT_port_tx_pause) | \
1505 (1ULL << EF10_STAT_port_tx_unicast) | \
1506 (1ULL << EF10_STAT_port_tx_multicast) | \
1507 (1ULL << EF10_STAT_port_tx_broadcast) | \
1508 (1ULL << EF10_STAT_port_rx_bytes) | \
1509 (1ULL << \
1510 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1511 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1512 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1513 (1ULL << EF10_STAT_port_rx_packets) | \
1514 (1ULL << EF10_STAT_port_rx_good) | \
1515 (1ULL << EF10_STAT_port_rx_bad) | \
1516 (1ULL << EF10_STAT_port_rx_pause) | \
1517 (1ULL << EF10_STAT_port_rx_control) | \
1518 (1ULL << EF10_STAT_port_rx_unicast) | \
1519 (1ULL << EF10_STAT_port_rx_multicast) | \
1520 (1ULL << EF10_STAT_port_rx_broadcast) | \
1521 (1ULL << EF10_STAT_port_rx_lt64) | \
1522 (1ULL << EF10_STAT_port_rx_64) | \
1523 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1524 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1525 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1526 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1527 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1528 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1529 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1530 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1531 (1ULL << EF10_STAT_port_rx_overflow) | \
1532 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001533 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1534 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001535
Edward Cree69b365c2016-08-26 15:12:41 +01001536/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1537 * For a 10G/40G switchable port we do not expose these because they might
1538 * not include all the packets they should.
1539 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001540 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001541#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1542 (1ULL << EF10_STAT_port_tx_lt64) | \
1543 (1ULL << EF10_STAT_port_tx_64) | \
1544 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1545 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1546 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1547 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1548 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1549 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001550
1551/* These statistics are only provided by the 40G MAC. For a 10G/40G
1552 * switchable port we do expose these because the errors will otherwise
1553 * be silent.
1554 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001555#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1556 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001557
Edward Cree568d7a02013-09-25 17:32:09 +01001558/* These statistics are only provided if the firmware supports the
1559 * capability PM_AND_RXDP_COUNTERS.
1560 */
1561#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001562 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1563 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1564 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1565 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1566 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1567 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1568 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1569 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1570 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1571 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1572 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1573 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001574
Edward Cree4bae9132013-09-27 18:52:49 +01001575static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001576{
Edward Cree4bae9132013-09-27 18:52:49 +01001577 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001578 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001579 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001580
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001581 if (!(efx->mcdi->fn_flags &
1582 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1583 return 0;
1584
Edward Cree69b365c2016-08-26 15:12:41 +01001585 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001586 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001587 /* 8000 series have everything even at 40G */
1588 if (nic_data->datapath_caps2 &
1589 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1590 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1591 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001592 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001593 }
Edward Cree568d7a02013-09-25 17:32:09 +01001594
1595 if (nic_data->datapath_caps &
1596 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1597 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1598
Edward Cree4bae9132013-09-27 18:52:49 +01001599 return raw_mask;
1600}
1601
1602static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1603{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001604 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001605 u64 raw_mask[2];
1606
1607 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1608
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001609 /* Only show vadaptor stats when EVB capability is present */
1610 if (nic_data->datapath_caps &
1611 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1612 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1613 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1614 } else {
1615 raw_mask[1] = 0;
1616 }
Edward Cree4bae9132013-09-27 18:52:49 +01001617
1618#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001619 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001620 mask[0] = raw_mask[0];
1621 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001622#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001623 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001624 mask[0] = raw_mask[0] & 0xffffffff;
1625 mask[1] = raw_mask[0] >> 32;
1626 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001627#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001628}
1629
1630static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1631{
Edward Cree4bae9132013-09-27 18:52:49 +01001632 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1633
1634 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001635 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001636 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001637}
1638
Daniel Pieczkod7788192015-06-02 11:39:20 +01001639static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1640 struct rtnl_link_stats64 *core_stats)
1641{
1642 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1643 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1644 u64 *stats = nic_data->stats;
1645 size_t stats_count = 0, index;
1646
1647 efx_ef10_get_stat_mask(efx, mask);
1648
1649 if (full_stats) {
1650 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1651 if (efx_ef10_stat_desc[index].name) {
1652 *full_stats++ = stats[index];
1653 ++stats_count;
1654 }
1655 }
1656 }
1657
Bert Kenwardfbe43072015-08-26 16:39:03 +01001658 if (!core_stats)
1659 return stats_count;
1660
1661 if (nic_data->datapath_caps &
1662 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1663 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001664 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1665 stats[EF10_STAT_rx_multicast] +
1666 stats[EF10_STAT_rx_broadcast];
1667 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1668 stats[EF10_STAT_tx_multicast] +
1669 stats[EF10_STAT_tx_broadcast];
1670 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1671 stats[EF10_STAT_rx_multicast_bytes] +
1672 stats[EF10_STAT_rx_broadcast_bytes];
1673 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1674 stats[EF10_STAT_tx_multicast_bytes] +
1675 stats[EF10_STAT_tx_broadcast_bytes];
1676 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001677 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001678 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1679 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1680 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1681 core_stats->rx_errors = core_stats->rx_crc_errors;
1682 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001683 } else {
1684 /* Use port stats. */
1685 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1686 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1687 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1688 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1689 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1690 stats[GENERIC_STAT_rx_nodesc_trunc] +
1691 stats[GENERIC_STAT_rx_noskb_drops];
1692 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1693 core_stats->rx_length_errors =
1694 stats[EF10_STAT_port_rx_gtjumbo] +
1695 stats[EF10_STAT_port_rx_length_error];
1696 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1697 core_stats->rx_frame_errors =
1698 stats[EF10_STAT_port_rx_align_error];
1699 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1700 core_stats->rx_errors = (core_stats->rx_length_errors +
1701 core_stats->rx_crc_errors +
1702 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001703 }
1704
1705 return stats_count;
1706}
1707
1708static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001709{
1710 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001711 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001712 __le64 generation_start, generation_end;
1713 u64 *stats = nic_data->stats;
1714 __le64 *dma_stats;
1715
Edward Cree4bae9132013-09-27 18:52:49 +01001716 efx_ef10_get_stat_mask(efx, mask);
1717
Ben Hutchings8127d662013-08-29 19:19:29 +01001718 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001719
1720 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1721 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1722 return 0;
1723 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001724 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001725 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001726 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001727 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1728 if (generation_end != generation_start)
1729 return -EAGAIN;
1730
1731 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001732 efx_nic_fix_nodesc_drop_stat(efx,
1733 &stats[EF10_STAT_port_rx_nodesc_drops]);
1734 stats[EF10_STAT_port_rx_good_bytes] =
1735 stats[EF10_STAT_port_rx_bytes] -
1736 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1737 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1738 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001739 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001740 return 0;
1741}
1742
1743
Daniel Pieczkod7788192015-06-02 11:39:20 +01001744static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1745 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001746{
Ben Hutchings8127d662013-08-29 19:19:29 +01001747 int retry;
1748
1749 /* If we're unlucky enough to read statistics during the DMA, wait
1750 * up to 10ms for it to finish (typically takes <500us)
1751 */
1752 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001753 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001754 break;
1755 udelay(100);
1756 }
1757
Daniel Pieczkod7788192015-06-02 11:39:20 +01001758 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1759}
1760
1761static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1762{
1763 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1764 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1765 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1766 __le64 generation_start, generation_end;
1767 u64 *stats = nic_data->stats;
1768 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1769 struct efx_buffer stats_buf;
1770 __le64 *dma_stats;
1771 int rc;
1772
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001773 spin_unlock_bh(&efx->stats_lock);
1774
1775 if (in_interrupt()) {
1776 /* If in atomic context, cannot update stats. Just update the
1777 * software stats and return so the caller can continue.
1778 */
1779 spin_lock_bh(&efx->stats_lock);
1780 efx_update_sw_stats(efx, stats);
1781 return 0;
1782 }
1783
Daniel Pieczkod7788192015-06-02 11:39:20 +01001784 efx_ef10_get_stat_mask(efx, mask);
1785
1786 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001787 if (rc) {
1788 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001789 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001790 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001791
1792 dma_stats = stats_buf.addr;
1793 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1794
1795 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1796 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001797 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001798 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1799 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1800
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001801 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1802 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001803 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001804 if (rc) {
1805 /* Expect ENOENT if DMA queues have not been set up */
1806 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1807 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1808 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001809 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001810 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001811
1812 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001813 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1814 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001815 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001816 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001817 rmb();
1818 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1819 stats, stats_buf.addr, false);
1820 rmb();
1821 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1822 if (generation_end != generation_start) {
1823 rc = -EAGAIN;
1824 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001825 }
1826
Daniel Pieczkod7788192015-06-02 11:39:20 +01001827 efx_update_sw_stats(efx, stats);
1828out:
1829 efx_nic_free_buffer(efx, &stats_buf);
1830 return rc;
1831}
Ben Hutchings8127d662013-08-29 19:19:29 +01001832
Daniel Pieczkod7788192015-06-02 11:39:20 +01001833static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1834 struct rtnl_link_stats64 *core_stats)
1835{
1836 if (efx_ef10_try_update_nic_stats_vf(efx))
1837 return 0;
1838
1839 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001840}
1841
1842static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1843{
1844 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001845 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001846 efx_dword_t timer_cmd;
1847
Bert Kenward539de7c2016-08-11 13:02:09 +01001848 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001849 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001850 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001851 } else {
1852 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001853 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001854 }
1855
Bert Kenward539de7c2016-08-11 13:02:09 +01001856 if (EFX_EF10_WORKAROUND_61265(efx)) {
1857 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1858 unsigned int ns = usecs * 1000;
1859
1860 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1861 channel->channel);
1862 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1863 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1864 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1865
1866 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1867 inbuf, sizeof(inbuf), 0, NULL, 0);
1868 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1869 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1870
Ben Hutchings8127d662013-08-29 19:19:29 +01001871 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1872 EFE_DD_EVQ_IND_TIMER_FLAGS,
1873 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001874 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001875 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1876 channel->channel);
1877 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001878 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1879
Ben Hutchings8127d662013-08-29 19:19:29 +01001880 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001881 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001882 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1883 channel->channel);
1884 }
1885}
1886
Shradha Shah02246a72015-05-06 00:58:14 +01001887static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1888 struct ethtool_wolinfo *wol) {}
1889
1890static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1891{
1892 return -EOPNOTSUPP;
1893}
1894
Ben Hutchings8127d662013-08-29 19:19:29 +01001895static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1896{
1897 wol->supported = 0;
1898 wol->wolopts = 0;
1899 memset(&wol->sopass, 0, sizeof(wol->sopass));
1900}
1901
1902static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1903{
1904 if (type != 0)
1905 return -EINVAL;
1906 return 0;
1907}
1908
1909static void efx_ef10_mcdi_request(struct efx_nic *efx,
1910 const efx_dword_t *hdr, size_t hdr_len,
1911 const efx_dword_t *sdu, size_t sdu_len)
1912{
1913 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1914 u8 *pdu = nic_data->mcdi_buf.addr;
1915
1916 memcpy(pdu, hdr, hdr_len);
1917 memcpy(pdu + hdr_len, sdu, sdu_len);
1918 wmb();
1919
1920 /* The hardware provides 'low' and 'high' (doorbell) registers
1921 * for passing the 64-bit address of an MCDI request to
1922 * firmware. However the dwords are swapped by firmware. The
1923 * least significant bits of the doorbell are then 0 for all
1924 * MCDI requests due to alignment.
1925 */
1926 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1927 ER_DZ_MC_DB_LWRD);
1928 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1929 ER_DZ_MC_DB_HWRD);
1930}
1931
1932static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1933{
1934 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1935 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1936
1937 rmb();
1938 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1939}
1940
1941static void
1942efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1943 size_t offset, size_t outlen)
1944{
1945 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1946 const u8 *pdu = nic_data->mcdi_buf.addr;
1947
1948 memcpy(outbuf, pdu + offset, outlen);
1949}
1950
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001951static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1952{
1953 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1954
1955 /* All our allocations have been reset */
1956 efx_ef10_reset_mc_allocations(efx);
1957
1958 /* The datapath firmware might have been changed */
1959 nic_data->must_check_datapath_caps = true;
1960
1961 /* MAC statistics have been cleared on the NIC; clear the local
1962 * statistic that we update with efx_update_diff_stat().
1963 */
1964 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1965}
1966
Ben Hutchings8127d662013-08-29 19:19:29 +01001967static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1968{
1969 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1970 int rc;
1971
1972 rc = efx_ef10_get_warm_boot_count(efx);
1973 if (rc < 0) {
1974 /* The firmware is presumably in the process of
1975 * rebooting. However, we are supposed to report each
1976 * reboot just once, so we must only do that once we
1977 * can read and store the updated warm boot count.
1978 */
1979 return 0;
1980 }
1981
1982 if (rc == nic_data->warm_boot_count)
1983 return 0;
1984
1985 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001986 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01001987
Ben Hutchings8127d662013-08-29 19:19:29 +01001988 return -EIO;
1989}
1990
1991/* Handle an MSI interrupt
1992 *
1993 * Handle an MSI hardware interrupt. This routine schedules event
1994 * queue processing. No interrupt acknowledgement cycle is necessary.
1995 * Also, we never need to check that the interrupt is for us, since
1996 * MSI interrupts cannot be shared.
1997 */
1998static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1999{
2000 struct efx_msi_context *context = dev_id;
2001 struct efx_nic *efx = context->efx;
2002
2003 netif_vdbg(efx, intr, efx->net_dev,
2004 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2005
2006 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2007 /* Note test interrupts */
2008 if (context->index == efx->irq_level)
2009 efx->last_irq_cpu = raw_smp_processor_id();
2010
2011 /* Schedule processing of the channel */
2012 efx_schedule_channel_irq(efx->channel[context->index]);
2013 }
2014
2015 return IRQ_HANDLED;
2016}
2017
2018static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2019{
2020 struct efx_nic *efx = dev_id;
2021 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2022 struct efx_channel *channel;
2023 efx_dword_t reg;
2024 u32 queues;
2025
2026 /* Read the ISR which also ACKs the interrupts */
2027 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2028 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2029
2030 if (queues == 0)
2031 return IRQ_NONE;
2032
2033 if (likely(soft_enabled)) {
2034 /* Note test interrupts */
2035 if (queues & (1U << efx->irq_level))
2036 efx->last_irq_cpu = raw_smp_processor_id();
2037
2038 efx_for_each_channel(channel, efx) {
2039 if (queues & 1)
2040 efx_schedule_channel_irq(channel);
2041 queues >>= 1;
2042 }
2043 }
2044
2045 netif_vdbg(efx, intr, efx->net_dev,
2046 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2047 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2048
2049 return IRQ_HANDLED;
2050}
2051
Jon Cooper942e2982016-08-26 15:13:30 +01002052static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002053{
2054 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2055
Jon Cooper942e2982016-08-26 15:13:30 +01002056 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2057 NULL) == 0)
2058 return -ENOTSUPP;
2059
Ben Hutchings8127d662013-08-29 19:19:29 +01002060 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2061
2062 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002063 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002064 inbuf, sizeof(inbuf), NULL, 0, NULL);
2065}
2066
2067static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2068{
2069 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2070 (tx_queue->ptr_mask + 1) *
2071 sizeof(efx_qword_t),
2072 GFP_KERNEL);
2073}
2074
2075/* This writes to the TX_DESC_WPTR and also pushes data */
2076static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2077 const efx_qword_t *txd)
2078{
2079 unsigned int write_ptr;
2080 efx_oword_t reg;
2081
2082 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2083 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2084 reg.qword[0] = *txd;
2085 efx_writeo_page(tx_queue->efx, &reg,
2086 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2087}
2088
Bert Kenwarde9117e52016-11-17 10:51:54 +00002089/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2090 */
2091static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2092 struct sk_buff *skb,
2093 bool *data_mapped)
2094{
2095 struct efx_tx_buffer *buffer;
2096 struct tcphdr *tcp;
2097 struct iphdr *ip;
2098
2099 u16 ipv4_id;
2100 u32 seqnum;
2101 u32 mss;
2102
2103 EFX_BUG_ON_PARANOID(tx_queue->tso_version != 2);
2104
2105 mss = skb_shinfo(skb)->gso_size;
2106
2107 if (unlikely(mss < 4)) {
2108 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2109 return -EINVAL;
2110 }
2111
2112 ip = ip_hdr(skb);
2113 if (ip->version == 4) {
2114 /* Modify IPv4 header if needed. */
2115 ip->tot_len = 0;
2116 ip->check = 0;
2117 ipv4_id = ip->id;
2118 } else {
2119 /* Modify IPv6 header if needed. */
2120 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2121
2122 ipv6->payload_len = 0;
2123 ipv4_id = 0;
2124 }
2125
2126 tcp = tcp_hdr(skb);
2127 seqnum = ntohl(tcp->seq);
2128
2129 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2130
2131 buffer->flags = EFX_TX_BUF_OPTION;
2132 buffer->len = 0;
2133 buffer->unmap_len = 0;
2134 EFX_POPULATE_QWORD_5(buffer->option,
2135 ESF_DZ_TX_DESC_IS_OPT, 1,
2136 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2137 ESF_DZ_TX_TSO_OPTION_TYPE,
2138 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2139 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2140 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2141 );
2142 ++tx_queue->insert_count;
2143
2144 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2145
2146 buffer->flags = EFX_TX_BUF_OPTION;
2147 buffer->len = 0;
2148 buffer->unmap_len = 0;
2149 EFX_POPULATE_QWORD_4(buffer->option,
2150 ESF_DZ_TX_DESC_IS_OPT, 1,
2151 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2152 ESF_DZ_TX_TSO_OPTION_TYPE,
2153 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2154 ESF_DZ_TX_TSO_TCP_MSS, mss
2155 );
2156 ++tx_queue->insert_count;
2157
2158 return 0;
2159}
2160
Ben Hutchings8127d662013-08-29 19:19:29 +01002161static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2162{
2163 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2164 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002165 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2166 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2167 struct efx_channel *channel = tx_queue->channel;
2168 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002169 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002170 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002171 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002172 dma_addr_t dma_addr;
2173 efx_qword_t *txd;
2174 int rc;
2175 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002176 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002177
Bert Kenwarde9117e52016-11-17 10:51:54 +00002178 /* TSOv2 is a limited resource that can only be configured on a limited
2179 * number of queues. TSO without checksum offload is not really a thing,
2180 * so we only enable it for those queues.
2181 *
2182 * TODO: handle failure to allocate this in the case where we've used
2183 * all the queues.
2184 */
2185 if (csum_offload && (nic_data->datapath_caps2 &
2186 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2187 tso_v2 = true;
2188 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2189 channel->channel);
2190 }
2191
Ben Hutchings8127d662013-08-29 19:19:29 +01002192 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2193 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2194 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2195 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002196 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2197 /* This flag was removed from mcdi_pcol.h for
2198 * the non-_EXT version of INIT_TXQ. However,
2199 * firmware still honours it.
2200 */
2201 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
Ben Hutchings8127d662013-08-29 19:19:29 +01002202 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2203 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002204
Ben Hutchings8127d662013-08-29 19:19:29 +01002205 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002206 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002207
2208 dma_addr = tx_queue->txd.buf.dma_addr;
2209
2210 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2211 tx_queue->queue, entries, (u64)dma_addr);
2212
2213 for (i = 0; i < entries; ++i) {
2214 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2215 dma_addr += EFX_BUF_SIZE;
2216 }
2217
2218 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2219
2220 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002221 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002222 if (rc)
2223 goto fail;
2224
2225 /* A previous user of this TX queue might have set us up the
2226 * bomb by writing a descriptor to the TX push collector but
2227 * not the doorbell. (Each collector belongs to a port, not a
2228 * queue or function, so cannot easily be reset.) We must
2229 * attempt to push a no-op descriptor in its place.
2230 */
2231 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2232 tx_queue->insert_count = 1;
2233 txd = efx_tx_desc(tx_queue, 0);
2234 EFX_POPULATE_QWORD_4(*txd,
2235 ESF_DZ_TX_DESC_IS_OPT, true,
2236 ESF_DZ_TX_OPTION_TYPE,
2237 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2238 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2239 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2240 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002241
Bert Kenwarde9117e52016-11-17 10:51:54 +00002242 if (tso_v2) {
2243 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2244 tx_queue->tso_version = 2;
2245 } else if (nic_data->datapath_caps &
2246 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002247 tx_queue->tso_version = 1;
2248 }
2249
Ben Hutchings8127d662013-08-29 19:19:29 +01002250 wmb();
2251 efx_ef10_push_tx_desc(tx_queue, txd);
2252
2253 return;
2254
2255fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002256 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2257 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002258}
2259
2260static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2261{
2262 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002263 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002264 struct efx_nic *efx = tx_queue->efx;
2265 size_t outlen;
2266 int rc;
2267
2268 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2269 tx_queue->queue);
2270
Edward Cree1e0b8122013-05-31 18:36:12 +01002271 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002272 outbuf, sizeof(outbuf), &outlen);
2273
2274 if (rc && rc != -EALREADY)
2275 goto fail;
2276
2277 return;
2278
2279fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002280 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2281 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002282}
2283
2284static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2285{
2286 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2287}
2288
2289/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2290static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2291{
2292 unsigned int write_ptr;
2293 efx_dword_t reg;
2294
2295 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2296 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2297 efx_writed_page(tx_queue->efx, &reg,
2298 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2299}
2300
Bert Kenwarde9117e52016-11-17 10:51:54 +00002301#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2302
2303static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2304 dma_addr_t dma_addr, unsigned int len)
2305{
2306 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2307 /* If we need to break across multiple descriptors we should
2308 * stop at a page boundary. This assumes the length limit is
2309 * greater than the page size.
2310 */
2311 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2312
2313 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2314 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2315 }
2316
2317 return len;
2318}
2319
Ben Hutchings8127d662013-08-29 19:19:29 +01002320static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2321{
2322 unsigned int old_write_count = tx_queue->write_count;
2323 struct efx_tx_buffer *buffer;
2324 unsigned int write_ptr;
2325 efx_qword_t *txd;
2326
Martin Habetsb2663a42015-11-02 12:51:31 +00002327 tx_queue->xmit_more_available = false;
2328 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2329 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002330
2331 do {
2332 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2333 buffer = &tx_queue->buffer[write_ptr];
2334 txd = efx_tx_desc(tx_queue, write_ptr);
2335 ++tx_queue->write_count;
2336
2337 /* Create TX descriptor ring entry */
2338 if (buffer->flags & EFX_TX_BUF_OPTION) {
2339 *txd = buffer->option;
2340 } else {
2341 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2342 EFX_POPULATE_QWORD_3(
2343 *txd,
2344 ESF_DZ_TX_KER_CONT,
2345 buffer->flags & EFX_TX_BUF_CONT,
2346 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2347 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2348 }
2349 } while (tx_queue->write_count != tx_queue->insert_count);
2350
2351 wmb(); /* Ensure descriptors are written before they are fetched */
2352
2353 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2354 txd = efx_tx_desc(tx_queue,
2355 old_write_count & tx_queue->ptr_mask);
2356 efx_ef10_push_tx_desc(tx_queue, txd);
2357 ++tx_queue->pushes;
2358 } else {
2359 efx_ef10_notify_tx_desc(tx_queue);
2360 }
2361}
2362
Edward Creea33a4c72016-11-03 22:12:27 +00002363#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2364 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2365#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2366 1 << RSS_MODE_HASH_DST_PORT_LBN)
2367#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2368 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2369 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2370 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2371 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2372 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2373 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2374 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2375 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2376 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2377
2378static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2379{
2380 /* Firmware had a bug (sfc bug 61952) where it would not actually
2381 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2382 * This meant that it would always contain whatever was previously
2383 * in the MCDI buffer. Fortunately, all firmware versions with
2384 * this bug have the same default flags value for a newly-allocated
2385 * RSS context, and the only time we want to get the flags is just
2386 * after allocating. Moreover, the response has a 32-bit hole
2387 * where the context ID would be in the request, so we can use an
2388 * overlength buffer in the request and pre-fill the flags field
2389 * with what we believe the default to be. Thus if the firmware
2390 * has the bug, it will leave our pre-filled value in the flags
2391 * field of the response, and we will get the right answer.
2392 *
2393 * However, this does mean that this function should NOT be used if
2394 * the RSS context flags might not be their defaults - it is ONLY
2395 * reliably correct for a newly-allocated RSS context.
2396 */
2397 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2398 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2399 size_t outlen;
2400 int rc;
2401
2402 /* Check we have a hole for the context ID */
2403 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2404 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2405 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2406 RSS_CONTEXT_FLAGS_DEFAULT);
2407 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2408 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2409 if (rc == 0) {
2410 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2411 rc = -EIO;
2412 else
2413 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2414 }
2415 return rc;
2416}
2417
2418/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2419 * If we fail, we just leave the RSS context at its default hash settings,
2420 * which is safe but may slightly reduce performance.
2421 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2422 * just need to set the UDP ports flags (for both IP versions).
2423 */
2424static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2425{
2426 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2427 u32 flags;
2428
2429 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2430
2431 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2432 return;
2433 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2434 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2435 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2436 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002437 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2438 NULL, 0, NULL))
2439 /* Succeeded, so UDP 4-tuple is now enabled */
2440 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002441}
2442
Jon Cooper267c0152015-05-06 00:59:38 +01002443static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2444 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002445{
2446 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2447 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002448 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002449 size_t outlen;
2450 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002451 u32 alloc_type = exclusive ?
2452 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2453 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2454 unsigned rss_spread = exclusive ?
2455 efx->rss_spread :
2456 min(rounddown_pow_of_two(efx->rss_spread),
2457 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2458
2459 if (!exclusive && rss_spread == 1) {
2460 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2461 if (context_size)
2462 *context_size = 1;
2463 return 0;
2464 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002465
Jon Cooperdcb41232016-04-25 16:51:00 +01002466 if (nic_data->datapath_caps &
2467 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2468 return -EOPNOTSUPP;
2469
Ben Hutchings8127d662013-08-29 19:19:29 +01002470 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002471 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002472 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2473 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002474
2475 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2476 outbuf, sizeof(outbuf), &outlen);
2477 if (rc != 0)
2478 return rc;
2479
2480 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2481 return -EIO;
2482
2483 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2484
Jon Cooper267c0152015-05-06 00:59:38 +01002485 if (context_size)
2486 *context_size = rss_spread;
2487
Edward Creea33a4c72016-11-03 22:12:27 +00002488 if (nic_data->datapath_caps &
2489 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2490 efx_ef10_set_rss_flags(efx, *context);
2491
Ben Hutchings8127d662013-08-29 19:19:29 +01002492 return 0;
2493}
2494
2495static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2496{
2497 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2498 int rc;
2499
2500 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2501 context);
2502
2503 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2504 NULL, 0, NULL);
2505 WARN_ON(rc != 0);
2506}
2507
Jon Cooper267c0152015-05-06 00:59:38 +01002508static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2509 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002510{
2511 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2512 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2513 int i, rc;
2514
2515 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2516 context);
2517 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2518 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2519
2520 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2521 MCDI_PTR(tablebuf,
2522 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002523 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002524
2525 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2526 sizeof(tablebuf), NULL, 0, NULL);
2527 if (rc != 0)
2528 return rc;
2529
2530 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2531 context);
2532 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2533 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2534 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2535 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2536 efx->rx_hash_key[i];
2537
2538 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2539 sizeof(keybuf), NULL, 0, NULL);
2540}
2541
2542static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2543{
2544 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2545
2546 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2547 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2548 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2549}
2550
Jon Cooper267c0152015-05-06 00:59:38 +01002551static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2552 unsigned *context_size)
2553{
2554 u32 new_rx_rss_context;
2555 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2556 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2557 false, context_size);
2558
2559 if (rc != 0)
2560 return rc;
2561
2562 nic_data->rx_rss_context = new_rx_rss_context;
2563 nic_data->rx_rss_context_exclusive = false;
2564 efx_set_default_rx_indir_table(efx);
2565 return 0;
2566}
2567
2568static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2569 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002570{
2571 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2572 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002573 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002574
Jon Cooper267c0152015-05-06 00:59:38 +01002575 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2576 !nic_data->rx_rss_context_exclusive) {
2577 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2578 true, NULL);
2579 if (rc == -EOPNOTSUPP)
2580 return rc;
2581 else if (rc != 0)
2582 goto fail1;
2583 } else {
2584 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002585 }
2586
Jon Cooper267c0152015-05-06 00:59:38 +01002587 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2588 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002589 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002590 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002591
Jon Cooper267c0152015-05-06 00:59:38 +01002592 if (nic_data->rx_rss_context != new_rx_rss_context)
2593 efx_ef10_rx_free_indir_table(efx);
2594 nic_data->rx_rss_context = new_rx_rss_context;
2595 nic_data->rx_rss_context_exclusive = true;
2596 if (rx_indir_table != efx->rx_indir_table)
2597 memcpy(efx->rx_indir_table, rx_indir_table,
2598 sizeof(efx->rx_indir_table));
2599 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002600
Jon Cooper267c0152015-05-06 00:59:38 +01002601fail2:
2602 if (new_rx_rss_context != nic_data->rx_rss_context)
2603 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2604fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002605 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002606 return rc;
2607}
2608
2609static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2610 const u32 *rx_indir_table)
2611{
2612 int rc;
2613
2614 if (efx->rss_spread == 1)
2615 return 0;
2616
2617 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2618
2619 if (rc == -ENOBUFS && !user) {
2620 unsigned context_size;
2621 bool mismatch = false;
2622 size_t i;
2623
2624 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2625 i++)
2626 mismatch = rx_indir_table[i] !=
2627 ethtool_rxfh_indir_default(i, efx->rss_spread);
2628
2629 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2630 if (rc == 0) {
2631 if (context_size != efx->rss_spread)
2632 netif_warn(efx, probe, efx->net_dev,
2633 "Could not allocate an exclusive RSS"
2634 " context; allocated a shared one of"
2635 " different size."
2636 " Wanted %u, got %u.\n",
2637 efx->rss_spread, context_size);
2638 else if (mismatch)
2639 netif_warn(efx, probe, efx->net_dev,
2640 "Could not allocate an exclusive RSS"
2641 " context; allocated a shared one but"
2642 " could not apply custom"
2643 " indirection.\n");
2644 else
2645 netif_info(efx, probe, efx->net_dev,
2646 "Could not allocate an exclusive RSS"
2647 " context; allocated a shared one.\n");
2648 }
2649 }
2650 return rc;
2651}
2652
2653static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2654 const u32 *rx_indir_table
2655 __attribute__ ((unused)))
2656{
2657 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2658
2659 if (user)
2660 return -EOPNOTSUPP;
2661 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2662 return 0;
2663 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002664}
2665
2666static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2667{
2668 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2669 (rx_queue->ptr_mask + 1) *
2670 sizeof(efx_qword_t),
2671 GFP_KERNEL);
2672}
2673
2674static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2675{
2676 MCDI_DECLARE_BUF(inbuf,
2677 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2678 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002679 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2680 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2681 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002682 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002683 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002684 dma_addr_t dma_addr;
2685 int rc;
2686 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002687 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002688
2689 rx_queue->scatter_n = 0;
2690 rx_queue->scatter_len = 0;
2691
2692 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2693 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2694 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2695 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2696 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002697 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2698 INIT_RXQ_IN_FLAG_PREFIX, 1,
2699 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002700 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002701 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002702
2703 dma_addr = rx_queue->rxd.buf.dma_addr;
2704
2705 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2706 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2707
2708 for (i = 0; i < entries; ++i) {
2709 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2710 dma_addr += EFX_BUF_SIZE;
2711 }
2712
2713 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2714
2715 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002716 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002717 if (rc)
2718 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2719 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002720}
2721
2722static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2723{
2724 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002725 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002726 struct efx_nic *efx = rx_queue->efx;
2727 size_t outlen;
2728 int rc;
2729
2730 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2731 efx_rx_queue_index(rx_queue));
2732
Edward Cree1e0b8122013-05-31 18:36:12 +01002733 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002734 outbuf, sizeof(outbuf), &outlen);
2735
2736 if (rc && rc != -EALREADY)
2737 goto fail;
2738
2739 return;
2740
2741fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002742 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2743 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002744}
2745
2746static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2747{
2748 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2749}
2750
2751/* This creates an entry in the RX descriptor queue */
2752static inline void
2753efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2754{
2755 struct efx_rx_buffer *rx_buf;
2756 efx_qword_t *rxd;
2757
2758 rxd = efx_rx_desc(rx_queue, index);
2759 rx_buf = efx_rx_buffer(rx_queue, index);
2760 EFX_POPULATE_QWORD_2(*rxd,
2761 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2762 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2763}
2764
2765static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2766{
2767 struct efx_nic *efx = rx_queue->efx;
2768 unsigned int write_count;
2769 efx_dword_t reg;
2770
2771 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2772 write_count = rx_queue->added_count & ~7;
2773 if (rx_queue->notified_count == write_count)
2774 return;
2775
2776 do
2777 efx_ef10_build_rx_desc(
2778 rx_queue,
2779 rx_queue->notified_count & rx_queue->ptr_mask);
2780 while (++rx_queue->notified_count != write_count);
2781
2782 wmb();
2783 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2784 write_count & rx_queue->ptr_mask);
2785 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2786 efx_rx_queue_index(rx_queue));
2787}
2788
2789static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2790
2791static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2792{
2793 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2794 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2795 efx_qword_t event;
2796
2797 EFX_POPULATE_QWORD_2(event,
2798 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2799 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2800
2801 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2802
2803 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2804 * already swapped the data to little-endian order.
2805 */
2806 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2807 sizeof(efx_qword_t));
2808
2809 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2810 inbuf, sizeof(inbuf), 0,
2811 efx_ef10_rx_defer_refill_complete, 0);
2812}
2813
2814static void
2815efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2816 int rc, efx_dword_t *outbuf,
2817 size_t outlen_actual)
2818{
2819 /* nothing to do */
2820}
2821
2822static int efx_ef10_ev_probe(struct efx_channel *channel)
2823{
2824 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2825 (channel->eventq_mask + 1) *
2826 sizeof(efx_qword_t),
2827 GFP_KERNEL);
2828}
2829
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002830static void efx_ef10_ev_fini(struct efx_channel *channel)
2831{
2832 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2833 MCDI_DECLARE_BUF_ERR(outbuf);
2834 struct efx_nic *efx = channel->efx;
2835 size_t outlen;
2836 int rc;
2837
2838 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2839
2840 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2841 outbuf, sizeof(outbuf), &outlen);
2842
2843 if (rc && rc != -EALREADY)
2844 goto fail;
2845
2846 return;
2847
2848fail:
2849 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2850 outbuf, outlen, rc);
2851}
2852
Ben Hutchings8127d662013-08-29 19:19:29 +01002853static int efx_ef10_ev_init(struct efx_channel *channel)
2854{
2855 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002856 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2857 EFX_BUF_SIZE));
2858 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002859 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2860 struct efx_nic *efx = channel->efx;
2861 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002862 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002863 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002864 dma_addr_t dma_addr;
2865 int rc;
2866 int i;
2867
2868 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002869
2870 /* Fill event queue with all ones (i.e. empty events) */
2871 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2872
2873 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2874 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2875 /* INIT_EVQ expects index in vector table, not absolute */
2876 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002877 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2878 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2879 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2880 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2881 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2882 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2883 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2884
Bert Kenwarda9955602016-08-11 13:01:54 +01002885 if (nic_data->datapath_caps2 &
2886 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2887 /* Use the new generic approach to specifying event queue
2888 * configuration, requesting lower latency or higher throughput.
2889 * The options that actually get used appear in the output.
2890 */
2891 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2892 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2893 INIT_EVQ_V2_IN_FLAG_TYPE,
2894 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2895 } else {
2896 bool cut_thru = !(nic_data->datapath_caps &
2897 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2898
2899 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2900 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2901 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2902 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2903 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2904 }
2905
Ben Hutchings8127d662013-08-29 19:19:29 +01002906 dma_addr = channel->eventq.buf.dma_addr;
2907 for (i = 0; i < entries; ++i) {
2908 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2909 dma_addr += EFX_BUF_SIZE;
2910 }
2911
2912 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2913
2914 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2915 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01002916
2917 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2918 netif_dbg(efx, drv, efx->net_dev,
2919 "Channel %d using event queue flags %08x\n",
2920 channel->channel,
2921 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2922
Ben Hutchings8127d662013-08-29 19:19:29 +01002923 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002924 if (channel->channel || rc)
2925 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002926
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002927 /* Successfully created event queue on channel 0 */
2928 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002929 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01002930 /* GET_WORKAROUNDS was implemented before this workaround,
2931 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01002932 */
2933 nic_data->workaround_26807 = false;
2934 rc = 0;
2935 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002936 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002937 } else {
2938 nic_data->workaround_26807 =
2939 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002940
Edward Cree832dc9e2015-07-21 15:09:31 +01002941 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2942 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002943 unsigned int flags;
2944
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002945 rc = efx_mcdi_set_workaround(efx,
2946 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002947 true, &flags);
2948
2949 if (!rc) {
2950 if (flags &
2951 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2952 netif_info(efx, drv, efx->net_dev,
2953 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002954
2955 /* With MCFW v4.6.x and earlier, the
2956 * boot count will have incremented,
2957 * so re-read the warm_boot_count
2958 * value now to ensure this function
2959 * doesn't think it has changed next
2960 * time it checks.
2961 */
2962 rc = efx_ef10_get_warm_boot_count(efx);
2963 if (rc >= 0) {
2964 nic_data->warm_boot_count = rc;
2965 rc = 0;
2966 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002967 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002968 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002969 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002970 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002971 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002972 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002973 }
2974
2975 if (!rc)
2976 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002977
2978fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002979 efx_ef10_ev_fini(channel);
2980 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002981}
2982
2983static void efx_ef10_ev_remove(struct efx_channel *channel)
2984{
2985 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2986}
2987
2988static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2989 unsigned int rx_queue_label)
2990{
2991 struct efx_nic *efx = rx_queue->efx;
2992
2993 netif_info(efx, hw, efx->net_dev,
2994 "rx event arrived on queue %d labeled as queue %u\n",
2995 efx_rx_queue_index(rx_queue), rx_queue_label);
2996
2997 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2998}
2999
3000static void
3001efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3002 unsigned int actual, unsigned int expected)
3003{
3004 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3005 struct efx_nic *efx = rx_queue->efx;
3006
3007 netif_info(efx, hw, efx->net_dev,
3008 "dropped %d events (index=%d expected=%d)\n",
3009 dropped, actual, expected);
3010
3011 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3012}
3013
3014/* partially received RX was aborted. clean up. */
3015static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3016{
3017 unsigned int rx_desc_ptr;
3018
Ben Hutchings8127d662013-08-29 19:19:29 +01003019 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3020 "scattered RX aborted (dropping %u buffers)\n",
3021 rx_queue->scatter_n);
3022
3023 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3024
3025 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3026 0, EFX_RX_PKT_DISCARD);
3027
3028 rx_queue->removed_count += rx_queue->scatter_n;
3029 rx_queue->scatter_n = 0;
3030 rx_queue->scatter_len = 0;
3031 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3032}
3033
3034static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3035 const efx_qword_t *event)
3036{
3037 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
3038 unsigned int n_descs, n_packets, i;
3039 struct efx_nic *efx = channel->efx;
3040 struct efx_rx_queue *rx_queue;
3041 bool rx_cont;
3042 u16 flags = 0;
3043
3044 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3045 return 0;
3046
3047 /* Basic packet information */
3048 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3049 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3050 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3051 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3052 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3053
Ben Hutchings48ce5632013-11-01 16:42:44 +00003054 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3055 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3056 EFX_QWORD_FMT "\n",
3057 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003058
3059 rx_queue = efx_channel_get_rx_queue(channel);
3060
3061 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3062 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3063
3064 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3065 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3066
3067 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003068 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3069
Ben Hutchings8127d662013-08-29 19:19:29 +01003070 /* detect rx abort */
3071 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003072 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3073 netdev_WARN(efx->net_dev,
3074 "invalid RX abort: scatter_n=%u event="
3075 EFX_QWORD_FMT "\n",
3076 rx_queue->scatter_n,
3077 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003078 efx_ef10_handle_rx_abort(rx_queue);
3079 return 0;
3080 }
3081
Ben Hutchings92a04162013-09-24 23:21:57 +01003082 /* Check that RX completion merging is valid, i.e.
3083 * the current firmware supports it and this is a
3084 * non-scattered packet.
3085 */
3086 if (!(nic_data->datapath_caps &
3087 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3088 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003089 efx_ef10_handle_rx_bad_lbits(
3090 rx_queue, next_ptr_lbits,
3091 (rx_queue->removed_count +
3092 rx_queue->scatter_n + 1) &
3093 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3094 return 0;
3095 }
3096
3097 /* Merged completion for multiple non-scattered packets */
3098 rx_queue->scatter_n = 1;
3099 rx_queue->scatter_len = 0;
3100 n_packets = n_descs;
3101 ++channel->n_rx_merge_events;
3102 channel->n_rx_merge_packets += n_packets;
3103 flags |= EFX_RX_PKT_PREFIX_LEN;
3104 } else {
3105 ++rx_queue->scatter_n;
3106 rx_queue->scatter_len += rx_bytes;
3107 if (rx_cont)
3108 return 0;
3109 n_packets = 1;
3110 }
3111
3112 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
3113 flags |= EFX_RX_PKT_DISCARD;
3114
3115 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
3116 channel->n_rx_ip_hdr_chksum_err += n_packets;
3117 } else if (unlikely(EFX_QWORD_FIELD(*event,
3118 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
3119 channel->n_rx_tcp_udp_chksum_err += n_packets;
3120 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3121 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
3122 flags |= EFX_RX_PKT_CSUMMED;
3123 }
3124
3125 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3126 flags |= EFX_RX_PKT_TCP;
3127
3128 channel->irq_mod_score += 2 * n_packets;
3129
3130 /* Handle received packet(s) */
3131 for (i = 0; i < n_packets; i++) {
3132 efx_rx_packet(rx_queue,
3133 rx_queue->removed_count & rx_queue->ptr_mask,
3134 rx_queue->scatter_n, rx_queue->scatter_len,
3135 flags);
3136 rx_queue->removed_count += rx_queue->scatter_n;
3137 }
3138
3139 rx_queue->scatter_n = 0;
3140 rx_queue->scatter_len = 0;
3141
3142 return n_packets;
3143}
3144
3145static int
3146efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3147{
3148 struct efx_nic *efx = channel->efx;
3149 struct efx_tx_queue *tx_queue;
3150 unsigned int tx_ev_desc_ptr;
3151 unsigned int tx_ev_q_label;
3152 int tx_descs = 0;
3153
3154 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3155 return 0;
3156
3157 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3158 return 0;
3159
3160 /* Transmit completion */
3161 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3162 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3163 tx_queue = efx_channel_get_tx_queue(channel,
3164 tx_ev_q_label % EFX_TXQ_TYPES);
3165 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3166 tx_queue->ptr_mask);
3167 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3168
3169 return tx_descs;
3170}
3171
3172static void
3173efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3174{
3175 struct efx_nic *efx = channel->efx;
3176 int subcode;
3177
3178 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3179
3180 switch (subcode) {
3181 case ESE_DZ_DRV_TIMER_EV:
3182 case ESE_DZ_DRV_WAKE_UP_EV:
3183 break;
3184 case ESE_DZ_DRV_START_UP_EV:
3185 /* event queue init complete. ok. */
3186 break;
3187 default:
3188 netif_err(efx, hw, efx->net_dev,
3189 "channel %d unknown driver event type %d"
3190 " (data " EFX_QWORD_FMT ")\n",
3191 channel->channel, subcode,
3192 EFX_QWORD_VAL(*event));
3193
3194 }
3195}
3196
3197static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3198 efx_qword_t *event)
3199{
3200 struct efx_nic *efx = channel->efx;
3201 u32 subcode;
3202
3203 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3204
3205 switch (subcode) {
3206 case EFX_EF10_TEST:
3207 channel->event_test_cpu = raw_smp_processor_id();
3208 break;
3209 case EFX_EF10_REFILL:
3210 /* The queue must be empty, so we won't receive any rx
3211 * events, so efx_process_channel() won't refill the
3212 * queue. Refill it here
3213 */
Jon Coopercce28792013-10-02 11:04:14 +01003214 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003215 break;
3216 default:
3217 netif_err(efx, hw, efx->net_dev,
3218 "channel %d unknown driver event type %u"
3219 " (data " EFX_QWORD_FMT ")\n",
3220 channel->channel, (unsigned) subcode,
3221 EFX_QWORD_VAL(*event));
3222 }
3223}
3224
3225static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3226{
3227 struct efx_nic *efx = channel->efx;
3228 efx_qword_t event, *p_event;
3229 unsigned int read_ptr;
3230 int ev_code;
3231 int tx_descs = 0;
3232 int spent = 0;
3233
Eric W. Biederman75363a42014-03-14 18:11:22 -07003234 if (quota <= 0)
3235 return spent;
3236
Ben Hutchings8127d662013-08-29 19:19:29 +01003237 read_ptr = channel->eventq_read_ptr;
3238
3239 for (;;) {
3240 p_event = efx_event(channel, read_ptr);
3241 event = *p_event;
3242
3243 if (!efx_event_present(&event))
3244 break;
3245
3246 EFX_SET_QWORD(*p_event);
3247
3248 ++read_ptr;
3249
3250 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3251
3252 netif_vdbg(efx, drv, efx->net_dev,
3253 "processing event on %d " EFX_QWORD_FMT "\n",
3254 channel->channel, EFX_QWORD_VAL(event));
3255
3256 switch (ev_code) {
3257 case ESE_DZ_EV_CODE_MCDI_EV:
3258 efx_mcdi_process_event(channel, &event);
3259 break;
3260 case ESE_DZ_EV_CODE_RX_EV:
3261 spent += efx_ef10_handle_rx_event(channel, &event);
3262 if (spent >= quota) {
3263 /* XXX can we split a merged event to
3264 * avoid going over-quota?
3265 */
3266 spent = quota;
3267 goto out;
3268 }
3269 break;
3270 case ESE_DZ_EV_CODE_TX_EV:
3271 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3272 if (tx_descs > efx->txq_entries) {
3273 spent = quota;
3274 goto out;
3275 } else if (++spent == quota) {
3276 goto out;
3277 }
3278 break;
3279 case ESE_DZ_EV_CODE_DRIVER_EV:
3280 efx_ef10_handle_driver_event(channel, &event);
3281 if (++spent == quota)
3282 goto out;
3283 break;
3284 case EFX_EF10_DRVGEN_EV:
3285 efx_ef10_handle_driver_generated_event(channel, &event);
3286 break;
3287 default:
3288 netif_err(efx, hw, efx->net_dev,
3289 "channel %d unknown event type %d"
3290 " (data " EFX_QWORD_FMT ")\n",
3291 channel->channel, ev_code,
3292 EFX_QWORD_VAL(event));
3293 }
3294 }
3295
3296out:
3297 channel->eventq_read_ptr = read_ptr;
3298 return spent;
3299}
3300
3301static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3302{
3303 struct efx_nic *efx = channel->efx;
3304 efx_dword_t rptr;
3305
3306 if (EFX_EF10_WORKAROUND_35388(efx)) {
3307 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3308 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3309 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3310 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3311
3312 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3313 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3314 ERF_DD_EVQ_IND_RPTR,
3315 (channel->eventq_read_ptr &
3316 channel->eventq_mask) >>
3317 ERF_DD_EVQ_IND_RPTR_WIDTH);
3318 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3319 channel->channel);
3320 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3321 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3322 ERF_DD_EVQ_IND_RPTR,
3323 channel->eventq_read_ptr &
3324 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3325 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3326 channel->channel);
3327 } else {
3328 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3329 channel->eventq_read_ptr &
3330 channel->eventq_mask);
3331 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3332 }
3333}
3334
3335static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3336{
3337 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3338 struct efx_nic *efx = channel->efx;
3339 efx_qword_t event;
3340 int rc;
3341
3342 EFX_POPULATE_QWORD_2(event,
3343 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3344 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3345
3346 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3347
3348 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3349 * already swapped the data to little-endian order.
3350 */
3351 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3352 sizeof(efx_qword_t));
3353
3354 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3355 NULL, 0, NULL);
3356 if (rc != 0)
3357 goto fail;
3358
3359 return;
3360
3361fail:
3362 WARN_ON(true);
3363 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3364}
3365
3366void efx_ef10_handle_drain_event(struct efx_nic *efx)
3367{
3368 if (atomic_dec_and_test(&efx->active_queues))
3369 wake_up(&efx->flush_wq);
3370
3371 WARN_ON(atomic_read(&efx->active_queues) < 0);
3372}
3373
3374static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3375{
3376 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3377 struct efx_channel *channel;
3378 struct efx_tx_queue *tx_queue;
3379 struct efx_rx_queue *rx_queue;
3380 int pending;
3381
3382 /* If the MC has just rebooted, the TX/RX queues will have already been
3383 * torn down, but efx->active_queues needs to be set to zero.
3384 */
3385 if (nic_data->must_realloc_vis) {
3386 atomic_set(&efx->active_queues, 0);
3387 return 0;
3388 }
3389
3390 /* Do not attempt to write to the NIC during EEH recovery */
3391 if (efx->state != STATE_RECOVERY) {
3392 efx_for_each_channel(channel, efx) {
3393 efx_for_each_channel_rx_queue(rx_queue, channel)
3394 efx_ef10_rx_fini(rx_queue);
3395 efx_for_each_channel_tx_queue(tx_queue, channel)
3396 efx_ef10_tx_fini(tx_queue);
3397 }
3398
3399 wait_event_timeout(efx->flush_wq,
3400 atomic_read(&efx->active_queues) == 0,
3401 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3402 pending = atomic_read(&efx->active_queues);
3403 if (pending) {
3404 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3405 pending);
3406 return -ETIMEDOUT;
3407 }
3408 }
3409
3410 return 0;
3411}
3412
Edward Creee2835462014-04-16 19:27:48 +01003413static void efx_ef10_prepare_flr(struct efx_nic *efx)
3414{
3415 atomic_set(&efx->active_queues, 0);
3416}
3417
Ben Hutchings8127d662013-08-29 19:19:29 +01003418static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3419 const struct efx_filter_spec *right)
3420{
3421 if ((left->match_flags ^ right->match_flags) |
3422 ((left->flags ^ right->flags) &
3423 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3424 return false;
3425
3426 return memcmp(&left->outer_vid, &right->outer_vid,
3427 sizeof(struct efx_filter_spec) -
3428 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3429}
3430
3431static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3432{
3433 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3434 return jhash2((const u32 *)&spec->outer_vid,
3435 (sizeof(struct efx_filter_spec) -
3436 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3437 0);
3438 /* XXX should we randomise the initval? */
3439}
3440
3441/* Decide whether a filter should be exclusive or else should allow
3442 * delivery to additional recipients. Currently we decide that
3443 * filters for specific local unicast MAC and IP addresses are
3444 * exclusive.
3445 */
3446static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3447{
3448 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3449 !is_multicast_ether_addr(spec->loc_mac))
3450 return true;
3451
3452 if ((spec->match_flags &
3453 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3454 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3455 if (spec->ether_type == htons(ETH_P_IP) &&
3456 !ipv4_is_multicast(spec->loc_host[0]))
3457 return true;
3458 if (spec->ether_type == htons(ETH_P_IPV6) &&
3459 ((const u8 *)spec->loc_host)[0] != 0xff)
3460 return true;
3461 }
3462
3463 return false;
3464}
3465
3466static struct efx_filter_spec *
3467efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3468 unsigned int filter_idx)
3469{
3470 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3471 ~EFX_EF10_FILTER_FLAGS);
3472}
3473
3474static unsigned int
3475efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3476 unsigned int filter_idx)
3477{
3478 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3479}
3480
3481static void
3482efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3483 unsigned int filter_idx,
3484 const struct efx_filter_spec *spec,
3485 unsigned int flags)
3486{
3487 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3488}
3489
3490static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3491 const struct efx_filter_spec *spec,
3492 efx_dword_t *inbuf, u64 handle,
3493 bool replacing)
3494{
3495 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003496 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003497
3498 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3499
Jon Cooperdcb41232016-04-25 16:51:00 +01003500 /* Remove RSS flag if we don't have an RSS context. */
3501 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3502 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3503 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3504 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3505
Ben Hutchings8127d662013-08-29 19:19:29 +01003506 if (replacing) {
3507 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3508 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3509 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3510 } else {
3511 u32 match_fields = 0;
3512
3513 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3514 efx_ef10_filter_is_exclusive(spec) ?
3515 MC_CMD_FILTER_OP_IN_OP_INSERT :
3516 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3517
3518 /* Convert match flags and values. Unlike almost
3519 * everything else in MCDI, these fields are in
3520 * network byte order.
3521 */
3522 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3523 match_fields |=
3524 is_multicast_ether_addr(spec->loc_mac) ?
3525 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3526 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3527#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3528 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3529 match_fields |= \
3530 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3531 mcdi_field ## _LBN; \
3532 BUILD_BUG_ON( \
3533 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3534 sizeof(spec->gen_field)); \
3535 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3536 &spec->gen_field, sizeof(spec->gen_field)); \
3537 }
3538 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3539 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3540 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3541 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3542 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3543 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3544 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3545 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3546 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3547 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3548#undef COPY_FIELD
3549 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3550 match_fields);
3551 }
3552
Daniel Pieczko45b24492015-05-06 00:57:14 +01003553 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003554 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3555 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3556 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3557 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003558 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003559 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3560 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003561 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3562 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3563 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003564 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003565 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003566 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3567 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003568 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003569 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3570 spec->rss_context !=
3571 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3572 spec->rss_context : nic_data->rx_rss_context);
3573}
3574
3575static int efx_ef10_filter_push(struct efx_nic *efx,
3576 const struct efx_filter_spec *spec,
3577 u64 *handle, bool replacing)
3578{
3579 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3580 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3581 int rc;
3582
3583 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3584 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3585 outbuf, sizeof(outbuf), NULL);
3586 if (rc == 0)
3587 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003588 if (rc == -ENOSPC)
3589 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003590 return rc;
3591}
3592
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003593static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003594{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003595 unsigned int match_flags = spec->match_flags;
3596 u32 mcdi_flags = 0;
3597
3598 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3599 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3600 mcdi_flags |=
3601 is_multicast_ether_addr(spec->loc_mac) ?
3602 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3603 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3604 }
3605
3606#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3607 unsigned int old_match_flags = match_flags; \
3608 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3609 if (match_flags != old_match_flags) \
3610 mcdi_flags |= \
3611 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3612 mcdi_field ## _LBN); \
3613 }
3614 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3615 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3616 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3617 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3618 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3619 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3620 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3621 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3622 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3623 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3624#undef MAP_FILTER_TO_MCDI_FLAG
3625
3626 /* Did we map them all? */
3627 WARN_ON_ONCE(match_flags);
3628
3629 return mcdi_flags;
3630}
3631
3632static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3633 const struct efx_filter_spec *spec)
3634{
3635 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003636 unsigned int match_pri;
3637
3638 for (match_pri = 0;
3639 match_pri < table->rx_match_count;
3640 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003641 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003642 return match_pri;
3643
3644 return -EPROTONOSUPPORT;
3645}
3646
3647static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3648 struct efx_filter_spec *spec,
3649 bool replace_equal)
3650{
3651 struct efx_ef10_filter_table *table = efx->filter_state;
3652 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3653 struct efx_filter_spec *saved_spec;
3654 unsigned int match_pri, hash;
3655 unsigned int priv_flags;
3656 bool replacing = false;
3657 int ins_index = -1;
3658 DEFINE_WAIT(wait);
3659 bool is_mc_recip;
3660 s32 rc;
3661
3662 /* For now, only support RX filters */
3663 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3664 EFX_FILTER_FLAG_RX)
3665 return -EINVAL;
3666
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003667 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003668 if (rc < 0)
3669 return rc;
3670 match_pri = rc;
3671
3672 hash = efx_ef10_filter_hash(spec);
3673 is_mc_recip = efx_filter_is_mc_recipient(spec);
3674 if (is_mc_recip)
3675 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3676
3677 /* Find any existing filters with the same match tuple or
3678 * else a free slot to insert at. If any of them are busy,
3679 * we have to wait and retry.
3680 */
3681 for (;;) {
3682 unsigned int depth = 1;
3683 unsigned int i;
3684
3685 spin_lock_bh(&efx->filter_lock);
3686
3687 for (;;) {
3688 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3689 saved_spec = efx_ef10_filter_entry_spec(table, i);
3690
3691 if (!saved_spec) {
3692 if (ins_index < 0)
3693 ins_index = i;
3694 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3695 if (table->entry[i].spec &
3696 EFX_EF10_FILTER_FLAG_BUSY)
3697 break;
3698 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003699 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003700 rc = -EPERM;
3701 goto out_unlock;
3702 }
3703 if (!is_mc_recip) {
3704 /* This is the only one */
3705 if (spec->priority ==
3706 saved_spec->priority &&
3707 !replace_equal) {
3708 rc = -EEXIST;
3709 goto out_unlock;
3710 }
3711 ins_index = i;
3712 goto found;
3713 } else if (spec->priority >
3714 saved_spec->priority ||
3715 (spec->priority ==
3716 saved_spec->priority &&
3717 replace_equal)) {
3718 if (ins_index < 0)
3719 ins_index = i;
3720 else
3721 __set_bit(depth, mc_rem_map);
3722 }
3723 }
3724
3725 /* Once we reach the maximum search depth, use
3726 * the first suitable slot or return -EBUSY if
3727 * there was none
3728 */
3729 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3730 if (ins_index < 0) {
3731 rc = -EBUSY;
3732 goto out_unlock;
3733 }
3734 goto found;
3735 }
3736
3737 ++depth;
3738 }
3739
3740 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3741 spin_unlock_bh(&efx->filter_lock);
3742 schedule();
3743 }
3744
3745found:
3746 /* Create a software table entry if necessary, and mark it
3747 * busy. We might yet fail to insert, but any attempt to
3748 * insert a conflicting filter while we're waiting for the
3749 * firmware must find the busy entry.
3750 */
3751 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3752 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003753 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3754 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003755 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003756 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3757 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003758 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003759 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003760 rc = ins_index;
3761 goto out_unlock;
3762 }
3763 replacing = true;
3764 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3765 } else {
3766 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3767 if (!saved_spec) {
3768 rc = -ENOMEM;
3769 goto out_unlock;
3770 }
3771 *saved_spec = *spec;
3772 priv_flags = 0;
3773 }
3774 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3775 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3776
3777 /* Mark lower-priority multicast recipients busy prior to removal */
3778 if (is_mc_recip) {
3779 unsigned int depth, i;
3780
3781 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3782 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3783 if (test_bit(depth, mc_rem_map))
3784 table->entry[i].spec |=
3785 EFX_EF10_FILTER_FLAG_BUSY;
3786 }
3787 }
3788
3789 spin_unlock_bh(&efx->filter_lock);
3790
3791 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3792 replacing);
3793
3794 /* Finalise the software table entry */
3795 spin_lock_bh(&efx->filter_lock);
3796 if (rc == 0) {
3797 if (replacing) {
3798 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003799 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3800 saved_spec->flags |=
3801 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003802 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003803 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003804 saved_spec->flags |= spec->flags;
3805 saved_spec->rss_context = spec->rss_context;
3806 saved_spec->dmaq_id = spec->dmaq_id;
3807 }
3808 } else if (!replacing) {
3809 kfree(saved_spec);
3810 saved_spec = NULL;
3811 }
3812 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3813
3814 /* Remove and finalise entries for lower-priority multicast
3815 * recipients
3816 */
3817 if (is_mc_recip) {
3818 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3819 unsigned int depth, i;
3820
3821 memset(inbuf, 0, sizeof(inbuf));
3822
3823 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3824 if (!test_bit(depth, mc_rem_map))
3825 continue;
3826
3827 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3828 saved_spec = efx_ef10_filter_entry_spec(table, i);
3829 priv_flags = efx_ef10_filter_entry_flags(table, i);
3830
3831 if (rc == 0) {
3832 spin_unlock_bh(&efx->filter_lock);
3833 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3834 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3835 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3836 table->entry[i].handle);
3837 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3838 inbuf, sizeof(inbuf),
3839 NULL, 0, NULL);
3840 spin_lock_bh(&efx->filter_lock);
3841 }
3842
3843 if (rc == 0) {
3844 kfree(saved_spec);
3845 saved_spec = NULL;
3846 priv_flags = 0;
3847 } else {
3848 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3849 }
3850 efx_ef10_filter_set_entry(table, i, saved_spec,
3851 priv_flags);
3852 }
3853 }
3854
3855 /* If successful, return the inserted filter ID */
3856 if (rc == 0)
3857 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3858
3859 wake_up_all(&table->waitq);
3860out_unlock:
3861 spin_unlock_bh(&efx->filter_lock);
3862 finish_wait(&table->waitq, &wait);
3863 return rc;
3864}
3865
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003866static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003867{
3868 /* no need to do anything here on EF10 */
3869}
3870
3871/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003872 * If !by_index, remove by ID
3873 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003874 * Filter ID may come from userland and must be range-checked.
3875 */
3876static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003877 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003878 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003879{
3880 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3881 struct efx_ef10_filter_table *table = efx->filter_state;
3882 MCDI_DECLARE_BUF(inbuf,
3883 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3884 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3885 struct efx_filter_spec *spec;
3886 DEFINE_WAIT(wait);
3887 int rc;
3888
3889 /* Find the software table entry and mark it busy. Don't
3890 * remove it yet; any attempt to update while we're waiting
3891 * for the firmware must find the busy entry.
3892 */
3893 for (;;) {
3894 spin_lock_bh(&efx->filter_lock);
3895 if (!(table->entry[filter_idx].spec &
3896 EFX_EF10_FILTER_FLAG_BUSY))
3897 break;
3898 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3899 spin_unlock_bh(&efx->filter_lock);
3900 schedule();
3901 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003902
Ben Hutchings8127d662013-08-29 19:19:29 +01003903 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003904 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003905 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003906 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003907 filter_id / HUNT_FILTER_TBL_ROWS)) {
3908 rc = -ENOENT;
3909 goto out_unlock;
3910 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003911
3912 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003913 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003914 /* Just remove flags */
3915 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003916 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003917 rc = 0;
3918 goto out_unlock;
3919 }
3920
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003921 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003922 rc = -ENOENT;
3923 goto out_unlock;
3924 }
3925
Ben Hutchings8127d662013-08-29 19:19:29 +01003926 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3927 spin_unlock_bh(&efx->filter_lock);
3928
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003929 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003930 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003931
3932 struct efx_filter_spec new_spec = *spec;
3933
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003934 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003935 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003936 (efx_rss_enabled(efx) ?
3937 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003938 new_spec.dmaq_id = 0;
3939 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3940 rc = efx_ef10_filter_push(efx, &new_spec,
3941 &table->entry[filter_idx].handle,
3942 true);
3943
3944 spin_lock_bh(&efx->filter_lock);
3945 if (rc == 0)
3946 *spec = new_spec;
3947 } else {
3948 /* Really remove the filter */
3949
3950 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3951 efx_ef10_filter_is_exclusive(spec) ?
3952 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3953 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3954 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3955 table->entry[filter_idx].handle);
3956 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3957 inbuf, sizeof(inbuf), NULL, 0, NULL);
3958
3959 spin_lock_bh(&efx->filter_lock);
3960 if (rc == 0) {
3961 kfree(spec);
3962 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3963 }
3964 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003965
Ben Hutchings8127d662013-08-29 19:19:29 +01003966 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3967 wake_up_all(&table->waitq);
3968out_unlock:
3969 spin_unlock_bh(&efx->filter_lock);
3970 finish_wait(&table->waitq, &wait);
3971 return rc;
3972}
3973
3974static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3975 enum efx_filter_priority priority,
3976 u32 filter_id)
3977{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003978 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3979 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003980}
3981
Edward Cree12fb0da2015-07-21 15:11:00 +01003982static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
3983{
3984 return filter_id % HUNT_FILTER_TBL_ROWS;
3985}
3986
Edward Cree8c915622016-06-15 17:49:05 +01003987static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
3988 enum efx_filter_priority priority,
3989 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01003990{
Edward Cree8c915622016-06-15 17:49:05 +01003991 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
3992 return;
3993 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01003994}
3995
Ben Hutchings8127d662013-08-29 19:19:29 +01003996static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3997 enum efx_filter_priority priority,
3998 u32 filter_id, struct efx_filter_spec *spec)
3999{
4000 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4001 struct efx_ef10_filter_table *table = efx->filter_state;
4002 const struct efx_filter_spec *saved_spec;
4003 int rc;
4004
4005 spin_lock_bh(&efx->filter_lock);
4006 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4007 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004008 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004009 filter_id / HUNT_FILTER_TBL_ROWS) {
4010 *spec = *saved_spec;
4011 rc = 0;
4012 } else {
4013 rc = -ENOENT;
4014 }
4015 spin_unlock_bh(&efx->filter_lock);
4016 return rc;
4017}
4018
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004019static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004020 enum efx_filter_priority priority)
4021{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004022 unsigned int priority_mask;
4023 unsigned int i;
4024 int rc;
4025
4026 priority_mask = (((1U << (priority + 1)) - 1) &
4027 ~(1U << EFX_FILTER_PRI_AUTO));
4028
4029 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4030 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4031 i, true);
4032 if (rc && rc != -ENOENT)
4033 return rc;
4034 }
4035
4036 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004037}
4038
4039static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4040 enum efx_filter_priority priority)
4041{
4042 struct efx_ef10_filter_table *table = efx->filter_state;
4043 unsigned int filter_idx;
4044 s32 count = 0;
4045
4046 spin_lock_bh(&efx->filter_lock);
4047 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4048 if (table->entry[filter_idx].spec &&
4049 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4050 priority)
4051 ++count;
4052 }
4053 spin_unlock_bh(&efx->filter_lock);
4054 return count;
4055}
4056
4057static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4058{
4059 struct efx_ef10_filter_table *table = efx->filter_state;
4060
4061 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4062}
4063
4064static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4065 enum efx_filter_priority priority,
4066 u32 *buf, u32 size)
4067{
4068 struct efx_ef10_filter_table *table = efx->filter_state;
4069 struct efx_filter_spec *spec;
4070 unsigned int filter_idx;
4071 s32 count = 0;
4072
4073 spin_lock_bh(&efx->filter_lock);
4074 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4075 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4076 if (spec && spec->priority == priority) {
4077 if (count == size) {
4078 count = -EMSGSIZE;
4079 break;
4080 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004081 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004082 HUNT_FILTER_TBL_ROWS +
4083 filter_idx);
4084 }
4085 }
4086 spin_unlock_bh(&efx->filter_lock);
4087 return count;
4088}
4089
4090#ifdef CONFIG_RFS_ACCEL
4091
4092static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4093
4094static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4095 struct efx_filter_spec *spec)
4096{
4097 struct efx_ef10_filter_table *table = efx->filter_state;
4098 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4099 struct efx_filter_spec *saved_spec;
4100 unsigned int hash, i, depth = 1;
4101 bool replacing = false;
4102 int ins_index = -1;
4103 u64 cookie;
4104 s32 rc;
4105
4106 /* Must be an RX filter without RSS and not for a multicast
4107 * destination address (RFS only works for connected sockets).
4108 * These restrictions allow us to pass only a tiny amount of
4109 * data through to the completion function.
4110 */
4111 EFX_WARN_ON_PARANOID(spec->flags !=
4112 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4113 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4114 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4115
4116 hash = efx_ef10_filter_hash(spec);
4117
4118 spin_lock_bh(&efx->filter_lock);
4119
4120 /* Find any existing filter with the same match tuple or else
4121 * a free slot to insert at. If an existing filter is busy,
4122 * we have to give up.
4123 */
4124 for (;;) {
4125 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4126 saved_spec = efx_ef10_filter_entry_spec(table, i);
4127
4128 if (!saved_spec) {
4129 if (ins_index < 0)
4130 ins_index = i;
4131 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4132 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4133 rc = -EBUSY;
4134 goto fail_unlock;
4135 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004136 if (spec->priority < saved_spec->priority) {
4137 rc = -EPERM;
4138 goto fail_unlock;
4139 }
4140 ins_index = i;
4141 break;
4142 }
4143
4144 /* Once we reach the maximum search depth, use the
4145 * first suitable slot or return -EBUSY if there was
4146 * none
4147 */
4148 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4149 if (ins_index < 0) {
4150 rc = -EBUSY;
4151 goto fail_unlock;
4152 }
4153 break;
4154 }
4155
4156 ++depth;
4157 }
4158
4159 /* Create a software table entry if necessary, and mark it
4160 * busy. We might yet fail to insert, but any attempt to
4161 * insert a conflicting filter while we're waiting for the
4162 * firmware must find the busy entry.
4163 */
4164 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4165 if (saved_spec) {
4166 replacing = true;
4167 } else {
4168 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4169 if (!saved_spec) {
4170 rc = -ENOMEM;
4171 goto fail_unlock;
4172 }
4173 *saved_spec = *spec;
4174 }
4175 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4176 EFX_EF10_FILTER_FLAG_BUSY);
4177
4178 spin_unlock_bh(&efx->filter_lock);
4179
4180 /* Pack up the variables needed on completion */
4181 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4182
4183 efx_ef10_filter_push_prep(efx, spec, inbuf,
4184 table->entry[ins_index].handle, replacing);
4185 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4186 MC_CMD_FILTER_OP_OUT_LEN,
4187 efx_ef10_filter_rfs_insert_complete, cookie);
4188
4189 return ins_index;
4190
4191fail_unlock:
4192 spin_unlock_bh(&efx->filter_lock);
4193 return rc;
4194}
4195
4196static void
4197efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4198 int rc, efx_dword_t *outbuf,
4199 size_t outlen_actual)
4200{
4201 struct efx_ef10_filter_table *table = efx->filter_state;
4202 unsigned int ins_index, dmaq_id;
4203 struct efx_filter_spec *spec;
4204 bool replacing;
4205
4206 /* Unpack the cookie */
4207 replacing = cookie >> 31;
4208 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4209 dmaq_id = cookie & 0xffff;
4210
4211 spin_lock_bh(&efx->filter_lock);
4212 spec = efx_ef10_filter_entry_spec(table, ins_index);
4213 if (rc == 0) {
4214 table->entry[ins_index].handle =
4215 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4216 if (replacing)
4217 spec->dmaq_id = dmaq_id;
4218 } else if (!replacing) {
4219 kfree(spec);
4220 spec = NULL;
4221 }
4222 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4223 spin_unlock_bh(&efx->filter_lock);
4224
4225 wake_up_all(&table->waitq);
4226}
4227
4228static void
4229efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4230 unsigned long filter_idx,
4231 int rc, efx_dword_t *outbuf,
4232 size_t outlen_actual);
4233
4234static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4235 unsigned int filter_idx)
4236{
4237 struct efx_ef10_filter_table *table = efx->filter_state;
4238 struct efx_filter_spec *spec =
4239 efx_ef10_filter_entry_spec(table, filter_idx);
4240 MCDI_DECLARE_BUF(inbuf,
4241 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4242 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4243
4244 if (!spec ||
4245 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4246 spec->priority != EFX_FILTER_PRI_HINT ||
4247 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4248 flow_id, filter_idx))
4249 return false;
4250
4251 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4252 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4253 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4254 table->entry[filter_idx].handle);
4255 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4256 efx_ef10_filter_rfs_expire_complete, filter_idx))
4257 return false;
4258
4259 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4260 return true;
4261}
4262
4263static void
4264efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4265 unsigned long filter_idx,
4266 int rc, efx_dword_t *outbuf,
4267 size_t outlen_actual)
4268{
4269 struct efx_ef10_filter_table *table = efx->filter_state;
4270 struct efx_filter_spec *spec =
4271 efx_ef10_filter_entry_spec(table, filter_idx);
4272
4273 spin_lock_bh(&efx->filter_lock);
4274 if (rc == 0) {
4275 kfree(spec);
4276 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4277 }
4278 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4279 wake_up_all(&table->waitq);
4280 spin_unlock_bh(&efx->filter_lock);
4281}
4282
4283#endif /* CONFIG_RFS_ACCEL */
4284
4285static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4286{
4287 int match_flags = 0;
4288
4289#define MAP_FLAG(gen_flag, mcdi_field) { \
4290 u32 old_mcdi_flags = mcdi_flags; \
4291 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4292 mcdi_field ## _LBN); \
4293 if (mcdi_flags != old_mcdi_flags) \
4294 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4295 }
4296 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4297 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4298 MAP_FLAG(REM_HOST, SRC_IP);
4299 MAP_FLAG(LOC_HOST, DST_IP);
4300 MAP_FLAG(REM_MAC, SRC_MAC);
4301 MAP_FLAG(REM_PORT, SRC_PORT);
4302 MAP_FLAG(LOC_MAC, DST_MAC);
4303 MAP_FLAG(LOC_PORT, DST_PORT);
4304 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4305 MAP_FLAG(INNER_VID, INNER_VLAN);
4306 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4307 MAP_FLAG(IP_PROTO, IP_PROTO);
4308#undef MAP_FLAG
4309
4310 /* Did we map them all? */
4311 if (mcdi_flags)
4312 return -EINVAL;
4313
4314 return match_flags;
4315}
4316
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004317static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4318{
4319 struct efx_ef10_filter_table *table = efx->filter_state;
4320 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4321
4322 /* See comment in efx_ef10_filter_table_remove() */
4323 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4324 return;
4325
4326 if (!table)
4327 return;
4328
4329 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4330 efx_ef10_filter_del_vlan_internal(efx, vlan);
4331}
4332
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004333static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4334 enum efx_filter_match_flags match_flags)
4335{
4336 unsigned int match_pri;
4337 int mf;
4338
4339 for (match_pri = 0;
4340 match_pri < table->rx_match_count;
4341 match_pri++) {
4342 mf = efx_ef10_filter_match_flags_from_mcdi(
4343 table->rx_match_mcdi_flags[match_pri]);
4344 if (mf == match_flags)
4345 return true;
4346 }
4347
4348 return false;
4349}
4350
Ben Hutchings8127d662013-08-29 19:19:29 +01004351static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4352{
4353 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4354 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004355 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004356 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004357 unsigned int pd_match_pri, pd_match_count;
4358 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004359 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004360 size_t outlen;
4361 int rc;
4362
Edward Creedd987082016-06-15 17:43:43 +01004363 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4364 return -EINVAL;
4365
4366 if (efx->filter_state) /* already probed */
4367 return 0;
4368
Ben Hutchings8127d662013-08-29 19:19:29 +01004369 table = kzalloc(sizeof(*table), GFP_KERNEL);
4370 if (!table)
4371 return -ENOMEM;
4372
4373 /* Find out which RX filter types are supported, and their priorities */
4374 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4375 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4376 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4377 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4378 &outlen);
4379 if (rc)
4380 goto fail;
4381 pd_match_count = MCDI_VAR_ARRAY_LEN(
4382 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4383 table->rx_match_count = 0;
4384
4385 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4386 u32 mcdi_flags =
4387 MCDI_ARRAY_DWORD(
4388 outbuf,
4389 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4390 pd_match_pri);
4391 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4392 if (rc < 0) {
4393 netif_dbg(efx, probe, efx->net_dev,
4394 "%s: fw flags %#x pri %u not supported in driver\n",
4395 __func__, mcdi_flags, pd_match_pri);
4396 } else {
4397 netif_dbg(efx, probe, efx->net_dev,
4398 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4399 __func__, mcdi_flags, pd_match_pri,
4400 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004401 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4402 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004403 }
4404 }
4405
Martin Habetse4478ad2016-06-15 17:51:07 +01004406 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4407 !(efx_ef10_filter_match_supported(table,
4408 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4409 efx_ef10_filter_match_supported(table,
4410 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4411 netif_info(efx, probe, net_dev,
4412 "VLAN filters are not supported in this firmware variant\n");
4413 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4414 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4415 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4416 }
4417
Ben Hutchings8127d662013-08-29 19:19:29 +01004418 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4419 if (!table->entry) {
4420 rc = -ENOMEM;
4421 goto fail;
4422 }
4423
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004424 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004425 table->vlan_filter =
4426 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004427 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004428
Ben Hutchings8127d662013-08-29 19:19:29 +01004429 efx->filter_state = table;
4430 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004431
4432 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4433 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4434 if (rc)
4435 goto fail_add_vlan;
4436 }
4437
Ben Hutchings8127d662013-08-29 19:19:29 +01004438 return 0;
4439
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004440fail_add_vlan:
4441 efx_ef10_filter_cleanup_vlans(efx);
4442 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004443fail:
4444 kfree(table);
4445 return rc;
4446}
4447
Edward Cree0d322412015-05-20 11:10:03 +01004448/* Caller must hold efx->filter_sem for read if race against
4449 * efx_ef10_filter_table_remove() is possible
4450 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004451static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4452{
4453 struct efx_ef10_filter_table *table = efx->filter_state;
4454 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4455 struct efx_filter_spec *spec;
4456 unsigned int filter_idx;
4457 bool failed = false;
4458 int rc;
4459
Edward Cree0d322412015-05-20 11:10:03 +01004460 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4461
Ben Hutchings8127d662013-08-29 19:19:29 +01004462 if (!nic_data->must_restore_filters)
4463 return;
4464
Edward Cree0d322412015-05-20 11:10:03 +01004465 if (!table)
4466 return;
4467
Ben Hutchings8127d662013-08-29 19:19:29 +01004468 spin_lock_bh(&efx->filter_lock);
4469
4470 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4471 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4472 if (!spec)
4473 continue;
4474
4475 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4476 spin_unlock_bh(&efx->filter_lock);
4477
4478 rc = efx_ef10_filter_push(efx, spec,
4479 &table->entry[filter_idx].handle,
4480 false);
4481 if (rc)
4482 failed = true;
4483
4484 spin_lock_bh(&efx->filter_lock);
4485 if (rc) {
4486 kfree(spec);
4487 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4488 } else {
4489 table->entry[filter_idx].spec &=
4490 ~EFX_EF10_FILTER_FLAG_BUSY;
4491 }
4492 }
4493
4494 spin_unlock_bh(&efx->filter_lock);
4495
4496 if (failed)
4497 netif_err(efx, hw, efx->net_dev,
4498 "unable to restore all filters\n");
4499 else
4500 nic_data->must_restore_filters = false;
4501}
4502
4503static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4504{
4505 struct efx_ef10_filter_table *table = efx->filter_state;
4506 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4507 struct efx_filter_spec *spec;
4508 unsigned int filter_idx;
4509 int rc;
4510
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004511 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004512 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004513 /* If we were called without locking, then it's not safe to free
4514 * the table as others might be using it. So we just WARN, leak
4515 * the memory, and potentially get an inconsistent filter table
4516 * state.
4517 * This should never actually happen.
4518 */
4519 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4520 return;
4521
Edward Cree0d322412015-05-20 11:10:03 +01004522 if (!table)
4523 return;
4524
Ben Hutchings8127d662013-08-29 19:19:29 +01004525 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4526 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4527 if (!spec)
4528 continue;
4529
4530 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4531 efx_ef10_filter_is_exclusive(spec) ?
4532 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4533 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4534 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4535 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004536 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4537 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004538 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004539 netif_info(efx, drv, efx->net_dev,
4540 "%s: filter %04x remove failed\n",
4541 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004542 kfree(spec);
4543 }
4544
4545 vfree(table->entry);
4546 kfree(table);
4547}
4548
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004549static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4550{
4551 struct efx_ef10_filter_table *table = efx->filter_state;
4552 unsigned int filter_idx;
4553
4554 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4555 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4556 if (!table->entry[filter_idx].spec)
4557 netif_dbg(efx, drv, efx->net_dev,
4558 "marked null spec old %04x:%04x\n", *id,
4559 filter_idx);
4560 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4561 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004562 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004563}
4564
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004565/* Mark old per-VLAN filters that may need to be removed */
4566static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4567 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004568{
4569 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004570 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004571
Edward Cree12fb0da2015-07-21 15:11:00 +01004572 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004573 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004574 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004575 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4576 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4577 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4578 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004579}
4580
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004581/* Mark old filters that may need to be removed.
4582 * Caller must hold efx->filter_sem for read if race against
4583 * efx_ef10_filter_table_remove() is possible
4584 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004585static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4586{
4587 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004588 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004589
4590 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004591 list_for_each_entry(vlan, &table->vlan_list, list)
4592 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004593 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004594}
Ben Hutchings8127d662013-08-29 19:19:29 +01004595
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004596static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004597{
4598 struct efx_ef10_filter_table *table = efx->filter_state;
4599 struct net_device *net_dev = efx->net_dev;
4600 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004601 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004602 unsigned int i;
4603
Edward Cree12fb0da2015-07-21 15:11:00 +01004604 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004605 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004606 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004607 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4608 i = 1;
4609 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004610 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004611 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004612 break;
4613 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004614 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4615 i++;
4616 }
4617}
4618
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004619static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004620{
4621 struct efx_ef10_filter_table *table = efx->filter_state;
4622 struct net_device *net_dev = efx->net_dev;
4623 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004624 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004625
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004626 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004627
Edward Cree12fb0da2015-07-21 15:11:00 +01004628 addr_count = netdev_mc_count(net_dev);
4629 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004630 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004631 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004632 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004633 break;
4634 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004635 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4636 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004637 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004638
4639 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004640}
Ben Hutchings8127d662013-08-29 19:19:29 +01004641
Edward Cree12fb0da2015-07-21 15:11:00 +01004642static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004643 struct efx_ef10_filter_vlan *vlan,
4644 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004645{
4646 struct efx_ef10_filter_table *table = efx->filter_state;
4647 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004648 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004649 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004650 u8 baddr[ETH_ALEN];
4651 unsigned int i, j;
4652 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004653 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004654 int rc;
4655
4656 if (multicast) {
4657 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004658 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004659 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004660 } else {
4661 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004662 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004663 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004664 }
4665
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004666 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4667
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004668 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004669 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004670 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004671 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004672 rc = efx_ef10_filter_insert(efx, &spec, true);
4673 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004674 if (rollback) {
4675 netif_info(efx, drv, efx->net_dev,
4676 "efx_ef10_filter_insert failed rc=%d\n",
4677 rc);
4678 /* Fall back to promiscuous */
4679 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004680 efx_ef10_filter_remove_unsafe(
4681 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004682 ids[j]);
4683 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004684 }
4685 return rc;
4686 } else {
4687 /* mark as not inserted, and carry on */
4688 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004689 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004690 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004691 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004692 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004693
Edward Cree12fb0da2015-07-21 15:11:00 +01004694 if (multicast && rollback) {
4695 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004696 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004697 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004698 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004699 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004700 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004701 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004702 "Broadcast filter insert failed rc=%d\n", 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 {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004712 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004713 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004714 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004715 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004716 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004717
4718 return 0;
4719}
4720
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004721static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4722 struct efx_ef10_filter_vlan *vlan,
4723 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004724{
Edward Cree12fb0da2015-07-21 15:11:00 +01004725 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004726 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004727 struct efx_filter_spec spec;
4728 u8 baddr[ETH_ALEN];
4729 int rc;
4730
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004731 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4732
4733 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004734
4735 if (multicast)
4736 efx_filter_set_mc_def(&spec);
4737 else
4738 efx_filter_set_uc_def(&spec);
4739
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004740 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4741 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4742
Edward Cree12fb0da2015-07-21 15:11:00 +01004743 rc = efx_ef10_filter_insert(efx, &spec, true);
4744 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004745 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4746 efx->net_dev,
4747 "%scast mismatch filter insert failed rc=%d\n",
4748 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004749 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004750 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4751 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004752 if (!nic_data->workaround_26807) {
4753 /* Also need an Ethernet broadcast filter */
4754 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004755 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004756 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004757 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004758 rc = efx_ef10_filter_insert(efx, &spec, true);
4759 if (rc < 0) {
4760 netif_warn(efx, drv, efx->net_dev,
4761 "Broadcast filter insert failed rc=%d\n",
4762 rc);
4763 if (rollback) {
4764 /* Roll back the mc_def filter */
4765 efx_ef10_filter_remove_unsafe(
4766 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004767 vlan->mcdef);
4768 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004769 return rc;
4770 }
4771 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004772 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004773 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004774 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004775 }
4776 }
4777 rc = 0;
4778 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004779 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4780 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004781 rc = 0;
4782 }
4783 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004784}
4785
4786/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4787 * flag or removes these filters, we don't need to hold the filter_lock while
4788 * scanning for these filters.
4789 */
4790static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4791{
4792 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004793 int remove_failed = 0;
4794 int remove_noent = 0;
4795 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004796 int i;
4797
Ben Hutchings8127d662013-08-29 19:19:29 +01004798 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4799 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004800 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004801 rc = efx_ef10_filter_remove_internal(efx,
4802 1U << EFX_FILTER_PRI_AUTO, i, true);
4803 if (rc == -ENOENT)
4804 remove_noent++;
4805 else if (rc)
4806 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004807 }
4808 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004809
4810 if (remove_failed)
4811 netif_info(efx, drv, efx->net_dev,
4812 "%s: failed to remove %d filters\n",
4813 __func__, remove_failed);
4814 if (remove_noent)
4815 netif_info(efx, drv, efx->net_dev,
4816 "%s: failed to remove %d non-existent filters\n",
4817 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004818}
4819
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004820static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4821{
4822 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4823 u8 mac_old[ETH_ALEN];
4824 int rc, rc2;
4825
4826 /* Only reconfigure a PF-created vport */
4827 if (is_zero_ether_addr(nic_data->vport_mac))
4828 return 0;
4829
4830 efx_device_detach_sync(efx);
4831 efx_net_stop(efx->net_dev);
4832 down_write(&efx->filter_sem);
4833 efx_ef10_filter_table_remove(efx);
4834 up_write(&efx->filter_sem);
4835
4836 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4837 if (rc)
4838 goto restore_filters;
4839
4840 ether_addr_copy(mac_old, nic_data->vport_mac);
4841 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4842 nic_data->vport_mac);
4843 if (rc)
4844 goto restore_vadaptor;
4845
4846 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4847 efx->net_dev->dev_addr);
4848 if (!rc) {
4849 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4850 } else {
4851 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4852 if (rc2) {
4853 /* Failed to add original MAC, so clear vport_mac */
4854 eth_zero_addr(nic_data->vport_mac);
4855 goto reset_nic;
4856 }
4857 }
4858
4859restore_vadaptor:
4860 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4861 if (rc2)
4862 goto reset_nic;
4863restore_filters:
4864 down_write(&efx->filter_sem);
4865 rc2 = efx_ef10_filter_table_probe(efx);
4866 up_write(&efx->filter_sem);
4867 if (rc2)
4868 goto reset_nic;
4869
4870 rc2 = efx_net_open(efx->net_dev);
4871 if (rc2)
4872 goto reset_nic;
4873
4874 netif_device_attach(efx->net_dev);
4875
4876 return rc;
4877
4878reset_nic:
4879 netif_err(efx, drv, efx->net_dev,
4880 "Failed to restore when changing MAC address - scheduling reset\n");
4881 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4882
4883 return rc ? rc : rc2;
4884}
4885
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004886/* Caller must hold efx->filter_sem for read if race against
4887 * efx_ef10_filter_table_remove() is possible
4888 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004889static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4890 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004891{
4892 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004893 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004894
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004895 /* Do not install unspecified VID if VLAN filtering is enabled.
4896 * Do not install all specified VIDs if VLAN filtering is disabled.
4897 */
4898 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4899 return;
4900
Edward Cree12fb0da2015-07-21 15:11:00 +01004901 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004902 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004903 efx_ef10_filter_insert_def(efx, vlan, false, false);
4904 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004905 } else {
4906 /* If any of the filters failed to insert, fall back to
4907 * promiscuous mode - add in the uc_def filter. But keep
4908 * our individual unicast filters.
4909 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004910 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4911 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004912 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004913
Edward Cree12fb0da2015-07-21 15:11:00 +01004914 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004915 /* If changing promiscuous state with cascaded multicast filters, remove
4916 * old filters first, so that packets are dropped rather than duplicated
4917 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004918 if (nic_data->workaround_26807 &&
4919 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004920 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004921 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004922 if (nic_data->workaround_26807) {
4923 /* If we failed to insert promiscuous filters, rollback
4924 * and fall back to individual multicast filters
4925 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004926 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004927 /* Changing promisc state, so remove old filters */
4928 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004929 efx_ef10_filter_insert_addr_list(efx, vlan,
4930 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004931 }
4932 } else {
4933 /* If we failed to insert promiscuous filters, don't
4934 * rollback. Regardless, also insert the mc_list
4935 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004936 efx_ef10_filter_insert_def(efx, vlan, true, false);
4937 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004938 }
4939 } else {
4940 /* If any filters failed to insert, rollback and fall back to
4941 * promiscuous mode - mc_def filter and maybe broadcast. If
4942 * that fails, roll back again and insert as many of our
4943 * individual multicast filters as we can.
4944 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004945 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004946 /* Changing promisc state, so remove old filters */
4947 if (nic_data->workaround_26807)
4948 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004949 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4950 efx_ef10_filter_insert_addr_list(efx, vlan,
4951 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004952 }
4953 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004954}
4955
4956/* Caller must hold efx->filter_sem for read if race against
4957 * efx_ef10_filter_table_remove() is possible
4958 */
4959static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4960{
4961 struct efx_ef10_filter_table *table = efx->filter_state;
4962 struct net_device *net_dev = efx->net_dev;
4963 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004964 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004965
4966 if (!efx_dev_registered(efx))
4967 return;
4968
4969 if (!table)
4970 return;
4971
4972 efx_ef10_filter_mark_old(efx);
4973
4974 /* Copy/convert the address lists; add the primary station
4975 * address and broadcast address
4976 */
4977 netif_addr_lock_bh(net_dev);
4978 efx_ef10_filter_uc_addr_list(efx);
4979 efx_ef10_filter_mc_addr_list(efx);
4980 netif_addr_unlock_bh(net_dev);
4981
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004982 /* If VLAN filtering changes, all old filters are finally removed.
4983 * Do it in advance to avoid conflicts for unicast untagged and
4984 * VLAN 0 tagged filters.
4985 */
4986 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4987 if (table->vlan_filter != vlan_filter) {
4988 table->vlan_filter = vlan_filter;
4989 efx_ef10_filter_remove_old(efx);
4990 }
4991
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004992 list_for_each_entry(vlan, &table->vlan_list, list)
4993 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004994
4995 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004996 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004997}
4998
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004999static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5000{
5001 struct efx_ef10_filter_table *table = efx->filter_state;
5002 struct efx_ef10_filter_vlan *vlan;
5003
5004 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5005
5006 list_for_each_entry(vlan, &table->vlan_list, list) {
5007 if (vlan->vid == vid)
5008 return vlan;
5009 }
5010
5011 return NULL;
5012}
5013
5014static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5015{
5016 struct efx_ef10_filter_table *table = efx->filter_state;
5017 struct efx_ef10_filter_vlan *vlan;
5018 unsigned int i;
5019
5020 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5021 return -EINVAL;
5022
5023 vlan = efx_ef10_filter_find_vlan(efx, vid);
5024 if (WARN_ON(vlan)) {
5025 netif_err(efx, drv, efx->net_dev,
5026 "VLAN %u already added\n", vid);
5027 return -EALREADY;
5028 }
5029
5030 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5031 if (!vlan)
5032 return -ENOMEM;
5033
5034 vlan->vid = vid;
5035
5036 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5037 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5038 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5039 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5040 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
5041 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
5042 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
5043
5044 list_add_tail(&vlan->list, &table->vlan_list);
5045
5046 if (efx_dev_registered(efx))
5047 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5048
5049 return 0;
5050}
5051
5052static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5053 struct efx_ef10_filter_vlan *vlan)
5054{
5055 unsigned int i;
5056
5057 /* See comment in efx_ef10_filter_table_remove() */
5058 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5059 return;
5060
5061 list_del(&vlan->list);
5062
Edward Cree8c915622016-06-15 17:49:05 +01005063 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005064 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005065 vlan->uc[i]);
5066 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005067 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005068 vlan->mc[i]);
5069 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
5070 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
5071 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005072
5073 kfree(vlan);
5074}
5075
5076static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5077{
5078 struct efx_ef10_filter_vlan *vlan;
5079
5080 /* See comment in efx_ef10_filter_table_remove() */
5081 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5082 return;
5083
5084 vlan = efx_ef10_filter_find_vlan(efx, vid);
5085 if (!vlan) {
5086 netif_err(efx, drv, efx->net_dev,
5087 "VLAN %u not found in filter state\n", vid);
5088 return;
5089 }
5090
5091 efx_ef10_filter_del_vlan_internal(efx, vlan);
5092}
5093
Shradha Shah910c8782015-05-20 11:12:48 +01005094static int efx_ef10_set_mac_address(struct efx_nic *efx)
5095{
5096 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5097 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5098 bool was_enabled = efx->port_enabled;
5099 int rc;
5100
5101 efx_device_detach_sync(efx);
5102 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005103
5104 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005105 down_write(&efx->filter_sem);
5106 efx_ef10_filter_table_remove(efx);
5107
5108 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5109 efx->net_dev->dev_addr);
5110 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5111 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005112 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5113 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005114
5115 efx_ef10_filter_table_probe(efx);
5116 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005117 mutex_unlock(&efx->mac_lock);
5118
Shradha Shah910c8782015-05-20 11:12:48 +01005119 if (was_enabled)
5120 efx_net_open(efx->net_dev);
5121 netif_device_attach(efx->net_dev);
5122
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005123#ifdef CONFIG_SFC_SRIOV
5124 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005125 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5126
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005127 if (rc == -EPERM) {
5128 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005129
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005130 /* Switch to PF and change MAC address on vport */
5131 efx_pf = pci_get_drvdata(pci_dev_pf);
5132
5133 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005134 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005135 efx->net_dev->dev_addr);
5136 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005137 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5138 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5139 unsigned int i;
5140
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005141 /* MAC address successfully changed by VF (with MAC
5142 * spoofing) so update the parent PF if possible.
5143 */
Shradha Shah910c8782015-05-20 11:12:48 +01005144 for (i = 0; i < efx_pf->vf_count; ++i) {
5145 struct ef10_vf *vf = nic_data->vf + i;
5146
5147 if (vf->efx == efx) {
5148 ether_addr_copy(vf->mac,
5149 efx->net_dev->dev_addr);
5150 return 0;
5151 }
5152 }
5153 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005154 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005155#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005156 if (rc == -EPERM) {
5157 netif_err(efx, drv, efx->net_dev,
5158 "Cannot change MAC address; use sfboot to enable"
5159 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005160 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5161 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5162 * fall-back to the method of changing the MAC address on the
5163 * vport. This only applies to PFs because such versions of
5164 * MCFW do not support VFs.
5165 */
5166 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005167 } else {
5168 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5169 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005170 }
5171
Shradha Shah910c8782015-05-20 11:12:48 +01005172 return rc;
5173}
5174
Ben Hutchings8127d662013-08-29 19:19:29 +01005175static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5176{
5177 efx_ef10_filter_sync_rx_mode(efx);
5178
5179 return efx_mcdi_set_mac(efx);
5180}
5181
Shradha Shah862f8942015-05-20 11:08:56 +01005182static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5183{
5184 efx_ef10_filter_sync_rx_mode(efx);
5185
5186 return 0;
5187}
5188
Jon Cooper74cd60a2013-09-16 14:18:51 +01005189static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5190{
5191 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5192
5193 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5194 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5195 NULL, 0, NULL);
5196}
5197
5198/* MC BISTs follow a different poll mechanism to phy BISTs.
5199 * The BIST is done in the poll handler on the MC, and the MCDI command
5200 * will block until the BIST is done.
5201 */
5202static int efx_ef10_poll_bist(struct efx_nic *efx)
5203{
5204 int rc;
5205 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5206 size_t outlen;
5207 u32 result;
5208
5209 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5210 outbuf, sizeof(outbuf), &outlen);
5211 if (rc != 0)
5212 return rc;
5213
5214 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5215 return -EIO;
5216
5217 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5218 switch (result) {
5219 case MC_CMD_POLL_BIST_PASSED:
5220 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5221 return 0;
5222 case MC_CMD_POLL_BIST_TIMEOUT:
5223 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5224 return -EIO;
5225 case MC_CMD_POLL_BIST_FAILED:
5226 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5227 return -EIO;
5228 default:
5229 netif_err(efx, hw, efx->net_dev,
5230 "BIST returned unknown result %u", result);
5231 return -EIO;
5232 }
5233}
5234
5235static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5236{
5237 int rc;
5238
5239 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5240
5241 rc = efx_ef10_start_bist(efx, bist_type);
5242 if (rc != 0)
5243 return rc;
5244
5245 return efx_ef10_poll_bist(efx);
5246}
5247
5248static int
5249efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5250{
5251 int rc, rc2;
5252
5253 efx_reset_down(efx, RESET_TYPE_WORLD);
5254
5255 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5256 NULL, 0, NULL, 0, NULL);
5257 if (rc != 0)
5258 goto out;
5259
5260 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5261 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5262
5263 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5264
5265out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005266 if (rc == -EPERM)
5267 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005268 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5269 return rc ? rc : rc2;
5270}
5271
Ben Hutchings8127d662013-08-29 19:19:29 +01005272#ifdef CONFIG_SFC_MTD
5273
5274struct efx_ef10_nvram_type_info {
5275 u16 type, type_mask;
5276 u8 port;
5277 const char *name;
5278};
5279
5280static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5281 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5282 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5283 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5284 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5285 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5286 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5287 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5288 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5289 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005290 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005291 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5292};
5293
5294static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5295 struct efx_mcdi_mtd_partition *part,
5296 unsigned int type)
5297{
5298 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5299 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5300 const struct efx_ef10_nvram_type_info *info;
5301 size_t size, erase_size, outlen;
5302 bool protected;
5303 int rc;
5304
5305 for (info = efx_ef10_nvram_types; ; info++) {
5306 if (info ==
5307 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5308 return -ENODEV;
5309 if ((type & ~info->type_mask) == info->type)
5310 break;
5311 }
5312 if (info->port != efx_port_num(efx))
5313 return -ENODEV;
5314
5315 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5316 if (rc)
5317 return rc;
5318 if (protected)
5319 return -ENODEV; /* hide it */
5320
5321 part->nvram_type = type;
5322
5323 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5324 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5325 outbuf, sizeof(outbuf), &outlen);
5326 if (rc)
5327 return rc;
5328 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5329 return -EIO;
5330 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5331 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5332 part->fw_subtype = MCDI_DWORD(outbuf,
5333 NVRAM_METADATA_OUT_SUBTYPE);
5334
5335 part->common.dev_type_name = "EF10 NVRAM manager";
5336 part->common.type_name = info->name;
5337
5338 part->common.mtd.type = MTD_NORFLASH;
5339 part->common.mtd.flags = MTD_CAP_NORFLASH;
5340 part->common.mtd.size = size;
5341 part->common.mtd.erasesize = erase_size;
5342
5343 return 0;
5344}
5345
5346static int efx_ef10_mtd_probe(struct efx_nic *efx)
5347{
5348 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5349 struct efx_mcdi_mtd_partition *parts;
5350 size_t outlen, n_parts_total, i, n_parts;
5351 unsigned int type;
5352 int rc;
5353
5354 ASSERT_RTNL();
5355
5356 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5357 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5358 outbuf, sizeof(outbuf), &outlen);
5359 if (rc)
5360 return rc;
5361 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5362 return -EIO;
5363
5364 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5365 if (n_parts_total >
5366 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5367 return -EIO;
5368
5369 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5370 if (!parts)
5371 return -ENOMEM;
5372
5373 n_parts = 0;
5374 for (i = 0; i < n_parts_total; i++) {
5375 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5376 i);
5377 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5378 if (rc == 0)
5379 n_parts++;
5380 else if (rc != -ENODEV)
5381 goto fail;
5382 }
5383
5384 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5385fail:
5386 if (rc)
5387 kfree(parts);
5388 return rc;
5389}
5390
5391#endif /* CONFIG_SFC_MTD */
5392
5393static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5394{
5395 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5396}
5397
Shradha Shah02246a72015-05-06 00:58:14 +01005398static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5399 u32 host_time) {}
5400
Jon Cooperbd9a2652013-11-18 12:54:41 +00005401static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5402 bool temp)
5403{
5404 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5405 int rc;
5406
5407 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5408 channel->sync_events_state == SYNC_EVENTS_VALID ||
5409 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5410 return 0;
5411 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5412
5413 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5414 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5415 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5416 channel->channel);
5417
5418 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5419 inbuf, sizeof(inbuf), NULL, 0, NULL);
5420
5421 if (rc != 0)
5422 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5423 SYNC_EVENTS_DISABLED;
5424
5425 return rc;
5426}
5427
5428static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5429 bool temp)
5430{
5431 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5432 int rc;
5433
5434 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5435 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5436 return 0;
5437 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5438 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5439 return 0;
5440 }
5441 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5442 SYNC_EVENTS_DISABLED;
5443
5444 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5445 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5446 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5447 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5448 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5449 channel->channel);
5450
5451 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5452 inbuf, sizeof(inbuf), NULL, 0, NULL);
5453
5454 return rc;
5455}
5456
5457static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5458 bool temp)
5459{
5460 int (*set)(struct efx_channel *channel, bool temp);
5461 struct efx_channel *channel;
5462
5463 set = en ?
5464 efx_ef10_rx_enable_timestamping :
5465 efx_ef10_rx_disable_timestamping;
5466
5467 efx_for_each_channel(channel, efx) {
5468 int rc = set(channel, temp);
5469 if (en && rc != 0) {
5470 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5471 return rc;
5472 }
5473 }
5474
5475 return 0;
5476}
5477
Shradha Shah02246a72015-05-06 00:58:14 +01005478static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5479 struct hwtstamp_config *init)
5480{
5481 return -EOPNOTSUPP;
5482}
5483
Jon Cooperbd9a2652013-11-18 12:54:41 +00005484static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5485 struct hwtstamp_config *init)
5486{
5487 int rc;
5488
5489 switch (init->rx_filter) {
5490 case HWTSTAMP_FILTER_NONE:
5491 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5492 /* if TX timestamping is still requested then leave PTP on */
5493 return efx_ptp_change_mode(efx,
5494 init->tx_type != HWTSTAMP_TX_OFF, 0);
5495 case HWTSTAMP_FILTER_ALL:
5496 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5497 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5498 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5499 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5500 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5501 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5502 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5503 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5504 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5505 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5506 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5507 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5508 init->rx_filter = HWTSTAMP_FILTER_ALL;
5509 rc = efx_ptp_change_mode(efx, true, 0);
5510 if (!rc)
5511 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5512 if (rc)
5513 efx_ptp_change_mode(efx, false, 0);
5514 return rc;
5515 default:
5516 return -ERANGE;
5517 }
5518}
5519
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005520static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5521{
5522 if (proto != htons(ETH_P_8021Q))
5523 return -EINVAL;
5524
5525 return efx_ef10_add_vlan(efx, vid);
5526}
5527
5528static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5529{
5530 if (proto != htons(ETH_P_8021Q))
5531 return -EINVAL;
5532
5533 return efx_ef10_del_vlan(efx, vid);
5534}
5535
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005536#define EF10_OFFLOAD_FEATURES \
5537 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005538 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005539 NETIF_F_IPV6_CSUM | \
5540 NETIF_F_RXHASH | \
5541 NETIF_F_NTUPLE)
5542
Shradha Shah02246a72015-05-06 00:58:14 +01005543const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005544 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005545 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005546 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005547 .probe = efx_ef10_probe_vf,
5548 .remove = efx_ef10_remove,
5549 .dimension_resources = efx_ef10_dimension_resources,
5550 .init = efx_ef10_init_nic,
5551 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005552 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005553 .map_reset_flags = efx_ef10_map_reset_flags,
5554 .reset = efx_ef10_reset,
5555 .probe_port = efx_mcdi_port_probe,
5556 .remove_port = efx_mcdi_port_remove,
5557 .fini_dmaq = efx_ef10_fini_dmaq,
5558 .prepare_flr = efx_ef10_prepare_flr,
5559 .finish_flr = efx_port_dummy_op_void,
5560 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005561 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005562 .start_stats = efx_port_dummy_op_void,
5563 .pull_stats = efx_port_dummy_op_void,
5564 .stop_stats = efx_port_dummy_op_void,
5565 .set_id_led = efx_mcdi_set_id_led,
5566 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005567 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005568 .check_mac_fault = efx_mcdi_mac_check_fault,
5569 .reconfigure_port = efx_mcdi_port_reconfigure,
5570 .get_wol = efx_ef10_get_wol_vf,
5571 .set_wol = efx_ef10_set_wol_vf,
5572 .resume_wol = efx_port_dummy_op_void,
5573 .mcdi_request = efx_ef10_mcdi_request,
5574 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5575 .mcdi_read_response = efx_ef10_mcdi_read_response,
5576 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005577 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005578 .irq_enable_master = efx_port_dummy_op_void,
5579 .irq_test_generate = efx_ef10_irq_test_generate,
5580 .irq_disable_non_ev = efx_port_dummy_op_void,
5581 .irq_handle_msi = efx_ef10_msi_interrupt,
5582 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5583 .tx_probe = efx_ef10_tx_probe,
5584 .tx_init = efx_ef10_tx_init,
5585 .tx_remove = efx_ef10_tx_remove,
5586 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005587 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005588 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005589 .rx_probe = efx_ef10_rx_probe,
5590 .rx_init = efx_ef10_rx_init,
5591 .rx_remove = efx_ef10_rx_remove,
5592 .rx_write = efx_ef10_rx_write,
5593 .rx_defer_refill = efx_ef10_rx_defer_refill,
5594 .ev_probe = efx_ef10_ev_probe,
5595 .ev_init = efx_ef10_ev_init,
5596 .ev_fini = efx_ef10_ev_fini,
5597 .ev_remove = efx_ef10_ev_remove,
5598 .ev_process = efx_ef10_ev_process,
5599 .ev_read_ack = efx_ef10_ev_read_ack,
5600 .ev_test_generate = efx_ef10_ev_test_generate,
5601 .filter_table_probe = efx_ef10_filter_table_probe,
5602 .filter_table_restore = efx_ef10_filter_table_restore,
5603 .filter_table_remove = efx_ef10_filter_table_remove,
5604 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5605 .filter_insert = efx_ef10_filter_insert,
5606 .filter_remove_safe = efx_ef10_filter_remove_safe,
5607 .filter_get_safe = efx_ef10_filter_get_safe,
5608 .filter_clear_rx = efx_ef10_filter_clear_rx,
5609 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5610 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5611 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5612#ifdef CONFIG_RFS_ACCEL
5613 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5614 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5615#endif
5616#ifdef CONFIG_SFC_MTD
5617 .mtd_probe = efx_port_dummy_op_int,
5618#endif
5619 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5620 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005621 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5622 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005623#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005624 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5625 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5626 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01005627 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005628#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005629 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005630 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005631
Shradha Shah02246a72015-05-06 00:58:14 +01005632 .revision = EFX_REV_HUNT_A0,
5633 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5634 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5635 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5636 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5637 .can_rx_scatter = true,
5638 .always_rx_scatter = true,
5639 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5640 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005641 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005642 .mcdi_max_ver = 2,
5643 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5644 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5645 1 << HWTSTAMP_FILTER_ALL,
5646};
5647
5648const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005649 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005650 .mem_bar = EFX_MEM_BAR,
5651 .mem_map_size = efx_ef10_mem_map_size,
5652 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005653 .remove = efx_ef10_remove,
5654 .dimension_resources = efx_ef10_dimension_resources,
5655 .init = efx_ef10_init_nic,
5656 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005657 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005658 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005659 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005660 .probe_port = efx_mcdi_port_probe,
5661 .remove_port = efx_mcdi_port_remove,
5662 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005663 .prepare_flr = efx_ef10_prepare_flr,
5664 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005665 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005666 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005667 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005668 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005669 .stop_stats = efx_mcdi_mac_stop_stats,
5670 .set_id_led = efx_mcdi_set_id_led,
5671 .push_irq_moderation = efx_ef10_push_irq_moderation,
5672 .reconfigure_mac = efx_ef10_mac_reconfigure,
5673 .check_mac_fault = efx_mcdi_mac_check_fault,
5674 .reconfigure_port = efx_mcdi_port_reconfigure,
5675 .get_wol = efx_ef10_get_wol,
5676 .set_wol = efx_ef10_set_wol,
5677 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005678 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005679 .test_nvram = efx_mcdi_nvram_test_all,
5680 .mcdi_request = efx_ef10_mcdi_request,
5681 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5682 .mcdi_read_response = efx_ef10_mcdi_read_response,
5683 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005684 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005685 .irq_enable_master = efx_port_dummy_op_void,
5686 .irq_test_generate = efx_ef10_irq_test_generate,
5687 .irq_disable_non_ev = efx_port_dummy_op_void,
5688 .irq_handle_msi = efx_ef10_msi_interrupt,
5689 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5690 .tx_probe = efx_ef10_tx_probe,
5691 .tx_init = efx_ef10_tx_init,
5692 .tx_remove = efx_ef10_tx_remove,
5693 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005694 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005695 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005696 .rx_probe = efx_ef10_rx_probe,
5697 .rx_init = efx_ef10_rx_init,
5698 .rx_remove = efx_ef10_rx_remove,
5699 .rx_write = efx_ef10_rx_write,
5700 .rx_defer_refill = efx_ef10_rx_defer_refill,
5701 .ev_probe = efx_ef10_ev_probe,
5702 .ev_init = efx_ef10_ev_init,
5703 .ev_fini = efx_ef10_ev_fini,
5704 .ev_remove = efx_ef10_ev_remove,
5705 .ev_process = efx_ef10_ev_process,
5706 .ev_read_ack = efx_ef10_ev_read_ack,
5707 .ev_test_generate = efx_ef10_ev_test_generate,
5708 .filter_table_probe = efx_ef10_filter_table_probe,
5709 .filter_table_restore = efx_ef10_filter_table_restore,
5710 .filter_table_remove = efx_ef10_filter_table_remove,
5711 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5712 .filter_insert = efx_ef10_filter_insert,
5713 .filter_remove_safe = efx_ef10_filter_remove_safe,
5714 .filter_get_safe = efx_ef10_filter_get_safe,
5715 .filter_clear_rx = efx_ef10_filter_clear_rx,
5716 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5717 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5718 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5719#ifdef CONFIG_RFS_ACCEL
5720 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5721 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5722#endif
5723#ifdef CONFIG_SFC_MTD
5724 .mtd_probe = efx_ef10_mtd_probe,
5725 .mtd_rename = efx_mcdi_mtd_rename,
5726 .mtd_read = efx_mcdi_mtd_read,
5727 .mtd_erase = efx_mcdi_mtd_erase,
5728 .mtd_write = efx_mcdi_mtd_write,
5729 .mtd_sync = efx_mcdi_mtd_sync,
5730#endif
5731 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005732 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5733 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005734 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5735 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005736#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005737 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005738 .sriov_init = efx_ef10_sriov_init,
5739 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005740 .sriov_wanted = efx_ef10_sriov_wanted,
5741 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005742 .sriov_flr = efx_ef10_sriov_flr,
5743 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5744 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5745 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5746 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005747 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005748 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5749 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5750 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005751#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005752 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005753 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01005754
5755 .revision = EFX_REV_HUNT_A0,
5756 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5757 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5758 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005759 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005760 .can_rx_scatter = true,
5761 .always_rx_scatter = true,
5762 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5763 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005764 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005765 .mcdi_max_ver = 2,
5766 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005767 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5768 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005769};