blob: 626054d650100a1a406232d011ea3587a01a5494 [file] [log] [blame]
Ben Hutchings8127d662013-08-29 19:19:29 +01001/****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2012-2013 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include "net_driver.h"
11#include "ef10_regs.h"
12#include "io.h"
13#include "mcdi.h"
14#include "mcdi_pcol.h"
15#include "nic.h"
16#include "workarounds.h"
Jon Cooper74cd60a2013-09-16 14:18:51 +010017#include "selftest.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010018#include "ef10_sriov.h"
Ben Hutchings8127d662013-08-29 19:19:29 +010019#include <linux/in.h>
20#include <linux/jhash.h>
21#include <linux/wait.h>
22#include <linux/workqueue.h>
23
24/* Hardware control for EF10 architecture including 'Huntington'. */
25
26#define EFX_EF10_DRVGEN_EV 7
27enum {
28 EFX_EF10_TEST = 1,
29 EFX_EF10_REFILL,
30};
31
32/* The reserved RSS context value */
33#define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
Jon Cooper267c0152015-05-06 00:59:38 +010034/* The maximum size of a shared RSS context */
35/* TODO: this should really be from the mcdi protocol export */
36#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
Ben Hutchings8127d662013-08-29 19:19:29 +010037
38/* The filter table(s) are managed by firmware and we have write-only
39 * access. When removing filters we must identify them to the
40 * firmware by a 64-bit handle, but this is too wide for Linux kernel
41 * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
42 * be able to tell in advance whether a requested insertion will
43 * replace an existing filter. Therefore we maintain a software hash
44 * table, which should be at least as large as the hardware hash
45 * table.
46 *
47 * Huntington has a single 8K filter table shared between all filter
48 * types and both ports.
49 */
50#define HUNT_FILTER_TBL_ROWS 8192
51
Edward Cree12fb0da2015-07-21 15:11:00 +010052#define EFX_EF10_FILTER_ID_INVALID 0xffff
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010053
54#define EFX_EF10_FILTER_DEV_UC_MAX 32
55#define EFX_EF10_FILTER_DEV_MC_MAX 256
56
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010057/* VLAN list entry */
58struct efx_ef10_vlan {
59 struct list_head list;
60 u16 vid;
61};
62
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010063/* Per-VLAN filters information */
64struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010065 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010066 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010067 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
68 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
69 u16 ucdef;
70 u16 bcast;
71 u16 mcdef;
72};
73
Daniel Pieczko822b96f2015-07-21 15:10:27 +010074struct efx_ef10_dev_addr {
75 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010076};
77
Ben Hutchings8127d662013-08-29 19:19:29 +010078struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010079/* The MCDI match masks supported by this fw & hw, in order of priority */
80 u32 rx_match_mcdi_flags[
Ben Hutchings8127d662013-08-29 19:19:29 +010081 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
82 unsigned int rx_match_count;
83
84 struct {
85 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000086/* BUSY flag indicates that an update is in progress. AUTO_OLD is
87 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +010088 */
89#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000090#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +010091#define EFX_EF10_FILTER_FLAGS 3UL
92 u64 handle; /* firmware handle */
93 } *entry;
94 wait_queue_head_t waitq;
95/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +010096 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
97 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +010098 int dev_uc_count;
99 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100100 bool uc_promisc;
101 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100102/* Whether in multicast promiscuous mode when last changed */
103 bool mc_promisc_last;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100104 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100105 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100106};
107
108/* An arbitrary search limit for the software hash table */
109#define EFX_EF10_FILTER_SEARCH_LIMIT 200
110
Ben Hutchings8127d662013-08-29 19:19:29 +0100111static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
112static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100113static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
114static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
115 struct efx_ef10_filter_vlan *vlan);
116static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Ben Hutchings8127d662013-08-29 19:19:29 +0100117
118static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
119{
120 efx_dword_t reg;
121
122 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
123 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
124 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
125}
126
127static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
128{
Shradha Shah02246a72015-05-06 00:58:14 +0100129 int bar;
130
131 bar = efx->type->mem_bar;
132 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100133}
134
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100135static bool efx_ef10_is_vf(struct efx_nic *efx)
136{
137 return efx->type->is_vf;
138}
139
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100140static int efx_ef10_get_pf_index(struct efx_nic *efx)
141{
142 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
143 struct efx_ef10_nic_data *nic_data = efx->nic_data;
144 size_t outlen;
145 int rc;
146
147 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
148 sizeof(outbuf), &outlen);
149 if (rc)
150 return rc;
151 if (outlen < sizeof(outbuf))
152 return -EIO;
153
154 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
155 return 0;
156}
157
Shradha Shah88a37de2015-05-20 11:09:15 +0100158#ifdef CONFIG_SFC_SRIOV
159static int efx_ef10_get_vf_index(struct efx_nic *efx)
160{
161 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
162 struct efx_ef10_nic_data *nic_data = efx->nic_data;
163 size_t outlen;
164 int rc;
165
166 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
167 sizeof(outbuf), &outlen);
168 if (rc)
169 return rc;
170 if (outlen < sizeof(outbuf))
171 return -EIO;
172
173 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
174 return 0;
175}
176#endif
177
Ben Hutchingse5a25382013-09-05 22:50:59 +0100178static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100179{
180 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN);
181 struct efx_ef10_nic_data *nic_data = efx->nic_data;
182 size_t outlen;
183 int rc;
184
185 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
186
187 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
188 outbuf, sizeof(outbuf), &outlen);
189 if (rc)
190 return rc;
Ben Hutchingse5a25382013-09-05 22:50:59 +0100191 if (outlen < sizeof(outbuf)) {
192 netif_err(efx, drv, efx->net_dev,
193 "unable to read datapath firmware capabilities\n");
194 return -EIO;
195 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100196
Ben Hutchingse5a25382013-09-05 22:50:59 +0100197 nic_data->datapath_caps =
198 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
199
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100200 /* record the DPCPU firmware IDs to determine VEB vswitching support.
201 */
202 nic_data->rx_dpcpu_fw_id =
203 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
204 nic_data->tx_dpcpu_fw_id =
205 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
206
Ben Hutchingse5a25382013-09-05 22:50:59 +0100207 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100208 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
209 netif_err(efx, probe, efx->net_dev,
210 "current firmware does not support an RX prefix\n");
211 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100212 }
213
214 return 0;
215}
216
217static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
218{
219 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
220 int rc;
221
222 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
223 outbuf, sizeof(outbuf), NULL);
224 if (rc)
225 return rc;
226 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
227 return rc > 0 ? rc : -ERANGE;
228}
229
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100230static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100231{
232 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
233 size_t outlen;
234 int rc;
235
236 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
237
238 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
239 outbuf, sizeof(outbuf), &outlen);
240 if (rc)
241 return rc;
242 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
243 return -EIO;
244
Edward Creecd84ff42014-03-07 18:27:41 +0000245 ether_addr_copy(mac_address,
246 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100247 return 0;
248}
249
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100250static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
251{
252 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
253 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
254 size_t outlen;
255 int num_addrs, rc;
256
257 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
258 EVB_PORT_ID_ASSIGNED);
259 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
260 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
261
262 if (rc)
263 return rc;
264 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
265 return -EIO;
266
267 num_addrs = MCDI_DWORD(outbuf,
268 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
269
270 WARN_ON(num_addrs != 1);
271
272 ether_addr_copy(mac_address,
273 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
274
275 return 0;
276}
277
Shradha Shah0f5c0842015-06-02 11:37:58 +0100278static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
279 struct device_attribute *attr,
280 char *buf)
281{
282 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
283
284 return sprintf(buf, "%d\n",
285 ((efx->mcdi->fn_flags) &
286 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
287 ? 1 : 0);
288}
289
290static ssize_t efx_ef10_show_primary_flag(struct device *dev,
291 struct device_attribute *attr,
292 char *buf)
293{
294 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
295
296 return sprintf(buf, "%d\n",
297 ((efx->mcdi->fn_flags) &
298 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
299 ? 1 : 0);
300}
301
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100302static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
303{
304 struct efx_ef10_nic_data *nic_data = efx->nic_data;
305 struct efx_ef10_vlan *vlan;
306
307 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
308
309 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
310 if (vlan->vid == vid)
311 return vlan;
312 }
313
314 return NULL;
315}
316
317static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
318{
319 struct efx_ef10_nic_data *nic_data = efx->nic_data;
320 struct efx_ef10_vlan *vlan;
321 int rc;
322
323 mutex_lock(&nic_data->vlan_lock);
324
325 vlan = efx_ef10_find_vlan(efx, vid);
326 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100327 /* We add VID 0 on init. 8021q adds it on module init
328 * for all interfaces with VLAN filtring feature.
329 */
330 if (vid == 0)
331 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100332 netif_warn(efx, drv, efx->net_dev,
333 "VLAN %u already added\n", vid);
334 rc = -EALREADY;
335 goto fail_exist;
336 }
337
338 rc = -ENOMEM;
339 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
340 if (!vlan)
341 goto fail_alloc;
342
343 vlan->vid = vid;
344
345 list_add_tail(&vlan->list, &nic_data->vlan_list);
346
347 if (efx->filter_state) {
348 mutex_lock(&efx->mac_lock);
349 down_write(&efx->filter_sem);
350 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
351 up_write(&efx->filter_sem);
352 mutex_unlock(&efx->mac_lock);
353 if (rc)
354 goto fail_filter_add_vlan;
355 }
356
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100357done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100358 mutex_unlock(&nic_data->vlan_lock);
359 return 0;
360
361fail_filter_add_vlan:
362 list_del(&vlan->list);
363 kfree(vlan);
364fail_alloc:
365fail_exist:
366 mutex_unlock(&nic_data->vlan_lock);
367 return rc;
368}
369
370static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
371 struct efx_ef10_vlan *vlan)
372{
373 struct efx_ef10_nic_data *nic_data = efx->nic_data;
374
375 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
376
377 if (efx->filter_state) {
378 down_write(&efx->filter_sem);
379 efx_ef10_filter_del_vlan(efx, vlan->vid);
380 up_write(&efx->filter_sem);
381 }
382
383 list_del(&vlan->list);
384 kfree(vlan);
385}
386
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100387static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
388{
389 struct efx_ef10_nic_data *nic_data = efx->nic_data;
390 struct efx_ef10_vlan *vlan;
391 int rc = 0;
392
393 /* 8021q removes VID 0 on module unload for all interfaces
394 * with VLAN filtering feature. We need to keep it to receive
395 * untagged traffic.
396 */
397 if (vid == 0)
398 return 0;
399
400 mutex_lock(&nic_data->vlan_lock);
401
402 vlan = efx_ef10_find_vlan(efx, vid);
403 if (!vlan) {
404 netif_err(efx, drv, efx->net_dev,
405 "VLAN %u to be deleted not found\n", vid);
406 rc = -ENOENT;
407 } else {
408 efx_ef10_del_vlan_internal(efx, vlan);
409 }
410
411 mutex_unlock(&nic_data->vlan_lock);
412
413 return rc;
414}
415
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100416static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
417{
418 struct efx_ef10_nic_data *nic_data = efx->nic_data;
419 struct efx_ef10_vlan *vlan, *next_vlan;
420
421 mutex_lock(&nic_data->vlan_lock);
422 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
423 efx_ef10_del_vlan_internal(efx, vlan);
424 mutex_unlock(&nic_data->vlan_lock);
425}
426
Shradha Shah0f5c0842015-06-02 11:37:58 +0100427static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
428 NULL);
429static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
430
Ben Hutchings8127d662013-08-29 19:19:29 +0100431static int efx_ef10_probe(struct efx_nic *efx)
432{
433 struct efx_ef10_nic_data *nic_data;
Shradha Shah8be41322015-06-02 11:37:25 +0100434 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100435 int i, rc;
436
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000437 /* We can have one VI for each 8K region. However, until we
438 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100439 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +0100440 efx->max_channels = min_t(unsigned int,
441 EFX_MAX_CHANNELS,
442 efx_ef10_mem_map_size(efx) /
443 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
444 efx->max_tx_channels = efx->max_channels;
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000445 if (WARN_ON(efx->max_channels == 0))
446 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100447
448 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
449 if (!nic_data)
450 return -ENOMEM;
451 efx->nic_data = nic_data;
452
Edward Cree75aba2a2015-05-27 13:13:54 +0100453 /* we assume later that we can copy from this buffer in dwords */
454 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
455
Ben Hutchings8127d662013-08-29 19:19:29 +0100456 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
457 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
458 if (rc)
459 goto fail1;
460
461 /* Get the MC's warm boot count. In case it's rebooting right
462 * now, be prepared to retry.
463 */
464 i = 0;
465 for (;;) {
466 rc = efx_ef10_get_warm_boot_count(efx);
467 if (rc >= 0)
468 break;
469 if (++i == 5)
470 goto fail2;
471 ssleep(1);
472 }
473 nic_data->warm_boot_count = rc;
474
475 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
476
Daniel Pieczko45b24492015-05-06 00:57:14 +0100477 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
478
Ben Hutchings8127d662013-08-29 19:19:29 +0100479 /* In case we're recovering from a crash (kexec), we want to
480 * cancel any outstanding request by the previous user of this
481 * function. We send a special message using the least
482 * significant bits of the 'high' (doorbell) register.
483 */
484 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
485
486 rc = efx_mcdi_init(efx);
487 if (rc)
488 goto fail2;
489
490 /* Reset (most) configuration for this function */
491 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
492 if (rc)
493 goto fail3;
494
495 /* Enable event logging */
496 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
497 if (rc)
498 goto fail3;
499
Shradha Shah0f5c0842015-06-02 11:37:58 +0100500 rc = device_create_file(&efx->pci_dev->dev,
501 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100502 if (rc)
503 goto fail3;
504
Shradha Shah0f5c0842015-06-02 11:37:58 +0100505 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
506 if (rc)
507 goto fail4;
508
509 rc = efx_ef10_get_pf_index(efx);
510 if (rc)
511 goto fail5;
512
Ben Hutchingse5a25382013-09-05 22:50:59 +0100513 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100514 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100515 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100516
517 efx->rx_packet_len_offset =
518 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
519
Ben Hutchings8127d662013-08-29 19:19:29 +0100520 rc = efx_mcdi_port_get_number(efx);
521 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100522 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100523 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100524 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100525
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100526 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100527 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100528 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100529
530 rc = efx_ef10_get_sysclk_freq(efx);
531 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100532 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100533 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
534
Edward Cree267d9d72015-05-06 00:59:18 +0100535 /* Check whether firmware supports bug 35388 workaround.
536 * First try to enable it, then if we get EPERM, just
537 * ask if it's already enabled
538 */
Daniel Pieczko34ccfe62015-07-21 15:09:43 +0100539 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true, NULL);
Shradha Shahc9012e02015-06-02 11:37:41 +0100540 if (rc == 0) {
Ben Hutchings8127d662013-08-29 19:19:29 +0100541 nic_data->workaround_35388 = true;
Shradha Shahc9012e02015-06-02 11:37:41 +0100542 } else if (rc == -EPERM) {
Edward Cree267d9d72015-05-06 00:59:18 +0100543 unsigned int enabled;
544
545 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
546 if (rc)
547 goto fail3;
548 nic_data->workaround_35388 = enabled &
549 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
Shradha Shahc9012e02015-06-02 11:37:41 +0100550 } else if (rc != -ENOSYS && rc != -ENOENT) {
Shradha Shah0f5c0842015-06-02 11:37:58 +0100551 goto fail5;
Shradha Shahc9012e02015-06-02 11:37:41 +0100552 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100553 netif_dbg(efx, probe, efx->net_dev,
554 "workaround for bug 35388 is %sabled\n",
555 nic_data->workaround_35388 ? "en" : "dis");
556
557 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100558 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100559 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100560
Ben Hutchings9aecda92013-12-05 21:28:42 +0000561 efx_ptp_probe(efx, NULL);
562
Shradha Shah1d051e02015-06-02 11:38:16 +0100563#ifdef CONFIG_SFC_SRIOV
564 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
565 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
566 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
567
568 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
569 } else
570#endif
571 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
572
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100573 INIT_LIST_HEAD(&nic_data->vlan_list);
574 mutex_init(&nic_data->vlan_lock);
575
576 /* Add unspecified VID to support VLAN filtering being disabled */
577 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
578 if (rc)
579 goto fail_add_vid_unspec;
580
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100581 /* If VLAN filtering is enabled, we need VID 0 to get untagged
582 * traffic. It is added automatically if 8021q module is loaded,
583 * but we can't rely on it since module may be not loaded.
584 */
585 rc = efx_ef10_add_vlan(efx, 0);
586 if (rc)
587 goto fail_add_vid_0;
588
Ben Hutchings8127d662013-08-29 19:19:29 +0100589 return 0;
590
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100591fail_add_vid_0:
592 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100593fail_add_vid_unspec:
594 mutex_destroy(&nic_data->vlan_lock);
595 efx_ptp_remove(efx);
596 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100597fail5:
598 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
599fail4:
600 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100601fail3:
602 efx_mcdi_fini(efx);
603fail2:
604 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
605fail1:
606 kfree(nic_data);
607 efx->nic_data = NULL;
608 return rc;
609}
610
611static int efx_ef10_free_vis(struct efx_nic *efx)
612{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100613 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100614 size_t outlen;
615 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
616 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100617
618 /* -EALREADY means nothing to free, so ignore */
619 if (rc == -EALREADY)
620 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100621 if (rc)
622 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
623 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100624 return rc;
625}
626
Ben Hutchings183233b2013-06-28 21:47:12 +0100627#ifdef EFX_USE_PIO
628
629static void efx_ef10_free_piobufs(struct efx_nic *efx)
630{
631 struct efx_ef10_nic_data *nic_data = efx->nic_data;
632 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
633 unsigned int i;
634 int rc;
635
636 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
637
638 for (i = 0; i < nic_data->n_piobufs; i++) {
639 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
640 nic_data->piobuf_handle[i]);
641 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
642 NULL, 0, NULL);
643 WARN_ON(rc);
644 }
645
646 nic_data->n_piobufs = 0;
647}
648
649static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
650{
651 struct efx_ef10_nic_data *nic_data = efx->nic_data;
652 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
653 unsigned int i;
654 size_t outlen;
655 int rc = 0;
656
657 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
658
659 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000660 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
661 outbuf, sizeof(outbuf), &outlen);
662 if (rc) {
663 /* Don't display the MC error if we didn't have space
664 * for a VF.
665 */
666 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
667 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
668 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100669 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000670 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100671 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
672 rc = -EIO;
673 break;
674 }
675 nic_data->piobuf_handle[i] =
676 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
677 netif_dbg(efx, probe, efx->net_dev,
678 "allocated PIO buffer %u handle %x\n", i,
679 nic_data->piobuf_handle[i]);
680 }
681
682 nic_data->n_piobufs = i;
683 if (rc)
684 efx_ef10_free_piobufs(efx);
685 return rc;
686}
687
688static int efx_ef10_link_piobufs(struct efx_nic *efx)
689{
690 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100691 _MCDI_DECLARE_BUF(inbuf,
692 max(MC_CMD_LINK_PIOBUF_IN_LEN,
693 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100694 struct efx_channel *channel;
695 struct efx_tx_queue *tx_queue;
696 unsigned int offset, index;
697 int rc;
698
699 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
700 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
701
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100702 memset(inbuf, 0, sizeof(inbuf));
703
Ben Hutchings183233b2013-06-28 21:47:12 +0100704 /* Link a buffer to each VI in the write-combining mapping */
705 for (index = 0; index < nic_data->n_piobufs; ++index) {
706 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
707 nic_data->piobuf_handle[index]);
708 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
709 nic_data->pio_write_vi_base + index);
710 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
711 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
712 NULL, 0, NULL);
713 if (rc) {
714 netif_err(efx, drv, efx->net_dev,
715 "failed to link VI %u to PIO buffer %u (%d)\n",
716 nic_data->pio_write_vi_base + index, index,
717 rc);
718 goto fail;
719 }
720 netif_dbg(efx, probe, efx->net_dev,
721 "linked VI %u to PIO buffer %u\n",
722 nic_data->pio_write_vi_base + index, index);
723 }
724
725 /* Link a buffer to each TX queue */
726 efx_for_each_channel(channel, efx) {
727 efx_for_each_channel_tx_queue(tx_queue, channel) {
728 /* We assign the PIO buffers to queues in
729 * reverse order to allow for the following
730 * special case.
731 */
732 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
733 tx_queue->channel->channel - 1) *
734 efx_piobuf_size);
735 index = offset / ER_DZ_TX_PIOBUF_SIZE;
736 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
737
738 /* When the host page size is 4K, the first
739 * host page in the WC mapping may be within
740 * the same VI page as the last TX queue. We
741 * can only link one buffer to each VI.
742 */
743 if (tx_queue->queue == nic_data->pio_write_vi_base) {
744 BUG_ON(index != 0);
745 rc = 0;
746 } else {
747 MCDI_SET_DWORD(inbuf,
748 LINK_PIOBUF_IN_PIOBUF_HANDLE,
749 nic_data->piobuf_handle[index]);
750 MCDI_SET_DWORD(inbuf,
751 LINK_PIOBUF_IN_TXQ_INSTANCE,
752 tx_queue->queue);
753 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
754 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
755 NULL, 0, NULL);
756 }
757
758 if (rc) {
759 /* This is non-fatal; the TX path just
760 * won't use PIO for this queue
761 */
762 netif_err(efx, drv, efx->net_dev,
763 "failed to link VI %u to PIO buffer %u (%d)\n",
764 tx_queue->queue, index, rc);
765 tx_queue->piobuf = NULL;
766 } else {
767 tx_queue->piobuf =
768 nic_data->pio_write_base +
769 index * EFX_VI_PAGE_SIZE + offset;
770 tx_queue->piobuf_offset = offset;
771 netif_dbg(efx, probe, efx->net_dev,
772 "linked VI %u to PIO buffer %u offset %x addr %p\n",
773 tx_queue->queue, index,
774 tx_queue->piobuf_offset,
775 tx_queue->piobuf);
776 }
777 }
778 }
779
780 return 0;
781
782fail:
783 while (index--) {
784 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
785 nic_data->pio_write_vi_base + index);
786 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
787 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
788 NULL, 0, NULL);
789 }
790 return rc;
791}
792
Edward Creec0795bf2016-05-24 18:53:36 +0100793static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
794{
795 struct efx_channel *channel;
796 struct efx_tx_queue *tx_queue;
797
798 /* All our existing PIO buffers went away */
799 efx_for_each_channel(channel, efx)
800 efx_for_each_channel_tx_queue(tx_queue, channel)
801 tx_queue->piobuf = NULL;
802}
803
Ben Hutchings183233b2013-06-28 21:47:12 +0100804#else /* !EFX_USE_PIO */
805
806static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
807{
808 return n == 0 ? 0 : -ENOBUFS;
809}
810
811static int efx_ef10_link_piobufs(struct efx_nic *efx)
812{
813 return 0;
814}
815
816static void efx_ef10_free_piobufs(struct efx_nic *efx)
817{
818}
819
Edward Creec0795bf2016-05-24 18:53:36 +0100820static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
821{
822}
823
Ben Hutchings183233b2013-06-28 21:47:12 +0100824#endif /* EFX_USE_PIO */
825
Ben Hutchings8127d662013-08-29 19:19:29 +0100826static void efx_ef10_remove(struct efx_nic *efx)
827{
828 struct efx_ef10_nic_data *nic_data = efx->nic_data;
829 int rc;
830
Shradha Shahf1122a32015-05-20 11:09:46 +0100831#ifdef CONFIG_SFC_SRIOV
832 struct efx_ef10_nic_data *nic_data_pf;
833 struct pci_dev *pci_dev_pf;
834 struct efx_nic *efx_pf;
835 struct ef10_vf *vf;
836
837 if (efx->pci_dev->is_virtfn) {
838 pci_dev_pf = efx->pci_dev->physfn;
839 if (pci_dev_pf) {
840 efx_pf = pci_get_drvdata(pci_dev_pf);
841 nic_data_pf = efx_pf->nic_data;
842 vf = nic_data_pf->vf + nic_data->vf_index;
843 vf->efx = NULL;
844 } else
845 netif_info(efx, drv, efx->net_dev,
846 "Could not get the PF id from VF\n");
847 }
848#endif
849
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100850 efx_ef10_cleanup_vlans(efx);
851 mutex_destroy(&nic_data->vlan_lock);
852
Ben Hutchings9aecda92013-12-05 21:28:42 +0000853 efx_ptp_remove(efx);
854
Ben Hutchings8127d662013-08-29 19:19:29 +0100855 efx_mcdi_mon_remove(efx);
856
Ben Hutchings8127d662013-08-29 19:19:29 +0100857 efx_ef10_rx_free_indir_table(efx);
858
Ben Hutchings183233b2013-06-28 21:47:12 +0100859 if (nic_data->wc_membase)
860 iounmap(nic_data->wc_membase);
861
Ben Hutchings8127d662013-08-29 19:19:29 +0100862 rc = efx_ef10_free_vis(efx);
863 WARN_ON(rc != 0);
864
Ben Hutchings183233b2013-06-28 21:47:12 +0100865 if (!nic_data->must_restore_piobufs)
866 efx_ef10_free_piobufs(efx);
867
Shradha Shah0f5c0842015-06-02 11:37:58 +0100868 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
869 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
870
Ben Hutchings8127d662013-08-29 19:19:29 +0100871 efx_mcdi_fini(efx);
872 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
873 kfree(nic_data);
874}
875
Shradha Shah88a37de2015-05-20 11:09:15 +0100876static int efx_ef10_probe_pf(struct efx_nic *efx)
877{
878 return efx_ef10_probe(efx);
879}
880
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100881int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
882{
883 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
884
885 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
886 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
887 NULL, 0, NULL);
888}
889
890int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
891{
892 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
893
894 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
895 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
896 NULL, 0, NULL);
897}
898
899int efx_ef10_vport_add_mac(struct efx_nic *efx,
900 unsigned int port_id, u8 *mac)
901{
902 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
903
904 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
905 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
906
907 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
908 sizeof(inbuf), NULL, 0, NULL);
909}
910
911int efx_ef10_vport_del_mac(struct efx_nic *efx,
912 unsigned int port_id, u8 *mac)
913{
914 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
915
916 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
917 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
918
919 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
920 sizeof(inbuf), NULL, 0, NULL);
921}
922
Shradha Shah88a37de2015-05-20 11:09:15 +0100923#ifdef CONFIG_SFC_SRIOV
924static int efx_ef10_probe_vf(struct efx_nic *efx)
925{
926 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +0100927 struct pci_dev *pci_dev_pf;
928
929 /* If the parent PF has no VF data structure, it doesn't know about this
930 * VF so fail probe. The VF needs to be re-created. This can happen
931 * if the PF driver is unloaded while the VF is assigned to a guest.
932 */
933 pci_dev_pf = efx->pci_dev->physfn;
934 if (pci_dev_pf) {
935 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
936 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
937
938 if (!nic_data_pf->vf) {
939 netif_info(efx, drv, efx->net_dev,
940 "The VF cannot link to its parent PF; "
941 "please destroy and re-create the VF\n");
942 return -EBUSY;
943 }
944 }
Shradha Shah88a37de2015-05-20 11:09:15 +0100945
946 rc = efx_ef10_probe(efx);
947 if (rc)
948 return rc;
949
950 rc = efx_ef10_get_vf_index(efx);
951 if (rc)
952 goto fail;
953
Shradha Shahf1122a32015-05-20 11:09:46 +0100954 if (efx->pci_dev->is_virtfn) {
955 if (efx->pci_dev->physfn) {
956 struct efx_nic *efx_pf =
957 pci_get_drvdata(efx->pci_dev->physfn);
958 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
959 struct efx_ef10_nic_data *nic_data = efx->nic_data;
960
961 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +0100962 nic_data_p->vf[nic_data->vf_index].pci_dev =
963 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +0100964 } else
965 netif_info(efx, drv, efx->net_dev,
966 "Could not get the PF id from VF\n");
967 }
968
Shradha Shah88a37de2015-05-20 11:09:15 +0100969 return 0;
970
971fail:
972 efx_ef10_remove(efx);
973 return rc;
974}
975#else
976static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
977{
978 return 0;
979}
980#endif
981
Ben Hutchings8127d662013-08-29 19:19:29 +0100982static int efx_ef10_alloc_vis(struct efx_nic *efx,
983 unsigned int min_vis, unsigned int max_vis)
984{
985 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
986 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
987 struct efx_ef10_nic_data *nic_data = efx->nic_data;
988 size_t outlen;
989 int rc;
990
991 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
992 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
993 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
994 outbuf, sizeof(outbuf), &outlen);
995 if (rc != 0)
996 return rc;
997
998 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
999 return -EIO;
1000
1001 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1002 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1003
1004 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1005 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1006 return 0;
1007}
1008
Ben Hutchings183233b2013-06-28 21:47:12 +01001009/* Note that the failure path of this function does not free
1010 * resources, as this will be done by efx_ef10_remove().
1011 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001012static int efx_ef10_dimension_resources(struct efx_nic *efx)
1013{
Ben Hutchings183233b2013-06-28 21:47:12 +01001014 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1015 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001016 unsigned int min_vis = max(EFX_TXQ_TYPES,
1017 efx_separate_tx_channels ? 2 : 1);
1018 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001019 void __iomem *membase;
1020 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001021
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001022 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001023
1024#ifdef EFX_USE_PIO
1025 /* Try to allocate PIO buffers if wanted and if the full
1026 * number of PIO buffers would be sufficient to allocate one
1027 * copy-buffer per TX channel. Failure is non-fatal, as there
1028 * are only a small number of PIO buffers shared between all
1029 * functions of the controller.
1030 */
1031 if (efx_piobuf_size != 0 &&
1032 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1033 efx->n_tx_channels) {
1034 unsigned int n_piobufs =
1035 DIV_ROUND_UP(efx->n_tx_channels,
1036 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
1037
1038 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1039 if (rc)
1040 netif_err(efx, probe, efx->net_dev,
1041 "failed to allocate PIO buffers (%d)\n", rc);
1042 else
1043 netif_dbg(efx, probe, efx->net_dev,
1044 "allocated %u PIO buffers\n", n_piobufs);
1045 }
1046#else
1047 nic_data->n_piobufs = 0;
1048#endif
1049
1050 /* PIO buffers should be mapped with write-combining enabled,
1051 * and we want to make single UC and WC mappings rather than
1052 * several of each (in fact that's the only option if host
1053 * page size is >4K). So we may allocate some extra VIs just
1054 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001055 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001056 * The UC mapping contains (channel_vis - 1) complete VIs and the
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001057 * first half of the next VI. Then the WC mapping begins with
1058 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001059 */
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001060 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
Ben Hutchings183233b2013-06-28 21:47:12 +01001061 ER_DZ_TX_PIOBUF);
1062 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001063 /* pio_write_vi_base rounds down to give the number of complete
1064 * VIs inside the UC mapping.
1065 */
Ben Hutchings183233b2013-06-28 21:47:12 +01001066 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1067 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1068 nic_data->n_piobufs) *
1069 EFX_VI_PAGE_SIZE) -
1070 uc_mem_map_size);
1071 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1072 } else {
1073 pio_write_vi_base = 0;
1074 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001075 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001076 }
1077
1078 /* In case the last attached driver failed to free VIs, do it now */
1079 rc = efx_ef10_free_vis(efx);
1080 if (rc != 0)
1081 return rc;
1082
1083 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1084 if (rc != 0)
1085 return rc;
1086
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001087 if (nic_data->n_allocated_vis < channel_vis) {
1088 netif_info(efx, drv, efx->net_dev,
1089 "Could not allocate enough VIs to satisfy RSS"
1090 " requirements. Performance may not be optimal.\n");
1091 /* We didn't get the VIs to populate our channels.
1092 * We could keep what we got but then we'd have more
1093 * interrupts than we need.
1094 * Instead calculate new max_channels and restart
1095 */
1096 efx->max_channels = nic_data->n_allocated_vis;
1097 efx->max_tx_channels =
1098 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1099
1100 efx_ef10_free_vis(efx);
1101 return -EAGAIN;
1102 }
1103
Ben Hutchings183233b2013-06-28 21:47:12 +01001104 /* If we didn't get enough VIs to map all the PIO buffers, free the
1105 * PIO buffers
1106 */
1107 if (nic_data->n_piobufs &&
1108 nic_data->n_allocated_vis <
1109 pio_write_vi_base + nic_data->n_piobufs) {
1110 netif_dbg(efx, probe, efx->net_dev,
1111 "%u VIs are not sufficient to map %u PIO buffers\n",
1112 nic_data->n_allocated_vis, nic_data->n_piobufs);
1113 efx_ef10_free_piobufs(efx);
1114 }
1115
1116 /* Shrink the original UC mapping of the memory BAR */
1117 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1118 if (!membase) {
1119 netif_err(efx, probe, efx->net_dev,
1120 "could not shrink memory BAR to %x\n",
1121 uc_mem_map_size);
1122 return -ENOMEM;
1123 }
1124 iounmap(efx->membase);
1125 efx->membase = membase;
1126
1127 /* Set up the WC mapping if needed */
1128 if (wc_mem_map_size) {
1129 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1130 uc_mem_map_size,
1131 wc_mem_map_size);
1132 if (!nic_data->wc_membase) {
1133 netif_err(efx, probe, efx->net_dev,
1134 "could not allocate WC mapping of size %x\n",
1135 wc_mem_map_size);
1136 return -ENOMEM;
1137 }
1138 nic_data->pio_write_vi_base = pio_write_vi_base;
1139 nic_data->pio_write_base =
1140 nic_data->wc_membase +
1141 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1142 uc_mem_map_size);
1143
1144 rc = efx_ef10_link_piobufs(efx);
1145 if (rc)
1146 efx_ef10_free_piobufs(efx);
1147 }
1148
1149 netif_dbg(efx, probe, efx->net_dev,
1150 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1151 &efx->membase_phys, efx->membase, uc_mem_map_size,
1152 nic_data->wc_membase, wc_mem_map_size);
1153
1154 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001155}
1156
1157static int efx_ef10_init_nic(struct efx_nic *efx)
1158{
1159 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1160 int rc;
1161
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001162 if (nic_data->must_check_datapath_caps) {
1163 rc = efx_ef10_init_datapath_caps(efx);
1164 if (rc)
1165 return rc;
1166 nic_data->must_check_datapath_caps = false;
1167 }
1168
Ben Hutchings8127d662013-08-29 19:19:29 +01001169 if (nic_data->must_realloc_vis) {
1170 /* We cannot let the number of VIs change now */
1171 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1172 nic_data->n_allocated_vis);
1173 if (rc)
1174 return rc;
1175 nic_data->must_realloc_vis = false;
1176 }
1177
Ben Hutchings183233b2013-06-28 21:47:12 +01001178 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1179 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1180 if (rc == 0) {
1181 rc = efx_ef10_link_piobufs(efx);
1182 if (rc)
1183 efx_ef10_free_piobufs(efx);
1184 }
1185
1186 /* Log an error on failure, but this is non-fatal */
1187 if (rc)
1188 netif_err(efx, drv, efx->net_dev,
1189 "failed to restore PIO buffers (%d)\n", rc);
1190 nic_data->must_restore_piobufs = false;
1191 }
1192
Jon Cooper267c0152015-05-06 00:59:38 +01001193 /* don't fail init if RSS setup doesn't work */
1194 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1195
Ben Hutchings8127d662013-08-29 19:19:29 +01001196 return 0;
1197}
1198
Jon Cooper3e336262014-01-17 19:48:06 +00001199static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1200{
1201 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001202#ifdef CONFIG_SFC_SRIOV
1203 unsigned int i;
1204#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001205
1206 /* All our allocations have been reset */
1207 nic_data->must_realloc_vis = true;
1208 nic_data->must_restore_filters = true;
1209 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001210 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001211 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001212
1213 /* Driver-created vswitches and vports must be re-created */
1214 nic_data->must_probe_vswitching = true;
1215 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1216#ifdef CONFIG_SFC_SRIOV
1217 if (nic_data->vf)
1218 for (i = 0; i < efx->vf_count; i++)
1219 nic_data->vf[i].vport_id = 0;
1220#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001221}
1222
Jon Cooper087e9022015-05-20 11:11:35 +01001223static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1224{
1225 if (reason == RESET_TYPE_MC_FAILURE)
1226 return RESET_TYPE_DATAPATH;
1227
1228 return efx_mcdi_map_reset_reason(reason);
1229}
1230
Ben Hutchings8127d662013-08-29 19:19:29 +01001231static int efx_ef10_map_reset_flags(u32 *flags)
1232{
1233 enum {
1234 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1235 ETH_RESET_SHARED_SHIFT),
1236 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1237 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1238 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1239 ETH_RESET_SHARED_SHIFT)
1240 };
1241
1242 /* We assume for now that our PCI function is permitted to
1243 * reset everything.
1244 */
1245
1246 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1247 *flags &= ~EF10_RESET_MC;
1248 return RESET_TYPE_WORLD;
1249 }
1250
1251 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1252 *flags &= ~EF10_RESET_PORT;
1253 return RESET_TYPE_ALL;
1254 }
1255
1256 /* no invisible reset implemented */
1257
1258 return -EINVAL;
1259}
1260
Jon Cooper3e336262014-01-17 19:48:06 +00001261static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1262{
1263 int rc = efx_mcdi_reset(efx, reset_type);
1264
Daniel Pieczko27324822015-07-31 11:14:54 +01001265 /* Unprivileged functions return -EPERM, but need to return success
1266 * here so that the datapath is brought back up.
1267 */
1268 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1269 rc = 0;
1270
Jon Cooper3e336262014-01-17 19:48:06 +00001271 /* If it was a port reset, trigger reallocation of MC resources.
1272 * Note that on an MC reset nothing needs to be done now because we'll
1273 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001274 * For an FLR, we never get an MC reset event, but the MC has reset all
1275 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001276 */
Edward Creee2835462014-04-16 19:27:48 +01001277 if ((reset_type == RESET_TYPE_ALL ||
1278 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001279 efx_ef10_reset_mc_allocations(efx);
1280 return rc;
1281}
1282
Ben Hutchings8127d662013-08-29 19:19:29 +01001283#define EF10_DMA_STAT(ext_name, mcdi_name) \
1284 [EF10_STAT_ ## ext_name] = \
1285 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1286#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1287 [EF10_STAT_ ## int_name] = \
1288 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1289#define EF10_OTHER_STAT(ext_name) \
1290 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001291#define GENERIC_SW_STAT(ext_name) \
1292 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001293
1294static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001295 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1296 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1297 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1298 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1299 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1300 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1301 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1302 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1303 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1304 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1305 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1306 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1307 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1308 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1309 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1310 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1311 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1312 EF10_OTHER_STAT(port_rx_good_bytes),
1313 EF10_OTHER_STAT(port_rx_bad_bytes),
1314 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1315 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1316 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1317 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1318 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1319 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1320 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1321 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1322 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1323 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1324 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1325 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1326 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1327 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1328 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1329 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1330 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1331 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1332 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1333 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1334 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1335 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001336 GENERIC_SW_STAT(rx_nodesc_trunc),
1337 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001338 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1339 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1340 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1341 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1342 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1343 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1344 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1345 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1346 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1347 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1348 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1349 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001350 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1351 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1352 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1353 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1354 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1355 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1356 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1357 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1358 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1359 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1360 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1361 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1362 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1363 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1364 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1365 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1366 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1367 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001368};
1369
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001370#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1371 (1ULL << EF10_STAT_port_tx_packets) | \
1372 (1ULL << EF10_STAT_port_tx_pause) | \
1373 (1ULL << EF10_STAT_port_tx_unicast) | \
1374 (1ULL << EF10_STAT_port_tx_multicast) | \
1375 (1ULL << EF10_STAT_port_tx_broadcast) | \
1376 (1ULL << EF10_STAT_port_rx_bytes) | \
1377 (1ULL << \
1378 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1379 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1380 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1381 (1ULL << EF10_STAT_port_rx_packets) | \
1382 (1ULL << EF10_STAT_port_rx_good) | \
1383 (1ULL << EF10_STAT_port_rx_bad) | \
1384 (1ULL << EF10_STAT_port_rx_pause) | \
1385 (1ULL << EF10_STAT_port_rx_control) | \
1386 (1ULL << EF10_STAT_port_rx_unicast) | \
1387 (1ULL << EF10_STAT_port_rx_multicast) | \
1388 (1ULL << EF10_STAT_port_rx_broadcast) | \
1389 (1ULL << EF10_STAT_port_rx_lt64) | \
1390 (1ULL << EF10_STAT_port_rx_64) | \
1391 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1392 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1393 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1394 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1395 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1396 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1397 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1398 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1399 (1ULL << EF10_STAT_port_rx_overflow) | \
1400 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001401 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1402 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001403
1404/* These statistics are only provided by the 10G MAC. For a 10G/40G
1405 * switchable port we do not expose these because they might not
1406 * include all the packets they should.
1407 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001408#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1409 (1ULL << EF10_STAT_port_tx_lt64) | \
1410 (1ULL << EF10_STAT_port_tx_64) | \
1411 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1412 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1413 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1414 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1415 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1416 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001417
1418/* These statistics are only provided by the 40G MAC. For a 10G/40G
1419 * switchable port we do expose these because the errors will otherwise
1420 * be silent.
1421 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001422#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1423 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001424
Edward Cree568d7a02013-09-25 17:32:09 +01001425/* These statistics are only provided if the firmware supports the
1426 * capability PM_AND_RXDP_COUNTERS.
1427 */
1428#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001429 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1430 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1431 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1432 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1433 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1434 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1435 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1436 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1437 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1438 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1439 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1440 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001441
Edward Cree4bae9132013-09-27 18:52:49 +01001442static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001443{
Edward Cree4bae9132013-09-27 18:52:49 +01001444 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001445 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001446 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001447
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001448 if (!(efx->mcdi->fn_flags &
1449 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1450 return 0;
1451
Ben Hutchings8127d662013-08-29 19:19:29 +01001452 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001453 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001454 else
Edward Cree4bae9132013-09-27 18:52:49 +01001455 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001456
1457 if (nic_data->datapath_caps &
1458 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1459 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1460
Edward Cree4bae9132013-09-27 18:52:49 +01001461 return raw_mask;
1462}
1463
1464static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1465{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001466 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001467 u64 raw_mask[2];
1468
1469 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1470
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001471 /* Only show vadaptor stats when EVB capability is present */
1472 if (nic_data->datapath_caps &
1473 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1474 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1475 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1476 } else {
1477 raw_mask[1] = 0;
1478 }
Edward Cree4bae9132013-09-27 18:52:49 +01001479
1480#if BITS_PER_LONG == 64
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001481 mask[0] = raw_mask[0];
1482 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001483#else
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001484 mask[0] = raw_mask[0] & 0xffffffff;
1485 mask[1] = raw_mask[0] >> 32;
1486 mask[2] = raw_mask[1] & 0xffffffff;
1487 mask[3] = raw_mask[1] >> 32;
Edward Cree4bae9132013-09-27 18:52:49 +01001488#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001489}
1490
1491static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1492{
Edward Cree4bae9132013-09-27 18:52:49 +01001493 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1494
1495 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001496 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001497 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001498}
1499
Daniel Pieczkod7788192015-06-02 11:39:20 +01001500static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1501 struct rtnl_link_stats64 *core_stats)
1502{
1503 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1504 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1505 u64 *stats = nic_data->stats;
1506 size_t stats_count = 0, index;
1507
1508 efx_ef10_get_stat_mask(efx, mask);
1509
1510 if (full_stats) {
1511 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1512 if (efx_ef10_stat_desc[index].name) {
1513 *full_stats++ = stats[index];
1514 ++stats_count;
1515 }
1516 }
1517 }
1518
Bert Kenwardfbe43072015-08-26 16:39:03 +01001519 if (!core_stats)
1520 return stats_count;
1521
1522 if (nic_data->datapath_caps &
1523 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1524 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001525 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1526 stats[EF10_STAT_rx_multicast] +
1527 stats[EF10_STAT_rx_broadcast];
1528 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1529 stats[EF10_STAT_tx_multicast] +
1530 stats[EF10_STAT_tx_broadcast];
1531 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1532 stats[EF10_STAT_rx_multicast_bytes] +
1533 stats[EF10_STAT_rx_broadcast_bytes];
1534 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1535 stats[EF10_STAT_tx_multicast_bytes] +
1536 stats[EF10_STAT_tx_broadcast_bytes];
1537 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001538 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001539 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1540 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1541 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1542 core_stats->rx_errors = core_stats->rx_crc_errors;
1543 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001544 } else {
1545 /* Use port stats. */
1546 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1547 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1548 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1549 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1550 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1551 stats[GENERIC_STAT_rx_nodesc_trunc] +
1552 stats[GENERIC_STAT_rx_noskb_drops];
1553 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1554 core_stats->rx_length_errors =
1555 stats[EF10_STAT_port_rx_gtjumbo] +
1556 stats[EF10_STAT_port_rx_length_error];
1557 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1558 core_stats->rx_frame_errors =
1559 stats[EF10_STAT_port_rx_align_error];
1560 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1561 core_stats->rx_errors = (core_stats->rx_length_errors +
1562 core_stats->rx_crc_errors +
1563 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001564 }
1565
1566 return stats_count;
1567}
1568
1569static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001570{
1571 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001572 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001573 __le64 generation_start, generation_end;
1574 u64 *stats = nic_data->stats;
1575 __le64 *dma_stats;
1576
Edward Cree4bae9132013-09-27 18:52:49 +01001577 efx_ef10_get_stat_mask(efx, mask);
1578
Ben Hutchings8127d662013-08-29 19:19:29 +01001579 dma_stats = efx->stats_buffer.addr;
1580 nic_data = efx->nic_data;
1581
1582 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1583 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1584 return 0;
1585 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001586 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001587 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001588 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001589 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1590 if (generation_end != generation_start)
1591 return -EAGAIN;
1592
1593 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001594 efx_nic_fix_nodesc_drop_stat(efx,
1595 &stats[EF10_STAT_port_rx_nodesc_drops]);
1596 stats[EF10_STAT_port_rx_good_bytes] =
1597 stats[EF10_STAT_port_rx_bytes] -
1598 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1599 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1600 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001601 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001602 return 0;
1603}
1604
1605
Daniel Pieczkod7788192015-06-02 11:39:20 +01001606static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1607 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001608{
Ben Hutchings8127d662013-08-29 19:19:29 +01001609 int retry;
1610
1611 /* If we're unlucky enough to read statistics during the DMA, wait
1612 * up to 10ms for it to finish (typically takes <500us)
1613 */
1614 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001615 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001616 break;
1617 udelay(100);
1618 }
1619
Daniel Pieczkod7788192015-06-02 11:39:20 +01001620 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1621}
1622
1623static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1624{
1625 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1626 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1627 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1628 __le64 generation_start, generation_end;
1629 u64 *stats = nic_data->stats;
1630 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1631 struct efx_buffer stats_buf;
1632 __le64 *dma_stats;
1633 int rc;
1634
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001635 spin_unlock_bh(&efx->stats_lock);
1636
1637 if (in_interrupt()) {
1638 /* If in atomic context, cannot update stats. Just update the
1639 * software stats and return so the caller can continue.
1640 */
1641 spin_lock_bh(&efx->stats_lock);
1642 efx_update_sw_stats(efx, stats);
1643 return 0;
1644 }
1645
Daniel Pieczkod7788192015-06-02 11:39:20 +01001646 efx_ef10_get_stat_mask(efx, mask);
1647
1648 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001649 if (rc) {
1650 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001651 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001652 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001653
1654 dma_stats = stats_buf.addr;
1655 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1656
1657 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1658 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001659 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001660 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1661 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1662
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001663 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1664 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001665 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001666 if (rc) {
1667 /* Expect ENOENT if DMA queues have not been set up */
1668 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1669 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1670 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001671 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001672 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001673
1674 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001675 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1676 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001677 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001678 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001679 rmb();
1680 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1681 stats, stats_buf.addr, false);
1682 rmb();
1683 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1684 if (generation_end != generation_start) {
1685 rc = -EAGAIN;
1686 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001687 }
1688
Daniel Pieczkod7788192015-06-02 11:39:20 +01001689 efx_update_sw_stats(efx, stats);
1690out:
1691 efx_nic_free_buffer(efx, &stats_buf);
1692 return rc;
1693}
Ben Hutchings8127d662013-08-29 19:19:29 +01001694
Daniel Pieczkod7788192015-06-02 11:39:20 +01001695static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1696 struct rtnl_link_stats64 *core_stats)
1697{
1698 if (efx_ef10_try_update_nic_stats_vf(efx))
1699 return 0;
1700
1701 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001702}
1703
1704static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1705{
1706 struct efx_nic *efx = channel->efx;
1707 unsigned int mode, value;
1708 efx_dword_t timer_cmd;
1709
1710 if (channel->irq_moderation) {
1711 mode = 3;
1712 value = channel->irq_moderation - 1;
1713 } else {
1714 mode = 0;
1715 value = 0;
1716 }
1717
1718 if (EFX_EF10_WORKAROUND_35388(efx)) {
1719 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1720 EFE_DD_EVQ_IND_TIMER_FLAGS,
1721 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1722 ERF_DD_EVQ_IND_TIMER_VAL, value);
1723 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1724 channel->channel);
1725 } else {
1726 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1727 ERF_DZ_TC_TIMER_VAL, value);
1728 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1729 channel->channel);
1730 }
1731}
1732
Shradha Shah02246a72015-05-06 00:58:14 +01001733static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1734 struct ethtool_wolinfo *wol) {}
1735
1736static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1737{
1738 return -EOPNOTSUPP;
1739}
1740
Ben Hutchings8127d662013-08-29 19:19:29 +01001741static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1742{
1743 wol->supported = 0;
1744 wol->wolopts = 0;
1745 memset(&wol->sopass, 0, sizeof(wol->sopass));
1746}
1747
1748static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1749{
1750 if (type != 0)
1751 return -EINVAL;
1752 return 0;
1753}
1754
1755static void efx_ef10_mcdi_request(struct efx_nic *efx,
1756 const efx_dword_t *hdr, size_t hdr_len,
1757 const efx_dword_t *sdu, size_t sdu_len)
1758{
1759 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1760 u8 *pdu = nic_data->mcdi_buf.addr;
1761
1762 memcpy(pdu, hdr, hdr_len);
1763 memcpy(pdu + hdr_len, sdu, sdu_len);
1764 wmb();
1765
1766 /* The hardware provides 'low' and 'high' (doorbell) registers
1767 * for passing the 64-bit address of an MCDI request to
1768 * firmware. However the dwords are swapped by firmware. The
1769 * least significant bits of the doorbell are then 0 for all
1770 * MCDI requests due to alignment.
1771 */
1772 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1773 ER_DZ_MC_DB_LWRD);
1774 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1775 ER_DZ_MC_DB_HWRD);
1776}
1777
1778static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1779{
1780 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1781 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1782
1783 rmb();
1784 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1785}
1786
1787static void
1788efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1789 size_t offset, size_t outlen)
1790{
1791 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1792 const u8 *pdu = nic_data->mcdi_buf.addr;
1793
1794 memcpy(outbuf, pdu + offset, outlen);
1795}
1796
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001797static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1798{
1799 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1800
1801 /* All our allocations have been reset */
1802 efx_ef10_reset_mc_allocations(efx);
1803
1804 /* The datapath firmware might have been changed */
1805 nic_data->must_check_datapath_caps = true;
1806
1807 /* MAC statistics have been cleared on the NIC; clear the local
1808 * statistic that we update with efx_update_diff_stat().
1809 */
1810 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1811}
1812
Ben Hutchings8127d662013-08-29 19:19:29 +01001813static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1814{
1815 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1816 int rc;
1817
1818 rc = efx_ef10_get_warm_boot_count(efx);
1819 if (rc < 0) {
1820 /* The firmware is presumably in the process of
1821 * rebooting. However, we are supposed to report each
1822 * reboot just once, so we must only do that once we
1823 * can read and store the updated warm boot count.
1824 */
1825 return 0;
1826 }
1827
1828 if (rc == nic_data->warm_boot_count)
1829 return 0;
1830
1831 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01001832 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01001833
Ben Hutchings8127d662013-08-29 19:19:29 +01001834 return -EIO;
1835}
1836
1837/* Handle an MSI interrupt
1838 *
1839 * Handle an MSI hardware interrupt. This routine schedules event
1840 * queue processing. No interrupt acknowledgement cycle is necessary.
1841 * Also, we never need to check that the interrupt is for us, since
1842 * MSI interrupts cannot be shared.
1843 */
1844static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1845{
1846 struct efx_msi_context *context = dev_id;
1847 struct efx_nic *efx = context->efx;
1848
1849 netif_vdbg(efx, intr, efx->net_dev,
1850 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1851
1852 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1853 /* Note test interrupts */
1854 if (context->index == efx->irq_level)
1855 efx->last_irq_cpu = raw_smp_processor_id();
1856
1857 /* Schedule processing of the channel */
1858 efx_schedule_channel_irq(efx->channel[context->index]);
1859 }
1860
1861 return IRQ_HANDLED;
1862}
1863
1864static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1865{
1866 struct efx_nic *efx = dev_id;
1867 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1868 struct efx_channel *channel;
1869 efx_dword_t reg;
1870 u32 queues;
1871
1872 /* Read the ISR which also ACKs the interrupts */
1873 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1874 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1875
1876 if (queues == 0)
1877 return IRQ_NONE;
1878
1879 if (likely(soft_enabled)) {
1880 /* Note test interrupts */
1881 if (queues & (1U << efx->irq_level))
1882 efx->last_irq_cpu = raw_smp_processor_id();
1883
1884 efx_for_each_channel(channel, efx) {
1885 if (queues & 1)
1886 efx_schedule_channel_irq(channel);
1887 queues >>= 1;
1888 }
1889 }
1890
1891 netif_vdbg(efx, intr, efx->net_dev,
1892 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1893 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1894
1895 return IRQ_HANDLED;
1896}
1897
1898static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1899{
1900 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1901
1902 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1903
1904 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1905 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1906 inbuf, sizeof(inbuf), NULL, 0, NULL);
1907}
1908
1909static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1910{
1911 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1912 (tx_queue->ptr_mask + 1) *
1913 sizeof(efx_qword_t),
1914 GFP_KERNEL);
1915}
1916
1917/* This writes to the TX_DESC_WPTR and also pushes data */
1918static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1919 const efx_qword_t *txd)
1920{
1921 unsigned int write_ptr;
1922 efx_oword_t reg;
1923
1924 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1925 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1926 reg.qword[0] = *txd;
1927 efx_writeo_page(tx_queue->efx, &reg,
1928 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1929}
1930
1931static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1932{
1933 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1934 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001935 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1936 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1937 struct efx_channel *channel = tx_queue->channel;
1938 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001939 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001940 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001941 dma_addr_t dma_addr;
1942 efx_qword_t *txd;
1943 int rc;
1944 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001945 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001946
1947 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1948 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1949 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1950 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1951 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1952 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1953 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1954 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001955 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001956
1957 dma_addr = tx_queue->txd.buf.dma_addr;
1958
1959 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1960 tx_queue->queue, entries, (u64)dma_addr);
1961
1962 for (i = 0; i < entries; ++i) {
1963 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1964 dma_addr += EFX_BUF_SIZE;
1965 }
1966
1967 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1968
1969 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001970 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001971 if (rc)
1972 goto fail;
1973
1974 /* A previous user of this TX queue might have set us up the
1975 * bomb by writing a descriptor to the TX push collector but
1976 * not the doorbell. (Each collector belongs to a port, not a
1977 * queue or function, so cannot easily be reset.) We must
1978 * attempt to push a no-op descriptor in its place.
1979 */
1980 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1981 tx_queue->insert_count = 1;
1982 txd = efx_tx_desc(tx_queue, 0);
1983 EFX_POPULATE_QWORD_4(*txd,
1984 ESF_DZ_TX_DESC_IS_OPT, true,
1985 ESF_DZ_TX_OPTION_TYPE,
1986 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1987 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1988 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1989 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00001990
1991 if (nic_data->datapath_caps &
1992 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
1993 tx_queue->tso_version = 1;
1994 }
1995
Ben Hutchings8127d662013-08-29 19:19:29 +01001996 wmb();
1997 efx_ef10_push_tx_desc(tx_queue, txd);
1998
1999 return;
2000
2001fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002002 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2003 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002004}
2005
2006static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2007{
2008 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002009 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002010 struct efx_nic *efx = tx_queue->efx;
2011 size_t outlen;
2012 int rc;
2013
2014 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2015 tx_queue->queue);
2016
Edward Cree1e0b8122013-05-31 18:36:12 +01002017 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002018 outbuf, sizeof(outbuf), &outlen);
2019
2020 if (rc && rc != -EALREADY)
2021 goto fail;
2022
2023 return;
2024
2025fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002026 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2027 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002028}
2029
2030static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2031{
2032 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2033}
2034
2035/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2036static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2037{
2038 unsigned int write_ptr;
2039 efx_dword_t reg;
2040
2041 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2042 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2043 efx_writed_page(tx_queue->efx, &reg,
2044 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2045}
2046
2047static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2048{
2049 unsigned int old_write_count = tx_queue->write_count;
2050 struct efx_tx_buffer *buffer;
2051 unsigned int write_ptr;
2052 efx_qword_t *txd;
2053
Martin Habetsb2663a42015-11-02 12:51:31 +00002054 tx_queue->xmit_more_available = false;
2055 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2056 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002057
2058 do {
2059 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2060 buffer = &tx_queue->buffer[write_ptr];
2061 txd = efx_tx_desc(tx_queue, write_ptr);
2062 ++tx_queue->write_count;
2063
2064 /* Create TX descriptor ring entry */
2065 if (buffer->flags & EFX_TX_BUF_OPTION) {
2066 *txd = buffer->option;
2067 } else {
2068 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2069 EFX_POPULATE_QWORD_3(
2070 *txd,
2071 ESF_DZ_TX_KER_CONT,
2072 buffer->flags & EFX_TX_BUF_CONT,
2073 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2074 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2075 }
2076 } while (tx_queue->write_count != tx_queue->insert_count);
2077
2078 wmb(); /* Ensure descriptors are written before they are fetched */
2079
2080 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2081 txd = efx_tx_desc(tx_queue,
2082 old_write_count & tx_queue->ptr_mask);
2083 efx_ef10_push_tx_desc(tx_queue, txd);
2084 ++tx_queue->pushes;
2085 } else {
2086 efx_ef10_notify_tx_desc(tx_queue);
2087 }
2088}
2089
Jon Cooper267c0152015-05-06 00:59:38 +01002090static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2091 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002092{
2093 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2094 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002095 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002096 size_t outlen;
2097 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002098 u32 alloc_type = exclusive ?
2099 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2100 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2101 unsigned rss_spread = exclusive ?
2102 efx->rss_spread :
2103 min(rounddown_pow_of_two(efx->rss_spread),
2104 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2105
2106 if (!exclusive && rss_spread == 1) {
2107 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2108 if (context_size)
2109 *context_size = 1;
2110 return 0;
2111 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002112
Jon Cooperdcb41232016-04-25 16:51:00 +01002113 if (nic_data->datapath_caps &
2114 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2115 return -EOPNOTSUPP;
2116
Ben Hutchings8127d662013-08-29 19:19:29 +01002117 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002118 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002119 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2120 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002121
2122 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2123 outbuf, sizeof(outbuf), &outlen);
2124 if (rc != 0)
2125 return rc;
2126
2127 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2128 return -EIO;
2129
2130 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2131
Jon Cooper267c0152015-05-06 00:59:38 +01002132 if (context_size)
2133 *context_size = rss_spread;
2134
Ben Hutchings8127d662013-08-29 19:19:29 +01002135 return 0;
2136}
2137
2138static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2139{
2140 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2141 int rc;
2142
2143 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2144 context);
2145
2146 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2147 NULL, 0, NULL);
2148 WARN_ON(rc != 0);
2149}
2150
Jon Cooper267c0152015-05-06 00:59:38 +01002151static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2152 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002153{
2154 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2155 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2156 int i, rc;
2157
2158 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2159 context);
2160 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2161 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2162
2163 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2164 MCDI_PTR(tablebuf,
2165 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002166 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002167
2168 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2169 sizeof(tablebuf), NULL, 0, NULL);
2170 if (rc != 0)
2171 return rc;
2172
2173 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2174 context);
2175 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2176 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2177 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2178 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2179 efx->rx_hash_key[i];
2180
2181 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2182 sizeof(keybuf), NULL, 0, NULL);
2183}
2184
2185static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2186{
2187 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2188
2189 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2190 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2191 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2192}
2193
Jon Cooper267c0152015-05-06 00:59:38 +01002194static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2195 unsigned *context_size)
2196{
2197 u32 new_rx_rss_context;
2198 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2199 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2200 false, context_size);
2201
2202 if (rc != 0)
2203 return rc;
2204
2205 nic_data->rx_rss_context = new_rx_rss_context;
2206 nic_data->rx_rss_context_exclusive = false;
2207 efx_set_default_rx_indir_table(efx);
2208 return 0;
2209}
2210
2211static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2212 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01002213{
2214 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2215 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002216 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002217
Jon Cooper267c0152015-05-06 00:59:38 +01002218 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2219 !nic_data->rx_rss_context_exclusive) {
2220 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2221 true, NULL);
2222 if (rc == -EOPNOTSUPP)
2223 return rc;
2224 else if (rc != 0)
2225 goto fail1;
2226 } else {
2227 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002228 }
2229
Jon Cooper267c0152015-05-06 00:59:38 +01002230 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2231 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01002232 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002233 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002234
Jon Cooper267c0152015-05-06 00:59:38 +01002235 if (nic_data->rx_rss_context != new_rx_rss_context)
2236 efx_ef10_rx_free_indir_table(efx);
2237 nic_data->rx_rss_context = new_rx_rss_context;
2238 nic_data->rx_rss_context_exclusive = true;
2239 if (rx_indir_table != efx->rx_indir_table)
2240 memcpy(efx->rx_indir_table, rx_indir_table,
2241 sizeof(efx->rx_indir_table));
2242 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002243
Jon Cooper267c0152015-05-06 00:59:38 +01002244fail2:
2245 if (new_rx_rss_context != nic_data->rx_rss_context)
2246 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2247fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002248 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002249 return rc;
2250}
2251
2252static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2253 const u32 *rx_indir_table)
2254{
2255 int rc;
2256
2257 if (efx->rss_spread == 1)
2258 return 0;
2259
2260 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2261
2262 if (rc == -ENOBUFS && !user) {
2263 unsigned context_size;
2264 bool mismatch = false;
2265 size_t i;
2266
2267 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2268 i++)
2269 mismatch = rx_indir_table[i] !=
2270 ethtool_rxfh_indir_default(i, efx->rss_spread);
2271
2272 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2273 if (rc == 0) {
2274 if (context_size != efx->rss_spread)
2275 netif_warn(efx, probe, efx->net_dev,
2276 "Could not allocate an exclusive RSS"
2277 " context; allocated a shared one of"
2278 " different size."
2279 " Wanted %u, got %u.\n",
2280 efx->rss_spread, context_size);
2281 else if (mismatch)
2282 netif_warn(efx, probe, efx->net_dev,
2283 "Could not allocate an exclusive RSS"
2284 " context; allocated a shared one but"
2285 " could not apply custom"
2286 " indirection.\n");
2287 else
2288 netif_info(efx, probe, efx->net_dev,
2289 "Could not allocate an exclusive RSS"
2290 " context; allocated a shared one.\n");
2291 }
2292 }
2293 return rc;
2294}
2295
2296static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2297 const u32 *rx_indir_table
2298 __attribute__ ((unused)))
2299{
2300 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2301
2302 if (user)
2303 return -EOPNOTSUPP;
2304 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2305 return 0;
2306 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002307}
2308
2309static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2310{
2311 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2312 (rx_queue->ptr_mask + 1) *
2313 sizeof(efx_qword_t),
2314 GFP_KERNEL);
2315}
2316
2317static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2318{
2319 MCDI_DECLARE_BUF(inbuf,
2320 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2321 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002322 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2323 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2324 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002325 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002326 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002327 dma_addr_t dma_addr;
2328 int rc;
2329 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002330 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002331
2332 rx_queue->scatter_n = 0;
2333 rx_queue->scatter_len = 0;
2334
2335 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2336 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2337 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2338 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2339 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002340 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2341 INIT_RXQ_IN_FLAG_PREFIX, 1,
2342 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002343 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002344 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002345
2346 dma_addr = rx_queue->rxd.buf.dma_addr;
2347
2348 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2349 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2350
2351 for (i = 0; i < entries; ++i) {
2352 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2353 dma_addr += EFX_BUF_SIZE;
2354 }
2355
2356 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2357
2358 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002359 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002360 if (rc)
2361 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2362 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002363}
2364
2365static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2366{
2367 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002368 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002369 struct efx_nic *efx = rx_queue->efx;
2370 size_t outlen;
2371 int rc;
2372
2373 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2374 efx_rx_queue_index(rx_queue));
2375
Edward Cree1e0b8122013-05-31 18:36:12 +01002376 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002377 outbuf, sizeof(outbuf), &outlen);
2378
2379 if (rc && rc != -EALREADY)
2380 goto fail;
2381
2382 return;
2383
2384fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002385 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2386 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002387}
2388
2389static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2390{
2391 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2392}
2393
2394/* This creates an entry in the RX descriptor queue */
2395static inline void
2396efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2397{
2398 struct efx_rx_buffer *rx_buf;
2399 efx_qword_t *rxd;
2400
2401 rxd = efx_rx_desc(rx_queue, index);
2402 rx_buf = efx_rx_buffer(rx_queue, index);
2403 EFX_POPULATE_QWORD_2(*rxd,
2404 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2405 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2406}
2407
2408static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2409{
2410 struct efx_nic *efx = rx_queue->efx;
2411 unsigned int write_count;
2412 efx_dword_t reg;
2413
2414 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2415 write_count = rx_queue->added_count & ~7;
2416 if (rx_queue->notified_count == write_count)
2417 return;
2418
2419 do
2420 efx_ef10_build_rx_desc(
2421 rx_queue,
2422 rx_queue->notified_count & rx_queue->ptr_mask);
2423 while (++rx_queue->notified_count != write_count);
2424
2425 wmb();
2426 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2427 write_count & rx_queue->ptr_mask);
2428 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2429 efx_rx_queue_index(rx_queue));
2430}
2431
2432static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2433
2434static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2435{
2436 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2437 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2438 efx_qword_t event;
2439
2440 EFX_POPULATE_QWORD_2(event,
2441 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2442 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2443
2444 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2445
2446 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2447 * already swapped the data to little-endian order.
2448 */
2449 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2450 sizeof(efx_qword_t));
2451
2452 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2453 inbuf, sizeof(inbuf), 0,
2454 efx_ef10_rx_defer_refill_complete, 0);
2455}
2456
2457static void
2458efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2459 int rc, efx_dword_t *outbuf,
2460 size_t outlen_actual)
2461{
2462 /* nothing to do */
2463}
2464
2465static int efx_ef10_ev_probe(struct efx_channel *channel)
2466{
2467 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2468 (channel->eventq_mask + 1) *
2469 sizeof(efx_qword_t),
2470 GFP_KERNEL);
2471}
2472
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002473static void efx_ef10_ev_fini(struct efx_channel *channel)
2474{
2475 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2476 MCDI_DECLARE_BUF_ERR(outbuf);
2477 struct efx_nic *efx = channel->efx;
2478 size_t outlen;
2479 int rc;
2480
2481 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2482
2483 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2484 outbuf, sizeof(outbuf), &outlen);
2485
2486 if (rc && rc != -EALREADY)
2487 goto fail;
2488
2489 return;
2490
2491fail:
2492 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2493 outbuf, outlen, rc);
2494}
2495
Ben Hutchings8127d662013-08-29 19:19:29 +01002496static int efx_ef10_ev_init(struct efx_channel *channel)
2497{
2498 MCDI_DECLARE_BUF(inbuf,
2499 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2500 EFX_BUF_SIZE));
2501 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
2502 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2503 struct efx_nic *efx = channel->efx;
2504 struct efx_ef10_nic_data *nic_data;
2505 bool supports_rx_merge;
2506 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002507 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002508 dma_addr_t dma_addr;
2509 int rc;
2510 int i;
2511
2512 nic_data = efx->nic_data;
2513 supports_rx_merge =
2514 !!(nic_data->datapath_caps &
2515 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2516
2517 /* Fill event queue with all ones (i.e. empty events) */
2518 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2519
2520 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2521 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2522 /* INIT_EVQ expects index in vector table, not absolute */
2523 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
2524 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2525 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2526 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2527 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2528 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
2529 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2530 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2531 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2532 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2533 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2534 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2535 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2536
2537 dma_addr = channel->eventq.buf.dma_addr;
2538 for (i = 0; i < entries; ++i) {
2539 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2540 dma_addr += EFX_BUF_SIZE;
2541 }
2542
2543 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2544
2545 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2546 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01002547 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002548 if (channel->channel || rc)
2549 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002550
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002551 /* Successfully created event queue on channel 0 */
2552 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002553 if (rc == -ENOSYS) {
2554 /* GET_WORKAROUNDS was implemented before the bug26807
2555 * workaround, thus the latter must be unavailable in this fw
2556 */
2557 nic_data->workaround_26807 = false;
2558 rc = 0;
2559 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002560 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002561 } else {
2562 nic_data->workaround_26807 =
2563 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002564
Edward Cree832dc9e2015-07-21 15:09:31 +01002565 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2566 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002567 unsigned int flags;
2568
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002569 rc = efx_mcdi_set_workaround(efx,
2570 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002571 true, &flags);
2572
2573 if (!rc) {
2574 if (flags &
2575 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2576 netif_info(efx, drv, efx->net_dev,
2577 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00002578
2579 /* With MCFW v4.6.x and earlier, the
2580 * boot count will have incremented,
2581 * so re-read the warm_boot_count
2582 * value now to ensure this function
2583 * doesn't think it has changed next
2584 * time it checks.
2585 */
2586 rc = efx_ef10_get_warm_boot_count(efx);
2587 if (rc >= 0) {
2588 nic_data->warm_boot_count = rc;
2589 rc = 0;
2590 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002591 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002592 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002593 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002594 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002595 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002596 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002597 }
2598
2599 if (!rc)
2600 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002601
2602fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002603 efx_ef10_ev_fini(channel);
2604 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002605}
2606
2607static void efx_ef10_ev_remove(struct efx_channel *channel)
2608{
2609 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2610}
2611
2612static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2613 unsigned int rx_queue_label)
2614{
2615 struct efx_nic *efx = rx_queue->efx;
2616
2617 netif_info(efx, hw, efx->net_dev,
2618 "rx event arrived on queue %d labeled as queue %u\n",
2619 efx_rx_queue_index(rx_queue), rx_queue_label);
2620
2621 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2622}
2623
2624static void
2625efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2626 unsigned int actual, unsigned int expected)
2627{
2628 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2629 struct efx_nic *efx = rx_queue->efx;
2630
2631 netif_info(efx, hw, efx->net_dev,
2632 "dropped %d events (index=%d expected=%d)\n",
2633 dropped, actual, expected);
2634
2635 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2636}
2637
2638/* partially received RX was aborted. clean up. */
2639static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2640{
2641 unsigned int rx_desc_ptr;
2642
Ben Hutchings8127d662013-08-29 19:19:29 +01002643 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2644 "scattered RX aborted (dropping %u buffers)\n",
2645 rx_queue->scatter_n);
2646
2647 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2648
2649 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2650 0, EFX_RX_PKT_DISCARD);
2651
2652 rx_queue->removed_count += rx_queue->scatter_n;
2653 rx_queue->scatter_n = 0;
2654 rx_queue->scatter_len = 0;
2655 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2656}
2657
2658static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2659 const efx_qword_t *event)
2660{
2661 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2662 unsigned int n_descs, n_packets, i;
2663 struct efx_nic *efx = channel->efx;
2664 struct efx_rx_queue *rx_queue;
2665 bool rx_cont;
2666 u16 flags = 0;
2667
2668 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2669 return 0;
2670
2671 /* Basic packet information */
2672 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2673 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2674 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2675 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2676 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2677
Ben Hutchings48ce5632013-11-01 16:42:44 +00002678 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2679 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2680 EFX_QWORD_FMT "\n",
2681 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002682
2683 rx_queue = efx_channel_get_rx_queue(channel);
2684
2685 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2686 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2687
2688 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2689 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2690
2691 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002692 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2693
Ben Hutchings8127d662013-08-29 19:19:29 +01002694 /* detect rx abort */
2695 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002696 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2697 netdev_WARN(efx->net_dev,
2698 "invalid RX abort: scatter_n=%u event="
2699 EFX_QWORD_FMT "\n",
2700 rx_queue->scatter_n,
2701 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002702 efx_ef10_handle_rx_abort(rx_queue);
2703 return 0;
2704 }
2705
Ben Hutchings92a04162013-09-24 23:21:57 +01002706 /* Check that RX completion merging is valid, i.e.
2707 * the current firmware supports it and this is a
2708 * non-scattered packet.
2709 */
2710 if (!(nic_data->datapath_caps &
2711 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2712 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002713 efx_ef10_handle_rx_bad_lbits(
2714 rx_queue, next_ptr_lbits,
2715 (rx_queue->removed_count +
2716 rx_queue->scatter_n + 1) &
2717 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2718 return 0;
2719 }
2720
2721 /* Merged completion for multiple non-scattered packets */
2722 rx_queue->scatter_n = 1;
2723 rx_queue->scatter_len = 0;
2724 n_packets = n_descs;
2725 ++channel->n_rx_merge_events;
2726 channel->n_rx_merge_packets += n_packets;
2727 flags |= EFX_RX_PKT_PREFIX_LEN;
2728 } else {
2729 ++rx_queue->scatter_n;
2730 rx_queue->scatter_len += rx_bytes;
2731 if (rx_cont)
2732 return 0;
2733 n_packets = 1;
2734 }
2735
2736 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2737 flags |= EFX_RX_PKT_DISCARD;
2738
2739 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2740 channel->n_rx_ip_hdr_chksum_err += n_packets;
2741 } else if (unlikely(EFX_QWORD_FIELD(*event,
2742 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2743 channel->n_rx_tcp_udp_chksum_err += n_packets;
2744 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2745 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2746 flags |= EFX_RX_PKT_CSUMMED;
2747 }
2748
2749 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2750 flags |= EFX_RX_PKT_TCP;
2751
2752 channel->irq_mod_score += 2 * n_packets;
2753
2754 /* Handle received packet(s) */
2755 for (i = 0; i < n_packets; i++) {
2756 efx_rx_packet(rx_queue,
2757 rx_queue->removed_count & rx_queue->ptr_mask,
2758 rx_queue->scatter_n, rx_queue->scatter_len,
2759 flags);
2760 rx_queue->removed_count += rx_queue->scatter_n;
2761 }
2762
2763 rx_queue->scatter_n = 0;
2764 rx_queue->scatter_len = 0;
2765
2766 return n_packets;
2767}
2768
2769static int
2770efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2771{
2772 struct efx_nic *efx = channel->efx;
2773 struct efx_tx_queue *tx_queue;
2774 unsigned int tx_ev_desc_ptr;
2775 unsigned int tx_ev_q_label;
2776 int tx_descs = 0;
2777
2778 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2779 return 0;
2780
2781 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2782 return 0;
2783
2784 /* Transmit completion */
2785 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2786 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2787 tx_queue = efx_channel_get_tx_queue(channel,
2788 tx_ev_q_label % EFX_TXQ_TYPES);
2789 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2790 tx_queue->ptr_mask);
2791 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2792
2793 return tx_descs;
2794}
2795
2796static void
2797efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2798{
2799 struct efx_nic *efx = channel->efx;
2800 int subcode;
2801
2802 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2803
2804 switch (subcode) {
2805 case ESE_DZ_DRV_TIMER_EV:
2806 case ESE_DZ_DRV_WAKE_UP_EV:
2807 break;
2808 case ESE_DZ_DRV_START_UP_EV:
2809 /* event queue init complete. ok. */
2810 break;
2811 default:
2812 netif_err(efx, hw, efx->net_dev,
2813 "channel %d unknown driver event type %d"
2814 " (data " EFX_QWORD_FMT ")\n",
2815 channel->channel, subcode,
2816 EFX_QWORD_VAL(*event));
2817
2818 }
2819}
2820
2821static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2822 efx_qword_t *event)
2823{
2824 struct efx_nic *efx = channel->efx;
2825 u32 subcode;
2826
2827 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2828
2829 switch (subcode) {
2830 case EFX_EF10_TEST:
2831 channel->event_test_cpu = raw_smp_processor_id();
2832 break;
2833 case EFX_EF10_REFILL:
2834 /* The queue must be empty, so we won't receive any rx
2835 * events, so efx_process_channel() won't refill the
2836 * queue. Refill it here
2837 */
Jon Coopercce28792013-10-02 11:04:14 +01002838 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002839 break;
2840 default:
2841 netif_err(efx, hw, efx->net_dev,
2842 "channel %d unknown driver event type %u"
2843 " (data " EFX_QWORD_FMT ")\n",
2844 channel->channel, (unsigned) subcode,
2845 EFX_QWORD_VAL(*event));
2846 }
2847}
2848
2849static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2850{
2851 struct efx_nic *efx = channel->efx;
2852 efx_qword_t event, *p_event;
2853 unsigned int read_ptr;
2854 int ev_code;
2855 int tx_descs = 0;
2856 int spent = 0;
2857
Eric W. Biederman75363a42014-03-14 18:11:22 -07002858 if (quota <= 0)
2859 return spent;
2860
Ben Hutchings8127d662013-08-29 19:19:29 +01002861 read_ptr = channel->eventq_read_ptr;
2862
2863 for (;;) {
2864 p_event = efx_event(channel, read_ptr);
2865 event = *p_event;
2866
2867 if (!efx_event_present(&event))
2868 break;
2869
2870 EFX_SET_QWORD(*p_event);
2871
2872 ++read_ptr;
2873
2874 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2875
2876 netif_vdbg(efx, drv, efx->net_dev,
2877 "processing event on %d " EFX_QWORD_FMT "\n",
2878 channel->channel, EFX_QWORD_VAL(event));
2879
2880 switch (ev_code) {
2881 case ESE_DZ_EV_CODE_MCDI_EV:
2882 efx_mcdi_process_event(channel, &event);
2883 break;
2884 case ESE_DZ_EV_CODE_RX_EV:
2885 spent += efx_ef10_handle_rx_event(channel, &event);
2886 if (spent >= quota) {
2887 /* XXX can we split a merged event to
2888 * avoid going over-quota?
2889 */
2890 spent = quota;
2891 goto out;
2892 }
2893 break;
2894 case ESE_DZ_EV_CODE_TX_EV:
2895 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2896 if (tx_descs > efx->txq_entries) {
2897 spent = quota;
2898 goto out;
2899 } else if (++spent == quota) {
2900 goto out;
2901 }
2902 break;
2903 case ESE_DZ_EV_CODE_DRIVER_EV:
2904 efx_ef10_handle_driver_event(channel, &event);
2905 if (++spent == quota)
2906 goto out;
2907 break;
2908 case EFX_EF10_DRVGEN_EV:
2909 efx_ef10_handle_driver_generated_event(channel, &event);
2910 break;
2911 default:
2912 netif_err(efx, hw, efx->net_dev,
2913 "channel %d unknown event type %d"
2914 " (data " EFX_QWORD_FMT ")\n",
2915 channel->channel, ev_code,
2916 EFX_QWORD_VAL(event));
2917 }
2918 }
2919
2920out:
2921 channel->eventq_read_ptr = read_ptr;
2922 return spent;
2923}
2924
2925static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2926{
2927 struct efx_nic *efx = channel->efx;
2928 efx_dword_t rptr;
2929
2930 if (EFX_EF10_WORKAROUND_35388(efx)) {
2931 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2932 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2933 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2934 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2935
2936 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2937 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2938 ERF_DD_EVQ_IND_RPTR,
2939 (channel->eventq_read_ptr &
2940 channel->eventq_mask) >>
2941 ERF_DD_EVQ_IND_RPTR_WIDTH);
2942 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2943 channel->channel);
2944 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2945 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2946 ERF_DD_EVQ_IND_RPTR,
2947 channel->eventq_read_ptr &
2948 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2949 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2950 channel->channel);
2951 } else {
2952 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2953 channel->eventq_read_ptr &
2954 channel->eventq_mask);
2955 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2956 }
2957}
2958
2959static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2960{
2961 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2962 struct efx_nic *efx = channel->efx;
2963 efx_qword_t event;
2964 int rc;
2965
2966 EFX_POPULATE_QWORD_2(event,
2967 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2968 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2969
2970 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2971
2972 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2973 * already swapped the data to little-endian order.
2974 */
2975 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2976 sizeof(efx_qword_t));
2977
2978 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2979 NULL, 0, NULL);
2980 if (rc != 0)
2981 goto fail;
2982
2983 return;
2984
2985fail:
2986 WARN_ON(true);
2987 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2988}
2989
2990void efx_ef10_handle_drain_event(struct efx_nic *efx)
2991{
2992 if (atomic_dec_and_test(&efx->active_queues))
2993 wake_up(&efx->flush_wq);
2994
2995 WARN_ON(atomic_read(&efx->active_queues) < 0);
2996}
2997
2998static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2999{
3000 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3001 struct efx_channel *channel;
3002 struct efx_tx_queue *tx_queue;
3003 struct efx_rx_queue *rx_queue;
3004 int pending;
3005
3006 /* If the MC has just rebooted, the TX/RX queues will have already been
3007 * torn down, but efx->active_queues needs to be set to zero.
3008 */
3009 if (nic_data->must_realloc_vis) {
3010 atomic_set(&efx->active_queues, 0);
3011 return 0;
3012 }
3013
3014 /* Do not attempt to write to the NIC during EEH recovery */
3015 if (efx->state != STATE_RECOVERY) {
3016 efx_for_each_channel(channel, efx) {
3017 efx_for_each_channel_rx_queue(rx_queue, channel)
3018 efx_ef10_rx_fini(rx_queue);
3019 efx_for_each_channel_tx_queue(tx_queue, channel)
3020 efx_ef10_tx_fini(tx_queue);
3021 }
3022
3023 wait_event_timeout(efx->flush_wq,
3024 atomic_read(&efx->active_queues) == 0,
3025 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3026 pending = atomic_read(&efx->active_queues);
3027 if (pending) {
3028 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3029 pending);
3030 return -ETIMEDOUT;
3031 }
3032 }
3033
3034 return 0;
3035}
3036
Edward Creee2835462014-04-16 19:27:48 +01003037static void efx_ef10_prepare_flr(struct efx_nic *efx)
3038{
3039 atomic_set(&efx->active_queues, 0);
3040}
3041
Ben Hutchings8127d662013-08-29 19:19:29 +01003042static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3043 const struct efx_filter_spec *right)
3044{
3045 if ((left->match_flags ^ right->match_flags) |
3046 ((left->flags ^ right->flags) &
3047 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3048 return false;
3049
3050 return memcmp(&left->outer_vid, &right->outer_vid,
3051 sizeof(struct efx_filter_spec) -
3052 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3053}
3054
3055static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3056{
3057 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3058 return jhash2((const u32 *)&spec->outer_vid,
3059 (sizeof(struct efx_filter_spec) -
3060 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3061 0);
3062 /* XXX should we randomise the initval? */
3063}
3064
3065/* Decide whether a filter should be exclusive or else should allow
3066 * delivery to additional recipients. Currently we decide that
3067 * filters for specific local unicast MAC and IP addresses are
3068 * exclusive.
3069 */
3070static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3071{
3072 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3073 !is_multicast_ether_addr(spec->loc_mac))
3074 return true;
3075
3076 if ((spec->match_flags &
3077 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3078 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3079 if (spec->ether_type == htons(ETH_P_IP) &&
3080 !ipv4_is_multicast(spec->loc_host[0]))
3081 return true;
3082 if (spec->ether_type == htons(ETH_P_IPV6) &&
3083 ((const u8 *)spec->loc_host)[0] != 0xff)
3084 return true;
3085 }
3086
3087 return false;
3088}
3089
3090static struct efx_filter_spec *
3091efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3092 unsigned int filter_idx)
3093{
3094 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3095 ~EFX_EF10_FILTER_FLAGS);
3096}
3097
3098static unsigned int
3099efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3100 unsigned int filter_idx)
3101{
3102 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3103}
3104
3105static void
3106efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3107 unsigned int filter_idx,
3108 const struct efx_filter_spec *spec,
3109 unsigned int flags)
3110{
3111 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3112}
3113
3114static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3115 const struct efx_filter_spec *spec,
3116 efx_dword_t *inbuf, u64 handle,
3117 bool replacing)
3118{
3119 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01003120 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01003121
3122 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3123
Jon Cooperdcb41232016-04-25 16:51:00 +01003124 /* Remove RSS flag if we don't have an RSS context. */
3125 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3126 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3127 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3128 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3129
Ben Hutchings8127d662013-08-29 19:19:29 +01003130 if (replacing) {
3131 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3132 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3133 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3134 } else {
3135 u32 match_fields = 0;
3136
3137 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3138 efx_ef10_filter_is_exclusive(spec) ?
3139 MC_CMD_FILTER_OP_IN_OP_INSERT :
3140 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3141
3142 /* Convert match flags and values. Unlike almost
3143 * everything else in MCDI, these fields are in
3144 * network byte order.
3145 */
3146 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3147 match_fields |=
3148 is_multicast_ether_addr(spec->loc_mac) ?
3149 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3150 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3151#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3152 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3153 match_fields |= \
3154 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3155 mcdi_field ## _LBN; \
3156 BUILD_BUG_ON( \
3157 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3158 sizeof(spec->gen_field)); \
3159 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3160 &spec->gen_field, sizeof(spec->gen_field)); \
3161 }
3162 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3163 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3164 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3165 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3166 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3167 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3168 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3169 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3170 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3171 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3172#undef COPY_FIELD
3173 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3174 match_fields);
3175 }
3176
Daniel Pieczko45b24492015-05-06 00:57:14 +01003177 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003178 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3179 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3180 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3181 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01003182 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003183 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3184 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00003185 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3186 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3187 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003188 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01003189 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01003190 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3191 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01003192 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01003193 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3194 spec->rss_context !=
3195 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3196 spec->rss_context : nic_data->rx_rss_context);
3197}
3198
3199static int efx_ef10_filter_push(struct efx_nic *efx,
3200 const struct efx_filter_spec *spec,
3201 u64 *handle, bool replacing)
3202{
3203 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3204 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3205 int rc;
3206
3207 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3208 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3209 outbuf, sizeof(outbuf), NULL);
3210 if (rc == 0)
3211 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01003212 if (rc == -ENOSPC)
3213 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01003214 return rc;
3215}
3216
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003217static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01003218{
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003219 unsigned int match_flags = spec->match_flags;
3220 u32 mcdi_flags = 0;
3221
3222 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3223 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3224 mcdi_flags |=
3225 is_multicast_ether_addr(spec->loc_mac) ?
3226 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3227 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3228 }
3229
3230#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3231 unsigned int old_match_flags = match_flags; \
3232 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3233 if (match_flags != old_match_flags) \
3234 mcdi_flags |= \
3235 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3236 mcdi_field ## _LBN); \
3237 }
3238 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3239 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3240 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3241 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3242 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3243 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3244 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3245 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3246 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3247 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3248#undef MAP_FILTER_TO_MCDI_FLAG
3249
3250 /* Did we map them all? */
3251 WARN_ON_ONCE(match_flags);
3252
3253 return mcdi_flags;
3254}
3255
3256static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3257 const struct efx_filter_spec *spec)
3258{
3259 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003260 unsigned int match_pri;
3261
3262 for (match_pri = 0;
3263 match_pri < table->rx_match_count;
3264 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003265 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01003266 return match_pri;
3267
3268 return -EPROTONOSUPPORT;
3269}
3270
3271static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3272 struct efx_filter_spec *spec,
3273 bool replace_equal)
3274{
3275 struct efx_ef10_filter_table *table = efx->filter_state;
3276 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3277 struct efx_filter_spec *saved_spec;
3278 unsigned int match_pri, hash;
3279 unsigned int priv_flags;
3280 bool replacing = false;
3281 int ins_index = -1;
3282 DEFINE_WAIT(wait);
3283 bool is_mc_recip;
3284 s32 rc;
3285
3286 /* For now, only support RX filters */
3287 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3288 EFX_FILTER_FLAG_RX)
3289 return -EINVAL;
3290
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003291 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01003292 if (rc < 0)
3293 return rc;
3294 match_pri = rc;
3295
3296 hash = efx_ef10_filter_hash(spec);
3297 is_mc_recip = efx_filter_is_mc_recipient(spec);
3298 if (is_mc_recip)
3299 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3300
3301 /* Find any existing filters with the same match tuple or
3302 * else a free slot to insert at. If any of them are busy,
3303 * we have to wait and retry.
3304 */
3305 for (;;) {
3306 unsigned int depth = 1;
3307 unsigned int i;
3308
3309 spin_lock_bh(&efx->filter_lock);
3310
3311 for (;;) {
3312 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3313 saved_spec = efx_ef10_filter_entry_spec(table, i);
3314
3315 if (!saved_spec) {
3316 if (ins_index < 0)
3317 ins_index = i;
3318 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3319 if (table->entry[i].spec &
3320 EFX_EF10_FILTER_FLAG_BUSY)
3321 break;
3322 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003323 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003324 rc = -EPERM;
3325 goto out_unlock;
3326 }
3327 if (!is_mc_recip) {
3328 /* This is the only one */
3329 if (spec->priority ==
3330 saved_spec->priority &&
3331 !replace_equal) {
3332 rc = -EEXIST;
3333 goto out_unlock;
3334 }
3335 ins_index = i;
3336 goto found;
3337 } else if (spec->priority >
3338 saved_spec->priority ||
3339 (spec->priority ==
3340 saved_spec->priority &&
3341 replace_equal)) {
3342 if (ins_index < 0)
3343 ins_index = i;
3344 else
3345 __set_bit(depth, mc_rem_map);
3346 }
3347 }
3348
3349 /* Once we reach the maximum search depth, use
3350 * the first suitable slot or return -EBUSY if
3351 * there was none
3352 */
3353 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3354 if (ins_index < 0) {
3355 rc = -EBUSY;
3356 goto out_unlock;
3357 }
3358 goto found;
3359 }
3360
3361 ++depth;
3362 }
3363
3364 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3365 spin_unlock_bh(&efx->filter_lock);
3366 schedule();
3367 }
3368
3369found:
3370 /* Create a software table entry if necessary, and mark it
3371 * busy. We might yet fail to insert, but any attempt to
3372 * insert a conflicting filter while we're waiting for the
3373 * firmware must find the busy entry.
3374 */
3375 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3376 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003377 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3378 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003379 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003380 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3381 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003382 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003383 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003384 rc = ins_index;
3385 goto out_unlock;
3386 }
3387 replacing = true;
3388 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3389 } else {
3390 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3391 if (!saved_spec) {
3392 rc = -ENOMEM;
3393 goto out_unlock;
3394 }
3395 *saved_spec = *spec;
3396 priv_flags = 0;
3397 }
3398 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3399 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3400
3401 /* Mark lower-priority multicast recipients busy prior to removal */
3402 if (is_mc_recip) {
3403 unsigned int depth, i;
3404
3405 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3406 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3407 if (test_bit(depth, mc_rem_map))
3408 table->entry[i].spec |=
3409 EFX_EF10_FILTER_FLAG_BUSY;
3410 }
3411 }
3412
3413 spin_unlock_bh(&efx->filter_lock);
3414
3415 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3416 replacing);
3417
3418 /* Finalise the software table entry */
3419 spin_lock_bh(&efx->filter_lock);
3420 if (rc == 0) {
3421 if (replacing) {
3422 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003423 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3424 saved_spec->flags |=
3425 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003426 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003427 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003428 saved_spec->flags |= spec->flags;
3429 saved_spec->rss_context = spec->rss_context;
3430 saved_spec->dmaq_id = spec->dmaq_id;
3431 }
3432 } else if (!replacing) {
3433 kfree(saved_spec);
3434 saved_spec = NULL;
3435 }
3436 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3437
3438 /* Remove and finalise entries for lower-priority multicast
3439 * recipients
3440 */
3441 if (is_mc_recip) {
3442 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3443 unsigned int depth, i;
3444
3445 memset(inbuf, 0, sizeof(inbuf));
3446
3447 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3448 if (!test_bit(depth, mc_rem_map))
3449 continue;
3450
3451 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3452 saved_spec = efx_ef10_filter_entry_spec(table, i);
3453 priv_flags = efx_ef10_filter_entry_flags(table, i);
3454
3455 if (rc == 0) {
3456 spin_unlock_bh(&efx->filter_lock);
3457 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3458 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3459 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3460 table->entry[i].handle);
3461 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3462 inbuf, sizeof(inbuf),
3463 NULL, 0, NULL);
3464 spin_lock_bh(&efx->filter_lock);
3465 }
3466
3467 if (rc == 0) {
3468 kfree(saved_spec);
3469 saved_spec = NULL;
3470 priv_flags = 0;
3471 } else {
3472 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3473 }
3474 efx_ef10_filter_set_entry(table, i, saved_spec,
3475 priv_flags);
3476 }
3477 }
3478
3479 /* If successful, return the inserted filter ID */
3480 if (rc == 0)
3481 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3482
3483 wake_up_all(&table->waitq);
3484out_unlock:
3485 spin_unlock_bh(&efx->filter_lock);
3486 finish_wait(&table->waitq, &wait);
3487 return rc;
3488}
3489
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003490static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003491{
3492 /* no need to do anything here on EF10 */
3493}
3494
3495/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003496 * If !by_index, remove by ID
3497 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003498 * Filter ID may come from userland and must be range-checked.
3499 */
3500static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003501 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003502 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003503{
3504 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3505 struct efx_ef10_filter_table *table = efx->filter_state;
3506 MCDI_DECLARE_BUF(inbuf,
3507 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3508 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3509 struct efx_filter_spec *spec;
3510 DEFINE_WAIT(wait);
3511 int rc;
3512
3513 /* Find the software table entry and mark it busy. Don't
3514 * remove it yet; any attempt to update while we're waiting
3515 * for the firmware must find the busy entry.
3516 */
3517 for (;;) {
3518 spin_lock_bh(&efx->filter_lock);
3519 if (!(table->entry[filter_idx].spec &
3520 EFX_EF10_FILTER_FLAG_BUSY))
3521 break;
3522 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3523 spin_unlock_bh(&efx->filter_lock);
3524 schedule();
3525 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003526
Ben Hutchings8127d662013-08-29 19:19:29 +01003527 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003528 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003529 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003530 efx_ef10_filter_pri(table, spec) !=
Ben Hutchings8127d662013-08-29 19:19:29 +01003531 filter_id / HUNT_FILTER_TBL_ROWS)) {
3532 rc = -ENOENT;
3533 goto out_unlock;
3534 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003535
3536 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003537 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003538 /* Just remove flags */
3539 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003540 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003541 rc = 0;
3542 goto out_unlock;
3543 }
3544
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003545 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003546 rc = -ENOENT;
3547 goto out_unlock;
3548 }
3549
Ben Hutchings8127d662013-08-29 19:19:29 +01003550 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3551 spin_unlock_bh(&efx->filter_lock);
3552
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003553 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003554 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003555
3556 struct efx_filter_spec new_spec = *spec;
3557
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003558 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003559 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00003560 (efx_rss_enabled(efx) ?
3561 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01003562 new_spec.dmaq_id = 0;
3563 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3564 rc = efx_ef10_filter_push(efx, &new_spec,
3565 &table->entry[filter_idx].handle,
3566 true);
3567
3568 spin_lock_bh(&efx->filter_lock);
3569 if (rc == 0)
3570 *spec = new_spec;
3571 } else {
3572 /* Really remove the filter */
3573
3574 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3575 efx_ef10_filter_is_exclusive(spec) ?
3576 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3577 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3578 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3579 table->entry[filter_idx].handle);
3580 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3581 inbuf, sizeof(inbuf), NULL, 0, NULL);
3582
3583 spin_lock_bh(&efx->filter_lock);
3584 if (rc == 0) {
3585 kfree(spec);
3586 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3587 }
3588 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003589
Ben Hutchings8127d662013-08-29 19:19:29 +01003590 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3591 wake_up_all(&table->waitq);
3592out_unlock:
3593 spin_unlock_bh(&efx->filter_lock);
3594 finish_wait(&table->waitq, &wait);
3595 return rc;
3596}
3597
3598static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3599 enum efx_filter_priority priority,
3600 u32 filter_id)
3601{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003602 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3603 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003604}
3605
Edward Cree12fb0da2015-07-21 15:11:00 +01003606static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
3607{
3608 return filter_id % HUNT_FILTER_TBL_ROWS;
3609}
3610
Edward Cree8c915622016-06-15 17:49:05 +01003611static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
3612 enum efx_filter_priority priority,
3613 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01003614{
Edward Cree8c915622016-06-15 17:49:05 +01003615 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
3616 return;
3617 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01003618}
3619
Ben Hutchings8127d662013-08-29 19:19:29 +01003620static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3621 enum efx_filter_priority priority,
3622 u32 filter_id, struct efx_filter_spec *spec)
3623{
3624 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3625 struct efx_ef10_filter_table *table = efx->filter_state;
3626 const struct efx_filter_spec *saved_spec;
3627 int rc;
3628
3629 spin_lock_bh(&efx->filter_lock);
3630 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3631 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003632 efx_ef10_filter_pri(table, saved_spec) ==
Ben Hutchings8127d662013-08-29 19:19:29 +01003633 filter_id / HUNT_FILTER_TBL_ROWS) {
3634 *spec = *saved_spec;
3635 rc = 0;
3636 } else {
3637 rc = -ENOENT;
3638 }
3639 spin_unlock_bh(&efx->filter_lock);
3640 return rc;
3641}
3642
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003643static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003644 enum efx_filter_priority priority)
3645{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003646 unsigned int priority_mask;
3647 unsigned int i;
3648 int rc;
3649
3650 priority_mask = (((1U << (priority + 1)) - 1) &
3651 ~(1U << EFX_FILTER_PRI_AUTO));
3652
3653 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3654 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3655 i, true);
3656 if (rc && rc != -ENOENT)
3657 return rc;
3658 }
3659
3660 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003661}
3662
3663static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3664 enum efx_filter_priority priority)
3665{
3666 struct efx_ef10_filter_table *table = efx->filter_state;
3667 unsigned int filter_idx;
3668 s32 count = 0;
3669
3670 spin_lock_bh(&efx->filter_lock);
3671 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3672 if (table->entry[filter_idx].spec &&
3673 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3674 priority)
3675 ++count;
3676 }
3677 spin_unlock_bh(&efx->filter_lock);
3678 return count;
3679}
3680
3681static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3682{
3683 struct efx_ef10_filter_table *table = efx->filter_state;
3684
3685 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3686}
3687
3688static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3689 enum efx_filter_priority priority,
3690 u32 *buf, u32 size)
3691{
3692 struct efx_ef10_filter_table *table = efx->filter_state;
3693 struct efx_filter_spec *spec;
3694 unsigned int filter_idx;
3695 s32 count = 0;
3696
3697 spin_lock_bh(&efx->filter_lock);
3698 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3699 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3700 if (spec && spec->priority == priority) {
3701 if (count == size) {
3702 count = -EMSGSIZE;
3703 break;
3704 }
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003705 buf[count++] = (efx_ef10_filter_pri(table, spec) *
Ben Hutchings8127d662013-08-29 19:19:29 +01003706 HUNT_FILTER_TBL_ROWS +
3707 filter_idx);
3708 }
3709 }
3710 spin_unlock_bh(&efx->filter_lock);
3711 return count;
3712}
3713
3714#ifdef CONFIG_RFS_ACCEL
3715
3716static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3717
3718static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3719 struct efx_filter_spec *spec)
3720{
3721 struct efx_ef10_filter_table *table = efx->filter_state;
3722 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3723 struct efx_filter_spec *saved_spec;
3724 unsigned int hash, i, depth = 1;
3725 bool replacing = false;
3726 int ins_index = -1;
3727 u64 cookie;
3728 s32 rc;
3729
3730 /* Must be an RX filter without RSS and not for a multicast
3731 * destination address (RFS only works for connected sockets).
3732 * These restrictions allow us to pass only a tiny amount of
3733 * data through to the completion function.
3734 */
3735 EFX_WARN_ON_PARANOID(spec->flags !=
3736 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3737 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3738 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3739
3740 hash = efx_ef10_filter_hash(spec);
3741
3742 spin_lock_bh(&efx->filter_lock);
3743
3744 /* Find any existing filter with the same match tuple or else
3745 * a free slot to insert at. If an existing filter is busy,
3746 * we have to give up.
3747 */
3748 for (;;) {
3749 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3750 saved_spec = efx_ef10_filter_entry_spec(table, i);
3751
3752 if (!saved_spec) {
3753 if (ins_index < 0)
3754 ins_index = i;
3755 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3756 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3757 rc = -EBUSY;
3758 goto fail_unlock;
3759 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003760 if (spec->priority < saved_spec->priority) {
3761 rc = -EPERM;
3762 goto fail_unlock;
3763 }
3764 ins_index = i;
3765 break;
3766 }
3767
3768 /* Once we reach the maximum search depth, use the
3769 * first suitable slot or return -EBUSY if there was
3770 * none
3771 */
3772 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3773 if (ins_index < 0) {
3774 rc = -EBUSY;
3775 goto fail_unlock;
3776 }
3777 break;
3778 }
3779
3780 ++depth;
3781 }
3782
3783 /* Create a software table entry if necessary, and mark it
3784 * busy. We might yet fail to insert, but any attempt to
3785 * insert a conflicting filter while we're waiting for the
3786 * firmware must find the busy entry.
3787 */
3788 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3789 if (saved_spec) {
3790 replacing = true;
3791 } else {
3792 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3793 if (!saved_spec) {
3794 rc = -ENOMEM;
3795 goto fail_unlock;
3796 }
3797 *saved_spec = *spec;
3798 }
3799 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3800 EFX_EF10_FILTER_FLAG_BUSY);
3801
3802 spin_unlock_bh(&efx->filter_lock);
3803
3804 /* Pack up the variables needed on completion */
3805 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3806
3807 efx_ef10_filter_push_prep(efx, spec, inbuf,
3808 table->entry[ins_index].handle, replacing);
3809 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3810 MC_CMD_FILTER_OP_OUT_LEN,
3811 efx_ef10_filter_rfs_insert_complete, cookie);
3812
3813 return ins_index;
3814
3815fail_unlock:
3816 spin_unlock_bh(&efx->filter_lock);
3817 return rc;
3818}
3819
3820static void
3821efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3822 int rc, efx_dword_t *outbuf,
3823 size_t outlen_actual)
3824{
3825 struct efx_ef10_filter_table *table = efx->filter_state;
3826 unsigned int ins_index, dmaq_id;
3827 struct efx_filter_spec *spec;
3828 bool replacing;
3829
3830 /* Unpack the cookie */
3831 replacing = cookie >> 31;
3832 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3833 dmaq_id = cookie & 0xffff;
3834
3835 spin_lock_bh(&efx->filter_lock);
3836 spec = efx_ef10_filter_entry_spec(table, ins_index);
3837 if (rc == 0) {
3838 table->entry[ins_index].handle =
3839 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3840 if (replacing)
3841 spec->dmaq_id = dmaq_id;
3842 } else if (!replacing) {
3843 kfree(spec);
3844 spec = NULL;
3845 }
3846 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3847 spin_unlock_bh(&efx->filter_lock);
3848
3849 wake_up_all(&table->waitq);
3850}
3851
3852static void
3853efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3854 unsigned long filter_idx,
3855 int rc, efx_dword_t *outbuf,
3856 size_t outlen_actual);
3857
3858static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3859 unsigned int filter_idx)
3860{
3861 struct efx_ef10_filter_table *table = efx->filter_state;
3862 struct efx_filter_spec *spec =
3863 efx_ef10_filter_entry_spec(table, filter_idx);
3864 MCDI_DECLARE_BUF(inbuf,
3865 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3866 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3867
3868 if (!spec ||
3869 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3870 spec->priority != EFX_FILTER_PRI_HINT ||
3871 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3872 flow_id, filter_idx))
3873 return false;
3874
3875 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3876 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3877 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3878 table->entry[filter_idx].handle);
3879 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3880 efx_ef10_filter_rfs_expire_complete, filter_idx))
3881 return false;
3882
3883 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3884 return true;
3885}
3886
3887static void
3888efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3889 unsigned long filter_idx,
3890 int rc, efx_dword_t *outbuf,
3891 size_t outlen_actual)
3892{
3893 struct efx_ef10_filter_table *table = efx->filter_state;
3894 struct efx_filter_spec *spec =
3895 efx_ef10_filter_entry_spec(table, filter_idx);
3896
3897 spin_lock_bh(&efx->filter_lock);
3898 if (rc == 0) {
3899 kfree(spec);
3900 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3901 }
3902 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3903 wake_up_all(&table->waitq);
3904 spin_unlock_bh(&efx->filter_lock);
3905}
3906
3907#endif /* CONFIG_RFS_ACCEL */
3908
3909static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3910{
3911 int match_flags = 0;
3912
3913#define MAP_FLAG(gen_flag, mcdi_field) { \
3914 u32 old_mcdi_flags = mcdi_flags; \
3915 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3916 mcdi_field ## _LBN); \
3917 if (mcdi_flags != old_mcdi_flags) \
3918 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3919 }
3920 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3921 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3922 MAP_FLAG(REM_HOST, SRC_IP);
3923 MAP_FLAG(LOC_HOST, DST_IP);
3924 MAP_FLAG(REM_MAC, SRC_MAC);
3925 MAP_FLAG(REM_PORT, SRC_PORT);
3926 MAP_FLAG(LOC_MAC, DST_MAC);
3927 MAP_FLAG(LOC_PORT, DST_PORT);
3928 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3929 MAP_FLAG(INNER_VID, INNER_VLAN);
3930 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3931 MAP_FLAG(IP_PROTO, IP_PROTO);
3932#undef MAP_FLAG
3933
3934 /* Did we map them all? */
3935 if (mcdi_flags)
3936 return -EINVAL;
3937
3938 return match_flags;
3939}
3940
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01003941static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
3942{
3943 struct efx_ef10_filter_table *table = efx->filter_state;
3944 struct efx_ef10_filter_vlan *vlan, *next_vlan;
3945
3946 /* See comment in efx_ef10_filter_table_remove() */
3947 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
3948 return;
3949
3950 if (!table)
3951 return;
3952
3953 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
3954 efx_ef10_filter_del_vlan_internal(efx, vlan);
3955}
3956
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01003957static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
3958 enum efx_filter_match_flags match_flags)
3959{
3960 unsigned int match_pri;
3961 int mf;
3962
3963 for (match_pri = 0;
3964 match_pri < table->rx_match_count;
3965 match_pri++) {
3966 mf = efx_ef10_filter_match_flags_from_mcdi(
3967 table->rx_match_mcdi_flags[match_pri]);
3968 if (mf == match_flags)
3969 return true;
3970 }
3971
3972 return false;
3973}
3974
Ben Hutchings8127d662013-08-29 19:19:29 +01003975static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3976{
3977 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3978 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01003979 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003980 unsigned int pd_match_pri, pd_match_count;
3981 struct efx_ef10_filter_table *table;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01003982 struct efx_ef10_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01003983 size_t outlen;
3984 int rc;
3985
Edward Creedd987082016-06-15 17:43:43 +01003986 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
3987 return -EINVAL;
3988
3989 if (efx->filter_state) /* already probed */
3990 return 0;
3991
Ben Hutchings8127d662013-08-29 19:19:29 +01003992 table = kzalloc(sizeof(*table), GFP_KERNEL);
3993 if (!table)
3994 return -ENOMEM;
3995
3996 /* Find out which RX filter types are supported, and their priorities */
3997 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3998 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3999 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4000 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4001 &outlen);
4002 if (rc)
4003 goto fail;
4004 pd_match_count = MCDI_VAR_ARRAY_LEN(
4005 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4006 table->rx_match_count = 0;
4007
4008 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4009 u32 mcdi_flags =
4010 MCDI_ARRAY_DWORD(
4011 outbuf,
4012 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4013 pd_match_pri);
4014 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4015 if (rc < 0) {
4016 netif_dbg(efx, probe, efx->net_dev,
4017 "%s: fw flags %#x pri %u not supported in driver\n",
4018 __func__, mcdi_flags, pd_match_pri);
4019 } else {
4020 netif_dbg(efx, probe, efx->net_dev,
4021 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4022 __func__, mcdi_flags, pd_match_pri,
4023 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004024 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4025 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004026 }
4027 }
4028
4029 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4030 if (!table->entry) {
4031 rc = -ENOMEM;
4032 goto fail;
4033 }
4034
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01004035 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004036 table->vlan_filter =
4037 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004038 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01004039
Ben Hutchings8127d662013-08-29 19:19:29 +01004040 efx->filter_state = table;
4041 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004042
4043 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4044 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4045 if (rc)
4046 goto fail_add_vlan;
4047 }
4048
Ben Hutchings8127d662013-08-29 19:19:29 +01004049 return 0;
4050
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004051fail_add_vlan:
4052 efx_ef10_filter_cleanup_vlans(efx);
4053 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01004054fail:
4055 kfree(table);
4056 return rc;
4057}
4058
Edward Cree0d322412015-05-20 11:10:03 +01004059/* Caller must hold efx->filter_sem for read if race against
4060 * efx_ef10_filter_table_remove() is possible
4061 */
Ben Hutchings8127d662013-08-29 19:19:29 +01004062static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4063{
4064 struct efx_ef10_filter_table *table = efx->filter_state;
4065 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4066 struct efx_filter_spec *spec;
4067 unsigned int filter_idx;
4068 bool failed = false;
4069 int rc;
4070
Edward Cree0d322412015-05-20 11:10:03 +01004071 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4072
Ben Hutchings8127d662013-08-29 19:19:29 +01004073 if (!nic_data->must_restore_filters)
4074 return;
4075
Edward Cree0d322412015-05-20 11:10:03 +01004076 if (!table)
4077 return;
4078
Ben Hutchings8127d662013-08-29 19:19:29 +01004079 spin_lock_bh(&efx->filter_lock);
4080
4081 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4082 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4083 if (!spec)
4084 continue;
4085
4086 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4087 spin_unlock_bh(&efx->filter_lock);
4088
4089 rc = efx_ef10_filter_push(efx, spec,
4090 &table->entry[filter_idx].handle,
4091 false);
4092 if (rc)
4093 failed = true;
4094
4095 spin_lock_bh(&efx->filter_lock);
4096 if (rc) {
4097 kfree(spec);
4098 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4099 } else {
4100 table->entry[filter_idx].spec &=
4101 ~EFX_EF10_FILTER_FLAG_BUSY;
4102 }
4103 }
4104
4105 spin_unlock_bh(&efx->filter_lock);
4106
4107 if (failed)
4108 netif_err(efx, hw, efx->net_dev,
4109 "unable to restore all filters\n");
4110 else
4111 nic_data->must_restore_filters = false;
4112}
4113
4114static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4115{
4116 struct efx_ef10_filter_table *table = efx->filter_state;
4117 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4118 struct efx_filter_spec *spec;
4119 unsigned int filter_idx;
4120 int rc;
4121
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004122 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01004123 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01004124 /* If we were called without locking, then it's not safe to free
4125 * the table as others might be using it. So we just WARN, leak
4126 * the memory, and potentially get an inconsistent filter table
4127 * state.
4128 * This should never actually happen.
4129 */
4130 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4131 return;
4132
Edward Cree0d322412015-05-20 11:10:03 +01004133 if (!table)
4134 return;
4135
Ben Hutchings8127d662013-08-29 19:19:29 +01004136 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4137 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4138 if (!spec)
4139 continue;
4140
4141 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4142 efx_ef10_filter_is_exclusive(spec) ?
4143 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4144 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4145 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4146 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00004147 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4148 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00004149 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00004150 netif_info(efx, drv, efx->net_dev,
4151 "%s: filter %04x remove failed\n",
4152 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01004153 kfree(spec);
4154 }
4155
4156 vfree(table->entry);
4157 kfree(table);
4158}
4159
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004160static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4161{
4162 struct efx_ef10_filter_table *table = efx->filter_state;
4163 unsigned int filter_idx;
4164
4165 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4166 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4167 if (!table->entry[filter_idx].spec)
4168 netif_dbg(efx, drv, efx->net_dev,
4169 "marked null spec old %04x:%04x\n", *id,
4170 filter_idx);
4171 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4172 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004173 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004174}
4175
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004176/* Mark old per-VLAN filters that may need to be removed */
4177static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4178 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01004179{
4180 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004181 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01004182
Edward Cree12fb0da2015-07-21 15:11:00 +01004183 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004184 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01004185 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004186 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4187 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4188 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4189 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004190}
4191
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004192/* Mark old filters that may need to be removed.
4193 * Caller must hold efx->filter_sem for read if race against
4194 * efx_ef10_filter_table_remove() is possible
4195 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004196static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4197{
4198 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004199 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004200
4201 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004202 list_for_each_entry(vlan, &table->vlan_list, list)
4203 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01004204 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004205}
Ben Hutchings8127d662013-08-29 19:19:29 +01004206
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004207static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004208{
4209 struct efx_ef10_filter_table *table = efx->filter_state;
4210 struct net_device *net_dev = efx->net_dev;
4211 struct netdev_hw_addr *uc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004212 int addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004213 unsigned int i;
4214
Edward Cree12fb0da2015-07-21 15:11:00 +01004215 addr_count = netdev_uc_count(net_dev);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004216 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Edward Cree12fb0da2015-07-21 15:11:00 +01004217 table->dev_uc_count = 1 + addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004218 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4219 i = 1;
4220 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004221 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004222 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004223 break;
4224 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004225 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4226 i++;
4227 }
4228}
4229
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004230static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004231{
4232 struct efx_ef10_filter_table *table = efx->filter_state;
4233 struct net_device *net_dev = efx->net_dev;
4234 struct netdev_hw_addr *mc;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004235 unsigned int i, addr_count;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004236
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004237 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004238
Edward Cree12fb0da2015-07-21 15:11:00 +01004239 addr_count = netdev_mc_count(net_dev);
4240 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004241 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004242 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004243 table->mc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01004244 break;
4245 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004246 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4247 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004248 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004249
4250 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004251}
Ben Hutchings8127d662013-08-29 19:19:29 +01004252
Edward Cree12fb0da2015-07-21 15:11:00 +01004253static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004254 struct efx_ef10_filter_vlan *vlan,
4255 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004256{
4257 struct efx_ef10_filter_table *table = efx->filter_state;
4258 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004259 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004260 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01004261 u8 baddr[ETH_ALEN];
4262 unsigned int i, j;
4263 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004264 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004265 int rc;
4266
4267 if (multicast) {
4268 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004269 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004270 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004271 } else {
4272 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01004273 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004274 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004275 }
4276
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004277 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4278
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004279 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01004280 for (i = 0; i < addr_count; i++) {
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004281 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004282 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01004283 rc = efx_ef10_filter_insert(efx, &spec, true);
4284 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004285 if (rollback) {
4286 netif_info(efx, drv, efx->net_dev,
4287 "efx_ef10_filter_insert failed rc=%d\n",
4288 rc);
4289 /* Fall back to promiscuous */
4290 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004291 efx_ef10_filter_remove_unsafe(
4292 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004293 ids[j]);
4294 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004295 }
4296 return rc;
4297 } else {
4298 /* mark as not inserted, and carry on */
4299 rc = EFX_EF10_FILTER_ID_INVALID;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004300 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004301 }
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004302 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004303 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004304
Edward Cree12fb0da2015-07-21 15:11:00 +01004305 if (multicast && rollback) {
4306 /* Also need an Ethernet broadcast filter */
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004307 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004308 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004309 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004310 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004311 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004312 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01004313 "Broadcast filter insert failed rc=%d\n", rc);
4314 /* Fall back to promiscuous */
4315 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004316 efx_ef10_filter_remove_unsafe(
4317 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004318 ids[j]);
4319 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004320 }
4321 return rc;
4322 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004323 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004324 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004325 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004326 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004327 }
Edward Cree12fb0da2015-07-21 15:11:00 +01004328
4329 return 0;
4330}
4331
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004332static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4333 struct efx_ef10_filter_vlan *vlan,
4334 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01004335{
Edward Cree12fb0da2015-07-21 15:11:00 +01004336 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004337 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01004338 struct efx_filter_spec spec;
4339 u8 baddr[ETH_ALEN];
4340 int rc;
4341
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004342 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4343
4344 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004345
4346 if (multicast)
4347 efx_filter_set_mc_def(&spec);
4348 else
4349 efx_filter_set_uc_def(&spec);
4350
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004351 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4352 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4353
Edward Cree12fb0da2015-07-21 15:11:00 +01004354 rc = efx_ef10_filter_insert(efx, &spec, true);
4355 if (rc < 0) {
Bert Kenward09a04202015-12-23 08:58:15 +00004356 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4357 efx->net_dev,
4358 "%scast mismatch filter insert failed rc=%d\n",
4359 multicast ? "Multi" : "Uni", rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004360 } else if (multicast) {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004361 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4362 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004363 if (!nic_data->workaround_26807) {
4364 /* Also need an Ethernet broadcast filter */
4365 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004366 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01004367 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004368 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01004369 rc = efx_ef10_filter_insert(efx, &spec, true);
4370 if (rc < 0) {
4371 netif_warn(efx, drv, efx->net_dev,
4372 "Broadcast filter insert failed rc=%d\n",
4373 rc);
4374 if (rollback) {
4375 /* Roll back the mc_def filter */
4376 efx_ef10_filter_remove_unsafe(
4377 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004378 vlan->mcdef);
4379 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01004380 return rc;
4381 }
4382 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004383 EFX_WARN_ON_PARANOID(vlan->bcast !=
Andrew Rybchenko6a379582016-06-15 17:44:20 +01004384 EFX_EF10_FILTER_ID_INVALID);
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004385 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01004386 }
4387 }
4388 rc = 0;
4389 } else {
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01004390 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4391 vlan->ucdef = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01004392 rc = 0;
4393 }
4394 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004395}
4396
4397/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4398 * flag or removes these filters, we don't need to hold the filter_lock while
4399 * scanning for these filters.
4400 */
4401static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4402{
4403 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00004404 int remove_failed = 0;
4405 int remove_noent = 0;
4406 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004407 int i;
4408
Ben Hutchings8127d662013-08-29 19:19:29 +01004409 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4410 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004411 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00004412 rc = efx_ef10_filter_remove_internal(efx,
4413 1U << EFX_FILTER_PRI_AUTO, i, true);
4414 if (rc == -ENOENT)
4415 remove_noent++;
4416 else if (rc)
4417 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004418 }
4419 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00004420
4421 if (remove_failed)
4422 netif_info(efx, drv, efx->net_dev,
4423 "%s: failed to remove %d filters\n",
4424 __func__, remove_failed);
4425 if (remove_noent)
4426 netif_info(efx, drv, efx->net_dev,
4427 "%s: failed to remove %d non-existent filters\n",
4428 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01004429}
4430
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004431static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4432{
4433 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4434 u8 mac_old[ETH_ALEN];
4435 int rc, rc2;
4436
4437 /* Only reconfigure a PF-created vport */
4438 if (is_zero_ether_addr(nic_data->vport_mac))
4439 return 0;
4440
4441 efx_device_detach_sync(efx);
4442 efx_net_stop(efx->net_dev);
4443 down_write(&efx->filter_sem);
4444 efx_ef10_filter_table_remove(efx);
4445 up_write(&efx->filter_sem);
4446
4447 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4448 if (rc)
4449 goto restore_filters;
4450
4451 ether_addr_copy(mac_old, nic_data->vport_mac);
4452 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4453 nic_data->vport_mac);
4454 if (rc)
4455 goto restore_vadaptor;
4456
4457 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4458 efx->net_dev->dev_addr);
4459 if (!rc) {
4460 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4461 } else {
4462 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4463 if (rc2) {
4464 /* Failed to add original MAC, so clear vport_mac */
4465 eth_zero_addr(nic_data->vport_mac);
4466 goto reset_nic;
4467 }
4468 }
4469
4470restore_vadaptor:
4471 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4472 if (rc2)
4473 goto reset_nic;
4474restore_filters:
4475 down_write(&efx->filter_sem);
4476 rc2 = efx_ef10_filter_table_probe(efx);
4477 up_write(&efx->filter_sem);
4478 if (rc2)
4479 goto reset_nic;
4480
4481 rc2 = efx_net_open(efx->net_dev);
4482 if (rc2)
4483 goto reset_nic;
4484
4485 netif_device_attach(efx->net_dev);
4486
4487 return rc;
4488
4489reset_nic:
4490 netif_err(efx, drv, efx->net_dev,
4491 "Failed to restore when changing MAC address - scheduling reset\n");
4492 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4493
4494 return rc ? rc : rc2;
4495}
4496
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004497/* Caller must hold efx->filter_sem for read if race against
4498 * efx_ef10_filter_table_remove() is possible
4499 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004500static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4501 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004502{
4503 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004504 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004505
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004506 /* Do not install unspecified VID if VLAN filtering is enabled.
4507 * Do not install all specified VIDs if VLAN filtering is disabled.
4508 */
4509 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4510 return;
4511
Edward Cree12fb0da2015-07-21 15:11:00 +01004512 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004513 if (table->uc_promisc) {
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004514 efx_ef10_filter_insert_def(efx, vlan, false, false);
4515 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004516 } else {
4517 /* If any of the filters failed to insert, fall back to
4518 * promiscuous mode - add in the uc_def filter. But keep
4519 * our individual unicast filters.
4520 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004521 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4522 efx_ef10_filter_insert_def(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004523 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004524
Edward Cree12fb0da2015-07-21 15:11:00 +01004525 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004526 /* If changing promiscuous state with cascaded multicast filters, remove
4527 * old filters first, so that packets are dropped rather than duplicated
4528 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004529 if (nic_data->workaround_26807 &&
4530 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01004531 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004532 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004533 if (nic_data->workaround_26807) {
4534 /* If we failed to insert promiscuous filters, rollback
4535 * and fall back to individual multicast filters
4536 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004537 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004538 /* Changing promisc state, so remove old filters */
4539 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004540 efx_ef10_filter_insert_addr_list(efx, vlan,
4541 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004542 }
4543 } else {
4544 /* If we failed to insert promiscuous filters, don't
4545 * rollback. Regardless, also insert the mc_list
4546 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004547 efx_ef10_filter_insert_def(efx, vlan, true, false);
4548 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004549 }
4550 } else {
4551 /* If any filters failed to insert, rollback and fall back to
4552 * promiscuous mode - mc_def filter and maybe broadcast. If
4553 * that fails, roll back again and insert as many of our
4554 * individual multicast filters as we can.
4555 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004556 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01004557 /* Changing promisc state, so remove old filters */
4558 if (nic_data->workaround_26807)
4559 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01004560 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4561 efx_ef10_filter_insert_addr_list(efx, vlan,
4562 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01004563 }
4564 }
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004565}
4566
4567/* Caller must hold efx->filter_sem for read if race against
4568 * efx_ef10_filter_table_remove() is possible
4569 */
4570static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4571{
4572 struct efx_ef10_filter_table *table = efx->filter_state;
4573 struct net_device *net_dev = efx->net_dev;
4574 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004575 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004576
4577 if (!efx_dev_registered(efx))
4578 return;
4579
4580 if (!table)
4581 return;
4582
4583 efx_ef10_filter_mark_old(efx);
4584
4585 /* Copy/convert the address lists; add the primary station
4586 * address and broadcast address
4587 */
4588 netif_addr_lock_bh(net_dev);
4589 efx_ef10_filter_uc_addr_list(efx);
4590 efx_ef10_filter_mc_addr_list(efx);
4591 netif_addr_unlock_bh(net_dev);
4592
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01004593 /* If VLAN filtering changes, all old filters are finally removed.
4594 * Do it in advance to avoid conflicts for unicast untagged and
4595 * VLAN 0 tagged filters.
4596 */
4597 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4598 if (table->vlan_filter != vlan_filter) {
4599 table->vlan_filter = vlan_filter;
4600 efx_ef10_filter_remove_old(efx);
4601 }
4602
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004603 list_for_each_entry(vlan, &table->vlan_list, list)
4604 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004605
4606 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01004607 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01004608}
4609
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004610static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
4611{
4612 struct efx_ef10_filter_table *table = efx->filter_state;
4613 struct efx_ef10_filter_vlan *vlan;
4614
4615 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4616
4617 list_for_each_entry(vlan, &table->vlan_list, list) {
4618 if (vlan->vid == vid)
4619 return vlan;
4620 }
4621
4622 return NULL;
4623}
4624
4625static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
4626{
4627 struct efx_ef10_filter_table *table = efx->filter_state;
4628 struct efx_ef10_filter_vlan *vlan;
4629 unsigned int i;
4630
4631 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4632 return -EINVAL;
4633
4634 vlan = efx_ef10_filter_find_vlan(efx, vid);
4635 if (WARN_ON(vlan)) {
4636 netif_err(efx, drv, efx->net_dev,
4637 "VLAN %u already added\n", vid);
4638 return -EALREADY;
4639 }
4640
4641 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
4642 if (!vlan)
4643 return -ENOMEM;
4644
4645 vlan->vid = vid;
4646
4647 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
4648 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
4649 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
4650 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
4651 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
4652 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
4653 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
4654
4655 list_add_tail(&vlan->list, &table->vlan_list);
4656
4657 if (efx_dev_registered(efx))
4658 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
4659
4660 return 0;
4661}
4662
4663static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
4664 struct efx_ef10_filter_vlan *vlan)
4665{
4666 unsigned int i;
4667
4668 /* See comment in efx_ef10_filter_table_remove() */
4669 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4670 return;
4671
4672 list_del(&vlan->list);
4673
Edward Cree8c915622016-06-15 17:49:05 +01004674 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004675 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01004676 vlan->uc[i]);
4677 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004678 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01004679 vlan->mc[i]);
4680 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
4681 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
4682 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004683
4684 kfree(vlan);
4685}
4686
4687static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
4688{
4689 struct efx_ef10_filter_vlan *vlan;
4690
4691 /* See comment in efx_ef10_filter_table_remove() */
4692 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4693 return;
4694
4695 vlan = efx_ef10_filter_find_vlan(efx, vid);
4696 if (!vlan) {
4697 netif_err(efx, drv, efx->net_dev,
4698 "VLAN %u not found in filter state\n", vid);
4699 return;
4700 }
4701
4702 efx_ef10_filter_del_vlan_internal(efx, vlan);
4703}
4704
Shradha Shah910c8782015-05-20 11:12:48 +01004705static int efx_ef10_set_mac_address(struct efx_nic *efx)
4706{
4707 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
4708 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4709 bool was_enabled = efx->port_enabled;
4710 int rc;
4711
4712 efx_device_detach_sync(efx);
4713 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01004714
4715 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01004716 down_write(&efx->filter_sem);
4717 efx_ef10_filter_table_remove(efx);
4718
4719 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
4720 efx->net_dev->dev_addr);
4721 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
4722 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01004723 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
4724 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01004725
4726 efx_ef10_filter_table_probe(efx);
4727 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01004728 mutex_unlock(&efx->mac_lock);
4729
Shradha Shah910c8782015-05-20 11:12:48 +01004730 if (was_enabled)
4731 efx_net_open(efx->net_dev);
4732 netif_device_attach(efx->net_dev);
4733
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004734#ifdef CONFIG_SFC_SRIOV
4735 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01004736 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
4737
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004738 if (rc == -EPERM) {
4739 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01004740
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004741 /* Switch to PF and change MAC address on vport */
4742 efx_pf = pci_get_drvdata(pci_dev_pf);
4743
4744 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004745 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004746 efx->net_dev->dev_addr);
4747 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01004748 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
4749 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
4750 unsigned int i;
4751
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004752 /* MAC address successfully changed by VF (with MAC
4753 * spoofing) so update the parent PF if possible.
4754 */
Shradha Shah910c8782015-05-20 11:12:48 +01004755 for (i = 0; i < efx_pf->vf_count; ++i) {
4756 struct ef10_vf *vf = nic_data->vf + i;
4757
4758 if (vf->efx == efx) {
4759 ether_addr_copy(vf->mac,
4760 efx->net_dev->dev_addr);
4761 return 0;
4762 }
4763 }
4764 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004765 } else
Shradha Shah910c8782015-05-20 11:12:48 +01004766#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004767 if (rc == -EPERM) {
4768 netif_err(efx, drv, efx->net_dev,
4769 "Cannot change MAC address; use sfboot to enable"
4770 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004771 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
4772 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
4773 * fall-back to the method of changing the MAC address on the
4774 * vport. This only applies to PFs because such versions of
4775 * MCFW do not support VFs.
4776 */
4777 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01004778 } else {
4779 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
4780 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004781 }
4782
Shradha Shah910c8782015-05-20 11:12:48 +01004783 return rc;
4784}
4785
Ben Hutchings8127d662013-08-29 19:19:29 +01004786static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
4787{
4788 efx_ef10_filter_sync_rx_mode(efx);
4789
4790 return efx_mcdi_set_mac(efx);
4791}
4792
Shradha Shah862f8942015-05-20 11:08:56 +01004793static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
4794{
4795 efx_ef10_filter_sync_rx_mode(efx);
4796
4797 return 0;
4798}
4799
Jon Cooper74cd60a2013-09-16 14:18:51 +01004800static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
4801{
4802 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
4803
4804 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
4805 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
4806 NULL, 0, NULL);
4807}
4808
4809/* MC BISTs follow a different poll mechanism to phy BISTs.
4810 * The BIST is done in the poll handler on the MC, and the MCDI command
4811 * will block until the BIST is done.
4812 */
4813static int efx_ef10_poll_bist(struct efx_nic *efx)
4814{
4815 int rc;
4816 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
4817 size_t outlen;
4818 u32 result;
4819
4820 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
4821 outbuf, sizeof(outbuf), &outlen);
4822 if (rc != 0)
4823 return rc;
4824
4825 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
4826 return -EIO;
4827
4828 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
4829 switch (result) {
4830 case MC_CMD_POLL_BIST_PASSED:
4831 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
4832 return 0;
4833 case MC_CMD_POLL_BIST_TIMEOUT:
4834 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
4835 return -EIO;
4836 case MC_CMD_POLL_BIST_FAILED:
4837 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
4838 return -EIO;
4839 default:
4840 netif_err(efx, hw, efx->net_dev,
4841 "BIST returned unknown result %u", result);
4842 return -EIO;
4843 }
4844}
4845
4846static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
4847{
4848 int rc;
4849
4850 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
4851
4852 rc = efx_ef10_start_bist(efx, bist_type);
4853 if (rc != 0)
4854 return rc;
4855
4856 return efx_ef10_poll_bist(efx);
4857}
4858
4859static int
4860efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
4861{
4862 int rc, rc2;
4863
4864 efx_reset_down(efx, RESET_TYPE_WORLD);
4865
4866 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
4867 NULL, 0, NULL, 0, NULL);
4868 if (rc != 0)
4869 goto out;
4870
4871 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
4872 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
4873
4874 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
4875
4876out:
Daniel Pieczko27324822015-07-31 11:14:54 +01004877 if (rc == -EPERM)
4878 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01004879 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
4880 return rc ? rc : rc2;
4881}
4882
Ben Hutchings8127d662013-08-29 19:19:29 +01004883#ifdef CONFIG_SFC_MTD
4884
4885struct efx_ef10_nvram_type_info {
4886 u16 type, type_mask;
4887 u8 port;
4888 const char *name;
4889};
4890
4891static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
4892 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
4893 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
4894 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
4895 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
4896 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
4897 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
4898 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
4899 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
4900 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01004901 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01004902 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
4903};
4904
4905static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
4906 struct efx_mcdi_mtd_partition *part,
4907 unsigned int type)
4908{
4909 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
4910 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
4911 const struct efx_ef10_nvram_type_info *info;
4912 size_t size, erase_size, outlen;
4913 bool protected;
4914 int rc;
4915
4916 for (info = efx_ef10_nvram_types; ; info++) {
4917 if (info ==
4918 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
4919 return -ENODEV;
4920 if ((type & ~info->type_mask) == info->type)
4921 break;
4922 }
4923 if (info->port != efx_port_num(efx))
4924 return -ENODEV;
4925
4926 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
4927 if (rc)
4928 return rc;
4929 if (protected)
4930 return -ENODEV; /* hide it */
4931
4932 part->nvram_type = type;
4933
4934 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
4935 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
4936 outbuf, sizeof(outbuf), &outlen);
4937 if (rc)
4938 return rc;
4939 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
4940 return -EIO;
4941 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
4942 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
4943 part->fw_subtype = MCDI_DWORD(outbuf,
4944 NVRAM_METADATA_OUT_SUBTYPE);
4945
4946 part->common.dev_type_name = "EF10 NVRAM manager";
4947 part->common.type_name = info->name;
4948
4949 part->common.mtd.type = MTD_NORFLASH;
4950 part->common.mtd.flags = MTD_CAP_NORFLASH;
4951 part->common.mtd.size = size;
4952 part->common.mtd.erasesize = erase_size;
4953
4954 return 0;
4955}
4956
4957static int efx_ef10_mtd_probe(struct efx_nic *efx)
4958{
4959 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
4960 struct efx_mcdi_mtd_partition *parts;
4961 size_t outlen, n_parts_total, i, n_parts;
4962 unsigned int type;
4963 int rc;
4964
4965 ASSERT_RTNL();
4966
4967 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
4968 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
4969 outbuf, sizeof(outbuf), &outlen);
4970 if (rc)
4971 return rc;
4972 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
4973 return -EIO;
4974
4975 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
4976 if (n_parts_total >
4977 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
4978 return -EIO;
4979
4980 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
4981 if (!parts)
4982 return -ENOMEM;
4983
4984 n_parts = 0;
4985 for (i = 0; i < n_parts_total; i++) {
4986 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
4987 i);
4988 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
4989 if (rc == 0)
4990 n_parts++;
4991 else if (rc != -ENODEV)
4992 goto fail;
4993 }
4994
4995 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
4996fail:
4997 if (rc)
4998 kfree(parts);
4999 return rc;
5000}
5001
5002#endif /* CONFIG_SFC_MTD */
5003
5004static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5005{
5006 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5007}
5008
Shradha Shah02246a72015-05-06 00:58:14 +01005009static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5010 u32 host_time) {}
5011
Jon Cooperbd9a2652013-11-18 12:54:41 +00005012static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5013 bool temp)
5014{
5015 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5016 int rc;
5017
5018 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5019 channel->sync_events_state == SYNC_EVENTS_VALID ||
5020 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5021 return 0;
5022 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5023
5024 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5025 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5026 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5027 channel->channel);
5028
5029 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5030 inbuf, sizeof(inbuf), NULL, 0, NULL);
5031
5032 if (rc != 0)
5033 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5034 SYNC_EVENTS_DISABLED;
5035
5036 return rc;
5037}
5038
5039static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5040 bool temp)
5041{
5042 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5043 int rc;
5044
5045 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5046 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5047 return 0;
5048 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5049 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5050 return 0;
5051 }
5052 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5053 SYNC_EVENTS_DISABLED;
5054
5055 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5056 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5057 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5058 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5059 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5060 channel->channel);
5061
5062 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5063 inbuf, sizeof(inbuf), NULL, 0, NULL);
5064
5065 return rc;
5066}
5067
5068static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5069 bool temp)
5070{
5071 int (*set)(struct efx_channel *channel, bool temp);
5072 struct efx_channel *channel;
5073
5074 set = en ?
5075 efx_ef10_rx_enable_timestamping :
5076 efx_ef10_rx_disable_timestamping;
5077
5078 efx_for_each_channel(channel, efx) {
5079 int rc = set(channel, temp);
5080 if (en && rc != 0) {
5081 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5082 return rc;
5083 }
5084 }
5085
5086 return 0;
5087}
5088
Shradha Shah02246a72015-05-06 00:58:14 +01005089static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5090 struct hwtstamp_config *init)
5091{
5092 return -EOPNOTSUPP;
5093}
5094
Jon Cooperbd9a2652013-11-18 12:54:41 +00005095static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5096 struct hwtstamp_config *init)
5097{
5098 int rc;
5099
5100 switch (init->rx_filter) {
5101 case HWTSTAMP_FILTER_NONE:
5102 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5103 /* if TX timestamping is still requested then leave PTP on */
5104 return efx_ptp_change_mode(efx,
5105 init->tx_type != HWTSTAMP_TX_OFF, 0);
5106 case HWTSTAMP_FILTER_ALL:
5107 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5108 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5109 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5110 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5111 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5112 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5113 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5114 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5115 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5116 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5117 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5118 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5119 init->rx_filter = HWTSTAMP_FILTER_ALL;
5120 rc = efx_ptp_change_mode(efx, true, 0);
5121 if (!rc)
5122 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5123 if (rc)
5124 efx_ptp_change_mode(efx, false, 0);
5125 return rc;
5126 default:
5127 return -ERANGE;
5128 }
5129}
5130
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005131static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5132{
5133 if (proto != htons(ETH_P_8021Q))
5134 return -EINVAL;
5135
5136 return efx_ef10_add_vlan(efx, vid);
5137}
5138
5139static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5140{
5141 if (proto != htons(ETH_P_8021Q))
5142 return -EINVAL;
5143
5144 return efx_ef10_del_vlan(efx, vid);
5145}
5146
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005147#define EF10_OFFLOAD_FEATURES \
5148 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005149 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005150 NETIF_F_IPV6_CSUM | \
5151 NETIF_F_RXHASH | \
5152 NETIF_F_NTUPLE)
5153
Shradha Shah02246a72015-05-06 00:58:14 +01005154const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005155 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01005156 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01005157 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01005158 .probe = efx_ef10_probe_vf,
5159 .remove = efx_ef10_remove,
5160 .dimension_resources = efx_ef10_dimension_resources,
5161 .init = efx_ef10_init_nic,
5162 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005163 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01005164 .map_reset_flags = efx_ef10_map_reset_flags,
5165 .reset = efx_ef10_reset,
5166 .probe_port = efx_mcdi_port_probe,
5167 .remove_port = efx_mcdi_port_remove,
5168 .fini_dmaq = efx_ef10_fini_dmaq,
5169 .prepare_flr = efx_ef10_prepare_flr,
5170 .finish_flr = efx_port_dummy_op_void,
5171 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005172 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005173 .start_stats = efx_port_dummy_op_void,
5174 .pull_stats = efx_port_dummy_op_void,
5175 .stop_stats = efx_port_dummy_op_void,
5176 .set_id_led = efx_mcdi_set_id_led,
5177 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01005178 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01005179 .check_mac_fault = efx_mcdi_mac_check_fault,
5180 .reconfigure_port = efx_mcdi_port_reconfigure,
5181 .get_wol = efx_ef10_get_wol_vf,
5182 .set_wol = efx_ef10_set_wol_vf,
5183 .resume_wol = efx_port_dummy_op_void,
5184 .mcdi_request = efx_ef10_mcdi_request,
5185 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5186 .mcdi_read_response = efx_ef10_mcdi_read_response,
5187 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005188 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01005189 .irq_enable_master = efx_port_dummy_op_void,
5190 .irq_test_generate = efx_ef10_irq_test_generate,
5191 .irq_disable_non_ev = efx_port_dummy_op_void,
5192 .irq_handle_msi = efx_ef10_msi_interrupt,
5193 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5194 .tx_probe = efx_ef10_tx_probe,
5195 .tx_init = efx_ef10_tx_init,
5196 .tx_remove = efx_ef10_tx_remove,
5197 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01005198 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01005199 .rx_probe = efx_ef10_rx_probe,
5200 .rx_init = efx_ef10_rx_init,
5201 .rx_remove = efx_ef10_rx_remove,
5202 .rx_write = efx_ef10_rx_write,
5203 .rx_defer_refill = efx_ef10_rx_defer_refill,
5204 .ev_probe = efx_ef10_ev_probe,
5205 .ev_init = efx_ef10_ev_init,
5206 .ev_fini = efx_ef10_ev_fini,
5207 .ev_remove = efx_ef10_ev_remove,
5208 .ev_process = efx_ef10_ev_process,
5209 .ev_read_ack = efx_ef10_ev_read_ack,
5210 .ev_test_generate = efx_ef10_ev_test_generate,
5211 .filter_table_probe = efx_ef10_filter_table_probe,
5212 .filter_table_restore = efx_ef10_filter_table_restore,
5213 .filter_table_remove = efx_ef10_filter_table_remove,
5214 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5215 .filter_insert = efx_ef10_filter_insert,
5216 .filter_remove_safe = efx_ef10_filter_remove_safe,
5217 .filter_get_safe = efx_ef10_filter_get_safe,
5218 .filter_clear_rx = efx_ef10_filter_clear_rx,
5219 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5220 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5221 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5222#ifdef CONFIG_RFS_ACCEL
5223 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5224 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5225#endif
5226#ifdef CONFIG_SFC_MTD
5227 .mtd_probe = efx_port_dummy_op_int,
5228#endif
5229 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5230 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005231 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5232 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01005233#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005234 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5235 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5236 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01005237 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01005238#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005239 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01005240 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005241
Shradha Shah02246a72015-05-06 00:58:14 +01005242 .revision = EFX_REV_HUNT_A0,
5243 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5244 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5245 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5246 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5247 .can_rx_scatter = true,
5248 .always_rx_scatter = true,
5249 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5250 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005251 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01005252 .mcdi_max_ver = 2,
5253 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5254 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5255 1 << HWTSTAMP_FILTER_ALL,
5256};
5257
5258const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01005259 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01005260 .mem_bar = EFX_MEM_BAR,
5261 .mem_map_size = efx_ef10_mem_map_size,
5262 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005263 .remove = efx_ef10_remove,
5264 .dimension_resources = efx_ef10_dimension_resources,
5265 .init = efx_ef10_init_nic,
5266 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01005267 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01005268 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00005269 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01005270 .probe_port = efx_mcdi_port_probe,
5271 .remove_port = efx_mcdi_port_remove,
5272 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01005273 .prepare_flr = efx_ef10_prepare_flr,
5274 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01005275 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01005276 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01005277 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01005278 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01005279 .stop_stats = efx_mcdi_mac_stop_stats,
5280 .set_id_led = efx_mcdi_set_id_led,
5281 .push_irq_moderation = efx_ef10_push_irq_moderation,
5282 .reconfigure_mac = efx_ef10_mac_reconfigure,
5283 .check_mac_fault = efx_mcdi_mac_check_fault,
5284 .reconfigure_port = efx_mcdi_port_reconfigure,
5285 .get_wol = efx_ef10_get_wol,
5286 .set_wol = efx_ef10_set_wol,
5287 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01005288 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01005289 .test_nvram = efx_mcdi_nvram_test_all,
5290 .mcdi_request = efx_ef10_mcdi_request,
5291 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5292 .mcdi_read_response = efx_ef10_mcdi_read_response,
5293 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01005294 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01005295 .irq_enable_master = efx_port_dummy_op_void,
5296 .irq_test_generate = efx_ef10_irq_test_generate,
5297 .irq_disable_non_ev = efx_port_dummy_op_void,
5298 .irq_handle_msi = efx_ef10_msi_interrupt,
5299 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5300 .tx_probe = efx_ef10_tx_probe,
5301 .tx_init = efx_ef10_tx_init,
5302 .tx_remove = efx_ef10_tx_remove,
5303 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01005304 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01005305 .rx_probe = efx_ef10_rx_probe,
5306 .rx_init = efx_ef10_rx_init,
5307 .rx_remove = efx_ef10_rx_remove,
5308 .rx_write = efx_ef10_rx_write,
5309 .rx_defer_refill = efx_ef10_rx_defer_refill,
5310 .ev_probe = efx_ef10_ev_probe,
5311 .ev_init = efx_ef10_ev_init,
5312 .ev_fini = efx_ef10_ev_fini,
5313 .ev_remove = efx_ef10_ev_remove,
5314 .ev_process = efx_ef10_ev_process,
5315 .ev_read_ack = efx_ef10_ev_read_ack,
5316 .ev_test_generate = efx_ef10_ev_test_generate,
5317 .filter_table_probe = efx_ef10_filter_table_probe,
5318 .filter_table_restore = efx_ef10_filter_table_restore,
5319 .filter_table_remove = efx_ef10_filter_table_remove,
5320 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5321 .filter_insert = efx_ef10_filter_insert,
5322 .filter_remove_safe = efx_ef10_filter_remove_safe,
5323 .filter_get_safe = efx_ef10_filter_get_safe,
5324 .filter_clear_rx = efx_ef10_filter_clear_rx,
5325 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5326 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5327 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5328#ifdef CONFIG_RFS_ACCEL
5329 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5330 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5331#endif
5332#ifdef CONFIG_SFC_MTD
5333 .mtd_probe = efx_ef10_mtd_probe,
5334 .mtd_rename = efx_mcdi_mtd_rename,
5335 .mtd_read = efx_mcdi_mtd_read,
5336 .mtd_erase = efx_mcdi_mtd_erase,
5337 .mtd_write = efx_mcdi_mtd_write,
5338 .mtd_sync = efx_mcdi_mtd_sync,
5339#endif
5340 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005341 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5342 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005343 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5344 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005345#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01005346 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005347 .sriov_init = efx_ef10_sriov_init,
5348 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00005349 .sriov_wanted = efx_ef10_sriov_wanted,
5350 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005351 .sriov_flr = efx_ef10_sriov_flr,
5352 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5353 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5354 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5355 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01005356 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01005357 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5358 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5359 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01005360#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01005361 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005362 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01005363
5364 .revision = EFX_REV_HUNT_A0,
5365 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5366 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5367 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005368 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01005369 .can_rx_scatter = true,
5370 .always_rx_scatter = true,
5371 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5372 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01005373 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01005374 .mcdi_max_ver = 2,
5375 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00005376 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5377 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01005378};