blob: 9cbe573563d75738bc35aecff5a905a2c7ba3c70 [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 Kenwardca889a052016-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 Kenwardca889a052016-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 Kenwardca889a052016-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.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002181 */
2182 if (csum_offload && (nic_data->datapath_caps2 &
2183 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2184 tso_v2 = true;
2185 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2186 channel->channel);
2187 }
2188
Ben Hutchings8127d662013-08-29 19:19:29 +01002189 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2190 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2191 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2192 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002193 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002194 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002195
2196 dma_addr = tx_queue->txd.buf.dma_addr;
2197
2198 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2199 tx_queue->queue, entries, (u64)dma_addr);
2200
2201 for (i = 0; i < entries; ++i) {
2202 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2203 dma_addr += EFX_BUF_SIZE;
2204 }
2205
2206 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2207
Edward Creee638ee12016-11-17 10:52:07 +00002208 do {
2209 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2210 /* This flag was removed from mcdi_pcol.h for
2211 * the non-_EXT version of INIT_TXQ. However,
2212 * firmware still honours it.
2213 */
2214 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2215 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2216 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2217
2218 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2219 NULL, 0, NULL);
2220 if (rc == -ENOSPC && tso_v2) {
2221 /* Retry without TSOv2 if we're short on contexts. */
2222 tso_v2 = false;
2223 netif_warn(efx, probe, efx->net_dev,
2224 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2225 } else if (rc) {
2226 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2227 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2228 NULL, 0, rc);
2229 goto fail;
2230 }
2231 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002232
2233 /* A previous user of this TX queue might have set us up the
2234 * bomb by writing a descriptor to the TX push collector but
2235 * not the doorbell. (Each collector belongs to a port, not a
2236 * queue or function, so cannot easily be reset.) We must
2237 * attempt to push a no-op descriptor in its place.
2238 */
2239 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2240 tx_queue->insert_count = 1;
2241 txd = efx_tx_desc(tx_queue, 0);
2242 EFX_POPULATE_QWORD_4(*txd,
2243 ESF_DZ_TX_DESC_IS_OPT, true,
2244 ESF_DZ_TX_OPTION_TYPE,
2245 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2246 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2247 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2248 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002249
Bert Kenwarde9117e52016-11-17 10:51:54 +00002250 if (tso_v2) {
2251 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2252 tx_queue->tso_version = 2;
2253 } else if (nic_data->datapath_caps &
2254 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002255 tx_queue->tso_version = 1;
2256 }
2257
Ben Hutchings8127d662013-08-29 19:19:29 +01002258 wmb();
2259 efx_ef10_push_tx_desc(tx_queue, txd);
2260
2261 return;
2262
2263fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002264 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2265 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002266}
2267
2268static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2269{
2270 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002271 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002272 struct efx_nic *efx = tx_queue->efx;
2273 size_t outlen;
2274 int rc;
2275
2276 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2277 tx_queue->queue);
2278
Edward Cree1e0b8122013-05-31 18:36:12 +01002279 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002280 outbuf, sizeof(outbuf), &outlen);
2281
2282 if (rc && rc != -EALREADY)
2283 goto fail;
2284
2285 return;
2286
2287fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002288 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2289 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002290}
2291
2292static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2293{
2294 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2295}
2296
2297/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2298static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2299{
2300 unsigned int write_ptr;
2301 efx_dword_t reg;
2302
2303 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2304 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2305 efx_writed_page(tx_queue->efx, &reg,
2306 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2307}
2308
Bert Kenwarde9117e52016-11-17 10:51:54 +00002309#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2310
2311static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2312 dma_addr_t dma_addr, unsigned int len)
2313{
2314 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2315 /* If we need to break across multiple descriptors we should
2316 * stop at a page boundary. This assumes the length limit is
2317 * greater than the page size.
2318 */
2319 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2320
2321 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2322 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2323 }
2324
2325 return len;
2326}
2327
Ben Hutchings8127d662013-08-29 19:19:29 +01002328static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2329{
2330 unsigned int old_write_count = tx_queue->write_count;
2331 struct efx_tx_buffer *buffer;
2332 unsigned int write_ptr;
2333 efx_qword_t *txd;
2334
Martin Habetsb2663a42015-11-02 12:51:31 +00002335 tx_queue->xmit_more_available = false;
2336 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2337 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002338
2339 do {
2340 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2341 buffer = &tx_queue->buffer[write_ptr];
2342 txd = efx_tx_desc(tx_queue, write_ptr);
2343 ++tx_queue->write_count;
2344
2345 /* Create TX descriptor ring entry */
2346 if (buffer->flags & EFX_TX_BUF_OPTION) {
2347 *txd = buffer->option;
2348 } else {
2349 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2350 EFX_POPULATE_QWORD_3(
2351 *txd,
2352 ESF_DZ_TX_KER_CONT,
2353 buffer->flags & EFX_TX_BUF_CONT,
2354 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2355 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2356 }
2357 } while (tx_queue->write_count != tx_queue->insert_count);
2358
2359 wmb(); /* Ensure descriptors are written before they are fetched */
2360
2361 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2362 txd = efx_tx_desc(tx_queue,
2363 old_write_count & tx_queue->ptr_mask);
2364 efx_ef10_push_tx_desc(tx_queue, txd);
2365 ++tx_queue->pushes;
2366 } else {
2367 efx_ef10_notify_tx_desc(tx_queue);
2368 }
2369}
2370
Edward Creea33a4c72016-11-03 22:12:27 +00002371#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2372 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2373#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2374 1 << RSS_MODE_HASH_DST_PORT_LBN)
2375#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2376 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2377 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2378 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2379 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2380 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2381 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2382 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2383 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2384 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2385
2386static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2387{
2388 /* Firmware had a bug (sfc bug 61952) where it would not actually
2389 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2390 * This meant that it would always contain whatever was previously
2391 * in the MCDI buffer. Fortunately, all firmware versions with
2392 * this bug have the same default flags value for a newly-allocated
2393 * RSS context, and the only time we want to get the flags is just
2394 * after allocating. Moreover, the response has a 32-bit hole
2395 * where the context ID would be in the request, so we can use an
2396 * overlength buffer in the request and pre-fill the flags field
2397 * with what we believe the default to be. Thus if the firmware
2398 * has the bug, it will leave our pre-filled value in the flags
2399 * field of the response, and we will get the right answer.
2400 *
2401 * However, this does mean that this function should NOT be used if
2402 * the RSS context flags might not be their defaults - it is ONLY
2403 * reliably correct for a newly-allocated RSS context.
2404 */
2405 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2406 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2407 size_t outlen;
2408 int rc;
2409
2410 /* Check we have a hole for the context ID */
2411 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2412 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2413 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2414 RSS_CONTEXT_FLAGS_DEFAULT);
2415 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2416 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2417 if (rc == 0) {
2418 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2419 rc = -EIO;
2420 else
2421 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2422 }
2423 return rc;
2424}
2425
2426/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2427 * If we fail, we just leave the RSS context at its default hash settings,
2428 * which is safe but may slightly reduce performance.
2429 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2430 * just need to set the UDP ports flags (for both IP versions).
2431 */
2432static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2433{
2434 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2435 u32 flags;
2436
2437 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2438
2439 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2440 return;
2441 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2442 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2443 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2444 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002445 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2446 NULL, 0, NULL))
2447 /* Succeeded, so UDP 4-tuple is now enabled */
2448 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002449}
2450
Jon Cooper267c0152015-05-06 00:59:38 +01002451static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2452 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002453{
2454 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2455 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002456 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002457 size_t outlen;
2458 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002459 u32 alloc_type = exclusive ?
2460 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2461 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2462 unsigned rss_spread = exclusive ?
2463 efx->rss_spread :
2464 min(rounddown_pow_of_two(efx->rss_spread),
2465 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2466
2467 if (!exclusive && rss_spread == 1) {
2468 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2469 if (context_size)
2470 *context_size = 1;
2471 return 0;
2472 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002473
Jon Cooperdcb41232016-04-25 16:51:00 +01002474 if (nic_data->datapath_caps &
2475 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2476 return -EOPNOTSUPP;
2477
Ben Hutchings8127d662013-08-29 19:19:29 +01002478 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002479 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002480 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2481 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002482
2483 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2484 outbuf, sizeof(outbuf), &outlen);
2485 if (rc != 0)
2486 return rc;
2487
2488 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2489 return -EIO;
2490
2491 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2492
Jon Cooper267c0152015-05-06 00:59:38 +01002493 if (context_size)
2494 *context_size = rss_spread;
2495
Edward Creea33a4c72016-11-03 22:12:27 +00002496 if (nic_data->datapath_caps &
2497 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2498 efx_ef10_set_rss_flags(efx, *context);
2499
Ben Hutchings8127d662013-08-29 19:19:29 +01002500 return 0;
2501}
2502
2503static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2504{
2505 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2506 int rc;
2507
2508 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2509 context);
2510
2511 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2512 NULL, 0, NULL);
2513 WARN_ON(rc != 0);
2514}
2515
Jon Cooper267c0152015-05-06 00:59:38 +01002516static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2517 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002518{
2519 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2520 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2521 int i, rc;
2522
2523 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2524 context);
2525 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2526 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2527
2528 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2529 MCDI_PTR(tablebuf,
2530 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002531 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002532
2533 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2534 sizeof(tablebuf), NULL, 0, NULL);
2535 if (rc != 0)
2536 return rc;
2537
2538 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2539 context);
2540 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2541 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2542 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2543 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2544 efx->rx_hash_key[i];
2545
2546 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2547 sizeof(keybuf), NULL, 0, NULL);
2548}
2549
2550static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2551{
2552 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2553
2554 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2555 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2556 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2557}
2558
Jon Cooper267c0152015-05-06 00:59:38 +01002559static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2560 unsigned *context_size)
2561{
2562 u32 new_rx_rss_context;
2563 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2564 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2565 false, context_size);
2566
2567 if (rc != 0)
2568 return rc;
2569
2570 nic_data->rx_rss_context = new_rx_rss_context;
2571 nic_data->rx_rss_context_exclusive = false;
2572 efx_set_default_rx_indir_table(efx);
2573 return 0;
2574}
2575
2576static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2577 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002578{
2579 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2580 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002581 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002582
Jon Cooper267c0152015-05-06 00:59:38 +01002583 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2584 !nic_data->rx_rss_context_exclusive) {
2585 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2586 true, NULL);
2587 if (rc == -EOPNOTSUPP)
2588 return rc;
2589 else if (rc != 0)
2590 goto fail1;
2591 } else {
2592 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002593 }
2594
Jon Cooper267c0152015-05-06 00:59:38 +01002595 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2596 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002597 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002598 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002599
Jon Cooper267c0152015-05-06 00:59:38 +01002600 if (nic_data->rx_rss_context != new_rx_rss_context)
2601 efx_ef10_rx_free_indir_table(efx);
2602 nic_data->rx_rss_context = new_rx_rss_context;
2603 nic_data->rx_rss_context_exclusive = true;
2604 if (rx_indir_table != efx->rx_indir_table)
2605 memcpy(efx->rx_indir_table, rx_indir_table,
2606 sizeof(efx->rx_indir_table));
2607 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002608
Jon Cooper267c0152015-05-06 00:59:38 +01002609fail2:
2610 if (new_rx_rss_context != nic_data->rx_rss_context)
2611 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2612fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002613 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002614 return rc;
2615}
2616
2617static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2618 const u32 *rx_indir_table)
2619{
2620 int rc;
2621
2622 if (efx->rss_spread == 1)
2623 return 0;
2624
2625 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2626
2627 if (rc == -ENOBUFS && !user) {
2628 unsigned context_size;
2629 bool mismatch = false;
2630 size_t i;
2631
2632 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2633 i++)
2634 mismatch = rx_indir_table[i] !=
2635 ethtool_rxfh_indir_default(i, efx->rss_spread);
2636
2637 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2638 if (rc == 0) {
2639 if (context_size != efx->rss_spread)
2640 netif_warn(efx, probe, efx->net_dev,
2641 "Could not allocate an exclusive RSS"
2642 " context; allocated a shared one of"
2643 " different size."
2644 " Wanted %u, got %u.\n",
2645 efx->rss_spread, context_size);
2646 else if (mismatch)
2647 netif_warn(efx, probe, efx->net_dev,
2648 "Could not allocate an exclusive RSS"
2649 " context; allocated a shared one but"
2650 " could not apply custom"
2651 " indirection.\n");
2652 else
2653 netif_info(efx, probe, efx->net_dev,
2654 "Could not allocate an exclusive RSS"
2655 " context; allocated a shared one.\n");
2656 }
2657 }
2658 return rc;
2659}
2660
2661static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2662 const u32 *rx_indir_table
2663 __attribute__ ((unused)))
2664{
2665 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2666
2667 if (user)
2668 return -EOPNOTSUPP;
2669 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2670 return 0;
2671 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002672}
2673
2674static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2675{
2676 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2677 (rx_queue->ptr_mask + 1) *
2678 sizeof(efx_qword_t),
2679 GFP_KERNEL);
2680}
2681
2682static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2683{
2684 MCDI_DECLARE_BUF(inbuf,
2685 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2686 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002687 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2688 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2689 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002690 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002691 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002692 dma_addr_t dma_addr;
2693 int rc;
2694 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002695 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002696
2697 rx_queue->scatter_n = 0;
2698 rx_queue->scatter_len = 0;
2699
2700 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2701 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2702 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2703 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2704 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002705 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2706 INIT_RXQ_IN_FLAG_PREFIX, 1,
2707 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002708 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002709 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002710
2711 dma_addr = rx_queue->rxd.buf.dma_addr;
2712
2713 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2714 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2715
2716 for (i = 0; i < entries; ++i) {
2717 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2718 dma_addr += EFX_BUF_SIZE;
2719 }
2720
2721 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2722
2723 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002724 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002725 if (rc)
2726 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2727 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002728}
2729
2730static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2731{
2732 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002733 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002734 struct efx_nic *efx = rx_queue->efx;
2735 size_t outlen;
2736 int rc;
2737
2738 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2739 efx_rx_queue_index(rx_queue));
2740
Edward Cree1e0b8122013-05-31 18:36:12 +01002741 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002742 outbuf, sizeof(outbuf), &outlen);
2743
2744 if (rc && rc != -EALREADY)
2745 goto fail;
2746
2747 return;
2748
2749fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002750 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2751 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002752}
2753
2754static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2755{
2756 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2757}
2758
2759/* This creates an entry in the RX descriptor queue */
2760static inline void
2761efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2762{
2763 struct efx_rx_buffer *rx_buf;
2764 efx_qword_t *rxd;
2765
2766 rxd = efx_rx_desc(rx_queue, index);
2767 rx_buf = efx_rx_buffer(rx_queue, index);
2768 EFX_POPULATE_QWORD_2(*rxd,
2769 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2770 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2771}
2772
2773static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2774{
2775 struct efx_nic *efx = rx_queue->efx;
2776 unsigned int write_count;
2777 efx_dword_t reg;
2778
2779 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2780 write_count = rx_queue->added_count & ~7;
2781 if (rx_queue->notified_count == write_count)
2782 return;
2783
2784 do
2785 efx_ef10_build_rx_desc(
2786 rx_queue,
2787 rx_queue->notified_count & rx_queue->ptr_mask);
2788 while (++rx_queue->notified_count != write_count);
2789
2790 wmb();
2791 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2792 write_count & rx_queue->ptr_mask);
2793 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2794 efx_rx_queue_index(rx_queue));
2795}
2796
2797static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2798
2799static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2800{
2801 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2802 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2803 efx_qword_t event;
2804
2805 EFX_POPULATE_QWORD_2(event,
2806 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2807 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2808
2809 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2810
2811 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2812 * already swapped the data to little-endian order.
2813 */
2814 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2815 sizeof(efx_qword_t));
2816
2817 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2818 inbuf, sizeof(inbuf), 0,
2819 efx_ef10_rx_defer_refill_complete, 0);
2820}
2821
2822static void
2823efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2824 int rc, efx_dword_t *outbuf,
2825 size_t outlen_actual)
2826{
2827 /* nothing to do */
2828}
2829
2830static int efx_ef10_ev_probe(struct efx_channel *channel)
2831{
2832 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2833 (channel->eventq_mask + 1) *
2834 sizeof(efx_qword_t),
2835 GFP_KERNEL);
2836}
2837
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002838static void efx_ef10_ev_fini(struct efx_channel *channel)
2839{
2840 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2841 MCDI_DECLARE_BUF_ERR(outbuf);
2842 struct efx_nic *efx = channel->efx;
2843 size_t outlen;
2844 int rc;
2845
2846 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2847
2848 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2849 outbuf, sizeof(outbuf), &outlen);
2850
2851 if (rc && rc != -EALREADY)
2852 goto fail;
2853
2854 return;
2855
2856fail:
2857 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2858 outbuf, outlen, rc);
2859}
2860
Ben Hutchings8127d662013-08-29 19:19:29 +01002861static int efx_ef10_ev_init(struct efx_channel *channel)
2862{
2863 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002864 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2865 EFX_BUF_SIZE));
2866 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002867 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2868 struct efx_nic *efx = channel->efx;
2869 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002870 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002871 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002872 dma_addr_t dma_addr;
2873 int rc;
2874 int i;
2875
2876 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002877
2878 /* Fill event queue with all ones (i.e. empty events) */
2879 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2880
2881 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2882 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2883 /* INIT_EVQ expects index in vector table, not absolute */
2884 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002885 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2886 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2887 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2888 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2889 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2890 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2891 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2892
Bert Kenwarda9955602016-08-11 13:01:54 +01002893 if (nic_data->datapath_caps2 &
2894 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2895 /* Use the new generic approach to specifying event queue
2896 * configuration, requesting lower latency or higher throughput.
2897 * The options that actually get used appear in the output.
2898 */
2899 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2900 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2901 INIT_EVQ_V2_IN_FLAG_TYPE,
2902 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2903 } else {
2904 bool cut_thru = !(nic_data->datapath_caps &
2905 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2906
2907 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2908 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2909 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2910 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2911 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2912 }
2913
Ben Hutchings8127d662013-08-29 19:19:29 +01002914 dma_addr = channel->eventq.buf.dma_addr;
2915 for (i = 0; i < entries; ++i) {
2916 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2917 dma_addr += EFX_BUF_SIZE;
2918 }
2919
2920 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2921
2922 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2923 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01002924
2925 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2926 netif_dbg(efx, drv, efx->net_dev,
2927 "Channel %d using event queue flags %08x\n",
2928 channel->channel,
2929 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2930
Ben Hutchings8127d662013-08-29 19:19:29 +01002931 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002932 if (channel->channel || rc)
2933 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002934
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002935 /* Successfully created event queue on channel 0 */
2936 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002937 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01002938 /* GET_WORKAROUNDS was implemented before this workaround,
2939 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01002940 */
2941 nic_data->workaround_26807 = false;
2942 rc = 0;
2943 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002944 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002945 } else {
2946 nic_data->workaround_26807 =
2947 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002948
Edward Cree832dc9e2015-07-21 15:09:31 +01002949 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2950 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002951 unsigned int flags;
2952
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002953 rc = efx_mcdi_set_workaround(efx,
2954 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002955 true, &flags);
2956
2957 if (!rc) {
2958 if (flags &
2959 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2960 netif_info(efx, drv, efx->net_dev,
2961 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002962
2963 /* With MCFW v4.6.x and earlier, the
2964 * boot count will have incremented,
2965 * so re-read the warm_boot_count
2966 * value now to ensure this function
2967 * doesn't think it has changed next
2968 * time it checks.
2969 */
2970 rc = efx_ef10_get_warm_boot_count(efx);
2971 if (rc >= 0) {
2972 nic_data->warm_boot_count = rc;
2973 rc = 0;
2974 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002975 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002976 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002977 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002978 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002979 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002980 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002981 }
2982
2983 if (!rc)
2984 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002985
2986fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002987 efx_ef10_ev_fini(channel);
2988 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002989}
2990
2991static void efx_ef10_ev_remove(struct efx_channel *channel)
2992{
2993 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2994}
2995
2996static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2997 unsigned int rx_queue_label)
2998{
2999 struct efx_nic *efx = rx_queue->efx;
3000
3001 netif_info(efx, hw, efx->net_dev,
3002 "rx event arrived on queue %d labeled as queue %u\n",
3003 efx_rx_queue_index(rx_queue), rx_queue_label);
3004
3005 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3006}
3007
3008static void
3009efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3010 unsigned int actual, unsigned int expected)
3011{
3012 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3013 struct efx_nic *efx = rx_queue->efx;
3014
3015 netif_info(efx, hw, efx->net_dev,
3016 "dropped %d events (index=%d expected=%d)\n",
3017 dropped, actual, expected);
3018
3019 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3020}
3021
3022/* partially received RX was aborted. clean up. */
3023static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3024{
3025 unsigned int rx_desc_ptr;
3026
Ben Hutchings8127d662013-08-29 19:19:29 +01003027 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3028 "scattered RX aborted (dropping %u buffers)\n",
3029 rx_queue->scatter_n);
3030
3031 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3032
3033 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3034 0, EFX_RX_PKT_DISCARD);
3035
3036 rx_queue->removed_count += rx_queue->scatter_n;
3037 rx_queue->scatter_n = 0;
3038 rx_queue->scatter_len = 0;
3039 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3040}
3041
3042static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3043 const efx_qword_t *event)
3044{
3045 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
3046 unsigned int n_descs, n_packets, i;
3047 struct efx_nic *efx = channel->efx;
3048 struct efx_rx_queue *rx_queue;
3049 bool rx_cont;
3050 u16 flags = 0;
3051
3052 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3053 return 0;
3054
3055 /* Basic packet information */
3056 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3057 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3058 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3059 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3060 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3061
Ben Hutchings48ce5632013-11-01 16:42:44 +00003062 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3063 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3064 EFX_QWORD_FMT "\n",
3065 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003066
3067 rx_queue = efx_channel_get_rx_queue(channel);
3068
3069 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3070 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3071
3072 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3073 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3074
3075 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003076 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3077
Ben Hutchings8127d662013-08-29 19:19:29 +01003078 /* detect rx abort */
3079 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003080 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3081 netdev_WARN(efx->net_dev,
3082 "invalid RX abort: scatter_n=%u event="
3083 EFX_QWORD_FMT "\n",
3084 rx_queue->scatter_n,
3085 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003086 efx_ef10_handle_rx_abort(rx_queue);
3087 return 0;
3088 }
3089
Ben Hutchings92a04162013-09-24 23:21:57 +01003090 /* Check that RX completion merging is valid, i.e.
3091 * the current firmware supports it and this is a
3092 * non-scattered packet.
3093 */
3094 if (!(nic_data->datapath_caps &
3095 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3096 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003097 efx_ef10_handle_rx_bad_lbits(
3098 rx_queue, next_ptr_lbits,
3099 (rx_queue->removed_count +
3100 rx_queue->scatter_n + 1) &
3101 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3102 return 0;
3103 }
3104
3105 /* Merged completion for multiple non-scattered packets */
3106 rx_queue->scatter_n = 1;
3107 rx_queue->scatter_len = 0;
3108 n_packets = n_descs;
3109 ++channel->n_rx_merge_events;
3110 channel->n_rx_merge_packets += n_packets;
3111 flags |= EFX_RX_PKT_PREFIX_LEN;
3112 } else {
3113 ++rx_queue->scatter_n;
3114 rx_queue->scatter_len += rx_bytes;
3115 if (rx_cont)
3116 return 0;
3117 n_packets = 1;
3118 }
3119
3120 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
3121 flags |= EFX_RX_PKT_DISCARD;
3122
3123 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
3124 channel->n_rx_ip_hdr_chksum_err += n_packets;
3125 } else if (unlikely(EFX_QWORD_FIELD(*event,
3126 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
3127 channel->n_rx_tcp_udp_chksum_err += n_packets;
3128 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3129 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
3130 flags |= EFX_RX_PKT_CSUMMED;
3131 }
3132
3133 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3134 flags |= EFX_RX_PKT_TCP;
3135
3136 channel->irq_mod_score += 2 * n_packets;
3137
3138 /* Handle received packet(s) */
3139 for (i = 0; i < n_packets; i++) {
3140 efx_rx_packet(rx_queue,
3141 rx_queue->removed_count & rx_queue->ptr_mask,
3142 rx_queue->scatter_n, rx_queue->scatter_len,
3143 flags);
3144 rx_queue->removed_count += rx_queue->scatter_n;
3145 }
3146
3147 rx_queue->scatter_n = 0;
3148 rx_queue->scatter_len = 0;
3149
3150 return n_packets;
3151}
3152
3153static int
3154efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3155{
3156 struct efx_nic *efx = channel->efx;
3157 struct efx_tx_queue *tx_queue;
3158 unsigned int tx_ev_desc_ptr;
3159 unsigned int tx_ev_q_label;
3160 int tx_descs = 0;
3161
3162 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3163 return 0;
3164
3165 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3166 return 0;
3167
3168 /* Transmit completion */
3169 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3170 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3171 tx_queue = efx_channel_get_tx_queue(channel,
3172 tx_ev_q_label % EFX_TXQ_TYPES);
3173 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3174 tx_queue->ptr_mask);
3175 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3176
3177 return tx_descs;
3178}
3179
3180static void
3181efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3182{
3183 struct efx_nic *efx = channel->efx;
3184 int subcode;
3185
3186 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3187
3188 switch (subcode) {
3189 case ESE_DZ_DRV_TIMER_EV:
3190 case ESE_DZ_DRV_WAKE_UP_EV:
3191 break;
3192 case ESE_DZ_DRV_START_UP_EV:
3193 /* event queue init complete. ok. */
3194 break;
3195 default:
3196 netif_err(efx, hw, efx->net_dev,
3197 "channel %d unknown driver event type %d"
3198 " (data " EFX_QWORD_FMT ")\n",
3199 channel->channel, subcode,
3200 EFX_QWORD_VAL(*event));
3201
3202 }
3203}
3204
3205static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3206 efx_qword_t *event)
3207{
3208 struct efx_nic *efx = channel->efx;
3209 u32 subcode;
3210
3211 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3212
3213 switch (subcode) {
3214 case EFX_EF10_TEST:
3215 channel->event_test_cpu = raw_smp_processor_id();
3216 break;
3217 case EFX_EF10_REFILL:
3218 /* The queue must be empty, so we won't receive any rx
3219 * events, so efx_process_channel() won't refill the
3220 * queue. Refill it here
3221 */
Jon Coopercce28792013-10-02 11:04:14 +01003222 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003223 break;
3224 default:
3225 netif_err(efx, hw, efx->net_dev,
3226 "channel %d unknown driver event type %u"
3227 " (data " EFX_QWORD_FMT ")\n",
3228 channel->channel, (unsigned) subcode,
3229 EFX_QWORD_VAL(*event));
3230 }
3231}
3232
3233static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3234{
3235 struct efx_nic *efx = channel->efx;
3236 efx_qword_t event, *p_event;
3237 unsigned int read_ptr;
3238 int ev_code;
3239 int tx_descs = 0;
3240 int spent = 0;
3241
Eric W. Biederman75363a42014-03-14 18:11:22 -07003242 if (quota <= 0)
3243 return spent;
3244
Ben Hutchings8127d662013-08-29 19:19:29 +01003245 read_ptr = channel->eventq_read_ptr;
3246
3247 for (;;) {
3248 p_event = efx_event(channel, read_ptr);
3249 event = *p_event;
3250
3251 if (!efx_event_present(&event))
3252 break;
3253
3254 EFX_SET_QWORD(*p_event);
3255
3256 ++read_ptr;
3257
3258 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3259
3260 netif_vdbg(efx, drv, efx->net_dev,
3261 "processing event on %d " EFX_QWORD_FMT "\n",
3262 channel->channel, EFX_QWORD_VAL(event));
3263
3264 switch (ev_code) {
3265 case ESE_DZ_EV_CODE_MCDI_EV:
3266 efx_mcdi_process_event(channel, &event);
3267 break;
3268 case ESE_DZ_EV_CODE_RX_EV:
3269 spent += efx_ef10_handle_rx_event(channel, &event);
3270 if (spent >= quota) {
3271 /* XXX can we split a merged event to
3272 * avoid going over-quota?
3273 */
3274 spent = quota;
3275 goto out;
3276 }
3277 break;
3278 case ESE_DZ_EV_CODE_TX_EV:
3279 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3280 if (tx_descs > efx->txq_entries) {
3281 spent = quota;
3282 goto out;
3283 } else if (++spent == quota) {
3284 goto out;
3285 }
3286 break;
3287 case ESE_DZ_EV_CODE_DRIVER_EV:
3288 efx_ef10_handle_driver_event(channel, &event);
3289 if (++spent == quota)
3290 goto out;
3291 break;
3292 case EFX_EF10_DRVGEN_EV:
3293 efx_ef10_handle_driver_generated_event(channel, &event);
3294 break;
3295 default:
3296 netif_err(efx, hw, efx->net_dev,
3297 "channel %d unknown event type %d"
3298 " (data " EFX_QWORD_FMT ")\n",
3299 channel->channel, ev_code,
3300 EFX_QWORD_VAL(event));
3301 }
3302 }
3303
3304out:
3305 channel->eventq_read_ptr = read_ptr;
3306 return spent;
3307}
3308
3309static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3310{
3311 struct efx_nic *efx = channel->efx;
3312 efx_dword_t rptr;
3313
3314 if (EFX_EF10_WORKAROUND_35388(efx)) {
3315 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3316 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3317 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3318 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3319
3320 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3321 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3322 ERF_DD_EVQ_IND_RPTR,
3323 (channel->eventq_read_ptr &
3324 channel->eventq_mask) >>
3325 ERF_DD_EVQ_IND_RPTR_WIDTH);
3326 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3327 channel->channel);
3328 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3329 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3330 ERF_DD_EVQ_IND_RPTR,
3331 channel->eventq_read_ptr &
3332 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3333 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3334 channel->channel);
3335 } else {
3336 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3337 channel->eventq_read_ptr &
3338 channel->eventq_mask);
3339 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3340 }
3341}
3342
3343static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3344{
3345 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3346 struct efx_nic *efx = channel->efx;
3347 efx_qword_t event;
3348 int rc;
3349
3350 EFX_POPULATE_QWORD_2(event,
3351 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3352 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3353
3354 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3355
3356 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3357 * already swapped the data to little-endian order.
3358 */
3359 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3360 sizeof(efx_qword_t));
3361
3362 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3363 NULL, 0, NULL);
3364 if (rc != 0)
3365 goto fail;
3366
3367 return;
3368
3369fail:
3370 WARN_ON(true);
3371 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3372}
3373
3374void efx_ef10_handle_drain_event(struct efx_nic *efx)
3375{
3376 if (atomic_dec_and_test(&efx->active_queues))
3377 wake_up(&efx->flush_wq);
3378
3379 WARN_ON(atomic_read(&efx->active_queues) < 0);
3380}
3381
3382static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3383{
3384 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3385 struct efx_channel *channel;
3386 struct efx_tx_queue *tx_queue;
3387 struct efx_rx_queue *rx_queue;
3388 int pending;
3389
3390 /* If the MC has just rebooted, the TX/RX queues will have already been
3391 * torn down, but efx->active_queues needs to be set to zero.
3392 */
3393 if (nic_data->must_realloc_vis) {
3394 atomic_set(&efx->active_queues, 0);
3395 return 0;
3396 }
3397
3398 /* Do not attempt to write to the NIC during EEH recovery */
3399 if (efx->state != STATE_RECOVERY) {
3400 efx_for_each_channel(channel, efx) {
3401 efx_for_each_channel_rx_queue(rx_queue, channel)
3402 efx_ef10_rx_fini(rx_queue);
3403 efx_for_each_channel_tx_queue(tx_queue, channel)
3404 efx_ef10_tx_fini(tx_queue);
3405 }
3406
3407 wait_event_timeout(efx->flush_wq,
3408 atomic_read(&efx->active_queues) == 0,
3409 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3410 pending = atomic_read(&efx->active_queues);
3411 if (pending) {
3412 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3413 pending);
3414 return -ETIMEDOUT;
3415 }
3416 }
3417
3418 return 0;
3419}
3420
Edward Creee2835462014-04-16 19:27:48 +01003421static void efx_ef10_prepare_flr(struct efx_nic *efx)
3422{
3423 atomic_set(&efx->active_queues, 0);
3424}
3425
Ben Hutchings8127d662013-08-29 19:19:29 +01003426static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3427 const struct efx_filter_spec *right)
3428{
3429 if ((left->match_flags ^ right->match_flags) |
3430 ((left->flags ^ right->flags) &
3431 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3432 return false;
3433
3434 return memcmp(&left->outer_vid, &right->outer_vid,
3435 sizeof(struct efx_filter_spec) -
3436 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3437}
3438
3439static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3440{
3441 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3442 return jhash2((const u32 *)&spec->outer_vid,
3443 (sizeof(struct efx_filter_spec) -
3444 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3445 0);
3446 /* XXX should we randomise the initval? */
3447}
3448
3449/* Decide whether a filter should be exclusive or else should allow
3450 * delivery to additional recipients. Currently we decide that
3451 * filters for specific local unicast MAC and IP addresses are
3452 * exclusive.
3453 */
3454static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3455{
3456 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3457 !is_multicast_ether_addr(spec->loc_mac))
3458 return true;
3459
3460 if ((spec->match_flags &
3461 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3462 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3463 if (spec->ether_type == htons(ETH_P_IP) &&
3464 !ipv4_is_multicast(spec->loc_host[0]))
3465 return true;
3466 if (spec->ether_type == htons(ETH_P_IPV6) &&
3467 ((const u8 *)spec->loc_host)[0] != 0xff)
3468 return true;
3469 }
3470
3471 return false;
3472}
3473
3474static struct efx_filter_spec *
3475efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3476 unsigned int filter_idx)
3477{
3478 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3479 ~EFX_EF10_FILTER_FLAGS);
3480}
3481
3482static unsigned int
3483efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3484 unsigned int filter_idx)
3485{
3486 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3487}
3488
3489static void
3490efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3491 unsigned int filter_idx,
3492 const struct efx_filter_spec *spec,
3493 unsigned int flags)
3494{
3495 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3496}
3497
3498static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3499 const struct efx_filter_spec *spec,
3500 efx_dword_t *inbuf, u64 handle,
3501 bool replacing)
3502{
3503 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003504 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003505
3506 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3507
Jon Cooperdcb41232016-04-25 16:51:00 +01003508 /* Remove RSS flag if we don't have an RSS context. */
3509 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3510 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3511 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3512 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3513
Ben Hutchings8127d662013-08-29 19:19:29 +01003514 if (replacing) {
3515 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3516 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3517 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3518 } else {
3519 u32 match_fields = 0;
3520
3521 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3522 efx_ef10_filter_is_exclusive(spec) ?
3523 MC_CMD_FILTER_OP_IN_OP_INSERT :
3524 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3525
3526 /* Convert match flags and values. Unlike almost
3527 * everything else in MCDI, these fields are in
3528 * network byte order.
3529 */
3530 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3531 match_fields |=
3532 is_multicast_ether_addr(spec->loc_mac) ?
3533 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3534 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3535#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3536 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3537 match_fields |= \
3538 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3539 mcdi_field ## _LBN; \
3540 BUILD_BUG_ON( \
3541 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3542 sizeof(spec->gen_field)); \
3543 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3544 &spec->gen_field, sizeof(spec->gen_field)); \
3545 }
3546 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3547 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3548 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3549 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3550 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3551 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3552 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3553 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3554 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3555 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3556#undef COPY_FIELD
3557 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3558 match_fields);
3559 }
3560
Daniel Pieczko45b24492015-05-06 00:57:14 +01003561 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003562 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3563 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3564 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3565 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003566 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003567 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3568 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003569 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3570 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3571 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003572 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003573 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003574 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3575 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003576 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003577 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3578 spec->rss_context !=
3579 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3580 spec->rss_context : nic_data->rx_rss_context);
3581}
3582
3583static int efx_ef10_filter_push(struct efx_nic *efx,
3584 const struct efx_filter_spec *spec,
3585 u64 *handle, bool replacing)
3586{
3587 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3588 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3589 int rc;
3590
3591 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3592 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3593 outbuf, sizeof(outbuf), NULL);
3594 if (rc == 0)
3595 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003596 if (rc == -ENOSPC)
3597 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003598 return rc;
3599}
3600
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003601static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003602{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003603 unsigned int match_flags = spec->match_flags;
3604 u32 mcdi_flags = 0;
3605
3606 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3607 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3608 mcdi_flags |=
3609 is_multicast_ether_addr(spec->loc_mac) ?
3610 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3611 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3612 }
3613
3614#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3615 unsigned int old_match_flags = match_flags; \
3616 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3617 if (match_flags != old_match_flags) \
3618 mcdi_flags |= \
3619 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3620 mcdi_field ## _LBN); \
3621 }
3622 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3623 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3624 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3625 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3626 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3627 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3628 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3629 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3630 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3631 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3632#undef MAP_FILTER_TO_MCDI_FLAG
3633
3634 /* Did we map them all? */
3635 WARN_ON_ONCE(match_flags);
3636
3637 return mcdi_flags;
3638}
3639
3640static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3641 const struct efx_filter_spec *spec)
3642{
3643 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003644 unsigned int match_pri;
3645
3646 for (match_pri = 0;
3647 match_pri < table->rx_match_count;
3648 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003649 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003650 return match_pri;
3651
3652 return -EPROTONOSUPPORT;
3653}
3654
3655static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3656 struct efx_filter_spec *spec,
3657 bool replace_equal)
3658{
3659 struct efx_ef10_filter_table *table = efx->filter_state;
3660 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3661 struct efx_filter_spec *saved_spec;
3662 unsigned int match_pri, hash;
3663 unsigned int priv_flags;
3664 bool replacing = false;
3665 int ins_index = -1;
3666 DEFINE_WAIT(wait);
3667 bool is_mc_recip;
3668 s32 rc;
3669
3670 /* For now, only support RX filters */
3671 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3672 EFX_FILTER_FLAG_RX)
3673 return -EINVAL;
3674
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003675 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003676 if (rc < 0)
3677 return rc;
3678 match_pri = rc;
3679
3680 hash = efx_ef10_filter_hash(spec);
3681 is_mc_recip = efx_filter_is_mc_recipient(spec);
3682 if (is_mc_recip)
3683 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3684
3685 /* Find any existing filters with the same match tuple or
3686 * else a free slot to insert at. If any of them are busy,
3687 * we have to wait and retry.
3688 */
3689 for (;;) {
3690 unsigned int depth = 1;
3691 unsigned int i;
3692
3693 spin_lock_bh(&efx->filter_lock);
3694
3695 for (;;) {
3696 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3697 saved_spec = efx_ef10_filter_entry_spec(table, i);
3698
3699 if (!saved_spec) {
3700 if (ins_index < 0)
3701 ins_index = i;
3702 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3703 if (table->entry[i].spec &
3704 EFX_EF10_FILTER_FLAG_BUSY)
3705 break;
3706 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003707 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003708 rc = -EPERM;
3709 goto out_unlock;
3710 }
3711 if (!is_mc_recip) {
3712 /* This is the only one */
3713 if (spec->priority ==
3714 saved_spec->priority &&
3715 !replace_equal) {
3716 rc = -EEXIST;
3717 goto out_unlock;
3718 }
3719 ins_index = i;
3720 goto found;
3721 } else if (spec->priority >
3722 saved_spec->priority ||
3723 (spec->priority ==
3724 saved_spec->priority &&
3725 replace_equal)) {
3726 if (ins_index < 0)
3727 ins_index = i;
3728 else
3729 __set_bit(depth, mc_rem_map);
3730 }
3731 }
3732
3733 /* Once we reach the maximum search depth, use
3734 * the first suitable slot or return -EBUSY if
3735 * there was none
3736 */
3737 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3738 if (ins_index < 0) {
3739 rc = -EBUSY;
3740 goto out_unlock;
3741 }
3742 goto found;
3743 }
3744
3745 ++depth;
3746 }
3747
3748 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3749 spin_unlock_bh(&efx->filter_lock);
3750 schedule();
3751 }
3752
3753found:
3754 /* Create a software table entry if necessary, and mark it
3755 * busy. We might yet fail to insert, but any attempt to
3756 * insert a conflicting filter while we're waiting for the
3757 * firmware must find the busy entry.
3758 */
3759 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3760 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003761 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3762 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003763 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003764 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3765 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003766 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003767 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003768 rc = ins_index;
3769 goto out_unlock;
3770 }
3771 replacing = true;
3772 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3773 } else {
3774 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3775 if (!saved_spec) {
3776 rc = -ENOMEM;
3777 goto out_unlock;
3778 }
3779 *saved_spec = *spec;
3780 priv_flags = 0;
3781 }
3782 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3783 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3784
3785 /* Mark lower-priority multicast recipients busy prior to removal */
3786 if (is_mc_recip) {
3787 unsigned int depth, i;
3788
3789 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3790 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3791 if (test_bit(depth, mc_rem_map))
3792 table->entry[i].spec |=
3793 EFX_EF10_FILTER_FLAG_BUSY;
3794 }
3795 }
3796
3797 spin_unlock_bh(&efx->filter_lock);
3798
3799 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3800 replacing);
3801
3802 /* Finalise the software table entry */
3803 spin_lock_bh(&efx->filter_lock);
3804 if (rc == 0) {
3805 if (replacing) {
3806 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003807 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3808 saved_spec->flags |=
3809 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003810 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003811 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003812 saved_spec->flags |= spec->flags;
3813 saved_spec->rss_context = spec->rss_context;
3814 saved_spec->dmaq_id = spec->dmaq_id;
3815 }
3816 } else if (!replacing) {
3817 kfree(saved_spec);
3818 saved_spec = NULL;
3819 }
3820 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3821
3822 /* Remove and finalise entries for lower-priority multicast
3823 * recipients
3824 */
3825 if (is_mc_recip) {
3826 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3827 unsigned int depth, i;
3828
3829 memset(inbuf, 0, sizeof(inbuf));
3830
3831 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3832 if (!test_bit(depth, mc_rem_map))
3833 continue;
3834
3835 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3836 saved_spec = efx_ef10_filter_entry_spec(table, i);
3837 priv_flags = efx_ef10_filter_entry_flags(table, i);
3838
3839 if (rc == 0) {
3840 spin_unlock_bh(&efx->filter_lock);
3841 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3842 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3843 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3844 table->entry[i].handle);
3845 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3846 inbuf, sizeof(inbuf),
3847 NULL, 0, NULL);
3848 spin_lock_bh(&efx->filter_lock);
3849 }
3850
3851 if (rc == 0) {
3852 kfree(saved_spec);
3853 saved_spec = NULL;
3854 priv_flags = 0;
3855 } else {
3856 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3857 }
3858 efx_ef10_filter_set_entry(table, i, saved_spec,
3859 priv_flags);
3860 }
3861 }
3862
3863 /* If successful, return the inserted filter ID */
3864 if (rc == 0)
3865 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3866
3867 wake_up_all(&table->waitq);
3868out_unlock:
3869 spin_unlock_bh(&efx->filter_lock);
3870 finish_wait(&table->waitq, &wait);
3871 return rc;
3872}
3873
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003874static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003875{
3876 /* no need to do anything here on EF10 */
3877}
3878
3879/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003880 * If !by_index, remove by ID
3881 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003882 * Filter ID may come from userland and must be range-checked.
3883 */
3884static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003885 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003886 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003887{
3888 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3889 struct efx_ef10_filter_table *table = efx->filter_state;
3890 MCDI_DECLARE_BUF(inbuf,
3891 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3892 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3893 struct efx_filter_spec *spec;
3894 DEFINE_WAIT(wait);
3895 int rc;
3896
3897 /* Find the software table entry and mark it busy. Don't
3898 * remove it yet; any attempt to update while we're waiting
3899 * for the firmware must find the busy entry.
3900 */
3901 for (;;) {
3902 spin_lock_bh(&efx->filter_lock);
3903 if (!(table->entry[filter_idx].spec &
3904 EFX_EF10_FILTER_FLAG_BUSY))
3905 break;
3906 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3907 spin_unlock_bh(&efx->filter_lock);
3908 schedule();
3909 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003910
Ben Hutchings8127d662013-08-29 19:19:29 +01003911 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003912 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003913 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003914 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003915 filter_id / HUNT_FILTER_TBL_ROWS)) {
3916 rc = -ENOENT;
3917 goto out_unlock;
3918 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003919
3920 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003921 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003922 /* Just remove flags */
3923 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003924 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003925 rc = 0;
3926 goto out_unlock;
3927 }
3928
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003929 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003930 rc = -ENOENT;
3931 goto out_unlock;
3932 }
3933
Ben Hutchings8127d662013-08-29 19:19:29 +01003934 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3935 spin_unlock_bh(&efx->filter_lock);
3936
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003937 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003938 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003939
3940 struct efx_filter_spec new_spec = *spec;
3941
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003942 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003943 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003944 (efx_rss_enabled(efx) ?
3945 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003946 new_spec.dmaq_id = 0;
3947 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3948 rc = efx_ef10_filter_push(efx, &new_spec,
3949 &table->entry[filter_idx].handle,
3950 true);
3951
3952 spin_lock_bh(&efx->filter_lock);
3953 if (rc == 0)
3954 *spec = new_spec;
3955 } else {
3956 /* Really remove the filter */
3957
3958 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3959 efx_ef10_filter_is_exclusive(spec) ?
3960 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3961 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3962 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3963 table->entry[filter_idx].handle);
3964 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3965 inbuf, sizeof(inbuf), NULL, 0, NULL);
3966
3967 spin_lock_bh(&efx->filter_lock);
3968 if (rc == 0) {
3969 kfree(spec);
3970 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3971 }
3972 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003973
Ben Hutchings8127d662013-08-29 19:19:29 +01003974 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3975 wake_up_all(&table->waitq);
3976out_unlock:
3977 spin_unlock_bh(&efx->filter_lock);
3978 finish_wait(&table->waitq, &wait);
3979 return rc;
3980}
3981
3982static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3983 enum efx_filter_priority priority,
3984 u32 filter_id)
3985{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003986 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3987 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003988}
3989
Edward Cree12fb0da2015-07-21 15:11:00 +01003990static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
3991{
3992 return filter_id % HUNT_FILTER_TBL_ROWS;
3993}
3994
Edward Cree8c915622016-06-15 17:49:05 +01003995static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
3996 enum efx_filter_priority priority,
3997 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01003998{
Edward Cree8c915622016-06-15 17:49:05 +01003999 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4000 return;
4001 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004002}
4003
Ben Hutchings8127d662013-08-29 19:19:29 +01004004static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4005 enum efx_filter_priority priority,
4006 u32 filter_id, struct efx_filter_spec *spec)
4007{
4008 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4009 struct efx_ef10_filter_table *table = efx->filter_state;
4010 const struct efx_filter_spec *saved_spec;
4011 int rc;
4012
4013 spin_lock_bh(&efx->filter_lock);
4014 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4015 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004016 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004017 filter_id / HUNT_FILTER_TBL_ROWS) {
4018 *spec = *saved_spec;
4019 rc = 0;
4020 } else {
4021 rc = -ENOENT;
4022 }
4023 spin_unlock_bh(&efx->filter_lock);
4024 return rc;
4025}
4026
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004027static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004028 enum efx_filter_priority priority)
4029{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004030 unsigned int priority_mask;
4031 unsigned int i;
4032 int rc;
4033
4034 priority_mask = (((1U << (priority + 1)) - 1) &
4035 ~(1U << EFX_FILTER_PRI_AUTO));
4036
4037 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4038 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4039 i, true);
4040 if (rc && rc != -ENOENT)
4041 return rc;
4042 }
4043
4044 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004045}
4046
4047static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4048 enum efx_filter_priority priority)
4049{
4050 struct efx_ef10_filter_table *table = efx->filter_state;
4051 unsigned int filter_idx;
4052 s32 count = 0;
4053
4054 spin_lock_bh(&efx->filter_lock);
4055 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4056 if (table->entry[filter_idx].spec &&
4057 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4058 priority)
4059 ++count;
4060 }
4061 spin_unlock_bh(&efx->filter_lock);
4062 return count;
4063}
4064
4065static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4066{
4067 struct efx_ef10_filter_table *table = efx->filter_state;
4068
4069 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4070}
4071
4072static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4073 enum efx_filter_priority priority,
4074 u32 *buf, u32 size)
4075{
4076 struct efx_ef10_filter_table *table = efx->filter_state;
4077 struct efx_filter_spec *spec;
4078 unsigned int filter_idx;
4079 s32 count = 0;
4080
4081 spin_lock_bh(&efx->filter_lock);
4082 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4083 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4084 if (spec && spec->priority == priority) {
4085 if (count == size) {
4086 count = -EMSGSIZE;
4087 break;
4088 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004089 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004090 HUNT_FILTER_TBL_ROWS +
4091 filter_idx);
4092 }
4093 }
4094 spin_unlock_bh(&efx->filter_lock);
4095 return count;
4096}
4097
4098#ifdef CONFIG_RFS_ACCEL
4099
4100static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4101
4102static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4103 struct efx_filter_spec *spec)
4104{
4105 struct efx_ef10_filter_table *table = efx->filter_state;
4106 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4107 struct efx_filter_spec *saved_spec;
4108 unsigned int hash, i, depth = 1;
4109 bool replacing = false;
4110 int ins_index = -1;
4111 u64 cookie;
4112 s32 rc;
4113
4114 /* Must be an RX filter without RSS and not for a multicast
4115 * destination address (RFS only works for connected sockets).
4116 * These restrictions allow us to pass only a tiny amount of
4117 * data through to the completion function.
4118 */
4119 EFX_WARN_ON_PARANOID(spec->flags !=
4120 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4121 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4122 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4123
4124 hash = efx_ef10_filter_hash(spec);
4125
4126 spin_lock_bh(&efx->filter_lock);
4127
4128 /* Find any existing filter with the same match tuple or else
4129 * a free slot to insert at. If an existing filter is busy,
4130 * we have to give up.
4131 */
4132 for (;;) {
4133 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4134 saved_spec = efx_ef10_filter_entry_spec(table, i);
4135
4136 if (!saved_spec) {
4137 if (ins_index < 0)
4138 ins_index = i;
4139 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4140 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4141 rc = -EBUSY;
4142 goto fail_unlock;
4143 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004144 if (spec->priority < saved_spec->priority) {
4145 rc = -EPERM;
4146 goto fail_unlock;
4147 }
4148 ins_index = i;
4149 break;
4150 }
4151
4152 /* Once we reach the maximum search depth, use the
4153 * first suitable slot or return -EBUSY if there was
4154 * none
4155 */
4156 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4157 if (ins_index < 0) {
4158 rc = -EBUSY;
4159 goto fail_unlock;
4160 }
4161 break;
4162 }
4163
4164 ++depth;
4165 }
4166
4167 /* Create a software table entry if necessary, and mark it
4168 * busy. We might yet fail to insert, but any attempt to
4169 * insert a conflicting filter while we're waiting for the
4170 * firmware must find the busy entry.
4171 */
4172 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4173 if (saved_spec) {
4174 replacing = true;
4175 } else {
4176 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4177 if (!saved_spec) {
4178 rc = -ENOMEM;
4179 goto fail_unlock;
4180 }
4181 *saved_spec = *spec;
4182 }
4183 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4184 EFX_EF10_FILTER_FLAG_BUSY);
4185
4186 spin_unlock_bh(&efx->filter_lock);
4187
4188 /* Pack up the variables needed on completion */
4189 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4190
4191 efx_ef10_filter_push_prep(efx, spec, inbuf,
4192 table->entry[ins_index].handle, replacing);
4193 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4194 MC_CMD_FILTER_OP_OUT_LEN,
4195 efx_ef10_filter_rfs_insert_complete, cookie);
4196
4197 return ins_index;
4198
4199fail_unlock:
4200 spin_unlock_bh(&efx->filter_lock);
4201 return rc;
4202}
4203
4204static void
4205efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4206 int rc, efx_dword_t *outbuf,
4207 size_t outlen_actual)
4208{
4209 struct efx_ef10_filter_table *table = efx->filter_state;
4210 unsigned int ins_index, dmaq_id;
4211 struct efx_filter_spec *spec;
4212 bool replacing;
4213
4214 /* Unpack the cookie */
4215 replacing = cookie >> 31;
4216 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4217 dmaq_id = cookie & 0xffff;
4218
4219 spin_lock_bh(&efx->filter_lock);
4220 spec = efx_ef10_filter_entry_spec(table, ins_index);
4221 if (rc == 0) {
4222 table->entry[ins_index].handle =
4223 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4224 if (replacing)
4225 spec->dmaq_id = dmaq_id;
4226 } else if (!replacing) {
4227 kfree(spec);
4228 spec = NULL;
4229 }
4230 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4231 spin_unlock_bh(&efx->filter_lock);
4232
4233 wake_up_all(&table->waitq);
4234}
4235
4236static void
4237efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4238 unsigned long filter_idx,
4239 int rc, efx_dword_t *outbuf,
4240 size_t outlen_actual);
4241
4242static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4243 unsigned int filter_idx)
4244{
4245 struct efx_ef10_filter_table *table = efx->filter_state;
4246 struct efx_filter_spec *spec =
4247 efx_ef10_filter_entry_spec(table, filter_idx);
4248 MCDI_DECLARE_BUF(inbuf,
4249 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4250 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4251
4252 if (!spec ||
4253 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4254 spec->priority != EFX_FILTER_PRI_HINT ||
4255 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4256 flow_id, filter_idx))
4257 return false;
4258
4259 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4260 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4261 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4262 table->entry[filter_idx].handle);
4263 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4264 efx_ef10_filter_rfs_expire_complete, filter_idx))
4265 return false;
4266
4267 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4268 return true;
4269}
4270
4271static void
4272efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4273 unsigned long filter_idx,
4274 int rc, efx_dword_t *outbuf,
4275 size_t outlen_actual)
4276{
4277 struct efx_ef10_filter_table *table = efx->filter_state;
4278 struct efx_filter_spec *spec =
4279 efx_ef10_filter_entry_spec(table, filter_idx);
4280
4281 spin_lock_bh(&efx->filter_lock);
4282 if (rc == 0) {
4283 kfree(spec);
4284 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4285 }
4286 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4287 wake_up_all(&table->waitq);
4288 spin_unlock_bh(&efx->filter_lock);
4289}
4290
4291#endif /* CONFIG_RFS_ACCEL */
4292
4293static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4294{
4295 int match_flags = 0;
4296
4297#define MAP_FLAG(gen_flag, mcdi_field) { \
4298 u32 old_mcdi_flags = mcdi_flags; \
4299 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4300 mcdi_field ## _LBN); \
4301 if (mcdi_flags != old_mcdi_flags) \
4302 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4303 }
4304 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4305 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4306 MAP_FLAG(REM_HOST, SRC_IP);
4307 MAP_FLAG(LOC_HOST, DST_IP);
4308 MAP_FLAG(REM_MAC, SRC_MAC);
4309 MAP_FLAG(REM_PORT, SRC_PORT);
4310 MAP_FLAG(LOC_MAC, DST_MAC);
4311 MAP_FLAG(LOC_PORT, DST_PORT);
4312 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4313 MAP_FLAG(INNER_VID, INNER_VLAN);
4314 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4315 MAP_FLAG(IP_PROTO, IP_PROTO);
4316#undef MAP_FLAG
4317
4318 /* Did we map them all? */
4319 if (mcdi_flags)
4320 return -EINVAL;
4321
4322 return match_flags;
4323}
4324
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004325static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4326{
4327 struct efx_ef10_filter_table *table = efx->filter_state;
4328 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4329
4330 /* See comment in efx_ef10_filter_table_remove() */
4331 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4332 return;
4333
4334 if (!table)
4335 return;
4336
4337 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4338 efx_ef10_filter_del_vlan_internal(efx, vlan);
4339}
4340
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004341static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4342 enum efx_filter_match_flags match_flags)
4343{
4344 unsigned int match_pri;
4345 int mf;
4346
4347 for (match_pri = 0;
4348 match_pri < table->rx_match_count;
4349 match_pri++) {
4350 mf = efx_ef10_filter_match_flags_from_mcdi(
4351 table->rx_match_mcdi_flags[match_pri]);
4352 if (mf == match_flags)
4353 return true;
4354 }
4355
4356 return false;
4357}
4358
Ben Hutchings8127d662013-08-29 19:19:29 +01004359static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4360{
4361 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4362 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004363 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004364 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004365 unsigned int pd_match_pri, pd_match_count;
4366 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004367 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004368 size_t outlen;
4369 int rc;
4370
Edward Creedd987082016-06-15 17:43:43 +01004371 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4372 return -EINVAL;
4373
4374 if (efx->filter_state) /* already probed */
4375 return 0;
4376
Ben Hutchings8127d662013-08-29 19:19:29 +01004377 table = kzalloc(sizeof(*table), GFP_KERNEL);
4378 if (!table)
4379 return -ENOMEM;
4380
4381 /* Find out which RX filter types are supported, and their priorities */
4382 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4383 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4384 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4385 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4386 &outlen);
4387 if (rc)
4388 goto fail;
4389 pd_match_count = MCDI_VAR_ARRAY_LEN(
4390 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4391 table->rx_match_count = 0;
4392
4393 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4394 u32 mcdi_flags =
4395 MCDI_ARRAY_DWORD(
4396 outbuf,
4397 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4398 pd_match_pri);
4399 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4400 if (rc < 0) {
4401 netif_dbg(efx, probe, efx->net_dev,
4402 "%s: fw flags %#x pri %u not supported in driver\n",
4403 __func__, mcdi_flags, pd_match_pri);
4404 } else {
4405 netif_dbg(efx, probe, efx->net_dev,
4406 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4407 __func__, mcdi_flags, pd_match_pri,
4408 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004409 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4410 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004411 }
4412 }
4413
Martin Habetse4478ad2016-06-15 17:51:07 +01004414 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4415 !(efx_ef10_filter_match_supported(table,
4416 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4417 efx_ef10_filter_match_supported(table,
4418 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4419 netif_info(efx, probe, net_dev,
4420 "VLAN filters are not supported in this firmware variant\n");
4421 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4422 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4423 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4424 }
4425
Ben Hutchings8127d662013-08-29 19:19:29 +01004426 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4427 if (!table->entry) {
4428 rc = -ENOMEM;
4429 goto fail;
4430 }
4431
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004432 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004433 table->vlan_filter =
4434 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004435 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004436
Ben Hutchings8127d662013-08-29 19:19:29 +01004437 efx->filter_state = table;
4438 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004439
4440 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4441 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4442 if (rc)
4443 goto fail_add_vlan;
4444 }
4445
Ben Hutchings8127d662013-08-29 19:19:29 +01004446 return 0;
4447
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004448fail_add_vlan:
4449 efx_ef10_filter_cleanup_vlans(efx);
4450 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004451fail:
4452 kfree(table);
4453 return rc;
4454}
4455
Edward Cree0d322412015-05-20 11:10:03 +01004456/* Caller must hold efx->filter_sem for read if race against
4457 * efx_ef10_filter_table_remove() is possible
4458 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004459static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4460{
4461 struct efx_ef10_filter_table *table = efx->filter_state;
4462 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4463 struct efx_filter_spec *spec;
4464 unsigned int filter_idx;
4465 bool failed = false;
4466 int rc;
4467
Edward Cree0d322412015-05-20 11:10:03 +01004468 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4469
Ben Hutchings8127d662013-08-29 19:19:29 +01004470 if (!nic_data->must_restore_filters)
4471 return;
4472
Edward Cree0d322412015-05-20 11:10:03 +01004473 if (!table)
4474 return;
4475
Ben Hutchings8127d662013-08-29 19:19:29 +01004476 spin_lock_bh(&efx->filter_lock);
4477
4478 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4479 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4480 if (!spec)
4481 continue;
4482
4483 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4484 spin_unlock_bh(&efx->filter_lock);
4485
4486 rc = efx_ef10_filter_push(efx, spec,
4487 &table->entry[filter_idx].handle,
4488 false);
4489 if (rc)
4490 failed = true;
4491
4492 spin_lock_bh(&efx->filter_lock);
4493 if (rc) {
4494 kfree(spec);
4495 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4496 } else {
4497 table->entry[filter_idx].spec &=
4498 ~EFX_EF10_FILTER_FLAG_BUSY;
4499 }
4500 }
4501
4502 spin_unlock_bh(&efx->filter_lock);
4503
4504 if (failed)
4505 netif_err(efx, hw, efx->net_dev,
4506 "unable to restore all filters\n");
4507 else
4508 nic_data->must_restore_filters = false;
4509}
4510
4511static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4512{
4513 struct efx_ef10_filter_table *table = efx->filter_state;
4514 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4515 struct efx_filter_spec *spec;
4516 unsigned int filter_idx;
4517 int rc;
4518
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004519 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004520 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004521 /* If we were called without locking, then it's not safe to free
4522 * the table as others might be using it. So we just WARN, leak
4523 * the memory, and potentially get an inconsistent filter table
4524 * state.
4525 * This should never actually happen.
4526 */
4527 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4528 return;
4529
Edward Cree0d322412015-05-20 11:10:03 +01004530 if (!table)
4531 return;
4532
Ben Hutchings8127d662013-08-29 19:19:29 +01004533 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4534 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4535 if (!spec)
4536 continue;
4537
4538 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4539 efx_ef10_filter_is_exclusive(spec) ?
4540 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4541 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4542 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4543 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004544 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4545 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004546 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004547 netif_info(efx, drv, efx->net_dev,
4548 "%s: filter %04x remove failed\n",
4549 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004550 kfree(spec);
4551 }
4552
4553 vfree(table->entry);
4554 kfree(table);
4555}
4556
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004557static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4558{
4559 struct efx_ef10_filter_table *table = efx->filter_state;
4560 unsigned int filter_idx;
4561
4562 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4563 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4564 if (!table->entry[filter_idx].spec)
4565 netif_dbg(efx, drv, efx->net_dev,
4566 "marked null spec old %04x:%04x\n", *id,
4567 filter_idx);
4568 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4569 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004570 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004571}
4572
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004573/* Mark old per-VLAN filters that may need to be removed */
4574static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4575 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004576{
4577 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004578 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004579
Edward Cree12fb0da2015-07-21 15:11:00 +01004580 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004581 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004582 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004583 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4584 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4585 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4586 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004587}
4588
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004589/* Mark old filters that may need to be removed.
4590 * Caller must hold efx->filter_sem for read if race against
4591 * efx_ef10_filter_table_remove() is possible
4592 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004593static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4594{
4595 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004596 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004597
4598 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004599 list_for_each_entry(vlan, &table->vlan_list, list)
4600 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004601 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004602}
Ben Hutchings8127d662013-08-29 19:19:29 +01004603
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004604static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004605{
4606 struct efx_ef10_filter_table *table = efx->filter_state;
4607 struct net_device *net_dev = efx->net_dev;
4608 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004609 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004610 unsigned int i;
4611
Edward Cree12fb0da2015-07-21 15:11:00 +01004612 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004613 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004614 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004615 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4616 i = 1;
4617 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004618 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004619 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004620 break;
4621 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004622 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4623 i++;
4624 }
4625}
4626
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004627static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004628{
4629 struct efx_ef10_filter_table *table = efx->filter_state;
4630 struct net_device *net_dev = efx->net_dev;
4631 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004632 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004633
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004634 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004635
Edward Cree12fb0da2015-07-21 15:11:00 +01004636 addr_count = netdev_mc_count(net_dev);
4637 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004638 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004639 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004640 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004641 break;
4642 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004643 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4644 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004645 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004646
4647 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004648}
Ben Hutchings8127d662013-08-29 19:19:29 +01004649
Edward Cree12fb0da2015-07-21 15:11:00 +01004650static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004651 struct efx_ef10_filter_vlan *vlan,
4652 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004653{
4654 struct efx_ef10_filter_table *table = efx->filter_state;
4655 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004656 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004657 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004658 u8 baddr[ETH_ALEN];
4659 unsigned int i, j;
4660 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004661 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004662 int rc;
4663
4664 if (multicast) {
4665 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004666 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004667 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004668 } else {
4669 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004670 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004671 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004672 }
4673
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004674 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4675
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004676 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004677 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004678 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004679 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004680 rc = efx_ef10_filter_insert(efx, &spec, true);
4681 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004682 if (rollback) {
4683 netif_info(efx, drv, efx->net_dev,
4684 "efx_ef10_filter_insert failed rc=%d\n",
4685 rc);
4686 /* Fall back to promiscuous */
4687 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004688 efx_ef10_filter_remove_unsafe(
4689 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004690 ids[j]);
4691 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004692 }
4693 return rc;
4694 } else {
4695 /* mark as not inserted, and carry on */
4696 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004697 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004698 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004699 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004700 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004701
Edward Cree12fb0da2015-07-21 15:11:00 +01004702 if (multicast && rollback) {
4703 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004704 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004705 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004706 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004707 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004708 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004709 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004710 "Broadcast filter insert failed rc=%d\n", rc);
4711 /* Fall back to promiscuous */
4712 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004713 efx_ef10_filter_remove_unsafe(
4714 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004715 ids[j]);
4716 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004717 }
4718 return rc;
4719 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004720 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004721 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004722 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004723 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004724 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004725
4726 return 0;
4727}
4728
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004729static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4730 struct efx_ef10_filter_vlan *vlan,
4731 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004732{
Edward Cree12fb0da2015-07-21 15:11:00 +01004733 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004734 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004735 struct efx_filter_spec spec;
4736 u8 baddr[ETH_ALEN];
4737 int rc;
4738
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004739 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4740
4741 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004742
4743 if (multicast)
4744 efx_filter_set_mc_def(&spec);
4745 else
4746 efx_filter_set_uc_def(&spec);
4747
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004748 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4749 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4750
Edward Cree12fb0da2015-07-21 15:11:00 +01004751 rc = efx_ef10_filter_insert(efx, &spec, true);
4752 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004753 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4754 efx->net_dev,
4755 "%scast mismatch filter insert failed rc=%d\n",
4756 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004757 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004758 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4759 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004760 if (!nic_data->workaround_26807) {
4761 /* Also need an Ethernet broadcast filter */
4762 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004763 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004764 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004765 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004766 rc = efx_ef10_filter_insert(efx, &spec, true);
4767 if (rc < 0) {
4768 netif_warn(efx, drv, efx->net_dev,
4769 "Broadcast filter insert failed rc=%d\n",
4770 rc);
4771 if (rollback) {
4772 /* Roll back the mc_def filter */
4773 efx_ef10_filter_remove_unsafe(
4774 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004775 vlan->mcdef);
4776 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004777 return rc;
4778 }
4779 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004780 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004781 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004782 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004783 }
4784 }
4785 rc = 0;
4786 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004787 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4788 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004789 rc = 0;
4790 }
4791 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004792}
4793
4794/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4795 * flag or removes these filters, we don't need to hold the filter_lock while
4796 * scanning for these filters.
4797 */
4798static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4799{
4800 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004801 int remove_failed = 0;
4802 int remove_noent = 0;
4803 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004804 int i;
4805
Ben Hutchings8127d662013-08-29 19:19:29 +01004806 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4807 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004808 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004809 rc = efx_ef10_filter_remove_internal(efx,
4810 1U << EFX_FILTER_PRI_AUTO, i, true);
4811 if (rc == -ENOENT)
4812 remove_noent++;
4813 else if (rc)
4814 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004815 }
4816 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004817
4818 if (remove_failed)
4819 netif_info(efx, drv, efx->net_dev,
4820 "%s: failed to remove %d filters\n",
4821 __func__, remove_failed);
4822 if (remove_noent)
4823 netif_info(efx, drv, efx->net_dev,
4824 "%s: failed to remove %d non-existent filters\n",
4825 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004826}
4827
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004828static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4829{
4830 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4831 u8 mac_old[ETH_ALEN];
4832 int rc, rc2;
4833
4834 /* Only reconfigure a PF-created vport */
4835 if (is_zero_ether_addr(nic_data->vport_mac))
4836 return 0;
4837
4838 efx_device_detach_sync(efx);
4839 efx_net_stop(efx->net_dev);
4840 down_write(&efx->filter_sem);
4841 efx_ef10_filter_table_remove(efx);
4842 up_write(&efx->filter_sem);
4843
4844 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4845 if (rc)
4846 goto restore_filters;
4847
4848 ether_addr_copy(mac_old, nic_data->vport_mac);
4849 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4850 nic_data->vport_mac);
4851 if (rc)
4852 goto restore_vadaptor;
4853
4854 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4855 efx->net_dev->dev_addr);
4856 if (!rc) {
4857 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4858 } else {
4859 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4860 if (rc2) {
4861 /* Failed to add original MAC, so clear vport_mac */
4862 eth_zero_addr(nic_data->vport_mac);
4863 goto reset_nic;
4864 }
4865 }
4866
4867restore_vadaptor:
4868 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4869 if (rc2)
4870 goto reset_nic;
4871restore_filters:
4872 down_write(&efx->filter_sem);
4873 rc2 = efx_ef10_filter_table_probe(efx);
4874 up_write(&efx->filter_sem);
4875 if (rc2)
4876 goto reset_nic;
4877
4878 rc2 = efx_net_open(efx->net_dev);
4879 if (rc2)
4880 goto reset_nic;
4881
4882 netif_device_attach(efx->net_dev);
4883
4884 return rc;
4885
4886reset_nic:
4887 netif_err(efx, drv, efx->net_dev,
4888 "Failed to restore when changing MAC address - scheduling reset\n");
4889 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4890
4891 return rc ? rc : rc2;
4892}
4893
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004894/* Caller must hold efx->filter_sem for read if race against
4895 * efx_ef10_filter_table_remove() is possible
4896 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004897static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4898 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004899{
4900 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004901 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004902
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004903 /* Do not install unspecified VID if VLAN filtering is enabled.
4904 * Do not install all specified VIDs if VLAN filtering is disabled.
4905 */
4906 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4907 return;
4908
Edward Cree12fb0da2015-07-21 15:11:00 +01004909 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004910 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004911 efx_ef10_filter_insert_def(efx, vlan, false, false);
4912 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004913 } else {
4914 /* If any of the filters failed to insert, fall back to
4915 * promiscuous mode - add in the uc_def filter. But keep
4916 * our individual unicast filters.
4917 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004918 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4919 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004920 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004921
Edward Cree12fb0da2015-07-21 15:11:00 +01004922 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004923 /* If changing promiscuous state with cascaded multicast filters, remove
4924 * old filters first, so that packets are dropped rather than duplicated
4925 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004926 if (nic_data->workaround_26807 &&
4927 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004928 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004929 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004930 if (nic_data->workaround_26807) {
4931 /* If we failed to insert promiscuous filters, rollback
4932 * and fall back to individual multicast filters
4933 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004934 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004935 /* Changing promisc state, so remove old filters */
4936 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004937 efx_ef10_filter_insert_addr_list(efx, vlan,
4938 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004939 }
4940 } else {
4941 /* If we failed to insert promiscuous filters, don't
4942 * rollback. Regardless, also insert the mc_list
4943 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004944 efx_ef10_filter_insert_def(efx, vlan, true, false);
4945 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004946 }
4947 } else {
4948 /* If any filters failed to insert, rollback and fall back to
4949 * promiscuous mode - mc_def filter and maybe broadcast. If
4950 * that fails, roll back again and insert as many of our
4951 * individual multicast filters as we can.
4952 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004953 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004954 /* Changing promisc state, so remove old filters */
4955 if (nic_data->workaround_26807)
4956 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004957 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4958 efx_ef10_filter_insert_addr_list(efx, vlan,
4959 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004960 }
4961 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004962}
4963
4964/* Caller must hold efx->filter_sem for read if race against
4965 * efx_ef10_filter_table_remove() is possible
4966 */
4967static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4968{
4969 struct efx_ef10_filter_table *table = efx->filter_state;
4970 struct net_device *net_dev = efx->net_dev;
4971 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004972 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004973
4974 if (!efx_dev_registered(efx))
4975 return;
4976
4977 if (!table)
4978 return;
4979
4980 efx_ef10_filter_mark_old(efx);
4981
4982 /* Copy/convert the address lists; add the primary station
4983 * address and broadcast address
4984 */
4985 netif_addr_lock_bh(net_dev);
4986 efx_ef10_filter_uc_addr_list(efx);
4987 efx_ef10_filter_mc_addr_list(efx);
4988 netif_addr_unlock_bh(net_dev);
4989
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004990 /* If VLAN filtering changes, all old filters are finally removed.
4991 * Do it in advance to avoid conflicts for unicast untagged and
4992 * VLAN 0 tagged filters.
4993 */
4994 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4995 if (table->vlan_filter != vlan_filter) {
4996 table->vlan_filter = vlan_filter;
4997 efx_ef10_filter_remove_old(efx);
4998 }
4999
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005000 list_for_each_entry(vlan, &table->vlan_list, list)
5001 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005002
5003 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005004 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005005}
5006
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005007static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5008{
5009 struct efx_ef10_filter_table *table = efx->filter_state;
5010 struct efx_ef10_filter_vlan *vlan;
5011
5012 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5013
5014 list_for_each_entry(vlan, &table->vlan_list, list) {
5015 if (vlan->vid == vid)
5016 return vlan;
5017 }
5018
5019 return NULL;
5020}
5021
5022static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5023{
5024 struct efx_ef10_filter_table *table = efx->filter_state;
5025 struct efx_ef10_filter_vlan *vlan;
5026 unsigned int i;
5027
5028 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5029 return -EINVAL;
5030
5031 vlan = efx_ef10_filter_find_vlan(efx, vid);
5032 if (WARN_ON(vlan)) {
5033 netif_err(efx, drv, efx->net_dev,
5034 "VLAN %u already added\n", vid);
5035 return -EALREADY;
5036 }
5037
5038 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5039 if (!vlan)
5040 return -ENOMEM;
5041
5042 vlan->vid = vid;
5043
5044 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5045 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5046 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5047 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5048 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
5049 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
5050 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
5051
5052 list_add_tail(&vlan->list, &table->vlan_list);
5053
5054 if (efx_dev_registered(efx))
5055 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5056
5057 return 0;
5058}
5059
5060static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5061 struct efx_ef10_filter_vlan *vlan)
5062{
5063 unsigned int i;
5064
5065 /* See comment in efx_ef10_filter_table_remove() */
5066 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5067 return;
5068
5069 list_del(&vlan->list);
5070
Edward Cree8c915622016-06-15 17:49:05 +01005071 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005072 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005073 vlan->uc[i]);
5074 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005075 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005076 vlan->mc[i]);
5077 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
5078 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
5079 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005080
5081 kfree(vlan);
5082}
5083
5084static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5085{
5086 struct efx_ef10_filter_vlan *vlan;
5087
5088 /* See comment in efx_ef10_filter_table_remove() */
5089 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5090 return;
5091
5092 vlan = efx_ef10_filter_find_vlan(efx, vid);
5093 if (!vlan) {
5094 netif_err(efx, drv, efx->net_dev,
5095 "VLAN %u not found in filter state\n", vid);
5096 return;
5097 }
5098
5099 efx_ef10_filter_del_vlan_internal(efx, vlan);
5100}
5101
Shradha Shah910c8782015-05-20 11:12:48 +01005102static int efx_ef10_set_mac_address(struct efx_nic *efx)
5103{
5104 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5105 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5106 bool was_enabled = efx->port_enabled;
5107 int rc;
5108
5109 efx_device_detach_sync(efx);
5110 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005111
5112 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005113 down_write(&efx->filter_sem);
5114 efx_ef10_filter_table_remove(efx);
5115
5116 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5117 efx->net_dev->dev_addr);
5118 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5119 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005120 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5121 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005122
5123 efx_ef10_filter_table_probe(efx);
5124 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005125 mutex_unlock(&efx->mac_lock);
5126
Shradha Shah910c8782015-05-20 11:12:48 +01005127 if (was_enabled)
5128 efx_net_open(efx->net_dev);
5129 netif_device_attach(efx->net_dev);
5130
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005131#ifdef CONFIG_SFC_SRIOV
5132 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005133 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5134
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005135 if (rc == -EPERM) {
5136 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005137
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005138 /* Switch to PF and change MAC address on vport */
5139 efx_pf = pci_get_drvdata(pci_dev_pf);
5140
5141 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005142 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005143 efx->net_dev->dev_addr);
5144 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005145 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5146 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5147 unsigned int i;
5148
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005149 /* MAC address successfully changed by VF (with MAC
5150 * spoofing) so update the parent PF if possible.
5151 */
Shradha Shah910c8782015-05-20 11:12:48 +01005152 for (i = 0; i < efx_pf->vf_count; ++i) {
5153 struct ef10_vf *vf = nic_data->vf + i;
5154
5155 if (vf->efx == efx) {
5156 ether_addr_copy(vf->mac,
5157 efx->net_dev->dev_addr);
5158 return 0;
5159 }
5160 }
5161 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005162 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005163#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005164 if (rc == -EPERM) {
5165 netif_err(efx, drv, efx->net_dev,
5166 "Cannot change MAC address; use sfboot to enable"
5167 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005168 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5169 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5170 * fall-back to the method of changing the MAC address on the
5171 * vport. This only applies to PFs because such versions of
5172 * MCFW do not support VFs.
5173 */
5174 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005175 } else {
5176 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5177 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005178 }
5179
Shradha Shah910c8782015-05-20 11:12:48 +01005180 return rc;
5181}
5182
Ben Hutchings8127d662013-08-29 19:19:29 +01005183static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5184{
5185 efx_ef10_filter_sync_rx_mode(efx);
5186
5187 return efx_mcdi_set_mac(efx);
5188}
5189
Shradha Shah862f8942015-05-20 11:08:56 +01005190static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5191{
5192 efx_ef10_filter_sync_rx_mode(efx);
5193
5194 return 0;
5195}
5196
Jon Cooper74cd60a2013-09-16 14:18:51 +01005197static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5198{
5199 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5200
5201 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5202 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5203 NULL, 0, NULL);
5204}
5205
5206/* MC BISTs follow a different poll mechanism to phy BISTs.
5207 * The BIST is done in the poll handler on the MC, and the MCDI command
5208 * will block until the BIST is done.
5209 */
5210static int efx_ef10_poll_bist(struct efx_nic *efx)
5211{
5212 int rc;
5213 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5214 size_t outlen;
5215 u32 result;
5216
5217 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5218 outbuf, sizeof(outbuf), &outlen);
5219 if (rc != 0)
5220 return rc;
5221
5222 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5223 return -EIO;
5224
5225 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5226 switch (result) {
5227 case MC_CMD_POLL_BIST_PASSED:
5228 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5229 return 0;
5230 case MC_CMD_POLL_BIST_TIMEOUT:
5231 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5232 return -EIO;
5233 case MC_CMD_POLL_BIST_FAILED:
5234 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5235 return -EIO;
5236 default:
5237 netif_err(efx, hw, efx->net_dev,
5238 "BIST returned unknown result %u", result);
5239 return -EIO;
5240 }
5241}
5242
5243static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5244{
5245 int rc;
5246
5247 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5248
5249 rc = efx_ef10_start_bist(efx, bist_type);
5250 if (rc != 0)
5251 return rc;
5252
5253 return efx_ef10_poll_bist(efx);
5254}
5255
5256static int
5257efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5258{
5259 int rc, rc2;
5260
5261 efx_reset_down(efx, RESET_TYPE_WORLD);
5262
5263 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5264 NULL, 0, NULL, 0, NULL);
5265 if (rc != 0)
5266 goto out;
5267
5268 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5269 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5270
5271 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5272
5273out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005274 if (rc == -EPERM)
5275 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005276 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5277 return rc ? rc : rc2;
5278}
5279
Ben Hutchings8127d662013-08-29 19:19:29 +01005280#ifdef CONFIG_SFC_MTD
5281
5282struct efx_ef10_nvram_type_info {
5283 u16 type, type_mask;
5284 u8 port;
5285 const char *name;
5286};
5287
5288static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5289 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5290 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5291 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5292 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5293 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5294 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5295 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5296 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5297 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005298 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005299 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5300};
5301
5302static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5303 struct efx_mcdi_mtd_partition *part,
5304 unsigned int type)
5305{
5306 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5307 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5308 const struct efx_ef10_nvram_type_info *info;
5309 size_t size, erase_size, outlen;
5310 bool protected;
5311 int rc;
5312
5313 for (info = efx_ef10_nvram_types; ; info++) {
5314 if (info ==
5315 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5316 return -ENODEV;
5317 if ((type & ~info->type_mask) == info->type)
5318 break;
5319 }
5320 if (info->port != efx_port_num(efx))
5321 return -ENODEV;
5322
5323 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5324 if (rc)
5325 return rc;
5326 if (protected)
5327 return -ENODEV; /* hide it */
5328
5329 part->nvram_type = type;
5330
5331 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5332 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5333 outbuf, sizeof(outbuf), &outlen);
5334 if (rc)
5335 return rc;
5336 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5337 return -EIO;
5338 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5339 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5340 part->fw_subtype = MCDI_DWORD(outbuf,
5341 NVRAM_METADATA_OUT_SUBTYPE);
5342
5343 part->common.dev_type_name = "EF10 NVRAM manager";
5344 part->common.type_name = info->name;
5345
5346 part->common.mtd.type = MTD_NORFLASH;
5347 part->common.mtd.flags = MTD_CAP_NORFLASH;
5348 part->common.mtd.size = size;
5349 part->common.mtd.erasesize = erase_size;
5350
5351 return 0;
5352}
5353
5354static int efx_ef10_mtd_probe(struct efx_nic *efx)
5355{
5356 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5357 struct efx_mcdi_mtd_partition *parts;
5358 size_t outlen, n_parts_total, i, n_parts;
5359 unsigned int type;
5360 int rc;
5361
5362 ASSERT_RTNL();
5363
5364 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5365 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5366 outbuf, sizeof(outbuf), &outlen);
5367 if (rc)
5368 return rc;
5369 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5370 return -EIO;
5371
5372 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5373 if (n_parts_total >
5374 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5375 return -EIO;
5376
5377 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5378 if (!parts)
5379 return -ENOMEM;
5380
5381 n_parts = 0;
5382 for (i = 0; i < n_parts_total; i++) {
5383 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5384 i);
5385 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5386 if (rc == 0)
5387 n_parts++;
5388 else if (rc != -ENODEV)
5389 goto fail;
5390 }
5391
5392 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5393fail:
5394 if (rc)
5395 kfree(parts);
5396 return rc;
5397}
5398
5399#endif /* CONFIG_SFC_MTD */
5400
5401static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5402{
5403 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5404}
5405
Shradha Shah02246a72015-05-06 00:58:14 +01005406static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5407 u32 host_time) {}
5408
Jon Cooperbd9a2652013-11-18 12:54:41 +00005409static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5410 bool temp)
5411{
5412 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5413 int rc;
5414
5415 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5416 channel->sync_events_state == SYNC_EVENTS_VALID ||
5417 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5418 return 0;
5419 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5420
5421 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5422 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5423 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5424 channel->channel);
5425
5426 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5427 inbuf, sizeof(inbuf), NULL, 0, NULL);
5428
5429 if (rc != 0)
5430 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5431 SYNC_EVENTS_DISABLED;
5432
5433 return rc;
5434}
5435
5436static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5437 bool temp)
5438{
5439 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5440 int rc;
5441
5442 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5443 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5444 return 0;
5445 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5446 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5447 return 0;
5448 }
5449 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5450 SYNC_EVENTS_DISABLED;
5451
5452 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5453 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5454 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5455 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5456 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5457 channel->channel);
5458
5459 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5460 inbuf, sizeof(inbuf), NULL, 0, NULL);
5461
5462 return rc;
5463}
5464
5465static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5466 bool temp)
5467{
5468 int (*set)(struct efx_channel *channel, bool temp);
5469 struct efx_channel *channel;
5470
5471 set = en ?
5472 efx_ef10_rx_enable_timestamping :
5473 efx_ef10_rx_disable_timestamping;
5474
5475 efx_for_each_channel(channel, efx) {
5476 int rc = set(channel, temp);
5477 if (en && rc != 0) {
5478 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5479 return rc;
5480 }
5481 }
5482
5483 return 0;
5484}
5485
Shradha Shah02246a72015-05-06 00:58:14 +01005486static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5487 struct hwtstamp_config *init)
5488{
5489 return -EOPNOTSUPP;
5490}
5491
Jon Cooperbd9a2652013-11-18 12:54:41 +00005492static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5493 struct hwtstamp_config *init)
5494{
5495 int rc;
5496
5497 switch (init->rx_filter) {
5498 case HWTSTAMP_FILTER_NONE:
5499 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5500 /* if TX timestamping is still requested then leave PTP on */
5501 return efx_ptp_change_mode(efx,
5502 init->tx_type != HWTSTAMP_TX_OFF, 0);
5503 case HWTSTAMP_FILTER_ALL:
5504 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5505 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5506 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5507 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5508 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5509 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5510 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5511 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5512 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5513 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5514 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5515 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5516 init->rx_filter = HWTSTAMP_FILTER_ALL;
5517 rc = efx_ptp_change_mode(efx, true, 0);
5518 if (!rc)
5519 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5520 if (rc)
5521 efx_ptp_change_mode(efx, false, 0);
5522 return rc;
5523 default:
5524 return -ERANGE;
5525 }
5526}
5527
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005528static int efx_ef10_vlan_rx_add_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_add_vlan(efx, vid);
5534}
5535
5536static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5537{
5538 if (proto != htons(ETH_P_8021Q))
5539 return -EINVAL;
5540
5541 return efx_ef10_del_vlan(efx, vid);
5542}
5543
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005544#define EF10_OFFLOAD_FEATURES \
5545 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005546 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005547 NETIF_F_IPV6_CSUM | \
5548 NETIF_F_RXHASH | \
5549 NETIF_F_NTUPLE)
5550
Shradha Shah02246a72015-05-06 00:58:14 +01005551const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005552 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005553 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005554 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005555 .probe = efx_ef10_probe_vf,
5556 .remove = efx_ef10_remove,
5557 .dimension_resources = efx_ef10_dimension_resources,
5558 .init = efx_ef10_init_nic,
5559 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005560 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005561 .map_reset_flags = efx_ef10_map_reset_flags,
5562 .reset = efx_ef10_reset,
5563 .probe_port = efx_mcdi_port_probe,
5564 .remove_port = efx_mcdi_port_remove,
5565 .fini_dmaq = efx_ef10_fini_dmaq,
5566 .prepare_flr = efx_ef10_prepare_flr,
5567 .finish_flr = efx_port_dummy_op_void,
5568 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005569 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005570 .start_stats = efx_port_dummy_op_void,
5571 .pull_stats = efx_port_dummy_op_void,
5572 .stop_stats = efx_port_dummy_op_void,
5573 .set_id_led = efx_mcdi_set_id_led,
5574 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005575 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005576 .check_mac_fault = efx_mcdi_mac_check_fault,
5577 .reconfigure_port = efx_mcdi_port_reconfigure,
5578 .get_wol = efx_ef10_get_wol_vf,
5579 .set_wol = efx_ef10_set_wol_vf,
5580 .resume_wol = efx_port_dummy_op_void,
5581 .mcdi_request = efx_ef10_mcdi_request,
5582 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5583 .mcdi_read_response = efx_ef10_mcdi_read_response,
5584 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005585 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005586 .irq_enable_master = efx_port_dummy_op_void,
5587 .irq_test_generate = efx_ef10_irq_test_generate,
5588 .irq_disable_non_ev = efx_port_dummy_op_void,
5589 .irq_handle_msi = efx_ef10_msi_interrupt,
5590 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5591 .tx_probe = efx_ef10_tx_probe,
5592 .tx_init = efx_ef10_tx_init,
5593 .tx_remove = efx_ef10_tx_remove,
5594 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005595 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005596 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005597 .rx_probe = efx_ef10_rx_probe,
5598 .rx_init = efx_ef10_rx_init,
5599 .rx_remove = efx_ef10_rx_remove,
5600 .rx_write = efx_ef10_rx_write,
5601 .rx_defer_refill = efx_ef10_rx_defer_refill,
5602 .ev_probe = efx_ef10_ev_probe,
5603 .ev_init = efx_ef10_ev_init,
5604 .ev_fini = efx_ef10_ev_fini,
5605 .ev_remove = efx_ef10_ev_remove,
5606 .ev_process = efx_ef10_ev_process,
5607 .ev_read_ack = efx_ef10_ev_read_ack,
5608 .ev_test_generate = efx_ef10_ev_test_generate,
5609 .filter_table_probe = efx_ef10_filter_table_probe,
5610 .filter_table_restore = efx_ef10_filter_table_restore,
5611 .filter_table_remove = efx_ef10_filter_table_remove,
5612 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5613 .filter_insert = efx_ef10_filter_insert,
5614 .filter_remove_safe = efx_ef10_filter_remove_safe,
5615 .filter_get_safe = efx_ef10_filter_get_safe,
5616 .filter_clear_rx = efx_ef10_filter_clear_rx,
5617 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5618 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5619 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5620#ifdef CONFIG_RFS_ACCEL
5621 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5622 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5623#endif
5624#ifdef CONFIG_SFC_MTD
5625 .mtd_probe = efx_port_dummy_op_int,
5626#endif
5627 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5628 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005629 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5630 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005631#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005632 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5633 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5634 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01005635 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005636#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005637 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005638 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005639
Shradha Shah02246a72015-05-06 00:58:14 +01005640 .revision = EFX_REV_HUNT_A0,
5641 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5642 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5643 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5644 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5645 .can_rx_scatter = true,
5646 .always_rx_scatter = true,
5647 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5648 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005649 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005650 .mcdi_max_ver = 2,
5651 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5652 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5653 1 << HWTSTAMP_FILTER_ALL,
5654};
5655
5656const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005657 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005658 .mem_bar = EFX_MEM_BAR,
5659 .mem_map_size = efx_ef10_mem_map_size,
5660 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005661 .remove = efx_ef10_remove,
5662 .dimension_resources = efx_ef10_dimension_resources,
5663 .init = efx_ef10_init_nic,
5664 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005665 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005666 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005667 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005668 .probe_port = efx_mcdi_port_probe,
5669 .remove_port = efx_mcdi_port_remove,
5670 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005671 .prepare_flr = efx_ef10_prepare_flr,
5672 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005673 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005674 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005675 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005676 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005677 .stop_stats = efx_mcdi_mac_stop_stats,
5678 .set_id_led = efx_mcdi_set_id_led,
5679 .push_irq_moderation = efx_ef10_push_irq_moderation,
5680 .reconfigure_mac = efx_ef10_mac_reconfigure,
5681 .check_mac_fault = efx_mcdi_mac_check_fault,
5682 .reconfigure_port = efx_mcdi_port_reconfigure,
5683 .get_wol = efx_ef10_get_wol,
5684 .set_wol = efx_ef10_set_wol,
5685 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005686 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005687 .test_nvram = efx_mcdi_nvram_test_all,
5688 .mcdi_request = efx_ef10_mcdi_request,
5689 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5690 .mcdi_read_response = efx_ef10_mcdi_read_response,
5691 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005692 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005693 .irq_enable_master = efx_port_dummy_op_void,
5694 .irq_test_generate = efx_ef10_irq_test_generate,
5695 .irq_disable_non_ev = efx_port_dummy_op_void,
5696 .irq_handle_msi = efx_ef10_msi_interrupt,
5697 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5698 .tx_probe = efx_ef10_tx_probe,
5699 .tx_init = efx_ef10_tx_init,
5700 .tx_remove = efx_ef10_tx_remove,
5701 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005702 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005703 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005704 .rx_probe = efx_ef10_rx_probe,
5705 .rx_init = efx_ef10_rx_init,
5706 .rx_remove = efx_ef10_rx_remove,
5707 .rx_write = efx_ef10_rx_write,
5708 .rx_defer_refill = efx_ef10_rx_defer_refill,
5709 .ev_probe = efx_ef10_ev_probe,
5710 .ev_init = efx_ef10_ev_init,
5711 .ev_fini = efx_ef10_ev_fini,
5712 .ev_remove = efx_ef10_ev_remove,
5713 .ev_process = efx_ef10_ev_process,
5714 .ev_read_ack = efx_ef10_ev_read_ack,
5715 .ev_test_generate = efx_ef10_ev_test_generate,
5716 .filter_table_probe = efx_ef10_filter_table_probe,
5717 .filter_table_restore = efx_ef10_filter_table_restore,
5718 .filter_table_remove = efx_ef10_filter_table_remove,
5719 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5720 .filter_insert = efx_ef10_filter_insert,
5721 .filter_remove_safe = efx_ef10_filter_remove_safe,
5722 .filter_get_safe = efx_ef10_filter_get_safe,
5723 .filter_clear_rx = efx_ef10_filter_clear_rx,
5724 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5725 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5726 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5727#ifdef CONFIG_RFS_ACCEL
5728 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5729 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5730#endif
5731#ifdef CONFIG_SFC_MTD
5732 .mtd_probe = efx_ef10_mtd_probe,
5733 .mtd_rename = efx_mcdi_mtd_rename,
5734 .mtd_read = efx_mcdi_mtd_read,
5735 .mtd_erase = efx_mcdi_mtd_erase,
5736 .mtd_write = efx_mcdi_mtd_write,
5737 .mtd_sync = efx_mcdi_mtd_sync,
5738#endif
5739 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005740 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5741 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005742 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5743 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005744#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005745 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005746 .sriov_init = efx_ef10_sriov_init,
5747 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005748 .sriov_wanted = efx_ef10_sriov_wanted,
5749 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005750 .sriov_flr = efx_ef10_sriov_flr,
5751 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5752 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5753 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5754 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005755 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005756 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5757 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5758 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005759#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005760 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005761 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01005762
5763 .revision = EFX_REV_HUNT_A0,
5764 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5765 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5766 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005767 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005768 .can_rx_scatter = true,
5769 .always_rx_scatter = true,
5770 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5771 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005772 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005773 .mcdi_max_ver = 2,
5774 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005775 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5776 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005777};