blob: d0c1ed0e035409af13918464756f765ed79cec2d [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
Edward Creec6347002017-01-13 21:20:29 +0000200 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
Bert Kenwardca889a02016-08-11 13:01:35 +0100201 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
202 GET_CAPABILITIES_V2_OUT_FLAGS2);
Edward Creec6347002017-01-13 21:20:29 +0000203 nic_data->piobuf_size = MCDI_WORD(outbuf,
204 GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
205 } else {
Bert Kenwardca889a02016-08-11 13:01:35 +0100206 nic_data->datapath_caps2 = 0;
Edward Creec6347002017-01-13 21:20:29 +0000207 nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
208 }
Bert Kenwardca889a02016-08-11 13:01:35 +0100209
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100210 /* record the DPCPU firmware IDs to determine VEB vswitching support.
211 */
212 nic_data->rx_dpcpu_fw_id =
213 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
214 nic_data->tx_dpcpu_fw_id =
215 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
216
Ben Hutchingse5a25382013-09-05 22:50:59 +0100217 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100218 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
219 netif_err(efx, probe, efx->net_dev,
220 "current firmware does not support an RX prefix\n");
221 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100222 }
223
224 return 0;
225}
226
227static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
228{
229 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
230 int rc;
231
232 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
233 outbuf, sizeof(outbuf), NULL);
234 if (rc)
235 return rc;
236 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
237 return rc > 0 ? rc : -ERANGE;
238}
239
Bert Kenwardd95e3292016-08-11 13:02:36 +0100240static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
241{
242 struct efx_ef10_nic_data *nic_data = efx->nic_data;
243 unsigned int implemented;
244 unsigned int enabled;
245 int rc;
246
247 nic_data->workaround_35388 = false;
248 nic_data->workaround_61265 = false;
249
250 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
251
252 if (rc == -ENOSYS) {
253 /* Firmware without GET_WORKAROUNDS - not a problem. */
254 rc = 0;
255 } else if (rc == 0) {
256 /* Bug61265 workaround is always enabled if implemented. */
257 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
258 nic_data->workaround_61265 = true;
259
260 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
261 nic_data->workaround_35388 = true;
262 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
263 /* Workaround is implemented but not enabled.
264 * Try to enable it.
265 */
266 rc = efx_mcdi_set_workaround(efx,
267 MC_CMD_WORKAROUND_BUG35388,
268 true, NULL);
269 if (rc == 0)
270 nic_data->workaround_35388 = true;
271 /* If we failed to set the workaround just carry on. */
272 rc = 0;
273 }
274 }
275
276 netif_dbg(efx, probe, efx->net_dev,
277 "workaround for bug 35388 is %sabled\n",
278 nic_data->workaround_35388 ? "en" : "dis");
279 netif_dbg(efx, probe, efx->net_dev,
280 "workaround for bug 61265 is %sabled\n",
281 nic_data->workaround_61265 ? "en" : "dis");
282
283 return rc;
284}
285
286static void efx_ef10_process_timer_config(struct efx_nic *efx,
287 const efx_dword_t *data)
288{
289 unsigned int max_count;
290
291 if (EFX_EF10_WORKAROUND_61265(efx)) {
292 efx->timer_quantum_ns = MCDI_DWORD(data,
293 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
294 efx->timer_max_ns = MCDI_DWORD(data,
295 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
296 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
297 efx->timer_quantum_ns = MCDI_DWORD(data,
298 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
299 max_count = MCDI_DWORD(data,
300 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
301 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
302 } else {
303 efx->timer_quantum_ns = MCDI_DWORD(data,
304 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
305 max_count = MCDI_DWORD(data,
306 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
307 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
308 }
309
310 netif_dbg(efx, probe, efx->net_dev,
311 "got timer properties from MC: quantum %u ns; max %u ns\n",
312 efx->timer_quantum_ns, efx->timer_max_ns);
313}
314
315static int efx_ef10_get_timer_config(struct efx_nic *efx)
316{
317 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
318 int rc;
319
320 rc = efx_ef10_get_timer_workarounds(efx);
321 if (rc)
322 return rc;
323
324 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
325 outbuf, sizeof(outbuf), NULL);
326
327 if (rc == 0) {
328 efx_ef10_process_timer_config(efx, outbuf);
329 } else if (rc == -ENOSYS || rc == -EPERM) {
330 /* Not available - fall back to Huntington defaults. */
331 unsigned int quantum;
332
333 rc = efx_ef10_get_sysclk_freq(efx);
334 if (rc < 0)
335 return rc;
336
337 quantum = 1536000 / rc; /* 1536 cycles */
338 efx->timer_quantum_ns = quantum;
339 efx->timer_max_ns = efx->type->timer_period_max * quantum;
340 rc = 0;
341 } else {
342 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
343 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
344 NULL, 0, rc);
345 }
346
347 return rc;
348}
349
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100350static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100351{
352 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
353 size_t outlen;
354 int rc;
355
356 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
357
358 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
359 outbuf, sizeof(outbuf), &outlen);
360 if (rc)
361 return rc;
362 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
363 return -EIO;
364
Edward Creecd84ff42014-03-07 18:27:41 +0000365 ether_addr_copy(mac_address,
366 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100367 return 0;
368}
369
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100370static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
371{
372 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
373 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
374 size_t outlen;
375 int num_addrs, rc;
376
377 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
378 EVB_PORT_ID_ASSIGNED);
379 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
380 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
381
382 if (rc)
383 return rc;
384 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
385 return -EIO;
386
387 num_addrs = MCDI_DWORD(outbuf,
388 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
389
390 WARN_ON(num_addrs != 1);
391
392 ether_addr_copy(mac_address,
393 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
394
395 return 0;
396}
397
Shradha Shah0f5c0842015-06-02 11:37:58 +0100398static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
399 struct device_attribute *attr,
400 char *buf)
401{
402 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
403
404 return sprintf(buf, "%d\n",
405 ((efx->mcdi->fn_flags) &
406 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
407 ? 1 : 0);
408}
409
410static ssize_t efx_ef10_show_primary_flag(struct device *dev,
411 struct device_attribute *attr,
412 char *buf)
413{
414 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
415
416 return sprintf(buf, "%d\n",
417 ((efx->mcdi->fn_flags) &
418 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
419 ? 1 : 0);
420}
421
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100422static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
423{
424 struct efx_ef10_nic_data *nic_data = efx->nic_data;
425 struct efx_ef10_vlan *vlan;
426
427 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
428
429 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
430 if (vlan->vid == vid)
431 return vlan;
432 }
433
434 return NULL;
435}
436
437static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
438{
439 struct efx_ef10_nic_data *nic_data = efx->nic_data;
440 struct efx_ef10_vlan *vlan;
441 int rc;
442
443 mutex_lock(&nic_data->vlan_lock);
444
445 vlan = efx_ef10_find_vlan(efx, vid);
446 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100447 /* We add VID 0 on init. 8021q adds it on module init
448 * for all interfaces with VLAN filtring feature.
449 */
450 if (vid == 0)
451 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100452 netif_warn(efx, drv, efx->net_dev,
453 "VLAN %u already added\n", vid);
454 rc = -EALREADY;
455 goto fail_exist;
456 }
457
458 rc = -ENOMEM;
459 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
460 if (!vlan)
461 goto fail_alloc;
462
463 vlan->vid = vid;
464
465 list_add_tail(&vlan->list, &nic_data->vlan_list);
466
467 if (efx->filter_state) {
468 mutex_lock(&efx->mac_lock);
469 down_write(&efx->filter_sem);
470 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
471 up_write(&efx->filter_sem);
472 mutex_unlock(&efx->mac_lock);
473 if (rc)
474 goto fail_filter_add_vlan;
475 }
476
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100477done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100478 mutex_unlock(&nic_data->vlan_lock);
479 return 0;
480
481fail_filter_add_vlan:
482 list_del(&vlan->list);
483 kfree(vlan);
484fail_alloc:
485fail_exist:
486 mutex_unlock(&nic_data->vlan_lock);
487 return rc;
488}
489
490static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
491 struct efx_ef10_vlan *vlan)
492{
493 struct efx_ef10_nic_data *nic_data = efx->nic_data;
494
495 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
496
497 if (efx->filter_state) {
498 down_write(&efx->filter_sem);
499 efx_ef10_filter_del_vlan(efx, vlan->vid);
500 up_write(&efx->filter_sem);
501 }
502
503 list_del(&vlan->list);
504 kfree(vlan);
505}
506
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100507static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
508{
509 struct efx_ef10_nic_data *nic_data = efx->nic_data;
510 struct efx_ef10_vlan *vlan;
511 int rc = 0;
512
513 /* 8021q removes VID 0 on module unload for all interfaces
514 * with VLAN filtering feature. We need to keep it to receive
515 * untagged traffic.
516 */
517 if (vid == 0)
518 return 0;
519
520 mutex_lock(&nic_data->vlan_lock);
521
522 vlan = efx_ef10_find_vlan(efx, vid);
523 if (!vlan) {
524 netif_err(efx, drv, efx->net_dev,
525 "VLAN %u to be deleted not found\n", vid);
526 rc = -ENOENT;
527 } else {
528 efx_ef10_del_vlan_internal(efx, vlan);
529 }
530
531 mutex_unlock(&nic_data->vlan_lock);
532
533 return rc;
534}
535
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100536static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
537{
538 struct efx_ef10_nic_data *nic_data = efx->nic_data;
539 struct efx_ef10_vlan *vlan, *next_vlan;
540
541 mutex_lock(&nic_data->vlan_lock);
542 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
543 efx_ef10_del_vlan_internal(efx, vlan);
544 mutex_unlock(&nic_data->vlan_lock);
545}
546
Shradha Shah0f5c0842015-06-02 11:37:58 +0100547static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
548 NULL);
549static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
550
Ben Hutchings8127d662013-08-29 19:19:29 +0100551static int efx_ef10_probe(struct efx_nic *efx)
552{
553 struct efx_ef10_nic_data *nic_data;
554 int i, rc;
555
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000556 /* We can have one VI for each 8K region. However, until we
557 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100558 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100559 efx->max_channels = min_t(unsigned int,
560 EFX_MAX_CHANNELS,
561 efx_ef10_mem_map_size(efx) /
562 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
563 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000564 if (WARN_ON(efx->max_channels == 0))
565 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100566
567 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
568 if (!nic_data)
569 return -ENOMEM;
570 efx->nic_data = nic_data;
571
Edward Cree75aba2a2015-05-27 13:13:54 +0100572 /* we assume later that we can copy from this buffer in dwords */
573 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
574
Ben Hutchings8127d662013-08-29 19:19:29 +0100575 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
576 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
577 if (rc)
578 goto fail1;
579
580 /* Get the MC's warm boot count. In case it's rebooting right
581 * now, be prepared to retry.
582 */
583 i = 0;
584 for (;;) {
585 rc = efx_ef10_get_warm_boot_count(efx);
586 if (rc >= 0)
587 break;
588 if (++i == 5)
589 goto fail2;
590 ssleep(1);
591 }
592 nic_data->warm_boot_count = rc;
593
594 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
595
Daniel Pieczko45b24492015-05-06 00:57:14 +0100596 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
597
Ben Hutchings8127d662013-08-29 19:19:29 +0100598 /* In case we're recovering from a crash (kexec), we want to
599 * cancel any outstanding request by the previous user of this
600 * function. We send a special message using the least
601 * significant bits of the 'high' (doorbell) register.
602 */
603 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
604
605 rc = efx_mcdi_init(efx);
606 if (rc)
607 goto fail2;
608
609 /* Reset (most) configuration for this function */
610 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
611 if (rc)
612 goto fail3;
613
614 /* Enable event logging */
615 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
616 if (rc)
617 goto fail3;
618
Shradha Shah0f5c0842015-06-02 11:37:58 +0100619 rc = device_create_file(&efx->pci_dev->dev,
620 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100621 if (rc)
622 goto fail3;
623
Shradha Shah0f5c0842015-06-02 11:37:58 +0100624 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
625 if (rc)
626 goto fail4;
627
628 rc = efx_ef10_get_pf_index(efx);
629 if (rc)
630 goto fail5;
631
Ben Hutchingse5a25382013-09-05 22:50:59 +0100632 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100633 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100634 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100635
636 efx->rx_packet_len_offset =
637 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
638
Ben Hutchings8127d662013-08-29 19:19:29 +0100639 rc = efx_mcdi_port_get_number(efx);
640 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100641 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100642 efx->port_num = rc;
643
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100644 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100645 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100646 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100647
Bert Kenwardd95e3292016-08-11 13:02:36 +0100648 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100649 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100650 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100651
Ben Hutchings8127d662013-08-29 19:19:29 +0100652 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100653 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100654 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100655
Ben Hutchings9aecda92013-12-05 21:28:42 +0000656 efx_ptp_probe(efx, NULL);
657
Shradha Shah1d051e02015-06-02 11:38:16 +0100658#ifdef CONFIG_SFC_SRIOV
659 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
660 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
661 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
662
663 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
664 } else
665#endif
666 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
667
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100668 INIT_LIST_HEAD(&nic_data->vlan_list);
669 mutex_init(&nic_data->vlan_lock);
670
671 /* Add unspecified VID to support VLAN filtering being disabled */
672 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
673 if (rc)
674 goto fail_add_vid_unspec;
675
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100676 /* If VLAN filtering is enabled, we need VID 0 to get untagged
677 * traffic. It is added automatically if 8021q module is loaded,
678 * but we can't rely on it since module may be not loaded.
679 */
680 rc = efx_ef10_add_vlan(efx, 0);
681 if (rc)
682 goto fail_add_vid_0;
683
Ben Hutchings8127d662013-08-29 19:19:29 +0100684 return 0;
685
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100686fail_add_vid_0:
687 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100688fail_add_vid_unspec:
689 mutex_destroy(&nic_data->vlan_lock);
690 efx_ptp_remove(efx);
691 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100692fail5:
693 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
694fail4:
695 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100696fail3:
697 efx_mcdi_fini(efx);
698fail2:
699 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
700fail1:
701 kfree(nic_data);
702 efx->nic_data = NULL;
703 return rc;
704}
705
706static int efx_ef10_free_vis(struct efx_nic *efx)
707{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100708 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100709 size_t outlen;
710 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
711 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100712
713 /* -EALREADY means nothing to free, so ignore */
714 if (rc == -EALREADY)
715 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100716 if (rc)
717 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
718 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100719 return rc;
720}
721
Ben Hutchings183233b2013-06-28 21:47:12 +0100722#ifdef EFX_USE_PIO
723
724static void efx_ef10_free_piobufs(struct efx_nic *efx)
725{
726 struct efx_ef10_nic_data *nic_data = efx->nic_data;
727 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
728 unsigned int i;
729 int rc;
730
731 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
732
733 for (i = 0; i < nic_data->n_piobufs; i++) {
734 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
735 nic_data->piobuf_handle[i]);
736 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
737 NULL, 0, NULL);
738 WARN_ON(rc);
739 }
740
741 nic_data->n_piobufs = 0;
742}
743
744static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
745{
746 struct efx_ef10_nic_data *nic_data = efx->nic_data;
747 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
748 unsigned int i;
749 size_t outlen;
750 int rc = 0;
751
752 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
753
754 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000755 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
756 outbuf, sizeof(outbuf), &outlen);
757 if (rc) {
758 /* Don't display the MC error if we didn't have space
759 * for a VF.
760 */
761 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
762 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
763 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100764 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000765 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100766 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
767 rc = -EIO;
768 break;
769 }
770 nic_data->piobuf_handle[i] =
771 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
772 netif_dbg(efx, probe, efx->net_dev,
773 "allocated PIO buffer %u handle %x\n", i,
774 nic_data->piobuf_handle[i]);
775 }
776
777 nic_data->n_piobufs = i;
778 if (rc)
779 efx_ef10_free_piobufs(efx);
780 return rc;
781}
782
783static int efx_ef10_link_piobufs(struct efx_nic *efx)
784{
785 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100786 _MCDI_DECLARE_BUF(inbuf,
787 max(MC_CMD_LINK_PIOBUF_IN_LEN,
788 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100789 struct efx_channel *channel;
790 struct efx_tx_queue *tx_queue;
791 unsigned int offset, index;
792 int rc;
793
794 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
795 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
796
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100797 memset(inbuf, 0, sizeof(inbuf));
798
Ben Hutchings183233b2013-06-28 21:47:12 +0100799 /* Link a buffer to each VI in the write-combining mapping */
800 for (index = 0; index < nic_data->n_piobufs; ++index) {
801 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
802 nic_data->piobuf_handle[index]);
803 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
804 nic_data->pio_write_vi_base + index);
805 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
806 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
807 NULL, 0, NULL);
808 if (rc) {
809 netif_err(efx, drv, efx->net_dev,
810 "failed to link VI %u to PIO buffer %u (%d)\n",
811 nic_data->pio_write_vi_base + index, index,
812 rc);
813 goto fail;
814 }
815 netif_dbg(efx, probe, efx->net_dev,
816 "linked VI %u to PIO buffer %u\n",
817 nic_data->pio_write_vi_base + index, index);
818 }
819
820 /* Link a buffer to each TX queue */
821 efx_for_each_channel(channel, efx) {
822 efx_for_each_channel_tx_queue(tx_queue, channel) {
823 /* We assign the PIO buffers to queues in
824 * reverse order to allow for the following
825 * special case.
826 */
827 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
828 tx_queue->channel->channel - 1) *
829 efx_piobuf_size);
Edward Creec6347002017-01-13 21:20:29 +0000830 index = offset / nic_data->piobuf_size;
831 offset = offset % nic_data->piobuf_size;
Ben Hutchings183233b2013-06-28 21:47:12 +0100832
833 /* When the host page size is 4K, the first
834 * host page in the WC mapping may be within
835 * the same VI page as the last TX queue. We
836 * can only link one buffer to each VI.
837 */
838 if (tx_queue->queue == nic_data->pio_write_vi_base) {
839 BUG_ON(index != 0);
840 rc = 0;
841 } else {
842 MCDI_SET_DWORD(inbuf,
843 LINK_PIOBUF_IN_PIOBUF_HANDLE,
844 nic_data->piobuf_handle[index]);
845 MCDI_SET_DWORD(inbuf,
846 LINK_PIOBUF_IN_TXQ_INSTANCE,
847 tx_queue->queue);
848 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
849 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
850 NULL, 0, NULL);
851 }
852
853 if (rc) {
854 /* This is non-fatal; the TX path just
855 * won't use PIO for this queue
856 */
857 netif_err(efx, drv, efx->net_dev,
858 "failed to link VI %u to PIO buffer %u (%d)\n",
859 tx_queue->queue, index, rc);
860 tx_queue->piobuf = NULL;
861 } else {
862 tx_queue->piobuf =
863 nic_data->pio_write_base +
864 index * EFX_VI_PAGE_SIZE + offset;
865 tx_queue->piobuf_offset = offset;
866 netif_dbg(efx, probe, efx->net_dev,
867 "linked VI %u to PIO buffer %u offset %x addr %p\n",
868 tx_queue->queue, index,
869 tx_queue->piobuf_offset,
870 tx_queue->piobuf);
871 }
872 }
873 }
874
875 return 0;
876
877fail:
878 while (index--) {
879 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
880 nic_data->pio_write_vi_base + index);
881 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
882 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
883 NULL, 0, NULL);
884 }
885 return rc;
886}
887
Edward Creec0795bf2016-05-24 18:53:36 +0100888static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
889{
890 struct efx_channel *channel;
891 struct efx_tx_queue *tx_queue;
892
893 /* All our existing PIO buffers went away */
894 efx_for_each_channel(channel, efx)
895 efx_for_each_channel_tx_queue(tx_queue, channel)
896 tx_queue->piobuf = NULL;
897}
898
Ben Hutchings183233b2013-06-28 21:47:12 +0100899#else /* !EFX_USE_PIO */
900
901static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
902{
903 return n == 0 ? 0 : -ENOBUFS;
904}
905
906static int efx_ef10_link_piobufs(struct efx_nic *efx)
907{
908 return 0;
909}
910
911static void efx_ef10_free_piobufs(struct efx_nic *efx)
912{
913}
914
Edward Creec0795bf2016-05-24 18:53:36 +0100915static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
916{
917}
918
Ben Hutchings183233b2013-06-28 21:47:12 +0100919#endif /* EFX_USE_PIO */
920
Ben Hutchings8127d662013-08-29 19:19:29 +0100921static void efx_ef10_remove(struct efx_nic *efx)
922{
923 struct efx_ef10_nic_data *nic_data = efx->nic_data;
924 int rc;
925
Shradha Shahf1122a32015-05-20 11:09:46 +0100926#ifdef CONFIG_SFC_SRIOV
927 struct efx_ef10_nic_data *nic_data_pf;
928 struct pci_dev *pci_dev_pf;
929 struct efx_nic *efx_pf;
930 struct ef10_vf *vf;
931
932 if (efx->pci_dev->is_virtfn) {
933 pci_dev_pf = efx->pci_dev->physfn;
934 if (pci_dev_pf) {
935 efx_pf = pci_get_drvdata(pci_dev_pf);
936 nic_data_pf = efx_pf->nic_data;
937 vf = nic_data_pf->vf + nic_data->vf_index;
938 vf->efx = NULL;
939 } else
940 netif_info(efx, drv, efx->net_dev,
941 "Could not get the PF id from VF\n");
942 }
943#endif
944
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100945 efx_ef10_cleanup_vlans(efx);
946 mutex_destroy(&nic_data->vlan_lock);
947
Ben Hutchings9aecda92013-12-05 21:28:42 +0000948 efx_ptp_remove(efx);
949
Ben Hutchings8127d662013-08-29 19:19:29 +0100950 efx_mcdi_mon_remove(efx);
951
Ben Hutchings8127d662013-08-29 19:19:29 +0100952 efx_ef10_rx_free_indir_table(efx);
953
Ben Hutchings183233b2013-06-28 21:47:12 +0100954 if (nic_data->wc_membase)
955 iounmap(nic_data->wc_membase);
956
Ben Hutchings8127d662013-08-29 19:19:29 +0100957 rc = efx_ef10_free_vis(efx);
958 WARN_ON(rc != 0);
959
Ben Hutchings183233b2013-06-28 21:47:12 +0100960 if (!nic_data->must_restore_piobufs)
961 efx_ef10_free_piobufs(efx);
962
Shradha Shah0f5c0842015-06-02 11:37:58 +0100963 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
964 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
965
Ben Hutchings8127d662013-08-29 19:19:29 +0100966 efx_mcdi_fini(efx);
967 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
968 kfree(nic_data);
969}
970
Shradha Shah88a37de2015-05-20 11:09:15 +0100971static int efx_ef10_probe_pf(struct efx_nic *efx)
972{
973 return efx_ef10_probe(efx);
974}
975
Andrew Rybchenko38d27f32016-06-15 17:52:08 +0100976int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
977 u32 *port_flags, u32 *vadaptor_flags,
978 unsigned int *vlan_tags)
979{
980 struct efx_ef10_nic_data *nic_data = efx->nic_data;
981 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
982 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
983 size_t outlen;
984 int rc;
985
986 if (nic_data->datapath_caps &
987 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
988 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
989 port_id);
990
991 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
992 outbuf, sizeof(outbuf), &outlen);
993 if (rc)
994 return rc;
995
996 if (outlen < sizeof(outbuf)) {
997 rc = -EIO;
998 return rc;
999 }
1000 }
1001
1002 if (port_flags)
1003 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1004 if (vadaptor_flags)
1005 *vadaptor_flags =
1006 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1007 if (vlan_tags)
1008 *vlan_tags =
1009 MCDI_DWORD(outbuf,
1010 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1011
1012 return 0;
1013}
1014
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001015int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1016{
1017 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1018
1019 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1020 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1021 NULL, 0, NULL);
1022}
1023
1024int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1025{
1026 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1027
1028 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1029 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1030 NULL, 0, NULL);
1031}
1032
1033int efx_ef10_vport_add_mac(struct efx_nic *efx,
1034 unsigned int port_id, u8 *mac)
1035{
1036 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1037
1038 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1039 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1040
1041 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1042 sizeof(inbuf), NULL, 0, NULL);
1043}
1044
1045int efx_ef10_vport_del_mac(struct efx_nic *efx,
1046 unsigned int port_id, u8 *mac)
1047{
1048 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1049
1050 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1051 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1052
1053 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1054 sizeof(inbuf), NULL, 0, NULL);
1055}
1056
Shradha Shah88a37de2015-05-20 11:09:15 +01001057#ifdef CONFIG_SFC_SRIOV
1058static int efx_ef10_probe_vf(struct efx_nic *efx)
1059{
1060 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001061 struct pci_dev *pci_dev_pf;
1062
1063 /* If the parent PF has no VF data structure, it doesn't know about this
1064 * VF so fail probe. The VF needs to be re-created. This can happen
1065 * if the PF driver is unloaded while the VF is assigned to a guest.
1066 */
1067 pci_dev_pf = efx->pci_dev->physfn;
1068 if (pci_dev_pf) {
1069 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1070 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1071
1072 if (!nic_data_pf->vf) {
1073 netif_info(efx, drv, efx->net_dev,
1074 "The VF cannot link to its parent PF; "
1075 "please destroy and re-create the VF\n");
1076 return -EBUSY;
1077 }
1078 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001079
1080 rc = efx_ef10_probe(efx);
1081 if (rc)
1082 return rc;
1083
1084 rc = efx_ef10_get_vf_index(efx);
1085 if (rc)
1086 goto fail;
1087
Shradha Shahf1122a32015-05-20 11:09:46 +01001088 if (efx->pci_dev->is_virtfn) {
1089 if (efx->pci_dev->physfn) {
1090 struct efx_nic *efx_pf =
1091 pci_get_drvdata(efx->pci_dev->physfn);
1092 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1093 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1094
1095 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001096 nic_data_p->vf[nic_data->vf_index].pci_dev =
1097 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001098 } else
1099 netif_info(efx, drv, efx->net_dev,
1100 "Could not get the PF id from VF\n");
1101 }
1102
Shradha Shah88a37de2015-05-20 11:09:15 +01001103 return 0;
1104
1105fail:
1106 efx_ef10_remove(efx);
1107 return rc;
1108}
1109#else
1110static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1111{
1112 return 0;
1113}
1114#endif
1115
Ben Hutchings8127d662013-08-29 19:19:29 +01001116static int efx_ef10_alloc_vis(struct efx_nic *efx,
1117 unsigned int min_vis, unsigned int max_vis)
1118{
1119 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1120 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1121 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1122 size_t outlen;
1123 int rc;
1124
1125 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1126 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1127 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1128 outbuf, sizeof(outbuf), &outlen);
1129 if (rc != 0)
1130 return rc;
1131
1132 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1133 return -EIO;
1134
1135 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1136 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1137
1138 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1139 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1140 return 0;
1141}
1142
Ben Hutchings183233b2013-06-28 21:47:12 +01001143/* Note that the failure path of this function does not free
1144 * resources, as this will be done by efx_ef10_remove().
1145 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001146static int efx_ef10_dimension_resources(struct efx_nic *efx)
1147{
Ben Hutchings183233b2013-06-28 21:47:12 +01001148 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1149 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001150 unsigned int min_vis = max(EFX_TXQ_TYPES,
1151 efx_separate_tx_channels ? 2 : 1);
1152 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001153 void __iomem *membase;
1154 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001155
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001156 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001157
1158#ifdef EFX_USE_PIO
1159 /* Try to allocate PIO buffers if wanted and if the full
1160 * number of PIO buffers would be sufficient to allocate one
1161 * copy-buffer per TX channel. Failure is non-fatal, as there
1162 * are only a small number of PIO buffers shared between all
1163 * functions of the controller.
1164 */
1165 if (efx_piobuf_size != 0 &&
Edward Creec6347002017-01-13 21:20:29 +00001166 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
Ben Hutchings183233b2013-06-28 21:47:12 +01001167 efx->n_tx_channels) {
1168 unsigned int n_piobufs =
1169 DIV_ROUND_UP(efx->n_tx_channels,
Edward Creec6347002017-01-13 21:20:29 +00001170 nic_data->piobuf_size / efx_piobuf_size);
Ben Hutchings183233b2013-06-28 21:47:12 +01001171
1172 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001173 if (rc == -ENOSPC)
1174 netif_dbg(efx, probe, efx->net_dev,
1175 "out of PIO buffers; cannot allocate more\n");
1176 else if (rc == -EPERM)
1177 netif_dbg(efx, probe, efx->net_dev,
1178 "not permitted to allocate PIO buffers\n");
1179 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001180 netif_err(efx, probe, efx->net_dev,
1181 "failed to allocate PIO buffers (%d)\n", rc);
1182 else
1183 netif_dbg(efx, probe, efx->net_dev,
1184 "allocated %u PIO buffers\n", n_piobufs);
1185 }
1186#else
1187 nic_data->n_piobufs = 0;
1188#endif
1189
1190 /* PIO buffers should be mapped with write-combining enabled,
1191 * and we want to make single UC and WC mappings rather than
1192 * several of each (in fact that's the only option if host
1193 * page size is >4K). So we may allocate some extra VIs just
1194 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001195 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001196 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001197 * first half of the next VI. Then the WC mapping begins with
1198 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001199 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001200 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001201 ER_DZ_TX_PIOBUF);
1202 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001203 /* pio_write_vi_base rounds down to give the number of complete
1204 * VIs inside the UC mapping.
1205 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001206 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1207 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1208 nic_data->n_piobufs) *
1209 EFX_VI_PAGE_SIZE) -
1210 uc_mem_map_size);
1211 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1212 } else {
1213 pio_write_vi_base = 0;
1214 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001215 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001216 }
1217
1218 /* In case the last attached driver failed to free VIs, do it now */
1219 rc = efx_ef10_free_vis(efx);
1220 if (rc != 0)
1221 return rc;
1222
1223 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1224 if (rc != 0)
1225 return rc;
1226
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001227 if (nic_data->n_allocated_vis < channel_vis) {
1228 netif_info(efx, drv, efx->net_dev,
1229 "Could not allocate enough VIs to satisfy RSS"
1230 " requirements. Performance may not be optimal.\n");
1231 /* We didn't get the VIs to populate our channels.
1232 * We could keep what we got but then we'd have more
1233 * interrupts than we need.
1234 * Instead calculate new max_channels and restart
1235 */
1236 efx->max_channels = nic_data->n_allocated_vis;
1237 efx->max_tx_channels =
1238 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1239
1240 efx_ef10_free_vis(efx);
1241 return -EAGAIN;
1242 }
1243
Ben Hutchings183233b2013-06-28 21:47:12 +01001244 /* If we didn't get enough VIs to map all the PIO buffers, free the
1245 * PIO buffers
1246 */
1247 if (nic_data->n_piobufs &&
1248 nic_data->n_allocated_vis <
1249 pio_write_vi_base + nic_data->n_piobufs) {
1250 netif_dbg(efx, probe, efx->net_dev,
1251 "%u VIs are not sufficient to map %u PIO buffers\n",
1252 nic_data->n_allocated_vis, nic_data->n_piobufs);
1253 efx_ef10_free_piobufs(efx);
1254 }
1255
1256 /* Shrink the original UC mapping of the memory BAR */
1257 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1258 if (!membase) {
1259 netif_err(efx, probe, efx->net_dev,
1260 "could not shrink memory BAR to %x\n",
1261 uc_mem_map_size);
1262 return -ENOMEM;
1263 }
1264 iounmap(efx->membase);
1265 efx->membase = membase;
1266
1267 /* Set up the WC mapping if needed */
1268 if (wc_mem_map_size) {
1269 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1270 uc_mem_map_size,
1271 wc_mem_map_size);
1272 if (!nic_data->wc_membase) {
1273 netif_err(efx, probe, efx->net_dev,
1274 "could not allocate WC mapping of size %x\n",
1275 wc_mem_map_size);
1276 return -ENOMEM;
1277 }
1278 nic_data->pio_write_vi_base = pio_write_vi_base;
1279 nic_data->pio_write_base =
1280 nic_data->wc_membase +
1281 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1282 uc_mem_map_size);
1283
1284 rc = efx_ef10_link_piobufs(efx);
1285 if (rc)
1286 efx_ef10_free_piobufs(efx);
1287 }
1288
1289 netif_dbg(efx, probe, efx->net_dev,
1290 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1291 &efx->membase_phys, efx->membase, uc_mem_map_size,
1292 nic_data->wc_membase, wc_mem_map_size);
1293
1294 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001295}
1296
1297static int efx_ef10_init_nic(struct efx_nic *efx)
1298{
1299 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1300 int rc;
1301
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001302 if (nic_data->must_check_datapath_caps) {
1303 rc = efx_ef10_init_datapath_caps(efx);
1304 if (rc)
1305 return rc;
1306 nic_data->must_check_datapath_caps = false;
1307 }
1308
Ben Hutchings8127d662013-08-29 19:19:29 +01001309 if (nic_data->must_realloc_vis) {
1310 /* We cannot let the number of VIs change now */
1311 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1312 nic_data->n_allocated_vis);
1313 if (rc)
1314 return rc;
1315 nic_data->must_realloc_vis = false;
1316 }
1317
Ben Hutchings183233b2013-06-28 21:47:12 +01001318 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1319 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1320 if (rc == 0) {
1321 rc = efx_ef10_link_piobufs(efx);
1322 if (rc)
1323 efx_ef10_free_piobufs(efx);
1324 }
1325
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001326 /* Log an error on failure, but this is non-fatal.
1327 * Permission errors are less important - we've presumably
1328 * had the PIO buffer licence removed.
1329 */
1330 if (rc == -EPERM)
1331 netif_dbg(efx, drv, efx->net_dev,
1332 "not permitted to restore PIO buffers\n");
1333 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001334 netif_err(efx, drv, efx->net_dev,
1335 "failed to restore PIO buffers (%d)\n", rc);
1336 nic_data->must_restore_piobufs = false;
1337 }
1338
Jon Cooper267c0152015-05-06 00:59:38 +01001339 /* don't fail init if RSS setup doesn't work */
Edward Creef74d1992017-01-17 12:01:53 +00001340 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
Edward Cree4fdda952017-01-04 15:10:56 +00001341 efx->rss_active = (rc == 0);
Jon Cooper267c0152015-05-06 00:59:38 +01001342
Ben Hutchings8127d662013-08-29 19:19:29 +01001343 return 0;
1344}
1345
Jon Cooper3e336262014-01-17 19:48:06 +00001346static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1347{
1348 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001349#ifdef CONFIG_SFC_SRIOV
1350 unsigned int i;
1351#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001352
1353 /* All our allocations have been reset */
1354 nic_data->must_realloc_vis = true;
1355 nic_data->must_restore_filters = true;
1356 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001357 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001358 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001359
1360 /* Driver-created vswitches and vports must be re-created */
1361 nic_data->must_probe_vswitching = true;
1362 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1363#ifdef CONFIG_SFC_SRIOV
1364 if (nic_data->vf)
1365 for (i = 0; i < efx->vf_count; i++)
1366 nic_data->vf[i].vport_id = 0;
1367#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001368}
1369
Jon Cooper087e9022015-05-20 11:11:35 +01001370static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1371{
1372 if (reason == RESET_TYPE_MC_FAILURE)
1373 return RESET_TYPE_DATAPATH;
1374
1375 return efx_mcdi_map_reset_reason(reason);
1376}
1377
Ben Hutchings8127d662013-08-29 19:19:29 +01001378static int efx_ef10_map_reset_flags(u32 *flags)
1379{
1380 enum {
1381 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1382 ETH_RESET_SHARED_SHIFT),
1383 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1384 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1385 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1386 ETH_RESET_SHARED_SHIFT)
1387 };
1388
1389 /* We assume for now that our PCI function is permitted to
1390 * reset everything.
1391 */
1392
1393 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1394 *flags &= ~EF10_RESET_MC;
1395 return RESET_TYPE_WORLD;
1396 }
1397
1398 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1399 *flags &= ~EF10_RESET_PORT;
1400 return RESET_TYPE_ALL;
1401 }
1402
1403 /* no invisible reset implemented */
1404
1405 return -EINVAL;
1406}
1407
Jon Cooper3e336262014-01-17 19:48:06 +00001408static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1409{
1410 int rc = efx_mcdi_reset(efx, reset_type);
1411
Daniel Pieczko27324822015-07-31 11:14:54 +01001412 /* Unprivileged functions return -EPERM, but need to return success
1413 * here so that the datapath is brought back up.
1414 */
1415 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1416 rc = 0;
1417
Jon Cooper3e336262014-01-17 19:48:06 +00001418 /* If it was a port reset, trigger reallocation of MC resources.
1419 * Note that on an MC reset nothing needs to be done now because we'll
1420 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001421 * For an FLR, we never get an MC reset event, but the MC has reset all
1422 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001423 */
Edward Creee2835462014-04-16 19:27:48 +01001424 if ((reset_type == RESET_TYPE_ALL ||
1425 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001426 efx_ef10_reset_mc_allocations(efx);
1427 return rc;
1428}
1429
Ben Hutchings8127d662013-08-29 19:19:29 +01001430#define EF10_DMA_STAT(ext_name, mcdi_name) \
1431 [EF10_STAT_ ## ext_name] = \
1432 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1433#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1434 [EF10_STAT_ ## int_name] = \
1435 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1436#define EF10_OTHER_STAT(ext_name) \
1437 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001438#define GENERIC_SW_STAT(ext_name) \
1439 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001440
1441static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001442 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1443 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1444 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1445 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1446 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1447 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1448 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1449 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1450 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1451 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1452 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1453 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1454 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1455 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1456 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1457 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1458 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1459 EF10_OTHER_STAT(port_rx_good_bytes),
1460 EF10_OTHER_STAT(port_rx_bad_bytes),
1461 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1462 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1463 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1464 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1465 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1466 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1467 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1468 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1469 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1470 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1471 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1472 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1473 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1474 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1475 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1476 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1477 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1478 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1479 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1480 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1481 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1482 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001483 GENERIC_SW_STAT(rx_nodesc_trunc),
1484 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001485 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1486 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1487 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1488 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1489 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1490 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1491 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1492 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1493 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1494 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1495 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1496 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001497 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1498 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1499 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1500 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1501 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1502 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1503 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1504 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1505 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1506 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1507 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1508 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1509 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1510 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1511 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1512 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1513 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1514 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001515};
1516
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001517#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1518 (1ULL << EF10_STAT_port_tx_packets) | \
1519 (1ULL << EF10_STAT_port_tx_pause) | \
1520 (1ULL << EF10_STAT_port_tx_unicast) | \
1521 (1ULL << EF10_STAT_port_tx_multicast) | \
1522 (1ULL << EF10_STAT_port_tx_broadcast) | \
1523 (1ULL << EF10_STAT_port_rx_bytes) | \
1524 (1ULL << \
1525 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1526 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1527 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1528 (1ULL << EF10_STAT_port_rx_packets) | \
1529 (1ULL << EF10_STAT_port_rx_good) | \
1530 (1ULL << EF10_STAT_port_rx_bad) | \
1531 (1ULL << EF10_STAT_port_rx_pause) | \
1532 (1ULL << EF10_STAT_port_rx_control) | \
1533 (1ULL << EF10_STAT_port_rx_unicast) | \
1534 (1ULL << EF10_STAT_port_rx_multicast) | \
1535 (1ULL << EF10_STAT_port_rx_broadcast) | \
1536 (1ULL << EF10_STAT_port_rx_lt64) | \
1537 (1ULL << EF10_STAT_port_rx_64) | \
1538 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1539 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1540 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1541 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1542 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1543 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1544 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1545 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1546 (1ULL << EF10_STAT_port_rx_overflow) | \
1547 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001548 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1549 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001550
Edward Cree69b365c2016-08-26 15:12:41 +01001551/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1552 * For a 10G/40G switchable port we do not expose these because they might
1553 * not include all the packets they should.
1554 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001555 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001556#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1557 (1ULL << EF10_STAT_port_tx_lt64) | \
1558 (1ULL << EF10_STAT_port_tx_64) | \
1559 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1560 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1561 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1562 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1563 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1564 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001565
1566/* These statistics are only provided by the 40G MAC. For a 10G/40G
1567 * switchable port we do expose these because the errors will otherwise
1568 * be silent.
1569 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001570#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1571 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001572
Edward Cree568d7a02013-09-25 17:32:09 +01001573/* These statistics are only provided if the firmware supports the
1574 * capability PM_AND_RXDP_COUNTERS.
1575 */
1576#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001577 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1578 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1579 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1580 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1581 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1582 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1583 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1584 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1585 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1586 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1587 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1588 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001589
Edward Cree4bae9132013-09-27 18:52:49 +01001590static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001591{
Edward Cree4bae9132013-09-27 18:52:49 +01001592 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001593 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001594 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001595
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001596 if (!(efx->mcdi->fn_flags &
1597 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1598 return 0;
1599
Edward Cree69b365c2016-08-26 15:12:41 +01001600 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001601 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001602 /* 8000 series have everything even at 40G */
1603 if (nic_data->datapath_caps2 &
1604 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1605 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1606 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001607 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001608 }
Edward Cree568d7a02013-09-25 17:32:09 +01001609
1610 if (nic_data->datapath_caps &
1611 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1612 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1613
Edward Cree4bae9132013-09-27 18:52:49 +01001614 return raw_mask;
1615}
1616
1617static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1618{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001619 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001620 u64 raw_mask[2];
1621
1622 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1623
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001624 /* Only show vadaptor stats when EVB capability is present */
1625 if (nic_data->datapath_caps &
1626 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1627 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1628 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1629 } else {
1630 raw_mask[1] = 0;
1631 }
Edward Cree4bae9132013-09-27 18:52:49 +01001632
1633#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001634 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001635 mask[0] = raw_mask[0];
1636 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001637#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001638 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001639 mask[0] = raw_mask[0] & 0xffffffff;
1640 mask[1] = raw_mask[0] >> 32;
1641 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001642#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001643}
1644
1645static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1646{
Edward Cree4bae9132013-09-27 18:52:49 +01001647 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1648
1649 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001650 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001651 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001652}
1653
Daniel Pieczkod7788192015-06-02 11:39:20 +01001654static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1655 struct rtnl_link_stats64 *core_stats)
1656{
1657 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1658 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1659 u64 *stats = nic_data->stats;
1660 size_t stats_count = 0, index;
1661
1662 efx_ef10_get_stat_mask(efx, mask);
1663
1664 if (full_stats) {
1665 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1666 if (efx_ef10_stat_desc[index].name) {
1667 *full_stats++ = stats[index];
1668 ++stats_count;
1669 }
1670 }
1671 }
1672
Bert Kenwardfbe43072015-08-26 16:39:03 +01001673 if (!core_stats)
1674 return stats_count;
1675
1676 if (nic_data->datapath_caps &
1677 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1678 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001679 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1680 stats[EF10_STAT_rx_multicast] +
1681 stats[EF10_STAT_rx_broadcast];
1682 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1683 stats[EF10_STAT_tx_multicast] +
1684 stats[EF10_STAT_tx_broadcast];
1685 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1686 stats[EF10_STAT_rx_multicast_bytes] +
1687 stats[EF10_STAT_rx_broadcast_bytes];
1688 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1689 stats[EF10_STAT_tx_multicast_bytes] +
1690 stats[EF10_STAT_tx_broadcast_bytes];
1691 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001692 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001693 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1694 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1695 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1696 core_stats->rx_errors = core_stats->rx_crc_errors;
1697 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001698 } else {
1699 /* Use port stats. */
1700 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1701 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1702 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1703 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1704 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1705 stats[GENERIC_STAT_rx_nodesc_trunc] +
1706 stats[GENERIC_STAT_rx_noskb_drops];
1707 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1708 core_stats->rx_length_errors =
1709 stats[EF10_STAT_port_rx_gtjumbo] +
1710 stats[EF10_STAT_port_rx_length_error];
1711 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1712 core_stats->rx_frame_errors =
1713 stats[EF10_STAT_port_rx_align_error];
1714 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1715 core_stats->rx_errors = (core_stats->rx_length_errors +
1716 core_stats->rx_crc_errors +
1717 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001718 }
1719
1720 return stats_count;
1721}
1722
1723static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001724{
1725 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001726 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001727 __le64 generation_start, generation_end;
1728 u64 *stats = nic_data->stats;
1729 __le64 *dma_stats;
1730
Edward Cree4bae9132013-09-27 18:52:49 +01001731 efx_ef10_get_stat_mask(efx, mask);
1732
Ben Hutchings8127d662013-08-29 19:19:29 +01001733 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001734
1735 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1736 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1737 return 0;
1738 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001739 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001740 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001741 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001742 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1743 if (generation_end != generation_start)
1744 return -EAGAIN;
1745
1746 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001747 efx_nic_fix_nodesc_drop_stat(efx,
1748 &stats[EF10_STAT_port_rx_nodesc_drops]);
1749 stats[EF10_STAT_port_rx_good_bytes] =
1750 stats[EF10_STAT_port_rx_bytes] -
1751 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1752 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1753 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001754 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001755 return 0;
1756}
1757
1758
Daniel Pieczkod7788192015-06-02 11:39:20 +01001759static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1760 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001761{
Ben Hutchings8127d662013-08-29 19:19:29 +01001762 int retry;
1763
1764 /* If we're unlucky enough to read statistics during the DMA, wait
1765 * up to 10ms for it to finish (typically takes <500us)
1766 */
1767 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001768 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001769 break;
1770 udelay(100);
1771 }
1772
Daniel Pieczkod7788192015-06-02 11:39:20 +01001773 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1774}
1775
1776static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1777{
1778 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1779 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1780 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1781 __le64 generation_start, generation_end;
1782 u64 *stats = nic_data->stats;
1783 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1784 struct efx_buffer stats_buf;
1785 __le64 *dma_stats;
1786 int rc;
1787
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001788 spin_unlock_bh(&efx->stats_lock);
1789
1790 if (in_interrupt()) {
1791 /* If in atomic context, cannot update stats. Just update the
1792 * software stats and return so the caller can continue.
1793 */
1794 spin_lock_bh(&efx->stats_lock);
1795 efx_update_sw_stats(efx, stats);
1796 return 0;
1797 }
1798
Daniel Pieczkod7788192015-06-02 11:39:20 +01001799 efx_ef10_get_stat_mask(efx, mask);
1800
1801 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001802 if (rc) {
1803 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001804 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001805 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001806
1807 dma_stats = stats_buf.addr;
1808 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1809
1810 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1811 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001812 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001813 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1814 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1815
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001816 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1817 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001818 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001819 if (rc) {
1820 /* Expect ENOENT if DMA queues have not been set up */
1821 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1822 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1823 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001824 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001825 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001826
1827 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001828 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1829 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001830 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001831 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001832 rmb();
1833 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1834 stats, stats_buf.addr, false);
1835 rmb();
1836 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1837 if (generation_end != generation_start) {
1838 rc = -EAGAIN;
1839 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001840 }
1841
Daniel Pieczkod7788192015-06-02 11:39:20 +01001842 efx_update_sw_stats(efx, stats);
1843out:
1844 efx_nic_free_buffer(efx, &stats_buf);
1845 return rc;
1846}
Ben Hutchings8127d662013-08-29 19:19:29 +01001847
Daniel Pieczkod7788192015-06-02 11:39:20 +01001848static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1849 struct rtnl_link_stats64 *core_stats)
1850{
1851 if (efx_ef10_try_update_nic_stats_vf(efx))
1852 return 0;
1853
1854 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001855}
1856
1857static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1858{
1859 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001860 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001861 efx_dword_t timer_cmd;
1862
Bert Kenward539de7c2016-08-11 13:02:09 +01001863 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001864 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001865 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001866 } else {
1867 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001868 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001869 }
1870
Bert Kenward539de7c2016-08-11 13:02:09 +01001871 if (EFX_EF10_WORKAROUND_61265(efx)) {
1872 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1873 unsigned int ns = usecs * 1000;
1874
1875 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1876 channel->channel);
1877 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1878 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1879 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1880
1881 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1882 inbuf, sizeof(inbuf), 0, NULL, 0);
1883 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1884 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1885
Ben Hutchings8127d662013-08-29 19:19:29 +01001886 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1887 EFE_DD_EVQ_IND_TIMER_FLAGS,
1888 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001889 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001890 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1891 channel->channel);
1892 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001893 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1894
Ben Hutchings8127d662013-08-29 19:19:29 +01001895 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001896 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001897 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1898 channel->channel);
1899 }
1900}
1901
Shradha Shah02246a72015-05-06 00:58:14 +01001902static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1903 struct ethtool_wolinfo *wol) {}
1904
1905static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1906{
1907 return -EOPNOTSUPP;
1908}
1909
Ben Hutchings8127d662013-08-29 19:19:29 +01001910static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1911{
1912 wol->supported = 0;
1913 wol->wolopts = 0;
1914 memset(&wol->sopass, 0, sizeof(wol->sopass));
1915}
1916
1917static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1918{
1919 if (type != 0)
1920 return -EINVAL;
1921 return 0;
1922}
1923
1924static void efx_ef10_mcdi_request(struct efx_nic *efx,
1925 const efx_dword_t *hdr, size_t hdr_len,
1926 const efx_dword_t *sdu, size_t sdu_len)
1927{
1928 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1929 u8 *pdu = nic_data->mcdi_buf.addr;
1930
1931 memcpy(pdu, hdr, hdr_len);
1932 memcpy(pdu + hdr_len, sdu, sdu_len);
1933 wmb();
1934
1935 /* The hardware provides 'low' and 'high' (doorbell) registers
1936 * for passing the 64-bit address of an MCDI request to
1937 * firmware. However the dwords are swapped by firmware. The
1938 * least significant bits of the doorbell are then 0 for all
1939 * MCDI requests due to alignment.
1940 */
1941 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1942 ER_DZ_MC_DB_LWRD);
1943 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1944 ER_DZ_MC_DB_HWRD);
1945}
1946
1947static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1948{
1949 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1950 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1951
1952 rmb();
1953 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1954}
1955
1956static void
1957efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1958 size_t offset, size_t outlen)
1959{
1960 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1961 const u8 *pdu = nic_data->mcdi_buf.addr;
1962
1963 memcpy(outbuf, pdu + offset, outlen);
1964}
1965
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001966static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1967{
1968 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1969
1970 /* All our allocations have been reset */
1971 efx_ef10_reset_mc_allocations(efx);
1972
1973 /* The datapath firmware might have been changed */
1974 nic_data->must_check_datapath_caps = true;
1975
1976 /* MAC statistics have been cleared on the NIC; clear the local
1977 * statistic that we update with efx_update_diff_stat().
1978 */
1979 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1980}
1981
Ben Hutchings8127d662013-08-29 19:19:29 +01001982static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1983{
1984 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1985 int rc;
1986
1987 rc = efx_ef10_get_warm_boot_count(efx);
1988 if (rc < 0) {
1989 /* The firmware is presumably in the process of
1990 * rebooting. However, we are supposed to report each
1991 * reboot just once, so we must only do that once we
1992 * can read and store the updated warm boot count.
1993 */
1994 return 0;
1995 }
1996
1997 if (rc == nic_data->warm_boot_count)
1998 return 0;
1999
2000 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002001 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01002002
Ben Hutchings8127d662013-08-29 19:19:29 +01002003 return -EIO;
2004}
2005
2006/* Handle an MSI interrupt
2007 *
2008 * Handle an MSI hardware interrupt. This routine schedules event
2009 * queue processing. No interrupt acknowledgement cycle is necessary.
2010 * Also, we never need to check that the interrupt is for us, since
2011 * MSI interrupts cannot be shared.
2012 */
2013static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2014{
2015 struct efx_msi_context *context = dev_id;
2016 struct efx_nic *efx = context->efx;
2017
2018 netif_vdbg(efx, intr, efx->net_dev,
2019 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2020
2021 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2022 /* Note test interrupts */
2023 if (context->index == efx->irq_level)
2024 efx->last_irq_cpu = raw_smp_processor_id();
2025
2026 /* Schedule processing of the channel */
2027 efx_schedule_channel_irq(efx->channel[context->index]);
2028 }
2029
2030 return IRQ_HANDLED;
2031}
2032
2033static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2034{
2035 struct efx_nic *efx = dev_id;
2036 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2037 struct efx_channel *channel;
2038 efx_dword_t reg;
2039 u32 queues;
2040
2041 /* Read the ISR which also ACKs the interrupts */
2042 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2043 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2044
2045 if (queues == 0)
2046 return IRQ_NONE;
2047
2048 if (likely(soft_enabled)) {
2049 /* Note test interrupts */
2050 if (queues & (1U << efx->irq_level))
2051 efx->last_irq_cpu = raw_smp_processor_id();
2052
2053 efx_for_each_channel(channel, efx) {
2054 if (queues & 1)
2055 efx_schedule_channel_irq(channel);
2056 queues >>= 1;
2057 }
2058 }
2059
2060 netif_vdbg(efx, intr, efx->net_dev,
2061 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2062 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2063
2064 return IRQ_HANDLED;
2065}
2066
Jon Cooper942e2982016-08-26 15:13:30 +01002067static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002068{
2069 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2070
Jon Cooper942e2982016-08-26 15:13:30 +01002071 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2072 NULL) == 0)
2073 return -ENOTSUPP;
2074
Ben Hutchings8127d662013-08-29 19:19:29 +01002075 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2076
2077 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002078 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002079 inbuf, sizeof(inbuf), NULL, 0, NULL);
2080}
2081
2082static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2083{
2084 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2085 (tx_queue->ptr_mask + 1) *
2086 sizeof(efx_qword_t),
2087 GFP_KERNEL);
2088}
2089
2090/* This writes to the TX_DESC_WPTR and also pushes data */
2091static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2092 const efx_qword_t *txd)
2093{
2094 unsigned int write_ptr;
2095 efx_oword_t reg;
2096
2097 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2098 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2099 reg.qword[0] = *txd;
2100 efx_writeo_page(tx_queue->efx, &reg,
2101 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2102}
2103
Bert Kenwarde9117e52016-11-17 10:51:54 +00002104/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2105 */
2106static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2107 struct sk_buff *skb,
2108 bool *data_mapped)
2109{
2110 struct efx_tx_buffer *buffer;
2111 struct tcphdr *tcp;
2112 struct iphdr *ip;
2113
2114 u16 ipv4_id;
2115 u32 seqnum;
2116 u32 mss;
2117
Edward Creee01b16a2016-12-02 15:51:33 +00002118 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002119
2120 mss = skb_shinfo(skb)->gso_size;
2121
2122 if (unlikely(mss < 4)) {
2123 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2124 return -EINVAL;
2125 }
2126
2127 ip = ip_hdr(skb);
2128 if (ip->version == 4) {
2129 /* Modify IPv4 header if needed. */
2130 ip->tot_len = 0;
2131 ip->check = 0;
2132 ipv4_id = ip->id;
2133 } else {
2134 /* Modify IPv6 header if needed. */
2135 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2136
2137 ipv6->payload_len = 0;
2138 ipv4_id = 0;
2139 }
2140
2141 tcp = tcp_hdr(skb);
2142 seqnum = ntohl(tcp->seq);
2143
2144 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2145
2146 buffer->flags = EFX_TX_BUF_OPTION;
2147 buffer->len = 0;
2148 buffer->unmap_len = 0;
2149 EFX_POPULATE_QWORD_5(buffer->option,
2150 ESF_DZ_TX_DESC_IS_OPT, 1,
2151 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2152 ESF_DZ_TX_TSO_OPTION_TYPE,
2153 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2154 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2155 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2156 );
2157 ++tx_queue->insert_count;
2158
2159 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2160
2161 buffer->flags = EFX_TX_BUF_OPTION;
2162 buffer->len = 0;
2163 buffer->unmap_len = 0;
2164 EFX_POPULATE_QWORD_4(buffer->option,
2165 ESF_DZ_TX_DESC_IS_OPT, 1,
2166 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2167 ESF_DZ_TX_TSO_OPTION_TYPE,
2168 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2169 ESF_DZ_TX_TSO_TCP_MSS, mss
2170 );
2171 ++tx_queue->insert_count;
2172
2173 return 0;
2174}
2175
Edward Cree46d1efd2016-11-17 10:52:36 +00002176static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2177{
2178 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2179 u32 tso_versions = 0;
2180
2181 if (nic_data->datapath_caps &
2182 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2183 tso_versions |= BIT(1);
2184 if (nic_data->datapath_caps2 &
2185 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2186 tso_versions |= BIT(2);
2187 return tso_versions;
2188}
2189
Ben Hutchings8127d662013-08-29 19:19:29 +01002190static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2191{
2192 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2193 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002194 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2195 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2196 struct efx_channel *channel = tx_queue->channel;
2197 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002198 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002199 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002200 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002201 dma_addr_t dma_addr;
2202 efx_qword_t *txd;
2203 int rc;
2204 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002205 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002206
Bert Kenwarde9117e52016-11-17 10:51:54 +00002207 /* TSOv2 is a limited resource that can only be configured on a limited
2208 * number of queues. TSO without checksum offload is not really a thing,
2209 * so we only enable it for those queues.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002210 */
2211 if (csum_offload && (nic_data->datapath_caps2 &
2212 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2213 tso_v2 = true;
2214 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2215 channel->channel);
2216 }
2217
Ben Hutchings8127d662013-08-29 19:19:29 +01002218 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2219 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2220 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2221 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002222 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002223 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002224
2225 dma_addr = tx_queue->txd.buf.dma_addr;
2226
2227 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2228 tx_queue->queue, entries, (u64)dma_addr);
2229
2230 for (i = 0; i < entries; ++i) {
2231 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2232 dma_addr += EFX_BUF_SIZE;
2233 }
2234
2235 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2236
Edward Creee638ee12016-11-17 10:52:07 +00002237 do {
2238 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2239 /* This flag was removed from mcdi_pcol.h for
2240 * the non-_EXT version of INIT_TXQ. However,
2241 * firmware still honours it.
2242 */
2243 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2244 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2245 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2246
2247 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2248 NULL, 0, NULL);
2249 if (rc == -ENOSPC && tso_v2) {
2250 /* Retry without TSOv2 if we're short on contexts. */
2251 tso_v2 = false;
2252 netif_warn(efx, probe, efx->net_dev,
2253 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2254 } else if (rc) {
2255 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2256 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2257 NULL, 0, rc);
2258 goto fail;
2259 }
2260 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002261
2262 /* A previous user of this TX queue might have set us up the
2263 * bomb by writing a descriptor to the TX push collector but
2264 * not the doorbell. (Each collector belongs to a port, not a
2265 * queue or function, so cannot easily be reset.) We must
2266 * attempt to push a no-op descriptor in its place.
2267 */
2268 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2269 tx_queue->insert_count = 1;
2270 txd = efx_tx_desc(tx_queue, 0);
2271 EFX_POPULATE_QWORD_4(*txd,
2272 ESF_DZ_TX_DESC_IS_OPT, true,
2273 ESF_DZ_TX_OPTION_TYPE,
2274 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2275 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2276 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2277 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002278
Bert Kenwarde9117e52016-11-17 10:51:54 +00002279 if (tso_v2) {
2280 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2281 tx_queue->tso_version = 2;
2282 } else if (nic_data->datapath_caps &
2283 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002284 tx_queue->tso_version = 1;
2285 }
2286
Ben Hutchings8127d662013-08-29 19:19:29 +01002287 wmb();
2288 efx_ef10_push_tx_desc(tx_queue, txd);
2289
2290 return;
2291
2292fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002293 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2294 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002295}
2296
2297static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2298{
2299 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002300 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002301 struct efx_nic *efx = tx_queue->efx;
2302 size_t outlen;
2303 int rc;
2304
2305 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2306 tx_queue->queue);
2307
Edward Cree1e0b8122013-05-31 18:36:12 +01002308 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002309 outbuf, sizeof(outbuf), &outlen);
2310
2311 if (rc && rc != -EALREADY)
2312 goto fail;
2313
2314 return;
2315
2316fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002317 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2318 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002319}
2320
2321static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2322{
2323 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2324}
2325
2326/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2327static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2328{
2329 unsigned int write_ptr;
2330 efx_dword_t reg;
2331
2332 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2333 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2334 efx_writed_page(tx_queue->efx, &reg,
2335 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2336}
2337
Bert Kenwarde9117e52016-11-17 10:51:54 +00002338#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2339
2340static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2341 dma_addr_t dma_addr, unsigned int len)
2342{
2343 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2344 /* If we need to break across multiple descriptors we should
2345 * stop at a page boundary. This assumes the length limit is
2346 * greater than the page size.
2347 */
2348 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2349
2350 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2351 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2352 }
2353
2354 return len;
2355}
2356
Ben Hutchings8127d662013-08-29 19:19:29 +01002357static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2358{
2359 unsigned int old_write_count = tx_queue->write_count;
2360 struct efx_tx_buffer *buffer;
2361 unsigned int write_ptr;
2362 efx_qword_t *txd;
2363
Martin Habetsb2663a42015-11-02 12:51:31 +00002364 tx_queue->xmit_more_available = false;
2365 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2366 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002367
2368 do {
2369 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2370 buffer = &tx_queue->buffer[write_ptr];
2371 txd = efx_tx_desc(tx_queue, write_ptr);
2372 ++tx_queue->write_count;
2373
2374 /* Create TX descriptor ring entry */
2375 if (buffer->flags & EFX_TX_BUF_OPTION) {
2376 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002377 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2378 /* PIO descriptor */
2379 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002380 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002381 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002382 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2383 EFX_POPULATE_QWORD_3(
2384 *txd,
2385 ESF_DZ_TX_KER_CONT,
2386 buffer->flags & EFX_TX_BUF_CONT,
2387 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2388 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2389 }
2390 } while (tx_queue->write_count != tx_queue->insert_count);
2391
2392 wmb(); /* Ensure descriptors are written before they are fetched */
2393
2394 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2395 txd = efx_tx_desc(tx_queue,
2396 old_write_count & tx_queue->ptr_mask);
2397 efx_ef10_push_tx_desc(tx_queue, txd);
2398 ++tx_queue->pushes;
2399 } else {
2400 efx_ef10_notify_tx_desc(tx_queue);
2401 }
2402}
2403
Edward Creea33a4c72016-11-03 22:12:27 +00002404#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2405 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2406#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2407 1 << RSS_MODE_HASH_DST_PORT_LBN)
2408#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2409 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2410 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2411 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2412 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2413 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2414 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2415 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2416 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2417 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2418
2419static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2420{
2421 /* Firmware had a bug (sfc bug 61952) where it would not actually
2422 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2423 * This meant that it would always contain whatever was previously
2424 * in the MCDI buffer. Fortunately, all firmware versions with
2425 * this bug have the same default flags value for a newly-allocated
2426 * RSS context, and the only time we want to get the flags is just
2427 * after allocating. Moreover, the response has a 32-bit hole
2428 * where the context ID would be in the request, so we can use an
2429 * overlength buffer in the request and pre-fill the flags field
2430 * with what we believe the default to be. Thus if the firmware
2431 * has the bug, it will leave our pre-filled value in the flags
2432 * field of the response, and we will get the right answer.
2433 *
2434 * However, this does mean that this function should NOT be used if
2435 * the RSS context flags might not be their defaults - it is ONLY
2436 * reliably correct for a newly-allocated RSS context.
2437 */
2438 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2439 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2440 size_t outlen;
2441 int rc;
2442
2443 /* Check we have a hole for the context ID */
2444 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2445 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2446 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2447 RSS_CONTEXT_FLAGS_DEFAULT);
2448 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2449 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2450 if (rc == 0) {
2451 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2452 rc = -EIO;
2453 else
2454 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2455 }
2456 return rc;
2457}
2458
2459/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2460 * If we fail, we just leave the RSS context at its default hash settings,
2461 * which is safe but may slightly reduce performance.
2462 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2463 * just need to set the UDP ports flags (for both IP versions).
2464 */
2465static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2466{
2467 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2468 u32 flags;
2469
2470 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2471
2472 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2473 return;
2474 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2475 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2476 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2477 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002478 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2479 NULL, 0, NULL))
2480 /* Succeeded, so UDP 4-tuple is now enabled */
2481 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002482}
2483
Jon Cooper267c0152015-05-06 00:59:38 +01002484static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2485 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002486{
2487 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2488 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002489 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002490 size_t outlen;
2491 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002492 u32 alloc_type = exclusive ?
2493 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2494 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2495 unsigned rss_spread = exclusive ?
2496 efx->rss_spread :
2497 min(rounddown_pow_of_two(efx->rss_spread),
2498 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2499
2500 if (!exclusive && rss_spread == 1) {
2501 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2502 if (context_size)
2503 *context_size = 1;
2504 return 0;
2505 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002506
Jon Cooperdcb41232016-04-25 16:51:00 +01002507 if (nic_data->datapath_caps &
2508 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2509 return -EOPNOTSUPP;
2510
Ben Hutchings8127d662013-08-29 19:19:29 +01002511 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002512 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002513 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2514 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002515
2516 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2517 outbuf, sizeof(outbuf), &outlen);
2518 if (rc != 0)
2519 return rc;
2520
2521 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2522 return -EIO;
2523
2524 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2525
Jon Cooper267c0152015-05-06 00:59:38 +01002526 if (context_size)
2527 *context_size = rss_spread;
2528
Edward Creea33a4c72016-11-03 22:12:27 +00002529 if (nic_data->datapath_caps &
2530 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2531 efx_ef10_set_rss_flags(efx, *context);
2532
Ben Hutchings8127d662013-08-29 19:19:29 +01002533 return 0;
2534}
2535
2536static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2537{
2538 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2539 int rc;
2540
2541 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2542 context);
2543
2544 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2545 NULL, 0, NULL);
2546 WARN_ON(rc != 0);
2547}
2548
Jon Cooper267c0152015-05-06 00:59:38 +01002549static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
Edward Creef74d1992017-01-17 12:01:53 +00002550 const u32 *rx_indir_table, const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002551{
2552 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2553 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2554 int i, rc;
2555
2556 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2557 context);
2558 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2559 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2560
Edward Creef74d1992017-01-17 12:01:53 +00002561 /* This iterates over the length of efx->rx_indir_table, but copies
2562 * bytes from rx_indir_table. That's because the latter is a pointer
2563 * rather than an array, but should have the same length.
2564 * The efx->rx_hash_key loop below is similar.
2565 */
Ben Hutchings8127d662013-08-29 19:19:29 +01002566 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2567 MCDI_PTR(tablebuf,
2568 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002569 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002570
2571 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2572 sizeof(tablebuf), NULL, 0, NULL);
2573 if (rc != 0)
2574 return rc;
2575
2576 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2577 context);
2578 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2579 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2580 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
Edward Creef74d1992017-01-17 12:01:53 +00002581 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002582
2583 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2584 sizeof(keybuf), NULL, 0, NULL);
2585}
2586
2587static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2588{
2589 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2590
2591 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2592 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2593 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2594}
2595
Jon Cooper267c0152015-05-06 00:59:38 +01002596static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2597 unsigned *context_size)
2598{
2599 u32 new_rx_rss_context;
2600 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2601 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2602 false, context_size);
2603
2604 if (rc != 0)
2605 return rc;
2606
2607 nic_data->rx_rss_context = new_rx_rss_context;
2608 nic_data->rx_rss_context_exclusive = false;
2609 efx_set_default_rx_indir_table(efx);
2610 return 0;
2611}
2612
2613static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
Edward Creef74d1992017-01-17 12:01:53 +00002614 const u32 *rx_indir_table,
2615 const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002616{
2617 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2618 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002619 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002620
Jon Cooper267c0152015-05-06 00:59:38 +01002621 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2622 !nic_data->rx_rss_context_exclusive) {
2623 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2624 true, NULL);
2625 if (rc == -EOPNOTSUPP)
2626 return rc;
2627 else if (rc != 0)
2628 goto fail1;
2629 } else {
2630 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002631 }
2632
Jon Cooper267c0152015-05-06 00:59:38 +01002633 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
Edward Creef74d1992017-01-17 12:01:53 +00002634 rx_indir_table, key);
Ben Hutchings8127d662013-08-29 19:19:29 +01002635 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002636 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002637
Jon Cooper267c0152015-05-06 00:59:38 +01002638 if (nic_data->rx_rss_context != new_rx_rss_context)
2639 efx_ef10_rx_free_indir_table(efx);
2640 nic_data->rx_rss_context = new_rx_rss_context;
2641 nic_data->rx_rss_context_exclusive = true;
2642 if (rx_indir_table != efx->rx_indir_table)
2643 memcpy(efx->rx_indir_table, rx_indir_table,
2644 sizeof(efx->rx_indir_table));
Edward Creef74d1992017-01-17 12:01:53 +00002645 if (key != efx->rx_hash_key)
2646 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2647
Jon Cooper267c0152015-05-06 00:59:38 +01002648 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002649
Jon Cooper267c0152015-05-06 00:59:38 +01002650fail2:
2651 if (new_rx_rss_context != nic_data->rx_rss_context)
2652 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2653fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002654 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002655 return rc;
2656}
2657
Edward Creea707d182017-01-17 12:02:12 +00002658static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2659{
2660 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2661 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2662 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2663 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2664 size_t outlen;
2665 int rc, i;
2666
2667 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2668 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2669
2670 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2671 return -ENOENT;
2672
2673 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2674 nic_data->rx_rss_context);
2675 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2676 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2677 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2678 tablebuf, sizeof(tablebuf), &outlen);
2679 if (rc != 0)
2680 return rc;
2681
2682 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2683 return -EIO;
2684
2685 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2686 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2687 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2688
2689 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2690 nic_data->rx_rss_context);
2691 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2692 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2693 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2694 keybuf, sizeof(keybuf), &outlen);
2695 if (rc != 0)
2696 return rc;
2697
2698 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2699 return -EIO;
2700
2701 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2702 efx->rx_hash_key[i] = MCDI_PTR(
2703 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2704
2705 return 0;
2706}
2707
Jon Cooper267c0152015-05-06 00:59:38 +01002708static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
Edward Creef74d1992017-01-17 12:01:53 +00002709 const u32 *rx_indir_table,
2710 const u8 *key)
Jon Cooper267c0152015-05-06 00:59:38 +01002711{
2712 int rc;
2713
2714 if (efx->rss_spread == 1)
2715 return 0;
2716
Edward Creef74d1992017-01-17 12:01:53 +00002717 if (!key)
2718 key = efx->rx_hash_key;
2719
2720 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
Jon Cooper267c0152015-05-06 00:59:38 +01002721
2722 if (rc == -ENOBUFS && !user) {
2723 unsigned context_size;
2724 bool mismatch = false;
2725 size_t i;
2726
2727 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2728 i++)
2729 mismatch = rx_indir_table[i] !=
2730 ethtool_rxfh_indir_default(i, efx->rss_spread);
2731
2732 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2733 if (rc == 0) {
2734 if (context_size != efx->rss_spread)
2735 netif_warn(efx, probe, efx->net_dev,
2736 "Could not allocate an exclusive RSS"
2737 " context; allocated a shared one of"
2738 " different size."
2739 " Wanted %u, got %u.\n",
2740 efx->rss_spread, context_size);
2741 else if (mismatch)
2742 netif_warn(efx, probe, efx->net_dev,
2743 "Could not allocate an exclusive RSS"
2744 " context; allocated a shared one but"
2745 " could not apply custom"
2746 " indirection.\n");
2747 else
2748 netif_info(efx, probe, efx->net_dev,
2749 "Could not allocate an exclusive RSS"
2750 " context; allocated a shared one.\n");
2751 }
2752 }
2753 return rc;
2754}
2755
2756static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2757 const u32 *rx_indir_table
Edward Creef74d1992017-01-17 12:01:53 +00002758 __attribute__ ((unused)),
2759 const u8 *key
Jon Cooper267c0152015-05-06 00:59:38 +01002760 __attribute__ ((unused)))
2761{
2762 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2763
2764 if (user)
2765 return -EOPNOTSUPP;
2766 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2767 return 0;
2768 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002769}
2770
2771static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2772{
2773 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2774 (rx_queue->ptr_mask + 1) *
2775 sizeof(efx_qword_t),
2776 GFP_KERNEL);
2777}
2778
2779static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2780{
2781 MCDI_DECLARE_BUF(inbuf,
2782 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2783 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002784 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2785 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2786 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002787 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002788 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002789 dma_addr_t dma_addr;
2790 int rc;
2791 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002792 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002793
2794 rx_queue->scatter_n = 0;
2795 rx_queue->scatter_len = 0;
2796
2797 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2798 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2799 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2800 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2801 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002802 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2803 INIT_RXQ_IN_FLAG_PREFIX, 1,
2804 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002805 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002806 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002807
2808 dma_addr = rx_queue->rxd.buf.dma_addr;
2809
2810 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2811 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2812
2813 for (i = 0; i < entries; ++i) {
2814 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2815 dma_addr += EFX_BUF_SIZE;
2816 }
2817
2818 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2819
2820 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002821 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002822 if (rc)
2823 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2824 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002825}
2826
2827static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2828{
2829 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002830 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002831 struct efx_nic *efx = rx_queue->efx;
2832 size_t outlen;
2833 int rc;
2834
2835 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2836 efx_rx_queue_index(rx_queue));
2837
Edward Cree1e0b8122013-05-31 18:36:12 +01002838 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002839 outbuf, sizeof(outbuf), &outlen);
2840
2841 if (rc && rc != -EALREADY)
2842 goto fail;
2843
2844 return;
2845
2846fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002847 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2848 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002849}
2850
2851static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2852{
2853 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2854}
2855
2856/* This creates an entry in the RX descriptor queue */
2857static inline void
2858efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2859{
2860 struct efx_rx_buffer *rx_buf;
2861 efx_qword_t *rxd;
2862
2863 rxd = efx_rx_desc(rx_queue, index);
2864 rx_buf = efx_rx_buffer(rx_queue, index);
2865 EFX_POPULATE_QWORD_2(*rxd,
2866 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2867 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2868}
2869
2870static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2871{
2872 struct efx_nic *efx = rx_queue->efx;
2873 unsigned int write_count;
2874 efx_dword_t reg;
2875
2876 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2877 write_count = rx_queue->added_count & ~7;
2878 if (rx_queue->notified_count == write_count)
2879 return;
2880
2881 do
2882 efx_ef10_build_rx_desc(
2883 rx_queue,
2884 rx_queue->notified_count & rx_queue->ptr_mask);
2885 while (++rx_queue->notified_count != write_count);
2886
2887 wmb();
2888 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2889 write_count & rx_queue->ptr_mask);
2890 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2891 efx_rx_queue_index(rx_queue));
2892}
2893
2894static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2895
2896static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2897{
2898 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2899 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2900 efx_qword_t event;
2901
2902 EFX_POPULATE_QWORD_2(event,
2903 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2904 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2905
2906 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2907
2908 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2909 * already swapped the data to little-endian order.
2910 */
2911 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2912 sizeof(efx_qword_t));
2913
2914 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2915 inbuf, sizeof(inbuf), 0,
2916 efx_ef10_rx_defer_refill_complete, 0);
2917}
2918
2919static void
2920efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2921 int rc, efx_dword_t *outbuf,
2922 size_t outlen_actual)
2923{
2924 /* nothing to do */
2925}
2926
2927static int efx_ef10_ev_probe(struct efx_channel *channel)
2928{
2929 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2930 (channel->eventq_mask + 1) *
2931 sizeof(efx_qword_t),
2932 GFP_KERNEL);
2933}
2934
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002935static void efx_ef10_ev_fini(struct efx_channel *channel)
2936{
2937 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2938 MCDI_DECLARE_BUF_ERR(outbuf);
2939 struct efx_nic *efx = channel->efx;
2940 size_t outlen;
2941 int rc;
2942
2943 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2944
2945 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2946 outbuf, sizeof(outbuf), &outlen);
2947
2948 if (rc && rc != -EALREADY)
2949 goto fail;
2950
2951 return;
2952
2953fail:
2954 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2955 outbuf, outlen, rc);
2956}
2957
Ben Hutchings8127d662013-08-29 19:19:29 +01002958static int efx_ef10_ev_init(struct efx_channel *channel)
2959{
2960 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002961 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2962 EFX_BUF_SIZE));
2963 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002964 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2965 struct efx_nic *efx = channel->efx;
2966 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002967 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002968 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002969 dma_addr_t dma_addr;
2970 int rc;
2971 int i;
2972
2973 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002974
2975 /* Fill event queue with all ones (i.e. empty events) */
2976 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2977
2978 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2979 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2980 /* INIT_EVQ expects index in vector table, not absolute */
2981 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002982 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2983 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2984 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2985 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2986 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2987 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2988 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2989
Bert Kenwarda9955602016-08-11 13:01:54 +01002990 if (nic_data->datapath_caps2 &
2991 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2992 /* Use the new generic approach to specifying event queue
2993 * configuration, requesting lower latency or higher throughput.
2994 * The options that actually get used appear in the output.
2995 */
2996 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2997 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2998 INIT_EVQ_V2_IN_FLAG_TYPE,
2999 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3000 } else {
3001 bool cut_thru = !(nic_data->datapath_caps &
3002 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3003
3004 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3005 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3006 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3007 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3008 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3009 }
3010
Ben Hutchings8127d662013-08-29 19:19:29 +01003011 dma_addr = channel->eventq.buf.dma_addr;
3012 for (i = 0; i < entries; ++i) {
3013 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3014 dma_addr += EFX_BUF_SIZE;
3015 }
3016
3017 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3018
3019 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3020 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01003021
3022 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3023 netif_dbg(efx, drv, efx->net_dev,
3024 "Channel %d using event queue flags %08x\n",
3025 channel->channel,
3026 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3027
Ben Hutchings8127d662013-08-29 19:19:29 +01003028 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003029 if (channel->channel || rc)
3030 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003031
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003032 /* Successfully created event queue on channel 0 */
3033 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01003034 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01003035 /* GET_WORKAROUNDS was implemented before this workaround,
3036 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01003037 */
3038 nic_data->workaround_26807 = false;
3039 rc = 0;
3040 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003041 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01003042 } else {
3043 nic_data->workaround_26807 =
3044 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01003045
Edward Cree832dc9e2015-07-21 15:09:31 +01003046 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3047 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003048 unsigned int flags;
3049
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01003050 rc = efx_mcdi_set_workaround(efx,
3051 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003052 true, &flags);
3053
3054 if (!rc) {
3055 if (flags &
3056 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3057 netif_info(efx, drv, efx->net_dev,
3058 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00003059
3060 /* With MCFW v4.6.x and earlier, the
3061 * boot count will have incremented,
3062 * so re-read the warm_boot_count
3063 * value now to ensure this function
3064 * doesn't think it has changed next
3065 * time it checks.
3066 */
3067 rc = efx_ef10_get_warm_boot_count(efx);
3068 if (rc >= 0) {
3069 nic_data->warm_boot_count = rc;
3070 rc = 0;
3071 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003072 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003073 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003074 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01003075 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003076 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003077 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003078 }
3079
3080 if (!rc)
3081 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003082
3083fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003084 efx_ef10_ev_fini(channel);
3085 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003086}
3087
3088static void efx_ef10_ev_remove(struct efx_channel *channel)
3089{
3090 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3091}
3092
3093static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3094 unsigned int rx_queue_label)
3095{
3096 struct efx_nic *efx = rx_queue->efx;
3097
3098 netif_info(efx, hw, efx->net_dev,
3099 "rx event arrived on queue %d labeled as queue %u\n",
3100 efx_rx_queue_index(rx_queue), rx_queue_label);
3101
3102 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3103}
3104
3105static void
3106efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3107 unsigned int actual, unsigned int expected)
3108{
3109 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3110 struct efx_nic *efx = rx_queue->efx;
3111
3112 netif_info(efx, hw, efx->net_dev,
3113 "dropped %d events (index=%d expected=%d)\n",
3114 dropped, actual, expected);
3115
3116 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3117}
3118
3119/* partially received RX was aborted. clean up. */
3120static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3121{
3122 unsigned int rx_desc_ptr;
3123
Ben Hutchings8127d662013-08-29 19:19:29 +01003124 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3125 "scattered RX aborted (dropping %u buffers)\n",
3126 rx_queue->scatter_n);
3127
3128 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3129
3130 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3131 0, EFX_RX_PKT_DISCARD);
3132
3133 rx_queue->removed_count += rx_queue->scatter_n;
3134 rx_queue->scatter_n = 0;
3135 rx_queue->scatter_len = 0;
3136 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3137}
3138
3139static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3140 const efx_qword_t *event)
3141{
3142 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
3143 unsigned int n_descs, n_packets, i;
3144 struct efx_nic *efx = channel->efx;
3145 struct efx_rx_queue *rx_queue;
3146 bool rx_cont;
3147 u16 flags = 0;
3148
3149 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3150 return 0;
3151
3152 /* Basic packet information */
3153 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3154 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3155 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3156 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3157 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3158
Ben Hutchings48ce5632013-11-01 16:42:44 +00003159 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3160 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3161 EFX_QWORD_FMT "\n",
3162 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003163
3164 rx_queue = efx_channel_get_rx_queue(channel);
3165
3166 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3167 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3168
3169 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3170 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3171
3172 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003173 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3174
Ben Hutchings8127d662013-08-29 19:19:29 +01003175 /* detect rx abort */
3176 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003177 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3178 netdev_WARN(efx->net_dev,
3179 "invalid RX abort: scatter_n=%u event="
3180 EFX_QWORD_FMT "\n",
3181 rx_queue->scatter_n,
3182 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003183 efx_ef10_handle_rx_abort(rx_queue);
3184 return 0;
3185 }
3186
Ben Hutchings92a04162013-09-24 23:21:57 +01003187 /* Check that RX completion merging is valid, i.e.
3188 * the current firmware supports it and this is a
3189 * non-scattered packet.
3190 */
3191 if (!(nic_data->datapath_caps &
3192 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3193 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003194 efx_ef10_handle_rx_bad_lbits(
3195 rx_queue, next_ptr_lbits,
3196 (rx_queue->removed_count +
3197 rx_queue->scatter_n + 1) &
3198 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3199 return 0;
3200 }
3201
3202 /* Merged completion for multiple non-scattered packets */
3203 rx_queue->scatter_n = 1;
3204 rx_queue->scatter_len = 0;
3205 n_packets = n_descs;
3206 ++channel->n_rx_merge_events;
3207 channel->n_rx_merge_packets += n_packets;
3208 flags |= EFX_RX_PKT_PREFIX_LEN;
3209 } else {
3210 ++rx_queue->scatter_n;
3211 rx_queue->scatter_len += rx_bytes;
3212 if (rx_cont)
3213 return 0;
3214 n_packets = 1;
3215 }
3216
3217 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
3218 flags |= EFX_RX_PKT_DISCARD;
3219
3220 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
3221 channel->n_rx_ip_hdr_chksum_err += n_packets;
3222 } else if (unlikely(EFX_QWORD_FIELD(*event,
3223 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
3224 channel->n_rx_tcp_udp_chksum_err += n_packets;
3225 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3226 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
3227 flags |= EFX_RX_PKT_CSUMMED;
3228 }
3229
3230 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3231 flags |= EFX_RX_PKT_TCP;
3232
3233 channel->irq_mod_score += 2 * n_packets;
3234
3235 /* Handle received packet(s) */
3236 for (i = 0; i < n_packets; i++) {
3237 efx_rx_packet(rx_queue,
3238 rx_queue->removed_count & rx_queue->ptr_mask,
3239 rx_queue->scatter_n, rx_queue->scatter_len,
3240 flags);
3241 rx_queue->removed_count += rx_queue->scatter_n;
3242 }
3243
3244 rx_queue->scatter_n = 0;
3245 rx_queue->scatter_len = 0;
3246
3247 return n_packets;
3248}
3249
3250static int
3251efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3252{
3253 struct efx_nic *efx = channel->efx;
3254 struct efx_tx_queue *tx_queue;
3255 unsigned int tx_ev_desc_ptr;
3256 unsigned int tx_ev_q_label;
3257 int tx_descs = 0;
3258
3259 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3260 return 0;
3261
3262 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3263 return 0;
3264
3265 /* Transmit completion */
3266 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3267 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3268 tx_queue = efx_channel_get_tx_queue(channel,
3269 tx_ev_q_label % EFX_TXQ_TYPES);
3270 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3271 tx_queue->ptr_mask);
3272 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3273
3274 return tx_descs;
3275}
3276
3277static void
3278efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3279{
3280 struct efx_nic *efx = channel->efx;
3281 int subcode;
3282
3283 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3284
3285 switch (subcode) {
3286 case ESE_DZ_DRV_TIMER_EV:
3287 case ESE_DZ_DRV_WAKE_UP_EV:
3288 break;
3289 case ESE_DZ_DRV_START_UP_EV:
3290 /* event queue init complete. ok. */
3291 break;
3292 default:
3293 netif_err(efx, hw, efx->net_dev,
3294 "channel %d unknown driver event type %d"
3295 " (data " EFX_QWORD_FMT ")\n",
3296 channel->channel, subcode,
3297 EFX_QWORD_VAL(*event));
3298
3299 }
3300}
3301
3302static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3303 efx_qword_t *event)
3304{
3305 struct efx_nic *efx = channel->efx;
3306 u32 subcode;
3307
3308 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3309
3310 switch (subcode) {
3311 case EFX_EF10_TEST:
3312 channel->event_test_cpu = raw_smp_processor_id();
3313 break;
3314 case EFX_EF10_REFILL:
3315 /* The queue must be empty, so we won't receive any rx
3316 * events, so efx_process_channel() won't refill the
3317 * queue. Refill it here
3318 */
Jon Coopercce28792013-10-02 11:04:14 +01003319 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003320 break;
3321 default:
3322 netif_err(efx, hw, efx->net_dev,
3323 "channel %d unknown driver event type %u"
3324 " (data " EFX_QWORD_FMT ")\n",
3325 channel->channel, (unsigned) subcode,
3326 EFX_QWORD_VAL(*event));
3327 }
3328}
3329
3330static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3331{
3332 struct efx_nic *efx = channel->efx;
3333 efx_qword_t event, *p_event;
3334 unsigned int read_ptr;
3335 int ev_code;
3336 int tx_descs = 0;
3337 int spent = 0;
3338
Eric W. Biederman75363a42014-03-14 18:11:22 -07003339 if (quota <= 0)
3340 return spent;
3341
Ben Hutchings8127d662013-08-29 19:19:29 +01003342 read_ptr = channel->eventq_read_ptr;
3343
3344 for (;;) {
3345 p_event = efx_event(channel, read_ptr);
3346 event = *p_event;
3347
3348 if (!efx_event_present(&event))
3349 break;
3350
3351 EFX_SET_QWORD(*p_event);
3352
3353 ++read_ptr;
3354
3355 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3356
3357 netif_vdbg(efx, drv, efx->net_dev,
3358 "processing event on %d " EFX_QWORD_FMT "\n",
3359 channel->channel, EFX_QWORD_VAL(event));
3360
3361 switch (ev_code) {
3362 case ESE_DZ_EV_CODE_MCDI_EV:
3363 efx_mcdi_process_event(channel, &event);
3364 break;
3365 case ESE_DZ_EV_CODE_RX_EV:
3366 spent += efx_ef10_handle_rx_event(channel, &event);
3367 if (spent >= quota) {
3368 /* XXX can we split a merged event to
3369 * avoid going over-quota?
3370 */
3371 spent = quota;
3372 goto out;
3373 }
3374 break;
3375 case ESE_DZ_EV_CODE_TX_EV:
3376 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3377 if (tx_descs > efx->txq_entries) {
3378 spent = quota;
3379 goto out;
3380 } else if (++spent == quota) {
3381 goto out;
3382 }
3383 break;
3384 case ESE_DZ_EV_CODE_DRIVER_EV:
3385 efx_ef10_handle_driver_event(channel, &event);
3386 if (++spent == quota)
3387 goto out;
3388 break;
3389 case EFX_EF10_DRVGEN_EV:
3390 efx_ef10_handle_driver_generated_event(channel, &event);
3391 break;
3392 default:
3393 netif_err(efx, hw, efx->net_dev,
3394 "channel %d unknown event type %d"
3395 " (data " EFX_QWORD_FMT ")\n",
3396 channel->channel, ev_code,
3397 EFX_QWORD_VAL(event));
3398 }
3399 }
3400
3401out:
3402 channel->eventq_read_ptr = read_ptr;
3403 return spent;
3404}
3405
3406static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3407{
3408 struct efx_nic *efx = channel->efx;
3409 efx_dword_t rptr;
3410
3411 if (EFX_EF10_WORKAROUND_35388(efx)) {
3412 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3413 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3414 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3415 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3416
3417 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3418 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3419 ERF_DD_EVQ_IND_RPTR,
3420 (channel->eventq_read_ptr &
3421 channel->eventq_mask) >>
3422 ERF_DD_EVQ_IND_RPTR_WIDTH);
3423 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3424 channel->channel);
3425 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3426 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3427 ERF_DD_EVQ_IND_RPTR,
3428 channel->eventq_read_ptr &
3429 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3430 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3431 channel->channel);
3432 } else {
3433 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3434 channel->eventq_read_ptr &
3435 channel->eventq_mask);
3436 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3437 }
3438}
3439
3440static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3441{
3442 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3443 struct efx_nic *efx = channel->efx;
3444 efx_qword_t event;
3445 int rc;
3446
3447 EFX_POPULATE_QWORD_2(event,
3448 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3449 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3450
3451 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3452
3453 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3454 * already swapped the data to little-endian order.
3455 */
3456 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3457 sizeof(efx_qword_t));
3458
3459 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3460 NULL, 0, NULL);
3461 if (rc != 0)
3462 goto fail;
3463
3464 return;
3465
3466fail:
3467 WARN_ON(true);
3468 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3469}
3470
3471void efx_ef10_handle_drain_event(struct efx_nic *efx)
3472{
3473 if (atomic_dec_and_test(&efx->active_queues))
3474 wake_up(&efx->flush_wq);
3475
3476 WARN_ON(atomic_read(&efx->active_queues) < 0);
3477}
3478
3479static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3480{
3481 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3482 struct efx_channel *channel;
3483 struct efx_tx_queue *tx_queue;
3484 struct efx_rx_queue *rx_queue;
3485 int pending;
3486
3487 /* If the MC has just rebooted, the TX/RX queues will have already been
3488 * torn down, but efx->active_queues needs to be set to zero.
3489 */
3490 if (nic_data->must_realloc_vis) {
3491 atomic_set(&efx->active_queues, 0);
3492 return 0;
3493 }
3494
3495 /* Do not attempt to write to the NIC during EEH recovery */
3496 if (efx->state != STATE_RECOVERY) {
3497 efx_for_each_channel(channel, efx) {
3498 efx_for_each_channel_rx_queue(rx_queue, channel)
3499 efx_ef10_rx_fini(rx_queue);
3500 efx_for_each_channel_tx_queue(tx_queue, channel)
3501 efx_ef10_tx_fini(tx_queue);
3502 }
3503
3504 wait_event_timeout(efx->flush_wq,
3505 atomic_read(&efx->active_queues) == 0,
3506 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3507 pending = atomic_read(&efx->active_queues);
3508 if (pending) {
3509 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3510 pending);
3511 return -ETIMEDOUT;
3512 }
3513 }
3514
3515 return 0;
3516}
3517
Edward Creee2835462014-04-16 19:27:48 +01003518static void efx_ef10_prepare_flr(struct efx_nic *efx)
3519{
3520 atomic_set(&efx->active_queues, 0);
3521}
3522
Ben Hutchings8127d662013-08-29 19:19:29 +01003523static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3524 const struct efx_filter_spec *right)
3525{
3526 if ((left->match_flags ^ right->match_flags) |
3527 ((left->flags ^ right->flags) &
3528 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3529 return false;
3530
3531 return memcmp(&left->outer_vid, &right->outer_vid,
3532 sizeof(struct efx_filter_spec) -
3533 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3534}
3535
3536static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3537{
3538 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3539 return jhash2((const u32 *)&spec->outer_vid,
3540 (sizeof(struct efx_filter_spec) -
3541 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3542 0);
3543 /* XXX should we randomise the initval? */
3544}
3545
3546/* Decide whether a filter should be exclusive or else should allow
3547 * delivery to additional recipients. Currently we decide that
3548 * filters for specific local unicast MAC and IP addresses are
3549 * exclusive.
3550 */
3551static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3552{
3553 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3554 !is_multicast_ether_addr(spec->loc_mac))
3555 return true;
3556
3557 if ((spec->match_flags &
3558 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3559 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3560 if (spec->ether_type == htons(ETH_P_IP) &&
3561 !ipv4_is_multicast(spec->loc_host[0]))
3562 return true;
3563 if (spec->ether_type == htons(ETH_P_IPV6) &&
3564 ((const u8 *)spec->loc_host)[0] != 0xff)
3565 return true;
3566 }
3567
3568 return false;
3569}
3570
3571static struct efx_filter_spec *
3572efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3573 unsigned int filter_idx)
3574{
3575 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3576 ~EFX_EF10_FILTER_FLAGS);
3577}
3578
3579static unsigned int
3580efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3581 unsigned int filter_idx)
3582{
3583 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3584}
3585
3586static void
3587efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3588 unsigned int filter_idx,
3589 const struct efx_filter_spec *spec,
3590 unsigned int flags)
3591{
3592 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3593}
3594
3595static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3596 const struct efx_filter_spec *spec,
3597 efx_dword_t *inbuf, u64 handle,
3598 bool replacing)
3599{
3600 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003601 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003602
3603 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3604
Jon Cooperdcb41232016-04-25 16:51:00 +01003605 /* Remove RSS flag if we don't have an RSS context. */
3606 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3607 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3608 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3609 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3610
Ben Hutchings8127d662013-08-29 19:19:29 +01003611 if (replacing) {
3612 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3613 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3614 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3615 } else {
3616 u32 match_fields = 0;
3617
3618 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3619 efx_ef10_filter_is_exclusive(spec) ?
3620 MC_CMD_FILTER_OP_IN_OP_INSERT :
3621 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3622
3623 /* Convert match flags and values. Unlike almost
3624 * everything else in MCDI, these fields are in
3625 * network byte order.
3626 */
3627 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3628 match_fields |=
3629 is_multicast_ether_addr(spec->loc_mac) ?
3630 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3631 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3632#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3633 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3634 match_fields |= \
3635 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3636 mcdi_field ## _LBN; \
3637 BUILD_BUG_ON( \
3638 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3639 sizeof(spec->gen_field)); \
3640 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3641 &spec->gen_field, sizeof(spec->gen_field)); \
3642 }
3643 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3644 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3645 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3646 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3647 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3648 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3649 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3650 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3651 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3652 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3653#undef COPY_FIELD
3654 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3655 match_fields);
3656 }
3657
Daniel Pieczko45b24492015-05-06 00:57:14 +01003658 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003659 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3660 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3661 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3662 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003663 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003664 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3665 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003666 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3667 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3668 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003669 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003670 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003671 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3672 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003673 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003674 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3675 spec->rss_context !=
3676 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3677 spec->rss_context : nic_data->rx_rss_context);
3678}
3679
3680static int efx_ef10_filter_push(struct efx_nic *efx,
3681 const struct efx_filter_spec *spec,
3682 u64 *handle, bool replacing)
3683{
3684 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3685 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3686 int rc;
3687
3688 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3689 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3690 outbuf, sizeof(outbuf), NULL);
3691 if (rc == 0)
3692 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003693 if (rc == -ENOSPC)
3694 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003695 return rc;
3696}
3697
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003698static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003699{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003700 unsigned int match_flags = spec->match_flags;
3701 u32 mcdi_flags = 0;
3702
3703 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3704 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3705 mcdi_flags |=
3706 is_multicast_ether_addr(spec->loc_mac) ?
3707 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3708 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3709 }
3710
3711#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3712 unsigned int old_match_flags = match_flags; \
3713 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3714 if (match_flags != old_match_flags) \
3715 mcdi_flags |= \
3716 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3717 mcdi_field ## _LBN); \
3718 }
3719 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3720 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3721 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3722 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3723 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3724 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3725 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3726 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3727 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3728 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3729#undef MAP_FILTER_TO_MCDI_FLAG
3730
3731 /* Did we map them all? */
3732 WARN_ON_ONCE(match_flags);
3733
3734 return mcdi_flags;
3735}
3736
3737static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3738 const struct efx_filter_spec *spec)
3739{
3740 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003741 unsigned int match_pri;
3742
3743 for (match_pri = 0;
3744 match_pri < table->rx_match_count;
3745 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003746 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003747 return match_pri;
3748
3749 return -EPROTONOSUPPORT;
3750}
3751
3752static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3753 struct efx_filter_spec *spec,
3754 bool replace_equal)
3755{
3756 struct efx_ef10_filter_table *table = efx->filter_state;
3757 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3758 struct efx_filter_spec *saved_spec;
3759 unsigned int match_pri, hash;
3760 unsigned int priv_flags;
3761 bool replacing = false;
3762 int ins_index = -1;
3763 DEFINE_WAIT(wait);
3764 bool is_mc_recip;
3765 s32 rc;
3766
3767 /* For now, only support RX filters */
3768 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3769 EFX_FILTER_FLAG_RX)
3770 return -EINVAL;
3771
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003772 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003773 if (rc < 0)
3774 return rc;
3775 match_pri = rc;
3776
3777 hash = efx_ef10_filter_hash(spec);
3778 is_mc_recip = efx_filter_is_mc_recipient(spec);
3779 if (is_mc_recip)
3780 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3781
3782 /* Find any existing filters with the same match tuple or
3783 * else a free slot to insert at. If any of them are busy,
3784 * we have to wait and retry.
3785 */
3786 for (;;) {
3787 unsigned int depth = 1;
3788 unsigned int i;
3789
3790 spin_lock_bh(&efx->filter_lock);
3791
3792 for (;;) {
3793 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3794 saved_spec = efx_ef10_filter_entry_spec(table, i);
3795
3796 if (!saved_spec) {
3797 if (ins_index < 0)
3798 ins_index = i;
3799 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3800 if (table->entry[i].spec &
3801 EFX_EF10_FILTER_FLAG_BUSY)
3802 break;
3803 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003804 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003805 rc = -EPERM;
3806 goto out_unlock;
3807 }
3808 if (!is_mc_recip) {
3809 /* This is the only one */
3810 if (spec->priority ==
3811 saved_spec->priority &&
3812 !replace_equal) {
3813 rc = -EEXIST;
3814 goto out_unlock;
3815 }
3816 ins_index = i;
3817 goto found;
3818 } else if (spec->priority >
3819 saved_spec->priority ||
3820 (spec->priority ==
3821 saved_spec->priority &&
3822 replace_equal)) {
3823 if (ins_index < 0)
3824 ins_index = i;
3825 else
3826 __set_bit(depth, mc_rem_map);
3827 }
3828 }
3829
3830 /* Once we reach the maximum search depth, use
3831 * the first suitable slot or return -EBUSY if
3832 * there was none
3833 */
3834 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3835 if (ins_index < 0) {
3836 rc = -EBUSY;
3837 goto out_unlock;
3838 }
3839 goto found;
3840 }
3841
3842 ++depth;
3843 }
3844
3845 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3846 spin_unlock_bh(&efx->filter_lock);
3847 schedule();
3848 }
3849
3850found:
3851 /* Create a software table entry if necessary, and mark it
3852 * busy. We might yet fail to insert, but any attempt to
3853 * insert a conflicting filter while we're waiting for the
3854 * firmware must find the busy entry.
3855 */
3856 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3857 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003858 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3859 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003860 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003861 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3862 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003863 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003864 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003865 rc = ins_index;
3866 goto out_unlock;
3867 }
3868 replacing = true;
3869 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3870 } else {
3871 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3872 if (!saved_spec) {
3873 rc = -ENOMEM;
3874 goto out_unlock;
3875 }
3876 *saved_spec = *spec;
3877 priv_flags = 0;
3878 }
3879 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3880 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3881
3882 /* Mark lower-priority multicast recipients busy prior to removal */
3883 if (is_mc_recip) {
3884 unsigned int depth, i;
3885
3886 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3887 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3888 if (test_bit(depth, mc_rem_map))
3889 table->entry[i].spec |=
3890 EFX_EF10_FILTER_FLAG_BUSY;
3891 }
3892 }
3893
3894 spin_unlock_bh(&efx->filter_lock);
3895
3896 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3897 replacing);
3898
3899 /* Finalise the software table entry */
3900 spin_lock_bh(&efx->filter_lock);
3901 if (rc == 0) {
3902 if (replacing) {
3903 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003904 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3905 saved_spec->flags |=
3906 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003907 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003908 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003909 saved_spec->flags |= spec->flags;
3910 saved_spec->rss_context = spec->rss_context;
3911 saved_spec->dmaq_id = spec->dmaq_id;
3912 }
3913 } else if (!replacing) {
3914 kfree(saved_spec);
3915 saved_spec = NULL;
3916 }
3917 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3918
3919 /* Remove and finalise entries for lower-priority multicast
3920 * recipients
3921 */
3922 if (is_mc_recip) {
3923 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3924 unsigned int depth, i;
3925
3926 memset(inbuf, 0, sizeof(inbuf));
3927
3928 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3929 if (!test_bit(depth, mc_rem_map))
3930 continue;
3931
3932 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3933 saved_spec = efx_ef10_filter_entry_spec(table, i);
3934 priv_flags = efx_ef10_filter_entry_flags(table, i);
3935
3936 if (rc == 0) {
3937 spin_unlock_bh(&efx->filter_lock);
3938 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3939 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3940 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3941 table->entry[i].handle);
3942 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3943 inbuf, sizeof(inbuf),
3944 NULL, 0, NULL);
3945 spin_lock_bh(&efx->filter_lock);
3946 }
3947
3948 if (rc == 0) {
3949 kfree(saved_spec);
3950 saved_spec = NULL;
3951 priv_flags = 0;
3952 } else {
3953 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3954 }
3955 efx_ef10_filter_set_entry(table, i, saved_spec,
3956 priv_flags);
3957 }
3958 }
3959
3960 /* If successful, return the inserted filter ID */
3961 if (rc == 0)
3962 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3963
3964 wake_up_all(&table->waitq);
3965out_unlock:
3966 spin_unlock_bh(&efx->filter_lock);
3967 finish_wait(&table->waitq, &wait);
3968 return rc;
3969}
3970
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003971static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003972{
3973 /* no need to do anything here on EF10 */
3974}
3975
3976/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003977 * If !by_index, remove by ID
3978 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003979 * Filter ID may come from userland and must be range-checked.
3980 */
3981static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003982 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003983 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003984{
3985 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3986 struct efx_ef10_filter_table *table = efx->filter_state;
3987 MCDI_DECLARE_BUF(inbuf,
3988 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3989 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3990 struct efx_filter_spec *spec;
3991 DEFINE_WAIT(wait);
3992 int rc;
3993
3994 /* Find the software table entry and mark it busy. Don't
3995 * remove it yet; any attempt to update while we're waiting
3996 * for the firmware must find the busy entry.
3997 */
3998 for (;;) {
3999 spin_lock_bh(&efx->filter_lock);
4000 if (!(table->entry[filter_idx].spec &
4001 EFX_EF10_FILTER_FLAG_BUSY))
4002 break;
4003 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4004 spin_unlock_bh(&efx->filter_lock);
4005 schedule();
4006 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004007
Ben Hutchings8127d662013-08-29 19:19:29 +01004008 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004009 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004010 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004011 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01004012 filter_id / HUNT_FILTER_TBL_ROWS)) {
4013 rc = -ENOENT;
4014 goto out_unlock;
4015 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004016
4017 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004018 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004019 /* Just remove flags */
4020 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004021 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004022 rc = 0;
4023 goto out_unlock;
4024 }
4025
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004026 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004027 rc = -ENOENT;
4028 goto out_unlock;
4029 }
4030
Ben Hutchings8127d662013-08-29 19:19:29 +01004031 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4032 spin_unlock_bh(&efx->filter_lock);
4033
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004034 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004035 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01004036
4037 struct efx_filter_spec new_spec = *spec;
4038
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004039 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004040 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004041 (efx_rss_enabled(efx) ?
4042 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01004043 new_spec.dmaq_id = 0;
4044 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4045 rc = efx_ef10_filter_push(efx, &new_spec,
4046 &table->entry[filter_idx].handle,
4047 true);
4048
4049 spin_lock_bh(&efx->filter_lock);
4050 if (rc == 0)
4051 *spec = new_spec;
4052 } else {
4053 /* Really remove the filter */
4054
4055 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4056 efx_ef10_filter_is_exclusive(spec) ?
4057 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4058 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4059 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4060 table->entry[filter_idx].handle);
4061 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4062 inbuf, sizeof(inbuf), NULL, 0, NULL);
4063
4064 spin_lock_bh(&efx->filter_lock);
4065 if (rc == 0) {
4066 kfree(spec);
4067 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4068 }
4069 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004070
Ben Hutchings8127d662013-08-29 19:19:29 +01004071 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4072 wake_up_all(&table->waitq);
4073out_unlock:
4074 spin_unlock_bh(&efx->filter_lock);
4075 finish_wait(&table->waitq, &wait);
4076 return rc;
4077}
4078
4079static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4080 enum efx_filter_priority priority,
4081 u32 filter_id)
4082{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004083 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4084 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004085}
4086
Edward Cree12fb0da2015-07-21 15:11:00 +01004087static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
4088{
4089 return filter_id % HUNT_FILTER_TBL_ROWS;
4090}
4091
Edward Cree8c915622016-06-15 17:49:05 +01004092static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4093 enum efx_filter_priority priority,
4094 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004095{
Edward Cree8c915622016-06-15 17:49:05 +01004096 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4097 return;
4098 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004099}
4100
Ben Hutchings8127d662013-08-29 19:19:29 +01004101static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4102 enum efx_filter_priority priority,
4103 u32 filter_id, struct efx_filter_spec *spec)
4104{
4105 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4106 struct efx_ef10_filter_table *table = efx->filter_state;
4107 const struct efx_filter_spec *saved_spec;
4108 int rc;
4109
4110 spin_lock_bh(&efx->filter_lock);
4111 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4112 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004113 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004114 filter_id / HUNT_FILTER_TBL_ROWS) {
4115 *spec = *saved_spec;
4116 rc = 0;
4117 } else {
4118 rc = -ENOENT;
4119 }
4120 spin_unlock_bh(&efx->filter_lock);
4121 return rc;
4122}
4123
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004124static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004125 enum efx_filter_priority priority)
4126{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004127 unsigned int priority_mask;
4128 unsigned int i;
4129 int rc;
4130
4131 priority_mask = (((1U << (priority + 1)) - 1) &
4132 ~(1U << EFX_FILTER_PRI_AUTO));
4133
4134 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4135 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4136 i, true);
4137 if (rc && rc != -ENOENT)
4138 return rc;
4139 }
4140
4141 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004142}
4143
4144static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4145 enum efx_filter_priority priority)
4146{
4147 struct efx_ef10_filter_table *table = efx->filter_state;
4148 unsigned int filter_idx;
4149 s32 count = 0;
4150
4151 spin_lock_bh(&efx->filter_lock);
4152 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4153 if (table->entry[filter_idx].spec &&
4154 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4155 priority)
4156 ++count;
4157 }
4158 spin_unlock_bh(&efx->filter_lock);
4159 return count;
4160}
4161
4162static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4163{
4164 struct efx_ef10_filter_table *table = efx->filter_state;
4165
4166 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4167}
4168
4169static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4170 enum efx_filter_priority priority,
4171 u32 *buf, u32 size)
4172{
4173 struct efx_ef10_filter_table *table = efx->filter_state;
4174 struct efx_filter_spec *spec;
4175 unsigned int filter_idx;
4176 s32 count = 0;
4177
4178 spin_lock_bh(&efx->filter_lock);
4179 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4180 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4181 if (spec && spec->priority == priority) {
4182 if (count == size) {
4183 count = -EMSGSIZE;
4184 break;
4185 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004186 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004187 HUNT_FILTER_TBL_ROWS +
4188 filter_idx);
4189 }
4190 }
4191 spin_unlock_bh(&efx->filter_lock);
4192 return count;
4193}
4194
4195#ifdef CONFIG_RFS_ACCEL
4196
4197static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4198
4199static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4200 struct efx_filter_spec *spec)
4201{
4202 struct efx_ef10_filter_table *table = efx->filter_state;
4203 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4204 struct efx_filter_spec *saved_spec;
4205 unsigned int hash, i, depth = 1;
4206 bool replacing = false;
4207 int ins_index = -1;
4208 u64 cookie;
4209 s32 rc;
4210
4211 /* Must be an RX filter without RSS and not for a multicast
4212 * destination address (RFS only works for connected sockets).
4213 * These restrictions allow us to pass only a tiny amount of
4214 * data through to the completion function.
4215 */
4216 EFX_WARN_ON_PARANOID(spec->flags !=
4217 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4218 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4219 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4220
4221 hash = efx_ef10_filter_hash(spec);
4222
4223 spin_lock_bh(&efx->filter_lock);
4224
4225 /* Find any existing filter with the same match tuple or else
4226 * a free slot to insert at. If an existing filter is busy,
4227 * we have to give up.
4228 */
4229 for (;;) {
4230 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4231 saved_spec = efx_ef10_filter_entry_spec(table, i);
4232
4233 if (!saved_spec) {
4234 if (ins_index < 0)
4235 ins_index = i;
4236 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4237 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4238 rc = -EBUSY;
4239 goto fail_unlock;
4240 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004241 if (spec->priority < saved_spec->priority) {
4242 rc = -EPERM;
4243 goto fail_unlock;
4244 }
4245 ins_index = i;
4246 break;
4247 }
4248
4249 /* Once we reach the maximum search depth, use the
4250 * first suitable slot or return -EBUSY if there was
4251 * none
4252 */
4253 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4254 if (ins_index < 0) {
4255 rc = -EBUSY;
4256 goto fail_unlock;
4257 }
4258 break;
4259 }
4260
4261 ++depth;
4262 }
4263
4264 /* Create a software table entry if necessary, and mark it
4265 * busy. We might yet fail to insert, but any attempt to
4266 * insert a conflicting filter while we're waiting for the
4267 * firmware must find the busy entry.
4268 */
4269 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4270 if (saved_spec) {
4271 replacing = true;
4272 } else {
4273 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4274 if (!saved_spec) {
4275 rc = -ENOMEM;
4276 goto fail_unlock;
4277 }
4278 *saved_spec = *spec;
4279 }
4280 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4281 EFX_EF10_FILTER_FLAG_BUSY);
4282
4283 spin_unlock_bh(&efx->filter_lock);
4284
4285 /* Pack up the variables needed on completion */
4286 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4287
4288 efx_ef10_filter_push_prep(efx, spec, inbuf,
4289 table->entry[ins_index].handle, replacing);
4290 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4291 MC_CMD_FILTER_OP_OUT_LEN,
4292 efx_ef10_filter_rfs_insert_complete, cookie);
4293
4294 return ins_index;
4295
4296fail_unlock:
4297 spin_unlock_bh(&efx->filter_lock);
4298 return rc;
4299}
4300
4301static void
4302efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4303 int rc, efx_dword_t *outbuf,
4304 size_t outlen_actual)
4305{
4306 struct efx_ef10_filter_table *table = efx->filter_state;
4307 unsigned int ins_index, dmaq_id;
4308 struct efx_filter_spec *spec;
4309 bool replacing;
4310
4311 /* Unpack the cookie */
4312 replacing = cookie >> 31;
4313 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4314 dmaq_id = cookie & 0xffff;
4315
4316 spin_lock_bh(&efx->filter_lock);
4317 spec = efx_ef10_filter_entry_spec(table, ins_index);
4318 if (rc == 0) {
4319 table->entry[ins_index].handle =
4320 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4321 if (replacing)
4322 spec->dmaq_id = dmaq_id;
4323 } else if (!replacing) {
4324 kfree(spec);
4325 spec = NULL;
4326 }
4327 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4328 spin_unlock_bh(&efx->filter_lock);
4329
4330 wake_up_all(&table->waitq);
4331}
4332
4333static void
4334efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4335 unsigned long filter_idx,
4336 int rc, efx_dword_t *outbuf,
4337 size_t outlen_actual);
4338
4339static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4340 unsigned int filter_idx)
4341{
4342 struct efx_ef10_filter_table *table = efx->filter_state;
4343 struct efx_filter_spec *spec =
4344 efx_ef10_filter_entry_spec(table, filter_idx);
4345 MCDI_DECLARE_BUF(inbuf,
4346 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4347 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4348
4349 if (!spec ||
4350 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4351 spec->priority != EFX_FILTER_PRI_HINT ||
4352 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4353 flow_id, filter_idx))
4354 return false;
4355
4356 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4357 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4358 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4359 table->entry[filter_idx].handle);
4360 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4361 efx_ef10_filter_rfs_expire_complete, filter_idx))
4362 return false;
4363
4364 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4365 return true;
4366}
4367
4368static void
4369efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4370 unsigned long filter_idx,
4371 int rc, efx_dword_t *outbuf,
4372 size_t outlen_actual)
4373{
4374 struct efx_ef10_filter_table *table = efx->filter_state;
4375 struct efx_filter_spec *spec =
4376 efx_ef10_filter_entry_spec(table, filter_idx);
4377
4378 spin_lock_bh(&efx->filter_lock);
4379 if (rc == 0) {
4380 kfree(spec);
4381 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4382 }
4383 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4384 wake_up_all(&table->waitq);
4385 spin_unlock_bh(&efx->filter_lock);
4386}
4387
4388#endif /* CONFIG_RFS_ACCEL */
4389
4390static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4391{
4392 int match_flags = 0;
4393
4394#define MAP_FLAG(gen_flag, mcdi_field) { \
4395 u32 old_mcdi_flags = mcdi_flags; \
4396 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4397 mcdi_field ## _LBN); \
4398 if (mcdi_flags != old_mcdi_flags) \
4399 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4400 }
4401 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4402 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4403 MAP_FLAG(REM_HOST, SRC_IP);
4404 MAP_FLAG(LOC_HOST, DST_IP);
4405 MAP_FLAG(REM_MAC, SRC_MAC);
4406 MAP_FLAG(REM_PORT, SRC_PORT);
4407 MAP_FLAG(LOC_MAC, DST_MAC);
4408 MAP_FLAG(LOC_PORT, DST_PORT);
4409 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4410 MAP_FLAG(INNER_VID, INNER_VLAN);
4411 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4412 MAP_FLAG(IP_PROTO, IP_PROTO);
4413#undef MAP_FLAG
4414
4415 /* Did we map them all? */
4416 if (mcdi_flags)
4417 return -EINVAL;
4418
4419 return match_flags;
4420}
4421
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004422static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4423{
4424 struct efx_ef10_filter_table *table = efx->filter_state;
4425 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4426
4427 /* See comment in efx_ef10_filter_table_remove() */
4428 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4429 return;
4430
4431 if (!table)
4432 return;
4433
4434 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4435 efx_ef10_filter_del_vlan_internal(efx, vlan);
4436}
4437
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004438static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4439 enum efx_filter_match_flags match_flags)
4440{
4441 unsigned int match_pri;
4442 int mf;
4443
4444 for (match_pri = 0;
4445 match_pri < table->rx_match_count;
4446 match_pri++) {
4447 mf = efx_ef10_filter_match_flags_from_mcdi(
4448 table->rx_match_mcdi_flags[match_pri]);
4449 if (mf == match_flags)
4450 return true;
4451 }
4452
4453 return false;
4454}
4455
Ben Hutchings8127d662013-08-29 19:19:29 +01004456static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4457{
4458 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4459 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004460 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004461 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004462 unsigned int pd_match_pri, pd_match_count;
4463 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004464 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004465 size_t outlen;
4466 int rc;
4467
Edward Creedd987082016-06-15 17:43:43 +01004468 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4469 return -EINVAL;
4470
4471 if (efx->filter_state) /* already probed */
4472 return 0;
4473
Ben Hutchings8127d662013-08-29 19:19:29 +01004474 table = kzalloc(sizeof(*table), GFP_KERNEL);
4475 if (!table)
4476 return -ENOMEM;
4477
4478 /* Find out which RX filter types are supported, and their priorities */
4479 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4480 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4481 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4482 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4483 &outlen);
4484 if (rc)
4485 goto fail;
4486 pd_match_count = MCDI_VAR_ARRAY_LEN(
4487 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4488 table->rx_match_count = 0;
4489
4490 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4491 u32 mcdi_flags =
4492 MCDI_ARRAY_DWORD(
4493 outbuf,
4494 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4495 pd_match_pri);
4496 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4497 if (rc < 0) {
4498 netif_dbg(efx, probe, efx->net_dev,
4499 "%s: fw flags %#x pri %u not supported in driver\n",
4500 __func__, mcdi_flags, pd_match_pri);
4501 } else {
4502 netif_dbg(efx, probe, efx->net_dev,
4503 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4504 __func__, mcdi_flags, pd_match_pri,
4505 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004506 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4507 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004508 }
4509 }
4510
Martin Habetse4478ad2016-06-15 17:51:07 +01004511 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4512 !(efx_ef10_filter_match_supported(table,
4513 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4514 efx_ef10_filter_match_supported(table,
4515 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4516 netif_info(efx, probe, net_dev,
4517 "VLAN filters are not supported in this firmware variant\n");
4518 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4519 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4520 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4521 }
4522
Ben Hutchings8127d662013-08-29 19:19:29 +01004523 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4524 if (!table->entry) {
4525 rc = -ENOMEM;
4526 goto fail;
4527 }
4528
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004529 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004530 table->vlan_filter =
4531 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004532 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004533
Ben Hutchings8127d662013-08-29 19:19:29 +01004534 efx->filter_state = table;
4535 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004536
4537 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4538 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4539 if (rc)
4540 goto fail_add_vlan;
4541 }
4542
Ben Hutchings8127d662013-08-29 19:19:29 +01004543 return 0;
4544
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004545fail_add_vlan:
4546 efx_ef10_filter_cleanup_vlans(efx);
4547 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004548fail:
4549 kfree(table);
4550 return rc;
4551}
4552
Edward Cree0d322412015-05-20 11:10:03 +01004553/* Caller must hold efx->filter_sem for read if race against
4554 * efx_ef10_filter_table_remove() is possible
4555 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004556static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4557{
4558 struct efx_ef10_filter_table *table = efx->filter_state;
4559 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004560 unsigned int invalid_filters = 0, failed = 0;
4561 struct efx_ef10_filter_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004562 struct efx_filter_spec *spec;
4563 unsigned int filter_idx;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004564 u32 mcdi_flags;
4565 int match_pri;
Ben Hutchings8127d662013-08-29 19:19:29 +01004566 int rc;
4567
Edward Cree0d322412015-05-20 11:10:03 +01004568 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4569
Ben Hutchings8127d662013-08-29 19:19:29 +01004570 if (!nic_data->must_restore_filters)
4571 return;
4572
Edward Cree0d322412015-05-20 11:10:03 +01004573 if (!table)
4574 return;
4575
Ben Hutchings8127d662013-08-29 19:19:29 +01004576 spin_lock_bh(&efx->filter_lock);
4577
4578 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4579 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4580 if (!spec)
4581 continue;
4582
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004583 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4584 match_pri = 0;
4585 while (match_pri < table->rx_match_count &&
4586 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
4587 ++match_pri;
4588 if (match_pri >= table->rx_match_count) {
4589 invalid_filters++;
4590 goto not_restored;
4591 }
4592 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4593 spec->rss_context != nic_data->rx_rss_context)
4594 netif_warn(efx, drv, efx->net_dev,
4595 "Warning: unable to restore a filter with specific RSS context.\n");
4596
Ben Hutchings8127d662013-08-29 19:19:29 +01004597 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4598 spin_unlock_bh(&efx->filter_lock);
4599
4600 rc = efx_ef10_filter_push(efx, spec,
4601 &table->entry[filter_idx].handle,
4602 false);
4603 if (rc)
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004604 failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004605 spin_lock_bh(&efx->filter_lock);
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004606
Ben Hutchings8127d662013-08-29 19:19:29 +01004607 if (rc) {
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004608not_restored:
4609 list_for_each_entry(vlan, &table->vlan_list, list) {
4610 if (vlan->ucdef == filter_idx)
4611 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
4612 if (vlan->mcdef == filter_idx)
4613 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
4614 if (vlan->bcast == filter_idx)
4615 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
4616 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004617 kfree(spec);
4618 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4619 } else {
4620 table->entry[filter_idx].spec &=
4621 ~EFX_EF10_FILTER_FLAG_BUSY;
4622 }
4623 }
4624
4625 spin_unlock_bh(&efx->filter_lock);
4626
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004627 /* This can happen validly if the MC's capabilities have changed, so
4628 * is not an error.
4629 */
4630 if (invalid_filters)
4631 netif_dbg(efx, drv, efx->net_dev,
4632 "Did not restore %u filters that are now unsupported.\n",
4633 invalid_filters);
4634
Ben Hutchings8127d662013-08-29 19:19:29 +01004635 if (failed)
4636 netif_err(efx, hw, efx->net_dev,
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004637 "unable to restore %u filters\n", failed);
Ben Hutchings8127d662013-08-29 19:19:29 +01004638 else
4639 nic_data->must_restore_filters = false;
4640}
4641
4642static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4643{
4644 struct efx_ef10_filter_table *table = efx->filter_state;
4645 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4646 struct efx_filter_spec *spec;
4647 unsigned int filter_idx;
4648 int rc;
4649
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004650 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004651 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004652 /* If we were called without locking, then it's not safe to free
4653 * the table as others might be using it. So we just WARN, leak
4654 * the memory, and potentially get an inconsistent filter table
4655 * state.
4656 * This should never actually happen.
4657 */
4658 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4659 return;
4660
Edward Cree0d322412015-05-20 11:10:03 +01004661 if (!table)
4662 return;
4663
Ben Hutchings8127d662013-08-29 19:19:29 +01004664 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4665 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4666 if (!spec)
4667 continue;
4668
4669 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4670 efx_ef10_filter_is_exclusive(spec) ?
4671 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4672 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4673 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4674 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004675 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4676 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004677 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004678 netif_info(efx, drv, efx->net_dev,
4679 "%s: filter %04x remove failed\n",
4680 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004681 kfree(spec);
4682 }
4683
4684 vfree(table->entry);
4685 kfree(table);
4686}
4687
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004688static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4689{
4690 struct efx_ef10_filter_table *table = efx->filter_state;
4691 unsigned int filter_idx;
4692
4693 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4694 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4695 if (!table->entry[filter_idx].spec)
4696 netif_dbg(efx, drv, efx->net_dev,
4697 "marked null spec old %04x:%04x\n", *id,
4698 filter_idx);
4699 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4700 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004701 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004702}
4703
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004704/* Mark old per-VLAN filters that may need to be removed */
4705static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4706 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004707{
4708 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004709 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004710
Edward Cree12fb0da2015-07-21 15:11:00 +01004711 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004712 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004713 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004714 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4715 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4716 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4717 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004718}
4719
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004720/* Mark old filters that may need to be removed.
4721 * Caller must hold efx->filter_sem for read if race against
4722 * efx_ef10_filter_table_remove() is possible
4723 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004724static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4725{
4726 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004727 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004728
4729 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004730 list_for_each_entry(vlan, &table->vlan_list, list)
4731 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004732 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004733}
Ben Hutchings8127d662013-08-29 19:19:29 +01004734
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004735static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004736{
4737 struct efx_ef10_filter_table *table = efx->filter_state;
4738 struct net_device *net_dev = efx->net_dev;
4739 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004740 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004741 unsigned int i;
4742
Edward Cree12fb0da2015-07-21 15:11:00 +01004743 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004744 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004745 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004746 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4747 i = 1;
4748 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004749 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004750 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004751 break;
4752 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004753 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4754 i++;
4755 }
4756}
4757
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004758static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004759{
4760 struct efx_ef10_filter_table *table = efx->filter_state;
4761 struct net_device *net_dev = efx->net_dev;
4762 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004763 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004764
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004765 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004766
Edward Cree12fb0da2015-07-21 15:11:00 +01004767 addr_count = netdev_mc_count(net_dev);
4768 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004769 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004770 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004771 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004772 break;
4773 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004774 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4775 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004776 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004777
4778 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004779}
Ben Hutchings8127d662013-08-29 19:19:29 +01004780
Edward Cree12fb0da2015-07-21 15:11:00 +01004781static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004782 struct efx_ef10_filter_vlan *vlan,
4783 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004784{
4785 struct efx_ef10_filter_table *table = efx->filter_state;
4786 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004787 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004788 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004789 u8 baddr[ETH_ALEN];
4790 unsigned int i, j;
4791 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004792 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004793 int rc;
4794
4795 if (multicast) {
4796 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004797 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004798 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004799 } else {
4800 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004801 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004802 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004803 }
4804
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004805 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4806
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004807 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004808 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004809 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004810 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004811 rc = efx_ef10_filter_insert(efx, &spec, true);
4812 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004813 if (rollback) {
4814 netif_info(efx, drv, efx->net_dev,
4815 "efx_ef10_filter_insert failed rc=%d\n",
4816 rc);
4817 /* Fall back to promiscuous */
4818 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004819 efx_ef10_filter_remove_unsafe(
4820 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004821 ids[j]);
4822 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004823 }
4824 return rc;
4825 } else {
4826 /* mark as not inserted, and carry on */
4827 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004828 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004829 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004830 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004831 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004832
Edward Cree12fb0da2015-07-21 15:11:00 +01004833 if (multicast && rollback) {
4834 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004835 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004836 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004837 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004838 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004839 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004840 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004841 "Broadcast filter insert failed rc=%d\n", rc);
4842 /* Fall back to promiscuous */
4843 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004844 efx_ef10_filter_remove_unsafe(
4845 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004846 ids[j]);
4847 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004848 }
4849 return rc;
4850 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004851 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004852 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004853 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004854 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004855 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004856
4857 return 0;
4858}
4859
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004860static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4861 struct efx_ef10_filter_vlan *vlan,
4862 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004863{
Edward Cree12fb0da2015-07-21 15:11:00 +01004864 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004865 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004866 struct efx_filter_spec spec;
4867 u8 baddr[ETH_ALEN];
4868 int rc;
4869
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004870 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4871
4872 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004873
4874 if (multicast)
4875 efx_filter_set_mc_def(&spec);
4876 else
4877 efx_filter_set_uc_def(&spec);
4878
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004879 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4880 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4881
Edward Cree12fb0da2015-07-21 15:11:00 +01004882 rc = efx_ef10_filter_insert(efx, &spec, true);
4883 if (rc < 0) {
Jon Cooper34e7aef2017-01-27 15:02:39 +00004884 netif_cond_dbg(efx, drv, efx->net_dev,
4885 rc == -EPERM, warn,
4886 "%scast mismatch filter insert failed rc=%d\n",
4887 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004888 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004889 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4890 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004891 if (!nic_data->workaround_26807) {
4892 /* Also need an Ethernet broadcast filter */
4893 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004894 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004895 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004896 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004897 rc = efx_ef10_filter_insert(efx, &spec, true);
4898 if (rc < 0) {
4899 netif_warn(efx, drv, efx->net_dev,
4900 "Broadcast filter insert failed rc=%d\n",
4901 rc);
4902 if (rollback) {
4903 /* Roll back the mc_def filter */
4904 efx_ef10_filter_remove_unsafe(
4905 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004906 vlan->mcdef);
4907 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004908 return rc;
4909 }
4910 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004911 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004912 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004913 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004914 }
4915 }
4916 rc = 0;
4917 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004918 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4919 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004920 rc = 0;
4921 }
4922 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004923}
4924
4925/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4926 * flag or removes these filters, we don't need to hold the filter_lock while
4927 * scanning for these filters.
4928 */
4929static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4930{
4931 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004932 int remove_failed = 0;
4933 int remove_noent = 0;
4934 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004935 int i;
4936
Ben Hutchings8127d662013-08-29 19:19:29 +01004937 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4938 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004939 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004940 rc = efx_ef10_filter_remove_internal(efx,
4941 1U << EFX_FILTER_PRI_AUTO, i, true);
4942 if (rc == -ENOENT)
4943 remove_noent++;
4944 else if (rc)
4945 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004946 }
4947 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004948
4949 if (remove_failed)
4950 netif_info(efx, drv, efx->net_dev,
4951 "%s: failed to remove %d filters\n",
4952 __func__, remove_failed);
4953 if (remove_noent)
4954 netif_info(efx, drv, efx->net_dev,
4955 "%s: failed to remove %d non-existent filters\n",
4956 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004957}
4958
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004959static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4960{
4961 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4962 u8 mac_old[ETH_ALEN];
4963 int rc, rc2;
4964
4965 /* Only reconfigure a PF-created vport */
4966 if (is_zero_ether_addr(nic_data->vport_mac))
4967 return 0;
4968
4969 efx_device_detach_sync(efx);
4970 efx_net_stop(efx->net_dev);
4971 down_write(&efx->filter_sem);
4972 efx_ef10_filter_table_remove(efx);
4973 up_write(&efx->filter_sem);
4974
4975 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4976 if (rc)
4977 goto restore_filters;
4978
4979 ether_addr_copy(mac_old, nic_data->vport_mac);
4980 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4981 nic_data->vport_mac);
4982 if (rc)
4983 goto restore_vadaptor;
4984
4985 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4986 efx->net_dev->dev_addr);
4987 if (!rc) {
4988 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4989 } else {
4990 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4991 if (rc2) {
4992 /* Failed to add original MAC, so clear vport_mac */
4993 eth_zero_addr(nic_data->vport_mac);
4994 goto reset_nic;
4995 }
4996 }
4997
4998restore_vadaptor:
4999 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5000 if (rc2)
5001 goto reset_nic;
5002restore_filters:
5003 down_write(&efx->filter_sem);
5004 rc2 = efx_ef10_filter_table_probe(efx);
5005 up_write(&efx->filter_sem);
5006 if (rc2)
5007 goto reset_nic;
5008
5009 rc2 = efx_net_open(efx->net_dev);
5010 if (rc2)
5011 goto reset_nic;
5012
5013 netif_device_attach(efx->net_dev);
5014
5015 return rc;
5016
5017reset_nic:
5018 netif_err(efx, drv, efx->net_dev,
5019 "Failed to restore when changing MAC address - scheduling reset\n");
5020 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5021
5022 return rc ? rc : rc2;
5023}
5024
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005025/* Caller must hold efx->filter_sem for read if race against
5026 * efx_ef10_filter_table_remove() is possible
5027 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005028static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5029 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005030{
5031 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005032 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005033
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005034 /* Do not install unspecified VID if VLAN filtering is enabled.
5035 * Do not install all specified VIDs if VLAN filtering is disabled.
5036 */
5037 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5038 return;
5039
Edward Cree12fb0da2015-07-21 15:11:00 +01005040 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005041 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005042 efx_ef10_filter_insert_def(efx, vlan, false, false);
5043 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005044 } else {
5045 /* If any of the filters failed to insert, fall back to
5046 * promiscuous mode - add in the uc_def filter. But keep
5047 * our individual unicast filters.
5048 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005049 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
5050 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005051 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005052
Edward Cree12fb0da2015-07-21 15:11:00 +01005053 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005054 /* If changing promiscuous state with cascaded multicast filters, remove
5055 * old filters first, so that packets are dropped rather than duplicated
5056 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005057 if (nic_data->workaround_26807 &&
5058 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005059 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005060 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005061 if (nic_data->workaround_26807) {
5062 /* If we failed to insert promiscuous filters, rollback
5063 * and fall back to individual multicast filters
5064 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005065 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005066 /* Changing promisc state, so remove old filters */
5067 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005068 efx_ef10_filter_insert_addr_list(efx, vlan,
5069 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005070 }
5071 } else {
5072 /* If we failed to insert promiscuous filters, don't
5073 * rollback. Regardless, also insert the mc_list
5074 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005075 efx_ef10_filter_insert_def(efx, vlan, true, false);
5076 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005077 }
5078 } else {
5079 /* If any filters failed to insert, rollback and fall back to
5080 * promiscuous mode - mc_def filter and maybe broadcast. If
5081 * that fails, roll back again and insert as many of our
5082 * individual multicast filters as we can.
5083 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005084 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005085 /* Changing promisc state, so remove old filters */
5086 if (nic_data->workaround_26807)
5087 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005088 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
5089 efx_ef10_filter_insert_addr_list(efx, vlan,
5090 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005091 }
5092 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005093}
5094
5095/* Caller must hold efx->filter_sem for read if race against
5096 * efx_ef10_filter_table_remove() is possible
5097 */
5098static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5099{
5100 struct efx_ef10_filter_table *table = efx->filter_state;
5101 struct net_device *net_dev = efx->net_dev;
5102 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005103 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005104
5105 if (!efx_dev_registered(efx))
5106 return;
5107
5108 if (!table)
5109 return;
5110
5111 efx_ef10_filter_mark_old(efx);
5112
5113 /* Copy/convert the address lists; add the primary station
5114 * address and broadcast address
5115 */
5116 netif_addr_lock_bh(net_dev);
5117 efx_ef10_filter_uc_addr_list(efx);
5118 efx_ef10_filter_mc_addr_list(efx);
5119 netif_addr_unlock_bh(net_dev);
5120
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005121 /* If VLAN filtering changes, all old filters are finally removed.
5122 * Do it in advance to avoid conflicts for unicast untagged and
5123 * VLAN 0 tagged filters.
5124 */
5125 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5126 if (table->vlan_filter != vlan_filter) {
5127 table->vlan_filter = vlan_filter;
5128 efx_ef10_filter_remove_old(efx);
5129 }
5130
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005131 list_for_each_entry(vlan, &table->vlan_list, list)
5132 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005133
5134 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005135 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005136}
5137
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005138static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5139{
5140 struct efx_ef10_filter_table *table = efx->filter_state;
5141 struct efx_ef10_filter_vlan *vlan;
5142
5143 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5144
5145 list_for_each_entry(vlan, &table->vlan_list, list) {
5146 if (vlan->vid == vid)
5147 return vlan;
5148 }
5149
5150 return NULL;
5151}
5152
5153static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5154{
5155 struct efx_ef10_filter_table *table = efx->filter_state;
5156 struct efx_ef10_filter_vlan *vlan;
5157 unsigned int i;
5158
5159 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5160 return -EINVAL;
5161
5162 vlan = efx_ef10_filter_find_vlan(efx, vid);
5163 if (WARN_ON(vlan)) {
5164 netif_err(efx, drv, efx->net_dev,
5165 "VLAN %u already added\n", vid);
5166 return -EALREADY;
5167 }
5168
5169 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5170 if (!vlan)
5171 return -ENOMEM;
5172
5173 vlan->vid = vid;
5174
5175 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5176 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5177 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5178 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5179 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
5180 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
5181 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
5182
5183 list_add_tail(&vlan->list, &table->vlan_list);
5184
5185 if (efx_dev_registered(efx))
5186 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5187
5188 return 0;
5189}
5190
5191static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5192 struct efx_ef10_filter_vlan *vlan)
5193{
5194 unsigned int i;
5195
5196 /* See comment in efx_ef10_filter_table_remove() */
5197 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5198 return;
5199
5200 list_del(&vlan->list);
5201
Edward Cree8c915622016-06-15 17:49:05 +01005202 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005203 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005204 vlan->uc[i]);
5205 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005206 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005207 vlan->mc[i]);
5208 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
5209 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
5210 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005211
5212 kfree(vlan);
5213}
5214
5215static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5216{
5217 struct efx_ef10_filter_vlan *vlan;
5218
5219 /* See comment in efx_ef10_filter_table_remove() */
5220 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5221 return;
5222
5223 vlan = efx_ef10_filter_find_vlan(efx, vid);
5224 if (!vlan) {
5225 netif_err(efx, drv, efx->net_dev,
5226 "VLAN %u not found in filter state\n", vid);
5227 return;
5228 }
5229
5230 efx_ef10_filter_del_vlan_internal(efx, vlan);
5231}
5232
Shradha Shah910c8782015-05-20 11:12:48 +01005233static int efx_ef10_set_mac_address(struct efx_nic *efx)
5234{
5235 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5236 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5237 bool was_enabled = efx->port_enabled;
5238 int rc;
5239
5240 efx_device_detach_sync(efx);
5241 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005242
5243 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005244 down_write(&efx->filter_sem);
5245 efx_ef10_filter_table_remove(efx);
5246
5247 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5248 efx->net_dev->dev_addr);
5249 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5250 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005251 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5252 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005253
5254 efx_ef10_filter_table_probe(efx);
5255 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005256 mutex_unlock(&efx->mac_lock);
5257
Shradha Shah910c8782015-05-20 11:12:48 +01005258 if (was_enabled)
5259 efx_net_open(efx->net_dev);
5260 netif_device_attach(efx->net_dev);
5261
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005262#ifdef CONFIG_SFC_SRIOV
5263 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005264 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5265
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005266 if (rc == -EPERM) {
5267 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005268
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005269 /* Switch to PF and change MAC address on vport */
5270 efx_pf = pci_get_drvdata(pci_dev_pf);
5271
5272 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005273 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005274 efx->net_dev->dev_addr);
5275 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005276 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5277 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5278 unsigned int i;
5279
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005280 /* MAC address successfully changed by VF (with MAC
5281 * spoofing) so update the parent PF if possible.
5282 */
Shradha Shah910c8782015-05-20 11:12:48 +01005283 for (i = 0; i < efx_pf->vf_count; ++i) {
5284 struct ef10_vf *vf = nic_data->vf + i;
5285
5286 if (vf->efx == efx) {
5287 ether_addr_copy(vf->mac,
5288 efx->net_dev->dev_addr);
5289 return 0;
5290 }
5291 }
5292 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005293 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005294#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005295 if (rc == -EPERM) {
5296 netif_err(efx, drv, efx->net_dev,
5297 "Cannot change MAC address; use sfboot to enable"
5298 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005299 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5300 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5301 * fall-back to the method of changing the MAC address on the
5302 * vport. This only applies to PFs because such versions of
5303 * MCFW do not support VFs.
5304 */
5305 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005306 } else {
5307 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5308 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005309 }
5310
Shradha Shah910c8782015-05-20 11:12:48 +01005311 return rc;
5312}
5313
Ben Hutchings8127d662013-08-29 19:19:29 +01005314static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5315{
5316 efx_ef10_filter_sync_rx_mode(efx);
5317
5318 return efx_mcdi_set_mac(efx);
5319}
5320
Shradha Shah862f8942015-05-20 11:08:56 +01005321static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5322{
5323 efx_ef10_filter_sync_rx_mode(efx);
5324
5325 return 0;
5326}
5327
Jon Cooper74cd60a2013-09-16 14:18:51 +01005328static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5329{
5330 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5331
5332 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5333 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5334 NULL, 0, NULL);
5335}
5336
5337/* MC BISTs follow a different poll mechanism to phy BISTs.
5338 * The BIST is done in the poll handler on the MC, and the MCDI command
5339 * will block until the BIST is done.
5340 */
5341static int efx_ef10_poll_bist(struct efx_nic *efx)
5342{
5343 int rc;
5344 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5345 size_t outlen;
5346 u32 result;
5347
5348 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5349 outbuf, sizeof(outbuf), &outlen);
5350 if (rc != 0)
5351 return rc;
5352
5353 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5354 return -EIO;
5355
5356 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5357 switch (result) {
5358 case MC_CMD_POLL_BIST_PASSED:
5359 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5360 return 0;
5361 case MC_CMD_POLL_BIST_TIMEOUT:
5362 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5363 return -EIO;
5364 case MC_CMD_POLL_BIST_FAILED:
5365 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5366 return -EIO;
5367 default:
5368 netif_err(efx, hw, efx->net_dev,
5369 "BIST returned unknown result %u", result);
5370 return -EIO;
5371 }
5372}
5373
5374static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5375{
5376 int rc;
5377
5378 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5379
5380 rc = efx_ef10_start_bist(efx, bist_type);
5381 if (rc != 0)
5382 return rc;
5383
5384 return efx_ef10_poll_bist(efx);
5385}
5386
5387static int
5388efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5389{
5390 int rc, rc2;
5391
5392 efx_reset_down(efx, RESET_TYPE_WORLD);
5393
5394 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5395 NULL, 0, NULL, 0, NULL);
5396 if (rc != 0)
5397 goto out;
5398
5399 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5400 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5401
5402 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5403
5404out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005405 if (rc == -EPERM)
5406 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005407 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5408 return rc ? rc : rc2;
5409}
5410
Ben Hutchings8127d662013-08-29 19:19:29 +01005411#ifdef CONFIG_SFC_MTD
5412
5413struct efx_ef10_nvram_type_info {
5414 u16 type, type_mask;
5415 u8 port;
5416 const char *name;
5417};
5418
5419static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5420 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5421 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5422 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5423 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5424 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5425 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5426 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5427 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5428 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005429 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005430 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5431};
5432
5433static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5434 struct efx_mcdi_mtd_partition *part,
5435 unsigned int type)
5436{
5437 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5438 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5439 const struct efx_ef10_nvram_type_info *info;
5440 size_t size, erase_size, outlen;
5441 bool protected;
5442 int rc;
5443
5444 for (info = efx_ef10_nvram_types; ; info++) {
5445 if (info ==
5446 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5447 return -ENODEV;
5448 if ((type & ~info->type_mask) == info->type)
5449 break;
5450 }
5451 if (info->port != efx_port_num(efx))
5452 return -ENODEV;
5453
5454 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5455 if (rc)
5456 return rc;
5457 if (protected)
5458 return -ENODEV; /* hide it */
5459
5460 part->nvram_type = type;
5461
5462 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5463 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5464 outbuf, sizeof(outbuf), &outlen);
5465 if (rc)
5466 return rc;
5467 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5468 return -EIO;
5469 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5470 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5471 part->fw_subtype = MCDI_DWORD(outbuf,
5472 NVRAM_METADATA_OUT_SUBTYPE);
5473
5474 part->common.dev_type_name = "EF10 NVRAM manager";
5475 part->common.type_name = info->name;
5476
5477 part->common.mtd.type = MTD_NORFLASH;
5478 part->common.mtd.flags = MTD_CAP_NORFLASH;
5479 part->common.mtd.size = size;
5480 part->common.mtd.erasesize = erase_size;
5481
5482 return 0;
5483}
5484
5485static int efx_ef10_mtd_probe(struct efx_nic *efx)
5486{
5487 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5488 struct efx_mcdi_mtd_partition *parts;
5489 size_t outlen, n_parts_total, i, n_parts;
5490 unsigned int type;
5491 int rc;
5492
5493 ASSERT_RTNL();
5494
5495 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5496 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5497 outbuf, sizeof(outbuf), &outlen);
5498 if (rc)
5499 return rc;
5500 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5501 return -EIO;
5502
5503 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5504 if (n_parts_total >
5505 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5506 return -EIO;
5507
5508 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5509 if (!parts)
5510 return -ENOMEM;
5511
5512 n_parts = 0;
5513 for (i = 0; i < n_parts_total; i++) {
5514 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5515 i);
5516 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5517 if (rc == 0)
5518 n_parts++;
5519 else if (rc != -ENODEV)
5520 goto fail;
5521 }
5522
5523 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5524fail:
5525 if (rc)
5526 kfree(parts);
5527 return rc;
5528}
5529
5530#endif /* CONFIG_SFC_MTD */
5531
5532static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5533{
5534 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5535}
5536
Shradha Shah02246a72015-05-06 00:58:14 +01005537static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5538 u32 host_time) {}
5539
Jon Cooperbd9a2652013-11-18 12:54:41 +00005540static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5541 bool temp)
5542{
5543 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5544 int rc;
5545
5546 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5547 channel->sync_events_state == SYNC_EVENTS_VALID ||
5548 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5549 return 0;
5550 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5551
5552 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5553 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5554 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5555 channel->channel);
5556
5557 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5558 inbuf, sizeof(inbuf), NULL, 0, NULL);
5559
5560 if (rc != 0)
5561 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5562 SYNC_EVENTS_DISABLED;
5563
5564 return rc;
5565}
5566
5567static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5568 bool temp)
5569{
5570 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5571 int rc;
5572
5573 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5574 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5575 return 0;
5576 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5577 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5578 return 0;
5579 }
5580 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5581 SYNC_EVENTS_DISABLED;
5582
5583 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5584 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5585 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5586 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5587 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5588 channel->channel);
5589
5590 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5591 inbuf, sizeof(inbuf), NULL, 0, NULL);
5592
5593 return rc;
5594}
5595
5596static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5597 bool temp)
5598{
5599 int (*set)(struct efx_channel *channel, bool temp);
5600 struct efx_channel *channel;
5601
5602 set = en ?
5603 efx_ef10_rx_enable_timestamping :
5604 efx_ef10_rx_disable_timestamping;
5605
5606 efx_for_each_channel(channel, efx) {
5607 int rc = set(channel, temp);
5608 if (en && rc != 0) {
5609 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5610 return rc;
5611 }
5612 }
5613
5614 return 0;
5615}
5616
Shradha Shah02246a72015-05-06 00:58:14 +01005617static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5618 struct hwtstamp_config *init)
5619{
5620 return -EOPNOTSUPP;
5621}
5622
Jon Cooperbd9a2652013-11-18 12:54:41 +00005623static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5624 struct hwtstamp_config *init)
5625{
5626 int rc;
5627
5628 switch (init->rx_filter) {
5629 case HWTSTAMP_FILTER_NONE:
5630 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5631 /* if TX timestamping is still requested then leave PTP on */
5632 return efx_ptp_change_mode(efx,
5633 init->tx_type != HWTSTAMP_TX_OFF, 0);
5634 case HWTSTAMP_FILTER_ALL:
5635 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5636 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5637 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5638 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5639 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5640 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5641 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5642 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5643 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5644 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5645 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5646 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5647 init->rx_filter = HWTSTAMP_FILTER_ALL;
5648 rc = efx_ptp_change_mode(efx, true, 0);
5649 if (!rc)
5650 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5651 if (rc)
5652 efx_ptp_change_mode(efx, false, 0);
5653 return rc;
5654 default:
5655 return -ERANGE;
5656 }
5657}
5658
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005659static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
5660 struct netdev_phys_item_id *ppid)
5661{
5662 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5663
5664 if (!is_valid_ether_addr(nic_data->port_id))
5665 return -EOPNOTSUPP;
5666
5667 ppid->id_len = ETH_ALEN;
5668 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
5669
5670 return 0;
5671}
5672
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005673static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5674{
5675 if (proto != htons(ETH_P_8021Q))
5676 return -EINVAL;
5677
5678 return efx_ef10_add_vlan(efx, vid);
5679}
5680
5681static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5682{
5683 if (proto != htons(ETH_P_8021Q))
5684 return -EINVAL;
5685
5686 return efx_ef10_del_vlan(efx, vid);
5687}
5688
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005689#define EF10_OFFLOAD_FEATURES \
5690 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005691 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005692 NETIF_F_IPV6_CSUM | \
5693 NETIF_F_RXHASH | \
5694 NETIF_F_NTUPLE)
5695
Shradha Shah02246a72015-05-06 00:58:14 +01005696const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005697 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005698 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005699 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005700 .probe = efx_ef10_probe_vf,
5701 .remove = efx_ef10_remove,
5702 .dimension_resources = efx_ef10_dimension_resources,
5703 .init = efx_ef10_init_nic,
5704 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005705 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005706 .map_reset_flags = efx_ef10_map_reset_flags,
5707 .reset = efx_ef10_reset,
5708 .probe_port = efx_mcdi_port_probe,
5709 .remove_port = efx_mcdi_port_remove,
5710 .fini_dmaq = efx_ef10_fini_dmaq,
5711 .prepare_flr = efx_ef10_prepare_flr,
5712 .finish_flr = efx_port_dummy_op_void,
5713 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005714 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005715 .start_stats = efx_port_dummy_op_void,
5716 .pull_stats = efx_port_dummy_op_void,
5717 .stop_stats = efx_port_dummy_op_void,
5718 .set_id_led = efx_mcdi_set_id_led,
5719 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005720 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005721 .check_mac_fault = efx_mcdi_mac_check_fault,
5722 .reconfigure_port = efx_mcdi_port_reconfigure,
5723 .get_wol = efx_ef10_get_wol_vf,
5724 .set_wol = efx_ef10_set_wol_vf,
5725 .resume_wol = efx_port_dummy_op_void,
5726 .mcdi_request = efx_ef10_mcdi_request,
5727 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5728 .mcdi_read_response = efx_ef10_mcdi_read_response,
5729 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005730 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005731 .irq_enable_master = efx_port_dummy_op_void,
5732 .irq_test_generate = efx_ef10_irq_test_generate,
5733 .irq_disable_non_ev = efx_port_dummy_op_void,
5734 .irq_handle_msi = efx_ef10_msi_interrupt,
5735 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5736 .tx_probe = efx_ef10_tx_probe,
5737 .tx_init = efx_ef10_tx_init,
5738 .tx_remove = efx_ef10_tx_remove,
5739 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005740 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005741 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00005742 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005743 .rx_probe = efx_ef10_rx_probe,
5744 .rx_init = efx_ef10_rx_init,
5745 .rx_remove = efx_ef10_rx_remove,
5746 .rx_write = efx_ef10_rx_write,
5747 .rx_defer_refill = efx_ef10_rx_defer_refill,
5748 .ev_probe = efx_ef10_ev_probe,
5749 .ev_init = efx_ef10_ev_init,
5750 .ev_fini = efx_ef10_ev_fini,
5751 .ev_remove = efx_ef10_ev_remove,
5752 .ev_process = efx_ef10_ev_process,
5753 .ev_read_ack = efx_ef10_ev_read_ack,
5754 .ev_test_generate = efx_ef10_ev_test_generate,
5755 .filter_table_probe = efx_ef10_filter_table_probe,
5756 .filter_table_restore = efx_ef10_filter_table_restore,
5757 .filter_table_remove = efx_ef10_filter_table_remove,
5758 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5759 .filter_insert = efx_ef10_filter_insert,
5760 .filter_remove_safe = efx_ef10_filter_remove_safe,
5761 .filter_get_safe = efx_ef10_filter_get_safe,
5762 .filter_clear_rx = efx_ef10_filter_clear_rx,
5763 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5764 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5765 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5766#ifdef CONFIG_RFS_ACCEL
5767 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5768 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5769#endif
5770#ifdef CONFIG_SFC_MTD
5771 .mtd_probe = efx_port_dummy_op_int,
5772#endif
5773 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5774 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005775 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5776 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005777#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005778 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5779 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5780 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005781#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005782 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005783 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005784
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005785 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005786 .revision = EFX_REV_HUNT_A0,
5787 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5788 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5789 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5790 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5791 .can_rx_scatter = true,
5792 .always_rx_scatter = true,
5793 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5794 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005795 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005796 .mcdi_max_ver = 2,
5797 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5798 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5799 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00005800 .rx_hash_key_size = 40,
Shradha Shah02246a72015-05-06 00:58:14 +01005801};
5802
5803const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005804 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005805 .mem_bar = EFX_MEM_BAR,
5806 .mem_map_size = efx_ef10_mem_map_size,
5807 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005808 .remove = efx_ef10_remove,
5809 .dimension_resources = efx_ef10_dimension_resources,
5810 .init = efx_ef10_init_nic,
5811 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005812 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005813 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005814 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005815 .probe_port = efx_mcdi_port_probe,
5816 .remove_port = efx_mcdi_port_remove,
5817 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005818 .prepare_flr = efx_ef10_prepare_flr,
5819 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005820 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005821 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005822 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005823 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005824 .stop_stats = efx_mcdi_mac_stop_stats,
5825 .set_id_led = efx_mcdi_set_id_led,
5826 .push_irq_moderation = efx_ef10_push_irq_moderation,
5827 .reconfigure_mac = efx_ef10_mac_reconfigure,
5828 .check_mac_fault = efx_mcdi_mac_check_fault,
5829 .reconfigure_port = efx_mcdi_port_reconfigure,
5830 .get_wol = efx_ef10_get_wol,
5831 .set_wol = efx_ef10_set_wol,
5832 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005833 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005834 .test_nvram = efx_mcdi_nvram_test_all,
5835 .mcdi_request = efx_ef10_mcdi_request,
5836 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5837 .mcdi_read_response = efx_ef10_mcdi_read_response,
5838 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005839 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005840 .irq_enable_master = efx_port_dummy_op_void,
5841 .irq_test_generate = efx_ef10_irq_test_generate,
5842 .irq_disable_non_ev = efx_port_dummy_op_void,
5843 .irq_handle_msi = efx_ef10_msi_interrupt,
5844 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5845 .tx_probe = efx_ef10_tx_probe,
5846 .tx_init = efx_ef10_tx_init,
5847 .tx_remove = efx_ef10_tx_remove,
5848 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005849 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005850 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00005851 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005852 .rx_probe = efx_ef10_rx_probe,
5853 .rx_init = efx_ef10_rx_init,
5854 .rx_remove = efx_ef10_rx_remove,
5855 .rx_write = efx_ef10_rx_write,
5856 .rx_defer_refill = efx_ef10_rx_defer_refill,
5857 .ev_probe = efx_ef10_ev_probe,
5858 .ev_init = efx_ef10_ev_init,
5859 .ev_fini = efx_ef10_ev_fini,
5860 .ev_remove = efx_ef10_ev_remove,
5861 .ev_process = efx_ef10_ev_process,
5862 .ev_read_ack = efx_ef10_ev_read_ack,
5863 .ev_test_generate = efx_ef10_ev_test_generate,
5864 .filter_table_probe = efx_ef10_filter_table_probe,
5865 .filter_table_restore = efx_ef10_filter_table_restore,
5866 .filter_table_remove = efx_ef10_filter_table_remove,
5867 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5868 .filter_insert = efx_ef10_filter_insert,
5869 .filter_remove_safe = efx_ef10_filter_remove_safe,
5870 .filter_get_safe = efx_ef10_filter_get_safe,
5871 .filter_clear_rx = efx_ef10_filter_clear_rx,
5872 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5873 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5874 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5875#ifdef CONFIG_RFS_ACCEL
5876 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5877 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5878#endif
5879#ifdef CONFIG_SFC_MTD
5880 .mtd_probe = efx_ef10_mtd_probe,
5881 .mtd_rename = efx_mcdi_mtd_rename,
5882 .mtd_read = efx_mcdi_mtd_read,
5883 .mtd_erase = efx_mcdi_mtd_erase,
5884 .mtd_write = efx_mcdi_mtd_write,
5885 .mtd_sync = efx_mcdi_mtd_sync,
5886#endif
5887 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005888 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5889 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005890 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5891 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005892#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005893 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005894 .sriov_init = efx_ef10_sriov_init,
5895 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005896 .sriov_wanted = efx_ef10_sriov_wanted,
5897 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005898 .sriov_flr = efx_ef10_sriov_flr,
5899 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5900 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5901 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5902 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005903 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005904 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5905 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5906 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005907#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005908 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005909 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00005910 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01005911
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005912 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01005913 .revision = EFX_REV_HUNT_A0,
5914 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5915 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5916 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005917 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005918 .can_rx_scatter = true,
5919 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00005920 .option_descriptors = true,
Ben Hutchings8127d662013-08-29 19:19:29 +01005921 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5922 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005923 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005924 .mcdi_max_ver = 2,
5925 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005926 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5927 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00005928 .rx_hash_key_size = 40,
Ben Hutchings8127d662013-08-29 19:19:29 +01005929};