blob: 784b46fb039a32733386ee2825684f6b14fa4d16 [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
52struct efx_ef10_filter_table {
53/* The RX match field masks supported by this fw & hw, in order of priority */
54 enum efx_filter_match_flags rx_match_flags[
55 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
56 unsigned int rx_match_count;
57
58 struct {
59 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000060/* BUSY flag indicates that an update is in progress. AUTO_OLD is
61 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +010062 */
63#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000064#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +010065#define EFX_EF10_FILTER_FLAGS 3UL
66 u64 handle; /* firmware handle */
67 } *entry;
68 wait_queue_head_t waitq;
69/* Shadow of net_device address lists, guarded by mac_lock */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000070#define EFX_EF10_FILTER_DEV_UC_MAX 32
71#define EFX_EF10_FILTER_DEV_MC_MAX 256
Ben Hutchings8127d662013-08-29 19:19:29 +010072 struct {
73 u8 addr[ETH_ALEN];
74 u16 id;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000075 } dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX],
76 dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
77 int dev_uc_count; /* negative for PROMISC */
78 int dev_mc_count; /* negative for PROMISC/ALLMULTI */
Ben Hutchings8127d662013-08-29 19:19:29 +010079};
80
81/* An arbitrary search limit for the software hash table */
82#define EFX_EF10_FILTER_SEARCH_LIMIT 200
83
Ben Hutchings8127d662013-08-29 19:19:29 +010084static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
85static void efx_ef10_filter_table_remove(struct efx_nic *efx);
86
87static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
88{
89 efx_dword_t reg;
90
91 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
92 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
93 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
94}
95
96static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
97{
Shradha Shah02246a72015-05-06 00:58:14 +010098 int bar;
99
100 bar = efx->type->mem_bar;
101 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100102}
103
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100104static bool efx_ef10_is_vf(struct efx_nic *efx)
105{
106 return efx->type->is_vf;
107}
108
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100109static int efx_ef10_get_pf_index(struct efx_nic *efx)
110{
111 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
112 struct efx_ef10_nic_data *nic_data = efx->nic_data;
113 size_t outlen;
114 int rc;
115
116 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
117 sizeof(outbuf), &outlen);
118 if (rc)
119 return rc;
120 if (outlen < sizeof(outbuf))
121 return -EIO;
122
123 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
124 return 0;
125}
126
Shradha Shah88a37de2015-05-20 11:09:15 +0100127#ifdef CONFIG_SFC_SRIOV
128static int efx_ef10_get_vf_index(struct efx_nic *efx)
129{
130 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
131 struct efx_ef10_nic_data *nic_data = efx->nic_data;
132 size_t outlen;
133 int rc;
134
135 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
136 sizeof(outbuf), &outlen);
137 if (rc)
138 return rc;
139 if (outlen < sizeof(outbuf))
140 return -EIO;
141
142 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
143 return 0;
144}
145#endif
146
Ben Hutchingse5a25382013-09-05 22:50:59 +0100147static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100148{
149 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN);
150 struct efx_ef10_nic_data *nic_data = efx->nic_data;
151 size_t outlen;
152 int rc;
153
154 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
155
156 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
157 outbuf, sizeof(outbuf), &outlen);
158 if (rc)
159 return rc;
Ben Hutchingse5a25382013-09-05 22:50:59 +0100160 if (outlen < sizeof(outbuf)) {
161 netif_err(efx, drv, efx->net_dev,
162 "unable to read datapath firmware capabilities\n");
163 return -EIO;
164 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100165
Ben Hutchingse5a25382013-09-05 22:50:59 +0100166 nic_data->datapath_caps =
167 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
168
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100169 /* record the DPCPU firmware IDs to determine VEB vswitching support.
170 */
171 nic_data->rx_dpcpu_fw_id =
172 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
173 nic_data->tx_dpcpu_fw_id =
174 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
175
Ben Hutchingse5a25382013-09-05 22:50:59 +0100176 if (!(nic_data->datapath_caps &
177 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) {
178 netif_err(efx, drv, efx->net_dev,
179 "current firmware does not support TSO\n");
180 return -ENODEV;
181 }
182
183 if (!(nic_data->datapath_caps &
184 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
185 netif_err(efx, probe, efx->net_dev,
186 "current firmware does not support an RX prefix\n");
187 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100188 }
189
190 return 0;
191}
192
193static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
194{
195 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
196 int rc;
197
198 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
199 outbuf, sizeof(outbuf), NULL);
200 if (rc)
201 return rc;
202 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
203 return rc > 0 ? rc : -ERANGE;
204}
205
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100206static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100207{
208 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
209 size_t outlen;
210 int rc;
211
212 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
213
214 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
215 outbuf, sizeof(outbuf), &outlen);
216 if (rc)
217 return rc;
218 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
219 return -EIO;
220
Edward Creecd84ff42014-03-07 18:27:41 +0000221 ether_addr_copy(mac_address,
222 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100223 return 0;
224}
225
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100226static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
227{
228 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
229 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
230 size_t outlen;
231 int num_addrs, rc;
232
233 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
234 EVB_PORT_ID_ASSIGNED);
235 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
236 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
237
238 if (rc)
239 return rc;
240 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
241 return -EIO;
242
243 num_addrs = MCDI_DWORD(outbuf,
244 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
245
246 WARN_ON(num_addrs != 1);
247
248 ether_addr_copy(mac_address,
249 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
250
251 return 0;
252}
253
Shradha Shah0f5c0842015-06-02 11:37:58 +0100254static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
255 struct device_attribute *attr,
256 char *buf)
257{
258 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
259
260 return sprintf(buf, "%d\n",
261 ((efx->mcdi->fn_flags) &
262 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
263 ? 1 : 0);
264}
265
266static ssize_t efx_ef10_show_primary_flag(struct device *dev,
267 struct device_attribute *attr,
268 char *buf)
269{
270 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
271
272 return sprintf(buf, "%d\n",
273 ((efx->mcdi->fn_flags) &
274 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
275 ? 1 : 0);
276}
277
278static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
279 NULL);
280static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
281
Ben Hutchings8127d662013-08-29 19:19:29 +0100282static int efx_ef10_probe(struct efx_nic *efx)
283{
284 struct efx_ef10_nic_data *nic_data;
Shradha Shah8be41322015-06-02 11:37:25 +0100285 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100286 int i, rc;
287
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000288 /* We can have one VI for each 8K region. However, until we
289 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100290 */
291 efx->max_channels =
292 min_t(unsigned int,
293 EFX_MAX_CHANNELS,
Shradha Shah02246a72015-05-06 00:58:14 +0100294 efx_ef10_mem_map_size(efx) /
Ben Hutchings8127d662013-08-29 19:19:29 +0100295 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000296 if (WARN_ON(efx->max_channels == 0))
297 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100298
299 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
300 if (!nic_data)
301 return -ENOMEM;
302 efx->nic_data = nic_data;
303
Edward Cree75aba2a2015-05-27 13:13:54 +0100304 /* we assume later that we can copy from this buffer in dwords */
305 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
306
Ben Hutchings8127d662013-08-29 19:19:29 +0100307 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
308 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
309 if (rc)
310 goto fail1;
311
312 /* Get the MC's warm boot count. In case it's rebooting right
313 * now, be prepared to retry.
314 */
315 i = 0;
316 for (;;) {
317 rc = efx_ef10_get_warm_boot_count(efx);
318 if (rc >= 0)
319 break;
320 if (++i == 5)
321 goto fail2;
322 ssleep(1);
323 }
324 nic_data->warm_boot_count = rc;
325
326 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
327
Daniel Pieczko45b24492015-05-06 00:57:14 +0100328 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
329
Ben Hutchings8127d662013-08-29 19:19:29 +0100330 /* In case we're recovering from a crash (kexec), we want to
331 * cancel any outstanding request by the previous user of this
332 * function. We send a special message using the least
333 * significant bits of the 'high' (doorbell) register.
334 */
335 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
336
337 rc = efx_mcdi_init(efx);
338 if (rc)
339 goto fail2;
340
341 /* Reset (most) configuration for this function */
342 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
343 if (rc)
344 goto fail3;
345
346 /* Enable event logging */
347 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
348 if (rc)
349 goto fail3;
350
Shradha Shah0f5c0842015-06-02 11:37:58 +0100351 rc = device_create_file(&efx->pci_dev->dev,
352 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100353 if (rc)
354 goto fail3;
355
Shradha Shah0f5c0842015-06-02 11:37:58 +0100356 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
357 if (rc)
358 goto fail4;
359
360 rc = efx_ef10_get_pf_index(efx);
361 if (rc)
362 goto fail5;
363
Ben Hutchingse5a25382013-09-05 22:50:59 +0100364 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100365 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100366 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100367
368 efx->rx_packet_len_offset =
369 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
370
Ben Hutchings8127d662013-08-29 19:19:29 +0100371 rc = efx_mcdi_port_get_number(efx);
372 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100373 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100374 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100375 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100376
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100377 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100378 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100379 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100380
381 rc = efx_ef10_get_sysclk_freq(efx);
382 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100383 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100384 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
385
Edward Cree267d9d72015-05-06 00:59:18 +0100386 /* Check whether firmware supports bug 35388 workaround.
387 * First try to enable it, then if we get EPERM, just
388 * ask if it's already enabled
389 */
Daniel Pieczko34ccfe62015-07-21 15:09:43 +0100390 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true, NULL);
Shradha Shahc9012e02015-06-02 11:37:41 +0100391 if (rc == 0) {
Ben Hutchings8127d662013-08-29 19:19:29 +0100392 nic_data->workaround_35388 = true;
Shradha Shahc9012e02015-06-02 11:37:41 +0100393 } else if (rc == -EPERM) {
Edward Cree267d9d72015-05-06 00:59:18 +0100394 unsigned int enabled;
395
396 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
397 if (rc)
398 goto fail3;
399 nic_data->workaround_35388 = enabled &
400 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
Shradha Shahc9012e02015-06-02 11:37:41 +0100401 } else if (rc != -ENOSYS && rc != -ENOENT) {
Shradha Shah0f5c0842015-06-02 11:37:58 +0100402 goto fail5;
Shradha Shahc9012e02015-06-02 11:37:41 +0100403 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100404 netif_dbg(efx, probe, efx->net_dev,
405 "workaround for bug 35388 is %sabled\n",
406 nic_data->workaround_35388 ? "en" : "dis");
407
408 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100409 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100410 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100411
Ben Hutchings9aecda92013-12-05 21:28:42 +0000412 efx_ptp_probe(efx, NULL);
413
Shradha Shah1d051e02015-06-02 11:38:16 +0100414#ifdef CONFIG_SFC_SRIOV
415 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
416 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
417 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
418
419 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
420 } else
421#endif
422 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
423
Ben Hutchings8127d662013-08-29 19:19:29 +0100424 return 0;
425
Shradha Shah0f5c0842015-06-02 11:37:58 +0100426fail5:
427 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
428fail4:
429 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100430fail3:
431 efx_mcdi_fini(efx);
432fail2:
433 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
434fail1:
435 kfree(nic_data);
436 efx->nic_data = NULL;
437 return rc;
438}
439
440static int efx_ef10_free_vis(struct efx_nic *efx)
441{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100442 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100443 size_t outlen;
444 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
445 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100446
447 /* -EALREADY means nothing to free, so ignore */
448 if (rc == -EALREADY)
449 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100450 if (rc)
451 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
452 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100453 return rc;
454}
455
Ben Hutchings183233b2013-06-28 21:47:12 +0100456#ifdef EFX_USE_PIO
457
458static void efx_ef10_free_piobufs(struct efx_nic *efx)
459{
460 struct efx_ef10_nic_data *nic_data = efx->nic_data;
461 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
462 unsigned int i;
463 int rc;
464
465 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
466
467 for (i = 0; i < nic_data->n_piobufs; i++) {
468 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
469 nic_data->piobuf_handle[i]);
470 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
471 NULL, 0, NULL);
472 WARN_ON(rc);
473 }
474
475 nic_data->n_piobufs = 0;
476}
477
478static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
479{
480 struct efx_ef10_nic_data *nic_data = efx->nic_data;
481 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
482 unsigned int i;
483 size_t outlen;
484 int rc = 0;
485
486 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
487
488 for (i = 0; i < n; i++) {
489 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
490 outbuf, sizeof(outbuf), &outlen);
491 if (rc)
492 break;
493 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
494 rc = -EIO;
495 break;
496 }
497 nic_data->piobuf_handle[i] =
498 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
499 netif_dbg(efx, probe, efx->net_dev,
500 "allocated PIO buffer %u handle %x\n", i,
501 nic_data->piobuf_handle[i]);
502 }
503
504 nic_data->n_piobufs = i;
505 if (rc)
506 efx_ef10_free_piobufs(efx);
507 return rc;
508}
509
510static int efx_ef10_link_piobufs(struct efx_nic *efx)
511{
512 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100513 _MCDI_DECLARE_BUF(inbuf,
514 max(MC_CMD_LINK_PIOBUF_IN_LEN,
515 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100516 struct efx_channel *channel;
517 struct efx_tx_queue *tx_queue;
518 unsigned int offset, index;
519 int rc;
520
521 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
522 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
523
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100524 memset(inbuf, 0, sizeof(inbuf));
525
Ben Hutchings183233b2013-06-28 21:47:12 +0100526 /* Link a buffer to each VI in the write-combining mapping */
527 for (index = 0; index < nic_data->n_piobufs; ++index) {
528 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
529 nic_data->piobuf_handle[index]);
530 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
531 nic_data->pio_write_vi_base + index);
532 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
533 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
534 NULL, 0, NULL);
535 if (rc) {
536 netif_err(efx, drv, efx->net_dev,
537 "failed to link VI %u to PIO buffer %u (%d)\n",
538 nic_data->pio_write_vi_base + index, index,
539 rc);
540 goto fail;
541 }
542 netif_dbg(efx, probe, efx->net_dev,
543 "linked VI %u to PIO buffer %u\n",
544 nic_data->pio_write_vi_base + index, index);
545 }
546
547 /* Link a buffer to each TX queue */
548 efx_for_each_channel(channel, efx) {
549 efx_for_each_channel_tx_queue(tx_queue, channel) {
550 /* We assign the PIO buffers to queues in
551 * reverse order to allow for the following
552 * special case.
553 */
554 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
555 tx_queue->channel->channel - 1) *
556 efx_piobuf_size);
557 index = offset / ER_DZ_TX_PIOBUF_SIZE;
558 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
559
560 /* When the host page size is 4K, the first
561 * host page in the WC mapping may be within
562 * the same VI page as the last TX queue. We
563 * can only link one buffer to each VI.
564 */
565 if (tx_queue->queue == nic_data->pio_write_vi_base) {
566 BUG_ON(index != 0);
567 rc = 0;
568 } else {
569 MCDI_SET_DWORD(inbuf,
570 LINK_PIOBUF_IN_PIOBUF_HANDLE,
571 nic_data->piobuf_handle[index]);
572 MCDI_SET_DWORD(inbuf,
573 LINK_PIOBUF_IN_TXQ_INSTANCE,
574 tx_queue->queue);
575 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
576 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
577 NULL, 0, NULL);
578 }
579
580 if (rc) {
581 /* This is non-fatal; the TX path just
582 * won't use PIO for this queue
583 */
584 netif_err(efx, drv, efx->net_dev,
585 "failed to link VI %u to PIO buffer %u (%d)\n",
586 tx_queue->queue, index, rc);
587 tx_queue->piobuf = NULL;
588 } else {
589 tx_queue->piobuf =
590 nic_data->pio_write_base +
591 index * EFX_VI_PAGE_SIZE + offset;
592 tx_queue->piobuf_offset = offset;
593 netif_dbg(efx, probe, efx->net_dev,
594 "linked VI %u to PIO buffer %u offset %x addr %p\n",
595 tx_queue->queue, index,
596 tx_queue->piobuf_offset,
597 tx_queue->piobuf);
598 }
599 }
600 }
601
602 return 0;
603
604fail:
605 while (index--) {
606 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
607 nic_data->pio_write_vi_base + index);
608 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
609 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
610 NULL, 0, NULL);
611 }
612 return rc;
613}
614
615#else /* !EFX_USE_PIO */
616
617static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
618{
619 return n == 0 ? 0 : -ENOBUFS;
620}
621
622static int efx_ef10_link_piobufs(struct efx_nic *efx)
623{
624 return 0;
625}
626
627static void efx_ef10_free_piobufs(struct efx_nic *efx)
628{
629}
630
631#endif /* EFX_USE_PIO */
632
Ben Hutchings8127d662013-08-29 19:19:29 +0100633static void efx_ef10_remove(struct efx_nic *efx)
634{
635 struct efx_ef10_nic_data *nic_data = efx->nic_data;
636 int rc;
637
Shradha Shahf1122a32015-05-20 11:09:46 +0100638#ifdef CONFIG_SFC_SRIOV
639 struct efx_ef10_nic_data *nic_data_pf;
640 struct pci_dev *pci_dev_pf;
641 struct efx_nic *efx_pf;
642 struct ef10_vf *vf;
643
644 if (efx->pci_dev->is_virtfn) {
645 pci_dev_pf = efx->pci_dev->physfn;
646 if (pci_dev_pf) {
647 efx_pf = pci_get_drvdata(pci_dev_pf);
648 nic_data_pf = efx_pf->nic_data;
649 vf = nic_data_pf->vf + nic_data->vf_index;
650 vf->efx = NULL;
651 } else
652 netif_info(efx, drv, efx->net_dev,
653 "Could not get the PF id from VF\n");
654 }
655#endif
656
Ben Hutchings9aecda92013-12-05 21:28:42 +0000657 efx_ptp_remove(efx);
658
Ben Hutchings8127d662013-08-29 19:19:29 +0100659 efx_mcdi_mon_remove(efx);
660
Ben Hutchings8127d662013-08-29 19:19:29 +0100661 efx_ef10_rx_free_indir_table(efx);
662
Ben Hutchings183233b2013-06-28 21:47:12 +0100663 if (nic_data->wc_membase)
664 iounmap(nic_data->wc_membase);
665
Ben Hutchings8127d662013-08-29 19:19:29 +0100666 rc = efx_ef10_free_vis(efx);
667 WARN_ON(rc != 0);
668
Ben Hutchings183233b2013-06-28 21:47:12 +0100669 if (!nic_data->must_restore_piobufs)
670 efx_ef10_free_piobufs(efx);
671
Shradha Shah0f5c0842015-06-02 11:37:58 +0100672 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
673 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
674
Ben Hutchings8127d662013-08-29 19:19:29 +0100675 efx_mcdi_fini(efx);
676 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
677 kfree(nic_data);
678}
679
Shradha Shah88a37de2015-05-20 11:09:15 +0100680static int efx_ef10_probe_pf(struct efx_nic *efx)
681{
682 return efx_ef10_probe(efx);
683}
684
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100685int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
686{
687 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
688
689 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
690 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
691 NULL, 0, NULL);
692}
693
694int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
695{
696 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
697
698 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
699 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
700 NULL, 0, NULL);
701}
702
703int efx_ef10_vport_add_mac(struct efx_nic *efx,
704 unsigned int port_id, u8 *mac)
705{
706 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
707
708 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
709 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
710
711 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
712 sizeof(inbuf), NULL, 0, NULL);
713}
714
715int efx_ef10_vport_del_mac(struct efx_nic *efx,
716 unsigned int port_id, u8 *mac)
717{
718 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
719
720 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
721 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
722
723 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
724 sizeof(inbuf), NULL, 0, NULL);
725}
726
Shradha Shah88a37de2015-05-20 11:09:15 +0100727#ifdef CONFIG_SFC_SRIOV
728static int efx_ef10_probe_vf(struct efx_nic *efx)
729{
730 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +0100731 struct pci_dev *pci_dev_pf;
732
733 /* If the parent PF has no VF data structure, it doesn't know about this
734 * VF so fail probe. The VF needs to be re-created. This can happen
735 * if the PF driver is unloaded while the VF is assigned to a guest.
736 */
737 pci_dev_pf = efx->pci_dev->physfn;
738 if (pci_dev_pf) {
739 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
740 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
741
742 if (!nic_data_pf->vf) {
743 netif_info(efx, drv, efx->net_dev,
744 "The VF cannot link to its parent PF; "
745 "please destroy and re-create the VF\n");
746 return -EBUSY;
747 }
748 }
Shradha Shah88a37de2015-05-20 11:09:15 +0100749
750 rc = efx_ef10_probe(efx);
751 if (rc)
752 return rc;
753
754 rc = efx_ef10_get_vf_index(efx);
755 if (rc)
756 goto fail;
757
Shradha Shahf1122a32015-05-20 11:09:46 +0100758 if (efx->pci_dev->is_virtfn) {
759 if (efx->pci_dev->physfn) {
760 struct efx_nic *efx_pf =
761 pci_get_drvdata(efx->pci_dev->physfn);
762 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
763 struct efx_ef10_nic_data *nic_data = efx->nic_data;
764
765 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +0100766 nic_data_p->vf[nic_data->vf_index].pci_dev =
767 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +0100768 } else
769 netif_info(efx, drv, efx->net_dev,
770 "Could not get the PF id from VF\n");
771 }
772
Shradha Shah88a37de2015-05-20 11:09:15 +0100773 return 0;
774
775fail:
776 efx_ef10_remove(efx);
777 return rc;
778}
779#else
780static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
781{
782 return 0;
783}
784#endif
785
Ben Hutchings8127d662013-08-29 19:19:29 +0100786static int efx_ef10_alloc_vis(struct efx_nic *efx,
787 unsigned int min_vis, unsigned int max_vis)
788{
789 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
790 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
791 struct efx_ef10_nic_data *nic_data = efx->nic_data;
792 size_t outlen;
793 int rc;
794
795 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
796 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
797 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
798 outbuf, sizeof(outbuf), &outlen);
799 if (rc != 0)
800 return rc;
801
802 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
803 return -EIO;
804
805 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
806 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
807
808 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
809 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
810 return 0;
811}
812
Ben Hutchings183233b2013-06-28 21:47:12 +0100813/* Note that the failure path of this function does not free
814 * resources, as this will be done by efx_ef10_remove().
815 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100816static int efx_ef10_dimension_resources(struct efx_nic *efx)
817{
Ben Hutchings183233b2013-06-28 21:47:12 +0100818 struct efx_ef10_nic_data *nic_data = efx->nic_data;
819 unsigned int uc_mem_map_size, wc_mem_map_size;
820 unsigned int min_vis, pio_write_vi_base, max_vis;
821 void __iomem *membase;
822 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100823
Ben Hutchings183233b2013-06-28 21:47:12 +0100824 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
825
826#ifdef EFX_USE_PIO
827 /* Try to allocate PIO buffers if wanted and if the full
828 * number of PIO buffers would be sufficient to allocate one
829 * copy-buffer per TX channel. Failure is non-fatal, as there
830 * are only a small number of PIO buffers shared between all
831 * functions of the controller.
832 */
833 if (efx_piobuf_size != 0 &&
834 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
835 efx->n_tx_channels) {
836 unsigned int n_piobufs =
837 DIV_ROUND_UP(efx->n_tx_channels,
838 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
839
840 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
841 if (rc)
842 netif_err(efx, probe, efx->net_dev,
843 "failed to allocate PIO buffers (%d)\n", rc);
844 else
845 netif_dbg(efx, probe, efx->net_dev,
846 "allocated %u PIO buffers\n", n_piobufs);
847 }
848#else
849 nic_data->n_piobufs = 0;
850#endif
851
852 /* PIO buffers should be mapped with write-combining enabled,
853 * and we want to make single UC and WC mappings rather than
854 * several of each (in fact that's the only option if host
855 * page size is >4K). So we may allocate some extra VIs just
856 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100857 *
858 * The UC mapping contains (min_vis - 1) complete VIs and the
859 * first half of the next VI. Then the WC mapping begins with
860 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100861 */
862 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
863 ER_DZ_TX_PIOBUF);
864 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100865 /* pio_write_vi_base rounds down to give the number of complete
866 * VIs inside the UC mapping.
867 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100868 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
869 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
870 nic_data->n_piobufs) *
871 EFX_VI_PAGE_SIZE) -
872 uc_mem_map_size);
873 max_vis = pio_write_vi_base + nic_data->n_piobufs;
874 } else {
875 pio_write_vi_base = 0;
876 wc_mem_map_size = 0;
877 max_vis = min_vis;
878 }
879
880 /* In case the last attached driver failed to free VIs, do it now */
881 rc = efx_ef10_free_vis(efx);
882 if (rc != 0)
883 return rc;
884
885 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
886 if (rc != 0)
887 return rc;
888
889 /* If we didn't get enough VIs to map all the PIO buffers, free the
890 * PIO buffers
891 */
892 if (nic_data->n_piobufs &&
893 nic_data->n_allocated_vis <
894 pio_write_vi_base + nic_data->n_piobufs) {
895 netif_dbg(efx, probe, efx->net_dev,
896 "%u VIs are not sufficient to map %u PIO buffers\n",
897 nic_data->n_allocated_vis, nic_data->n_piobufs);
898 efx_ef10_free_piobufs(efx);
899 }
900
901 /* Shrink the original UC mapping of the memory BAR */
902 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
903 if (!membase) {
904 netif_err(efx, probe, efx->net_dev,
905 "could not shrink memory BAR to %x\n",
906 uc_mem_map_size);
907 return -ENOMEM;
908 }
909 iounmap(efx->membase);
910 efx->membase = membase;
911
912 /* Set up the WC mapping if needed */
913 if (wc_mem_map_size) {
914 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
915 uc_mem_map_size,
916 wc_mem_map_size);
917 if (!nic_data->wc_membase) {
918 netif_err(efx, probe, efx->net_dev,
919 "could not allocate WC mapping of size %x\n",
920 wc_mem_map_size);
921 return -ENOMEM;
922 }
923 nic_data->pio_write_vi_base = pio_write_vi_base;
924 nic_data->pio_write_base =
925 nic_data->wc_membase +
926 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
927 uc_mem_map_size);
928
929 rc = efx_ef10_link_piobufs(efx);
930 if (rc)
931 efx_ef10_free_piobufs(efx);
932 }
933
934 netif_dbg(efx, probe, efx->net_dev,
935 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
936 &efx->membase_phys, efx->membase, uc_mem_map_size,
937 nic_data->wc_membase, wc_mem_map_size);
938
939 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100940}
941
942static int efx_ef10_init_nic(struct efx_nic *efx)
943{
944 struct efx_ef10_nic_data *nic_data = efx->nic_data;
945 int rc;
946
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100947 if (nic_data->must_check_datapath_caps) {
948 rc = efx_ef10_init_datapath_caps(efx);
949 if (rc)
950 return rc;
951 nic_data->must_check_datapath_caps = false;
952 }
953
Ben Hutchings8127d662013-08-29 19:19:29 +0100954 if (nic_data->must_realloc_vis) {
955 /* We cannot let the number of VIs change now */
956 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
957 nic_data->n_allocated_vis);
958 if (rc)
959 return rc;
960 nic_data->must_realloc_vis = false;
961 }
962
Ben Hutchings183233b2013-06-28 21:47:12 +0100963 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
964 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
965 if (rc == 0) {
966 rc = efx_ef10_link_piobufs(efx);
967 if (rc)
968 efx_ef10_free_piobufs(efx);
969 }
970
971 /* Log an error on failure, but this is non-fatal */
972 if (rc)
973 netif_err(efx, drv, efx->net_dev,
974 "failed to restore PIO buffers (%d)\n", rc);
975 nic_data->must_restore_piobufs = false;
976 }
977
Jon Cooper267c0152015-05-06 00:59:38 +0100978 /* don't fail init if RSS setup doesn't work */
979 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
980
Ben Hutchings8127d662013-08-29 19:19:29 +0100981 return 0;
982}
983
Jon Cooper3e336262014-01-17 19:48:06 +0000984static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
985{
986 struct efx_ef10_nic_data *nic_data = efx->nic_data;
987
988 /* All our allocations have been reset */
989 nic_data->must_realloc_vis = true;
990 nic_data->must_restore_filters = true;
991 nic_data->must_restore_piobufs = true;
992 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
993}
994
Jon Cooper087e9022015-05-20 11:11:35 +0100995static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
996{
997 if (reason == RESET_TYPE_MC_FAILURE)
998 return RESET_TYPE_DATAPATH;
999
1000 return efx_mcdi_map_reset_reason(reason);
1001}
1002
Ben Hutchings8127d662013-08-29 19:19:29 +01001003static int efx_ef10_map_reset_flags(u32 *flags)
1004{
1005 enum {
1006 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1007 ETH_RESET_SHARED_SHIFT),
1008 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1009 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1010 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1011 ETH_RESET_SHARED_SHIFT)
1012 };
1013
1014 /* We assume for now that our PCI function is permitted to
1015 * reset everything.
1016 */
1017
1018 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1019 *flags &= ~EF10_RESET_MC;
1020 return RESET_TYPE_WORLD;
1021 }
1022
1023 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1024 *flags &= ~EF10_RESET_PORT;
1025 return RESET_TYPE_ALL;
1026 }
1027
1028 /* no invisible reset implemented */
1029
1030 return -EINVAL;
1031}
1032
Jon Cooper3e336262014-01-17 19:48:06 +00001033static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1034{
1035 int rc = efx_mcdi_reset(efx, reset_type);
1036
1037 /* If it was a port reset, trigger reallocation of MC resources.
1038 * Note that on an MC reset nothing needs to be done now because we'll
1039 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001040 * For an FLR, we never get an MC reset event, but the MC has reset all
1041 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001042 */
Edward Creee2835462014-04-16 19:27:48 +01001043 if ((reset_type == RESET_TYPE_ALL ||
1044 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001045 efx_ef10_reset_mc_allocations(efx);
1046 return rc;
1047}
1048
Ben Hutchings8127d662013-08-29 19:19:29 +01001049#define EF10_DMA_STAT(ext_name, mcdi_name) \
1050 [EF10_STAT_ ## ext_name] = \
1051 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1052#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1053 [EF10_STAT_ ## int_name] = \
1054 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1055#define EF10_OTHER_STAT(ext_name) \
1056 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001057#define GENERIC_SW_STAT(ext_name) \
1058 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001059
1060static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001061 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1062 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1063 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1064 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1065 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1066 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1067 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1068 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1069 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1070 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1071 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1072 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1073 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1074 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1075 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1076 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1077 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1078 EF10_OTHER_STAT(port_rx_good_bytes),
1079 EF10_OTHER_STAT(port_rx_bad_bytes),
1080 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1081 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1082 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1083 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1084 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1085 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1086 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1087 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1088 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1089 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1090 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1091 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1092 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1093 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1094 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1095 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1096 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1097 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1098 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1099 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1100 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1101 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001102 GENERIC_SW_STAT(rx_nodesc_trunc),
1103 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001104 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1105 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1106 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1107 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1108 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1109 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1110 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1111 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1112 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1113 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1114 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1115 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001116 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1117 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1118 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1119 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1120 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1121 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1122 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1123 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1124 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1125 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1126 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1127 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1128 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1129 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1130 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1131 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1132 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1133 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001134};
1135
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001136#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1137 (1ULL << EF10_STAT_port_tx_packets) | \
1138 (1ULL << EF10_STAT_port_tx_pause) | \
1139 (1ULL << EF10_STAT_port_tx_unicast) | \
1140 (1ULL << EF10_STAT_port_tx_multicast) | \
1141 (1ULL << EF10_STAT_port_tx_broadcast) | \
1142 (1ULL << EF10_STAT_port_rx_bytes) | \
1143 (1ULL << \
1144 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1145 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1146 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1147 (1ULL << EF10_STAT_port_rx_packets) | \
1148 (1ULL << EF10_STAT_port_rx_good) | \
1149 (1ULL << EF10_STAT_port_rx_bad) | \
1150 (1ULL << EF10_STAT_port_rx_pause) | \
1151 (1ULL << EF10_STAT_port_rx_control) | \
1152 (1ULL << EF10_STAT_port_rx_unicast) | \
1153 (1ULL << EF10_STAT_port_rx_multicast) | \
1154 (1ULL << EF10_STAT_port_rx_broadcast) | \
1155 (1ULL << EF10_STAT_port_rx_lt64) | \
1156 (1ULL << EF10_STAT_port_rx_64) | \
1157 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1158 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1159 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1160 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1161 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1162 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1163 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1164 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1165 (1ULL << EF10_STAT_port_rx_overflow) | \
1166 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001167 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1168 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001169
1170/* These statistics are only provided by the 10G MAC. For a 10G/40G
1171 * switchable port we do not expose these because they might not
1172 * include all the packets they should.
1173 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001174#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1175 (1ULL << EF10_STAT_port_tx_lt64) | \
1176 (1ULL << EF10_STAT_port_tx_64) | \
1177 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1178 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1179 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1180 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1181 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1182 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001183
1184/* These statistics are only provided by the 40G MAC. For a 10G/40G
1185 * switchable port we do expose these because the errors will otherwise
1186 * be silent.
1187 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001188#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1189 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001190
Edward Cree568d7a02013-09-25 17:32:09 +01001191/* These statistics are only provided if the firmware supports the
1192 * capability PM_AND_RXDP_COUNTERS.
1193 */
1194#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001195 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1196 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1197 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1198 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1199 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1200 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1201 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1202 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1203 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1204 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1205 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1206 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001207
Edward Cree4bae9132013-09-27 18:52:49 +01001208static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001209{
Edward Cree4bae9132013-09-27 18:52:49 +01001210 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001211 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001212 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001213
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001214 if (!(efx->mcdi->fn_flags &
1215 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1216 return 0;
1217
Ben Hutchings8127d662013-08-29 19:19:29 +01001218 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001219 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001220 else
Edward Cree4bae9132013-09-27 18:52:49 +01001221 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001222
1223 if (nic_data->datapath_caps &
1224 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1225 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1226
Edward Cree4bae9132013-09-27 18:52:49 +01001227 return raw_mask;
1228}
1229
1230static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1231{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001232 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001233 u64 raw_mask[2];
1234
1235 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1236
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001237 /* Only show vadaptor stats when EVB capability is present */
1238 if (nic_data->datapath_caps &
1239 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1240 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1241 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1242 } else {
1243 raw_mask[1] = 0;
1244 }
Edward Cree4bae9132013-09-27 18:52:49 +01001245
1246#if BITS_PER_LONG == 64
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001247 mask[0] = raw_mask[0];
1248 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001249#else
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001250 mask[0] = raw_mask[0] & 0xffffffff;
1251 mask[1] = raw_mask[0] >> 32;
1252 mask[2] = raw_mask[1] & 0xffffffff;
1253 mask[3] = raw_mask[1] >> 32;
Edward Cree4bae9132013-09-27 18:52:49 +01001254#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001255}
1256
1257static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1258{
Edward Cree4bae9132013-09-27 18:52:49 +01001259 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1260
1261 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001262 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001263 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001264}
1265
Daniel Pieczkod7788192015-06-02 11:39:20 +01001266static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1267 struct rtnl_link_stats64 *core_stats)
1268{
1269 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1270 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1271 u64 *stats = nic_data->stats;
1272 size_t stats_count = 0, index;
1273
1274 efx_ef10_get_stat_mask(efx, mask);
1275
1276 if (full_stats) {
1277 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1278 if (efx_ef10_stat_desc[index].name) {
1279 *full_stats++ = stats[index];
1280 ++stats_count;
1281 }
1282 }
1283 }
1284
1285 if (core_stats) {
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001286 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1287 stats[EF10_STAT_rx_multicast] +
1288 stats[EF10_STAT_rx_broadcast];
1289 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1290 stats[EF10_STAT_tx_multicast] +
1291 stats[EF10_STAT_tx_broadcast];
1292 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1293 stats[EF10_STAT_rx_multicast_bytes] +
1294 stats[EF10_STAT_rx_broadcast_bytes];
1295 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1296 stats[EF10_STAT_tx_multicast_bytes] +
1297 stats[EF10_STAT_tx_broadcast_bytes];
1298 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001299 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001300 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1301 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1302 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1303 core_stats->rx_errors = core_stats->rx_crc_errors;
1304 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Daniel Pieczkod7788192015-06-02 11:39:20 +01001305 }
1306
1307 return stats_count;
1308}
1309
1310static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001311{
1312 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001313 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001314 __le64 generation_start, generation_end;
1315 u64 *stats = nic_data->stats;
1316 __le64 *dma_stats;
1317
Edward Cree4bae9132013-09-27 18:52:49 +01001318 efx_ef10_get_stat_mask(efx, mask);
1319
Ben Hutchings8127d662013-08-29 19:19:29 +01001320 dma_stats = efx->stats_buffer.addr;
1321 nic_data = efx->nic_data;
1322
1323 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1324 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1325 return 0;
1326 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001327 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001328 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001329 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001330 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1331 if (generation_end != generation_start)
1332 return -EAGAIN;
1333
1334 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001335 efx_nic_fix_nodesc_drop_stat(efx,
1336 &stats[EF10_STAT_port_rx_nodesc_drops]);
1337 stats[EF10_STAT_port_rx_good_bytes] =
1338 stats[EF10_STAT_port_rx_bytes] -
1339 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1340 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1341 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001342 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001343 return 0;
1344}
1345
1346
Daniel Pieczkod7788192015-06-02 11:39:20 +01001347static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1348 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001349{
Ben Hutchings8127d662013-08-29 19:19:29 +01001350 int retry;
1351
1352 /* If we're unlucky enough to read statistics during the DMA, wait
1353 * up to 10ms for it to finish (typically takes <500us)
1354 */
1355 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001356 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001357 break;
1358 udelay(100);
1359 }
1360
Daniel Pieczkod7788192015-06-02 11:39:20 +01001361 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1362}
1363
1364static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1365{
1366 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1367 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1368 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1369 __le64 generation_start, generation_end;
1370 u64 *stats = nic_data->stats;
1371 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1372 struct efx_buffer stats_buf;
1373 __le64 *dma_stats;
1374 int rc;
1375
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001376 spin_unlock_bh(&efx->stats_lock);
1377
1378 if (in_interrupt()) {
1379 /* If in atomic context, cannot update stats. Just update the
1380 * software stats and return so the caller can continue.
1381 */
1382 spin_lock_bh(&efx->stats_lock);
1383 efx_update_sw_stats(efx, stats);
1384 return 0;
1385 }
1386
Daniel Pieczkod7788192015-06-02 11:39:20 +01001387 efx_ef10_get_stat_mask(efx, mask);
1388
1389 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001390 if (rc) {
1391 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001392 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001393 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001394
1395 dma_stats = stats_buf.addr;
1396 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1397
1398 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1399 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001400 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001401 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1402 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1403
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001404 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1405 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001406 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001407 if (rc) {
1408 /* Expect ENOENT if DMA queues have not been set up */
1409 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1410 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1411 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001412 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001413 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001414
1415 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001416 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1417 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001418 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001419 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001420 rmb();
1421 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1422 stats, stats_buf.addr, false);
1423 rmb();
1424 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1425 if (generation_end != generation_start) {
1426 rc = -EAGAIN;
1427 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001428 }
1429
Daniel Pieczkod7788192015-06-02 11:39:20 +01001430 efx_update_sw_stats(efx, stats);
1431out:
1432 efx_nic_free_buffer(efx, &stats_buf);
1433 return rc;
1434}
Ben Hutchings8127d662013-08-29 19:19:29 +01001435
Daniel Pieczkod7788192015-06-02 11:39:20 +01001436static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1437 struct rtnl_link_stats64 *core_stats)
1438{
1439 if (efx_ef10_try_update_nic_stats_vf(efx))
1440 return 0;
1441
1442 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001443}
1444
1445static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1446{
1447 struct efx_nic *efx = channel->efx;
1448 unsigned int mode, value;
1449 efx_dword_t timer_cmd;
1450
1451 if (channel->irq_moderation) {
1452 mode = 3;
1453 value = channel->irq_moderation - 1;
1454 } else {
1455 mode = 0;
1456 value = 0;
1457 }
1458
1459 if (EFX_EF10_WORKAROUND_35388(efx)) {
1460 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1461 EFE_DD_EVQ_IND_TIMER_FLAGS,
1462 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1463 ERF_DD_EVQ_IND_TIMER_VAL, value);
1464 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1465 channel->channel);
1466 } else {
1467 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1468 ERF_DZ_TC_TIMER_VAL, value);
1469 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1470 channel->channel);
1471 }
1472}
1473
Shradha Shah02246a72015-05-06 00:58:14 +01001474static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1475 struct ethtool_wolinfo *wol) {}
1476
1477static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1478{
1479 return -EOPNOTSUPP;
1480}
1481
Ben Hutchings8127d662013-08-29 19:19:29 +01001482static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1483{
1484 wol->supported = 0;
1485 wol->wolopts = 0;
1486 memset(&wol->sopass, 0, sizeof(wol->sopass));
1487}
1488
1489static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1490{
1491 if (type != 0)
1492 return -EINVAL;
1493 return 0;
1494}
1495
1496static void efx_ef10_mcdi_request(struct efx_nic *efx,
1497 const efx_dword_t *hdr, size_t hdr_len,
1498 const efx_dword_t *sdu, size_t sdu_len)
1499{
1500 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1501 u8 *pdu = nic_data->mcdi_buf.addr;
1502
1503 memcpy(pdu, hdr, hdr_len);
1504 memcpy(pdu + hdr_len, sdu, sdu_len);
1505 wmb();
1506
1507 /* The hardware provides 'low' and 'high' (doorbell) registers
1508 * for passing the 64-bit address of an MCDI request to
1509 * firmware. However the dwords are swapped by firmware. The
1510 * least significant bits of the doorbell are then 0 for all
1511 * MCDI requests due to alignment.
1512 */
1513 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1514 ER_DZ_MC_DB_LWRD);
1515 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1516 ER_DZ_MC_DB_HWRD);
1517}
1518
1519static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1520{
1521 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1522 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1523
1524 rmb();
1525 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1526}
1527
1528static void
1529efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1530 size_t offset, size_t outlen)
1531{
1532 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1533 const u8 *pdu = nic_data->mcdi_buf.addr;
1534
1535 memcpy(outbuf, pdu + offset, outlen);
1536}
1537
1538static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1539{
1540 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1541 int rc;
1542
1543 rc = efx_ef10_get_warm_boot_count(efx);
1544 if (rc < 0) {
1545 /* The firmware is presumably in the process of
1546 * rebooting. However, we are supposed to report each
1547 * reboot just once, so we must only do that once we
1548 * can read and store the updated warm boot count.
1549 */
1550 return 0;
1551 }
1552
1553 if (rc == nic_data->warm_boot_count)
1554 return 0;
1555
1556 nic_data->warm_boot_count = rc;
1557
1558 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001559 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001560
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001561 /* Driver-created vswitches and vports must be re-created */
1562 nic_data->must_probe_vswitching = true;
1563 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1564
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001565 /* The datapath firmware might have been changed */
1566 nic_data->must_check_datapath_caps = true;
1567
Ben Hutchings869070c2013-09-05 22:46:10 +01001568 /* MAC statistics have been cleared on the NIC; clear the local
1569 * statistic that we update with efx_update_diff_stat().
1570 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001571 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
Ben Hutchings869070c2013-09-05 22:46:10 +01001572
Ben Hutchings8127d662013-08-29 19:19:29 +01001573 return -EIO;
1574}
1575
1576/* Handle an MSI interrupt
1577 *
1578 * Handle an MSI hardware interrupt. This routine schedules event
1579 * queue processing. No interrupt acknowledgement cycle is necessary.
1580 * Also, we never need to check that the interrupt is for us, since
1581 * MSI interrupts cannot be shared.
1582 */
1583static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1584{
1585 struct efx_msi_context *context = dev_id;
1586 struct efx_nic *efx = context->efx;
1587
1588 netif_vdbg(efx, intr, efx->net_dev,
1589 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1590
1591 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1592 /* Note test interrupts */
1593 if (context->index == efx->irq_level)
1594 efx->last_irq_cpu = raw_smp_processor_id();
1595
1596 /* Schedule processing of the channel */
1597 efx_schedule_channel_irq(efx->channel[context->index]);
1598 }
1599
1600 return IRQ_HANDLED;
1601}
1602
1603static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1604{
1605 struct efx_nic *efx = dev_id;
1606 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1607 struct efx_channel *channel;
1608 efx_dword_t reg;
1609 u32 queues;
1610
1611 /* Read the ISR which also ACKs the interrupts */
1612 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1613 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1614
1615 if (queues == 0)
1616 return IRQ_NONE;
1617
1618 if (likely(soft_enabled)) {
1619 /* Note test interrupts */
1620 if (queues & (1U << efx->irq_level))
1621 efx->last_irq_cpu = raw_smp_processor_id();
1622
1623 efx_for_each_channel(channel, efx) {
1624 if (queues & 1)
1625 efx_schedule_channel_irq(channel);
1626 queues >>= 1;
1627 }
1628 }
1629
1630 netif_vdbg(efx, intr, efx->net_dev,
1631 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1632 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1633
1634 return IRQ_HANDLED;
1635}
1636
1637static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1638{
1639 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1640
1641 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1642
1643 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1644 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1645 inbuf, sizeof(inbuf), NULL, 0, NULL);
1646}
1647
1648static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1649{
1650 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1651 (tx_queue->ptr_mask + 1) *
1652 sizeof(efx_qword_t),
1653 GFP_KERNEL);
1654}
1655
1656/* This writes to the TX_DESC_WPTR and also pushes data */
1657static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1658 const efx_qword_t *txd)
1659{
1660 unsigned int write_ptr;
1661 efx_oword_t reg;
1662
1663 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1664 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1665 reg.qword[0] = *txd;
1666 efx_writeo_page(tx_queue->efx, &reg,
1667 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1668}
1669
1670static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1671{
1672 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1673 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001674 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1675 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1676 struct efx_channel *channel = tx_queue->channel;
1677 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001678 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001679 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001680 dma_addr_t dma_addr;
1681 efx_qword_t *txd;
1682 int rc;
1683 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001684 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001685
1686 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1687 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1688 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1689 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1690 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1691 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1692 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1693 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001694 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001695
1696 dma_addr = tx_queue->txd.buf.dma_addr;
1697
1698 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1699 tx_queue->queue, entries, (u64)dma_addr);
1700
1701 for (i = 0; i < entries; ++i) {
1702 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1703 dma_addr += EFX_BUF_SIZE;
1704 }
1705
1706 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1707
1708 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001709 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001710 if (rc)
1711 goto fail;
1712
1713 /* A previous user of this TX queue might have set us up the
1714 * bomb by writing a descriptor to the TX push collector but
1715 * not the doorbell. (Each collector belongs to a port, not a
1716 * queue or function, so cannot easily be reset.) We must
1717 * attempt to push a no-op descriptor in its place.
1718 */
1719 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1720 tx_queue->insert_count = 1;
1721 txd = efx_tx_desc(tx_queue, 0);
1722 EFX_POPULATE_QWORD_4(*txd,
1723 ESF_DZ_TX_DESC_IS_OPT, true,
1724 ESF_DZ_TX_OPTION_TYPE,
1725 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1726 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1727 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1728 tx_queue->write_count = 1;
1729 wmb();
1730 efx_ef10_push_tx_desc(tx_queue, txd);
1731
1732 return;
1733
1734fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001735 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1736 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001737}
1738
1739static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1740{
1741 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001742 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001743 struct efx_nic *efx = tx_queue->efx;
1744 size_t outlen;
1745 int rc;
1746
1747 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1748 tx_queue->queue);
1749
Edward Cree1e0b8122013-05-31 18:36:12 +01001750 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001751 outbuf, sizeof(outbuf), &outlen);
1752
1753 if (rc && rc != -EALREADY)
1754 goto fail;
1755
1756 return;
1757
1758fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001759 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1760 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001761}
1762
1763static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1764{
1765 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1766}
1767
1768/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1769static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1770{
1771 unsigned int write_ptr;
1772 efx_dword_t reg;
1773
1774 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1775 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1776 efx_writed_page(tx_queue->efx, &reg,
1777 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1778}
1779
1780static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1781{
1782 unsigned int old_write_count = tx_queue->write_count;
1783 struct efx_tx_buffer *buffer;
1784 unsigned int write_ptr;
1785 efx_qword_t *txd;
1786
1787 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1788
1789 do {
1790 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1791 buffer = &tx_queue->buffer[write_ptr];
1792 txd = efx_tx_desc(tx_queue, write_ptr);
1793 ++tx_queue->write_count;
1794
1795 /* Create TX descriptor ring entry */
1796 if (buffer->flags & EFX_TX_BUF_OPTION) {
1797 *txd = buffer->option;
1798 } else {
1799 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1800 EFX_POPULATE_QWORD_3(
1801 *txd,
1802 ESF_DZ_TX_KER_CONT,
1803 buffer->flags & EFX_TX_BUF_CONT,
1804 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1805 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1806 }
1807 } while (tx_queue->write_count != tx_queue->insert_count);
1808
1809 wmb(); /* Ensure descriptors are written before they are fetched */
1810
1811 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1812 txd = efx_tx_desc(tx_queue,
1813 old_write_count & tx_queue->ptr_mask);
1814 efx_ef10_push_tx_desc(tx_queue, txd);
1815 ++tx_queue->pushes;
1816 } else {
1817 efx_ef10_notify_tx_desc(tx_queue);
1818 }
1819}
1820
Jon Cooper267c0152015-05-06 00:59:38 +01001821static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1822 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001823{
1824 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1825 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001826 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001827 size_t outlen;
1828 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001829 u32 alloc_type = exclusive ?
1830 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1831 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1832 unsigned rss_spread = exclusive ?
1833 efx->rss_spread :
1834 min(rounddown_pow_of_two(efx->rss_spread),
1835 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1836
1837 if (!exclusive && rss_spread == 1) {
1838 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1839 if (context_size)
1840 *context_size = 1;
1841 return 0;
1842 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001843
1844 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001845 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001846 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1847 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001848
1849 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1850 outbuf, sizeof(outbuf), &outlen);
1851 if (rc != 0)
1852 return rc;
1853
1854 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1855 return -EIO;
1856
1857 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1858
Jon Cooper267c0152015-05-06 00:59:38 +01001859 if (context_size)
1860 *context_size = rss_spread;
1861
Ben Hutchings8127d662013-08-29 19:19:29 +01001862 return 0;
1863}
1864
1865static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1866{
1867 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1868 int rc;
1869
1870 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1871 context);
1872
1873 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1874 NULL, 0, NULL);
1875 WARN_ON(rc != 0);
1876}
1877
Jon Cooper267c0152015-05-06 00:59:38 +01001878static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1879 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001880{
1881 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1882 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1883 int i, rc;
1884
1885 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1886 context);
1887 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1888 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1889
1890 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1891 MCDI_PTR(tablebuf,
1892 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001893 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001894
1895 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1896 sizeof(tablebuf), NULL, 0, NULL);
1897 if (rc != 0)
1898 return rc;
1899
1900 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1901 context);
1902 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1903 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1904 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1905 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1906 efx->rx_hash_key[i];
1907
1908 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1909 sizeof(keybuf), NULL, 0, NULL);
1910}
1911
1912static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1913{
1914 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1915
1916 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1917 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1918 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1919}
1920
Jon Cooper267c0152015-05-06 00:59:38 +01001921static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1922 unsigned *context_size)
1923{
1924 u32 new_rx_rss_context;
1925 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1926 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1927 false, context_size);
1928
1929 if (rc != 0)
1930 return rc;
1931
1932 nic_data->rx_rss_context = new_rx_rss_context;
1933 nic_data->rx_rss_context_exclusive = false;
1934 efx_set_default_rx_indir_table(efx);
1935 return 0;
1936}
1937
1938static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1939 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001940{
1941 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1942 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001943 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001944
Jon Cooper267c0152015-05-06 00:59:38 +01001945 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1946 !nic_data->rx_rss_context_exclusive) {
1947 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1948 true, NULL);
1949 if (rc == -EOPNOTSUPP)
1950 return rc;
1951 else if (rc != 0)
1952 goto fail1;
1953 } else {
1954 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001955 }
1956
Jon Cooper267c0152015-05-06 00:59:38 +01001957 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1958 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001959 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001960 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001961
Jon Cooper267c0152015-05-06 00:59:38 +01001962 if (nic_data->rx_rss_context != new_rx_rss_context)
1963 efx_ef10_rx_free_indir_table(efx);
1964 nic_data->rx_rss_context = new_rx_rss_context;
1965 nic_data->rx_rss_context_exclusive = true;
1966 if (rx_indir_table != efx->rx_indir_table)
1967 memcpy(efx->rx_indir_table, rx_indir_table,
1968 sizeof(efx->rx_indir_table));
1969 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001970
Jon Cooper267c0152015-05-06 00:59:38 +01001971fail2:
1972 if (new_rx_rss_context != nic_data->rx_rss_context)
1973 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1974fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001975 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001976 return rc;
1977}
1978
1979static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1980 const u32 *rx_indir_table)
1981{
1982 int rc;
1983
1984 if (efx->rss_spread == 1)
1985 return 0;
1986
1987 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1988
1989 if (rc == -ENOBUFS && !user) {
1990 unsigned context_size;
1991 bool mismatch = false;
1992 size_t i;
1993
1994 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1995 i++)
1996 mismatch = rx_indir_table[i] !=
1997 ethtool_rxfh_indir_default(i, efx->rss_spread);
1998
1999 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2000 if (rc == 0) {
2001 if (context_size != efx->rss_spread)
2002 netif_warn(efx, probe, efx->net_dev,
2003 "Could not allocate an exclusive RSS"
2004 " context; allocated a shared one of"
2005 " different size."
2006 " Wanted %u, got %u.\n",
2007 efx->rss_spread, context_size);
2008 else if (mismatch)
2009 netif_warn(efx, probe, efx->net_dev,
2010 "Could not allocate an exclusive RSS"
2011 " context; allocated a shared one but"
2012 " could not apply custom"
2013 " indirection.\n");
2014 else
2015 netif_info(efx, probe, efx->net_dev,
2016 "Could not allocate an exclusive RSS"
2017 " context; allocated a shared one.\n");
2018 }
2019 }
2020 return rc;
2021}
2022
2023static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2024 const u32 *rx_indir_table
2025 __attribute__ ((unused)))
2026{
2027 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2028
2029 if (user)
2030 return -EOPNOTSUPP;
2031 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2032 return 0;
2033 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002034}
2035
2036static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2037{
2038 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2039 (rx_queue->ptr_mask + 1) *
2040 sizeof(efx_qword_t),
2041 GFP_KERNEL);
2042}
2043
2044static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2045{
2046 MCDI_DECLARE_BUF(inbuf,
2047 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2048 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002049 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2050 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2051 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002052 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002053 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002054 dma_addr_t dma_addr;
2055 int rc;
2056 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002057 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002058
2059 rx_queue->scatter_n = 0;
2060 rx_queue->scatter_len = 0;
2061
2062 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2063 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2064 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2065 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2066 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00002067 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2068 INIT_RXQ_IN_FLAG_PREFIX, 1,
2069 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01002070 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002071 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002072
2073 dma_addr = rx_queue->rxd.buf.dma_addr;
2074
2075 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2076 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2077
2078 for (i = 0; i < entries; ++i) {
2079 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2080 dma_addr += EFX_BUF_SIZE;
2081 }
2082
2083 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2084
2085 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002086 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002087 if (rc)
2088 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2089 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002090}
2091
2092static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2093{
2094 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002095 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002096 struct efx_nic *efx = rx_queue->efx;
2097 size_t outlen;
2098 int rc;
2099
2100 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2101 efx_rx_queue_index(rx_queue));
2102
Edward Cree1e0b8122013-05-31 18:36:12 +01002103 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002104 outbuf, sizeof(outbuf), &outlen);
2105
2106 if (rc && rc != -EALREADY)
2107 goto fail;
2108
2109 return;
2110
2111fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002112 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2113 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002114}
2115
2116static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2117{
2118 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2119}
2120
2121/* This creates an entry in the RX descriptor queue */
2122static inline void
2123efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2124{
2125 struct efx_rx_buffer *rx_buf;
2126 efx_qword_t *rxd;
2127
2128 rxd = efx_rx_desc(rx_queue, index);
2129 rx_buf = efx_rx_buffer(rx_queue, index);
2130 EFX_POPULATE_QWORD_2(*rxd,
2131 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2132 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2133}
2134
2135static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2136{
2137 struct efx_nic *efx = rx_queue->efx;
2138 unsigned int write_count;
2139 efx_dword_t reg;
2140
2141 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2142 write_count = rx_queue->added_count & ~7;
2143 if (rx_queue->notified_count == write_count)
2144 return;
2145
2146 do
2147 efx_ef10_build_rx_desc(
2148 rx_queue,
2149 rx_queue->notified_count & rx_queue->ptr_mask);
2150 while (++rx_queue->notified_count != write_count);
2151
2152 wmb();
2153 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2154 write_count & rx_queue->ptr_mask);
2155 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2156 efx_rx_queue_index(rx_queue));
2157}
2158
2159static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2160
2161static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2162{
2163 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2164 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2165 efx_qword_t event;
2166
2167 EFX_POPULATE_QWORD_2(event,
2168 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2169 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2170
2171 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2172
2173 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2174 * already swapped the data to little-endian order.
2175 */
2176 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2177 sizeof(efx_qword_t));
2178
2179 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2180 inbuf, sizeof(inbuf), 0,
2181 efx_ef10_rx_defer_refill_complete, 0);
2182}
2183
2184static void
2185efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2186 int rc, efx_dword_t *outbuf,
2187 size_t outlen_actual)
2188{
2189 /* nothing to do */
2190}
2191
2192static int efx_ef10_ev_probe(struct efx_channel *channel)
2193{
2194 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2195 (channel->eventq_mask + 1) *
2196 sizeof(efx_qword_t),
2197 GFP_KERNEL);
2198}
2199
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002200static void efx_ef10_ev_fini(struct efx_channel *channel)
2201{
2202 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2203 MCDI_DECLARE_BUF_ERR(outbuf);
2204 struct efx_nic *efx = channel->efx;
2205 size_t outlen;
2206 int rc;
2207
2208 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2209
2210 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2211 outbuf, sizeof(outbuf), &outlen);
2212
2213 if (rc && rc != -EALREADY)
2214 goto fail;
2215
2216 return;
2217
2218fail:
2219 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2220 outbuf, outlen, rc);
2221}
2222
Ben Hutchings8127d662013-08-29 19:19:29 +01002223static int efx_ef10_ev_init(struct efx_channel *channel)
2224{
2225 MCDI_DECLARE_BUF(inbuf,
2226 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2227 EFX_BUF_SIZE));
2228 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
2229 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2230 struct efx_nic *efx = channel->efx;
2231 struct efx_ef10_nic_data *nic_data;
2232 bool supports_rx_merge;
2233 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002234 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01002235 dma_addr_t dma_addr;
2236 int rc;
2237 int i;
2238
2239 nic_data = efx->nic_data;
2240 supports_rx_merge =
2241 !!(nic_data->datapath_caps &
2242 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2243
2244 /* Fill event queue with all ones (i.e. empty events) */
2245 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2246
2247 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2248 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2249 /* INIT_EVQ expects index in vector table, not absolute */
2250 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
2251 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2252 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2253 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2254 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2255 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
2256 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2257 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2258 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2259 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2260 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2261 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2262 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2263
2264 dma_addr = channel->eventq.buf.dma_addr;
2265 for (i = 0; i < entries; ++i) {
2266 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2267 dma_addr += EFX_BUF_SIZE;
2268 }
2269
2270 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2271
2272 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2273 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01002274 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002275 if (channel->channel || rc)
2276 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002277
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002278 /* Successfully created event queue on channel 0 */
2279 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01002280 if (rc == -ENOSYS) {
2281 /* GET_WORKAROUNDS was implemented before the bug26807
2282 * workaround, thus the latter must be unavailable in this fw
2283 */
2284 nic_data->workaround_26807 = false;
2285 rc = 0;
2286 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002287 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01002288 } else {
2289 nic_data->workaround_26807 =
2290 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01002291
Edward Cree832dc9e2015-07-21 15:09:31 +01002292 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2293 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002294 unsigned int flags;
2295
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01002296 rc = efx_mcdi_set_workaround(efx,
2297 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002298 true, &flags);
2299
2300 if (!rc) {
2301 if (flags &
2302 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2303 netif_info(efx, drv, efx->net_dev,
2304 "other functions on NIC have been reset\n");
2305 /* MC's boot count has incremented */
2306 ++nic_data->warm_boot_count;
2307 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002308 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002309 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01002310 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01002311 }
Edward Cree832dc9e2015-07-21 15:09:31 +01002312 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002313 }
2314
2315 if (!rc)
2316 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002317
2318fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01002319 efx_ef10_ev_fini(channel);
2320 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01002321}
2322
2323static void efx_ef10_ev_remove(struct efx_channel *channel)
2324{
2325 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2326}
2327
2328static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2329 unsigned int rx_queue_label)
2330{
2331 struct efx_nic *efx = rx_queue->efx;
2332
2333 netif_info(efx, hw, efx->net_dev,
2334 "rx event arrived on queue %d labeled as queue %u\n",
2335 efx_rx_queue_index(rx_queue), rx_queue_label);
2336
2337 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2338}
2339
2340static void
2341efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2342 unsigned int actual, unsigned int expected)
2343{
2344 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2345 struct efx_nic *efx = rx_queue->efx;
2346
2347 netif_info(efx, hw, efx->net_dev,
2348 "dropped %d events (index=%d expected=%d)\n",
2349 dropped, actual, expected);
2350
2351 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2352}
2353
2354/* partially received RX was aborted. clean up. */
2355static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2356{
2357 unsigned int rx_desc_ptr;
2358
Ben Hutchings8127d662013-08-29 19:19:29 +01002359 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2360 "scattered RX aborted (dropping %u buffers)\n",
2361 rx_queue->scatter_n);
2362
2363 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2364
2365 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2366 0, EFX_RX_PKT_DISCARD);
2367
2368 rx_queue->removed_count += rx_queue->scatter_n;
2369 rx_queue->scatter_n = 0;
2370 rx_queue->scatter_len = 0;
2371 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2372}
2373
2374static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2375 const efx_qword_t *event)
2376{
2377 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2378 unsigned int n_descs, n_packets, i;
2379 struct efx_nic *efx = channel->efx;
2380 struct efx_rx_queue *rx_queue;
2381 bool rx_cont;
2382 u16 flags = 0;
2383
2384 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2385 return 0;
2386
2387 /* Basic packet information */
2388 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2389 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2390 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2391 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2392 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2393
Ben Hutchings48ce5632013-11-01 16:42:44 +00002394 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2395 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2396 EFX_QWORD_FMT "\n",
2397 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002398
2399 rx_queue = efx_channel_get_rx_queue(channel);
2400
2401 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2402 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2403
2404 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2405 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2406
2407 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002408 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2409
Ben Hutchings8127d662013-08-29 19:19:29 +01002410 /* detect rx abort */
2411 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002412 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2413 netdev_WARN(efx->net_dev,
2414 "invalid RX abort: scatter_n=%u event="
2415 EFX_QWORD_FMT "\n",
2416 rx_queue->scatter_n,
2417 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002418 efx_ef10_handle_rx_abort(rx_queue);
2419 return 0;
2420 }
2421
Ben Hutchings92a04162013-09-24 23:21:57 +01002422 /* Check that RX completion merging is valid, i.e.
2423 * the current firmware supports it and this is a
2424 * non-scattered packet.
2425 */
2426 if (!(nic_data->datapath_caps &
2427 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2428 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002429 efx_ef10_handle_rx_bad_lbits(
2430 rx_queue, next_ptr_lbits,
2431 (rx_queue->removed_count +
2432 rx_queue->scatter_n + 1) &
2433 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2434 return 0;
2435 }
2436
2437 /* Merged completion for multiple non-scattered packets */
2438 rx_queue->scatter_n = 1;
2439 rx_queue->scatter_len = 0;
2440 n_packets = n_descs;
2441 ++channel->n_rx_merge_events;
2442 channel->n_rx_merge_packets += n_packets;
2443 flags |= EFX_RX_PKT_PREFIX_LEN;
2444 } else {
2445 ++rx_queue->scatter_n;
2446 rx_queue->scatter_len += rx_bytes;
2447 if (rx_cont)
2448 return 0;
2449 n_packets = 1;
2450 }
2451
2452 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2453 flags |= EFX_RX_PKT_DISCARD;
2454
2455 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2456 channel->n_rx_ip_hdr_chksum_err += n_packets;
2457 } else if (unlikely(EFX_QWORD_FIELD(*event,
2458 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2459 channel->n_rx_tcp_udp_chksum_err += n_packets;
2460 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2461 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2462 flags |= EFX_RX_PKT_CSUMMED;
2463 }
2464
2465 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2466 flags |= EFX_RX_PKT_TCP;
2467
2468 channel->irq_mod_score += 2 * n_packets;
2469
2470 /* Handle received packet(s) */
2471 for (i = 0; i < n_packets; i++) {
2472 efx_rx_packet(rx_queue,
2473 rx_queue->removed_count & rx_queue->ptr_mask,
2474 rx_queue->scatter_n, rx_queue->scatter_len,
2475 flags);
2476 rx_queue->removed_count += rx_queue->scatter_n;
2477 }
2478
2479 rx_queue->scatter_n = 0;
2480 rx_queue->scatter_len = 0;
2481
2482 return n_packets;
2483}
2484
2485static int
2486efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2487{
2488 struct efx_nic *efx = channel->efx;
2489 struct efx_tx_queue *tx_queue;
2490 unsigned int tx_ev_desc_ptr;
2491 unsigned int tx_ev_q_label;
2492 int tx_descs = 0;
2493
2494 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2495 return 0;
2496
2497 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2498 return 0;
2499
2500 /* Transmit completion */
2501 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2502 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2503 tx_queue = efx_channel_get_tx_queue(channel,
2504 tx_ev_q_label % EFX_TXQ_TYPES);
2505 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2506 tx_queue->ptr_mask);
2507 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2508
2509 return tx_descs;
2510}
2511
2512static void
2513efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2514{
2515 struct efx_nic *efx = channel->efx;
2516 int subcode;
2517
2518 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2519
2520 switch (subcode) {
2521 case ESE_DZ_DRV_TIMER_EV:
2522 case ESE_DZ_DRV_WAKE_UP_EV:
2523 break;
2524 case ESE_DZ_DRV_START_UP_EV:
2525 /* event queue init complete. ok. */
2526 break;
2527 default:
2528 netif_err(efx, hw, efx->net_dev,
2529 "channel %d unknown driver event type %d"
2530 " (data " EFX_QWORD_FMT ")\n",
2531 channel->channel, subcode,
2532 EFX_QWORD_VAL(*event));
2533
2534 }
2535}
2536
2537static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2538 efx_qword_t *event)
2539{
2540 struct efx_nic *efx = channel->efx;
2541 u32 subcode;
2542
2543 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2544
2545 switch (subcode) {
2546 case EFX_EF10_TEST:
2547 channel->event_test_cpu = raw_smp_processor_id();
2548 break;
2549 case EFX_EF10_REFILL:
2550 /* The queue must be empty, so we won't receive any rx
2551 * events, so efx_process_channel() won't refill the
2552 * queue. Refill it here
2553 */
Jon Coopercce28792013-10-02 11:04:14 +01002554 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002555 break;
2556 default:
2557 netif_err(efx, hw, efx->net_dev,
2558 "channel %d unknown driver event type %u"
2559 " (data " EFX_QWORD_FMT ")\n",
2560 channel->channel, (unsigned) subcode,
2561 EFX_QWORD_VAL(*event));
2562 }
2563}
2564
2565static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2566{
2567 struct efx_nic *efx = channel->efx;
2568 efx_qword_t event, *p_event;
2569 unsigned int read_ptr;
2570 int ev_code;
2571 int tx_descs = 0;
2572 int spent = 0;
2573
Eric W. Biederman75363a42014-03-14 18:11:22 -07002574 if (quota <= 0)
2575 return spent;
2576
Ben Hutchings8127d662013-08-29 19:19:29 +01002577 read_ptr = channel->eventq_read_ptr;
2578
2579 for (;;) {
2580 p_event = efx_event(channel, read_ptr);
2581 event = *p_event;
2582
2583 if (!efx_event_present(&event))
2584 break;
2585
2586 EFX_SET_QWORD(*p_event);
2587
2588 ++read_ptr;
2589
2590 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2591
2592 netif_vdbg(efx, drv, efx->net_dev,
2593 "processing event on %d " EFX_QWORD_FMT "\n",
2594 channel->channel, EFX_QWORD_VAL(event));
2595
2596 switch (ev_code) {
2597 case ESE_DZ_EV_CODE_MCDI_EV:
2598 efx_mcdi_process_event(channel, &event);
2599 break;
2600 case ESE_DZ_EV_CODE_RX_EV:
2601 spent += efx_ef10_handle_rx_event(channel, &event);
2602 if (spent >= quota) {
2603 /* XXX can we split a merged event to
2604 * avoid going over-quota?
2605 */
2606 spent = quota;
2607 goto out;
2608 }
2609 break;
2610 case ESE_DZ_EV_CODE_TX_EV:
2611 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2612 if (tx_descs > efx->txq_entries) {
2613 spent = quota;
2614 goto out;
2615 } else if (++spent == quota) {
2616 goto out;
2617 }
2618 break;
2619 case ESE_DZ_EV_CODE_DRIVER_EV:
2620 efx_ef10_handle_driver_event(channel, &event);
2621 if (++spent == quota)
2622 goto out;
2623 break;
2624 case EFX_EF10_DRVGEN_EV:
2625 efx_ef10_handle_driver_generated_event(channel, &event);
2626 break;
2627 default:
2628 netif_err(efx, hw, efx->net_dev,
2629 "channel %d unknown event type %d"
2630 " (data " EFX_QWORD_FMT ")\n",
2631 channel->channel, ev_code,
2632 EFX_QWORD_VAL(event));
2633 }
2634 }
2635
2636out:
2637 channel->eventq_read_ptr = read_ptr;
2638 return spent;
2639}
2640
2641static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2642{
2643 struct efx_nic *efx = channel->efx;
2644 efx_dword_t rptr;
2645
2646 if (EFX_EF10_WORKAROUND_35388(efx)) {
2647 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2648 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2649 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2650 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2651
2652 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2653 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2654 ERF_DD_EVQ_IND_RPTR,
2655 (channel->eventq_read_ptr &
2656 channel->eventq_mask) >>
2657 ERF_DD_EVQ_IND_RPTR_WIDTH);
2658 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2659 channel->channel);
2660 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2661 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2662 ERF_DD_EVQ_IND_RPTR,
2663 channel->eventq_read_ptr &
2664 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2665 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2666 channel->channel);
2667 } else {
2668 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2669 channel->eventq_read_ptr &
2670 channel->eventq_mask);
2671 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2672 }
2673}
2674
2675static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2676{
2677 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2678 struct efx_nic *efx = channel->efx;
2679 efx_qword_t event;
2680 int rc;
2681
2682 EFX_POPULATE_QWORD_2(event,
2683 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2684 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2685
2686 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2687
2688 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2689 * already swapped the data to little-endian order.
2690 */
2691 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2692 sizeof(efx_qword_t));
2693
2694 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2695 NULL, 0, NULL);
2696 if (rc != 0)
2697 goto fail;
2698
2699 return;
2700
2701fail:
2702 WARN_ON(true);
2703 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2704}
2705
2706void efx_ef10_handle_drain_event(struct efx_nic *efx)
2707{
2708 if (atomic_dec_and_test(&efx->active_queues))
2709 wake_up(&efx->flush_wq);
2710
2711 WARN_ON(atomic_read(&efx->active_queues) < 0);
2712}
2713
2714static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2715{
2716 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2717 struct efx_channel *channel;
2718 struct efx_tx_queue *tx_queue;
2719 struct efx_rx_queue *rx_queue;
2720 int pending;
2721
2722 /* If the MC has just rebooted, the TX/RX queues will have already been
2723 * torn down, but efx->active_queues needs to be set to zero.
2724 */
2725 if (nic_data->must_realloc_vis) {
2726 atomic_set(&efx->active_queues, 0);
2727 return 0;
2728 }
2729
2730 /* Do not attempt to write to the NIC during EEH recovery */
2731 if (efx->state != STATE_RECOVERY) {
2732 efx_for_each_channel(channel, efx) {
2733 efx_for_each_channel_rx_queue(rx_queue, channel)
2734 efx_ef10_rx_fini(rx_queue);
2735 efx_for_each_channel_tx_queue(tx_queue, channel)
2736 efx_ef10_tx_fini(tx_queue);
2737 }
2738
2739 wait_event_timeout(efx->flush_wq,
2740 atomic_read(&efx->active_queues) == 0,
2741 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2742 pending = atomic_read(&efx->active_queues);
2743 if (pending) {
2744 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2745 pending);
2746 return -ETIMEDOUT;
2747 }
2748 }
2749
2750 return 0;
2751}
2752
Edward Creee2835462014-04-16 19:27:48 +01002753static void efx_ef10_prepare_flr(struct efx_nic *efx)
2754{
2755 atomic_set(&efx->active_queues, 0);
2756}
2757
Ben Hutchings8127d662013-08-29 19:19:29 +01002758static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2759 const struct efx_filter_spec *right)
2760{
2761 if ((left->match_flags ^ right->match_flags) |
2762 ((left->flags ^ right->flags) &
2763 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2764 return false;
2765
2766 return memcmp(&left->outer_vid, &right->outer_vid,
2767 sizeof(struct efx_filter_spec) -
2768 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2769}
2770
2771static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2772{
2773 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2774 return jhash2((const u32 *)&spec->outer_vid,
2775 (sizeof(struct efx_filter_spec) -
2776 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2777 0);
2778 /* XXX should we randomise the initval? */
2779}
2780
2781/* Decide whether a filter should be exclusive or else should allow
2782 * delivery to additional recipients. Currently we decide that
2783 * filters for specific local unicast MAC and IP addresses are
2784 * exclusive.
2785 */
2786static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2787{
2788 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2789 !is_multicast_ether_addr(spec->loc_mac))
2790 return true;
2791
2792 if ((spec->match_flags &
2793 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2794 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2795 if (spec->ether_type == htons(ETH_P_IP) &&
2796 !ipv4_is_multicast(spec->loc_host[0]))
2797 return true;
2798 if (spec->ether_type == htons(ETH_P_IPV6) &&
2799 ((const u8 *)spec->loc_host)[0] != 0xff)
2800 return true;
2801 }
2802
2803 return false;
2804}
2805
2806static struct efx_filter_spec *
2807efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2808 unsigned int filter_idx)
2809{
2810 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2811 ~EFX_EF10_FILTER_FLAGS);
2812}
2813
2814static unsigned int
2815efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2816 unsigned int filter_idx)
2817{
2818 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2819}
2820
2821static void
2822efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2823 unsigned int filter_idx,
2824 const struct efx_filter_spec *spec,
2825 unsigned int flags)
2826{
2827 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2828}
2829
2830static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2831 const struct efx_filter_spec *spec,
2832 efx_dword_t *inbuf, u64 handle,
2833 bool replacing)
2834{
2835 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2836
2837 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2838
2839 if (replacing) {
2840 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2841 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2842 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2843 } else {
2844 u32 match_fields = 0;
2845
2846 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2847 efx_ef10_filter_is_exclusive(spec) ?
2848 MC_CMD_FILTER_OP_IN_OP_INSERT :
2849 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2850
2851 /* Convert match flags and values. Unlike almost
2852 * everything else in MCDI, these fields are in
2853 * network byte order.
2854 */
2855 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2856 match_fields |=
2857 is_multicast_ether_addr(spec->loc_mac) ?
2858 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2859 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2860#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2861 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2862 match_fields |= \
2863 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2864 mcdi_field ## _LBN; \
2865 BUILD_BUG_ON( \
2866 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2867 sizeof(spec->gen_field)); \
2868 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2869 &spec->gen_field, sizeof(spec->gen_field)); \
2870 }
2871 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2872 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2873 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2874 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2875 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2876 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2877 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2878 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2879 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2880 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2881#undef COPY_FIELD
2882 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2883 match_fields);
2884 }
2885
Daniel Pieczko45b24492015-05-06 00:57:14 +01002886 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002887 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2888 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2889 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2890 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002891 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002892 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2893 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002894 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2895 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2896 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002897 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2898 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2899 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2900 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2901 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2902 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2903 spec->rss_context !=
2904 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2905 spec->rss_context : nic_data->rx_rss_context);
2906}
2907
2908static int efx_ef10_filter_push(struct efx_nic *efx,
2909 const struct efx_filter_spec *spec,
2910 u64 *handle, bool replacing)
2911{
2912 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2913 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2914 int rc;
2915
2916 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2917 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2918 outbuf, sizeof(outbuf), NULL);
2919 if (rc == 0)
2920 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002921 if (rc == -ENOSPC)
2922 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002923 return rc;
2924}
2925
2926static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2927 enum efx_filter_match_flags match_flags)
2928{
2929 unsigned int match_pri;
2930
2931 for (match_pri = 0;
2932 match_pri < table->rx_match_count;
2933 match_pri++)
2934 if (table->rx_match_flags[match_pri] == match_flags)
2935 return match_pri;
2936
2937 return -EPROTONOSUPPORT;
2938}
2939
2940static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2941 struct efx_filter_spec *spec,
2942 bool replace_equal)
2943{
2944 struct efx_ef10_filter_table *table = efx->filter_state;
2945 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2946 struct efx_filter_spec *saved_spec;
2947 unsigned int match_pri, hash;
2948 unsigned int priv_flags;
2949 bool replacing = false;
2950 int ins_index = -1;
2951 DEFINE_WAIT(wait);
2952 bool is_mc_recip;
2953 s32 rc;
2954
2955 /* For now, only support RX filters */
2956 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2957 EFX_FILTER_FLAG_RX)
2958 return -EINVAL;
2959
2960 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2961 if (rc < 0)
2962 return rc;
2963 match_pri = rc;
2964
2965 hash = efx_ef10_filter_hash(spec);
2966 is_mc_recip = efx_filter_is_mc_recipient(spec);
2967 if (is_mc_recip)
2968 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2969
2970 /* Find any existing filters with the same match tuple or
2971 * else a free slot to insert at. If any of them are busy,
2972 * we have to wait and retry.
2973 */
2974 for (;;) {
2975 unsigned int depth = 1;
2976 unsigned int i;
2977
2978 spin_lock_bh(&efx->filter_lock);
2979
2980 for (;;) {
2981 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2982 saved_spec = efx_ef10_filter_entry_spec(table, i);
2983
2984 if (!saved_spec) {
2985 if (ins_index < 0)
2986 ins_index = i;
2987 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2988 if (table->entry[i].spec &
2989 EFX_EF10_FILTER_FLAG_BUSY)
2990 break;
2991 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002992 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002993 rc = -EPERM;
2994 goto out_unlock;
2995 }
2996 if (!is_mc_recip) {
2997 /* This is the only one */
2998 if (spec->priority ==
2999 saved_spec->priority &&
3000 !replace_equal) {
3001 rc = -EEXIST;
3002 goto out_unlock;
3003 }
3004 ins_index = i;
3005 goto found;
3006 } else if (spec->priority >
3007 saved_spec->priority ||
3008 (spec->priority ==
3009 saved_spec->priority &&
3010 replace_equal)) {
3011 if (ins_index < 0)
3012 ins_index = i;
3013 else
3014 __set_bit(depth, mc_rem_map);
3015 }
3016 }
3017
3018 /* Once we reach the maximum search depth, use
3019 * the first suitable slot or return -EBUSY if
3020 * there was none
3021 */
3022 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3023 if (ins_index < 0) {
3024 rc = -EBUSY;
3025 goto out_unlock;
3026 }
3027 goto found;
3028 }
3029
3030 ++depth;
3031 }
3032
3033 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3034 spin_unlock_bh(&efx->filter_lock);
3035 schedule();
3036 }
3037
3038found:
3039 /* Create a software table entry if necessary, and mark it
3040 * busy. We might yet fail to insert, but any attempt to
3041 * insert a conflicting filter while we're waiting for the
3042 * firmware must find the busy entry.
3043 */
3044 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3045 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003046 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3047 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003048 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003049 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3050 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003051 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003052 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003053 rc = ins_index;
3054 goto out_unlock;
3055 }
3056 replacing = true;
3057 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3058 } else {
3059 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3060 if (!saved_spec) {
3061 rc = -ENOMEM;
3062 goto out_unlock;
3063 }
3064 *saved_spec = *spec;
3065 priv_flags = 0;
3066 }
3067 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3068 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3069
3070 /* Mark lower-priority multicast recipients busy prior to removal */
3071 if (is_mc_recip) {
3072 unsigned int depth, i;
3073
3074 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3075 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3076 if (test_bit(depth, mc_rem_map))
3077 table->entry[i].spec |=
3078 EFX_EF10_FILTER_FLAG_BUSY;
3079 }
3080 }
3081
3082 spin_unlock_bh(&efx->filter_lock);
3083
3084 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3085 replacing);
3086
3087 /* Finalise the software table entry */
3088 spin_lock_bh(&efx->filter_lock);
3089 if (rc == 0) {
3090 if (replacing) {
3091 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003092 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3093 saved_spec->flags |=
3094 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003095 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003096 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003097 saved_spec->flags |= spec->flags;
3098 saved_spec->rss_context = spec->rss_context;
3099 saved_spec->dmaq_id = spec->dmaq_id;
3100 }
3101 } else if (!replacing) {
3102 kfree(saved_spec);
3103 saved_spec = NULL;
3104 }
3105 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3106
3107 /* Remove and finalise entries for lower-priority multicast
3108 * recipients
3109 */
3110 if (is_mc_recip) {
3111 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3112 unsigned int depth, i;
3113
3114 memset(inbuf, 0, sizeof(inbuf));
3115
3116 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3117 if (!test_bit(depth, mc_rem_map))
3118 continue;
3119
3120 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3121 saved_spec = efx_ef10_filter_entry_spec(table, i);
3122 priv_flags = efx_ef10_filter_entry_flags(table, i);
3123
3124 if (rc == 0) {
3125 spin_unlock_bh(&efx->filter_lock);
3126 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3127 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3128 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3129 table->entry[i].handle);
3130 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3131 inbuf, sizeof(inbuf),
3132 NULL, 0, NULL);
3133 spin_lock_bh(&efx->filter_lock);
3134 }
3135
3136 if (rc == 0) {
3137 kfree(saved_spec);
3138 saved_spec = NULL;
3139 priv_flags = 0;
3140 } else {
3141 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3142 }
3143 efx_ef10_filter_set_entry(table, i, saved_spec,
3144 priv_flags);
3145 }
3146 }
3147
3148 /* If successful, return the inserted filter ID */
3149 if (rc == 0)
3150 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3151
3152 wake_up_all(&table->waitq);
3153out_unlock:
3154 spin_unlock_bh(&efx->filter_lock);
3155 finish_wait(&table->waitq, &wait);
3156 return rc;
3157}
3158
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003159static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003160{
3161 /* no need to do anything here on EF10 */
3162}
3163
3164/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003165 * If !by_index, remove by ID
3166 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003167 * Filter ID may come from userland and must be range-checked.
3168 */
3169static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003170 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003171 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003172{
3173 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3174 struct efx_ef10_filter_table *table = efx->filter_state;
3175 MCDI_DECLARE_BUF(inbuf,
3176 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3177 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3178 struct efx_filter_spec *spec;
3179 DEFINE_WAIT(wait);
3180 int rc;
3181
3182 /* Find the software table entry and mark it busy. Don't
3183 * remove it yet; any attempt to update while we're waiting
3184 * for the firmware must find the busy entry.
3185 */
3186 for (;;) {
3187 spin_lock_bh(&efx->filter_lock);
3188 if (!(table->entry[filter_idx].spec &
3189 EFX_EF10_FILTER_FLAG_BUSY))
3190 break;
3191 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3192 spin_unlock_bh(&efx->filter_lock);
3193 schedule();
3194 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003195
Ben Hutchings8127d662013-08-29 19:19:29 +01003196 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003197 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003198 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01003199 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
3200 filter_id / HUNT_FILTER_TBL_ROWS)) {
3201 rc = -ENOENT;
3202 goto out_unlock;
3203 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003204
3205 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003206 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003207 /* Just remove flags */
3208 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003209 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003210 rc = 0;
3211 goto out_unlock;
3212 }
3213
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003214 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003215 rc = -ENOENT;
3216 goto out_unlock;
3217 }
3218
Ben Hutchings8127d662013-08-29 19:19:29 +01003219 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3220 spin_unlock_bh(&efx->filter_lock);
3221
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003222 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003223 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003224
3225 struct efx_filter_spec new_spec = *spec;
3226
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003227 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003228 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003229 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003230 new_spec.dmaq_id = 0;
3231 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3232 rc = efx_ef10_filter_push(efx, &new_spec,
3233 &table->entry[filter_idx].handle,
3234 true);
3235
3236 spin_lock_bh(&efx->filter_lock);
3237 if (rc == 0)
3238 *spec = new_spec;
3239 } else {
3240 /* Really remove the filter */
3241
3242 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3243 efx_ef10_filter_is_exclusive(spec) ?
3244 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3245 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3246 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3247 table->entry[filter_idx].handle);
3248 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3249 inbuf, sizeof(inbuf), NULL, 0, NULL);
3250
3251 spin_lock_bh(&efx->filter_lock);
3252 if (rc == 0) {
3253 kfree(spec);
3254 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3255 }
3256 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003257
Ben Hutchings8127d662013-08-29 19:19:29 +01003258 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3259 wake_up_all(&table->waitq);
3260out_unlock:
3261 spin_unlock_bh(&efx->filter_lock);
3262 finish_wait(&table->waitq, &wait);
3263 return rc;
3264}
3265
3266static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3267 enum efx_filter_priority priority,
3268 u32 filter_id)
3269{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003270 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3271 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003272}
3273
3274static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3275 enum efx_filter_priority priority,
3276 u32 filter_id, struct efx_filter_spec *spec)
3277{
3278 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3279 struct efx_ef10_filter_table *table = efx->filter_state;
3280 const struct efx_filter_spec *saved_spec;
3281 int rc;
3282
3283 spin_lock_bh(&efx->filter_lock);
3284 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3285 if (saved_spec && saved_spec->priority == priority &&
3286 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
3287 filter_id / HUNT_FILTER_TBL_ROWS) {
3288 *spec = *saved_spec;
3289 rc = 0;
3290 } else {
3291 rc = -ENOENT;
3292 }
3293 spin_unlock_bh(&efx->filter_lock);
3294 return rc;
3295}
3296
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003297static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003298 enum efx_filter_priority priority)
3299{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003300 unsigned int priority_mask;
3301 unsigned int i;
3302 int rc;
3303
3304 priority_mask = (((1U << (priority + 1)) - 1) &
3305 ~(1U << EFX_FILTER_PRI_AUTO));
3306
3307 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3308 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3309 i, true);
3310 if (rc && rc != -ENOENT)
3311 return rc;
3312 }
3313
3314 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003315}
3316
3317static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3318 enum efx_filter_priority priority)
3319{
3320 struct efx_ef10_filter_table *table = efx->filter_state;
3321 unsigned int filter_idx;
3322 s32 count = 0;
3323
3324 spin_lock_bh(&efx->filter_lock);
3325 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3326 if (table->entry[filter_idx].spec &&
3327 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3328 priority)
3329 ++count;
3330 }
3331 spin_unlock_bh(&efx->filter_lock);
3332 return count;
3333}
3334
3335static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3336{
3337 struct efx_ef10_filter_table *table = efx->filter_state;
3338
3339 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3340}
3341
3342static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3343 enum efx_filter_priority priority,
3344 u32 *buf, u32 size)
3345{
3346 struct efx_ef10_filter_table *table = efx->filter_state;
3347 struct efx_filter_spec *spec;
3348 unsigned int filter_idx;
3349 s32 count = 0;
3350
3351 spin_lock_bh(&efx->filter_lock);
3352 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3353 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3354 if (spec && spec->priority == priority) {
3355 if (count == size) {
3356 count = -EMSGSIZE;
3357 break;
3358 }
3359 buf[count++] = (efx_ef10_filter_rx_match_pri(
3360 table, spec->match_flags) *
3361 HUNT_FILTER_TBL_ROWS +
3362 filter_idx);
3363 }
3364 }
3365 spin_unlock_bh(&efx->filter_lock);
3366 return count;
3367}
3368
3369#ifdef CONFIG_RFS_ACCEL
3370
3371static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3372
3373static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3374 struct efx_filter_spec *spec)
3375{
3376 struct efx_ef10_filter_table *table = efx->filter_state;
3377 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3378 struct efx_filter_spec *saved_spec;
3379 unsigned int hash, i, depth = 1;
3380 bool replacing = false;
3381 int ins_index = -1;
3382 u64 cookie;
3383 s32 rc;
3384
3385 /* Must be an RX filter without RSS and not for a multicast
3386 * destination address (RFS only works for connected sockets).
3387 * These restrictions allow us to pass only a tiny amount of
3388 * data through to the completion function.
3389 */
3390 EFX_WARN_ON_PARANOID(spec->flags !=
3391 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3392 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3393 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3394
3395 hash = efx_ef10_filter_hash(spec);
3396
3397 spin_lock_bh(&efx->filter_lock);
3398
3399 /* Find any existing filter with the same match tuple or else
3400 * a free slot to insert at. If an existing filter is busy,
3401 * we have to give up.
3402 */
3403 for (;;) {
3404 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3405 saved_spec = efx_ef10_filter_entry_spec(table, i);
3406
3407 if (!saved_spec) {
3408 if (ins_index < 0)
3409 ins_index = i;
3410 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3411 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3412 rc = -EBUSY;
3413 goto fail_unlock;
3414 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003415 if (spec->priority < saved_spec->priority) {
3416 rc = -EPERM;
3417 goto fail_unlock;
3418 }
3419 ins_index = i;
3420 break;
3421 }
3422
3423 /* Once we reach the maximum search depth, use the
3424 * first suitable slot or return -EBUSY if there was
3425 * none
3426 */
3427 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3428 if (ins_index < 0) {
3429 rc = -EBUSY;
3430 goto fail_unlock;
3431 }
3432 break;
3433 }
3434
3435 ++depth;
3436 }
3437
3438 /* Create a software table entry if necessary, and mark it
3439 * busy. We might yet fail to insert, but any attempt to
3440 * insert a conflicting filter while we're waiting for the
3441 * firmware must find the busy entry.
3442 */
3443 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3444 if (saved_spec) {
3445 replacing = true;
3446 } else {
3447 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3448 if (!saved_spec) {
3449 rc = -ENOMEM;
3450 goto fail_unlock;
3451 }
3452 *saved_spec = *spec;
3453 }
3454 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3455 EFX_EF10_FILTER_FLAG_BUSY);
3456
3457 spin_unlock_bh(&efx->filter_lock);
3458
3459 /* Pack up the variables needed on completion */
3460 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3461
3462 efx_ef10_filter_push_prep(efx, spec, inbuf,
3463 table->entry[ins_index].handle, replacing);
3464 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3465 MC_CMD_FILTER_OP_OUT_LEN,
3466 efx_ef10_filter_rfs_insert_complete, cookie);
3467
3468 return ins_index;
3469
3470fail_unlock:
3471 spin_unlock_bh(&efx->filter_lock);
3472 return rc;
3473}
3474
3475static void
3476efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3477 int rc, efx_dword_t *outbuf,
3478 size_t outlen_actual)
3479{
3480 struct efx_ef10_filter_table *table = efx->filter_state;
3481 unsigned int ins_index, dmaq_id;
3482 struct efx_filter_spec *spec;
3483 bool replacing;
3484
3485 /* Unpack the cookie */
3486 replacing = cookie >> 31;
3487 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3488 dmaq_id = cookie & 0xffff;
3489
3490 spin_lock_bh(&efx->filter_lock);
3491 spec = efx_ef10_filter_entry_spec(table, ins_index);
3492 if (rc == 0) {
3493 table->entry[ins_index].handle =
3494 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3495 if (replacing)
3496 spec->dmaq_id = dmaq_id;
3497 } else if (!replacing) {
3498 kfree(spec);
3499 spec = NULL;
3500 }
3501 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3502 spin_unlock_bh(&efx->filter_lock);
3503
3504 wake_up_all(&table->waitq);
3505}
3506
3507static void
3508efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3509 unsigned long filter_idx,
3510 int rc, efx_dword_t *outbuf,
3511 size_t outlen_actual);
3512
3513static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3514 unsigned int filter_idx)
3515{
3516 struct efx_ef10_filter_table *table = efx->filter_state;
3517 struct efx_filter_spec *spec =
3518 efx_ef10_filter_entry_spec(table, filter_idx);
3519 MCDI_DECLARE_BUF(inbuf,
3520 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3521 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3522
3523 if (!spec ||
3524 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3525 spec->priority != EFX_FILTER_PRI_HINT ||
3526 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3527 flow_id, filter_idx))
3528 return false;
3529
3530 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3531 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3532 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3533 table->entry[filter_idx].handle);
3534 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3535 efx_ef10_filter_rfs_expire_complete, filter_idx))
3536 return false;
3537
3538 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3539 return true;
3540}
3541
3542static void
3543efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3544 unsigned long filter_idx,
3545 int rc, efx_dword_t *outbuf,
3546 size_t outlen_actual)
3547{
3548 struct efx_ef10_filter_table *table = efx->filter_state;
3549 struct efx_filter_spec *spec =
3550 efx_ef10_filter_entry_spec(table, filter_idx);
3551
3552 spin_lock_bh(&efx->filter_lock);
3553 if (rc == 0) {
3554 kfree(spec);
3555 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3556 }
3557 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3558 wake_up_all(&table->waitq);
3559 spin_unlock_bh(&efx->filter_lock);
3560}
3561
3562#endif /* CONFIG_RFS_ACCEL */
3563
3564static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3565{
3566 int match_flags = 0;
3567
3568#define MAP_FLAG(gen_flag, mcdi_field) { \
3569 u32 old_mcdi_flags = mcdi_flags; \
3570 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3571 mcdi_field ## _LBN); \
3572 if (mcdi_flags != old_mcdi_flags) \
3573 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3574 }
3575 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3576 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3577 MAP_FLAG(REM_HOST, SRC_IP);
3578 MAP_FLAG(LOC_HOST, DST_IP);
3579 MAP_FLAG(REM_MAC, SRC_MAC);
3580 MAP_FLAG(REM_PORT, SRC_PORT);
3581 MAP_FLAG(LOC_MAC, DST_MAC);
3582 MAP_FLAG(LOC_PORT, DST_PORT);
3583 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3584 MAP_FLAG(INNER_VID, INNER_VLAN);
3585 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3586 MAP_FLAG(IP_PROTO, IP_PROTO);
3587#undef MAP_FLAG
3588
3589 /* Did we map them all? */
3590 if (mcdi_flags)
3591 return -EINVAL;
3592
3593 return match_flags;
3594}
3595
3596static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3597{
3598 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3599 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3600 unsigned int pd_match_pri, pd_match_count;
3601 struct efx_ef10_filter_table *table;
3602 size_t outlen;
3603 int rc;
3604
3605 table = kzalloc(sizeof(*table), GFP_KERNEL);
3606 if (!table)
3607 return -ENOMEM;
3608
3609 /* Find out which RX filter types are supported, and their priorities */
3610 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3611 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3612 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3613 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3614 &outlen);
3615 if (rc)
3616 goto fail;
3617 pd_match_count = MCDI_VAR_ARRAY_LEN(
3618 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3619 table->rx_match_count = 0;
3620
3621 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3622 u32 mcdi_flags =
3623 MCDI_ARRAY_DWORD(
3624 outbuf,
3625 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3626 pd_match_pri);
3627 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3628 if (rc < 0) {
3629 netif_dbg(efx, probe, efx->net_dev,
3630 "%s: fw flags %#x pri %u not supported in driver\n",
3631 __func__, mcdi_flags, pd_match_pri);
3632 } else {
3633 netif_dbg(efx, probe, efx->net_dev,
3634 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3635 __func__, mcdi_flags, pd_match_pri,
3636 rc, table->rx_match_count);
3637 table->rx_match_flags[table->rx_match_count++] = rc;
3638 }
3639 }
3640
3641 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3642 if (!table->entry) {
3643 rc = -ENOMEM;
3644 goto fail;
3645 }
3646
3647 efx->filter_state = table;
3648 init_waitqueue_head(&table->waitq);
3649 return 0;
3650
3651fail:
3652 kfree(table);
3653 return rc;
3654}
3655
Edward Cree0d322412015-05-20 11:10:03 +01003656/* Caller must hold efx->filter_sem for read if race against
3657 * efx_ef10_filter_table_remove() is possible
3658 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003659static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3660{
3661 struct efx_ef10_filter_table *table = efx->filter_state;
3662 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3663 struct efx_filter_spec *spec;
3664 unsigned int filter_idx;
3665 bool failed = false;
3666 int rc;
3667
Edward Cree0d322412015-05-20 11:10:03 +01003668 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3669
Ben Hutchings8127d662013-08-29 19:19:29 +01003670 if (!nic_data->must_restore_filters)
3671 return;
3672
Edward Cree0d322412015-05-20 11:10:03 +01003673 if (!table)
3674 return;
3675
Ben Hutchings8127d662013-08-29 19:19:29 +01003676 spin_lock_bh(&efx->filter_lock);
3677
3678 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3679 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3680 if (!spec)
3681 continue;
3682
3683 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3684 spin_unlock_bh(&efx->filter_lock);
3685
3686 rc = efx_ef10_filter_push(efx, spec,
3687 &table->entry[filter_idx].handle,
3688 false);
3689 if (rc)
3690 failed = true;
3691
3692 spin_lock_bh(&efx->filter_lock);
3693 if (rc) {
3694 kfree(spec);
3695 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3696 } else {
3697 table->entry[filter_idx].spec &=
3698 ~EFX_EF10_FILTER_FLAG_BUSY;
3699 }
3700 }
3701
3702 spin_unlock_bh(&efx->filter_lock);
3703
3704 if (failed)
3705 netif_err(efx, hw, efx->net_dev,
3706 "unable to restore all filters\n");
3707 else
3708 nic_data->must_restore_filters = false;
3709}
3710
Edward Cree0d322412015-05-20 11:10:03 +01003711/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003712static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3713{
3714 struct efx_ef10_filter_table *table = efx->filter_state;
3715 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3716 struct efx_filter_spec *spec;
3717 unsigned int filter_idx;
3718 int rc;
3719
Edward Cree0d322412015-05-20 11:10:03 +01003720 efx->filter_state = NULL;
3721 if (!table)
3722 return;
3723
Ben Hutchings8127d662013-08-29 19:19:29 +01003724 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3725 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3726 if (!spec)
3727 continue;
3728
3729 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3730 efx_ef10_filter_is_exclusive(spec) ?
3731 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3732 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3733 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3734 table->entry[filter_idx].handle);
3735 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3736 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003737 if (rc)
3738 netdev_WARN(efx->net_dev,
3739 "filter_idx=%#x handle=%#llx\n",
3740 filter_idx,
3741 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003742 kfree(spec);
3743 }
3744
3745 vfree(table->entry);
3746 kfree(table);
3747}
3748
Edward Cree0d322412015-05-20 11:10:03 +01003749/* Caller must hold efx->filter_sem for read if race against
3750 * efx_ef10_filter_table_remove() is possible
3751 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003752static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3753{
3754 struct efx_ef10_filter_table *table = efx->filter_state;
3755 struct net_device *net_dev = efx->net_dev;
3756 struct efx_filter_spec spec;
3757 bool remove_failed = false;
3758 struct netdev_hw_addr *uc;
3759 struct netdev_hw_addr *mc;
3760 unsigned int filter_idx;
Jon Cooperb6f568e2015-07-21 15:10:15 +01003761 int i, rc;
3762 bool uc_promisc = false, mc_promisc = false;
Ben Hutchings8127d662013-08-29 19:19:29 +01003763
3764 if (!efx_dev_registered(efx))
3765 return;
3766
Edward Cree0d322412015-05-20 11:10:03 +01003767 if (!table)
3768 return;
3769
Ben Hutchings8127d662013-08-29 19:19:29 +01003770 /* Mark old filters that may need to be removed */
3771 spin_lock_bh(&efx->filter_lock);
Jon Cooperb6f568e2015-07-21 15:10:15 +01003772 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003773 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3774 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003775 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003776 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003777 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3778 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003779 }
3780 spin_unlock_bh(&efx->filter_lock);
3781
3782 /* Copy/convert the address lists; add the primary station
3783 * address and broadcast address
3784 */
3785 netif_addr_lock_bh(net_dev);
3786 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003787 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
Jon Cooperb6f568e2015-07-21 15:10:15 +01003788 table->dev_uc_count = 0;
3789 uc_promisc = true;
Ben Hutchings8127d662013-08-29 19:19:29 +01003790 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003791 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003792 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003793 i = 1;
3794 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003795 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003796 i++;
3797 }
3798 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003799 if (netdev_mc_count(net_dev) + 2 /* room for broadcast and promisc */
3800 >= EFX_EF10_FILTER_DEV_MC_MAX) {
3801 table->dev_mc_count = 1;
3802 eth_broadcast_addr(table->dev_mc_list[0].addr);
3803 mc_promisc = true;
Ben Hutchings8127d662013-08-29 19:19:29 +01003804 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003805 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3806 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003807 i = 1;
3808 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003809 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003810 i++;
3811 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003812 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI))
3813 mc_promisc = true;
Ben Hutchings8127d662013-08-29 19:19:29 +01003814 }
3815 netif_addr_unlock_bh(net_dev);
3816
3817 /* Insert/renew unicast filters */
Jon Cooperb6f568e2015-07-21 15:10:15 +01003818 for (i = 0; i < table->dev_uc_count; i++) {
3819 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3820 EFX_FILTER_FLAG_RX_RSS,
3821 0);
3822 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
3823 table->dev_uc_list[i].addr);
3824 rc = efx_ef10_filter_insert(efx, &spec, true);
3825 if (rc < 0) {
3826 /* Fall back to unicast-promisc */
3827 while (i--)
3828 efx_ef10_filter_remove_safe(
3829 efx, EFX_FILTER_PRI_AUTO,
3830 table->dev_uc_list[i].id);
3831 table->dev_uc_count = 0;
3832 uc_promisc = true;
3833 break;
Ben Hutchings8127d662013-08-29 19:19:29 +01003834 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003835 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003836 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003837 if (uc_promisc) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003838 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3839 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003840 0);
3841 efx_filter_set_uc_def(&spec);
3842 rc = efx_ef10_filter_insert(efx, &spec, true);
3843 if (rc < 0) {
3844 WARN_ON(1);
Ben Hutchings8127d662013-08-29 19:19:29 +01003845 } else {
Jon Cooperb6f568e2015-07-21 15:10:15 +01003846 table->dev_uc_list[table->dev_uc_count++].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003847 }
3848 }
3849
3850 /* Insert/renew multicast filters */
Jon Cooperb6f568e2015-07-21 15:10:15 +01003851 for (i = 0; i < table->dev_mc_count; i++) {
3852 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3853 EFX_FILTER_FLAG_RX_RSS,
3854 0);
3855 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
3856 table->dev_mc_list[i].addr);
3857 rc = efx_ef10_filter_insert(efx, &spec, true);
3858 if (rc < 0) {
3859 /* Fall back to multicast-promisc.
3860 * Leave the broadcast filter.
3861 */
3862 while (i > 1)
3863 efx_ef10_filter_remove_safe(
3864 efx, EFX_FILTER_PRI_AUTO,
3865 table->dev_mc_list[--i].id);
3866 table->dev_mc_count = i;
3867 mc_promisc = true;
3868 break;
Ben Hutchings8127d662013-08-29 19:19:29 +01003869 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003870 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003871 }
Jon Cooperb6f568e2015-07-21 15:10:15 +01003872 if (mc_promisc) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003873 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3874 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003875 0);
3876 efx_filter_set_mc_def(&spec);
3877 rc = efx_ef10_filter_insert(efx, &spec, true);
3878 if (rc < 0) {
3879 WARN_ON(1);
Ben Hutchings8127d662013-08-29 19:19:29 +01003880 } else {
Jon Cooperb6f568e2015-07-21 15:10:15 +01003881 table->dev_mc_list[table->dev_mc_count++].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003882 }
3883 }
3884
3885 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003886 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003887 * don't need to hold the filter_lock while scanning for
3888 * these filters.
3889 */
3890 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3891 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003892 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003893 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003894 efx, 1U << EFX_FILTER_PRI_AUTO,
3895 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003896 remove_failed = true;
3897 }
3898 }
3899 WARN_ON(remove_failed);
3900}
3901
Daniel Pieczko7a186f42015-07-07 11:37:19 +01003902static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
3903{
3904 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3905 u8 mac_old[ETH_ALEN];
3906 int rc, rc2;
3907
3908 /* Only reconfigure a PF-created vport */
3909 if (is_zero_ether_addr(nic_data->vport_mac))
3910 return 0;
3911
3912 efx_device_detach_sync(efx);
3913 efx_net_stop(efx->net_dev);
3914 down_write(&efx->filter_sem);
3915 efx_ef10_filter_table_remove(efx);
3916 up_write(&efx->filter_sem);
3917
3918 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
3919 if (rc)
3920 goto restore_filters;
3921
3922 ether_addr_copy(mac_old, nic_data->vport_mac);
3923 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
3924 nic_data->vport_mac);
3925 if (rc)
3926 goto restore_vadaptor;
3927
3928 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
3929 efx->net_dev->dev_addr);
3930 if (!rc) {
3931 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
3932 } else {
3933 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
3934 if (rc2) {
3935 /* Failed to add original MAC, so clear vport_mac */
3936 eth_zero_addr(nic_data->vport_mac);
3937 goto reset_nic;
3938 }
3939 }
3940
3941restore_vadaptor:
3942 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
3943 if (rc2)
3944 goto reset_nic;
3945restore_filters:
3946 down_write(&efx->filter_sem);
3947 rc2 = efx_ef10_filter_table_probe(efx);
3948 up_write(&efx->filter_sem);
3949 if (rc2)
3950 goto reset_nic;
3951
3952 rc2 = efx_net_open(efx->net_dev);
3953 if (rc2)
3954 goto reset_nic;
3955
3956 netif_device_attach(efx->net_dev);
3957
3958 return rc;
3959
3960reset_nic:
3961 netif_err(efx, drv, efx->net_dev,
3962 "Failed to restore when changing MAC address - scheduling reset\n");
3963 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
3964
3965 return rc ? rc : rc2;
3966}
3967
Shradha Shah910c8782015-05-20 11:12:48 +01003968static int efx_ef10_set_mac_address(struct efx_nic *efx)
3969{
3970 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
3971 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3972 bool was_enabled = efx->port_enabled;
3973 int rc;
3974
3975 efx_device_detach_sync(efx);
3976 efx_net_stop(efx->net_dev);
3977 down_write(&efx->filter_sem);
3978 efx_ef10_filter_table_remove(efx);
3979
3980 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
3981 efx->net_dev->dev_addr);
3982 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
3983 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01003984 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
3985 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01003986
3987 efx_ef10_filter_table_probe(efx);
3988 up_write(&efx->filter_sem);
3989 if (was_enabled)
3990 efx_net_open(efx->net_dev);
3991 netif_device_attach(efx->net_dev);
3992
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01003993#ifdef CONFIG_SFC_SRIOV
3994 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01003995 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3996
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01003997 if (rc == -EPERM) {
3998 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01003999
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004000 /* Switch to PF and change MAC address on vport */
4001 efx_pf = pci_get_drvdata(pci_dev_pf);
4002
4003 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004004 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004005 efx->net_dev->dev_addr);
4006 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01004007 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
4008 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
4009 unsigned int i;
4010
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004011 /* MAC address successfully changed by VF (with MAC
4012 * spoofing) so update the parent PF if possible.
4013 */
Shradha Shah910c8782015-05-20 11:12:48 +01004014 for (i = 0; i < efx_pf->vf_count; ++i) {
4015 struct ef10_vf *vf = nic_data->vf + i;
4016
4017 if (vf->efx == efx) {
4018 ether_addr_copy(vf->mac,
4019 efx->net_dev->dev_addr);
4020 return 0;
4021 }
4022 }
4023 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004024 } else
Shradha Shah910c8782015-05-20 11:12:48 +01004025#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004026 if (rc == -EPERM) {
4027 netif_err(efx, drv, efx->net_dev,
4028 "Cannot change MAC address; use sfboot to enable"
4029 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01004030 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
4031 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
4032 * fall-back to the method of changing the MAC address on the
4033 * vport. This only applies to PFs because such versions of
4034 * MCFW do not support VFs.
4035 */
4036 rc = efx_ef10_vport_set_mac_address(efx);
Daniel Pieczko535a6172015-07-07 11:37:33 +01004037 } else {
4038 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
4039 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01004040 }
4041
Shradha Shah910c8782015-05-20 11:12:48 +01004042 return rc;
4043}
4044
Ben Hutchings8127d662013-08-29 19:19:29 +01004045static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
4046{
4047 efx_ef10_filter_sync_rx_mode(efx);
4048
4049 return efx_mcdi_set_mac(efx);
4050}
4051
Shradha Shah862f8942015-05-20 11:08:56 +01004052static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
4053{
4054 efx_ef10_filter_sync_rx_mode(efx);
4055
4056 return 0;
4057}
4058
Jon Cooper74cd60a2013-09-16 14:18:51 +01004059static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
4060{
4061 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
4062
4063 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
4064 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
4065 NULL, 0, NULL);
4066}
4067
4068/* MC BISTs follow a different poll mechanism to phy BISTs.
4069 * The BIST is done in the poll handler on the MC, and the MCDI command
4070 * will block until the BIST is done.
4071 */
4072static int efx_ef10_poll_bist(struct efx_nic *efx)
4073{
4074 int rc;
4075 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
4076 size_t outlen;
4077 u32 result;
4078
4079 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
4080 outbuf, sizeof(outbuf), &outlen);
4081 if (rc != 0)
4082 return rc;
4083
4084 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
4085 return -EIO;
4086
4087 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
4088 switch (result) {
4089 case MC_CMD_POLL_BIST_PASSED:
4090 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
4091 return 0;
4092 case MC_CMD_POLL_BIST_TIMEOUT:
4093 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
4094 return -EIO;
4095 case MC_CMD_POLL_BIST_FAILED:
4096 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
4097 return -EIO;
4098 default:
4099 netif_err(efx, hw, efx->net_dev,
4100 "BIST returned unknown result %u", result);
4101 return -EIO;
4102 }
4103}
4104
4105static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
4106{
4107 int rc;
4108
4109 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
4110
4111 rc = efx_ef10_start_bist(efx, bist_type);
4112 if (rc != 0)
4113 return rc;
4114
4115 return efx_ef10_poll_bist(efx);
4116}
4117
4118static int
4119efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
4120{
4121 int rc, rc2;
4122
4123 efx_reset_down(efx, RESET_TYPE_WORLD);
4124
4125 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
4126 NULL, 0, NULL, 0, NULL);
4127 if (rc != 0)
4128 goto out;
4129
4130 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
4131 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
4132
4133 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
4134
4135out:
4136 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
4137 return rc ? rc : rc2;
4138}
4139
Ben Hutchings8127d662013-08-29 19:19:29 +01004140#ifdef CONFIG_SFC_MTD
4141
4142struct efx_ef10_nvram_type_info {
4143 u16 type, type_mask;
4144 u8 port;
4145 const char *name;
4146};
4147
4148static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
4149 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
4150 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
4151 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
4152 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
4153 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
4154 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
4155 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
4156 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
4157 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01004158 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01004159 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
4160};
4161
4162static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
4163 struct efx_mcdi_mtd_partition *part,
4164 unsigned int type)
4165{
4166 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
4167 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
4168 const struct efx_ef10_nvram_type_info *info;
4169 size_t size, erase_size, outlen;
4170 bool protected;
4171 int rc;
4172
4173 for (info = efx_ef10_nvram_types; ; info++) {
4174 if (info ==
4175 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
4176 return -ENODEV;
4177 if ((type & ~info->type_mask) == info->type)
4178 break;
4179 }
4180 if (info->port != efx_port_num(efx))
4181 return -ENODEV;
4182
4183 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
4184 if (rc)
4185 return rc;
4186 if (protected)
4187 return -ENODEV; /* hide it */
4188
4189 part->nvram_type = type;
4190
4191 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
4192 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
4193 outbuf, sizeof(outbuf), &outlen);
4194 if (rc)
4195 return rc;
4196 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
4197 return -EIO;
4198 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
4199 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
4200 part->fw_subtype = MCDI_DWORD(outbuf,
4201 NVRAM_METADATA_OUT_SUBTYPE);
4202
4203 part->common.dev_type_name = "EF10 NVRAM manager";
4204 part->common.type_name = info->name;
4205
4206 part->common.mtd.type = MTD_NORFLASH;
4207 part->common.mtd.flags = MTD_CAP_NORFLASH;
4208 part->common.mtd.size = size;
4209 part->common.mtd.erasesize = erase_size;
4210
4211 return 0;
4212}
4213
4214static int efx_ef10_mtd_probe(struct efx_nic *efx)
4215{
4216 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
4217 struct efx_mcdi_mtd_partition *parts;
4218 size_t outlen, n_parts_total, i, n_parts;
4219 unsigned int type;
4220 int rc;
4221
4222 ASSERT_RTNL();
4223
4224 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
4225 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
4226 outbuf, sizeof(outbuf), &outlen);
4227 if (rc)
4228 return rc;
4229 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
4230 return -EIO;
4231
4232 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
4233 if (n_parts_total >
4234 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
4235 return -EIO;
4236
4237 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
4238 if (!parts)
4239 return -ENOMEM;
4240
4241 n_parts = 0;
4242 for (i = 0; i < n_parts_total; i++) {
4243 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
4244 i);
4245 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
4246 if (rc == 0)
4247 n_parts++;
4248 else if (rc != -ENODEV)
4249 goto fail;
4250 }
4251
4252 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
4253fail:
4254 if (rc)
4255 kfree(parts);
4256 return rc;
4257}
4258
4259#endif /* CONFIG_SFC_MTD */
4260
4261static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
4262{
4263 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
4264}
4265
Shradha Shah02246a72015-05-06 00:58:14 +01004266static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
4267 u32 host_time) {}
4268
Jon Cooperbd9a2652013-11-18 12:54:41 +00004269static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
4270 bool temp)
4271{
4272 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
4273 int rc;
4274
4275 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
4276 channel->sync_events_state == SYNC_EVENTS_VALID ||
4277 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
4278 return 0;
4279 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
4280
4281 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
4282 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4283 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
4284 channel->channel);
4285
4286 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4287 inbuf, sizeof(inbuf), NULL, 0, NULL);
4288
4289 if (rc != 0)
4290 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4291 SYNC_EVENTS_DISABLED;
4292
4293 return rc;
4294}
4295
4296static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
4297 bool temp)
4298{
4299 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
4300 int rc;
4301
4302 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
4303 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
4304 return 0;
4305 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
4306 channel->sync_events_state = SYNC_EVENTS_DISABLED;
4307 return 0;
4308 }
4309 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4310 SYNC_EVENTS_DISABLED;
4311
4312 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
4313 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4314 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
4315 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
4316 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
4317 channel->channel);
4318
4319 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4320 inbuf, sizeof(inbuf), NULL, 0, NULL);
4321
4322 return rc;
4323}
4324
4325static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
4326 bool temp)
4327{
4328 int (*set)(struct efx_channel *channel, bool temp);
4329 struct efx_channel *channel;
4330
4331 set = en ?
4332 efx_ef10_rx_enable_timestamping :
4333 efx_ef10_rx_disable_timestamping;
4334
4335 efx_for_each_channel(channel, efx) {
4336 int rc = set(channel, temp);
4337 if (en && rc != 0) {
4338 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
4339 return rc;
4340 }
4341 }
4342
4343 return 0;
4344}
4345
Shradha Shah02246a72015-05-06 00:58:14 +01004346static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
4347 struct hwtstamp_config *init)
4348{
4349 return -EOPNOTSUPP;
4350}
4351
Jon Cooperbd9a2652013-11-18 12:54:41 +00004352static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
4353 struct hwtstamp_config *init)
4354{
4355 int rc;
4356
4357 switch (init->rx_filter) {
4358 case HWTSTAMP_FILTER_NONE:
4359 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
4360 /* if TX timestamping is still requested then leave PTP on */
4361 return efx_ptp_change_mode(efx,
4362 init->tx_type != HWTSTAMP_TX_OFF, 0);
4363 case HWTSTAMP_FILTER_ALL:
4364 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
4365 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
4366 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
4367 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
4368 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
4369 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
4370 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
4371 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
4372 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
4373 case HWTSTAMP_FILTER_PTP_V2_EVENT:
4374 case HWTSTAMP_FILTER_PTP_V2_SYNC:
4375 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
4376 init->rx_filter = HWTSTAMP_FILTER_ALL;
4377 rc = efx_ptp_change_mode(efx, true, 0);
4378 if (!rc)
4379 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
4380 if (rc)
4381 efx_ptp_change_mode(efx, false, 0);
4382 return rc;
4383 default:
4384 return -ERANGE;
4385 }
4386}
4387
Shradha Shah02246a72015-05-06 00:58:14 +01004388const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004389 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01004390 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01004391 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01004392 .probe = efx_ef10_probe_vf,
4393 .remove = efx_ef10_remove,
4394 .dimension_resources = efx_ef10_dimension_resources,
4395 .init = efx_ef10_init_nic,
4396 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004397 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01004398 .map_reset_flags = efx_ef10_map_reset_flags,
4399 .reset = efx_ef10_reset,
4400 .probe_port = efx_mcdi_port_probe,
4401 .remove_port = efx_mcdi_port_remove,
4402 .fini_dmaq = efx_ef10_fini_dmaq,
4403 .prepare_flr = efx_ef10_prepare_flr,
4404 .finish_flr = efx_port_dummy_op_void,
4405 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004406 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004407 .start_stats = efx_port_dummy_op_void,
4408 .pull_stats = efx_port_dummy_op_void,
4409 .stop_stats = efx_port_dummy_op_void,
4410 .set_id_led = efx_mcdi_set_id_led,
4411 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01004412 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004413 .check_mac_fault = efx_mcdi_mac_check_fault,
4414 .reconfigure_port = efx_mcdi_port_reconfigure,
4415 .get_wol = efx_ef10_get_wol_vf,
4416 .set_wol = efx_ef10_set_wol_vf,
4417 .resume_wol = efx_port_dummy_op_void,
4418 .mcdi_request = efx_ef10_mcdi_request,
4419 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4420 .mcdi_read_response = efx_ef10_mcdi_read_response,
4421 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4422 .irq_enable_master = efx_port_dummy_op_void,
4423 .irq_test_generate = efx_ef10_irq_test_generate,
4424 .irq_disable_non_ev = efx_port_dummy_op_void,
4425 .irq_handle_msi = efx_ef10_msi_interrupt,
4426 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4427 .tx_probe = efx_ef10_tx_probe,
4428 .tx_init = efx_ef10_tx_init,
4429 .tx_remove = efx_ef10_tx_remove,
4430 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004431 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01004432 .rx_probe = efx_ef10_rx_probe,
4433 .rx_init = efx_ef10_rx_init,
4434 .rx_remove = efx_ef10_rx_remove,
4435 .rx_write = efx_ef10_rx_write,
4436 .rx_defer_refill = efx_ef10_rx_defer_refill,
4437 .ev_probe = efx_ef10_ev_probe,
4438 .ev_init = efx_ef10_ev_init,
4439 .ev_fini = efx_ef10_ev_fini,
4440 .ev_remove = efx_ef10_ev_remove,
4441 .ev_process = efx_ef10_ev_process,
4442 .ev_read_ack = efx_ef10_ev_read_ack,
4443 .ev_test_generate = efx_ef10_ev_test_generate,
4444 .filter_table_probe = efx_ef10_filter_table_probe,
4445 .filter_table_restore = efx_ef10_filter_table_restore,
4446 .filter_table_remove = efx_ef10_filter_table_remove,
4447 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4448 .filter_insert = efx_ef10_filter_insert,
4449 .filter_remove_safe = efx_ef10_filter_remove_safe,
4450 .filter_get_safe = efx_ef10_filter_get_safe,
4451 .filter_clear_rx = efx_ef10_filter_clear_rx,
4452 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4453 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4454 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4455#ifdef CONFIG_RFS_ACCEL
4456 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4457 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4458#endif
4459#ifdef CONFIG_SFC_MTD
4460 .mtd_probe = efx_port_dummy_op_int,
4461#endif
4462 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4463 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4464#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004465 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4466 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4467 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01004468 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01004469#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004470 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01004471 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004472
Shradha Shah02246a72015-05-06 00:58:14 +01004473 .revision = EFX_REV_HUNT_A0,
4474 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4475 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4476 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4477 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4478 .can_rx_scatter = true,
4479 .always_rx_scatter = true,
4480 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4481 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4482 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4483 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4484 .mcdi_max_ver = 2,
4485 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4486 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4487 1 << HWTSTAMP_FILTER_ALL,
4488};
4489
4490const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004491 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004492 .mem_bar = EFX_MEM_BAR,
4493 .mem_map_size = efx_ef10_mem_map_size,
4494 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004495 .remove = efx_ef10_remove,
4496 .dimension_resources = efx_ef10_dimension_resources,
4497 .init = efx_ef10_init_nic,
4498 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004499 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01004500 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004501 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004502 .probe_port = efx_mcdi_port_probe,
4503 .remove_port = efx_mcdi_port_remove,
4504 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004505 .prepare_flr = efx_ef10_prepare_flr,
4506 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004507 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004508 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004509 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004510 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004511 .stop_stats = efx_mcdi_mac_stop_stats,
4512 .set_id_led = efx_mcdi_set_id_led,
4513 .push_irq_moderation = efx_ef10_push_irq_moderation,
4514 .reconfigure_mac = efx_ef10_mac_reconfigure,
4515 .check_mac_fault = efx_mcdi_mac_check_fault,
4516 .reconfigure_port = efx_mcdi_port_reconfigure,
4517 .get_wol = efx_ef10_get_wol,
4518 .set_wol = efx_ef10_set_wol,
4519 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004520 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004521 .test_nvram = efx_mcdi_nvram_test_all,
4522 .mcdi_request = efx_ef10_mcdi_request,
4523 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4524 .mcdi_read_response = efx_ef10_mcdi_read_response,
4525 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4526 .irq_enable_master = efx_port_dummy_op_void,
4527 .irq_test_generate = efx_ef10_irq_test_generate,
4528 .irq_disable_non_ev = efx_port_dummy_op_void,
4529 .irq_handle_msi = efx_ef10_msi_interrupt,
4530 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4531 .tx_probe = efx_ef10_tx_probe,
4532 .tx_init = efx_ef10_tx_init,
4533 .tx_remove = efx_ef10_tx_remove,
4534 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004535 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004536 .rx_probe = efx_ef10_rx_probe,
4537 .rx_init = efx_ef10_rx_init,
4538 .rx_remove = efx_ef10_rx_remove,
4539 .rx_write = efx_ef10_rx_write,
4540 .rx_defer_refill = efx_ef10_rx_defer_refill,
4541 .ev_probe = efx_ef10_ev_probe,
4542 .ev_init = efx_ef10_ev_init,
4543 .ev_fini = efx_ef10_ev_fini,
4544 .ev_remove = efx_ef10_ev_remove,
4545 .ev_process = efx_ef10_ev_process,
4546 .ev_read_ack = efx_ef10_ev_read_ack,
4547 .ev_test_generate = efx_ef10_ev_test_generate,
4548 .filter_table_probe = efx_ef10_filter_table_probe,
4549 .filter_table_restore = efx_ef10_filter_table_restore,
4550 .filter_table_remove = efx_ef10_filter_table_remove,
4551 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4552 .filter_insert = efx_ef10_filter_insert,
4553 .filter_remove_safe = efx_ef10_filter_remove_safe,
4554 .filter_get_safe = efx_ef10_filter_get_safe,
4555 .filter_clear_rx = efx_ef10_filter_clear_rx,
4556 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4557 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4558 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4559#ifdef CONFIG_RFS_ACCEL
4560 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4561 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4562#endif
4563#ifdef CONFIG_SFC_MTD
4564 .mtd_probe = efx_ef10_mtd_probe,
4565 .mtd_rename = efx_mcdi_mtd_rename,
4566 .mtd_read = efx_mcdi_mtd_read,
4567 .mtd_erase = efx_mcdi_mtd_erase,
4568 .mtd_write = efx_mcdi_mtd_write,
4569 .mtd_sync = efx_mcdi_mtd_sync,
4570#endif
4571 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004572 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4573 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004574#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004575 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004576 .sriov_init = efx_ef10_sriov_init,
4577 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004578 .sriov_wanted = efx_ef10_sriov_wanted,
4579 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004580 .sriov_flr = efx_ef10_sriov_flr,
4581 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4582 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4583 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4584 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01004585 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004586 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4587 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4588 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004589#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004590 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004591 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01004592
4593 .revision = EFX_REV_HUNT_A0,
4594 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4595 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4596 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004597 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004598 .can_rx_scatter = true,
4599 .always_rx_scatter = true,
4600 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4601 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4602 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4603 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4604 .mcdi_max_ver = 2,
4605 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004606 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4607 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004608};