blob: fd1008daf1e378ffc8a18f13ae31eec9453e3240 [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
Edward Cree9b410802017-01-27 15:02:52 +000063enum efx_ef10_default_filters {
64 EFX_EF10_BCAST,
65 EFX_EF10_UCDEF,
66 EFX_EF10_MCDEF,
67 EFX_EF10_VXLAN4_UCDEF,
68 EFX_EF10_VXLAN4_MCDEF,
69 EFX_EF10_VXLAN6_UCDEF,
70 EFX_EF10_VXLAN6_MCDEF,
71 EFX_EF10_NVGRE4_UCDEF,
72 EFX_EF10_NVGRE4_MCDEF,
73 EFX_EF10_NVGRE6_UCDEF,
74 EFX_EF10_NVGRE6_MCDEF,
75 EFX_EF10_GENEVE4_UCDEF,
76 EFX_EF10_GENEVE4_MCDEF,
77 EFX_EF10_GENEVE6_UCDEF,
78 EFX_EF10_GENEVE6_MCDEF,
79
80 EFX_EF10_NUM_DEFAULT_FILTERS
81};
82
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010083/* Per-VLAN filters information */
84struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010085 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010086 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010087 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
88 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree9b410802017-01-27 15:02:52 +000089 u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS];
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010090};
91
Daniel Pieczko822b96f2015-07-21 15:10:27 +010092struct efx_ef10_dev_addr {
93 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010094};
95
Ben Hutchings8127d662013-08-29 19:19:29 +010096struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010097/* The MCDI match masks supported by this fw & hw, in order of priority */
98 u32 rx_match_mcdi_flags[
Edward Cree9b410802017-01-27 15:02:52 +000099 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
Ben Hutchings8127d662013-08-29 19:19:29 +0100100 unsigned int rx_match_count;
101
102 struct {
103 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000104/* BUSY flag indicates that an update is in progress. AUTO_OLD is
105 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +0100106 */
107#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000108#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +0100109#define EFX_EF10_FILTER_FLAGS 3UL
110 u64 handle; /* firmware handle */
111 } *entry;
112 wait_queue_head_t waitq;
113/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +0100114 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
115 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +0100116 int dev_uc_count;
117 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100118 bool uc_promisc;
119 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100120/* Whether in multicast promiscuous mode when last changed */
121 bool mc_promisc_last;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100122 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100123 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100124};
125
126/* An arbitrary search limit for the software hash table */
127#define EFX_EF10_FILTER_SEARCH_LIMIT 200
128
Ben Hutchings8127d662013-08-29 19:19:29 +0100129static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
130static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100131static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
132static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
133 struct efx_ef10_filter_vlan *vlan);
134static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Ben Hutchings8127d662013-08-29 19:19:29 +0100135
136static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
137{
138 efx_dword_t reg;
139
140 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
141 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
142 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
143}
144
145static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
146{
Shradha Shah02246a72015-05-06 00:58:14 +0100147 int bar;
148
149 bar = efx->type->mem_bar;
150 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100151}
152
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100153static bool efx_ef10_is_vf(struct efx_nic *efx)
154{
155 return efx->type->is_vf;
156}
157
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100158static int efx_ef10_get_pf_index(struct efx_nic *efx)
159{
160 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
161 struct efx_ef10_nic_data *nic_data = efx->nic_data;
162 size_t outlen;
163 int rc;
164
165 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
166 sizeof(outbuf), &outlen);
167 if (rc)
168 return rc;
169 if (outlen < sizeof(outbuf))
170 return -EIO;
171
172 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
173 return 0;
174}
175
Shradha Shah88a37de2015-05-20 11:09:15 +0100176#ifdef CONFIG_SFC_SRIOV
177static int efx_ef10_get_vf_index(struct efx_nic *efx)
178{
179 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
180 struct efx_ef10_nic_data *nic_data = efx->nic_data;
181 size_t outlen;
182 int rc;
183
184 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
185 sizeof(outbuf), &outlen);
186 if (rc)
187 return rc;
188 if (outlen < sizeof(outbuf))
189 return -EIO;
190
191 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
192 return 0;
193}
194#endif
195
Ben Hutchingse5a25382013-09-05 22:50:59 +0100196static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100197{
Bert Kenwardca889a02016-08-11 13:01:35 +0100198 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +0100199 struct efx_ef10_nic_data *nic_data = efx->nic_data;
200 size_t outlen;
201 int rc;
202
203 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
204
205 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
206 outbuf, sizeof(outbuf), &outlen);
207 if (rc)
208 return rc;
Bert Kenwardca889a02016-08-11 13:01:35 +0100209 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
Ben Hutchingse5a25382013-09-05 22:50:59 +0100210 netif_err(efx, drv, efx->net_dev,
211 "unable to read datapath firmware capabilities\n");
212 return -EIO;
213 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100214
Ben Hutchingse5a25382013-09-05 22:50:59 +0100215 nic_data->datapath_caps =
216 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
217
Edward Creec6347002017-01-13 21:20:29 +0000218 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
Bert Kenwardca889a02016-08-11 13:01:35 +0100219 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
220 GET_CAPABILITIES_V2_OUT_FLAGS2);
Edward Creec6347002017-01-13 21:20:29 +0000221 nic_data->piobuf_size = MCDI_WORD(outbuf,
222 GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
223 } else {
Bert Kenwardca889a02016-08-11 13:01:35 +0100224 nic_data->datapath_caps2 = 0;
Edward Creec6347002017-01-13 21:20:29 +0000225 nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
226 }
Bert Kenwardca889a02016-08-11 13:01:35 +0100227
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100228 /* record the DPCPU firmware IDs to determine VEB vswitching support.
229 */
230 nic_data->rx_dpcpu_fw_id =
231 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
232 nic_data->tx_dpcpu_fw_id =
233 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
234
Ben Hutchingse5a25382013-09-05 22:50:59 +0100235 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100236 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
237 netif_err(efx, probe, efx->net_dev,
238 "current firmware does not support an RX prefix\n");
239 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100240 }
241
242 return 0;
243}
244
245static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
246{
247 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
248 int rc;
249
250 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
251 outbuf, sizeof(outbuf), NULL);
252 if (rc)
253 return rc;
254 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
255 return rc > 0 ? rc : -ERANGE;
256}
257
Bert Kenwardd95e3292016-08-11 13:02:36 +0100258static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
259{
260 struct efx_ef10_nic_data *nic_data = efx->nic_data;
261 unsigned int implemented;
262 unsigned int enabled;
263 int rc;
264
265 nic_data->workaround_35388 = false;
266 nic_data->workaround_61265 = false;
267
268 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
269
270 if (rc == -ENOSYS) {
271 /* Firmware without GET_WORKAROUNDS - not a problem. */
272 rc = 0;
273 } else if (rc == 0) {
274 /* Bug61265 workaround is always enabled if implemented. */
275 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
276 nic_data->workaround_61265 = true;
277
278 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
279 nic_data->workaround_35388 = true;
280 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
281 /* Workaround is implemented but not enabled.
282 * Try to enable it.
283 */
284 rc = efx_mcdi_set_workaround(efx,
285 MC_CMD_WORKAROUND_BUG35388,
286 true, NULL);
287 if (rc == 0)
288 nic_data->workaround_35388 = true;
289 /* If we failed to set the workaround just carry on. */
290 rc = 0;
291 }
292 }
293
294 netif_dbg(efx, probe, efx->net_dev,
295 "workaround for bug 35388 is %sabled\n",
296 nic_data->workaround_35388 ? "en" : "dis");
297 netif_dbg(efx, probe, efx->net_dev,
298 "workaround for bug 61265 is %sabled\n",
299 nic_data->workaround_61265 ? "en" : "dis");
300
301 return rc;
302}
303
304static void efx_ef10_process_timer_config(struct efx_nic *efx,
305 const efx_dword_t *data)
306{
307 unsigned int max_count;
308
309 if (EFX_EF10_WORKAROUND_61265(efx)) {
310 efx->timer_quantum_ns = MCDI_DWORD(data,
311 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
312 efx->timer_max_ns = MCDI_DWORD(data,
313 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
314 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
315 efx->timer_quantum_ns = MCDI_DWORD(data,
316 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
317 max_count = MCDI_DWORD(data,
318 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
319 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
320 } else {
321 efx->timer_quantum_ns = MCDI_DWORD(data,
322 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
323 max_count = MCDI_DWORD(data,
324 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
325 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
326 }
327
328 netif_dbg(efx, probe, efx->net_dev,
329 "got timer properties from MC: quantum %u ns; max %u ns\n",
330 efx->timer_quantum_ns, efx->timer_max_ns);
331}
332
333static int efx_ef10_get_timer_config(struct efx_nic *efx)
334{
335 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
336 int rc;
337
338 rc = efx_ef10_get_timer_workarounds(efx);
339 if (rc)
340 return rc;
341
342 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
343 outbuf, sizeof(outbuf), NULL);
344
345 if (rc == 0) {
346 efx_ef10_process_timer_config(efx, outbuf);
347 } else if (rc == -ENOSYS || rc == -EPERM) {
348 /* Not available - fall back to Huntington defaults. */
349 unsigned int quantum;
350
351 rc = efx_ef10_get_sysclk_freq(efx);
352 if (rc < 0)
353 return rc;
354
355 quantum = 1536000 / rc; /* 1536 cycles */
356 efx->timer_quantum_ns = quantum;
357 efx->timer_max_ns = efx->type->timer_period_max * quantum;
358 rc = 0;
359 } else {
360 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
361 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
362 NULL, 0, rc);
363 }
364
365 return rc;
366}
367
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100368static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100369{
370 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
371 size_t outlen;
372 int rc;
373
374 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
375
376 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
377 outbuf, sizeof(outbuf), &outlen);
378 if (rc)
379 return rc;
380 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
381 return -EIO;
382
Edward Creecd84ff42014-03-07 18:27:41 +0000383 ether_addr_copy(mac_address,
384 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100385 return 0;
386}
387
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100388static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
389{
390 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
391 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
392 size_t outlen;
393 int num_addrs, rc;
394
395 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
396 EVB_PORT_ID_ASSIGNED);
397 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
398 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
399
400 if (rc)
401 return rc;
402 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
403 return -EIO;
404
405 num_addrs = MCDI_DWORD(outbuf,
406 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
407
408 WARN_ON(num_addrs != 1);
409
410 ether_addr_copy(mac_address,
411 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
412
413 return 0;
414}
415
Shradha Shah0f5c0842015-06-02 11:37:58 +0100416static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
417 struct device_attribute *attr,
418 char *buf)
419{
420 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
421
422 return sprintf(buf, "%d\n",
423 ((efx->mcdi->fn_flags) &
424 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
425 ? 1 : 0);
426}
427
428static ssize_t efx_ef10_show_primary_flag(struct device *dev,
429 struct device_attribute *attr,
430 char *buf)
431{
432 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
433
434 return sprintf(buf, "%d\n",
435 ((efx->mcdi->fn_flags) &
436 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
437 ? 1 : 0);
438}
439
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100440static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
441{
442 struct efx_ef10_nic_data *nic_data = efx->nic_data;
443 struct efx_ef10_vlan *vlan;
444
445 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
446
447 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
448 if (vlan->vid == vid)
449 return vlan;
450 }
451
452 return NULL;
453}
454
455static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
456{
457 struct efx_ef10_nic_data *nic_data = efx->nic_data;
458 struct efx_ef10_vlan *vlan;
459 int rc;
460
461 mutex_lock(&nic_data->vlan_lock);
462
463 vlan = efx_ef10_find_vlan(efx, vid);
464 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100465 /* We add VID 0 on init. 8021q adds it on module init
466 * for all interfaces with VLAN filtring feature.
467 */
468 if (vid == 0)
469 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100470 netif_warn(efx, drv, efx->net_dev,
471 "VLAN %u already added\n", vid);
472 rc = -EALREADY;
473 goto fail_exist;
474 }
475
476 rc = -ENOMEM;
477 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
478 if (!vlan)
479 goto fail_alloc;
480
481 vlan->vid = vid;
482
483 list_add_tail(&vlan->list, &nic_data->vlan_list);
484
485 if (efx->filter_state) {
486 mutex_lock(&efx->mac_lock);
487 down_write(&efx->filter_sem);
488 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
489 up_write(&efx->filter_sem);
490 mutex_unlock(&efx->mac_lock);
491 if (rc)
492 goto fail_filter_add_vlan;
493 }
494
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100495done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100496 mutex_unlock(&nic_data->vlan_lock);
497 return 0;
498
499fail_filter_add_vlan:
500 list_del(&vlan->list);
501 kfree(vlan);
502fail_alloc:
503fail_exist:
504 mutex_unlock(&nic_data->vlan_lock);
505 return rc;
506}
507
508static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
509 struct efx_ef10_vlan *vlan)
510{
511 struct efx_ef10_nic_data *nic_data = efx->nic_data;
512
513 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
514
515 if (efx->filter_state) {
516 down_write(&efx->filter_sem);
517 efx_ef10_filter_del_vlan(efx, vlan->vid);
518 up_write(&efx->filter_sem);
519 }
520
521 list_del(&vlan->list);
522 kfree(vlan);
523}
524
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100525static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
526{
527 struct efx_ef10_nic_data *nic_data = efx->nic_data;
528 struct efx_ef10_vlan *vlan;
529 int rc = 0;
530
531 /* 8021q removes VID 0 on module unload for all interfaces
532 * with VLAN filtering feature. We need to keep it to receive
533 * untagged traffic.
534 */
535 if (vid == 0)
536 return 0;
537
538 mutex_lock(&nic_data->vlan_lock);
539
540 vlan = efx_ef10_find_vlan(efx, vid);
541 if (!vlan) {
542 netif_err(efx, drv, efx->net_dev,
543 "VLAN %u to be deleted not found\n", vid);
544 rc = -ENOENT;
545 } else {
546 efx_ef10_del_vlan_internal(efx, vlan);
547 }
548
549 mutex_unlock(&nic_data->vlan_lock);
550
551 return rc;
552}
553
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100554static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
555{
556 struct efx_ef10_nic_data *nic_data = efx->nic_data;
557 struct efx_ef10_vlan *vlan, *next_vlan;
558
559 mutex_lock(&nic_data->vlan_lock);
560 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
561 efx_ef10_del_vlan_internal(efx, vlan);
562 mutex_unlock(&nic_data->vlan_lock);
563}
564
Shradha Shah0f5c0842015-06-02 11:37:58 +0100565static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
566 NULL);
567static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
568
Ben Hutchings8127d662013-08-29 19:19:29 +0100569static int efx_ef10_probe(struct efx_nic *efx)
570{
571 struct efx_ef10_nic_data *nic_data;
572 int i, rc;
573
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000574 /* We can have one VI for each 8K region. However, until we
575 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100576 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100577 efx->max_channels = min_t(unsigned int,
578 EFX_MAX_CHANNELS,
579 efx_ef10_mem_map_size(efx) /
580 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
581 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000582 if (WARN_ON(efx->max_channels == 0))
583 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100584
585 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
586 if (!nic_data)
587 return -ENOMEM;
588 efx->nic_data = nic_data;
589
Edward Cree75aba2a2015-05-27 13:13:54 +0100590 /* we assume later that we can copy from this buffer in dwords */
591 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
592
Ben Hutchings8127d662013-08-29 19:19:29 +0100593 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
594 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
595 if (rc)
596 goto fail1;
597
598 /* Get the MC's warm boot count. In case it's rebooting right
599 * now, be prepared to retry.
600 */
601 i = 0;
602 for (;;) {
603 rc = efx_ef10_get_warm_boot_count(efx);
604 if (rc >= 0)
605 break;
606 if (++i == 5)
607 goto fail2;
608 ssleep(1);
609 }
610 nic_data->warm_boot_count = rc;
611
612 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
613
Daniel Pieczko45b24492015-05-06 00:57:14 +0100614 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
615
Ben Hutchings8127d662013-08-29 19:19:29 +0100616 /* In case we're recovering from a crash (kexec), we want to
617 * cancel any outstanding request by the previous user of this
618 * function. We send a special message using the least
619 * significant bits of the 'high' (doorbell) register.
620 */
621 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
622
623 rc = efx_mcdi_init(efx);
624 if (rc)
625 goto fail2;
626
627 /* Reset (most) configuration for this function */
628 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
629 if (rc)
630 goto fail3;
631
632 /* Enable event logging */
633 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
634 if (rc)
635 goto fail3;
636
Shradha Shah0f5c0842015-06-02 11:37:58 +0100637 rc = device_create_file(&efx->pci_dev->dev,
638 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100639 if (rc)
640 goto fail3;
641
Shradha Shah0f5c0842015-06-02 11:37:58 +0100642 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
643 if (rc)
644 goto fail4;
645
646 rc = efx_ef10_get_pf_index(efx);
647 if (rc)
648 goto fail5;
649
Ben Hutchingse5a25382013-09-05 22:50:59 +0100650 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100651 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100652 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100653
654 efx->rx_packet_len_offset =
655 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
656
Ben Hutchings8127d662013-08-29 19:19:29 +0100657 rc = efx_mcdi_port_get_number(efx);
658 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100659 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100660 efx->port_num = rc;
661
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100662 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100663 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100664 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100665
Bert Kenwardd95e3292016-08-11 13:02:36 +0100666 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100667 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100668 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100669
Ben Hutchings8127d662013-08-29 19:19:29 +0100670 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100671 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100672 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100673
Ben Hutchings9aecda92013-12-05 21:28:42 +0000674 efx_ptp_probe(efx, NULL);
675
Shradha Shah1d051e02015-06-02 11:38:16 +0100676#ifdef CONFIG_SFC_SRIOV
677 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
678 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
679 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
680
681 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
682 } else
683#endif
684 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
685
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100686 INIT_LIST_HEAD(&nic_data->vlan_list);
687 mutex_init(&nic_data->vlan_lock);
688
689 /* Add unspecified VID to support VLAN filtering being disabled */
690 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
691 if (rc)
692 goto fail_add_vid_unspec;
693
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100694 /* If VLAN filtering is enabled, we need VID 0 to get untagged
695 * traffic. It is added automatically if 8021q module is loaded,
696 * but we can't rely on it since module may be not loaded.
697 */
698 rc = efx_ef10_add_vlan(efx, 0);
699 if (rc)
700 goto fail_add_vid_0;
701
Ben Hutchings8127d662013-08-29 19:19:29 +0100702 return 0;
703
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100704fail_add_vid_0:
705 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100706fail_add_vid_unspec:
707 mutex_destroy(&nic_data->vlan_lock);
708 efx_ptp_remove(efx);
709 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100710fail5:
711 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
712fail4:
713 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100714fail3:
715 efx_mcdi_fini(efx);
716fail2:
717 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
718fail1:
719 kfree(nic_data);
720 efx->nic_data = NULL;
721 return rc;
722}
723
724static int efx_ef10_free_vis(struct efx_nic *efx)
725{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100726 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100727 size_t outlen;
728 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
729 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100730
731 /* -EALREADY means nothing to free, so ignore */
732 if (rc == -EALREADY)
733 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100734 if (rc)
735 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
736 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100737 return rc;
738}
739
Ben Hutchings183233b2013-06-28 21:47:12 +0100740#ifdef EFX_USE_PIO
741
742static void efx_ef10_free_piobufs(struct efx_nic *efx)
743{
744 struct efx_ef10_nic_data *nic_data = efx->nic_data;
745 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
746 unsigned int i;
747 int rc;
748
749 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
750
751 for (i = 0; i < nic_data->n_piobufs; i++) {
752 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
753 nic_data->piobuf_handle[i]);
754 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
755 NULL, 0, NULL);
756 WARN_ON(rc);
757 }
758
759 nic_data->n_piobufs = 0;
760}
761
762static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
763{
764 struct efx_ef10_nic_data *nic_data = efx->nic_data;
765 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
766 unsigned int i;
767 size_t outlen;
768 int rc = 0;
769
770 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
771
772 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000773 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
774 outbuf, sizeof(outbuf), &outlen);
775 if (rc) {
776 /* Don't display the MC error if we didn't have space
777 * for a VF.
778 */
779 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
780 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
781 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100782 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000783 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100784 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
785 rc = -EIO;
786 break;
787 }
788 nic_data->piobuf_handle[i] =
789 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
790 netif_dbg(efx, probe, efx->net_dev,
791 "allocated PIO buffer %u handle %x\n", i,
792 nic_data->piobuf_handle[i]);
793 }
794
795 nic_data->n_piobufs = i;
796 if (rc)
797 efx_ef10_free_piobufs(efx);
798 return rc;
799}
800
801static int efx_ef10_link_piobufs(struct efx_nic *efx)
802{
803 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100804 _MCDI_DECLARE_BUF(inbuf,
805 max(MC_CMD_LINK_PIOBUF_IN_LEN,
806 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100807 struct efx_channel *channel;
808 struct efx_tx_queue *tx_queue;
809 unsigned int offset, index;
810 int rc;
811
812 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
813 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
814
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100815 memset(inbuf, 0, sizeof(inbuf));
816
Ben Hutchings183233b2013-06-28 21:47:12 +0100817 /* Link a buffer to each VI in the write-combining mapping */
818 for (index = 0; index < nic_data->n_piobufs; ++index) {
819 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
820 nic_data->piobuf_handle[index]);
821 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
822 nic_data->pio_write_vi_base + index);
823 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
824 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
825 NULL, 0, NULL);
826 if (rc) {
827 netif_err(efx, drv, efx->net_dev,
828 "failed to link VI %u to PIO buffer %u (%d)\n",
829 nic_data->pio_write_vi_base + index, index,
830 rc);
831 goto fail;
832 }
833 netif_dbg(efx, probe, efx->net_dev,
834 "linked VI %u to PIO buffer %u\n",
835 nic_data->pio_write_vi_base + index, index);
836 }
837
838 /* Link a buffer to each TX queue */
839 efx_for_each_channel(channel, efx) {
840 efx_for_each_channel_tx_queue(tx_queue, channel) {
841 /* We assign the PIO buffers to queues in
842 * reverse order to allow for the following
843 * special case.
844 */
845 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
846 tx_queue->channel->channel - 1) *
847 efx_piobuf_size);
Edward Creec6347002017-01-13 21:20:29 +0000848 index = offset / nic_data->piobuf_size;
849 offset = offset % nic_data->piobuf_size;
Ben Hutchings183233b2013-06-28 21:47:12 +0100850
851 /* When the host page size is 4K, the first
852 * host page in the WC mapping may be within
853 * the same VI page as the last TX queue. We
854 * can only link one buffer to each VI.
855 */
856 if (tx_queue->queue == nic_data->pio_write_vi_base) {
857 BUG_ON(index != 0);
858 rc = 0;
859 } else {
860 MCDI_SET_DWORD(inbuf,
861 LINK_PIOBUF_IN_PIOBUF_HANDLE,
862 nic_data->piobuf_handle[index]);
863 MCDI_SET_DWORD(inbuf,
864 LINK_PIOBUF_IN_TXQ_INSTANCE,
865 tx_queue->queue);
866 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
867 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
868 NULL, 0, NULL);
869 }
870
871 if (rc) {
872 /* This is non-fatal; the TX path just
873 * won't use PIO for this queue
874 */
875 netif_err(efx, drv, efx->net_dev,
876 "failed to link VI %u to PIO buffer %u (%d)\n",
877 tx_queue->queue, index, rc);
878 tx_queue->piobuf = NULL;
879 } else {
880 tx_queue->piobuf =
881 nic_data->pio_write_base +
882 index * EFX_VI_PAGE_SIZE + offset;
883 tx_queue->piobuf_offset = offset;
884 netif_dbg(efx, probe, efx->net_dev,
885 "linked VI %u to PIO buffer %u offset %x addr %p\n",
886 tx_queue->queue, index,
887 tx_queue->piobuf_offset,
888 tx_queue->piobuf);
889 }
890 }
891 }
892
893 return 0;
894
895fail:
896 while (index--) {
897 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
898 nic_data->pio_write_vi_base + index);
899 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
900 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
901 NULL, 0, NULL);
902 }
903 return rc;
904}
905
Edward Creec0795bf2016-05-24 18:53:36 +0100906static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
907{
908 struct efx_channel *channel;
909 struct efx_tx_queue *tx_queue;
910
911 /* All our existing PIO buffers went away */
912 efx_for_each_channel(channel, efx)
913 efx_for_each_channel_tx_queue(tx_queue, channel)
914 tx_queue->piobuf = NULL;
915}
916
Ben Hutchings183233b2013-06-28 21:47:12 +0100917#else /* !EFX_USE_PIO */
918
919static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
920{
921 return n == 0 ? 0 : -ENOBUFS;
922}
923
924static int efx_ef10_link_piobufs(struct efx_nic *efx)
925{
926 return 0;
927}
928
929static void efx_ef10_free_piobufs(struct efx_nic *efx)
930{
931}
932
Edward Creec0795bf2016-05-24 18:53:36 +0100933static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
934{
935}
936
Ben Hutchings183233b2013-06-28 21:47:12 +0100937#endif /* EFX_USE_PIO */
938
Ben Hutchings8127d662013-08-29 19:19:29 +0100939static void efx_ef10_remove(struct efx_nic *efx)
940{
941 struct efx_ef10_nic_data *nic_data = efx->nic_data;
942 int rc;
943
Shradha Shahf1122a32015-05-20 11:09:46 +0100944#ifdef CONFIG_SFC_SRIOV
945 struct efx_ef10_nic_data *nic_data_pf;
946 struct pci_dev *pci_dev_pf;
947 struct efx_nic *efx_pf;
948 struct ef10_vf *vf;
949
950 if (efx->pci_dev->is_virtfn) {
951 pci_dev_pf = efx->pci_dev->physfn;
952 if (pci_dev_pf) {
953 efx_pf = pci_get_drvdata(pci_dev_pf);
954 nic_data_pf = efx_pf->nic_data;
955 vf = nic_data_pf->vf + nic_data->vf_index;
956 vf->efx = NULL;
957 } else
958 netif_info(efx, drv, efx->net_dev,
959 "Could not get the PF id from VF\n");
960 }
961#endif
962
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100963 efx_ef10_cleanup_vlans(efx);
964 mutex_destroy(&nic_data->vlan_lock);
965
Ben Hutchings9aecda92013-12-05 21:28:42 +0000966 efx_ptp_remove(efx);
967
Ben Hutchings8127d662013-08-29 19:19:29 +0100968 efx_mcdi_mon_remove(efx);
969
Ben Hutchings8127d662013-08-29 19:19:29 +0100970 efx_ef10_rx_free_indir_table(efx);
971
Ben Hutchings183233b2013-06-28 21:47:12 +0100972 if (nic_data->wc_membase)
973 iounmap(nic_data->wc_membase);
974
Ben Hutchings8127d662013-08-29 19:19:29 +0100975 rc = efx_ef10_free_vis(efx);
976 WARN_ON(rc != 0);
977
Ben Hutchings183233b2013-06-28 21:47:12 +0100978 if (!nic_data->must_restore_piobufs)
979 efx_ef10_free_piobufs(efx);
980
Shradha Shah0f5c0842015-06-02 11:37:58 +0100981 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
982 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
983
Ben Hutchings8127d662013-08-29 19:19:29 +0100984 efx_mcdi_fini(efx);
985 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
986 kfree(nic_data);
987}
988
Shradha Shah88a37de2015-05-20 11:09:15 +0100989static int efx_ef10_probe_pf(struct efx_nic *efx)
990{
991 return efx_ef10_probe(efx);
992}
993
Andrew Rybchenko38d27f32016-06-15 17:52:08 +0100994int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
995 u32 *port_flags, u32 *vadaptor_flags,
996 unsigned int *vlan_tags)
997{
998 struct efx_ef10_nic_data *nic_data = efx->nic_data;
999 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
1000 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
1001 size_t outlen;
1002 int rc;
1003
1004 if (nic_data->datapath_caps &
1005 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
1006 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
1007 port_id);
1008
1009 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
1010 outbuf, sizeof(outbuf), &outlen);
1011 if (rc)
1012 return rc;
1013
1014 if (outlen < sizeof(outbuf)) {
1015 rc = -EIO;
1016 return rc;
1017 }
1018 }
1019
1020 if (port_flags)
1021 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1022 if (vadaptor_flags)
1023 *vadaptor_flags =
1024 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1025 if (vlan_tags)
1026 *vlan_tags =
1027 MCDI_DWORD(outbuf,
1028 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1029
1030 return 0;
1031}
1032
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001033int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1034{
1035 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1036
1037 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1038 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1039 NULL, 0, NULL);
1040}
1041
1042int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1043{
1044 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1045
1046 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1047 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1048 NULL, 0, NULL);
1049}
1050
1051int efx_ef10_vport_add_mac(struct efx_nic *efx,
1052 unsigned int port_id, u8 *mac)
1053{
1054 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1055
1056 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1057 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1058
1059 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1060 sizeof(inbuf), NULL, 0, NULL);
1061}
1062
1063int efx_ef10_vport_del_mac(struct efx_nic *efx,
1064 unsigned int port_id, u8 *mac)
1065{
1066 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1067
1068 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1069 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1070
1071 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1072 sizeof(inbuf), NULL, 0, NULL);
1073}
1074
Shradha Shah88a37de2015-05-20 11:09:15 +01001075#ifdef CONFIG_SFC_SRIOV
1076static int efx_ef10_probe_vf(struct efx_nic *efx)
1077{
1078 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001079 struct pci_dev *pci_dev_pf;
1080
1081 /* If the parent PF has no VF data structure, it doesn't know about this
1082 * VF so fail probe. The VF needs to be re-created. This can happen
1083 * if the PF driver is unloaded while the VF is assigned to a guest.
1084 */
1085 pci_dev_pf = efx->pci_dev->physfn;
1086 if (pci_dev_pf) {
1087 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1088 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1089
1090 if (!nic_data_pf->vf) {
1091 netif_info(efx, drv, efx->net_dev,
1092 "The VF cannot link to its parent PF; "
1093 "please destroy and re-create the VF\n");
1094 return -EBUSY;
1095 }
1096 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001097
1098 rc = efx_ef10_probe(efx);
1099 if (rc)
1100 return rc;
1101
1102 rc = efx_ef10_get_vf_index(efx);
1103 if (rc)
1104 goto fail;
1105
Shradha Shahf1122a32015-05-20 11:09:46 +01001106 if (efx->pci_dev->is_virtfn) {
1107 if (efx->pci_dev->physfn) {
1108 struct efx_nic *efx_pf =
1109 pci_get_drvdata(efx->pci_dev->physfn);
1110 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1111 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1112
1113 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001114 nic_data_p->vf[nic_data->vf_index].pci_dev =
1115 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001116 } else
1117 netif_info(efx, drv, efx->net_dev,
1118 "Could not get the PF id from VF\n");
1119 }
1120
Shradha Shah88a37de2015-05-20 11:09:15 +01001121 return 0;
1122
1123fail:
1124 efx_ef10_remove(efx);
1125 return rc;
1126}
1127#else
1128static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1129{
1130 return 0;
1131}
1132#endif
1133
Ben Hutchings8127d662013-08-29 19:19:29 +01001134static int efx_ef10_alloc_vis(struct efx_nic *efx,
1135 unsigned int min_vis, unsigned int max_vis)
1136{
1137 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1138 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1139 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1140 size_t outlen;
1141 int rc;
1142
1143 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1144 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1145 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1146 outbuf, sizeof(outbuf), &outlen);
1147 if (rc != 0)
1148 return rc;
1149
1150 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1151 return -EIO;
1152
1153 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1154 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1155
1156 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1157 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1158 return 0;
1159}
1160
Ben Hutchings183233b2013-06-28 21:47:12 +01001161/* Note that the failure path of this function does not free
1162 * resources, as this will be done by efx_ef10_remove().
1163 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001164static int efx_ef10_dimension_resources(struct efx_nic *efx)
1165{
Ben Hutchings183233b2013-06-28 21:47:12 +01001166 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1167 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001168 unsigned int min_vis = max(EFX_TXQ_TYPES,
1169 efx_separate_tx_channels ? 2 : 1);
1170 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001171 void __iomem *membase;
1172 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001173
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001174 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001175
1176#ifdef EFX_USE_PIO
1177 /* Try to allocate PIO buffers if wanted and if the full
1178 * number of PIO buffers would be sufficient to allocate one
1179 * copy-buffer per TX channel. Failure is non-fatal, as there
1180 * are only a small number of PIO buffers shared between all
1181 * functions of the controller.
1182 */
1183 if (efx_piobuf_size != 0 &&
Edward Creec6347002017-01-13 21:20:29 +00001184 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
Ben Hutchings183233b2013-06-28 21:47:12 +01001185 efx->n_tx_channels) {
1186 unsigned int n_piobufs =
1187 DIV_ROUND_UP(efx->n_tx_channels,
Edward Creec6347002017-01-13 21:20:29 +00001188 nic_data->piobuf_size / efx_piobuf_size);
Ben Hutchings183233b2013-06-28 21:47:12 +01001189
1190 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001191 if (rc == -ENOSPC)
1192 netif_dbg(efx, probe, efx->net_dev,
1193 "out of PIO buffers; cannot allocate more\n");
1194 else if (rc == -EPERM)
1195 netif_dbg(efx, probe, efx->net_dev,
1196 "not permitted to allocate PIO buffers\n");
1197 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001198 netif_err(efx, probe, efx->net_dev,
1199 "failed to allocate PIO buffers (%d)\n", rc);
1200 else
1201 netif_dbg(efx, probe, efx->net_dev,
1202 "allocated %u PIO buffers\n", n_piobufs);
1203 }
1204#else
1205 nic_data->n_piobufs = 0;
1206#endif
1207
1208 /* PIO buffers should be mapped with write-combining enabled,
1209 * and we want to make single UC and WC mappings rather than
1210 * several of each (in fact that's the only option if host
1211 * page size is >4K). So we may allocate some extra VIs just
1212 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001213 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001214 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001215 * first half of the next VI. Then the WC mapping begins with
1216 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001217 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001218 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001219 ER_DZ_TX_PIOBUF);
1220 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001221 /* pio_write_vi_base rounds down to give the number of complete
1222 * VIs inside the UC mapping.
1223 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001224 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1225 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1226 nic_data->n_piobufs) *
1227 EFX_VI_PAGE_SIZE) -
1228 uc_mem_map_size);
1229 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1230 } else {
1231 pio_write_vi_base = 0;
1232 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001233 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001234 }
1235
1236 /* In case the last attached driver failed to free VIs, do it now */
1237 rc = efx_ef10_free_vis(efx);
1238 if (rc != 0)
1239 return rc;
1240
1241 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1242 if (rc != 0)
1243 return rc;
1244
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001245 if (nic_data->n_allocated_vis < channel_vis) {
1246 netif_info(efx, drv, efx->net_dev,
1247 "Could not allocate enough VIs to satisfy RSS"
1248 " requirements. Performance may not be optimal.\n");
1249 /* We didn't get the VIs to populate our channels.
1250 * We could keep what we got but then we'd have more
1251 * interrupts than we need.
1252 * Instead calculate new max_channels and restart
1253 */
1254 efx->max_channels = nic_data->n_allocated_vis;
1255 efx->max_tx_channels =
1256 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1257
1258 efx_ef10_free_vis(efx);
1259 return -EAGAIN;
1260 }
1261
Ben Hutchings183233b2013-06-28 21:47:12 +01001262 /* If we didn't get enough VIs to map all the PIO buffers, free the
1263 * PIO buffers
1264 */
1265 if (nic_data->n_piobufs &&
1266 nic_data->n_allocated_vis <
1267 pio_write_vi_base + nic_data->n_piobufs) {
1268 netif_dbg(efx, probe, efx->net_dev,
1269 "%u VIs are not sufficient to map %u PIO buffers\n",
1270 nic_data->n_allocated_vis, nic_data->n_piobufs);
1271 efx_ef10_free_piobufs(efx);
1272 }
1273
1274 /* Shrink the original UC mapping of the memory BAR */
1275 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1276 if (!membase) {
1277 netif_err(efx, probe, efx->net_dev,
1278 "could not shrink memory BAR to %x\n",
1279 uc_mem_map_size);
1280 return -ENOMEM;
1281 }
1282 iounmap(efx->membase);
1283 efx->membase = membase;
1284
1285 /* Set up the WC mapping if needed */
1286 if (wc_mem_map_size) {
1287 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1288 uc_mem_map_size,
1289 wc_mem_map_size);
1290 if (!nic_data->wc_membase) {
1291 netif_err(efx, probe, efx->net_dev,
1292 "could not allocate WC mapping of size %x\n",
1293 wc_mem_map_size);
1294 return -ENOMEM;
1295 }
1296 nic_data->pio_write_vi_base = pio_write_vi_base;
1297 nic_data->pio_write_base =
1298 nic_data->wc_membase +
1299 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1300 uc_mem_map_size);
1301
1302 rc = efx_ef10_link_piobufs(efx);
1303 if (rc)
1304 efx_ef10_free_piobufs(efx);
1305 }
1306
1307 netif_dbg(efx, probe, efx->net_dev,
1308 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1309 &efx->membase_phys, efx->membase, uc_mem_map_size,
1310 nic_data->wc_membase, wc_mem_map_size);
1311
1312 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001313}
1314
1315static int efx_ef10_init_nic(struct efx_nic *efx)
1316{
1317 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1318 int rc;
1319
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001320 if (nic_data->must_check_datapath_caps) {
1321 rc = efx_ef10_init_datapath_caps(efx);
1322 if (rc)
1323 return rc;
1324 nic_data->must_check_datapath_caps = false;
1325 }
1326
Ben Hutchings8127d662013-08-29 19:19:29 +01001327 if (nic_data->must_realloc_vis) {
1328 /* We cannot let the number of VIs change now */
1329 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1330 nic_data->n_allocated_vis);
1331 if (rc)
1332 return rc;
1333 nic_data->must_realloc_vis = false;
1334 }
1335
Ben Hutchings183233b2013-06-28 21:47:12 +01001336 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1337 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1338 if (rc == 0) {
1339 rc = efx_ef10_link_piobufs(efx);
1340 if (rc)
1341 efx_ef10_free_piobufs(efx);
1342 }
1343
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001344 /* Log an error on failure, but this is non-fatal.
1345 * Permission errors are less important - we've presumably
1346 * had the PIO buffer licence removed.
1347 */
1348 if (rc == -EPERM)
1349 netif_dbg(efx, drv, efx->net_dev,
1350 "not permitted to restore PIO buffers\n");
1351 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001352 netif_err(efx, drv, efx->net_dev,
1353 "failed to restore PIO buffers (%d)\n", rc);
1354 nic_data->must_restore_piobufs = false;
1355 }
1356
Jon Cooper267c0152015-05-06 00:59:38 +01001357 /* don't fail init if RSS setup doesn't work */
Edward Creef74d1992017-01-17 12:01:53 +00001358 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
Edward Cree4fdda952017-01-04 15:10:56 +00001359 efx->rss_active = (rc == 0);
Jon Cooper267c0152015-05-06 00:59:38 +01001360
Ben Hutchings8127d662013-08-29 19:19:29 +01001361 return 0;
1362}
1363
Jon Cooper3e336262014-01-17 19:48:06 +00001364static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1365{
1366 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001367#ifdef CONFIG_SFC_SRIOV
1368 unsigned int i;
1369#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001370
1371 /* All our allocations have been reset */
1372 nic_data->must_realloc_vis = true;
1373 nic_data->must_restore_filters = true;
1374 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001375 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001376 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001377
1378 /* Driver-created vswitches and vports must be re-created */
1379 nic_data->must_probe_vswitching = true;
1380 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1381#ifdef CONFIG_SFC_SRIOV
1382 if (nic_data->vf)
1383 for (i = 0; i < efx->vf_count; i++)
1384 nic_data->vf[i].vport_id = 0;
1385#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001386}
1387
Jon Cooper087e9022015-05-20 11:11:35 +01001388static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1389{
1390 if (reason == RESET_TYPE_MC_FAILURE)
1391 return RESET_TYPE_DATAPATH;
1392
1393 return efx_mcdi_map_reset_reason(reason);
1394}
1395
Ben Hutchings8127d662013-08-29 19:19:29 +01001396static int efx_ef10_map_reset_flags(u32 *flags)
1397{
1398 enum {
1399 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1400 ETH_RESET_SHARED_SHIFT),
1401 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1402 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1403 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1404 ETH_RESET_SHARED_SHIFT)
1405 };
1406
1407 /* We assume for now that our PCI function is permitted to
1408 * reset everything.
1409 */
1410
1411 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1412 *flags &= ~EF10_RESET_MC;
1413 return RESET_TYPE_WORLD;
1414 }
1415
1416 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1417 *flags &= ~EF10_RESET_PORT;
1418 return RESET_TYPE_ALL;
1419 }
1420
1421 /* no invisible reset implemented */
1422
1423 return -EINVAL;
1424}
1425
Jon Cooper3e336262014-01-17 19:48:06 +00001426static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1427{
1428 int rc = efx_mcdi_reset(efx, reset_type);
1429
Daniel Pieczko27324822015-07-31 11:14:54 +01001430 /* Unprivileged functions return -EPERM, but need to return success
1431 * here so that the datapath is brought back up.
1432 */
1433 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1434 rc = 0;
1435
Jon Cooper3e336262014-01-17 19:48:06 +00001436 /* If it was a port reset, trigger reallocation of MC resources.
1437 * Note that on an MC reset nothing needs to be done now because we'll
1438 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001439 * For an FLR, we never get an MC reset event, but the MC has reset all
1440 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001441 */
Edward Creee2835462014-04-16 19:27:48 +01001442 if ((reset_type == RESET_TYPE_ALL ||
1443 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001444 efx_ef10_reset_mc_allocations(efx);
1445 return rc;
1446}
1447
Ben Hutchings8127d662013-08-29 19:19:29 +01001448#define EF10_DMA_STAT(ext_name, mcdi_name) \
1449 [EF10_STAT_ ## ext_name] = \
1450 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1451#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1452 [EF10_STAT_ ## int_name] = \
1453 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1454#define EF10_OTHER_STAT(ext_name) \
1455 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001456#define GENERIC_SW_STAT(ext_name) \
1457 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001458
1459static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001460 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1461 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1462 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1463 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1464 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1465 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1466 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1467 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1468 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1469 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1470 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1471 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1472 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1473 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1474 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1475 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1476 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1477 EF10_OTHER_STAT(port_rx_good_bytes),
1478 EF10_OTHER_STAT(port_rx_bad_bytes),
1479 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1480 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1481 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1482 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1483 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1484 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1485 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1486 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1487 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1488 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1489 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1490 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1491 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1492 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1493 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1494 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1495 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1496 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1497 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1498 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1499 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1500 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001501 GENERIC_SW_STAT(rx_nodesc_trunc),
1502 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001503 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1504 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1505 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1506 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1507 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1508 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1509 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1510 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1511 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1512 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1513 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1514 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001515 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1516 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1517 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1518 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1519 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1520 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1521 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1522 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1523 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1524 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1525 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1526 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1527 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1528 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1529 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1530 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1531 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1532 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001533};
1534
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001535#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1536 (1ULL << EF10_STAT_port_tx_packets) | \
1537 (1ULL << EF10_STAT_port_tx_pause) | \
1538 (1ULL << EF10_STAT_port_tx_unicast) | \
1539 (1ULL << EF10_STAT_port_tx_multicast) | \
1540 (1ULL << EF10_STAT_port_tx_broadcast) | \
1541 (1ULL << EF10_STAT_port_rx_bytes) | \
1542 (1ULL << \
1543 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1544 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1545 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1546 (1ULL << EF10_STAT_port_rx_packets) | \
1547 (1ULL << EF10_STAT_port_rx_good) | \
1548 (1ULL << EF10_STAT_port_rx_bad) | \
1549 (1ULL << EF10_STAT_port_rx_pause) | \
1550 (1ULL << EF10_STAT_port_rx_control) | \
1551 (1ULL << EF10_STAT_port_rx_unicast) | \
1552 (1ULL << EF10_STAT_port_rx_multicast) | \
1553 (1ULL << EF10_STAT_port_rx_broadcast) | \
1554 (1ULL << EF10_STAT_port_rx_lt64) | \
1555 (1ULL << EF10_STAT_port_rx_64) | \
1556 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1557 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1558 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1559 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1560 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1561 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1562 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1563 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1564 (1ULL << EF10_STAT_port_rx_overflow) | \
1565 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001566 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1567 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001568
Edward Cree69b365c2016-08-26 15:12:41 +01001569/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1570 * For a 10G/40G switchable port we do not expose these because they might
1571 * not include all the packets they should.
1572 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001573 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001574#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1575 (1ULL << EF10_STAT_port_tx_lt64) | \
1576 (1ULL << EF10_STAT_port_tx_64) | \
1577 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1578 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1579 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1580 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1581 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1582 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001583
1584/* These statistics are only provided by the 40G MAC. For a 10G/40G
1585 * switchable port we do expose these because the errors will otherwise
1586 * be silent.
1587 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001588#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1589 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001590
Edward Cree568d7a02013-09-25 17:32:09 +01001591/* These statistics are only provided if the firmware supports the
1592 * capability PM_AND_RXDP_COUNTERS.
1593 */
1594#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001595 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1596 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1597 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1598 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1599 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1600 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1601 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1602 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1603 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1604 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1605 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1606 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001607
Edward Cree4bae9132013-09-27 18:52:49 +01001608static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001609{
Edward Cree4bae9132013-09-27 18:52:49 +01001610 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001611 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001612 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001613
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001614 if (!(efx->mcdi->fn_flags &
1615 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1616 return 0;
1617
Edward Cree69b365c2016-08-26 15:12:41 +01001618 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001619 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001620 /* 8000 series have everything even at 40G */
1621 if (nic_data->datapath_caps2 &
1622 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1623 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1624 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001625 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001626 }
Edward Cree568d7a02013-09-25 17:32:09 +01001627
1628 if (nic_data->datapath_caps &
1629 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1630 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1631
Edward Cree4bae9132013-09-27 18:52:49 +01001632 return raw_mask;
1633}
1634
1635static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1636{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001637 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001638 u64 raw_mask[2];
1639
1640 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1641
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001642 /* Only show vadaptor stats when EVB capability is present */
1643 if (nic_data->datapath_caps &
1644 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1645 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1646 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1647 } else {
1648 raw_mask[1] = 0;
1649 }
Edward Cree4bae9132013-09-27 18:52:49 +01001650
1651#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001652 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001653 mask[0] = raw_mask[0];
1654 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001655#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001656 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001657 mask[0] = raw_mask[0] & 0xffffffff;
1658 mask[1] = raw_mask[0] >> 32;
1659 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001660#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001661}
1662
1663static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1664{
Edward Cree4bae9132013-09-27 18:52:49 +01001665 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1666
1667 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001668 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001669 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001670}
1671
Daniel Pieczkod7788192015-06-02 11:39:20 +01001672static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1673 struct rtnl_link_stats64 *core_stats)
1674{
1675 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1676 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1677 u64 *stats = nic_data->stats;
1678 size_t stats_count = 0, index;
1679
1680 efx_ef10_get_stat_mask(efx, mask);
1681
1682 if (full_stats) {
1683 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1684 if (efx_ef10_stat_desc[index].name) {
1685 *full_stats++ = stats[index];
1686 ++stats_count;
1687 }
1688 }
1689 }
1690
Bert Kenwardfbe43072015-08-26 16:39:03 +01001691 if (!core_stats)
1692 return stats_count;
1693
1694 if (nic_data->datapath_caps &
1695 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1696 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001697 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1698 stats[EF10_STAT_rx_multicast] +
1699 stats[EF10_STAT_rx_broadcast];
1700 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1701 stats[EF10_STAT_tx_multicast] +
1702 stats[EF10_STAT_tx_broadcast];
1703 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1704 stats[EF10_STAT_rx_multicast_bytes] +
1705 stats[EF10_STAT_rx_broadcast_bytes];
1706 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1707 stats[EF10_STAT_tx_multicast_bytes] +
1708 stats[EF10_STAT_tx_broadcast_bytes];
1709 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001710 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001711 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1712 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1713 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1714 core_stats->rx_errors = core_stats->rx_crc_errors;
1715 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001716 } else {
1717 /* Use port stats. */
1718 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1719 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1720 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1721 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1722 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1723 stats[GENERIC_STAT_rx_nodesc_trunc] +
1724 stats[GENERIC_STAT_rx_noskb_drops];
1725 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1726 core_stats->rx_length_errors =
1727 stats[EF10_STAT_port_rx_gtjumbo] +
1728 stats[EF10_STAT_port_rx_length_error];
1729 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1730 core_stats->rx_frame_errors =
1731 stats[EF10_STAT_port_rx_align_error];
1732 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1733 core_stats->rx_errors = (core_stats->rx_length_errors +
1734 core_stats->rx_crc_errors +
1735 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001736 }
1737
1738 return stats_count;
1739}
1740
1741static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001742{
1743 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001744 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001745 __le64 generation_start, generation_end;
1746 u64 *stats = nic_data->stats;
1747 __le64 *dma_stats;
1748
Edward Cree4bae9132013-09-27 18:52:49 +01001749 efx_ef10_get_stat_mask(efx, mask);
1750
Ben Hutchings8127d662013-08-29 19:19:29 +01001751 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001752
1753 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1754 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1755 return 0;
1756 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001757 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001758 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001759 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001760 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1761 if (generation_end != generation_start)
1762 return -EAGAIN;
1763
1764 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001765 efx_nic_fix_nodesc_drop_stat(efx,
1766 &stats[EF10_STAT_port_rx_nodesc_drops]);
1767 stats[EF10_STAT_port_rx_good_bytes] =
1768 stats[EF10_STAT_port_rx_bytes] -
1769 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1770 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1771 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001772 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001773 return 0;
1774}
1775
1776
Daniel Pieczkod7788192015-06-02 11:39:20 +01001777static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1778 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001779{
Ben Hutchings8127d662013-08-29 19:19:29 +01001780 int retry;
1781
1782 /* If we're unlucky enough to read statistics during the DMA, wait
1783 * up to 10ms for it to finish (typically takes <500us)
1784 */
1785 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001786 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001787 break;
1788 udelay(100);
1789 }
1790
Daniel Pieczkod7788192015-06-02 11:39:20 +01001791 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1792}
1793
1794static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1795{
1796 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1797 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1798 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1799 __le64 generation_start, generation_end;
1800 u64 *stats = nic_data->stats;
1801 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1802 struct efx_buffer stats_buf;
1803 __le64 *dma_stats;
1804 int rc;
1805
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001806 spin_unlock_bh(&efx->stats_lock);
1807
1808 if (in_interrupt()) {
1809 /* If in atomic context, cannot update stats. Just update the
1810 * software stats and return so the caller can continue.
1811 */
1812 spin_lock_bh(&efx->stats_lock);
1813 efx_update_sw_stats(efx, stats);
1814 return 0;
1815 }
1816
Daniel Pieczkod7788192015-06-02 11:39:20 +01001817 efx_ef10_get_stat_mask(efx, mask);
1818
1819 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001820 if (rc) {
1821 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001822 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001823 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001824
1825 dma_stats = stats_buf.addr;
1826 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1827
1828 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1829 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001830 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001831 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1832 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1833
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001834 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1835 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001836 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001837 if (rc) {
1838 /* Expect ENOENT if DMA queues have not been set up */
1839 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1840 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1841 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001842 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001843 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001844
1845 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001846 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1847 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001848 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001849 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001850 rmb();
1851 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1852 stats, stats_buf.addr, false);
1853 rmb();
1854 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1855 if (generation_end != generation_start) {
1856 rc = -EAGAIN;
1857 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001858 }
1859
Daniel Pieczkod7788192015-06-02 11:39:20 +01001860 efx_update_sw_stats(efx, stats);
1861out:
1862 efx_nic_free_buffer(efx, &stats_buf);
1863 return rc;
1864}
Ben Hutchings8127d662013-08-29 19:19:29 +01001865
Daniel Pieczkod7788192015-06-02 11:39:20 +01001866static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1867 struct rtnl_link_stats64 *core_stats)
1868{
1869 if (efx_ef10_try_update_nic_stats_vf(efx))
1870 return 0;
1871
1872 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001873}
1874
1875static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1876{
1877 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01001878 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01001879 efx_dword_t timer_cmd;
1880
Bert Kenward539de7c2016-08-11 13:02:09 +01001881 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01001882 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01001883 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01001884 } else {
1885 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01001886 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001887 }
1888
Bert Kenward539de7c2016-08-11 13:02:09 +01001889 if (EFX_EF10_WORKAROUND_61265(efx)) {
1890 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1891 unsigned int ns = usecs * 1000;
1892
1893 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1894 channel->channel);
1895 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1896 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1897 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1898
1899 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1900 inbuf, sizeof(inbuf), 0, NULL, 0);
1901 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1902 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1903
Ben Hutchings8127d662013-08-29 19:19:29 +01001904 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1905 EFE_DD_EVQ_IND_TIMER_FLAGS,
1906 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001907 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001908 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1909 channel->channel);
1910 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01001911 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1912
Ben Hutchings8127d662013-08-29 19:19:29 +01001913 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01001914 ERF_DZ_TC_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01001915 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1916 channel->channel);
1917 }
1918}
1919
Shradha Shah02246a72015-05-06 00:58:14 +01001920static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1921 struct ethtool_wolinfo *wol) {}
1922
1923static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1924{
1925 return -EOPNOTSUPP;
1926}
1927
Ben Hutchings8127d662013-08-29 19:19:29 +01001928static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1929{
1930 wol->supported = 0;
1931 wol->wolopts = 0;
1932 memset(&wol->sopass, 0, sizeof(wol->sopass));
1933}
1934
1935static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1936{
1937 if (type != 0)
1938 return -EINVAL;
1939 return 0;
1940}
1941
1942static void efx_ef10_mcdi_request(struct efx_nic *efx,
1943 const efx_dword_t *hdr, size_t hdr_len,
1944 const efx_dword_t *sdu, size_t sdu_len)
1945{
1946 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1947 u8 *pdu = nic_data->mcdi_buf.addr;
1948
1949 memcpy(pdu, hdr, hdr_len);
1950 memcpy(pdu + hdr_len, sdu, sdu_len);
1951 wmb();
1952
1953 /* The hardware provides 'low' and 'high' (doorbell) registers
1954 * for passing the 64-bit address of an MCDI request to
1955 * firmware. However the dwords are swapped by firmware. The
1956 * least significant bits of the doorbell are then 0 for all
1957 * MCDI requests due to alignment.
1958 */
1959 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1960 ER_DZ_MC_DB_LWRD);
1961 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1962 ER_DZ_MC_DB_HWRD);
1963}
1964
1965static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1966{
1967 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1968 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1969
1970 rmb();
1971 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1972}
1973
1974static void
1975efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1976 size_t offset, size_t outlen)
1977{
1978 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1979 const u8 *pdu = nic_data->mcdi_buf.addr;
1980
1981 memcpy(outbuf, pdu + offset, outlen);
1982}
1983
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001984static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1985{
1986 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1987
1988 /* All our allocations have been reset */
1989 efx_ef10_reset_mc_allocations(efx);
1990
1991 /* The datapath firmware might have been changed */
1992 nic_data->must_check_datapath_caps = true;
1993
1994 /* MAC statistics have been cleared on the NIC; clear the local
1995 * statistic that we update with efx_update_diff_stat().
1996 */
1997 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1998}
1999
Ben Hutchings8127d662013-08-29 19:19:29 +01002000static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2001{
2002 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2003 int rc;
2004
2005 rc = efx_ef10_get_warm_boot_count(efx);
2006 if (rc < 0) {
2007 /* The firmware is presumably in the process of
2008 * rebooting. However, we are supposed to report each
2009 * reboot just once, so we must only do that once we
2010 * can read and store the updated warm boot count.
2011 */
2012 return 0;
2013 }
2014
2015 if (rc == nic_data->warm_boot_count)
2016 return 0;
2017
2018 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002019 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01002020
Ben Hutchings8127d662013-08-29 19:19:29 +01002021 return -EIO;
2022}
2023
2024/* Handle an MSI interrupt
2025 *
2026 * Handle an MSI hardware interrupt. This routine schedules event
2027 * queue processing. No interrupt acknowledgement cycle is necessary.
2028 * Also, we never need to check that the interrupt is for us, since
2029 * MSI interrupts cannot be shared.
2030 */
2031static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2032{
2033 struct efx_msi_context *context = dev_id;
2034 struct efx_nic *efx = context->efx;
2035
2036 netif_vdbg(efx, intr, efx->net_dev,
2037 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2038
2039 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2040 /* Note test interrupts */
2041 if (context->index == efx->irq_level)
2042 efx->last_irq_cpu = raw_smp_processor_id();
2043
2044 /* Schedule processing of the channel */
2045 efx_schedule_channel_irq(efx->channel[context->index]);
2046 }
2047
2048 return IRQ_HANDLED;
2049}
2050
2051static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2052{
2053 struct efx_nic *efx = dev_id;
2054 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2055 struct efx_channel *channel;
2056 efx_dword_t reg;
2057 u32 queues;
2058
2059 /* Read the ISR which also ACKs the interrupts */
2060 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2061 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2062
2063 if (queues == 0)
2064 return IRQ_NONE;
2065
2066 if (likely(soft_enabled)) {
2067 /* Note test interrupts */
2068 if (queues & (1U << efx->irq_level))
2069 efx->last_irq_cpu = raw_smp_processor_id();
2070
2071 efx_for_each_channel(channel, efx) {
2072 if (queues & 1)
2073 efx_schedule_channel_irq(channel);
2074 queues >>= 1;
2075 }
2076 }
2077
2078 netif_vdbg(efx, intr, efx->net_dev,
2079 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2080 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2081
2082 return IRQ_HANDLED;
2083}
2084
Jon Cooper942e2982016-08-26 15:13:30 +01002085static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002086{
2087 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2088
Jon Cooper942e2982016-08-26 15:13:30 +01002089 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2090 NULL) == 0)
2091 return -ENOTSUPP;
2092
Ben Hutchings8127d662013-08-29 19:19:29 +01002093 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2094
2095 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002096 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002097 inbuf, sizeof(inbuf), NULL, 0, NULL);
2098}
2099
2100static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2101{
2102 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2103 (tx_queue->ptr_mask + 1) *
2104 sizeof(efx_qword_t),
2105 GFP_KERNEL);
2106}
2107
2108/* This writes to the TX_DESC_WPTR and also pushes data */
2109static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2110 const efx_qword_t *txd)
2111{
2112 unsigned int write_ptr;
2113 efx_oword_t reg;
2114
2115 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2116 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2117 reg.qword[0] = *txd;
2118 efx_writeo_page(tx_queue->efx, &reg,
2119 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2120}
2121
Bert Kenwarde9117e52016-11-17 10:51:54 +00002122/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2123 */
2124static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2125 struct sk_buff *skb,
2126 bool *data_mapped)
2127{
2128 struct efx_tx_buffer *buffer;
2129 struct tcphdr *tcp;
2130 struct iphdr *ip;
2131
2132 u16 ipv4_id;
2133 u32 seqnum;
2134 u32 mss;
2135
Edward Creee01b16a2016-12-02 15:51:33 +00002136 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002137
2138 mss = skb_shinfo(skb)->gso_size;
2139
2140 if (unlikely(mss < 4)) {
2141 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2142 return -EINVAL;
2143 }
2144
2145 ip = ip_hdr(skb);
2146 if (ip->version == 4) {
2147 /* Modify IPv4 header if needed. */
2148 ip->tot_len = 0;
2149 ip->check = 0;
2150 ipv4_id = ip->id;
2151 } else {
2152 /* Modify IPv6 header if needed. */
2153 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2154
2155 ipv6->payload_len = 0;
2156 ipv4_id = 0;
2157 }
2158
2159 tcp = tcp_hdr(skb);
2160 seqnum = ntohl(tcp->seq);
2161
2162 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2163
2164 buffer->flags = EFX_TX_BUF_OPTION;
2165 buffer->len = 0;
2166 buffer->unmap_len = 0;
2167 EFX_POPULATE_QWORD_5(buffer->option,
2168 ESF_DZ_TX_DESC_IS_OPT, 1,
2169 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2170 ESF_DZ_TX_TSO_OPTION_TYPE,
2171 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2172 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2173 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2174 );
2175 ++tx_queue->insert_count;
2176
2177 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2178
2179 buffer->flags = EFX_TX_BUF_OPTION;
2180 buffer->len = 0;
2181 buffer->unmap_len = 0;
2182 EFX_POPULATE_QWORD_4(buffer->option,
2183 ESF_DZ_TX_DESC_IS_OPT, 1,
2184 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2185 ESF_DZ_TX_TSO_OPTION_TYPE,
2186 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2187 ESF_DZ_TX_TSO_TCP_MSS, mss
2188 );
2189 ++tx_queue->insert_count;
2190
2191 return 0;
2192}
2193
Edward Cree46d1efd2016-11-17 10:52:36 +00002194static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2195{
2196 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2197 u32 tso_versions = 0;
2198
2199 if (nic_data->datapath_caps &
2200 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2201 tso_versions |= BIT(1);
2202 if (nic_data->datapath_caps2 &
2203 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2204 tso_versions |= BIT(2);
2205 return tso_versions;
2206}
2207
Ben Hutchings8127d662013-08-29 19:19:29 +01002208static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2209{
2210 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2211 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002212 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2213 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2214 struct efx_channel *channel = tx_queue->channel;
2215 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002216 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002217 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002218 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002219 dma_addr_t dma_addr;
2220 efx_qword_t *txd;
2221 int rc;
2222 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002223 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002224
Bert Kenwarde9117e52016-11-17 10:51:54 +00002225 /* TSOv2 is a limited resource that can only be configured on a limited
2226 * number of queues. TSO without checksum offload is not really a thing,
2227 * so we only enable it for those queues.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002228 */
2229 if (csum_offload && (nic_data->datapath_caps2 &
2230 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2231 tso_v2 = true;
2232 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2233 channel->channel);
2234 }
2235
Ben Hutchings8127d662013-08-29 19:19:29 +01002236 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2237 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2238 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2239 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002240 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002241 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002242
2243 dma_addr = tx_queue->txd.buf.dma_addr;
2244
2245 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2246 tx_queue->queue, entries, (u64)dma_addr);
2247
2248 for (i = 0; i < entries; ++i) {
2249 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2250 dma_addr += EFX_BUF_SIZE;
2251 }
2252
2253 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2254
Edward Creee638ee12016-11-17 10:52:07 +00002255 do {
2256 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2257 /* This flag was removed from mcdi_pcol.h for
2258 * the non-_EXT version of INIT_TXQ. However,
2259 * firmware still honours it.
2260 */
2261 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2262 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2263 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2264
2265 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2266 NULL, 0, NULL);
2267 if (rc == -ENOSPC && tso_v2) {
2268 /* Retry without TSOv2 if we're short on contexts. */
2269 tso_v2 = false;
2270 netif_warn(efx, probe, efx->net_dev,
2271 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2272 } else if (rc) {
2273 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2274 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2275 NULL, 0, rc);
2276 goto fail;
2277 }
2278 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002279
2280 /* A previous user of this TX queue might have set us up the
2281 * bomb by writing a descriptor to the TX push collector but
2282 * not the doorbell. (Each collector belongs to a port, not a
2283 * queue or function, so cannot easily be reset.) We must
2284 * attempt to push a no-op descriptor in its place.
2285 */
2286 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2287 tx_queue->insert_count = 1;
2288 txd = efx_tx_desc(tx_queue, 0);
2289 EFX_POPULATE_QWORD_4(*txd,
2290 ESF_DZ_TX_DESC_IS_OPT, true,
2291 ESF_DZ_TX_OPTION_TYPE,
2292 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2293 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2294 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2295 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002296
Bert Kenwarde9117e52016-11-17 10:51:54 +00002297 if (tso_v2) {
2298 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2299 tx_queue->tso_version = 2;
2300 } else if (nic_data->datapath_caps &
2301 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002302 tx_queue->tso_version = 1;
2303 }
2304
Ben Hutchings8127d662013-08-29 19:19:29 +01002305 wmb();
2306 efx_ef10_push_tx_desc(tx_queue, txd);
2307
2308 return;
2309
2310fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002311 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2312 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002313}
2314
2315static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2316{
2317 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002318 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002319 struct efx_nic *efx = tx_queue->efx;
2320 size_t outlen;
2321 int rc;
2322
2323 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2324 tx_queue->queue);
2325
Edward Cree1e0b8122013-05-31 18:36:12 +01002326 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002327 outbuf, sizeof(outbuf), &outlen);
2328
2329 if (rc && rc != -EALREADY)
2330 goto fail;
2331
2332 return;
2333
2334fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002335 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2336 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002337}
2338
2339static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2340{
2341 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2342}
2343
2344/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2345static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2346{
2347 unsigned int write_ptr;
2348 efx_dword_t reg;
2349
2350 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2351 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2352 efx_writed_page(tx_queue->efx, &reg,
2353 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2354}
2355
Bert Kenwarde9117e52016-11-17 10:51:54 +00002356#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2357
2358static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2359 dma_addr_t dma_addr, unsigned int len)
2360{
2361 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2362 /* If we need to break across multiple descriptors we should
2363 * stop at a page boundary. This assumes the length limit is
2364 * greater than the page size.
2365 */
2366 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2367
2368 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2369 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2370 }
2371
2372 return len;
2373}
2374
Ben Hutchings8127d662013-08-29 19:19:29 +01002375static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2376{
2377 unsigned int old_write_count = tx_queue->write_count;
2378 struct efx_tx_buffer *buffer;
2379 unsigned int write_ptr;
2380 efx_qword_t *txd;
2381
Martin Habetsb2663a42015-11-02 12:51:31 +00002382 tx_queue->xmit_more_available = false;
2383 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2384 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002385
2386 do {
2387 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2388 buffer = &tx_queue->buffer[write_ptr];
2389 txd = efx_tx_desc(tx_queue, write_ptr);
2390 ++tx_queue->write_count;
2391
2392 /* Create TX descriptor ring entry */
2393 if (buffer->flags & EFX_TX_BUF_OPTION) {
2394 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002395 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2396 /* PIO descriptor */
2397 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002398 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002399 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002400 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2401 EFX_POPULATE_QWORD_3(
2402 *txd,
2403 ESF_DZ_TX_KER_CONT,
2404 buffer->flags & EFX_TX_BUF_CONT,
2405 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2406 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2407 }
2408 } while (tx_queue->write_count != tx_queue->insert_count);
2409
2410 wmb(); /* Ensure descriptors are written before they are fetched */
2411
2412 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2413 txd = efx_tx_desc(tx_queue,
2414 old_write_count & tx_queue->ptr_mask);
2415 efx_ef10_push_tx_desc(tx_queue, txd);
2416 ++tx_queue->pushes;
2417 } else {
2418 efx_ef10_notify_tx_desc(tx_queue);
2419 }
2420}
2421
Edward Creea33a4c72016-11-03 22:12:27 +00002422#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2423 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2424#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2425 1 << RSS_MODE_HASH_DST_PORT_LBN)
2426#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2427 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2428 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2429 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2430 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2431 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2432 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2433 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2434 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2435 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2436
2437static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2438{
2439 /* Firmware had a bug (sfc bug 61952) where it would not actually
2440 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2441 * This meant that it would always contain whatever was previously
2442 * in the MCDI buffer. Fortunately, all firmware versions with
2443 * this bug have the same default flags value for a newly-allocated
2444 * RSS context, and the only time we want to get the flags is just
2445 * after allocating. Moreover, the response has a 32-bit hole
2446 * where the context ID would be in the request, so we can use an
2447 * overlength buffer in the request and pre-fill the flags field
2448 * with what we believe the default to be. Thus if the firmware
2449 * has the bug, it will leave our pre-filled value in the flags
2450 * field of the response, and we will get the right answer.
2451 *
2452 * However, this does mean that this function should NOT be used if
2453 * the RSS context flags might not be their defaults - it is ONLY
2454 * reliably correct for a newly-allocated RSS context.
2455 */
2456 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2457 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2458 size_t outlen;
2459 int rc;
2460
2461 /* Check we have a hole for the context ID */
2462 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2463 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2464 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2465 RSS_CONTEXT_FLAGS_DEFAULT);
2466 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2467 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2468 if (rc == 0) {
2469 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2470 rc = -EIO;
2471 else
2472 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2473 }
2474 return rc;
2475}
2476
2477/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2478 * If we fail, we just leave the RSS context at its default hash settings,
2479 * which is safe but may slightly reduce performance.
2480 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2481 * just need to set the UDP ports flags (for both IP versions).
2482 */
2483static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2484{
2485 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2486 u32 flags;
2487
2488 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2489
2490 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2491 return;
2492 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2493 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2494 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2495 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002496 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2497 NULL, 0, NULL))
2498 /* Succeeded, so UDP 4-tuple is now enabled */
2499 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002500}
2501
Jon Cooper267c0152015-05-06 00:59:38 +01002502static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2503 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002504{
2505 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2506 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002507 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002508 size_t outlen;
2509 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002510 u32 alloc_type = exclusive ?
2511 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2512 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2513 unsigned rss_spread = exclusive ?
2514 efx->rss_spread :
2515 min(rounddown_pow_of_two(efx->rss_spread),
2516 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2517
2518 if (!exclusive && rss_spread == 1) {
2519 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2520 if (context_size)
2521 *context_size = 1;
2522 return 0;
2523 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002524
Jon Cooperdcb41232016-04-25 16:51:00 +01002525 if (nic_data->datapath_caps &
2526 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2527 return -EOPNOTSUPP;
2528
Ben Hutchings8127d662013-08-29 19:19:29 +01002529 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002530 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002531 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2532 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002533
2534 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2535 outbuf, sizeof(outbuf), &outlen);
2536 if (rc != 0)
2537 return rc;
2538
2539 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2540 return -EIO;
2541
2542 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2543
Jon Cooper267c0152015-05-06 00:59:38 +01002544 if (context_size)
2545 *context_size = rss_spread;
2546
Edward Creea33a4c72016-11-03 22:12:27 +00002547 if (nic_data->datapath_caps &
2548 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2549 efx_ef10_set_rss_flags(efx, *context);
2550
Ben Hutchings8127d662013-08-29 19:19:29 +01002551 return 0;
2552}
2553
2554static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2555{
2556 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2557 int rc;
2558
2559 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2560 context);
2561
2562 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2563 NULL, 0, NULL);
2564 WARN_ON(rc != 0);
2565}
2566
Jon Cooper267c0152015-05-06 00:59:38 +01002567static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
Edward Creef74d1992017-01-17 12:01:53 +00002568 const u32 *rx_indir_table, const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002569{
2570 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2571 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2572 int i, rc;
2573
2574 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2575 context);
2576 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2577 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2578
Edward Creef74d1992017-01-17 12:01:53 +00002579 /* This iterates over the length of efx->rx_indir_table, but copies
2580 * bytes from rx_indir_table. That's because the latter is a pointer
2581 * rather than an array, but should have the same length.
2582 * The efx->rx_hash_key loop below is similar.
2583 */
Ben Hutchings8127d662013-08-29 19:19:29 +01002584 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2585 MCDI_PTR(tablebuf,
2586 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002587 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002588
2589 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2590 sizeof(tablebuf), NULL, 0, NULL);
2591 if (rc != 0)
2592 return rc;
2593
2594 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2595 context);
2596 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2597 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2598 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
Edward Creef74d1992017-01-17 12:01:53 +00002599 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002600
2601 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2602 sizeof(keybuf), NULL, 0, NULL);
2603}
2604
2605static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2606{
2607 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2608
2609 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2610 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2611 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2612}
2613
Jon Cooper267c0152015-05-06 00:59:38 +01002614static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2615 unsigned *context_size)
2616{
2617 u32 new_rx_rss_context;
2618 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2619 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2620 false, context_size);
2621
2622 if (rc != 0)
2623 return rc;
2624
2625 nic_data->rx_rss_context = new_rx_rss_context;
2626 nic_data->rx_rss_context_exclusive = false;
2627 efx_set_default_rx_indir_table(efx);
2628 return 0;
2629}
2630
2631static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
Edward Creef74d1992017-01-17 12:01:53 +00002632 const u32 *rx_indir_table,
2633 const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002634{
2635 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2636 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002637 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002638
Jon Cooper267c0152015-05-06 00:59:38 +01002639 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2640 !nic_data->rx_rss_context_exclusive) {
2641 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2642 true, NULL);
2643 if (rc == -EOPNOTSUPP)
2644 return rc;
2645 else if (rc != 0)
2646 goto fail1;
2647 } else {
2648 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002649 }
2650
Jon Cooper267c0152015-05-06 00:59:38 +01002651 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
Edward Creef74d1992017-01-17 12:01:53 +00002652 rx_indir_table, key);
Ben Hutchings8127d662013-08-29 19:19:29 +01002653 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002654 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002655
Jon Cooper267c0152015-05-06 00:59:38 +01002656 if (nic_data->rx_rss_context != new_rx_rss_context)
2657 efx_ef10_rx_free_indir_table(efx);
2658 nic_data->rx_rss_context = new_rx_rss_context;
2659 nic_data->rx_rss_context_exclusive = true;
2660 if (rx_indir_table != efx->rx_indir_table)
2661 memcpy(efx->rx_indir_table, rx_indir_table,
2662 sizeof(efx->rx_indir_table));
Edward Creef74d1992017-01-17 12:01:53 +00002663 if (key != efx->rx_hash_key)
2664 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2665
Jon Cooper267c0152015-05-06 00:59:38 +01002666 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002667
Jon Cooper267c0152015-05-06 00:59:38 +01002668fail2:
2669 if (new_rx_rss_context != nic_data->rx_rss_context)
2670 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2671fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002672 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002673 return rc;
2674}
2675
Edward Creea707d182017-01-17 12:02:12 +00002676static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2677{
2678 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2679 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2680 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2681 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2682 size_t outlen;
2683 int rc, i;
2684
2685 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2686 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2687
2688 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2689 return -ENOENT;
2690
2691 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2692 nic_data->rx_rss_context);
2693 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2694 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2695 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2696 tablebuf, sizeof(tablebuf), &outlen);
2697 if (rc != 0)
2698 return rc;
2699
2700 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2701 return -EIO;
2702
2703 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2704 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2705 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2706
2707 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2708 nic_data->rx_rss_context);
2709 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2710 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2711 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2712 keybuf, sizeof(keybuf), &outlen);
2713 if (rc != 0)
2714 return rc;
2715
2716 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2717 return -EIO;
2718
2719 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2720 efx->rx_hash_key[i] = MCDI_PTR(
2721 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2722
2723 return 0;
2724}
2725
Jon Cooper267c0152015-05-06 00:59:38 +01002726static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
Edward Creef74d1992017-01-17 12:01:53 +00002727 const u32 *rx_indir_table,
2728 const u8 *key)
Jon Cooper267c0152015-05-06 00:59:38 +01002729{
2730 int rc;
2731
2732 if (efx->rss_spread == 1)
2733 return 0;
2734
Edward Creef74d1992017-01-17 12:01:53 +00002735 if (!key)
2736 key = efx->rx_hash_key;
2737
2738 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
Jon Cooper267c0152015-05-06 00:59:38 +01002739
2740 if (rc == -ENOBUFS && !user) {
2741 unsigned context_size;
2742 bool mismatch = false;
2743 size_t i;
2744
2745 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2746 i++)
2747 mismatch = rx_indir_table[i] !=
2748 ethtool_rxfh_indir_default(i, efx->rss_spread);
2749
2750 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2751 if (rc == 0) {
2752 if (context_size != efx->rss_spread)
2753 netif_warn(efx, probe, efx->net_dev,
2754 "Could not allocate an exclusive RSS"
2755 " context; allocated a shared one of"
2756 " different size."
2757 " Wanted %u, got %u.\n",
2758 efx->rss_spread, context_size);
2759 else if (mismatch)
2760 netif_warn(efx, probe, efx->net_dev,
2761 "Could not allocate an exclusive RSS"
2762 " context; allocated a shared one but"
2763 " could not apply custom"
2764 " indirection.\n");
2765 else
2766 netif_info(efx, probe, efx->net_dev,
2767 "Could not allocate an exclusive RSS"
2768 " context; allocated a shared one.\n");
2769 }
2770 }
2771 return rc;
2772}
2773
2774static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2775 const u32 *rx_indir_table
Edward Creef74d1992017-01-17 12:01:53 +00002776 __attribute__ ((unused)),
2777 const u8 *key
Jon Cooper267c0152015-05-06 00:59:38 +01002778 __attribute__ ((unused)))
2779{
2780 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2781
2782 if (user)
2783 return -EOPNOTSUPP;
2784 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2785 return 0;
2786 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002787}
2788
2789static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2790{
2791 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2792 (rx_queue->ptr_mask + 1) *
2793 sizeof(efx_qword_t),
2794 GFP_KERNEL);
2795}
2796
2797static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2798{
2799 MCDI_DECLARE_BUF(inbuf,
2800 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2801 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002802 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2803 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2804 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002805 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002806 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002807 dma_addr_t dma_addr;
2808 int rc;
2809 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002810 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002811
2812 rx_queue->scatter_n = 0;
2813 rx_queue->scatter_len = 0;
2814
2815 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2816 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2817 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2818 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2819 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002820 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2821 INIT_RXQ_IN_FLAG_PREFIX, 1,
2822 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002823 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002824 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002825
2826 dma_addr = rx_queue->rxd.buf.dma_addr;
2827
2828 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2829 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2830
2831 for (i = 0; i < entries; ++i) {
2832 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2833 dma_addr += EFX_BUF_SIZE;
2834 }
2835
2836 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2837
2838 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002839 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002840 if (rc)
2841 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2842 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002843}
2844
2845static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2846{
2847 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002848 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002849 struct efx_nic *efx = rx_queue->efx;
2850 size_t outlen;
2851 int rc;
2852
2853 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2854 efx_rx_queue_index(rx_queue));
2855
Edward Cree1e0b8122013-05-31 18:36:12 +01002856 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002857 outbuf, sizeof(outbuf), &outlen);
2858
2859 if (rc && rc != -EALREADY)
2860 goto fail;
2861
2862 return;
2863
2864fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002865 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2866 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002867}
2868
2869static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2870{
2871 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2872}
2873
2874/* This creates an entry in the RX descriptor queue */
2875static inline void
2876efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2877{
2878 struct efx_rx_buffer *rx_buf;
2879 efx_qword_t *rxd;
2880
2881 rxd = efx_rx_desc(rx_queue, index);
2882 rx_buf = efx_rx_buffer(rx_queue, index);
2883 EFX_POPULATE_QWORD_2(*rxd,
2884 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2885 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2886}
2887
2888static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2889{
2890 struct efx_nic *efx = rx_queue->efx;
2891 unsigned int write_count;
2892 efx_dword_t reg;
2893
2894 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2895 write_count = rx_queue->added_count & ~7;
2896 if (rx_queue->notified_count == write_count)
2897 return;
2898
2899 do
2900 efx_ef10_build_rx_desc(
2901 rx_queue,
2902 rx_queue->notified_count & rx_queue->ptr_mask);
2903 while (++rx_queue->notified_count != write_count);
2904
2905 wmb();
2906 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2907 write_count & rx_queue->ptr_mask);
2908 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2909 efx_rx_queue_index(rx_queue));
2910}
2911
2912static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2913
2914static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2915{
2916 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2917 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2918 efx_qword_t event;
2919
2920 EFX_POPULATE_QWORD_2(event,
2921 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2922 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2923
2924 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2925
2926 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2927 * already swapped the data to little-endian order.
2928 */
2929 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2930 sizeof(efx_qword_t));
2931
2932 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2933 inbuf, sizeof(inbuf), 0,
2934 efx_ef10_rx_defer_refill_complete, 0);
2935}
2936
2937static void
2938efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2939 int rc, efx_dword_t *outbuf,
2940 size_t outlen_actual)
2941{
2942 /* nothing to do */
2943}
2944
2945static int efx_ef10_ev_probe(struct efx_channel *channel)
2946{
2947 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2948 (channel->eventq_mask + 1) *
2949 sizeof(efx_qword_t),
2950 GFP_KERNEL);
2951}
2952
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002953static void efx_ef10_ev_fini(struct efx_channel *channel)
2954{
2955 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2956 MCDI_DECLARE_BUF_ERR(outbuf);
2957 struct efx_nic *efx = channel->efx;
2958 size_t outlen;
2959 int rc;
2960
2961 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2962
2963 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2964 outbuf, sizeof(outbuf), &outlen);
2965
2966 if (rc && rc != -EALREADY)
2967 goto fail;
2968
2969 return;
2970
2971fail:
2972 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2973 outbuf, outlen, rc);
2974}
2975
Ben Hutchings8127d662013-08-29 19:19:29 +01002976static int efx_ef10_ev_init(struct efx_channel *channel)
2977{
2978 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01002979 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2980 EFX_BUF_SIZE));
2981 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01002982 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2983 struct efx_nic *efx = channel->efx;
2984 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002985 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002986 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002987 dma_addr_t dma_addr;
2988 int rc;
2989 int i;
2990
2991 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002992
2993 /* Fill event queue with all ones (i.e. empty events) */
2994 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2995
2996 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2997 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2998 /* INIT_EVQ expects index in vector table, not absolute */
2999 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01003000 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3001 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3002 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3003 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3004 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3005 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3006 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3007
Bert Kenwarda9955602016-08-11 13:01:54 +01003008 if (nic_data->datapath_caps2 &
3009 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3010 /* Use the new generic approach to specifying event queue
3011 * configuration, requesting lower latency or higher throughput.
3012 * The options that actually get used appear in the output.
3013 */
3014 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3015 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3016 INIT_EVQ_V2_IN_FLAG_TYPE,
3017 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3018 } else {
3019 bool cut_thru = !(nic_data->datapath_caps &
3020 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3021
3022 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3023 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3024 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3025 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3026 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3027 }
3028
Ben Hutchings8127d662013-08-29 19:19:29 +01003029 dma_addr = channel->eventq.buf.dma_addr;
3030 for (i = 0; i < entries; ++i) {
3031 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3032 dma_addr += EFX_BUF_SIZE;
3033 }
3034
3035 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3036
3037 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3038 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01003039
3040 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3041 netif_dbg(efx, drv, efx->net_dev,
3042 "Channel %d using event queue flags %08x\n",
3043 channel->channel,
3044 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3045
Ben Hutchings8127d662013-08-29 19:19:29 +01003046 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003047 if (channel->channel || rc)
3048 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003049
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003050 /* Successfully created event queue on channel 0 */
3051 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01003052 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01003053 /* GET_WORKAROUNDS was implemented before this workaround,
3054 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01003055 */
3056 nic_data->workaround_26807 = false;
3057 rc = 0;
3058 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003059 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01003060 } else {
3061 nic_data->workaround_26807 =
3062 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01003063
Edward Cree832dc9e2015-07-21 15:09:31 +01003064 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3065 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003066 unsigned int flags;
3067
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01003068 rc = efx_mcdi_set_workaround(efx,
3069 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003070 true, &flags);
3071
3072 if (!rc) {
3073 if (flags &
3074 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3075 netif_info(efx, drv, efx->net_dev,
3076 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00003077
3078 /* With MCFW v4.6.x and earlier, the
3079 * boot count will have incremented,
3080 * so re-read the warm_boot_count
3081 * value now to ensure this function
3082 * doesn't think it has changed next
3083 * time it checks.
3084 */
3085 rc = efx_ef10_get_warm_boot_count(efx);
3086 if (rc >= 0) {
3087 nic_data->warm_boot_count = rc;
3088 rc = 0;
3089 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003090 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003091 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003092 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01003093 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003094 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003095 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003096 }
3097
3098 if (!rc)
3099 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003100
3101fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003102 efx_ef10_ev_fini(channel);
3103 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003104}
3105
3106static void efx_ef10_ev_remove(struct efx_channel *channel)
3107{
3108 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3109}
3110
3111static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3112 unsigned int rx_queue_label)
3113{
3114 struct efx_nic *efx = rx_queue->efx;
3115
3116 netif_info(efx, hw, efx->net_dev,
3117 "rx event arrived on queue %d labeled as queue %u\n",
3118 efx_rx_queue_index(rx_queue), rx_queue_label);
3119
3120 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3121}
3122
3123static void
3124efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3125 unsigned int actual, unsigned int expected)
3126{
3127 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3128 struct efx_nic *efx = rx_queue->efx;
3129
3130 netif_info(efx, hw, efx->net_dev,
3131 "dropped %d events (index=%d expected=%d)\n",
3132 dropped, actual, expected);
3133
3134 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3135}
3136
3137/* partially received RX was aborted. clean up. */
3138static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3139{
3140 unsigned int rx_desc_ptr;
3141
Ben Hutchings8127d662013-08-29 19:19:29 +01003142 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3143 "scattered RX aborted (dropping %u buffers)\n",
3144 rx_queue->scatter_n);
3145
3146 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3147
3148 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3149 0, EFX_RX_PKT_DISCARD);
3150
3151 rx_queue->removed_count += rx_queue->scatter_n;
3152 rx_queue->scatter_n = 0;
3153 rx_queue->scatter_len = 0;
3154 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3155}
3156
Jon Coopera0ee3542017-02-08 16:50:40 +00003157static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3158 unsigned int n_packets,
3159 unsigned int rx_encap_hdr,
3160 unsigned int rx_l3_class,
3161 unsigned int rx_l4_class,
3162 const efx_qword_t *event)
3163{
3164 struct efx_nic *efx = channel->efx;
3165
3166 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
3167 if (!efx->loopback_selftest)
3168 channel->n_rx_eth_crc_err += n_packets;
3169 return EFX_RX_PKT_DISCARD;
3170 }
3171 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3172 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3173 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3174 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3175 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3176 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3177 netdev_WARN(efx->net_dev,
3178 "invalid class for RX_IPCKSUM_ERR: event="
3179 EFX_QWORD_FMT "\n",
3180 EFX_QWORD_VAL(*event));
3181 if (!efx->loopback_selftest)
3182 *(rx_encap_hdr ?
3183 &channel->n_rx_outer_ip_hdr_chksum_err :
3184 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3185 return 0;
3186 }
3187 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3188 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3189 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3190 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3191 (rx_l4_class != ESE_DZ_L4_CLASS_TCP &&
3192 rx_l4_class != ESE_DZ_L4_CLASS_UDP))))
3193 netdev_WARN(efx->net_dev,
3194 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3195 EFX_QWORD_FMT "\n",
3196 EFX_QWORD_VAL(*event));
3197 if (!efx->loopback_selftest)
3198 *(rx_encap_hdr ?
3199 &channel->n_rx_outer_tcp_udp_chksum_err :
3200 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3201 return 0;
3202 }
3203 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3204 if (unlikely(!rx_encap_hdr))
3205 netdev_WARN(efx->net_dev,
3206 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3207 EFX_QWORD_FMT "\n",
3208 EFX_QWORD_VAL(*event));
3209 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3210 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3211 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3212 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3213 netdev_WARN(efx->net_dev,
3214 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3215 EFX_QWORD_FMT "\n",
3216 EFX_QWORD_VAL(*event));
3217 if (!efx->loopback_selftest)
3218 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3219 return 0;
3220 }
3221 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3222 if (unlikely(!rx_encap_hdr))
3223 netdev_WARN(efx->net_dev,
3224 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3225 EFX_QWORD_FMT "\n",
3226 EFX_QWORD_VAL(*event));
3227 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3228 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3229 (rx_l4_class != ESE_DZ_L4_CLASS_TCP &&
3230 rx_l4_class != ESE_DZ_L4_CLASS_UDP)))
3231 netdev_WARN(efx->net_dev,
3232 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3233 EFX_QWORD_FMT "\n",
3234 EFX_QWORD_VAL(*event));
3235 if (!efx->loopback_selftest)
3236 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3237 return 0;
3238 }
3239
3240 WARN_ON(1); /* No error bits were recognised */
3241 return 0;
3242}
3243
Ben Hutchings8127d662013-08-29 19:19:29 +01003244static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3245 const efx_qword_t *event)
3246{
Jon Coopera0ee3542017-02-08 16:50:40 +00003247 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3248 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
Ben Hutchings8127d662013-08-29 19:19:29 +01003249 unsigned int n_descs, n_packets, i;
3250 struct efx_nic *efx = channel->efx;
Jon Coopera0ee3542017-02-08 16:50:40 +00003251 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003252 struct efx_rx_queue *rx_queue;
Jon Coopera0ee3542017-02-08 16:50:40 +00003253 efx_qword_t errors;
Ben Hutchings8127d662013-08-29 19:19:29 +01003254 bool rx_cont;
3255 u16 flags = 0;
3256
3257 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3258 return 0;
3259
3260 /* Basic packet information */
3261 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3262 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3263 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
Jon Coopera0ee3542017-02-08 16:50:40 +00003264 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003265 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3266 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
Jon Coopera0ee3542017-02-08 16:50:40 +00003267 rx_encap_hdr =
3268 nic_data->datapath_caps &
3269 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3270 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3271 ESE_EZ_ENCAP_HDR_NONE;
Ben Hutchings8127d662013-08-29 19:19:29 +01003272
Ben Hutchings48ce5632013-11-01 16:42:44 +00003273 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3274 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3275 EFX_QWORD_FMT "\n",
3276 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003277
3278 rx_queue = efx_channel_get_rx_queue(channel);
3279
3280 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3281 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3282
3283 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3284 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3285
3286 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003287 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3288
Ben Hutchings8127d662013-08-29 19:19:29 +01003289 /* detect rx abort */
3290 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003291 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3292 netdev_WARN(efx->net_dev,
3293 "invalid RX abort: scatter_n=%u event="
3294 EFX_QWORD_FMT "\n",
3295 rx_queue->scatter_n,
3296 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003297 efx_ef10_handle_rx_abort(rx_queue);
3298 return 0;
3299 }
3300
Ben Hutchings92a04162013-09-24 23:21:57 +01003301 /* Check that RX completion merging is valid, i.e.
3302 * the current firmware supports it and this is a
3303 * non-scattered packet.
3304 */
3305 if (!(nic_data->datapath_caps &
3306 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3307 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003308 efx_ef10_handle_rx_bad_lbits(
3309 rx_queue, next_ptr_lbits,
3310 (rx_queue->removed_count +
3311 rx_queue->scatter_n + 1) &
3312 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3313 return 0;
3314 }
3315
3316 /* Merged completion for multiple non-scattered packets */
3317 rx_queue->scatter_n = 1;
3318 rx_queue->scatter_len = 0;
3319 n_packets = n_descs;
3320 ++channel->n_rx_merge_events;
3321 channel->n_rx_merge_packets += n_packets;
3322 flags |= EFX_RX_PKT_PREFIX_LEN;
3323 } else {
3324 ++rx_queue->scatter_n;
3325 rx_queue->scatter_len += rx_bytes;
3326 if (rx_cont)
3327 return 0;
3328 n_packets = 1;
3329 }
3330
Jon Coopera0ee3542017-02-08 16:50:40 +00003331 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3332 ESF_DZ_RX_IPCKSUM_ERR, 1,
3333 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3334 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3335 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3336 EFX_AND_QWORD(errors, *event, errors);
3337 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3338 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
3339 rx_l3_class, rx_l4_class,
3340 rx_encap_hdr, event);
3341 } else {
3342 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3343 rx_l4_class == ESE_DZ_L4_CLASS_UDP)
3344 flags |= EFX_RX_PKT_CSUMMED;
Ben Hutchings8127d662013-08-29 19:19:29 +01003345 }
3346
3347 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3348 flags |= EFX_RX_PKT_TCP;
3349
3350 channel->irq_mod_score += 2 * n_packets;
3351
3352 /* Handle received packet(s) */
3353 for (i = 0; i < n_packets; i++) {
3354 efx_rx_packet(rx_queue,
3355 rx_queue->removed_count & rx_queue->ptr_mask,
3356 rx_queue->scatter_n, rx_queue->scatter_len,
3357 flags);
3358 rx_queue->removed_count += rx_queue->scatter_n;
3359 }
3360
3361 rx_queue->scatter_n = 0;
3362 rx_queue->scatter_len = 0;
3363
3364 return n_packets;
3365}
3366
3367static int
3368efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3369{
3370 struct efx_nic *efx = channel->efx;
3371 struct efx_tx_queue *tx_queue;
3372 unsigned int tx_ev_desc_ptr;
3373 unsigned int tx_ev_q_label;
3374 int tx_descs = 0;
3375
3376 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
3377 return 0;
3378
3379 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3380 return 0;
3381
3382 /* Transmit completion */
3383 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3384 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3385 tx_queue = efx_channel_get_tx_queue(channel,
3386 tx_ev_q_label % EFX_TXQ_TYPES);
3387 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3388 tx_queue->ptr_mask);
3389 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3390
3391 return tx_descs;
3392}
3393
3394static void
3395efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3396{
3397 struct efx_nic *efx = channel->efx;
3398 int subcode;
3399
3400 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3401
3402 switch (subcode) {
3403 case ESE_DZ_DRV_TIMER_EV:
3404 case ESE_DZ_DRV_WAKE_UP_EV:
3405 break;
3406 case ESE_DZ_DRV_START_UP_EV:
3407 /* event queue init complete. ok. */
3408 break;
3409 default:
3410 netif_err(efx, hw, efx->net_dev,
3411 "channel %d unknown driver event type %d"
3412 " (data " EFX_QWORD_FMT ")\n",
3413 channel->channel, subcode,
3414 EFX_QWORD_VAL(*event));
3415
3416 }
3417}
3418
3419static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3420 efx_qword_t *event)
3421{
3422 struct efx_nic *efx = channel->efx;
3423 u32 subcode;
3424
3425 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3426
3427 switch (subcode) {
3428 case EFX_EF10_TEST:
3429 channel->event_test_cpu = raw_smp_processor_id();
3430 break;
3431 case EFX_EF10_REFILL:
3432 /* The queue must be empty, so we won't receive any rx
3433 * events, so efx_process_channel() won't refill the
3434 * queue. Refill it here
3435 */
Jon Coopercce28792013-10-02 11:04:14 +01003436 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003437 break;
3438 default:
3439 netif_err(efx, hw, efx->net_dev,
3440 "channel %d unknown driver event type %u"
3441 " (data " EFX_QWORD_FMT ")\n",
3442 channel->channel, (unsigned) subcode,
3443 EFX_QWORD_VAL(*event));
3444 }
3445}
3446
3447static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3448{
3449 struct efx_nic *efx = channel->efx;
3450 efx_qword_t event, *p_event;
3451 unsigned int read_ptr;
3452 int ev_code;
3453 int tx_descs = 0;
3454 int spent = 0;
3455
Eric W. Biederman75363a42014-03-14 18:11:22 -07003456 if (quota <= 0)
3457 return spent;
3458
Ben Hutchings8127d662013-08-29 19:19:29 +01003459 read_ptr = channel->eventq_read_ptr;
3460
3461 for (;;) {
3462 p_event = efx_event(channel, read_ptr);
3463 event = *p_event;
3464
3465 if (!efx_event_present(&event))
3466 break;
3467
3468 EFX_SET_QWORD(*p_event);
3469
3470 ++read_ptr;
3471
3472 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3473
3474 netif_vdbg(efx, drv, efx->net_dev,
3475 "processing event on %d " EFX_QWORD_FMT "\n",
3476 channel->channel, EFX_QWORD_VAL(event));
3477
3478 switch (ev_code) {
3479 case ESE_DZ_EV_CODE_MCDI_EV:
3480 efx_mcdi_process_event(channel, &event);
3481 break;
3482 case ESE_DZ_EV_CODE_RX_EV:
3483 spent += efx_ef10_handle_rx_event(channel, &event);
3484 if (spent >= quota) {
3485 /* XXX can we split a merged event to
3486 * avoid going over-quota?
3487 */
3488 spent = quota;
3489 goto out;
3490 }
3491 break;
3492 case ESE_DZ_EV_CODE_TX_EV:
3493 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3494 if (tx_descs > efx->txq_entries) {
3495 spent = quota;
3496 goto out;
3497 } else if (++spent == quota) {
3498 goto out;
3499 }
3500 break;
3501 case ESE_DZ_EV_CODE_DRIVER_EV:
3502 efx_ef10_handle_driver_event(channel, &event);
3503 if (++spent == quota)
3504 goto out;
3505 break;
3506 case EFX_EF10_DRVGEN_EV:
3507 efx_ef10_handle_driver_generated_event(channel, &event);
3508 break;
3509 default:
3510 netif_err(efx, hw, efx->net_dev,
3511 "channel %d unknown event type %d"
3512 " (data " EFX_QWORD_FMT ")\n",
3513 channel->channel, ev_code,
3514 EFX_QWORD_VAL(event));
3515 }
3516 }
3517
3518out:
3519 channel->eventq_read_ptr = read_ptr;
3520 return spent;
3521}
3522
3523static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3524{
3525 struct efx_nic *efx = channel->efx;
3526 efx_dword_t rptr;
3527
3528 if (EFX_EF10_WORKAROUND_35388(efx)) {
3529 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3530 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3531 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3532 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3533
3534 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3535 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3536 ERF_DD_EVQ_IND_RPTR,
3537 (channel->eventq_read_ptr &
3538 channel->eventq_mask) >>
3539 ERF_DD_EVQ_IND_RPTR_WIDTH);
3540 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3541 channel->channel);
3542 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3543 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3544 ERF_DD_EVQ_IND_RPTR,
3545 channel->eventq_read_ptr &
3546 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3547 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3548 channel->channel);
3549 } else {
3550 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3551 channel->eventq_read_ptr &
3552 channel->eventq_mask);
3553 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3554 }
3555}
3556
3557static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3558{
3559 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3560 struct efx_nic *efx = channel->efx;
3561 efx_qword_t event;
3562 int rc;
3563
3564 EFX_POPULATE_QWORD_2(event,
3565 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3566 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3567
3568 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3569
3570 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3571 * already swapped the data to little-endian order.
3572 */
3573 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3574 sizeof(efx_qword_t));
3575
3576 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3577 NULL, 0, NULL);
3578 if (rc != 0)
3579 goto fail;
3580
3581 return;
3582
3583fail:
3584 WARN_ON(true);
3585 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3586}
3587
3588void efx_ef10_handle_drain_event(struct efx_nic *efx)
3589{
3590 if (atomic_dec_and_test(&efx->active_queues))
3591 wake_up(&efx->flush_wq);
3592
3593 WARN_ON(atomic_read(&efx->active_queues) < 0);
3594}
3595
3596static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3597{
3598 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3599 struct efx_channel *channel;
3600 struct efx_tx_queue *tx_queue;
3601 struct efx_rx_queue *rx_queue;
3602 int pending;
3603
3604 /* If the MC has just rebooted, the TX/RX queues will have already been
3605 * torn down, but efx->active_queues needs to be set to zero.
3606 */
3607 if (nic_data->must_realloc_vis) {
3608 atomic_set(&efx->active_queues, 0);
3609 return 0;
3610 }
3611
3612 /* Do not attempt to write to the NIC during EEH recovery */
3613 if (efx->state != STATE_RECOVERY) {
3614 efx_for_each_channel(channel, efx) {
3615 efx_for_each_channel_rx_queue(rx_queue, channel)
3616 efx_ef10_rx_fini(rx_queue);
3617 efx_for_each_channel_tx_queue(tx_queue, channel)
3618 efx_ef10_tx_fini(tx_queue);
3619 }
3620
3621 wait_event_timeout(efx->flush_wq,
3622 atomic_read(&efx->active_queues) == 0,
3623 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3624 pending = atomic_read(&efx->active_queues);
3625 if (pending) {
3626 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3627 pending);
3628 return -ETIMEDOUT;
3629 }
3630 }
3631
3632 return 0;
3633}
3634
Edward Creee2835462014-04-16 19:27:48 +01003635static void efx_ef10_prepare_flr(struct efx_nic *efx)
3636{
3637 atomic_set(&efx->active_queues, 0);
3638}
3639
Ben Hutchings8127d662013-08-29 19:19:29 +01003640static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3641 const struct efx_filter_spec *right)
3642{
3643 if ((left->match_flags ^ right->match_flags) |
3644 ((left->flags ^ right->flags) &
3645 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3646 return false;
3647
3648 return memcmp(&left->outer_vid, &right->outer_vid,
3649 sizeof(struct efx_filter_spec) -
3650 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3651}
3652
3653static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3654{
3655 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3656 return jhash2((const u32 *)&spec->outer_vid,
3657 (sizeof(struct efx_filter_spec) -
3658 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3659 0);
3660 /* XXX should we randomise the initval? */
3661}
3662
3663/* Decide whether a filter should be exclusive or else should allow
3664 * delivery to additional recipients. Currently we decide that
3665 * filters for specific local unicast MAC and IP addresses are
3666 * exclusive.
3667 */
3668static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3669{
3670 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3671 !is_multicast_ether_addr(spec->loc_mac))
3672 return true;
3673
3674 if ((spec->match_flags &
3675 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3676 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3677 if (spec->ether_type == htons(ETH_P_IP) &&
3678 !ipv4_is_multicast(spec->loc_host[0]))
3679 return true;
3680 if (spec->ether_type == htons(ETH_P_IPV6) &&
3681 ((const u8 *)spec->loc_host)[0] != 0xff)
3682 return true;
3683 }
3684
3685 return false;
3686}
3687
3688static struct efx_filter_spec *
3689efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3690 unsigned int filter_idx)
3691{
3692 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3693 ~EFX_EF10_FILTER_FLAGS);
3694}
3695
3696static unsigned int
3697efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3698 unsigned int filter_idx)
3699{
3700 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3701}
3702
3703static void
3704efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3705 unsigned int filter_idx,
3706 const struct efx_filter_spec *spec,
3707 unsigned int flags)
3708{
3709 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3710}
3711
Edward Cree9b410802017-01-27 15:02:52 +00003712static void
3713efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
3714 const struct efx_filter_spec *spec,
3715 efx_dword_t *inbuf)
3716{
3717 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
3718 u32 match_fields = 0, uc_match, mc_match;
3719
3720 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3721 efx_ef10_filter_is_exclusive(spec) ?
3722 MC_CMD_FILTER_OP_IN_OP_INSERT :
3723 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3724
3725 /* Convert match flags and values. Unlike almost
3726 * everything else in MCDI, these fields are in
3727 * network byte order.
3728 */
3729#define COPY_VALUE(value, mcdi_field) \
3730 do { \
3731 match_fields |= \
3732 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3733 mcdi_field ## _LBN; \
3734 BUILD_BUG_ON( \
3735 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3736 sizeof(value)); \
3737 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3738 &value, sizeof(value)); \
3739 } while (0)
3740#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3741 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3742 COPY_VALUE(spec->gen_field, mcdi_field); \
3743 }
3744 /* Handle encap filters first. They will always be mismatch
3745 * (unknown UC or MC) filters
3746 */
3747 if (encap_type) {
3748 /* ether_type and outer_ip_proto need to be variables
3749 * because COPY_VALUE wants to memcpy them
3750 */
3751 __be16 ether_type =
3752 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
3753 ETH_P_IPV6 : ETH_P_IP);
3754 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
3755 u8 outer_ip_proto;
3756
3757 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
3758 case EFX_ENCAP_TYPE_VXLAN:
3759 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
3760 /* fallthrough */
3761 case EFX_ENCAP_TYPE_GENEVE:
3762 COPY_VALUE(ether_type, ETHER_TYPE);
3763 outer_ip_proto = IPPROTO_UDP;
3764 COPY_VALUE(outer_ip_proto, IP_PROTO);
3765 /* We always need to set the type field, even
3766 * though we're not matching on the TNI.
3767 */
3768 MCDI_POPULATE_DWORD_1(inbuf,
3769 FILTER_OP_EXT_IN_VNI_OR_VSID,
3770 FILTER_OP_EXT_IN_VNI_TYPE,
3771 vni_type);
3772 break;
3773 case EFX_ENCAP_TYPE_NVGRE:
3774 COPY_VALUE(ether_type, ETHER_TYPE);
3775 outer_ip_proto = IPPROTO_GRE;
3776 COPY_VALUE(outer_ip_proto, IP_PROTO);
3777 break;
3778 default:
3779 WARN_ON(1);
3780 }
3781
3782 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
3783 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
3784 } else {
3785 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3786 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
3787 }
3788
3789 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3790 match_fields |=
3791 is_multicast_ether_addr(spec->loc_mac) ?
3792 1 << mc_match :
3793 1 << uc_match;
3794 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3795 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3796 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3797 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3798 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3799 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3800 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3801 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3802 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3803 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3804#undef COPY_FIELD
3805#undef COPY_VALUE
3806 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3807 match_fields);
3808}
3809
Ben Hutchings8127d662013-08-29 19:19:29 +01003810static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3811 const struct efx_filter_spec *spec,
3812 efx_dword_t *inbuf, u64 handle,
3813 bool replacing)
3814{
3815 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003816 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003817
Edward Cree9b410802017-01-27 15:02:52 +00003818 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003819
Jon Cooperdcb41232016-04-25 16:51:00 +01003820 /* Remove RSS flag if we don't have an RSS context. */
3821 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3822 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3823 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3824 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3825
Ben Hutchings8127d662013-08-29 19:19:29 +01003826 if (replacing) {
3827 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3828 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3829 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3830 } else {
Edward Cree9b410802017-01-27 15:02:52 +00003831 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01003832 }
3833
Daniel Pieczko45b24492015-05-06 00:57:14 +01003834 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003835 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3836 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3837 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3838 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003839 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003840 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3841 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003842 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3843 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3844 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003845 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003846 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003847 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3848 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003849 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003850 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3851 spec->rss_context !=
3852 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3853 spec->rss_context : nic_data->rx_rss_context);
3854}
3855
3856static int efx_ef10_filter_push(struct efx_nic *efx,
3857 const struct efx_filter_spec *spec,
3858 u64 *handle, bool replacing)
3859{
Edward Cree9b410802017-01-27 15:02:52 +00003860 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
3861 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003862 int rc;
3863
3864 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3865 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3866 outbuf, sizeof(outbuf), NULL);
3867 if (rc == 0)
3868 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003869 if (rc == -ENOSPC)
3870 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003871 return rc;
3872}
3873
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003874static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003875{
Edward Cree9b410802017-01-27 15:02:52 +00003876 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003877 unsigned int match_flags = spec->match_flags;
Edward Cree9b410802017-01-27 15:02:52 +00003878 unsigned int uc_match, mc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003879 u32 mcdi_flags = 0;
3880
Edward Cree9b410802017-01-27 15:02:52 +00003881#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
3882 unsigned int old_match_flags = match_flags; \
3883 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3884 if (match_flags != old_match_flags) \
3885 mcdi_flags |= \
3886 (1 << ((encap) ? \
3887 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
3888 mcdi_field ## _LBN : \
3889 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
3890 mcdi_field ## _LBN)); \
3891 }
3892 /* inner or outer based on encap type */
3893 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
3894 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
3895 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
3896 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
3897 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
3898 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
3899 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
3900 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
3901 /* always outer */
3902 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
3903 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
3904#undef MAP_FILTER_TO_MCDI_FLAG
3905
3906 /* special handling for encap type, and mismatch */
3907 if (encap_type) {
3908 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
3909 mcdi_flags |=
3910 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
3911 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
3912
3913 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
3914 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
3915 } else {
3916 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3917 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
3918 }
3919
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003920 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3921 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3922 mcdi_flags |=
3923 is_multicast_ether_addr(spec->loc_mac) ?
Edward Cree9b410802017-01-27 15:02:52 +00003924 1 << mc_match :
3925 1 << uc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003926 }
3927
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003928 /* Did we map them all? */
3929 WARN_ON_ONCE(match_flags);
3930
3931 return mcdi_flags;
3932}
3933
3934static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3935 const struct efx_filter_spec *spec)
3936{
3937 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003938 unsigned int match_pri;
3939
3940 for (match_pri = 0;
3941 match_pri < table->rx_match_count;
3942 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003943 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003944 return match_pri;
3945
3946 return -EPROTONOSUPPORT;
3947}
3948
3949static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3950 struct efx_filter_spec *spec,
3951 bool replace_equal)
3952{
3953 struct efx_ef10_filter_table *table = efx->filter_state;
3954 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3955 struct efx_filter_spec *saved_spec;
3956 unsigned int match_pri, hash;
3957 unsigned int priv_flags;
3958 bool replacing = false;
3959 int ins_index = -1;
3960 DEFINE_WAIT(wait);
3961 bool is_mc_recip;
3962 s32 rc;
3963
3964 /* For now, only support RX filters */
3965 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3966 EFX_FILTER_FLAG_RX)
3967 return -EINVAL;
3968
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003969 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003970 if (rc < 0)
3971 return rc;
3972 match_pri = rc;
3973
3974 hash = efx_ef10_filter_hash(spec);
3975 is_mc_recip = efx_filter_is_mc_recipient(spec);
3976 if (is_mc_recip)
3977 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3978
3979 /* Find any existing filters with the same match tuple or
3980 * else a free slot to insert at. If any of them are busy,
3981 * we have to wait and retry.
3982 */
3983 for (;;) {
3984 unsigned int depth = 1;
3985 unsigned int i;
3986
3987 spin_lock_bh(&efx->filter_lock);
3988
3989 for (;;) {
3990 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3991 saved_spec = efx_ef10_filter_entry_spec(table, i);
3992
3993 if (!saved_spec) {
3994 if (ins_index < 0)
3995 ins_index = i;
3996 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3997 if (table->entry[i].spec &
3998 EFX_EF10_FILTER_FLAG_BUSY)
3999 break;
4000 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004001 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004002 rc = -EPERM;
4003 goto out_unlock;
4004 }
4005 if (!is_mc_recip) {
4006 /* This is the only one */
4007 if (spec->priority ==
4008 saved_spec->priority &&
4009 !replace_equal) {
4010 rc = -EEXIST;
4011 goto out_unlock;
4012 }
4013 ins_index = i;
4014 goto found;
4015 } else if (spec->priority >
4016 saved_spec->priority ||
4017 (spec->priority ==
4018 saved_spec->priority &&
4019 replace_equal)) {
4020 if (ins_index < 0)
4021 ins_index = i;
4022 else
4023 __set_bit(depth, mc_rem_map);
4024 }
4025 }
4026
4027 /* Once we reach the maximum search depth, use
4028 * the first suitable slot or return -EBUSY if
4029 * there was none
4030 */
4031 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4032 if (ins_index < 0) {
4033 rc = -EBUSY;
4034 goto out_unlock;
4035 }
4036 goto found;
4037 }
4038
4039 ++depth;
4040 }
4041
4042 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4043 spin_unlock_bh(&efx->filter_lock);
4044 schedule();
4045 }
4046
4047found:
4048 /* Create a software table entry if necessary, and mark it
4049 * busy. We might yet fail to insert, but any attempt to
4050 * insert a conflicting filter while we're waiting for the
4051 * firmware must find the busy entry.
4052 */
4053 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4054 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004055 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4056 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004057 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004058 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4059 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004060 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004061 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01004062 rc = ins_index;
4063 goto out_unlock;
4064 }
4065 replacing = true;
4066 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4067 } else {
4068 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4069 if (!saved_spec) {
4070 rc = -ENOMEM;
4071 goto out_unlock;
4072 }
4073 *saved_spec = *spec;
4074 priv_flags = 0;
4075 }
4076 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4077 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4078
4079 /* Mark lower-priority multicast recipients busy prior to removal */
4080 if (is_mc_recip) {
4081 unsigned int depth, i;
4082
4083 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4084 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4085 if (test_bit(depth, mc_rem_map))
4086 table->entry[i].spec |=
4087 EFX_EF10_FILTER_FLAG_BUSY;
4088 }
4089 }
4090
4091 spin_unlock_bh(&efx->filter_lock);
4092
4093 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4094 replacing);
4095
4096 /* Finalise the software table entry */
4097 spin_lock_bh(&efx->filter_lock);
4098 if (rc == 0) {
4099 if (replacing) {
4100 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004101 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4102 saved_spec->flags |=
4103 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004104 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004105 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004106 saved_spec->flags |= spec->flags;
4107 saved_spec->rss_context = spec->rss_context;
4108 saved_spec->dmaq_id = spec->dmaq_id;
4109 }
4110 } else if (!replacing) {
4111 kfree(saved_spec);
4112 saved_spec = NULL;
4113 }
4114 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4115
4116 /* Remove and finalise entries for lower-priority multicast
4117 * recipients
4118 */
4119 if (is_mc_recip) {
4120 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4121 unsigned int depth, i;
4122
4123 memset(inbuf, 0, sizeof(inbuf));
4124
4125 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4126 if (!test_bit(depth, mc_rem_map))
4127 continue;
4128
4129 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4130 saved_spec = efx_ef10_filter_entry_spec(table, i);
4131 priv_flags = efx_ef10_filter_entry_flags(table, i);
4132
4133 if (rc == 0) {
4134 spin_unlock_bh(&efx->filter_lock);
4135 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4136 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4137 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4138 table->entry[i].handle);
4139 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4140 inbuf, sizeof(inbuf),
4141 NULL, 0, NULL);
4142 spin_lock_bh(&efx->filter_lock);
4143 }
4144
4145 if (rc == 0) {
4146 kfree(saved_spec);
4147 saved_spec = NULL;
4148 priv_flags = 0;
4149 } else {
4150 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4151 }
4152 efx_ef10_filter_set_entry(table, i, saved_spec,
4153 priv_flags);
4154 }
4155 }
4156
4157 /* If successful, return the inserted filter ID */
4158 if (rc == 0)
4159 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
4160
4161 wake_up_all(&table->waitq);
4162out_unlock:
4163 spin_unlock_bh(&efx->filter_lock);
4164 finish_wait(&table->waitq, &wait);
4165 return rc;
4166}
4167
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08004168static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01004169{
4170 /* no need to do anything here on EF10 */
4171}
4172
4173/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004174 * If !by_index, remove by ID
4175 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01004176 * Filter ID may come from userland and must be range-checked.
4177 */
4178static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004179 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004180 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01004181{
4182 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4183 struct efx_ef10_filter_table *table = efx->filter_state;
4184 MCDI_DECLARE_BUF(inbuf,
4185 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4186 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4187 struct efx_filter_spec *spec;
4188 DEFINE_WAIT(wait);
4189 int rc;
4190
4191 /* Find the software table entry and mark it busy. Don't
4192 * remove it yet; any attempt to update while we're waiting
4193 * for the firmware must find the busy entry.
4194 */
4195 for (;;) {
4196 spin_lock_bh(&efx->filter_lock);
4197 if (!(table->entry[filter_idx].spec &
4198 EFX_EF10_FILTER_FLAG_BUSY))
4199 break;
4200 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4201 spin_unlock_bh(&efx->filter_lock);
4202 schedule();
4203 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004204
Ben Hutchings8127d662013-08-29 19:19:29 +01004205 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004206 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004207 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004208 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01004209 filter_id / HUNT_FILTER_TBL_ROWS)) {
4210 rc = -ENOENT;
4211 goto out_unlock;
4212 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004213
4214 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004215 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004216 /* Just remove flags */
4217 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004218 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004219 rc = 0;
4220 goto out_unlock;
4221 }
4222
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004223 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004224 rc = -ENOENT;
4225 goto out_unlock;
4226 }
4227
Ben Hutchings8127d662013-08-29 19:19:29 +01004228 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4229 spin_unlock_bh(&efx->filter_lock);
4230
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004231 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004232 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01004233
4234 struct efx_filter_spec new_spec = *spec;
4235
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004236 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004237 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004238 (efx_rss_enabled(efx) ?
4239 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01004240 new_spec.dmaq_id = 0;
4241 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4242 rc = efx_ef10_filter_push(efx, &new_spec,
4243 &table->entry[filter_idx].handle,
4244 true);
4245
4246 spin_lock_bh(&efx->filter_lock);
4247 if (rc == 0)
4248 *spec = new_spec;
4249 } else {
4250 /* Really remove the filter */
4251
4252 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4253 efx_ef10_filter_is_exclusive(spec) ?
4254 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4255 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4256 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4257 table->entry[filter_idx].handle);
4258 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4259 inbuf, sizeof(inbuf), NULL, 0, NULL);
4260
4261 spin_lock_bh(&efx->filter_lock);
4262 if (rc == 0) {
4263 kfree(spec);
4264 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4265 }
4266 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004267
Ben Hutchings8127d662013-08-29 19:19:29 +01004268 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4269 wake_up_all(&table->waitq);
4270out_unlock:
4271 spin_unlock_bh(&efx->filter_lock);
4272 finish_wait(&table->waitq, &wait);
4273 return rc;
4274}
4275
4276static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4277 enum efx_filter_priority priority,
4278 u32 filter_id)
4279{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004280 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4281 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004282}
4283
Edward Cree12fb0da2015-07-21 15:11:00 +01004284static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
4285{
4286 return filter_id % HUNT_FILTER_TBL_ROWS;
4287}
4288
Edward Cree8c915622016-06-15 17:49:05 +01004289static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4290 enum efx_filter_priority priority,
4291 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004292{
Edward Cree8c915622016-06-15 17:49:05 +01004293 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4294 return;
4295 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004296}
4297
Ben Hutchings8127d662013-08-29 19:19:29 +01004298static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4299 enum efx_filter_priority priority,
4300 u32 filter_id, struct efx_filter_spec *spec)
4301{
4302 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
4303 struct efx_ef10_filter_table *table = efx->filter_state;
4304 const struct efx_filter_spec *saved_spec;
4305 int rc;
4306
4307 spin_lock_bh(&efx->filter_lock);
4308 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4309 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004310 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01004311 filter_id / HUNT_FILTER_TBL_ROWS) {
4312 *spec = *saved_spec;
4313 rc = 0;
4314 } else {
4315 rc = -ENOENT;
4316 }
4317 spin_unlock_bh(&efx->filter_lock);
4318 return rc;
4319}
4320
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004321static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004322 enum efx_filter_priority priority)
4323{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004324 unsigned int priority_mask;
4325 unsigned int i;
4326 int rc;
4327
4328 priority_mask = (((1U << (priority + 1)) - 1) &
4329 ~(1U << EFX_FILTER_PRI_AUTO));
4330
4331 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4332 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4333 i, true);
4334 if (rc && rc != -ENOENT)
4335 return rc;
4336 }
4337
4338 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004339}
4340
4341static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4342 enum efx_filter_priority priority)
4343{
4344 struct efx_ef10_filter_table *table = efx->filter_state;
4345 unsigned int filter_idx;
4346 s32 count = 0;
4347
4348 spin_lock_bh(&efx->filter_lock);
4349 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4350 if (table->entry[filter_idx].spec &&
4351 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4352 priority)
4353 ++count;
4354 }
4355 spin_unlock_bh(&efx->filter_lock);
4356 return count;
4357}
4358
4359static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4360{
4361 struct efx_ef10_filter_table *table = efx->filter_state;
4362
4363 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
4364}
4365
4366static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4367 enum efx_filter_priority priority,
4368 u32 *buf, u32 size)
4369{
4370 struct efx_ef10_filter_table *table = efx->filter_state;
4371 struct efx_filter_spec *spec;
4372 unsigned int filter_idx;
4373 s32 count = 0;
4374
4375 spin_lock_bh(&efx->filter_lock);
4376 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4377 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4378 if (spec && spec->priority == priority) {
4379 if (count == size) {
4380 count = -EMSGSIZE;
4381 break;
4382 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004383 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01004384 HUNT_FILTER_TBL_ROWS +
4385 filter_idx);
4386 }
4387 }
4388 spin_unlock_bh(&efx->filter_lock);
4389 return count;
4390}
4391
4392#ifdef CONFIG_RFS_ACCEL
4393
4394static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4395
4396static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4397 struct efx_filter_spec *spec)
4398{
4399 struct efx_ef10_filter_table *table = efx->filter_state;
4400 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4401 struct efx_filter_spec *saved_spec;
4402 unsigned int hash, i, depth = 1;
4403 bool replacing = false;
4404 int ins_index = -1;
4405 u64 cookie;
4406 s32 rc;
4407
4408 /* Must be an RX filter without RSS and not for a multicast
4409 * destination address (RFS only works for connected sockets).
4410 * These restrictions allow us to pass only a tiny amount of
4411 * data through to the completion function.
4412 */
4413 EFX_WARN_ON_PARANOID(spec->flags !=
4414 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4415 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4416 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4417
4418 hash = efx_ef10_filter_hash(spec);
4419
4420 spin_lock_bh(&efx->filter_lock);
4421
4422 /* Find any existing filter with the same match tuple or else
4423 * a free slot to insert at. If an existing filter is busy,
4424 * we have to give up.
4425 */
4426 for (;;) {
4427 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4428 saved_spec = efx_ef10_filter_entry_spec(table, i);
4429
4430 if (!saved_spec) {
4431 if (ins_index < 0)
4432 ins_index = i;
4433 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4434 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4435 rc = -EBUSY;
4436 goto fail_unlock;
4437 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004438 if (spec->priority < saved_spec->priority) {
4439 rc = -EPERM;
4440 goto fail_unlock;
4441 }
4442 ins_index = i;
4443 break;
4444 }
4445
4446 /* Once we reach the maximum search depth, use the
4447 * first suitable slot or return -EBUSY if there was
4448 * none
4449 */
4450 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4451 if (ins_index < 0) {
4452 rc = -EBUSY;
4453 goto fail_unlock;
4454 }
4455 break;
4456 }
4457
4458 ++depth;
4459 }
4460
4461 /* Create a software table entry if necessary, and mark it
4462 * busy. We might yet fail to insert, but any attempt to
4463 * insert a conflicting filter while we're waiting for the
4464 * firmware must find the busy entry.
4465 */
4466 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4467 if (saved_spec) {
4468 replacing = true;
4469 } else {
4470 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4471 if (!saved_spec) {
4472 rc = -ENOMEM;
4473 goto fail_unlock;
4474 }
4475 *saved_spec = *spec;
4476 }
4477 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4478 EFX_EF10_FILTER_FLAG_BUSY);
4479
4480 spin_unlock_bh(&efx->filter_lock);
4481
4482 /* Pack up the variables needed on completion */
4483 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4484
4485 efx_ef10_filter_push_prep(efx, spec, inbuf,
4486 table->entry[ins_index].handle, replacing);
4487 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4488 MC_CMD_FILTER_OP_OUT_LEN,
4489 efx_ef10_filter_rfs_insert_complete, cookie);
4490
4491 return ins_index;
4492
4493fail_unlock:
4494 spin_unlock_bh(&efx->filter_lock);
4495 return rc;
4496}
4497
4498static void
4499efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4500 int rc, efx_dword_t *outbuf,
4501 size_t outlen_actual)
4502{
4503 struct efx_ef10_filter_table *table = efx->filter_state;
4504 unsigned int ins_index, dmaq_id;
4505 struct efx_filter_spec *spec;
4506 bool replacing;
4507
4508 /* Unpack the cookie */
4509 replacing = cookie >> 31;
4510 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4511 dmaq_id = cookie & 0xffff;
4512
4513 spin_lock_bh(&efx->filter_lock);
4514 spec = efx_ef10_filter_entry_spec(table, ins_index);
4515 if (rc == 0) {
4516 table->entry[ins_index].handle =
4517 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4518 if (replacing)
4519 spec->dmaq_id = dmaq_id;
4520 } else if (!replacing) {
4521 kfree(spec);
4522 spec = NULL;
4523 }
4524 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4525 spin_unlock_bh(&efx->filter_lock);
4526
4527 wake_up_all(&table->waitq);
4528}
4529
4530static void
4531efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4532 unsigned long filter_idx,
4533 int rc, efx_dword_t *outbuf,
4534 size_t outlen_actual);
4535
4536static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4537 unsigned int filter_idx)
4538{
4539 struct efx_ef10_filter_table *table = efx->filter_state;
4540 struct efx_filter_spec *spec =
4541 efx_ef10_filter_entry_spec(table, filter_idx);
4542 MCDI_DECLARE_BUF(inbuf,
4543 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4544 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4545
4546 if (!spec ||
4547 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4548 spec->priority != EFX_FILTER_PRI_HINT ||
4549 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4550 flow_id, filter_idx))
4551 return false;
4552
4553 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4554 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4555 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4556 table->entry[filter_idx].handle);
4557 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4558 efx_ef10_filter_rfs_expire_complete, filter_idx))
4559 return false;
4560
4561 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4562 return true;
4563}
4564
4565static void
4566efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4567 unsigned long filter_idx,
4568 int rc, efx_dword_t *outbuf,
4569 size_t outlen_actual)
4570{
4571 struct efx_ef10_filter_table *table = efx->filter_state;
4572 struct efx_filter_spec *spec =
4573 efx_ef10_filter_entry_spec(table, filter_idx);
4574
4575 spin_lock_bh(&efx->filter_lock);
4576 if (rc == 0) {
4577 kfree(spec);
4578 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4579 }
4580 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4581 wake_up_all(&table->waitq);
4582 spin_unlock_bh(&efx->filter_lock);
4583}
4584
4585#endif /* CONFIG_RFS_ACCEL */
4586
Edward Cree9b410802017-01-27 15:02:52 +00004587static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004588{
4589 int match_flags = 0;
4590
Edward Cree9b410802017-01-27 15:02:52 +00004591#define MAP_FLAG(gen_flag, mcdi_field) do { \
Ben Hutchings8127d662013-08-29 19:19:29 +01004592 u32 old_mcdi_flags = mcdi_flags; \
Edward Cree9b410802017-01-27 15:02:52 +00004593 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4594 mcdi_field ## _LBN); \
Ben Hutchings8127d662013-08-29 19:19:29 +01004595 if (mcdi_flags != old_mcdi_flags) \
4596 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
Edward Cree9b410802017-01-27 15:02:52 +00004597 } while (0)
4598
4599 if (encap) {
4600 /* encap filters must specify encap type */
4601 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4602 /* and imply ethertype and ip proto */
4603 mcdi_flags &=
4604 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4605 mcdi_flags &=
4606 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4607 /* VLAN tags refer to the outer packet */
4608 MAP_FLAG(INNER_VID, INNER_VLAN);
4609 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4610 /* everything else refers to the inner packet */
4611 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4612 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4613 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4614 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4615 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4616 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4617 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4618 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4619 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4620 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4621 } else {
4622 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4623 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4624 MAP_FLAG(REM_HOST, SRC_IP);
4625 MAP_FLAG(LOC_HOST, DST_IP);
4626 MAP_FLAG(REM_MAC, SRC_MAC);
4627 MAP_FLAG(REM_PORT, SRC_PORT);
4628 MAP_FLAG(LOC_MAC, DST_MAC);
4629 MAP_FLAG(LOC_PORT, DST_PORT);
4630 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4631 MAP_FLAG(INNER_VID, INNER_VLAN);
4632 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4633 MAP_FLAG(IP_PROTO, IP_PROTO);
Ben Hutchings8127d662013-08-29 19:19:29 +01004634 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004635#undef MAP_FLAG
4636
4637 /* Did we map them all? */
4638 if (mcdi_flags)
4639 return -EINVAL;
4640
4641 return match_flags;
4642}
4643
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004644static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4645{
4646 struct efx_ef10_filter_table *table = efx->filter_state;
4647 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4648
4649 /* See comment in efx_ef10_filter_table_remove() */
4650 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4651 return;
4652
4653 if (!table)
4654 return;
4655
4656 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4657 efx_ef10_filter_del_vlan_internal(efx, vlan);
4658}
4659
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004660static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
Edward Cree9b410802017-01-27 15:02:52 +00004661 bool encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004662 enum efx_filter_match_flags match_flags)
4663{
4664 unsigned int match_pri;
4665 int mf;
4666
4667 for (match_pri = 0;
4668 match_pri < table->rx_match_count;
4669 match_pri++) {
Edward Cree9b410802017-01-27 15:02:52 +00004670 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004671 table->rx_match_mcdi_flags[match_pri]);
4672 if (mf == match_flags)
4673 return true;
4674 }
4675
4676 return false;
4677}
4678
Edward Cree9b410802017-01-27 15:02:52 +00004679static int
4680efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4681 struct efx_ef10_filter_table *table,
4682 bool encap)
Ben Hutchings8127d662013-08-29 19:19:29 +01004683{
4684 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4685 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4686 unsigned int pd_match_pri, pd_match_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01004687 size_t outlen;
4688 int rc;
4689
Ben Hutchings8127d662013-08-29 19:19:29 +01004690 /* Find out which RX filter types are supported, and their priorities */
4691 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
Edward Cree9b410802017-01-27 15:02:52 +00004692 encap ?
4693 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
Ben Hutchings8127d662013-08-29 19:19:29 +01004694 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4695 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4696 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4697 &outlen);
4698 if (rc)
Edward Cree9b410802017-01-27 15:02:52 +00004699 return rc;
4700
Ben Hutchings8127d662013-08-29 19:19:29 +01004701 pd_match_count = MCDI_VAR_ARRAY_LEN(
4702 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
Ben Hutchings8127d662013-08-29 19:19:29 +01004703
4704 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4705 u32 mcdi_flags =
4706 MCDI_ARRAY_DWORD(
4707 outbuf,
4708 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4709 pd_match_pri);
Edward Cree9b410802017-01-27 15:02:52 +00004710 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
Ben Hutchings8127d662013-08-29 19:19:29 +01004711 if (rc < 0) {
4712 netif_dbg(efx, probe, efx->net_dev,
4713 "%s: fw flags %#x pri %u not supported in driver\n",
4714 __func__, mcdi_flags, pd_match_pri);
4715 } else {
4716 netif_dbg(efx, probe, efx->net_dev,
4717 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4718 __func__, mcdi_flags, pd_match_pri,
4719 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004720 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4721 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004722 }
4723 }
4724
Edward Cree9b410802017-01-27 15:02:52 +00004725 return 0;
4726}
4727
4728static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4729{
4730 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4731 struct net_device *net_dev = efx->net_dev;
4732 struct efx_ef10_filter_table *table;
4733 struct efx_ef10_vlan *vlan;
4734 int rc;
4735
4736 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4737 return -EINVAL;
4738
4739 if (efx->filter_state) /* already probed */
4740 return 0;
4741
4742 table = kzalloc(sizeof(*table), GFP_KERNEL);
4743 if (!table)
4744 return -ENOMEM;
4745
4746 table->rx_match_count = 0;
4747 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
4748 if (rc)
4749 goto fail;
4750 if (nic_data->datapath_caps &
4751 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
4752 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
4753 if (rc)
4754 goto fail;
Martin Habetse4478ad2016-06-15 17:51:07 +01004755 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
Edward Cree9b410802017-01-27 15:02:52 +00004756 !(efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004757 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
Edward Cree9b410802017-01-27 15:02:52 +00004758 efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01004759 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4760 netif_info(efx, probe, net_dev,
4761 "VLAN filters are not supported in this firmware variant\n");
4762 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4763 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4764 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4765 }
4766
Ben Hutchings8127d662013-08-29 19:19:29 +01004767 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4768 if (!table->entry) {
4769 rc = -ENOMEM;
4770 goto fail;
4771 }
4772
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004773 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004774 table->vlan_filter =
4775 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004776 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004777
Ben Hutchings8127d662013-08-29 19:19:29 +01004778 efx->filter_state = table;
4779 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004780
4781 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4782 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4783 if (rc)
4784 goto fail_add_vlan;
4785 }
4786
Ben Hutchings8127d662013-08-29 19:19:29 +01004787 return 0;
4788
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004789fail_add_vlan:
4790 efx_ef10_filter_cleanup_vlans(efx);
4791 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004792fail:
4793 kfree(table);
4794 return rc;
4795}
4796
Edward Cree0d322412015-05-20 11:10:03 +01004797/* Caller must hold efx->filter_sem for read if race against
4798 * efx_ef10_filter_table_remove() is possible
4799 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004800static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4801{
4802 struct efx_ef10_filter_table *table = efx->filter_state;
4803 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004804 unsigned int invalid_filters = 0, failed = 0;
4805 struct efx_ef10_filter_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01004806 struct efx_filter_spec *spec;
4807 unsigned int filter_idx;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004808 u32 mcdi_flags;
4809 int match_pri;
Edward Cree9b410802017-01-27 15:02:52 +00004810 int rc, i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004811
Edward Cree0d322412015-05-20 11:10:03 +01004812 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4813
Ben Hutchings8127d662013-08-29 19:19:29 +01004814 if (!nic_data->must_restore_filters)
4815 return;
4816
Edward Cree0d322412015-05-20 11:10:03 +01004817 if (!table)
4818 return;
4819
Ben Hutchings8127d662013-08-29 19:19:29 +01004820 spin_lock_bh(&efx->filter_lock);
4821
4822 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4823 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4824 if (!spec)
4825 continue;
4826
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004827 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4828 match_pri = 0;
4829 while (match_pri < table->rx_match_count &&
4830 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
4831 ++match_pri;
4832 if (match_pri >= table->rx_match_count) {
4833 invalid_filters++;
4834 goto not_restored;
4835 }
4836 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4837 spec->rss_context != nic_data->rx_rss_context)
4838 netif_warn(efx, drv, efx->net_dev,
4839 "Warning: unable to restore a filter with specific RSS context.\n");
4840
Ben Hutchings8127d662013-08-29 19:19:29 +01004841 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4842 spin_unlock_bh(&efx->filter_lock);
4843
4844 rc = efx_ef10_filter_push(efx, spec,
4845 &table->entry[filter_idx].handle,
4846 false);
4847 if (rc)
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004848 failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004849 spin_lock_bh(&efx->filter_lock);
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004850
Ben Hutchings8127d662013-08-29 19:19:29 +01004851 if (rc) {
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004852not_restored:
Edward Cree9b410802017-01-27 15:02:52 +00004853 list_for_each_entry(vlan, &table->vlan_list, list)
4854 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
4855 if (vlan->default_filters[i] == filter_idx)
4856 vlan->default_filters[i] =
4857 EFX_EF10_FILTER_ID_INVALID;
4858
Ben Hutchings8127d662013-08-29 19:19:29 +01004859 kfree(spec);
4860 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4861 } else {
4862 table->entry[filter_idx].spec &=
4863 ~EFX_EF10_FILTER_FLAG_BUSY;
4864 }
4865 }
4866
4867 spin_unlock_bh(&efx->filter_lock);
4868
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004869 /* This can happen validly if the MC's capabilities have changed, so
4870 * is not an error.
4871 */
4872 if (invalid_filters)
4873 netif_dbg(efx, drv, efx->net_dev,
4874 "Did not restore %u filters that are now unsupported.\n",
4875 invalid_filters);
4876
Ben Hutchings8127d662013-08-29 19:19:29 +01004877 if (failed)
4878 netif_err(efx, hw, efx->net_dev,
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00004879 "unable to restore %u filters\n", failed);
Ben Hutchings8127d662013-08-29 19:19:29 +01004880 else
4881 nic_data->must_restore_filters = false;
4882}
4883
4884static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4885{
4886 struct efx_ef10_filter_table *table = efx->filter_state;
4887 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4888 struct efx_filter_spec *spec;
4889 unsigned int filter_idx;
4890 int rc;
4891
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004892 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004893 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004894 /* If we were called without locking, then it's not safe to free
4895 * the table as others might be using it. So we just WARN, leak
4896 * the memory, and potentially get an inconsistent filter table
4897 * state.
4898 * This should never actually happen.
4899 */
4900 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4901 return;
4902
Edward Cree0d322412015-05-20 11:10:03 +01004903 if (!table)
4904 return;
4905
Ben Hutchings8127d662013-08-29 19:19:29 +01004906 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4907 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4908 if (!spec)
4909 continue;
4910
4911 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4912 efx_ef10_filter_is_exclusive(spec) ?
4913 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4914 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4915 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4916 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004917 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4918 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004919 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004920 netif_info(efx, drv, efx->net_dev,
4921 "%s: filter %04x remove failed\n",
4922 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004923 kfree(spec);
4924 }
4925
4926 vfree(table->entry);
4927 kfree(table);
4928}
4929
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004930static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4931{
4932 struct efx_ef10_filter_table *table = efx->filter_state;
4933 unsigned int filter_idx;
4934
4935 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4936 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4937 if (!table->entry[filter_idx].spec)
4938 netif_dbg(efx, drv, efx->net_dev,
4939 "marked null spec old %04x:%04x\n", *id,
4940 filter_idx);
4941 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4942 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004943 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004944}
4945
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004946/* Mark old per-VLAN filters that may need to be removed */
4947static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4948 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004949{
4950 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004951 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004952
Edward Cree12fb0da2015-07-21 15:11:00 +01004953 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004954 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004955 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004956 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00004957 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
4958 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004959}
4960
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004961/* Mark old filters that may need to be removed.
4962 * Caller must hold efx->filter_sem for read if race against
4963 * efx_ef10_filter_table_remove() is possible
4964 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004965static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4966{
4967 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004968 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004969
4970 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004971 list_for_each_entry(vlan, &table->vlan_list, list)
4972 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004973 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004974}
Ben Hutchings8127d662013-08-29 19:19:29 +01004975
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004976static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004977{
4978 struct efx_ef10_filter_table *table = efx->filter_state;
4979 struct net_device *net_dev = efx->net_dev;
4980 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004981 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004982 unsigned int i;
4983
Edward Cree12fb0da2015-07-21 15:11:00 +01004984 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004985 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004986 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004987 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4988 i = 1;
4989 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004990 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004991 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004992 break;
4993 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004994 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4995 i++;
4996 }
4997}
4998
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004999static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005000{
5001 struct efx_ef10_filter_table *table = efx->filter_state;
5002 struct net_device *net_dev = efx->net_dev;
5003 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005004 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005005
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005006 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005007
Edward Cree12fb0da2015-07-21 15:11:00 +01005008 addr_count = netdev_mc_count(net_dev);
5009 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005010 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005011 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005012 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005013 break;
5014 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005015 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5016 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005017 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005018
5019 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005020}
Ben Hutchings8127d662013-08-29 19:19:29 +01005021
Edward Cree12fb0da2015-07-21 15:11:00 +01005022static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005023 struct efx_ef10_filter_vlan *vlan,
5024 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005025{
5026 struct efx_ef10_filter_table *table = efx->filter_state;
5027 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005028 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005029 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01005030 u8 baddr[ETH_ALEN];
5031 unsigned int i, j;
5032 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005033 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005034 int rc;
5035
5036 if (multicast) {
5037 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005038 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005039 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005040 } else {
5041 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005042 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005043 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005044 }
5045
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005046 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5047
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005048 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01005049 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005050 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005051 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01005052 rc = efx_ef10_filter_insert(efx, &spec, true);
5053 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005054 if (rollback) {
5055 netif_info(efx, drv, efx->net_dev,
5056 "efx_ef10_filter_insert failed rc=%d\n",
5057 rc);
5058 /* Fall back to promiscuous */
5059 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005060 efx_ef10_filter_remove_unsafe(
5061 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005062 ids[j]);
5063 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005064 }
5065 return rc;
5066 } else {
5067 /* mark as not inserted, and carry on */
5068 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005069 }
Ben Hutchings8127d662013-08-29 19:19:29 +01005070 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005071 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01005072 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005073
Edward Cree12fb0da2015-07-21 15:11:00 +01005074 if (multicast && rollback) {
5075 /* Also need an Ethernet broadcast filter */
Edward Cree9b410802017-01-27 15:02:52 +00005076 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5077 EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005078 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005079 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005080 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005081 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01005082 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005083 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01005084 "Broadcast filter insert failed rc=%d\n", rc);
5085 /* Fall back to promiscuous */
5086 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005087 efx_ef10_filter_remove_unsafe(
5088 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005089 ids[j]);
5090 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005091 }
5092 return rc;
5093 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005094 vlan->default_filters[EFX_EF10_BCAST] =
5095 efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005096 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005097 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005098
5099 return 0;
5100}
5101
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005102static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5103 struct efx_ef10_filter_vlan *vlan,
Edward Cree9b410802017-01-27 15:02:52 +00005104 enum efx_encap_type encap_type,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005105 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01005106{
Edward Cree12fb0da2015-07-21 15:11:00 +01005107 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005108 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01005109 struct efx_filter_spec spec;
5110 u8 baddr[ETH_ALEN];
5111 int rc;
Edward Cree9b410802017-01-27 15:02:52 +00005112 u16 *id;
Edward Cree12fb0da2015-07-21 15:11:00 +01005113
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005114 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5115
5116 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005117
5118 if (multicast)
5119 efx_filter_set_mc_def(&spec);
5120 else
5121 efx_filter_set_uc_def(&spec);
5122
Edward Cree9b410802017-01-27 15:02:52 +00005123 if (encap_type) {
5124 if (nic_data->datapath_caps &
5125 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5126 efx_filter_set_encap_type(&spec, encap_type);
5127 else
5128 /* don't insert encap filters on non-supporting
5129 * platforms. ID will be left as INVALID.
5130 */
5131 return 0;
5132 }
5133
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005134 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5135 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5136
Edward Cree12fb0da2015-07-21 15:11:00 +01005137 rc = efx_ef10_filter_insert(efx, &spec, true);
5138 if (rc < 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005139 const char *um = multicast ? "Multicast" : "Unicast";
5140 const char *encap_name = "";
5141 const char *encap_ipv = "";
5142
5143 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5144 EFX_ENCAP_TYPE_VXLAN)
5145 encap_name = "VXLAN ";
5146 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5147 EFX_ENCAP_TYPE_NVGRE)
5148 encap_name = "NVGRE ";
5149 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5150 EFX_ENCAP_TYPE_GENEVE)
5151 encap_name = "GENEVE ";
5152 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5153 encap_ipv = "IPv6 ";
5154 else if (encap_type)
5155 encap_ipv = "IPv4 ";
5156
5157 /* unprivileged functions can't insert mismatch filters
5158 * for encapsulated or unicast traffic, so downgrade
5159 * those warnings to debug.
5160 */
Jon Cooper34e7aef2017-01-27 15:02:39 +00005161 netif_cond_dbg(efx, drv, efx->net_dev,
Edward Cree9b410802017-01-27 15:02:52 +00005162 rc == -EPERM && (encap_type || !multicast), warn,
5163 "%s%s%s mismatch filter insert failed rc=%d\n",
5164 encap_name, encap_ipv, um, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005165 } else if (multicast) {
Edward Cree9b410802017-01-27 15:02:52 +00005166 /* mapping from encap types to default filter IDs (multicast) */
5167 static enum efx_ef10_default_filters map[] = {
5168 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5169 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5170 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5171 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5172 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5173 EFX_EF10_VXLAN6_MCDEF,
5174 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5175 EFX_EF10_NVGRE6_MCDEF,
5176 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5177 EFX_EF10_GENEVE6_MCDEF,
5178 };
5179
5180 /* quick bounds check (BCAST result impossible) */
5181 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Colin Ian Kinge9904992017-01-31 16:30:02 +00005182 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005183 WARN_ON(1);
5184 return -EINVAL;
5185 }
5186 /* then follow map */
5187 id = &vlan->default_filters[map[encap_type]];
5188
5189 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5190 *id = efx_ef10_filter_get_unsafe_id(efx, rc);
5191 if (!nic_data->workaround_26807 && !encap_type) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005192 /* Also need an Ethernet broadcast filter */
5193 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005194 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005195 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005196 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01005197 rc = efx_ef10_filter_insert(efx, &spec, true);
5198 if (rc < 0) {
5199 netif_warn(efx, drv, efx->net_dev,
5200 "Broadcast filter insert failed rc=%d\n",
5201 rc);
5202 if (rollback) {
5203 /* Roll back the mc_def filter */
5204 efx_ef10_filter_remove_unsafe(
5205 efx, EFX_FILTER_PRI_AUTO,
Edward Cree9b410802017-01-27 15:02:52 +00005206 *id);
5207 *id = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005208 return rc;
5209 }
5210 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005211 EFX_WARN_ON_PARANOID(
5212 vlan->default_filters[EFX_EF10_BCAST] !=
5213 EFX_EF10_FILTER_ID_INVALID);
5214 vlan->default_filters[EFX_EF10_BCAST] =
5215 efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005216 }
5217 }
5218 rc = 0;
5219 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005220 /* mapping from encap types to default filter IDs (unicast) */
5221 static enum efx_ef10_default_filters map[] = {
5222 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5223 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5224 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5225 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5226 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5227 EFX_EF10_VXLAN6_UCDEF,
5228 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5229 EFX_EF10_NVGRE6_UCDEF,
5230 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5231 EFX_EF10_GENEVE6_UCDEF,
5232 };
5233
5234 /* quick bounds check (BCAST result impossible) */
5235 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Dan Carpenteree467fb2017-02-07 10:44:31 +03005236 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005237 WARN_ON(1);
5238 return -EINVAL;
5239 }
5240 /* then follow map */
5241 id = &vlan->default_filters[map[encap_type]];
5242 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5243 *id = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01005244 rc = 0;
5245 }
5246 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005247}
5248
5249/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5250 * flag or removes these filters, we don't need to hold the filter_lock while
5251 * scanning for these filters.
5252 */
5253static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5254{
5255 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005256 int remove_failed = 0;
5257 int remove_noent = 0;
5258 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005259 int i;
5260
Ben Hutchings8127d662013-08-29 19:19:29 +01005261 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
5262 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00005263 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00005264 rc = efx_ef10_filter_remove_internal(efx,
5265 1U << EFX_FILTER_PRI_AUTO, i, true);
5266 if (rc == -ENOENT)
5267 remove_noent++;
5268 else if (rc)
5269 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005270 }
5271 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00005272
5273 if (remove_failed)
5274 netif_info(efx, drv, efx->net_dev,
5275 "%s: failed to remove %d filters\n",
5276 __func__, remove_failed);
5277 if (remove_noent)
5278 netif_info(efx, drv, efx->net_dev,
5279 "%s: failed to remove %d non-existent filters\n",
5280 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01005281}
5282
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005283static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5284{
5285 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5286 u8 mac_old[ETH_ALEN];
5287 int rc, rc2;
5288
5289 /* Only reconfigure a PF-created vport */
5290 if (is_zero_ether_addr(nic_data->vport_mac))
5291 return 0;
5292
5293 efx_device_detach_sync(efx);
5294 efx_net_stop(efx->net_dev);
5295 down_write(&efx->filter_sem);
5296 efx_ef10_filter_table_remove(efx);
5297 up_write(&efx->filter_sem);
5298
5299 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5300 if (rc)
5301 goto restore_filters;
5302
5303 ether_addr_copy(mac_old, nic_data->vport_mac);
5304 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5305 nic_data->vport_mac);
5306 if (rc)
5307 goto restore_vadaptor;
5308
5309 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5310 efx->net_dev->dev_addr);
5311 if (!rc) {
5312 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5313 } else {
5314 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5315 if (rc2) {
5316 /* Failed to add original MAC, so clear vport_mac */
5317 eth_zero_addr(nic_data->vport_mac);
5318 goto reset_nic;
5319 }
5320 }
5321
5322restore_vadaptor:
5323 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5324 if (rc2)
5325 goto reset_nic;
5326restore_filters:
5327 down_write(&efx->filter_sem);
5328 rc2 = efx_ef10_filter_table_probe(efx);
5329 up_write(&efx->filter_sem);
5330 if (rc2)
5331 goto reset_nic;
5332
5333 rc2 = efx_net_open(efx->net_dev);
5334 if (rc2)
5335 goto reset_nic;
5336
5337 netif_device_attach(efx->net_dev);
5338
5339 return rc;
5340
5341reset_nic:
5342 netif_err(efx, drv, efx->net_dev,
5343 "Failed to restore when changing MAC address - scheduling reset\n");
5344 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5345
5346 return rc ? rc : rc2;
5347}
5348
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005349/* Caller must hold efx->filter_sem for read if race against
5350 * efx_ef10_filter_table_remove() is possible
5351 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005352static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5353 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005354{
5355 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005356 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005357
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005358 /* Do not install unspecified VID if VLAN filtering is enabled.
5359 * Do not install all specified VIDs if VLAN filtering is disabled.
5360 */
5361 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5362 return;
5363
Edward Cree12fb0da2015-07-21 15:11:00 +01005364 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005365 if (table->uc_promisc) {
Edward Cree9b410802017-01-27 15:02:52 +00005366 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5367 false, false);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005368 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005369 } else {
5370 /* If any of the filters failed to insert, fall back to
5371 * promiscuous mode - add in the uc_def filter. But keep
5372 * our individual unicast filters.
5373 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005374 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
Edward Cree9b410802017-01-27 15:02:52 +00005375 efx_ef10_filter_insert_def(efx, vlan,
5376 EFX_ENCAP_TYPE_NONE,
5377 false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005378 }
Edward Cree9b410802017-01-27 15:02:52 +00005379 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5380 false, false);
5381 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5382 EFX_ENCAP_FLAG_IPV6,
5383 false, false);
5384 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5385 false, false);
5386 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5387 EFX_ENCAP_FLAG_IPV6,
5388 false, false);
5389 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5390 false, false);
5391 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5392 EFX_ENCAP_FLAG_IPV6,
5393 false, false);
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005394
Edward Cree12fb0da2015-07-21 15:11:00 +01005395 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005396 /* If changing promiscuous state with cascaded multicast filters, remove
5397 * old filters first, so that packets are dropped rather than duplicated
5398 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005399 if (nic_data->workaround_26807 &&
5400 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005401 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005402 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005403 if (nic_data->workaround_26807) {
5404 /* If we failed to insert promiscuous filters, rollback
5405 * and fall back to individual multicast filters
5406 */
Edward Cree9b410802017-01-27 15:02:52 +00005407 if (efx_ef10_filter_insert_def(efx, vlan,
5408 EFX_ENCAP_TYPE_NONE,
5409 true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005410 /* Changing promisc state, so remove old filters */
5411 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005412 efx_ef10_filter_insert_addr_list(efx, vlan,
5413 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005414 }
5415 } else {
5416 /* If we failed to insert promiscuous filters, don't
5417 * rollback. Regardless, also insert the mc_list
5418 */
Edward Cree9b410802017-01-27 15:02:52 +00005419 efx_ef10_filter_insert_def(efx, vlan,
5420 EFX_ENCAP_TYPE_NONE,
5421 true, false);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005422 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005423 }
5424 } else {
5425 /* If any filters failed to insert, rollback and fall back to
5426 * promiscuous mode - mc_def filter and maybe broadcast. If
5427 * that fails, roll back again and insert as many of our
5428 * individual multicast filters as we can.
5429 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005430 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005431 /* Changing promisc state, so remove old filters */
5432 if (nic_data->workaround_26807)
5433 efx_ef10_filter_remove_old(efx);
Edward Cree9b410802017-01-27 15:02:52 +00005434 if (efx_ef10_filter_insert_def(efx, vlan,
5435 EFX_ENCAP_TYPE_NONE,
5436 true, true))
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005437 efx_ef10_filter_insert_addr_list(efx, vlan,
5438 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005439 }
5440 }
Edward Cree9b410802017-01-27 15:02:52 +00005441 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5442 true, false);
5443 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5444 EFX_ENCAP_FLAG_IPV6,
5445 true, false);
5446 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5447 true, false);
5448 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5449 EFX_ENCAP_FLAG_IPV6,
5450 true, false);
5451 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5452 true, false);
5453 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5454 EFX_ENCAP_FLAG_IPV6,
5455 true, false);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005456}
5457
5458/* Caller must hold efx->filter_sem for read if race against
5459 * efx_ef10_filter_table_remove() is possible
5460 */
5461static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5462{
5463 struct efx_ef10_filter_table *table = efx->filter_state;
5464 struct net_device *net_dev = efx->net_dev;
5465 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005466 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005467
5468 if (!efx_dev_registered(efx))
5469 return;
5470
5471 if (!table)
5472 return;
5473
5474 efx_ef10_filter_mark_old(efx);
5475
5476 /* Copy/convert the address lists; add the primary station
5477 * address and broadcast address
5478 */
5479 netif_addr_lock_bh(net_dev);
5480 efx_ef10_filter_uc_addr_list(efx);
5481 efx_ef10_filter_mc_addr_list(efx);
5482 netif_addr_unlock_bh(net_dev);
5483
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005484 /* If VLAN filtering changes, all old filters are finally removed.
5485 * Do it in advance to avoid conflicts for unicast untagged and
5486 * VLAN 0 tagged filters.
5487 */
5488 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5489 if (table->vlan_filter != vlan_filter) {
5490 table->vlan_filter = vlan_filter;
5491 efx_ef10_filter_remove_old(efx);
5492 }
5493
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005494 list_for_each_entry(vlan, &table->vlan_list, list)
5495 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005496
5497 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005498 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005499}
5500
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005501static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5502{
5503 struct efx_ef10_filter_table *table = efx->filter_state;
5504 struct efx_ef10_filter_vlan *vlan;
5505
5506 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5507
5508 list_for_each_entry(vlan, &table->vlan_list, list) {
5509 if (vlan->vid == vid)
5510 return vlan;
5511 }
5512
5513 return NULL;
5514}
5515
5516static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5517{
5518 struct efx_ef10_filter_table *table = efx->filter_state;
5519 struct efx_ef10_filter_vlan *vlan;
5520 unsigned int i;
5521
5522 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5523 return -EINVAL;
5524
5525 vlan = efx_ef10_filter_find_vlan(efx, vid);
5526 if (WARN_ON(vlan)) {
5527 netif_err(efx, drv, efx->net_dev,
5528 "VLAN %u already added\n", vid);
5529 return -EALREADY;
5530 }
5531
5532 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5533 if (!vlan)
5534 return -ENOMEM;
5535
5536 vlan->vid = vid;
5537
5538 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5539 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5540 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5541 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree9b410802017-01-27 15:02:52 +00005542 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5543 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005544
5545 list_add_tail(&vlan->list, &table->vlan_list);
5546
5547 if (efx_dev_registered(efx))
5548 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5549
5550 return 0;
5551}
5552
5553static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5554 struct efx_ef10_filter_vlan *vlan)
5555{
5556 unsigned int i;
5557
5558 /* See comment in efx_ef10_filter_table_remove() */
5559 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5560 return;
5561
5562 list_del(&vlan->list);
5563
Edward Cree8c915622016-06-15 17:49:05 +01005564 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005565 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005566 vlan->uc[i]);
5567 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005568 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005569 vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005570 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5571 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5572 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5573 vlan->default_filters[i]);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005574
5575 kfree(vlan);
5576}
5577
5578static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5579{
5580 struct efx_ef10_filter_vlan *vlan;
5581
5582 /* See comment in efx_ef10_filter_table_remove() */
5583 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5584 return;
5585
5586 vlan = efx_ef10_filter_find_vlan(efx, vid);
5587 if (!vlan) {
5588 netif_err(efx, drv, efx->net_dev,
5589 "VLAN %u not found in filter state\n", vid);
5590 return;
5591 }
5592
5593 efx_ef10_filter_del_vlan_internal(efx, vlan);
5594}
5595
Shradha Shah910c8782015-05-20 11:12:48 +01005596static int efx_ef10_set_mac_address(struct efx_nic *efx)
5597{
5598 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5599 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5600 bool was_enabled = efx->port_enabled;
5601 int rc;
5602
5603 efx_device_detach_sync(efx);
5604 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005605
5606 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005607 down_write(&efx->filter_sem);
5608 efx_ef10_filter_table_remove(efx);
5609
5610 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5611 efx->net_dev->dev_addr);
5612 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5613 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005614 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5615 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005616
5617 efx_ef10_filter_table_probe(efx);
5618 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005619 mutex_unlock(&efx->mac_lock);
5620
Shradha Shah910c8782015-05-20 11:12:48 +01005621 if (was_enabled)
5622 efx_net_open(efx->net_dev);
5623 netif_device_attach(efx->net_dev);
5624
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005625#ifdef CONFIG_SFC_SRIOV
5626 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005627 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5628
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005629 if (rc == -EPERM) {
5630 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005631
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005632 /* Switch to PF and change MAC address on vport */
5633 efx_pf = pci_get_drvdata(pci_dev_pf);
5634
5635 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005636 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005637 efx->net_dev->dev_addr);
5638 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005639 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5640 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5641 unsigned int i;
5642
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005643 /* MAC address successfully changed by VF (with MAC
5644 * spoofing) so update the parent PF if possible.
5645 */
Shradha Shah910c8782015-05-20 11:12:48 +01005646 for (i = 0; i < efx_pf->vf_count; ++i) {
5647 struct ef10_vf *vf = nic_data->vf + i;
5648
5649 if (vf->efx == efx) {
5650 ether_addr_copy(vf->mac,
5651 efx->net_dev->dev_addr);
5652 return 0;
5653 }
5654 }
5655 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005656 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005657#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005658 if (rc == -EPERM) {
5659 netif_err(efx, drv, efx->net_dev,
5660 "Cannot change MAC address; use sfboot to enable"
5661 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005662 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5663 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5664 * fall-back to the method of changing the MAC address on the
5665 * vport. This only applies to PFs because such versions of
5666 * MCFW do not support VFs.
5667 */
5668 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005669 } else {
5670 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5671 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005672 }
5673
Shradha Shah910c8782015-05-20 11:12:48 +01005674 return rc;
5675}
5676
Ben Hutchings8127d662013-08-29 19:19:29 +01005677static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5678{
5679 efx_ef10_filter_sync_rx_mode(efx);
5680
5681 return efx_mcdi_set_mac(efx);
5682}
5683
Shradha Shah862f8942015-05-20 11:08:56 +01005684static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5685{
5686 efx_ef10_filter_sync_rx_mode(efx);
5687
5688 return 0;
5689}
5690
Jon Cooper74cd60a2013-09-16 14:18:51 +01005691static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5692{
5693 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5694
5695 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5696 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5697 NULL, 0, NULL);
5698}
5699
5700/* MC BISTs follow a different poll mechanism to phy BISTs.
5701 * The BIST is done in the poll handler on the MC, and the MCDI command
5702 * will block until the BIST is done.
5703 */
5704static int efx_ef10_poll_bist(struct efx_nic *efx)
5705{
5706 int rc;
5707 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5708 size_t outlen;
5709 u32 result;
5710
5711 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5712 outbuf, sizeof(outbuf), &outlen);
5713 if (rc != 0)
5714 return rc;
5715
5716 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5717 return -EIO;
5718
5719 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5720 switch (result) {
5721 case MC_CMD_POLL_BIST_PASSED:
5722 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5723 return 0;
5724 case MC_CMD_POLL_BIST_TIMEOUT:
5725 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5726 return -EIO;
5727 case MC_CMD_POLL_BIST_FAILED:
5728 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5729 return -EIO;
5730 default:
5731 netif_err(efx, hw, efx->net_dev,
5732 "BIST returned unknown result %u", result);
5733 return -EIO;
5734 }
5735}
5736
5737static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5738{
5739 int rc;
5740
5741 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5742
5743 rc = efx_ef10_start_bist(efx, bist_type);
5744 if (rc != 0)
5745 return rc;
5746
5747 return efx_ef10_poll_bist(efx);
5748}
5749
5750static int
5751efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5752{
5753 int rc, rc2;
5754
5755 efx_reset_down(efx, RESET_TYPE_WORLD);
5756
5757 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5758 NULL, 0, NULL, 0, NULL);
5759 if (rc != 0)
5760 goto out;
5761
5762 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5763 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5764
5765 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5766
5767out:
Daniel Pieczko27324822015-07-31 11:14:54 +01005768 if (rc == -EPERM)
5769 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01005770 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5771 return rc ? rc : rc2;
5772}
5773
Ben Hutchings8127d662013-08-29 19:19:29 +01005774#ifdef CONFIG_SFC_MTD
5775
5776struct efx_ef10_nvram_type_info {
5777 u16 type, type_mask;
5778 u8 port;
5779 const char *name;
5780};
5781
5782static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5783 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5784 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5785 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5786 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5787 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5788 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5789 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5790 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5791 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01005792 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01005793 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5794};
5795
5796static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5797 struct efx_mcdi_mtd_partition *part,
5798 unsigned int type)
5799{
5800 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5801 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5802 const struct efx_ef10_nvram_type_info *info;
5803 size_t size, erase_size, outlen;
5804 bool protected;
5805 int rc;
5806
5807 for (info = efx_ef10_nvram_types; ; info++) {
5808 if (info ==
5809 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5810 return -ENODEV;
5811 if ((type & ~info->type_mask) == info->type)
5812 break;
5813 }
5814 if (info->port != efx_port_num(efx))
5815 return -ENODEV;
5816
5817 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5818 if (rc)
5819 return rc;
5820 if (protected)
5821 return -ENODEV; /* hide it */
5822
5823 part->nvram_type = type;
5824
5825 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5826 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5827 outbuf, sizeof(outbuf), &outlen);
5828 if (rc)
5829 return rc;
5830 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5831 return -EIO;
5832 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5833 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5834 part->fw_subtype = MCDI_DWORD(outbuf,
5835 NVRAM_METADATA_OUT_SUBTYPE);
5836
5837 part->common.dev_type_name = "EF10 NVRAM manager";
5838 part->common.type_name = info->name;
5839
5840 part->common.mtd.type = MTD_NORFLASH;
5841 part->common.mtd.flags = MTD_CAP_NORFLASH;
5842 part->common.mtd.size = size;
5843 part->common.mtd.erasesize = erase_size;
5844
5845 return 0;
5846}
5847
5848static int efx_ef10_mtd_probe(struct efx_nic *efx)
5849{
5850 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5851 struct efx_mcdi_mtd_partition *parts;
5852 size_t outlen, n_parts_total, i, n_parts;
5853 unsigned int type;
5854 int rc;
5855
5856 ASSERT_RTNL();
5857
5858 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5859 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5860 outbuf, sizeof(outbuf), &outlen);
5861 if (rc)
5862 return rc;
5863 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5864 return -EIO;
5865
5866 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5867 if (n_parts_total >
5868 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5869 return -EIO;
5870
5871 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5872 if (!parts)
5873 return -ENOMEM;
5874
5875 n_parts = 0;
5876 for (i = 0; i < n_parts_total; i++) {
5877 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5878 i);
5879 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5880 if (rc == 0)
5881 n_parts++;
5882 else if (rc != -ENODEV)
5883 goto fail;
5884 }
5885
5886 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5887fail:
5888 if (rc)
5889 kfree(parts);
5890 return rc;
5891}
5892
5893#endif /* CONFIG_SFC_MTD */
5894
5895static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5896{
5897 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5898}
5899
Shradha Shah02246a72015-05-06 00:58:14 +01005900static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5901 u32 host_time) {}
5902
Jon Cooperbd9a2652013-11-18 12:54:41 +00005903static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5904 bool temp)
5905{
5906 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5907 int rc;
5908
5909 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5910 channel->sync_events_state == SYNC_EVENTS_VALID ||
5911 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5912 return 0;
5913 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5914
5915 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5916 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5917 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5918 channel->channel);
5919
5920 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5921 inbuf, sizeof(inbuf), NULL, 0, NULL);
5922
5923 if (rc != 0)
5924 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5925 SYNC_EVENTS_DISABLED;
5926
5927 return rc;
5928}
5929
5930static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5931 bool temp)
5932{
5933 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5934 int rc;
5935
5936 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5937 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5938 return 0;
5939 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5940 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5941 return 0;
5942 }
5943 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5944 SYNC_EVENTS_DISABLED;
5945
5946 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5947 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5948 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5949 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5950 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5951 channel->channel);
5952
5953 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5954 inbuf, sizeof(inbuf), NULL, 0, NULL);
5955
5956 return rc;
5957}
5958
5959static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5960 bool temp)
5961{
5962 int (*set)(struct efx_channel *channel, bool temp);
5963 struct efx_channel *channel;
5964
5965 set = en ?
5966 efx_ef10_rx_enable_timestamping :
5967 efx_ef10_rx_disable_timestamping;
5968
5969 efx_for_each_channel(channel, efx) {
5970 int rc = set(channel, temp);
5971 if (en && rc != 0) {
5972 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5973 return rc;
5974 }
5975 }
5976
5977 return 0;
5978}
5979
Shradha Shah02246a72015-05-06 00:58:14 +01005980static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5981 struct hwtstamp_config *init)
5982{
5983 return -EOPNOTSUPP;
5984}
5985
Jon Cooperbd9a2652013-11-18 12:54:41 +00005986static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5987 struct hwtstamp_config *init)
5988{
5989 int rc;
5990
5991 switch (init->rx_filter) {
5992 case HWTSTAMP_FILTER_NONE:
5993 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5994 /* if TX timestamping is still requested then leave PTP on */
5995 return efx_ptp_change_mode(efx,
5996 init->tx_type != HWTSTAMP_TX_OFF, 0);
5997 case HWTSTAMP_FILTER_ALL:
5998 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5999 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6000 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6001 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6002 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6003 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6004 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6005 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6006 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6007 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6008 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6009 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6010 init->rx_filter = HWTSTAMP_FILTER_ALL;
6011 rc = efx_ptp_change_mode(efx, true, 0);
6012 if (!rc)
6013 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6014 if (rc)
6015 efx_ptp_change_mode(efx, false, 0);
6016 return rc;
6017 default:
6018 return -ERANGE;
6019 }
6020}
6021
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006022static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6023 struct netdev_phys_item_id *ppid)
6024{
6025 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6026
6027 if (!is_valid_ether_addr(nic_data->port_id))
6028 return -EOPNOTSUPP;
6029
6030 ppid->id_len = ETH_ALEN;
6031 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6032
6033 return 0;
6034}
6035
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006036static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6037{
6038 if (proto != htons(ETH_P_8021Q))
6039 return -EINVAL;
6040
6041 return efx_ef10_add_vlan(efx, vid);
6042}
6043
6044static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6045{
6046 if (proto != htons(ETH_P_8021Q))
6047 return -EINVAL;
6048
6049 return efx_ef10_del_vlan(efx, vid);
6050}
6051
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006052#define EF10_OFFLOAD_FEATURES \
6053 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006054 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006055 NETIF_F_IPV6_CSUM | \
6056 NETIF_F_RXHASH | \
6057 NETIF_F_NTUPLE)
6058
Shradha Shah02246a72015-05-06 00:58:14 +01006059const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006060 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01006061 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01006062 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01006063 .probe = efx_ef10_probe_vf,
6064 .remove = efx_ef10_remove,
6065 .dimension_resources = efx_ef10_dimension_resources,
6066 .init = efx_ef10_init_nic,
6067 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006068 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01006069 .map_reset_flags = efx_ef10_map_reset_flags,
6070 .reset = efx_ef10_reset,
6071 .probe_port = efx_mcdi_port_probe,
6072 .remove_port = efx_mcdi_port_remove,
6073 .fini_dmaq = efx_ef10_fini_dmaq,
6074 .prepare_flr = efx_ef10_prepare_flr,
6075 .finish_flr = efx_port_dummy_op_void,
6076 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006077 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006078 .start_stats = efx_port_dummy_op_void,
6079 .pull_stats = efx_port_dummy_op_void,
6080 .stop_stats = efx_port_dummy_op_void,
6081 .set_id_led = efx_mcdi_set_id_led,
6082 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01006083 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006084 .check_mac_fault = efx_mcdi_mac_check_fault,
6085 .reconfigure_port = efx_mcdi_port_reconfigure,
6086 .get_wol = efx_ef10_get_wol_vf,
6087 .set_wol = efx_ef10_set_wol_vf,
6088 .resume_wol = efx_port_dummy_op_void,
6089 .mcdi_request = efx_ef10_mcdi_request,
6090 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6091 .mcdi_read_response = efx_ef10_mcdi_read_response,
6092 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006093 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01006094 .irq_enable_master = efx_port_dummy_op_void,
6095 .irq_test_generate = efx_ef10_irq_test_generate,
6096 .irq_disable_non_ev = efx_port_dummy_op_void,
6097 .irq_handle_msi = efx_ef10_msi_interrupt,
6098 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6099 .tx_probe = efx_ef10_tx_probe,
6100 .tx_init = efx_ef10_tx_init,
6101 .tx_remove = efx_ef10_tx_remove,
6102 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006103 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006104 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006105 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01006106 .rx_probe = efx_ef10_rx_probe,
6107 .rx_init = efx_ef10_rx_init,
6108 .rx_remove = efx_ef10_rx_remove,
6109 .rx_write = efx_ef10_rx_write,
6110 .rx_defer_refill = efx_ef10_rx_defer_refill,
6111 .ev_probe = efx_ef10_ev_probe,
6112 .ev_init = efx_ef10_ev_init,
6113 .ev_fini = efx_ef10_ev_fini,
6114 .ev_remove = efx_ef10_ev_remove,
6115 .ev_process = efx_ef10_ev_process,
6116 .ev_read_ack = efx_ef10_ev_read_ack,
6117 .ev_test_generate = efx_ef10_ev_test_generate,
6118 .filter_table_probe = efx_ef10_filter_table_probe,
6119 .filter_table_restore = efx_ef10_filter_table_restore,
6120 .filter_table_remove = efx_ef10_filter_table_remove,
6121 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6122 .filter_insert = efx_ef10_filter_insert,
6123 .filter_remove_safe = efx_ef10_filter_remove_safe,
6124 .filter_get_safe = efx_ef10_filter_get_safe,
6125 .filter_clear_rx = efx_ef10_filter_clear_rx,
6126 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6127 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6128 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6129#ifdef CONFIG_RFS_ACCEL
6130 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6131 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6132#endif
6133#ifdef CONFIG_SFC_MTD
6134 .mtd_probe = efx_port_dummy_op_int,
6135#endif
6136 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6137 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006138 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6139 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01006140#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006141 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6142 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6143 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006144#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006145 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01006146 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006147
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006148 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01006149 .revision = EFX_REV_HUNT_A0,
6150 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6151 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6152 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6153 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6154 .can_rx_scatter = true,
6155 .always_rx_scatter = true,
6156 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6157 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006158 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01006159 .mcdi_max_ver = 2,
6160 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6161 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6162 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006163 .rx_hash_key_size = 40,
Shradha Shah02246a72015-05-06 00:58:14 +01006164};
6165
6166const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006167 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01006168 .mem_bar = EFX_MEM_BAR,
6169 .mem_map_size = efx_ef10_mem_map_size,
6170 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006171 .remove = efx_ef10_remove,
6172 .dimension_resources = efx_ef10_dimension_resources,
6173 .init = efx_ef10_init_nic,
6174 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006175 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01006176 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00006177 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01006178 .probe_port = efx_mcdi_port_probe,
6179 .remove_port = efx_mcdi_port_remove,
6180 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01006181 .prepare_flr = efx_ef10_prepare_flr,
6182 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01006183 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006184 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006185 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01006186 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01006187 .stop_stats = efx_mcdi_mac_stop_stats,
6188 .set_id_led = efx_mcdi_set_id_led,
6189 .push_irq_moderation = efx_ef10_push_irq_moderation,
6190 .reconfigure_mac = efx_ef10_mac_reconfigure,
6191 .check_mac_fault = efx_mcdi_mac_check_fault,
6192 .reconfigure_port = efx_mcdi_port_reconfigure,
6193 .get_wol = efx_ef10_get_wol,
6194 .set_wol = efx_ef10_set_wol,
6195 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01006196 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01006197 .test_nvram = efx_mcdi_nvram_test_all,
6198 .mcdi_request = efx_ef10_mcdi_request,
6199 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6200 .mcdi_read_response = efx_ef10_mcdi_read_response,
6201 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006202 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01006203 .irq_enable_master = efx_port_dummy_op_void,
6204 .irq_test_generate = efx_ef10_irq_test_generate,
6205 .irq_disable_non_ev = efx_port_dummy_op_void,
6206 .irq_handle_msi = efx_ef10_msi_interrupt,
6207 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6208 .tx_probe = efx_ef10_tx_probe,
6209 .tx_init = efx_ef10_tx_init,
6210 .tx_remove = efx_ef10_tx_remove,
6211 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006212 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006213 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006214 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01006215 .rx_probe = efx_ef10_rx_probe,
6216 .rx_init = efx_ef10_rx_init,
6217 .rx_remove = efx_ef10_rx_remove,
6218 .rx_write = efx_ef10_rx_write,
6219 .rx_defer_refill = efx_ef10_rx_defer_refill,
6220 .ev_probe = efx_ef10_ev_probe,
6221 .ev_init = efx_ef10_ev_init,
6222 .ev_fini = efx_ef10_ev_fini,
6223 .ev_remove = efx_ef10_ev_remove,
6224 .ev_process = efx_ef10_ev_process,
6225 .ev_read_ack = efx_ef10_ev_read_ack,
6226 .ev_test_generate = efx_ef10_ev_test_generate,
6227 .filter_table_probe = efx_ef10_filter_table_probe,
6228 .filter_table_restore = efx_ef10_filter_table_restore,
6229 .filter_table_remove = efx_ef10_filter_table_remove,
6230 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6231 .filter_insert = efx_ef10_filter_insert,
6232 .filter_remove_safe = efx_ef10_filter_remove_safe,
6233 .filter_get_safe = efx_ef10_filter_get_safe,
6234 .filter_clear_rx = efx_ef10_filter_clear_rx,
6235 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6236 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6237 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6238#ifdef CONFIG_RFS_ACCEL
6239 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6240 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6241#endif
6242#ifdef CONFIG_SFC_MTD
6243 .mtd_probe = efx_ef10_mtd_probe,
6244 .mtd_rename = efx_mcdi_mtd_rename,
6245 .mtd_read = efx_mcdi_mtd_read,
6246 .mtd_erase = efx_mcdi_mtd_erase,
6247 .mtd_write = efx_mcdi_mtd_write,
6248 .mtd_sync = efx_mcdi_mtd_sync,
6249#endif
6250 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006251 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6252 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006253 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6254 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006255#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01006256 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006257 .sriov_init = efx_ef10_sriov_init,
6258 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006259 .sriov_wanted = efx_ef10_sriov_wanted,
6260 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006261 .sriov_flr = efx_ef10_sriov_flr,
6262 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6263 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6264 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6265 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01006266 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006267 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6268 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6269 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006270#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006271 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01006272 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00006273 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01006274
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006275 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01006276 .revision = EFX_REV_HUNT_A0,
6277 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6278 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6279 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006280 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01006281 .can_rx_scatter = true,
6282 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00006283 .option_descriptors = true,
Ben Hutchings8127d662013-08-29 19:19:29 +01006284 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6285 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006286 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01006287 .mcdi_max_ver = 2,
6288 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006289 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6290 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006291 .rx_hash_key_size = 40,
Ben Hutchings8127d662013-08-29 19:19:29 +01006292};