blob: 03f464fdd2b90ab7508173762f57f00ef2f5b605 [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 Pieczko1cd9ecb2015-05-06 00:57:53 +0100104static int efx_ef10_get_pf_index(struct efx_nic *efx)
105{
106 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
107 struct efx_ef10_nic_data *nic_data = efx->nic_data;
108 size_t outlen;
109 int rc;
110
111 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
112 sizeof(outbuf), &outlen);
113 if (rc)
114 return rc;
115 if (outlen < sizeof(outbuf))
116 return -EIO;
117
118 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
119 return 0;
120}
121
Shradha Shah88a37de2015-05-20 11:09:15 +0100122#ifdef CONFIG_SFC_SRIOV
123static int efx_ef10_get_vf_index(struct efx_nic *efx)
124{
125 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
126 struct efx_ef10_nic_data *nic_data = efx->nic_data;
127 size_t outlen;
128 int rc;
129
130 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
131 sizeof(outbuf), &outlen);
132 if (rc)
133 return rc;
134 if (outlen < sizeof(outbuf))
135 return -EIO;
136
137 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
138 return 0;
139}
140#endif
141
Ben Hutchingse5a25382013-09-05 22:50:59 +0100142static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100143{
144 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN);
145 struct efx_ef10_nic_data *nic_data = efx->nic_data;
146 size_t outlen;
147 int rc;
148
149 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
150
151 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
152 outbuf, sizeof(outbuf), &outlen);
153 if (rc)
154 return rc;
Ben Hutchingse5a25382013-09-05 22:50:59 +0100155 if (outlen < sizeof(outbuf)) {
156 netif_err(efx, drv, efx->net_dev,
157 "unable to read datapath firmware capabilities\n");
158 return -EIO;
159 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100160
Ben Hutchingse5a25382013-09-05 22:50:59 +0100161 nic_data->datapath_caps =
162 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
163
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100164 /* record the DPCPU firmware IDs to determine VEB vswitching support.
165 */
166 nic_data->rx_dpcpu_fw_id =
167 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
168 nic_data->tx_dpcpu_fw_id =
169 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
170
Ben Hutchingse5a25382013-09-05 22:50:59 +0100171 if (!(nic_data->datapath_caps &
172 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) {
173 netif_err(efx, drv, efx->net_dev,
174 "current firmware does not support TSO\n");
175 return -ENODEV;
176 }
177
178 if (!(nic_data->datapath_caps &
179 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
180 netif_err(efx, probe, efx->net_dev,
181 "current firmware does not support an RX prefix\n");
182 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100183 }
184
185 return 0;
186}
187
188static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
189{
190 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
191 int rc;
192
193 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
194 outbuf, sizeof(outbuf), NULL);
195 if (rc)
196 return rc;
197 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
198 return rc > 0 ? rc : -ERANGE;
199}
200
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100201static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100202{
203 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
204 size_t outlen;
205 int rc;
206
207 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
208
209 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
210 outbuf, sizeof(outbuf), &outlen);
211 if (rc)
212 return rc;
213 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
214 return -EIO;
215
Edward Creecd84ff42014-03-07 18:27:41 +0000216 ether_addr_copy(mac_address,
217 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100218 return 0;
219}
220
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100221static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
222{
223 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
224 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
225 size_t outlen;
226 int num_addrs, rc;
227
228 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
229 EVB_PORT_ID_ASSIGNED);
230 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
231 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
232
233 if (rc)
234 return rc;
235 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
236 return -EIO;
237
238 num_addrs = MCDI_DWORD(outbuf,
239 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
240
241 WARN_ON(num_addrs != 1);
242
243 ether_addr_copy(mac_address,
244 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
245
246 return 0;
247}
248
Shradha Shah0f5c0842015-06-02 11:37:58 +0100249static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
250 struct device_attribute *attr,
251 char *buf)
252{
253 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
254
255 return sprintf(buf, "%d\n",
256 ((efx->mcdi->fn_flags) &
257 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
258 ? 1 : 0);
259}
260
261static ssize_t efx_ef10_show_primary_flag(struct device *dev,
262 struct device_attribute *attr,
263 char *buf)
264{
265 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
266
267 return sprintf(buf, "%d\n",
268 ((efx->mcdi->fn_flags) &
269 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
270 ? 1 : 0);
271}
272
273static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
274 NULL);
275static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
276
Ben Hutchings8127d662013-08-29 19:19:29 +0100277static int efx_ef10_probe(struct efx_nic *efx)
278{
279 struct efx_ef10_nic_data *nic_data;
Shradha Shah8be41322015-06-02 11:37:25 +0100280 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100281 int i, rc;
282
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000283 /* We can have one VI for each 8K region. However, until we
284 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100285 */
286 efx->max_channels =
287 min_t(unsigned int,
288 EFX_MAX_CHANNELS,
Shradha Shah02246a72015-05-06 00:58:14 +0100289 efx_ef10_mem_map_size(efx) /
Ben Hutchings8127d662013-08-29 19:19:29 +0100290 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000291 if (WARN_ON(efx->max_channels == 0))
292 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100293
294 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
295 if (!nic_data)
296 return -ENOMEM;
297 efx->nic_data = nic_data;
298
Edward Cree75aba2a2015-05-27 13:13:54 +0100299 /* we assume later that we can copy from this buffer in dwords */
300 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
301
Ben Hutchings8127d662013-08-29 19:19:29 +0100302 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
303 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
304 if (rc)
305 goto fail1;
306
307 /* Get the MC's warm boot count. In case it's rebooting right
308 * now, be prepared to retry.
309 */
310 i = 0;
311 for (;;) {
312 rc = efx_ef10_get_warm_boot_count(efx);
313 if (rc >= 0)
314 break;
315 if (++i == 5)
316 goto fail2;
317 ssleep(1);
318 }
319 nic_data->warm_boot_count = rc;
320
321 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
322
Daniel Pieczko45b24492015-05-06 00:57:14 +0100323 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
324
Ben Hutchings8127d662013-08-29 19:19:29 +0100325 /* In case we're recovering from a crash (kexec), we want to
326 * cancel any outstanding request by the previous user of this
327 * function. We send a special message using the least
328 * significant bits of the 'high' (doorbell) register.
329 */
330 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
331
332 rc = efx_mcdi_init(efx);
333 if (rc)
334 goto fail2;
335
336 /* Reset (most) configuration for this function */
337 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
338 if (rc)
339 goto fail3;
340
341 /* Enable event logging */
342 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
343 if (rc)
344 goto fail3;
345
Shradha Shah0f5c0842015-06-02 11:37:58 +0100346 rc = device_create_file(&efx->pci_dev->dev,
347 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100348 if (rc)
349 goto fail3;
350
Shradha Shah0f5c0842015-06-02 11:37:58 +0100351 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
352 if (rc)
353 goto fail4;
354
355 rc = efx_ef10_get_pf_index(efx);
356 if (rc)
357 goto fail5;
358
Ben Hutchingse5a25382013-09-05 22:50:59 +0100359 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100360 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100361 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100362
363 efx->rx_packet_len_offset =
364 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
365
Ben Hutchings8127d662013-08-29 19:19:29 +0100366 rc = efx_mcdi_port_get_number(efx);
367 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100368 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100369 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100370 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100371
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100372 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100373 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100374 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100375
376 rc = efx_ef10_get_sysclk_freq(efx);
377 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100378 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100379 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
380
Edward Cree267d9d72015-05-06 00:59:18 +0100381 /* Check whether firmware supports bug 35388 workaround.
382 * First try to enable it, then if we get EPERM, just
383 * ask if it's already enabled
384 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100385 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true);
Shradha Shahc9012e02015-06-02 11:37:41 +0100386 if (rc == 0) {
Ben Hutchings8127d662013-08-29 19:19:29 +0100387 nic_data->workaround_35388 = true;
Shradha Shahc9012e02015-06-02 11:37:41 +0100388 } else if (rc == -EPERM) {
Edward Cree267d9d72015-05-06 00:59:18 +0100389 unsigned int enabled;
390
391 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
392 if (rc)
393 goto fail3;
394 nic_data->workaround_35388 = enabled &
395 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
Shradha Shahc9012e02015-06-02 11:37:41 +0100396 } else if (rc != -ENOSYS && rc != -ENOENT) {
Shradha Shah0f5c0842015-06-02 11:37:58 +0100397 goto fail5;
Shradha Shahc9012e02015-06-02 11:37:41 +0100398 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100399 netif_dbg(efx, probe, efx->net_dev,
400 "workaround for bug 35388 is %sabled\n",
401 nic_data->workaround_35388 ? "en" : "dis");
402
403 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100404 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100405 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100406
Ben Hutchings9aecda92013-12-05 21:28:42 +0000407 efx_ptp_probe(efx, NULL);
408
Shradha Shah1d051e02015-06-02 11:38:16 +0100409#ifdef CONFIG_SFC_SRIOV
410 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
411 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
412 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
413
414 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
415 } else
416#endif
417 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
418
Ben Hutchings8127d662013-08-29 19:19:29 +0100419 return 0;
420
Shradha Shah0f5c0842015-06-02 11:37:58 +0100421fail5:
422 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
423fail4:
424 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100425fail3:
426 efx_mcdi_fini(efx);
427fail2:
428 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
429fail1:
430 kfree(nic_data);
431 efx->nic_data = NULL;
432 return rc;
433}
434
435static int efx_ef10_free_vis(struct efx_nic *efx)
436{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100437 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100438 size_t outlen;
439 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
440 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100441
442 /* -EALREADY means nothing to free, so ignore */
443 if (rc == -EALREADY)
444 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100445 if (rc)
446 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
447 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100448 return rc;
449}
450
Ben Hutchings183233b2013-06-28 21:47:12 +0100451#ifdef EFX_USE_PIO
452
453static void efx_ef10_free_piobufs(struct efx_nic *efx)
454{
455 struct efx_ef10_nic_data *nic_data = efx->nic_data;
456 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
457 unsigned int i;
458 int rc;
459
460 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
461
462 for (i = 0; i < nic_data->n_piobufs; i++) {
463 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
464 nic_data->piobuf_handle[i]);
465 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
466 NULL, 0, NULL);
467 WARN_ON(rc);
468 }
469
470 nic_data->n_piobufs = 0;
471}
472
473static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
474{
475 struct efx_ef10_nic_data *nic_data = efx->nic_data;
476 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
477 unsigned int i;
478 size_t outlen;
479 int rc = 0;
480
481 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
482
483 for (i = 0; i < n; i++) {
484 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
485 outbuf, sizeof(outbuf), &outlen);
486 if (rc)
487 break;
488 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
489 rc = -EIO;
490 break;
491 }
492 nic_data->piobuf_handle[i] =
493 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
494 netif_dbg(efx, probe, efx->net_dev,
495 "allocated PIO buffer %u handle %x\n", i,
496 nic_data->piobuf_handle[i]);
497 }
498
499 nic_data->n_piobufs = i;
500 if (rc)
501 efx_ef10_free_piobufs(efx);
502 return rc;
503}
504
505static int efx_ef10_link_piobufs(struct efx_nic *efx)
506{
507 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100508 _MCDI_DECLARE_BUF(inbuf,
509 max(MC_CMD_LINK_PIOBUF_IN_LEN,
510 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100511 struct efx_channel *channel;
512 struct efx_tx_queue *tx_queue;
513 unsigned int offset, index;
514 int rc;
515
516 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
517 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
518
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100519 memset(inbuf, 0, sizeof(inbuf));
520
Ben Hutchings183233b2013-06-28 21:47:12 +0100521 /* Link a buffer to each VI in the write-combining mapping */
522 for (index = 0; index < nic_data->n_piobufs; ++index) {
523 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
524 nic_data->piobuf_handle[index]);
525 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
526 nic_data->pio_write_vi_base + index);
527 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
528 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
529 NULL, 0, NULL);
530 if (rc) {
531 netif_err(efx, drv, efx->net_dev,
532 "failed to link VI %u to PIO buffer %u (%d)\n",
533 nic_data->pio_write_vi_base + index, index,
534 rc);
535 goto fail;
536 }
537 netif_dbg(efx, probe, efx->net_dev,
538 "linked VI %u to PIO buffer %u\n",
539 nic_data->pio_write_vi_base + index, index);
540 }
541
542 /* Link a buffer to each TX queue */
543 efx_for_each_channel(channel, efx) {
544 efx_for_each_channel_tx_queue(tx_queue, channel) {
545 /* We assign the PIO buffers to queues in
546 * reverse order to allow for the following
547 * special case.
548 */
549 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
550 tx_queue->channel->channel - 1) *
551 efx_piobuf_size);
552 index = offset / ER_DZ_TX_PIOBUF_SIZE;
553 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
554
555 /* When the host page size is 4K, the first
556 * host page in the WC mapping may be within
557 * the same VI page as the last TX queue. We
558 * can only link one buffer to each VI.
559 */
560 if (tx_queue->queue == nic_data->pio_write_vi_base) {
561 BUG_ON(index != 0);
562 rc = 0;
563 } else {
564 MCDI_SET_DWORD(inbuf,
565 LINK_PIOBUF_IN_PIOBUF_HANDLE,
566 nic_data->piobuf_handle[index]);
567 MCDI_SET_DWORD(inbuf,
568 LINK_PIOBUF_IN_TXQ_INSTANCE,
569 tx_queue->queue);
570 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
571 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
572 NULL, 0, NULL);
573 }
574
575 if (rc) {
576 /* This is non-fatal; the TX path just
577 * won't use PIO for this queue
578 */
579 netif_err(efx, drv, efx->net_dev,
580 "failed to link VI %u to PIO buffer %u (%d)\n",
581 tx_queue->queue, index, rc);
582 tx_queue->piobuf = NULL;
583 } else {
584 tx_queue->piobuf =
585 nic_data->pio_write_base +
586 index * EFX_VI_PAGE_SIZE + offset;
587 tx_queue->piobuf_offset = offset;
588 netif_dbg(efx, probe, efx->net_dev,
589 "linked VI %u to PIO buffer %u offset %x addr %p\n",
590 tx_queue->queue, index,
591 tx_queue->piobuf_offset,
592 tx_queue->piobuf);
593 }
594 }
595 }
596
597 return 0;
598
599fail:
600 while (index--) {
601 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
602 nic_data->pio_write_vi_base + index);
603 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
604 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
605 NULL, 0, NULL);
606 }
607 return rc;
608}
609
610#else /* !EFX_USE_PIO */
611
612static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
613{
614 return n == 0 ? 0 : -ENOBUFS;
615}
616
617static int efx_ef10_link_piobufs(struct efx_nic *efx)
618{
619 return 0;
620}
621
622static void efx_ef10_free_piobufs(struct efx_nic *efx)
623{
624}
625
626#endif /* EFX_USE_PIO */
627
Ben Hutchings8127d662013-08-29 19:19:29 +0100628static void efx_ef10_remove(struct efx_nic *efx)
629{
630 struct efx_ef10_nic_data *nic_data = efx->nic_data;
631 int rc;
632
Shradha Shahf1122a32015-05-20 11:09:46 +0100633#ifdef CONFIG_SFC_SRIOV
634 struct efx_ef10_nic_data *nic_data_pf;
635 struct pci_dev *pci_dev_pf;
636 struct efx_nic *efx_pf;
637 struct ef10_vf *vf;
638
639 if (efx->pci_dev->is_virtfn) {
640 pci_dev_pf = efx->pci_dev->physfn;
641 if (pci_dev_pf) {
642 efx_pf = pci_get_drvdata(pci_dev_pf);
643 nic_data_pf = efx_pf->nic_data;
644 vf = nic_data_pf->vf + nic_data->vf_index;
645 vf->efx = NULL;
646 } else
647 netif_info(efx, drv, efx->net_dev,
648 "Could not get the PF id from VF\n");
649 }
650#endif
651
Ben Hutchings9aecda92013-12-05 21:28:42 +0000652 efx_ptp_remove(efx);
653
Ben Hutchings8127d662013-08-29 19:19:29 +0100654 efx_mcdi_mon_remove(efx);
655
Ben Hutchings8127d662013-08-29 19:19:29 +0100656 efx_ef10_rx_free_indir_table(efx);
657
Ben Hutchings183233b2013-06-28 21:47:12 +0100658 if (nic_data->wc_membase)
659 iounmap(nic_data->wc_membase);
660
Ben Hutchings8127d662013-08-29 19:19:29 +0100661 rc = efx_ef10_free_vis(efx);
662 WARN_ON(rc != 0);
663
Ben Hutchings183233b2013-06-28 21:47:12 +0100664 if (!nic_data->must_restore_piobufs)
665 efx_ef10_free_piobufs(efx);
666
Shradha Shah0f5c0842015-06-02 11:37:58 +0100667 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
668 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
669
Ben Hutchings8127d662013-08-29 19:19:29 +0100670 efx_mcdi_fini(efx);
671 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
672 kfree(nic_data);
673}
674
Shradha Shah88a37de2015-05-20 11:09:15 +0100675static int efx_ef10_probe_pf(struct efx_nic *efx)
676{
677 return efx_ef10_probe(efx);
678}
679
680#ifdef CONFIG_SFC_SRIOV
681static int efx_ef10_probe_vf(struct efx_nic *efx)
682{
683 int rc;
684
685 rc = efx_ef10_probe(efx);
686 if (rc)
687 return rc;
688
689 rc = efx_ef10_get_vf_index(efx);
690 if (rc)
691 goto fail;
692
Shradha Shahf1122a32015-05-20 11:09:46 +0100693 if (efx->pci_dev->is_virtfn) {
694 if (efx->pci_dev->physfn) {
695 struct efx_nic *efx_pf =
696 pci_get_drvdata(efx->pci_dev->physfn);
697 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
698 struct efx_ef10_nic_data *nic_data = efx->nic_data;
699
700 nic_data_p->vf[nic_data->vf_index].efx = efx;
701 } else
702 netif_info(efx, drv, efx->net_dev,
703 "Could not get the PF id from VF\n");
704 }
705
Shradha Shah88a37de2015-05-20 11:09:15 +0100706 return 0;
707
708fail:
709 efx_ef10_remove(efx);
710 return rc;
711}
712#else
713static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
714{
715 return 0;
716}
717#endif
718
Ben Hutchings8127d662013-08-29 19:19:29 +0100719static int efx_ef10_alloc_vis(struct efx_nic *efx,
720 unsigned int min_vis, unsigned int max_vis)
721{
722 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
723 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
724 struct efx_ef10_nic_data *nic_data = efx->nic_data;
725 size_t outlen;
726 int rc;
727
728 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
729 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
730 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
731 outbuf, sizeof(outbuf), &outlen);
732 if (rc != 0)
733 return rc;
734
735 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
736 return -EIO;
737
738 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
739 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
740
741 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
742 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
743 return 0;
744}
745
Ben Hutchings183233b2013-06-28 21:47:12 +0100746/* Note that the failure path of this function does not free
747 * resources, as this will be done by efx_ef10_remove().
748 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100749static int efx_ef10_dimension_resources(struct efx_nic *efx)
750{
Ben Hutchings183233b2013-06-28 21:47:12 +0100751 struct efx_ef10_nic_data *nic_data = efx->nic_data;
752 unsigned int uc_mem_map_size, wc_mem_map_size;
753 unsigned int min_vis, pio_write_vi_base, max_vis;
754 void __iomem *membase;
755 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100756
Ben Hutchings183233b2013-06-28 21:47:12 +0100757 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
758
759#ifdef EFX_USE_PIO
760 /* Try to allocate PIO buffers if wanted and if the full
761 * number of PIO buffers would be sufficient to allocate one
762 * copy-buffer per TX channel. Failure is non-fatal, as there
763 * are only a small number of PIO buffers shared between all
764 * functions of the controller.
765 */
766 if (efx_piobuf_size != 0 &&
767 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
768 efx->n_tx_channels) {
769 unsigned int n_piobufs =
770 DIV_ROUND_UP(efx->n_tx_channels,
771 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
772
773 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
774 if (rc)
775 netif_err(efx, probe, efx->net_dev,
776 "failed to allocate PIO buffers (%d)\n", rc);
777 else
778 netif_dbg(efx, probe, efx->net_dev,
779 "allocated %u PIO buffers\n", n_piobufs);
780 }
781#else
782 nic_data->n_piobufs = 0;
783#endif
784
785 /* PIO buffers should be mapped with write-combining enabled,
786 * and we want to make single UC and WC mappings rather than
787 * several of each (in fact that's the only option if host
788 * page size is >4K). So we may allocate some extra VIs just
789 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100790 *
791 * The UC mapping contains (min_vis - 1) complete VIs and the
792 * first half of the next VI. Then the WC mapping begins with
793 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100794 */
795 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
796 ER_DZ_TX_PIOBUF);
797 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100798 /* pio_write_vi_base rounds down to give the number of complete
799 * VIs inside the UC mapping.
800 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100801 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
802 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
803 nic_data->n_piobufs) *
804 EFX_VI_PAGE_SIZE) -
805 uc_mem_map_size);
806 max_vis = pio_write_vi_base + nic_data->n_piobufs;
807 } else {
808 pio_write_vi_base = 0;
809 wc_mem_map_size = 0;
810 max_vis = min_vis;
811 }
812
813 /* In case the last attached driver failed to free VIs, do it now */
814 rc = efx_ef10_free_vis(efx);
815 if (rc != 0)
816 return rc;
817
818 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
819 if (rc != 0)
820 return rc;
821
822 /* If we didn't get enough VIs to map all the PIO buffers, free the
823 * PIO buffers
824 */
825 if (nic_data->n_piobufs &&
826 nic_data->n_allocated_vis <
827 pio_write_vi_base + nic_data->n_piobufs) {
828 netif_dbg(efx, probe, efx->net_dev,
829 "%u VIs are not sufficient to map %u PIO buffers\n",
830 nic_data->n_allocated_vis, nic_data->n_piobufs);
831 efx_ef10_free_piobufs(efx);
832 }
833
834 /* Shrink the original UC mapping of the memory BAR */
835 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
836 if (!membase) {
837 netif_err(efx, probe, efx->net_dev,
838 "could not shrink memory BAR to %x\n",
839 uc_mem_map_size);
840 return -ENOMEM;
841 }
842 iounmap(efx->membase);
843 efx->membase = membase;
844
845 /* Set up the WC mapping if needed */
846 if (wc_mem_map_size) {
847 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
848 uc_mem_map_size,
849 wc_mem_map_size);
850 if (!nic_data->wc_membase) {
851 netif_err(efx, probe, efx->net_dev,
852 "could not allocate WC mapping of size %x\n",
853 wc_mem_map_size);
854 return -ENOMEM;
855 }
856 nic_data->pio_write_vi_base = pio_write_vi_base;
857 nic_data->pio_write_base =
858 nic_data->wc_membase +
859 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
860 uc_mem_map_size);
861
862 rc = efx_ef10_link_piobufs(efx);
863 if (rc)
864 efx_ef10_free_piobufs(efx);
865 }
866
867 netif_dbg(efx, probe, efx->net_dev,
868 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
869 &efx->membase_phys, efx->membase, uc_mem_map_size,
870 nic_data->wc_membase, wc_mem_map_size);
871
872 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100873}
874
875static int efx_ef10_init_nic(struct efx_nic *efx)
876{
877 struct efx_ef10_nic_data *nic_data = efx->nic_data;
878 int rc;
879
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100880 if (nic_data->must_check_datapath_caps) {
881 rc = efx_ef10_init_datapath_caps(efx);
882 if (rc)
883 return rc;
884 nic_data->must_check_datapath_caps = false;
885 }
886
Ben Hutchings8127d662013-08-29 19:19:29 +0100887 if (nic_data->must_realloc_vis) {
888 /* We cannot let the number of VIs change now */
889 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
890 nic_data->n_allocated_vis);
891 if (rc)
892 return rc;
893 nic_data->must_realloc_vis = false;
894 }
895
Ben Hutchings183233b2013-06-28 21:47:12 +0100896 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
897 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
898 if (rc == 0) {
899 rc = efx_ef10_link_piobufs(efx);
900 if (rc)
901 efx_ef10_free_piobufs(efx);
902 }
903
904 /* Log an error on failure, but this is non-fatal */
905 if (rc)
906 netif_err(efx, drv, efx->net_dev,
907 "failed to restore PIO buffers (%d)\n", rc);
908 nic_data->must_restore_piobufs = false;
909 }
910
Jon Cooper267c0152015-05-06 00:59:38 +0100911 /* don't fail init if RSS setup doesn't work */
912 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
913
Ben Hutchings8127d662013-08-29 19:19:29 +0100914 return 0;
915}
916
Jon Cooper3e336262014-01-17 19:48:06 +0000917static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
918{
919 struct efx_ef10_nic_data *nic_data = efx->nic_data;
920
921 /* All our allocations have been reset */
922 nic_data->must_realloc_vis = true;
923 nic_data->must_restore_filters = true;
924 nic_data->must_restore_piobufs = true;
925 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
926}
927
Jon Cooper087e9022015-05-20 11:11:35 +0100928static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
929{
930 if (reason == RESET_TYPE_MC_FAILURE)
931 return RESET_TYPE_DATAPATH;
932
933 return efx_mcdi_map_reset_reason(reason);
934}
935
Ben Hutchings8127d662013-08-29 19:19:29 +0100936static int efx_ef10_map_reset_flags(u32 *flags)
937{
938 enum {
939 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
940 ETH_RESET_SHARED_SHIFT),
941 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
942 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
943 ETH_RESET_PHY | ETH_RESET_MGMT) <<
944 ETH_RESET_SHARED_SHIFT)
945 };
946
947 /* We assume for now that our PCI function is permitted to
948 * reset everything.
949 */
950
951 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
952 *flags &= ~EF10_RESET_MC;
953 return RESET_TYPE_WORLD;
954 }
955
956 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
957 *flags &= ~EF10_RESET_PORT;
958 return RESET_TYPE_ALL;
959 }
960
961 /* no invisible reset implemented */
962
963 return -EINVAL;
964}
965
Jon Cooper3e336262014-01-17 19:48:06 +0000966static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
967{
968 int rc = efx_mcdi_reset(efx, reset_type);
969
970 /* If it was a port reset, trigger reallocation of MC resources.
971 * Note that on an MC reset nothing needs to be done now because we'll
972 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +0100973 * For an FLR, we never get an MC reset event, but the MC has reset all
974 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +0000975 */
Edward Creee2835462014-04-16 19:27:48 +0100976 if ((reset_type == RESET_TYPE_ALL ||
977 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +0000978 efx_ef10_reset_mc_allocations(efx);
979 return rc;
980}
981
Ben Hutchings8127d662013-08-29 19:19:29 +0100982#define EF10_DMA_STAT(ext_name, mcdi_name) \
983 [EF10_STAT_ ## ext_name] = \
984 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
985#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
986 [EF10_STAT_ ## int_name] = \
987 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
988#define EF10_OTHER_STAT(ext_name) \
989 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +0100990#define GENERIC_SW_STAT(ext_name) \
991 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100992
993static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +0100994 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
995 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
996 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
997 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
998 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
999 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1000 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1001 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1002 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1003 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1004 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1005 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1006 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1007 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1008 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1009 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1010 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1011 EF10_OTHER_STAT(port_rx_good_bytes),
1012 EF10_OTHER_STAT(port_rx_bad_bytes),
1013 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1014 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1015 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1016 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1017 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1018 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1019 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1020 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1021 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1022 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1023 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1024 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1025 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1026 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1027 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1028 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1029 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1030 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1031 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1032 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1033 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1034 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001035 GENERIC_SW_STAT(rx_nodesc_trunc),
1036 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001037 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1038 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1039 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1040 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1041 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1042 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1043 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1044 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1045 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1046 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1047 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1048 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001049 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1050 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1051 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1052 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1053 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1054 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1055 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1056 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1057 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1058 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1059 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1060 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1061 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1062 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1063 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1064 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1065 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1066 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Ben Hutchings8127d662013-08-29 19:19:29 +01001067};
1068
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001069#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1070 (1ULL << EF10_STAT_port_tx_packets) | \
1071 (1ULL << EF10_STAT_port_tx_pause) | \
1072 (1ULL << EF10_STAT_port_tx_unicast) | \
1073 (1ULL << EF10_STAT_port_tx_multicast) | \
1074 (1ULL << EF10_STAT_port_tx_broadcast) | \
1075 (1ULL << EF10_STAT_port_rx_bytes) | \
1076 (1ULL << \
1077 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1078 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1079 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1080 (1ULL << EF10_STAT_port_rx_packets) | \
1081 (1ULL << EF10_STAT_port_rx_good) | \
1082 (1ULL << EF10_STAT_port_rx_bad) | \
1083 (1ULL << EF10_STAT_port_rx_pause) | \
1084 (1ULL << EF10_STAT_port_rx_control) | \
1085 (1ULL << EF10_STAT_port_rx_unicast) | \
1086 (1ULL << EF10_STAT_port_rx_multicast) | \
1087 (1ULL << EF10_STAT_port_rx_broadcast) | \
1088 (1ULL << EF10_STAT_port_rx_lt64) | \
1089 (1ULL << EF10_STAT_port_rx_64) | \
1090 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1091 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1092 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1093 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1094 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1095 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1096 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1097 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1098 (1ULL << EF10_STAT_port_rx_overflow) | \
1099 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001100 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1101 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001102
1103/* These statistics are only provided by the 10G MAC. For a 10G/40G
1104 * switchable port we do not expose these because they might not
1105 * include all the packets they should.
1106 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001107#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1108 (1ULL << EF10_STAT_port_tx_lt64) | \
1109 (1ULL << EF10_STAT_port_tx_64) | \
1110 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1111 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1112 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1113 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1114 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1115 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001116
1117/* These statistics are only provided by the 40G MAC. For a 10G/40G
1118 * switchable port we do expose these because the errors will otherwise
1119 * be silent.
1120 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001121#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1122 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001123
Edward Cree568d7a02013-09-25 17:32:09 +01001124/* These statistics are only provided if the firmware supports the
1125 * capability PM_AND_RXDP_COUNTERS.
1126 */
1127#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001128 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1129 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1130 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1131 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1132 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1133 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1134 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1135 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1136 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1137 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1138 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1139 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001140
Edward Cree4bae9132013-09-27 18:52:49 +01001141static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001142{
Edward Cree4bae9132013-09-27 18:52:49 +01001143 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001144 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001145 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001146
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001147 if (!(efx->mcdi->fn_flags &
1148 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1149 return 0;
1150
Ben Hutchings8127d662013-08-29 19:19:29 +01001151 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001152 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001153 else
Edward Cree4bae9132013-09-27 18:52:49 +01001154 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001155
1156 if (nic_data->datapath_caps &
1157 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1158 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1159
Edward Cree4bae9132013-09-27 18:52:49 +01001160 return raw_mask;
1161}
1162
1163static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1164{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001165 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001166 u64 raw_mask[2];
1167
1168 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1169
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001170 /* Only show vadaptor stats when EVB capability is present */
1171 if (nic_data->datapath_caps &
1172 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1173 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1174 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1175 } else {
1176 raw_mask[1] = 0;
1177 }
Edward Cree4bae9132013-09-27 18:52:49 +01001178
1179#if BITS_PER_LONG == 64
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001180 mask[0] = raw_mask[0];
1181 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001182#else
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001183 mask[0] = raw_mask[0] & 0xffffffff;
1184 mask[1] = raw_mask[0] >> 32;
1185 mask[2] = raw_mask[1] & 0xffffffff;
1186 mask[3] = raw_mask[1] >> 32;
Edward Cree4bae9132013-09-27 18:52:49 +01001187#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001188}
1189
1190static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1191{
Edward Cree4bae9132013-09-27 18:52:49 +01001192 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1193
1194 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001195 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001196 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001197}
1198
Daniel Pieczkod7788192015-06-02 11:39:20 +01001199static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1200 struct rtnl_link_stats64 *core_stats)
1201{
1202 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1203 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1204 u64 *stats = nic_data->stats;
1205 size_t stats_count = 0, index;
1206
1207 efx_ef10_get_stat_mask(efx, mask);
1208
1209 if (full_stats) {
1210 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1211 if (efx_ef10_stat_desc[index].name) {
1212 *full_stats++ = stats[index];
1213 ++stats_count;
1214 }
1215 }
1216 }
1217
1218 if (core_stats) {
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001219 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1220 stats[EF10_STAT_rx_multicast] +
1221 stats[EF10_STAT_rx_broadcast];
1222 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1223 stats[EF10_STAT_tx_multicast] +
1224 stats[EF10_STAT_tx_broadcast];
1225 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1226 stats[EF10_STAT_rx_multicast_bytes] +
1227 stats[EF10_STAT_rx_broadcast_bytes];
1228 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1229 stats[EF10_STAT_tx_multicast_bytes] +
1230 stats[EF10_STAT_tx_broadcast_bytes];
1231 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001232 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001233 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1234 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1235 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1236 core_stats->rx_errors = core_stats->rx_crc_errors;
1237 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Daniel Pieczkod7788192015-06-02 11:39:20 +01001238 }
1239
1240 return stats_count;
1241}
1242
1243static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001244{
1245 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001246 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001247 __le64 generation_start, generation_end;
1248 u64 *stats = nic_data->stats;
1249 __le64 *dma_stats;
1250
Edward Cree4bae9132013-09-27 18:52:49 +01001251 efx_ef10_get_stat_mask(efx, mask);
1252
Ben Hutchings8127d662013-08-29 19:19:29 +01001253 dma_stats = efx->stats_buffer.addr;
1254 nic_data = efx->nic_data;
1255
1256 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1257 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1258 return 0;
1259 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001260 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001261 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001262 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001263 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1264 if (generation_end != generation_start)
1265 return -EAGAIN;
1266
1267 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001268 efx_nic_fix_nodesc_drop_stat(efx,
1269 &stats[EF10_STAT_port_rx_nodesc_drops]);
1270 stats[EF10_STAT_port_rx_good_bytes] =
1271 stats[EF10_STAT_port_rx_bytes] -
1272 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1273 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1274 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001275 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001276 return 0;
1277}
1278
1279
Daniel Pieczkod7788192015-06-02 11:39:20 +01001280static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1281 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001282{
Ben Hutchings8127d662013-08-29 19:19:29 +01001283 int retry;
1284
1285 /* If we're unlucky enough to read statistics during the DMA, wait
1286 * up to 10ms for it to finish (typically takes <500us)
1287 */
1288 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001289 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001290 break;
1291 udelay(100);
1292 }
1293
Daniel Pieczkod7788192015-06-02 11:39:20 +01001294 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1295}
1296
1297static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1298{
1299 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1300 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1301 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1302 __le64 generation_start, generation_end;
1303 u64 *stats = nic_data->stats;
1304 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1305 struct efx_buffer stats_buf;
1306 __le64 *dma_stats;
1307 int rc;
1308
1309 efx_ef10_get_stat_mask(efx, mask);
1310
1311 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
1312 if (rc)
1313 return rc;
1314
1315 dma_stats = stats_buf.addr;
1316 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1317
1318 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1319 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001320 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001321 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1322 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1323
1324 spin_unlock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001325 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1326 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001327 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001328 if (rc) {
1329 /* Expect ENOENT if DMA queues have not been set up */
1330 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1331 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1332 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001333 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001334 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001335
1336 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001337 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1338 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001339 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001340 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001341 rmb();
1342 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1343 stats, stats_buf.addr, false);
1344 rmb();
1345 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1346 if (generation_end != generation_start) {
1347 rc = -EAGAIN;
1348 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001349 }
1350
Daniel Pieczkod7788192015-06-02 11:39:20 +01001351 efx_update_sw_stats(efx, stats);
1352out:
1353 efx_nic_free_buffer(efx, &stats_buf);
1354 return rc;
1355}
Ben Hutchings8127d662013-08-29 19:19:29 +01001356
Daniel Pieczkod7788192015-06-02 11:39:20 +01001357static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1358 struct rtnl_link_stats64 *core_stats)
1359{
1360 if (efx_ef10_try_update_nic_stats_vf(efx))
1361 return 0;
1362
1363 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001364}
1365
1366static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1367{
1368 struct efx_nic *efx = channel->efx;
1369 unsigned int mode, value;
1370 efx_dword_t timer_cmd;
1371
1372 if (channel->irq_moderation) {
1373 mode = 3;
1374 value = channel->irq_moderation - 1;
1375 } else {
1376 mode = 0;
1377 value = 0;
1378 }
1379
1380 if (EFX_EF10_WORKAROUND_35388(efx)) {
1381 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1382 EFE_DD_EVQ_IND_TIMER_FLAGS,
1383 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1384 ERF_DD_EVQ_IND_TIMER_VAL, value);
1385 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1386 channel->channel);
1387 } else {
1388 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1389 ERF_DZ_TC_TIMER_VAL, value);
1390 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1391 channel->channel);
1392 }
1393}
1394
Shradha Shah02246a72015-05-06 00:58:14 +01001395static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1396 struct ethtool_wolinfo *wol) {}
1397
1398static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1399{
1400 return -EOPNOTSUPP;
1401}
1402
Ben Hutchings8127d662013-08-29 19:19:29 +01001403static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1404{
1405 wol->supported = 0;
1406 wol->wolopts = 0;
1407 memset(&wol->sopass, 0, sizeof(wol->sopass));
1408}
1409
1410static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1411{
1412 if (type != 0)
1413 return -EINVAL;
1414 return 0;
1415}
1416
1417static void efx_ef10_mcdi_request(struct efx_nic *efx,
1418 const efx_dword_t *hdr, size_t hdr_len,
1419 const efx_dword_t *sdu, size_t sdu_len)
1420{
1421 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1422 u8 *pdu = nic_data->mcdi_buf.addr;
1423
1424 memcpy(pdu, hdr, hdr_len);
1425 memcpy(pdu + hdr_len, sdu, sdu_len);
1426 wmb();
1427
1428 /* The hardware provides 'low' and 'high' (doorbell) registers
1429 * for passing the 64-bit address of an MCDI request to
1430 * firmware. However the dwords are swapped by firmware. The
1431 * least significant bits of the doorbell are then 0 for all
1432 * MCDI requests due to alignment.
1433 */
1434 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1435 ER_DZ_MC_DB_LWRD);
1436 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1437 ER_DZ_MC_DB_HWRD);
1438}
1439
1440static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1441{
1442 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1443 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1444
1445 rmb();
1446 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1447}
1448
1449static void
1450efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1451 size_t offset, size_t outlen)
1452{
1453 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1454 const u8 *pdu = nic_data->mcdi_buf.addr;
1455
1456 memcpy(outbuf, pdu + offset, outlen);
1457}
1458
1459static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1460{
1461 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1462 int rc;
1463
1464 rc = efx_ef10_get_warm_boot_count(efx);
1465 if (rc < 0) {
1466 /* The firmware is presumably in the process of
1467 * rebooting. However, we are supposed to report each
1468 * reboot just once, so we must only do that once we
1469 * can read and store the updated warm boot count.
1470 */
1471 return 0;
1472 }
1473
1474 if (rc == nic_data->warm_boot_count)
1475 return 0;
1476
1477 nic_data->warm_boot_count = rc;
1478
1479 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001480 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001481
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001482 /* Driver-created vswitches and vports must be re-created */
1483 nic_data->must_probe_vswitching = true;
1484 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1485
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001486 /* The datapath firmware might have been changed */
1487 nic_data->must_check_datapath_caps = true;
1488
Ben Hutchings869070c2013-09-05 22:46:10 +01001489 /* MAC statistics have been cleared on the NIC; clear the local
1490 * statistic that we update with efx_update_diff_stat().
1491 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001492 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
Ben Hutchings869070c2013-09-05 22:46:10 +01001493
Ben Hutchings8127d662013-08-29 19:19:29 +01001494 return -EIO;
1495}
1496
1497/* Handle an MSI interrupt
1498 *
1499 * Handle an MSI hardware interrupt. This routine schedules event
1500 * queue processing. No interrupt acknowledgement cycle is necessary.
1501 * Also, we never need to check that the interrupt is for us, since
1502 * MSI interrupts cannot be shared.
1503 */
1504static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1505{
1506 struct efx_msi_context *context = dev_id;
1507 struct efx_nic *efx = context->efx;
1508
1509 netif_vdbg(efx, intr, efx->net_dev,
1510 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1511
1512 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1513 /* Note test interrupts */
1514 if (context->index == efx->irq_level)
1515 efx->last_irq_cpu = raw_smp_processor_id();
1516
1517 /* Schedule processing of the channel */
1518 efx_schedule_channel_irq(efx->channel[context->index]);
1519 }
1520
1521 return IRQ_HANDLED;
1522}
1523
1524static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1525{
1526 struct efx_nic *efx = dev_id;
1527 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1528 struct efx_channel *channel;
1529 efx_dword_t reg;
1530 u32 queues;
1531
1532 /* Read the ISR which also ACKs the interrupts */
1533 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1534 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1535
1536 if (queues == 0)
1537 return IRQ_NONE;
1538
1539 if (likely(soft_enabled)) {
1540 /* Note test interrupts */
1541 if (queues & (1U << efx->irq_level))
1542 efx->last_irq_cpu = raw_smp_processor_id();
1543
1544 efx_for_each_channel(channel, efx) {
1545 if (queues & 1)
1546 efx_schedule_channel_irq(channel);
1547 queues >>= 1;
1548 }
1549 }
1550
1551 netif_vdbg(efx, intr, efx->net_dev,
1552 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1553 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1554
1555 return IRQ_HANDLED;
1556}
1557
1558static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1559{
1560 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1561
1562 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1563
1564 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1565 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1566 inbuf, sizeof(inbuf), NULL, 0, NULL);
1567}
1568
1569static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1570{
1571 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1572 (tx_queue->ptr_mask + 1) *
1573 sizeof(efx_qword_t),
1574 GFP_KERNEL);
1575}
1576
1577/* This writes to the TX_DESC_WPTR and also pushes data */
1578static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1579 const efx_qword_t *txd)
1580{
1581 unsigned int write_ptr;
1582 efx_oword_t reg;
1583
1584 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1585 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1586 reg.qword[0] = *txd;
1587 efx_writeo_page(tx_queue->efx, &reg,
1588 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1589}
1590
1591static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1592{
1593 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1594 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001595 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1596 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1597 struct efx_channel *channel = tx_queue->channel;
1598 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001599 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001600 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001601 dma_addr_t dma_addr;
1602 efx_qword_t *txd;
1603 int rc;
1604 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001605 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001606
1607 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1608 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1609 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1610 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1611 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1612 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1613 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1614 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001615 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001616
1617 dma_addr = tx_queue->txd.buf.dma_addr;
1618
1619 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1620 tx_queue->queue, entries, (u64)dma_addr);
1621
1622 for (i = 0; i < entries; ++i) {
1623 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1624 dma_addr += EFX_BUF_SIZE;
1625 }
1626
1627 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1628
1629 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001630 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001631 if (rc)
1632 goto fail;
1633
1634 /* A previous user of this TX queue might have set us up the
1635 * bomb by writing a descriptor to the TX push collector but
1636 * not the doorbell. (Each collector belongs to a port, not a
1637 * queue or function, so cannot easily be reset.) We must
1638 * attempt to push a no-op descriptor in its place.
1639 */
1640 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1641 tx_queue->insert_count = 1;
1642 txd = efx_tx_desc(tx_queue, 0);
1643 EFX_POPULATE_QWORD_4(*txd,
1644 ESF_DZ_TX_DESC_IS_OPT, true,
1645 ESF_DZ_TX_OPTION_TYPE,
1646 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1647 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1648 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1649 tx_queue->write_count = 1;
1650 wmb();
1651 efx_ef10_push_tx_desc(tx_queue, txd);
1652
1653 return;
1654
1655fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001656 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1657 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001658}
1659
1660static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1661{
1662 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001663 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001664 struct efx_nic *efx = tx_queue->efx;
1665 size_t outlen;
1666 int rc;
1667
1668 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1669 tx_queue->queue);
1670
Edward Cree1e0b8122013-05-31 18:36:12 +01001671 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001672 outbuf, sizeof(outbuf), &outlen);
1673
1674 if (rc && rc != -EALREADY)
1675 goto fail;
1676
1677 return;
1678
1679fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001680 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1681 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001682}
1683
1684static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1685{
1686 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1687}
1688
1689/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1690static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1691{
1692 unsigned int write_ptr;
1693 efx_dword_t reg;
1694
1695 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1696 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1697 efx_writed_page(tx_queue->efx, &reg,
1698 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1699}
1700
1701static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1702{
1703 unsigned int old_write_count = tx_queue->write_count;
1704 struct efx_tx_buffer *buffer;
1705 unsigned int write_ptr;
1706 efx_qword_t *txd;
1707
1708 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1709
1710 do {
1711 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1712 buffer = &tx_queue->buffer[write_ptr];
1713 txd = efx_tx_desc(tx_queue, write_ptr);
1714 ++tx_queue->write_count;
1715
1716 /* Create TX descriptor ring entry */
1717 if (buffer->flags & EFX_TX_BUF_OPTION) {
1718 *txd = buffer->option;
1719 } else {
1720 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1721 EFX_POPULATE_QWORD_3(
1722 *txd,
1723 ESF_DZ_TX_KER_CONT,
1724 buffer->flags & EFX_TX_BUF_CONT,
1725 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1726 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1727 }
1728 } while (tx_queue->write_count != tx_queue->insert_count);
1729
1730 wmb(); /* Ensure descriptors are written before they are fetched */
1731
1732 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1733 txd = efx_tx_desc(tx_queue,
1734 old_write_count & tx_queue->ptr_mask);
1735 efx_ef10_push_tx_desc(tx_queue, txd);
1736 ++tx_queue->pushes;
1737 } else {
1738 efx_ef10_notify_tx_desc(tx_queue);
1739 }
1740}
1741
Jon Cooper267c0152015-05-06 00:59:38 +01001742static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1743 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001744{
1745 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1746 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001747 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001748 size_t outlen;
1749 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001750 u32 alloc_type = exclusive ?
1751 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1752 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1753 unsigned rss_spread = exclusive ?
1754 efx->rss_spread :
1755 min(rounddown_pow_of_two(efx->rss_spread),
1756 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1757
1758 if (!exclusive && rss_spread == 1) {
1759 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1760 if (context_size)
1761 *context_size = 1;
1762 return 0;
1763 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001764
1765 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001766 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001767 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1768 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001769
1770 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1771 outbuf, sizeof(outbuf), &outlen);
1772 if (rc != 0)
1773 return rc;
1774
1775 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1776 return -EIO;
1777
1778 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1779
Jon Cooper267c0152015-05-06 00:59:38 +01001780 if (context_size)
1781 *context_size = rss_spread;
1782
Ben Hutchings8127d662013-08-29 19:19:29 +01001783 return 0;
1784}
1785
1786static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1787{
1788 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1789 int rc;
1790
1791 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1792 context);
1793
1794 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1795 NULL, 0, NULL);
1796 WARN_ON(rc != 0);
1797}
1798
Jon Cooper267c0152015-05-06 00:59:38 +01001799static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1800 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001801{
1802 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1803 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1804 int i, rc;
1805
1806 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1807 context);
1808 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1809 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1810
1811 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1812 MCDI_PTR(tablebuf,
1813 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001814 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001815
1816 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1817 sizeof(tablebuf), NULL, 0, NULL);
1818 if (rc != 0)
1819 return rc;
1820
1821 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1822 context);
1823 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1824 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1825 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1826 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1827 efx->rx_hash_key[i];
1828
1829 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1830 sizeof(keybuf), NULL, 0, NULL);
1831}
1832
1833static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1834{
1835 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1836
1837 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1838 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1839 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1840}
1841
Jon Cooper267c0152015-05-06 00:59:38 +01001842static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1843 unsigned *context_size)
1844{
1845 u32 new_rx_rss_context;
1846 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1847 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1848 false, context_size);
1849
1850 if (rc != 0)
1851 return rc;
1852
1853 nic_data->rx_rss_context = new_rx_rss_context;
1854 nic_data->rx_rss_context_exclusive = false;
1855 efx_set_default_rx_indir_table(efx);
1856 return 0;
1857}
1858
1859static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1860 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001861{
1862 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1863 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001864 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001865
Jon Cooper267c0152015-05-06 00:59:38 +01001866 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1867 !nic_data->rx_rss_context_exclusive) {
1868 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1869 true, NULL);
1870 if (rc == -EOPNOTSUPP)
1871 return rc;
1872 else if (rc != 0)
1873 goto fail1;
1874 } else {
1875 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001876 }
1877
Jon Cooper267c0152015-05-06 00:59:38 +01001878 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1879 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001880 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001881 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001882
Jon Cooper267c0152015-05-06 00:59:38 +01001883 if (nic_data->rx_rss_context != new_rx_rss_context)
1884 efx_ef10_rx_free_indir_table(efx);
1885 nic_data->rx_rss_context = new_rx_rss_context;
1886 nic_data->rx_rss_context_exclusive = true;
1887 if (rx_indir_table != efx->rx_indir_table)
1888 memcpy(efx->rx_indir_table, rx_indir_table,
1889 sizeof(efx->rx_indir_table));
1890 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001891
Jon Cooper267c0152015-05-06 00:59:38 +01001892fail2:
1893 if (new_rx_rss_context != nic_data->rx_rss_context)
1894 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1895fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001896 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001897 return rc;
1898}
1899
1900static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1901 const u32 *rx_indir_table)
1902{
1903 int rc;
1904
1905 if (efx->rss_spread == 1)
1906 return 0;
1907
1908 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1909
1910 if (rc == -ENOBUFS && !user) {
1911 unsigned context_size;
1912 bool mismatch = false;
1913 size_t i;
1914
1915 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1916 i++)
1917 mismatch = rx_indir_table[i] !=
1918 ethtool_rxfh_indir_default(i, efx->rss_spread);
1919
1920 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1921 if (rc == 0) {
1922 if (context_size != efx->rss_spread)
1923 netif_warn(efx, probe, efx->net_dev,
1924 "Could not allocate an exclusive RSS"
1925 " context; allocated a shared one of"
1926 " different size."
1927 " Wanted %u, got %u.\n",
1928 efx->rss_spread, context_size);
1929 else if (mismatch)
1930 netif_warn(efx, probe, efx->net_dev,
1931 "Could not allocate an exclusive RSS"
1932 " context; allocated a shared one but"
1933 " could not apply custom"
1934 " indirection.\n");
1935 else
1936 netif_info(efx, probe, efx->net_dev,
1937 "Could not allocate an exclusive RSS"
1938 " context; allocated a shared one.\n");
1939 }
1940 }
1941 return rc;
1942}
1943
1944static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1945 const u32 *rx_indir_table
1946 __attribute__ ((unused)))
1947{
1948 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1949
1950 if (user)
1951 return -EOPNOTSUPP;
1952 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1953 return 0;
1954 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001955}
1956
1957static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1958{
1959 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1960 (rx_queue->ptr_mask + 1) *
1961 sizeof(efx_qword_t),
1962 GFP_KERNEL);
1963}
1964
1965static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1966{
1967 MCDI_DECLARE_BUF(inbuf,
1968 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1969 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001970 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1971 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1972 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001973 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001974 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001975 dma_addr_t dma_addr;
1976 int rc;
1977 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001978 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001979
1980 rx_queue->scatter_n = 0;
1981 rx_queue->scatter_len = 0;
1982
1983 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1984 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1985 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1986 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1987 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001988 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1989 INIT_RXQ_IN_FLAG_PREFIX, 1,
1990 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001991 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001992 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001993
1994 dma_addr = rx_queue->rxd.buf.dma_addr;
1995
1996 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1997 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1998
1999 for (i = 0; i < entries; ++i) {
2000 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2001 dma_addr += EFX_BUF_SIZE;
2002 }
2003
2004 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2005
2006 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002007 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002008 if (rc)
2009 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2010 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002011}
2012
2013static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2014{
2015 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002016 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002017 struct efx_nic *efx = rx_queue->efx;
2018 size_t outlen;
2019 int rc;
2020
2021 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2022 efx_rx_queue_index(rx_queue));
2023
Edward Cree1e0b8122013-05-31 18:36:12 +01002024 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002025 outbuf, sizeof(outbuf), &outlen);
2026
2027 if (rc && rc != -EALREADY)
2028 goto fail;
2029
2030 return;
2031
2032fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002033 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2034 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002035}
2036
2037static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2038{
2039 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2040}
2041
2042/* This creates an entry in the RX descriptor queue */
2043static inline void
2044efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2045{
2046 struct efx_rx_buffer *rx_buf;
2047 efx_qword_t *rxd;
2048
2049 rxd = efx_rx_desc(rx_queue, index);
2050 rx_buf = efx_rx_buffer(rx_queue, index);
2051 EFX_POPULATE_QWORD_2(*rxd,
2052 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2053 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2054}
2055
2056static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2057{
2058 struct efx_nic *efx = rx_queue->efx;
2059 unsigned int write_count;
2060 efx_dword_t reg;
2061
2062 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2063 write_count = rx_queue->added_count & ~7;
2064 if (rx_queue->notified_count == write_count)
2065 return;
2066
2067 do
2068 efx_ef10_build_rx_desc(
2069 rx_queue,
2070 rx_queue->notified_count & rx_queue->ptr_mask);
2071 while (++rx_queue->notified_count != write_count);
2072
2073 wmb();
2074 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2075 write_count & rx_queue->ptr_mask);
2076 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2077 efx_rx_queue_index(rx_queue));
2078}
2079
2080static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2081
2082static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2083{
2084 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2085 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2086 efx_qword_t event;
2087
2088 EFX_POPULATE_QWORD_2(event,
2089 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2090 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2091
2092 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2093
2094 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2095 * already swapped the data to little-endian order.
2096 */
2097 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2098 sizeof(efx_qword_t));
2099
2100 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2101 inbuf, sizeof(inbuf), 0,
2102 efx_ef10_rx_defer_refill_complete, 0);
2103}
2104
2105static void
2106efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2107 int rc, efx_dword_t *outbuf,
2108 size_t outlen_actual)
2109{
2110 /* nothing to do */
2111}
2112
2113static int efx_ef10_ev_probe(struct efx_channel *channel)
2114{
2115 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2116 (channel->eventq_mask + 1) *
2117 sizeof(efx_qword_t),
2118 GFP_KERNEL);
2119}
2120
2121static int efx_ef10_ev_init(struct efx_channel *channel)
2122{
2123 MCDI_DECLARE_BUF(inbuf,
2124 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2125 EFX_BUF_SIZE));
2126 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
2127 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2128 struct efx_nic *efx = channel->efx;
2129 struct efx_ef10_nic_data *nic_data;
2130 bool supports_rx_merge;
2131 size_t inlen, outlen;
2132 dma_addr_t dma_addr;
2133 int rc;
2134 int i;
2135
2136 nic_data = efx->nic_data;
2137 supports_rx_merge =
2138 !!(nic_data->datapath_caps &
2139 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2140
2141 /* Fill event queue with all ones (i.e. empty events) */
2142 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2143
2144 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2145 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2146 /* INIT_EVQ expects index in vector table, not absolute */
2147 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
2148 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2149 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2150 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2151 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2152 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
2153 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2154 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2155 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2156 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2157 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2158 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2159 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2160
2161 dma_addr = channel->eventq.buf.dma_addr;
2162 for (i = 0; i < entries; ++i) {
2163 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2164 dma_addr += EFX_BUF_SIZE;
2165 }
2166
2167 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2168
2169 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2170 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01002171 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01002172 return rc;
2173}
2174
2175static void efx_ef10_ev_fini(struct efx_channel *channel)
2176{
2177 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002178 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002179 struct efx_nic *efx = channel->efx;
2180 size_t outlen;
2181 int rc;
2182
2183 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2184
Edward Cree1e0b8122013-05-31 18:36:12 +01002185 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002186 outbuf, sizeof(outbuf), &outlen);
2187
2188 if (rc && rc != -EALREADY)
2189 goto fail;
2190
2191 return;
2192
2193fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002194 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2195 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002196}
2197
2198static void efx_ef10_ev_remove(struct efx_channel *channel)
2199{
2200 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2201}
2202
2203static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2204 unsigned int rx_queue_label)
2205{
2206 struct efx_nic *efx = rx_queue->efx;
2207
2208 netif_info(efx, hw, efx->net_dev,
2209 "rx event arrived on queue %d labeled as queue %u\n",
2210 efx_rx_queue_index(rx_queue), rx_queue_label);
2211
2212 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2213}
2214
2215static void
2216efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2217 unsigned int actual, unsigned int expected)
2218{
2219 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2220 struct efx_nic *efx = rx_queue->efx;
2221
2222 netif_info(efx, hw, efx->net_dev,
2223 "dropped %d events (index=%d expected=%d)\n",
2224 dropped, actual, expected);
2225
2226 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2227}
2228
2229/* partially received RX was aborted. clean up. */
2230static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2231{
2232 unsigned int rx_desc_ptr;
2233
Ben Hutchings8127d662013-08-29 19:19:29 +01002234 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2235 "scattered RX aborted (dropping %u buffers)\n",
2236 rx_queue->scatter_n);
2237
2238 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2239
2240 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2241 0, EFX_RX_PKT_DISCARD);
2242
2243 rx_queue->removed_count += rx_queue->scatter_n;
2244 rx_queue->scatter_n = 0;
2245 rx_queue->scatter_len = 0;
2246 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2247}
2248
2249static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2250 const efx_qword_t *event)
2251{
2252 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2253 unsigned int n_descs, n_packets, i;
2254 struct efx_nic *efx = channel->efx;
2255 struct efx_rx_queue *rx_queue;
2256 bool rx_cont;
2257 u16 flags = 0;
2258
2259 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2260 return 0;
2261
2262 /* Basic packet information */
2263 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2264 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2265 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2266 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2267 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2268
Ben Hutchings48ce5632013-11-01 16:42:44 +00002269 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2270 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2271 EFX_QWORD_FMT "\n",
2272 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002273
2274 rx_queue = efx_channel_get_rx_queue(channel);
2275
2276 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2277 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2278
2279 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2280 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2281
2282 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002283 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2284
Ben Hutchings8127d662013-08-29 19:19:29 +01002285 /* detect rx abort */
2286 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002287 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2288 netdev_WARN(efx->net_dev,
2289 "invalid RX abort: scatter_n=%u event="
2290 EFX_QWORD_FMT "\n",
2291 rx_queue->scatter_n,
2292 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002293 efx_ef10_handle_rx_abort(rx_queue);
2294 return 0;
2295 }
2296
Ben Hutchings92a04162013-09-24 23:21:57 +01002297 /* Check that RX completion merging is valid, i.e.
2298 * the current firmware supports it and this is a
2299 * non-scattered packet.
2300 */
2301 if (!(nic_data->datapath_caps &
2302 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2303 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002304 efx_ef10_handle_rx_bad_lbits(
2305 rx_queue, next_ptr_lbits,
2306 (rx_queue->removed_count +
2307 rx_queue->scatter_n + 1) &
2308 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2309 return 0;
2310 }
2311
2312 /* Merged completion for multiple non-scattered packets */
2313 rx_queue->scatter_n = 1;
2314 rx_queue->scatter_len = 0;
2315 n_packets = n_descs;
2316 ++channel->n_rx_merge_events;
2317 channel->n_rx_merge_packets += n_packets;
2318 flags |= EFX_RX_PKT_PREFIX_LEN;
2319 } else {
2320 ++rx_queue->scatter_n;
2321 rx_queue->scatter_len += rx_bytes;
2322 if (rx_cont)
2323 return 0;
2324 n_packets = 1;
2325 }
2326
2327 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2328 flags |= EFX_RX_PKT_DISCARD;
2329
2330 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2331 channel->n_rx_ip_hdr_chksum_err += n_packets;
2332 } else if (unlikely(EFX_QWORD_FIELD(*event,
2333 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2334 channel->n_rx_tcp_udp_chksum_err += n_packets;
2335 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2336 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2337 flags |= EFX_RX_PKT_CSUMMED;
2338 }
2339
2340 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2341 flags |= EFX_RX_PKT_TCP;
2342
2343 channel->irq_mod_score += 2 * n_packets;
2344
2345 /* Handle received packet(s) */
2346 for (i = 0; i < n_packets; i++) {
2347 efx_rx_packet(rx_queue,
2348 rx_queue->removed_count & rx_queue->ptr_mask,
2349 rx_queue->scatter_n, rx_queue->scatter_len,
2350 flags);
2351 rx_queue->removed_count += rx_queue->scatter_n;
2352 }
2353
2354 rx_queue->scatter_n = 0;
2355 rx_queue->scatter_len = 0;
2356
2357 return n_packets;
2358}
2359
2360static int
2361efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2362{
2363 struct efx_nic *efx = channel->efx;
2364 struct efx_tx_queue *tx_queue;
2365 unsigned int tx_ev_desc_ptr;
2366 unsigned int tx_ev_q_label;
2367 int tx_descs = 0;
2368
2369 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2370 return 0;
2371
2372 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2373 return 0;
2374
2375 /* Transmit completion */
2376 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2377 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2378 tx_queue = efx_channel_get_tx_queue(channel,
2379 tx_ev_q_label % EFX_TXQ_TYPES);
2380 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2381 tx_queue->ptr_mask);
2382 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2383
2384 return tx_descs;
2385}
2386
2387static void
2388efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2389{
2390 struct efx_nic *efx = channel->efx;
2391 int subcode;
2392
2393 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2394
2395 switch (subcode) {
2396 case ESE_DZ_DRV_TIMER_EV:
2397 case ESE_DZ_DRV_WAKE_UP_EV:
2398 break;
2399 case ESE_DZ_DRV_START_UP_EV:
2400 /* event queue init complete. ok. */
2401 break;
2402 default:
2403 netif_err(efx, hw, efx->net_dev,
2404 "channel %d unknown driver event type %d"
2405 " (data " EFX_QWORD_FMT ")\n",
2406 channel->channel, subcode,
2407 EFX_QWORD_VAL(*event));
2408
2409 }
2410}
2411
2412static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2413 efx_qword_t *event)
2414{
2415 struct efx_nic *efx = channel->efx;
2416 u32 subcode;
2417
2418 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2419
2420 switch (subcode) {
2421 case EFX_EF10_TEST:
2422 channel->event_test_cpu = raw_smp_processor_id();
2423 break;
2424 case EFX_EF10_REFILL:
2425 /* The queue must be empty, so we won't receive any rx
2426 * events, so efx_process_channel() won't refill the
2427 * queue. Refill it here
2428 */
Jon Coopercce28792013-10-02 11:04:14 +01002429 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002430 break;
2431 default:
2432 netif_err(efx, hw, efx->net_dev,
2433 "channel %d unknown driver event type %u"
2434 " (data " EFX_QWORD_FMT ")\n",
2435 channel->channel, (unsigned) subcode,
2436 EFX_QWORD_VAL(*event));
2437 }
2438}
2439
2440static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2441{
2442 struct efx_nic *efx = channel->efx;
2443 efx_qword_t event, *p_event;
2444 unsigned int read_ptr;
2445 int ev_code;
2446 int tx_descs = 0;
2447 int spent = 0;
2448
Eric W. Biederman75363a42014-03-14 18:11:22 -07002449 if (quota <= 0)
2450 return spent;
2451
Ben Hutchings8127d662013-08-29 19:19:29 +01002452 read_ptr = channel->eventq_read_ptr;
2453
2454 for (;;) {
2455 p_event = efx_event(channel, read_ptr);
2456 event = *p_event;
2457
2458 if (!efx_event_present(&event))
2459 break;
2460
2461 EFX_SET_QWORD(*p_event);
2462
2463 ++read_ptr;
2464
2465 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2466
2467 netif_vdbg(efx, drv, efx->net_dev,
2468 "processing event on %d " EFX_QWORD_FMT "\n",
2469 channel->channel, EFX_QWORD_VAL(event));
2470
2471 switch (ev_code) {
2472 case ESE_DZ_EV_CODE_MCDI_EV:
2473 efx_mcdi_process_event(channel, &event);
2474 break;
2475 case ESE_DZ_EV_CODE_RX_EV:
2476 spent += efx_ef10_handle_rx_event(channel, &event);
2477 if (spent >= quota) {
2478 /* XXX can we split a merged event to
2479 * avoid going over-quota?
2480 */
2481 spent = quota;
2482 goto out;
2483 }
2484 break;
2485 case ESE_DZ_EV_CODE_TX_EV:
2486 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2487 if (tx_descs > efx->txq_entries) {
2488 spent = quota;
2489 goto out;
2490 } else if (++spent == quota) {
2491 goto out;
2492 }
2493 break;
2494 case ESE_DZ_EV_CODE_DRIVER_EV:
2495 efx_ef10_handle_driver_event(channel, &event);
2496 if (++spent == quota)
2497 goto out;
2498 break;
2499 case EFX_EF10_DRVGEN_EV:
2500 efx_ef10_handle_driver_generated_event(channel, &event);
2501 break;
2502 default:
2503 netif_err(efx, hw, efx->net_dev,
2504 "channel %d unknown event type %d"
2505 " (data " EFX_QWORD_FMT ")\n",
2506 channel->channel, ev_code,
2507 EFX_QWORD_VAL(event));
2508 }
2509 }
2510
2511out:
2512 channel->eventq_read_ptr = read_ptr;
2513 return spent;
2514}
2515
2516static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2517{
2518 struct efx_nic *efx = channel->efx;
2519 efx_dword_t rptr;
2520
2521 if (EFX_EF10_WORKAROUND_35388(efx)) {
2522 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2523 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2524 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2525 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2526
2527 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2528 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2529 ERF_DD_EVQ_IND_RPTR,
2530 (channel->eventq_read_ptr &
2531 channel->eventq_mask) >>
2532 ERF_DD_EVQ_IND_RPTR_WIDTH);
2533 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2534 channel->channel);
2535 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2536 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2537 ERF_DD_EVQ_IND_RPTR,
2538 channel->eventq_read_ptr &
2539 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2540 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2541 channel->channel);
2542 } else {
2543 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2544 channel->eventq_read_ptr &
2545 channel->eventq_mask);
2546 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2547 }
2548}
2549
2550static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2551{
2552 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2553 struct efx_nic *efx = channel->efx;
2554 efx_qword_t event;
2555 int rc;
2556
2557 EFX_POPULATE_QWORD_2(event,
2558 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2559 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2560
2561 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2562
2563 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2564 * already swapped the data to little-endian order.
2565 */
2566 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2567 sizeof(efx_qword_t));
2568
2569 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2570 NULL, 0, NULL);
2571 if (rc != 0)
2572 goto fail;
2573
2574 return;
2575
2576fail:
2577 WARN_ON(true);
2578 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2579}
2580
2581void efx_ef10_handle_drain_event(struct efx_nic *efx)
2582{
2583 if (atomic_dec_and_test(&efx->active_queues))
2584 wake_up(&efx->flush_wq);
2585
2586 WARN_ON(atomic_read(&efx->active_queues) < 0);
2587}
2588
2589static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2590{
2591 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2592 struct efx_channel *channel;
2593 struct efx_tx_queue *tx_queue;
2594 struct efx_rx_queue *rx_queue;
2595 int pending;
2596
2597 /* If the MC has just rebooted, the TX/RX queues will have already been
2598 * torn down, but efx->active_queues needs to be set to zero.
2599 */
2600 if (nic_data->must_realloc_vis) {
2601 atomic_set(&efx->active_queues, 0);
2602 return 0;
2603 }
2604
2605 /* Do not attempt to write to the NIC during EEH recovery */
2606 if (efx->state != STATE_RECOVERY) {
2607 efx_for_each_channel(channel, efx) {
2608 efx_for_each_channel_rx_queue(rx_queue, channel)
2609 efx_ef10_rx_fini(rx_queue);
2610 efx_for_each_channel_tx_queue(tx_queue, channel)
2611 efx_ef10_tx_fini(tx_queue);
2612 }
2613
2614 wait_event_timeout(efx->flush_wq,
2615 atomic_read(&efx->active_queues) == 0,
2616 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2617 pending = atomic_read(&efx->active_queues);
2618 if (pending) {
2619 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2620 pending);
2621 return -ETIMEDOUT;
2622 }
2623 }
2624
2625 return 0;
2626}
2627
Edward Creee2835462014-04-16 19:27:48 +01002628static void efx_ef10_prepare_flr(struct efx_nic *efx)
2629{
2630 atomic_set(&efx->active_queues, 0);
2631}
2632
Ben Hutchings8127d662013-08-29 19:19:29 +01002633static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2634 const struct efx_filter_spec *right)
2635{
2636 if ((left->match_flags ^ right->match_flags) |
2637 ((left->flags ^ right->flags) &
2638 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2639 return false;
2640
2641 return memcmp(&left->outer_vid, &right->outer_vid,
2642 sizeof(struct efx_filter_spec) -
2643 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2644}
2645
2646static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2647{
2648 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2649 return jhash2((const u32 *)&spec->outer_vid,
2650 (sizeof(struct efx_filter_spec) -
2651 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2652 0);
2653 /* XXX should we randomise the initval? */
2654}
2655
2656/* Decide whether a filter should be exclusive or else should allow
2657 * delivery to additional recipients. Currently we decide that
2658 * filters for specific local unicast MAC and IP addresses are
2659 * exclusive.
2660 */
2661static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2662{
2663 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2664 !is_multicast_ether_addr(spec->loc_mac))
2665 return true;
2666
2667 if ((spec->match_flags &
2668 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2669 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2670 if (spec->ether_type == htons(ETH_P_IP) &&
2671 !ipv4_is_multicast(spec->loc_host[0]))
2672 return true;
2673 if (spec->ether_type == htons(ETH_P_IPV6) &&
2674 ((const u8 *)spec->loc_host)[0] != 0xff)
2675 return true;
2676 }
2677
2678 return false;
2679}
2680
2681static struct efx_filter_spec *
2682efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2683 unsigned int filter_idx)
2684{
2685 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2686 ~EFX_EF10_FILTER_FLAGS);
2687}
2688
2689static unsigned int
2690efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2691 unsigned int filter_idx)
2692{
2693 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2694}
2695
2696static void
2697efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2698 unsigned int filter_idx,
2699 const struct efx_filter_spec *spec,
2700 unsigned int flags)
2701{
2702 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2703}
2704
2705static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2706 const struct efx_filter_spec *spec,
2707 efx_dword_t *inbuf, u64 handle,
2708 bool replacing)
2709{
2710 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2711
2712 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2713
2714 if (replacing) {
2715 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2716 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2717 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2718 } else {
2719 u32 match_fields = 0;
2720
2721 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2722 efx_ef10_filter_is_exclusive(spec) ?
2723 MC_CMD_FILTER_OP_IN_OP_INSERT :
2724 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2725
2726 /* Convert match flags and values. Unlike almost
2727 * everything else in MCDI, these fields are in
2728 * network byte order.
2729 */
2730 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2731 match_fields |=
2732 is_multicast_ether_addr(spec->loc_mac) ?
2733 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2734 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2735#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2736 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2737 match_fields |= \
2738 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2739 mcdi_field ## _LBN; \
2740 BUILD_BUG_ON( \
2741 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2742 sizeof(spec->gen_field)); \
2743 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2744 &spec->gen_field, sizeof(spec->gen_field)); \
2745 }
2746 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2747 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2748 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2749 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2750 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2751 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2752 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2753 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2754 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2755 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2756#undef COPY_FIELD
2757 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2758 match_fields);
2759 }
2760
Daniel Pieczko45b24492015-05-06 00:57:14 +01002761 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002762 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2763 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2764 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2765 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002766 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002767 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2768 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002769 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2770 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2771 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002772 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2773 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2774 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2775 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2776 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2777 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2778 spec->rss_context !=
2779 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2780 spec->rss_context : nic_data->rx_rss_context);
2781}
2782
2783static int efx_ef10_filter_push(struct efx_nic *efx,
2784 const struct efx_filter_spec *spec,
2785 u64 *handle, bool replacing)
2786{
2787 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2788 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2789 int rc;
2790
2791 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2792 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2793 outbuf, sizeof(outbuf), NULL);
2794 if (rc == 0)
2795 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002796 if (rc == -ENOSPC)
2797 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002798 return rc;
2799}
2800
2801static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2802 enum efx_filter_match_flags match_flags)
2803{
2804 unsigned int match_pri;
2805
2806 for (match_pri = 0;
2807 match_pri < table->rx_match_count;
2808 match_pri++)
2809 if (table->rx_match_flags[match_pri] == match_flags)
2810 return match_pri;
2811
2812 return -EPROTONOSUPPORT;
2813}
2814
2815static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2816 struct efx_filter_spec *spec,
2817 bool replace_equal)
2818{
2819 struct efx_ef10_filter_table *table = efx->filter_state;
2820 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2821 struct efx_filter_spec *saved_spec;
2822 unsigned int match_pri, hash;
2823 unsigned int priv_flags;
2824 bool replacing = false;
2825 int ins_index = -1;
2826 DEFINE_WAIT(wait);
2827 bool is_mc_recip;
2828 s32 rc;
2829
2830 /* For now, only support RX filters */
2831 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2832 EFX_FILTER_FLAG_RX)
2833 return -EINVAL;
2834
2835 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2836 if (rc < 0)
2837 return rc;
2838 match_pri = rc;
2839
2840 hash = efx_ef10_filter_hash(spec);
2841 is_mc_recip = efx_filter_is_mc_recipient(spec);
2842 if (is_mc_recip)
2843 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2844
2845 /* Find any existing filters with the same match tuple or
2846 * else a free slot to insert at. If any of them are busy,
2847 * we have to wait and retry.
2848 */
2849 for (;;) {
2850 unsigned int depth = 1;
2851 unsigned int i;
2852
2853 spin_lock_bh(&efx->filter_lock);
2854
2855 for (;;) {
2856 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2857 saved_spec = efx_ef10_filter_entry_spec(table, i);
2858
2859 if (!saved_spec) {
2860 if (ins_index < 0)
2861 ins_index = i;
2862 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2863 if (table->entry[i].spec &
2864 EFX_EF10_FILTER_FLAG_BUSY)
2865 break;
2866 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002867 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002868 rc = -EPERM;
2869 goto out_unlock;
2870 }
2871 if (!is_mc_recip) {
2872 /* This is the only one */
2873 if (spec->priority ==
2874 saved_spec->priority &&
2875 !replace_equal) {
2876 rc = -EEXIST;
2877 goto out_unlock;
2878 }
2879 ins_index = i;
2880 goto found;
2881 } else if (spec->priority >
2882 saved_spec->priority ||
2883 (spec->priority ==
2884 saved_spec->priority &&
2885 replace_equal)) {
2886 if (ins_index < 0)
2887 ins_index = i;
2888 else
2889 __set_bit(depth, mc_rem_map);
2890 }
2891 }
2892
2893 /* Once we reach the maximum search depth, use
2894 * the first suitable slot or return -EBUSY if
2895 * there was none
2896 */
2897 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2898 if (ins_index < 0) {
2899 rc = -EBUSY;
2900 goto out_unlock;
2901 }
2902 goto found;
2903 }
2904
2905 ++depth;
2906 }
2907
2908 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2909 spin_unlock_bh(&efx->filter_lock);
2910 schedule();
2911 }
2912
2913found:
2914 /* Create a software table entry if necessary, and mark it
2915 * busy. We might yet fail to insert, but any attempt to
2916 * insert a conflicting filter while we're waiting for the
2917 * firmware must find the busy entry.
2918 */
2919 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2920 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002921 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2922 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002923 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002924 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2925 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002926 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002927 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002928 rc = ins_index;
2929 goto out_unlock;
2930 }
2931 replacing = true;
2932 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2933 } else {
2934 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2935 if (!saved_spec) {
2936 rc = -ENOMEM;
2937 goto out_unlock;
2938 }
2939 *saved_spec = *spec;
2940 priv_flags = 0;
2941 }
2942 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2943 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2944
2945 /* Mark lower-priority multicast recipients busy prior to removal */
2946 if (is_mc_recip) {
2947 unsigned int depth, i;
2948
2949 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2950 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2951 if (test_bit(depth, mc_rem_map))
2952 table->entry[i].spec |=
2953 EFX_EF10_FILTER_FLAG_BUSY;
2954 }
2955 }
2956
2957 spin_unlock_bh(&efx->filter_lock);
2958
2959 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2960 replacing);
2961
2962 /* Finalise the software table entry */
2963 spin_lock_bh(&efx->filter_lock);
2964 if (rc == 0) {
2965 if (replacing) {
2966 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002967 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2968 saved_spec->flags |=
2969 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002970 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002971 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002972 saved_spec->flags |= spec->flags;
2973 saved_spec->rss_context = spec->rss_context;
2974 saved_spec->dmaq_id = spec->dmaq_id;
2975 }
2976 } else if (!replacing) {
2977 kfree(saved_spec);
2978 saved_spec = NULL;
2979 }
2980 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2981
2982 /* Remove and finalise entries for lower-priority multicast
2983 * recipients
2984 */
2985 if (is_mc_recip) {
2986 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2987 unsigned int depth, i;
2988
2989 memset(inbuf, 0, sizeof(inbuf));
2990
2991 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2992 if (!test_bit(depth, mc_rem_map))
2993 continue;
2994
2995 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2996 saved_spec = efx_ef10_filter_entry_spec(table, i);
2997 priv_flags = efx_ef10_filter_entry_flags(table, i);
2998
2999 if (rc == 0) {
3000 spin_unlock_bh(&efx->filter_lock);
3001 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3002 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3003 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3004 table->entry[i].handle);
3005 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3006 inbuf, sizeof(inbuf),
3007 NULL, 0, NULL);
3008 spin_lock_bh(&efx->filter_lock);
3009 }
3010
3011 if (rc == 0) {
3012 kfree(saved_spec);
3013 saved_spec = NULL;
3014 priv_flags = 0;
3015 } else {
3016 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3017 }
3018 efx_ef10_filter_set_entry(table, i, saved_spec,
3019 priv_flags);
3020 }
3021 }
3022
3023 /* If successful, return the inserted filter ID */
3024 if (rc == 0)
3025 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3026
3027 wake_up_all(&table->waitq);
3028out_unlock:
3029 spin_unlock_bh(&efx->filter_lock);
3030 finish_wait(&table->waitq, &wait);
3031 return rc;
3032}
3033
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003034static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003035{
3036 /* no need to do anything here on EF10 */
3037}
3038
3039/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003040 * If !by_index, remove by ID
3041 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003042 * Filter ID may come from userland and must be range-checked.
3043 */
3044static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003045 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003046 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003047{
3048 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3049 struct efx_ef10_filter_table *table = efx->filter_state;
3050 MCDI_DECLARE_BUF(inbuf,
3051 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3052 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3053 struct efx_filter_spec *spec;
3054 DEFINE_WAIT(wait);
3055 int rc;
3056
3057 /* Find the software table entry and mark it busy. Don't
3058 * remove it yet; any attempt to update while we're waiting
3059 * for the firmware must find the busy entry.
3060 */
3061 for (;;) {
3062 spin_lock_bh(&efx->filter_lock);
3063 if (!(table->entry[filter_idx].spec &
3064 EFX_EF10_FILTER_FLAG_BUSY))
3065 break;
3066 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3067 spin_unlock_bh(&efx->filter_lock);
3068 schedule();
3069 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003070
Ben Hutchings8127d662013-08-29 19:19:29 +01003071 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003072 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003073 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01003074 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
3075 filter_id / HUNT_FILTER_TBL_ROWS)) {
3076 rc = -ENOENT;
3077 goto out_unlock;
3078 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003079
3080 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003081 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003082 /* Just remove flags */
3083 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003084 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003085 rc = 0;
3086 goto out_unlock;
3087 }
3088
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003089 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003090 rc = -ENOENT;
3091 goto out_unlock;
3092 }
3093
Ben Hutchings8127d662013-08-29 19:19:29 +01003094 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3095 spin_unlock_bh(&efx->filter_lock);
3096
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003097 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003098 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003099
3100 struct efx_filter_spec new_spec = *spec;
3101
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003102 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003103 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003104 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003105 new_spec.dmaq_id = 0;
3106 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3107 rc = efx_ef10_filter_push(efx, &new_spec,
3108 &table->entry[filter_idx].handle,
3109 true);
3110
3111 spin_lock_bh(&efx->filter_lock);
3112 if (rc == 0)
3113 *spec = new_spec;
3114 } else {
3115 /* Really remove the filter */
3116
3117 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3118 efx_ef10_filter_is_exclusive(spec) ?
3119 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3120 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3121 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3122 table->entry[filter_idx].handle);
3123 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3124 inbuf, sizeof(inbuf), NULL, 0, NULL);
3125
3126 spin_lock_bh(&efx->filter_lock);
3127 if (rc == 0) {
3128 kfree(spec);
3129 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3130 }
3131 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003132
Ben Hutchings8127d662013-08-29 19:19:29 +01003133 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3134 wake_up_all(&table->waitq);
3135out_unlock:
3136 spin_unlock_bh(&efx->filter_lock);
3137 finish_wait(&table->waitq, &wait);
3138 return rc;
3139}
3140
3141static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3142 enum efx_filter_priority priority,
3143 u32 filter_id)
3144{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003145 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3146 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003147}
3148
3149static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3150 enum efx_filter_priority priority,
3151 u32 filter_id, struct efx_filter_spec *spec)
3152{
3153 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3154 struct efx_ef10_filter_table *table = efx->filter_state;
3155 const struct efx_filter_spec *saved_spec;
3156 int rc;
3157
3158 spin_lock_bh(&efx->filter_lock);
3159 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3160 if (saved_spec && saved_spec->priority == priority &&
3161 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
3162 filter_id / HUNT_FILTER_TBL_ROWS) {
3163 *spec = *saved_spec;
3164 rc = 0;
3165 } else {
3166 rc = -ENOENT;
3167 }
3168 spin_unlock_bh(&efx->filter_lock);
3169 return rc;
3170}
3171
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003172static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003173 enum efx_filter_priority priority)
3174{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003175 unsigned int priority_mask;
3176 unsigned int i;
3177 int rc;
3178
3179 priority_mask = (((1U << (priority + 1)) - 1) &
3180 ~(1U << EFX_FILTER_PRI_AUTO));
3181
3182 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3183 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3184 i, true);
3185 if (rc && rc != -ENOENT)
3186 return rc;
3187 }
3188
3189 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003190}
3191
3192static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3193 enum efx_filter_priority priority)
3194{
3195 struct efx_ef10_filter_table *table = efx->filter_state;
3196 unsigned int filter_idx;
3197 s32 count = 0;
3198
3199 spin_lock_bh(&efx->filter_lock);
3200 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3201 if (table->entry[filter_idx].spec &&
3202 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3203 priority)
3204 ++count;
3205 }
3206 spin_unlock_bh(&efx->filter_lock);
3207 return count;
3208}
3209
3210static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3211{
3212 struct efx_ef10_filter_table *table = efx->filter_state;
3213
3214 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3215}
3216
3217static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3218 enum efx_filter_priority priority,
3219 u32 *buf, u32 size)
3220{
3221 struct efx_ef10_filter_table *table = efx->filter_state;
3222 struct efx_filter_spec *spec;
3223 unsigned int filter_idx;
3224 s32 count = 0;
3225
3226 spin_lock_bh(&efx->filter_lock);
3227 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3228 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3229 if (spec && spec->priority == priority) {
3230 if (count == size) {
3231 count = -EMSGSIZE;
3232 break;
3233 }
3234 buf[count++] = (efx_ef10_filter_rx_match_pri(
3235 table, spec->match_flags) *
3236 HUNT_FILTER_TBL_ROWS +
3237 filter_idx);
3238 }
3239 }
3240 spin_unlock_bh(&efx->filter_lock);
3241 return count;
3242}
3243
3244#ifdef CONFIG_RFS_ACCEL
3245
3246static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3247
3248static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3249 struct efx_filter_spec *spec)
3250{
3251 struct efx_ef10_filter_table *table = efx->filter_state;
3252 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3253 struct efx_filter_spec *saved_spec;
3254 unsigned int hash, i, depth = 1;
3255 bool replacing = false;
3256 int ins_index = -1;
3257 u64 cookie;
3258 s32 rc;
3259
3260 /* Must be an RX filter without RSS and not for a multicast
3261 * destination address (RFS only works for connected sockets).
3262 * These restrictions allow us to pass only a tiny amount of
3263 * data through to the completion function.
3264 */
3265 EFX_WARN_ON_PARANOID(spec->flags !=
3266 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3267 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3268 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3269
3270 hash = efx_ef10_filter_hash(spec);
3271
3272 spin_lock_bh(&efx->filter_lock);
3273
3274 /* Find any existing filter with the same match tuple or else
3275 * a free slot to insert at. If an existing filter is busy,
3276 * we have to give up.
3277 */
3278 for (;;) {
3279 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3280 saved_spec = efx_ef10_filter_entry_spec(table, i);
3281
3282 if (!saved_spec) {
3283 if (ins_index < 0)
3284 ins_index = i;
3285 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3286 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3287 rc = -EBUSY;
3288 goto fail_unlock;
3289 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003290 if (spec->priority < saved_spec->priority) {
3291 rc = -EPERM;
3292 goto fail_unlock;
3293 }
3294 ins_index = i;
3295 break;
3296 }
3297
3298 /* Once we reach the maximum search depth, use the
3299 * first suitable slot or return -EBUSY if there was
3300 * none
3301 */
3302 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3303 if (ins_index < 0) {
3304 rc = -EBUSY;
3305 goto fail_unlock;
3306 }
3307 break;
3308 }
3309
3310 ++depth;
3311 }
3312
3313 /* Create a software table entry if necessary, and mark it
3314 * busy. We might yet fail to insert, but any attempt to
3315 * insert a conflicting filter while we're waiting for the
3316 * firmware must find the busy entry.
3317 */
3318 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3319 if (saved_spec) {
3320 replacing = true;
3321 } else {
3322 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3323 if (!saved_spec) {
3324 rc = -ENOMEM;
3325 goto fail_unlock;
3326 }
3327 *saved_spec = *spec;
3328 }
3329 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3330 EFX_EF10_FILTER_FLAG_BUSY);
3331
3332 spin_unlock_bh(&efx->filter_lock);
3333
3334 /* Pack up the variables needed on completion */
3335 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3336
3337 efx_ef10_filter_push_prep(efx, spec, inbuf,
3338 table->entry[ins_index].handle, replacing);
3339 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3340 MC_CMD_FILTER_OP_OUT_LEN,
3341 efx_ef10_filter_rfs_insert_complete, cookie);
3342
3343 return ins_index;
3344
3345fail_unlock:
3346 spin_unlock_bh(&efx->filter_lock);
3347 return rc;
3348}
3349
3350static void
3351efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3352 int rc, efx_dword_t *outbuf,
3353 size_t outlen_actual)
3354{
3355 struct efx_ef10_filter_table *table = efx->filter_state;
3356 unsigned int ins_index, dmaq_id;
3357 struct efx_filter_spec *spec;
3358 bool replacing;
3359
3360 /* Unpack the cookie */
3361 replacing = cookie >> 31;
3362 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3363 dmaq_id = cookie & 0xffff;
3364
3365 spin_lock_bh(&efx->filter_lock);
3366 spec = efx_ef10_filter_entry_spec(table, ins_index);
3367 if (rc == 0) {
3368 table->entry[ins_index].handle =
3369 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3370 if (replacing)
3371 spec->dmaq_id = dmaq_id;
3372 } else if (!replacing) {
3373 kfree(spec);
3374 spec = NULL;
3375 }
3376 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3377 spin_unlock_bh(&efx->filter_lock);
3378
3379 wake_up_all(&table->waitq);
3380}
3381
3382static void
3383efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3384 unsigned long filter_idx,
3385 int rc, efx_dword_t *outbuf,
3386 size_t outlen_actual);
3387
3388static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3389 unsigned int filter_idx)
3390{
3391 struct efx_ef10_filter_table *table = efx->filter_state;
3392 struct efx_filter_spec *spec =
3393 efx_ef10_filter_entry_spec(table, filter_idx);
3394 MCDI_DECLARE_BUF(inbuf,
3395 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3396 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3397
3398 if (!spec ||
3399 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3400 spec->priority != EFX_FILTER_PRI_HINT ||
3401 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3402 flow_id, filter_idx))
3403 return false;
3404
3405 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3406 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3407 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3408 table->entry[filter_idx].handle);
3409 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3410 efx_ef10_filter_rfs_expire_complete, filter_idx))
3411 return false;
3412
3413 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3414 return true;
3415}
3416
3417static void
3418efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3419 unsigned long filter_idx,
3420 int rc, efx_dword_t *outbuf,
3421 size_t outlen_actual)
3422{
3423 struct efx_ef10_filter_table *table = efx->filter_state;
3424 struct efx_filter_spec *spec =
3425 efx_ef10_filter_entry_spec(table, filter_idx);
3426
3427 spin_lock_bh(&efx->filter_lock);
3428 if (rc == 0) {
3429 kfree(spec);
3430 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3431 }
3432 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3433 wake_up_all(&table->waitq);
3434 spin_unlock_bh(&efx->filter_lock);
3435}
3436
3437#endif /* CONFIG_RFS_ACCEL */
3438
3439static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3440{
3441 int match_flags = 0;
3442
3443#define MAP_FLAG(gen_flag, mcdi_field) { \
3444 u32 old_mcdi_flags = mcdi_flags; \
3445 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3446 mcdi_field ## _LBN); \
3447 if (mcdi_flags != old_mcdi_flags) \
3448 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3449 }
3450 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3451 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3452 MAP_FLAG(REM_HOST, SRC_IP);
3453 MAP_FLAG(LOC_HOST, DST_IP);
3454 MAP_FLAG(REM_MAC, SRC_MAC);
3455 MAP_FLAG(REM_PORT, SRC_PORT);
3456 MAP_FLAG(LOC_MAC, DST_MAC);
3457 MAP_FLAG(LOC_PORT, DST_PORT);
3458 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3459 MAP_FLAG(INNER_VID, INNER_VLAN);
3460 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3461 MAP_FLAG(IP_PROTO, IP_PROTO);
3462#undef MAP_FLAG
3463
3464 /* Did we map them all? */
3465 if (mcdi_flags)
3466 return -EINVAL;
3467
3468 return match_flags;
3469}
3470
3471static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3472{
3473 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3474 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3475 unsigned int pd_match_pri, pd_match_count;
3476 struct efx_ef10_filter_table *table;
3477 size_t outlen;
3478 int rc;
3479
3480 table = kzalloc(sizeof(*table), GFP_KERNEL);
3481 if (!table)
3482 return -ENOMEM;
3483
3484 /* Find out which RX filter types are supported, and their priorities */
3485 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3486 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3487 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3488 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3489 &outlen);
3490 if (rc)
3491 goto fail;
3492 pd_match_count = MCDI_VAR_ARRAY_LEN(
3493 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3494 table->rx_match_count = 0;
3495
3496 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3497 u32 mcdi_flags =
3498 MCDI_ARRAY_DWORD(
3499 outbuf,
3500 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3501 pd_match_pri);
3502 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3503 if (rc < 0) {
3504 netif_dbg(efx, probe, efx->net_dev,
3505 "%s: fw flags %#x pri %u not supported in driver\n",
3506 __func__, mcdi_flags, pd_match_pri);
3507 } else {
3508 netif_dbg(efx, probe, efx->net_dev,
3509 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3510 __func__, mcdi_flags, pd_match_pri,
3511 rc, table->rx_match_count);
3512 table->rx_match_flags[table->rx_match_count++] = rc;
3513 }
3514 }
3515
3516 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3517 if (!table->entry) {
3518 rc = -ENOMEM;
3519 goto fail;
3520 }
3521
3522 efx->filter_state = table;
3523 init_waitqueue_head(&table->waitq);
3524 return 0;
3525
3526fail:
3527 kfree(table);
3528 return rc;
3529}
3530
Edward Cree0d322412015-05-20 11:10:03 +01003531/* Caller must hold efx->filter_sem for read if race against
3532 * efx_ef10_filter_table_remove() is possible
3533 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003534static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3535{
3536 struct efx_ef10_filter_table *table = efx->filter_state;
3537 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3538 struct efx_filter_spec *spec;
3539 unsigned int filter_idx;
3540 bool failed = false;
3541 int rc;
3542
Edward Cree0d322412015-05-20 11:10:03 +01003543 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3544
Ben Hutchings8127d662013-08-29 19:19:29 +01003545 if (!nic_data->must_restore_filters)
3546 return;
3547
Edward Cree0d322412015-05-20 11:10:03 +01003548 if (!table)
3549 return;
3550
Ben Hutchings8127d662013-08-29 19:19:29 +01003551 spin_lock_bh(&efx->filter_lock);
3552
3553 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3554 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3555 if (!spec)
3556 continue;
3557
3558 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3559 spin_unlock_bh(&efx->filter_lock);
3560
3561 rc = efx_ef10_filter_push(efx, spec,
3562 &table->entry[filter_idx].handle,
3563 false);
3564 if (rc)
3565 failed = true;
3566
3567 spin_lock_bh(&efx->filter_lock);
3568 if (rc) {
3569 kfree(spec);
3570 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3571 } else {
3572 table->entry[filter_idx].spec &=
3573 ~EFX_EF10_FILTER_FLAG_BUSY;
3574 }
3575 }
3576
3577 spin_unlock_bh(&efx->filter_lock);
3578
3579 if (failed)
3580 netif_err(efx, hw, efx->net_dev,
3581 "unable to restore all filters\n");
3582 else
3583 nic_data->must_restore_filters = false;
3584}
3585
Edward Cree0d322412015-05-20 11:10:03 +01003586/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003587static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3588{
3589 struct efx_ef10_filter_table *table = efx->filter_state;
3590 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3591 struct efx_filter_spec *spec;
3592 unsigned int filter_idx;
3593 int rc;
3594
Edward Cree0d322412015-05-20 11:10:03 +01003595 efx->filter_state = NULL;
3596 if (!table)
3597 return;
3598
Ben Hutchings8127d662013-08-29 19:19:29 +01003599 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3600 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3601 if (!spec)
3602 continue;
3603
3604 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3605 efx_ef10_filter_is_exclusive(spec) ?
3606 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3607 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3608 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3609 table->entry[filter_idx].handle);
3610 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3611 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003612 if (rc)
3613 netdev_WARN(efx->net_dev,
3614 "filter_idx=%#x handle=%#llx\n",
3615 filter_idx,
3616 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003617 kfree(spec);
3618 }
3619
3620 vfree(table->entry);
3621 kfree(table);
3622}
3623
Edward Cree0d322412015-05-20 11:10:03 +01003624/* Caller must hold efx->filter_sem for read if race against
3625 * efx_ef10_filter_table_remove() is possible
3626 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003627static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3628{
3629 struct efx_ef10_filter_table *table = efx->filter_state;
3630 struct net_device *net_dev = efx->net_dev;
3631 struct efx_filter_spec spec;
3632 bool remove_failed = false;
3633 struct netdev_hw_addr *uc;
3634 struct netdev_hw_addr *mc;
3635 unsigned int filter_idx;
3636 int i, n, rc;
3637
3638 if (!efx_dev_registered(efx))
3639 return;
3640
Edward Cree0d322412015-05-20 11:10:03 +01003641 if (!table)
3642 return;
3643
Ben Hutchings8127d662013-08-29 19:19:29 +01003644 /* Mark old filters that may need to be removed */
3645 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003646 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003647 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003648 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3649 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003650 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003651 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003652 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003653 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3654 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003655 }
3656 spin_unlock_bh(&efx->filter_lock);
3657
3658 /* Copy/convert the address lists; add the primary station
3659 * address and broadcast address
3660 */
3661 netif_addr_lock_bh(net_dev);
3662 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003663 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3664 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003665 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003666 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003667 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003668 i = 1;
3669 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003670 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003671 i++;
3672 }
3673 }
3674 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003675 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3676 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003677 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003678 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3679 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003680 i = 1;
3681 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003682 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003683 i++;
3684 }
3685 }
3686 netif_addr_unlock_bh(net_dev);
3687
3688 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003689 if (table->dev_uc_count >= 0) {
3690 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003691 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3692 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003693 0);
3694 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003695 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003696 rc = efx_ef10_filter_insert(efx, &spec, true);
3697 if (rc < 0) {
3698 /* Fall back to unicast-promisc */
3699 while (i--)
3700 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003701 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003702 table->dev_uc_list[i].id);
3703 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003704 break;
3705 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003706 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003707 }
3708 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003709 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003710 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3711 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003712 0);
3713 efx_filter_set_uc_def(&spec);
3714 rc = efx_ef10_filter_insert(efx, &spec, true);
3715 if (rc < 0) {
3716 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003717 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003718 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003719 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003720 }
3721 }
3722
3723 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003724 if (table->dev_mc_count >= 0) {
3725 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003726 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3727 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003728 0);
3729 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003730 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003731 rc = efx_ef10_filter_insert(efx, &spec, true);
3732 if (rc < 0) {
3733 /* Fall back to multicast-promisc */
3734 while (i--)
3735 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003736 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003737 table->dev_mc_list[i].id);
3738 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003739 break;
3740 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003741 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003742 }
3743 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003744 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003745 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3746 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003747 0);
3748 efx_filter_set_mc_def(&spec);
3749 rc = efx_ef10_filter_insert(efx, &spec, true);
3750 if (rc < 0) {
3751 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003752 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003753 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003754 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003755 }
3756 }
3757
3758 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003759 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003760 * don't need to hold the filter_lock while scanning for
3761 * these filters.
3762 */
3763 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3764 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003765 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003766 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003767 efx, 1U << EFX_FILTER_PRI_AUTO,
3768 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003769 remove_failed = true;
3770 }
3771 }
3772 WARN_ON(remove_failed);
3773}
3774
Shradha Shah910c8782015-05-20 11:12:48 +01003775static int efx_ef10_set_mac_address(struct efx_nic *efx)
3776{
3777 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
3778 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3779 bool was_enabled = efx->port_enabled;
3780 int rc;
3781
3782 efx_device_detach_sync(efx);
3783 efx_net_stop(efx->net_dev);
3784 down_write(&efx->filter_sem);
3785 efx_ef10_filter_table_remove(efx);
3786
3787 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
3788 efx->net_dev->dev_addr);
3789 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
3790 nic_data->vport_id);
3791 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
3792 sizeof(inbuf), NULL, 0, NULL);
3793
3794 efx_ef10_filter_table_probe(efx);
3795 up_write(&efx->filter_sem);
3796 if (was_enabled)
3797 efx_net_open(efx->net_dev);
3798 netif_device_attach(efx->net_dev);
3799
3800#if !defined(CONFIG_SFC_SRIOV)
3801 if (rc == -EPERM)
3802 netif_err(efx, drv, efx->net_dev,
3803 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3804 " on this interface\n");
3805#else
3806 if (rc == -EPERM) {
3807 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3808
3809 /* Switch to PF and change MAC address on vport */
3810 if (efx->pci_dev->is_virtfn && pci_dev_pf) {
3811 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3812
3813 if (!efx_ef10_sriov_set_vf_mac(efx_pf,
3814 nic_data->vf_index,
3815 efx->net_dev->dev_addr))
3816 return 0;
3817 }
3818 netif_err(efx, drv, efx->net_dev,
3819 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3820 " on this interface\n");
3821 } else if (efx->pci_dev->is_virtfn) {
3822 /* Successfully changed by VF (with MAC spoofing), so update the
3823 * parent PF if possible.
3824 */
3825 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3826
3827 if (pci_dev_pf) {
3828 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3829 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
3830 unsigned int i;
3831
3832 for (i = 0; i < efx_pf->vf_count; ++i) {
3833 struct ef10_vf *vf = nic_data->vf + i;
3834
3835 if (vf->efx == efx) {
3836 ether_addr_copy(vf->mac,
3837 efx->net_dev->dev_addr);
3838 return 0;
3839 }
3840 }
3841 }
3842 }
3843#endif
3844 return rc;
3845}
3846
Ben Hutchings8127d662013-08-29 19:19:29 +01003847static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3848{
3849 efx_ef10_filter_sync_rx_mode(efx);
3850
3851 return efx_mcdi_set_mac(efx);
3852}
3853
Shradha Shah862f8942015-05-20 11:08:56 +01003854static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3855{
3856 efx_ef10_filter_sync_rx_mode(efx);
3857
3858 return 0;
3859}
3860
Jon Cooper74cd60a2013-09-16 14:18:51 +01003861static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3862{
3863 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3864
3865 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3866 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3867 NULL, 0, NULL);
3868}
3869
3870/* MC BISTs follow a different poll mechanism to phy BISTs.
3871 * The BIST is done in the poll handler on the MC, and the MCDI command
3872 * will block until the BIST is done.
3873 */
3874static int efx_ef10_poll_bist(struct efx_nic *efx)
3875{
3876 int rc;
3877 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3878 size_t outlen;
3879 u32 result;
3880
3881 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3882 outbuf, sizeof(outbuf), &outlen);
3883 if (rc != 0)
3884 return rc;
3885
3886 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3887 return -EIO;
3888
3889 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3890 switch (result) {
3891 case MC_CMD_POLL_BIST_PASSED:
3892 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3893 return 0;
3894 case MC_CMD_POLL_BIST_TIMEOUT:
3895 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3896 return -EIO;
3897 case MC_CMD_POLL_BIST_FAILED:
3898 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3899 return -EIO;
3900 default:
3901 netif_err(efx, hw, efx->net_dev,
3902 "BIST returned unknown result %u", result);
3903 return -EIO;
3904 }
3905}
3906
3907static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3908{
3909 int rc;
3910
3911 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3912
3913 rc = efx_ef10_start_bist(efx, bist_type);
3914 if (rc != 0)
3915 return rc;
3916
3917 return efx_ef10_poll_bist(efx);
3918}
3919
3920static int
3921efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3922{
3923 int rc, rc2;
3924
3925 efx_reset_down(efx, RESET_TYPE_WORLD);
3926
3927 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3928 NULL, 0, NULL, 0, NULL);
3929 if (rc != 0)
3930 goto out;
3931
3932 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3933 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3934
3935 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3936
3937out:
3938 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3939 return rc ? rc : rc2;
3940}
3941
Ben Hutchings8127d662013-08-29 19:19:29 +01003942#ifdef CONFIG_SFC_MTD
3943
3944struct efx_ef10_nvram_type_info {
3945 u16 type, type_mask;
3946 u8 port;
3947 const char *name;
3948};
3949
3950static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3951 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3952 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3953 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3954 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3955 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3956 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3957 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3958 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3959 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003960 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003961 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3962};
3963
3964static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3965 struct efx_mcdi_mtd_partition *part,
3966 unsigned int type)
3967{
3968 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3969 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3970 const struct efx_ef10_nvram_type_info *info;
3971 size_t size, erase_size, outlen;
3972 bool protected;
3973 int rc;
3974
3975 for (info = efx_ef10_nvram_types; ; info++) {
3976 if (info ==
3977 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3978 return -ENODEV;
3979 if ((type & ~info->type_mask) == info->type)
3980 break;
3981 }
3982 if (info->port != efx_port_num(efx))
3983 return -ENODEV;
3984
3985 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3986 if (rc)
3987 return rc;
3988 if (protected)
3989 return -ENODEV; /* hide it */
3990
3991 part->nvram_type = type;
3992
3993 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3994 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3995 outbuf, sizeof(outbuf), &outlen);
3996 if (rc)
3997 return rc;
3998 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3999 return -EIO;
4000 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
4001 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
4002 part->fw_subtype = MCDI_DWORD(outbuf,
4003 NVRAM_METADATA_OUT_SUBTYPE);
4004
4005 part->common.dev_type_name = "EF10 NVRAM manager";
4006 part->common.type_name = info->name;
4007
4008 part->common.mtd.type = MTD_NORFLASH;
4009 part->common.mtd.flags = MTD_CAP_NORFLASH;
4010 part->common.mtd.size = size;
4011 part->common.mtd.erasesize = erase_size;
4012
4013 return 0;
4014}
4015
4016static int efx_ef10_mtd_probe(struct efx_nic *efx)
4017{
4018 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
4019 struct efx_mcdi_mtd_partition *parts;
4020 size_t outlen, n_parts_total, i, n_parts;
4021 unsigned int type;
4022 int rc;
4023
4024 ASSERT_RTNL();
4025
4026 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
4027 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
4028 outbuf, sizeof(outbuf), &outlen);
4029 if (rc)
4030 return rc;
4031 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
4032 return -EIO;
4033
4034 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
4035 if (n_parts_total >
4036 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
4037 return -EIO;
4038
4039 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
4040 if (!parts)
4041 return -ENOMEM;
4042
4043 n_parts = 0;
4044 for (i = 0; i < n_parts_total; i++) {
4045 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
4046 i);
4047 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
4048 if (rc == 0)
4049 n_parts++;
4050 else if (rc != -ENODEV)
4051 goto fail;
4052 }
4053
4054 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
4055fail:
4056 if (rc)
4057 kfree(parts);
4058 return rc;
4059}
4060
4061#endif /* CONFIG_SFC_MTD */
4062
4063static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
4064{
4065 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
4066}
4067
Shradha Shah02246a72015-05-06 00:58:14 +01004068static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
4069 u32 host_time) {}
4070
Jon Cooperbd9a2652013-11-18 12:54:41 +00004071static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
4072 bool temp)
4073{
4074 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
4075 int rc;
4076
4077 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
4078 channel->sync_events_state == SYNC_EVENTS_VALID ||
4079 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
4080 return 0;
4081 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
4082
4083 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
4084 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4085 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
4086 channel->channel);
4087
4088 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4089 inbuf, sizeof(inbuf), NULL, 0, NULL);
4090
4091 if (rc != 0)
4092 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4093 SYNC_EVENTS_DISABLED;
4094
4095 return rc;
4096}
4097
4098static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
4099 bool temp)
4100{
4101 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
4102 int rc;
4103
4104 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
4105 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
4106 return 0;
4107 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
4108 channel->sync_events_state = SYNC_EVENTS_DISABLED;
4109 return 0;
4110 }
4111 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4112 SYNC_EVENTS_DISABLED;
4113
4114 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
4115 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4116 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
4117 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
4118 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
4119 channel->channel);
4120
4121 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4122 inbuf, sizeof(inbuf), NULL, 0, NULL);
4123
4124 return rc;
4125}
4126
4127static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
4128 bool temp)
4129{
4130 int (*set)(struct efx_channel *channel, bool temp);
4131 struct efx_channel *channel;
4132
4133 set = en ?
4134 efx_ef10_rx_enable_timestamping :
4135 efx_ef10_rx_disable_timestamping;
4136
4137 efx_for_each_channel(channel, efx) {
4138 int rc = set(channel, temp);
4139 if (en && rc != 0) {
4140 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
4141 return rc;
4142 }
4143 }
4144
4145 return 0;
4146}
4147
Shradha Shah02246a72015-05-06 00:58:14 +01004148static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
4149 struct hwtstamp_config *init)
4150{
4151 return -EOPNOTSUPP;
4152}
4153
Jon Cooperbd9a2652013-11-18 12:54:41 +00004154static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
4155 struct hwtstamp_config *init)
4156{
4157 int rc;
4158
4159 switch (init->rx_filter) {
4160 case HWTSTAMP_FILTER_NONE:
4161 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
4162 /* if TX timestamping is still requested then leave PTP on */
4163 return efx_ptp_change_mode(efx,
4164 init->tx_type != HWTSTAMP_TX_OFF, 0);
4165 case HWTSTAMP_FILTER_ALL:
4166 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
4167 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
4168 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
4169 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
4170 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
4171 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
4172 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
4173 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
4174 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
4175 case HWTSTAMP_FILTER_PTP_V2_EVENT:
4176 case HWTSTAMP_FILTER_PTP_V2_SYNC:
4177 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
4178 init->rx_filter = HWTSTAMP_FILTER_ALL;
4179 rc = efx_ptp_change_mode(efx, true, 0);
4180 if (!rc)
4181 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
4182 if (rc)
4183 efx_ptp_change_mode(efx, false, 0);
4184 return rc;
4185 default:
4186 return -ERANGE;
4187 }
4188}
4189
Shradha Shah02246a72015-05-06 00:58:14 +01004190const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004191 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01004192 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01004193 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01004194 .probe = efx_ef10_probe_vf,
4195 .remove = efx_ef10_remove,
4196 .dimension_resources = efx_ef10_dimension_resources,
4197 .init = efx_ef10_init_nic,
4198 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004199 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01004200 .map_reset_flags = efx_ef10_map_reset_flags,
4201 .reset = efx_ef10_reset,
4202 .probe_port = efx_mcdi_port_probe,
4203 .remove_port = efx_mcdi_port_remove,
4204 .fini_dmaq = efx_ef10_fini_dmaq,
4205 .prepare_flr = efx_ef10_prepare_flr,
4206 .finish_flr = efx_port_dummy_op_void,
4207 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004208 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004209 .start_stats = efx_port_dummy_op_void,
4210 .pull_stats = efx_port_dummy_op_void,
4211 .stop_stats = efx_port_dummy_op_void,
4212 .set_id_led = efx_mcdi_set_id_led,
4213 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01004214 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004215 .check_mac_fault = efx_mcdi_mac_check_fault,
4216 .reconfigure_port = efx_mcdi_port_reconfigure,
4217 .get_wol = efx_ef10_get_wol_vf,
4218 .set_wol = efx_ef10_set_wol_vf,
4219 .resume_wol = efx_port_dummy_op_void,
4220 .mcdi_request = efx_ef10_mcdi_request,
4221 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4222 .mcdi_read_response = efx_ef10_mcdi_read_response,
4223 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4224 .irq_enable_master = efx_port_dummy_op_void,
4225 .irq_test_generate = efx_ef10_irq_test_generate,
4226 .irq_disable_non_ev = efx_port_dummy_op_void,
4227 .irq_handle_msi = efx_ef10_msi_interrupt,
4228 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4229 .tx_probe = efx_ef10_tx_probe,
4230 .tx_init = efx_ef10_tx_init,
4231 .tx_remove = efx_ef10_tx_remove,
4232 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004233 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01004234 .rx_probe = efx_ef10_rx_probe,
4235 .rx_init = efx_ef10_rx_init,
4236 .rx_remove = efx_ef10_rx_remove,
4237 .rx_write = efx_ef10_rx_write,
4238 .rx_defer_refill = efx_ef10_rx_defer_refill,
4239 .ev_probe = efx_ef10_ev_probe,
4240 .ev_init = efx_ef10_ev_init,
4241 .ev_fini = efx_ef10_ev_fini,
4242 .ev_remove = efx_ef10_ev_remove,
4243 .ev_process = efx_ef10_ev_process,
4244 .ev_read_ack = efx_ef10_ev_read_ack,
4245 .ev_test_generate = efx_ef10_ev_test_generate,
4246 .filter_table_probe = efx_ef10_filter_table_probe,
4247 .filter_table_restore = efx_ef10_filter_table_restore,
4248 .filter_table_remove = efx_ef10_filter_table_remove,
4249 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4250 .filter_insert = efx_ef10_filter_insert,
4251 .filter_remove_safe = efx_ef10_filter_remove_safe,
4252 .filter_get_safe = efx_ef10_filter_get_safe,
4253 .filter_clear_rx = efx_ef10_filter_clear_rx,
4254 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4255 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4256 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4257#ifdef CONFIG_RFS_ACCEL
4258 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4259 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4260#endif
4261#ifdef CONFIG_SFC_MTD
4262 .mtd_probe = efx_port_dummy_op_int,
4263#endif
4264 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4265 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4266#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004267 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4268 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4269 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01004270 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01004271#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004272 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01004273 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004274
Shradha Shah02246a72015-05-06 00:58:14 +01004275 .revision = EFX_REV_HUNT_A0,
4276 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4277 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4278 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4279 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4280 .can_rx_scatter = true,
4281 .always_rx_scatter = true,
4282 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4283 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4284 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4285 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4286 .mcdi_max_ver = 2,
4287 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4288 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4289 1 << HWTSTAMP_FILTER_ALL,
4290};
4291
4292const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004293 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004294 .mem_bar = EFX_MEM_BAR,
4295 .mem_map_size = efx_ef10_mem_map_size,
4296 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004297 .remove = efx_ef10_remove,
4298 .dimension_resources = efx_ef10_dimension_resources,
4299 .init = efx_ef10_init_nic,
4300 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004301 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01004302 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004303 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004304 .probe_port = efx_mcdi_port_probe,
4305 .remove_port = efx_mcdi_port_remove,
4306 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004307 .prepare_flr = efx_ef10_prepare_flr,
4308 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004309 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004310 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004311 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004312 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004313 .stop_stats = efx_mcdi_mac_stop_stats,
4314 .set_id_led = efx_mcdi_set_id_led,
4315 .push_irq_moderation = efx_ef10_push_irq_moderation,
4316 .reconfigure_mac = efx_ef10_mac_reconfigure,
4317 .check_mac_fault = efx_mcdi_mac_check_fault,
4318 .reconfigure_port = efx_mcdi_port_reconfigure,
4319 .get_wol = efx_ef10_get_wol,
4320 .set_wol = efx_ef10_set_wol,
4321 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004322 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004323 .test_nvram = efx_mcdi_nvram_test_all,
4324 .mcdi_request = efx_ef10_mcdi_request,
4325 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4326 .mcdi_read_response = efx_ef10_mcdi_read_response,
4327 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4328 .irq_enable_master = efx_port_dummy_op_void,
4329 .irq_test_generate = efx_ef10_irq_test_generate,
4330 .irq_disable_non_ev = efx_port_dummy_op_void,
4331 .irq_handle_msi = efx_ef10_msi_interrupt,
4332 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4333 .tx_probe = efx_ef10_tx_probe,
4334 .tx_init = efx_ef10_tx_init,
4335 .tx_remove = efx_ef10_tx_remove,
4336 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004337 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004338 .rx_probe = efx_ef10_rx_probe,
4339 .rx_init = efx_ef10_rx_init,
4340 .rx_remove = efx_ef10_rx_remove,
4341 .rx_write = efx_ef10_rx_write,
4342 .rx_defer_refill = efx_ef10_rx_defer_refill,
4343 .ev_probe = efx_ef10_ev_probe,
4344 .ev_init = efx_ef10_ev_init,
4345 .ev_fini = efx_ef10_ev_fini,
4346 .ev_remove = efx_ef10_ev_remove,
4347 .ev_process = efx_ef10_ev_process,
4348 .ev_read_ack = efx_ef10_ev_read_ack,
4349 .ev_test_generate = efx_ef10_ev_test_generate,
4350 .filter_table_probe = efx_ef10_filter_table_probe,
4351 .filter_table_restore = efx_ef10_filter_table_restore,
4352 .filter_table_remove = efx_ef10_filter_table_remove,
4353 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4354 .filter_insert = efx_ef10_filter_insert,
4355 .filter_remove_safe = efx_ef10_filter_remove_safe,
4356 .filter_get_safe = efx_ef10_filter_get_safe,
4357 .filter_clear_rx = efx_ef10_filter_clear_rx,
4358 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4359 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4360 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4361#ifdef CONFIG_RFS_ACCEL
4362 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4363 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4364#endif
4365#ifdef CONFIG_SFC_MTD
4366 .mtd_probe = efx_ef10_mtd_probe,
4367 .mtd_rename = efx_mcdi_mtd_rename,
4368 .mtd_read = efx_mcdi_mtd_read,
4369 .mtd_erase = efx_mcdi_mtd_erase,
4370 .mtd_write = efx_mcdi_mtd_write,
4371 .mtd_sync = efx_mcdi_mtd_sync,
4372#endif
4373 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004374 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4375 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004376#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004377 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004378 .sriov_init = efx_ef10_sriov_init,
4379 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004380 .sriov_wanted = efx_ef10_sriov_wanted,
4381 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004382 .sriov_flr = efx_ef10_sriov_flr,
4383 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4384 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4385 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4386 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01004387 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004388 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4389 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4390 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004391#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004392 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004393 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01004394
4395 .revision = EFX_REV_HUNT_A0,
4396 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4397 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4398 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004399 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004400 .can_rx_scatter = true,
4401 .always_rx_scatter = true,
4402 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4403 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4404 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4405 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4406 .mcdi_max_ver = 2,
4407 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004408 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4409 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004410};