blob: 2ce576919f97ca1d6d1670a2647d39a041396d34 [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);
1173 if (rc)
1174 netif_err(efx, probe, efx->net_dev,
1175 "failed to allocate PIO buffers (%d)\n", rc);
1176 else
1177 netif_dbg(efx, probe, efx->net_dev,
1178 "allocated %u PIO buffers\n", n_piobufs);
1179 }
1180#else
1181 nic_data->n_piobufs = 0;
1182#endif
1183
1184 /* PIO buffers should be mapped with write-combining enabled,
1185 * and we want to make single UC and WC mappings rather than
1186 * several of each (in fact that's the only option if host
1187 * page size is >4K). So we may allocate some extra VIs just
1188 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001189 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001190 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001191 * first half of the next VI. Then the WC mapping begins with
1192 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001193 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001194 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001195 ER_DZ_TX_PIOBUF);
1196 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001197 /* pio_write_vi_base rounds down to give the number of complete
1198 * VIs inside the UC mapping.
1199 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001200 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1201 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1202 nic_data->n_piobufs) *
1203 EFX_VI_PAGE_SIZE) -
1204 uc_mem_map_size);
1205 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1206 } else {
1207 pio_write_vi_base = 0;
1208 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001209 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001210 }
1211
1212 /* In case the last attached driver failed to free VIs, do it now */
1213 rc = efx_ef10_free_vis(efx);
1214 if (rc != 0)
1215 return rc;
1216
1217 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1218 if (rc != 0)
1219 return rc;
1220
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001221 if (nic_data->n_allocated_vis < channel_vis) {
1222 netif_info(efx, drv, efx->net_dev,
1223 "Could not allocate enough VIs to satisfy RSS"
1224 " requirements. Performance may not be optimal.\n");
1225 /* We didn't get the VIs to populate our channels.
1226 * We could keep what we got but then we'd have more
1227 * interrupts than we need.
1228 * Instead calculate new max_channels and restart
1229 */
1230 efx->max_channels = nic_data->n_allocated_vis;
1231 efx->max_tx_channels =
1232 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1233
1234 efx_ef10_free_vis(efx);
1235 return -EAGAIN;
1236 }
1237
Ben Hutchings183233b2013-06-28 21:47:12 +01001238 /* If we didn't get enough VIs to map all the PIO buffers, free the
1239 * PIO buffers
1240 */
1241 if (nic_data->n_piobufs &&
1242 nic_data->n_allocated_vis <
1243 pio_write_vi_base + nic_data->n_piobufs) {
1244 netif_dbg(efx, probe, efx->net_dev,
1245 "%u VIs are not sufficient to map %u PIO buffers\n",
1246 nic_data->n_allocated_vis, nic_data->n_piobufs);
1247 efx_ef10_free_piobufs(efx);
1248 }
1249
1250 /* Shrink the original UC mapping of the memory BAR */
1251 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1252 if (!membase) {
1253 netif_err(efx, probe, efx->net_dev,
1254 "could not shrink memory BAR to %x\n",
1255 uc_mem_map_size);
1256 return -ENOMEM;
1257 }
1258 iounmap(efx->membase);
1259 efx->membase = membase;
1260
1261 /* Set up the WC mapping if needed */
1262 if (wc_mem_map_size) {
1263 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1264 uc_mem_map_size,
1265 wc_mem_map_size);
1266 if (!nic_data->wc_membase) {
1267 netif_err(efx, probe, efx->net_dev,
1268 "could not allocate WC mapping of size %x\n",
1269 wc_mem_map_size);
1270 return -ENOMEM;
1271 }
1272 nic_data->pio_write_vi_base = pio_write_vi_base;
1273 nic_data->pio_write_base =
1274 nic_data->wc_membase +
1275 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1276 uc_mem_map_size);
1277
1278 rc = efx_ef10_link_piobufs(efx);
1279 if (rc)
1280 efx_ef10_free_piobufs(efx);
1281 }
1282
1283 netif_dbg(efx, probe, efx->net_dev,
1284 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1285 &efx->membase_phys, efx->membase, uc_mem_map_size,
1286 nic_data->wc_membase, wc_mem_map_size);
1287
1288 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001289}
1290
1291static int efx_ef10_init_nic(struct efx_nic *efx)
1292{
1293 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1294 int rc;
1295
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001296 if (nic_data->must_check_datapath_caps) {
1297 rc = efx_ef10_init_datapath_caps(efx);
1298 if (rc)
1299 return rc;
1300 nic_data->must_check_datapath_caps = false;
1301 }
1302
Ben Hutchings8127d662013-08-29 19:19:29 +01001303 if (nic_data->must_realloc_vis) {
1304 /* We cannot let the number of VIs change now */
1305 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1306 nic_data->n_allocated_vis);
1307 if (rc)
1308 return rc;
1309 nic_data->must_realloc_vis = false;
1310 }
1311
Ben Hutchings183233b2013-06-28 21:47:12 +01001312 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1313 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1314 if (rc == 0) {
1315 rc = efx_ef10_link_piobufs(efx);
1316 if (rc)
1317 efx_ef10_free_piobufs(efx);
1318 }
1319
1320 /* Log an error on failure, but this is non-fatal */
1321 if (rc)
1322 netif_err(efx, drv, efx->net_dev,
1323 "failed to restore PIO buffers (%d)\n", rc);
1324 nic_data->must_restore_piobufs = false;
1325 }
1326
Jon Cooper267c0152015-05-06 00:59:38 +01001327 /* don't fail init if RSS setup doesn't work */
Edward Cree4fdda952017-01-04 15:10:56 +00001328 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1329 efx->rss_active = (rc == 0);
Jon Cooper267c0152015-05-06 00:59:38 +01001330
Ben Hutchings8127d662013-08-29 19:19:29 +01001331 return 0;
1332}
1333
Jon Cooper3e336262014-01-17 19:48:06 +00001334static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1335{
1336 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001337#ifdef CONFIG_SFC_SRIOV
1338 unsigned int i;
1339#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001340
1341 /* All our allocations have been reset */
1342 nic_data->must_realloc_vis = true;
1343 nic_data->must_restore_filters = true;
1344 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001345 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001346 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001347
1348 /* Driver-created vswitches and vports must be re-created */
1349 nic_data->must_probe_vswitching = true;
1350 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1351#ifdef CONFIG_SFC_SRIOV
1352 if (nic_data->vf)
1353 for (i = 0; i < efx->vf_count; i++)
1354 nic_data->vf[i].vport_id = 0;
1355#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001356}
1357
Jon Cooper087e9022015-05-20 11:11:35 +01001358static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1359{
1360 if (reason == RESET_TYPE_MC_FAILURE)
1361 return RESET_TYPE_DATAPATH;
1362
1363 return efx_mcdi_map_reset_reason(reason);
1364}
1365
Ben Hutchings8127d662013-08-29 19:19:29 +01001366static int efx_ef10_map_reset_flags(u32 *flags)
1367{
1368 enum {
1369 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1370 ETH_RESET_SHARED_SHIFT),
1371 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1372 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1373 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1374 ETH_RESET_SHARED_SHIFT)
1375 };
1376
1377 /* We assume for now that our PCI function is permitted to
1378 * reset everything.
1379 */
1380
1381 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1382 *flags &= ~EF10_RESET_MC;
1383 return RESET_TYPE_WORLD;
1384 }
1385
1386 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1387 *flags &= ~EF10_RESET_PORT;
1388 return RESET_TYPE_ALL;
1389 }
1390
1391 /* no invisible reset implemented */
1392
1393 return -EINVAL;
1394}
1395
Jon Cooper3e336262014-01-17 19:48:06 +00001396static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1397{
1398 int rc = efx_mcdi_reset(efx, reset_type);
1399
Daniel Pieczko27324822015-07-31 11:14:54 +01001400 /* Unprivileged functions return -EPERM, but need to return success
1401 * here so that the datapath is brought back up.
1402 */
1403 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1404 rc = 0;
1405
Jon Cooper3e336262014-01-17 19:48:06 +00001406 /* If it was a port reset, trigger reallocation of MC resources.
1407 * Note that on an MC reset nothing needs to be done now because we'll
1408 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001409 * For an FLR, we never get an MC reset event, but the MC has reset all
1410 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001411 */
Edward Creee2835462014-04-16 19:27:48 +01001412 if ((reset_type == RESET_TYPE_ALL ||
1413 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001414 efx_ef10_reset_mc_allocations(efx);
1415 return rc;
1416}
1417
Ben Hutchings8127d662013-08-29 19:19:29 +01001418#define EF10_DMA_STAT(ext_name, mcdi_name) \
1419 [EF10_STAT_ ## ext_name] = \
1420 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1421#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1422 [EF10_STAT_ ## int_name] = \
1423 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1424#define EF10_OTHER_STAT(ext_name) \
1425 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001426#define GENERIC_SW_STAT(ext_name) \
1427 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001428
1429static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001430 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1431 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1432 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1433 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1434 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1435 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1436 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1437 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1438 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1439 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1440 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1441 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1442 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1443 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1444 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1445 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1446 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1447 EF10_OTHER_STAT(port_rx_good_bytes),
1448 EF10_OTHER_STAT(port_rx_bad_bytes),
1449 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1450 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1451 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1452 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1453 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1454 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1455 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1456 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1457 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1458 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1459 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1460 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1461 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1462 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1463 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1464 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1465 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1466 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1467 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1468 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1469 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1470 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001471 GENERIC_SW_STAT(rx_nodesc_trunc),
1472 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001473 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1474 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1475 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1476 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1477 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1478 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1479 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1480 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1481 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1482 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1483 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1484 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001485 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1486 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1487 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1488 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1489 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1490 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1491 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1492 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1493 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1494 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1495 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1496 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1497 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1498 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1499 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1500 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1501 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1502 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001503};
1504
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001505#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1506 (1ULL << EF10_STAT_port_tx_packets) | \
1507 (1ULL << EF10_STAT_port_tx_pause) | \
1508 (1ULL << EF10_STAT_port_tx_unicast) | \
1509 (1ULL << EF10_STAT_port_tx_multicast) | \
1510 (1ULL << EF10_STAT_port_tx_broadcast) | \
1511 (1ULL << EF10_STAT_port_rx_bytes) | \
1512 (1ULL << \
1513 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1514 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1515 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1516 (1ULL << EF10_STAT_port_rx_packets) | \
1517 (1ULL << EF10_STAT_port_rx_good) | \
1518 (1ULL << EF10_STAT_port_rx_bad) | \
1519 (1ULL << EF10_STAT_port_rx_pause) | \
1520 (1ULL << EF10_STAT_port_rx_control) | \
1521 (1ULL << EF10_STAT_port_rx_unicast) | \
1522 (1ULL << EF10_STAT_port_rx_multicast) | \
1523 (1ULL << EF10_STAT_port_rx_broadcast) | \
1524 (1ULL << EF10_STAT_port_rx_lt64) | \
1525 (1ULL << EF10_STAT_port_rx_64) | \
1526 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1527 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1528 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1529 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1530 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1531 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1532 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1533 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1534 (1ULL << EF10_STAT_port_rx_overflow) | \
1535 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001536 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1537 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001538
Edward Cree69b365c2016-08-26 15:12:41 +01001539/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1540 * For a 10G/40G switchable port we do not expose these because they might
1541 * not include all the packets they should.
1542 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001543 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001544#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1545 (1ULL << EF10_STAT_port_tx_lt64) | \
1546 (1ULL << EF10_STAT_port_tx_64) | \
1547 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1548 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1549 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1550 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1551 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1552 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001553
1554/* These statistics are only provided by the 40G MAC. For a 10G/40G
1555 * switchable port we do expose these because the errors will otherwise
1556 * be silent.
1557 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001558#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1559 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001560
Edward Cree568d7a02013-09-25 17:32:09 +01001561/* These statistics are only provided if the firmware supports the
1562 * capability PM_AND_RXDP_COUNTERS.
1563 */
1564#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001565 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1566 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1567 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1568 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1569 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1570 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1571 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1572 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1573 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1574 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1575 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1576 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001577
Edward Cree4bae9132013-09-27 18:52:49 +01001578static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001579{
Edward Cree4bae9132013-09-27 18:52:49 +01001580 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001581 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001582 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001583
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001584 if (!(efx->mcdi->fn_flags &
1585 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1586 return 0;
1587
Edward Cree69b365c2016-08-26 15:12:41 +01001588 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001589 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001590 /* 8000 series have everything even at 40G */
1591 if (nic_data->datapath_caps2 &
1592 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1593 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1594 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001595 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001596 }
Edward Cree568d7a02013-09-25 17:32:09 +01001597
1598 if (nic_data->datapath_caps &
1599 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1600 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1601
Edward Cree4bae9132013-09-27 18:52:49 +01001602 return raw_mask;
1603}
1604
1605static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1606{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001607 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001608 u64 raw_mask[2];
1609
1610 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1611
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001612 /* Only show vadaptor stats when EVB capability is present */
1613 if (nic_data->datapath_caps &
1614 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1615 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1616 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1617 } else {
1618 raw_mask[1] = 0;
1619 }
Edward Cree4bae9132013-09-27 18:52:49 +01001620
1621#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001622 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001623 mask[0] = raw_mask[0];
1624 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001625#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001626 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001627 mask[0] = raw_mask[0] & 0xffffffff;
1628 mask[1] = raw_mask[0] >> 32;
1629 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001630#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001631}
1632
1633static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1634{
Edward Cree4bae9132013-09-27 18:52:49 +01001635 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1636
1637 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001638 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001639 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001640}
1641
Daniel Pieczkod7788192015-06-02 11:39:20 +01001642static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1643 struct rtnl_link_stats64 *core_stats)
1644{
1645 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1646 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1647 u64 *stats = nic_data->stats;
1648 size_t stats_count = 0, index;
1649
1650 efx_ef10_get_stat_mask(efx, mask);
1651
1652 if (full_stats) {
1653 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1654 if (efx_ef10_stat_desc[index].name) {
1655 *full_stats++ = stats[index];
1656 ++stats_count;
1657 }
1658 }
1659 }
1660
Bert Kenwardfbe43072015-08-26 16:39:03 +01001661 if (!core_stats)
1662 return stats_count;
1663
1664 if (nic_data->datapath_caps &
1665 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1666 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001667 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1668 stats[EF10_STAT_rx_multicast] +
1669 stats[EF10_STAT_rx_broadcast];
1670 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1671 stats[EF10_STAT_tx_multicast] +
1672 stats[EF10_STAT_tx_broadcast];
1673 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1674 stats[EF10_STAT_rx_multicast_bytes] +
1675 stats[EF10_STAT_rx_broadcast_bytes];
1676 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1677 stats[EF10_STAT_tx_multicast_bytes] +
1678 stats[EF10_STAT_tx_broadcast_bytes];
1679 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001680 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001681 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1682 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1683 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1684 core_stats->rx_errors = core_stats->rx_crc_errors;
1685 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001686 } else {
1687 /* Use port stats. */
1688 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1689 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1690 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1691 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1692 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1693 stats[GENERIC_STAT_rx_nodesc_trunc] +
1694 stats[GENERIC_STAT_rx_noskb_drops];
1695 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1696 core_stats->rx_length_errors =
1697 stats[EF10_STAT_port_rx_gtjumbo] +
1698 stats[EF10_STAT_port_rx_length_error];
1699 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1700 core_stats->rx_frame_errors =
1701 stats[EF10_STAT_port_rx_align_error];
1702 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1703 core_stats->rx_errors = (core_stats->rx_length_errors +
1704 core_stats->rx_crc_errors +
1705 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001706 }
1707
1708 return stats_count;
1709}
1710
1711static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001712{
1713 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001714 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001715 __le64 generation_start, generation_end;
1716 u64 *stats = nic_data->stats;
1717 __le64 *dma_stats;
1718
Edward Cree4bae9132013-09-27 18:52:49 +01001719 efx_ef10_get_stat_mask(efx, mask);
1720
Ben Hutchings8127d662013-08-29 19:19:29 +01001721 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001722
1723 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1724 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1725 return 0;
1726 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001727 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001728 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001729 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001730 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1731 if (generation_end != generation_start)
1732 return -EAGAIN;
1733
1734 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001735 efx_nic_fix_nodesc_drop_stat(efx,
1736 &stats[EF10_STAT_port_rx_nodesc_drops]);
1737 stats[EF10_STAT_port_rx_good_bytes] =
1738 stats[EF10_STAT_port_rx_bytes] -
1739 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1740 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1741 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001742 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001743 return 0;
1744}
1745
1746
Daniel Pieczkod7788192015-06-02 11:39:20 +01001747static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1748 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001749{
Ben Hutchings8127d662013-08-29 19:19:29 +01001750 int retry;
1751
1752 /* If we're unlucky enough to read statistics during the DMA, wait
1753 * up to 10ms for it to finish (typically takes <500us)
1754 */
1755 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001756 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001757 break;
1758 udelay(100);
1759 }
1760
Daniel Pieczkod7788192015-06-02 11:39:20 +01001761 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1762}
1763
1764static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1765{
1766 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1767 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1768 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1769 __le64 generation_start, generation_end;
1770 u64 *stats = nic_data->stats;
1771 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1772 struct efx_buffer stats_buf;
1773 __le64 *dma_stats;
1774 int rc;
1775
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001776 spin_unlock_bh(&efx->stats_lock);
1777
1778 if (in_interrupt()) {
1779 /* If in atomic context, cannot update stats. Just update the
1780 * software stats and return so the caller can continue.
1781 */
1782 spin_lock_bh(&efx->stats_lock);
1783 efx_update_sw_stats(efx, stats);
1784 return 0;
1785 }
1786
Daniel Pieczkod7788192015-06-02 11:39:20 +01001787 efx_ef10_get_stat_mask(efx, mask);
1788
1789 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001790 if (rc) {
1791 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001792 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001793 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001794
1795 dma_stats = stats_buf.addr;
1796 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1797
1798 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1799 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001800 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001801 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1802 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1803
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001804 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1805 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001806 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001807 if (rc) {
1808 /* Expect ENOENT if DMA queues have not been set up */
1809 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1810 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1811 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001812 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001813 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001814
1815 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001816 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1817 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001818 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001819 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001820 rmb();
1821 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1822 stats, stats_buf.addr, false);
1823 rmb();
1824 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1825 if (generation_end != generation_start) {
1826 rc = -EAGAIN;
1827 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001828 }
1829
Daniel Pieczkod7788192015-06-02 11:39:20 +01001830 efx_update_sw_stats(efx, stats);
1831out:
1832 efx_nic_free_buffer(efx, &stats_buf);
1833 return rc;
1834}
Ben Hutchings8127d662013-08-29 19:19:29 +01001835
Daniel Pieczkod7788192015-06-02 11:39:20 +01001836static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1837 struct rtnl_link_stats64 *core_stats)
1838{
1839 if (efx_ef10_try_update_nic_stats_vf(efx))
1840 return 0;
1841
1842 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001843}
1844
1845static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1846{
1847 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001848 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001849 efx_dword_t timer_cmd;
1850
Bert Kenward539de7c2016-08-11 13:02:09 +01001851 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001852 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001853 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001854 } else {
1855 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001856 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001857 }
1858
Bert Kenward539de7c2016-08-11 13:02:09 +01001859 if (EFX_EF10_WORKAROUND_61265(efx)) {
1860 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1861 unsigned int ns = usecs * 1000;
1862
1863 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1864 channel->channel);
1865 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1866 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1867 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1868
1869 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1870 inbuf, sizeof(inbuf), 0, NULL, 0);
1871 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1872 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1873
Ben Hutchings8127d662013-08-29 19:19:29 +01001874 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1875 EFE_DD_EVQ_IND_TIMER_FLAGS,
1876 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001877 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001878 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1879 channel->channel);
1880 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001881 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1882
Ben Hutchings8127d662013-08-29 19:19:29 +01001883 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001884 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001885 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1886 channel->channel);
1887 }
1888}
1889
Shradha Shah02246a72015-05-06 00:58:14 +01001890static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1891 struct ethtool_wolinfo *wol) {}
1892
1893static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1894{
1895 return -EOPNOTSUPP;
1896}
1897
Ben Hutchings8127d662013-08-29 19:19:29 +01001898static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1899{
1900 wol->supported = 0;
1901 wol->wolopts = 0;
1902 memset(&wol->sopass, 0, sizeof(wol->sopass));
1903}
1904
1905static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1906{
1907 if (type != 0)
1908 return -EINVAL;
1909 return 0;
1910}
1911
1912static void efx_ef10_mcdi_request(struct efx_nic *efx,
1913 const efx_dword_t *hdr, size_t hdr_len,
1914 const efx_dword_t *sdu, size_t sdu_len)
1915{
1916 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1917 u8 *pdu = nic_data->mcdi_buf.addr;
1918
1919 memcpy(pdu, hdr, hdr_len);
1920 memcpy(pdu + hdr_len, sdu, sdu_len);
1921 wmb();
1922
1923 /* The hardware provides 'low' and 'high' (doorbell) registers
1924 * for passing the 64-bit address of an MCDI request to
1925 * firmware. However the dwords are swapped by firmware. The
1926 * least significant bits of the doorbell are then 0 for all
1927 * MCDI requests due to alignment.
1928 */
1929 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1930 ER_DZ_MC_DB_LWRD);
1931 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1932 ER_DZ_MC_DB_HWRD);
1933}
1934
1935static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1936{
1937 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1938 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1939
1940 rmb();
1941 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1942}
1943
1944static void
1945efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1946 size_t offset, size_t outlen)
1947{
1948 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1949 const u8 *pdu = nic_data->mcdi_buf.addr;
1950
1951 memcpy(outbuf, pdu + offset, outlen);
1952}
1953
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001954static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1955{
1956 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1957
1958 /* All our allocations have been reset */
1959 efx_ef10_reset_mc_allocations(efx);
1960
1961 /* The datapath firmware might have been changed */
1962 nic_data->must_check_datapath_caps = true;
1963
1964 /* MAC statistics have been cleared on the NIC; clear the local
1965 * statistic that we update with efx_update_diff_stat().
1966 */
1967 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1968}
1969
Ben Hutchings8127d662013-08-29 19:19:29 +01001970static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1971{
1972 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1973 int rc;
1974
1975 rc = efx_ef10_get_warm_boot_count(efx);
1976 if (rc < 0) {
1977 /* The firmware is presumably in the process of
1978 * rebooting. However, we are supposed to report each
1979 * reboot just once, so we must only do that once we
1980 * can read and store the updated warm boot count.
1981 */
1982 return 0;
1983 }
1984
1985 if (rc == nic_data->warm_boot_count)
1986 return 0;
1987
1988 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001989 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01001990
Ben Hutchings8127d662013-08-29 19:19:29 +01001991 return -EIO;
1992}
1993
1994/* Handle an MSI interrupt
1995 *
1996 * Handle an MSI hardware interrupt. This routine schedules event
1997 * queue processing. No interrupt acknowledgement cycle is necessary.
1998 * Also, we never need to check that the interrupt is for us, since
1999 * MSI interrupts cannot be shared.
2000 */
2001static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2002{
2003 struct efx_msi_context *context = dev_id;
2004 struct efx_nic *efx = context->efx;
2005
2006 netif_vdbg(efx, intr, efx->net_dev,
2007 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2008
2009 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2010 /* Note test interrupts */
2011 if (context->index == efx->irq_level)
2012 efx->last_irq_cpu = raw_smp_processor_id();
2013
2014 /* Schedule processing of the channel */
2015 efx_schedule_channel_irq(efx->channel[context->index]);
2016 }
2017
2018 return IRQ_HANDLED;
2019}
2020
2021static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2022{
2023 struct efx_nic *efx = dev_id;
2024 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2025 struct efx_channel *channel;
2026 efx_dword_t reg;
2027 u32 queues;
2028
2029 /* Read the ISR which also ACKs the interrupts */
2030 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2031 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2032
2033 if (queues == 0)
2034 return IRQ_NONE;
2035
2036 if (likely(soft_enabled)) {
2037 /* Note test interrupts */
2038 if (queues & (1U << efx->irq_level))
2039 efx->last_irq_cpu = raw_smp_processor_id();
2040
2041 efx_for_each_channel(channel, efx) {
2042 if (queues & 1)
2043 efx_schedule_channel_irq(channel);
2044 queues >>= 1;
2045 }
2046 }
2047
2048 netif_vdbg(efx, intr, efx->net_dev,
2049 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2050 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2051
2052 return IRQ_HANDLED;
2053}
2054
Jon Cooper942e2982016-08-26 15:13:30 +01002055static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002056{
2057 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2058
Jon Cooper942e2982016-08-26 15:13:30 +01002059 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2060 NULL) == 0)
2061 return -ENOTSUPP;
2062
Ben Hutchings8127d662013-08-29 19:19:29 +01002063 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2064
2065 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002066 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002067 inbuf, sizeof(inbuf), NULL, 0, NULL);
2068}
2069
2070static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2071{
2072 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2073 (tx_queue->ptr_mask + 1) *
2074 sizeof(efx_qword_t),
2075 GFP_KERNEL);
2076}
2077
2078/* This writes to the TX_DESC_WPTR and also pushes data */
2079static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2080 const efx_qword_t *txd)
2081{
2082 unsigned int write_ptr;
2083 efx_oword_t reg;
2084
2085 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2086 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2087 reg.qword[0] = *txd;
2088 efx_writeo_page(tx_queue->efx, &reg,
2089 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2090}
2091
Bert Kenwarde9117e52016-11-17 10:51:54 +00002092/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2093 */
2094static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2095 struct sk_buff *skb,
2096 bool *data_mapped)
2097{
2098 struct efx_tx_buffer *buffer;
2099 struct tcphdr *tcp;
2100 struct iphdr *ip;
2101
2102 u16 ipv4_id;
2103 u32 seqnum;
2104 u32 mss;
2105
Edward Creee01b16a2016-12-02 15:51:33 +00002106 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002107
2108 mss = skb_shinfo(skb)->gso_size;
2109
2110 if (unlikely(mss < 4)) {
2111 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2112 return -EINVAL;
2113 }
2114
2115 ip = ip_hdr(skb);
2116 if (ip->version == 4) {
2117 /* Modify IPv4 header if needed. */
2118 ip->tot_len = 0;
2119 ip->check = 0;
2120 ipv4_id = ip->id;
2121 } else {
2122 /* Modify IPv6 header if needed. */
2123 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2124
2125 ipv6->payload_len = 0;
2126 ipv4_id = 0;
2127 }
2128
2129 tcp = tcp_hdr(skb);
2130 seqnum = ntohl(tcp->seq);
2131
2132 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2133
2134 buffer->flags = EFX_TX_BUF_OPTION;
2135 buffer->len = 0;
2136 buffer->unmap_len = 0;
2137 EFX_POPULATE_QWORD_5(buffer->option,
2138 ESF_DZ_TX_DESC_IS_OPT, 1,
2139 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2140 ESF_DZ_TX_TSO_OPTION_TYPE,
2141 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2142 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2143 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2144 );
2145 ++tx_queue->insert_count;
2146
2147 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2148
2149 buffer->flags = EFX_TX_BUF_OPTION;
2150 buffer->len = 0;
2151 buffer->unmap_len = 0;
2152 EFX_POPULATE_QWORD_4(buffer->option,
2153 ESF_DZ_TX_DESC_IS_OPT, 1,
2154 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2155 ESF_DZ_TX_TSO_OPTION_TYPE,
2156 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2157 ESF_DZ_TX_TSO_TCP_MSS, mss
2158 );
2159 ++tx_queue->insert_count;
2160
2161 return 0;
2162}
2163
Edward Cree46d1efd2016-11-17 10:52:36 +00002164static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2165{
2166 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2167 u32 tso_versions = 0;
2168
2169 if (nic_data->datapath_caps &
2170 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2171 tso_versions |= BIT(1);
2172 if (nic_data->datapath_caps2 &
2173 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2174 tso_versions |= BIT(2);
2175 return tso_versions;
2176}
2177
Ben Hutchings8127d662013-08-29 19:19:29 +01002178static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2179{
2180 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2181 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002182 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2183 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2184 struct efx_channel *channel = tx_queue->channel;
2185 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002186 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002187 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002188 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002189 dma_addr_t dma_addr;
2190 efx_qword_t *txd;
2191 int rc;
2192 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002193 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002194
Bert Kenwarde9117e52016-11-17 10:51:54 +00002195 /* TSOv2 is a limited resource that can only be configured on a limited
2196 * number of queues. TSO without checksum offload is not really a thing,
2197 * so we only enable it for those queues.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002198 */
2199 if (csum_offload && (nic_data->datapath_caps2 &
2200 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2201 tso_v2 = true;
2202 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2203 channel->channel);
2204 }
2205
Ben Hutchings8127d662013-08-29 19:19:29 +01002206 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2207 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2208 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2209 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002210 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002211 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002212
2213 dma_addr = tx_queue->txd.buf.dma_addr;
2214
2215 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2216 tx_queue->queue, entries, (u64)dma_addr);
2217
2218 for (i = 0; i < entries; ++i) {
2219 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2220 dma_addr += EFX_BUF_SIZE;
2221 }
2222
2223 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2224
Edward Creee638ee12016-11-17 10:52:07 +00002225 do {
2226 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2227 /* This flag was removed from mcdi_pcol.h for
2228 * the non-_EXT version of INIT_TXQ. However,
2229 * firmware still honours it.
2230 */
2231 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2232 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2233 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2234
2235 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2236 NULL, 0, NULL);
2237 if (rc == -ENOSPC && tso_v2) {
2238 /* Retry without TSOv2 if we're short on contexts. */
2239 tso_v2 = false;
2240 netif_warn(efx, probe, efx->net_dev,
2241 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2242 } else if (rc) {
2243 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2244 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2245 NULL, 0, rc);
2246 goto fail;
2247 }
2248 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002249
2250 /* A previous user of this TX queue might have set us up the
2251 * bomb by writing a descriptor to the TX push collector but
2252 * not the doorbell. (Each collector belongs to a port, not a
2253 * queue or function, so cannot easily be reset.) We must
2254 * attempt to push a no-op descriptor in its place.
2255 */
2256 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2257 tx_queue->insert_count = 1;
2258 txd = efx_tx_desc(tx_queue, 0);
2259 EFX_POPULATE_QWORD_4(*txd,
2260 ESF_DZ_TX_DESC_IS_OPT, true,
2261 ESF_DZ_TX_OPTION_TYPE,
2262 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2263 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2264 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2265 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002266
Bert Kenwarde9117e52016-11-17 10:51:54 +00002267 if (tso_v2) {
2268 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2269 tx_queue->tso_version = 2;
2270 } else if (nic_data->datapath_caps &
2271 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002272 tx_queue->tso_version = 1;
2273 }
2274
Ben Hutchings8127d662013-08-29 19:19:29 +01002275 wmb();
2276 efx_ef10_push_tx_desc(tx_queue, txd);
2277
2278 return;
2279
2280fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002281 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2282 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002283}
2284
2285static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2286{
2287 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002288 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002289 struct efx_nic *efx = tx_queue->efx;
2290 size_t outlen;
2291 int rc;
2292
2293 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2294 tx_queue->queue);
2295
Edward Cree1e0b8122013-05-31 18:36:12 +01002296 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002297 outbuf, sizeof(outbuf), &outlen);
2298
2299 if (rc && rc != -EALREADY)
2300 goto fail;
2301
2302 return;
2303
2304fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002305 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2306 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002307}
2308
2309static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2310{
2311 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2312}
2313
2314/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2315static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2316{
2317 unsigned int write_ptr;
2318 efx_dword_t reg;
2319
2320 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2321 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2322 efx_writed_page(tx_queue->efx, &reg,
2323 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2324}
2325
Bert Kenwarde9117e52016-11-17 10:51:54 +00002326#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2327
2328static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2329 dma_addr_t dma_addr, unsigned int len)
2330{
2331 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2332 /* If we need to break across multiple descriptors we should
2333 * stop at a page boundary. This assumes the length limit is
2334 * greater than the page size.
2335 */
2336 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2337
2338 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2339 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2340 }
2341
2342 return len;
2343}
2344
Ben Hutchings8127d662013-08-29 19:19:29 +01002345static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2346{
2347 unsigned int old_write_count = tx_queue->write_count;
2348 struct efx_tx_buffer *buffer;
2349 unsigned int write_ptr;
2350 efx_qword_t *txd;
2351
Martin Habetsb2663a42015-11-02 12:51:31 +00002352 tx_queue->xmit_more_available = false;
2353 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2354 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002355
2356 do {
2357 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2358 buffer = &tx_queue->buffer[write_ptr];
2359 txd = efx_tx_desc(tx_queue, write_ptr);
2360 ++tx_queue->write_count;
2361
2362 /* Create TX descriptor ring entry */
2363 if (buffer->flags & EFX_TX_BUF_OPTION) {
2364 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002365 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2366 /* PIO descriptor */
2367 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002368 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002369 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002370 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2371 EFX_POPULATE_QWORD_3(
2372 *txd,
2373 ESF_DZ_TX_KER_CONT,
2374 buffer->flags & EFX_TX_BUF_CONT,
2375 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2376 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2377 }
2378 } while (tx_queue->write_count != tx_queue->insert_count);
2379
2380 wmb(); /* Ensure descriptors are written before they are fetched */
2381
2382 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2383 txd = efx_tx_desc(tx_queue,
2384 old_write_count & tx_queue->ptr_mask);
2385 efx_ef10_push_tx_desc(tx_queue, txd);
2386 ++tx_queue->pushes;
2387 } else {
2388 efx_ef10_notify_tx_desc(tx_queue);
2389 }
2390}
2391
Edward Creea33a4c72016-11-03 22:12:27 +00002392#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2393 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2394#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2395 1 << RSS_MODE_HASH_DST_PORT_LBN)
2396#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2397 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2398 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2399 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2400 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2401 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2402 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2403 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2404 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2405 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2406
2407static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2408{
2409 /* Firmware had a bug (sfc bug 61952) where it would not actually
2410 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2411 * This meant that it would always contain whatever was previously
2412 * in the MCDI buffer. Fortunately, all firmware versions with
2413 * this bug have the same default flags value for a newly-allocated
2414 * RSS context, and the only time we want to get the flags is just
2415 * after allocating. Moreover, the response has a 32-bit hole
2416 * where the context ID would be in the request, so we can use an
2417 * overlength buffer in the request and pre-fill the flags field
2418 * with what we believe the default to be. Thus if the firmware
2419 * has the bug, it will leave our pre-filled value in the flags
2420 * field of the response, and we will get the right answer.
2421 *
2422 * However, this does mean that this function should NOT be used if
2423 * the RSS context flags might not be their defaults - it is ONLY
2424 * reliably correct for a newly-allocated RSS context.
2425 */
2426 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2427 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2428 size_t outlen;
2429 int rc;
2430
2431 /* Check we have a hole for the context ID */
2432 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2433 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2434 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2435 RSS_CONTEXT_FLAGS_DEFAULT);
2436 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2437 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2438 if (rc == 0) {
2439 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2440 rc = -EIO;
2441 else
2442 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2443 }
2444 return rc;
2445}
2446
2447/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2448 * If we fail, we just leave the RSS context at its default hash settings,
2449 * which is safe but may slightly reduce performance.
2450 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2451 * just need to set the UDP ports flags (for both IP versions).
2452 */
2453static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2454{
2455 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2456 u32 flags;
2457
2458 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2459
2460 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2461 return;
2462 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2463 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2464 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2465 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002466 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2467 NULL, 0, NULL))
2468 /* Succeeded, so UDP 4-tuple is now enabled */
2469 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002470}
2471
Jon Cooper267c0152015-05-06 00:59:38 +01002472static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2473 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002474{
2475 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2476 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002477 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002478 size_t outlen;
2479 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002480 u32 alloc_type = exclusive ?
2481 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2482 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2483 unsigned rss_spread = exclusive ?
2484 efx->rss_spread :
2485 min(rounddown_pow_of_two(efx->rss_spread),
2486 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2487
2488 if (!exclusive && rss_spread == 1) {
2489 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2490 if (context_size)
2491 *context_size = 1;
2492 return 0;
2493 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002494
Jon Cooperdcb41232016-04-25 16:51:00 +01002495 if (nic_data->datapath_caps &
2496 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2497 return -EOPNOTSUPP;
2498
Ben Hutchings8127d662013-08-29 19:19:29 +01002499 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002500 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002501 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2502 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002503
2504 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2505 outbuf, sizeof(outbuf), &outlen);
2506 if (rc != 0)
2507 return rc;
2508
2509 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2510 return -EIO;
2511
2512 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2513
Jon Cooper267c0152015-05-06 00:59:38 +01002514 if (context_size)
2515 *context_size = rss_spread;
2516
Edward Creea33a4c72016-11-03 22:12:27 +00002517 if (nic_data->datapath_caps &
2518 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2519 efx_ef10_set_rss_flags(efx, *context);
2520
Ben Hutchings8127d662013-08-29 19:19:29 +01002521 return 0;
2522}
2523
2524static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2525{
2526 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2527 int rc;
2528
2529 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2530 context);
2531
2532 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2533 NULL, 0, NULL);
2534 WARN_ON(rc != 0);
2535}
2536
Jon Cooper267c0152015-05-06 00:59:38 +01002537static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2538 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002539{
2540 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2541 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2542 int i, rc;
2543
2544 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2545 context);
2546 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2547 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2548
2549 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2550 MCDI_PTR(tablebuf,
2551 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002552 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002553
2554 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2555 sizeof(tablebuf), NULL, 0, NULL);
2556 if (rc != 0)
2557 return rc;
2558
2559 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2560 context);
2561 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2562 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2563 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2564 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2565 efx->rx_hash_key[i];
2566
2567 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2568 sizeof(keybuf), NULL, 0, NULL);
2569}
2570
2571static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2572{
2573 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2574
2575 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2576 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2577 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2578}
2579
Jon Cooper267c0152015-05-06 00:59:38 +01002580static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2581 unsigned *context_size)
2582{
2583 u32 new_rx_rss_context;
2584 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2585 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2586 false, context_size);
2587
2588 if (rc != 0)
2589 return rc;
2590
2591 nic_data->rx_rss_context = new_rx_rss_context;
2592 nic_data->rx_rss_context_exclusive = false;
2593 efx_set_default_rx_indir_table(efx);
2594 return 0;
2595}
2596
2597static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2598 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002599{
2600 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2601 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002602 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002603
Jon Cooper267c0152015-05-06 00:59:38 +01002604 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2605 !nic_data->rx_rss_context_exclusive) {
2606 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2607 true, NULL);
2608 if (rc == -EOPNOTSUPP)
2609 return rc;
2610 else if (rc != 0)
2611 goto fail1;
2612 } else {
2613 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002614 }
2615
Jon Cooper267c0152015-05-06 00:59:38 +01002616 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2617 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002618 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002619 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002620
Jon Cooper267c0152015-05-06 00:59:38 +01002621 if (nic_data->rx_rss_context != new_rx_rss_context)
2622 efx_ef10_rx_free_indir_table(efx);
2623 nic_data->rx_rss_context = new_rx_rss_context;
2624 nic_data->rx_rss_context_exclusive = true;
2625 if (rx_indir_table != efx->rx_indir_table)
2626 memcpy(efx->rx_indir_table, rx_indir_table,
2627 sizeof(efx->rx_indir_table));
2628 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002629
Jon Cooper267c0152015-05-06 00:59:38 +01002630fail2:
2631 if (new_rx_rss_context != nic_data->rx_rss_context)
2632 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2633fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002634 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002635 return rc;
2636}
2637
2638static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2639 const u32 *rx_indir_table)
2640{
2641 int rc;
2642
2643 if (efx->rss_spread == 1)
2644 return 0;
2645
2646 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2647
2648 if (rc == -ENOBUFS && !user) {
2649 unsigned context_size;
2650 bool mismatch = false;
2651 size_t i;
2652
2653 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2654 i++)
2655 mismatch = rx_indir_table[i] !=
2656 ethtool_rxfh_indir_default(i, efx->rss_spread);
2657
2658 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2659 if (rc == 0) {
2660 if (context_size != efx->rss_spread)
2661 netif_warn(efx, probe, efx->net_dev,
2662 "Could not allocate an exclusive RSS"
2663 " context; allocated a shared one of"
2664 " different size."
2665 " Wanted %u, got %u.\n",
2666 efx->rss_spread, context_size);
2667 else if (mismatch)
2668 netif_warn(efx, probe, efx->net_dev,
2669 "Could not allocate an exclusive RSS"
2670 " context; allocated a shared one but"
2671 " could not apply custom"
2672 " indirection.\n");
2673 else
2674 netif_info(efx, probe, efx->net_dev,
2675 "Could not allocate an exclusive RSS"
2676 " context; allocated a shared one.\n");
2677 }
2678 }
2679 return rc;
2680}
2681
2682static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2683 const u32 *rx_indir_table
2684 __attribute__ ((unused)))
2685{
2686 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2687
2688 if (user)
2689 return -EOPNOTSUPP;
2690 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2691 return 0;
2692 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002693}
2694
2695static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2696{
2697 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2698 (rx_queue->ptr_mask + 1) *
2699 sizeof(efx_qword_t),
2700 GFP_KERNEL);
2701}
2702
2703static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2704{
2705 MCDI_DECLARE_BUF(inbuf,
2706 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2707 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002708 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2709 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2710 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002711 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002712 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002713 dma_addr_t dma_addr;
2714 int rc;
2715 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002716 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002717
2718 rx_queue->scatter_n = 0;
2719 rx_queue->scatter_len = 0;
2720
2721 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2722 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2723 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2724 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2725 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002726 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2727 INIT_RXQ_IN_FLAG_PREFIX, 1,
2728 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002729 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002730 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002731
2732 dma_addr = rx_queue->rxd.buf.dma_addr;
2733
2734 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2735 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2736
2737 for (i = 0; i < entries; ++i) {
2738 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2739 dma_addr += EFX_BUF_SIZE;
2740 }
2741
2742 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2743
2744 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002745 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002746 if (rc)
2747 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2748 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002749}
2750
2751static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2752{
2753 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002754 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002755 struct efx_nic *efx = rx_queue->efx;
2756 size_t outlen;
2757 int rc;
2758
2759 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2760 efx_rx_queue_index(rx_queue));
2761
Edward Cree1e0b8122013-05-31 18:36:12 +01002762 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002763 outbuf, sizeof(outbuf), &outlen);
2764
2765 if (rc && rc != -EALREADY)
2766 goto fail;
2767
2768 return;
2769
2770fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002771 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2772 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002773}
2774
2775static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2776{
2777 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2778}
2779
2780/* This creates an entry in the RX descriptor queue */
2781static inline void
2782efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2783{
2784 struct efx_rx_buffer *rx_buf;
2785 efx_qword_t *rxd;
2786
2787 rxd = efx_rx_desc(rx_queue, index);
2788 rx_buf = efx_rx_buffer(rx_queue, index);
2789 EFX_POPULATE_QWORD_2(*rxd,
2790 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2791 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2792}
2793
2794static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2795{
2796 struct efx_nic *efx = rx_queue->efx;
2797 unsigned int write_count;
2798 efx_dword_t reg;
2799
2800 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2801 write_count = rx_queue->added_count & ~7;
2802 if (rx_queue->notified_count == write_count)
2803 return;
2804
2805 do
2806 efx_ef10_build_rx_desc(
2807 rx_queue,
2808 rx_queue->notified_count & rx_queue->ptr_mask);
2809 while (++rx_queue->notified_count != write_count);
2810
2811 wmb();
2812 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2813 write_count & rx_queue->ptr_mask);
2814 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2815 efx_rx_queue_index(rx_queue));
2816}
2817
2818static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2819
2820static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2821{
2822 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2823 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2824 efx_qword_t event;
2825
2826 EFX_POPULATE_QWORD_2(event,
2827 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2828 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2829
2830 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2831
2832 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2833 * already swapped the data to little-endian order.
2834 */
2835 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2836 sizeof(efx_qword_t));
2837
2838 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2839 inbuf, sizeof(inbuf), 0,
2840 efx_ef10_rx_defer_refill_complete, 0);
2841}
2842
2843static void
2844efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2845 int rc, efx_dword_t *outbuf,
2846 size_t outlen_actual)
2847{
2848 /* nothing to do */
2849}
2850
2851static int efx_ef10_ev_probe(struct efx_channel *channel)
2852{
2853 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2854 (channel->eventq_mask + 1) *
2855 sizeof(efx_qword_t),
2856 GFP_KERNEL);
2857}
2858
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002859static void efx_ef10_ev_fini(struct efx_channel *channel)
2860{
2861 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2862 MCDI_DECLARE_BUF_ERR(outbuf);
2863 struct efx_nic *efx = channel->efx;
2864 size_t outlen;
2865 int rc;
2866
2867 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2868
2869 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2870 outbuf, sizeof(outbuf), &outlen);
2871
2872 if (rc && rc != -EALREADY)
2873 goto fail;
2874
2875 return;
2876
2877fail:
2878 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2879 outbuf, outlen, rc);
2880}
2881
Ben Hutchings8127d662013-08-29 19:19:29 +01002882static int efx_ef10_ev_init(struct efx_channel *channel)
2883{
2884 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002885 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2886 EFX_BUF_SIZE));
2887 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002888 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2889 struct efx_nic *efx = channel->efx;
2890 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002891 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002892 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002893 dma_addr_t dma_addr;
2894 int rc;
2895 int i;
2896
2897 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002898
2899 /* Fill event queue with all ones (i.e. empty events) */
2900 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2901
2902 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2903 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2904 /* INIT_EVQ expects index in vector table, not absolute */
2905 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01002906 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2907 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2908 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2909 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2910 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2911 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2912 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2913
Bert Kenwarda9955602016-08-11 13:01:54 +01002914 if (nic_data->datapath_caps2 &
2915 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2916 /* Use the new generic approach to specifying event queue
2917 * configuration, requesting lower latency or higher throughput.
2918 * The options that actually get used appear in the output.
2919 */
2920 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2921 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2922 INIT_EVQ_V2_IN_FLAG_TYPE,
2923 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2924 } else {
2925 bool cut_thru = !(nic_data->datapath_caps &
2926 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2927
2928 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2929 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2930 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2931 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2932 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2933 }
2934
Ben Hutchings8127d662013-08-29 19:19:29 +01002935 dma_addr = channel->eventq.buf.dma_addr;
2936 for (i = 0; i < entries; ++i) {
2937 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2938 dma_addr += EFX_BUF_SIZE;
2939 }
2940
2941 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2942
2943 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2944 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01002945
2946 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2947 netif_dbg(efx, drv, efx->net_dev,
2948 "Channel %d using event queue flags %08x\n",
2949 channel->channel,
2950 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2951
Ben Hutchings8127d662013-08-29 19:19:29 +01002952 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002953 if (channel->channel || rc)
2954 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002955
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002956 /* Successfully created event queue on channel 0 */
2957 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002958 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01002959 /* GET_WORKAROUNDS was implemented before this workaround,
2960 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01002961 */
2962 nic_data->workaround_26807 = false;
2963 rc = 0;
2964 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002965 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002966 } else {
2967 nic_data->workaround_26807 =
2968 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002969
Edward Cree832dc9e2015-07-21 15:09:31 +01002970 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2971 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002972 unsigned int flags;
2973
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002974 rc = efx_mcdi_set_workaround(efx,
2975 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002976 true, &flags);
2977
2978 if (!rc) {
2979 if (flags &
2980 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2981 netif_info(efx, drv, efx->net_dev,
2982 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002983
2984 /* With MCFW v4.6.x and earlier, the
2985 * boot count will have incremented,
2986 * so re-read the warm_boot_count
2987 * value now to ensure this function
2988 * doesn't think it has changed next
2989 * time it checks.
2990 */
2991 rc = efx_ef10_get_warm_boot_count(efx);
2992 if (rc >= 0) {
2993 nic_data->warm_boot_count = rc;
2994 rc = 0;
2995 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002996 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002997 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002998 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002999 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003000 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003001 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003002 }
3003
3004 if (!rc)
3005 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003006
3007fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003008 efx_ef10_ev_fini(channel);
3009 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003010}
3011
3012static void efx_ef10_ev_remove(struct efx_channel *channel)
3013{
3014 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3015}
3016
3017static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3018 unsigned int rx_queue_label)
3019{
3020 struct efx_nic *efx = rx_queue->efx;
3021
3022 netif_info(efx, hw, efx->net_dev,
3023 "rx event arrived on queue %d labeled as queue %u\n",
3024 efx_rx_queue_index(rx_queue), rx_queue_label);
3025
3026 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3027}
3028
3029static void
3030efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3031 unsigned int actual, unsigned int expected)
3032{
3033 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3034 struct efx_nic *efx = rx_queue->efx;
3035
3036 netif_info(efx, hw, efx->net_dev,
3037 "dropped %d events (index=%d expected=%d)\n",
3038 dropped, actual, expected);
3039
3040 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3041}
3042
3043/* partially received RX was aborted. clean up. */
3044static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3045{
3046 unsigned int rx_desc_ptr;
3047
Ben Hutchings8127d662013-08-29 19:19:29 +01003048 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3049 "scattered RX aborted (dropping %u buffers)\n",
3050 rx_queue->scatter_n);
3051
3052 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3053
3054 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3055 0, EFX_RX_PKT_DISCARD);
3056
3057 rx_queue->removed_count += rx_queue->scatter_n;
3058 rx_queue->scatter_n = 0;
3059 rx_queue->scatter_len = 0;
3060 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3061}
3062
3063static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3064 const efx_qword_t *event)
3065{
3066 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
3067 unsigned int n_descs, n_packets, i;
3068 struct efx_nic *efx = channel->efx;
3069 struct efx_rx_queue *rx_queue;
3070 bool rx_cont;
3071 u16 flags = 0;
3072
3073 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3074 return 0;
3075
3076 /* Basic packet information */
3077 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3078 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3079 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3080 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3081 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3082
Ben Hutchings48ce5632013-11-01 16:42:44 +00003083 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3084 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3085 EFX_QWORD_FMT "\n",
3086 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003087
3088 rx_queue = efx_channel_get_rx_queue(channel);
3089
3090 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3091 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3092
3093 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3094 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3095
3096 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003097 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3098
Ben Hutchings8127d662013-08-29 19:19:29 +01003099 /* detect rx abort */
3100 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003101 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3102 netdev_WARN(efx->net_dev,
3103 "invalid RX abort: scatter_n=%u event="
3104 EFX_QWORD_FMT "\n",
3105 rx_queue->scatter_n,
3106 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003107 efx_ef10_handle_rx_abort(rx_queue);
3108 return 0;
3109 }
3110
Ben Hutchings92a04162013-09-24 23:21:57 +01003111 /* Check that RX completion merging is valid, i.e.
3112 * the current firmware supports it and this is a
3113 * non-scattered packet.
3114 */
3115 if (!(nic_data->datapath_caps &
3116 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3117 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003118 efx_ef10_handle_rx_bad_lbits(
3119 rx_queue, next_ptr_lbits,
3120 (rx_queue->removed_count +
3121 rx_queue->scatter_n + 1) &
3122 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3123 return 0;
3124 }
3125
3126 /* Merged completion for multiple non-scattered packets */
3127 rx_queue->scatter_n = 1;
3128 rx_queue->scatter_len = 0;
3129 n_packets = n_descs;
3130 ++channel->n_rx_merge_events;
3131 channel->n_rx_merge_packets += n_packets;
3132 flags |= EFX_RX_PKT_PREFIX_LEN;
3133 } else {
3134 ++rx_queue->scatter_n;
3135 rx_queue->scatter_len += rx_bytes;
3136 if (rx_cont)
3137 return 0;
3138 n_packets = 1;
3139 }
3140
3141 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
3142 flags |= EFX_RX_PKT_DISCARD;
3143
3144 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
3145 channel->n_rx_ip_hdr_chksum_err += n_packets;
3146 } else if (unlikely(EFX_QWORD_FIELD(*event,
3147 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
3148 channel->n_rx_tcp_udp_chksum_err += n_packets;
3149 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3150 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
3151 flags |= EFX_RX_PKT_CSUMMED;
3152 }
3153
3154 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3155 flags |= EFX_RX_PKT_TCP;
3156
3157 channel->irq_mod_score += 2 * n_packets;
3158
3159 /* Handle received packet(s) */
3160 for (i = 0; i < n_packets; i++) {
3161 efx_rx_packet(rx_queue,
3162 rx_queue->removed_count & rx_queue->ptr_mask,
3163 rx_queue->scatter_n, rx_queue->scatter_len,
3164 flags);
3165 rx_queue->removed_count += rx_queue->scatter_n;
3166 }
3167
3168 rx_queue->scatter_n = 0;
3169 rx_queue->scatter_len = 0;
3170
3171 return n_packets;
3172}
3173
3174static int
3175efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3176{
3177 struct efx_nic *efx = channel->efx;
3178 struct efx_tx_queue *tx_queue;
3179 unsigned int tx_ev_desc_ptr;
3180 unsigned int tx_ev_q_label;
3181 int tx_descs = 0;
3182
3183 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3184 return 0;
3185
3186 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3187 return 0;
3188
3189 /* Transmit completion */
3190 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3191 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3192 tx_queue = efx_channel_get_tx_queue(channel,
3193 tx_ev_q_label % EFX_TXQ_TYPES);
3194 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3195 tx_queue->ptr_mask);
3196 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3197
3198 return tx_descs;
3199}
3200
3201static void
3202efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3203{
3204 struct efx_nic *efx = channel->efx;
3205 int subcode;
3206
3207 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3208
3209 switch (subcode) {
3210 case ESE_DZ_DRV_TIMER_EV:
3211 case ESE_DZ_DRV_WAKE_UP_EV:
3212 break;
3213 case ESE_DZ_DRV_START_UP_EV:
3214 /* event queue init complete. ok. */
3215 break;
3216 default:
3217 netif_err(efx, hw, efx->net_dev,
3218 "channel %d unknown driver event type %d"
3219 " (data " EFX_QWORD_FMT ")\n",
3220 channel->channel, subcode,
3221 EFX_QWORD_VAL(*event));
3222
3223 }
3224}
3225
3226static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3227 efx_qword_t *event)
3228{
3229 struct efx_nic *efx = channel->efx;
3230 u32 subcode;
3231
3232 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3233
3234 switch (subcode) {
3235 case EFX_EF10_TEST:
3236 channel->event_test_cpu = raw_smp_processor_id();
3237 break;
3238 case EFX_EF10_REFILL:
3239 /* The queue must be empty, so we won't receive any rx
3240 * events, so efx_process_channel() won't refill the
3241 * queue. Refill it here
3242 */
Jon Coopercce28792013-10-02 11:04:14 +01003243 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003244 break;
3245 default:
3246 netif_err(efx, hw, efx->net_dev,
3247 "channel %d unknown driver event type %u"
3248 " (data " EFX_QWORD_FMT ")\n",
3249 channel->channel, (unsigned) subcode,
3250 EFX_QWORD_VAL(*event));
3251 }
3252}
3253
3254static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3255{
3256 struct efx_nic *efx = channel->efx;
3257 efx_qword_t event, *p_event;
3258 unsigned int read_ptr;
3259 int ev_code;
3260 int tx_descs = 0;
3261 int spent = 0;
3262
Eric W. Biederman75363a42014-03-14 18:11:22 -07003263 if (quota <= 0)
3264 return spent;
3265
Ben Hutchings8127d662013-08-29 19:19:29 +01003266 read_ptr = channel->eventq_read_ptr;
3267
3268 for (;;) {
3269 p_event = efx_event(channel, read_ptr);
3270 event = *p_event;
3271
3272 if (!efx_event_present(&event))
3273 break;
3274
3275 EFX_SET_QWORD(*p_event);
3276
3277 ++read_ptr;
3278
3279 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3280
3281 netif_vdbg(efx, drv, efx->net_dev,
3282 "processing event on %d " EFX_QWORD_FMT "\n",
3283 channel->channel, EFX_QWORD_VAL(event));
3284
3285 switch (ev_code) {
3286 case ESE_DZ_EV_CODE_MCDI_EV:
3287 efx_mcdi_process_event(channel, &event);
3288 break;
3289 case ESE_DZ_EV_CODE_RX_EV:
3290 spent += efx_ef10_handle_rx_event(channel, &event);
3291 if (spent >= quota) {
3292 /* XXX can we split a merged event to
3293 * avoid going over-quota?
3294 */
3295 spent = quota;
3296 goto out;
3297 }
3298 break;
3299 case ESE_DZ_EV_CODE_TX_EV:
3300 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3301 if (tx_descs > efx->txq_entries) {
3302 spent = quota;
3303 goto out;
3304 } else if (++spent == quota) {
3305 goto out;
3306 }
3307 break;
3308 case ESE_DZ_EV_CODE_DRIVER_EV:
3309 efx_ef10_handle_driver_event(channel, &event);
3310 if (++spent == quota)
3311 goto out;
3312 break;
3313 case EFX_EF10_DRVGEN_EV:
3314 efx_ef10_handle_driver_generated_event(channel, &event);
3315 break;
3316 default:
3317 netif_err(efx, hw, efx->net_dev,
3318 "channel %d unknown event type %d"
3319 " (data " EFX_QWORD_FMT ")\n",
3320 channel->channel, ev_code,
3321 EFX_QWORD_VAL(event));
3322 }
3323 }
3324
3325out:
3326 channel->eventq_read_ptr = read_ptr;
3327 return spent;
3328}
3329
3330static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3331{
3332 struct efx_nic *efx = channel->efx;
3333 efx_dword_t rptr;
3334
3335 if (EFX_EF10_WORKAROUND_35388(efx)) {
3336 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3337 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3338 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3339 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3340
3341 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3342 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3343 ERF_DD_EVQ_IND_RPTR,
3344 (channel->eventq_read_ptr &
3345 channel->eventq_mask) >>
3346 ERF_DD_EVQ_IND_RPTR_WIDTH);
3347 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3348 channel->channel);
3349 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3350 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3351 ERF_DD_EVQ_IND_RPTR,
3352 channel->eventq_read_ptr &
3353 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3354 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3355 channel->channel);
3356 } else {
3357 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3358 channel->eventq_read_ptr &
3359 channel->eventq_mask);
3360 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3361 }
3362}
3363
3364static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3365{
3366 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3367 struct efx_nic *efx = channel->efx;
3368 efx_qword_t event;
3369 int rc;
3370
3371 EFX_POPULATE_QWORD_2(event,
3372 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3373 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3374
3375 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3376
3377 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3378 * already swapped the data to little-endian order.
3379 */
3380 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3381 sizeof(efx_qword_t));
3382
3383 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3384 NULL, 0, NULL);
3385 if (rc != 0)
3386 goto fail;
3387
3388 return;
3389
3390fail:
3391 WARN_ON(true);
3392 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3393}
3394
3395void efx_ef10_handle_drain_event(struct efx_nic *efx)
3396{
3397 if (atomic_dec_and_test(&efx->active_queues))
3398 wake_up(&efx->flush_wq);
3399
3400 WARN_ON(atomic_read(&efx->active_queues) < 0);
3401}
3402
3403static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3404{
3405 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3406 struct efx_channel *channel;
3407 struct efx_tx_queue *tx_queue;
3408 struct efx_rx_queue *rx_queue;
3409 int pending;
3410
3411 /* If the MC has just rebooted, the TX/RX queues will have already been
3412 * torn down, but efx->active_queues needs to be set to zero.
3413 */
3414 if (nic_data->must_realloc_vis) {
3415 atomic_set(&efx->active_queues, 0);
3416 return 0;
3417 }
3418
3419 /* Do not attempt to write to the NIC during EEH recovery */
3420 if (efx->state != STATE_RECOVERY) {
3421 efx_for_each_channel(channel, efx) {
3422 efx_for_each_channel_rx_queue(rx_queue, channel)
3423 efx_ef10_rx_fini(rx_queue);
3424 efx_for_each_channel_tx_queue(tx_queue, channel)
3425 efx_ef10_tx_fini(tx_queue);
3426 }
3427
3428 wait_event_timeout(efx->flush_wq,
3429 atomic_read(&efx->active_queues) == 0,
3430 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3431 pending = atomic_read(&efx->active_queues);
3432 if (pending) {
3433 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3434 pending);
3435 return -ETIMEDOUT;
3436 }
3437 }
3438
3439 return 0;
3440}
3441
Edward Creee2835462014-04-16 19:27:48 +01003442static void efx_ef10_prepare_flr(struct efx_nic *efx)
3443{
3444 atomic_set(&efx->active_queues, 0);
3445}
3446
Ben Hutchings8127d662013-08-29 19:19:29 +01003447static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3448 const struct efx_filter_spec *right)
3449{
3450 if ((left->match_flags ^ right->match_flags) |
3451 ((left->flags ^ right->flags) &
3452 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3453 return false;
3454
3455 return memcmp(&left->outer_vid, &right->outer_vid,
3456 sizeof(struct efx_filter_spec) -
3457 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3458}
3459
3460static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3461{
3462 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3463 return jhash2((const u32 *)&spec->outer_vid,
3464 (sizeof(struct efx_filter_spec) -
3465 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3466 0);
3467 /* XXX should we randomise the initval? */
3468}
3469
3470/* Decide whether a filter should be exclusive or else should allow
3471 * delivery to additional recipients. Currently we decide that
3472 * filters for specific local unicast MAC and IP addresses are
3473 * exclusive.
3474 */
3475static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3476{
3477 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3478 !is_multicast_ether_addr(spec->loc_mac))
3479 return true;
3480
3481 if ((spec->match_flags &
3482 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3483 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3484 if (spec->ether_type == htons(ETH_P_IP) &&
3485 !ipv4_is_multicast(spec->loc_host[0]))
3486 return true;
3487 if (spec->ether_type == htons(ETH_P_IPV6) &&
3488 ((const u8 *)spec->loc_host)[0] != 0xff)
3489 return true;
3490 }
3491
3492 return false;
3493}
3494
3495static struct efx_filter_spec *
3496efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3497 unsigned int filter_idx)
3498{
3499 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3500 ~EFX_EF10_FILTER_FLAGS);
3501}
3502
3503static unsigned int
3504efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3505 unsigned int filter_idx)
3506{
3507 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3508}
3509
3510static void
3511efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3512 unsigned int filter_idx,
3513 const struct efx_filter_spec *spec,
3514 unsigned int flags)
3515{
3516 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3517}
3518
3519static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3520 const struct efx_filter_spec *spec,
3521 efx_dword_t *inbuf, u64 handle,
3522 bool replacing)
3523{
3524 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003525 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003526
3527 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3528
Jon Cooperdcb41232016-04-25 16:51:00 +01003529 /* Remove RSS flag if we don't have an RSS context. */
3530 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3531 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3532 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3533 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3534
Ben Hutchings8127d662013-08-29 19:19:29 +01003535 if (replacing) {
3536 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3537 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3538 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3539 } else {
3540 u32 match_fields = 0;
3541
3542 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3543 efx_ef10_filter_is_exclusive(spec) ?
3544 MC_CMD_FILTER_OP_IN_OP_INSERT :
3545 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3546
3547 /* Convert match flags and values. Unlike almost
3548 * everything else in MCDI, these fields are in
3549 * network byte order.
3550 */
3551 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3552 match_fields |=
3553 is_multicast_ether_addr(spec->loc_mac) ?
3554 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3555 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3556#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3557 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3558 match_fields |= \
3559 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3560 mcdi_field ## _LBN; \
3561 BUILD_BUG_ON( \
3562 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3563 sizeof(spec->gen_field)); \
3564 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3565 &spec->gen_field, sizeof(spec->gen_field)); \
3566 }
3567 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3568 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3569 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3570 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3571 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3572 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3573 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3574 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3575 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3576 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3577#undef COPY_FIELD
3578 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3579 match_fields);
3580 }
3581
Daniel Pieczko45b24492015-05-06 00:57:14 +01003582 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003583 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3584 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3585 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3586 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003587 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003588 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3589 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003590 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3591 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3592 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003593 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003594 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003595 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3596 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003597 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003598 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3599 spec->rss_context !=
3600 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3601 spec->rss_context : nic_data->rx_rss_context);
3602}
3603
3604static int efx_ef10_filter_push(struct efx_nic *efx,
3605 const struct efx_filter_spec *spec,
3606 u64 *handle, bool replacing)
3607{
3608 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3609 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3610 int rc;
3611
3612 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3613 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3614 outbuf, sizeof(outbuf), NULL);
3615 if (rc == 0)
3616 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003617 if (rc == -ENOSPC)
3618 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003619 return rc;
3620}
3621
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003622static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003623{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003624 unsigned int match_flags = spec->match_flags;
3625 u32 mcdi_flags = 0;
3626
3627 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3628 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3629 mcdi_flags |=
3630 is_multicast_ether_addr(spec->loc_mac) ?
3631 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3632 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3633 }
3634
3635#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3636 unsigned int old_match_flags = match_flags; \
3637 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3638 if (match_flags != old_match_flags) \
3639 mcdi_flags |= \
3640 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3641 mcdi_field ## _LBN); \
3642 }
3643 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3644 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3645 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3646 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3647 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3648 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3649 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3650 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3651 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3652 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3653#undef MAP_FILTER_TO_MCDI_FLAG
3654
3655 /* Did we map them all? */
3656 WARN_ON_ONCE(match_flags);
3657
3658 return mcdi_flags;
3659}
3660
3661static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3662 const struct efx_filter_spec *spec)
3663{
3664 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003665 unsigned int match_pri;
3666
3667 for (match_pri = 0;
3668 match_pri < table->rx_match_count;
3669 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003670 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003671 return match_pri;
3672
3673 return -EPROTONOSUPPORT;
3674}
3675
3676static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3677 struct efx_filter_spec *spec,
3678 bool replace_equal)
3679{
3680 struct efx_ef10_filter_table *table = efx->filter_state;
3681 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3682 struct efx_filter_spec *saved_spec;
3683 unsigned int match_pri, hash;
3684 unsigned int priv_flags;
3685 bool replacing = false;
3686 int ins_index = -1;
3687 DEFINE_WAIT(wait);
3688 bool is_mc_recip;
3689 s32 rc;
3690
3691 /* For now, only support RX filters */
3692 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3693 EFX_FILTER_FLAG_RX)
3694 return -EINVAL;
3695
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003696 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003697 if (rc < 0)
3698 return rc;
3699 match_pri = rc;
3700
3701 hash = efx_ef10_filter_hash(spec);
3702 is_mc_recip = efx_filter_is_mc_recipient(spec);
3703 if (is_mc_recip)
3704 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3705
3706 /* Find any existing filters with the same match tuple or
3707 * else a free slot to insert at. If any of them are busy,
3708 * we have to wait and retry.
3709 */
3710 for (;;) {
3711 unsigned int depth = 1;
3712 unsigned int i;
3713
3714 spin_lock_bh(&efx->filter_lock);
3715
3716 for (;;) {
3717 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3718 saved_spec = efx_ef10_filter_entry_spec(table, i);
3719
3720 if (!saved_spec) {
3721 if (ins_index < 0)
3722 ins_index = i;
3723 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3724 if (table->entry[i].spec &
3725 EFX_EF10_FILTER_FLAG_BUSY)
3726 break;
3727 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003728 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003729 rc = -EPERM;
3730 goto out_unlock;
3731 }
3732 if (!is_mc_recip) {
3733 /* This is the only one */
3734 if (spec->priority ==
3735 saved_spec->priority &&
3736 !replace_equal) {
3737 rc = -EEXIST;
3738 goto out_unlock;
3739 }
3740 ins_index = i;
3741 goto found;
3742 } else if (spec->priority >
3743 saved_spec->priority ||
3744 (spec->priority ==
3745 saved_spec->priority &&
3746 replace_equal)) {
3747 if (ins_index < 0)
3748 ins_index = i;
3749 else
3750 __set_bit(depth, mc_rem_map);
3751 }
3752 }
3753
3754 /* Once we reach the maximum search depth, use
3755 * the first suitable slot or return -EBUSY if
3756 * there was none
3757 */
3758 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3759 if (ins_index < 0) {
3760 rc = -EBUSY;
3761 goto out_unlock;
3762 }
3763 goto found;
3764 }
3765
3766 ++depth;
3767 }
3768
3769 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3770 spin_unlock_bh(&efx->filter_lock);
3771 schedule();
3772 }
3773
3774found:
3775 /* Create a software table entry if necessary, and mark it
3776 * busy. We might yet fail to insert, but any attempt to
3777 * insert a conflicting filter while we're waiting for the
3778 * firmware must find the busy entry.
3779 */
3780 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3781 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003782 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3783 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003784 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003785 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3786 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003787 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003788 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003789 rc = ins_index;
3790 goto out_unlock;
3791 }
3792 replacing = true;
3793 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3794 } else {
3795 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3796 if (!saved_spec) {
3797 rc = -ENOMEM;
3798 goto out_unlock;
3799 }
3800 *saved_spec = *spec;
3801 priv_flags = 0;
3802 }
3803 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3804 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3805
3806 /* Mark lower-priority multicast recipients busy prior to removal */
3807 if (is_mc_recip) {
3808 unsigned int depth, i;
3809
3810 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3811 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3812 if (test_bit(depth, mc_rem_map))
3813 table->entry[i].spec |=
3814 EFX_EF10_FILTER_FLAG_BUSY;
3815 }
3816 }
3817
3818 spin_unlock_bh(&efx->filter_lock);
3819
3820 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3821 replacing);
3822
3823 /* Finalise the software table entry */
3824 spin_lock_bh(&efx->filter_lock);
3825 if (rc == 0) {
3826 if (replacing) {
3827 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003828 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3829 saved_spec->flags |=
3830 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003831 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003832 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003833 saved_spec->flags |= spec->flags;
3834 saved_spec->rss_context = spec->rss_context;
3835 saved_spec->dmaq_id = spec->dmaq_id;
3836 }
3837 } else if (!replacing) {
3838 kfree(saved_spec);
3839 saved_spec = NULL;
3840 }
3841 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3842
3843 /* Remove and finalise entries for lower-priority multicast
3844 * recipients
3845 */
3846 if (is_mc_recip) {
3847 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3848 unsigned int depth, i;
3849
3850 memset(inbuf, 0, sizeof(inbuf));
3851
3852 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3853 if (!test_bit(depth, mc_rem_map))
3854 continue;
3855
3856 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3857 saved_spec = efx_ef10_filter_entry_spec(table, i);
3858 priv_flags = efx_ef10_filter_entry_flags(table, i);
3859
3860 if (rc == 0) {
3861 spin_unlock_bh(&efx->filter_lock);
3862 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3863 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3864 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3865 table->entry[i].handle);
3866 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3867 inbuf, sizeof(inbuf),
3868 NULL, 0, NULL);
3869 spin_lock_bh(&efx->filter_lock);
3870 }
3871
3872 if (rc == 0) {
3873 kfree(saved_spec);
3874 saved_spec = NULL;
3875 priv_flags = 0;
3876 } else {
3877 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3878 }
3879 efx_ef10_filter_set_entry(table, i, saved_spec,
3880 priv_flags);
3881 }
3882 }
3883
3884 /* If successful, return the inserted filter ID */
3885 if (rc == 0)
3886 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3887
3888 wake_up_all(&table->waitq);
3889out_unlock:
3890 spin_unlock_bh(&efx->filter_lock);
3891 finish_wait(&table->waitq, &wait);
3892 return rc;
3893}
3894
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003895static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003896{
3897 /* no need to do anything here on EF10 */
3898}
3899
3900/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003901 * If !by_index, remove by ID
3902 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003903 * Filter ID may come from userland and must be range-checked.
3904 */
3905static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003906 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003907 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003908{
3909 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3910 struct efx_ef10_filter_table *table = efx->filter_state;
3911 MCDI_DECLARE_BUF(inbuf,
3912 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3913 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3914 struct efx_filter_spec *spec;
3915 DEFINE_WAIT(wait);
3916 int rc;
3917
3918 /* Find the software table entry and mark it busy. Don't
3919 * remove it yet; any attempt to update while we're waiting
3920 * for the firmware must find the busy entry.
3921 */
3922 for (;;) {
3923 spin_lock_bh(&efx->filter_lock);
3924 if (!(table->entry[filter_idx].spec &
3925 EFX_EF10_FILTER_FLAG_BUSY))
3926 break;
3927 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3928 spin_unlock_bh(&efx->filter_lock);
3929 schedule();
3930 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003931
Ben Hutchings8127d662013-08-29 19:19:29 +01003932 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003933 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003934 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003935 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003936 filter_id / HUNT_FILTER_TBL_ROWS)) {
3937 rc = -ENOENT;
3938 goto out_unlock;
3939 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003940
3941 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003942 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003943 /* Just remove flags */
3944 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003945 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003946 rc = 0;
3947 goto out_unlock;
3948 }
3949
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003950 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003951 rc = -ENOENT;
3952 goto out_unlock;
3953 }
3954
Ben Hutchings8127d662013-08-29 19:19:29 +01003955 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3956 spin_unlock_bh(&efx->filter_lock);
3957
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003958 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003959 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003960
3961 struct efx_filter_spec new_spec = *spec;
3962
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003963 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003964 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003965 (efx_rss_enabled(efx) ?
3966 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003967 new_spec.dmaq_id = 0;
3968 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3969 rc = efx_ef10_filter_push(efx, &new_spec,
3970 &table->entry[filter_idx].handle,
3971 true);
3972
3973 spin_lock_bh(&efx->filter_lock);
3974 if (rc == 0)
3975 *spec = new_spec;
3976 } else {
3977 /* Really remove the filter */
3978
3979 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3980 efx_ef10_filter_is_exclusive(spec) ?
3981 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3982 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3983 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3984 table->entry[filter_idx].handle);
3985 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3986 inbuf, sizeof(inbuf), NULL, 0, NULL);
3987
3988 spin_lock_bh(&efx->filter_lock);
3989 if (rc == 0) {
3990 kfree(spec);
3991 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3992 }
3993 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003994
Ben Hutchings8127d662013-08-29 19:19:29 +01003995 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3996 wake_up_all(&table->waitq);
3997out_unlock:
3998 spin_unlock_bh(&efx->filter_lock);
3999 finish_wait(&table->waitq, &wait);
4000 return rc;
4001}
4002
4003static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4004 enum efx_filter_priority priority,
4005 u32 filter_id)
4006{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004007 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4008 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004009}
4010
Edward Cree12fb0da2015-07-21 15:11:00 +01004011static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
4012{
4013 return filter_id % HUNT_FILTER_TBL_ROWS;
4014}
4015
Edward Cree8c915622016-06-15 17:49:05 +01004016static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4017 enum efx_filter_priority priority,
4018 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004019{
Edward Cree8c915622016-06-15 17:49:05 +01004020 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4021 return;
4022 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004023}
4024
Ben Hutchings8127d662013-08-29 19:19:29 +01004025static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4026 enum efx_filter_priority priority,
4027 u32 filter_id, struct efx_filter_spec *spec)
4028{
4029 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4030 struct efx_ef10_filter_table *table = efx->filter_state;
4031 const struct efx_filter_spec *saved_spec;
4032 int rc;
4033
4034 spin_lock_bh(&efx->filter_lock);
4035 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4036 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004037 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004038 filter_id / HUNT_FILTER_TBL_ROWS) {
4039 *spec = *saved_spec;
4040 rc = 0;
4041 } else {
4042 rc = -ENOENT;
4043 }
4044 spin_unlock_bh(&efx->filter_lock);
4045 return rc;
4046}
4047
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004048static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004049 enum efx_filter_priority priority)
4050{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004051 unsigned int priority_mask;
4052 unsigned int i;
4053 int rc;
4054
4055 priority_mask = (((1U << (priority + 1)) - 1) &
4056 ~(1U << EFX_FILTER_PRI_AUTO));
4057
4058 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4059 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4060 i, true);
4061 if (rc && rc != -ENOENT)
4062 return rc;
4063 }
4064
4065 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004066}
4067
4068static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4069 enum efx_filter_priority priority)
4070{
4071 struct efx_ef10_filter_table *table = efx->filter_state;
4072 unsigned int filter_idx;
4073 s32 count = 0;
4074
4075 spin_lock_bh(&efx->filter_lock);
4076 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4077 if (table->entry[filter_idx].spec &&
4078 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4079 priority)
4080 ++count;
4081 }
4082 spin_unlock_bh(&efx->filter_lock);
4083 return count;
4084}
4085
4086static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4087{
4088 struct efx_ef10_filter_table *table = efx->filter_state;
4089
4090 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4091}
4092
4093static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4094 enum efx_filter_priority priority,
4095 u32 *buf, u32 size)
4096{
4097 struct efx_ef10_filter_table *table = efx->filter_state;
4098 struct efx_filter_spec *spec;
4099 unsigned int filter_idx;
4100 s32 count = 0;
4101
4102 spin_lock_bh(&efx->filter_lock);
4103 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4104 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4105 if (spec && spec->priority == priority) {
4106 if (count == size) {
4107 count = -EMSGSIZE;
4108 break;
4109 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004110 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004111 HUNT_FILTER_TBL_ROWS +
4112 filter_idx);
4113 }
4114 }
4115 spin_unlock_bh(&efx->filter_lock);
4116 return count;
4117}
4118
4119#ifdef CONFIG_RFS_ACCEL
4120
4121static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4122
4123static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4124 struct efx_filter_spec *spec)
4125{
4126 struct efx_ef10_filter_table *table = efx->filter_state;
4127 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4128 struct efx_filter_spec *saved_spec;
4129 unsigned int hash, i, depth = 1;
4130 bool replacing = false;
4131 int ins_index = -1;
4132 u64 cookie;
4133 s32 rc;
4134
4135 /* Must be an RX filter without RSS and not for a multicast
4136 * destination address (RFS only works for connected sockets).
4137 * These restrictions allow us to pass only a tiny amount of
4138 * data through to the completion function.
4139 */
4140 EFX_WARN_ON_PARANOID(spec->flags !=
4141 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4142 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4143 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4144
4145 hash = efx_ef10_filter_hash(spec);
4146
4147 spin_lock_bh(&efx->filter_lock);
4148
4149 /* Find any existing filter with the same match tuple or else
4150 * a free slot to insert at. If an existing filter is busy,
4151 * we have to give up.
4152 */
4153 for (;;) {
4154 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4155 saved_spec = efx_ef10_filter_entry_spec(table, i);
4156
4157 if (!saved_spec) {
4158 if (ins_index < 0)
4159 ins_index = i;
4160 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4161 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4162 rc = -EBUSY;
4163 goto fail_unlock;
4164 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004165 if (spec->priority < saved_spec->priority) {
4166 rc = -EPERM;
4167 goto fail_unlock;
4168 }
4169 ins_index = i;
4170 break;
4171 }
4172
4173 /* Once we reach the maximum search depth, use the
4174 * first suitable slot or return -EBUSY if there was
4175 * none
4176 */
4177 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4178 if (ins_index < 0) {
4179 rc = -EBUSY;
4180 goto fail_unlock;
4181 }
4182 break;
4183 }
4184
4185 ++depth;
4186 }
4187
4188 /* Create a software table entry if necessary, and mark it
4189 * busy. We might yet fail to insert, but any attempt to
4190 * insert a conflicting filter while we're waiting for the
4191 * firmware must find the busy entry.
4192 */
4193 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4194 if (saved_spec) {
4195 replacing = true;
4196 } else {
4197 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4198 if (!saved_spec) {
4199 rc = -ENOMEM;
4200 goto fail_unlock;
4201 }
4202 *saved_spec = *spec;
4203 }
4204 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4205 EFX_EF10_FILTER_FLAG_BUSY);
4206
4207 spin_unlock_bh(&efx->filter_lock);
4208
4209 /* Pack up the variables needed on completion */
4210 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4211
4212 efx_ef10_filter_push_prep(efx, spec, inbuf,
4213 table->entry[ins_index].handle, replacing);
4214 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4215 MC_CMD_FILTER_OP_OUT_LEN,
4216 efx_ef10_filter_rfs_insert_complete, cookie);
4217
4218 return ins_index;
4219
4220fail_unlock:
4221 spin_unlock_bh(&efx->filter_lock);
4222 return rc;
4223}
4224
4225static void
4226efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4227 int rc, efx_dword_t *outbuf,
4228 size_t outlen_actual)
4229{
4230 struct efx_ef10_filter_table *table = efx->filter_state;
4231 unsigned int ins_index, dmaq_id;
4232 struct efx_filter_spec *spec;
4233 bool replacing;
4234
4235 /* Unpack the cookie */
4236 replacing = cookie >> 31;
4237 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4238 dmaq_id = cookie & 0xffff;
4239
4240 spin_lock_bh(&efx->filter_lock);
4241 spec = efx_ef10_filter_entry_spec(table, ins_index);
4242 if (rc == 0) {
4243 table->entry[ins_index].handle =
4244 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4245 if (replacing)
4246 spec->dmaq_id = dmaq_id;
4247 } else if (!replacing) {
4248 kfree(spec);
4249 spec = NULL;
4250 }
4251 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4252 spin_unlock_bh(&efx->filter_lock);
4253
4254 wake_up_all(&table->waitq);
4255}
4256
4257static void
4258efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4259 unsigned long filter_idx,
4260 int rc, efx_dword_t *outbuf,
4261 size_t outlen_actual);
4262
4263static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4264 unsigned int filter_idx)
4265{
4266 struct efx_ef10_filter_table *table = efx->filter_state;
4267 struct efx_filter_spec *spec =
4268 efx_ef10_filter_entry_spec(table, filter_idx);
4269 MCDI_DECLARE_BUF(inbuf,
4270 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4271 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4272
4273 if (!spec ||
4274 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4275 spec->priority != EFX_FILTER_PRI_HINT ||
4276 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4277 flow_id, filter_idx))
4278 return false;
4279
4280 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4281 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4282 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4283 table->entry[filter_idx].handle);
4284 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4285 efx_ef10_filter_rfs_expire_complete, filter_idx))
4286 return false;
4287
4288 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4289 return true;
4290}
4291
4292static void
4293efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4294 unsigned long filter_idx,
4295 int rc, efx_dword_t *outbuf,
4296 size_t outlen_actual)
4297{
4298 struct efx_ef10_filter_table *table = efx->filter_state;
4299 struct efx_filter_spec *spec =
4300 efx_ef10_filter_entry_spec(table, filter_idx);
4301
4302 spin_lock_bh(&efx->filter_lock);
4303 if (rc == 0) {
4304 kfree(spec);
4305 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4306 }
4307 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4308 wake_up_all(&table->waitq);
4309 spin_unlock_bh(&efx->filter_lock);
4310}
4311
4312#endif /* CONFIG_RFS_ACCEL */
4313
4314static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4315{
4316 int match_flags = 0;
4317
4318#define MAP_FLAG(gen_flag, mcdi_field) { \
4319 u32 old_mcdi_flags = mcdi_flags; \
4320 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4321 mcdi_field ## _LBN); \
4322 if (mcdi_flags != old_mcdi_flags) \
4323 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4324 }
4325 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4326 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4327 MAP_FLAG(REM_HOST, SRC_IP);
4328 MAP_FLAG(LOC_HOST, DST_IP);
4329 MAP_FLAG(REM_MAC, SRC_MAC);
4330 MAP_FLAG(REM_PORT, SRC_PORT);
4331 MAP_FLAG(LOC_MAC, DST_MAC);
4332 MAP_FLAG(LOC_PORT, DST_PORT);
4333 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4334 MAP_FLAG(INNER_VID, INNER_VLAN);
4335 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4336 MAP_FLAG(IP_PROTO, IP_PROTO);
4337#undef MAP_FLAG
4338
4339 /* Did we map them all? */
4340 if (mcdi_flags)
4341 return -EINVAL;
4342
4343 return match_flags;
4344}
4345
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004346static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4347{
4348 struct efx_ef10_filter_table *table = efx->filter_state;
4349 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4350
4351 /* See comment in efx_ef10_filter_table_remove() */
4352 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4353 return;
4354
4355 if (!table)
4356 return;
4357
4358 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4359 efx_ef10_filter_del_vlan_internal(efx, vlan);
4360}
4361
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004362static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4363 enum efx_filter_match_flags match_flags)
4364{
4365 unsigned int match_pri;
4366 int mf;
4367
4368 for (match_pri = 0;
4369 match_pri < table->rx_match_count;
4370 match_pri++) {
4371 mf = efx_ef10_filter_match_flags_from_mcdi(
4372 table->rx_match_mcdi_flags[match_pri]);
4373 if (mf == match_flags)
4374 return true;
4375 }
4376
4377 return false;
4378}
4379
Ben Hutchings8127d662013-08-29 19:19:29 +01004380static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4381{
4382 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4383 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004384 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Martin Habetse4478ad2016-06-15 17:51:07 +01004385 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +01004386 unsigned int pd_match_pri, pd_match_count;
4387 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004388 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004389 size_t outlen;
4390 int rc;
4391
Edward Creedd987082016-06-15 17:43:43 +01004392 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4393 return -EINVAL;
4394
4395 if (efx->filter_state) /* already probed */
4396 return 0;
4397
Ben Hutchings8127d662013-08-29 19:19:29 +01004398 table = kzalloc(sizeof(*table), GFP_KERNEL);
4399 if (!table)
4400 return -ENOMEM;
4401
4402 /* Find out which RX filter types are supported, and their priorities */
4403 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4404 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4405 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4406 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4407 &outlen);
4408 if (rc)
4409 goto fail;
4410 pd_match_count = MCDI_VAR_ARRAY_LEN(
4411 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4412 table->rx_match_count = 0;
4413
4414 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4415 u32 mcdi_flags =
4416 MCDI_ARRAY_DWORD(
4417 outbuf,
4418 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4419 pd_match_pri);
4420 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4421 if (rc < 0) {
4422 netif_dbg(efx, probe, efx->net_dev,
4423 "%s: fw flags %#x pri %u not supported in driver\n",
4424 __func__, mcdi_flags, pd_match_pri);
4425 } else {
4426 netif_dbg(efx, probe, efx->net_dev,
4427 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4428 __func__, mcdi_flags, pd_match_pri,
4429 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004430 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4431 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004432 }
4433 }
4434
Martin Habetse4478ad2016-06-15 17:51:07 +01004435 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4436 !(efx_ef10_filter_match_supported(table,
4437 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4438 efx_ef10_filter_match_supported(table,
4439 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4440 netif_info(efx, probe, net_dev,
4441 "VLAN filters are not supported in this firmware variant\n");
4442 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4443 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4444 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4445 }
4446
Ben Hutchings8127d662013-08-29 19:19:29 +01004447 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4448 if (!table->entry) {
4449 rc = -ENOMEM;
4450 goto fail;
4451 }
4452
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004453 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004454 table->vlan_filter =
4455 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004456 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004457
Ben Hutchings8127d662013-08-29 19:19:29 +01004458 efx->filter_state = table;
4459 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004460
4461 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4462 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4463 if (rc)
4464 goto fail_add_vlan;
4465 }
4466
Ben Hutchings8127d662013-08-29 19:19:29 +01004467 return 0;
4468
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004469fail_add_vlan:
4470 efx_ef10_filter_cleanup_vlans(efx);
4471 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004472fail:
4473 kfree(table);
4474 return rc;
4475}
4476
Edward Cree0d322412015-05-20 11:10:03 +01004477/* Caller must hold efx->filter_sem for read if race against
4478 * efx_ef10_filter_table_remove() is possible
4479 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004480static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4481{
4482 struct efx_ef10_filter_table *table = efx->filter_state;
4483 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4484 struct efx_filter_spec *spec;
4485 unsigned int filter_idx;
4486 bool failed = false;
4487 int rc;
4488
Edward Cree0d322412015-05-20 11:10:03 +01004489 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4490
Ben Hutchings8127d662013-08-29 19:19:29 +01004491 if (!nic_data->must_restore_filters)
4492 return;
4493
Edward Cree0d322412015-05-20 11:10:03 +01004494 if (!table)
4495 return;
4496
Ben Hutchings8127d662013-08-29 19:19:29 +01004497 spin_lock_bh(&efx->filter_lock);
4498
4499 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4500 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4501 if (!spec)
4502 continue;
4503
4504 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4505 spin_unlock_bh(&efx->filter_lock);
4506
4507 rc = efx_ef10_filter_push(efx, spec,
4508 &table->entry[filter_idx].handle,
4509 false);
4510 if (rc)
4511 failed = true;
4512
4513 spin_lock_bh(&efx->filter_lock);
4514 if (rc) {
4515 kfree(spec);
4516 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4517 } else {
4518 table->entry[filter_idx].spec &=
4519 ~EFX_EF10_FILTER_FLAG_BUSY;
4520 }
4521 }
4522
4523 spin_unlock_bh(&efx->filter_lock);
4524
4525 if (failed)
4526 netif_err(efx, hw, efx->net_dev,
4527 "unable to restore all filters\n");
4528 else
4529 nic_data->must_restore_filters = false;
4530}
4531
4532static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4533{
4534 struct efx_ef10_filter_table *table = efx->filter_state;
4535 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4536 struct efx_filter_spec *spec;
4537 unsigned int filter_idx;
4538 int rc;
4539
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004540 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004541 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004542 /* If we were called without locking, then it's not safe to free
4543 * the table as others might be using it. So we just WARN, leak
4544 * the memory, and potentially get an inconsistent filter table
4545 * state.
4546 * This should never actually happen.
4547 */
4548 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4549 return;
4550
Edward Cree0d322412015-05-20 11:10:03 +01004551 if (!table)
4552 return;
4553
Ben Hutchings8127d662013-08-29 19:19:29 +01004554 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4555 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4556 if (!spec)
4557 continue;
4558
4559 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4560 efx_ef10_filter_is_exclusive(spec) ?
4561 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4562 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4563 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4564 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004565 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4566 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004567 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004568 netif_info(efx, drv, efx->net_dev,
4569 "%s: filter %04x remove failed\n",
4570 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004571 kfree(spec);
4572 }
4573
4574 vfree(table->entry);
4575 kfree(table);
4576}
4577
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004578static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4579{
4580 struct efx_ef10_filter_table *table = efx->filter_state;
4581 unsigned int filter_idx;
4582
4583 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4584 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4585 if (!table->entry[filter_idx].spec)
4586 netif_dbg(efx, drv, efx->net_dev,
4587 "marked null spec old %04x:%04x\n", *id,
4588 filter_idx);
4589 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4590 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004591 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004592}
4593
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004594/* Mark old per-VLAN filters that may need to be removed */
4595static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4596 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004597{
4598 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004599 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004600
Edward Cree12fb0da2015-07-21 15:11:00 +01004601 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004602 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004603 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004604 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4605 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4606 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4607 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004608}
4609
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004610/* Mark old filters that may need to be removed.
4611 * Caller must hold efx->filter_sem for read if race against
4612 * efx_ef10_filter_table_remove() is possible
4613 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004614static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4615{
4616 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004617 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004618
4619 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004620 list_for_each_entry(vlan, &table->vlan_list, list)
4621 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004622 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004623}
Ben Hutchings8127d662013-08-29 19:19:29 +01004624
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004625static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004626{
4627 struct efx_ef10_filter_table *table = efx->filter_state;
4628 struct net_device *net_dev = efx->net_dev;
4629 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004630 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004631 unsigned int i;
4632
Edward Cree12fb0da2015-07-21 15:11:00 +01004633 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004634 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004635 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004636 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4637 i = 1;
4638 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004639 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004640 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004641 break;
4642 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004643 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4644 i++;
4645 }
4646}
4647
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004648static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004649{
4650 struct efx_ef10_filter_table *table = efx->filter_state;
4651 struct net_device *net_dev = efx->net_dev;
4652 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004653 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004654
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004655 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004656
Edward Cree12fb0da2015-07-21 15:11:00 +01004657 addr_count = netdev_mc_count(net_dev);
4658 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004659 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004660 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004661 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004662 break;
4663 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004664 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4665 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004666 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004667
4668 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004669}
Ben Hutchings8127d662013-08-29 19:19:29 +01004670
Edward Cree12fb0da2015-07-21 15:11:00 +01004671static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004672 struct efx_ef10_filter_vlan *vlan,
4673 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004674{
4675 struct efx_ef10_filter_table *table = efx->filter_state;
4676 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004677 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004678 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004679 u8 baddr[ETH_ALEN];
4680 unsigned int i, j;
4681 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004682 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004683 int rc;
4684
4685 if (multicast) {
4686 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004687 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004688 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004689 } else {
4690 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004691 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004692 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004693 }
4694
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004695 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4696
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004697 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004698 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004699 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004700 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004701 rc = efx_ef10_filter_insert(efx, &spec, true);
4702 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004703 if (rollback) {
4704 netif_info(efx, drv, efx->net_dev,
4705 "efx_ef10_filter_insert failed rc=%d\n",
4706 rc);
4707 /* Fall back to promiscuous */
4708 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004709 efx_ef10_filter_remove_unsafe(
4710 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004711 ids[j]);
4712 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004713 }
4714 return rc;
4715 } else {
4716 /* mark as not inserted, and carry on */
4717 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004718 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004719 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004720 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004721 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004722
Edward Cree12fb0da2015-07-21 15:11:00 +01004723 if (multicast && rollback) {
4724 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004725 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004726 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004727 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004728 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004729 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004730 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004731 "Broadcast filter insert failed rc=%d\n", rc);
4732 /* Fall back to promiscuous */
4733 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004734 efx_ef10_filter_remove_unsafe(
4735 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004736 ids[j]);
4737 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004738 }
4739 return rc;
4740 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004741 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004742 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004743 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004744 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004745 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004746
4747 return 0;
4748}
4749
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004750static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4751 struct efx_ef10_filter_vlan *vlan,
4752 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004753{
Edward Cree12fb0da2015-07-21 15:11:00 +01004754 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004755 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004756 struct efx_filter_spec spec;
4757 u8 baddr[ETH_ALEN];
4758 int rc;
4759
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004760 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4761
4762 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004763
4764 if (multicast)
4765 efx_filter_set_mc_def(&spec);
4766 else
4767 efx_filter_set_uc_def(&spec);
4768
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004769 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4770 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4771
Edward Cree12fb0da2015-07-21 15:11:00 +01004772 rc = efx_ef10_filter_insert(efx, &spec, true);
4773 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004774 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4775 efx->net_dev,
4776 "%scast mismatch filter insert failed rc=%d\n",
4777 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004778 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004779 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4780 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004781 if (!nic_data->workaround_26807) {
4782 /* Also need an Ethernet broadcast filter */
4783 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004784 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004785 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004786 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004787 rc = efx_ef10_filter_insert(efx, &spec, true);
4788 if (rc < 0) {
4789 netif_warn(efx, drv, efx->net_dev,
4790 "Broadcast filter insert failed rc=%d\n",
4791 rc);
4792 if (rollback) {
4793 /* Roll back the mc_def filter */
4794 efx_ef10_filter_remove_unsafe(
4795 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004796 vlan->mcdef);
4797 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004798 return rc;
4799 }
4800 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004801 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004802 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004803 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004804 }
4805 }
4806 rc = 0;
4807 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004808 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4809 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004810 rc = 0;
4811 }
4812 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004813}
4814
4815/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4816 * flag or removes these filters, we don't need to hold the filter_lock while
4817 * scanning for these filters.
4818 */
4819static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4820{
4821 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004822 int remove_failed = 0;
4823 int remove_noent = 0;
4824 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004825 int i;
4826
Ben Hutchings8127d662013-08-29 19:19:29 +01004827 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4828 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004829 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004830 rc = efx_ef10_filter_remove_internal(efx,
4831 1U << EFX_FILTER_PRI_AUTO, i, true);
4832 if (rc == -ENOENT)
4833 remove_noent++;
4834 else if (rc)
4835 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004836 }
4837 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004838
4839 if (remove_failed)
4840 netif_info(efx, drv, efx->net_dev,
4841 "%s: failed to remove %d filters\n",
4842 __func__, remove_failed);
4843 if (remove_noent)
4844 netif_info(efx, drv, efx->net_dev,
4845 "%s: failed to remove %d non-existent filters\n",
4846 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004847}
4848
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004849static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4850{
4851 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4852 u8 mac_old[ETH_ALEN];
4853 int rc, rc2;
4854
4855 /* Only reconfigure a PF-created vport */
4856 if (is_zero_ether_addr(nic_data->vport_mac))
4857 return 0;
4858
4859 efx_device_detach_sync(efx);
4860 efx_net_stop(efx->net_dev);
4861 down_write(&efx->filter_sem);
4862 efx_ef10_filter_table_remove(efx);
4863 up_write(&efx->filter_sem);
4864
4865 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4866 if (rc)
4867 goto restore_filters;
4868
4869 ether_addr_copy(mac_old, nic_data->vport_mac);
4870 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4871 nic_data->vport_mac);
4872 if (rc)
4873 goto restore_vadaptor;
4874
4875 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4876 efx->net_dev->dev_addr);
4877 if (!rc) {
4878 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4879 } else {
4880 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4881 if (rc2) {
4882 /* Failed to add original MAC, so clear vport_mac */
4883 eth_zero_addr(nic_data->vport_mac);
4884 goto reset_nic;
4885 }
4886 }
4887
4888restore_vadaptor:
4889 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4890 if (rc2)
4891 goto reset_nic;
4892restore_filters:
4893 down_write(&efx->filter_sem);
4894 rc2 = efx_ef10_filter_table_probe(efx);
4895 up_write(&efx->filter_sem);
4896 if (rc2)
4897 goto reset_nic;
4898
4899 rc2 = efx_net_open(efx->net_dev);
4900 if (rc2)
4901 goto reset_nic;
4902
4903 netif_device_attach(efx->net_dev);
4904
4905 return rc;
4906
4907reset_nic:
4908 netif_err(efx, drv, efx->net_dev,
4909 "Failed to restore when changing MAC address - scheduling reset\n");
4910 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4911
4912 return rc ? rc : rc2;
4913}
4914
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004915/* Caller must hold efx->filter_sem for read if race against
4916 * efx_ef10_filter_table_remove() is possible
4917 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004918static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4919 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004920{
4921 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004922 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004923
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004924 /* Do not install unspecified VID if VLAN filtering is enabled.
4925 * Do not install all specified VIDs if VLAN filtering is disabled.
4926 */
4927 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4928 return;
4929
Edward Cree12fb0da2015-07-21 15:11:00 +01004930 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004931 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004932 efx_ef10_filter_insert_def(efx, vlan, false, false);
4933 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004934 } else {
4935 /* If any of the filters failed to insert, fall back to
4936 * promiscuous mode - add in the uc_def filter. But keep
4937 * our individual unicast filters.
4938 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004939 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4940 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004941 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004942
Edward Cree12fb0da2015-07-21 15:11:00 +01004943 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004944 /* If changing promiscuous state with cascaded multicast filters, remove
4945 * old filters first, so that packets are dropped rather than duplicated
4946 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004947 if (nic_data->workaround_26807 &&
4948 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004949 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004950 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004951 if (nic_data->workaround_26807) {
4952 /* If we failed to insert promiscuous filters, rollback
4953 * and fall back to individual multicast filters
4954 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004955 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004956 /* Changing promisc state, so remove old filters */
4957 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004958 efx_ef10_filter_insert_addr_list(efx, vlan,
4959 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004960 }
4961 } else {
4962 /* If we failed to insert promiscuous filters, don't
4963 * rollback. Regardless, also insert the mc_list
4964 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004965 efx_ef10_filter_insert_def(efx, vlan, true, false);
4966 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004967 }
4968 } else {
4969 /* If any filters failed to insert, rollback and fall back to
4970 * promiscuous mode - mc_def filter and maybe broadcast. If
4971 * that fails, roll back again and insert as many of our
4972 * individual multicast filters as we can.
4973 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004974 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004975 /* Changing promisc state, so remove old filters */
4976 if (nic_data->workaround_26807)
4977 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004978 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4979 efx_ef10_filter_insert_addr_list(efx, vlan,
4980 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004981 }
4982 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004983}
4984
4985/* Caller must hold efx->filter_sem for read if race against
4986 * efx_ef10_filter_table_remove() is possible
4987 */
4988static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4989{
4990 struct efx_ef10_filter_table *table = efx->filter_state;
4991 struct net_device *net_dev = efx->net_dev;
4992 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004993 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004994
4995 if (!efx_dev_registered(efx))
4996 return;
4997
4998 if (!table)
4999 return;
5000
5001 efx_ef10_filter_mark_old(efx);
5002
5003 /* Copy/convert the address lists; add the primary station
5004 * address and broadcast address
5005 */
5006 netif_addr_lock_bh(net_dev);
5007 efx_ef10_filter_uc_addr_list(efx);
5008 efx_ef10_filter_mc_addr_list(efx);
5009 netif_addr_unlock_bh(net_dev);
5010
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005011 /* If VLAN filtering changes, all old filters are finally removed.
5012 * Do it in advance to avoid conflicts for unicast untagged and
5013 * VLAN 0 tagged filters.
5014 */
5015 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5016 if (table->vlan_filter != vlan_filter) {
5017 table->vlan_filter = vlan_filter;
5018 efx_ef10_filter_remove_old(efx);
5019 }
5020
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005021 list_for_each_entry(vlan, &table->vlan_list, list)
5022 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005023
5024 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005025 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005026}
5027
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005028static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5029{
5030 struct efx_ef10_filter_table *table = efx->filter_state;
5031 struct efx_ef10_filter_vlan *vlan;
5032
5033 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5034
5035 list_for_each_entry(vlan, &table->vlan_list, list) {
5036 if (vlan->vid == vid)
5037 return vlan;
5038 }
5039
5040 return NULL;
5041}
5042
5043static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5044{
5045 struct efx_ef10_filter_table *table = efx->filter_state;
5046 struct efx_ef10_filter_vlan *vlan;
5047 unsigned int i;
5048
5049 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5050 return -EINVAL;
5051
5052 vlan = efx_ef10_filter_find_vlan(efx, vid);
5053 if (WARN_ON(vlan)) {
5054 netif_err(efx, drv, efx->net_dev,
5055 "VLAN %u already added\n", vid);
5056 return -EALREADY;
5057 }
5058
5059 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5060 if (!vlan)
5061 return -ENOMEM;
5062
5063 vlan->vid = vid;
5064
5065 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5066 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5067 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5068 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5069 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
5070 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
5071 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
5072
5073 list_add_tail(&vlan->list, &table->vlan_list);
5074
5075 if (efx_dev_registered(efx))
5076 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5077
5078 return 0;
5079}
5080
5081static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5082 struct efx_ef10_filter_vlan *vlan)
5083{
5084 unsigned int i;
5085
5086 /* See comment in efx_ef10_filter_table_remove() */
5087 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5088 return;
5089
5090 list_del(&vlan->list);
5091
Edward Cree8c915622016-06-15 17:49:05 +01005092 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005093 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005094 vlan->uc[i]);
5095 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005096 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005097 vlan->mc[i]);
5098 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
5099 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
5100 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005101
5102 kfree(vlan);
5103}
5104
5105static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5106{
5107 struct efx_ef10_filter_vlan *vlan;
5108
5109 /* See comment in efx_ef10_filter_table_remove() */
5110 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5111 return;
5112
5113 vlan = efx_ef10_filter_find_vlan(efx, vid);
5114 if (!vlan) {
5115 netif_err(efx, drv, efx->net_dev,
5116 "VLAN %u not found in filter state\n", vid);
5117 return;
5118 }
5119
5120 efx_ef10_filter_del_vlan_internal(efx, vlan);
5121}
5122
Shradha Shah910c8782015-05-20 11:12:48 +01005123static int efx_ef10_set_mac_address(struct efx_nic *efx)
5124{
5125 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5126 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5127 bool was_enabled = efx->port_enabled;
5128 int rc;
5129
5130 efx_device_detach_sync(efx);
5131 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005132
5133 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005134 down_write(&efx->filter_sem);
5135 efx_ef10_filter_table_remove(efx);
5136
5137 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5138 efx->net_dev->dev_addr);
5139 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5140 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005141 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5142 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005143
5144 efx_ef10_filter_table_probe(efx);
5145 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005146 mutex_unlock(&efx->mac_lock);
5147
Shradha Shah910c8782015-05-20 11:12:48 +01005148 if (was_enabled)
5149 efx_net_open(efx->net_dev);
5150 netif_device_attach(efx->net_dev);
5151
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005152#ifdef CONFIG_SFC_SRIOV
5153 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005154 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5155
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005156 if (rc == -EPERM) {
5157 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005158
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005159 /* Switch to PF and change MAC address on vport */
5160 efx_pf = pci_get_drvdata(pci_dev_pf);
5161
5162 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005163 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005164 efx->net_dev->dev_addr);
5165 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005166 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5167 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5168 unsigned int i;
5169
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005170 /* MAC address successfully changed by VF (with MAC
5171 * spoofing) so update the parent PF if possible.
5172 */
Shradha Shah910c8782015-05-20 11:12:48 +01005173 for (i = 0; i < efx_pf->vf_count; ++i) {
5174 struct ef10_vf *vf = nic_data->vf + i;
5175
5176 if (vf->efx == efx) {
5177 ether_addr_copy(vf->mac,
5178 efx->net_dev->dev_addr);
5179 return 0;
5180 }
5181 }
5182 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005183 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005184#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005185 if (rc == -EPERM) {
5186 netif_err(efx, drv, efx->net_dev,
5187 "Cannot change MAC address; use sfboot to enable"
5188 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005189 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5190 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5191 * fall-back to the method of changing the MAC address on the
5192 * vport. This only applies to PFs because such versions of
5193 * MCFW do not support VFs.
5194 */
5195 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005196 } else {
5197 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5198 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005199 }
5200
Shradha Shah910c8782015-05-20 11:12:48 +01005201 return rc;
5202}
5203
Ben Hutchings8127d662013-08-29 19:19:29 +01005204static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5205{
5206 efx_ef10_filter_sync_rx_mode(efx);
5207
5208 return efx_mcdi_set_mac(efx);
5209}
5210
Shradha Shah862f8942015-05-20 11:08:56 +01005211static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5212{
5213 efx_ef10_filter_sync_rx_mode(efx);
5214
5215 return 0;
5216}
5217
Jon Cooper74cd60a2013-09-16 14:18:51 +01005218static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5219{
5220 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5221
5222 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5223 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5224 NULL, 0, NULL);
5225}
5226
5227/* MC BISTs follow a different poll mechanism to phy BISTs.
5228 * The BIST is done in the poll handler on the MC, and the MCDI command
5229 * will block until the BIST is done.
5230 */
5231static int efx_ef10_poll_bist(struct efx_nic *efx)
5232{
5233 int rc;
5234 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5235 size_t outlen;
5236 u32 result;
5237
5238 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5239 outbuf, sizeof(outbuf), &outlen);
5240 if (rc != 0)
5241 return rc;
5242
5243 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5244 return -EIO;
5245
5246 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5247 switch (result) {
5248 case MC_CMD_POLL_BIST_PASSED:
5249 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5250 return 0;
5251 case MC_CMD_POLL_BIST_TIMEOUT:
5252 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5253 return -EIO;
5254 case MC_CMD_POLL_BIST_FAILED:
5255 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5256 return -EIO;
5257 default:
5258 netif_err(efx, hw, efx->net_dev,
5259 "BIST returned unknown result %u", result);
5260 return -EIO;
5261 }
5262}
5263
5264static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5265{
5266 int rc;
5267
5268 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5269
5270 rc = efx_ef10_start_bist(efx, bist_type);
5271 if (rc != 0)
5272 return rc;
5273
5274 return efx_ef10_poll_bist(efx);
5275}
5276
5277static int
5278efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5279{
5280 int rc, rc2;
5281
5282 efx_reset_down(efx, RESET_TYPE_WORLD);
5283
5284 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5285 NULL, 0, NULL, 0, NULL);
5286 if (rc != 0)
5287 goto out;
5288
5289 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5290 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5291
5292 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5293
5294out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005295 if (rc == -EPERM)
5296 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005297 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5298 return rc ? rc : rc2;
5299}
5300
Ben Hutchings8127d662013-08-29 19:19:29 +01005301#ifdef CONFIG_SFC_MTD
5302
5303struct efx_ef10_nvram_type_info {
5304 u16 type, type_mask;
5305 u8 port;
5306 const char *name;
5307};
5308
5309static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5310 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5311 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5312 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5313 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5314 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5315 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5316 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5317 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5318 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005319 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005320 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5321};
5322
5323static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5324 struct efx_mcdi_mtd_partition *part,
5325 unsigned int type)
5326{
5327 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5328 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5329 const struct efx_ef10_nvram_type_info *info;
5330 size_t size, erase_size, outlen;
5331 bool protected;
5332 int rc;
5333
5334 for (info = efx_ef10_nvram_types; ; info++) {
5335 if (info ==
5336 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5337 return -ENODEV;
5338 if ((type & ~info->type_mask) == info->type)
5339 break;
5340 }
5341 if (info->port != efx_port_num(efx))
5342 return -ENODEV;
5343
5344 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5345 if (rc)
5346 return rc;
5347 if (protected)
5348 return -ENODEV; /* hide it */
5349
5350 part->nvram_type = type;
5351
5352 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5353 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5354 outbuf, sizeof(outbuf), &outlen);
5355 if (rc)
5356 return rc;
5357 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5358 return -EIO;
5359 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5360 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5361 part->fw_subtype = MCDI_DWORD(outbuf,
5362 NVRAM_METADATA_OUT_SUBTYPE);
5363
5364 part->common.dev_type_name = "EF10 NVRAM manager";
5365 part->common.type_name = info->name;
5366
5367 part->common.mtd.type = MTD_NORFLASH;
5368 part->common.mtd.flags = MTD_CAP_NORFLASH;
5369 part->common.mtd.size = size;
5370 part->common.mtd.erasesize = erase_size;
5371
5372 return 0;
5373}
5374
5375static int efx_ef10_mtd_probe(struct efx_nic *efx)
5376{
5377 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5378 struct efx_mcdi_mtd_partition *parts;
5379 size_t outlen, n_parts_total, i, n_parts;
5380 unsigned int type;
5381 int rc;
5382
5383 ASSERT_RTNL();
5384
5385 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5386 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5387 outbuf, sizeof(outbuf), &outlen);
5388 if (rc)
5389 return rc;
5390 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5391 return -EIO;
5392
5393 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5394 if (n_parts_total >
5395 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5396 return -EIO;
5397
5398 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5399 if (!parts)
5400 return -ENOMEM;
5401
5402 n_parts = 0;
5403 for (i = 0; i < n_parts_total; i++) {
5404 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5405 i);
5406 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5407 if (rc == 0)
5408 n_parts++;
5409 else if (rc != -ENODEV)
5410 goto fail;
5411 }
5412
5413 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5414fail:
5415 if (rc)
5416 kfree(parts);
5417 return rc;
5418}
5419
5420#endif /* CONFIG_SFC_MTD */
5421
5422static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5423{
5424 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5425}
5426
Shradha Shah02246a72015-05-06 00:58:14 +01005427static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5428 u32 host_time) {}
5429
Jon Cooperbd9a2652013-11-18 12:54:41 +00005430static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5431 bool temp)
5432{
5433 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5434 int rc;
5435
5436 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5437 channel->sync_events_state == SYNC_EVENTS_VALID ||
5438 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5439 return 0;
5440 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5441
5442 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5443 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5444 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5445 channel->channel);
5446
5447 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5448 inbuf, sizeof(inbuf), NULL, 0, NULL);
5449
5450 if (rc != 0)
5451 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5452 SYNC_EVENTS_DISABLED;
5453
5454 return rc;
5455}
5456
5457static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5458 bool temp)
5459{
5460 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5461 int rc;
5462
5463 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5464 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5465 return 0;
5466 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5467 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5468 return 0;
5469 }
5470 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5471 SYNC_EVENTS_DISABLED;
5472
5473 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5474 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5475 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5476 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5477 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5478 channel->channel);
5479
5480 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5481 inbuf, sizeof(inbuf), NULL, 0, NULL);
5482
5483 return rc;
5484}
5485
5486static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5487 bool temp)
5488{
5489 int (*set)(struct efx_channel *channel, bool temp);
5490 struct efx_channel *channel;
5491
5492 set = en ?
5493 efx_ef10_rx_enable_timestamping :
5494 efx_ef10_rx_disable_timestamping;
5495
5496 efx_for_each_channel(channel, efx) {
5497 int rc = set(channel, temp);
5498 if (en && rc != 0) {
5499 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5500 return rc;
5501 }
5502 }
5503
5504 return 0;
5505}
5506
Shradha Shah02246a72015-05-06 00:58:14 +01005507static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5508 struct hwtstamp_config *init)
5509{
5510 return -EOPNOTSUPP;
5511}
5512
Jon Cooperbd9a2652013-11-18 12:54:41 +00005513static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5514 struct hwtstamp_config *init)
5515{
5516 int rc;
5517
5518 switch (init->rx_filter) {
5519 case HWTSTAMP_FILTER_NONE:
5520 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5521 /* if TX timestamping is still requested then leave PTP on */
5522 return efx_ptp_change_mode(efx,
5523 init->tx_type != HWTSTAMP_TX_OFF, 0);
5524 case HWTSTAMP_FILTER_ALL:
5525 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5526 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5527 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5528 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5529 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5530 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5531 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5532 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5533 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5534 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5535 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5536 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5537 init->rx_filter = HWTSTAMP_FILTER_ALL;
5538 rc = efx_ptp_change_mode(efx, true, 0);
5539 if (!rc)
5540 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5541 if (rc)
5542 efx_ptp_change_mode(efx, false, 0);
5543 return rc;
5544 default:
5545 return -ERANGE;
5546 }
5547}
5548
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005549static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
5550 struct netdev_phys_item_id *ppid)
5551{
5552 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5553
5554 if (!is_valid_ether_addr(nic_data->port_id))
5555 return -EOPNOTSUPP;
5556
5557 ppid->id_len = ETH_ALEN;
5558 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
5559
5560 return 0;
5561}
5562
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005563static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5564{
5565 if (proto != htons(ETH_P_8021Q))
5566 return -EINVAL;
5567
5568 return efx_ef10_add_vlan(efx, vid);
5569}
5570
5571static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5572{
5573 if (proto != htons(ETH_P_8021Q))
5574 return -EINVAL;
5575
5576 return efx_ef10_del_vlan(efx, vid);
5577}
5578
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005579#define EF10_OFFLOAD_FEATURES \
5580 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005581 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005582 NETIF_F_IPV6_CSUM | \
5583 NETIF_F_RXHASH | \
5584 NETIF_F_NTUPLE)
5585
Shradha Shah02246a72015-05-06 00:58:14 +01005586const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005587 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005588 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005589 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005590 .probe = efx_ef10_probe_vf,
5591 .remove = efx_ef10_remove,
5592 .dimension_resources = efx_ef10_dimension_resources,
5593 .init = efx_ef10_init_nic,
5594 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005595 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005596 .map_reset_flags = efx_ef10_map_reset_flags,
5597 .reset = efx_ef10_reset,
5598 .probe_port = efx_mcdi_port_probe,
5599 .remove_port = efx_mcdi_port_remove,
5600 .fini_dmaq = efx_ef10_fini_dmaq,
5601 .prepare_flr = efx_ef10_prepare_flr,
5602 .finish_flr = efx_port_dummy_op_void,
5603 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005604 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005605 .start_stats = efx_port_dummy_op_void,
5606 .pull_stats = efx_port_dummy_op_void,
5607 .stop_stats = efx_port_dummy_op_void,
5608 .set_id_led = efx_mcdi_set_id_led,
5609 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005610 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005611 .check_mac_fault = efx_mcdi_mac_check_fault,
5612 .reconfigure_port = efx_mcdi_port_reconfigure,
5613 .get_wol = efx_ef10_get_wol_vf,
5614 .set_wol = efx_ef10_set_wol_vf,
5615 .resume_wol = efx_port_dummy_op_void,
5616 .mcdi_request = efx_ef10_mcdi_request,
5617 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5618 .mcdi_read_response = efx_ef10_mcdi_read_response,
5619 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005620 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005621 .irq_enable_master = efx_port_dummy_op_void,
5622 .irq_test_generate = efx_ef10_irq_test_generate,
5623 .irq_disable_non_ev = efx_port_dummy_op_void,
5624 .irq_handle_msi = efx_ef10_msi_interrupt,
5625 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5626 .tx_probe = efx_ef10_tx_probe,
5627 .tx_init = efx_ef10_tx_init,
5628 .tx_remove = efx_ef10_tx_remove,
5629 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005630 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005631 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005632 .rx_probe = efx_ef10_rx_probe,
5633 .rx_init = efx_ef10_rx_init,
5634 .rx_remove = efx_ef10_rx_remove,
5635 .rx_write = efx_ef10_rx_write,
5636 .rx_defer_refill = efx_ef10_rx_defer_refill,
5637 .ev_probe = efx_ef10_ev_probe,
5638 .ev_init = efx_ef10_ev_init,
5639 .ev_fini = efx_ef10_ev_fini,
5640 .ev_remove = efx_ef10_ev_remove,
5641 .ev_process = efx_ef10_ev_process,
5642 .ev_read_ack = efx_ef10_ev_read_ack,
5643 .ev_test_generate = efx_ef10_ev_test_generate,
5644 .filter_table_probe = efx_ef10_filter_table_probe,
5645 .filter_table_restore = efx_ef10_filter_table_restore,
5646 .filter_table_remove = efx_ef10_filter_table_remove,
5647 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5648 .filter_insert = efx_ef10_filter_insert,
5649 .filter_remove_safe = efx_ef10_filter_remove_safe,
5650 .filter_get_safe = efx_ef10_filter_get_safe,
5651 .filter_clear_rx = efx_ef10_filter_clear_rx,
5652 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5653 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5654 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5655#ifdef CONFIG_RFS_ACCEL
5656 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5657 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5658#endif
5659#ifdef CONFIG_SFC_MTD
5660 .mtd_probe = efx_port_dummy_op_int,
5661#endif
5662 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5663 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005664 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5665 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005666#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005667 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5668 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5669 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005670#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005671 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005672 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005673
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005674 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005675 .revision = EFX_REV_HUNT_A0,
5676 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5677 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5678 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5679 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5680 .can_rx_scatter = true,
5681 .always_rx_scatter = true,
5682 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5683 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005684 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005685 .mcdi_max_ver = 2,
5686 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5687 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5688 1 << HWTSTAMP_FILTER_ALL,
5689};
5690
5691const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005692 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005693 .mem_bar = EFX_MEM_BAR,
5694 .mem_map_size = efx_ef10_mem_map_size,
5695 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005696 .remove = efx_ef10_remove,
5697 .dimension_resources = efx_ef10_dimension_resources,
5698 .init = efx_ef10_init_nic,
5699 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005700 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005701 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005702 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005703 .probe_port = efx_mcdi_port_probe,
5704 .remove_port = efx_mcdi_port_remove,
5705 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005706 .prepare_flr = efx_ef10_prepare_flr,
5707 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005708 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005709 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005710 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005711 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005712 .stop_stats = efx_mcdi_mac_stop_stats,
5713 .set_id_led = efx_mcdi_set_id_led,
5714 .push_irq_moderation = efx_ef10_push_irq_moderation,
5715 .reconfigure_mac = efx_ef10_mac_reconfigure,
5716 .check_mac_fault = efx_mcdi_mac_check_fault,
5717 .reconfigure_port = efx_mcdi_port_reconfigure,
5718 .get_wol = efx_ef10_get_wol,
5719 .set_wol = efx_ef10_set_wol,
5720 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005721 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005722 .test_nvram = efx_mcdi_nvram_test_all,
5723 .mcdi_request = efx_ef10_mcdi_request,
5724 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5725 .mcdi_read_response = efx_ef10_mcdi_read_response,
5726 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005727 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005728 .irq_enable_master = efx_port_dummy_op_void,
5729 .irq_test_generate = efx_ef10_irq_test_generate,
5730 .irq_disable_non_ev = efx_port_dummy_op_void,
5731 .irq_handle_msi = efx_ef10_msi_interrupt,
5732 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5733 .tx_probe = efx_ef10_tx_probe,
5734 .tx_init = efx_ef10_tx_init,
5735 .tx_remove = efx_ef10_tx_remove,
5736 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00005737 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01005738 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005739 .rx_probe = efx_ef10_rx_probe,
5740 .rx_init = efx_ef10_rx_init,
5741 .rx_remove = efx_ef10_rx_remove,
5742 .rx_write = efx_ef10_rx_write,
5743 .rx_defer_refill = efx_ef10_rx_defer_refill,
5744 .ev_probe = efx_ef10_ev_probe,
5745 .ev_init = efx_ef10_ev_init,
5746 .ev_fini = efx_ef10_ev_fini,
5747 .ev_remove = efx_ef10_ev_remove,
5748 .ev_process = efx_ef10_ev_process,
5749 .ev_read_ack = efx_ef10_ev_read_ack,
5750 .ev_test_generate = efx_ef10_ev_test_generate,
5751 .filter_table_probe = efx_ef10_filter_table_probe,
5752 .filter_table_restore = efx_ef10_filter_table_restore,
5753 .filter_table_remove = efx_ef10_filter_table_remove,
5754 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5755 .filter_insert = efx_ef10_filter_insert,
5756 .filter_remove_safe = efx_ef10_filter_remove_safe,
5757 .filter_get_safe = efx_ef10_filter_get_safe,
5758 .filter_clear_rx = efx_ef10_filter_clear_rx,
5759 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5760 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5761 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5762#ifdef CONFIG_RFS_ACCEL
5763 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5764 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5765#endif
5766#ifdef CONFIG_SFC_MTD
5767 .mtd_probe = efx_ef10_mtd_probe,
5768 .mtd_rename = efx_mcdi_mtd_rename,
5769 .mtd_read = efx_mcdi_mtd_read,
5770 .mtd_erase = efx_mcdi_mtd_erase,
5771 .mtd_write = efx_mcdi_mtd_write,
5772 .mtd_sync = efx_mcdi_mtd_sync,
5773#endif
5774 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005775 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5776 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005777 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5778 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005779#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005780 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005781 .sriov_init = efx_ef10_sriov_init,
5782 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005783 .sriov_wanted = efx_ef10_sriov_wanted,
5784 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005785 .sriov_flr = efx_ef10_sriov_flr,
5786 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5787 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5788 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5789 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005790 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005791 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5792 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5793 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005794#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005795 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005796 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00005797 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01005798
Bert Kenward08a7b29b2017-01-10 16:23:33 +00005799 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01005800 .revision = EFX_REV_HUNT_A0,
5801 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5802 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5803 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005804 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005805 .can_rx_scatter = true,
5806 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00005807 .option_descriptors = true,
Ben Hutchings8127d662013-08-29 19:19:29 +01005808 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5809 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005810 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005811 .mcdi_max_ver = 2,
5812 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005813 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5814 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005815};