blob: 6fe1d0ba78b223eb448d6b8f6f0091faabefb439 [file] [log] [blame]
Ben Hutchings8127d662013-08-29 19:19:29 +01001/****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2012-2013 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include "net_driver.h"
11#include "ef10_regs.h"
12#include "io.h"
13#include "mcdi.h"
14#include "mcdi_pcol.h"
15#include "nic.h"
16#include "workarounds.h"
Jon Cooper74cd60a2013-09-16 14:18:51 +010017#include "selftest.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010018#include "ef10_sriov.h"
Ben Hutchings8127d662013-08-29 19:19:29 +010019#include <linux/in.h>
20#include <linux/jhash.h>
21#include <linux/wait.h>
22#include <linux/workqueue.h>
23
24/* Hardware control for EF10 architecture including 'Huntington'. */
25
26#define EFX_EF10_DRVGEN_EV 7
27enum {
28 EFX_EF10_TEST = 1,
29 EFX_EF10_REFILL,
30};
31
32/* The reserved RSS context value */
33#define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
Jon Cooper267c0152015-05-06 00:59:38 +010034/* The maximum size of a shared RSS context */
35/* TODO: this should really be from the mcdi protocol export */
36#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
Ben Hutchings8127d662013-08-29 19:19:29 +010037
38/* The filter table(s) are managed by firmware and we have write-only
39 * access. When removing filters we must identify them to the
40 * firmware by a 64-bit handle, but this is too wide for Linux kernel
41 * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
42 * be able to tell in advance whether a requested insertion will
43 * replace an existing filter. Therefore we maintain a software hash
44 * table, which should be at least as large as the hardware hash
45 * table.
46 *
47 * Huntington has a single 8K filter table shared between all filter
48 * types and both ports.
49 */
50#define HUNT_FILTER_TBL_ROWS 8192
51
Edward Cree12fb0da2015-07-21 15:11:00 +010052#define EFX_EF10_FILTER_ID_INVALID 0xffff
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010053
54#define EFX_EF10_FILTER_DEV_UC_MAX 32
55#define EFX_EF10_FILTER_DEV_MC_MAX 256
56
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010057/* VLAN list entry */
58struct efx_ef10_vlan {
59 struct list_head list;
60 u16 vid;
61};
62
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010063/* Per-VLAN filters information */
64struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010065 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010066 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010067 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
68 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
69 u16 ucdef;
70 u16 bcast;
71 u16 mcdef;
72};
73
Daniel Pieczko822b96f2015-07-21 15:10:27 +010074struct efx_ef10_dev_addr {
75 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010076};
77
Ben Hutchings8127d662013-08-29 19:19:29 +010078struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010079/* The MCDI match masks supported by this fw & hw, in order of priority */
80 u32 rx_match_mcdi_flags[
Ben Hutchings8127d662013-08-29 19:19:29 +010081 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
82 unsigned int rx_match_count;
83
84 struct {
85 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000086/* BUSY flag indicates that an update is in progress. AUTO_OLD is
87 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +010088 */
89#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000090#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +010091#define EFX_EF10_FILTER_FLAGS 3UL
92 u64 handle; /* firmware handle */
93 } *entry;
94 wait_queue_head_t waitq;
95/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +010096 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
97 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +010098 int dev_uc_count;
99 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100100 bool uc_promisc;
101 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100102/* Whether in multicast promiscuous mode when last changed */
103 bool mc_promisc_last;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100104 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100105 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100106};
107
108/* An arbitrary search limit for the software hash table */
109#define EFX_EF10_FILTER_SEARCH_LIMIT 200
110
Ben Hutchings8127d662013-08-29 19:19:29 +0100111static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
112static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100113static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
114static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
115 struct efx_ef10_filter_vlan *vlan);
116static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Ben Hutchings8127d662013-08-29 19:19:29 +0100117
118static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
119{
120 efx_dword_t reg;
121
122 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
123 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
124 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
125}
126
127static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
128{
Shradha Shah02246a72015-05-06 00:58:14 +0100129 int bar;
130
131 bar = efx->type->mem_bar;
132 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100133}
134
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100135static bool efx_ef10_is_vf(struct efx_nic *efx)
136{
137 return efx->type->is_vf;
138}
139
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100140static int efx_ef10_get_pf_index(struct efx_nic *efx)
141{
142 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
143 struct efx_ef10_nic_data *nic_data = efx->nic_data;
144 size_t outlen;
145 int rc;
146
147 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
148 sizeof(outbuf), &outlen);
149 if (rc)
150 return rc;
151 if (outlen < sizeof(outbuf))
152 return -EIO;
153
154 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
155 return 0;
156}
157
Shradha Shah88a37de2015-05-20 11:09:15 +0100158#ifdef CONFIG_SFC_SRIOV
159static int efx_ef10_get_vf_index(struct efx_nic *efx)
160{
161 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
162 struct efx_ef10_nic_data *nic_data = efx->nic_data;
163 size_t outlen;
164 int rc;
165
166 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
167 sizeof(outbuf), &outlen);
168 if (rc)
169 return rc;
170 if (outlen < sizeof(outbuf))
171 return -EIO;
172
173 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
174 return 0;
175}
176#endif
177
Ben Hutchingse5a25382013-09-05 22:50:59 +0100178static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100179{
Bert Kenwardca889a02016-08-11 13:01:35 +0100180 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +0100181 struct efx_ef10_nic_data *nic_data = efx->nic_data;
182 size_t outlen;
183 int rc;
184
185 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
186
187 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
188 outbuf, sizeof(outbuf), &outlen);
189 if (rc)
190 return rc;
Bert Kenwardca889a02016-08-11 13:01:35 +0100191 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
Ben Hutchingse5a25382013-09-05 22:50:59 +0100192 netif_err(efx, drv, efx->net_dev,
193 "unable to read datapath firmware capabilities\n");
194 return -EIO;
195 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100196
Ben Hutchingse5a25382013-09-05 22:50:59 +0100197 nic_data->datapath_caps =
198 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
199
Bert Kenwardca889a02016-08-11 13:01:35 +0100200 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)
201 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
202 GET_CAPABILITIES_V2_OUT_FLAGS2);
203 else
204 nic_data->datapath_caps2 = 0;
205
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100206 /* record the DPCPU firmware IDs to determine VEB vswitching support.
207 */
208 nic_data->rx_dpcpu_fw_id =
209 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
210 nic_data->tx_dpcpu_fw_id =
211 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
212
Ben Hutchingse5a25382013-09-05 22:50:59 +0100213 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100214 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
215 netif_err(efx, probe, efx->net_dev,
216 "current firmware does not support an RX prefix\n");
217 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100218 }
219
220 return 0;
221}
222
223static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
224{
225 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
226 int rc;
227
228 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
229 outbuf, sizeof(outbuf), NULL);
230 if (rc)
231 return rc;
232 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
233 return rc > 0 ? rc : -ERANGE;
234}
235
Bert Kenwardd95e3292016-08-11 13:02:36 +0100236static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
237{
238 struct efx_ef10_nic_data *nic_data = efx->nic_data;
239 unsigned int implemented;
240 unsigned int enabled;
241 int rc;
242
243 nic_data->workaround_35388 = false;
244 nic_data->workaround_61265 = false;
245
246 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
247
248 if (rc == -ENOSYS) {
249 /* Firmware without GET_WORKAROUNDS - not a problem. */
250 rc = 0;
251 } else if (rc == 0) {
252 /* Bug61265 workaround is always enabled if implemented. */
253 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
254 nic_data->workaround_61265 = true;
255
256 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
257 nic_data->workaround_35388 = true;
258 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
259 /* Workaround is implemented but not enabled.
260 * Try to enable it.
261 */
262 rc = efx_mcdi_set_workaround(efx,
263 MC_CMD_WORKAROUND_BUG35388,
264 true, NULL);
265 if (rc == 0)
266 nic_data->workaround_35388 = true;
267 /* If we failed to set the workaround just carry on. */
268 rc = 0;
269 }
270 }
271
272 netif_dbg(efx, probe, efx->net_dev,
273 "workaround for bug 35388 is %sabled\n",
274 nic_data->workaround_35388 ? "en" : "dis");
275 netif_dbg(efx, probe, efx->net_dev,
276 "workaround for bug 61265 is %sabled\n",
277 nic_data->workaround_61265 ? "en" : "dis");
278
279 return rc;
280}
281
282static void efx_ef10_process_timer_config(struct efx_nic *efx,
283 const efx_dword_t *data)
284{
285 unsigned int max_count;
286
287 if (EFX_EF10_WORKAROUND_61265(efx)) {
288 efx->timer_quantum_ns = MCDI_DWORD(data,
289 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
290 efx->timer_max_ns = MCDI_DWORD(data,
291 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
292 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
293 efx->timer_quantum_ns = MCDI_DWORD(data,
294 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
295 max_count = MCDI_DWORD(data,
296 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
297 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
298 } else {
299 efx->timer_quantum_ns = MCDI_DWORD(data,
300 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
301 max_count = MCDI_DWORD(data,
302 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
303 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
304 }
305
306 netif_dbg(efx, probe, efx->net_dev,
307 "got timer properties from MC: quantum %u ns; max %u ns\n",
308 efx->timer_quantum_ns, efx->timer_max_ns);
309}
310
311static int efx_ef10_get_timer_config(struct efx_nic *efx)
312{
313 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
314 int rc;
315
316 rc = efx_ef10_get_timer_workarounds(efx);
317 if (rc)
318 return rc;
319
320 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
321 outbuf, sizeof(outbuf), NULL);
322
323 if (rc == 0) {
324 efx_ef10_process_timer_config(efx, outbuf);
325 } else if (rc == -ENOSYS || rc == -EPERM) {
326 /* Not available - fall back to Huntington defaults. */
327 unsigned int quantum;
328
329 rc = efx_ef10_get_sysclk_freq(efx);
330 if (rc < 0)
331 return rc;
332
333 quantum = 1536000 / rc; /* 1536 cycles */
334 efx->timer_quantum_ns = quantum;
335 efx->timer_max_ns = efx->type->timer_period_max * quantum;
336 rc = 0;
337 } else {
338 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
339 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
340 NULL, 0, rc);
341 }
342
343 return rc;
344}
345
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100346static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100347{
348 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
349 size_t outlen;
350 int rc;
351
352 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
353
354 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
355 outbuf, sizeof(outbuf), &outlen);
356 if (rc)
357 return rc;
358 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
359 return -EIO;
360
Edward Creecd84ff42014-03-07 18:27:41 +0000361 ether_addr_copy(mac_address,
362 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100363 return 0;
364}
365
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100366static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
367{
368 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
369 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
370 size_t outlen;
371 int num_addrs, rc;
372
373 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
374 EVB_PORT_ID_ASSIGNED);
375 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
376 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
377
378 if (rc)
379 return rc;
380 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
381 return -EIO;
382
383 num_addrs = MCDI_DWORD(outbuf,
384 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
385
386 WARN_ON(num_addrs != 1);
387
388 ether_addr_copy(mac_address,
389 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
390
391 return 0;
392}
393
Shradha Shah0f5c0842015-06-02 11:37:58 +0100394static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
395 struct device_attribute *attr,
396 char *buf)
397{
398 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
399
400 return sprintf(buf, "%d\n",
401 ((efx->mcdi->fn_flags) &
402 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
403 ? 1 : 0);
404}
405
406static ssize_t efx_ef10_show_primary_flag(struct device *dev,
407 struct device_attribute *attr,
408 char *buf)
409{
410 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
411
412 return sprintf(buf, "%d\n",
413 ((efx->mcdi->fn_flags) &
414 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
415 ? 1 : 0);
416}
417
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100418static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
419{
420 struct efx_ef10_nic_data *nic_data = efx->nic_data;
421 struct efx_ef10_vlan *vlan;
422
423 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
424
425 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
426 if (vlan->vid == vid)
427 return vlan;
428 }
429
430 return NULL;
431}
432
433static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
434{
435 struct efx_ef10_nic_data *nic_data = efx->nic_data;
436 struct efx_ef10_vlan *vlan;
437 int rc;
438
439 mutex_lock(&nic_data->vlan_lock);
440
441 vlan = efx_ef10_find_vlan(efx, vid);
442 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100443 /* We add VID 0 on init. 8021q adds it on module init
444 * for all interfaces with VLAN filtring feature.
445 */
446 if (vid == 0)
447 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100448 netif_warn(efx, drv, efx->net_dev,
449 "VLAN %u already added\n", vid);
450 rc = -EALREADY;
451 goto fail_exist;
452 }
453
454 rc = -ENOMEM;
455 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
456 if (!vlan)
457 goto fail_alloc;
458
459 vlan->vid = vid;
460
461 list_add_tail(&vlan->list, &nic_data->vlan_list);
462
463 if (efx->filter_state) {
464 mutex_lock(&efx->mac_lock);
465 down_write(&efx->filter_sem);
466 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
467 up_write(&efx->filter_sem);
468 mutex_unlock(&efx->mac_lock);
469 if (rc)
470 goto fail_filter_add_vlan;
471 }
472
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100473done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100474 mutex_unlock(&nic_data->vlan_lock);
475 return 0;
476
477fail_filter_add_vlan:
478 list_del(&vlan->list);
479 kfree(vlan);
480fail_alloc:
481fail_exist:
482 mutex_unlock(&nic_data->vlan_lock);
483 return rc;
484}
485
486static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
487 struct efx_ef10_vlan *vlan)
488{
489 struct efx_ef10_nic_data *nic_data = efx->nic_data;
490
491 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
492
493 if (efx->filter_state) {
494 down_write(&efx->filter_sem);
495 efx_ef10_filter_del_vlan(efx, vlan->vid);
496 up_write(&efx->filter_sem);
497 }
498
499 list_del(&vlan->list);
500 kfree(vlan);
501}
502
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100503static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
504{
505 struct efx_ef10_nic_data *nic_data = efx->nic_data;
506 struct efx_ef10_vlan *vlan;
507 int rc = 0;
508
509 /* 8021q removes VID 0 on module unload for all interfaces
510 * with VLAN filtering feature. We need to keep it to receive
511 * untagged traffic.
512 */
513 if (vid == 0)
514 return 0;
515
516 mutex_lock(&nic_data->vlan_lock);
517
518 vlan = efx_ef10_find_vlan(efx, vid);
519 if (!vlan) {
520 netif_err(efx, drv, efx->net_dev,
521 "VLAN %u to be deleted not found\n", vid);
522 rc = -ENOENT;
523 } else {
524 efx_ef10_del_vlan_internal(efx, vlan);
525 }
526
527 mutex_unlock(&nic_data->vlan_lock);
528
529 return rc;
530}
531
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100532static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
533{
534 struct efx_ef10_nic_data *nic_data = efx->nic_data;
535 struct efx_ef10_vlan *vlan, *next_vlan;
536
537 mutex_lock(&nic_data->vlan_lock);
538 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
539 efx_ef10_del_vlan_internal(efx, vlan);
540 mutex_unlock(&nic_data->vlan_lock);
541}
542
Shradha Shah0f5c0842015-06-02 11:37:58 +0100543static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
544 NULL);
545static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
546
Ben Hutchings8127d662013-08-29 19:19:29 +0100547static int efx_ef10_probe(struct efx_nic *efx)
548{
549 struct efx_ef10_nic_data *nic_data;
Shradha Shah8be41322015-06-02 11:37:25 +0100550 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100551 int i, rc;
552
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000553 /* We can have one VI for each 8K region. However, until we
554 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100555 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100556 efx->max_channels = min_t(unsigned int,
557 EFX_MAX_CHANNELS,
558 efx_ef10_mem_map_size(efx) /
559 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
560 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000561 if (WARN_ON(efx->max_channels == 0))
562 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100563
564 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
565 if (!nic_data)
566 return -ENOMEM;
567 efx->nic_data = nic_data;
568
Edward Cree75aba2a2015-05-27 13:13:54 +0100569 /* we assume later that we can copy from this buffer in dwords */
570 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
571
Ben Hutchings8127d662013-08-29 19:19:29 +0100572 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
573 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
574 if (rc)
575 goto fail1;
576
577 /* Get the MC's warm boot count. In case it's rebooting right
578 * now, be prepared to retry.
579 */
580 i = 0;
581 for (;;) {
582 rc = efx_ef10_get_warm_boot_count(efx);
583 if (rc >= 0)
584 break;
585 if (++i == 5)
586 goto fail2;
587 ssleep(1);
588 }
589 nic_data->warm_boot_count = rc;
590
591 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
592
Daniel Pieczko45b24492015-05-06 00:57:14 +0100593 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
594
Ben Hutchings8127d662013-08-29 19:19:29 +0100595 /* In case we're recovering from a crash (kexec), we want to
596 * cancel any outstanding request by the previous user of this
597 * function. We send a special message using the least
598 * significant bits of the 'high' (doorbell) register.
599 */
600 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
601
602 rc = efx_mcdi_init(efx);
603 if (rc)
604 goto fail2;
605
606 /* Reset (most) configuration for this function */
607 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
608 if (rc)
609 goto fail3;
610
611 /* Enable event logging */
612 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
613 if (rc)
614 goto fail3;
615
Shradha Shah0f5c0842015-06-02 11:37:58 +0100616 rc = device_create_file(&efx->pci_dev->dev,
617 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100618 if (rc)
619 goto fail3;
620
Shradha Shah0f5c0842015-06-02 11:37:58 +0100621 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
622 if (rc)
623 goto fail4;
624
625 rc = efx_ef10_get_pf_index(efx);
626 if (rc)
627 goto fail5;
628
Ben Hutchingse5a25382013-09-05 22:50:59 +0100629 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100630 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100631 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100632
633 efx->rx_packet_len_offset =
634 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
635
Ben Hutchings8127d662013-08-29 19:19:29 +0100636 rc = efx_mcdi_port_get_number(efx);
637 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100638 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100639 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100640 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100641
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100642 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100643 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100644 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100645
Bert Kenwardd95e3292016-08-11 13:02:36 +0100646 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100647 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100648 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100649
Ben Hutchings8127d662013-08-29 19:19:29 +0100650 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100651 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100652 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100653
Ben Hutchings9aecda92013-12-05 21:28:42 +0000654 efx_ptp_probe(efx, NULL);
655
Shradha Shah1d051e02015-06-02 11:38:16 +0100656#ifdef CONFIG_SFC_SRIOV
657 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
658 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
659 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
660
661 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
662 } else
663#endif
664 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
665
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100666 INIT_LIST_HEAD(&nic_data->vlan_list);
667 mutex_init(&nic_data->vlan_lock);
668
669 /* Add unspecified VID to support VLAN filtering being disabled */
670 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
671 if (rc)
672 goto fail_add_vid_unspec;
673
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100674 /* If VLAN filtering is enabled, we need VID 0 to get untagged
675 * traffic. It is added automatically if 8021q module is loaded,
676 * but we can't rely on it since module may be not loaded.
677 */
678 rc = efx_ef10_add_vlan(efx, 0);
679 if (rc)
680 goto fail_add_vid_0;
681
Ben Hutchings8127d662013-08-29 19:19:29 +0100682 return 0;
683
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100684fail_add_vid_0:
685 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100686fail_add_vid_unspec:
687 mutex_destroy(&nic_data->vlan_lock);
688 efx_ptp_remove(efx);
689 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100690fail5:
691 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
692fail4:
693 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100694fail3:
695 efx_mcdi_fini(efx);
696fail2:
697 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
698fail1:
699 kfree(nic_data);
700 efx->nic_data = NULL;
701 return rc;
702}
703
704static int efx_ef10_free_vis(struct efx_nic *efx)
705{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100706 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100707 size_t outlen;
708 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
709 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100710
711 /* -EALREADY means nothing to free, so ignore */
712 if (rc == -EALREADY)
713 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100714 if (rc)
715 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
716 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100717 return rc;
718}
719
Ben Hutchings183233b2013-06-28 21:47:12 +0100720#ifdef EFX_USE_PIO
721
722static void efx_ef10_free_piobufs(struct efx_nic *efx)
723{
724 struct efx_ef10_nic_data *nic_data = efx->nic_data;
725 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
726 unsigned int i;
727 int rc;
728
729 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
730
731 for (i = 0; i < nic_data->n_piobufs; i++) {
732 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
733 nic_data->piobuf_handle[i]);
734 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
735 NULL, 0, NULL);
736 WARN_ON(rc);
737 }
738
739 nic_data->n_piobufs = 0;
740}
741
742static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
743{
744 struct efx_ef10_nic_data *nic_data = efx->nic_data;
745 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
746 unsigned int i;
747 size_t outlen;
748 int rc = 0;
749
750 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
751
752 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000753 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
754 outbuf, sizeof(outbuf), &outlen);
755 if (rc) {
756 /* Don't display the MC error if we didn't have space
757 * for a VF.
758 */
759 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
760 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
761 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100762 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000763 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100764 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
765 rc = -EIO;
766 break;
767 }
768 nic_data->piobuf_handle[i] =
769 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
770 netif_dbg(efx, probe, efx->net_dev,
771 "allocated PIO buffer %u handle %x\n", i,
772 nic_data->piobuf_handle[i]);
773 }
774
775 nic_data->n_piobufs = i;
776 if (rc)
777 efx_ef10_free_piobufs(efx);
778 return rc;
779}
780
781static int efx_ef10_link_piobufs(struct efx_nic *efx)
782{
783 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100784 _MCDI_DECLARE_BUF(inbuf,
785 max(MC_CMD_LINK_PIOBUF_IN_LEN,
786 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100787 struct efx_channel *channel;
788 struct efx_tx_queue *tx_queue;
789 unsigned int offset, index;
790 int rc;
791
792 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
793 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
794
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100795 memset(inbuf, 0, sizeof(inbuf));
796
Ben Hutchings183233b2013-06-28 21:47:12 +0100797 /* Link a buffer to each VI in the write-combining mapping */
798 for (index = 0; index < nic_data->n_piobufs; ++index) {
799 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
800 nic_data->piobuf_handle[index]);
801 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
802 nic_data->pio_write_vi_base + index);
803 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
804 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
805 NULL, 0, NULL);
806 if (rc) {
807 netif_err(efx, drv, efx->net_dev,
808 "failed to link VI %u to PIO buffer %u (%d)\n",
809 nic_data->pio_write_vi_base + index, index,
810 rc);
811 goto fail;
812 }
813 netif_dbg(efx, probe, efx->net_dev,
814 "linked VI %u to PIO buffer %u\n",
815 nic_data->pio_write_vi_base + index, index);
816 }
817
818 /* Link a buffer to each TX queue */
819 efx_for_each_channel(channel, efx) {
820 efx_for_each_channel_tx_queue(tx_queue, channel) {
821 /* We assign the PIO buffers to queues in
822 * reverse order to allow for the following
823 * special case.
824 */
825 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
826 tx_queue->channel->channel - 1) *
827 efx_piobuf_size);
828 index = offset / ER_DZ_TX_PIOBUF_SIZE;
829 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
830
831 /* When the host page size is 4K, the first
832 * host page in the WC mapping may be within
833 * the same VI page as the last TX queue. We
834 * can only link one buffer to each VI.
835 */
836 if (tx_queue->queue == nic_data->pio_write_vi_base) {
837 BUG_ON(index != 0);
838 rc = 0;
839 } else {
840 MCDI_SET_DWORD(inbuf,
841 LINK_PIOBUF_IN_PIOBUF_HANDLE,
842 nic_data->piobuf_handle[index]);
843 MCDI_SET_DWORD(inbuf,
844 LINK_PIOBUF_IN_TXQ_INSTANCE,
845 tx_queue->queue);
846 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
847 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
848 NULL, 0, NULL);
849 }
850
851 if (rc) {
852 /* This is non-fatal; the TX path just
853 * won't use PIO for this queue
854 */
855 netif_err(efx, drv, efx->net_dev,
856 "failed to link VI %u to PIO buffer %u (%d)\n",
857 tx_queue->queue, index, rc);
858 tx_queue->piobuf = NULL;
859 } else {
860 tx_queue->piobuf =
861 nic_data->pio_write_base +
862 index * EFX_VI_PAGE_SIZE + offset;
863 tx_queue->piobuf_offset = offset;
864 netif_dbg(efx, probe, efx->net_dev,
865 "linked VI %u to PIO buffer %u offset %x addr %p\n",
866 tx_queue->queue, index,
867 tx_queue->piobuf_offset,
868 tx_queue->piobuf);
869 }
870 }
871 }
872
873 return 0;
874
875fail:
876 while (index--) {
877 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
878 nic_data->pio_write_vi_base + index);
879 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
880 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
881 NULL, 0, NULL);
882 }
883 return rc;
884}
885
Edward Creec0795bf2016-05-24 18:53:36 +0100886static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
887{
888 struct efx_channel *channel;
889 struct efx_tx_queue *tx_queue;
890
891 /* All our existing PIO buffers went away */
892 efx_for_each_channel(channel, efx)
893 efx_for_each_channel_tx_queue(tx_queue, channel)
894 tx_queue->piobuf = NULL;
895}
896
Ben Hutchings183233b2013-06-28 21:47:12 +0100897#else /* !EFX_USE_PIO */
898
899static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
900{
901 return n == 0 ? 0 : -ENOBUFS;
902}
903
904static int efx_ef10_link_piobufs(struct efx_nic *efx)
905{
906 return 0;
907}
908
909static void efx_ef10_free_piobufs(struct efx_nic *efx)
910{
911}
912
Edward Creec0795bf2016-05-24 18:53:36 +0100913static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
914{
915}
916
Ben Hutchings183233b2013-06-28 21:47:12 +0100917#endif /* EFX_USE_PIO */
918
Ben Hutchings8127d662013-08-29 19:19:29 +0100919static void efx_ef10_remove(struct efx_nic *efx)
920{
921 struct efx_ef10_nic_data *nic_data = efx->nic_data;
922 int rc;
923
Shradha Shahf1122a32015-05-20 11:09:46 +0100924#ifdef CONFIG_SFC_SRIOV
925 struct efx_ef10_nic_data *nic_data_pf;
926 struct pci_dev *pci_dev_pf;
927 struct efx_nic *efx_pf;
928 struct ef10_vf *vf;
929
930 if (efx->pci_dev->is_virtfn) {
931 pci_dev_pf = efx->pci_dev->physfn;
932 if (pci_dev_pf) {
933 efx_pf = pci_get_drvdata(pci_dev_pf);
934 nic_data_pf = efx_pf->nic_data;
935 vf = nic_data_pf->vf + nic_data->vf_index;
936 vf->efx = NULL;
937 } else
938 netif_info(efx, drv, efx->net_dev,
939 "Could not get the PF id from VF\n");
940 }
941#endif
942
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100943 efx_ef10_cleanup_vlans(efx);
944 mutex_destroy(&nic_data->vlan_lock);
945
Ben Hutchings9aecda92013-12-05 21:28:42 +0000946 efx_ptp_remove(efx);
947
Ben Hutchings8127d662013-08-29 19:19:29 +0100948 efx_mcdi_mon_remove(efx);
949
Ben Hutchings8127d662013-08-29 19:19:29 +0100950 efx_ef10_rx_free_indir_table(efx);
951
Ben Hutchings183233b2013-06-28 21:47:12 +0100952 if (nic_data->wc_membase)
953 iounmap(nic_data->wc_membase);
954
Ben Hutchings8127d662013-08-29 19:19:29 +0100955 rc = efx_ef10_free_vis(efx);
956 WARN_ON(rc != 0);
957
Ben Hutchings183233b2013-06-28 21:47:12 +0100958 if (!nic_data->must_restore_piobufs)
959 efx_ef10_free_piobufs(efx);
960
Shradha Shah0f5c0842015-06-02 11:37:58 +0100961 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
962 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
963
Ben Hutchings8127d662013-08-29 19:19:29 +0100964 efx_mcdi_fini(efx);
965 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
966 kfree(nic_data);
967}
968
Shradha Shah88a37de2015-05-20 11:09:15 +0100969static int efx_ef10_probe_pf(struct efx_nic *efx)
970{
971 return efx_ef10_probe(efx);
972}
973
Andrew Rybchenko38d27f32016-06-15 17:52:08 +0100974int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
975 u32 *port_flags, u32 *vadaptor_flags,
976 unsigned int *vlan_tags)
977{
978 struct efx_ef10_nic_data *nic_data = efx->nic_data;
979 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
980 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
981 size_t outlen;
982 int rc;
983
984 if (nic_data->datapath_caps &
985 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
986 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
987 port_id);
988
989 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
990 outbuf, sizeof(outbuf), &outlen);
991 if (rc)
992 return rc;
993
994 if (outlen < sizeof(outbuf)) {
995 rc = -EIO;
996 return rc;
997 }
998 }
999
1000 if (port_flags)
1001 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1002 if (vadaptor_flags)
1003 *vadaptor_flags =
1004 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1005 if (vlan_tags)
1006 *vlan_tags =
1007 MCDI_DWORD(outbuf,
1008 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1009
1010 return 0;
1011}
1012
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001013int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1014{
1015 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1016
1017 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1018 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1019 NULL, 0, NULL);
1020}
1021
1022int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1023{
1024 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1025
1026 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1027 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1028 NULL, 0, NULL);
1029}
1030
1031int efx_ef10_vport_add_mac(struct efx_nic *efx,
1032 unsigned int port_id, u8 *mac)
1033{
1034 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1035
1036 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1037 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1038
1039 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1040 sizeof(inbuf), NULL, 0, NULL);
1041}
1042
1043int efx_ef10_vport_del_mac(struct efx_nic *efx,
1044 unsigned int port_id, u8 *mac)
1045{
1046 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1047
1048 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1049 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1050
1051 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1052 sizeof(inbuf), NULL, 0, NULL);
1053}
1054
Shradha Shah88a37de2015-05-20 11:09:15 +01001055#ifdef CONFIG_SFC_SRIOV
1056static int efx_ef10_probe_vf(struct efx_nic *efx)
1057{
1058 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001059 struct pci_dev *pci_dev_pf;
1060
1061 /* If the parent PF has no VF data structure, it doesn't know about this
1062 * VF so fail probe. The VF needs to be re-created. This can happen
1063 * if the PF driver is unloaded while the VF is assigned to a guest.
1064 */
1065 pci_dev_pf = efx->pci_dev->physfn;
1066 if (pci_dev_pf) {
1067 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1068 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1069
1070 if (!nic_data_pf->vf) {
1071 netif_info(efx, drv, efx->net_dev,
1072 "The VF cannot link to its parent PF; "
1073 "please destroy and re-create the VF\n");
1074 return -EBUSY;
1075 }
1076 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001077
1078 rc = efx_ef10_probe(efx);
1079 if (rc)
1080 return rc;
1081
1082 rc = efx_ef10_get_vf_index(efx);
1083 if (rc)
1084 goto fail;
1085
Shradha Shahf1122a32015-05-20 11:09:46 +01001086 if (efx->pci_dev->is_virtfn) {
1087 if (efx->pci_dev->physfn) {
1088 struct efx_nic *efx_pf =
1089 pci_get_drvdata(efx->pci_dev->physfn);
1090 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1091 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1092
1093 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001094 nic_data_p->vf[nic_data->vf_index].pci_dev =
1095 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001096 } else
1097 netif_info(efx, drv, efx->net_dev,
1098 "Could not get the PF id from VF\n");
1099 }
1100
Shradha Shah88a37de2015-05-20 11:09:15 +01001101 return 0;
1102
1103fail:
1104 efx_ef10_remove(efx);
1105 return rc;
1106}
1107#else
1108static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1109{
1110 return 0;
1111}
1112#endif
1113
Ben Hutchings8127d662013-08-29 19:19:29 +01001114static int efx_ef10_alloc_vis(struct efx_nic *efx,
1115 unsigned int min_vis, unsigned int max_vis)
1116{
1117 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1118 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1119 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1120 size_t outlen;
1121 int rc;
1122
1123 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1124 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1125 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1126 outbuf, sizeof(outbuf), &outlen);
1127 if (rc != 0)
1128 return rc;
1129
1130 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1131 return -EIO;
1132
1133 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1134 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1135
1136 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1137 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1138 return 0;
1139}
1140
Ben Hutchings183233b2013-06-28 21:47:12 +01001141/* Note that the failure path of this function does not free
1142 * resources, as this will be done by efx_ef10_remove().
1143 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001144static int efx_ef10_dimension_resources(struct efx_nic *efx)
1145{
Ben Hutchings183233b2013-06-28 21:47:12 +01001146 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1147 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001148 unsigned int min_vis = max(EFX_TXQ_TYPES,
1149 efx_separate_tx_channels ? 2 : 1);
1150 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001151 void __iomem *membase;
1152 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001153
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001154 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001155
1156#ifdef EFX_USE_PIO
1157 /* Try to allocate PIO buffers if wanted and if the full
1158 * number of PIO buffers would be sufficient to allocate one
1159 * copy-buffer per TX channel. Failure is non-fatal, as there
1160 * are only a small number of PIO buffers shared between all
1161 * functions of the controller.
1162 */
1163 if (efx_piobuf_size != 0 &&
1164 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1165 efx->n_tx_channels) {
1166 unsigned int n_piobufs =
1167 DIV_ROUND_UP(efx->n_tx_channels,
1168 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
1169
1170 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1171 if (rc)
1172 netif_err(efx, probe, efx->net_dev,
1173 "failed to allocate PIO buffers (%d)\n", rc);
1174 else
1175 netif_dbg(efx, probe, efx->net_dev,
1176 "allocated %u PIO buffers\n", n_piobufs);
1177 }
1178#else
1179 nic_data->n_piobufs = 0;
1180#endif
1181
1182 /* PIO buffers should be mapped with write-combining enabled,
1183 * and we want to make single UC and WC mappings rather than
1184 * several of each (in fact that's the only option if host
1185 * page size is >4K). So we may allocate some extra VIs just
1186 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001187 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001188 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001189 * first half of the next VI. Then the WC mapping begins with
1190 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001191 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001192 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001193 ER_DZ_TX_PIOBUF);
1194 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001195 /* pio_write_vi_base rounds down to give the number of complete
1196 * VIs inside the UC mapping.
1197 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001198 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1199 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1200 nic_data->n_piobufs) *
1201 EFX_VI_PAGE_SIZE) -
1202 uc_mem_map_size);
1203 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1204 } else {
1205 pio_write_vi_base = 0;
1206 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001207 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001208 }
1209
1210 /* In case the last attached driver failed to free VIs, do it now */
1211 rc = efx_ef10_free_vis(efx);
1212 if (rc != 0)
1213 return rc;
1214
1215 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1216 if (rc != 0)
1217 return rc;
1218
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001219 if (nic_data->n_allocated_vis < channel_vis) {
1220 netif_info(efx, drv, efx->net_dev,
1221 "Could not allocate enough VIs to satisfy RSS"
1222 " requirements. Performance may not be optimal.\n");
1223 /* We didn't get the VIs to populate our channels.
1224 * We could keep what we got but then we'd have more
1225 * interrupts than we need.
1226 * Instead calculate new max_channels and restart
1227 */
1228 efx->max_channels = nic_data->n_allocated_vis;
1229 efx->max_tx_channels =
1230 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1231
1232 efx_ef10_free_vis(efx);
1233 return -EAGAIN;
1234 }
1235
Ben Hutchings183233b2013-06-28 21:47:12 +01001236 /* If we didn't get enough VIs to map all the PIO buffers, free the
1237 * PIO buffers
1238 */
1239 if (nic_data->n_piobufs &&
1240 nic_data->n_allocated_vis <
1241 pio_write_vi_base + nic_data->n_piobufs) {
1242 netif_dbg(efx, probe, efx->net_dev,
1243 "%u VIs are not sufficient to map %u PIO buffers\n",
1244 nic_data->n_allocated_vis, nic_data->n_piobufs);
1245 efx_ef10_free_piobufs(efx);
1246 }
1247
1248 /* Shrink the original UC mapping of the memory BAR */
1249 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1250 if (!membase) {
1251 netif_err(efx, probe, efx->net_dev,
1252 "could not shrink memory BAR to %x\n",
1253 uc_mem_map_size);
1254 return -ENOMEM;
1255 }
1256 iounmap(efx->membase);
1257 efx->membase = membase;
1258
1259 /* Set up the WC mapping if needed */
1260 if (wc_mem_map_size) {
1261 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1262 uc_mem_map_size,
1263 wc_mem_map_size);
1264 if (!nic_data->wc_membase) {
1265 netif_err(efx, probe, efx->net_dev,
1266 "could not allocate WC mapping of size %x\n",
1267 wc_mem_map_size);
1268 return -ENOMEM;
1269 }
1270 nic_data->pio_write_vi_base = pio_write_vi_base;
1271 nic_data->pio_write_base =
1272 nic_data->wc_membase +
1273 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1274 uc_mem_map_size);
1275
1276 rc = efx_ef10_link_piobufs(efx);
1277 if (rc)
1278 efx_ef10_free_piobufs(efx);
1279 }
1280
1281 netif_dbg(efx, probe, efx->net_dev,
1282 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1283 &efx->membase_phys, efx->membase, uc_mem_map_size,
1284 nic_data->wc_membase, wc_mem_map_size);
1285
1286 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001287}
1288
1289static int efx_ef10_init_nic(struct efx_nic *efx)
1290{
1291 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1292 int rc;
1293
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001294 if (nic_data->must_check_datapath_caps) {
1295 rc = efx_ef10_init_datapath_caps(efx);
1296 if (rc)
1297 return rc;
1298 nic_data->must_check_datapath_caps = false;
1299 }
1300
Ben Hutchings8127d662013-08-29 19:19:29 +01001301 if (nic_data->must_realloc_vis) {
1302 /* We cannot let the number of VIs change now */
1303 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1304 nic_data->n_allocated_vis);
1305 if (rc)
1306 return rc;
1307 nic_data->must_realloc_vis = false;
1308 }
1309
Ben Hutchings183233b2013-06-28 21:47:12 +01001310 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1311 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1312 if (rc == 0) {
1313 rc = efx_ef10_link_piobufs(efx);
1314 if (rc)
1315 efx_ef10_free_piobufs(efx);
1316 }
1317
1318 /* Log an error on failure, but this is non-fatal */
1319 if (rc)
1320 netif_err(efx, drv, efx->net_dev,
1321 "failed to restore PIO buffers (%d)\n", rc);
1322 nic_data->must_restore_piobufs = false;
1323 }
1324
Jon Cooper267c0152015-05-06 00:59:38 +01001325 /* don't fail init if RSS setup doesn't work */
1326 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1327
Ben Hutchings8127d662013-08-29 19:19:29 +01001328 return 0;
1329}
1330
Jon Cooper3e336262014-01-17 19:48:06 +00001331static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1332{
1333 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001334#ifdef CONFIG_SFC_SRIOV
1335 unsigned int i;
1336#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001337
1338 /* All our allocations have been reset */
1339 nic_data->must_realloc_vis = true;
1340 nic_data->must_restore_filters = true;
1341 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001342 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001343 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001344
1345 /* Driver-created vswitches and vports must be re-created */
1346 nic_data->must_probe_vswitching = true;
1347 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1348#ifdef CONFIG_SFC_SRIOV
1349 if (nic_data->vf)
1350 for (i = 0; i < efx->vf_count; i++)
1351 nic_data->vf[i].vport_id = 0;
1352#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001353}
1354
Jon Cooper087e9022015-05-20 11:11:35 +01001355static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1356{
1357 if (reason == RESET_TYPE_MC_FAILURE)
1358 return RESET_TYPE_DATAPATH;
1359
1360 return efx_mcdi_map_reset_reason(reason);
1361}
1362
Ben Hutchings8127d662013-08-29 19:19:29 +01001363static int efx_ef10_map_reset_flags(u32 *flags)
1364{
1365 enum {
1366 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1367 ETH_RESET_SHARED_SHIFT),
1368 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1369 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1370 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1371 ETH_RESET_SHARED_SHIFT)
1372 };
1373
1374 /* We assume for now that our PCI function is permitted to
1375 * reset everything.
1376 */
1377
1378 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1379 *flags &= ~EF10_RESET_MC;
1380 return RESET_TYPE_WORLD;
1381 }
1382
1383 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1384 *flags &= ~EF10_RESET_PORT;
1385 return RESET_TYPE_ALL;
1386 }
1387
1388 /* no invisible reset implemented */
1389
1390 return -EINVAL;
1391}
1392
Jon Cooper3e336262014-01-17 19:48:06 +00001393static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1394{
1395 int rc = efx_mcdi_reset(efx, reset_type);
1396
Daniel Pieczko27324822015-07-31 11:14:54 +01001397 /* Unprivileged functions return -EPERM, but need to return success
1398 * here so that the datapath is brought back up.
1399 */
1400 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1401 rc = 0;
1402
Jon Cooper3e336262014-01-17 19:48:06 +00001403 /* If it was a port reset, trigger reallocation of MC resources.
1404 * Note that on an MC reset nothing needs to be done now because we'll
1405 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001406 * For an FLR, we never get an MC reset event, but the MC has reset all
1407 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001408 */
Edward Creee2835462014-04-16 19:27:48 +01001409 if ((reset_type == RESET_TYPE_ALL ||
1410 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001411 efx_ef10_reset_mc_allocations(efx);
1412 return rc;
1413}
1414
Ben Hutchings8127d662013-08-29 19:19:29 +01001415#define EF10_DMA_STAT(ext_name, mcdi_name) \
1416 [EF10_STAT_ ## ext_name] = \
1417 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1418#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1419 [EF10_STAT_ ## int_name] = \
1420 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1421#define EF10_OTHER_STAT(ext_name) \
1422 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001423#define GENERIC_SW_STAT(ext_name) \
1424 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001425
1426static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001427 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1428 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1429 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1430 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1431 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1432 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1433 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1434 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1435 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1436 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1437 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1438 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1439 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1440 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1441 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1442 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1443 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1444 EF10_OTHER_STAT(port_rx_good_bytes),
1445 EF10_OTHER_STAT(port_rx_bad_bytes),
1446 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1447 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1448 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1449 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1450 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1451 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1452 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1453 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1454 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1455 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1456 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1457 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1458 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1459 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1460 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1461 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1462 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1463 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1464 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1465 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1466 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1467 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001468 GENERIC_SW_STAT(rx_nodesc_trunc),
1469 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001470 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1471 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1472 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1473 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1474 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1475 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1476 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1477 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1478 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1479 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1480 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1481 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001482 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1483 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1484 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1485 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1486 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1487 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1488 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1489 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1490 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1491 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1492 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1493 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1494 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1495 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1496 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1497 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1498 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1499 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001500};
1501
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001502#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1503 (1ULL << EF10_STAT_port_tx_packets) | \
1504 (1ULL << EF10_STAT_port_tx_pause) | \
1505 (1ULL << EF10_STAT_port_tx_unicast) | \
1506 (1ULL << EF10_STAT_port_tx_multicast) | \
1507 (1ULL << EF10_STAT_port_tx_broadcast) | \
1508 (1ULL << EF10_STAT_port_rx_bytes) | \
1509 (1ULL << \
1510 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1511 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1512 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1513 (1ULL << EF10_STAT_port_rx_packets) | \
1514 (1ULL << EF10_STAT_port_rx_good) | \
1515 (1ULL << EF10_STAT_port_rx_bad) | \
1516 (1ULL << EF10_STAT_port_rx_pause) | \
1517 (1ULL << EF10_STAT_port_rx_control) | \
1518 (1ULL << EF10_STAT_port_rx_unicast) | \
1519 (1ULL << EF10_STAT_port_rx_multicast) | \
1520 (1ULL << EF10_STAT_port_rx_broadcast) | \
1521 (1ULL << EF10_STAT_port_rx_lt64) | \
1522 (1ULL << EF10_STAT_port_rx_64) | \
1523 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1524 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1525 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1526 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1527 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1528 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1529 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1530 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1531 (1ULL << EF10_STAT_port_rx_overflow) | \
1532 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001533 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1534 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001535
Edward Cree69b365c2016-08-26 15:12:41 +01001536/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1537 * For a 10G/40G switchable port we do not expose these because they might
1538 * not include all the packets they should.
1539 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001540 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001541#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1542 (1ULL << EF10_STAT_port_tx_lt64) | \
1543 (1ULL << EF10_STAT_port_tx_64) | \
1544 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1545 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1546 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1547 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1548 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1549 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001550
1551/* These statistics are only provided by the 40G MAC. For a 10G/40G
1552 * switchable port we do expose these because the errors will otherwise
1553 * be silent.
1554 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001555#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1556 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001557
Edward Cree568d7a02013-09-25 17:32:09 +01001558/* These statistics are only provided if the firmware supports the
1559 * capability PM_AND_RXDP_COUNTERS.
1560 */
1561#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001562 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1563 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1564 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1565 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1566 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1567 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1568 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1569 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1570 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1571 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1572 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1573 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001574
Edward Cree4bae9132013-09-27 18:52:49 +01001575static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001576{
Edward Cree4bae9132013-09-27 18:52:49 +01001577 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001578 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001579 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001580
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001581 if (!(efx->mcdi->fn_flags &
1582 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1583 return 0;
1584
Edward Cree69b365c2016-08-26 15:12:41 +01001585 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001586 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001587 /* 8000 series have everything even at 40G */
1588 if (nic_data->datapath_caps2 &
1589 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1590 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1591 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001592 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001593 }
Edward Cree568d7a02013-09-25 17:32:09 +01001594
1595 if (nic_data->datapath_caps &
1596 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1597 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1598
Edward Cree4bae9132013-09-27 18:52:49 +01001599 return raw_mask;
1600}
1601
1602static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1603{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001604 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001605 u64 raw_mask[2];
1606
1607 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1608
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001609 /* Only show vadaptor stats when EVB capability is present */
1610 if (nic_data->datapath_caps &
1611 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1612 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1613 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1614 } else {
1615 raw_mask[1] = 0;
1616 }
Edward Cree4bae9132013-09-27 18:52:49 +01001617
1618#if BITS_PER_LONG == 64
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001619 mask[0] = raw_mask[0];
1620 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001621#else
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001622 mask[0] = raw_mask[0] & 0xffffffff;
1623 mask[1] = raw_mask[0] >> 32;
1624 mask[2] = raw_mask[1] & 0xffffffff;
1625 mask[3] = raw_mask[1] >> 32;
Edward Cree4bae9132013-09-27 18:52:49 +01001626#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001627}
1628
1629static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1630{
Edward Cree4bae9132013-09-27 18:52:49 +01001631 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1632
1633 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001634 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001635 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001636}
1637
Daniel Pieczkod7788192015-06-02 11:39:20 +01001638static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1639 struct rtnl_link_stats64 *core_stats)
1640{
1641 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1642 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1643 u64 *stats = nic_data->stats;
1644 size_t stats_count = 0, index;
1645
1646 efx_ef10_get_stat_mask(efx, mask);
1647
1648 if (full_stats) {
1649 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1650 if (efx_ef10_stat_desc[index].name) {
1651 *full_stats++ = stats[index];
1652 ++stats_count;
1653 }
1654 }
1655 }
1656
Bert Kenwardfbe43072015-08-26 16:39:03 +01001657 if (!core_stats)
1658 return stats_count;
1659
1660 if (nic_data->datapath_caps &
1661 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1662 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001663 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1664 stats[EF10_STAT_rx_multicast] +
1665 stats[EF10_STAT_rx_broadcast];
1666 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1667 stats[EF10_STAT_tx_multicast] +
1668 stats[EF10_STAT_tx_broadcast];
1669 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1670 stats[EF10_STAT_rx_multicast_bytes] +
1671 stats[EF10_STAT_rx_broadcast_bytes];
1672 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1673 stats[EF10_STAT_tx_multicast_bytes] +
1674 stats[EF10_STAT_tx_broadcast_bytes];
1675 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001676 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001677 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1678 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1679 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1680 core_stats->rx_errors = core_stats->rx_crc_errors;
1681 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001682 } else {
1683 /* Use port stats. */
1684 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1685 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1686 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1687 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1688 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1689 stats[GENERIC_STAT_rx_nodesc_trunc] +
1690 stats[GENERIC_STAT_rx_noskb_drops];
1691 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1692 core_stats->rx_length_errors =
1693 stats[EF10_STAT_port_rx_gtjumbo] +
1694 stats[EF10_STAT_port_rx_length_error];
1695 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1696 core_stats->rx_frame_errors =
1697 stats[EF10_STAT_port_rx_align_error];
1698 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1699 core_stats->rx_errors = (core_stats->rx_length_errors +
1700 core_stats->rx_crc_errors +
1701 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001702 }
1703
1704 return stats_count;
1705}
1706
1707static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001708{
1709 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001710 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001711 __le64 generation_start, generation_end;
1712 u64 *stats = nic_data->stats;
1713 __le64 *dma_stats;
1714
Edward Cree4bae9132013-09-27 18:52:49 +01001715 efx_ef10_get_stat_mask(efx, mask);
1716
Ben Hutchings8127d662013-08-29 19:19:29 +01001717 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001718
1719 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1720 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1721 return 0;
1722 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001723 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001724 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001725 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001726 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1727 if (generation_end != generation_start)
1728 return -EAGAIN;
1729
1730 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001731 efx_nic_fix_nodesc_drop_stat(efx,
1732 &stats[EF10_STAT_port_rx_nodesc_drops]);
1733 stats[EF10_STAT_port_rx_good_bytes] =
1734 stats[EF10_STAT_port_rx_bytes] -
1735 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1736 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1737 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001738 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001739 return 0;
1740}
1741
1742
Daniel Pieczkod7788192015-06-02 11:39:20 +01001743static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1744 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001745{
Ben Hutchings8127d662013-08-29 19:19:29 +01001746 int retry;
1747
1748 /* If we're unlucky enough to read statistics during the DMA, wait
1749 * up to 10ms for it to finish (typically takes <500us)
1750 */
1751 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001752 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001753 break;
1754 udelay(100);
1755 }
1756
Daniel Pieczkod7788192015-06-02 11:39:20 +01001757 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1758}
1759
1760static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1761{
1762 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1763 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1764 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1765 __le64 generation_start, generation_end;
1766 u64 *stats = nic_data->stats;
1767 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1768 struct efx_buffer stats_buf;
1769 __le64 *dma_stats;
1770 int rc;
1771
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001772 spin_unlock_bh(&efx->stats_lock);
1773
1774 if (in_interrupt()) {
1775 /* If in atomic context, cannot update stats. Just update the
1776 * software stats and return so the caller can continue.
1777 */
1778 spin_lock_bh(&efx->stats_lock);
1779 efx_update_sw_stats(efx, stats);
1780 return 0;
1781 }
1782
Daniel Pieczkod7788192015-06-02 11:39:20 +01001783 efx_ef10_get_stat_mask(efx, mask);
1784
1785 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001786 if (rc) {
1787 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001788 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001789 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001790
1791 dma_stats = stats_buf.addr;
1792 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1793
1794 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1795 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001796 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001797 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1798 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1799
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001800 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1801 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001802 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001803 if (rc) {
1804 /* Expect ENOENT if DMA queues have not been set up */
1805 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1806 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1807 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001808 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001809 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001810
1811 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001812 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1813 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001814 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001815 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001816 rmb();
1817 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1818 stats, stats_buf.addr, false);
1819 rmb();
1820 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1821 if (generation_end != generation_start) {
1822 rc = -EAGAIN;
1823 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001824 }
1825
Daniel Pieczkod7788192015-06-02 11:39:20 +01001826 efx_update_sw_stats(efx, stats);
1827out:
1828 efx_nic_free_buffer(efx, &stats_buf);
1829 return rc;
1830}
Ben Hutchings8127d662013-08-29 19:19:29 +01001831
Daniel Pieczkod7788192015-06-02 11:39:20 +01001832static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1833 struct rtnl_link_stats64 *core_stats)
1834{
1835 if (efx_ef10_try_update_nic_stats_vf(efx))
1836 return 0;
1837
1838 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001839}
1840
1841static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1842{
1843 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001844 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001845 efx_dword_t timer_cmd;
1846
Bert Kenward539de7c2016-08-11 13:02:09 +01001847 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001848 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001849 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001850 } else {
1851 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001852 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001853 }
1854
Bert Kenward539de7c2016-08-11 13:02:09 +01001855 if (EFX_EF10_WORKAROUND_61265(efx)) {
1856 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1857 unsigned int ns = usecs * 1000;
1858
1859 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1860 channel->channel);
1861 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1862 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1863 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1864
1865 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1866 inbuf, sizeof(inbuf), 0, NULL, 0);
1867 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1868 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1869
Ben Hutchings8127d662013-08-29 19:19:29 +01001870 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1871 EFE_DD_EVQ_IND_TIMER_FLAGS,
1872 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001873 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001874 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1875 channel->channel);
1876 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001877 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1878
Ben Hutchings8127d662013-08-29 19:19:29 +01001879 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001880 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001881 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1882 channel->channel);
1883 }
1884}
1885
Shradha Shah02246a72015-05-06 00:58:14 +01001886static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1887 struct ethtool_wolinfo *wol) {}
1888
1889static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1890{
1891 return -EOPNOTSUPP;
1892}
1893
Ben Hutchings8127d662013-08-29 19:19:29 +01001894static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1895{
1896 wol->supported = 0;
1897 wol->wolopts = 0;
1898 memset(&wol->sopass, 0, sizeof(wol->sopass));
1899}
1900
1901static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1902{
1903 if (type != 0)
1904 return -EINVAL;
1905 return 0;
1906}
1907
1908static void efx_ef10_mcdi_request(struct efx_nic *efx,
1909 const efx_dword_t *hdr, size_t hdr_len,
1910 const efx_dword_t *sdu, size_t sdu_len)
1911{
1912 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1913 u8 *pdu = nic_data->mcdi_buf.addr;
1914
1915 memcpy(pdu, hdr, hdr_len);
1916 memcpy(pdu + hdr_len, sdu, sdu_len);
1917 wmb();
1918
1919 /* The hardware provides 'low' and 'high' (doorbell) registers
1920 * for passing the 64-bit address of an MCDI request to
1921 * firmware. However the dwords are swapped by firmware. The
1922 * least significant bits of the doorbell are then 0 for all
1923 * MCDI requests due to alignment.
1924 */
1925 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1926 ER_DZ_MC_DB_LWRD);
1927 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1928 ER_DZ_MC_DB_HWRD);
1929}
1930
1931static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1932{
1933 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1934 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1935
1936 rmb();
1937 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1938}
1939
1940static void
1941efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1942 size_t offset, size_t outlen)
1943{
1944 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1945 const u8 *pdu = nic_data->mcdi_buf.addr;
1946
1947 memcpy(outbuf, pdu + offset, outlen);
1948}
1949
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001950static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1951{
1952 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1953
1954 /* All our allocations have been reset */
1955 efx_ef10_reset_mc_allocations(efx);
1956
1957 /* The datapath firmware might have been changed */
1958 nic_data->must_check_datapath_caps = true;
1959
1960 /* MAC statistics have been cleared on the NIC; clear the local
1961 * statistic that we update with efx_update_diff_stat().
1962 */
1963 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1964}
1965
Ben Hutchings8127d662013-08-29 19:19:29 +01001966static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1967{
1968 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1969 int rc;
1970
1971 rc = efx_ef10_get_warm_boot_count(efx);
1972 if (rc < 0) {
1973 /* The firmware is presumably in the process of
1974 * rebooting. However, we are supposed to report each
1975 * reboot just once, so we must only do that once we
1976 * can read and store the updated warm boot count.
1977 */
1978 return 0;
1979 }
1980
1981 if (rc == nic_data->warm_boot_count)
1982 return 0;
1983
1984 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001985 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01001986
Ben Hutchings8127d662013-08-29 19:19:29 +01001987 return -EIO;
1988}
1989
1990/* Handle an MSI interrupt
1991 *
1992 * Handle an MSI hardware interrupt. This routine schedules event
1993 * queue processing. No interrupt acknowledgement cycle is necessary.
1994 * Also, we never need to check that the interrupt is for us, since
1995 * MSI interrupts cannot be shared.
1996 */
1997static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1998{
1999 struct efx_msi_context *context = dev_id;
2000 struct efx_nic *efx = context->efx;
2001
2002 netif_vdbg(efx, intr, efx->net_dev,
2003 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2004
2005 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2006 /* Note test interrupts */
2007 if (context->index == efx->irq_level)
2008 efx->last_irq_cpu = raw_smp_processor_id();
2009
2010 /* Schedule processing of the channel */
2011 efx_schedule_channel_irq(efx->channel[context->index]);
2012 }
2013
2014 return IRQ_HANDLED;
2015}
2016
2017static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2018{
2019 struct efx_nic *efx = dev_id;
2020 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2021 struct efx_channel *channel;
2022 efx_dword_t reg;
2023 u32 queues;
2024
2025 /* Read the ISR which also ACKs the interrupts */
2026 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2027 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2028
2029 if (queues == 0)
2030 return IRQ_NONE;
2031
2032 if (likely(soft_enabled)) {
2033 /* Note test interrupts */
2034 if (queues & (1U << efx->irq_level))
2035 efx->last_irq_cpu = raw_smp_processor_id();
2036
2037 efx_for_each_channel(channel, efx) {
2038 if (queues & 1)
2039 efx_schedule_channel_irq(channel);
2040 queues >>= 1;
2041 }
2042 }
2043
2044 netif_vdbg(efx, intr, efx->net_dev,
2045 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2046 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2047
2048 return IRQ_HANDLED;
2049}
2050
Jon Cooper942e2982016-08-26 15:13:30 +01002051static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002052{
2053 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2054
Jon Cooper942e2982016-08-26 15:13:30 +01002055 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2056 NULL) == 0)
2057 return -ENOTSUPP;
2058
Ben Hutchings8127d662013-08-29 19:19:29 +01002059 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2060
2061 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002062 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002063 inbuf, sizeof(inbuf), NULL, 0, NULL);
2064}
2065
2066static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2067{
2068 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2069 (tx_queue->ptr_mask + 1) *
2070 sizeof(efx_qword_t),
2071 GFP_KERNEL);
2072}
2073
2074/* This writes to the TX_DESC_WPTR and also pushes data */
2075static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2076 const efx_qword_t *txd)
2077{
2078 unsigned int write_ptr;
2079 efx_oword_t reg;
2080
2081 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2082 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2083 reg.qword[0] = *txd;
2084 efx_writeo_page(tx_queue->efx, &reg,
2085 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2086}
2087
2088static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2089{
2090 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2091 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002092 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2093 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2094 struct efx_channel *channel = tx_queue->channel;
2095 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002096 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002097 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002098 dma_addr_t dma_addr;
2099 efx_qword_t *txd;
2100 int rc;
2101 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002102 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002103
2104 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2105 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2106 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2107 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
2108 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
2109 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2110 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2111 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002112 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002113
2114 dma_addr = tx_queue->txd.buf.dma_addr;
2115
2116 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2117 tx_queue->queue, entries, (u64)dma_addr);
2118
2119 for (i = 0; i < entries; ++i) {
2120 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2121 dma_addr += EFX_BUF_SIZE;
2122 }
2123
2124 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2125
2126 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002127 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002128 if (rc)
2129 goto fail;
2130
2131 /* A previous user of this TX queue might have set us up the
2132 * bomb by writing a descriptor to the TX push collector but
2133 * not the doorbell. (Each collector belongs to a port, not a
2134 * queue or function, so cannot easily be reset.) We must
2135 * attempt to push a no-op descriptor in its place.
2136 */
2137 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2138 tx_queue->insert_count = 1;
2139 txd = efx_tx_desc(tx_queue, 0);
2140 EFX_POPULATE_QWORD_4(*txd,
2141 ESF_DZ_TX_DESC_IS_OPT, true,
2142 ESF_DZ_TX_OPTION_TYPE,
2143 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2144 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2145 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2146 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002147
2148 if (nic_data->datapath_caps &
2149 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2150 tx_queue->tso_version = 1;
2151 }
2152
Ben Hutchings8127d662013-08-29 19:19:29 +01002153 wmb();
2154 efx_ef10_push_tx_desc(tx_queue, txd);
2155
2156 return;
2157
2158fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002159 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2160 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002161}
2162
2163static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2164{
2165 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002166 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002167 struct efx_nic *efx = tx_queue->efx;
2168 size_t outlen;
2169 int rc;
2170
2171 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2172 tx_queue->queue);
2173
Edward Cree1e0b8122013-05-31 18:36:12 +01002174 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002175 outbuf, sizeof(outbuf), &outlen);
2176
2177 if (rc && rc != -EALREADY)
2178 goto fail;
2179
2180 return;
2181
2182fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002183 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2184 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002185}
2186
2187static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2188{
2189 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2190}
2191
2192/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2193static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2194{
2195 unsigned int write_ptr;
2196 efx_dword_t reg;
2197
2198 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2199 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2200 efx_writed_page(tx_queue->efx, &reg,
2201 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2202}
2203
2204static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2205{
2206 unsigned int old_write_count = tx_queue->write_count;
2207 struct efx_tx_buffer *buffer;
2208 unsigned int write_ptr;
2209 efx_qword_t *txd;
2210
Martin Habetsb2663a42015-11-02 12:51:31 +00002211 tx_queue->xmit_more_available = false;
2212 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2213 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002214
2215 do {
2216 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2217 buffer = &tx_queue->buffer[write_ptr];
2218 txd = efx_tx_desc(tx_queue, write_ptr);
2219 ++tx_queue->write_count;
2220
2221 /* Create TX descriptor ring entry */
2222 if (buffer->flags & EFX_TX_BUF_OPTION) {
2223 *txd = buffer->option;
2224 } else {
2225 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2226 EFX_POPULATE_QWORD_3(
2227 *txd,
2228 ESF_DZ_TX_KER_CONT,
2229 buffer->flags & EFX_TX_BUF_CONT,
2230 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2231 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2232 }
2233 } while (tx_queue->write_count != tx_queue->insert_count);
2234
2235 wmb(); /* Ensure descriptors are written before they are fetched */
2236
2237 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2238 txd = efx_tx_desc(tx_queue,
2239 old_write_count & tx_queue->ptr_mask);
2240 efx_ef10_push_tx_desc(tx_queue, txd);
2241 ++tx_queue->pushes;
2242 } else {
2243 efx_ef10_notify_tx_desc(tx_queue);
2244 }
2245}
2246
Jon Cooper267c0152015-05-06 00:59:38 +01002247static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2248 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002249{
2250 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2251 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002252 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002253 size_t outlen;
2254 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002255 u32 alloc_type = exclusive ?
2256 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2257 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2258 unsigned rss_spread = exclusive ?
2259 efx->rss_spread :
2260 min(rounddown_pow_of_two(efx->rss_spread),
2261 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2262
2263 if (!exclusive && rss_spread == 1) {
2264 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2265 if (context_size)
2266 *context_size = 1;
2267 return 0;
2268 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002269
Jon Cooperdcb41232016-04-25 16:51:00 +01002270 if (nic_data->datapath_caps &
2271 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2272 return -EOPNOTSUPP;
2273
Ben Hutchings8127d662013-08-29 19:19:29 +01002274 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002275 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002276 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2277 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002278
2279 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2280 outbuf, sizeof(outbuf), &outlen);
2281 if (rc != 0)
2282 return rc;
2283
2284 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2285 return -EIO;
2286
2287 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2288
Jon Cooper267c0152015-05-06 00:59:38 +01002289 if (context_size)
2290 *context_size = rss_spread;
2291
Ben Hutchings8127d662013-08-29 19:19:29 +01002292 return 0;
2293}
2294
2295static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2296{
2297 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2298 int rc;
2299
2300 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2301 context);
2302
2303 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2304 NULL, 0, NULL);
2305 WARN_ON(rc != 0);
2306}
2307
Jon Cooper267c0152015-05-06 00:59:38 +01002308static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2309 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002310{
2311 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2312 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2313 int i, rc;
2314
2315 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2316 context);
2317 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2318 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2319
2320 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2321 MCDI_PTR(tablebuf,
2322 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002323 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002324
2325 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2326 sizeof(tablebuf), NULL, 0, NULL);
2327 if (rc != 0)
2328 return rc;
2329
2330 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2331 context);
2332 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2333 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2334 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2335 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2336 efx->rx_hash_key[i];
2337
2338 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2339 sizeof(keybuf), NULL, 0, NULL);
2340}
2341
2342static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2343{
2344 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2345
2346 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2347 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2348 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2349}
2350
Jon Cooper267c0152015-05-06 00:59:38 +01002351static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2352 unsigned *context_size)
2353{
2354 u32 new_rx_rss_context;
2355 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2356 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2357 false, context_size);
2358
2359 if (rc != 0)
2360 return rc;
2361
2362 nic_data->rx_rss_context = new_rx_rss_context;
2363 nic_data->rx_rss_context_exclusive = false;
2364 efx_set_default_rx_indir_table(efx);
2365 return 0;
2366}
2367
2368static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2369 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002370{
2371 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2372 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002373 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002374
Jon Cooper267c0152015-05-06 00:59:38 +01002375 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2376 !nic_data->rx_rss_context_exclusive) {
2377 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2378 true, NULL);
2379 if (rc == -EOPNOTSUPP)
2380 return rc;
2381 else if (rc != 0)
2382 goto fail1;
2383 } else {
2384 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002385 }
2386
Jon Cooper267c0152015-05-06 00:59:38 +01002387 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2388 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002389 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002390 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002391
Jon Cooper267c0152015-05-06 00:59:38 +01002392 if (nic_data->rx_rss_context != new_rx_rss_context)
2393 efx_ef10_rx_free_indir_table(efx);
2394 nic_data->rx_rss_context = new_rx_rss_context;
2395 nic_data->rx_rss_context_exclusive = true;
2396 if (rx_indir_table != efx->rx_indir_table)
2397 memcpy(efx->rx_indir_table, rx_indir_table,
2398 sizeof(efx->rx_indir_table));
2399 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002400
Jon Cooper267c0152015-05-06 00:59:38 +01002401fail2:
2402 if (new_rx_rss_context != nic_data->rx_rss_context)
2403 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2404fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002405 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002406 return rc;
2407}
2408
2409static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2410 const u32 *rx_indir_table)
2411{
2412 int rc;
2413
2414 if (efx->rss_spread == 1)
2415 return 0;
2416
2417 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2418
2419 if (rc == -ENOBUFS && !user) {
2420 unsigned context_size;
2421 bool mismatch = false;
2422 size_t i;
2423
2424 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2425 i++)
2426 mismatch = rx_indir_table[i] !=
2427 ethtool_rxfh_indir_default(i, efx->rss_spread);
2428
2429 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2430 if (rc == 0) {
2431 if (context_size != efx->rss_spread)
2432 netif_warn(efx, probe, efx->net_dev,
2433 "Could not allocate an exclusive RSS"
2434 " context; allocated a shared one of"
2435 " different size."
2436 " Wanted %u, got %u.\n",
2437 efx->rss_spread, context_size);
2438 else if (mismatch)
2439 netif_warn(efx, probe, efx->net_dev,
2440 "Could not allocate an exclusive RSS"
2441 " context; allocated a shared one but"
2442 " could not apply custom"
2443 " indirection.\n");
2444 else
2445 netif_info(efx, probe, efx->net_dev,
2446 "Could not allocate an exclusive RSS"
2447 " context; allocated a shared one.\n");
2448 }
2449 }
2450 return rc;
2451}
2452
2453static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2454 const u32 *rx_indir_table
2455 __attribute__ ((unused)))
2456{
2457 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2458
2459 if (user)
2460 return -EOPNOTSUPP;
2461 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2462 return 0;
2463 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002464}
2465
2466static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2467{
2468 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2469 (rx_queue->ptr_mask + 1) *
2470 sizeof(efx_qword_t),
2471 GFP_KERNEL);
2472}
2473
2474static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2475{
2476 MCDI_DECLARE_BUF(inbuf,
2477 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2478 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002479 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2480 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2481 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002482 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002483 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002484 dma_addr_t dma_addr;
2485 int rc;
2486 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002487 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002488
2489 rx_queue->scatter_n = 0;
2490 rx_queue->scatter_len = 0;
2491
2492 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2493 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2494 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2495 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2496 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002497 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2498 INIT_RXQ_IN_FLAG_PREFIX, 1,
2499 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002500 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002501 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002502
2503 dma_addr = rx_queue->rxd.buf.dma_addr;
2504
2505 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2506 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2507
2508 for (i = 0; i < entries; ++i) {
2509 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2510 dma_addr += EFX_BUF_SIZE;
2511 }
2512
2513 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2514
2515 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002516 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002517 if (rc)
2518 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2519 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002520}
2521
2522static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2523{
2524 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002525 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002526 struct efx_nic *efx = rx_queue->efx;
2527 size_t outlen;
2528 int rc;
2529
2530 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2531 efx_rx_queue_index(rx_queue));
2532
Edward Cree1e0b8122013-05-31 18:36:12 +01002533 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002534 outbuf, sizeof(outbuf), &outlen);
2535
2536 if (rc && rc != -EALREADY)
2537 goto fail;
2538
2539 return;
2540
2541fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002542 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2543 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002544}
2545
2546static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2547{
2548 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2549}
2550
2551/* This creates an entry in the RX descriptor queue */
2552static inline void
2553efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2554{
2555 struct efx_rx_buffer *rx_buf;
2556 efx_qword_t *rxd;
2557
2558 rxd = efx_rx_desc(rx_queue, index);
2559 rx_buf = efx_rx_buffer(rx_queue, index);
2560 EFX_POPULATE_QWORD_2(*rxd,
2561 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2562 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2563}
2564
2565static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2566{
2567 struct efx_nic *efx = rx_queue->efx;
2568 unsigned int write_count;
2569 efx_dword_t reg;
2570
2571 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2572 write_count = rx_queue->added_count & ~7;
2573 if (rx_queue->notified_count == write_count)
2574 return;
2575
2576 do
2577 efx_ef10_build_rx_desc(
2578 rx_queue,
2579 rx_queue->notified_count & rx_queue->ptr_mask);
2580 while (++rx_queue->notified_count != write_count);
2581
2582 wmb();
2583 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2584 write_count & rx_queue->ptr_mask);
2585 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2586 efx_rx_queue_index(rx_queue));
2587}
2588
2589static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2590
2591static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2592{
2593 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2594 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2595 efx_qword_t event;
2596
2597 EFX_POPULATE_QWORD_2(event,
2598 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2599 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2600
2601 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2602
2603 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2604 * already swapped the data to little-endian order.
2605 */
2606 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2607 sizeof(efx_qword_t));
2608
2609 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2610 inbuf, sizeof(inbuf), 0,
2611 efx_ef10_rx_defer_refill_complete, 0);
2612}
2613
2614static void
2615efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2616 int rc, efx_dword_t *outbuf,
2617 size_t outlen_actual)
2618{
2619 /* nothing to do */
2620}
2621
2622static int efx_ef10_ev_probe(struct efx_channel *channel)
2623{
2624 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2625 (channel->eventq_mask + 1) *
2626 sizeof(efx_qword_t),
2627 GFP_KERNEL);
2628}
2629
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002630static void efx_ef10_ev_fini(struct efx_channel *channel)
2631{
2632 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2633 MCDI_DECLARE_BUF_ERR(outbuf);
2634 struct efx_nic *efx = channel->efx;
2635 size_t outlen;
2636 int rc;
2637
2638 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2639
2640 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2641 outbuf, sizeof(outbuf), &outlen);
2642
2643 if (rc && rc != -EALREADY)
2644 goto fail;
2645
2646 return;
2647
2648fail:
2649 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2650 outbuf, outlen, rc);
2651}
2652
Ben Hutchings8127d662013-08-29 19:19:29 +01002653static int efx_ef10_ev_init(struct efx_channel *channel)
2654{
2655 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002656 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2657 EFX_BUF_SIZE));
2658 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002659 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2660 struct efx_nic *efx = channel->efx;
2661 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002662 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002663 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002664 dma_addr_t dma_addr;
2665 int rc;
2666 int i;
2667
2668 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002669
2670 /* Fill event queue with all ones (i.e. empty events) */
2671 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2672
2673 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2674 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2675 /* INIT_EVQ expects index in vector table, not absolute */
2676 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002677 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2678 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2679 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2680 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2681 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2682 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2683 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2684
Bert Kenwarda9955602016-08-11 13:01:54 +01002685 if (nic_data->datapath_caps2 &
2686 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2687 /* Use the new generic approach to specifying event queue
2688 * configuration, requesting lower latency or higher throughput.
2689 * The options that actually get used appear in the output.
2690 */
2691 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2692 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2693 INIT_EVQ_V2_IN_FLAG_TYPE,
2694 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2695 } else {
2696 bool cut_thru = !(nic_data->datapath_caps &
2697 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2698
2699 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2700 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2701 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2702 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2703 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2704 }
2705
Ben Hutchings8127d662013-08-29 19:19:29 +01002706 dma_addr = channel->eventq.buf.dma_addr;
2707 for (i = 0; i < entries; ++i) {
2708 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2709 dma_addr += EFX_BUF_SIZE;
2710 }
2711
2712 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2713
2714 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2715 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01002716
2717 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2718 netif_dbg(efx, drv, efx->net_dev,
2719 "Channel %d using event queue flags %08x\n",
2720 channel->channel,
2721 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2722
Ben Hutchings8127d662013-08-29 19:19:29 +01002723 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002724 if (channel->channel || rc)
2725 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002726
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002727 /* Successfully created event queue on channel 0 */
2728 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002729 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01002730 /* GET_WORKAROUNDS was implemented before this workaround,
2731 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01002732 */
2733 nic_data->workaround_26807 = false;
2734 rc = 0;
2735 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002736 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002737 } else {
2738 nic_data->workaround_26807 =
2739 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002740
Edward Cree832dc9e2015-07-21 15:09:31 +01002741 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2742 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002743 unsigned int flags;
2744
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002745 rc = efx_mcdi_set_workaround(efx,
2746 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002747 true, &flags);
2748
2749 if (!rc) {
2750 if (flags &
2751 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2752 netif_info(efx, drv, efx->net_dev,
2753 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002754
2755 /* With MCFW v4.6.x and earlier, the
2756 * boot count will have incremented,
2757 * so re-read the warm_boot_count
2758 * value now to ensure this function
2759 * doesn't think it has changed next
2760 * time it checks.
2761 */
2762 rc = efx_ef10_get_warm_boot_count(efx);
2763 if (rc >= 0) {
2764 nic_data->warm_boot_count = rc;
2765 rc = 0;
2766 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002767 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002768 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002769 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002770 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002771 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002772 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002773 }
2774
2775 if (!rc)
2776 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002777
2778fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002779 efx_ef10_ev_fini(channel);
2780 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002781}
2782
2783static void efx_ef10_ev_remove(struct efx_channel *channel)
2784{
2785 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2786}
2787
2788static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2789 unsigned int rx_queue_label)
2790{
2791 struct efx_nic *efx = rx_queue->efx;
2792
2793 netif_info(efx, hw, efx->net_dev,
2794 "rx event arrived on queue %d labeled as queue %u\n",
2795 efx_rx_queue_index(rx_queue), rx_queue_label);
2796
2797 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2798}
2799
2800static void
2801efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2802 unsigned int actual, unsigned int expected)
2803{
2804 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2805 struct efx_nic *efx = rx_queue->efx;
2806
2807 netif_info(efx, hw, efx->net_dev,
2808 "dropped %d events (index=%d expected=%d)\n",
2809 dropped, actual, expected);
2810
2811 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2812}
2813
2814/* partially received RX was aborted. clean up. */
2815static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2816{
2817 unsigned int rx_desc_ptr;
2818
Ben Hutchings8127d662013-08-29 19:19:29 +01002819 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2820 "scattered RX aborted (dropping %u buffers)\n",
2821 rx_queue->scatter_n);
2822
2823 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2824
2825 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2826 0, EFX_RX_PKT_DISCARD);
2827
2828 rx_queue->removed_count += rx_queue->scatter_n;
2829 rx_queue->scatter_n = 0;
2830 rx_queue->scatter_len = 0;
2831 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2832}
2833
2834static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2835 const efx_qword_t *event)
2836{
2837 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2838 unsigned int n_descs, n_packets, i;
2839 struct efx_nic *efx = channel->efx;
2840 struct efx_rx_queue *rx_queue;
2841 bool rx_cont;
2842 u16 flags = 0;
2843
2844 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2845 return 0;
2846
2847 /* Basic packet information */
2848 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2849 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2850 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2851 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2852 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2853
Ben Hutchings48ce5632013-11-01 16:42:44 +00002854 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2855 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2856 EFX_QWORD_FMT "\n",
2857 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002858
2859 rx_queue = efx_channel_get_rx_queue(channel);
2860
2861 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2862 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2863
2864 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2865 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2866
2867 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002868 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2869
Ben Hutchings8127d662013-08-29 19:19:29 +01002870 /* detect rx abort */
2871 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002872 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2873 netdev_WARN(efx->net_dev,
2874 "invalid RX abort: scatter_n=%u event="
2875 EFX_QWORD_FMT "\n",
2876 rx_queue->scatter_n,
2877 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002878 efx_ef10_handle_rx_abort(rx_queue);
2879 return 0;
2880 }
2881
Ben Hutchings92a04162013-09-24 23:21:57 +01002882 /* Check that RX completion merging is valid, i.e.
2883 * the current firmware supports it and this is a
2884 * non-scattered packet.
2885 */
2886 if (!(nic_data->datapath_caps &
2887 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2888 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002889 efx_ef10_handle_rx_bad_lbits(
2890 rx_queue, next_ptr_lbits,
2891 (rx_queue->removed_count +
2892 rx_queue->scatter_n + 1) &
2893 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2894 return 0;
2895 }
2896
2897 /* Merged completion for multiple non-scattered packets */
2898 rx_queue->scatter_n = 1;
2899 rx_queue->scatter_len = 0;
2900 n_packets = n_descs;
2901 ++channel->n_rx_merge_events;
2902 channel->n_rx_merge_packets += n_packets;
2903 flags |= EFX_RX_PKT_PREFIX_LEN;
2904 } else {
2905 ++rx_queue->scatter_n;
2906 rx_queue->scatter_len += rx_bytes;
2907 if (rx_cont)
2908 return 0;
2909 n_packets = 1;
2910 }
2911
2912 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2913 flags |= EFX_RX_PKT_DISCARD;
2914
2915 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2916 channel->n_rx_ip_hdr_chksum_err += n_packets;
2917 } else if (unlikely(EFX_QWORD_FIELD(*event,
2918 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2919 channel->n_rx_tcp_udp_chksum_err += n_packets;
2920 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2921 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2922 flags |= EFX_RX_PKT_CSUMMED;
2923 }
2924
2925 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2926 flags |= EFX_RX_PKT_TCP;
2927
2928 channel->irq_mod_score += 2 * n_packets;
2929
2930 /* Handle received packet(s) */
2931 for (i = 0; i < n_packets; i++) {
2932 efx_rx_packet(rx_queue,
2933 rx_queue->removed_count & rx_queue->ptr_mask,
2934 rx_queue->scatter_n, rx_queue->scatter_len,
2935 flags);
2936 rx_queue->removed_count += rx_queue->scatter_n;
2937 }
2938
2939 rx_queue->scatter_n = 0;
2940 rx_queue->scatter_len = 0;
2941
2942 return n_packets;
2943}
2944
2945static int
2946efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2947{
2948 struct efx_nic *efx = channel->efx;
2949 struct efx_tx_queue *tx_queue;
2950 unsigned int tx_ev_desc_ptr;
2951 unsigned int tx_ev_q_label;
2952 int tx_descs = 0;
2953
2954 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2955 return 0;
2956
2957 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2958 return 0;
2959
2960 /* Transmit completion */
2961 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2962 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2963 tx_queue = efx_channel_get_tx_queue(channel,
2964 tx_ev_q_label % EFX_TXQ_TYPES);
2965 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2966 tx_queue->ptr_mask);
2967 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2968
2969 return tx_descs;
2970}
2971
2972static void
2973efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2974{
2975 struct efx_nic *efx = channel->efx;
2976 int subcode;
2977
2978 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2979
2980 switch (subcode) {
2981 case ESE_DZ_DRV_TIMER_EV:
2982 case ESE_DZ_DRV_WAKE_UP_EV:
2983 break;
2984 case ESE_DZ_DRV_START_UP_EV:
2985 /* event queue init complete. ok. */
2986 break;
2987 default:
2988 netif_err(efx, hw, efx->net_dev,
2989 "channel %d unknown driver event type %d"
2990 " (data " EFX_QWORD_FMT ")\n",
2991 channel->channel, subcode,
2992 EFX_QWORD_VAL(*event));
2993
2994 }
2995}
2996
2997static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2998 efx_qword_t *event)
2999{
3000 struct efx_nic *efx = channel->efx;
3001 u32 subcode;
3002
3003 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3004
3005 switch (subcode) {
3006 case EFX_EF10_TEST:
3007 channel->event_test_cpu = raw_smp_processor_id();
3008 break;
3009 case EFX_EF10_REFILL:
3010 /* The queue must be empty, so we won't receive any rx
3011 * events, so efx_process_channel() won't refill the
3012 * queue. Refill it here
3013 */
Jon Coopercce28792013-10-02 11:04:14 +01003014 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003015 break;
3016 default:
3017 netif_err(efx, hw, efx->net_dev,
3018 "channel %d unknown driver event type %u"
3019 " (data " EFX_QWORD_FMT ")\n",
3020 channel->channel, (unsigned) subcode,
3021 EFX_QWORD_VAL(*event));
3022 }
3023}
3024
3025static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3026{
3027 struct efx_nic *efx = channel->efx;
3028 efx_qword_t event, *p_event;
3029 unsigned int read_ptr;
3030 int ev_code;
3031 int tx_descs = 0;
3032 int spent = 0;
3033
Eric W. Biederman75363a42014-03-14 18:11:22 -07003034 if (quota <= 0)
3035 return spent;
3036
Ben Hutchings8127d662013-08-29 19:19:29 +01003037 read_ptr = channel->eventq_read_ptr;
3038
3039 for (;;) {
3040 p_event = efx_event(channel, read_ptr);
3041 event = *p_event;
3042
3043 if (!efx_event_present(&event))
3044 break;
3045
3046 EFX_SET_QWORD(*p_event);
3047
3048 ++read_ptr;
3049
3050 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3051
3052 netif_vdbg(efx, drv, efx->net_dev,
3053 "processing event on %d " EFX_QWORD_FMT "\n",
3054 channel->channel, EFX_QWORD_VAL(event));
3055
3056 switch (ev_code) {
3057 case ESE_DZ_EV_CODE_MCDI_EV:
3058 efx_mcdi_process_event(channel, &event);
3059 break;
3060 case ESE_DZ_EV_CODE_RX_EV:
3061 spent += efx_ef10_handle_rx_event(channel, &event);
3062 if (spent >= quota) {
3063 /* XXX can we split a merged event to
3064 * avoid going over-quota?
3065 */
3066 spent = quota;
3067 goto out;
3068 }
3069 break;
3070 case ESE_DZ_EV_CODE_TX_EV:
3071 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3072 if (tx_descs > efx->txq_entries) {
3073 spent = quota;
3074 goto out;
3075 } else if (++spent == quota) {
3076 goto out;
3077 }
3078 break;
3079 case ESE_DZ_EV_CODE_DRIVER_EV:
3080 efx_ef10_handle_driver_event(channel, &event);
3081 if (++spent == quota)
3082 goto out;
3083 break;
3084 case EFX_EF10_DRVGEN_EV:
3085 efx_ef10_handle_driver_generated_event(channel, &event);
3086 break;
3087 default:
3088 netif_err(efx, hw, efx->net_dev,
3089 "channel %d unknown event type %d"
3090 " (data " EFX_QWORD_FMT ")\n",
3091 channel->channel, ev_code,
3092 EFX_QWORD_VAL(event));
3093 }
3094 }
3095
3096out:
3097 channel->eventq_read_ptr = read_ptr;
3098 return spent;
3099}
3100
3101static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3102{
3103 struct efx_nic *efx = channel->efx;
3104 efx_dword_t rptr;
3105
3106 if (EFX_EF10_WORKAROUND_35388(efx)) {
3107 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3108 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3109 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3110 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3111
3112 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3113 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3114 ERF_DD_EVQ_IND_RPTR,
3115 (channel->eventq_read_ptr &
3116 channel->eventq_mask) >>
3117 ERF_DD_EVQ_IND_RPTR_WIDTH);
3118 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3119 channel->channel);
3120 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3121 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3122 ERF_DD_EVQ_IND_RPTR,
3123 channel->eventq_read_ptr &
3124 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3125 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3126 channel->channel);
3127 } else {
3128 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3129 channel->eventq_read_ptr &
3130 channel->eventq_mask);
3131 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3132 }
3133}
3134
3135static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3136{
3137 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3138 struct efx_nic *efx = channel->efx;
3139 efx_qword_t event;
3140 int rc;
3141
3142 EFX_POPULATE_QWORD_2(event,
3143 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3144 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3145
3146 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3147
3148 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3149 * already swapped the data to little-endian order.
3150 */
3151 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3152 sizeof(efx_qword_t));
3153
3154 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3155 NULL, 0, NULL);
3156 if (rc != 0)
3157 goto fail;
3158
3159 return;
3160
3161fail:
3162 WARN_ON(true);
3163 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3164}
3165
3166void efx_ef10_handle_drain_event(struct efx_nic *efx)
3167{
3168 if (atomic_dec_and_test(&efx->active_queues))
3169 wake_up(&efx->flush_wq);
3170
3171 WARN_ON(atomic_read(&efx->active_queues) < 0);
3172}
3173
3174static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3175{
3176 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3177 struct efx_channel *channel;
3178 struct efx_tx_queue *tx_queue;
3179 struct efx_rx_queue *rx_queue;
3180 int pending;
3181
3182 /* If the MC has just rebooted, the TX/RX queues will have already been
3183 * torn down, but efx->active_queues needs to be set to zero.
3184 */
3185 if (nic_data->must_realloc_vis) {
3186 atomic_set(&efx->active_queues, 0);
3187 return 0;
3188 }
3189
3190 /* Do not attempt to write to the NIC during EEH recovery */
3191 if (efx->state != STATE_RECOVERY) {
3192 efx_for_each_channel(channel, efx) {
3193 efx_for_each_channel_rx_queue(rx_queue, channel)
3194 efx_ef10_rx_fini(rx_queue);
3195 efx_for_each_channel_tx_queue(tx_queue, channel)
3196 efx_ef10_tx_fini(tx_queue);
3197 }
3198
3199 wait_event_timeout(efx->flush_wq,
3200 atomic_read(&efx->active_queues) == 0,
3201 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3202 pending = atomic_read(&efx->active_queues);
3203 if (pending) {
3204 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3205 pending);
3206 return -ETIMEDOUT;
3207 }
3208 }
3209
3210 return 0;
3211}
3212
Edward Creee2835462014-04-16 19:27:48 +01003213static void efx_ef10_prepare_flr(struct efx_nic *efx)
3214{
3215 atomic_set(&efx->active_queues, 0);
3216}
3217
Ben Hutchings8127d662013-08-29 19:19:29 +01003218static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3219 const struct efx_filter_spec *right)
3220{
3221 if ((left->match_flags ^ right->match_flags) |
3222 ((left->flags ^ right->flags) &
3223 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3224 return false;
3225
3226 return memcmp(&left->outer_vid, &right->outer_vid,
3227 sizeof(struct efx_filter_spec) -
3228 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3229}
3230
3231static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3232{
3233 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3234 return jhash2((const u32 *)&spec->outer_vid,
3235 (sizeof(struct efx_filter_spec) -
3236 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3237 0);
3238 /* XXX should we randomise the initval? */
3239}
3240
3241/* Decide whether a filter should be exclusive or else should allow
3242 * delivery to additional recipients. Currently we decide that
3243 * filters for specific local unicast MAC and IP addresses are
3244 * exclusive.
3245 */
3246static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3247{
3248 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3249 !is_multicast_ether_addr(spec->loc_mac))
3250 return true;
3251
3252 if ((spec->match_flags &
3253 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3254 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3255 if (spec->ether_type == htons(ETH_P_IP) &&
3256 !ipv4_is_multicast(spec->loc_host[0]))
3257 return true;
3258 if (spec->ether_type == htons(ETH_P_IPV6) &&
3259 ((const u8 *)spec->loc_host)[0] != 0xff)
3260 return true;
3261 }
3262
3263 return false;
3264}
3265
3266static struct efx_filter_spec *
3267efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3268 unsigned int filter_idx)
3269{
3270 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3271 ~EFX_EF10_FILTER_FLAGS);
3272}
3273
3274static unsigned int
3275efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3276 unsigned int filter_idx)
3277{
3278 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3279}
3280
3281static void
3282efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3283 unsigned int filter_idx,
3284 const struct efx_filter_spec *spec,
3285 unsigned int flags)
3286{
3287 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3288}
3289
3290static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3291 const struct efx_filter_spec *spec,
3292 efx_dword_t *inbuf, u64 handle,
3293 bool replacing)
3294{
3295 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003296 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003297
3298 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3299
Jon Cooperdcb41232016-04-25 16:51:00 +01003300 /* Remove RSS flag if we don't have an RSS context. */
3301 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3302 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3303 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3304 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3305
Ben Hutchings8127d662013-08-29 19:19:29 +01003306 if (replacing) {
3307 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3308 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3309 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3310 } else {
3311 u32 match_fields = 0;
3312
3313 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3314 efx_ef10_filter_is_exclusive(spec) ?
3315 MC_CMD_FILTER_OP_IN_OP_INSERT :
3316 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3317
3318 /* Convert match flags and values. Unlike almost
3319 * everything else in MCDI, these fields are in
3320 * network byte order.
3321 */
3322 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3323 match_fields |=
3324 is_multicast_ether_addr(spec->loc_mac) ?
3325 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3326 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3327#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3328 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3329 match_fields |= \
3330 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3331 mcdi_field ## _LBN; \
3332 BUILD_BUG_ON( \
3333 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3334 sizeof(spec->gen_field)); \
3335 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3336 &spec->gen_field, sizeof(spec->gen_field)); \
3337 }
3338 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3339 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3340 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3341 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3342 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3343 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3344 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3345 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3346 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3347 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3348#undef COPY_FIELD
3349 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3350 match_fields);
3351 }
3352
Daniel Pieczko45b24492015-05-06 00:57:14 +01003353 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003354 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3355 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3356 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3357 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003358 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003359 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3360 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003361 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3362 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3363 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003364 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003365 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003366 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3367 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003368 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003369 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3370 spec->rss_context !=
3371 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3372 spec->rss_context : nic_data->rx_rss_context);
3373}
3374
3375static int efx_ef10_filter_push(struct efx_nic *efx,
3376 const struct efx_filter_spec *spec,
3377 u64 *handle, bool replacing)
3378{
3379 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3380 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3381 int rc;
3382
3383 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3384 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3385 outbuf, sizeof(outbuf), NULL);
3386 if (rc == 0)
3387 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003388 if (rc == -ENOSPC)
3389 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003390 return rc;
3391}
3392
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003393static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003394{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003395 unsigned int match_flags = spec->match_flags;
3396 u32 mcdi_flags = 0;
3397
3398 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3399 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3400 mcdi_flags |=
3401 is_multicast_ether_addr(spec->loc_mac) ?
3402 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3403 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3404 }
3405
3406#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3407 unsigned int old_match_flags = match_flags; \
3408 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3409 if (match_flags != old_match_flags) \
3410 mcdi_flags |= \
3411 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3412 mcdi_field ## _LBN); \
3413 }
3414 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3415 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3416 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3417 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3418 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3419 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3420 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3421 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3422 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3423 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3424#undef MAP_FILTER_TO_MCDI_FLAG
3425
3426 /* Did we map them all? */
3427 WARN_ON_ONCE(match_flags);
3428
3429 return mcdi_flags;
3430}
3431
3432static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3433 const struct efx_filter_spec *spec)
3434{
3435 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003436 unsigned int match_pri;
3437
3438 for (match_pri = 0;
3439 match_pri < table->rx_match_count;
3440 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003441 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003442 return match_pri;
3443
3444 return -EPROTONOSUPPORT;
3445}
3446
3447static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3448 struct efx_filter_spec *spec,
3449 bool replace_equal)
3450{
3451 struct efx_ef10_filter_table *table = efx->filter_state;
3452 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3453 struct efx_filter_spec *saved_spec;
3454 unsigned int match_pri, hash;
3455 unsigned int priv_flags;
3456 bool replacing = false;
3457 int ins_index = -1;
3458 DEFINE_WAIT(wait);
3459 bool is_mc_recip;
3460 s32 rc;
3461
3462 /* For now, only support RX filters */
3463 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3464 EFX_FILTER_FLAG_RX)
3465 return -EINVAL;
3466
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003467 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003468 if (rc < 0)
3469 return rc;
3470 match_pri = rc;
3471
3472 hash = efx_ef10_filter_hash(spec);
3473 is_mc_recip = efx_filter_is_mc_recipient(spec);
3474 if (is_mc_recip)
3475 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3476
3477 /* Find any existing filters with the same match tuple or
3478 * else a free slot to insert at. If any of them are busy,
3479 * we have to wait and retry.
3480 */
3481 for (;;) {
3482 unsigned int depth = 1;
3483 unsigned int i;
3484
3485 spin_lock_bh(&efx->filter_lock);
3486
3487 for (;;) {
3488 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3489 saved_spec = efx_ef10_filter_entry_spec(table, i);
3490
3491 if (!saved_spec) {
3492 if (ins_index < 0)
3493 ins_index = i;
3494 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3495 if (table->entry[i].spec &
3496 EFX_EF10_FILTER_FLAG_BUSY)
3497 break;
3498 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003499 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003500 rc = -EPERM;
3501 goto out_unlock;
3502 }
3503 if (!is_mc_recip) {
3504 /* This is the only one */
3505 if (spec->priority ==
3506 saved_spec->priority &&
3507 !replace_equal) {
3508 rc = -EEXIST;
3509 goto out_unlock;
3510 }
3511 ins_index = i;
3512 goto found;
3513 } else if (spec->priority >
3514 saved_spec->priority ||
3515 (spec->priority ==
3516 saved_spec->priority &&
3517 replace_equal)) {
3518 if (ins_index < 0)
3519 ins_index = i;
3520 else
3521 __set_bit(depth, mc_rem_map);
3522 }
3523 }
3524
3525 /* Once we reach the maximum search depth, use
3526 * the first suitable slot or return -EBUSY if
3527 * there was none
3528 */
3529 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3530 if (ins_index < 0) {
3531 rc = -EBUSY;
3532 goto out_unlock;
3533 }
3534 goto found;
3535 }
3536
3537 ++depth;
3538 }
3539
3540 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3541 spin_unlock_bh(&efx->filter_lock);
3542 schedule();
3543 }
3544
3545found:
3546 /* Create a software table entry if necessary, and mark it
3547 * busy. We might yet fail to insert, but any attempt to
3548 * insert a conflicting filter while we're waiting for the
3549 * firmware must find the busy entry.
3550 */
3551 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3552 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003553 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3554 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003555 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003556 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3557 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003558 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003559 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003560 rc = ins_index;
3561 goto out_unlock;
3562 }
3563 replacing = true;
3564 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3565 } else {
3566 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3567 if (!saved_spec) {
3568 rc = -ENOMEM;
3569 goto out_unlock;
3570 }
3571 *saved_spec = *spec;
3572 priv_flags = 0;
3573 }
3574 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3575 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3576
3577 /* Mark lower-priority multicast recipients busy prior to removal */
3578 if (is_mc_recip) {
3579 unsigned int depth, i;
3580
3581 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3582 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3583 if (test_bit(depth, mc_rem_map))
3584 table->entry[i].spec |=
3585 EFX_EF10_FILTER_FLAG_BUSY;
3586 }
3587 }
3588
3589 spin_unlock_bh(&efx->filter_lock);
3590
3591 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3592 replacing);
3593
3594 /* Finalise the software table entry */
3595 spin_lock_bh(&efx->filter_lock);
3596 if (rc == 0) {
3597 if (replacing) {
3598 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003599 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3600 saved_spec->flags |=
3601 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003602 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003603 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003604 saved_spec->flags |= spec->flags;
3605 saved_spec->rss_context = spec->rss_context;
3606 saved_spec->dmaq_id = spec->dmaq_id;
3607 }
3608 } else if (!replacing) {
3609 kfree(saved_spec);
3610 saved_spec = NULL;
3611 }
3612 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3613
3614 /* Remove and finalise entries for lower-priority multicast
3615 * recipients
3616 */
3617 if (is_mc_recip) {
3618 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3619 unsigned int depth, i;
3620
3621 memset(inbuf, 0, sizeof(inbuf));
3622
3623 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3624 if (!test_bit(depth, mc_rem_map))
3625 continue;
3626
3627 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3628 saved_spec = efx_ef10_filter_entry_spec(table, i);
3629 priv_flags = efx_ef10_filter_entry_flags(table, i);
3630
3631 if (rc == 0) {
3632 spin_unlock_bh(&efx->filter_lock);
3633 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3634 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3635 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3636 table->entry[i].handle);
3637 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3638 inbuf, sizeof(inbuf),
3639 NULL, 0, NULL);
3640 spin_lock_bh(&efx->filter_lock);
3641 }
3642
3643 if (rc == 0) {
3644 kfree(saved_spec);
3645 saved_spec = NULL;
3646 priv_flags = 0;
3647 } else {
3648 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3649 }
3650 efx_ef10_filter_set_entry(table, i, saved_spec,
3651 priv_flags);
3652 }
3653 }
3654
3655 /* If successful, return the inserted filter ID */
3656 if (rc == 0)
3657 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3658
3659 wake_up_all(&table->waitq);
3660out_unlock:
3661 spin_unlock_bh(&efx->filter_lock);
3662 finish_wait(&table->waitq, &wait);
3663 return rc;
3664}
3665
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003666static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003667{
3668 /* no need to do anything here on EF10 */
3669}
3670
3671/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003672 * If !by_index, remove by ID
3673 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003674 * Filter ID may come from userland and must be range-checked.
3675 */
3676static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003677 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003678 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003679{
3680 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3681 struct efx_ef10_filter_table *table = efx->filter_state;
3682 MCDI_DECLARE_BUF(inbuf,
3683 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3684 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3685 struct efx_filter_spec *spec;
3686 DEFINE_WAIT(wait);
3687 int rc;
3688
3689 /* Find the software table entry and mark it busy. Don't
3690 * remove it yet; any attempt to update while we're waiting
3691 * for the firmware must find the busy entry.
3692 */
3693 for (;;) {
3694 spin_lock_bh(&efx->filter_lock);
3695 if (!(table->entry[filter_idx].spec &
3696 EFX_EF10_FILTER_FLAG_BUSY))
3697 break;
3698 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3699 spin_unlock_bh(&efx->filter_lock);
3700 schedule();
3701 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003702
Ben Hutchings8127d662013-08-29 19:19:29 +01003703 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003704 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003705 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003706 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003707 filter_id / HUNT_FILTER_TBL_ROWS)) {
3708 rc = -ENOENT;
3709 goto out_unlock;
3710 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003711
3712 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003713 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003714 /* Just remove flags */
3715 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003716 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003717 rc = 0;
3718 goto out_unlock;
3719 }
3720
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003721 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003722 rc = -ENOENT;
3723 goto out_unlock;
3724 }
3725
Ben Hutchings8127d662013-08-29 19:19:29 +01003726 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3727 spin_unlock_bh(&efx->filter_lock);
3728
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003729 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003730 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003731
3732 struct efx_filter_spec new_spec = *spec;
3733
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003734 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003735 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003736 (efx_rss_enabled(efx) ?
3737 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003738 new_spec.dmaq_id = 0;
3739 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3740 rc = efx_ef10_filter_push(efx, &new_spec,
3741 &table->entry[filter_idx].handle,
3742 true);
3743
3744 spin_lock_bh(&efx->filter_lock);
3745 if (rc == 0)
3746 *spec = new_spec;
3747 } else {
3748 /* Really remove the filter */
3749
3750 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3751 efx_ef10_filter_is_exclusive(spec) ?
3752 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3753 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3754 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3755 table->entry[filter_idx].handle);
3756 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3757 inbuf, sizeof(inbuf), NULL, 0, NULL);
3758
3759 spin_lock_bh(&efx->filter_lock);
3760 if (rc == 0) {
3761 kfree(spec);
3762 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3763 }
3764 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003765
Ben Hutchings8127d662013-08-29 19:19:29 +01003766 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3767 wake_up_all(&table->waitq);
3768out_unlock:
3769 spin_unlock_bh(&efx->filter_lock);
3770 finish_wait(&table->waitq, &wait);
3771 return rc;
3772}
3773
3774static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3775 enum efx_filter_priority priority,
3776 u32 filter_id)
3777{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003778 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3779 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003780}
3781
Edward Cree12fb0da2015-07-21 15:11:00 +01003782static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
3783{
3784 return filter_id % HUNT_FILTER_TBL_ROWS;
3785}
3786
Edward Cree8c915622016-06-15 17:49:05 +01003787static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
3788 enum efx_filter_priority priority,
3789 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01003790{
Edward Cree8c915622016-06-15 17:49:05 +01003791 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
3792 return;
3793 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01003794}
3795
Ben Hutchings8127d662013-08-29 19:19:29 +01003796static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3797 enum efx_filter_priority priority,
3798 u32 filter_id, struct efx_filter_spec *spec)
3799{
3800 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3801 struct efx_ef10_filter_table *table = efx->filter_state;
3802 const struct efx_filter_spec *saved_spec;
3803 int rc;
3804
3805 spin_lock_bh(&efx->filter_lock);
3806 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3807 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003808 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01003809 filter_id / HUNT_FILTER_TBL_ROWS) {
3810 *spec = *saved_spec;
3811 rc = 0;
3812 } else {
3813 rc = -ENOENT;
3814 }
3815 spin_unlock_bh(&efx->filter_lock);
3816 return rc;
3817}
3818
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003819static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003820 enum efx_filter_priority priority)
3821{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003822 unsigned int priority_mask;
3823 unsigned int i;
3824 int rc;
3825
3826 priority_mask = (((1U << (priority + 1)) - 1) &
3827 ~(1U << EFX_FILTER_PRI_AUTO));
3828
3829 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3830 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3831 i, true);
3832 if (rc && rc != -ENOENT)
3833 return rc;
3834 }
3835
3836 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003837}
3838
3839static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3840 enum efx_filter_priority priority)
3841{
3842 struct efx_ef10_filter_table *table = efx->filter_state;
3843 unsigned int filter_idx;
3844 s32 count = 0;
3845
3846 spin_lock_bh(&efx->filter_lock);
3847 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3848 if (table->entry[filter_idx].spec &&
3849 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3850 priority)
3851 ++count;
3852 }
3853 spin_unlock_bh(&efx->filter_lock);
3854 return count;
3855}
3856
3857static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3858{
3859 struct efx_ef10_filter_table *table = efx->filter_state;
3860
3861 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3862}
3863
3864static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3865 enum efx_filter_priority priority,
3866 u32 *buf, u32 size)
3867{
3868 struct efx_ef10_filter_table *table = efx->filter_state;
3869 struct efx_filter_spec *spec;
3870 unsigned int filter_idx;
3871 s32 count = 0;
3872
3873 spin_lock_bh(&efx->filter_lock);
3874 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3875 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3876 if (spec && spec->priority == priority) {
3877 if (count == size) {
3878 count = -EMSGSIZE;
3879 break;
3880 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003881 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01003882 HUNT_FILTER_TBL_ROWS +
3883 filter_idx);
3884 }
3885 }
3886 spin_unlock_bh(&efx->filter_lock);
3887 return count;
3888}
3889
3890#ifdef CONFIG_RFS_ACCEL
3891
3892static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3893
3894static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3895 struct efx_filter_spec *spec)
3896{
3897 struct efx_ef10_filter_table *table = efx->filter_state;
3898 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3899 struct efx_filter_spec *saved_spec;
3900 unsigned int hash, i, depth = 1;
3901 bool replacing = false;
3902 int ins_index = -1;
3903 u64 cookie;
3904 s32 rc;
3905
3906 /* Must be an RX filter without RSS and not for a multicast
3907 * destination address (RFS only works for connected sockets).
3908 * These restrictions allow us to pass only a tiny amount of
3909 * data through to the completion function.
3910 */
3911 EFX_WARN_ON_PARANOID(spec->flags !=
3912 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3913 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3914 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3915
3916 hash = efx_ef10_filter_hash(spec);
3917
3918 spin_lock_bh(&efx->filter_lock);
3919
3920 /* Find any existing filter with the same match tuple or else
3921 * a free slot to insert at. If an existing filter is busy,
3922 * we have to give up.
3923 */
3924 for (;;) {
3925 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3926 saved_spec = efx_ef10_filter_entry_spec(table, i);
3927
3928 if (!saved_spec) {
3929 if (ins_index < 0)
3930 ins_index = i;
3931 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3932 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3933 rc = -EBUSY;
3934 goto fail_unlock;
3935 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003936 if (spec->priority < saved_spec->priority) {
3937 rc = -EPERM;
3938 goto fail_unlock;
3939 }
3940 ins_index = i;
3941 break;
3942 }
3943
3944 /* Once we reach the maximum search depth, use the
3945 * first suitable slot or return -EBUSY if there was
3946 * none
3947 */
3948 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3949 if (ins_index < 0) {
3950 rc = -EBUSY;
3951 goto fail_unlock;
3952 }
3953 break;
3954 }
3955
3956 ++depth;
3957 }
3958
3959 /* Create a software table entry if necessary, and mark it
3960 * busy. We might yet fail to insert, but any attempt to
3961 * insert a conflicting filter while we're waiting for the
3962 * firmware must find the busy entry.
3963 */
3964 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3965 if (saved_spec) {
3966 replacing = true;
3967 } else {
3968 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3969 if (!saved_spec) {
3970 rc = -ENOMEM;
3971 goto fail_unlock;
3972 }
3973 *saved_spec = *spec;
3974 }
3975 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3976 EFX_EF10_FILTER_FLAG_BUSY);
3977
3978 spin_unlock_bh(&efx->filter_lock);
3979
3980 /* Pack up the variables needed on completion */
3981 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3982
3983 efx_ef10_filter_push_prep(efx, spec, inbuf,
3984 table->entry[ins_index].handle, replacing);
3985 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3986 MC_CMD_FILTER_OP_OUT_LEN,
3987 efx_ef10_filter_rfs_insert_complete, cookie);
3988
3989 return ins_index;
3990
3991fail_unlock:
3992 spin_unlock_bh(&efx->filter_lock);
3993 return rc;
3994}
3995
3996static void
3997efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3998 int rc, efx_dword_t *outbuf,
3999 size_t outlen_actual)
4000{
4001 struct efx_ef10_filter_table *table = efx->filter_state;
4002 unsigned int ins_index, dmaq_id;
4003 struct efx_filter_spec *spec;
4004 bool replacing;
4005
4006 /* Unpack the cookie */
4007 replacing = cookie >> 31;
4008 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4009 dmaq_id = cookie & 0xffff;
4010
4011 spin_lock_bh(&efx->filter_lock);
4012 spec = efx_ef10_filter_entry_spec(table, ins_index);
4013 if (rc == 0) {
4014 table->entry[ins_index].handle =
4015 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4016 if (replacing)
4017 spec->dmaq_id = dmaq_id;
4018 } else if (!replacing) {
4019 kfree(spec);
4020 spec = NULL;
4021 }
4022 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4023 spin_unlock_bh(&efx->filter_lock);
4024
4025 wake_up_all(&table->waitq);
4026}
4027
4028static void
4029efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4030 unsigned long filter_idx,
4031 int rc, efx_dword_t *outbuf,
4032 size_t outlen_actual);
4033
4034static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4035 unsigned int filter_idx)
4036{
4037 struct efx_ef10_filter_table *table = efx->filter_state;
4038 struct efx_filter_spec *spec =
4039 efx_ef10_filter_entry_spec(table, filter_idx);
4040 MCDI_DECLARE_BUF(inbuf,
4041 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4042 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4043
4044 if (!spec ||
4045 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4046 spec->priority != EFX_FILTER_PRI_HINT ||
4047 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4048 flow_id, filter_idx))
4049 return false;
4050
4051 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4052 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4053 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4054 table->entry[filter_idx].handle);
4055 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4056 efx_ef10_filter_rfs_expire_complete, filter_idx))
4057 return false;
4058
4059 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4060 return true;
4061}
4062
4063static void
4064efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4065 unsigned long filter_idx,
4066 int rc, efx_dword_t *outbuf,
4067 size_t outlen_actual)
4068{
4069 struct efx_ef10_filter_table *table = efx->filter_state;
4070 struct efx_filter_spec *spec =
4071 efx_ef10_filter_entry_spec(table, filter_idx);
4072
4073 spin_lock_bh(&efx->filter_lock);
4074 if (rc == 0) {
4075 kfree(spec);
4076 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4077 }
4078 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4079 wake_up_all(&table->waitq);
4080 spin_unlock_bh(&efx->filter_lock);
4081}
4082
4083#endif /* CONFIG_RFS_ACCEL */
4084
4085static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4086{
4087 int match_flags = 0;
4088
4089#define MAP_FLAG(gen_flag, mcdi_field) { \
4090 u32 old_mcdi_flags = mcdi_flags; \
4091 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4092 mcdi_field ## _LBN); \
4093 if (mcdi_flags != old_mcdi_flags) \
4094 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4095 }
4096 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4097 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4098 MAP_FLAG(REM_HOST, SRC_IP);
4099 MAP_FLAG(LOC_HOST, DST_IP);
4100 MAP_FLAG(REM_MAC, SRC_MAC);
4101 MAP_FLAG(REM_PORT, SRC_PORT);
4102 MAP_FLAG(LOC_MAC, DST_MAC);
4103 MAP_FLAG(LOC_PORT, DST_PORT);
4104 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4105 MAP_FLAG(INNER_VID, INNER_VLAN);
4106 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4107 MAP_FLAG(IP_PROTO, IP_PROTO);
4108#undef MAP_FLAG
4109
4110 /* Did we map them all? */
4111 if (mcdi_flags)
4112 return -EINVAL;
4113
4114 return match_flags;
4115}
4116
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004117static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4118{
4119 struct efx_ef10_filter_table *table = efx->filter_state;
4120 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4121
4122 /* See comment in efx_ef10_filter_table_remove() */
4123 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4124 return;
4125
4126 if (!table)
4127 return;
4128
4129 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4130 efx_ef10_filter_del_vlan_internal(efx, vlan);
4131}
4132
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004133static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4134 enum efx_filter_match_flags match_flags)
4135{
4136 unsigned int match_pri;
4137 int mf;
4138
4139 for (match_pri = 0;
4140 match_pri < table->rx_match_count;
4141 match_pri++) {
4142 mf = efx_ef10_filter_match_flags_from_mcdi(
4143 table->rx_match_mcdi_flags[match_pri]);
4144 if (mf == match_flags)
4145 return true;
4146 }
4147
4148 return false;
4149}
4150
Ben Hutchings8127d662013-08-29 19:19:29 +01004151static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4152{
4153 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4154 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004155 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004156 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004157 unsigned int pd_match_pri, pd_match_count;
4158 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004159 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004160 size_t outlen;
4161 int rc;
4162
Edward Creedd987082016-06-15 17:43:43 +01004163 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4164 return -EINVAL;
4165
4166 if (efx->filter_state) /* already probed */
4167 return 0;
4168
Ben Hutchings8127d662013-08-29 19:19:29 +01004169 table = kzalloc(sizeof(*table), GFP_KERNEL);
4170 if (!table)
4171 return -ENOMEM;
4172
4173 /* Find out which RX filter types are supported, and their priorities */
4174 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4175 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4176 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4177 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4178 &outlen);
4179 if (rc)
4180 goto fail;
4181 pd_match_count = MCDI_VAR_ARRAY_LEN(
4182 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4183 table->rx_match_count = 0;
4184
4185 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4186 u32 mcdi_flags =
4187 MCDI_ARRAY_DWORD(
4188 outbuf,
4189 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4190 pd_match_pri);
4191 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4192 if (rc < 0) {
4193 netif_dbg(efx, probe, efx->net_dev,
4194 "%s: fw flags %#x pri %u not supported in driver\n",
4195 __func__, mcdi_flags, pd_match_pri);
4196 } else {
4197 netif_dbg(efx, probe, efx->net_dev,
4198 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4199 __func__, mcdi_flags, pd_match_pri,
4200 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004201 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4202 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004203 }
4204 }
4205
Martin Habetse4478ad2016-06-15 17:51:07 +01004206 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4207 !(efx_ef10_filter_match_supported(table,
4208 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4209 efx_ef10_filter_match_supported(table,
4210 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4211 netif_info(efx, probe, net_dev,
4212 "VLAN filters are not supported in this firmware variant\n");
4213 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4214 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4215 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4216 }
4217
Ben Hutchings8127d662013-08-29 19:19:29 +01004218 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4219 if (!table->entry) {
4220 rc = -ENOMEM;
4221 goto fail;
4222 }
4223
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004224 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004225 table->vlan_filter =
4226 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004227 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004228
Ben Hutchings8127d662013-08-29 19:19:29 +01004229 efx->filter_state = table;
4230 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004231
4232 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4233 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4234 if (rc)
4235 goto fail_add_vlan;
4236 }
4237
Ben Hutchings8127d662013-08-29 19:19:29 +01004238 return 0;
4239
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004240fail_add_vlan:
4241 efx_ef10_filter_cleanup_vlans(efx);
4242 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004243fail:
4244 kfree(table);
4245 return rc;
4246}
4247
Edward Cree0d322412015-05-20 11:10:03 +01004248/* Caller must hold efx->filter_sem for read if race against
4249 * efx_ef10_filter_table_remove() is possible
4250 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004251static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4252{
4253 struct efx_ef10_filter_table *table = efx->filter_state;
4254 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4255 struct efx_filter_spec *spec;
4256 unsigned int filter_idx;
4257 bool failed = false;
4258 int rc;
4259
Edward Cree0d322412015-05-20 11:10:03 +01004260 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4261
Ben Hutchings8127d662013-08-29 19:19:29 +01004262 if (!nic_data->must_restore_filters)
4263 return;
4264
Edward Cree0d322412015-05-20 11:10:03 +01004265 if (!table)
4266 return;
4267
Ben Hutchings8127d662013-08-29 19:19:29 +01004268 spin_lock_bh(&efx->filter_lock);
4269
4270 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4271 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4272 if (!spec)
4273 continue;
4274
4275 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4276 spin_unlock_bh(&efx->filter_lock);
4277
4278 rc = efx_ef10_filter_push(efx, spec,
4279 &table->entry[filter_idx].handle,
4280 false);
4281 if (rc)
4282 failed = true;
4283
4284 spin_lock_bh(&efx->filter_lock);
4285 if (rc) {
4286 kfree(spec);
4287 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4288 } else {
4289 table->entry[filter_idx].spec &=
4290 ~EFX_EF10_FILTER_FLAG_BUSY;
4291 }
4292 }
4293
4294 spin_unlock_bh(&efx->filter_lock);
4295
4296 if (failed)
4297 netif_err(efx, hw, efx->net_dev,
4298 "unable to restore all filters\n");
4299 else
4300 nic_data->must_restore_filters = false;
4301}
4302
4303static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4304{
4305 struct efx_ef10_filter_table *table = efx->filter_state;
4306 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4307 struct efx_filter_spec *spec;
4308 unsigned int filter_idx;
4309 int rc;
4310
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004311 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004312 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004313 /* If we were called without locking, then it's not safe to free
4314 * the table as others might be using it. So we just WARN, leak
4315 * the memory, and potentially get an inconsistent filter table
4316 * state.
4317 * This should never actually happen.
4318 */
4319 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4320 return;
4321
Edward Cree0d322412015-05-20 11:10:03 +01004322 if (!table)
4323 return;
4324
Ben Hutchings8127d662013-08-29 19:19:29 +01004325 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4326 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4327 if (!spec)
4328 continue;
4329
4330 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4331 efx_ef10_filter_is_exclusive(spec) ?
4332 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4333 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4334 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4335 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004336 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4337 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004338 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004339 netif_info(efx, drv, efx->net_dev,
4340 "%s: filter %04x remove failed\n",
4341 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004342 kfree(spec);
4343 }
4344
4345 vfree(table->entry);
4346 kfree(table);
4347}
4348
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004349static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4350{
4351 struct efx_ef10_filter_table *table = efx->filter_state;
4352 unsigned int filter_idx;
4353
4354 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4355 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4356 if (!table->entry[filter_idx].spec)
4357 netif_dbg(efx, drv, efx->net_dev,
4358 "marked null spec old %04x:%04x\n", *id,
4359 filter_idx);
4360 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4361 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004362 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004363}
4364
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004365/* Mark old per-VLAN filters that may need to be removed */
4366static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4367 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004368{
4369 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004370 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004371
Edward Cree12fb0da2015-07-21 15:11:00 +01004372 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004373 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004374 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004375 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4376 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4377 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4378 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004379}
4380
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004381/* Mark old filters that may need to be removed.
4382 * Caller must hold efx->filter_sem for read if race against
4383 * efx_ef10_filter_table_remove() is possible
4384 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004385static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4386{
4387 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004388 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004389
4390 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004391 list_for_each_entry(vlan, &table->vlan_list, list)
4392 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004393 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004394}
Ben Hutchings8127d662013-08-29 19:19:29 +01004395
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004396static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004397{
4398 struct efx_ef10_filter_table *table = efx->filter_state;
4399 struct net_device *net_dev = efx->net_dev;
4400 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004401 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004402 unsigned int i;
4403
Edward Cree12fb0da2015-07-21 15:11:00 +01004404 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004405 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004406 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004407 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4408 i = 1;
4409 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004410 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004411 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004412 break;
4413 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004414 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4415 i++;
4416 }
4417}
4418
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004419static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004420{
4421 struct efx_ef10_filter_table *table = efx->filter_state;
4422 struct net_device *net_dev = efx->net_dev;
4423 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004424 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004425
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004426 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004427
Edward Cree12fb0da2015-07-21 15:11:00 +01004428 addr_count = netdev_mc_count(net_dev);
4429 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004430 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004431 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004432 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004433 break;
4434 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004435 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4436 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004437 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004438
4439 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004440}
Ben Hutchings8127d662013-08-29 19:19:29 +01004441
Edward Cree12fb0da2015-07-21 15:11:00 +01004442static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004443 struct efx_ef10_filter_vlan *vlan,
4444 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004445{
4446 struct efx_ef10_filter_table *table = efx->filter_state;
4447 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004448 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004449 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004450 u8 baddr[ETH_ALEN];
4451 unsigned int i, j;
4452 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004453 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004454 int rc;
4455
4456 if (multicast) {
4457 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004458 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004459 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004460 } else {
4461 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004462 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004463 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004464 }
4465
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004466 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4467
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004468 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004469 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004470 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004471 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004472 rc = efx_ef10_filter_insert(efx, &spec, true);
4473 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004474 if (rollback) {
4475 netif_info(efx, drv, efx->net_dev,
4476 "efx_ef10_filter_insert failed rc=%d\n",
4477 rc);
4478 /* Fall back to promiscuous */
4479 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004480 efx_ef10_filter_remove_unsafe(
4481 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004482 ids[j]);
4483 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004484 }
4485 return rc;
4486 } else {
4487 /* mark as not inserted, and carry on */
4488 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004489 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004490 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004491 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004492 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004493
Edward Cree12fb0da2015-07-21 15:11:00 +01004494 if (multicast && rollback) {
4495 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004496 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004497 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004498 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004499 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004500 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004501 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004502 "Broadcast filter insert failed rc=%d\n", rc);
4503 /* Fall back to promiscuous */
4504 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004505 efx_ef10_filter_remove_unsafe(
4506 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004507 ids[j]);
4508 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004509 }
4510 return rc;
4511 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004512 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004513 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004514 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004515 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004516 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004517
4518 return 0;
4519}
4520
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004521static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4522 struct efx_ef10_filter_vlan *vlan,
4523 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004524{
Edward Cree12fb0da2015-07-21 15:11:00 +01004525 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004526 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004527 struct efx_filter_spec spec;
4528 u8 baddr[ETH_ALEN];
4529 int rc;
4530
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004531 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4532
4533 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004534
4535 if (multicast)
4536 efx_filter_set_mc_def(&spec);
4537 else
4538 efx_filter_set_uc_def(&spec);
4539
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004540 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4541 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4542
Edward Cree12fb0da2015-07-21 15:11:00 +01004543 rc = efx_ef10_filter_insert(efx, &spec, true);
4544 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004545 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4546 efx->net_dev,
4547 "%scast mismatch filter insert failed rc=%d\n",
4548 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004549 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004550 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4551 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004552 if (!nic_data->workaround_26807) {
4553 /* Also need an Ethernet broadcast filter */
4554 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004555 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004556 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004557 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004558 rc = efx_ef10_filter_insert(efx, &spec, true);
4559 if (rc < 0) {
4560 netif_warn(efx, drv, efx->net_dev,
4561 "Broadcast filter insert failed rc=%d\n",
4562 rc);
4563 if (rollback) {
4564 /* Roll back the mc_def filter */
4565 efx_ef10_filter_remove_unsafe(
4566 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004567 vlan->mcdef);
4568 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004569 return rc;
4570 }
4571 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004572 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004573 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004574 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004575 }
4576 }
4577 rc = 0;
4578 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004579 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4580 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004581 rc = 0;
4582 }
4583 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004584}
4585
4586/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4587 * flag or removes these filters, we don't need to hold the filter_lock while
4588 * scanning for these filters.
4589 */
4590static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4591{
4592 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004593 int remove_failed = 0;
4594 int remove_noent = 0;
4595 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004596 int i;
4597
Ben Hutchings8127d662013-08-29 19:19:29 +01004598 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4599 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004600 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004601 rc = efx_ef10_filter_remove_internal(efx,
4602 1U << EFX_FILTER_PRI_AUTO, i, true);
4603 if (rc == -ENOENT)
4604 remove_noent++;
4605 else if (rc)
4606 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004607 }
4608 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004609
4610 if (remove_failed)
4611 netif_info(efx, drv, efx->net_dev,
4612 "%s: failed to remove %d filters\n",
4613 __func__, remove_failed);
4614 if (remove_noent)
4615 netif_info(efx, drv, efx->net_dev,
4616 "%s: failed to remove %d non-existent filters\n",
4617 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004618}
4619
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004620static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4621{
4622 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4623 u8 mac_old[ETH_ALEN];
4624 int rc, rc2;
4625
4626 /* Only reconfigure a PF-created vport */
4627 if (is_zero_ether_addr(nic_data->vport_mac))
4628 return 0;
4629
4630 efx_device_detach_sync(efx);
4631 efx_net_stop(efx->net_dev);
4632 down_write(&efx->filter_sem);
4633 efx_ef10_filter_table_remove(efx);
4634 up_write(&efx->filter_sem);
4635
4636 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4637 if (rc)
4638 goto restore_filters;
4639
4640 ether_addr_copy(mac_old, nic_data->vport_mac);
4641 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4642 nic_data->vport_mac);
4643 if (rc)
4644 goto restore_vadaptor;
4645
4646 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4647 efx->net_dev->dev_addr);
4648 if (!rc) {
4649 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4650 } else {
4651 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4652 if (rc2) {
4653 /* Failed to add original MAC, so clear vport_mac */
4654 eth_zero_addr(nic_data->vport_mac);
4655 goto reset_nic;
4656 }
4657 }
4658
4659restore_vadaptor:
4660 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4661 if (rc2)
4662 goto reset_nic;
4663restore_filters:
4664 down_write(&efx->filter_sem);
4665 rc2 = efx_ef10_filter_table_probe(efx);
4666 up_write(&efx->filter_sem);
4667 if (rc2)
4668 goto reset_nic;
4669
4670 rc2 = efx_net_open(efx->net_dev);
4671 if (rc2)
4672 goto reset_nic;
4673
4674 netif_device_attach(efx->net_dev);
4675
4676 return rc;
4677
4678reset_nic:
4679 netif_err(efx, drv, efx->net_dev,
4680 "Failed to restore when changing MAC address - scheduling reset\n");
4681 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4682
4683 return rc ? rc : rc2;
4684}
4685
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004686/* Caller must hold efx->filter_sem for read if race against
4687 * efx_ef10_filter_table_remove() is possible
4688 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004689static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4690 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004691{
4692 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004693 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004694
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004695 /* Do not install unspecified VID if VLAN filtering is enabled.
4696 * Do not install all specified VIDs if VLAN filtering is disabled.
4697 */
4698 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4699 return;
4700
Edward Cree12fb0da2015-07-21 15:11:00 +01004701 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004702 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004703 efx_ef10_filter_insert_def(efx, vlan, false, false);
4704 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004705 } else {
4706 /* If any of the filters failed to insert, fall back to
4707 * promiscuous mode - add in the uc_def filter. But keep
4708 * our individual unicast filters.
4709 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004710 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4711 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004712 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004713
Edward Cree12fb0da2015-07-21 15:11:00 +01004714 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004715 /* If changing promiscuous state with cascaded multicast filters, remove
4716 * old filters first, so that packets are dropped rather than duplicated
4717 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004718 if (nic_data->workaround_26807 &&
4719 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004720 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004721 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004722 if (nic_data->workaround_26807) {
4723 /* If we failed to insert promiscuous filters, rollback
4724 * and fall back to individual multicast filters
4725 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004726 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004727 /* Changing promisc state, so remove old filters */
4728 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004729 efx_ef10_filter_insert_addr_list(efx, vlan,
4730 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004731 }
4732 } else {
4733 /* If we failed to insert promiscuous filters, don't
4734 * rollback. Regardless, also insert the mc_list
4735 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004736 efx_ef10_filter_insert_def(efx, vlan, true, false);
4737 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004738 }
4739 } else {
4740 /* If any filters failed to insert, rollback and fall back to
4741 * promiscuous mode - mc_def filter and maybe broadcast. If
4742 * that fails, roll back again and insert as many of our
4743 * individual multicast filters as we can.
4744 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004745 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004746 /* Changing promisc state, so remove old filters */
4747 if (nic_data->workaround_26807)
4748 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004749 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4750 efx_ef10_filter_insert_addr_list(efx, vlan,
4751 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004752 }
4753 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004754}
4755
4756/* Caller must hold efx->filter_sem for read if race against
4757 * efx_ef10_filter_table_remove() is possible
4758 */
4759static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4760{
4761 struct efx_ef10_filter_table *table = efx->filter_state;
4762 struct net_device *net_dev = efx->net_dev;
4763 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004764 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004765
4766 if (!efx_dev_registered(efx))
4767 return;
4768
4769 if (!table)
4770 return;
4771
4772 efx_ef10_filter_mark_old(efx);
4773
4774 /* Copy/convert the address lists; add the primary station
4775 * address and broadcast address
4776 */
4777 netif_addr_lock_bh(net_dev);
4778 efx_ef10_filter_uc_addr_list(efx);
4779 efx_ef10_filter_mc_addr_list(efx);
4780 netif_addr_unlock_bh(net_dev);
4781
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004782 /* If VLAN filtering changes, all old filters are finally removed.
4783 * Do it in advance to avoid conflicts for unicast untagged and
4784 * VLAN 0 tagged filters.
4785 */
4786 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4787 if (table->vlan_filter != vlan_filter) {
4788 table->vlan_filter = vlan_filter;
4789 efx_ef10_filter_remove_old(efx);
4790 }
4791
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004792 list_for_each_entry(vlan, &table->vlan_list, list)
4793 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004794
4795 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004796 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004797}
4798
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004799static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
4800{
4801 struct efx_ef10_filter_table *table = efx->filter_state;
4802 struct efx_ef10_filter_vlan *vlan;
4803
4804 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4805
4806 list_for_each_entry(vlan, &table->vlan_list, list) {
4807 if (vlan->vid == vid)
4808 return vlan;
4809 }
4810
4811 return NULL;
4812}
4813
4814static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
4815{
4816 struct efx_ef10_filter_table *table = efx->filter_state;
4817 struct efx_ef10_filter_vlan *vlan;
4818 unsigned int i;
4819
4820 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4821 return -EINVAL;
4822
4823 vlan = efx_ef10_filter_find_vlan(efx, vid);
4824 if (WARN_ON(vlan)) {
4825 netif_err(efx, drv, efx->net_dev,
4826 "VLAN %u already added\n", vid);
4827 return -EALREADY;
4828 }
4829
4830 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
4831 if (!vlan)
4832 return -ENOMEM;
4833
4834 vlan->vid = vid;
4835
4836 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
4837 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
4838 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
4839 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
4840 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
4841 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
4842 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
4843
4844 list_add_tail(&vlan->list, &table->vlan_list);
4845
4846 if (efx_dev_registered(efx))
4847 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
4848
4849 return 0;
4850}
4851
4852static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
4853 struct efx_ef10_filter_vlan *vlan)
4854{
4855 unsigned int i;
4856
4857 /* See comment in efx_ef10_filter_table_remove() */
4858 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4859 return;
4860
4861 list_del(&vlan->list);
4862
Edward Cree8c915622016-06-15 17:49:05 +01004863 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004864 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01004865 vlan->uc[i]);
4866 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004867 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01004868 vlan->mc[i]);
4869 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
4870 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
4871 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004872
4873 kfree(vlan);
4874}
4875
4876static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
4877{
4878 struct efx_ef10_filter_vlan *vlan;
4879
4880 /* See comment in efx_ef10_filter_table_remove() */
4881 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4882 return;
4883
4884 vlan = efx_ef10_filter_find_vlan(efx, vid);
4885 if (!vlan) {
4886 netif_err(efx, drv, efx->net_dev,
4887 "VLAN %u not found in filter state\n", vid);
4888 return;
4889 }
4890
4891 efx_ef10_filter_del_vlan_internal(efx, vlan);
4892}
4893
Shradha Shah910c8782015-05-20 11:12:48 +01004894static int efx_ef10_set_mac_address(struct efx_nic *efx)
4895{
4896 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
4897 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4898 bool was_enabled = efx->port_enabled;
4899 int rc;
4900
4901 efx_device_detach_sync(efx);
4902 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01004903
4904 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01004905 down_write(&efx->filter_sem);
4906 efx_ef10_filter_table_remove(efx);
4907
4908 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
4909 efx->net_dev->dev_addr);
4910 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
4911 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01004912 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
4913 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01004914
4915 efx_ef10_filter_table_probe(efx);
4916 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01004917 mutex_unlock(&efx->mac_lock);
4918
Shradha Shah910c8782015-05-20 11:12:48 +01004919 if (was_enabled)
4920 efx_net_open(efx->net_dev);
4921 netif_device_attach(efx->net_dev);
4922
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004923#ifdef CONFIG_SFC_SRIOV
4924 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01004925 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
4926
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004927 if (rc == -EPERM) {
4928 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01004929
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004930 /* Switch to PF and change MAC address on vport */
4931 efx_pf = pci_get_drvdata(pci_dev_pf);
4932
4933 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004934 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004935 efx->net_dev->dev_addr);
4936 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01004937 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
4938 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
4939 unsigned int i;
4940
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004941 /* MAC address successfully changed by VF (with MAC
4942 * spoofing) so update the parent PF if possible.
4943 */
Shradha Shah910c8782015-05-20 11:12:48 +01004944 for (i = 0; i < efx_pf->vf_count; ++i) {
4945 struct ef10_vf *vf = nic_data->vf + i;
4946
4947 if (vf->efx == efx) {
4948 ether_addr_copy(vf->mac,
4949 efx->net_dev->dev_addr);
4950 return 0;
4951 }
4952 }
4953 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004954 } else
Shradha Shah910c8782015-05-20 11:12:48 +01004955#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004956 if (rc == -EPERM) {
4957 netif_err(efx, drv, efx->net_dev,
4958 "Cannot change MAC address; use sfboot to enable"
4959 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004960 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
4961 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
4962 * fall-back to the method of changing the MAC address on the
4963 * vport. This only applies to PFs because such versions of
4964 * MCFW do not support VFs.
4965 */
4966 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01004967 } else {
4968 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
4969 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004970 }
4971
Shradha Shah910c8782015-05-20 11:12:48 +01004972 return rc;
4973}
4974
Ben Hutchings8127d662013-08-29 19:19:29 +01004975static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
4976{
4977 efx_ef10_filter_sync_rx_mode(efx);
4978
4979 return efx_mcdi_set_mac(efx);
4980}
4981
Shradha Shah862f8942015-05-20 11:08:56 +01004982static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
4983{
4984 efx_ef10_filter_sync_rx_mode(efx);
4985
4986 return 0;
4987}
4988
Jon Cooper74cd60a2013-09-16 14:18:51 +01004989static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
4990{
4991 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
4992
4993 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
4994 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
4995 NULL, 0, NULL);
4996}
4997
4998/* MC BISTs follow a different poll mechanism to phy BISTs.
4999 * The BIST is done in the poll handler on the MC, and the MCDI command
5000 * will block until the BIST is done.
5001 */
5002static int efx_ef10_poll_bist(struct efx_nic *efx)
5003{
5004 int rc;
5005 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5006 size_t outlen;
5007 u32 result;
5008
5009 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5010 outbuf, sizeof(outbuf), &outlen);
5011 if (rc != 0)
5012 return rc;
5013
5014 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5015 return -EIO;
5016
5017 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5018 switch (result) {
5019 case MC_CMD_POLL_BIST_PASSED:
5020 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5021 return 0;
5022 case MC_CMD_POLL_BIST_TIMEOUT:
5023 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5024 return -EIO;
5025 case MC_CMD_POLL_BIST_FAILED:
5026 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5027 return -EIO;
5028 default:
5029 netif_err(efx, hw, efx->net_dev,
5030 "BIST returned unknown result %u", result);
5031 return -EIO;
5032 }
5033}
5034
5035static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5036{
5037 int rc;
5038
5039 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5040
5041 rc = efx_ef10_start_bist(efx, bist_type);
5042 if (rc != 0)
5043 return rc;
5044
5045 return efx_ef10_poll_bist(efx);
5046}
5047
5048static int
5049efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5050{
5051 int rc, rc2;
5052
5053 efx_reset_down(efx, RESET_TYPE_WORLD);
5054
5055 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5056 NULL, 0, NULL, 0, NULL);
5057 if (rc != 0)
5058 goto out;
5059
5060 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5061 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5062
5063 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5064
5065out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005066 if (rc == -EPERM)
5067 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005068 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5069 return rc ? rc : rc2;
5070}
5071
Ben Hutchings8127d662013-08-29 19:19:29 +01005072#ifdef CONFIG_SFC_MTD
5073
5074struct efx_ef10_nvram_type_info {
5075 u16 type, type_mask;
5076 u8 port;
5077 const char *name;
5078};
5079
5080static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5081 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5082 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5083 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5084 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5085 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5086 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5087 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5088 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5089 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005090 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005091 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5092};
5093
5094static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5095 struct efx_mcdi_mtd_partition *part,
5096 unsigned int type)
5097{
5098 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5099 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5100 const struct efx_ef10_nvram_type_info *info;
5101 size_t size, erase_size, outlen;
5102 bool protected;
5103 int rc;
5104
5105 for (info = efx_ef10_nvram_types; ; info++) {
5106 if (info ==
5107 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5108 return -ENODEV;
5109 if ((type & ~info->type_mask) == info->type)
5110 break;
5111 }
5112 if (info->port != efx_port_num(efx))
5113 return -ENODEV;
5114
5115 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5116 if (rc)
5117 return rc;
5118 if (protected)
5119 return -ENODEV; /* hide it */
5120
5121 part->nvram_type = type;
5122
5123 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5124 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5125 outbuf, sizeof(outbuf), &outlen);
5126 if (rc)
5127 return rc;
5128 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5129 return -EIO;
5130 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5131 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5132 part->fw_subtype = MCDI_DWORD(outbuf,
5133 NVRAM_METADATA_OUT_SUBTYPE);
5134
5135 part->common.dev_type_name = "EF10 NVRAM manager";
5136 part->common.type_name = info->name;
5137
5138 part->common.mtd.type = MTD_NORFLASH;
5139 part->common.mtd.flags = MTD_CAP_NORFLASH;
5140 part->common.mtd.size = size;
5141 part->common.mtd.erasesize = erase_size;
5142
5143 return 0;
5144}
5145
5146static int efx_ef10_mtd_probe(struct efx_nic *efx)
5147{
5148 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5149 struct efx_mcdi_mtd_partition *parts;
5150 size_t outlen, n_parts_total, i, n_parts;
5151 unsigned int type;
5152 int rc;
5153
5154 ASSERT_RTNL();
5155
5156 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5157 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5158 outbuf, sizeof(outbuf), &outlen);
5159 if (rc)
5160 return rc;
5161 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5162 return -EIO;
5163
5164 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5165 if (n_parts_total >
5166 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5167 return -EIO;
5168
5169 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5170 if (!parts)
5171 return -ENOMEM;
5172
5173 n_parts = 0;
5174 for (i = 0; i < n_parts_total; i++) {
5175 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5176 i);
5177 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5178 if (rc == 0)
5179 n_parts++;
5180 else if (rc != -ENODEV)
5181 goto fail;
5182 }
5183
5184 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5185fail:
5186 if (rc)
5187 kfree(parts);
5188 return rc;
5189}
5190
5191#endif /* CONFIG_SFC_MTD */
5192
5193static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5194{
5195 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5196}
5197
Shradha Shah02246a72015-05-06 00:58:14 +01005198static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5199 u32 host_time) {}
5200
Jon Cooperbd9a2652013-11-18 12:54:41 +00005201static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5202 bool temp)
5203{
5204 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5205 int rc;
5206
5207 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5208 channel->sync_events_state == SYNC_EVENTS_VALID ||
5209 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5210 return 0;
5211 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5212
5213 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5214 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5215 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5216 channel->channel);
5217
5218 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5219 inbuf, sizeof(inbuf), NULL, 0, NULL);
5220
5221 if (rc != 0)
5222 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5223 SYNC_EVENTS_DISABLED;
5224
5225 return rc;
5226}
5227
5228static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5229 bool temp)
5230{
5231 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5232 int rc;
5233
5234 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5235 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5236 return 0;
5237 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5238 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5239 return 0;
5240 }
5241 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5242 SYNC_EVENTS_DISABLED;
5243
5244 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5245 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5246 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5247 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5248 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5249 channel->channel);
5250
5251 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5252 inbuf, sizeof(inbuf), NULL, 0, NULL);
5253
5254 return rc;
5255}
5256
5257static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5258 bool temp)
5259{
5260 int (*set)(struct efx_channel *channel, bool temp);
5261 struct efx_channel *channel;
5262
5263 set = en ?
5264 efx_ef10_rx_enable_timestamping :
5265 efx_ef10_rx_disable_timestamping;
5266
5267 efx_for_each_channel(channel, efx) {
5268 int rc = set(channel, temp);
5269 if (en && rc != 0) {
5270 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5271 return rc;
5272 }
5273 }
5274
5275 return 0;
5276}
5277
Shradha Shah02246a72015-05-06 00:58:14 +01005278static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5279 struct hwtstamp_config *init)
5280{
5281 return -EOPNOTSUPP;
5282}
5283
Jon Cooperbd9a2652013-11-18 12:54:41 +00005284static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5285 struct hwtstamp_config *init)
5286{
5287 int rc;
5288
5289 switch (init->rx_filter) {
5290 case HWTSTAMP_FILTER_NONE:
5291 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5292 /* if TX timestamping is still requested then leave PTP on */
5293 return efx_ptp_change_mode(efx,
5294 init->tx_type != HWTSTAMP_TX_OFF, 0);
5295 case HWTSTAMP_FILTER_ALL:
5296 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5297 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5298 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5299 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5300 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5301 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5302 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5303 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5304 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5305 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5306 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5307 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5308 init->rx_filter = HWTSTAMP_FILTER_ALL;
5309 rc = efx_ptp_change_mode(efx, true, 0);
5310 if (!rc)
5311 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5312 if (rc)
5313 efx_ptp_change_mode(efx, false, 0);
5314 return rc;
5315 default:
5316 return -ERANGE;
5317 }
5318}
5319
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005320static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5321{
5322 if (proto != htons(ETH_P_8021Q))
5323 return -EINVAL;
5324
5325 return efx_ef10_add_vlan(efx, vid);
5326}
5327
5328static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5329{
5330 if (proto != htons(ETH_P_8021Q))
5331 return -EINVAL;
5332
5333 return efx_ef10_del_vlan(efx, vid);
5334}
5335
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005336#define EF10_OFFLOAD_FEATURES \
5337 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005338 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005339 NETIF_F_IPV6_CSUM | \
5340 NETIF_F_RXHASH | \
5341 NETIF_F_NTUPLE)
5342
Shradha Shah02246a72015-05-06 00:58:14 +01005343const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005344 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005345 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005346 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005347 .probe = efx_ef10_probe_vf,
5348 .remove = efx_ef10_remove,
5349 .dimension_resources = efx_ef10_dimension_resources,
5350 .init = efx_ef10_init_nic,
5351 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005352 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005353 .map_reset_flags = efx_ef10_map_reset_flags,
5354 .reset = efx_ef10_reset,
5355 .probe_port = efx_mcdi_port_probe,
5356 .remove_port = efx_mcdi_port_remove,
5357 .fini_dmaq = efx_ef10_fini_dmaq,
5358 .prepare_flr = efx_ef10_prepare_flr,
5359 .finish_flr = efx_port_dummy_op_void,
5360 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005361 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005362 .start_stats = efx_port_dummy_op_void,
5363 .pull_stats = efx_port_dummy_op_void,
5364 .stop_stats = efx_port_dummy_op_void,
5365 .set_id_led = efx_mcdi_set_id_led,
5366 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005367 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005368 .check_mac_fault = efx_mcdi_mac_check_fault,
5369 .reconfigure_port = efx_mcdi_port_reconfigure,
5370 .get_wol = efx_ef10_get_wol_vf,
5371 .set_wol = efx_ef10_set_wol_vf,
5372 .resume_wol = efx_port_dummy_op_void,
5373 .mcdi_request = efx_ef10_mcdi_request,
5374 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5375 .mcdi_read_response = efx_ef10_mcdi_read_response,
5376 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005377 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005378 .irq_enable_master = efx_port_dummy_op_void,
5379 .irq_test_generate = efx_ef10_irq_test_generate,
5380 .irq_disable_non_ev = efx_port_dummy_op_void,
5381 .irq_handle_msi = efx_ef10_msi_interrupt,
5382 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5383 .tx_probe = efx_ef10_tx_probe,
5384 .tx_init = efx_ef10_tx_init,
5385 .tx_remove = efx_ef10_tx_remove,
5386 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01005387 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005388 .rx_probe = efx_ef10_rx_probe,
5389 .rx_init = efx_ef10_rx_init,
5390 .rx_remove = efx_ef10_rx_remove,
5391 .rx_write = efx_ef10_rx_write,
5392 .rx_defer_refill = efx_ef10_rx_defer_refill,
5393 .ev_probe = efx_ef10_ev_probe,
5394 .ev_init = efx_ef10_ev_init,
5395 .ev_fini = efx_ef10_ev_fini,
5396 .ev_remove = efx_ef10_ev_remove,
5397 .ev_process = efx_ef10_ev_process,
5398 .ev_read_ack = efx_ef10_ev_read_ack,
5399 .ev_test_generate = efx_ef10_ev_test_generate,
5400 .filter_table_probe = efx_ef10_filter_table_probe,
5401 .filter_table_restore = efx_ef10_filter_table_restore,
5402 .filter_table_remove = efx_ef10_filter_table_remove,
5403 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5404 .filter_insert = efx_ef10_filter_insert,
5405 .filter_remove_safe = efx_ef10_filter_remove_safe,
5406 .filter_get_safe = efx_ef10_filter_get_safe,
5407 .filter_clear_rx = efx_ef10_filter_clear_rx,
5408 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5409 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5410 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5411#ifdef CONFIG_RFS_ACCEL
5412 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5413 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5414#endif
5415#ifdef CONFIG_SFC_MTD
5416 .mtd_probe = efx_port_dummy_op_int,
5417#endif
5418 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5419 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005420 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5421 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005422#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005423 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5424 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5425 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01005426 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005427#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005428 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005429 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005430
Shradha Shah02246a72015-05-06 00:58:14 +01005431 .revision = EFX_REV_HUNT_A0,
5432 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5433 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5434 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5435 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5436 .can_rx_scatter = true,
5437 .always_rx_scatter = true,
5438 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5439 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005440 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005441 .mcdi_max_ver = 2,
5442 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5443 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5444 1 << HWTSTAMP_FILTER_ALL,
5445};
5446
5447const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005448 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005449 .mem_bar = EFX_MEM_BAR,
5450 .mem_map_size = efx_ef10_mem_map_size,
5451 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005452 .remove = efx_ef10_remove,
5453 .dimension_resources = efx_ef10_dimension_resources,
5454 .init = efx_ef10_init_nic,
5455 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005456 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005457 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005458 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005459 .probe_port = efx_mcdi_port_probe,
5460 .remove_port = efx_mcdi_port_remove,
5461 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005462 .prepare_flr = efx_ef10_prepare_flr,
5463 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005464 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005465 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005466 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005467 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005468 .stop_stats = efx_mcdi_mac_stop_stats,
5469 .set_id_led = efx_mcdi_set_id_led,
5470 .push_irq_moderation = efx_ef10_push_irq_moderation,
5471 .reconfigure_mac = efx_ef10_mac_reconfigure,
5472 .check_mac_fault = efx_mcdi_mac_check_fault,
5473 .reconfigure_port = efx_mcdi_port_reconfigure,
5474 .get_wol = efx_ef10_get_wol,
5475 .set_wol = efx_ef10_set_wol,
5476 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005477 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005478 .test_nvram = efx_mcdi_nvram_test_all,
5479 .mcdi_request = efx_ef10_mcdi_request,
5480 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5481 .mcdi_read_response = efx_ef10_mcdi_read_response,
5482 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005483 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005484 .irq_enable_master = efx_port_dummy_op_void,
5485 .irq_test_generate = efx_ef10_irq_test_generate,
5486 .irq_disable_non_ev = efx_port_dummy_op_void,
5487 .irq_handle_msi = efx_ef10_msi_interrupt,
5488 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5489 .tx_probe = efx_ef10_tx_probe,
5490 .tx_init = efx_ef10_tx_init,
5491 .tx_remove = efx_ef10_tx_remove,
5492 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01005493 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005494 .rx_probe = efx_ef10_rx_probe,
5495 .rx_init = efx_ef10_rx_init,
5496 .rx_remove = efx_ef10_rx_remove,
5497 .rx_write = efx_ef10_rx_write,
5498 .rx_defer_refill = efx_ef10_rx_defer_refill,
5499 .ev_probe = efx_ef10_ev_probe,
5500 .ev_init = efx_ef10_ev_init,
5501 .ev_fini = efx_ef10_ev_fini,
5502 .ev_remove = efx_ef10_ev_remove,
5503 .ev_process = efx_ef10_ev_process,
5504 .ev_read_ack = efx_ef10_ev_read_ack,
5505 .ev_test_generate = efx_ef10_ev_test_generate,
5506 .filter_table_probe = efx_ef10_filter_table_probe,
5507 .filter_table_restore = efx_ef10_filter_table_restore,
5508 .filter_table_remove = efx_ef10_filter_table_remove,
5509 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5510 .filter_insert = efx_ef10_filter_insert,
5511 .filter_remove_safe = efx_ef10_filter_remove_safe,
5512 .filter_get_safe = efx_ef10_filter_get_safe,
5513 .filter_clear_rx = efx_ef10_filter_clear_rx,
5514 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5515 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5516 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5517#ifdef CONFIG_RFS_ACCEL
5518 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5519 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5520#endif
5521#ifdef CONFIG_SFC_MTD
5522 .mtd_probe = efx_ef10_mtd_probe,
5523 .mtd_rename = efx_mcdi_mtd_rename,
5524 .mtd_read = efx_mcdi_mtd_read,
5525 .mtd_erase = efx_mcdi_mtd_erase,
5526 .mtd_write = efx_mcdi_mtd_write,
5527 .mtd_sync = efx_mcdi_mtd_sync,
5528#endif
5529 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005530 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5531 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005532 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5533 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005534#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005535 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005536 .sriov_init = efx_ef10_sriov_init,
5537 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005538 .sriov_wanted = efx_ef10_sriov_wanted,
5539 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005540 .sriov_flr = efx_ef10_sriov_flr,
5541 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5542 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5543 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5544 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005545 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005546 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5547 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5548 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005549#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005550 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005551 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01005552
5553 .revision = EFX_REV_HUNT_A0,
5554 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5555 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5556 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005557 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005558 .can_rx_scatter = true,
5559 .always_rx_scatter = true,
5560 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5561 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005562 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005563 .mcdi_max_ver = 2,
5564 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005565 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5566 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005567};