blob: a79a24f94123877231eaeb4161e269e7ae3ecd88 [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 Pieczko3c36a2a2015-06-02 11:39:06 +01001165 u64 raw_mask[2];
1166
1167 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1168
1169 /* All functions see the vadaptor stats */
1170 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1171 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
Edward Cree4bae9132013-09-27 18:52:49 +01001172
1173#if BITS_PER_LONG == 64
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001174 mask[0] = raw_mask[0];
1175 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001176#else
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001177 mask[0] = raw_mask[0] & 0xffffffff;
1178 mask[1] = raw_mask[0] >> 32;
1179 mask[2] = raw_mask[1] & 0xffffffff;
1180 mask[3] = raw_mask[1] >> 32;
Edward Cree4bae9132013-09-27 18:52:49 +01001181#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001182}
1183
1184static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1185{
Edward Cree4bae9132013-09-27 18:52:49 +01001186 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1187
1188 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001189 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001190 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001191}
1192
Daniel Pieczkod7788192015-06-02 11:39:20 +01001193static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1194 struct rtnl_link_stats64 *core_stats)
1195{
1196 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1197 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1198 u64 *stats = nic_data->stats;
1199 size_t stats_count = 0, index;
1200
1201 efx_ef10_get_stat_mask(efx, mask);
1202
1203 if (full_stats) {
1204 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1205 if (efx_ef10_stat_desc[index].name) {
1206 *full_stats++ = stats[index];
1207 ++stats_count;
1208 }
1209 }
1210 }
1211
1212 if (core_stats) {
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001213 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1214 stats[EF10_STAT_rx_multicast] +
1215 stats[EF10_STAT_rx_broadcast];
1216 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1217 stats[EF10_STAT_tx_multicast] +
1218 stats[EF10_STAT_tx_broadcast];
1219 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1220 stats[EF10_STAT_rx_multicast_bytes] +
1221 stats[EF10_STAT_rx_broadcast_bytes];
1222 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1223 stats[EF10_STAT_tx_multicast_bytes] +
1224 stats[EF10_STAT_tx_broadcast_bytes];
1225 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001226 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001227 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1228 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1229 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1230 core_stats->rx_errors = core_stats->rx_crc_errors;
1231 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Daniel Pieczkod7788192015-06-02 11:39:20 +01001232 }
1233
1234 return stats_count;
1235}
1236
1237static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001238{
1239 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001240 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001241 __le64 generation_start, generation_end;
1242 u64 *stats = nic_data->stats;
1243 __le64 *dma_stats;
1244
Edward Cree4bae9132013-09-27 18:52:49 +01001245 efx_ef10_get_stat_mask(efx, mask);
1246
Ben Hutchings8127d662013-08-29 19:19:29 +01001247 dma_stats = efx->stats_buffer.addr;
1248 nic_data = efx->nic_data;
1249
1250 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1251 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1252 return 0;
1253 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001254 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001255 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001256 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001257 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1258 if (generation_end != generation_start)
1259 return -EAGAIN;
1260
1261 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001262 efx_nic_fix_nodesc_drop_stat(efx,
1263 &stats[EF10_STAT_port_rx_nodesc_drops]);
1264 stats[EF10_STAT_port_rx_good_bytes] =
1265 stats[EF10_STAT_port_rx_bytes] -
1266 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1267 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1268 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001269 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001270 return 0;
1271}
1272
1273
Daniel Pieczkod7788192015-06-02 11:39:20 +01001274static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1275 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001276{
Ben Hutchings8127d662013-08-29 19:19:29 +01001277 int retry;
1278
1279 /* If we're unlucky enough to read statistics during the DMA, wait
1280 * up to 10ms for it to finish (typically takes <500us)
1281 */
1282 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001283 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001284 break;
1285 udelay(100);
1286 }
1287
Daniel Pieczkod7788192015-06-02 11:39:20 +01001288 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1289}
1290
1291static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1292{
1293 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1294 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1295 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1296 __le64 generation_start, generation_end;
1297 u64 *stats = nic_data->stats;
1298 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1299 struct efx_buffer stats_buf;
1300 __le64 *dma_stats;
1301 int rc;
1302
1303 efx_ef10_get_stat_mask(efx, mask);
1304
1305 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
1306 if (rc)
1307 return rc;
1308
1309 dma_stats = stats_buf.addr;
1310 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1311
1312 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1313 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001314 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001315 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1316 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1317
1318 spin_unlock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001319 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1320 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001321 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001322 if (rc) {
1323 /* Expect ENOENT if DMA queues have not been set up */
1324 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1325 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1326 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001327 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01001328 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001329
1330 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001331 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1332 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001333 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001334 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01001335 rmb();
1336 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1337 stats, stats_buf.addr, false);
1338 rmb();
1339 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1340 if (generation_end != generation_start) {
1341 rc = -EAGAIN;
1342 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01001343 }
1344
Daniel Pieczkod7788192015-06-02 11:39:20 +01001345 efx_update_sw_stats(efx, stats);
1346out:
1347 efx_nic_free_buffer(efx, &stats_buf);
1348 return rc;
1349}
Ben Hutchings8127d662013-08-29 19:19:29 +01001350
Daniel Pieczkod7788192015-06-02 11:39:20 +01001351static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1352 struct rtnl_link_stats64 *core_stats)
1353{
1354 if (efx_ef10_try_update_nic_stats_vf(efx))
1355 return 0;
1356
1357 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001358}
1359
1360static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1361{
1362 struct efx_nic *efx = channel->efx;
1363 unsigned int mode, value;
1364 efx_dword_t timer_cmd;
1365
1366 if (channel->irq_moderation) {
1367 mode = 3;
1368 value = channel->irq_moderation - 1;
1369 } else {
1370 mode = 0;
1371 value = 0;
1372 }
1373
1374 if (EFX_EF10_WORKAROUND_35388(efx)) {
1375 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1376 EFE_DD_EVQ_IND_TIMER_FLAGS,
1377 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1378 ERF_DD_EVQ_IND_TIMER_VAL, value);
1379 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1380 channel->channel);
1381 } else {
1382 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1383 ERF_DZ_TC_TIMER_VAL, value);
1384 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1385 channel->channel);
1386 }
1387}
1388
Shradha Shah02246a72015-05-06 00:58:14 +01001389static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1390 struct ethtool_wolinfo *wol) {}
1391
1392static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1393{
1394 return -EOPNOTSUPP;
1395}
1396
Ben Hutchings8127d662013-08-29 19:19:29 +01001397static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1398{
1399 wol->supported = 0;
1400 wol->wolopts = 0;
1401 memset(&wol->sopass, 0, sizeof(wol->sopass));
1402}
1403
1404static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1405{
1406 if (type != 0)
1407 return -EINVAL;
1408 return 0;
1409}
1410
1411static void efx_ef10_mcdi_request(struct efx_nic *efx,
1412 const efx_dword_t *hdr, size_t hdr_len,
1413 const efx_dword_t *sdu, size_t sdu_len)
1414{
1415 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1416 u8 *pdu = nic_data->mcdi_buf.addr;
1417
1418 memcpy(pdu, hdr, hdr_len);
1419 memcpy(pdu + hdr_len, sdu, sdu_len);
1420 wmb();
1421
1422 /* The hardware provides 'low' and 'high' (doorbell) registers
1423 * for passing the 64-bit address of an MCDI request to
1424 * firmware. However the dwords are swapped by firmware. The
1425 * least significant bits of the doorbell are then 0 for all
1426 * MCDI requests due to alignment.
1427 */
1428 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1429 ER_DZ_MC_DB_LWRD);
1430 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1431 ER_DZ_MC_DB_HWRD);
1432}
1433
1434static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1435{
1436 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1437 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1438
1439 rmb();
1440 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1441}
1442
1443static void
1444efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1445 size_t offset, size_t outlen)
1446{
1447 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1448 const u8 *pdu = nic_data->mcdi_buf.addr;
1449
1450 memcpy(outbuf, pdu + offset, outlen);
1451}
1452
1453static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1454{
1455 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1456 int rc;
1457
1458 rc = efx_ef10_get_warm_boot_count(efx);
1459 if (rc < 0) {
1460 /* The firmware is presumably in the process of
1461 * rebooting. However, we are supposed to report each
1462 * reboot just once, so we must only do that once we
1463 * can read and store the updated warm boot count.
1464 */
1465 return 0;
1466 }
1467
1468 if (rc == nic_data->warm_boot_count)
1469 return 0;
1470
1471 nic_data->warm_boot_count = rc;
1472
1473 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001474 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001475
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001476 /* Driver-created vswitches and vports must be re-created */
1477 nic_data->must_probe_vswitching = true;
1478 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1479
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001480 /* The datapath firmware might have been changed */
1481 nic_data->must_check_datapath_caps = true;
1482
Ben Hutchings869070c2013-09-05 22:46:10 +01001483 /* MAC statistics have been cleared on the NIC; clear the local
1484 * statistic that we update with efx_update_diff_stat().
1485 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001486 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
Ben Hutchings869070c2013-09-05 22:46:10 +01001487
Ben Hutchings8127d662013-08-29 19:19:29 +01001488 return -EIO;
1489}
1490
1491/* Handle an MSI interrupt
1492 *
1493 * Handle an MSI hardware interrupt. This routine schedules event
1494 * queue processing. No interrupt acknowledgement cycle is necessary.
1495 * Also, we never need to check that the interrupt is for us, since
1496 * MSI interrupts cannot be shared.
1497 */
1498static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1499{
1500 struct efx_msi_context *context = dev_id;
1501 struct efx_nic *efx = context->efx;
1502
1503 netif_vdbg(efx, intr, efx->net_dev,
1504 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1505
1506 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1507 /* Note test interrupts */
1508 if (context->index == efx->irq_level)
1509 efx->last_irq_cpu = raw_smp_processor_id();
1510
1511 /* Schedule processing of the channel */
1512 efx_schedule_channel_irq(efx->channel[context->index]);
1513 }
1514
1515 return IRQ_HANDLED;
1516}
1517
1518static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1519{
1520 struct efx_nic *efx = dev_id;
1521 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1522 struct efx_channel *channel;
1523 efx_dword_t reg;
1524 u32 queues;
1525
1526 /* Read the ISR which also ACKs the interrupts */
1527 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1528 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1529
1530 if (queues == 0)
1531 return IRQ_NONE;
1532
1533 if (likely(soft_enabled)) {
1534 /* Note test interrupts */
1535 if (queues & (1U << efx->irq_level))
1536 efx->last_irq_cpu = raw_smp_processor_id();
1537
1538 efx_for_each_channel(channel, efx) {
1539 if (queues & 1)
1540 efx_schedule_channel_irq(channel);
1541 queues >>= 1;
1542 }
1543 }
1544
1545 netif_vdbg(efx, intr, efx->net_dev,
1546 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1547 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1548
1549 return IRQ_HANDLED;
1550}
1551
1552static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1553{
1554 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1555
1556 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1557
1558 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1559 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1560 inbuf, sizeof(inbuf), NULL, 0, NULL);
1561}
1562
1563static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1564{
1565 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1566 (tx_queue->ptr_mask + 1) *
1567 sizeof(efx_qword_t),
1568 GFP_KERNEL);
1569}
1570
1571/* This writes to the TX_DESC_WPTR and also pushes data */
1572static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1573 const efx_qword_t *txd)
1574{
1575 unsigned int write_ptr;
1576 efx_oword_t reg;
1577
1578 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1579 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1580 reg.qword[0] = *txd;
1581 efx_writeo_page(tx_queue->efx, &reg,
1582 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1583}
1584
1585static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1586{
1587 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1588 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001589 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1590 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1591 struct efx_channel *channel = tx_queue->channel;
1592 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001593 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001594 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001595 dma_addr_t dma_addr;
1596 efx_qword_t *txd;
1597 int rc;
1598 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001599 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001600
1601 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1602 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1603 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1604 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1605 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1606 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1607 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1608 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001609 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001610
1611 dma_addr = tx_queue->txd.buf.dma_addr;
1612
1613 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1614 tx_queue->queue, entries, (u64)dma_addr);
1615
1616 for (i = 0; i < entries; ++i) {
1617 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1618 dma_addr += EFX_BUF_SIZE;
1619 }
1620
1621 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1622
1623 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001624 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001625 if (rc)
1626 goto fail;
1627
1628 /* A previous user of this TX queue might have set us up the
1629 * bomb by writing a descriptor to the TX push collector but
1630 * not the doorbell. (Each collector belongs to a port, not a
1631 * queue or function, so cannot easily be reset.) We must
1632 * attempt to push a no-op descriptor in its place.
1633 */
1634 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1635 tx_queue->insert_count = 1;
1636 txd = efx_tx_desc(tx_queue, 0);
1637 EFX_POPULATE_QWORD_4(*txd,
1638 ESF_DZ_TX_DESC_IS_OPT, true,
1639 ESF_DZ_TX_OPTION_TYPE,
1640 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1641 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1642 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1643 tx_queue->write_count = 1;
1644 wmb();
1645 efx_ef10_push_tx_desc(tx_queue, txd);
1646
1647 return;
1648
1649fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001650 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1651 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001652}
1653
1654static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1655{
1656 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001657 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001658 struct efx_nic *efx = tx_queue->efx;
1659 size_t outlen;
1660 int rc;
1661
1662 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1663 tx_queue->queue);
1664
Edward Cree1e0b8122013-05-31 18:36:12 +01001665 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001666 outbuf, sizeof(outbuf), &outlen);
1667
1668 if (rc && rc != -EALREADY)
1669 goto fail;
1670
1671 return;
1672
1673fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001674 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1675 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001676}
1677
1678static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1679{
1680 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1681}
1682
1683/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1684static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1685{
1686 unsigned int write_ptr;
1687 efx_dword_t reg;
1688
1689 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1690 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1691 efx_writed_page(tx_queue->efx, &reg,
1692 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1693}
1694
1695static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1696{
1697 unsigned int old_write_count = tx_queue->write_count;
1698 struct efx_tx_buffer *buffer;
1699 unsigned int write_ptr;
1700 efx_qword_t *txd;
1701
1702 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1703
1704 do {
1705 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1706 buffer = &tx_queue->buffer[write_ptr];
1707 txd = efx_tx_desc(tx_queue, write_ptr);
1708 ++tx_queue->write_count;
1709
1710 /* Create TX descriptor ring entry */
1711 if (buffer->flags & EFX_TX_BUF_OPTION) {
1712 *txd = buffer->option;
1713 } else {
1714 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1715 EFX_POPULATE_QWORD_3(
1716 *txd,
1717 ESF_DZ_TX_KER_CONT,
1718 buffer->flags & EFX_TX_BUF_CONT,
1719 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1720 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1721 }
1722 } while (tx_queue->write_count != tx_queue->insert_count);
1723
1724 wmb(); /* Ensure descriptors are written before they are fetched */
1725
1726 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1727 txd = efx_tx_desc(tx_queue,
1728 old_write_count & tx_queue->ptr_mask);
1729 efx_ef10_push_tx_desc(tx_queue, txd);
1730 ++tx_queue->pushes;
1731 } else {
1732 efx_ef10_notify_tx_desc(tx_queue);
1733 }
1734}
1735
Jon Cooper267c0152015-05-06 00:59:38 +01001736static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1737 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001738{
1739 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1740 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001741 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001742 size_t outlen;
1743 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001744 u32 alloc_type = exclusive ?
1745 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1746 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1747 unsigned rss_spread = exclusive ?
1748 efx->rss_spread :
1749 min(rounddown_pow_of_two(efx->rss_spread),
1750 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1751
1752 if (!exclusive && rss_spread == 1) {
1753 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1754 if (context_size)
1755 *context_size = 1;
1756 return 0;
1757 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001758
1759 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001760 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001761 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1762 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001763
1764 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1765 outbuf, sizeof(outbuf), &outlen);
1766 if (rc != 0)
1767 return rc;
1768
1769 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1770 return -EIO;
1771
1772 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1773
Jon Cooper267c0152015-05-06 00:59:38 +01001774 if (context_size)
1775 *context_size = rss_spread;
1776
Ben Hutchings8127d662013-08-29 19:19:29 +01001777 return 0;
1778}
1779
1780static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1781{
1782 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1783 int rc;
1784
1785 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1786 context);
1787
1788 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1789 NULL, 0, NULL);
1790 WARN_ON(rc != 0);
1791}
1792
Jon Cooper267c0152015-05-06 00:59:38 +01001793static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1794 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001795{
1796 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1797 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1798 int i, rc;
1799
1800 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1801 context);
1802 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1803 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1804
1805 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1806 MCDI_PTR(tablebuf,
1807 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001808 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001809
1810 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1811 sizeof(tablebuf), NULL, 0, NULL);
1812 if (rc != 0)
1813 return rc;
1814
1815 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1816 context);
1817 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1818 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1819 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1820 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1821 efx->rx_hash_key[i];
1822
1823 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1824 sizeof(keybuf), NULL, 0, NULL);
1825}
1826
1827static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1828{
1829 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1830
1831 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1832 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1833 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1834}
1835
Jon Cooper267c0152015-05-06 00:59:38 +01001836static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1837 unsigned *context_size)
1838{
1839 u32 new_rx_rss_context;
1840 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1841 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1842 false, context_size);
1843
1844 if (rc != 0)
1845 return rc;
1846
1847 nic_data->rx_rss_context = new_rx_rss_context;
1848 nic_data->rx_rss_context_exclusive = false;
1849 efx_set_default_rx_indir_table(efx);
1850 return 0;
1851}
1852
1853static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1854 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001855{
1856 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1857 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001858 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001859
Jon Cooper267c0152015-05-06 00:59:38 +01001860 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1861 !nic_data->rx_rss_context_exclusive) {
1862 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1863 true, NULL);
1864 if (rc == -EOPNOTSUPP)
1865 return rc;
1866 else if (rc != 0)
1867 goto fail1;
1868 } else {
1869 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001870 }
1871
Jon Cooper267c0152015-05-06 00:59:38 +01001872 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1873 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001874 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001875 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001876
Jon Cooper267c0152015-05-06 00:59:38 +01001877 if (nic_data->rx_rss_context != new_rx_rss_context)
1878 efx_ef10_rx_free_indir_table(efx);
1879 nic_data->rx_rss_context = new_rx_rss_context;
1880 nic_data->rx_rss_context_exclusive = true;
1881 if (rx_indir_table != efx->rx_indir_table)
1882 memcpy(efx->rx_indir_table, rx_indir_table,
1883 sizeof(efx->rx_indir_table));
1884 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001885
Jon Cooper267c0152015-05-06 00:59:38 +01001886fail2:
1887 if (new_rx_rss_context != nic_data->rx_rss_context)
1888 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1889fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001890 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001891 return rc;
1892}
1893
1894static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1895 const u32 *rx_indir_table)
1896{
1897 int rc;
1898
1899 if (efx->rss_spread == 1)
1900 return 0;
1901
1902 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1903
1904 if (rc == -ENOBUFS && !user) {
1905 unsigned context_size;
1906 bool mismatch = false;
1907 size_t i;
1908
1909 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1910 i++)
1911 mismatch = rx_indir_table[i] !=
1912 ethtool_rxfh_indir_default(i, efx->rss_spread);
1913
1914 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1915 if (rc == 0) {
1916 if (context_size != efx->rss_spread)
1917 netif_warn(efx, probe, efx->net_dev,
1918 "Could not allocate an exclusive RSS"
1919 " context; allocated a shared one of"
1920 " different size."
1921 " Wanted %u, got %u.\n",
1922 efx->rss_spread, context_size);
1923 else if (mismatch)
1924 netif_warn(efx, probe, efx->net_dev,
1925 "Could not allocate an exclusive RSS"
1926 " context; allocated a shared one but"
1927 " could not apply custom"
1928 " indirection.\n");
1929 else
1930 netif_info(efx, probe, efx->net_dev,
1931 "Could not allocate an exclusive RSS"
1932 " context; allocated a shared one.\n");
1933 }
1934 }
1935 return rc;
1936}
1937
1938static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1939 const u32 *rx_indir_table
1940 __attribute__ ((unused)))
1941{
1942 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1943
1944 if (user)
1945 return -EOPNOTSUPP;
1946 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1947 return 0;
1948 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001949}
1950
1951static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1952{
1953 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1954 (rx_queue->ptr_mask + 1) *
1955 sizeof(efx_qword_t),
1956 GFP_KERNEL);
1957}
1958
1959static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1960{
1961 MCDI_DECLARE_BUF(inbuf,
1962 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1963 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001964 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1965 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1966 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001967 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001968 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001969 dma_addr_t dma_addr;
1970 int rc;
1971 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001972 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001973
1974 rx_queue->scatter_n = 0;
1975 rx_queue->scatter_len = 0;
1976
1977 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1978 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1979 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1980 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1981 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001982 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1983 INIT_RXQ_IN_FLAG_PREFIX, 1,
1984 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001985 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001986 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001987
1988 dma_addr = rx_queue->rxd.buf.dma_addr;
1989
1990 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1991 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1992
1993 for (i = 0; i < entries; ++i) {
1994 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
1995 dma_addr += EFX_BUF_SIZE;
1996 }
1997
1998 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
1999
2000 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002001 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00002002 if (rc)
2003 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2004 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01002005}
2006
2007static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2008{
2009 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002010 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002011 struct efx_nic *efx = rx_queue->efx;
2012 size_t outlen;
2013 int rc;
2014
2015 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2016 efx_rx_queue_index(rx_queue));
2017
Edward Cree1e0b8122013-05-31 18:36:12 +01002018 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002019 outbuf, sizeof(outbuf), &outlen);
2020
2021 if (rc && rc != -EALREADY)
2022 goto fail;
2023
2024 return;
2025
2026fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002027 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2028 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002029}
2030
2031static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2032{
2033 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2034}
2035
2036/* This creates an entry in the RX descriptor queue */
2037static inline void
2038efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2039{
2040 struct efx_rx_buffer *rx_buf;
2041 efx_qword_t *rxd;
2042
2043 rxd = efx_rx_desc(rx_queue, index);
2044 rx_buf = efx_rx_buffer(rx_queue, index);
2045 EFX_POPULATE_QWORD_2(*rxd,
2046 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2047 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2048}
2049
2050static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2051{
2052 struct efx_nic *efx = rx_queue->efx;
2053 unsigned int write_count;
2054 efx_dword_t reg;
2055
2056 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2057 write_count = rx_queue->added_count & ~7;
2058 if (rx_queue->notified_count == write_count)
2059 return;
2060
2061 do
2062 efx_ef10_build_rx_desc(
2063 rx_queue,
2064 rx_queue->notified_count & rx_queue->ptr_mask);
2065 while (++rx_queue->notified_count != write_count);
2066
2067 wmb();
2068 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2069 write_count & rx_queue->ptr_mask);
2070 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
2071 efx_rx_queue_index(rx_queue));
2072}
2073
2074static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2075
2076static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2077{
2078 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2079 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2080 efx_qword_t event;
2081
2082 EFX_POPULATE_QWORD_2(event,
2083 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2084 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2085
2086 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2087
2088 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2089 * already swapped the data to little-endian order.
2090 */
2091 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2092 sizeof(efx_qword_t));
2093
2094 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2095 inbuf, sizeof(inbuf), 0,
2096 efx_ef10_rx_defer_refill_complete, 0);
2097}
2098
2099static void
2100efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2101 int rc, efx_dword_t *outbuf,
2102 size_t outlen_actual)
2103{
2104 /* nothing to do */
2105}
2106
2107static int efx_ef10_ev_probe(struct efx_channel *channel)
2108{
2109 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2110 (channel->eventq_mask + 1) *
2111 sizeof(efx_qword_t),
2112 GFP_KERNEL);
2113}
2114
2115static int efx_ef10_ev_init(struct efx_channel *channel)
2116{
2117 MCDI_DECLARE_BUF(inbuf,
2118 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2119 EFX_BUF_SIZE));
2120 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
2121 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2122 struct efx_nic *efx = channel->efx;
2123 struct efx_ef10_nic_data *nic_data;
2124 bool supports_rx_merge;
2125 size_t inlen, outlen;
2126 dma_addr_t dma_addr;
2127 int rc;
2128 int i;
2129
2130 nic_data = efx->nic_data;
2131 supports_rx_merge =
2132 !!(nic_data->datapath_caps &
2133 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2134
2135 /* Fill event queue with all ones (i.e. empty events) */
2136 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2137
2138 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2139 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2140 /* INIT_EVQ expects index in vector table, not absolute */
2141 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
2142 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2143 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2144 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2145 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2146 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
2147 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2148 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2149 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2150 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2151 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2152 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2153 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2154
2155 dma_addr = channel->eventq.buf.dma_addr;
2156 for (i = 0; i < entries; ++i) {
2157 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2158 dma_addr += EFX_BUF_SIZE;
2159 }
2160
2161 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2162
2163 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2164 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01002165 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01002166 return rc;
2167}
2168
2169static void efx_ef10_ev_fini(struct efx_channel *channel)
2170{
2171 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002172 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002173 struct efx_nic *efx = channel->efx;
2174 size_t outlen;
2175 int rc;
2176
2177 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2178
Edward Cree1e0b8122013-05-31 18:36:12 +01002179 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002180 outbuf, sizeof(outbuf), &outlen);
2181
2182 if (rc && rc != -EALREADY)
2183 goto fail;
2184
2185 return;
2186
2187fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002188 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2189 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002190}
2191
2192static void efx_ef10_ev_remove(struct efx_channel *channel)
2193{
2194 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2195}
2196
2197static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2198 unsigned int rx_queue_label)
2199{
2200 struct efx_nic *efx = rx_queue->efx;
2201
2202 netif_info(efx, hw, efx->net_dev,
2203 "rx event arrived on queue %d labeled as queue %u\n",
2204 efx_rx_queue_index(rx_queue), rx_queue_label);
2205
2206 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2207}
2208
2209static void
2210efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2211 unsigned int actual, unsigned int expected)
2212{
2213 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2214 struct efx_nic *efx = rx_queue->efx;
2215
2216 netif_info(efx, hw, efx->net_dev,
2217 "dropped %d events (index=%d expected=%d)\n",
2218 dropped, actual, expected);
2219
2220 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2221}
2222
2223/* partially received RX was aborted. clean up. */
2224static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2225{
2226 unsigned int rx_desc_ptr;
2227
Ben Hutchings8127d662013-08-29 19:19:29 +01002228 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2229 "scattered RX aborted (dropping %u buffers)\n",
2230 rx_queue->scatter_n);
2231
2232 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2233
2234 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2235 0, EFX_RX_PKT_DISCARD);
2236
2237 rx_queue->removed_count += rx_queue->scatter_n;
2238 rx_queue->scatter_n = 0;
2239 rx_queue->scatter_len = 0;
2240 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2241}
2242
2243static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2244 const efx_qword_t *event)
2245{
2246 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2247 unsigned int n_descs, n_packets, i;
2248 struct efx_nic *efx = channel->efx;
2249 struct efx_rx_queue *rx_queue;
2250 bool rx_cont;
2251 u16 flags = 0;
2252
2253 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2254 return 0;
2255
2256 /* Basic packet information */
2257 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2258 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2259 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2260 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2261 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2262
Ben Hutchings48ce5632013-11-01 16:42:44 +00002263 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2264 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2265 EFX_QWORD_FMT "\n",
2266 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002267
2268 rx_queue = efx_channel_get_rx_queue(channel);
2269
2270 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2271 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2272
2273 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2274 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2275
2276 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002277 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2278
Ben Hutchings8127d662013-08-29 19:19:29 +01002279 /* detect rx abort */
2280 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002281 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2282 netdev_WARN(efx->net_dev,
2283 "invalid RX abort: scatter_n=%u event="
2284 EFX_QWORD_FMT "\n",
2285 rx_queue->scatter_n,
2286 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002287 efx_ef10_handle_rx_abort(rx_queue);
2288 return 0;
2289 }
2290
Ben Hutchings92a04162013-09-24 23:21:57 +01002291 /* Check that RX completion merging is valid, i.e.
2292 * the current firmware supports it and this is a
2293 * non-scattered packet.
2294 */
2295 if (!(nic_data->datapath_caps &
2296 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2297 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002298 efx_ef10_handle_rx_bad_lbits(
2299 rx_queue, next_ptr_lbits,
2300 (rx_queue->removed_count +
2301 rx_queue->scatter_n + 1) &
2302 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2303 return 0;
2304 }
2305
2306 /* Merged completion for multiple non-scattered packets */
2307 rx_queue->scatter_n = 1;
2308 rx_queue->scatter_len = 0;
2309 n_packets = n_descs;
2310 ++channel->n_rx_merge_events;
2311 channel->n_rx_merge_packets += n_packets;
2312 flags |= EFX_RX_PKT_PREFIX_LEN;
2313 } else {
2314 ++rx_queue->scatter_n;
2315 rx_queue->scatter_len += rx_bytes;
2316 if (rx_cont)
2317 return 0;
2318 n_packets = 1;
2319 }
2320
2321 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2322 flags |= EFX_RX_PKT_DISCARD;
2323
2324 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2325 channel->n_rx_ip_hdr_chksum_err += n_packets;
2326 } else if (unlikely(EFX_QWORD_FIELD(*event,
2327 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2328 channel->n_rx_tcp_udp_chksum_err += n_packets;
2329 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2330 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2331 flags |= EFX_RX_PKT_CSUMMED;
2332 }
2333
2334 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2335 flags |= EFX_RX_PKT_TCP;
2336
2337 channel->irq_mod_score += 2 * n_packets;
2338
2339 /* Handle received packet(s) */
2340 for (i = 0; i < n_packets; i++) {
2341 efx_rx_packet(rx_queue,
2342 rx_queue->removed_count & rx_queue->ptr_mask,
2343 rx_queue->scatter_n, rx_queue->scatter_len,
2344 flags);
2345 rx_queue->removed_count += rx_queue->scatter_n;
2346 }
2347
2348 rx_queue->scatter_n = 0;
2349 rx_queue->scatter_len = 0;
2350
2351 return n_packets;
2352}
2353
2354static int
2355efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2356{
2357 struct efx_nic *efx = channel->efx;
2358 struct efx_tx_queue *tx_queue;
2359 unsigned int tx_ev_desc_ptr;
2360 unsigned int tx_ev_q_label;
2361 int tx_descs = 0;
2362
2363 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2364 return 0;
2365
2366 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2367 return 0;
2368
2369 /* Transmit completion */
2370 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2371 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2372 tx_queue = efx_channel_get_tx_queue(channel,
2373 tx_ev_q_label % EFX_TXQ_TYPES);
2374 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2375 tx_queue->ptr_mask);
2376 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2377
2378 return tx_descs;
2379}
2380
2381static void
2382efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2383{
2384 struct efx_nic *efx = channel->efx;
2385 int subcode;
2386
2387 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2388
2389 switch (subcode) {
2390 case ESE_DZ_DRV_TIMER_EV:
2391 case ESE_DZ_DRV_WAKE_UP_EV:
2392 break;
2393 case ESE_DZ_DRV_START_UP_EV:
2394 /* event queue init complete. ok. */
2395 break;
2396 default:
2397 netif_err(efx, hw, efx->net_dev,
2398 "channel %d unknown driver event type %d"
2399 " (data " EFX_QWORD_FMT ")\n",
2400 channel->channel, subcode,
2401 EFX_QWORD_VAL(*event));
2402
2403 }
2404}
2405
2406static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2407 efx_qword_t *event)
2408{
2409 struct efx_nic *efx = channel->efx;
2410 u32 subcode;
2411
2412 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2413
2414 switch (subcode) {
2415 case EFX_EF10_TEST:
2416 channel->event_test_cpu = raw_smp_processor_id();
2417 break;
2418 case EFX_EF10_REFILL:
2419 /* The queue must be empty, so we won't receive any rx
2420 * events, so efx_process_channel() won't refill the
2421 * queue. Refill it here
2422 */
Jon Coopercce28792013-10-02 11:04:14 +01002423 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002424 break;
2425 default:
2426 netif_err(efx, hw, efx->net_dev,
2427 "channel %d unknown driver event type %u"
2428 " (data " EFX_QWORD_FMT ")\n",
2429 channel->channel, (unsigned) subcode,
2430 EFX_QWORD_VAL(*event));
2431 }
2432}
2433
2434static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2435{
2436 struct efx_nic *efx = channel->efx;
2437 efx_qword_t event, *p_event;
2438 unsigned int read_ptr;
2439 int ev_code;
2440 int tx_descs = 0;
2441 int spent = 0;
2442
Eric W. Biederman75363a42014-03-14 18:11:22 -07002443 if (quota <= 0)
2444 return spent;
2445
Ben Hutchings8127d662013-08-29 19:19:29 +01002446 read_ptr = channel->eventq_read_ptr;
2447
2448 for (;;) {
2449 p_event = efx_event(channel, read_ptr);
2450 event = *p_event;
2451
2452 if (!efx_event_present(&event))
2453 break;
2454
2455 EFX_SET_QWORD(*p_event);
2456
2457 ++read_ptr;
2458
2459 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2460
2461 netif_vdbg(efx, drv, efx->net_dev,
2462 "processing event on %d " EFX_QWORD_FMT "\n",
2463 channel->channel, EFX_QWORD_VAL(event));
2464
2465 switch (ev_code) {
2466 case ESE_DZ_EV_CODE_MCDI_EV:
2467 efx_mcdi_process_event(channel, &event);
2468 break;
2469 case ESE_DZ_EV_CODE_RX_EV:
2470 spent += efx_ef10_handle_rx_event(channel, &event);
2471 if (spent >= quota) {
2472 /* XXX can we split a merged event to
2473 * avoid going over-quota?
2474 */
2475 spent = quota;
2476 goto out;
2477 }
2478 break;
2479 case ESE_DZ_EV_CODE_TX_EV:
2480 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2481 if (tx_descs > efx->txq_entries) {
2482 spent = quota;
2483 goto out;
2484 } else if (++spent == quota) {
2485 goto out;
2486 }
2487 break;
2488 case ESE_DZ_EV_CODE_DRIVER_EV:
2489 efx_ef10_handle_driver_event(channel, &event);
2490 if (++spent == quota)
2491 goto out;
2492 break;
2493 case EFX_EF10_DRVGEN_EV:
2494 efx_ef10_handle_driver_generated_event(channel, &event);
2495 break;
2496 default:
2497 netif_err(efx, hw, efx->net_dev,
2498 "channel %d unknown event type %d"
2499 " (data " EFX_QWORD_FMT ")\n",
2500 channel->channel, ev_code,
2501 EFX_QWORD_VAL(event));
2502 }
2503 }
2504
2505out:
2506 channel->eventq_read_ptr = read_ptr;
2507 return spent;
2508}
2509
2510static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2511{
2512 struct efx_nic *efx = channel->efx;
2513 efx_dword_t rptr;
2514
2515 if (EFX_EF10_WORKAROUND_35388(efx)) {
2516 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2517 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2518 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2519 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2520
2521 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2522 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2523 ERF_DD_EVQ_IND_RPTR,
2524 (channel->eventq_read_ptr &
2525 channel->eventq_mask) >>
2526 ERF_DD_EVQ_IND_RPTR_WIDTH);
2527 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2528 channel->channel);
2529 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2530 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2531 ERF_DD_EVQ_IND_RPTR,
2532 channel->eventq_read_ptr &
2533 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2534 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2535 channel->channel);
2536 } else {
2537 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2538 channel->eventq_read_ptr &
2539 channel->eventq_mask);
2540 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2541 }
2542}
2543
2544static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2545{
2546 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2547 struct efx_nic *efx = channel->efx;
2548 efx_qword_t event;
2549 int rc;
2550
2551 EFX_POPULATE_QWORD_2(event,
2552 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2553 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2554
2555 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2556
2557 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2558 * already swapped the data to little-endian order.
2559 */
2560 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2561 sizeof(efx_qword_t));
2562
2563 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2564 NULL, 0, NULL);
2565 if (rc != 0)
2566 goto fail;
2567
2568 return;
2569
2570fail:
2571 WARN_ON(true);
2572 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2573}
2574
2575void efx_ef10_handle_drain_event(struct efx_nic *efx)
2576{
2577 if (atomic_dec_and_test(&efx->active_queues))
2578 wake_up(&efx->flush_wq);
2579
2580 WARN_ON(atomic_read(&efx->active_queues) < 0);
2581}
2582
2583static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2584{
2585 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2586 struct efx_channel *channel;
2587 struct efx_tx_queue *tx_queue;
2588 struct efx_rx_queue *rx_queue;
2589 int pending;
2590
2591 /* If the MC has just rebooted, the TX/RX queues will have already been
2592 * torn down, but efx->active_queues needs to be set to zero.
2593 */
2594 if (nic_data->must_realloc_vis) {
2595 atomic_set(&efx->active_queues, 0);
2596 return 0;
2597 }
2598
2599 /* Do not attempt to write to the NIC during EEH recovery */
2600 if (efx->state != STATE_RECOVERY) {
2601 efx_for_each_channel(channel, efx) {
2602 efx_for_each_channel_rx_queue(rx_queue, channel)
2603 efx_ef10_rx_fini(rx_queue);
2604 efx_for_each_channel_tx_queue(tx_queue, channel)
2605 efx_ef10_tx_fini(tx_queue);
2606 }
2607
2608 wait_event_timeout(efx->flush_wq,
2609 atomic_read(&efx->active_queues) == 0,
2610 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2611 pending = atomic_read(&efx->active_queues);
2612 if (pending) {
2613 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2614 pending);
2615 return -ETIMEDOUT;
2616 }
2617 }
2618
2619 return 0;
2620}
2621
Edward Creee2835462014-04-16 19:27:48 +01002622static void efx_ef10_prepare_flr(struct efx_nic *efx)
2623{
2624 atomic_set(&efx->active_queues, 0);
2625}
2626
Ben Hutchings8127d662013-08-29 19:19:29 +01002627static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2628 const struct efx_filter_spec *right)
2629{
2630 if ((left->match_flags ^ right->match_flags) |
2631 ((left->flags ^ right->flags) &
2632 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2633 return false;
2634
2635 return memcmp(&left->outer_vid, &right->outer_vid,
2636 sizeof(struct efx_filter_spec) -
2637 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2638}
2639
2640static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2641{
2642 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2643 return jhash2((const u32 *)&spec->outer_vid,
2644 (sizeof(struct efx_filter_spec) -
2645 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2646 0);
2647 /* XXX should we randomise the initval? */
2648}
2649
2650/* Decide whether a filter should be exclusive or else should allow
2651 * delivery to additional recipients. Currently we decide that
2652 * filters for specific local unicast MAC and IP addresses are
2653 * exclusive.
2654 */
2655static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2656{
2657 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2658 !is_multicast_ether_addr(spec->loc_mac))
2659 return true;
2660
2661 if ((spec->match_flags &
2662 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2663 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2664 if (spec->ether_type == htons(ETH_P_IP) &&
2665 !ipv4_is_multicast(spec->loc_host[0]))
2666 return true;
2667 if (spec->ether_type == htons(ETH_P_IPV6) &&
2668 ((const u8 *)spec->loc_host)[0] != 0xff)
2669 return true;
2670 }
2671
2672 return false;
2673}
2674
2675static struct efx_filter_spec *
2676efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2677 unsigned int filter_idx)
2678{
2679 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2680 ~EFX_EF10_FILTER_FLAGS);
2681}
2682
2683static unsigned int
2684efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2685 unsigned int filter_idx)
2686{
2687 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2688}
2689
2690static void
2691efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2692 unsigned int filter_idx,
2693 const struct efx_filter_spec *spec,
2694 unsigned int flags)
2695{
2696 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2697}
2698
2699static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2700 const struct efx_filter_spec *spec,
2701 efx_dword_t *inbuf, u64 handle,
2702 bool replacing)
2703{
2704 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2705
2706 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2707
2708 if (replacing) {
2709 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2710 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2711 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2712 } else {
2713 u32 match_fields = 0;
2714
2715 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2716 efx_ef10_filter_is_exclusive(spec) ?
2717 MC_CMD_FILTER_OP_IN_OP_INSERT :
2718 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2719
2720 /* Convert match flags and values. Unlike almost
2721 * everything else in MCDI, these fields are in
2722 * network byte order.
2723 */
2724 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2725 match_fields |=
2726 is_multicast_ether_addr(spec->loc_mac) ?
2727 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2728 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2729#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2730 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2731 match_fields |= \
2732 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2733 mcdi_field ## _LBN; \
2734 BUILD_BUG_ON( \
2735 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2736 sizeof(spec->gen_field)); \
2737 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2738 &spec->gen_field, sizeof(spec->gen_field)); \
2739 }
2740 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2741 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2742 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2743 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2744 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2745 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2746 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2747 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2748 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2749 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2750#undef COPY_FIELD
2751 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2752 match_fields);
2753 }
2754
Daniel Pieczko45b24492015-05-06 00:57:14 +01002755 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002756 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2757 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2758 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2759 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002760 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002761 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2762 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002763 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2764 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2765 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002766 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2767 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2768 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2769 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2770 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2771 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2772 spec->rss_context !=
2773 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2774 spec->rss_context : nic_data->rx_rss_context);
2775}
2776
2777static int efx_ef10_filter_push(struct efx_nic *efx,
2778 const struct efx_filter_spec *spec,
2779 u64 *handle, bool replacing)
2780{
2781 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2782 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2783 int rc;
2784
2785 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2786 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2787 outbuf, sizeof(outbuf), NULL);
2788 if (rc == 0)
2789 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002790 if (rc == -ENOSPC)
2791 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002792 return rc;
2793}
2794
2795static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2796 enum efx_filter_match_flags match_flags)
2797{
2798 unsigned int match_pri;
2799
2800 for (match_pri = 0;
2801 match_pri < table->rx_match_count;
2802 match_pri++)
2803 if (table->rx_match_flags[match_pri] == match_flags)
2804 return match_pri;
2805
2806 return -EPROTONOSUPPORT;
2807}
2808
2809static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2810 struct efx_filter_spec *spec,
2811 bool replace_equal)
2812{
2813 struct efx_ef10_filter_table *table = efx->filter_state;
2814 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2815 struct efx_filter_spec *saved_spec;
2816 unsigned int match_pri, hash;
2817 unsigned int priv_flags;
2818 bool replacing = false;
2819 int ins_index = -1;
2820 DEFINE_WAIT(wait);
2821 bool is_mc_recip;
2822 s32 rc;
2823
2824 /* For now, only support RX filters */
2825 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2826 EFX_FILTER_FLAG_RX)
2827 return -EINVAL;
2828
2829 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2830 if (rc < 0)
2831 return rc;
2832 match_pri = rc;
2833
2834 hash = efx_ef10_filter_hash(spec);
2835 is_mc_recip = efx_filter_is_mc_recipient(spec);
2836 if (is_mc_recip)
2837 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2838
2839 /* Find any existing filters with the same match tuple or
2840 * else a free slot to insert at. If any of them are busy,
2841 * we have to wait and retry.
2842 */
2843 for (;;) {
2844 unsigned int depth = 1;
2845 unsigned int i;
2846
2847 spin_lock_bh(&efx->filter_lock);
2848
2849 for (;;) {
2850 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2851 saved_spec = efx_ef10_filter_entry_spec(table, i);
2852
2853 if (!saved_spec) {
2854 if (ins_index < 0)
2855 ins_index = i;
2856 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2857 if (table->entry[i].spec &
2858 EFX_EF10_FILTER_FLAG_BUSY)
2859 break;
2860 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002861 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002862 rc = -EPERM;
2863 goto out_unlock;
2864 }
2865 if (!is_mc_recip) {
2866 /* This is the only one */
2867 if (spec->priority ==
2868 saved_spec->priority &&
2869 !replace_equal) {
2870 rc = -EEXIST;
2871 goto out_unlock;
2872 }
2873 ins_index = i;
2874 goto found;
2875 } else if (spec->priority >
2876 saved_spec->priority ||
2877 (spec->priority ==
2878 saved_spec->priority &&
2879 replace_equal)) {
2880 if (ins_index < 0)
2881 ins_index = i;
2882 else
2883 __set_bit(depth, mc_rem_map);
2884 }
2885 }
2886
2887 /* Once we reach the maximum search depth, use
2888 * the first suitable slot or return -EBUSY if
2889 * there was none
2890 */
2891 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2892 if (ins_index < 0) {
2893 rc = -EBUSY;
2894 goto out_unlock;
2895 }
2896 goto found;
2897 }
2898
2899 ++depth;
2900 }
2901
2902 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2903 spin_unlock_bh(&efx->filter_lock);
2904 schedule();
2905 }
2906
2907found:
2908 /* Create a software table entry if necessary, and mark it
2909 * busy. We might yet fail to insert, but any attempt to
2910 * insert a conflicting filter while we're waiting for the
2911 * firmware must find the busy entry.
2912 */
2913 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2914 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002915 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2916 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002917 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002918 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2919 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002920 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002921 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002922 rc = ins_index;
2923 goto out_unlock;
2924 }
2925 replacing = true;
2926 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2927 } else {
2928 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2929 if (!saved_spec) {
2930 rc = -ENOMEM;
2931 goto out_unlock;
2932 }
2933 *saved_spec = *spec;
2934 priv_flags = 0;
2935 }
2936 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2937 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2938
2939 /* Mark lower-priority multicast recipients busy prior to removal */
2940 if (is_mc_recip) {
2941 unsigned int depth, i;
2942
2943 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2944 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2945 if (test_bit(depth, mc_rem_map))
2946 table->entry[i].spec |=
2947 EFX_EF10_FILTER_FLAG_BUSY;
2948 }
2949 }
2950
2951 spin_unlock_bh(&efx->filter_lock);
2952
2953 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2954 replacing);
2955
2956 /* Finalise the software table entry */
2957 spin_lock_bh(&efx->filter_lock);
2958 if (rc == 0) {
2959 if (replacing) {
2960 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002961 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2962 saved_spec->flags |=
2963 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002964 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002965 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002966 saved_spec->flags |= spec->flags;
2967 saved_spec->rss_context = spec->rss_context;
2968 saved_spec->dmaq_id = spec->dmaq_id;
2969 }
2970 } else if (!replacing) {
2971 kfree(saved_spec);
2972 saved_spec = NULL;
2973 }
2974 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2975
2976 /* Remove and finalise entries for lower-priority multicast
2977 * recipients
2978 */
2979 if (is_mc_recip) {
2980 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2981 unsigned int depth, i;
2982
2983 memset(inbuf, 0, sizeof(inbuf));
2984
2985 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2986 if (!test_bit(depth, mc_rem_map))
2987 continue;
2988
2989 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2990 saved_spec = efx_ef10_filter_entry_spec(table, i);
2991 priv_flags = efx_ef10_filter_entry_flags(table, i);
2992
2993 if (rc == 0) {
2994 spin_unlock_bh(&efx->filter_lock);
2995 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2996 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2997 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2998 table->entry[i].handle);
2999 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3000 inbuf, sizeof(inbuf),
3001 NULL, 0, NULL);
3002 spin_lock_bh(&efx->filter_lock);
3003 }
3004
3005 if (rc == 0) {
3006 kfree(saved_spec);
3007 saved_spec = NULL;
3008 priv_flags = 0;
3009 } else {
3010 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3011 }
3012 efx_ef10_filter_set_entry(table, i, saved_spec,
3013 priv_flags);
3014 }
3015 }
3016
3017 /* If successful, return the inserted filter ID */
3018 if (rc == 0)
3019 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3020
3021 wake_up_all(&table->waitq);
3022out_unlock:
3023 spin_unlock_bh(&efx->filter_lock);
3024 finish_wait(&table->waitq, &wait);
3025 return rc;
3026}
3027
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08003028static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01003029{
3030 /* no need to do anything here on EF10 */
3031}
3032
3033/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003034 * If !by_index, remove by ID
3035 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01003036 * Filter ID may come from userland and must be range-checked.
3037 */
3038static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003039 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003040 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01003041{
3042 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3043 struct efx_ef10_filter_table *table = efx->filter_state;
3044 MCDI_DECLARE_BUF(inbuf,
3045 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3046 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3047 struct efx_filter_spec *spec;
3048 DEFINE_WAIT(wait);
3049 int rc;
3050
3051 /* Find the software table entry and mark it busy. Don't
3052 * remove it yet; any attempt to update while we're waiting
3053 * for the firmware must find the busy entry.
3054 */
3055 for (;;) {
3056 spin_lock_bh(&efx->filter_lock);
3057 if (!(table->entry[filter_idx].spec &
3058 EFX_EF10_FILTER_FLAG_BUSY))
3059 break;
3060 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3061 spin_unlock_bh(&efx->filter_lock);
3062 schedule();
3063 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003064
Ben Hutchings8127d662013-08-29 19:19:29 +01003065 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003066 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003067 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01003068 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
3069 filter_id / HUNT_FILTER_TBL_ROWS)) {
3070 rc = -ENOENT;
3071 goto out_unlock;
3072 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003073
3074 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003075 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003076 /* Just remove flags */
3077 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003078 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003079 rc = 0;
3080 goto out_unlock;
3081 }
3082
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003083 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003084 rc = -ENOENT;
3085 goto out_unlock;
3086 }
3087
Ben Hutchings8127d662013-08-29 19:19:29 +01003088 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3089 spin_unlock_bh(&efx->filter_lock);
3090
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003091 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003092 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01003093
3094 struct efx_filter_spec new_spec = *spec;
3095
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003096 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01003097 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003098 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003099 new_spec.dmaq_id = 0;
3100 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3101 rc = efx_ef10_filter_push(efx, &new_spec,
3102 &table->entry[filter_idx].handle,
3103 true);
3104
3105 spin_lock_bh(&efx->filter_lock);
3106 if (rc == 0)
3107 *spec = new_spec;
3108 } else {
3109 /* Really remove the filter */
3110
3111 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3112 efx_ef10_filter_is_exclusive(spec) ?
3113 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3114 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3115 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3116 table->entry[filter_idx].handle);
3117 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3118 inbuf, sizeof(inbuf), NULL, 0, NULL);
3119
3120 spin_lock_bh(&efx->filter_lock);
3121 if (rc == 0) {
3122 kfree(spec);
3123 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3124 }
3125 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003126
Ben Hutchings8127d662013-08-29 19:19:29 +01003127 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3128 wake_up_all(&table->waitq);
3129out_unlock:
3130 spin_unlock_bh(&efx->filter_lock);
3131 finish_wait(&table->waitq, &wait);
3132 return rc;
3133}
3134
3135static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3136 enum efx_filter_priority priority,
3137 u32 filter_id)
3138{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003139 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3140 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01003141}
3142
3143static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3144 enum efx_filter_priority priority,
3145 u32 filter_id, struct efx_filter_spec *spec)
3146{
3147 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3148 struct efx_ef10_filter_table *table = efx->filter_state;
3149 const struct efx_filter_spec *saved_spec;
3150 int rc;
3151
3152 spin_lock_bh(&efx->filter_lock);
3153 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3154 if (saved_spec && saved_spec->priority == priority &&
3155 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
3156 filter_id / HUNT_FILTER_TBL_ROWS) {
3157 *spec = *saved_spec;
3158 rc = 0;
3159 } else {
3160 rc = -ENOENT;
3161 }
3162 spin_unlock_bh(&efx->filter_lock);
3163 return rc;
3164}
3165
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003166static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003167 enum efx_filter_priority priority)
3168{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003169 unsigned int priority_mask;
3170 unsigned int i;
3171 int rc;
3172
3173 priority_mask = (((1U << (priority + 1)) - 1) &
3174 ~(1U << EFX_FILTER_PRI_AUTO));
3175
3176 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3177 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3178 i, true);
3179 if (rc && rc != -ENOENT)
3180 return rc;
3181 }
3182
3183 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003184}
3185
3186static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3187 enum efx_filter_priority priority)
3188{
3189 struct efx_ef10_filter_table *table = efx->filter_state;
3190 unsigned int filter_idx;
3191 s32 count = 0;
3192
3193 spin_lock_bh(&efx->filter_lock);
3194 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3195 if (table->entry[filter_idx].spec &&
3196 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3197 priority)
3198 ++count;
3199 }
3200 spin_unlock_bh(&efx->filter_lock);
3201 return count;
3202}
3203
3204static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3205{
3206 struct efx_ef10_filter_table *table = efx->filter_state;
3207
3208 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3209}
3210
3211static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3212 enum efx_filter_priority priority,
3213 u32 *buf, u32 size)
3214{
3215 struct efx_ef10_filter_table *table = efx->filter_state;
3216 struct efx_filter_spec *spec;
3217 unsigned int filter_idx;
3218 s32 count = 0;
3219
3220 spin_lock_bh(&efx->filter_lock);
3221 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3222 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3223 if (spec && spec->priority == priority) {
3224 if (count == size) {
3225 count = -EMSGSIZE;
3226 break;
3227 }
3228 buf[count++] = (efx_ef10_filter_rx_match_pri(
3229 table, spec->match_flags) *
3230 HUNT_FILTER_TBL_ROWS +
3231 filter_idx);
3232 }
3233 }
3234 spin_unlock_bh(&efx->filter_lock);
3235 return count;
3236}
3237
3238#ifdef CONFIG_RFS_ACCEL
3239
3240static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3241
3242static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3243 struct efx_filter_spec *spec)
3244{
3245 struct efx_ef10_filter_table *table = efx->filter_state;
3246 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3247 struct efx_filter_spec *saved_spec;
3248 unsigned int hash, i, depth = 1;
3249 bool replacing = false;
3250 int ins_index = -1;
3251 u64 cookie;
3252 s32 rc;
3253
3254 /* Must be an RX filter without RSS and not for a multicast
3255 * destination address (RFS only works for connected sockets).
3256 * These restrictions allow us to pass only a tiny amount of
3257 * data through to the completion function.
3258 */
3259 EFX_WARN_ON_PARANOID(spec->flags !=
3260 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3261 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3262 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3263
3264 hash = efx_ef10_filter_hash(spec);
3265
3266 spin_lock_bh(&efx->filter_lock);
3267
3268 /* Find any existing filter with the same match tuple or else
3269 * a free slot to insert at. If an existing filter is busy,
3270 * we have to give up.
3271 */
3272 for (;;) {
3273 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3274 saved_spec = efx_ef10_filter_entry_spec(table, i);
3275
3276 if (!saved_spec) {
3277 if (ins_index < 0)
3278 ins_index = i;
3279 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3280 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3281 rc = -EBUSY;
3282 goto fail_unlock;
3283 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003284 if (spec->priority < saved_spec->priority) {
3285 rc = -EPERM;
3286 goto fail_unlock;
3287 }
3288 ins_index = i;
3289 break;
3290 }
3291
3292 /* Once we reach the maximum search depth, use the
3293 * first suitable slot or return -EBUSY if there was
3294 * none
3295 */
3296 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3297 if (ins_index < 0) {
3298 rc = -EBUSY;
3299 goto fail_unlock;
3300 }
3301 break;
3302 }
3303
3304 ++depth;
3305 }
3306
3307 /* Create a software table entry if necessary, and mark it
3308 * busy. We might yet fail to insert, but any attempt to
3309 * insert a conflicting filter while we're waiting for the
3310 * firmware must find the busy entry.
3311 */
3312 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3313 if (saved_spec) {
3314 replacing = true;
3315 } else {
3316 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3317 if (!saved_spec) {
3318 rc = -ENOMEM;
3319 goto fail_unlock;
3320 }
3321 *saved_spec = *spec;
3322 }
3323 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3324 EFX_EF10_FILTER_FLAG_BUSY);
3325
3326 spin_unlock_bh(&efx->filter_lock);
3327
3328 /* Pack up the variables needed on completion */
3329 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3330
3331 efx_ef10_filter_push_prep(efx, spec, inbuf,
3332 table->entry[ins_index].handle, replacing);
3333 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3334 MC_CMD_FILTER_OP_OUT_LEN,
3335 efx_ef10_filter_rfs_insert_complete, cookie);
3336
3337 return ins_index;
3338
3339fail_unlock:
3340 spin_unlock_bh(&efx->filter_lock);
3341 return rc;
3342}
3343
3344static void
3345efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3346 int rc, efx_dword_t *outbuf,
3347 size_t outlen_actual)
3348{
3349 struct efx_ef10_filter_table *table = efx->filter_state;
3350 unsigned int ins_index, dmaq_id;
3351 struct efx_filter_spec *spec;
3352 bool replacing;
3353
3354 /* Unpack the cookie */
3355 replacing = cookie >> 31;
3356 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3357 dmaq_id = cookie & 0xffff;
3358
3359 spin_lock_bh(&efx->filter_lock);
3360 spec = efx_ef10_filter_entry_spec(table, ins_index);
3361 if (rc == 0) {
3362 table->entry[ins_index].handle =
3363 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3364 if (replacing)
3365 spec->dmaq_id = dmaq_id;
3366 } else if (!replacing) {
3367 kfree(spec);
3368 spec = NULL;
3369 }
3370 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3371 spin_unlock_bh(&efx->filter_lock);
3372
3373 wake_up_all(&table->waitq);
3374}
3375
3376static void
3377efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3378 unsigned long filter_idx,
3379 int rc, efx_dword_t *outbuf,
3380 size_t outlen_actual);
3381
3382static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3383 unsigned int filter_idx)
3384{
3385 struct efx_ef10_filter_table *table = efx->filter_state;
3386 struct efx_filter_spec *spec =
3387 efx_ef10_filter_entry_spec(table, filter_idx);
3388 MCDI_DECLARE_BUF(inbuf,
3389 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3390 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3391
3392 if (!spec ||
3393 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3394 spec->priority != EFX_FILTER_PRI_HINT ||
3395 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3396 flow_id, filter_idx))
3397 return false;
3398
3399 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3400 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3401 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3402 table->entry[filter_idx].handle);
3403 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3404 efx_ef10_filter_rfs_expire_complete, filter_idx))
3405 return false;
3406
3407 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3408 return true;
3409}
3410
3411static void
3412efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3413 unsigned long filter_idx,
3414 int rc, efx_dword_t *outbuf,
3415 size_t outlen_actual)
3416{
3417 struct efx_ef10_filter_table *table = efx->filter_state;
3418 struct efx_filter_spec *spec =
3419 efx_ef10_filter_entry_spec(table, filter_idx);
3420
3421 spin_lock_bh(&efx->filter_lock);
3422 if (rc == 0) {
3423 kfree(spec);
3424 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3425 }
3426 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3427 wake_up_all(&table->waitq);
3428 spin_unlock_bh(&efx->filter_lock);
3429}
3430
3431#endif /* CONFIG_RFS_ACCEL */
3432
3433static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3434{
3435 int match_flags = 0;
3436
3437#define MAP_FLAG(gen_flag, mcdi_field) { \
3438 u32 old_mcdi_flags = mcdi_flags; \
3439 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3440 mcdi_field ## _LBN); \
3441 if (mcdi_flags != old_mcdi_flags) \
3442 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3443 }
3444 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3445 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3446 MAP_FLAG(REM_HOST, SRC_IP);
3447 MAP_FLAG(LOC_HOST, DST_IP);
3448 MAP_FLAG(REM_MAC, SRC_MAC);
3449 MAP_FLAG(REM_PORT, SRC_PORT);
3450 MAP_FLAG(LOC_MAC, DST_MAC);
3451 MAP_FLAG(LOC_PORT, DST_PORT);
3452 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3453 MAP_FLAG(INNER_VID, INNER_VLAN);
3454 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3455 MAP_FLAG(IP_PROTO, IP_PROTO);
3456#undef MAP_FLAG
3457
3458 /* Did we map them all? */
3459 if (mcdi_flags)
3460 return -EINVAL;
3461
3462 return match_flags;
3463}
3464
3465static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3466{
3467 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3468 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3469 unsigned int pd_match_pri, pd_match_count;
3470 struct efx_ef10_filter_table *table;
3471 size_t outlen;
3472 int rc;
3473
3474 table = kzalloc(sizeof(*table), GFP_KERNEL);
3475 if (!table)
3476 return -ENOMEM;
3477
3478 /* Find out which RX filter types are supported, and their priorities */
3479 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3480 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3481 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3482 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3483 &outlen);
3484 if (rc)
3485 goto fail;
3486 pd_match_count = MCDI_VAR_ARRAY_LEN(
3487 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3488 table->rx_match_count = 0;
3489
3490 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3491 u32 mcdi_flags =
3492 MCDI_ARRAY_DWORD(
3493 outbuf,
3494 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3495 pd_match_pri);
3496 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3497 if (rc < 0) {
3498 netif_dbg(efx, probe, efx->net_dev,
3499 "%s: fw flags %#x pri %u not supported in driver\n",
3500 __func__, mcdi_flags, pd_match_pri);
3501 } else {
3502 netif_dbg(efx, probe, efx->net_dev,
3503 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3504 __func__, mcdi_flags, pd_match_pri,
3505 rc, table->rx_match_count);
3506 table->rx_match_flags[table->rx_match_count++] = rc;
3507 }
3508 }
3509
3510 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3511 if (!table->entry) {
3512 rc = -ENOMEM;
3513 goto fail;
3514 }
3515
3516 efx->filter_state = table;
3517 init_waitqueue_head(&table->waitq);
3518 return 0;
3519
3520fail:
3521 kfree(table);
3522 return rc;
3523}
3524
Edward Cree0d322412015-05-20 11:10:03 +01003525/* Caller must hold efx->filter_sem for read if race against
3526 * efx_ef10_filter_table_remove() is possible
3527 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003528static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3529{
3530 struct efx_ef10_filter_table *table = efx->filter_state;
3531 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3532 struct efx_filter_spec *spec;
3533 unsigned int filter_idx;
3534 bool failed = false;
3535 int rc;
3536
Edward Cree0d322412015-05-20 11:10:03 +01003537 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3538
Ben Hutchings8127d662013-08-29 19:19:29 +01003539 if (!nic_data->must_restore_filters)
3540 return;
3541
Edward Cree0d322412015-05-20 11:10:03 +01003542 if (!table)
3543 return;
3544
Ben Hutchings8127d662013-08-29 19:19:29 +01003545 spin_lock_bh(&efx->filter_lock);
3546
3547 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3548 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3549 if (!spec)
3550 continue;
3551
3552 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3553 spin_unlock_bh(&efx->filter_lock);
3554
3555 rc = efx_ef10_filter_push(efx, spec,
3556 &table->entry[filter_idx].handle,
3557 false);
3558 if (rc)
3559 failed = true;
3560
3561 spin_lock_bh(&efx->filter_lock);
3562 if (rc) {
3563 kfree(spec);
3564 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3565 } else {
3566 table->entry[filter_idx].spec &=
3567 ~EFX_EF10_FILTER_FLAG_BUSY;
3568 }
3569 }
3570
3571 spin_unlock_bh(&efx->filter_lock);
3572
3573 if (failed)
3574 netif_err(efx, hw, efx->net_dev,
3575 "unable to restore all filters\n");
3576 else
3577 nic_data->must_restore_filters = false;
3578}
3579
Edward Cree0d322412015-05-20 11:10:03 +01003580/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003581static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3582{
3583 struct efx_ef10_filter_table *table = efx->filter_state;
3584 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3585 struct efx_filter_spec *spec;
3586 unsigned int filter_idx;
3587 int rc;
3588
Edward Cree0d322412015-05-20 11:10:03 +01003589 efx->filter_state = NULL;
3590 if (!table)
3591 return;
3592
Ben Hutchings8127d662013-08-29 19:19:29 +01003593 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3594 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3595 if (!spec)
3596 continue;
3597
3598 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3599 efx_ef10_filter_is_exclusive(spec) ?
3600 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3601 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3602 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3603 table->entry[filter_idx].handle);
3604 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3605 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003606 if (rc)
3607 netdev_WARN(efx->net_dev,
3608 "filter_idx=%#x handle=%#llx\n",
3609 filter_idx,
3610 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003611 kfree(spec);
3612 }
3613
3614 vfree(table->entry);
3615 kfree(table);
3616}
3617
Edward Cree0d322412015-05-20 11:10:03 +01003618/* Caller must hold efx->filter_sem for read if race against
3619 * efx_ef10_filter_table_remove() is possible
3620 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003621static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3622{
3623 struct efx_ef10_filter_table *table = efx->filter_state;
3624 struct net_device *net_dev = efx->net_dev;
3625 struct efx_filter_spec spec;
3626 bool remove_failed = false;
3627 struct netdev_hw_addr *uc;
3628 struct netdev_hw_addr *mc;
3629 unsigned int filter_idx;
3630 int i, n, rc;
3631
3632 if (!efx_dev_registered(efx))
3633 return;
3634
Edward Cree0d322412015-05-20 11:10:03 +01003635 if (!table)
3636 return;
3637
Ben Hutchings8127d662013-08-29 19:19:29 +01003638 /* Mark old filters that may need to be removed */
3639 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003640 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003641 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003642 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3643 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003644 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003645 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003646 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003647 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3648 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003649 }
3650 spin_unlock_bh(&efx->filter_lock);
3651
3652 /* Copy/convert the address lists; add the primary station
3653 * address and broadcast address
3654 */
3655 netif_addr_lock_bh(net_dev);
3656 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003657 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3658 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003659 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003660 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003661 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003662 i = 1;
3663 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003664 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003665 i++;
3666 }
3667 }
3668 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003669 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3670 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003671 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003672 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3673 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003674 i = 1;
3675 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003676 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003677 i++;
3678 }
3679 }
3680 netif_addr_unlock_bh(net_dev);
3681
3682 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003683 if (table->dev_uc_count >= 0) {
3684 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003685 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3686 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003687 0);
3688 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003689 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003690 rc = efx_ef10_filter_insert(efx, &spec, true);
3691 if (rc < 0) {
3692 /* Fall back to unicast-promisc */
3693 while (i--)
3694 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003695 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003696 table->dev_uc_list[i].id);
3697 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003698 break;
3699 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003700 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003701 }
3702 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003703 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003704 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3705 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003706 0);
3707 efx_filter_set_uc_def(&spec);
3708 rc = efx_ef10_filter_insert(efx, &spec, true);
3709 if (rc < 0) {
3710 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003711 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003712 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003713 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003714 }
3715 }
3716
3717 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003718 if (table->dev_mc_count >= 0) {
3719 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003720 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3721 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003722 0);
3723 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003724 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003725 rc = efx_ef10_filter_insert(efx, &spec, true);
3726 if (rc < 0) {
3727 /* Fall back to multicast-promisc */
3728 while (i--)
3729 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003730 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003731 table->dev_mc_list[i].id);
3732 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003733 break;
3734 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003735 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003736 }
3737 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003738 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003739 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3740 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003741 0);
3742 efx_filter_set_mc_def(&spec);
3743 rc = efx_ef10_filter_insert(efx, &spec, true);
3744 if (rc < 0) {
3745 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003746 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003747 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003748 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003749 }
3750 }
3751
3752 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003753 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003754 * don't need to hold the filter_lock while scanning for
3755 * these filters.
3756 */
3757 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3758 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003759 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003760 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003761 efx, 1U << EFX_FILTER_PRI_AUTO,
3762 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003763 remove_failed = true;
3764 }
3765 }
3766 WARN_ON(remove_failed);
3767}
3768
Shradha Shah910c8782015-05-20 11:12:48 +01003769static int efx_ef10_set_mac_address(struct efx_nic *efx)
3770{
3771 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
3772 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3773 bool was_enabled = efx->port_enabled;
3774 int rc;
3775
3776 efx_device_detach_sync(efx);
3777 efx_net_stop(efx->net_dev);
3778 down_write(&efx->filter_sem);
3779 efx_ef10_filter_table_remove(efx);
3780
3781 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
3782 efx->net_dev->dev_addr);
3783 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
3784 nic_data->vport_id);
3785 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
3786 sizeof(inbuf), NULL, 0, NULL);
3787
3788 efx_ef10_filter_table_probe(efx);
3789 up_write(&efx->filter_sem);
3790 if (was_enabled)
3791 efx_net_open(efx->net_dev);
3792 netif_device_attach(efx->net_dev);
3793
3794#if !defined(CONFIG_SFC_SRIOV)
3795 if (rc == -EPERM)
3796 netif_err(efx, drv, efx->net_dev,
3797 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3798 " on this interface\n");
3799#else
3800 if (rc == -EPERM) {
3801 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3802
3803 /* Switch to PF and change MAC address on vport */
3804 if (efx->pci_dev->is_virtfn && pci_dev_pf) {
3805 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3806
3807 if (!efx_ef10_sriov_set_vf_mac(efx_pf,
3808 nic_data->vf_index,
3809 efx->net_dev->dev_addr))
3810 return 0;
3811 }
3812 netif_err(efx, drv, efx->net_dev,
3813 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3814 " on this interface\n");
3815 } else if (efx->pci_dev->is_virtfn) {
3816 /* Successfully changed by VF (with MAC spoofing), so update the
3817 * parent PF if possible.
3818 */
3819 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3820
3821 if (pci_dev_pf) {
3822 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3823 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
3824 unsigned int i;
3825
3826 for (i = 0; i < efx_pf->vf_count; ++i) {
3827 struct ef10_vf *vf = nic_data->vf + i;
3828
3829 if (vf->efx == efx) {
3830 ether_addr_copy(vf->mac,
3831 efx->net_dev->dev_addr);
3832 return 0;
3833 }
3834 }
3835 }
3836 }
3837#endif
3838 return rc;
3839}
3840
Ben Hutchings8127d662013-08-29 19:19:29 +01003841static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3842{
3843 efx_ef10_filter_sync_rx_mode(efx);
3844
3845 return efx_mcdi_set_mac(efx);
3846}
3847
Shradha Shah862f8942015-05-20 11:08:56 +01003848static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3849{
3850 efx_ef10_filter_sync_rx_mode(efx);
3851
3852 return 0;
3853}
3854
Jon Cooper74cd60a2013-09-16 14:18:51 +01003855static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3856{
3857 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3858
3859 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3860 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3861 NULL, 0, NULL);
3862}
3863
3864/* MC BISTs follow a different poll mechanism to phy BISTs.
3865 * The BIST is done in the poll handler on the MC, and the MCDI command
3866 * will block until the BIST is done.
3867 */
3868static int efx_ef10_poll_bist(struct efx_nic *efx)
3869{
3870 int rc;
3871 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3872 size_t outlen;
3873 u32 result;
3874
3875 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3876 outbuf, sizeof(outbuf), &outlen);
3877 if (rc != 0)
3878 return rc;
3879
3880 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3881 return -EIO;
3882
3883 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3884 switch (result) {
3885 case MC_CMD_POLL_BIST_PASSED:
3886 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3887 return 0;
3888 case MC_CMD_POLL_BIST_TIMEOUT:
3889 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3890 return -EIO;
3891 case MC_CMD_POLL_BIST_FAILED:
3892 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3893 return -EIO;
3894 default:
3895 netif_err(efx, hw, efx->net_dev,
3896 "BIST returned unknown result %u", result);
3897 return -EIO;
3898 }
3899}
3900
3901static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3902{
3903 int rc;
3904
3905 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3906
3907 rc = efx_ef10_start_bist(efx, bist_type);
3908 if (rc != 0)
3909 return rc;
3910
3911 return efx_ef10_poll_bist(efx);
3912}
3913
3914static int
3915efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3916{
3917 int rc, rc2;
3918
3919 efx_reset_down(efx, RESET_TYPE_WORLD);
3920
3921 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3922 NULL, 0, NULL, 0, NULL);
3923 if (rc != 0)
3924 goto out;
3925
3926 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3927 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3928
3929 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3930
3931out:
3932 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3933 return rc ? rc : rc2;
3934}
3935
Ben Hutchings8127d662013-08-29 19:19:29 +01003936#ifdef CONFIG_SFC_MTD
3937
3938struct efx_ef10_nvram_type_info {
3939 u16 type, type_mask;
3940 u8 port;
3941 const char *name;
3942};
3943
3944static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3945 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3946 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3947 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3948 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3949 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3950 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3951 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3952 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3953 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003954 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003955 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3956};
3957
3958static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3959 struct efx_mcdi_mtd_partition *part,
3960 unsigned int type)
3961{
3962 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3963 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3964 const struct efx_ef10_nvram_type_info *info;
3965 size_t size, erase_size, outlen;
3966 bool protected;
3967 int rc;
3968
3969 for (info = efx_ef10_nvram_types; ; info++) {
3970 if (info ==
3971 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3972 return -ENODEV;
3973 if ((type & ~info->type_mask) == info->type)
3974 break;
3975 }
3976 if (info->port != efx_port_num(efx))
3977 return -ENODEV;
3978
3979 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3980 if (rc)
3981 return rc;
3982 if (protected)
3983 return -ENODEV; /* hide it */
3984
3985 part->nvram_type = type;
3986
3987 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3988 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3989 outbuf, sizeof(outbuf), &outlen);
3990 if (rc)
3991 return rc;
3992 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3993 return -EIO;
3994 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3995 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3996 part->fw_subtype = MCDI_DWORD(outbuf,
3997 NVRAM_METADATA_OUT_SUBTYPE);
3998
3999 part->common.dev_type_name = "EF10 NVRAM manager";
4000 part->common.type_name = info->name;
4001
4002 part->common.mtd.type = MTD_NORFLASH;
4003 part->common.mtd.flags = MTD_CAP_NORFLASH;
4004 part->common.mtd.size = size;
4005 part->common.mtd.erasesize = erase_size;
4006
4007 return 0;
4008}
4009
4010static int efx_ef10_mtd_probe(struct efx_nic *efx)
4011{
4012 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
4013 struct efx_mcdi_mtd_partition *parts;
4014 size_t outlen, n_parts_total, i, n_parts;
4015 unsigned int type;
4016 int rc;
4017
4018 ASSERT_RTNL();
4019
4020 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
4021 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
4022 outbuf, sizeof(outbuf), &outlen);
4023 if (rc)
4024 return rc;
4025 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
4026 return -EIO;
4027
4028 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
4029 if (n_parts_total >
4030 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
4031 return -EIO;
4032
4033 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
4034 if (!parts)
4035 return -ENOMEM;
4036
4037 n_parts = 0;
4038 for (i = 0; i < n_parts_total; i++) {
4039 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
4040 i);
4041 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
4042 if (rc == 0)
4043 n_parts++;
4044 else if (rc != -ENODEV)
4045 goto fail;
4046 }
4047
4048 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
4049fail:
4050 if (rc)
4051 kfree(parts);
4052 return rc;
4053}
4054
4055#endif /* CONFIG_SFC_MTD */
4056
4057static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
4058{
4059 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
4060}
4061
Shradha Shah02246a72015-05-06 00:58:14 +01004062static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
4063 u32 host_time) {}
4064
Jon Cooperbd9a2652013-11-18 12:54:41 +00004065static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
4066 bool temp)
4067{
4068 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
4069 int rc;
4070
4071 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
4072 channel->sync_events_state == SYNC_EVENTS_VALID ||
4073 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
4074 return 0;
4075 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
4076
4077 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
4078 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4079 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
4080 channel->channel);
4081
4082 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4083 inbuf, sizeof(inbuf), NULL, 0, NULL);
4084
4085 if (rc != 0)
4086 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4087 SYNC_EVENTS_DISABLED;
4088
4089 return rc;
4090}
4091
4092static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
4093 bool temp)
4094{
4095 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
4096 int rc;
4097
4098 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
4099 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
4100 return 0;
4101 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
4102 channel->sync_events_state = SYNC_EVENTS_DISABLED;
4103 return 0;
4104 }
4105 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
4106 SYNC_EVENTS_DISABLED;
4107
4108 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
4109 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
4110 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
4111 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
4112 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
4113 channel->channel);
4114
4115 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
4116 inbuf, sizeof(inbuf), NULL, 0, NULL);
4117
4118 return rc;
4119}
4120
4121static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
4122 bool temp)
4123{
4124 int (*set)(struct efx_channel *channel, bool temp);
4125 struct efx_channel *channel;
4126
4127 set = en ?
4128 efx_ef10_rx_enable_timestamping :
4129 efx_ef10_rx_disable_timestamping;
4130
4131 efx_for_each_channel(channel, efx) {
4132 int rc = set(channel, temp);
4133 if (en && rc != 0) {
4134 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
4135 return rc;
4136 }
4137 }
4138
4139 return 0;
4140}
4141
Shradha Shah02246a72015-05-06 00:58:14 +01004142static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
4143 struct hwtstamp_config *init)
4144{
4145 return -EOPNOTSUPP;
4146}
4147
Jon Cooperbd9a2652013-11-18 12:54:41 +00004148static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
4149 struct hwtstamp_config *init)
4150{
4151 int rc;
4152
4153 switch (init->rx_filter) {
4154 case HWTSTAMP_FILTER_NONE:
4155 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
4156 /* if TX timestamping is still requested then leave PTP on */
4157 return efx_ptp_change_mode(efx,
4158 init->tx_type != HWTSTAMP_TX_OFF, 0);
4159 case HWTSTAMP_FILTER_ALL:
4160 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
4161 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
4162 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
4163 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
4164 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
4165 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
4166 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
4167 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
4168 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
4169 case HWTSTAMP_FILTER_PTP_V2_EVENT:
4170 case HWTSTAMP_FILTER_PTP_V2_SYNC:
4171 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
4172 init->rx_filter = HWTSTAMP_FILTER_ALL;
4173 rc = efx_ptp_change_mode(efx, true, 0);
4174 if (!rc)
4175 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
4176 if (rc)
4177 efx_ptp_change_mode(efx, false, 0);
4178 return rc;
4179 default:
4180 return -ERANGE;
4181 }
4182}
4183
Shradha Shah02246a72015-05-06 00:58:14 +01004184const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004185 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01004186 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01004187 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01004188 .probe = efx_ef10_probe_vf,
4189 .remove = efx_ef10_remove,
4190 .dimension_resources = efx_ef10_dimension_resources,
4191 .init = efx_ef10_init_nic,
4192 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004193 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01004194 .map_reset_flags = efx_ef10_map_reset_flags,
4195 .reset = efx_ef10_reset,
4196 .probe_port = efx_mcdi_port_probe,
4197 .remove_port = efx_mcdi_port_remove,
4198 .fini_dmaq = efx_ef10_fini_dmaq,
4199 .prepare_flr = efx_ef10_prepare_flr,
4200 .finish_flr = efx_port_dummy_op_void,
4201 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004202 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004203 .start_stats = efx_port_dummy_op_void,
4204 .pull_stats = efx_port_dummy_op_void,
4205 .stop_stats = efx_port_dummy_op_void,
4206 .set_id_led = efx_mcdi_set_id_led,
4207 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01004208 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004209 .check_mac_fault = efx_mcdi_mac_check_fault,
4210 .reconfigure_port = efx_mcdi_port_reconfigure,
4211 .get_wol = efx_ef10_get_wol_vf,
4212 .set_wol = efx_ef10_set_wol_vf,
4213 .resume_wol = efx_port_dummy_op_void,
4214 .mcdi_request = efx_ef10_mcdi_request,
4215 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4216 .mcdi_read_response = efx_ef10_mcdi_read_response,
4217 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4218 .irq_enable_master = efx_port_dummy_op_void,
4219 .irq_test_generate = efx_ef10_irq_test_generate,
4220 .irq_disable_non_ev = efx_port_dummy_op_void,
4221 .irq_handle_msi = efx_ef10_msi_interrupt,
4222 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4223 .tx_probe = efx_ef10_tx_probe,
4224 .tx_init = efx_ef10_tx_init,
4225 .tx_remove = efx_ef10_tx_remove,
4226 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004227 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01004228 .rx_probe = efx_ef10_rx_probe,
4229 .rx_init = efx_ef10_rx_init,
4230 .rx_remove = efx_ef10_rx_remove,
4231 .rx_write = efx_ef10_rx_write,
4232 .rx_defer_refill = efx_ef10_rx_defer_refill,
4233 .ev_probe = efx_ef10_ev_probe,
4234 .ev_init = efx_ef10_ev_init,
4235 .ev_fini = efx_ef10_ev_fini,
4236 .ev_remove = efx_ef10_ev_remove,
4237 .ev_process = efx_ef10_ev_process,
4238 .ev_read_ack = efx_ef10_ev_read_ack,
4239 .ev_test_generate = efx_ef10_ev_test_generate,
4240 .filter_table_probe = efx_ef10_filter_table_probe,
4241 .filter_table_restore = efx_ef10_filter_table_restore,
4242 .filter_table_remove = efx_ef10_filter_table_remove,
4243 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4244 .filter_insert = efx_ef10_filter_insert,
4245 .filter_remove_safe = efx_ef10_filter_remove_safe,
4246 .filter_get_safe = efx_ef10_filter_get_safe,
4247 .filter_clear_rx = efx_ef10_filter_clear_rx,
4248 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4249 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4250 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4251#ifdef CONFIG_RFS_ACCEL
4252 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4253 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4254#endif
4255#ifdef CONFIG_SFC_MTD
4256 .mtd_probe = efx_port_dummy_op_int,
4257#endif
4258 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4259 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4260#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004261 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4262 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4263 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah1d051e02015-06-02 11:38:16 +01004264 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01004265#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004266 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01004267 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004268
Shradha Shah02246a72015-05-06 00:58:14 +01004269 .revision = EFX_REV_HUNT_A0,
4270 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4271 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4272 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4273 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4274 .can_rx_scatter = true,
4275 .always_rx_scatter = true,
4276 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4277 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4278 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4279 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4280 .mcdi_max_ver = 2,
4281 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4282 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4283 1 << HWTSTAMP_FILTER_ALL,
4284};
4285
4286const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004287 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004288 .mem_bar = EFX_MEM_BAR,
4289 .mem_map_size = efx_ef10_mem_map_size,
4290 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004291 .remove = efx_ef10_remove,
4292 .dimension_resources = efx_ef10_dimension_resources,
4293 .init = efx_ef10_init_nic,
4294 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004295 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01004296 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004297 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004298 .probe_port = efx_mcdi_port_probe,
4299 .remove_port = efx_mcdi_port_remove,
4300 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004301 .prepare_flr = efx_ef10_prepare_flr,
4302 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004303 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01004304 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004305 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004306 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004307 .stop_stats = efx_mcdi_mac_stop_stats,
4308 .set_id_led = efx_mcdi_set_id_led,
4309 .push_irq_moderation = efx_ef10_push_irq_moderation,
4310 .reconfigure_mac = efx_ef10_mac_reconfigure,
4311 .check_mac_fault = efx_mcdi_mac_check_fault,
4312 .reconfigure_port = efx_mcdi_port_reconfigure,
4313 .get_wol = efx_ef10_get_wol,
4314 .set_wol = efx_ef10_set_wol,
4315 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004316 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004317 .test_nvram = efx_mcdi_nvram_test_all,
4318 .mcdi_request = efx_ef10_mcdi_request,
4319 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4320 .mcdi_read_response = efx_ef10_mcdi_read_response,
4321 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4322 .irq_enable_master = efx_port_dummy_op_void,
4323 .irq_test_generate = efx_ef10_irq_test_generate,
4324 .irq_disable_non_ev = efx_port_dummy_op_void,
4325 .irq_handle_msi = efx_ef10_msi_interrupt,
4326 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4327 .tx_probe = efx_ef10_tx_probe,
4328 .tx_init = efx_ef10_tx_init,
4329 .tx_remove = efx_ef10_tx_remove,
4330 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004331 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004332 .rx_probe = efx_ef10_rx_probe,
4333 .rx_init = efx_ef10_rx_init,
4334 .rx_remove = efx_ef10_rx_remove,
4335 .rx_write = efx_ef10_rx_write,
4336 .rx_defer_refill = efx_ef10_rx_defer_refill,
4337 .ev_probe = efx_ef10_ev_probe,
4338 .ev_init = efx_ef10_ev_init,
4339 .ev_fini = efx_ef10_ev_fini,
4340 .ev_remove = efx_ef10_ev_remove,
4341 .ev_process = efx_ef10_ev_process,
4342 .ev_read_ack = efx_ef10_ev_read_ack,
4343 .ev_test_generate = efx_ef10_ev_test_generate,
4344 .filter_table_probe = efx_ef10_filter_table_probe,
4345 .filter_table_restore = efx_ef10_filter_table_restore,
4346 .filter_table_remove = efx_ef10_filter_table_remove,
4347 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4348 .filter_insert = efx_ef10_filter_insert,
4349 .filter_remove_safe = efx_ef10_filter_remove_safe,
4350 .filter_get_safe = efx_ef10_filter_get_safe,
4351 .filter_clear_rx = efx_ef10_filter_clear_rx,
4352 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4353 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4354 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4355#ifdef CONFIG_RFS_ACCEL
4356 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4357 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4358#endif
4359#ifdef CONFIG_SFC_MTD
4360 .mtd_probe = efx_ef10_mtd_probe,
4361 .mtd_rename = efx_mcdi_mtd_rename,
4362 .mtd_read = efx_mcdi_mtd_read,
4363 .mtd_erase = efx_mcdi_mtd_erase,
4364 .mtd_write = efx_mcdi_mtd_write,
4365 .mtd_sync = efx_mcdi_mtd_sync,
4366#endif
4367 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004368 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4369 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004370#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004371 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004372 .sriov_init = efx_ef10_sriov_init,
4373 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004374 .sriov_wanted = efx_ef10_sriov_wanted,
4375 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004376 .sriov_flr = efx_ef10_sriov_flr,
4377 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4378 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4379 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4380 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01004381 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004382 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4383 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4384 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004385#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004386 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004387 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01004388
4389 .revision = EFX_REV_HUNT_A0,
4390 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4391 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4392 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004393 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004394 .can_rx_scatter = true,
4395 .always_rx_scatter = true,
4396 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4397 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4398 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4399 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4400 .mcdi_max_ver = 2,
4401 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004402 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4403 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004404};