blob: 40586265de61d687070461c26b20586cedb46510 [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
Ben Hutchings8127d662013-08-29 19:19:29 +0100249static int efx_ef10_probe(struct efx_nic *efx)
250{
251 struct efx_ef10_nic_data *nic_data;
252 int i, rc;
253
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000254 /* We can have one VI for each 8K region. However, until we
255 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100256 */
257 efx->max_channels =
258 min_t(unsigned int,
259 EFX_MAX_CHANNELS,
Shradha Shah02246a72015-05-06 00:58:14 +0100260 efx_ef10_mem_map_size(efx) /
Ben Hutchings8127d662013-08-29 19:19:29 +0100261 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000262 if (WARN_ON(efx->max_channels == 0))
263 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100264
265 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
266 if (!nic_data)
267 return -ENOMEM;
268 efx->nic_data = nic_data;
269
270 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
271 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
272 if (rc)
273 goto fail1;
274
275 /* Get the MC's warm boot count. In case it's rebooting right
276 * now, be prepared to retry.
277 */
278 i = 0;
279 for (;;) {
280 rc = efx_ef10_get_warm_boot_count(efx);
281 if (rc >= 0)
282 break;
283 if (++i == 5)
284 goto fail2;
285 ssleep(1);
286 }
287 nic_data->warm_boot_count = rc;
288
289 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
290
Daniel Pieczko45b24492015-05-06 00:57:14 +0100291 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
292
Ben Hutchings8127d662013-08-29 19:19:29 +0100293 /* In case we're recovering from a crash (kexec), we want to
294 * cancel any outstanding request by the previous user of this
295 * function. We send a special message using the least
296 * significant bits of the 'high' (doorbell) register.
297 */
298 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
299
300 rc = efx_mcdi_init(efx);
301 if (rc)
302 goto fail2;
303
304 /* Reset (most) configuration for this function */
305 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
306 if (rc)
307 goto fail3;
308
309 /* Enable event logging */
310 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
311 if (rc)
312 goto fail3;
313
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100314 rc = efx_ef10_get_pf_index(efx);
315 if (rc)
316 goto fail3;
317
Ben Hutchingse5a25382013-09-05 22:50:59 +0100318 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100319 if (rc < 0)
320 goto fail3;
321
322 efx->rx_packet_len_offset =
323 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
324
Ben Hutchings8127d662013-08-29 19:19:29 +0100325 rc = efx_mcdi_port_get_number(efx);
326 if (rc < 0)
327 goto fail3;
328 efx->port_num = rc;
329
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100330 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100331 if (rc)
332 goto fail3;
333
334 rc = efx_ef10_get_sysclk_freq(efx);
335 if (rc < 0)
336 goto fail3;
337 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
338
Edward Cree267d9d72015-05-06 00:59:18 +0100339 /* Check whether firmware supports bug 35388 workaround.
340 * First try to enable it, then if we get EPERM, just
341 * ask if it's already enabled
342 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100343 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true);
344 if (rc == 0)
345 nic_data->workaround_35388 = true;
Edward Cree267d9d72015-05-06 00:59:18 +0100346 else if (rc == -EPERM) {
347 unsigned int enabled;
348
349 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
350 if (rc)
351 goto fail3;
352 nic_data->workaround_35388 = enabled &
353 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
354 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100355 else if (rc != -ENOSYS && rc != -ENOENT)
356 goto fail3;
357 netif_dbg(efx, probe, efx->net_dev,
358 "workaround for bug 35388 is %sabled\n",
359 nic_data->workaround_35388 ? "en" : "dis");
360
361 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100362 if (rc && rc != -EPERM)
Ben Hutchings8127d662013-08-29 19:19:29 +0100363 goto fail3;
364
Ben Hutchings9aecda92013-12-05 21:28:42 +0000365 efx_ptp_probe(efx, NULL);
366
Ben Hutchings8127d662013-08-29 19:19:29 +0100367 return 0;
368
369fail3:
370 efx_mcdi_fini(efx);
371fail2:
372 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
373fail1:
374 kfree(nic_data);
375 efx->nic_data = NULL;
376 return rc;
377}
378
379static int efx_ef10_free_vis(struct efx_nic *efx)
380{
Edward Cree1e0b8122013-05-31 18:36:12 +0100381 MCDI_DECLARE_BUF_OUT_OR_ERR(outbuf, 0);
382 size_t outlen;
383 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
384 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100385
386 /* -EALREADY means nothing to free, so ignore */
387 if (rc == -EALREADY)
388 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100389 if (rc)
390 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
391 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100392 return rc;
393}
394
Ben Hutchings183233b2013-06-28 21:47:12 +0100395#ifdef EFX_USE_PIO
396
397static void efx_ef10_free_piobufs(struct efx_nic *efx)
398{
399 struct efx_ef10_nic_data *nic_data = efx->nic_data;
400 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
401 unsigned int i;
402 int rc;
403
404 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
405
406 for (i = 0; i < nic_data->n_piobufs; i++) {
407 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
408 nic_data->piobuf_handle[i]);
409 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
410 NULL, 0, NULL);
411 WARN_ON(rc);
412 }
413
414 nic_data->n_piobufs = 0;
415}
416
417static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
418{
419 struct efx_ef10_nic_data *nic_data = efx->nic_data;
420 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
421 unsigned int i;
422 size_t outlen;
423 int rc = 0;
424
425 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
426
427 for (i = 0; i < n; i++) {
428 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
429 outbuf, sizeof(outbuf), &outlen);
430 if (rc)
431 break;
432 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
433 rc = -EIO;
434 break;
435 }
436 nic_data->piobuf_handle[i] =
437 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
438 netif_dbg(efx, probe, efx->net_dev,
439 "allocated PIO buffer %u handle %x\n", i,
440 nic_data->piobuf_handle[i]);
441 }
442
443 nic_data->n_piobufs = i;
444 if (rc)
445 efx_ef10_free_piobufs(efx);
446 return rc;
447}
448
449static int efx_ef10_link_piobufs(struct efx_nic *efx)
450{
451 struct efx_ef10_nic_data *nic_data = efx->nic_data;
452 MCDI_DECLARE_BUF(inbuf,
453 max(MC_CMD_LINK_PIOBUF_IN_LEN,
454 MC_CMD_UNLINK_PIOBUF_IN_LEN));
455 struct efx_channel *channel;
456 struct efx_tx_queue *tx_queue;
457 unsigned int offset, index;
458 int rc;
459
460 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
461 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
462
463 /* Link a buffer to each VI in the write-combining mapping */
464 for (index = 0; index < nic_data->n_piobufs; ++index) {
465 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
466 nic_data->piobuf_handle[index]);
467 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
468 nic_data->pio_write_vi_base + index);
469 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
470 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
471 NULL, 0, NULL);
472 if (rc) {
473 netif_err(efx, drv, efx->net_dev,
474 "failed to link VI %u to PIO buffer %u (%d)\n",
475 nic_data->pio_write_vi_base + index, index,
476 rc);
477 goto fail;
478 }
479 netif_dbg(efx, probe, efx->net_dev,
480 "linked VI %u to PIO buffer %u\n",
481 nic_data->pio_write_vi_base + index, index);
482 }
483
484 /* Link a buffer to each TX queue */
485 efx_for_each_channel(channel, efx) {
486 efx_for_each_channel_tx_queue(tx_queue, channel) {
487 /* We assign the PIO buffers to queues in
488 * reverse order to allow for the following
489 * special case.
490 */
491 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
492 tx_queue->channel->channel - 1) *
493 efx_piobuf_size);
494 index = offset / ER_DZ_TX_PIOBUF_SIZE;
495 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
496
497 /* When the host page size is 4K, the first
498 * host page in the WC mapping may be within
499 * the same VI page as the last TX queue. We
500 * can only link one buffer to each VI.
501 */
502 if (tx_queue->queue == nic_data->pio_write_vi_base) {
503 BUG_ON(index != 0);
504 rc = 0;
505 } else {
506 MCDI_SET_DWORD(inbuf,
507 LINK_PIOBUF_IN_PIOBUF_HANDLE,
508 nic_data->piobuf_handle[index]);
509 MCDI_SET_DWORD(inbuf,
510 LINK_PIOBUF_IN_TXQ_INSTANCE,
511 tx_queue->queue);
512 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
513 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
514 NULL, 0, NULL);
515 }
516
517 if (rc) {
518 /* This is non-fatal; the TX path just
519 * won't use PIO for this queue
520 */
521 netif_err(efx, drv, efx->net_dev,
522 "failed to link VI %u to PIO buffer %u (%d)\n",
523 tx_queue->queue, index, rc);
524 tx_queue->piobuf = NULL;
525 } else {
526 tx_queue->piobuf =
527 nic_data->pio_write_base +
528 index * EFX_VI_PAGE_SIZE + offset;
529 tx_queue->piobuf_offset = offset;
530 netif_dbg(efx, probe, efx->net_dev,
531 "linked VI %u to PIO buffer %u offset %x addr %p\n",
532 tx_queue->queue, index,
533 tx_queue->piobuf_offset,
534 tx_queue->piobuf);
535 }
536 }
537 }
538
539 return 0;
540
541fail:
542 while (index--) {
543 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
544 nic_data->pio_write_vi_base + index);
545 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
546 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
547 NULL, 0, NULL);
548 }
549 return rc;
550}
551
552#else /* !EFX_USE_PIO */
553
554static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
555{
556 return n == 0 ? 0 : -ENOBUFS;
557}
558
559static int efx_ef10_link_piobufs(struct efx_nic *efx)
560{
561 return 0;
562}
563
564static void efx_ef10_free_piobufs(struct efx_nic *efx)
565{
566}
567
568#endif /* EFX_USE_PIO */
569
Ben Hutchings8127d662013-08-29 19:19:29 +0100570static void efx_ef10_remove(struct efx_nic *efx)
571{
572 struct efx_ef10_nic_data *nic_data = efx->nic_data;
573 int rc;
574
Shradha Shahf1122a32015-05-20 11:09:46 +0100575#ifdef CONFIG_SFC_SRIOV
576 struct efx_ef10_nic_data *nic_data_pf;
577 struct pci_dev *pci_dev_pf;
578 struct efx_nic *efx_pf;
579 struct ef10_vf *vf;
580
581 if (efx->pci_dev->is_virtfn) {
582 pci_dev_pf = efx->pci_dev->physfn;
583 if (pci_dev_pf) {
584 efx_pf = pci_get_drvdata(pci_dev_pf);
585 nic_data_pf = efx_pf->nic_data;
586 vf = nic_data_pf->vf + nic_data->vf_index;
587 vf->efx = NULL;
588 } else
589 netif_info(efx, drv, efx->net_dev,
590 "Could not get the PF id from VF\n");
591 }
592#endif
593
Ben Hutchings9aecda92013-12-05 21:28:42 +0000594 efx_ptp_remove(efx);
595
Ben Hutchings8127d662013-08-29 19:19:29 +0100596 efx_mcdi_mon_remove(efx);
597
Ben Hutchings8127d662013-08-29 19:19:29 +0100598 efx_ef10_rx_free_indir_table(efx);
599
Ben Hutchings183233b2013-06-28 21:47:12 +0100600 if (nic_data->wc_membase)
601 iounmap(nic_data->wc_membase);
602
Ben Hutchings8127d662013-08-29 19:19:29 +0100603 rc = efx_ef10_free_vis(efx);
604 WARN_ON(rc != 0);
605
Ben Hutchings183233b2013-06-28 21:47:12 +0100606 if (!nic_data->must_restore_piobufs)
607 efx_ef10_free_piobufs(efx);
608
Ben Hutchings8127d662013-08-29 19:19:29 +0100609 efx_mcdi_fini(efx);
610 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
611 kfree(nic_data);
612}
613
Shradha Shah88a37de2015-05-20 11:09:15 +0100614static int efx_ef10_probe_pf(struct efx_nic *efx)
615{
616 return efx_ef10_probe(efx);
617}
618
619#ifdef CONFIG_SFC_SRIOV
620static int efx_ef10_probe_vf(struct efx_nic *efx)
621{
622 int rc;
623
624 rc = efx_ef10_probe(efx);
625 if (rc)
626 return rc;
627
628 rc = efx_ef10_get_vf_index(efx);
629 if (rc)
630 goto fail;
631
Shradha Shahf1122a32015-05-20 11:09:46 +0100632 if (efx->pci_dev->is_virtfn) {
633 if (efx->pci_dev->physfn) {
634 struct efx_nic *efx_pf =
635 pci_get_drvdata(efx->pci_dev->physfn);
636 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
637 struct efx_ef10_nic_data *nic_data = efx->nic_data;
638
639 nic_data_p->vf[nic_data->vf_index].efx = efx;
640 } else
641 netif_info(efx, drv, efx->net_dev,
642 "Could not get the PF id from VF\n");
643 }
644
Shradha Shah88a37de2015-05-20 11:09:15 +0100645 return 0;
646
647fail:
648 efx_ef10_remove(efx);
649 return rc;
650}
651#else
652static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
653{
654 return 0;
655}
656#endif
657
Ben Hutchings8127d662013-08-29 19:19:29 +0100658static int efx_ef10_alloc_vis(struct efx_nic *efx,
659 unsigned int min_vis, unsigned int max_vis)
660{
661 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
662 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
663 struct efx_ef10_nic_data *nic_data = efx->nic_data;
664 size_t outlen;
665 int rc;
666
667 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
668 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
669 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
670 outbuf, sizeof(outbuf), &outlen);
671 if (rc != 0)
672 return rc;
673
674 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
675 return -EIO;
676
677 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
678 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
679
680 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
681 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
682 return 0;
683}
684
Ben Hutchings183233b2013-06-28 21:47:12 +0100685/* Note that the failure path of this function does not free
686 * resources, as this will be done by efx_ef10_remove().
687 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100688static int efx_ef10_dimension_resources(struct efx_nic *efx)
689{
Ben Hutchings183233b2013-06-28 21:47:12 +0100690 struct efx_ef10_nic_data *nic_data = efx->nic_data;
691 unsigned int uc_mem_map_size, wc_mem_map_size;
692 unsigned int min_vis, pio_write_vi_base, max_vis;
693 void __iomem *membase;
694 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100695
Ben Hutchings183233b2013-06-28 21:47:12 +0100696 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
697
698#ifdef EFX_USE_PIO
699 /* Try to allocate PIO buffers if wanted and if the full
700 * number of PIO buffers would be sufficient to allocate one
701 * copy-buffer per TX channel. Failure is non-fatal, as there
702 * are only a small number of PIO buffers shared between all
703 * functions of the controller.
704 */
705 if (efx_piobuf_size != 0 &&
706 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
707 efx->n_tx_channels) {
708 unsigned int n_piobufs =
709 DIV_ROUND_UP(efx->n_tx_channels,
710 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
711
712 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
713 if (rc)
714 netif_err(efx, probe, efx->net_dev,
715 "failed to allocate PIO buffers (%d)\n", rc);
716 else
717 netif_dbg(efx, probe, efx->net_dev,
718 "allocated %u PIO buffers\n", n_piobufs);
719 }
720#else
721 nic_data->n_piobufs = 0;
722#endif
723
724 /* PIO buffers should be mapped with write-combining enabled,
725 * and we want to make single UC and WC mappings rather than
726 * several of each (in fact that's the only option if host
727 * page size is >4K). So we may allocate some extra VIs just
728 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100729 *
730 * The UC mapping contains (min_vis - 1) complete VIs and the
731 * first half of the next VI. Then the WC mapping begins with
732 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100733 */
734 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
735 ER_DZ_TX_PIOBUF);
736 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100737 /* pio_write_vi_base rounds down to give the number of complete
738 * VIs inside the UC mapping.
739 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100740 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
741 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
742 nic_data->n_piobufs) *
743 EFX_VI_PAGE_SIZE) -
744 uc_mem_map_size);
745 max_vis = pio_write_vi_base + nic_data->n_piobufs;
746 } else {
747 pio_write_vi_base = 0;
748 wc_mem_map_size = 0;
749 max_vis = min_vis;
750 }
751
752 /* In case the last attached driver failed to free VIs, do it now */
753 rc = efx_ef10_free_vis(efx);
754 if (rc != 0)
755 return rc;
756
757 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
758 if (rc != 0)
759 return rc;
760
761 /* If we didn't get enough VIs to map all the PIO buffers, free the
762 * PIO buffers
763 */
764 if (nic_data->n_piobufs &&
765 nic_data->n_allocated_vis <
766 pio_write_vi_base + nic_data->n_piobufs) {
767 netif_dbg(efx, probe, efx->net_dev,
768 "%u VIs are not sufficient to map %u PIO buffers\n",
769 nic_data->n_allocated_vis, nic_data->n_piobufs);
770 efx_ef10_free_piobufs(efx);
771 }
772
773 /* Shrink the original UC mapping of the memory BAR */
774 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
775 if (!membase) {
776 netif_err(efx, probe, efx->net_dev,
777 "could not shrink memory BAR to %x\n",
778 uc_mem_map_size);
779 return -ENOMEM;
780 }
781 iounmap(efx->membase);
782 efx->membase = membase;
783
784 /* Set up the WC mapping if needed */
785 if (wc_mem_map_size) {
786 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
787 uc_mem_map_size,
788 wc_mem_map_size);
789 if (!nic_data->wc_membase) {
790 netif_err(efx, probe, efx->net_dev,
791 "could not allocate WC mapping of size %x\n",
792 wc_mem_map_size);
793 return -ENOMEM;
794 }
795 nic_data->pio_write_vi_base = pio_write_vi_base;
796 nic_data->pio_write_base =
797 nic_data->wc_membase +
798 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
799 uc_mem_map_size);
800
801 rc = efx_ef10_link_piobufs(efx);
802 if (rc)
803 efx_ef10_free_piobufs(efx);
804 }
805
806 netif_dbg(efx, probe, efx->net_dev,
807 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
808 &efx->membase_phys, efx->membase, uc_mem_map_size,
809 nic_data->wc_membase, wc_mem_map_size);
810
811 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100812}
813
814static int efx_ef10_init_nic(struct efx_nic *efx)
815{
816 struct efx_ef10_nic_data *nic_data = efx->nic_data;
817 int rc;
818
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100819 if (nic_data->must_check_datapath_caps) {
820 rc = efx_ef10_init_datapath_caps(efx);
821 if (rc)
822 return rc;
823 nic_data->must_check_datapath_caps = false;
824 }
825
Ben Hutchings8127d662013-08-29 19:19:29 +0100826 if (nic_data->must_realloc_vis) {
827 /* We cannot let the number of VIs change now */
828 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
829 nic_data->n_allocated_vis);
830 if (rc)
831 return rc;
832 nic_data->must_realloc_vis = false;
833 }
834
Ben Hutchings183233b2013-06-28 21:47:12 +0100835 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
836 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
837 if (rc == 0) {
838 rc = efx_ef10_link_piobufs(efx);
839 if (rc)
840 efx_ef10_free_piobufs(efx);
841 }
842
843 /* Log an error on failure, but this is non-fatal */
844 if (rc)
845 netif_err(efx, drv, efx->net_dev,
846 "failed to restore PIO buffers (%d)\n", rc);
847 nic_data->must_restore_piobufs = false;
848 }
849
Jon Cooper267c0152015-05-06 00:59:38 +0100850 /* don't fail init if RSS setup doesn't work */
851 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
852
Ben Hutchings8127d662013-08-29 19:19:29 +0100853 return 0;
854}
855
Jon Cooper3e336262014-01-17 19:48:06 +0000856static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
857{
858 struct efx_ef10_nic_data *nic_data = efx->nic_data;
859
860 /* All our allocations have been reset */
861 nic_data->must_realloc_vis = true;
862 nic_data->must_restore_filters = true;
863 nic_data->must_restore_piobufs = true;
864 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
865}
866
Ben Hutchings8127d662013-08-29 19:19:29 +0100867static int efx_ef10_map_reset_flags(u32 *flags)
868{
869 enum {
870 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
871 ETH_RESET_SHARED_SHIFT),
872 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
873 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
874 ETH_RESET_PHY | ETH_RESET_MGMT) <<
875 ETH_RESET_SHARED_SHIFT)
876 };
877
878 /* We assume for now that our PCI function is permitted to
879 * reset everything.
880 */
881
882 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
883 *flags &= ~EF10_RESET_MC;
884 return RESET_TYPE_WORLD;
885 }
886
887 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
888 *flags &= ~EF10_RESET_PORT;
889 return RESET_TYPE_ALL;
890 }
891
892 /* no invisible reset implemented */
893
894 return -EINVAL;
895}
896
Jon Cooper3e336262014-01-17 19:48:06 +0000897static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
898{
899 int rc = efx_mcdi_reset(efx, reset_type);
900
901 /* If it was a port reset, trigger reallocation of MC resources.
902 * Note that on an MC reset nothing needs to be done now because we'll
903 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +0100904 * For an FLR, we never get an MC reset event, but the MC has reset all
905 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +0000906 */
Edward Creee2835462014-04-16 19:27:48 +0100907 if ((reset_type == RESET_TYPE_ALL ||
908 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +0000909 efx_ef10_reset_mc_allocations(efx);
910 return rc;
911}
912
Ben Hutchings8127d662013-08-29 19:19:29 +0100913#define EF10_DMA_STAT(ext_name, mcdi_name) \
914 [EF10_STAT_ ## ext_name] = \
915 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
916#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
917 [EF10_STAT_ ## int_name] = \
918 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
919#define EF10_OTHER_STAT(ext_name) \
920 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +0100921#define GENERIC_SW_STAT(ext_name) \
922 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100923
924static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
925 EF10_DMA_STAT(tx_bytes, TX_BYTES),
926 EF10_DMA_STAT(tx_packets, TX_PKTS),
927 EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS),
928 EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS),
929 EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS),
930 EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS),
931 EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS),
932 EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS),
933 EF10_DMA_STAT(tx_64, TX_64_PKTS),
934 EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS),
935 EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS),
936 EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS),
937 EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS),
938 EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
939 EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
940 EF10_DMA_STAT(rx_bytes, RX_BYTES),
941 EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES),
942 EF10_OTHER_STAT(rx_good_bytes),
943 EF10_OTHER_STAT(rx_bad_bytes),
944 EF10_DMA_STAT(rx_packets, RX_PKTS),
945 EF10_DMA_STAT(rx_good, RX_GOOD_PKTS),
946 EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS),
947 EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS),
948 EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS),
949 EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS),
950 EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS),
951 EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS),
952 EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS),
953 EF10_DMA_STAT(rx_64, RX_64_PKTS),
954 EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS),
955 EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS),
956 EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS),
957 EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS),
958 EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
959 EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
960 EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS),
961 EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS),
962 EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS),
963 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
964 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
965 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +0100966 GENERIC_SW_STAT(rx_nodesc_trunc),
967 GENERIC_SW_STAT(rx_noskb_drops),
Edward Cree568d7a02013-09-25 17:32:09 +0100968 EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
969 EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
970 EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
971 EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
972 EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB),
973 EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB),
974 EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING),
975 EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
976 EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
977 EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
Shradha Shah79ac47a2013-11-28 18:48:49 +0000978 EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS),
979 EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS),
Ben Hutchings8127d662013-08-29 19:19:29 +0100980};
981
982#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \
983 (1ULL << EF10_STAT_tx_packets) | \
984 (1ULL << EF10_STAT_tx_pause) | \
985 (1ULL << EF10_STAT_tx_unicast) | \
986 (1ULL << EF10_STAT_tx_multicast) | \
987 (1ULL << EF10_STAT_tx_broadcast) | \
988 (1ULL << EF10_STAT_rx_bytes) | \
989 (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \
990 (1ULL << EF10_STAT_rx_good_bytes) | \
991 (1ULL << EF10_STAT_rx_bad_bytes) | \
992 (1ULL << EF10_STAT_rx_packets) | \
993 (1ULL << EF10_STAT_rx_good) | \
994 (1ULL << EF10_STAT_rx_bad) | \
995 (1ULL << EF10_STAT_rx_pause) | \
996 (1ULL << EF10_STAT_rx_control) | \
997 (1ULL << EF10_STAT_rx_unicast) | \
998 (1ULL << EF10_STAT_rx_multicast) | \
999 (1ULL << EF10_STAT_rx_broadcast) | \
1000 (1ULL << EF10_STAT_rx_lt64) | \
1001 (1ULL << EF10_STAT_rx_64) | \
1002 (1ULL << EF10_STAT_rx_65_to_127) | \
1003 (1ULL << EF10_STAT_rx_128_to_255) | \
1004 (1ULL << EF10_STAT_rx_256_to_511) | \
1005 (1ULL << EF10_STAT_rx_512_to_1023) | \
1006 (1ULL << EF10_STAT_rx_1024_to_15xx) | \
1007 (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \
1008 (1ULL << EF10_STAT_rx_gtjumbo) | \
1009 (1ULL << EF10_STAT_rx_bad_gtjumbo) | \
1010 (1ULL << EF10_STAT_rx_overflow) | \
Edward Creee4d112e2014-07-15 11:58:12 +01001011 (1ULL << EF10_STAT_rx_nodesc_drops) | \
1012 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1013 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001014
1015/* These statistics are only provided by the 10G MAC. For a 10G/40G
1016 * switchable port we do not expose these because they might not
1017 * include all the packets they should.
1018 */
1019#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \
1020 (1ULL << EF10_STAT_tx_lt64) | \
1021 (1ULL << EF10_STAT_tx_64) | \
1022 (1ULL << EF10_STAT_tx_65_to_127) | \
1023 (1ULL << EF10_STAT_tx_128_to_255) | \
1024 (1ULL << EF10_STAT_tx_256_to_511) | \
1025 (1ULL << EF10_STAT_tx_512_to_1023) | \
1026 (1ULL << EF10_STAT_tx_1024_to_15xx) | \
1027 (1ULL << EF10_STAT_tx_15xx_to_jumbo))
1028
1029/* These statistics are only provided by the 40G MAC. For a 10G/40G
1030 * switchable port we do expose these because the errors will otherwise
1031 * be silent.
1032 */
1033#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \
1034 (1ULL << EF10_STAT_rx_length_error))
1035
Edward Cree568d7a02013-09-25 17:32:09 +01001036/* These statistics are only provided if the firmware supports the
1037 * capability PM_AND_RXDP_COUNTERS.
1038 */
1039#define HUNT_PM_AND_RXDP_STAT_MASK ( \
1040 (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \
1041 (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \
1042 (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \
1043 (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \
1044 (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \
1045 (1ULL << EF10_STAT_rx_pm_discard_qbb) | \
1046 (1ULL << EF10_STAT_rx_pm_discard_mapping) | \
1047 (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \
1048 (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \
1049 (1ULL << EF10_STAT_rx_dp_streaming_packets) | \
Shradha Shah79ac47a2013-11-28 18:48:49 +00001050 (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \
1051 (1ULL << EF10_STAT_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001052
Edward Cree4bae9132013-09-27 18:52:49 +01001053static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001054{
Edward Cree4bae9132013-09-27 18:52:49 +01001055 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001056 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001057 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001058
1059 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001060 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001061 else
Edward Cree4bae9132013-09-27 18:52:49 +01001062 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001063
1064 if (nic_data->datapath_caps &
1065 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1066 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1067
Edward Cree4bae9132013-09-27 18:52:49 +01001068 return raw_mask;
1069}
1070
1071static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1072{
1073 u64 raw_mask = efx_ef10_raw_stat_mask(efx);
1074
1075#if BITS_PER_LONG == 64
1076 mask[0] = raw_mask;
1077#else
1078 mask[0] = raw_mask & 0xffffffff;
1079 mask[1] = raw_mask >> 32;
1080#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001081}
1082
1083static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1084{
Edward Cree4bae9132013-09-27 18:52:49 +01001085 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1086
1087 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001088 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001089 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001090}
1091
1092static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
1093{
1094 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001095 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001096 __le64 generation_start, generation_end;
1097 u64 *stats = nic_data->stats;
1098 __le64 *dma_stats;
1099
Edward Cree4bae9132013-09-27 18:52:49 +01001100 efx_ef10_get_stat_mask(efx, mask);
1101
Ben Hutchings8127d662013-08-29 19:19:29 +01001102 dma_stats = efx->stats_buffer.addr;
1103 nic_data = efx->nic_data;
1104
1105 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1106 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1107 return 0;
1108 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001109 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001110 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001111 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001112 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1113 if (generation_end != generation_start)
1114 return -EAGAIN;
1115
1116 /* Update derived statistics */
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001117 efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]);
Ben Hutchings8127d662013-08-29 19:19:29 +01001118 stats[EF10_STAT_rx_good_bytes] =
1119 stats[EF10_STAT_rx_bytes] -
1120 stats[EF10_STAT_rx_bytes_minus_good_bytes];
1121 efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes],
1122 stats[EF10_STAT_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001123 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001124 return 0;
1125}
1126
1127
1128static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats,
1129 struct rtnl_link_stats64 *core_stats)
1130{
Edward Cree4bae9132013-09-27 18:52:49 +01001131 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001132 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1133 u64 *stats = nic_data->stats;
1134 size_t stats_count = 0, index;
1135 int retry;
1136
Edward Cree4bae9132013-09-27 18:52:49 +01001137 efx_ef10_get_stat_mask(efx, mask);
1138
Ben Hutchings8127d662013-08-29 19:19:29 +01001139 /* If we're unlucky enough to read statistics during the DMA, wait
1140 * up to 10ms for it to finish (typically takes <500us)
1141 */
1142 for (retry = 0; retry < 100; ++retry) {
1143 if (efx_ef10_try_update_nic_stats(efx) == 0)
1144 break;
1145 udelay(100);
1146 }
1147
1148 if (full_stats) {
1149 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1150 if (efx_ef10_stat_desc[index].name) {
1151 *full_stats++ = stats[index];
1152 ++stats_count;
1153 }
1154 }
1155 }
1156
1157 if (core_stats) {
1158 core_stats->rx_packets = stats[EF10_STAT_rx_packets];
1159 core_stats->tx_packets = stats[EF10_STAT_tx_packets];
1160 core_stats->rx_bytes = stats[EF10_STAT_rx_bytes];
1161 core_stats->tx_bytes = stats[EF10_STAT_tx_bytes];
Edward Creee4d112e2014-07-15 11:58:12 +01001162 core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] +
1163 stats[GENERIC_STAT_rx_nodesc_trunc] +
1164 stats[GENERIC_STAT_rx_noskb_drops];
Ben Hutchings8127d662013-08-29 19:19:29 +01001165 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1166 core_stats->rx_length_errors =
1167 stats[EF10_STAT_rx_gtjumbo] +
1168 stats[EF10_STAT_rx_length_error];
1169 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1170 core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error];
1171 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1172 core_stats->rx_errors = (core_stats->rx_length_errors +
1173 core_stats->rx_crc_errors +
1174 core_stats->rx_frame_errors);
1175 }
1176
1177 return stats_count;
1178}
1179
1180static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1181{
1182 struct efx_nic *efx = channel->efx;
1183 unsigned int mode, value;
1184 efx_dword_t timer_cmd;
1185
1186 if (channel->irq_moderation) {
1187 mode = 3;
1188 value = channel->irq_moderation - 1;
1189 } else {
1190 mode = 0;
1191 value = 0;
1192 }
1193
1194 if (EFX_EF10_WORKAROUND_35388(efx)) {
1195 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1196 EFE_DD_EVQ_IND_TIMER_FLAGS,
1197 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1198 ERF_DD_EVQ_IND_TIMER_VAL, value);
1199 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1200 channel->channel);
1201 } else {
1202 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1203 ERF_DZ_TC_TIMER_VAL, value);
1204 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1205 channel->channel);
1206 }
1207}
1208
Shradha Shah02246a72015-05-06 00:58:14 +01001209static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1210 struct ethtool_wolinfo *wol) {}
1211
1212static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1213{
1214 return -EOPNOTSUPP;
1215}
1216
Ben Hutchings8127d662013-08-29 19:19:29 +01001217static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1218{
1219 wol->supported = 0;
1220 wol->wolopts = 0;
1221 memset(&wol->sopass, 0, sizeof(wol->sopass));
1222}
1223
1224static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1225{
1226 if (type != 0)
1227 return -EINVAL;
1228 return 0;
1229}
1230
1231static void efx_ef10_mcdi_request(struct efx_nic *efx,
1232 const efx_dword_t *hdr, size_t hdr_len,
1233 const efx_dword_t *sdu, size_t sdu_len)
1234{
1235 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1236 u8 *pdu = nic_data->mcdi_buf.addr;
1237
1238 memcpy(pdu, hdr, hdr_len);
1239 memcpy(pdu + hdr_len, sdu, sdu_len);
1240 wmb();
1241
1242 /* The hardware provides 'low' and 'high' (doorbell) registers
1243 * for passing the 64-bit address of an MCDI request to
1244 * firmware. However the dwords are swapped by firmware. The
1245 * least significant bits of the doorbell are then 0 for all
1246 * MCDI requests due to alignment.
1247 */
1248 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1249 ER_DZ_MC_DB_LWRD);
1250 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1251 ER_DZ_MC_DB_HWRD);
1252}
1253
1254static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1255{
1256 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1257 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1258
1259 rmb();
1260 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1261}
1262
1263static void
1264efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1265 size_t offset, size_t outlen)
1266{
1267 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1268 const u8 *pdu = nic_data->mcdi_buf.addr;
1269
1270 memcpy(outbuf, pdu + offset, outlen);
1271}
1272
1273static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1274{
1275 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1276 int rc;
1277
1278 rc = efx_ef10_get_warm_boot_count(efx);
1279 if (rc < 0) {
1280 /* The firmware is presumably in the process of
1281 * rebooting. However, we are supposed to report each
1282 * reboot just once, so we must only do that once we
1283 * can read and store the updated warm boot count.
1284 */
1285 return 0;
1286 }
1287
1288 if (rc == nic_data->warm_boot_count)
1289 return 0;
1290
1291 nic_data->warm_boot_count = rc;
1292
1293 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001294 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001295
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001296 /* Driver-created vswitches and vports must be re-created */
1297 nic_data->must_probe_vswitching = true;
1298 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1299
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001300 /* The datapath firmware might have been changed */
1301 nic_data->must_check_datapath_caps = true;
1302
Ben Hutchings869070c2013-09-05 22:46:10 +01001303 /* MAC statistics have been cleared on the NIC; clear the local
1304 * statistic that we update with efx_update_diff_stat().
1305 */
1306 nic_data->stats[EF10_STAT_rx_bad_bytes] = 0;
1307
Ben Hutchings8127d662013-08-29 19:19:29 +01001308 return -EIO;
1309}
1310
1311/* Handle an MSI interrupt
1312 *
1313 * Handle an MSI hardware interrupt. This routine schedules event
1314 * queue processing. No interrupt acknowledgement cycle is necessary.
1315 * Also, we never need to check that the interrupt is for us, since
1316 * MSI interrupts cannot be shared.
1317 */
1318static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1319{
1320 struct efx_msi_context *context = dev_id;
1321 struct efx_nic *efx = context->efx;
1322
1323 netif_vdbg(efx, intr, efx->net_dev,
1324 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1325
1326 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1327 /* Note test interrupts */
1328 if (context->index == efx->irq_level)
1329 efx->last_irq_cpu = raw_smp_processor_id();
1330
1331 /* Schedule processing of the channel */
1332 efx_schedule_channel_irq(efx->channel[context->index]);
1333 }
1334
1335 return IRQ_HANDLED;
1336}
1337
1338static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1339{
1340 struct efx_nic *efx = dev_id;
1341 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1342 struct efx_channel *channel;
1343 efx_dword_t reg;
1344 u32 queues;
1345
1346 /* Read the ISR which also ACKs the interrupts */
1347 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1348 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1349
1350 if (queues == 0)
1351 return IRQ_NONE;
1352
1353 if (likely(soft_enabled)) {
1354 /* Note test interrupts */
1355 if (queues & (1U << efx->irq_level))
1356 efx->last_irq_cpu = raw_smp_processor_id();
1357
1358 efx_for_each_channel(channel, efx) {
1359 if (queues & 1)
1360 efx_schedule_channel_irq(channel);
1361 queues >>= 1;
1362 }
1363 }
1364
1365 netif_vdbg(efx, intr, efx->net_dev,
1366 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1367 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1368
1369 return IRQ_HANDLED;
1370}
1371
1372static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1373{
1374 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1375
1376 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1377
1378 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1379 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1380 inbuf, sizeof(inbuf), NULL, 0, NULL);
1381}
1382
1383static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1384{
1385 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1386 (tx_queue->ptr_mask + 1) *
1387 sizeof(efx_qword_t),
1388 GFP_KERNEL);
1389}
1390
1391/* This writes to the TX_DESC_WPTR and also pushes data */
1392static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1393 const efx_qword_t *txd)
1394{
1395 unsigned int write_ptr;
1396 efx_oword_t reg;
1397
1398 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1399 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1400 reg.qword[0] = *txd;
1401 efx_writeo_page(tx_queue->efx, &reg,
1402 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1403}
1404
1405static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1406{
1407 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1408 EFX_BUF_SIZE));
1409 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_TXQ_OUT_LEN);
1410 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1411 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1412 struct efx_channel *channel = tx_queue->channel;
1413 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001414 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001415 size_t inlen, outlen;
1416 dma_addr_t dma_addr;
1417 efx_qword_t *txd;
1418 int rc;
1419 int i;
1420
1421 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1422 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1423 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1424 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1425 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1426 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1427 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1428 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001429 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001430
1431 dma_addr = tx_queue->txd.buf.dma_addr;
1432
1433 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1434 tx_queue->queue, entries, (u64)dma_addr);
1435
1436 for (i = 0; i < entries; ++i) {
1437 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1438 dma_addr += EFX_BUF_SIZE;
1439 }
1440
1441 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1442
1443 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
1444 outbuf, sizeof(outbuf), &outlen);
1445 if (rc)
1446 goto fail;
1447
1448 /* A previous user of this TX queue might have set us up the
1449 * bomb by writing a descriptor to the TX push collector but
1450 * not the doorbell. (Each collector belongs to a port, not a
1451 * queue or function, so cannot easily be reset.) We must
1452 * attempt to push a no-op descriptor in its place.
1453 */
1454 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1455 tx_queue->insert_count = 1;
1456 txd = efx_tx_desc(tx_queue, 0);
1457 EFX_POPULATE_QWORD_4(*txd,
1458 ESF_DZ_TX_DESC_IS_OPT, true,
1459 ESF_DZ_TX_OPTION_TYPE,
1460 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1461 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1462 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1463 tx_queue->write_count = 1;
1464 wmb();
1465 efx_ef10_push_tx_desc(tx_queue, txd);
1466
1467 return;
1468
1469fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001470 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1471 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001472}
1473
1474static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1475{
1476 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
1477 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_TXQ_OUT_LEN);
1478 struct efx_nic *efx = tx_queue->efx;
1479 size_t outlen;
1480 int rc;
1481
1482 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1483 tx_queue->queue);
1484
Edward Cree1e0b8122013-05-31 18:36:12 +01001485 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001486 outbuf, sizeof(outbuf), &outlen);
1487
1488 if (rc && rc != -EALREADY)
1489 goto fail;
1490
1491 return;
1492
1493fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001494 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1495 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001496}
1497
1498static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1499{
1500 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1501}
1502
1503/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1504static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1505{
1506 unsigned int write_ptr;
1507 efx_dword_t reg;
1508
1509 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1510 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1511 efx_writed_page(tx_queue->efx, &reg,
1512 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1513}
1514
1515static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1516{
1517 unsigned int old_write_count = tx_queue->write_count;
1518 struct efx_tx_buffer *buffer;
1519 unsigned int write_ptr;
1520 efx_qword_t *txd;
1521
1522 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1523
1524 do {
1525 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1526 buffer = &tx_queue->buffer[write_ptr];
1527 txd = efx_tx_desc(tx_queue, write_ptr);
1528 ++tx_queue->write_count;
1529
1530 /* Create TX descriptor ring entry */
1531 if (buffer->flags & EFX_TX_BUF_OPTION) {
1532 *txd = buffer->option;
1533 } else {
1534 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1535 EFX_POPULATE_QWORD_3(
1536 *txd,
1537 ESF_DZ_TX_KER_CONT,
1538 buffer->flags & EFX_TX_BUF_CONT,
1539 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1540 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1541 }
1542 } while (tx_queue->write_count != tx_queue->insert_count);
1543
1544 wmb(); /* Ensure descriptors are written before they are fetched */
1545
1546 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1547 txd = efx_tx_desc(tx_queue,
1548 old_write_count & tx_queue->ptr_mask);
1549 efx_ef10_push_tx_desc(tx_queue, txd);
1550 ++tx_queue->pushes;
1551 } else {
1552 efx_ef10_notify_tx_desc(tx_queue);
1553 }
1554}
1555
Jon Cooper267c0152015-05-06 00:59:38 +01001556static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1557 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001558{
1559 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1560 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001561 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001562 size_t outlen;
1563 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001564 u32 alloc_type = exclusive ?
1565 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1566 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1567 unsigned rss_spread = exclusive ?
1568 efx->rss_spread :
1569 min(rounddown_pow_of_two(efx->rss_spread),
1570 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1571
1572 if (!exclusive && rss_spread == 1) {
1573 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1574 if (context_size)
1575 *context_size = 1;
1576 return 0;
1577 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001578
1579 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001580 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001581 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1582 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001583
1584 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1585 outbuf, sizeof(outbuf), &outlen);
1586 if (rc != 0)
1587 return rc;
1588
1589 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1590 return -EIO;
1591
1592 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1593
Jon Cooper267c0152015-05-06 00:59:38 +01001594 if (context_size)
1595 *context_size = rss_spread;
1596
Ben Hutchings8127d662013-08-29 19:19:29 +01001597 return 0;
1598}
1599
1600static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1601{
1602 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1603 int rc;
1604
1605 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1606 context);
1607
1608 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1609 NULL, 0, NULL);
1610 WARN_ON(rc != 0);
1611}
1612
Jon Cooper267c0152015-05-06 00:59:38 +01001613static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1614 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001615{
1616 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1617 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1618 int i, rc;
1619
1620 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1621 context);
1622 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1623 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1624
1625 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1626 MCDI_PTR(tablebuf,
1627 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001628 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001629
1630 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1631 sizeof(tablebuf), NULL, 0, NULL);
1632 if (rc != 0)
1633 return rc;
1634
1635 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1636 context);
1637 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1638 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1639 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1640 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1641 efx->rx_hash_key[i];
1642
1643 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1644 sizeof(keybuf), NULL, 0, NULL);
1645}
1646
1647static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1648{
1649 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1650
1651 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1652 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1653 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1654}
1655
Jon Cooper267c0152015-05-06 00:59:38 +01001656static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1657 unsigned *context_size)
1658{
1659 u32 new_rx_rss_context;
1660 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1661 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1662 false, context_size);
1663
1664 if (rc != 0)
1665 return rc;
1666
1667 nic_data->rx_rss_context = new_rx_rss_context;
1668 nic_data->rx_rss_context_exclusive = false;
1669 efx_set_default_rx_indir_table(efx);
1670 return 0;
1671}
1672
1673static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1674 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001675{
1676 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1677 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001678 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001679
Jon Cooper267c0152015-05-06 00:59:38 +01001680 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1681 !nic_data->rx_rss_context_exclusive) {
1682 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1683 true, NULL);
1684 if (rc == -EOPNOTSUPP)
1685 return rc;
1686 else if (rc != 0)
1687 goto fail1;
1688 } else {
1689 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001690 }
1691
Jon Cooper267c0152015-05-06 00:59:38 +01001692 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1693 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001694 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001695 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001696
Jon Cooper267c0152015-05-06 00:59:38 +01001697 if (nic_data->rx_rss_context != new_rx_rss_context)
1698 efx_ef10_rx_free_indir_table(efx);
1699 nic_data->rx_rss_context = new_rx_rss_context;
1700 nic_data->rx_rss_context_exclusive = true;
1701 if (rx_indir_table != efx->rx_indir_table)
1702 memcpy(efx->rx_indir_table, rx_indir_table,
1703 sizeof(efx->rx_indir_table));
1704 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001705
Jon Cooper267c0152015-05-06 00:59:38 +01001706fail2:
1707 if (new_rx_rss_context != nic_data->rx_rss_context)
1708 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1709fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001710 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001711 return rc;
1712}
1713
1714static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1715 const u32 *rx_indir_table)
1716{
1717 int rc;
1718
1719 if (efx->rss_spread == 1)
1720 return 0;
1721
1722 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1723
1724 if (rc == -ENOBUFS && !user) {
1725 unsigned context_size;
1726 bool mismatch = false;
1727 size_t i;
1728
1729 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1730 i++)
1731 mismatch = rx_indir_table[i] !=
1732 ethtool_rxfh_indir_default(i, efx->rss_spread);
1733
1734 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1735 if (rc == 0) {
1736 if (context_size != efx->rss_spread)
1737 netif_warn(efx, probe, efx->net_dev,
1738 "Could not allocate an exclusive RSS"
1739 " context; allocated a shared one of"
1740 " different size."
1741 " Wanted %u, got %u.\n",
1742 efx->rss_spread, context_size);
1743 else if (mismatch)
1744 netif_warn(efx, probe, efx->net_dev,
1745 "Could not allocate an exclusive RSS"
1746 " context; allocated a shared one but"
1747 " could not apply custom"
1748 " indirection.\n");
1749 else
1750 netif_info(efx, probe, efx->net_dev,
1751 "Could not allocate an exclusive RSS"
1752 " context; allocated a shared one.\n");
1753 }
1754 }
1755 return rc;
1756}
1757
1758static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1759 const u32 *rx_indir_table
1760 __attribute__ ((unused)))
1761{
1762 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1763
1764 if (user)
1765 return -EOPNOTSUPP;
1766 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1767 return 0;
1768 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001769}
1770
1771static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1772{
1773 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1774 (rx_queue->ptr_mask + 1) *
1775 sizeof(efx_qword_t),
1776 GFP_KERNEL);
1777}
1778
1779static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1780{
1781 MCDI_DECLARE_BUF(inbuf,
1782 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1783 EFX_BUF_SIZE));
1784 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_RXQ_OUT_LEN);
1785 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1786 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1787 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001788 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001789 size_t inlen, outlen;
1790 dma_addr_t dma_addr;
1791 int rc;
1792 int i;
1793
1794 rx_queue->scatter_n = 0;
1795 rx_queue->scatter_len = 0;
1796
1797 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1798 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1799 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1800 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1801 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001802 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1803 INIT_RXQ_IN_FLAG_PREFIX, 1,
1804 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001805 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001806 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001807
1808 dma_addr = rx_queue->rxd.buf.dma_addr;
1809
1810 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1811 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1812
1813 for (i = 0; i < entries; ++i) {
1814 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
1815 dma_addr += EFX_BUF_SIZE;
1816 }
1817
1818 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
1819
1820 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
1821 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings48ce5632013-11-01 16:42:44 +00001822 if (rc)
1823 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
1824 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01001825}
1826
1827static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
1828{
1829 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
1830 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_RXQ_OUT_LEN);
1831 struct efx_nic *efx = rx_queue->efx;
1832 size_t outlen;
1833 int rc;
1834
1835 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
1836 efx_rx_queue_index(rx_queue));
1837
Edward Cree1e0b8122013-05-31 18:36:12 +01001838 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001839 outbuf, sizeof(outbuf), &outlen);
1840
1841 if (rc && rc != -EALREADY)
1842 goto fail;
1843
1844 return;
1845
1846fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001847 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
1848 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001849}
1850
1851static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
1852{
1853 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
1854}
1855
1856/* This creates an entry in the RX descriptor queue */
1857static inline void
1858efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
1859{
1860 struct efx_rx_buffer *rx_buf;
1861 efx_qword_t *rxd;
1862
1863 rxd = efx_rx_desc(rx_queue, index);
1864 rx_buf = efx_rx_buffer(rx_queue, index);
1865 EFX_POPULATE_QWORD_2(*rxd,
1866 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
1867 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
1868}
1869
1870static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
1871{
1872 struct efx_nic *efx = rx_queue->efx;
1873 unsigned int write_count;
1874 efx_dword_t reg;
1875
1876 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
1877 write_count = rx_queue->added_count & ~7;
1878 if (rx_queue->notified_count == write_count)
1879 return;
1880
1881 do
1882 efx_ef10_build_rx_desc(
1883 rx_queue,
1884 rx_queue->notified_count & rx_queue->ptr_mask);
1885 while (++rx_queue->notified_count != write_count);
1886
1887 wmb();
1888 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
1889 write_count & rx_queue->ptr_mask);
1890 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
1891 efx_rx_queue_index(rx_queue));
1892}
1893
1894static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
1895
1896static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
1897{
1898 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1899 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
1900 efx_qword_t event;
1901
1902 EFX_POPULATE_QWORD_2(event,
1903 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
1904 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
1905
1906 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
1907
1908 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
1909 * already swapped the data to little-endian order.
1910 */
1911 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
1912 sizeof(efx_qword_t));
1913
1914 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
1915 inbuf, sizeof(inbuf), 0,
1916 efx_ef10_rx_defer_refill_complete, 0);
1917}
1918
1919static void
1920efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
1921 int rc, efx_dword_t *outbuf,
1922 size_t outlen_actual)
1923{
1924 /* nothing to do */
1925}
1926
1927static int efx_ef10_ev_probe(struct efx_channel *channel)
1928{
1929 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
1930 (channel->eventq_mask + 1) *
1931 sizeof(efx_qword_t),
1932 GFP_KERNEL);
1933}
1934
1935static int efx_ef10_ev_init(struct efx_channel *channel)
1936{
1937 MCDI_DECLARE_BUF(inbuf,
1938 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
1939 EFX_BUF_SIZE));
1940 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
1941 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
1942 struct efx_nic *efx = channel->efx;
1943 struct efx_ef10_nic_data *nic_data;
1944 bool supports_rx_merge;
1945 size_t inlen, outlen;
1946 dma_addr_t dma_addr;
1947 int rc;
1948 int i;
1949
1950 nic_data = efx->nic_data;
1951 supports_rx_merge =
1952 !!(nic_data->datapath_caps &
1953 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
1954
1955 /* Fill event queue with all ones (i.e. empty events) */
1956 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
1957
1958 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
1959 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
1960 /* INIT_EVQ expects index in vector table, not absolute */
1961 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
1962 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
1963 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
1964 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
1965 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
1966 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
1967 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
1968 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
1969 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
1970 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
1971 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
1972 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
1973 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
1974
1975 dma_addr = channel->eventq.buf.dma_addr;
1976 for (i = 0; i < entries; ++i) {
1977 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
1978 dma_addr += EFX_BUF_SIZE;
1979 }
1980
1981 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
1982
1983 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
1984 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01001985 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01001986 return rc;
1987}
1988
1989static void efx_ef10_ev_fini(struct efx_channel *channel)
1990{
1991 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
1992 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_EVQ_OUT_LEN);
1993 struct efx_nic *efx = channel->efx;
1994 size_t outlen;
1995 int rc;
1996
1997 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
1998
Edward Cree1e0b8122013-05-31 18:36:12 +01001999 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002000 outbuf, sizeof(outbuf), &outlen);
2001
2002 if (rc && rc != -EALREADY)
2003 goto fail;
2004
2005 return;
2006
2007fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002008 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2009 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002010}
2011
2012static void efx_ef10_ev_remove(struct efx_channel *channel)
2013{
2014 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2015}
2016
2017static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2018 unsigned int rx_queue_label)
2019{
2020 struct efx_nic *efx = rx_queue->efx;
2021
2022 netif_info(efx, hw, efx->net_dev,
2023 "rx event arrived on queue %d labeled as queue %u\n",
2024 efx_rx_queue_index(rx_queue), rx_queue_label);
2025
2026 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2027}
2028
2029static void
2030efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2031 unsigned int actual, unsigned int expected)
2032{
2033 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2034 struct efx_nic *efx = rx_queue->efx;
2035
2036 netif_info(efx, hw, efx->net_dev,
2037 "dropped %d events (index=%d expected=%d)\n",
2038 dropped, actual, expected);
2039
2040 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2041}
2042
2043/* partially received RX was aborted. clean up. */
2044static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2045{
2046 unsigned int rx_desc_ptr;
2047
Ben Hutchings8127d662013-08-29 19:19:29 +01002048 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2049 "scattered RX aborted (dropping %u buffers)\n",
2050 rx_queue->scatter_n);
2051
2052 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2053
2054 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2055 0, EFX_RX_PKT_DISCARD);
2056
2057 rx_queue->removed_count += rx_queue->scatter_n;
2058 rx_queue->scatter_n = 0;
2059 rx_queue->scatter_len = 0;
2060 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2061}
2062
2063static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2064 const efx_qword_t *event)
2065{
2066 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2067 unsigned int n_descs, n_packets, i;
2068 struct efx_nic *efx = channel->efx;
2069 struct efx_rx_queue *rx_queue;
2070 bool rx_cont;
2071 u16 flags = 0;
2072
2073 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2074 return 0;
2075
2076 /* Basic packet information */
2077 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2078 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2079 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2080 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2081 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2082
Ben Hutchings48ce5632013-11-01 16:42:44 +00002083 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2084 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2085 EFX_QWORD_FMT "\n",
2086 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002087
2088 rx_queue = efx_channel_get_rx_queue(channel);
2089
2090 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2091 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2092
2093 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2094 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2095
2096 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002097 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2098
Ben Hutchings8127d662013-08-29 19:19:29 +01002099 /* detect rx abort */
2100 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002101 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2102 netdev_WARN(efx->net_dev,
2103 "invalid RX abort: scatter_n=%u event="
2104 EFX_QWORD_FMT "\n",
2105 rx_queue->scatter_n,
2106 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002107 efx_ef10_handle_rx_abort(rx_queue);
2108 return 0;
2109 }
2110
Ben Hutchings92a04162013-09-24 23:21:57 +01002111 /* Check that RX completion merging is valid, i.e.
2112 * the current firmware supports it and this is a
2113 * non-scattered packet.
2114 */
2115 if (!(nic_data->datapath_caps &
2116 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2117 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002118 efx_ef10_handle_rx_bad_lbits(
2119 rx_queue, next_ptr_lbits,
2120 (rx_queue->removed_count +
2121 rx_queue->scatter_n + 1) &
2122 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2123 return 0;
2124 }
2125
2126 /* Merged completion for multiple non-scattered packets */
2127 rx_queue->scatter_n = 1;
2128 rx_queue->scatter_len = 0;
2129 n_packets = n_descs;
2130 ++channel->n_rx_merge_events;
2131 channel->n_rx_merge_packets += n_packets;
2132 flags |= EFX_RX_PKT_PREFIX_LEN;
2133 } else {
2134 ++rx_queue->scatter_n;
2135 rx_queue->scatter_len += rx_bytes;
2136 if (rx_cont)
2137 return 0;
2138 n_packets = 1;
2139 }
2140
2141 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2142 flags |= EFX_RX_PKT_DISCARD;
2143
2144 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2145 channel->n_rx_ip_hdr_chksum_err += n_packets;
2146 } else if (unlikely(EFX_QWORD_FIELD(*event,
2147 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2148 channel->n_rx_tcp_udp_chksum_err += n_packets;
2149 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2150 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2151 flags |= EFX_RX_PKT_CSUMMED;
2152 }
2153
2154 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2155 flags |= EFX_RX_PKT_TCP;
2156
2157 channel->irq_mod_score += 2 * n_packets;
2158
2159 /* Handle received packet(s) */
2160 for (i = 0; i < n_packets; i++) {
2161 efx_rx_packet(rx_queue,
2162 rx_queue->removed_count & rx_queue->ptr_mask,
2163 rx_queue->scatter_n, rx_queue->scatter_len,
2164 flags);
2165 rx_queue->removed_count += rx_queue->scatter_n;
2166 }
2167
2168 rx_queue->scatter_n = 0;
2169 rx_queue->scatter_len = 0;
2170
2171 return n_packets;
2172}
2173
2174static int
2175efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2176{
2177 struct efx_nic *efx = channel->efx;
2178 struct efx_tx_queue *tx_queue;
2179 unsigned int tx_ev_desc_ptr;
2180 unsigned int tx_ev_q_label;
2181 int tx_descs = 0;
2182
2183 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2184 return 0;
2185
2186 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2187 return 0;
2188
2189 /* Transmit completion */
2190 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2191 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2192 tx_queue = efx_channel_get_tx_queue(channel,
2193 tx_ev_q_label % EFX_TXQ_TYPES);
2194 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2195 tx_queue->ptr_mask);
2196 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2197
2198 return tx_descs;
2199}
2200
2201static void
2202efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2203{
2204 struct efx_nic *efx = channel->efx;
2205 int subcode;
2206
2207 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2208
2209 switch (subcode) {
2210 case ESE_DZ_DRV_TIMER_EV:
2211 case ESE_DZ_DRV_WAKE_UP_EV:
2212 break;
2213 case ESE_DZ_DRV_START_UP_EV:
2214 /* event queue init complete. ok. */
2215 break;
2216 default:
2217 netif_err(efx, hw, efx->net_dev,
2218 "channel %d unknown driver event type %d"
2219 " (data " EFX_QWORD_FMT ")\n",
2220 channel->channel, subcode,
2221 EFX_QWORD_VAL(*event));
2222
2223 }
2224}
2225
2226static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2227 efx_qword_t *event)
2228{
2229 struct efx_nic *efx = channel->efx;
2230 u32 subcode;
2231
2232 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2233
2234 switch (subcode) {
2235 case EFX_EF10_TEST:
2236 channel->event_test_cpu = raw_smp_processor_id();
2237 break;
2238 case EFX_EF10_REFILL:
2239 /* The queue must be empty, so we won't receive any rx
2240 * events, so efx_process_channel() won't refill the
2241 * queue. Refill it here
2242 */
Jon Coopercce28792013-10-02 11:04:14 +01002243 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002244 break;
2245 default:
2246 netif_err(efx, hw, efx->net_dev,
2247 "channel %d unknown driver event type %u"
2248 " (data " EFX_QWORD_FMT ")\n",
2249 channel->channel, (unsigned) subcode,
2250 EFX_QWORD_VAL(*event));
2251 }
2252}
2253
2254static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2255{
2256 struct efx_nic *efx = channel->efx;
2257 efx_qword_t event, *p_event;
2258 unsigned int read_ptr;
2259 int ev_code;
2260 int tx_descs = 0;
2261 int spent = 0;
2262
Eric W. Biederman75363a42014-03-14 18:11:22 -07002263 if (quota <= 0)
2264 return spent;
2265
Ben Hutchings8127d662013-08-29 19:19:29 +01002266 read_ptr = channel->eventq_read_ptr;
2267
2268 for (;;) {
2269 p_event = efx_event(channel, read_ptr);
2270 event = *p_event;
2271
2272 if (!efx_event_present(&event))
2273 break;
2274
2275 EFX_SET_QWORD(*p_event);
2276
2277 ++read_ptr;
2278
2279 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2280
2281 netif_vdbg(efx, drv, efx->net_dev,
2282 "processing event on %d " EFX_QWORD_FMT "\n",
2283 channel->channel, EFX_QWORD_VAL(event));
2284
2285 switch (ev_code) {
2286 case ESE_DZ_EV_CODE_MCDI_EV:
2287 efx_mcdi_process_event(channel, &event);
2288 break;
2289 case ESE_DZ_EV_CODE_RX_EV:
2290 spent += efx_ef10_handle_rx_event(channel, &event);
2291 if (spent >= quota) {
2292 /* XXX can we split a merged event to
2293 * avoid going over-quota?
2294 */
2295 spent = quota;
2296 goto out;
2297 }
2298 break;
2299 case ESE_DZ_EV_CODE_TX_EV:
2300 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2301 if (tx_descs > efx->txq_entries) {
2302 spent = quota;
2303 goto out;
2304 } else if (++spent == quota) {
2305 goto out;
2306 }
2307 break;
2308 case ESE_DZ_EV_CODE_DRIVER_EV:
2309 efx_ef10_handle_driver_event(channel, &event);
2310 if (++spent == quota)
2311 goto out;
2312 break;
2313 case EFX_EF10_DRVGEN_EV:
2314 efx_ef10_handle_driver_generated_event(channel, &event);
2315 break;
2316 default:
2317 netif_err(efx, hw, efx->net_dev,
2318 "channel %d unknown event type %d"
2319 " (data " EFX_QWORD_FMT ")\n",
2320 channel->channel, ev_code,
2321 EFX_QWORD_VAL(event));
2322 }
2323 }
2324
2325out:
2326 channel->eventq_read_ptr = read_ptr;
2327 return spent;
2328}
2329
2330static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2331{
2332 struct efx_nic *efx = channel->efx;
2333 efx_dword_t rptr;
2334
2335 if (EFX_EF10_WORKAROUND_35388(efx)) {
2336 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2337 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2338 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2339 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2340
2341 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2342 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2343 ERF_DD_EVQ_IND_RPTR,
2344 (channel->eventq_read_ptr &
2345 channel->eventq_mask) >>
2346 ERF_DD_EVQ_IND_RPTR_WIDTH);
2347 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2348 channel->channel);
2349 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2350 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2351 ERF_DD_EVQ_IND_RPTR,
2352 channel->eventq_read_ptr &
2353 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2354 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2355 channel->channel);
2356 } else {
2357 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2358 channel->eventq_read_ptr &
2359 channel->eventq_mask);
2360 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2361 }
2362}
2363
2364static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2365{
2366 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2367 struct efx_nic *efx = channel->efx;
2368 efx_qword_t event;
2369 int rc;
2370
2371 EFX_POPULATE_QWORD_2(event,
2372 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2373 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2374
2375 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2376
2377 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2378 * already swapped the data to little-endian order.
2379 */
2380 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2381 sizeof(efx_qword_t));
2382
2383 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2384 NULL, 0, NULL);
2385 if (rc != 0)
2386 goto fail;
2387
2388 return;
2389
2390fail:
2391 WARN_ON(true);
2392 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2393}
2394
2395void efx_ef10_handle_drain_event(struct efx_nic *efx)
2396{
2397 if (atomic_dec_and_test(&efx->active_queues))
2398 wake_up(&efx->flush_wq);
2399
2400 WARN_ON(atomic_read(&efx->active_queues) < 0);
2401}
2402
2403static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2404{
2405 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2406 struct efx_channel *channel;
2407 struct efx_tx_queue *tx_queue;
2408 struct efx_rx_queue *rx_queue;
2409 int pending;
2410
2411 /* If the MC has just rebooted, the TX/RX queues will have already been
2412 * torn down, but efx->active_queues needs to be set to zero.
2413 */
2414 if (nic_data->must_realloc_vis) {
2415 atomic_set(&efx->active_queues, 0);
2416 return 0;
2417 }
2418
2419 /* Do not attempt to write to the NIC during EEH recovery */
2420 if (efx->state != STATE_RECOVERY) {
2421 efx_for_each_channel(channel, efx) {
2422 efx_for_each_channel_rx_queue(rx_queue, channel)
2423 efx_ef10_rx_fini(rx_queue);
2424 efx_for_each_channel_tx_queue(tx_queue, channel)
2425 efx_ef10_tx_fini(tx_queue);
2426 }
2427
2428 wait_event_timeout(efx->flush_wq,
2429 atomic_read(&efx->active_queues) == 0,
2430 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2431 pending = atomic_read(&efx->active_queues);
2432 if (pending) {
2433 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2434 pending);
2435 return -ETIMEDOUT;
2436 }
2437 }
2438
2439 return 0;
2440}
2441
Edward Creee2835462014-04-16 19:27:48 +01002442static void efx_ef10_prepare_flr(struct efx_nic *efx)
2443{
2444 atomic_set(&efx->active_queues, 0);
2445}
2446
Ben Hutchings8127d662013-08-29 19:19:29 +01002447static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2448 const struct efx_filter_spec *right)
2449{
2450 if ((left->match_flags ^ right->match_flags) |
2451 ((left->flags ^ right->flags) &
2452 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2453 return false;
2454
2455 return memcmp(&left->outer_vid, &right->outer_vid,
2456 sizeof(struct efx_filter_spec) -
2457 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2458}
2459
2460static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2461{
2462 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2463 return jhash2((const u32 *)&spec->outer_vid,
2464 (sizeof(struct efx_filter_spec) -
2465 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2466 0);
2467 /* XXX should we randomise the initval? */
2468}
2469
2470/* Decide whether a filter should be exclusive or else should allow
2471 * delivery to additional recipients. Currently we decide that
2472 * filters for specific local unicast MAC and IP addresses are
2473 * exclusive.
2474 */
2475static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2476{
2477 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2478 !is_multicast_ether_addr(spec->loc_mac))
2479 return true;
2480
2481 if ((spec->match_flags &
2482 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2483 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2484 if (spec->ether_type == htons(ETH_P_IP) &&
2485 !ipv4_is_multicast(spec->loc_host[0]))
2486 return true;
2487 if (spec->ether_type == htons(ETH_P_IPV6) &&
2488 ((const u8 *)spec->loc_host)[0] != 0xff)
2489 return true;
2490 }
2491
2492 return false;
2493}
2494
2495static struct efx_filter_spec *
2496efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2497 unsigned int filter_idx)
2498{
2499 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2500 ~EFX_EF10_FILTER_FLAGS);
2501}
2502
2503static unsigned int
2504efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2505 unsigned int filter_idx)
2506{
2507 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2508}
2509
2510static void
2511efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2512 unsigned int filter_idx,
2513 const struct efx_filter_spec *spec,
2514 unsigned int flags)
2515{
2516 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2517}
2518
2519static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2520 const struct efx_filter_spec *spec,
2521 efx_dword_t *inbuf, u64 handle,
2522 bool replacing)
2523{
2524 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2525
2526 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2527
2528 if (replacing) {
2529 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2530 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2531 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2532 } else {
2533 u32 match_fields = 0;
2534
2535 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2536 efx_ef10_filter_is_exclusive(spec) ?
2537 MC_CMD_FILTER_OP_IN_OP_INSERT :
2538 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2539
2540 /* Convert match flags and values. Unlike almost
2541 * everything else in MCDI, these fields are in
2542 * network byte order.
2543 */
2544 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2545 match_fields |=
2546 is_multicast_ether_addr(spec->loc_mac) ?
2547 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2548 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2549#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2550 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2551 match_fields |= \
2552 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2553 mcdi_field ## _LBN; \
2554 BUILD_BUG_ON( \
2555 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2556 sizeof(spec->gen_field)); \
2557 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2558 &spec->gen_field, sizeof(spec->gen_field)); \
2559 }
2560 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2561 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2562 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2563 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2564 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2565 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2566 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2567 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2568 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2569 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2570#undef COPY_FIELD
2571 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2572 match_fields);
2573 }
2574
Daniel Pieczko45b24492015-05-06 00:57:14 +01002575 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002576 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2577 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2578 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2579 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002580 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002581 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2582 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002583 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2584 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2585 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002586 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2587 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2588 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2589 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2590 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2591 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2592 spec->rss_context !=
2593 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2594 spec->rss_context : nic_data->rx_rss_context);
2595}
2596
2597static int efx_ef10_filter_push(struct efx_nic *efx,
2598 const struct efx_filter_spec *spec,
2599 u64 *handle, bool replacing)
2600{
2601 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2602 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2603 int rc;
2604
2605 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2606 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2607 outbuf, sizeof(outbuf), NULL);
2608 if (rc == 0)
2609 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002610 if (rc == -ENOSPC)
2611 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002612 return rc;
2613}
2614
2615static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2616 enum efx_filter_match_flags match_flags)
2617{
2618 unsigned int match_pri;
2619
2620 for (match_pri = 0;
2621 match_pri < table->rx_match_count;
2622 match_pri++)
2623 if (table->rx_match_flags[match_pri] == match_flags)
2624 return match_pri;
2625
2626 return -EPROTONOSUPPORT;
2627}
2628
2629static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2630 struct efx_filter_spec *spec,
2631 bool replace_equal)
2632{
2633 struct efx_ef10_filter_table *table = efx->filter_state;
2634 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2635 struct efx_filter_spec *saved_spec;
2636 unsigned int match_pri, hash;
2637 unsigned int priv_flags;
2638 bool replacing = false;
2639 int ins_index = -1;
2640 DEFINE_WAIT(wait);
2641 bool is_mc_recip;
2642 s32 rc;
2643
2644 /* For now, only support RX filters */
2645 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2646 EFX_FILTER_FLAG_RX)
2647 return -EINVAL;
2648
2649 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2650 if (rc < 0)
2651 return rc;
2652 match_pri = rc;
2653
2654 hash = efx_ef10_filter_hash(spec);
2655 is_mc_recip = efx_filter_is_mc_recipient(spec);
2656 if (is_mc_recip)
2657 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2658
2659 /* Find any existing filters with the same match tuple or
2660 * else a free slot to insert at. If any of them are busy,
2661 * we have to wait and retry.
2662 */
2663 for (;;) {
2664 unsigned int depth = 1;
2665 unsigned int i;
2666
2667 spin_lock_bh(&efx->filter_lock);
2668
2669 for (;;) {
2670 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2671 saved_spec = efx_ef10_filter_entry_spec(table, i);
2672
2673 if (!saved_spec) {
2674 if (ins_index < 0)
2675 ins_index = i;
2676 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2677 if (table->entry[i].spec &
2678 EFX_EF10_FILTER_FLAG_BUSY)
2679 break;
2680 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002681 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002682 rc = -EPERM;
2683 goto out_unlock;
2684 }
2685 if (!is_mc_recip) {
2686 /* This is the only one */
2687 if (spec->priority ==
2688 saved_spec->priority &&
2689 !replace_equal) {
2690 rc = -EEXIST;
2691 goto out_unlock;
2692 }
2693 ins_index = i;
2694 goto found;
2695 } else if (spec->priority >
2696 saved_spec->priority ||
2697 (spec->priority ==
2698 saved_spec->priority &&
2699 replace_equal)) {
2700 if (ins_index < 0)
2701 ins_index = i;
2702 else
2703 __set_bit(depth, mc_rem_map);
2704 }
2705 }
2706
2707 /* Once we reach the maximum search depth, use
2708 * the first suitable slot or return -EBUSY if
2709 * there was none
2710 */
2711 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2712 if (ins_index < 0) {
2713 rc = -EBUSY;
2714 goto out_unlock;
2715 }
2716 goto found;
2717 }
2718
2719 ++depth;
2720 }
2721
2722 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2723 spin_unlock_bh(&efx->filter_lock);
2724 schedule();
2725 }
2726
2727found:
2728 /* Create a software table entry if necessary, and mark it
2729 * busy. We might yet fail to insert, but any attempt to
2730 * insert a conflicting filter while we're waiting for the
2731 * firmware must find the busy entry.
2732 */
2733 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2734 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002735 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2736 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002737 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002738 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2739 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002740 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002741 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002742 rc = ins_index;
2743 goto out_unlock;
2744 }
2745 replacing = true;
2746 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2747 } else {
2748 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2749 if (!saved_spec) {
2750 rc = -ENOMEM;
2751 goto out_unlock;
2752 }
2753 *saved_spec = *spec;
2754 priv_flags = 0;
2755 }
2756 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2757 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2758
2759 /* Mark lower-priority multicast recipients busy prior to removal */
2760 if (is_mc_recip) {
2761 unsigned int depth, i;
2762
2763 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2764 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2765 if (test_bit(depth, mc_rem_map))
2766 table->entry[i].spec |=
2767 EFX_EF10_FILTER_FLAG_BUSY;
2768 }
2769 }
2770
2771 spin_unlock_bh(&efx->filter_lock);
2772
2773 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2774 replacing);
2775
2776 /* Finalise the software table entry */
2777 spin_lock_bh(&efx->filter_lock);
2778 if (rc == 0) {
2779 if (replacing) {
2780 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002781 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2782 saved_spec->flags |=
2783 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002784 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002785 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002786 saved_spec->flags |= spec->flags;
2787 saved_spec->rss_context = spec->rss_context;
2788 saved_spec->dmaq_id = spec->dmaq_id;
2789 }
2790 } else if (!replacing) {
2791 kfree(saved_spec);
2792 saved_spec = NULL;
2793 }
2794 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2795
2796 /* Remove and finalise entries for lower-priority multicast
2797 * recipients
2798 */
2799 if (is_mc_recip) {
2800 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2801 unsigned int depth, i;
2802
2803 memset(inbuf, 0, sizeof(inbuf));
2804
2805 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2806 if (!test_bit(depth, mc_rem_map))
2807 continue;
2808
2809 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2810 saved_spec = efx_ef10_filter_entry_spec(table, i);
2811 priv_flags = efx_ef10_filter_entry_flags(table, i);
2812
2813 if (rc == 0) {
2814 spin_unlock_bh(&efx->filter_lock);
2815 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2816 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2817 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2818 table->entry[i].handle);
2819 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2820 inbuf, sizeof(inbuf),
2821 NULL, 0, NULL);
2822 spin_lock_bh(&efx->filter_lock);
2823 }
2824
2825 if (rc == 0) {
2826 kfree(saved_spec);
2827 saved_spec = NULL;
2828 priv_flags = 0;
2829 } else {
2830 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
2831 }
2832 efx_ef10_filter_set_entry(table, i, saved_spec,
2833 priv_flags);
2834 }
2835 }
2836
2837 /* If successful, return the inserted filter ID */
2838 if (rc == 0)
2839 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
2840
2841 wake_up_all(&table->waitq);
2842out_unlock:
2843 spin_unlock_bh(&efx->filter_lock);
2844 finish_wait(&table->waitq, &wait);
2845 return rc;
2846}
2847
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08002848static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002849{
2850 /* no need to do anything here on EF10 */
2851}
2852
2853/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002854 * If !by_index, remove by ID
2855 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01002856 * Filter ID may come from userland and must be range-checked.
2857 */
2858static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002859 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002860 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01002861{
2862 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2863 struct efx_ef10_filter_table *table = efx->filter_state;
2864 MCDI_DECLARE_BUF(inbuf,
2865 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2866 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2867 struct efx_filter_spec *spec;
2868 DEFINE_WAIT(wait);
2869 int rc;
2870
2871 /* Find the software table entry and mark it busy. Don't
2872 * remove it yet; any attempt to update while we're waiting
2873 * for the firmware must find the busy entry.
2874 */
2875 for (;;) {
2876 spin_lock_bh(&efx->filter_lock);
2877 if (!(table->entry[filter_idx].spec &
2878 EFX_EF10_FILTER_FLAG_BUSY))
2879 break;
2880 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2881 spin_unlock_bh(&efx->filter_lock);
2882 schedule();
2883 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002884
Ben Hutchings8127d662013-08-29 19:19:29 +01002885 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002886 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002887 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01002888 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
2889 filter_id / HUNT_FILTER_TBL_ROWS)) {
2890 rc = -ENOENT;
2891 goto out_unlock;
2892 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002893
2894 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002895 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002896 /* Just remove flags */
2897 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002898 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002899 rc = 0;
2900 goto out_unlock;
2901 }
2902
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002903 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002904 rc = -ENOENT;
2905 goto out_unlock;
2906 }
2907
Ben Hutchings8127d662013-08-29 19:19:29 +01002908 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2909 spin_unlock_bh(&efx->filter_lock);
2910
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002911 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002912 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01002913
2914 struct efx_filter_spec new_spec = *spec;
2915
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002916 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002917 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002918 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01002919 new_spec.dmaq_id = 0;
2920 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
2921 rc = efx_ef10_filter_push(efx, &new_spec,
2922 &table->entry[filter_idx].handle,
2923 true);
2924
2925 spin_lock_bh(&efx->filter_lock);
2926 if (rc == 0)
2927 *spec = new_spec;
2928 } else {
2929 /* Really remove the filter */
2930
2931 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2932 efx_ef10_filter_is_exclusive(spec) ?
2933 MC_CMD_FILTER_OP_IN_OP_REMOVE :
2934 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2935 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2936 table->entry[filter_idx].handle);
2937 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2938 inbuf, sizeof(inbuf), NULL, 0, NULL);
2939
2940 spin_lock_bh(&efx->filter_lock);
2941 if (rc == 0) {
2942 kfree(spec);
2943 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2944 }
2945 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002946
Ben Hutchings8127d662013-08-29 19:19:29 +01002947 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2948 wake_up_all(&table->waitq);
2949out_unlock:
2950 spin_unlock_bh(&efx->filter_lock);
2951 finish_wait(&table->waitq, &wait);
2952 return rc;
2953}
2954
2955static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
2956 enum efx_filter_priority priority,
2957 u32 filter_id)
2958{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002959 return efx_ef10_filter_remove_internal(efx, 1U << priority,
2960 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01002961}
2962
2963static int efx_ef10_filter_get_safe(struct efx_nic *efx,
2964 enum efx_filter_priority priority,
2965 u32 filter_id, struct efx_filter_spec *spec)
2966{
2967 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2968 struct efx_ef10_filter_table *table = efx->filter_state;
2969 const struct efx_filter_spec *saved_spec;
2970 int rc;
2971
2972 spin_lock_bh(&efx->filter_lock);
2973 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
2974 if (saved_spec && saved_spec->priority == priority &&
2975 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
2976 filter_id / HUNT_FILTER_TBL_ROWS) {
2977 *spec = *saved_spec;
2978 rc = 0;
2979 } else {
2980 rc = -ENOENT;
2981 }
2982 spin_unlock_bh(&efx->filter_lock);
2983 return rc;
2984}
2985
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002986static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01002987 enum efx_filter_priority priority)
2988{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002989 unsigned int priority_mask;
2990 unsigned int i;
2991 int rc;
2992
2993 priority_mask = (((1U << (priority + 1)) - 1) &
2994 ~(1U << EFX_FILTER_PRI_AUTO));
2995
2996 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
2997 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
2998 i, true);
2999 if (rc && rc != -ENOENT)
3000 return rc;
3001 }
3002
3003 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003004}
3005
3006static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3007 enum efx_filter_priority priority)
3008{
3009 struct efx_ef10_filter_table *table = efx->filter_state;
3010 unsigned int filter_idx;
3011 s32 count = 0;
3012
3013 spin_lock_bh(&efx->filter_lock);
3014 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3015 if (table->entry[filter_idx].spec &&
3016 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3017 priority)
3018 ++count;
3019 }
3020 spin_unlock_bh(&efx->filter_lock);
3021 return count;
3022}
3023
3024static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3025{
3026 struct efx_ef10_filter_table *table = efx->filter_state;
3027
3028 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3029}
3030
3031static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3032 enum efx_filter_priority priority,
3033 u32 *buf, u32 size)
3034{
3035 struct efx_ef10_filter_table *table = efx->filter_state;
3036 struct efx_filter_spec *spec;
3037 unsigned int filter_idx;
3038 s32 count = 0;
3039
3040 spin_lock_bh(&efx->filter_lock);
3041 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3042 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3043 if (spec && spec->priority == priority) {
3044 if (count == size) {
3045 count = -EMSGSIZE;
3046 break;
3047 }
3048 buf[count++] = (efx_ef10_filter_rx_match_pri(
3049 table, spec->match_flags) *
3050 HUNT_FILTER_TBL_ROWS +
3051 filter_idx);
3052 }
3053 }
3054 spin_unlock_bh(&efx->filter_lock);
3055 return count;
3056}
3057
3058#ifdef CONFIG_RFS_ACCEL
3059
3060static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3061
3062static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3063 struct efx_filter_spec *spec)
3064{
3065 struct efx_ef10_filter_table *table = efx->filter_state;
3066 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3067 struct efx_filter_spec *saved_spec;
3068 unsigned int hash, i, depth = 1;
3069 bool replacing = false;
3070 int ins_index = -1;
3071 u64 cookie;
3072 s32 rc;
3073
3074 /* Must be an RX filter without RSS and not for a multicast
3075 * destination address (RFS only works for connected sockets).
3076 * These restrictions allow us to pass only a tiny amount of
3077 * data through to the completion function.
3078 */
3079 EFX_WARN_ON_PARANOID(spec->flags !=
3080 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3081 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3082 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3083
3084 hash = efx_ef10_filter_hash(spec);
3085
3086 spin_lock_bh(&efx->filter_lock);
3087
3088 /* Find any existing filter with the same match tuple or else
3089 * a free slot to insert at. If an existing filter is busy,
3090 * we have to give up.
3091 */
3092 for (;;) {
3093 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3094 saved_spec = efx_ef10_filter_entry_spec(table, i);
3095
3096 if (!saved_spec) {
3097 if (ins_index < 0)
3098 ins_index = i;
3099 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3100 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3101 rc = -EBUSY;
3102 goto fail_unlock;
3103 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003104 if (spec->priority < saved_spec->priority) {
3105 rc = -EPERM;
3106 goto fail_unlock;
3107 }
3108 ins_index = i;
3109 break;
3110 }
3111
3112 /* Once we reach the maximum search depth, use the
3113 * first suitable slot or return -EBUSY if there was
3114 * none
3115 */
3116 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3117 if (ins_index < 0) {
3118 rc = -EBUSY;
3119 goto fail_unlock;
3120 }
3121 break;
3122 }
3123
3124 ++depth;
3125 }
3126
3127 /* Create a software table entry if necessary, and mark it
3128 * busy. We might yet fail to insert, but any attempt to
3129 * insert a conflicting filter while we're waiting for the
3130 * firmware must find the busy entry.
3131 */
3132 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3133 if (saved_spec) {
3134 replacing = true;
3135 } else {
3136 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3137 if (!saved_spec) {
3138 rc = -ENOMEM;
3139 goto fail_unlock;
3140 }
3141 *saved_spec = *spec;
3142 }
3143 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3144 EFX_EF10_FILTER_FLAG_BUSY);
3145
3146 spin_unlock_bh(&efx->filter_lock);
3147
3148 /* Pack up the variables needed on completion */
3149 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3150
3151 efx_ef10_filter_push_prep(efx, spec, inbuf,
3152 table->entry[ins_index].handle, replacing);
3153 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3154 MC_CMD_FILTER_OP_OUT_LEN,
3155 efx_ef10_filter_rfs_insert_complete, cookie);
3156
3157 return ins_index;
3158
3159fail_unlock:
3160 spin_unlock_bh(&efx->filter_lock);
3161 return rc;
3162}
3163
3164static void
3165efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3166 int rc, efx_dword_t *outbuf,
3167 size_t outlen_actual)
3168{
3169 struct efx_ef10_filter_table *table = efx->filter_state;
3170 unsigned int ins_index, dmaq_id;
3171 struct efx_filter_spec *spec;
3172 bool replacing;
3173
3174 /* Unpack the cookie */
3175 replacing = cookie >> 31;
3176 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3177 dmaq_id = cookie & 0xffff;
3178
3179 spin_lock_bh(&efx->filter_lock);
3180 spec = efx_ef10_filter_entry_spec(table, ins_index);
3181 if (rc == 0) {
3182 table->entry[ins_index].handle =
3183 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3184 if (replacing)
3185 spec->dmaq_id = dmaq_id;
3186 } else if (!replacing) {
3187 kfree(spec);
3188 spec = NULL;
3189 }
3190 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3191 spin_unlock_bh(&efx->filter_lock);
3192
3193 wake_up_all(&table->waitq);
3194}
3195
3196static void
3197efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3198 unsigned long filter_idx,
3199 int rc, efx_dword_t *outbuf,
3200 size_t outlen_actual);
3201
3202static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3203 unsigned int filter_idx)
3204{
3205 struct efx_ef10_filter_table *table = efx->filter_state;
3206 struct efx_filter_spec *spec =
3207 efx_ef10_filter_entry_spec(table, filter_idx);
3208 MCDI_DECLARE_BUF(inbuf,
3209 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3210 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3211
3212 if (!spec ||
3213 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3214 spec->priority != EFX_FILTER_PRI_HINT ||
3215 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3216 flow_id, filter_idx))
3217 return false;
3218
3219 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3220 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3221 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3222 table->entry[filter_idx].handle);
3223 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3224 efx_ef10_filter_rfs_expire_complete, filter_idx))
3225 return false;
3226
3227 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3228 return true;
3229}
3230
3231static void
3232efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3233 unsigned long filter_idx,
3234 int rc, efx_dword_t *outbuf,
3235 size_t outlen_actual)
3236{
3237 struct efx_ef10_filter_table *table = efx->filter_state;
3238 struct efx_filter_spec *spec =
3239 efx_ef10_filter_entry_spec(table, filter_idx);
3240
3241 spin_lock_bh(&efx->filter_lock);
3242 if (rc == 0) {
3243 kfree(spec);
3244 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3245 }
3246 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3247 wake_up_all(&table->waitq);
3248 spin_unlock_bh(&efx->filter_lock);
3249}
3250
3251#endif /* CONFIG_RFS_ACCEL */
3252
3253static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3254{
3255 int match_flags = 0;
3256
3257#define MAP_FLAG(gen_flag, mcdi_field) { \
3258 u32 old_mcdi_flags = mcdi_flags; \
3259 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3260 mcdi_field ## _LBN); \
3261 if (mcdi_flags != old_mcdi_flags) \
3262 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3263 }
3264 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3265 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3266 MAP_FLAG(REM_HOST, SRC_IP);
3267 MAP_FLAG(LOC_HOST, DST_IP);
3268 MAP_FLAG(REM_MAC, SRC_MAC);
3269 MAP_FLAG(REM_PORT, SRC_PORT);
3270 MAP_FLAG(LOC_MAC, DST_MAC);
3271 MAP_FLAG(LOC_PORT, DST_PORT);
3272 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3273 MAP_FLAG(INNER_VID, INNER_VLAN);
3274 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3275 MAP_FLAG(IP_PROTO, IP_PROTO);
3276#undef MAP_FLAG
3277
3278 /* Did we map them all? */
3279 if (mcdi_flags)
3280 return -EINVAL;
3281
3282 return match_flags;
3283}
3284
3285static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3286{
3287 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3288 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3289 unsigned int pd_match_pri, pd_match_count;
3290 struct efx_ef10_filter_table *table;
3291 size_t outlen;
3292 int rc;
3293
3294 table = kzalloc(sizeof(*table), GFP_KERNEL);
3295 if (!table)
3296 return -ENOMEM;
3297
3298 /* Find out which RX filter types are supported, and their priorities */
3299 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3300 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3301 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3302 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3303 &outlen);
3304 if (rc)
3305 goto fail;
3306 pd_match_count = MCDI_VAR_ARRAY_LEN(
3307 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3308 table->rx_match_count = 0;
3309
3310 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3311 u32 mcdi_flags =
3312 MCDI_ARRAY_DWORD(
3313 outbuf,
3314 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3315 pd_match_pri);
3316 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3317 if (rc < 0) {
3318 netif_dbg(efx, probe, efx->net_dev,
3319 "%s: fw flags %#x pri %u not supported in driver\n",
3320 __func__, mcdi_flags, pd_match_pri);
3321 } else {
3322 netif_dbg(efx, probe, efx->net_dev,
3323 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3324 __func__, mcdi_flags, pd_match_pri,
3325 rc, table->rx_match_count);
3326 table->rx_match_flags[table->rx_match_count++] = rc;
3327 }
3328 }
3329
3330 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3331 if (!table->entry) {
3332 rc = -ENOMEM;
3333 goto fail;
3334 }
3335
3336 efx->filter_state = table;
3337 init_waitqueue_head(&table->waitq);
3338 return 0;
3339
3340fail:
3341 kfree(table);
3342 return rc;
3343}
3344
Edward Cree0d322412015-05-20 11:10:03 +01003345/* Caller must hold efx->filter_sem for read if race against
3346 * efx_ef10_filter_table_remove() is possible
3347 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003348static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3349{
3350 struct efx_ef10_filter_table *table = efx->filter_state;
3351 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3352 struct efx_filter_spec *spec;
3353 unsigned int filter_idx;
3354 bool failed = false;
3355 int rc;
3356
Edward Cree0d322412015-05-20 11:10:03 +01003357 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3358
Ben Hutchings8127d662013-08-29 19:19:29 +01003359 if (!nic_data->must_restore_filters)
3360 return;
3361
Edward Cree0d322412015-05-20 11:10:03 +01003362 if (!table)
3363 return;
3364
Ben Hutchings8127d662013-08-29 19:19:29 +01003365 spin_lock_bh(&efx->filter_lock);
3366
3367 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3368 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3369 if (!spec)
3370 continue;
3371
3372 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3373 spin_unlock_bh(&efx->filter_lock);
3374
3375 rc = efx_ef10_filter_push(efx, spec,
3376 &table->entry[filter_idx].handle,
3377 false);
3378 if (rc)
3379 failed = true;
3380
3381 spin_lock_bh(&efx->filter_lock);
3382 if (rc) {
3383 kfree(spec);
3384 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3385 } else {
3386 table->entry[filter_idx].spec &=
3387 ~EFX_EF10_FILTER_FLAG_BUSY;
3388 }
3389 }
3390
3391 spin_unlock_bh(&efx->filter_lock);
3392
3393 if (failed)
3394 netif_err(efx, hw, efx->net_dev,
3395 "unable to restore all filters\n");
3396 else
3397 nic_data->must_restore_filters = false;
3398}
3399
Edward Cree0d322412015-05-20 11:10:03 +01003400/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003401static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3402{
3403 struct efx_ef10_filter_table *table = efx->filter_state;
3404 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3405 struct efx_filter_spec *spec;
3406 unsigned int filter_idx;
3407 int rc;
3408
Edward Cree0d322412015-05-20 11:10:03 +01003409 efx->filter_state = NULL;
3410 if (!table)
3411 return;
3412
Ben Hutchings8127d662013-08-29 19:19:29 +01003413 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3414 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3415 if (!spec)
3416 continue;
3417
3418 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3419 efx_ef10_filter_is_exclusive(spec) ?
3420 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3421 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3422 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3423 table->entry[filter_idx].handle);
3424 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3425 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003426 if (rc)
3427 netdev_WARN(efx->net_dev,
3428 "filter_idx=%#x handle=%#llx\n",
3429 filter_idx,
3430 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003431 kfree(spec);
3432 }
3433
3434 vfree(table->entry);
3435 kfree(table);
3436}
3437
Edward Cree0d322412015-05-20 11:10:03 +01003438/* Caller must hold efx->filter_sem for read if race against
3439 * efx_ef10_filter_table_remove() is possible
3440 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003441static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3442{
3443 struct efx_ef10_filter_table *table = efx->filter_state;
3444 struct net_device *net_dev = efx->net_dev;
3445 struct efx_filter_spec spec;
3446 bool remove_failed = false;
3447 struct netdev_hw_addr *uc;
3448 struct netdev_hw_addr *mc;
3449 unsigned int filter_idx;
3450 int i, n, rc;
3451
3452 if (!efx_dev_registered(efx))
3453 return;
3454
Edward Cree0d322412015-05-20 11:10:03 +01003455 if (!table)
3456 return;
3457
Ben Hutchings8127d662013-08-29 19:19:29 +01003458 /* Mark old filters that may need to be removed */
3459 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003460 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003461 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003462 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3463 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003464 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003465 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003466 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003467 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3468 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003469 }
3470 spin_unlock_bh(&efx->filter_lock);
3471
3472 /* Copy/convert the address lists; add the primary station
3473 * address and broadcast address
3474 */
3475 netif_addr_lock_bh(net_dev);
3476 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003477 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3478 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003479 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003480 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003481 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003482 i = 1;
3483 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003484 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003485 i++;
3486 }
3487 }
3488 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003489 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3490 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003491 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003492 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3493 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003494 i = 1;
3495 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003496 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003497 i++;
3498 }
3499 }
3500 netif_addr_unlock_bh(net_dev);
3501
3502 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003503 if (table->dev_uc_count >= 0) {
3504 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003505 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3506 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003507 0);
3508 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003509 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003510 rc = efx_ef10_filter_insert(efx, &spec, true);
3511 if (rc < 0) {
3512 /* Fall back to unicast-promisc */
3513 while (i--)
3514 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003515 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003516 table->dev_uc_list[i].id);
3517 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003518 break;
3519 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003520 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003521 }
3522 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003523 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003524 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3525 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003526 0);
3527 efx_filter_set_uc_def(&spec);
3528 rc = efx_ef10_filter_insert(efx, &spec, true);
3529 if (rc < 0) {
3530 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003531 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003532 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003533 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003534 }
3535 }
3536
3537 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003538 if (table->dev_mc_count >= 0) {
3539 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003540 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3541 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003542 0);
3543 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003544 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003545 rc = efx_ef10_filter_insert(efx, &spec, true);
3546 if (rc < 0) {
3547 /* Fall back to multicast-promisc */
3548 while (i--)
3549 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003550 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003551 table->dev_mc_list[i].id);
3552 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003553 break;
3554 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003555 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003556 }
3557 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003558 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003559 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3560 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003561 0);
3562 efx_filter_set_mc_def(&spec);
3563 rc = efx_ef10_filter_insert(efx, &spec, true);
3564 if (rc < 0) {
3565 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003566 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003567 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003568 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003569 }
3570 }
3571
3572 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003573 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003574 * don't need to hold the filter_lock while scanning for
3575 * these filters.
3576 */
3577 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3578 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003579 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003580 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003581 efx, 1U << EFX_FILTER_PRI_AUTO,
3582 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003583 remove_failed = true;
3584 }
3585 }
3586 WARN_ON(remove_failed);
3587}
3588
3589static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3590{
3591 efx_ef10_filter_sync_rx_mode(efx);
3592
3593 return efx_mcdi_set_mac(efx);
3594}
3595
Shradha Shah862f8942015-05-20 11:08:56 +01003596static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3597{
3598 efx_ef10_filter_sync_rx_mode(efx);
3599
3600 return 0;
3601}
3602
Jon Cooper74cd60a2013-09-16 14:18:51 +01003603static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3604{
3605 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3606
3607 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3608 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3609 NULL, 0, NULL);
3610}
3611
3612/* MC BISTs follow a different poll mechanism to phy BISTs.
3613 * The BIST is done in the poll handler on the MC, and the MCDI command
3614 * will block until the BIST is done.
3615 */
3616static int efx_ef10_poll_bist(struct efx_nic *efx)
3617{
3618 int rc;
3619 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3620 size_t outlen;
3621 u32 result;
3622
3623 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3624 outbuf, sizeof(outbuf), &outlen);
3625 if (rc != 0)
3626 return rc;
3627
3628 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3629 return -EIO;
3630
3631 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3632 switch (result) {
3633 case MC_CMD_POLL_BIST_PASSED:
3634 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3635 return 0;
3636 case MC_CMD_POLL_BIST_TIMEOUT:
3637 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3638 return -EIO;
3639 case MC_CMD_POLL_BIST_FAILED:
3640 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3641 return -EIO;
3642 default:
3643 netif_err(efx, hw, efx->net_dev,
3644 "BIST returned unknown result %u", result);
3645 return -EIO;
3646 }
3647}
3648
3649static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3650{
3651 int rc;
3652
3653 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3654
3655 rc = efx_ef10_start_bist(efx, bist_type);
3656 if (rc != 0)
3657 return rc;
3658
3659 return efx_ef10_poll_bist(efx);
3660}
3661
3662static int
3663efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3664{
3665 int rc, rc2;
3666
3667 efx_reset_down(efx, RESET_TYPE_WORLD);
3668
3669 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3670 NULL, 0, NULL, 0, NULL);
3671 if (rc != 0)
3672 goto out;
3673
3674 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3675 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3676
3677 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3678
3679out:
3680 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3681 return rc ? rc : rc2;
3682}
3683
Ben Hutchings8127d662013-08-29 19:19:29 +01003684#ifdef CONFIG_SFC_MTD
3685
3686struct efx_ef10_nvram_type_info {
3687 u16 type, type_mask;
3688 u8 port;
3689 const char *name;
3690};
3691
3692static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3693 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3694 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3695 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3696 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3697 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3698 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3699 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3700 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3701 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003702 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003703 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3704};
3705
3706static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3707 struct efx_mcdi_mtd_partition *part,
3708 unsigned int type)
3709{
3710 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3711 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3712 const struct efx_ef10_nvram_type_info *info;
3713 size_t size, erase_size, outlen;
3714 bool protected;
3715 int rc;
3716
3717 for (info = efx_ef10_nvram_types; ; info++) {
3718 if (info ==
3719 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3720 return -ENODEV;
3721 if ((type & ~info->type_mask) == info->type)
3722 break;
3723 }
3724 if (info->port != efx_port_num(efx))
3725 return -ENODEV;
3726
3727 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3728 if (rc)
3729 return rc;
3730 if (protected)
3731 return -ENODEV; /* hide it */
3732
3733 part->nvram_type = type;
3734
3735 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3736 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3737 outbuf, sizeof(outbuf), &outlen);
3738 if (rc)
3739 return rc;
3740 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3741 return -EIO;
3742 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3743 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3744 part->fw_subtype = MCDI_DWORD(outbuf,
3745 NVRAM_METADATA_OUT_SUBTYPE);
3746
3747 part->common.dev_type_name = "EF10 NVRAM manager";
3748 part->common.type_name = info->name;
3749
3750 part->common.mtd.type = MTD_NORFLASH;
3751 part->common.mtd.flags = MTD_CAP_NORFLASH;
3752 part->common.mtd.size = size;
3753 part->common.mtd.erasesize = erase_size;
3754
3755 return 0;
3756}
3757
3758static int efx_ef10_mtd_probe(struct efx_nic *efx)
3759{
3760 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
3761 struct efx_mcdi_mtd_partition *parts;
3762 size_t outlen, n_parts_total, i, n_parts;
3763 unsigned int type;
3764 int rc;
3765
3766 ASSERT_RTNL();
3767
3768 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
3769 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
3770 outbuf, sizeof(outbuf), &outlen);
3771 if (rc)
3772 return rc;
3773 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
3774 return -EIO;
3775
3776 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
3777 if (n_parts_total >
3778 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
3779 return -EIO;
3780
3781 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
3782 if (!parts)
3783 return -ENOMEM;
3784
3785 n_parts = 0;
3786 for (i = 0; i < n_parts_total; i++) {
3787 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
3788 i);
3789 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
3790 if (rc == 0)
3791 n_parts++;
3792 else if (rc != -ENODEV)
3793 goto fail;
3794 }
3795
3796 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
3797fail:
3798 if (rc)
3799 kfree(parts);
3800 return rc;
3801}
3802
3803#endif /* CONFIG_SFC_MTD */
3804
3805static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
3806{
3807 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
3808}
3809
Shradha Shah02246a72015-05-06 00:58:14 +01003810static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
3811 u32 host_time) {}
3812
Jon Cooperbd9a2652013-11-18 12:54:41 +00003813static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
3814 bool temp)
3815{
3816 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
3817 int rc;
3818
3819 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
3820 channel->sync_events_state == SYNC_EVENTS_VALID ||
3821 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
3822 return 0;
3823 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
3824
3825 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
3826 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3827 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
3828 channel->channel);
3829
3830 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3831 inbuf, sizeof(inbuf), NULL, 0, NULL);
3832
3833 if (rc != 0)
3834 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3835 SYNC_EVENTS_DISABLED;
3836
3837 return rc;
3838}
3839
3840static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
3841 bool temp)
3842{
3843 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
3844 int rc;
3845
3846 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
3847 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
3848 return 0;
3849 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
3850 channel->sync_events_state = SYNC_EVENTS_DISABLED;
3851 return 0;
3852 }
3853 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3854 SYNC_EVENTS_DISABLED;
3855
3856 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
3857 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3858 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
3859 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
3860 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
3861 channel->channel);
3862
3863 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3864 inbuf, sizeof(inbuf), NULL, 0, NULL);
3865
3866 return rc;
3867}
3868
3869static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
3870 bool temp)
3871{
3872 int (*set)(struct efx_channel *channel, bool temp);
3873 struct efx_channel *channel;
3874
3875 set = en ?
3876 efx_ef10_rx_enable_timestamping :
3877 efx_ef10_rx_disable_timestamping;
3878
3879 efx_for_each_channel(channel, efx) {
3880 int rc = set(channel, temp);
3881 if (en && rc != 0) {
3882 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
3883 return rc;
3884 }
3885 }
3886
3887 return 0;
3888}
3889
Shradha Shah02246a72015-05-06 00:58:14 +01003890static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
3891 struct hwtstamp_config *init)
3892{
3893 return -EOPNOTSUPP;
3894}
3895
Jon Cooperbd9a2652013-11-18 12:54:41 +00003896static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
3897 struct hwtstamp_config *init)
3898{
3899 int rc;
3900
3901 switch (init->rx_filter) {
3902 case HWTSTAMP_FILTER_NONE:
3903 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
3904 /* if TX timestamping is still requested then leave PTP on */
3905 return efx_ptp_change_mode(efx,
3906 init->tx_type != HWTSTAMP_TX_OFF, 0);
3907 case HWTSTAMP_FILTER_ALL:
3908 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3909 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3910 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3911 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3912 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3913 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3914 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3915 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3916 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3917 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3918 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3919 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3920 init->rx_filter = HWTSTAMP_FILTER_ALL;
3921 rc = efx_ptp_change_mode(efx, true, 0);
3922 if (!rc)
3923 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
3924 if (rc)
3925 efx_ptp_change_mode(efx, false, 0);
3926 return rc;
3927 default:
3928 return -ERANGE;
3929 }
3930}
3931
Shradha Shah02246a72015-05-06 00:58:14 +01003932const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01003933 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01003934 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01003935 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01003936 .probe = efx_ef10_probe_vf,
3937 .remove = efx_ef10_remove,
3938 .dimension_resources = efx_ef10_dimension_resources,
3939 .init = efx_ef10_init_nic,
3940 .fini = efx_port_dummy_op_void,
3941 .map_reset_reason = efx_mcdi_map_reset_reason,
3942 .map_reset_flags = efx_ef10_map_reset_flags,
3943 .reset = efx_ef10_reset,
3944 .probe_port = efx_mcdi_port_probe,
3945 .remove_port = efx_mcdi_port_remove,
3946 .fini_dmaq = efx_ef10_fini_dmaq,
3947 .prepare_flr = efx_ef10_prepare_flr,
3948 .finish_flr = efx_port_dummy_op_void,
3949 .describe_stats = efx_ef10_describe_stats,
3950 .update_stats = efx_ef10_update_stats,
3951 .start_stats = efx_port_dummy_op_void,
3952 .pull_stats = efx_port_dummy_op_void,
3953 .stop_stats = efx_port_dummy_op_void,
3954 .set_id_led = efx_mcdi_set_id_led,
3955 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01003956 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01003957 .check_mac_fault = efx_mcdi_mac_check_fault,
3958 .reconfigure_port = efx_mcdi_port_reconfigure,
3959 .get_wol = efx_ef10_get_wol_vf,
3960 .set_wol = efx_ef10_set_wol_vf,
3961 .resume_wol = efx_port_dummy_op_void,
3962 .mcdi_request = efx_ef10_mcdi_request,
3963 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
3964 .mcdi_read_response = efx_ef10_mcdi_read_response,
3965 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
3966 .irq_enable_master = efx_port_dummy_op_void,
3967 .irq_test_generate = efx_ef10_irq_test_generate,
3968 .irq_disable_non_ev = efx_port_dummy_op_void,
3969 .irq_handle_msi = efx_ef10_msi_interrupt,
3970 .irq_handle_legacy = efx_ef10_legacy_interrupt,
3971 .tx_probe = efx_ef10_tx_probe,
3972 .tx_init = efx_ef10_tx_init,
3973 .tx_remove = efx_ef10_tx_remove,
3974 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01003975 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01003976 .rx_probe = efx_ef10_rx_probe,
3977 .rx_init = efx_ef10_rx_init,
3978 .rx_remove = efx_ef10_rx_remove,
3979 .rx_write = efx_ef10_rx_write,
3980 .rx_defer_refill = efx_ef10_rx_defer_refill,
3981 .ev_probe = efx_ef10_ev_probe,
3982 .ev_init = efx_ef10_ev_init,
3983 .ev_fini = efx_ef10_ev_fini,
3984 .ev_remove = efx_ef10_ev_remove,
3985 .ev_process = efx_ef10_ev_process,
3986 .ev_read_ack = efx_ef10_ev_read_ack,
3987 .ev_test_generate = efx_ef10_ev_test_generate,
3988 .filter_table_probe = efx_ef10_filter_table_probe,
3989 .filter_table_restore = efx_ef10_filter_table_restore,
3990 .filter_table_remove = efx_ef10_filter_table_remove,
3991 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
3992 .filter_insert = efx_ef10_filter_insert,
3993 .filter_remove_safe = efx_ef10_filter_remove_safe,
3994 .filter_get_safe = efx_ef10_filter_get_safe,
3995 .filter_clear_rx = efx_ef10_filter_clear_rx,
3996 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
3997 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
3998 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
3999#ifdef CONFIG_RFS_ACCEL
4000 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4001 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4002#endif
4003#ifdef CONFIG_SFC_MTD
4004 .mtd_probe = efx_port_dummy_op_int,
4005#endif
4006 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4007 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4008#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004009 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4010 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4011 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004012#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004013 .get_mac_address = efx_ef10_get_mac_address_vf,
4014
Shradha Shah02246a72015-05-06 00:58:14 +01004015 .revision = EFX_REV_HUNT_A0,
4016 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4017 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4018 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4019 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4020 .can_rx_scatter = true,
4021 .always_rx_scatter = true,
4022 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4023 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4024 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4025 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4026 .mcdi_max_ver = 2,
4027 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4028 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4029 1 << HWTSTAMP_FILTER_ALL,
4030};
4031
4032const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004033 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004034 .mem_bar = EFX_MEM_BAR,
4035 .mem_map_size = efx_ef10_mem_map_size,
4036 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004037 .remove = efx_ef10_remove,
4038 .dimension_resources = efx_ef10_dimension_resources,
4039 .init = efx_ef10_init_nic,
4040 .fini = efx_port_dummy_op_void,
4041 .map_reset_reason = efx_mcdi_map_reset_reason,
4042 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004043 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004044 .probe_port = efx_mcdi_port_probe,
4045 .remove_port = efx_mcdi_port_remove,
4046 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004047 .prepare_flr = efx_ef10_prepare_flr,
4048 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004049 .describe_stats = efx_ef10_describe_stats,
4050 .update_stats = efx_ef10_update_stats,
4051 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004052 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004053 .stop_stats = efx_mcdi_mac_stop_stats,
4054 .set_id_led = efx_mcdi_set_id_led,
4055 .push_irq_moderation = efx_ef10_push_irq_moderation,
4056 .reconfigure_mac = efx_ef10_mac_reconfigure,
4057 .check_mac_fault = efx_mcdi_mac_check_fault,
4058 .reconfigure_port = efx_mcdi_port_reconfigure,
4059 .get_wol = efx_ef10_get_wol,
4060 .set_wol = efx_ef10_set_wol,
4061 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004062 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004063 .test_nvram = efx_mcdi_nvram_test_all,
4064 .mcdi_request = efx_ef10_mcdi_request,
4065 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4066 .mcdi_read_response = efx_ef10_mcdi_read_response,
4067 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4068 .irq_enable_master = efx_port_dummy_op_void,
4069 .irq_test_generate = efx_ef10_irq_test_generate,
4070 .irq_disable_non_ev = efx_port_dummy_op_void,
4071 .irq_handle_msi = efx_ef10_msi_interrupt,
4072 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4073 .tx_probe = efx_ef10_tx_probe,
4074 .tx_init = efx_ef10_tx_init,
4075 .tx_remove = efx_ef10_tx_remove,
4076 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004077 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004078 .rx_probe = efx_ef10_rx_probe,
4079 .rx_init = efx_ef10_rx_init,
4080 .rx_remove = efx_ef10_rx_remove,
4081 .rx_write = efx_ef10_rx_write,
4082 .rx_defer_refill = efx_ef10_rx_defer_refill,
4083 .ev_probe = efx_ef10_ev_probe,
4084 .ev_init = efx_ef10_ev_init,
4085 .ev_fini = efx_ef10_ev_fini,
4086 .ev_remove = efx_ef10_ev_remove,
4087 .ev_process = efx_ef10_ev_process,
4088 .ev_read_ack = efx_ef10_ev_read_ack,
4089 .ev_test_generate = efx_ef10_ev_test_generate,
4090 .filter_table_probe = efx_ef10_filter_table_probe,
4091 .filter_table_restore = efx_ef10_filter_table_restore,
4092 .filter_table_remove = efx_ef10_filter_table_remove,
4093 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4094 .filter_insert = efx_ef10_filter_insert,
4095 .filter_remove_safe = efx_ef10_filter_remove_safe,
4096 .filter_get_safe = efx_ef10_filter_get_safe,
4097 .filter_clear_rx = efx_ef10_filter_clear_rx,
4098 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4099 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4100 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4101#ifdef CONFIG_RFS_ACCEL
4102 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4103 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4104#endif
4105#ifdef CONFIG_SFC_MTD
4106 .mtd_probe = efx_ef10_mtd_probe,
4107 .mtd_rename = efx_mcdi_mtd_rename,
4108 .mtd_read = efx_mcdi_mtd_read,
4109 .mtd_erase = efx_mcdi_mtd_erase,
4110 .mtd_write = efx_mcdi_mtd_write,
4111 .mtd_sync = efx_mcdi_mtd_sync,
4112#endif
4113 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004114 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4115 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004116#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004117 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004118 .sriov_init = efx_ef10_sriov_init,
4119 .sriov_fini = efx_ef10_sriov_fini,
4120 .sriov_mac_address_changed = efx_ef10_sriov_mac_address_changed,
4121 .sriov_wanted = efx_ef10_sriov_wanted,
4122 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004123 .sriov_flr = efx_ef10_sriov_flr,
4124 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4125 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4126 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4127 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004128 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4129 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4130 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004131#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004132 .get_mac_address = efx_ef10_get_mac_address_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004133
4134 .revision = EFX_REV_HUNT_A0,
4135 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4136 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4137 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004138 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004139 .can_rx_scatter = true,
4140 .always_rx_scatter = true,
4141 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4142 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4143 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4144 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4145 .mcdi_max_ver = 2,
4146 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004147 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4148 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004149};