1 /****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2012-2013 Solarflare Communications Inc.
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.
10 #include "net_driver.h"
11 #include "ef10_regs.h"
14 #include "mcdi_pcol.h"
16 #include "workarounds.h"
18 #include "ef10_sriov.h"
20 #include <linux/jhash.h>
21 #include <linux/wait.h>
22 #include <linux/workqueue.h>
24 /* Hardware control for EF10 architecture including 'Huntington'. */
26 #define EFX_EF10_DRVGEN_EV 7
32 /* The reserved RSS context value */
33 #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
34 /* 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
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
47 * Huntington has a single 8K filter table shared between all filter
48 * types and both ports.
50 #define HUNT_FILTER_TBL_ROWS 8192
52 #define EFX_EF10_FILTER_ID_INVALID 0xffff
54 #define EFX_EF10_FILTER_DEV_UC_MAX 32
55 #define EFX_EF10_FILTER_DEV_MC_MAX 256
58 struct efx_ef10_vlan {
59 struct list_head list;
63 enum efx_ef10_default_filters {
67 EFX_EF10_VXLAN4_UCDEF,
68 EFX_EF10_VXLAN4_MCDEF,
69 EFX_EF10_VXLAN6_UCDEF,
70 EFX_EF10_VXLAN6_MCDEF,
71 EFX_EF10_NVGRE4_UCDEF,
72 EFX_EF10_NVGRE4_MCDEF,
73 EFX_EF10_NVGRE6_UCDEF,
74 EFX_EF10_NVGRE6_MCDEF,
75 EFX_EF10_GENEVE4_UCDEF,
76 EFX_EF10_GENEVE4_MCDEF,
77 EFX_EF10_GENEVE6_UCDEF,
78 EFX_EF10_GENEVE6_MCDEF,
80 EFX_EF10_NUM_DEFAULT_FILTERS
83 /* Per-VLAN filters information */
84 struct efx_ef10_filter_vlan {
85 struct list_head list;
87 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
88 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
89 u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS];
92 struct efx_ef10_dev_addr {
96 struct efx_ef10_filter_table {
97 /* The MCDI match masks supported by this fw & hw, in order of priority */
98 u32 rx_match_mcdi_flags[
99 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
100 unsigned int rx_match_count;
103 unsigned long spec; /* pointer to spec plus flag bits */
104 /* BUSY flag indicates that an update is in progress. AUTO_OLD is
105 * used to mark and sweep MAC filters for the device address lists.
107 #define EFX_EF10_FILTER_FLAG_BUSY 1UL
108 #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
109 #define EFX_EF10_FILTER_FLAGS 3UL
110 u64 handle; /* firmware handle */
112 wait_queue_head_t waitq;
113 /* Shadow of net_device address lists, guarded by mac_lock */
114 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
115 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
120 /* Whether in multicast promiscuous mode when last changed */
121 bool mc_promisc_last;
122 bool mc_overflow; /* Too many MC addrs; should always imply mc_promisc */
124 struct list_head vlan_list;
127 /* An arbitrary search limit for the software hash table */
128 #define EFX_EF10_FILTER_SEARCH_LIMIT 200
130 static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
131 static void efx_ef10_filter_table_remove(struct efx_nic *efx);
132 static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
133 static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
134 struct efx_ef10_filter_vlan *vlan);
135 static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
136 static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading);
138 static u32 efx_ef10_filter_get_unsafe_id(u32 filter_id)
140 WARN_ON_ONCE(filter_id == EFX_EF10_FILTER_ID_INVALID);
141 return filter_id & (HUNT_FILTER_TBL_ROWS - 1);
144 static unsigned int efx_ef10_filter_get_unsafe_pri(u32 filter_id)
146 return filter_id / (HUNT_FILTER_TBL_ROWS * 2);
149 static u32 efx_ef10_make_filter_id(unsigned int pri, u16 idx)
151 return pri * HUNT_FILTER_TBL_ROWS * 2 + idx;
154 static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
158 efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS);
159 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
160 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
163 /* On all EF10s up to and including SFC9220 (Medford1), all PFs use BAR 0 for
164 * I/O space and BAR 2(&3) for memory. On SFC9250 (Medford2), there is no I/O
165 * bar; PFs use BAR 0/1 for memory.
167 static unsigned int efx_ef10_pf_mem_bar(struct efx_nic *efx)
169 switch (efx->pci_dev->device) {
170 case 0x0b03: /* SFC9250 PF */
177 /* All VFs use BAR 0/1 for memory */
178 static unsigned int efx_ef10_vf_mem_bar(struct efx_nic *efx)
183 static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
187 bar = efx->type->mem_bar(efx);
188 return resource_size(&efx->pci_dev->resource[bar]);
191 static bool efx_ef10_is_vf(struct efx_nic *efx)
193 return efx->type->is_vf;
196 static int efx_ef10_get_pf_index(struct efx_nic *efx)
198 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
199 struct efx_ef10_nic_data *nic_data = efx->nic_data;
203 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
204 sizeof(outbuf), &outlen);
207 if (outlen < sizeof(outbuf))
210 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
214 #ifdef CONFIG_SFC_SRIOV
215 static int efx_ef10_get_vf_index(struct efx_nic *efx)
217 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
218 struct efx_ef10_nic_data *nic_data = efx->nic_data;
222 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
223 sizeof(outbuf), &outlen);
226 if (outlen < sizeof(outbuf))
229 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
234 static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
236 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
237 struct efx_ef10_nic_data *nic_data = efx->nic_data;
241 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
243 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
244 outbuf, sizeof(outbuf), &outlen);
247 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
248 netif_err(efx, drv, efx->net_dev,
249 "unable to read datapath firmware capabilities\n");
253 nic_data->datapath_caps =
254 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
256 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
257 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
258 GET_CAPABILITIES_V2_OUT_FLAGS2);
259 nic_data->piobuf_size = MCDI_WORD(outbuf,
260 GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
262 nic_data->datapath_caps2 = 0;
263 nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
266 /* record the DPCPU firmware IDs to determine VEB vswitching support.
268 nic_data->rx_dpcpu_fw_id =
269 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
270 nic_data->tx_dpcpu_fw_id =
271 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
273 if (!(nic_data->datapath_caps &
274 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
275 netif_err(efx, probe, efx->net_dev,
276 "current firmware does not support an RX prefix\n");
280 if (outlen >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
281 u8 vi_window_mode = MCDI_BYTE(outbuf,
282 GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
284 switch (vi_window_mode) {
285 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
286 efx->vi_stride = 8192;
288 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
289 efx->vi_stride = 16384;
291 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
292 efx->vi_stride = 65536;
295 netif_err(efx, probe, efx->net_dev,
296 "Unrecognised VI window mode %d\n",
300 netif_dbg(efx, probe, efx->net_dev, "vi_stride = %u\n",
303 /* keep default VI stride */
304 netif_dbg(efx, probe, efx->net_dev,
305 "firmware did not report VI window mode, assuming vi_stride = %u\n",
309 if (outlen >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
310 efx->num_mac_stats = MCDI_WORD(outbuf,
311 GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
312 netif_dbg(efx, probe, efx->net_dev,
313 "firmware reports num_mac_stats = %u\n",
316 /* leave num_mac_stats as the default value, MC_CMD_MAC_NSTATS */
317 netif_dbg(efx, probe, efx->net_dev,
318 "firmware did not report num_mac_stats, assuming %u\n",
325 static void efx_ef10_read_licensed_features(struct efx_nic *efx)
327 MCDI_DECLARE_BUF(inbuf, MC_CMD_LICENSING_V3_IN_LEN);
328 MCDI_DECLARE_BUF(outbuf, MC_CMD_LICENSING_V3_OUT_LEN);
329 struct efx_ef10_nic_data *nic_data = efx->nic_data;
333 MCDI_SET_DWORD(inbuf, LICENSING_V3_IN_OP,
334 MC_CMD_LICENSING_V3_IN_OP_REPORT_LICENSE);
335 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_LICENSING_V3, inbuf, sizeof(inbuf),
336 outbuf, sizeof(outbuf), &outlen);
337 if (rc || (outlen < MC_CMD_LICENSING_V3_OUT_LEN))
340 nic_data->licensed_features = MCDI_QWORD(outbuf,
341 LICENSING_V3_OUT_LICENSED_FEATURES);
344 static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
346 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
349 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
350 outbuf, sizeof(outbuf), NULL);
353 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
354 return rc > 0 ? rc : -ERANGE;
357 static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
359 struct efx_ef10_nic_data *nic_data = efx->nic_data;
360 unsigned int implemented;
361 unsigned int enabled;
364 nic_data->workaround_35388 = false;
365 nic_data->workaround_61265 = false;
367 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
370 /* Firmware without GET_WORKAROUNDS - not a problem. */
372 } else if (rc == 0) {
373 /* Bug61265 workaround is always enabled if implemented. */
374 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
375 nic_data->workaround_61265 = true;
377 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
378 nic_data->workaround_35388 = true;
379 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
380 /* Workaround is implemented but not enabled.
383 rc = efx_mcdi_set_workaround(efx,
384 MC_CMD_WORKAROUND_BUG35388,
387 nic_data->workaround_35388 = true;
388 /* If we failed to set the workaround just carry on. */
393 netif_dbg(efx, probe, efx->net_dev,
394 "workaround for bug 35388 is %sabled\n",
395 nic_data->workaround_35388 ? "en" : "dis");
396 netif_dbg(efx, probe, efx->net_dev,
397 "workaround for bug 61265 is %sabled\n",
398 nic_data->workaround_61265 ? "en" : "dis");
403 static void efx_ef10_process_timer_config(struct efx_nic *efx,
404 const efx_dword_t *data)
406 unsigned int max_count;
408 if (EFX_EF10_WORKAROUND_61265(efx)) {
409 efx->timer_quantum_ns = MCDI_DWORD(data,
410 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
411 efx->timer_max_ns = MCDI_DWORD(data,
412 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
413 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
414 efx->timer_quantum_ns = MCDI_DWORD(data,
415 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
416 max_count = MCDI_DWORD(data,
417 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
418 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
420 efx->timer_quantum_ns = MCDI_DWORD(data,
421 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
422 max_count = MCDI_DWORD(data,
423 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
424 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
427 netif_dbg(efx, probe, efx->net_dev,
428 "got timer properties from MC: quantum %u ns; max %u ns\n",
429 efx->timer_quantum_ns, efx->timer_max_ns);
432 static int efx_ef10_get_timer_config(struct efx_nic *efx)
434 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
437 rc = efx_ef10_get_timer_workarounds(efx);
441 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
442 outbuf, sizeof(outbuf), NULL);
445 efx_ef10_process_timer_config(efx, outbuf);
446 } else if (rc == -ENOSYS || rc == -EPERM) {
447 /* Not available - fall back to Huntington defaults. */
448 unsigned int quantum;
450 rc = efx_ef10_get_sysclk_freq(efx);
454 quantum = 1536000 / rc; /* 1536 cycles */
455 efx->timer_quantum_ns = quantum;
456 efx->timer_max_ns = efx->type->timer_period_max * quantum;
459 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
460 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
467 static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
469 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
473 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
475 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
476 outbuf, sizeof(outbuf), &outlen);
479 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
482 ether_addr_copy(mac_address,
483 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
487 static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
489 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
490 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
494 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
495 EVB_PORT_ID_ASSIGNED);
496 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
497 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
501 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
504 num_addrs = MCDI_DWORD(outbuf,
505 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
507 WARN_ON(num_addrs != 1);
509 ether_addr_copy(mac_address,
510 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
515 static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
516 struct device_attribute *attr,
519 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
521 return sprintf(buf, "%d\n",
522 ((efx->mcdi->fn_flags) &
523 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
527 static ssize_t efx_ef10_show_primary_flag(struct device *dev,
528 struct device_attribute *attr,
531 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
533 return sprintf(buf, "%d\n",
534 ((efx->mcdi->fn_flags) &
535 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
539 static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
541 struct efx_ef10_nic_data *nic_data = efx->nic_data;
542 struct efx_ef10_vlan *vlan;
544 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
546 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
547 if (vlan->vid == vid)
554 static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
556 struct efx_ef10_nic_data *nic_data = efx->nic_data;
557 struct efx_ef10_vlan *vlan;
560 mutex_lock(&nic_data->vlan_lock);
562 vlan = efx_ef10_find_vlan(efx, vid);
564 /* We add VID 0 on init. 8021q adds it on module init
565 * for all interfaces with VLAN filtring feature.
569 netif_warn(efx, drv, efx->net_dev,
570 "VLAN %u already added\n", vid);
576 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
582 list_add_tail(&vlan->list, &nic_data->vlan_list);
584 if (efx->filter_state) {
585 mutex_lock(&efx->mac_lock);
586 down_write(&efx->filter_sem);
587 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
588 up_write(&efx->filter_sem);
589 mutex_unlock(&efx->mac_lock);
591 goto fail_filter_add_vlan;
595 mutex_unlock(&nic_data->vlan_lock);
598 fail_filter_add_vlan:
599 list_del(&vlan->list);
603 mutex_unlock(&nic_data->vlan_lock);
607 static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
608 struct efx_ef10_vlan *vlan)
610 struct efx_ef10_nic_data *nic_data = efx->nic_data;
612 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
614 if (efx->filter_state) {
615 down_write(&efx->filter_sem);
616 efx_ef10_filter_del_vlan(efx, vlan->vid);
617 up_write(&efx->filter_sem);
620 list_del(&vlan->list);
624 static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
626 struct efx_ef10_nic_data *nic_data = efx->nic_data;
627 struct efx_ef10_vlan *vlan;
630 /* 8021q removes VID 0 on module unload for all interfaces
631 * with VLAN filtering feature. We need to keep it to receive
637 mutex_lock(&nic_data->vlan_lock);
639 vlan = efx_ef10_find_vlan(efx, vid);
641 netif_err(efx, drv, efx->net_dev,
642 "VLAN %u to be deleted not found\n", vid);
645 efx_ef10_del_vlan_internal(efx, vlan);
648 mutex_unlock(&nic_data->vlan_lock);
653 static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
655 struct efx_ef10_nic_data *nic_data = efx->nic_data;
656 struct efx_ef10_vlan *vlan, *next_vlan;
658 mutex_lock(&nic_data->vlan_lock);
659 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
660 efx_ef10_del_vlan_internal(efx, vlan);
661 mutex_unlock(&nic_data->vlan_lock);
664 static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
666 static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
668 static int efx_ef10_probe(struct efx_nic *efx)
670 struct efx_ef10_nic_data *nic_data;
673 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
676 efx->nic_data = nic_data;
678 /* we assume later that we can copy from this buffer in dwords */
679 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
681 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
682 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
686 /* Get the MC's warm boot count. In case it's rebooting right
687 * now, be prepared to retry.
691 rc = efx_ef10_get_warm_boot_count(efx);
698 nic_data->warm_boot_count = rc;
700 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
702 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
704 /* In case we're recovering from a crash (kexec), we want to
705 * cancel any outstanding request by the previous user of this
706 * function. We send a special message using the least
707 * significant bits of the 'high' (doorbell) register.
709 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
711 rc = efx_mcdi_init(efx);
715 mutex_init(&nic_data->udp_tunnels_lock);
717 /* Reset (most) configuration for this function */
718 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
722 /* Enable event logging */
723 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
727 rc = device_create_file(&efx->pci_dev->dev,
728 &dev_attr_link_control_flag);
732 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
736 rc = efx_ef10_get_pf_index(efx);
740 rc = efx_ef10_init_datapath_caps(efx);
744 efx_ef10_read_licensed_features(efx);
746 /* We can have one VI for each vi_stride-byte region.
747 * However, until we use TX option descriptors we need two TX queues
750 efx->max_channels = min_t(unsigned int,
752 efx_ef10_mem_map_size(efx) /
753 (efx->vi_stride * EFX_TXQ_TYPES));
754 efx->max_tx_channels = efx->max_channels;
755 if (WARN_ON(efx->max_channels == 0)) {
760 efx->rx_packet_len_offset =
761 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
763 if (nic_data->datapath_caps &
764 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
765 efx->net_dev->hw_features |= NETIF_F_RXFCS;
767 rc = efx_mcdi_port_get_number(efx);
772 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
776 rc = efx_ef10_get_timer_config(efx);
780 rc = efx_mcdi_mon_probe(efx);
781 if (rc && rc != -EPERM)
784 efx_ptp_defer_probe_with_channel(efx);
786 #ifdef CONFIG_SFC_SRIOV
787 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
788 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
789 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
791 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
794 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
796 INIT_LIST_HEAD(&nic_data->vlan_list);
797 mutex_init(&nic_data->vlan_lock);
799 /* Add unspecified VID to support VLAN filtering being disabled */
800 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
802 goto fail_add_vid_unspec;
804 /* If VLAN filtering is enabled, we need VID 0 to get untagged
805 * traffic. It is added automatically if 8021q module is loaded,
806 * but we can't rely on it since module may be not loaded.
808 rc = efx_ef10_add_vlan(efx, 0);
815 efx_ef10_cleanup_vlans(efx);
817 mutex_destroy(&nic_data->vlan_lock);
819 efx_mcdi_mon_remove(efx);
821 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
823 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
825 efx_mcdi_detach(efx);
827 mutex_lock(&nic_data->udp_tunnels_lock);
828 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
829 (void)efx_ef10_set_udp_tnl_ports(efx, true);
830 mutex_unlock(&nic_data->udp_tunnels_lock);
831 mutex_destroy(&nic_data->udp_tunnels_lock);
835 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
838 efx->nic_data = NULL;
842 static int efx_ef10_free_vis(struct efx_nic *efx)
844 MCDI_DECLARE_BUF_ERR(outbuf);
846 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
847 outbuf, sizeof(outbuf), &outlen);
849 /* -EALREADY means nothing to free, so ignore */
853 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
860 static void efx_ef10_free_piobufs(struct efx_nic *efx)
862 struct efx_ef10_nic_data *nic_data = efx->nic_data;
863 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
867 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
869 for (i = 0; i < nic_data->n_piobufs; i++) {
870 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
871 nic_data->piobuf_handle[i]);
872 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
877 nic_data->n_piobufs = 0;
880 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
882 struct efx_ef10_nic_data *nic_data = efx->nic_data;
883 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
888 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
890 for (i = 0; i < n; i++) {
891 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
892 outbuf, sizeof(outbuf), &outlen);
894 /* Don't display the MC error if we didn't have space
897 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
898 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
899 0, outbuf, outlen, rc);
902 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
906 nic_data->piobuf_handle[i] =
907 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
908 netif_dbg(efx, probe, efx->net_dev,
909 "allocated PIO buffer %u handle %x\n", i,
910 nic_data->piobuf_handle[i]);
913 nic_data->n_piobufs = i;
915 efx_ef10_free_piobufs(efx);
919 static int efx_ef10_link_piobufs(struct efx_nic *efx)
921 struct efx_ef10_nic_data *nic_data = efx->nic_data;
922 MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
923 struct efx_channel *channel;
924 struct efx_tx_queue *tx_queue;
925 unsigned int offset, index;
928 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
929 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
931 /* Link a buffer to each VI in the write-combining mapping */
932 for (index = 0; index < nic_data->n_piobufs; ++index) {
933 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
934 nic_data->piobuf_handle[index]);
935 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
936 nic_data->pio_write_vi_base + index);
937 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
938 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
941 netif_err(efx, drv, efx->net_dev,
942 "failed to link VI %u to PIO buffer %u (%d)\n",
943 nic_data->pio_write_vi_base + index, index,
947 netif_dbg(efx, probe, efx->net_dev,
948 "linked VI %u to PIO buffer %u\n",
949 nic_data->pio_write_vi_base + index, index);
952 /* Link a buffer to each TX queue */
953 efx_for_each_channel(channel, efx) {
954 efx_for_each_channel_tx_queue(tx_queue, channel) {
955 /* We assign the PIO buffers to queues in
956 * reverse order to allow for the following
959 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
960 tx_queue->channel->channel - 1) *
962 index = offset / nic_data->piobuf_size;
963 offset = offset % nic_data->piobuf_size;
965 /* When the host page size is 4K, the first
966 * host page in the WC mapping may be within
967 * the same VI page as the last TX queue. We
968 * can only link one buffer to each VI.
970 if (tx_queue->queue == nic_data->pio_write_vi_base) {
974 MCDI_SET_DWORD(inbuf,
975 LINK_PIOBUF_IN_PIOBUF_HANDLE,
976 nic_data->piobuf_handle[index]);
977 MCDI_SET_DWORD(inbuf,
978 LINK_PIOBUF_IN_TXQ_INSTANCE,
980 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
981 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
986 /* This is non-fatal; the TX path just
987 * won't use PIO for this queue
989 netif_err(efx, drv, efx->net_dev,
990 "failed to link VI %u to PIO buffer %u (%d)\n",
991 tx_queue->queue, index, rc);
992 tx_queue->piobuf = NULL;
995 nic_data->pio_write_base +
996 index * efx->vi_stride + offset;
997 tx_queue->piobuf_offset = offset;
998 netif_dbg(efx, probe, efx->net_dev,
999 "linked VI %u to PIO buffer %u offset %x addr %p\n",
1000 tx_queue->queue, index,
1001 tx_queue->piobuf_offset,
1010 /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
1011 * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
1013 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
1015 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
1016 nic_data->pio_write_vi_base + index);
1017 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
1018 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
1024 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1026 struct efx_channel *channel;
1027 struct efx_tx_queue *tx_queue;
1029 /* All our existing PIO buffers went away */
1030 efx_for_each_channel(channel, efx)
1031 efx_for_each_channel_tx_queue(tx_queue, channel)
1032 tx_queue->piobuf = NULL;
1035 #else /* !EFX_USE_PIO */
1037 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
1039 return n == 0 ? 0 : -ENOBUFS;
1042 static int efx_ef10_link_piobufs(struct efx_nic *efx)
1047 static void efx_ef10_free_piobufs(struct efx_nic *efx)
1051 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1055 #endif /* EFX_USE_PIO */
1057 static void efx_ef10_remove(struct efx_nic *efx)
1059 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1062 #ifdef CONFIG_SFC_SRIOV
1063 struct efx_ef10_nic_data *nic_data_pf;
1064 struct pci_dev *pci_dev_pf;
1065 struct efx_nic *efx_pf;
1068 if (efx->pci_dev->is_virtfn) {
1069 pci_dev_pf = efx->pci_dev->physfn;
1071 efx_pf = pci_get_drvdata(pci_dev_pf);
1072 nic_data_pf = efx_pf->nic_data;
1073 vf = nic_data_pf->vf + nic_data->vf_index;
1076 netif_info(efx, drv, efx->net_dev,
1077 "Could not get the PF id from VF\n");
1081 efx_ef10_cleanup_vlans(efx);
1082 mutex_destroy(&nic_data->vlan_lock);
1084 efx_ptp_remove(efx);
1086 efx_mcdi_mon_remove(efx);
1088 efx_ef10_rx_free_indir_table(efx);
1090 if (nic_data->wc_membase)
1091 iounmap(nic_data->wc_membase);
1093 rc = efx_ef10_free_vis(efx);
1096 if (!nic_data->must_restore_piobufs)
1097 efx_ef10_free_piobufs(efx);
1099 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
1100 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
1102 efx_mcdi_detach(efx);
1104 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
1105 mutex_lock(&nic_data->udp_tunnels_lock);
1106 (void)efx_ef10_set_udp_tnl_ports(efx, true);
1107 mutex_unlock(&nic_data->udp_tunnels_lock);
1109 mutex_destroy(&nic_data->udp_tunnels_lock);
1112 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
1116 static int efx_ef10_probe_pf(struct efx_nic *efx)
1118 return efx_ef10_probe(efx);
1121 int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
1122 u32 *port_flags, u32 *vadaptor_flags,
1123 unsigned int *vlan_tags)
1125 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1126 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
1127 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
1131 if (nic_data->datapath_caps &
1132 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
1133 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
1136 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
1137 outbuf, sizeof(outbuf), &outlen);
1141 if (outlen < sizeof(outbuf)) {
1148 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1151 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1155 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1160 int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1162 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1164 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1165 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1169 int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1171 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1173 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1174 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1178 int efx_ef10_vport_add_mac(struct efx_nic *efx,
1179 unsigned int port_id, u8 *mac)
1181 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1183 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1184 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1186 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1187 sizeof(inbuf), NULL, 0, NULL);
1190 int efx_ef10_vport_del_mac(struct efx_nic *efx,
1191 unsigned int port_id, u8 *mac)
1193 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1195 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1196 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1198 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1199 sizeof(inbuf), NULL, 0, NULL);
1202 #ifdef CONFIG_SFC_SRIOV
1203 static int efx_ef10_probe_vf(struct efx_nic *efx)
1206 struct pci_dev *pci_dev_pf;
1208 /* If the parent PF has no VF data structure, it doesn't know about this
1209 * VF so fail probe. The VF needs to be re-created. This can happen
1210 * if the PF driver is unloaded while the VF is assigned to a guest.
1212 pci_dev_pf = efx->pci_dev->physfn;
1214 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1215 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1217 if (!nic_data_pf->vf) {
1218 netif_info(efx, drv, efx->net_dev,
1219 "The VF cannot link to its parent PF; "
1220 "please destroy and re-create the VF\n");
1225 rc = efx_ef10_probe(efx);
1229 rc = efx_ef10_get_vf_index(efx);
1233 if (efx->pci_dev->is_virtfn) {
1234 if (efx->pci_dev->physfn) {
1235 struct efx_nic *efx_pf =
1236 pci_get_drvdata(efx->pci_dev->physfn);
1237 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1238 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1240 nic_data_p->vf[nic_data->vf_index].efx = efx;
1241 nic_data_p->vf[nic_data->vf_index].pci_dev =
1244 netif_info(efx, drv, efx->net_dev,
1245 "Could not get the PF id from VF\n");
1251 efx_ef10_remove(efx);
1255 static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1261 static int efx_ef10_alloc_vis(struct efx_nic *efx,
1262 unsigned int min_vis, unsigned int max_vis)
1264 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1265 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1266 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1270 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1271 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1272 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1273 outbuf, sizeof(outbuf), &outlen);
1277 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1280 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1281 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1283 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1284 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1288 /* Note that the failure path of this function does not free
1289 * resources, as this will be done by efx_ef10_remove().
1291 static int efx_ef10_dimension_resources(struct efx_nic *efx)
1293 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1294 unsigned int uc_mem_map_size, wc_mem_map_size;
1295 unsigned int min_vis = max(EFX_TXQ_TYPES,
1296 efx_separate_tx_channels ? 2 : 1);
1297 unsigned int channel_vis, pio_write_vi_base, max_vis;
1298 void __iomem *membase;
1301 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
1304 /* Try to allocate PIO buffers if wanted and if the full
1305 * number of PIO buffers would be sufficient to allocate one
1306 * copy-buffer per TX channel. Failure is non-fatal, as there
1307 * are only a small number of PIO buffers shared between all
1308 * functions of the controller.
1310 if (efx_piobuf_size != 0 &&
1311 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1312 efx->n_tx_channels) {
1313 unsigned int n_piobufs =
1314 DIV_ROUND_UP(efx->n_tx_channels,
1315 nic_data->piobuf_size / efx_piobuf_size);
1317 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1319 netif_dbg(efx, probe, efx->net_dev,
1320 "out of PIO buffers; cannot allocate more\n");
1321 else if (rc == -EPERM)
1322 netif_dbg(efx, probe, efx->net_dev,
1323 "not permitted to allocate PIO buffers\n");
1325 netif_err(efx, probe, efx->net_dev,
1326 "failed to allocate PIO buffers (%d)\n", rc);
1328 netif_dbg(efx, probe, efx->net_dev,
1329 "allocated %u PIO buffers\n", n_piobufs);
1332 nic_data->n_piobufs = 0;
1335 /* PIO buffers should be mapped with write-combining enabled,
1336 * and we want to make single UC and WC mappings rather than
1337 * several of each (in fact that's the only option if host
1338 * page size is >4K). So we may allocate some extra VIs just
1339 * for writing PIO buffers through.
1341 * The UC mapping contains (channel_vis - 1) complete VIs and the
1342 * first 4K of the next VI. Then the WC mapping begins with
1343 * the remainder of this last VI.
1345 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
1347 if (nic_data->n_piobufs) {
1348 /* pio_write_vi_base rounds down to give the number of complete
1349 * VIs inside the UC mapping.
1351 pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
1352 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1353 nic_data->n_piobufs) *
1356 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1358 pio_write_vi_base = 0;
1359 wc_mem_map_size = 0;
1360 max_vis = channel_vis;
1363 /* In case the last attached driver failed to free VIs, do it now */
1364 rc = efx_ef10_free_vis(efx);
1368 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1372 if (nic_data->n_allocated_vis < channel_vis) {
1373 netif_info(efx, drv, efx->net_dev,
1374 "Could not allocate enough VIs to satisfy RSS"
1375 " requirements. Performance may not be optimal.\n");
1376 /* We didn't get the VIs to populate our channels.
1377 * We could keep what we got but then we'd have more
1378 * interrupts than we need.
1379 * Instead calculate new max_channels and restart
1381 efx->max_channels = nic_data->n_allocated_vis;
1382 efx->max_tx_channels =
1383 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1385 efx_ef10_free_vis(efx);
1389 /* If we didn't get enough VIs to map all the PIO buffers, free the
1392 if (nic_data->n_piobufs &&
1393 nic_data->n_allocated_vis <
1394 pio_write_vi_base + nic_data->n_piobufs) {
1395 netif_dbg(efx, probe, efx->net_dev,
1396 "%u VIs are not sufficient to map %u PIO buffers\n",
1397 nic_data->n_allocated_vis, nic_data->n_piobufs);
1398 efx_ef10_free_piobufs(efx);
1401 /* Shrink the original UC mapping of the memory BAR */
1402 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1404 netif_err(efx, probe, efx->net_dev,
1405 "could not shrink memory BAR to %x\n",
1409 iounmap(efx->membase);
1410 efx->membase = membase;
1412 /* Set up the WC mapping if needed */
1413 if (wc_mem_map_size) {
1414 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1417 if (!nic_data->wc_membase) {
1418 netif_err(efx, probe, efx->net_dev,
1419 "could not allocate WC mapping of size %x\n",
1423 nic_data->pio_write_vi_base = pio_write_vi_base;
1424 nic_data->pio_write_base =
1425 nic_data->wc_membase +
1426 (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
1429 rc = efx_ef10_link_piobufs(efx);
1431 efx_ef10_free_piobufs(efx);
1434 netif_dbg(efx, probe, efx->net_dev,
1435 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1436 &efx->membase_phys, efx->membase, uc_mem_map_size,
1437 nic_data->wc_membase, wc_mem_map_size);
1442 static int efx_ef10_init_nic(struct efx_nic *efx)
1444 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1447 if (nic_data->must_check_datapath_caps) {
1448 rc = efx_ef10_init_datapath_caps(efx);
1451 nic_data->must_check_datapath_caps = false;
1454 if (nic_data->must_realloc_vis) {
1455 /* We cannot let the number of VIs change now */
1456 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1457 nic_data->n_allocated_vis);
1460 nic_data->must_realloc_vis = false;
1463 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1464 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1466 rc = efx_ef10_link_piobufs(efx);
1468 efx_ef10_free_piobufs(efx);
1471 /* Log an error on failure, but this is non-fatal.
1472 * Permission errors are less important - we've presumably
1473 * had the PIO buffer licence removed.
1476 netif_dbg(efx, drv, efx->net_dev,
1477 "not permitted to restore PIO buffers\n");
1479 netif_err(efx, drv, efx->net_dev,
1480 "failed to restore PIO buffers (%d)\n", rc);
1481 nic_data->must_restore_piobufs = false;
1484 /* don't fail init if RSS setup doesn't work */
1485 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
1486 efx->rss_active = (rc == 0);
1491 static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1493 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1494 #ifdef CONFIG_SFC_SRIOV
1498 /* All our allocations have been reset */
1499 nic_data->must_realloc_vis = true;
1500 nic_data->must_restore_filters = true;
1501 nic_data->must_restore_piobufs = true;
1502 efx_ef10_forget_old_piobufs(efx);
1503 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1505 /* Driver-created vswitches and vports must be re-created */
1506 nic_data->must_probe_vswitching = true;
1507 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1508 #ifdef CONFIG_SFC_SRIOV
1510 for (i = 0; i < efx->vf_count; i++)
1511 nic_data->vf[i].vport_id = 0;
1515 static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1517 if (reason == RESET_TYPE_MC_FAILURE)
1518 return RESET_TYPE_DATAPATH;
1520 return efx_mcdi_map_reset_reason(reason);
1523 static int efx_ef10_map_reset_flags(u32 *flags)
1526 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1527 ETH_RESET_SHARED_SHIFT),
1528 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1529 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1530 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1531 ETH_RESET_SHARED_SHIFT)
1534 /* We assume for now that our PCI function is permitted to
1538 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1539 *flags &= ~EF10_RESET_MC;
1540 return RESET_TYPE_WORLD;
1543 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1544 *flags &= ~EF10_RESET_PORT;
1545 return RESET_TYPE_ALL;
1548 /* no invisible reset implemented */
1553 static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1555 int rc = efx_mcdi_reset(efx, reset_type);
1557 /* Unprivileged functions return -EPERM, but need to return success
1558 * here so that the datapath is brought back up.
1560 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1563 /* If it was a port reset, trigger reallocation of MC resources.
1564 * Note that on an MC reset nothing needs to be done now because we'll
1565 * detect the MC reset later and handle it then.
1566 * For an FLR, we never get an MC reset event, but the MC has reset all
1567 * resources assigned to us, so we have to trigger reallocation now.
1569 if ((reset_type == RESET_TYPE_ALL ||
1570 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
1571 efx_ef10_reset_mc_allocations(efx);
1575 #define EF10_DMA_STAT(ext_name, mcdi_name) \
1576 [EF10_STAT_ ## ext_name] = \
1577 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1578 #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1579 [EF10_STAT_ ## int_name] = \
1580 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1581 #define EF10_OTHER_STAT(ext_name) \
1582 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1583 #define GENERIC_SW_STAT(ext_name) \
1584 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1586 static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
1587 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1588 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1589 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1590 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1591 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1592 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1593 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1594 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1595 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1596 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1597 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1598 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1599 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1600 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1601 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1602 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1603 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1604 EF10_OTHER_STAT(port_rx_good_bytes),
1605 EF10_OTHER_STAT(port_rx_bad_bytes),
1606 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1607 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1608 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1609 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1610 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1611 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1612 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1613 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1614 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1615 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1616 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1617 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1618 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1619 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1620 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1621 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1622 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1623 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1624 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1625 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1626 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1627 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
1628 GENERIC_SW_STAT(rx_nodesc_trunc),
1629 GENERIC_SW_STAT(rx_noskb_drops),
1630 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1631 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1632 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1633 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1634 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1635 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1636 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1637 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1638 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1639 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1640 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1641 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
1642 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1643 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1644 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1645 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1646 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1647 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1648 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1649 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1650 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1651 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1652 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1653 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1654 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1655 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1656 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1657 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1658 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1659 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
1660 EF10_DMA_STAT(fec_uncorrected_errors, FEC_UNCORRECTED_ERRORS),
1661 EF10_DMA_STAT(fec_corrected_errors, FEC_CORRECTED_ERRORS),
1662 EF10_DMA_STAT(fec_corrected_symbols_lane0, FEC_CORRECTED_SYMBOLS_LANE0),
1663 EF10_DMA_STAT(fec_corrected_symbols_lane1, FEC_CORRECTED_SYMBOLS_LANE1),
1664 EF10_DMA_STAT(fec_corrected_symbols_lane2, FEC_CORRECTED_SYMBOLS_LANE2),
1665 EF10_DMA_STAT(fec_corrected_symbols_lane3, FEC_CORRECTED_SYMBOLS_LANE3),
1666 EF10_DMA_STAT(ctpio_dmabuf_start, CTPIO_DMABUF_START),
1667 EF10_DMA_STAT(ctpio_vi_busy_fallback, CTPIO_VI_BUSY_FALLBACK),
1668 EF10_DMA_STAT(ctpio_long_write_success, CTPIO_LONG_WRITE_SUCCESS),
1669 EF10_DMA_STAT(ctpio_missing_dbell_fail, CTPIO_MISSING_DBELL_FAIL),
1670 EF10_DMA_STAT(ctpio_overflow_fail, CTPIO_OVERFLOW_FAIL),
1671 EF10_DMA_STAT(ctpio_underflow_fail, CTPIO_UNDERFLOW_FAIL),
1672 EF10_DMA_STAT(ctpio_timeout_fail, CTPIO_TIMEOUT_FAIL),
1673 EF10_DMA_STAT(ctpio_noncontig_wr_fail, CTPIO_NONCONTIG_WR_FAIL),
1674 EF10_DMA_STAT(ctpio_frm_clobber_fail, CTPIO_FRM_CLOBBER_FAIL),
1675 EF10_DMA_STAT(ctpio_invalid_wr_fail, CTPIO_INVALID_WR_FAIL),
1676 EF10_DMA_STAT(ctpio_vi_clobber_fallback, CTPIO_VI_CLOBBER_FALLBACK),
1677 EF10_DMA_STAT(ctpio_unqualified_fallback, CTPIO_UNQUALIFIED_FALLBACK),
1678 EF10_DMA_STAT(ctpio_runt_fallback, CTPIO_RUNT_FALLBACK),
1679 EF10_DMA_STAT(ctpio_success, CTPIO_SUCCESS),
1680 EF10_DMA_STAT(ctpio_fallback, CTPIO_FALLBACK),
1681 EF10_DMA_STAT(ctpio_poison, CTPIO_POISON),
1682 EF10_DMA_STAT(ctpio_erase, CTPIO_ERASE),
1685 #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1686 (1ULL << EF10_STAT_port_tx_packets) | \
1687 (1ULL << EF10_STAT_port_tx_pause) | \
1688 (1ULL << EF10_STAT_port_tx_unicast) | \
1689 (1ULL << EF10_STAT_port_tx_multicast) | \
1690 (1ULL << EF10_STAT_port_tx_broadcast) | \
1691 (1ULL << EF10_STAT_port_rx_bytes) | \
1693 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1694 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1695 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1696 (1ULL << EF10_STAT_port_rx_packets) | \
1697 (1ULL << EF10_STAT_port_rx_good) | \
1698 (1ULL << EF10_STAT_port_rx_bad) | \
1699 (1ULL << EF10_STAT_port_rx_pause) | \
1700 (1ULL << EF10_STAT_port_rx_control) | \
1701 (1ULL << EF10_STAT_port_rx_unicast) | \
1702 (1ULL << EF10_STAT_port_rx_multicast) | \
1703 (1ULL << EF10_STAT_port_rx_broadcast) | \
1704 (1ULL << EF10_STAT_port_rx_lt64) | \
1705 (1ULL << EF10_STAT_port_rx_64) | \
1706 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1707 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1708 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1709 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1710 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1711 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1712 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1713 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1714 (1ULL << EF10_STAT_port_rx_overflow) | \
1715 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
1716 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1717 (1ULL << GENERIC_STAT_rx_noskb_drops))
1719 /* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1720 * For a 10G/40G switchable port we do not expose these because they might
1721 * not include all the packets they should.
1722 * On 8000 series NICs these statistics are always provided.
1724 #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1725 (1ULL << EF10_STAT_port_tx_lt64) | \
1726 (1ULL << EF10_STAT_port_tx_64) | \
1727 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1728 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1729 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1730 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1731 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1732 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
1734 /* These statistics are only provided by the 40G MAC. For a 10G/40G
1735 * switchable port we do expose these because the errors will otherwise
1738 #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1739 (1ULL << EF10_STAT_port_rx_length_error))
1741 /* These statistics are only provided if the firmware supports the
1742 * capability PM_AND_RXDP_COUNTERS.
1744 #define HUNT_PM_AND_RXDP_STAT_MASK ( \
1745 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1746 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1747 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1748 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1749 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1750 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1751 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1752 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1753 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1754 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1755 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1756 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
1758 /* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V2,
1759 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V2 in
1760 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1761 * These bits are in the second u64 of the raw mask.
1763 #define EF10_FEC_STAT_MASK ( \
1764 (1ULL << (EF10_STAT_fec_uncorrected_errors - 64)) | \
1765 (1ULL << (EF10_STAT_fec_corrected_errors - 64)) | \
1766 (1ULL << (EF10_STAT_fec_corrected_symbols_lane0 - 64)) | \
1767 (1ULL << (EF10_STAT_fec_corrected_symbols_lane1 - 64)) | \
1768 (1ULL << (EF10_STAT_fec_corrected_symbols_lane2 - 64)) | \
1769 (1ULL << (EF10_STAT_fec_corrected_symbols_lane3 - 64)))
1771 /* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V3,
1772 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V3 in
1773 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1774 * These bits are in the second u64 of the raw mask.
1776 #define EF10_CTPIO_STAT_MASK ( \
1777 (1ULL << (EF10_STAT_ctpio_dmabuf_start - 64)) | \
1778 (1ULL << (EF10_STAT_ctpio_vi_busy_fallback - 64)) | \
1779 (1ULL << (EF10_STAT_ctpio_long_write_success - 64)) | \
1780 (1ULL << (EF10_STAT_ctpio_missing_dbell_fail - 64)) | \
1781 (1ULL << (EF10_STAT_ctpio_overflow_fail - 64)) | \
1782 (1ULL << (EF10_STAT_ctpio_underflow_fail - 64)) | \
1783 (1ULL << (EF10_STAT_ctpio_timeout_fail - 64)) | \
1784 (1ULL << (EF10_STAT_ctpio_noncontig_wr_fail - 64)) | \
1785 (1ULL << (EF10_STAT_ctpio_frm_clobber_fail - 64)) | \
1786 (1ULL << (EF10_STAT_ctpio_invalid_wr_fail - 64)) | \
1787 (1ULL << (EF10_STAT_ctpio_vi_clobber_fallback - 64)) | \
1788 (1ULL << (EF10_STAT_ctpio_unqualified_fallback - 64)) | \
1789 (1ULL << (EF10_STAT_ctpio_runt_fallback - 64)) | \
1790 (1ULL << (EF10_STAT_ctpio_success - 64)) | \
1791 (1ULL << (EF10_STAT_ctpio_fallback - 64)) | \
1792 (1ULL << (EF10_STAT_ctpio_poison - 64)) | \
1793 (1ULL << (EF10_STAT_ctpio_erase - 64)))
1795 static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
1797 u64 raw_mask = HUNT_COMMON_STAT_MASK;
1798 u32 port_caps = efx_mcdi_phy_get_caps(efx);
1799 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1801 if (!(efx->mcdi->fn_flags &
1802 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1805 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
1806 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
1807 /* 8000 series have everything even at 40G */
1808 if (nic_data->datapath_caps2 &
1809 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1810 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1812 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1815 if (nic_data->datapath_caps &
1816 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1817 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1822 static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1824 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1827 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1829 /* Only show vadaptor stats when EVB capability is present */
1830 if (nic_data->datapath_caps &
1831 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1832 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1833 raw_mask[1] = (1ULL << (EF10_STAT_V1_COUNT - 64)) - 1;
1837 /* Only show FEC stats when NIC supports MC_CMD_MAC_STATS_V2 */
1838 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V2)
1839 raw_mask[1] |= EF10_FEC_STAT_MASK;
1841 /* CTPIO stats appear in V3. Only show them on devices that actually
1842 * support CTPIO. Although this driver doesn't use CTPIO others might,
1843 * and we may be reporting the stats for the underlying port.
1845 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V3 &&
1846 (nic_data->datapath_caps2 &
1847 (1 << MC_CMD_GET_CAPABILITIES_V4_OUT_CTPIO_LBN)))
1848 raw_mask[1] |= EF10_CTPIO_STAT_MASK;
1850 #if BITS_PER_LONG == 64
1851 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
1852 mask[0] = raw_mask[0];
1853 mask[1] = raw_mask[1];
1855 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
1856 mask[0] = raw_mask[0] & 0xffffffff;
1857 mask[1] = raw_mask[0] >> 32;
1858 mask[2] = raw_mask[1] & 0xffffffff;
1862 static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1864 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1866 efx_ef10_get_stat_mask(efx, mask);
1867 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
1871 static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1872 struct rtnl_link_stats64 *core_stats)
1874 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1875 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1876 u64 *stats = nic_data->stats;
1877 size_t stats_count = 0, index;
1879 efx_ef10_get_stat_mask(efx, mask);
1882 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1883 if (efx_ef10_stat_desc[index].name) {
1884 *full_stats++ = stats[index];
1893 if (nic_data->datapath_caps &
1894 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1895 /* Use vadaptor stats. */
1896 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1897 stats[EF10_STAT_rx_multicast] +
1898 stats[EF10_STAT_rx_broadcast];
1899 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1900 stats[EF10_STAT_tx_multicast] +
1901 stats[EF10_STAT_tx_broadcast];
1902 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1903 stats[EF10_STAT_rx_multicast_bytes] +
1904 stats[EF10_STAT_rx_broadcast_bytes];
1905 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1906 stats[EF10_STAT_tx_multicast_bytes] +
1907 stats[EF10_STAT_tx_broadcast_bytes];
1908 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
1909 stats[GENERIC_STAT_rx_noskb_drops];
1910 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1911 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1912 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1913 core_stats->rx_errors = core_stats->rx_crc_errors;
1914 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
1916 /* Use port stats. */
1917 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1918 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1919 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1920 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1921 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1922 stats[GENERIC_STAT_rx_nodesc_trunc] +
1923 stats[GENERIC_STAT_rx_noskb_drops];
1924 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1925 core_stats->rx_length_errors =
1926 stats[EF10_STAT_port_rx_gtjumbo] +
1927 stats[EF10_STAT_port_rx_length_error];
1928 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1929 core_stats->rx_frame_errors =
1930 stats[EF10_STAT_port_rx_align_error];
1931 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1932 core_stats->rx_errors = (core_stats->rx_length_errors +
1933 core_stats->rx_crc_errors +
1934 core_stats->rx_frame_errors);
1940 static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
1942 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1943 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1944 __le64 generation_start, generation_end;
1945 u64 *stats = nic_data->stats;
1948 efx_ef10_get_stat_mask(efx, mask);
1950 dma_stats = efx->stats_buffer.addr;
1952 generation_end = dma_stats[efx->num_mac_stats - 1];
1953 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1956 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1957 stats, efx->stats_buffer.addr, false);
1959 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1960 if (generation_end != generation_start)
1963 /* Update derived statistics */
1964 efx_nic_fix_nodesc_drop_stat(efx,
1965 &stats[EF10_STAT_port_rx_nodesc_drops]);
1966 stats[EF10_STAT_port_rx_good_bytes] =
1967 stats[EF10_STAT_port_rx_bytes] -
1968 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1969 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1970 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
1971 efx_update_sw_stats(efx, stats);
1976 static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1977 struct rtnl_link_stats64 *core_stats)
1981 /* If we're unlucky enough to read statistics during the DMA, wait
1982 * up to 10ms for it to finish (typically takes <500us)
1984 for (retry = 0; retry < 100; ++retry) {
1985 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
1990 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1993 static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1995 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1996 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1997 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1998 __le64 generation_start, generation_end;
1999 u64 *stats = nic_data->stats;
2000 u32 dma_len = efx->num_mac_stats * sizeof(u64);
2001 struct efx_buffer stats_buf;
2005 spin_unlock_bh(&efx->stats_lock);
2007 if (in_interrupt()) {
2008 /* If in atomic context, cannot update stats. Just update the
2009 * software stats and return so the caller can continue.
2011 spin_lock_bh(&efx->stats_lock);
2012 efx_update_sw_stats(efx, stats);
2016 efx_ef10_get_stat_mask(efx, mask);
2018 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
2020 spin_lock_bh(&efx->stats_lock);
2024 dma_stats = stats_buf.addr;
2025 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
2027 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
2028 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
2029 MAC_STATS_IN_DMA, 1);
2030 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
2031 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
2033 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
2035 spin_lock_bh(&efx->stats_lock);
2037 /* Expect ENOENT if DMA queues have not been set up */
2038 if (rc != -ENOENT || atomic_read(&efx->active_queues))
2039 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
2040 sizeof(inbuf), NULL, 0, rc);
2044 generation_end = dma_stats[efx->num_mac_stats - 1];
2045 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
2050 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
2051 stats, stats_buf.addr, false);
2053 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
2054 if (generation_end != generation_start) {
2059 efx_update_sw_stats(efx, stats);
2061 efx_nic_free_buffer(efx, &stats_buf);
2065 static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
2066 struct rtnl_link_stats64 *core_stats)
2068 if (efx_ef10_try_update_nic_stats_vf(efx))
2071 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
2074 static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
2076 struct efx_nic *efx = channel->efx;
2077 unsigned int mode, usecs;
2078 efx_dword_t timer_cmd;
2080 if (channel->irq_moderation_us) {
2082 usecs = channel->irq_moderation_us;
2088 if (EFX_EF10_WORKAROUND_61265(efx)) {
2089 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
2090 unsigned int ns = usecs * 1000;
2092 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
2094 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
2095 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
2096 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
2098 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
2099 inbuf, sizeof(inbuf), 0, NULL, 0);
2100 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
2101 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2103 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
2104 EFE_DD_EVQ_IND_TIMER_FLAGS,
2105 ERF_DD_EVQ_IND_TIMER_MODE, mode,
2106 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
2107 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
2110 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2112 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
2113 ERF_DZ_TC_TIMER_VAL, ticks,
2114 ERF_FZ_TC_TMR_REL_VAL, ticks);
2115 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
2120 static void efx_ef10_get_wol_vf(struct efx_nic *efx,
2121 struct ethtool_wolinfo *wol) {}
2123 static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
2128 static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
2132 memset(&wol->sopass, 0, sizeof(wol->sopass));
2135 static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
2142 static void efx_ef10_mcdi_request(struct efx_nic *efx,
2143 const efx_dword_t *hdr, size_t hdr_len,
2144 const efx_dword_t *sdu, size_t sdu_len)
2146 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2147 u8 *pdu = nic_data->mcdi_buf.addr;
2149 memcpy(pdu, hdr, hdr_len);
2150 memcpy(pdu + hdr_len, sdu, sdu_len);
2153 /* The hardware provides 'low' and 'high' (doorbell) registers
2154 * for passing the 64-bit address of an MCDI request to
2155 * firmware. However the dwords are swapped by firmware. The
2156 * least significant bits of the doorbell are then 0 for all
2157 * MCDI requests due to alignment.
2159 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
2161 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
2165 static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
2167 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2168 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
2171 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
2175 efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
2176 size_t offset, size_t outlen)
2178 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2179 const u8 *pdu = nic_data->mcdi_buf.addr;
2181 memcpy(outbuf, pdu + offset, outlen);
2184 static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
2186 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2188 /* All our allocations have been reset */
2189 efx_ef10_reset_mc_allocations(efx);
2191 /* The datapath firmware might have been changed */
2192 nic_data->must_check_datapath_caps = true;
2194 /* MAC statistics have been cleared on the NIC; clear the local
2195 * statistic that we update with efx_update_diff_stat().
2197 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
2200 static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2202 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2205 rc = efx_ef10_get_warm_boot_count(efx);
2207 /* The firmware is presumably in the process of
2208 * rebooting. However, we are supposed to report each
2209 * reboot just once, so we must only do that once we
2210 * can read and store the updated warm boot count.
2215 if (rc == nic_data->warm_boot_count)
2218 nic_data->warm_boot_count = rc;
2219 efx_ef10_mcdi_reboot_detected(efx);
2224 /* Handle an MSI interrupt
2226 * Handle an MSI hardware interrupt. This routine schedules event
2227 * queue processing. No interrupt acknowledgement cycle is necessary.
2228 * Also, we never need to check that the interrupt is for us, since
2229 * MSI interrupts cannot be shared.
2231 static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2233 struct efx_msi_context *context = dev_id;
2234 struct efx_nic *efx = context->efx;
2236 netif_vdbg(efx, intr, efx->net_dev,
2237 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2239 if (likely(READ_ONCE(efx->irq_soft_enabled))) {
2240 /* Note test interrupts */
2241 if (context->index == efx->irq_level)
2242 efx->last_irq_cpu = raw_smp_processor_id();
2244 /* Schedule processing of the channel */
2245 efx_schedule_channel_irq(efx->channel[context->index]);
2251 static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2253 struct efx_nic *efx = dev_id;
2254 bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
2255 struct efx_channel *channel;
2259 /* Read the ISR which also ACKs the interrupts */
2260 efx_readd(efx, ®, ER_DZ_BIU_INT_ISR);
2261 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2266 if (likely(soft_enabled)) {
2267 /* Note test interrupts */
2268 if (queues & (1U << efx->irq_level))
2269 efx->last_irq_cpu = raw_smp_processor_id();
2271 efx_for_each_channel(channel, efx) {
2273 efx_schedule_channel_irq(channel);
2278 netif_vdbg(efx, intr, efx->net_dev,
2279 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2280 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2285 static int efx_ef10_irq_test_generate(struct efx_nic *efx)
2287 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2289 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2293 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2295 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
2296 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
2297 inbuf, sizeof(inbuf), NULL, 0, NULL);
2300 static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2302 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2303 (tx_queue->ptr_mask + 1) *
2304 sizeof(efx_qword_t),
2308 /* This writes to the TX_DESC_WPTR and also pushes data */
2309 static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2310 const efx_qword_t *txd)
2312 unsigned int write_ptr;
2315 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2316 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2317 reg.qword[0] = *txd;
2318 efx_writeo_page(tx_queue->efx, ®,
2319 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2322 /* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2324 static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2325 struct sk_buff *skb,
2328 struct efx_tx_buffer *buffer;
2336 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
2338 mss = skb_shinfo(skb)->gso_size;
2340 if (unlikely(mss < 4)) {
2341 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2346 if (ip->version == 4) {
2347 /* Modify IPv4 header if needed. */
2350 ipv4_id = ntohs(ip->id);
2352 /* Modify IPv6 header if needed. */
2353 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2355 ipv6->payload_len = 0;
2360 seqnum = ntohl(tcp->seq);
2362 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2364 buffer->flags = EFX_TX_BUF_OPTION;
2366 buffer->unmap_len = 0;
2367 EFX_POPULATE_QWORD_5(buffer->option,
2368 ESF_DZ_TX_DESC_IS_OPT, 1,
2369 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2370 ESF_DZ_TX_TSO_OPTION_TYPE,
2371 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2372 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2373 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2375 ++tx_queue->insert_count;
2377 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2379 buffer->flags = EFX_TX_BUF_OPTION;
2381 buffer->unmap_len = 0;
2382 EFX_POPULATE_QWORD_4(buffer->option,
2383 ESF_DZ_TX_DESC_IS_OPT, 1,
2384 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2385 ESF_DZ_TX_TSO_OPTION_TYPE,
2386 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2387 ESF_DZ_TX_TSO_TCP_MSS, mss
2389 ++tx_queue->insert_count;
2394 static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2396 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2397 u32 tso_versions = 0;
2399 if (nic_data->datapath_caps &
2400 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2401 tso_versions |= BIT(1);
2402 if (nic_data->datapath_caps2 &
2403 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2404 tso_versions |= BIT(2);
2405 return tso_versions;
2408 static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2410 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2412 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2413 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2414 struct efx_channel *channel = tx_queue->channel;
2415 struct efx_nic *efx = tx_queue->efx;
2416 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2417 bool tso_v2 = false;
2419 dma_addr_t dma_addr;
2423 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
2425 /* Only attempt to enable TX timestamping if we have the license for it,
2426 * otherwise TXQ init will fail
2428 if (!(nic_data->licensed_features &
2429 (1 << LICENSED_V3_FEATURES_TX_TIMESTAMPS_LBN)))
2430 tx_queue->timestamping = false;
2432 /* TSOv2 is a limited resource that can only be configured on a limited
2433 * number of queues. TSO without checksum offload is not really a thing,
2434 * so we only enable it for those queues.
2435 * TSOv2 cannot be used with Hardware timestamping.
2437 if (csum_offload && (nic_data->datapath_caps2 &
2438 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) &&
2439 !tx_queue->timestamping) {
2441 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2445 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2446 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2447 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2448 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
2449 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
2450 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
2452 dma_addr = tx_queue->txd.buf.dma_addr;
2454 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2455 tx_queue->queue, entries, (u64)dma_addr);
2457 for (i = 0; i < entries; ++i) {
2458 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2459 dma_addr += EFX_BUF_SIZE;
2462 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2465 MCDI_POPULATE_DWORD_4(inbuf, INIT_TXQ_IN_FLAGS,
2466 /* This flag was removed from mcdi_pcol.h for
2467 * the non-_EXT version of INIT_TXQ. However,
2468 * firmware still honours it.
2470 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2471 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2472 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload,
2473 INIT_TXQ_EXT_IN_FLAG_TIMESTAMP,
2474 tx_queue->timestamping);
2476 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2478 if (rc == -ENOSPC && tso_v2) {
2479 /* Retry without TSOv2 if we're short on contexts. */
2481 netif_warn(efx, probe, efx->net_dev,
2482 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2484 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2485 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2491 /* A previous user of this TX queue might have set us up the
2492 * bomb by writing a descriptor to the TX push collector but
2493 * not the doorbell. (Each collector belongs to a port, not a
2494 * queue or function, so cannot easily be reset.) We must
2495 * attempt to push a no-op descriptor in its place.
2497 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2498 tx_queue->insert_count = 1;
2499 txd = efx_tx_desc(tx_queue, 0);
2500 EFX_POPULATE_QWORD_5(*txd,
2501 ESF_DZ_TX_DESC_IS_OPT, true,
2502 ESF_DZ_TX_OPTION_TYPE,
2503 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2504 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2505 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload,
2506 ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
2507 tx_queue->write_count = 1;
2510 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2511 tx_queue->tso_version = 2;
2512 } else if (nic_data->datapath_caps &
2513 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2514 tx_queue->tso_version = 1;
2518 efx_ef10_push_tx_desc(tx_queue, txd);
2523 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2527 static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2529 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
2530 MCDI_DECLARE_BUF_ERR(outbuf);
2531 struct efx_nic *efx = tx_queue->efx;
2535 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2538 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
2539 outbuf, sizeof(outbuf), &outlen);
2541 if (rc && rc != -EALREADY)
2547 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2548 outbuf, outlen, rc);
2551 static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2553 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2556 /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2557 static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2559 unsigned int write_ptr;
2562 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2563 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2564 efx_writed_page(tx_queue->efx, ®,
2565 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2568 #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2570 static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2571 dma_addr_t dma_addr, unsigned int len)
2573 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2574 /* If we need to break across multiple descriptors we should
2575 * stop at a page boundary. This assumes the length limit is
2576 * greater than the page size.
2578 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2580 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2581 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2587 static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2589 unsigned int old_write_count = tx_queue->write_count;
2590 struct efx_tx_buffer *buffer;
2591 unsigned int write_ptr;
2594 tx_queue->xmit_more_available = false;
2595 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2599 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2600 buffer = &tx_queue->buffer[write_ptr];
2601 txd = efx_tx_desc(tx_queue, write_ptr);
2602 ++tx_queue->write_count;
2604 /* Create TX descriptor ring entry */
2605 if (buffer->flags & EFX_TX_BUF_OPTION) {
2606 *txd = buffer->option;
2607 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2608 /* PIO descriptor */
2609 tx_queue->packet_write_count = tx_queue->write_count;
2611 tx_queue->packet_write_count = tx_queue->write_count;
2612 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2613 EFX_POPULATE_QWORD_3(
2616 buffer->flags & EFX_TX_BUF_CONT,
2617 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2618 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2620 } while (tx_queue->write_count != tx_queue->insert_count);
2622 wmb(); /* Ensure descriptors are written before they are fetched */
2624 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2625 txd = efx_tx_desc(tx_queue,
2626 old_write_count & tx_queue->ptr_mask);
2627 efx_ef10_push_tx_desc(tx_queue, txd);
2630 efx_ef10_notify_tx_desc(tx_queue);
2634 #define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2635 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2636 #define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2637 1 << RSS_MODE_HASH_DST_PORT_LBN)
2638 #define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2639 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2640 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2641 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2642 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2643 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2644 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2645 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2646 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2647 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2649 static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2651 /* Firmware had a bug (sfc bug 61952) where it would not actually
2652 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2653 * This meant that it would always contain whatever was previously
2654 * in the MCDI buffer. Fortunately, all firmware versions with
2655 * this bug have the same default flags value for a newly-allocated
2656 * RSS context, and the only time we want to get the flags is just
2657 * after allocating. Moreover, the response has a 32-bit hole
2658 * where the context ID would be in the request, so we can use an
2659 * overlength buffer in the request and pre-fill the flags field
2660 * with what we believe the default to be. Thus if the firmware
2661 * has the bug, it will leave our pre-filled value in the flags
2662 * field of the response, and we will get the right answer.
2664 * However, this does mean that this function should NOT be used if
2665 * the RSS context flags might not be their defaults - it is ONLY
2666 * reliably correct for a newly-allocated RSS context.
2668 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2669 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2673 /* Check we have a hole for the context ID */
2674 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2675 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2676 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2677 RSS_CONTEXT_FLAGS_DEFAULT);
2678 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2679 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2681 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2684 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2689 /* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2690 * If we fail, we just leave the RSS context at its default hash settings,
2691 * which is safe but may slightly reduce performance.
2692 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2693 * just need to set the UDP ports flags (for both IP versions).
2695 static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2697 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2700 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2702 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2704 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2705 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2706 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2707 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
2708 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2710 /* Succeeded, so UDP 4-tuple is now enabled */
2711 efx->rx_hash_udp_4tuple = true;
2714 static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2715 bool exclusive, unsigned *context_size)
2717 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2718 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
2719 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2722 u32 alloc_type = exclusive ?
2723 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2724 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2725 unsigned rss_spread = exclusive ?
2727 min(rounddown_pow_of_two(efx->rss_spread),
2728 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2730 if (!exclusive && rss_spread == 1) {
2731 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2737 if (nic_data->datapath_caps &
2738 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2741 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
2742 nic_data->vport_id);
2743 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2744 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
2746 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2747 outbuf, sizeof(outbuf), &outlen);
2751 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2754 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2757 *context_size = rss_spread;
2759 if (nic_data->datapath_caps &
2760 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2761 efx_ef10_set_rss_flags(efx, *context);
2766 static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2768 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2771 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2774 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2779 static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2780 const u32 *rx_indir_table, const u8 *key)
2782 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2783 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2786 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2788 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2789 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2791 /* This iterates over the length of efx->rx_indir_table, but copies
2792 * bytes from rx_indir_table. That's because the latter is a pointer
2793 * rather than an array, but should have the same length.
2794 * The efx->rx_hash_key loop below is similar.
2796 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2798 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
2799 (u8) rx_indir_table[i];
2801 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2802 sizeof(tablebuf), NULL, 0, NULL);
2806 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2808 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2809 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2810 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2811 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
2813 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2814 sizeof(keybuf), NULL, 0, NULL);
2817 static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2819 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2821 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2822 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2823 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2826 static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2827 unsigned *context_size)
2829 u32 new_rx_rss_context;
2830 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2831 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2832 false, context_size);
2837 nic_data->rx_rss_context = new_rx_rss_context;
2838 nic_data->rx_rss_context_exclusive = false;
2839 efx_set_default_rx_indir_table(efx);
2843 static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2844 const u32 *rx_indir_table,
2847 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2849 u32 new_rx_rss_context;
2851 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2852 !nic_data->rx_rss_context_exclusive) {
2853 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2855 if (rc == -EOPNOTSUPP)
2860 new_rx_rss_context = nic_data->rx_rss_context;
2863 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2864 rx_indir_table, key);
2868 if (nic_data->rx_rss_context != new_rx_rss_context)
2869 efx_ef10_rx_free_indir_table(efx);
2870 nic_data->rx_rss_context = new_rx_rss_context;
2871 nic_data->rx_rss_context_exclusive = true;
2872 if (rx_indir_table != efx->rx_indir_table)
2873 memcpy(efx->rx_indir_table, rx_indir_table,
2874 sizeof(efx->rx_indir_table));
2875 if (key != efx->rx_hash_key)
2876 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2881 if (new_rx_rss_context != nic_data->rx_rss_context)
2882 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2884 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2888 static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2890 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2891 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2892 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2893 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2897 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2898 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2900 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2903 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2904 nic_data->rx_rss_context);
2905 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2906 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2907 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2908 tablebuf, sizeof(tablebuf), &outlen);
2912 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2915 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2916 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2917 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2919 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2920 nic_data->rx_rss_context);
2921 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2922 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2923 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2924 keybuf, sizeof(keybuf), &outlen);
2928 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2931 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2932 efx->rx_hash_key[i] = MCDI_PTR(
2933 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2938 static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2939 const u32 *rx_indir_table,
2944 if (efx->rss_spread == 1)
2948 key = efx->rx_hash_key;
2950 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
2952 if (rc == -ENOBUFS && !user) {
2953 unsigned context_size;
2954 bool mismatch = false;
2957 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2959 mismatch = rx_indir_table[i] !=
2960 ethtool_rxfh_indir_default(i, efx->rss_spread);
2962 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2964 if (context_size != efx->rss_spread)
2965 netif_warn(efx, probe, efx->net_dev,
2966 "Could not allocate an exclusive RSS"
2967 " context; allocated a shared one of"
2969 " Wanted %u, got %u.\n",
2970 efx->rss_spread, context_size);
2972 netif_warn(efx, probe, efx->net_dev,
2973 "Could not allocate an exclusive RSS"
2974 " context; allocated a shared one but"
2975 " could not apply custom"
2978 netif_info(efx, probe, efx->net_dev,
2979 "Could not allocate an exclusive RSS"
2980 " context; allocated a shared one.\n");
2986 static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2987 const u32 *rx_indir_table
2988 __attribute__ ((unused)),
2990 __attribute__ ((unused)))
2992 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2996 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2998 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
3001 static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
3003 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
3004 (rx_queue->ptr_mask + 1) *
3005 sizeof(efx_qword_t),
3009 static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
3011 MCDI_DECLARE_BUF(inbuf,
3012 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
3014 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3015 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
3016 struct efx_nic *efx = rx_queue->efx;
3017 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3019 dma_addr_t dma_addr;
3022 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
3024 rx_queue->scatter_n = 0;
3025 rx_queue->scatter_len = 0;
3027 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
3028 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
3029 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
3030 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
3031 efx_rx_queue_index(rx_queue));
3032 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
3033 INIT_RXQ_IN_FLAG_PREFIX, 1,
3034 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
3035 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
3036 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
3038 dma_addr = rx_queue->rxd.buf.dma_addr;
3040 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
3041 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
3043 for (i = 0; i < entries; ++i) {
3044 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
3045 dma_addr += EFX_BUF_SIZE;
3048 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
3050 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
3053 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
3054 efx_rx_queue_index(rx_queue));
3057 static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
3059 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
3060 MCDI_DECLARE_BUF_ERR(outbuf);
3061 struct efx_nic *efx = rx_queue->efx;
3065 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
3066 efx_rx_queue_index(rx_queue));
3068 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
3069 outbuf, sizeof(outbuf), &outlen);
3071 if (rc && rc != -EALREADY)
3077 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
3078 outbuf, outlen, rc);
3081 static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
3083 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
3086 /* This creates an entry in the RX descriptor queue */
3088 efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
3090 struct efx_rx_buffer *rx_buf;
3093 rxd = efx_rx_desc(rx_queue, index);
3094 rx_buf = efx_rx_buffer(rx_queue, index);
3095 EFX_POPULATE_QWORD_2(*rxd,
3096 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
3097 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
3100 static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
3102 struct efx_nic *efx = rx_queue->efx;
3103 unsigned int write_count;
3106 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
3107 write_count = rx_queue->added_count & ~7;
3108 if (rx_queue->notified_count == write_count)
3112 efx_ef10_build_rx_desc(
3114 rx_queue->notified_count & rx_queue->ptr_mask);
3115 while (++rx_queue->notified_count != write_count);
3118 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
3119 write_count & rx_queue->ptr_mask);
3120 efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD,
3121 efx_rx_queue_index(rx_queue));
3124 static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
3126 static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
3128 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3129 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3132 EFX_POPULATE_QWORD_2(event,
3133 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3134 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
3136 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3138 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3139 * already swapped the data to little-endian order.
3141 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3142 sizeof(efx_qword_t));
3144 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
3145 inbuf, sizeof(inbuf), 0,
3146 efx_ef10_rx_defer_refill_complete, 0);
3150 efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
3151 int rc, efx_dword_t *outbuf,
3152 size_t outlen_actual)
3157 static int efx_ef10_ev_probe(struct efx_channel *channel)
3159 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
3160 (channel->eventq_mask + 1) *
3161 sizeof(efx_qword_t),
3165 static void efx_ef10_ev_fini(struct efx_channel *channel)
3167 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
3168 MCDI_DECLARE_BUF_ERR(outbuf);
3169 struct efx_nic *efx = channel->efx;
3173 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
3175 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
3176 outbuf, sizeof(outbuf), &outlen);
3178 if (rc && rc != -EALREADY)
3184 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
3185 outbuf, outlen, rc);
3188 static int efx_ef10_ev_init(struct efx_channel *channel)
3190 MCDI_DECLARE_BUF(inbuf,
3191 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
3193 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
3194 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
3195 struct efx_nic *efx = channel->efx;
3196 struct efx_ef10_nic_data *nic_data;
3197 size_t inlen, outlen;
3198 unsigned int enabled, implemented;
3199 dma_addr_t dma_addr;
3203 nic_data = efx->nic_data;
3205 /* Fill event queue with all ones (i.e. empty events) */
3206 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
3208 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
3209 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
3210 /* INIT_EVQ expects index in vector table, not absolute */
3211 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
3212 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3213 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3214 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3215 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3216 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3217 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3218 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3220 if (nic_data->datapath_caps2 &
3221 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3222 /* Use the new generic approach to specifying event queue
3223 * configuration, requesting lower latency or higher throughput.
3224 * The options that actually get used appear in the output.
3226 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3227 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3228 INIT_EVQ_V2_IN_FLAG_TYPE,
3229 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3231 bool cut_thru = !(nic_data->datapath_caps &
3232 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3234 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3235 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3236 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3237 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3238 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3241 dma_addr = channel->eventq.buf.dma_addr;
3242 for (i = 0; i < entries; ++i) {
3243 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3244 dma_addr += EFX_BUF_SIZE;
3247 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3249 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3250 outbuf, sizeof(outbuf), &outlen);
3252 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3253 netif_dbg(efx, drv, efx->net_dev,
3254 "Channel %d using event queue flags %08x\n",
3256 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3258 /* IRQ return is ignored */
3259 if (channel->channel || rc)
3262 /* Successfully created event queue on channel 0 */
3263 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
3264 if (rc == -ENOSYS) {
3265 /* GET_WORKAROUNDS was implemented before this workaround,
3266 * thus it must be unavailable in this firmware.
3268 nic_data->workaround_26807 = false;
3273 nic_data->workaround_26807 =
3274 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
3276 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3277 !nic_data->workaround_26807) {
3280 rc = efx_mcdi_set_workaround(efx,
3281 MC_CMD_WORKAROUND_BUG26807,
3286 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3287 netif_info(efx, drv, efx->net_dev,
3288 "other functions on NIC have been reset\n");
3290 /* With MCFW v4.6.x and earlier, the
3291 * boot count will have incremented,
3292 * so re-read the warm_boot_count
3293 * value now to ensure this function
3294 * doesn't think it has changed next
3297 rc = efx_ef10_get_warm_boot_count(efx);
3299 nic_data->warm_boot_count = rc;
3303 nic_data->workaround_26807 = true;
3304 } else if (rc == -EPERM) {
3314 efx_ef10_ev_fini(channel);
3318 static void efx_ef10_ev_remove(struct efx_channel *channel)
3320 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3323 static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3324 unsigned int rx_queue_label)
3326 struct efx_nic *efx = rx_queue->efx;
3328 netif_info(efx, hw, efx->net_dev,
3329 "rx event arrived on queue %d labeled as queue %u\n",
3330 efx_rx_queue_index(rx_queue), rx_queue_label);
3332 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3336 efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3337 unsigned int actual, unsigned int expected)
3339 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3340 struct efx_nic *efx = rx_queue->efx;
3342 netif_info(efx, hw, efx->net_dev,
3343 "dropped %d events (index=%d expected=%d)\n",
3344 dropped, actual, expected);
3346 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3349 /* partially received RX was aborted. clean up. */
3350 static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3352 unsigned int rx_desc_ptr;
3354 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3355 "scattered RX aborted (dropping %u buffers)\n",
3356 rx_queue->scatter_n);
3358 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3360 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3361 0, EFX_RX_PKT_DISCARD);
3363 rx_queue->removed_count += rx_queue->scatter_n;
3364 rx_queue->scatter_n = 0;
3365 rx_queue->scatter_len = 0;
3366 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3369 static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3370 unsigned int n_packets,
3371 unsigned int rx_encap_hdr,
3372 unsigned int rx_l3_class,
3373 unsigned int rx_l4_class,
3374 const efx_qword_t *event)
3376 struct efx_nic *efx = channel->efx;
3377 bool handled = false;
3379 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
3380 if (!(efx->net_dev->features & NETIF_F_RXALL)) {
3381 if (!efx->loopback_selftest)
3382 channel->n_rx_eth_crc_err += n_packets;
3383 return EFX_RX_PKT_DISCARD;
3387 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3388 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3389 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3390 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3391 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3392 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3393 netdev_WARN(efx->net_dev,
3394 "invalid class for RX_IPCKSUM_ERR: event="
3396 EFX_QWORD_VAL(*event));
3397 if (!efx->loopback_selftest)
3399 &channel->n_rx_outer_ip_hdr_chksum_err :
3400 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3403 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3404 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3405 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3406 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3407 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3408 rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
3409 netdev_WARN(efx->net_dev,
3410 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3412 EFX_QWORD_VAL(*event));
3413 if (!efx->loopback_selftest)
3415 &channel->n_rx_outer_tcp_udp_chksum_err :
3416 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3419 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3420 if (unlikely(!rx_encap_hdr))
3421 netdev_WARN(efx->net_dev,
3422 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3424 EFX_QWORD_VAL(*event));
3425 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3426 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3427 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3428 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3429 netdev_WARN(efx->net_dev,
3430 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3432 EFX_QWORD_VAL(*event));
3433 if (!efx->loopback_selftest)
3434 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3437 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3438 if (unlikely(!rx_encap_hdr))
3439 netdev_WARN(efx->net_dev,
3440 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3442 EFX_QWORD_VAL(*event));
3443 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3444 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3445 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3446 rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
3447 netdev_WARN(efx->net_dev,
3448 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3450 EFX_QWORD_VAL(*event));
3451 if (!efx->loopback_selftest)
3452 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3456 WARN_ON(!handled); /* No error bits were recognised */
3460 static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3461 const efx_qword_t *event)
3463 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3464 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
3465 unsigned int n_descs, n_packets, i;
3466 struct efx_nic *efx = channel->efx;
3467 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3468 struct efx_rx_queue *rx_queue;
3473 if (unlikely(READ_ONCE(efx->reset_pending)))
3476 /* Basic packet information */
3477 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3478 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3479 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3480 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
3481 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
3482 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3484 nic_data->datapath_caps &
3485 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3486 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3487 ESE_EZ_ENCAP_HDR_NONE;
3489 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3490 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3492 EFX_QWORD_VAL(*event));
3494 rx_queue = efx_channel_get_rx_queue(channel);
3496 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3497 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3499 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3500 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3502 if (n_descs != rx_queue->scatter_n + 1) {
3503 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3505 /* detect rx abort */
3506 if (unlikely(n_descs == rx_queue->scatter_n)) {
3507 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3508 netdev_WARN(efx->net_dev,
3509 "invalid RX abort: scatter_n=%u event="
3511 rx_queue->scatter_n,
3512 EFX_QWORD_VAL(*event));
3513 efx_ef10_handle_rx_abort(rx_queue);
3517 /* Check that RX completion merging is valid, i.e.
3518 * the current firmware supports it and this is a
3519 * non-scattered packet.
3521 if (!(nic_data->datapath_caps &
3522 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3523 rx_queue->scatter_n != 0 || rx_cont) {
3524 efx_ef10_handle_rx_bad_lbits(
3525 rx_queue, next_ptr_lbits,
3526 (rx_queue->removed_count +
3527 rx_queue->scatter_n + 1) &
3528 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3532 /* Merged completion for multiple non-scattered packets */
3533 rx_queue->scatter_n = 1;
3534 rx_queue->scatter_len = 0;
3535 n_packets = n_descs;
3536 ++channel->n_rx_merge_events;
3537 channel->n_rx_merge_packets += n_packets;
3538 flags |= EFX_RX_PKT_PREFIX_LEN;
3540 ++rx_queue->scatter_n;
3541 rx_queue->scatter_len += rx_bytes;
3547 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3548 ESF_DZ_RX_IPCKSUM_ERR, 1,
3549 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3550 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3551 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3552 EFX_AND_QWORD(errors, *event, errors);
3553 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3554 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
3556 rx_l3_class, rx_l4_class,
3559 bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
3560 rx_l4_class == ESE_FZ_L4_CLASS_UDP;
3562 switch (rx_encap_hdr) {
3563 case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
3564 flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
3566 flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
3568 case ESE_EZ_ENCAP_HDR_GRE:
3569 case ESE_EZ_ENCAP_HDR_NONE:
3571 flags |= EFX_RX_PKT_CSUMMED;
3574 netdev_WARN(efx->net_dev,
3575 "unknown encapsulation type: event="
3577 EFX_QWORD_VAL(*event));
3581 if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
3582 flags |= EFX_RX_PKT_TCP;
3584 channel->irq_mod_score += 2 * n_packets;
3586 /* Handle received packet(s) */
3587 for (i = 0; i < n_packets; i++) {
3588 efx_rx_packet(rx_queue,
3589 rx_queue->removed_count & rx_queue->ptr_mask,
3590 rx_queue->scatter_n, rx_queue->scatter_len,
3592 rx_queue->removed_count += rx_queue->scatter_n;
3595 rx_queue->scatter_n = 0;
3596 rx_queue->scatter_len = 0;
3601 static u32 efx_ef10_extract_event_ts(efx_qword_t *event)
3605 tstamp = EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_HI);
3607 tstamp |= EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_LO);
3613 efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3615 struct efx_nic *efx = channel->efx;
3616 struct efx_tx_queue *tx_queue;
3617 unsigned int tx_ev_desc_ptr;
3618 unsigned int tx_ev_q_label;
3619 unsigned int tx_ev_type;
3622 if (unlikely(READ_ONCE(efx->reset_pending)))
3625 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3628 /* Get the transmit queue */
3629 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3630 tx_queue = efx_channel_get_tx_queue(channel,
3631 tx_ev_q_label % EFX_TXQ_TYPES);
3633 if (!tx_queue->timestamping) {
3634 /* Transmit completion */
3635 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3636 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3640 /* Transmit timestamps are only available for 8XXX series. They result
3641 * in three events per packet. These occur in order, and are:
3642 * - the normal completion event
3643 * - the low part of the timestamp
3644 * - the high part of the timestamp
3646 * Each part of the timestamp is itself split across two 16 bit
3647 * fields in the event.
3649 tx_ev_type = EFX_QWORD_FIELD(*event, ESF_EZ_TX_SOFT1);
3651 switch (tx_ev_type) {
3652 case TX_TIMESTAMP_EVENT_TX_EV_COMPLETION:
3653 /* In case of Queue flush or FLR, we might have received
3654 * the previous TX completion event but not the Timestamp
3657 if (tx_queue->completed_desc_ptr != tx_queue->ptr_mask)
3658 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3660 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event,
3661 ESF_DZ_TX_DESCR_INDX);
3662 tx_queue->completed_desc_ptr =
3663 tx_ev_desc_ptr & tx_queue->ptr_mask;
3666 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_LO:
3667 ts_part = efx_ef10_extract_event_ts(event);
3668 tx_queue->completed_timestamp_minor = ts_part;
3671 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_HI:
3672 ts_part = efx_ef10_extract_event_ts(event);
3673 tx_queue->completed_timestamp_major = ts_part;
3675 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3676 tx_queue->completed_desc_ptr = tx_queue->ptr_mask;
3680 netif_err(efx, hw, efx->net_dev,
3681 "channel %d unknown tx event type %d (data "
3682 EFX_QWORD_FMT ")\n",
3683 channel->channel, tx_ev_type,
3684 EFX_QWORD_VAL(*event));
3690 efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3692 struct efx_nic *efx = channel->efx;
3695 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3698 case ESE_DZ_DRV_TIMER_EV:
3699 case ESE_DZ_DRV_WAKE_UP_EV:
3701 case ESE_DZ_DRV_START_UP_EV:
3702 /* event queue init complete. ok. */
3705 netif_err(efx, hw, efx->net_dev,
3706 "channel %d unknown driver event type %d"
3707 " (data " EFX_QWORD_FMT ")\n",
3708 channel->channel, subcode,
3709 EFX_QWORD_VAL(*event));
3714 static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3717 struct efx_nic *efx = channel->efx;
3720 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3724 channel->event_test_cpu = raw_smp_processor_id();
3726 case EFX_EF10_REFILL:
3727 /* The queue must be empty, so we won't receive any rx
3728 * events, so efx_process_channel() won't refill the
3729 * queue. Refill it here
3731 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
3734 netif_err(efx, hw, efx->net_dev,
3735 "channel %d unknown driver event type %u"
3736 " (data " EFX_QWORD_FMT ")\n",
3737 channel->channel, (unsigned) subcode,
3738 EFX_QWORD_VAL(*event));
3742 static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3744 struct efx_nic *efx = channel->efx;
3745 efx_qword_t event, *p_event;
3746 unsigned int read_ptr;
3753 read_ptr = channel->eventq_read_ptr;
3756 p_event = efx_event(channel, read_ptr);
3759 if (!efx_event_present(&event))
3762 EFX_SET_QWORD(*p_event);
3766 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3768 netif_vdbg(efx, drv, efx->net_dev,
3769 "processing event on %d " EFX_QWORD_FMT "\n",
3770 channel->channel, EFX_QWORD_VAL(event));
3773 case ESE_DZ_EV_CODE_MCDI_EV:
3774 efx_mcdi_process_event(channel, &event);
3776 case ESE_DZ_EV_CODE_RX_EV:
3777 spent += efx_ef10_handle_rx_event(channel, &event);
3778 if (spent >= quota) {
3779 /* XXX can we split a merged event to
3780 * avoid going over-quota?
3786 case ESE_DZ_EV_CODE_TX_EV:
3787 efx_ef10_handle_tx_event(channel, &event);
3789 case ESE_DZ_EV_CODE_DRIVER_EV:
3790 efx_ef10_handle_driver_event(channel, &event);
3791 if (++spent == quota)
3794 case EFX_EF10_DRVGEN_EV:
3795 efx_ef10_handle_driver_generated_event(channel, &event);
3798 netif_err(efx, hw, efx->net_dev,
3799 "channel %d unknown event type %d"
3800 " (data " EFX_QWORD_FMT ")\n",
3801 channel->channel, ev_code,
3802 EFX_QWORD_VAL(event));
3807 channel->eventq_read_ptr = read_ptr;
3811 static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3813 struct efx_nic *efx = channel->efx;
3816 if (EFX_EF10_WORKAROUND_35388(efx)) {
3817 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3818 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3819 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3820 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3822 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3823 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3824 ERF_DD_EVQ_IND_RPTR,
3825 (channel->eventq_read_ptr &
3826 channel->eventq_mask) >>
3827 ERF_DD_EVQ_IND_RPTR_WIDTH);
3828 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3830 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3831 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3832 ERF_DD_EVQ_IND_RPTR,
3833 channel->eventq_read_ptr &
3834 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3835 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3838 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3839 channel->eventq_read_ptr &
3840 channel->eventq_mask);
3841 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3845 static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3847 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3848 struct efx_nic *efx = channel->efx;
3852 EFX_POPULATE_QWORD_2(event,
3853 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3854 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3856 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3858 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3859 * already swapped the data to little-endian order.
3861 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3862 sizeof(efx_qword_t));
3864 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3873 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3876 void efx_ef10_handle_drain_event(struct efx_nic *efx)
3878 if (atomic_dec_and_test(&efx->active_queues))
3879 wake_up(&efx->flush_wq);
3881 WARN_ON(atomic_read(&efx->active_queues) < 0);
3884 static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3886 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3887 struct efx_channel *channel;
3888 struct efx_tx_queue *tx_queue;
3889 struct efx_rx_queue *rx_queue;
3892 /* If the MC has just rebooted, the TX/RX queues will have already been
3893 * torn down, but efx->active_queues needs to be set to zero.
3895 if (nic_data->must_realloc_vis) {
3896 atomic_set(&efx->active_queues, 0);
3900 /* Do not attempt to write to the NIC during EEH recovery */
3901 if (efx->state != STATE_RECOVERY) {
3902 efx_for_each_channel(channel, efx) {
3903 efx_for_each_channel_rx_queue(rx_queue, channel)
3904 efx_ef10_rx_fini(rx_queue);
3905 efx_for_each_channel_tx_queue(tx_queue, channel)
3906 efx_ef10_tx_fini(tx_queue);
3909 wait_event_timeout(efx->flush_wq,
3910 atomic_read(&efx->active_queues) == 0,
3911 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3912 pending = atomic_read(&efx->active_queues);
3914 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3923 static void efx_ef10_prepare_flr(struct efx_nic *efx)
3925 atomic_set(&efx->active_queues, 0);
3928 static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3929 const struct efx_filter_spec *right)
3931 if ((left->match_flags ^ right->match_flags) |
3932 ((left->flags ^ right->flags) &
3933 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3936 return memcmp(&left->outer_vid, &right->outer_vid,
3937 sizeof(struct efx_filter_spec) -
3938 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3941 static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3943 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3944 return jhash2((const u32 *)&spec->outer_vid,
3945 (sizeof(struct efx_filter_spec) -
3946 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3948 /* XXX should we randomise the initval? */
3951 /* Decide whether a filter should be exclusive or else should allow
3952 * delivery to additional recipients. Currently we decide that
3953 * filters for specific local unicast MAC and IP addresses are
3956 static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3958 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3959 !is_multicast_ether_addr(spec->loc_mac))
3962 if ((spec->match_flags &
3963 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3964 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3965 if (spec->ether_type == htons(ETH_P_IP) &&
3966 !ipv4_is_multicast(spec->loc_host[0]))
3968 if (spec->ether_type == htons(ETH_P_IPV6) &&
3969 ((const u8 *)spec->loc_host)[0] != 0xff)
3976 static struct efx_filter_spec *
3977 efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3978 unsigned int filter_idx)
3980 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3981 ~EFX_EF10_FILTER_FLAGS);
3985 efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3986 unsigned int filter_idx)
3988 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3992 efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3993 unsigned int filter_idx,
3994 const struct efx_filter_spec *spec,
3997 table->entry[filter_idx].spec = (unsigned long)spec | flags;
4001 efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
4002 const struct efx_filter_spec *spec,
4005 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
4006 u32 match_fields = 0, uc_match, mc_match;
4008 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4009 efx_ef10_filter_is_exclusive(spec) ?
4010 MC_CMD_FILTER_OP_IN_OP_INSERT :
4011 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
4013 /* Convert match flags and values. Unlike almost
4014 * everything else in MCDI, these fields are in
4015 * network byte order.
4017 #define COPY_VALUE(value, mcdi_field) \
4020 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4021 mcdi_field ## _LBN; \
4023 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
4025 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
4026 &value, sizeof(value)); \
4028 #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
4029 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
4030 COPY_VALUE(spec->gen_field, mcdi_field); \
4032 /* Handle encap filters first. They will always be mismatch
4033 * (unknown UC or MC) filters
4036 /* ether_type and outer_ip_proto need to be variables
4037 * because COPY_VALUE wants to memcpy them
4040 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
4041 ETH_P_IPV6 : ETH_P_IP);
4042 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
4045 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
4046 case EFX_ENCAP_TYPE_VXLAN:
4047 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
4049 case EFX_ENCAP_TYPE_GENEVE:
4050 COPY_VALUE(ether_type, ETHER_TYPE);
4051 outer_ip_proto = IPPROTO_UDP;
4052 COPY_VALUE(outer_ip_proto, IP_PROTO);
4053 /* We always need to set the type field, even
4054 * though we're not matching on the TNI.
4056 MCDI_POPULATE_DWORD_1(inbuf,
4057 FILTER_OP_EXT_IN_VNI_OR_VSID,
4058 FILTER_OP_EXT_IN_VNI_TYPE,
4061 case EFX_ENCAP_TYPE_NVGRE:
4062 COPY_VALUE(ether_type, ETHER_TYPE);
4063 outer_ip_proto = IPPROTO_GRE;
4064 COPY_VALUE(outer_ip_proto, IP_PROTO);
4070 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4071 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4073 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4074 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4077 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
4079 is_multicast_ether_addr(spec->loc_mac) ?
4082 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
4083 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
4084 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
4085 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
4086 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
4087 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
4088 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
4089 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
4090 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
4091 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
4094 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
4098 static void efx_ef10_filter_push_prep(struct efx_nic *efx,
4099 const struct efx_filter_spec *spec,
4100 efx_dword_t *inbuf, u64 handle,
4103 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4104 u32 flags = spec->flags;
4106 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
4108 /* Remove RSS flag if we don't have an RSS context. */
4109 if (flags & EFX_FILTER_FLAG_RX_RSS &&
4110 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4111 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
4112 flags &= ~EFX_FILTER_FLAG_RX_RSS;
4115 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4116 MC_CMD_FILTER_OP_IN_OP_REPLACE);
4117 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
4119 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
4122 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
4123 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
4124 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4125 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
4126 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
4127 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
4128 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
4129 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
4130 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
4131 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4133 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
4134 (flags & EFX_FILTER_FLAG_RX_RSS) ?
4135 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
4136 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
4137 if (flags & EFX_FILTER_FLAG_RX_RSS)
4138 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
4139 spec->rss_context !=
4140 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
4141 spec->rss_context : nic_data->rx_rss_context);
4144 static int efx_ef10_filter_push(struct efx_nic *efx,
4145 const struct efx_filter_spec *spec,
4146 u64 *handle, bool replacing)
4148 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4149 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
4152 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
4153 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4154 outbuf, sizeof(outbuf), NULL);
4156 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4158 rc = -EBUSY; /* to match efx_farch_filter_insert() */
4162 static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
4164 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
4165 unsigned int match_flags = spec->match_flags;
4166 unsigned int uc_match, mc_match;
4169 #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
4170 unsigned int old_match_flags = match_flags; \
4171 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
4172 if (match_flags != old_match_flags) \
4175 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
4176 mcdi_field ## _LBN : \
4177 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
4178 mcdi_field ## _LBN)); \
4180 /* inner or outer based on encap type */
4181 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
4182 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
4183 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
4184 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
4185 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
4186 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
4187 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
4188 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
4190 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
4191 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
4192 #undef MAP_FILTER_TO_MCDI_FLAG
4194 /* special handling for encap type, and mismatch */
4196 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
4198 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4199 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4201 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4202 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4204 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4205 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4208 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
4209 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
4211 is_multicast_ether_addr(spec->loc_mac) ?
4216 /* Did we map them all? */
4217 WARN_ON_ONCE(match_flags);
4222 static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
4223 const struct efx_filter_spec *spec)
4225 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4226 unsigned int match_pri;
4229 match_pri < table->rx_match_count;
4231 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
4234 return -EPROTONOSUPPORT;
4237 static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4238 struct efx_filter_spec *spec,
4241 struct efx_ef10_filter_table *table = efx->filter_state;
4242 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4243 struct efx_filter_spec *saved_spec;
4244 unsigned int match_pri, hash;
4245 unsigned int priv_flags;
4246 bool replacing = false;
4252 /* For now, only support RX filters */
4253 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4257 rc = efx_ef10_filter_pri(table, spec);
4262 hash = efx_ef10_filter_hash(spec);
4263 is_mc_recip = efx_filter_is_mc_recipient(spec);
4265 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4267 /* Find any existing filters with the same match tuple or
4268 * else a free slot to insert at. If any of them are busy,
4269 * we have to wait and retry.
4272 unsigned int depth = 1;
4275 spin_lock_bh(&efx->filter_lock);
4278 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4279 saved_spec = efx_ef10_filter_entry_spec(table, i);
4284 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4285 if (table->entry[i].spec &
4286 EFX_EF10_FILTER_FLAG_BUSY)
4288 if (spec->priority < saved_spec->priority &&
4289 spec->priority != EFX_FILTER_PRI_AUTO) {
4294 /* This is the only one */
4295 if (spec->priority ==
4296 saved_spec->priority &&
4303 } else if (spec->priority >
4304 saved_spec->priority ||
4306 saved_spec->priority &&
4311 __set_bit(depth, mc_rem_map);
4315 /* Once we reach the maximum search depth, use
4316 * the first suitable slot or return -EBUSY if
4319 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4320 if (ins_index < 0) {
4330 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4331 spin_unlock_bh(&efx->filter_lock);
4336 /* Create a software table entry if necessary, and mark it
4337 * busy. We might yet fail to insert, but any attempt to
4338 * insert a conflicting filter while we're waiting for the
4339 * firmware must find the busy entry.
4341 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4343 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4344 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
4345 /* Just make sure it won't be removed */
4346 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4347 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
4348 table->entry[ins_index].spec &=
4349 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
4354 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4356 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4361 *saved_spec = *spec;
4364 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4365 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4367 /* Mark lower-priority multicast recipients busy prior to removal */
4369 unsigned int depth, i;
4371 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4372 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4373 if (test_bit(depth, mc_rem_map))
4374 table->entry[i].spec |=
4375 EFX_EF10_FILTER_FLAG_BUSY;
4379 spin_unlock_bh(&efx->filter_lock);
4381 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4384 /* Finalise the software table entry */
4385 spin_lock_bh(&efx->filter_lock);
4388 /* Update the fields that may differ */
4389 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4390 saved_spec->flags |=
4391 EFX_FILTER_FLAG_RX_OVER_AUTO;
4392 saved_spec->priority = spec->priority;
4393 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
4394 saved_spec->flags |= spec->flags;
4395 saved_spec->rss_context = spec->rss_context;
4396 saved_spec->dmaq_id = spec->dmaq_id;
4398 } else if (!replacing) {
4402 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4404 /* Remove and finalise entries for lower-priority multicast
4408 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4409 unsigned int depth, i;
4411 memset(inbuf, 0, sizeof(inbuf));
4413 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4414 if (!test_bit(depth, mc_rem_map))
4417 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4418 saved_spec = efx_ef10_filter_entry_spec(table, i);
4419 priv_flags = efx_ef10_filter_entry_flags(table, i);
4422 spin_unlock_bh(&efx->filter_lock);
4423 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4424 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4425 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4426 table->entry[i].handle);
4427 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4428 inbuf, sizeof(inbuf),
4430 spin_lock_bh(&efx->filter_lock);
4438 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4440 efx_ef10_filter_set_entry(table, i, saved_spec,
4445 /* If successful, return the inserted filter ID */
4447 rc = efx_ef10_make_filter_id(match_pri, ins_index);
4449 wake_up_all(&table->waitq);
4451 spin_unlock_bh(&efx->filter_lock);
4452 finish_wait(&table->waitq, &wait);
4456 static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
4458 /* no need to do anything here on EF10 */
4462 * If !by_index, remove by ID
4463 * If by_index, remove by index
4464 * Filter ID may come from userland and must be range-checked.
4466 static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4467 unsigned int priority_mask,
4468 u32 filter_id, bool by_index)
4470 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
4471 struct efx_ef10_filter_table *table = efx->filter_state;
4472 MCDI_DECLARE_BUF(inbuf,
4473 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4474 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4475 struct efx_filter_spec *spec;
4479 /* Find the software table entry and mark it busy. Don't
4480 * remove it yet; any attempt to update while we're waiting
4481 * for the firmware must find the busy entry.
4484 spin_lock_bh(&efx->filter_lock);
4485 if (!(table->entry[filter_idx].spec &
4486 EFX_EF10_FILTER_FLAG_BUSY))
4488 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4489 spin_unlock_bh(&efx->filter_lock);
4493 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4496 efx_ef10_filter_pri(table, spec) !=
4497 efx_ef10_filter_get_unsafe_pri(filter_id))) {
4502 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
4503 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
4504 /* Just remove flags */
4505 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
4506 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
4511 if (!(priority_mask & (1U << spec->priority))) {
4516 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4517 spin_unlock_bh(&efx->filter_lock);
4519 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
4520 /* Reset to an automatic filter */
4522 struct efx_filter_spec new_spec = *spec;
4524 new_spec.priority = EFX_FILTER_PRI_AUTO;
4525 new_spec.flags = (EFX_FILTER_FLAG_RX |
4526 (efx_rss_enabled(efx) ?
4527 EFX_FILTER_FLAG_RX_RSS : 0));
4528 new_spec.dmaq_id = 0;
4529 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4530 rc = efx_ef10_filter_push(efx, &new_spec,
4531 &table->entry[filter_idx].handle,
4534 spin_lock_bh(&efx->filter_lock);
4538 /* Really remove the filter */
4540 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4541 efx_ef10_filter_is_exclusive(spec) ?
4542 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4543 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4544 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4545 table->entry[filter_idx].handle);
4546 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4547 inbuf, sizeof(inbuf), NULL, 0, NULL);
4549 spin_lock_bh(&efx->filter_lock);
4550 if ((rc == 0) || (rc == -ENOENT)) {
4551 /* Filter removed OK or didn't actually exist */
4553 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4555 efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
4556 MC_CMD_FILTER_OP_EXT_IN_LEN,
4561 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4562 wake_up_all(&table->waitq);
4564 spin_unlock_bh(&efx->filter_lock);
4565 finish_wait(&table->waitq, &wait);
4569 static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4570 enum efx_filter_priority priority,
4573 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4577 static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4578 enum efx_filter_priority priority,
4581 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4583 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
4586 static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4587 enum efx_filter_priority priority,
4588 u32 filter_id, struct efx_filter_spec *spec)
4590 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
4591 struct efx_ef10_filter_table *table = efx->filter_state;
4592 const struct efx_filter_spec *saved_spec;
4595 spin_lock_bh(&efx->filter_lock);
4596 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4597 if (saved_spec && saved_spec->priority == priority &&
4598 efx_ef10_filter_pri(table, saved_spec) ==
4599 efx_ef10_filter_get_unsafe_pri(filter_id)) {
4600 *spec = *saved_spec;
4605 spin_unlock_bh(&efx->filter_lock);
4609 static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
4610 enum efx_filter_priority priority)
4612 unsigned int priority_mask;
4616 priority_mask = (((1U << (priority + 1)) - 1) &
4617 ~(1U << EFX_FILTER_PRI_AUTO));
4619 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4620 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4622 if (rc && rc != -ENOENT)
4629 static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4630 enum efx_filter_priority priority)
4632 struct efx_ef10_filter_table *table = efx->filter_state;
4633 unsigned int filter_idx;
4636 spin_lock_bh(&efx->filter_lock);
4637 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4638 if (table->entry[filter_idx].spec &&
4639 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4643 spin_unlock_bh(&efx->filter_lock);
4647 static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4649 struct efx_ef10_filter_table *table = efx->filter_state;
4651 return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
4654 static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4655 enum efx_filter_priority priority,
4658 struct efx_ef10_filter_table *table = efx->filter_state;
4659 struct efx_filter_spec *spec;
4660 unsigned int filter_idx;
4663 spin_lock_bh(&efx->filter_lock);
4664 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4665 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4666 if (spec && spec->priority == priority) {
4667 if (count == size) {
4672 efx_ef10_make_filter_id(
4673 efx_ef10_filter_pri(table, spec),
4677 spin_unlock_bh(&efx->filter_lock);
4681 #ifdef CONFIG_RFS_ACCEL
4683 static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4685 static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4686 struct efx_filter_spec *spec)
4688 struct efx_ef10_filter_table *table = efx->filter_state;
4689 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4690 struct efx_filter_spec *saved_spec;
4691 unsigned int hash, i, depth = 1;
4692 bool replacing = false;
4697 /* Must be an RX filter without RSS and not for a multicast
4698 * destination address (RFS only works for connected sockets).
4699 * These restrictions allow us to pass only a tiny amount of
4700 * data through to the completion function.
4702 EFX_WARN_ON_PARANOID(spec->flags !=
4703 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4704 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4705 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4707 hash = efx_ef10_filter_hash(spec);
4709 spin_lock_bh(&efx->filter_lock);
4711 /* Find any existing filter with the same match tuple or else
4712 * a free slot to insert at. If an existing filter is busy,
4713 * we have to give up.
4716 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4717 saved_spec = efx_ef10_filter_entry_spec(table, i);
4722 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4723 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4727 if (spec->priority < saved_spec->priority) {
4735 /* Once we reach the maximum search depth, use the
4736 * first suitable slot or return -EBUSY if there was
4739 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4740 if (ins_index < 0) {
4750 /* Create a software table entry if necessary, and mark it
4751 * busy. We might yet fail to insert, but any attempt to
4752 * insert a conflicting filter while we're waiting for the
4753 * firmware must find the busy entry.
4755 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4759 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4764 *saved_spec = *spec;
4766 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4767 EFX_EF10_FILTER_FLAG_BUSY);
4769 spin_unlock_bh(&efx->filter_lock);
4771 /* Pack up the variables needed on completion */
4772 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4774 efx_ef10_filter_push_prep(efx, spec, inbuf,
4775 table->entry[ins_index].handle, replacing);
4776 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4777 MC_CMD_FILTER_OP_OUT_LEN,
4778 efx_ef10_filter_rfs_insert_complete, cookie);
4783 spin_unlock_bh(&efx->filter_lock);
4788 efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4789 int rc, efx_dword_t *outbuf,
4790 size_t outlen_actual)
4792 struct efx_ef10_filter_table *table = efx->filter_state;
4793 unsigned int ins_index, dmaq_id;
4794 struct efx_filter_spec *spec;
4797 /* Unpack the cookie */
4798 replacing = cookie >> 31;
4799 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4800 dmaq_id = cookie & 0xffff;
4802 spin_lock_bh(&efx->filter_lock);
4803 spec = efx_ef10_filter_entry_spec(table, ins_index);
4805 table->entry[ins_index].handle =
4806 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4808 spec->dmaq_id = dmaq_id;
4809 } else if (!replacing) {
4813 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4814 spin_unlock_bh(&efx->filter_lock);
4816 wake_up_all(&table->waitq);
4820 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4821 unsigned long filter_idx,
4822 int rc, efx_dword_t *outbuf,
4823 size_t outlen_actual);
4825 static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4826 unsigned int filter_idx)
4828 struct efx_ef10_filter_table *table = efx->filter_state;
4829 struct efx_filter_spec *spec =
4830 efx_ef10_filter_entry_spec(table, filter_idx);
4831 MCDI_DECLARE_BUF(inbuf,
4832 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4833 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4836 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4837 spec->priority != EFX_FILTER_PRI_HINT ||
4838 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4839 flow_id, filter_idx))
4842 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4843 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4844 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4845 table->entry[filter_idx].handle);
4846 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4847 efx_ef10_filter_rfs_expire_complete, filter_idx))
4850 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4855 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4856 unsigned long filter_idx,
4857 int rc, efx_dword_t *outbuf,
4858 size_t outlen_actual)
4860 struct efx_ef10_filter_table *table = efx->filter_state;
4861 struct efx_filter_spec *spec =
4862 efx_ef10_filter_entry_spec(table, filter_idx);
4864 spin_lock_bh(&efx->filter_lock);
4867 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4869 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4870 wake_up_all(&table->waitq);
4871 spin_unlock_bh(&efx->filter_lock);
4874 #endif /* CONFIG_RFS_ACCEL */
4876 static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
4878 int match_flags = 0;
4880 #define MAP_FLAG(gen_flag, mcdi_field) do { \
4881 u32 old_mcdi_flags = mcdi_flags; \
4882 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4883 mcdi_field ## _LBN); \
4884 if (mcdi_flags != old_mcdi_flags) \
4885 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4889 /* encap filters must specify encap type */
4890 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4891 /* and imply ethertype and ip proto */
4893 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4895 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4896 /* VLAN tags refer to the outer packet */
4897 MAP_FLAG(INNER_VID, INNER_VLAN);
4898 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4899 /* everything else refers to the inner packet */
4900 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4901 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4902 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4903 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4904 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4905 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4906 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4907 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4908 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4909 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4911 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4912 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4913 MAP_FLAG(REM_HOST, SRC_IP);
4914 MAP_FLAG(LOC_HOST, DST_IP);
4915 MAP_FLAG(REM_MAC, SRC_MAC);
4916 MAP_FLAG(REM_PORT, SRC_PORT);
4917 MAP_FLAG(LOC_MAC, DST_MAC);
4918 MAP_FLAG(LOC_PORT, DST_PORT);
4919 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4920 MAP_FLAG(INNER_VID, INNER_VLAN);
4921 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4922 MAP_FLAG(IP_PROTO, IP_PROTO);
4926 /* Did we map them all? */
4933 static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4935 struct efx_ef10_filter_table *table = efx->filter_state;
4936 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4938 /* See comment in efx_ef10_filter_table_remove() */
4939 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4945 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4946 efx_ef10_filter_del_vlan_internal(efx, vlan);
4949 static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4951 enum efx_filter_match_flags match_flags)
4953 unsigned int match_pri;
4957 match_pri < table->rx_match_count;
4959 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
4960 table->rx_match_mcdi_flags[match_pri]);
4961 if (mf == match_flags)
4969 efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4970 struct efx_ef10_filter_table *table,
4973 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4974 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4975 unsigned int pd_match_pri, pd_match_count;
4979 /* Find out which RX filter types are supported, and their priorities */
4980 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4982 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
4983 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4984 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4985 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4990 pd_match_count = MCDI_VAR_ARRAY_LEN(
4991 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4993 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4997 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4999 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
5001 netif_dbg(efx, probe, efx->net_dev,
5002 "%s: fw flags %#x pri %u not supported in driver\n",
5003 __func__, mcdi_flags, pd_match_pri);
5005 netif_dbg(efx, probe, efx->net_dev,
5006 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
5007 __func__, mcdi_flags, pd_match_pri,
5008 rc, table->rx_match_count);
5009 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
5010 table->rx_match_count++;
5017 static int efx_ef10_filter_table_probe(struct efx_nic *efx)
5019 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5020 struct net_device *net_dev = efx->net_dev;
5021 struct efx_ef10_filter_table *table;
5022 struct efx_ef10_vlan *vlan;
5025 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5028 if (efx->filter_state) /* already probed */
5031 table = kzalloc(sizeof(*table), GFP_KERNEL);
5035 table->rx_match_count = 0;
5036 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
5039 if (nic_data->datapath_caps &
5040 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5041 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
5044 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
5045 !(efx_ef10_filter_match_supported(table, false,
5046 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
5047 efx_ef10_filter_match_supported(table, false,
5048 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
5049 netif_info(efx, probe, net_dev,
5050 "VLAN filters are not supported in this firmware variant\n");
5051 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5052 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5053 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5056 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
5057 if (!table->entry) {
5062 table->mc_promisc_last = false;
5063 table->vlan_filter =
5064 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5065 INIT_LIST_HEAD(&table->vlan_list);
5067 efx->filter_state = table;
5068 init_waitqueue_head(&table->waitq);
5070 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
5071 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
5079 efx_ef10_filter_cleanup_vlans(efx);
5080 efx->filter_state = NULL;
5086 /* Caller must hold efx->filter_sem for read if race against
5087 * efx_ef10_filter_table_remove() is possible
5089 static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5091 struct efx_ef10_filter_table *table = efx->filter_state;
5092 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5093 unsigned int invalid_filters = 0, failed = 0;
5094 struct efx_ef10_filter_vlan *vlan;
5095 struct efx_filter_spec *spec;
5096 unsigned int filter_idx;
5101 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5103 if (!nic_data->must_restore_filters)
5109 spin_lock_bh(&efx->filter_lock);
5111 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5112 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5116 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
5118 while (match_pri < table->rx_match_count &&
5119 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
5121 if (match_pri >= table->rx_match_count) {
5125 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
5126 spec->rss_context != nic_data->rx_rss_context)
5127 netif_warn(efx, drv, efx->net_dev,
5128 "Warning: unable to restore a filter with specific RSS context.\n");
5130 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
5131 spin_unlock_bh(&efx->filter_lock);
5133 rc = efx_ef10_filter_push(efx, spec,
5134 &table->entry[filter_idx].handle,
5138 spin_lock_bh(&efx->filter_lock);
5142 list_for_each_entry(vlan, &table->vlan_list, list)
5143 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
5144 if (vlan->default_filters[i] == filter_idx)
5145 vlan->default_filters[i] =
5146 EFX_EF10_FILTER_ID_INVALID;
5149 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
5151 table->entry[filter_idx].spec &=
5152 ~EFX_EF10_FILTER_FLAG_BUSY;
5156 spin_unlock_bh(&efx->filter_lock);
5158 /* This can happen validly if the MC's capabilities have changed, so
5161 if (invalid_filters)
5162 netif_dbg(efx, drv, efx->net_dev,
5163 "Did not restore %u filters that are now unsupported.\n",
5167 netif_err(efx, hw, efx->net_dev,
5168 "unable to restore %u filters\n", failed);
5170 nic_data->must_restore_filters = false;
5173 static void efx_ef10_filter_table_remove(struct efx_nic *efx)
5175 struct efx_ef10_filter_table *table = efx->filter_state;
5176 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
5177 struct efx_filter_spec *spec;
5178 unsigned int filter_idx;
5181 efx_ef10_filter_cleanup_vlans(efx);
5182 efx->filter_state = NULL;
5183 /* If we were called without locking, then it's not safe to free
5184 * the table as others might be using it. So we just WARN, leak
5185 * the memory, and potentially get an inconsistent filter table
5187 * This should never actually happen.
5189 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5195 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5196 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5200 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
5201 efx_ef10_filter_is_exclusive(spec) ?
5202 MC_CMD_FILTER_OP_IN_OP_REMOVE :
5203 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
5204 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
5205 table->entry[filter_idx].handle);
5206 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
5207 sizeof(inbuf), NULL, 0, NULL);
5209 netif_info(efx, drv, efx->net_dev,
5210 "%s: filter %04x remove failed\n",
5211 __func__, filter_idx);
5215 vfree(table->entry);
5219 static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5221 struct efx_ef10_filter_table *table = efx->filter_state;
5222 unsigned int filter_idx;
5224 if (*id != EFX_EF10_FILTER_ID_INVALID) {
5225 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
5226 if (!table->entry[filter_idx].spec)
5227 netif_dbg(efx, drv, efx->net_dev,
5228 "marked null spec old %04x:%04x\n", *id,
5230 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
5231 *id = EFX_EF10_FILTER_ID_INVALID;
5235 /* Mark old per-VLAN filters that may need to be removed */
5236 static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
5237 struct efx_ef10_filter_vlan *vlan)
5239 struct efx_ef10_filter_table *table = efx->filter_state;
5242 for (i = 0; i < table->dev_uc_count; i++)
5243 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
5244 for (i = 0; i < table->dev_mc_count; i++)
5245 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
5246 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5247 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
5250 /* Mark old filters that may need to be removed.
5251 * Caller must hold efx->filter_sem for read if race against
5252 * efx_ef10_filter_table_remove() is possible
5254 static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5256 struct efx_ef10_filter_table *table = efx->filter_state;
5257 struct efx_ef10_filter_vlan *vlan;
5259 spin_lock_bh(&efx->filter_lock);
5260 list_for_each_entry(vlan, &table->vlan_list, list)
5261 _efx_ef10_filter_vlan_mark_old(efx, vlan);
5262 spin_unlock_bh(&efx->filter_lock);
5265 static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
5267 struct efx_ef10_filter_table *table = efx->filter_state;
5268 struct net_device *net_dev = efx->net_dev;
5269 struct netdev_hw_addr *uc;
5272 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
5273 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
5275 netdev_for_each_uc_addr(uc, net_dev) {
5276 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
5277 table->uc_promisc = true;
5280 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
5284 table->dev_uc_count = i;
5287 static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
5289 struct efx_ef10_filter_table *table = efx->filter_state;
5290 struct net_device *net_dev = efx->net_dev;
5291 struct netdev_hw_addr *mc;
5294 table->mc_overflow = false;
5295 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
5298 netdev_for_each_mc_addr(mc, net_dev) {
5299 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
5300 table->mc_promisc = true;
5301 table->mc_overflow = true;
5304 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5308 table->dev_mc_count = i;
5311 static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
5312 struct efx_ef10_filter_vlan *vlan,
5313 bool multicast, bool rollback)
5315 struct efx_ef10_filter_table *table = efx->filter_state;
5316 struct efx_ef10_dev_addr *addr_list;
5317 enum efx_filter_flags filter_flags;
5318 struct efx_filter_spec spec;
5326 addr_list = table->dev_mc_list;
5327 addr_count = table->dev_mc_count;
5330 addr_list = table->dev_uc_list;
5331 addr_count = table->dev_uc_count;
5335 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5337 /* Insert/renew filters */
5338 for (i = 0; i < addr_count; i++) {
5339 EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
5340 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5341 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
5342 rc = efx_ef10_filter_insert(efx, &spec, true);
5345 netif_info(efx, drv, efx->net_dev,
5346 "efx_ef10_filter_insert failed rc=%d\n",
5348 /* Fall back to promiscuous */
5349 for (j = 0; j < i; j++) {
5350 efx_ef10_filter_remove_unsafe(
5351 efx, EFX_FILTER_PRI_AUTO,
5353 ids[j] = EFX_EF10_FILTER_ID_INVALID;
5357 /* keep invalid ID, and carry on */
5360 ids[i] = efx_ef10_filter_get_unsafe_id(rc);
5364 if (multicast && rollback) {
5365 /* Also need an Ethernet broadcast filter */
5366 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5367 EFX_EF10_FILTER_ID_INVALID);
5368 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5369 eth_broadcast_addr(baddr);
5370 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
5371 rc = efx_ef10_filter_insert(efx, &spec, true);
5373 netif_warn(efx, drv, efx->net_dev,
5374 "Broadcast filter insert failed rc=%d\n", rc);
5375 /* Fall back to promiscuous */
5376 for (j = 0; j < i; j++) {
5377 efx_ef10_filter_remove_unsafe(
5378 efx, EFX_FILTER_PRI_AUTO,
5380 ids[j] = EFX_EF10_FILTER_ID_INVALID;
5384 vlan->default_filters[EFX_EF10_BCAST] =
5385 efx_ef10_filter_get_unsafe_id(rc);
5392 static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5393 struct efx_ef10_filter_vlan *vlan,
5394 enum efx_encap_type encap_type,
5395 bool multicast, bool rollback)
5397 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5398 enum efx_filter_flags filter_flags;
5399 struct efx_filter_spec spec;
5404 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5406 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5409 efx_filter_set_mc_def(&spec);
5411 efx_filter_set_uc_def(&spec);
5414 if (nic_data->datapath_caps &
5415 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5416 efx_filter_set_encap_type(&spec, encap_type);
5418 /* don't insert encap filters on non-supporting
5419 * platforms. ID will be left as INVALID.
5424 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5425 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5427 rc = efx_ef10_filter_insert(efx, &spec, true);
5429 const char *um = multicast ? "Multicast" : "Unicast";
5430 const char *encap_name = "";
5431 const char *encap_ipv = "";
5433 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5434 EFX_ENCAP_TYPE_VXLAN)
5435 encap_name = "VXLAN ";
5436 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5437 EFX_ENCAP_TYPE_NVGRE)
5438 encap_name = "NVGRE ";
5439 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5440 EFX_ENCAP_TYPE_GENEVE)
5441 encap_name = "GENEVE ";
5442 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5443 encap_ipv = "IPv6 ";
5444 else if (encap_type)
5445 encap_ipv = "IPv4 ";
5447 /* unprivileged functions can't insert mismatch filters
5448 * for encapsulated or unicast traffic, so downgrade
5449 * those warnings to debug.
5451 netif_cond_dbg(efx, drv, efx->net_dev,
5452 rc == -EPERM && (encap_type || !multicast), warn,
5453 "%s%s%s mismatch filter insert failed rc=%d\n",
5454 encap_name, encap_ipv, um, rc);
5455 } else if (multicast) {
5456 /* mapping from encap types to default filter IDs (multicast) */
5457 static enum efx_ef10_default_filters map[] = {
5458 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5459 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5460 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5461 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5462 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5463 EFX_EF10_VXLAN6_MCDEF,
5464 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5465 EFX_EF10_NVGRE6_MCDEF,
5466 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5467 EFX_EF10_GENEVE6_MCDEF,
5470 /* quick bounds check (BCAST result impossible) */
5471 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
5472 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
5476 /* then follow map */
5477 id = &vlan->default_filters[map[encap_type]];
5479 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5480 *id = efx_ef10_filter_get_unsafe_id(rc);
5481 if (!nic_data->workaround_26807 && !encap_type) {
5482 /* Also need an Ethernet broadcast filter */
5483 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
5485 eth_broadcast_addr(baddr);
5486 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
5487 rc = efx_ef10_filter_insert(efx, &spec, true);
5489 netif_warn(efx, drv, efx->net_dev,
5490 "Broadcast filter insert failed rc=%d\n",
5493 /* Roll back the mc_def filter */
5494 efx_ef10_filter_remove_unsafe(
5495 efx, EFX_FILTER_PRI_AUTO,
5497 *id = EFX_EF10_FILTER_ID_INVALID;
5501 EFX_WARN_ON_PARANOID(
5502 vlan->default_filters[EFX_EF10_BCAST] !=
5503 EFX_EF10_FILTER_ID_INVALID);
5504 vlan->default_filters[EFX_EF10_BCAST] =
5505 efx_ef10_filter_get_unsafe_id(rc);
5510 /* mapping from encap types to default filter IDs (unicast) */
5511 static enum efx_ef10_default_filters map[] = {
5512 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5513 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5514 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5515 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5516 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5517 EFX_EF10_VXLAN6_UCDEF,
5518 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5519 EFX_EF10_NVGRE6_UCDEF,
5520 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5521 EFX_EF10_GENEVE6_UCDEF,
5524 /* quick bounds check (BCAST result impossible) */
5525 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
5526 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
5530 /* then follow map */
5531 id = &vlan->default_filters[map[encap_type]];
5532 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5539 /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5540 * flag or removes these filters, we don't need to hold the filter_lock while
5541 * scanning for these filters.
5543 static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5545 struct efx_ef10_filter_table *table = efx->filter_state;
5546 int remove_failed = 0;
5547 int remove_noent = 0;
5551 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
5552 if (READ_ONCE(table->entry[i].spec) &
5553 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
5554 rc = efx_ef10_filter_remove_internal(efx,
5555 1U << EFX_FILTER_PRI_AUTO, i, true);
5564 netif_info(efx, drv, efx->net_dev,
5565 "%s: failed to remove %d filters\n",
5566 __func__, remove_failed);
5568 netif_info(efx, drv, efx->net_dev,
5569 "%s: failed to remove %d non-existent filters\n",
5570 __func__, remove_noent);
5573 static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5575 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5576 u8 mac_old[ETH_ALEN];
5579 /* Only reconfigure a PF-created vport */
5580 if (is_zero_ether_addr(nic_data->vport_mac))
5583 efx_device_detach_sync(efx);
5584 efx_net_stop(efx->net_dev);
5585 down_write(&efx->filter_sem);
5586 efx_ef10_filter_table_remove(efx);
5587 up_write(&efx->filter_sem);
5589 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5591 goto restore_filters;
5593 ether_addr_copy(mac_old, nic_data->vport_mac);
5594 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5595 nic_data->vport_mac);
5597 goto restore_vadaptor;
5599 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5600 efx->net_dev->dev_addr);
5602 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5604 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5606 /* Failed to add original MAC, so clear vport_mac */
5607 eth_zero_addr(nic_data->vport_mac);
5613 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5617 down_write(&efx->filter_sem);
5618 rc2 = efx_ef10_filter_table_probe(efx);
5619 up_write(&efx->filter_sem);
5623 rc2 = efx_net_open(efx->net_dev);
5627 efx_device_attach_if_not_resetting(efx);
5632 netif_err(efx, drv, efx->net_dev,
5633 "Failed to restore when changing MAC address - scheduling reset\n");
5634 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5636 return rc ? rc : rc2;
5639 /* Caller must hold efx->filter_sem for read if race against
5640 * efx_ef10_filter_table_remove() is possible
5642 static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5643 struct efx_ef10_filter_vlan *vlan)
5645 struct efx_ef10_filter_table *table = efx->filter_state;
5646 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5648 /* Do not install unspecified VID if VLAN filtering is enabled.
5649 * Do not install all specified VIDs if VLAN filtering is disabled.
5651 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5654 /* Insert/renew unicast filters */
5655 if (table->uc_promisc) {
5656 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5658 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
5660 /* If any of the filters failed to insert, fall back to
5661 * promiscuous mode - add in the uc_def filter. But keep
5662 * our individual unicast filters.
5664 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
5665 efx_ef10_filter_insert_def(efx, vlan,
5666 EFX_ENCAP_TYPE_NONE,
5669 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5671 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5672 EFX_ENCAP_FLAG_IPV6,
5674 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5676 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5677 EFX_ENCAP_FLAG_IPV6,
5679 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5681 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5682 EFX_ENCAP_FLAG_IPV6,
5685 /* Insert/renew multicast filters */
5686 /* If changing promiscuous state with cascaded multicast filters, remove
5687 * old filters first, so that packets are dropped rather than duplicated
5689 if (nic_data->workaround_26807 &&
5690 table->mc_promisc_last != table->mc_promisc)
5691 efx_ef10_filter_remove_old(efx);
5692 if (table->mc_promisc) {
5693 if (nic_data->workaround_26807) {
5694 /* If we failed to insert promiscuous filters, rollback
5695 * and fall back to individual multicast filters
5697 if (efx_ef10_filter_insert_def(efx, vlan,
5698 EFX_ENCAP_TYPE_NONE,
5700 /* Changing promisc state, so remove old filters */
5701 efx_ef10_filter_remove_old(efx);
5702 efx_ef10_filter_insert_addr_list(efx, vlan,
5706 /* If we failed to insert promiscuous filters, don't
5707 * rollback. Regardless, also insert the mc_list,
5708 * unless it's incomplete due to overflow
5710 efx_ef10_filter_insert_def(efx, vlan,
5711 EFX_ENCAP_TYPE_NONE,
5713 if (!table->mc_overflow)
5714 efx_ef10_filter_insert_addr_list(efx, vlan,
5718 /* If any filters failed to insert, rollback and fall back to
5719 * promiscuous mode - mc_def filter and maybe broadcast. If
5720 * that fails, roll back again and insert as many of our
5721 * individual multicast filters as we can.
5723 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
5724 /* Changing promisc state, so remove old filters */
5725 if (nic_data->workaround_26807)
5726 efx_ef10_filter_remove_old(efx);
5727 if (efx_ef10_filter_insert_def(efx, vlan,
5728 EFX_ENCAP_TYPE_NONE,
5730 efx_ef10_filter_insert_addr_list(efx, vlan,
5734 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5736 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5737 EFX_ENCAP_FLAG_IPV6,
5739 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5741 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5742 EFX_ENCAP_FLAG_IPV6,
5744 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5746 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5747 EFX_ENCAP_FLAG_IPV6,
5751 /* Caller must hold efx->filter_sem for read if race against
5752 * efx_ef10_filter_table_remove() is possible
5754 static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5756 struct efx_ef10_filter_table *table = efx->filter_state;
5757 struct net_device *net_dev = efx->net_dev;
5758 struct efx_ef10_filter_vlan *vlan;
5761 if (!efx_dev_registered(efx))
5767 efx_ef10_filter_mark_old(efx);
5769 /* Copy/convert the address lists; add the primary station
5770 * address and broadcast address
5772 netif_addr_lock_bh(net_dev);
5773 efx_ef10_filter_uc_addr_list(efx);
5774 efx_ef10_filter_mc_addr_list(efx);
5775 netif_addr_unlock_bh(net_dev);
5777 /* If VLAN filtering changes, all old filters are finally removed.
5778 * Do it in advance to avoid conflicts for unicast untagged and
5779 * VLAN 0 tagged filters.
5781 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5782 if (table->vlan_filter != vlan_filter) {
5783 table->vlan_filter = vlan_filter;
5784 efx_ef10_filter_remove_old(efx);
5787 list_for_each_entry(vlan, &table->vlan_list, list)
5788 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5790 efx_ef10_filter_remove_old(efx);
5791 table->mc_promisc_last = table->mc_promisc;
5794 static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5796 struct efx_ef10_filter_table *table = efx->filter_state;
5797 struct efx_ef10_filter_vlan *vlan;
5799 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5801 list_for_each_entry(vlan, &table->vlan_list, list) {
5802 if (vlan->vid == vid)
5809 static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5811 struct efx_ef10_filter_table *table = efx->filter_state;
5812 struct efx_ef10_filter_vlan *vlan;
5815 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5818 vlan = efx_ef10_filter_find_vlan(efx, vid);
5819 if (WARN_ON(vlan)) {
5820 netif_err(efx, drv, efx->net_dev,
5821 "VLAN %u already added\n", vid);
5825 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5831 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5832 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5833 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5834 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5835 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5836 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
5838 list_add_tail(&vlan->list, &table->vlan_list);
5840 if (efx_dev_registered(efx))
5841 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5846 static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5847 struct efx_ef10_filter_vlan *vlan)
5851 /* See comment in efx_ef10_filter_table_remove() */
5852 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5855 list_del(&vlan->list);
5857 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5858 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5860 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5861 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5863 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5864 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5865 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5866 vlan->default_filters[i]);
5871 static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5873 struct efx_ef10_filter_vlan *vlan;
5875 /* See comment in efx_ef10_filter_table_remove() */
5876 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5879 vlan = efx_ef10_filter_find_vlan(efx, vid);
5881 netif_err(efx, drv, efx->net_dev,
5882 "VLAN %u not found in filter state\n", vid);
5886 efx_ef10_filter_del_vlan_internal(efx, vlan);
5889 static int efx_ef10_set_mac_address(struct efx_nic *efx)
5891 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5892 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5893 bool was_enabled = efx->port_enabled;
5896 efx_device_detach_sync(efx);
5897 efx_net_stop(efx->net_dev);
5899 mutex_lock(&efx->mac_lock);
5900 down_write(&efx->filter_sem);
5901 efx_ef10_filter_table_remove(efx);
5903 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5904 efx->net_dev->dev_addr);
5905 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5906 nic_data->vport_id);
5907 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5908 sizeof(inbuf), NULL, 0, NULL);
5910 efx_ef10_filter_table_probe(efx);
5911 up_write(&efx->filter_sem);
5912 mutex_unlock(&efx->mac_lock);
5915 efx_net_open(efx->net_dev);
5916 efx_device_attach_if_not_resetting(efx);
5918 #ifdef CONFIG_SFC_SRIOV
5919 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
5920 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5923 struct efx_nic *efx_pf;
5925 /* Switch to PF and change MAC address on vport */
5926 efx_pf = pci_get_drvdata(pci_dev_pf);
5928 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
5930 efx->net_dev->dev_addr);
5932 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5933 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5936 /* MAC address successfully changed by VF (with MAC
5937 * spoofing) so update the parent PF if possible.
5939 for (i = 0; i < efx_pf->vf_count; ++i) {
5940 struct ef10_vf *vf = nic_data->vf + i;
5942 if (vf->efx == efx) {
5943 ether_addr_copy(vf->mac,
5944 efx->net_dev->dev_addr);
5952 netif_err(efx, drv, efx->net_dev,
5953 "Cannot change MAC address; use sfboot to enable"
5954 " mac-spoofing on this interface\n");
5955 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5956 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5957 * fall-back to the method of changing the MAC address on the
5958 * vport. This only applies to PFs because such versions of
5959 * MCFW do not support VFs.
5961 rc = efx_ef10_vport_set_mac_address(efx);
5963 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5964 sizeof(inbuf), NULL, 0, rc);
5970 static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5972 efx_ef10_filter_sync_rx_mode(efx);
5974 return efx_mcdi_set_mac(efx);
5977 static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5979 efx_ef10_filter_sync_rx_mode(efx);
5984 static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5986 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5988 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5989 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5993 /* MC BISTs follow a different poll mechanism to phy BISTs.
5994 * The BIST is done in the poll handler on the MC, and the MCDI command
5995 * will block until the BIST is done.
5997 static int efx_ef10_poll_bist(struct efx_nic *efx)
6000 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
6004 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
6005 outbuf, sizeof(outbuf), &outlen);
6009 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
6012 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
6014 case MC_CMD_POLL_BIST_PASSED:
6015 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
6017 case MC_CMD_POLL_BIST_TIMEOUT:
6018 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
6020 case MC_CMD_POLL_BIST_FAILED:
6021 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
6024 netif_err(efx, hw, efx->net_dev,
6025 "BIST returned unknown result %u", result);
6030 static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
6034 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
6036 rc = efx_ef10_start_bist(efx, bist_type);
6040 return efx_ef10_poll_bist(efx);
6044 efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
6048 efx_reset_down(efx, RESET_TYPE_WORLD);
6050 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
6051 NULL, 0, NULL, 0, NULL);
6055 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
6056 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
6058 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
6063 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
6064 return rc ? rc : rc2;
6067 #ifdef CONFIG_SFC_MTD
6069 struct efx_ef10_nvram_type_info {
6070 u16 type, type_mask;
6075 static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
6076 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
6077 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
6078 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
6079 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
6080 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
6081 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
6082 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
6083 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
6084 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
6085 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
6086 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
6089 static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
6090 struct efx_mcdi_mtd_partition *part,
6093 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
6094 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
6095 const struct efx_ef10_nvram_type_info *info;
6096 size_t size, erase_size, outlen;
6100 for (info = efx_ef10_nvram_types; ; info++) {
6102 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
6104 if ((type & ~info->type_mask) == info->type)
6107 if (info->port != efx_port_num(efx))
6110 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
6114 return -ENODEV; /* hide it */
6116 part->nvram_type = type;
6118 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
6119 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
6120 outbuf, sizeof(outbuf), &outlen);
6123 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
6125 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
6126 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
6127 part->fw_subtype = MCDI_DWORD(outbuf,
6128 NVRAM_METADATA_OUT_SUBTYPE);
6130 part->common.dev_type_name = "EF10 NVRAM manager";
6131 part->common.type_name = info->name;
6133 part->common.mtd.type = MTD_NORFLASH;
6134 part->common.mtd.flags = MTD_CAP_NORFLASH;
6135 part->common.mtd.size = size;
6136 part->common.mtd.erasesize = erase_size;
6141 static int efx_ef10_mtd_probe(struct efx_nic *efx)
6143 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
6144 struct efx_mcdi_mtd_partition *parts;
6145 size_t outlen, n_parts_total, i, n_parts;
6151 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
6152 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
6153 outbuf, sizeof(outbuf), &outlen);
6156 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
6159 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
6161 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
6164 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
6169 for (i = 0; i < n_parts_total; i++) {
6170 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
6172 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
6175 else if (rc != -ENODEV)
6179 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
6186 #endif /* CONFIG_SFC_MTD */
6188 static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
6190 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
6193 static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
6196 static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
6199 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
6202 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
6203 channel->sync_events_state == SYNC_EVENTS_VALID ||
6204 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
6206 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
6208 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
6209 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6210 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
6213 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6214 inbuf, sizeof(inbuf), NULL, 0, NULL);
6217 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6218 SYNC_EVENTS_DISABLED;
6223 static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
6226 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
6229 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
6230 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
6232 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
6233 channel->sync_events_state = SYNC_EVENTS_DISABLED;
6236 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6237 SYNC_EVENTS_DISABLED;
6239 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
6240 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6241 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
6242 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
6243 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
6246 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6247 inbuf, sizeof(inbuf), NULL, 0, NULL);
6252 static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
6255 int (*set)(struct efx_channel *channel, bool temp);
6256 struct efx_channel *channel;
6259 efx_ef10_rx_enable_timestamping :
6260 efx_ef10_rx_disable_timestamping;
6262 efx_for_each_channel(channel, efx) {
6263 int rc = set(channel, temp);
6264 if (en && rc != 0) {
6265 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
6273 static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
6274 struct hwtstamp_config *init)
6279 static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
6280 struct hwtstamp_config *init)
6284 switch (init->rx_filter) {
6285 case HWTSTAMP_FILTER_NONE:
6286 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
6287 /* if TX timestamping is still requested then leave PTP on */
6288 return efx_ptp_change_mode(efx,
6289 init->tx_type != HWTSTAMP_TX_OFF, 0);
6290 case HWTSTAMP_FILTER_ALL:
6291 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6292 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6293 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6294 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6295 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6296 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6297 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6298 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6299 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6300 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6301 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6302 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6303 case HWTSTAMP_FILTER_NTP_ALL:
6304 init->rx_filter = HWTSTAMP_FILTER_ALL;
6305 rc = efx_ptp_change_mode(efx, true, 0);
6307 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6309 efx_ptp_change_mode(efx, false, 0);
6316 static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6317 struct netdev_phys_item_id *ppid)
6319 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6321 if (!is_valid_ether_addr(nic_data->port_id))
6324 ppid->id_len = ETH_ALEN;
6325 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6330 static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6332 if (proto != htons(ETH_P_8021Q))
6335 return efx_ef10_add_vlan(efx, vid);
6338 static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6340 if (proto != htons(ETH_P_8021Q))
6343 return efx_ef10_del_vlan(efx, vid);
6346 /* We rely on the MCDI wiping out our TX rings if it made any changes to the
6347 * ports table, ensuring that any TSO descriptors that were made on a now-
6348 * removed tunnel port will be blown away and won't break things when we try
6349 * to transmit them using the new ports table.
6351 static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
6353 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6354 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
6355 MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
6356 bool will_reset = false;
6357 size_t num_entries = 0;
6358 size_t inlen, outlen;
6361 efx_dword_t flags_and_num_entries;
6363 WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
6365 nic_data->udp_tunnels_dirty = false;
6367 if (!(nic_data->datapath_caps &
6368 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
6369 efx_device_attach_if_not_resetting(efx);
6373 BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
6374 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
6376 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6377 if (nic_data->udp_tunnels[i].count &&
6378 nic_data->udp_tunnels[i].port) {
6381 EFX_POPULATE_DWORD_2(entry,
6382 TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
6383 ntohs(nic_data->udp_tunnels[i].port),
6384 TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
6385 nic_data->udp_tunnels[i].type);
6386 *_MCDI_ARRAY_DWORD(inbuf,
6387 SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
6388 num_entries++) = entry;
6392 BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
6393 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
6395 BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
6397 EFX_POPULATE_DWORD_2(flags_and_num_entries,
6398 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
6400 EFX_WORD_1, num_entries);
6401 *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
6402 flags_and_num_entries;
6404 inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
6406 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
6407 inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
6409 /* Most likely the MC rebooted due to another function also
6410 * setting its tunnel port list. Mark the tunnel port list as
6411 * dirty, so it will be pushed upon coming up from the reboot.
6413 nic_data->udp_tunnels_dirty = true;
6418 /* expected not available on unprivileged functions */
6420 netif_warn(efx, drv, efx->net_dev,
6421 "Unable to set UDP tunnel ports; rc=%d.\n", rc);
6422 } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
6423 (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
6424 netif_info(efx, drv, efx->net_dev,
6425 "Rebooting MC due to UDP tunnel port list change\n");
6428 /* Delay for the MC reset to complete. This will make
6429 * unloading other functions a bit smoother. This is a
6430 * race, but the other unload will work whichever way
6431 * it goes, this just avoids an unnecessary error
6436 if (!will_reset && !unloading) {
6437 /* The caller will have detached, relying on the MC reset to
6438 * trigger a re-attach. Since there won't be an MC reset, we
6439 * have to do the attach ourselves.
6441 efx_device_attach_if_not_resetting(efx);
6447 static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
6449 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6452 mutex_lock(&nic_data->udp_tunnels_lock);
6453 if (nic_data->udp_tunnels_dirty) {
6454 /* Make sure all TX are stopped while we modify the table, else
6455 * we might race against an efx_features_check().
6457 efx_device_detach_sync(efx);
6458 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6460 mutex_unlock(&nic_data->udp_tunnels_lock);
6464 static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
6467 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6470 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6471 if (!nic_data->udp_tunnels[i].count)
6473 if (nic_data->udp_tunnels[i].port == port)
6474 return &nic_data->udp_tunnels[i];
6479 static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
6480 struct efx_udp_tunnel tnl)
6482 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6483 struct efx_udp_tunnel *match;
6488 if (!(nic_data->datapath_caps &
6489 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6492 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6493 netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
6494 typebuf, ntohs(tnl.port));
6496 mutex_lock(&nic_data->udp_tunnels_lock);
6497 /* Make sure all TX are stopped while we add to the table, else we
6498 * might race against an efx_features_check().
6500 efx_device_detach_sync(efx);
6502 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6503 if (match != NULL) {
6504 if (match->type == tnl.type) {
6505 netif_dbg(efx, drv, efx->net_dev,
6506 "Referencing existing tunnel entry\n");
6508 /* No need to cause an MCDI update */
6512 efx_get_udp_tunnel_type_name(match->type,
6513 typebuf, sizeof(typebuf));
6514 netif_dbg(efx, drv, efx->net_dev,
6515 "UDP port %d is already in use by %s\n",
6516 ntohs(tnl.port), typebuf);
6521 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
6522 if (!nic_data->udp_tunnels[i].count) {
6523 nic_data->udp_tunnels[i] = tnl;
6524 nic_data->udp_tunnels[i].count = 1;
6525 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6529 netif_dbg(efx, drv, efx->net_dev,
6530 "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
6531 typebuf, ntohs(tnl.port));
6536 mutex_unlock(&nic_data->udp_tunnels_lock);
6540 /* Called under the TX lock with the TX queue running, hence no-one can be
6541 * in the middle of updating the UDP tunnels table. However, they could
6542 * have tried and failed the MCDI, in which case they'll have set the dirty
6543 * flag before dropping their locks.
6545 static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
6547 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6549 if (!(nic_data->datapath_caps &
6550 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6553 if (nic_data->udp_tunnels_dirty)
6554 /* SW table may not match HW state, so just assume we can't
6555 * use any UDP tunnel offloads.
6559 return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
6562 static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
6563 struct efx_udp_tunnel tnl)
6565 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6566 struct efx_udp_tunnel *match;
6570 if (!(nic_data->datapath_caps &
6571 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6574 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6575 netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
6576 typebuf, ntohs(tnl.port));
6578 mutex_lock(&nic_data->udp_tunnels_lock);
6579 /* Make sure all TX are stopped while we remove from the table, else we
6580 * might race against an efx_features_check().
6582 efx_device_detach_sync(efx);
6584 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6585 if (match != NULL) {
6586 if (match->type == tnl.type) {
6587 if (--match->count) {
6588 /* Port is still in use, so nothing to do */
6589 netif_dbg(efx, drv, efx->net_dev,
6590 "UDP tunnel port %d remains active\n",
6595 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6598 efx_get_udp_tunnel_type_name(match->type,
6599 typebuf, sizeof(typebuf));
6600 netif_warn(efx, drv, efx->net_dev,
6601 "UDP port %d is actually in use by %s, not removing\n",
6602 ntohs(tnl.port), typebuf);
6607 mutex_unlock(&nic_data->udp_tunnels_lock);
6611 #define EF10_OFFLOAD_FEATURES \
6612 (NETIF_F_IP_CSUM | \
6613 NETIF_F_HW_VLAN_CTAG_FILTER | \
6614 NETIF_F_IPV6_CSUM | \
6618 const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
6620 .mem_bar = efx_ef10_vf_mem_bar,
6621 .mem_map_size = efx_ef10_mem_map_size,
6622 .probe = efx_ef10_probe_vf,
6623 .remove = efx_ef10_remove,
6624 .dimension_resources = efx_ef10_dimension_resources,
6625 .init = efx_ef10_init_nic,
6626 .fini = efx_port_dummy_op_void,
6627 .map_reset_reason = efx_ef10_map_reset_reason,
6628 .map_reset_flags = efx_ef10_map_reset_flags,
6629 .reset = efx_ef10_reset,
6630 .probe_port = efx_mcdi_port_probe,
6631 .remove_port = efx_mcdi_port_remove,
6632 .fini_dmaq = efx_ef10_fini_dmaq,
6633 .prepare_flr = efx_ef10_prepare_flr,
6634 .finish_flr = efx_port_dummy_op_void,
6635 .describe_stats = efx_ef10_describe_stats,
6636 .update_stats = efx_ef10_update_stats_vf,
6637 .start_stats = efx_port_dummy_op_void,
6638 .pull_stats = efx_port_dummy_op_void,
6639 .stop_stats = efx_port_dummy_op_void,
6640 .set_id_led = efx_mcdi_set_id_led,
6641 .push_irq_moderation = efx_ef10_push_irq_moderation,
6642 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
6643 .check_mac_fault = efx_mcdi_mac_check_fault,
6644 .reconfigure_port = efx_mcdi_port_reconfigure,
6645 .get_wol = efx_ef10_get_wol_vf,
6646 .set_wol = efx_ef10_set_wol_vf,
6647 .resume_wol = efx_port_dummy_op_void,
6648 .mcdi_request = efx_ef10_mcdi_request,
6649 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6650 .mcdi_read_response = efx_ef10_mcdi_read_response,
6651 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
6652 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
6653 .irq_enable_master = efx_port_dummy_op_void,
6654 .irq_test_generate = efx_ef10_irq_test_generate,
6655 .irq_disable_non_ev = efx_port_dummy_op_void,
6656 .irq_handle_msi = efx_ef10_msi_interrupt,
6657 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6658 .tx_probe = efx_ef10_tx_probe,
6659 .tx_init = efx_ef10_tx_init,
6660 .tx_remove = efx_ef10_tx_remove,
6661 .tx_write = efx_ef10_tx_write,
6662 .tx_limit_len = efx_ef10_tx_limit_len,
6663 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
6664 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
6665 .rx_probe = efx_ef10_rx_probe,
6666 .rx_init = efx_ef10_rx_init,
6667 .rx_remove = efx_ef10_rx_remove,
6668 .rx_write = efx_ef10_rx_write,
6669 .rx_defer_refill = efx_ef10_rx_defer_refill,
6670 .ev_probe = efx_ef10_ev_probe,
6671 .ev_init = efx_ef10_ev_init,
6672 .ev_fini = efx_ef10_ev_fini,
6673 .ev_remove = efx_ef10_ev_remove,
6674 .ev_process = efx_ef10_ev_process,
6675 .ev_read_ack = efx_ef10_ev_read_ack,
6676 .ev_test_generate = efx_ef10_ev_test_generate,
6677 .filter_table_probe = efx_ef10_filter_table_probe,
6678 .filter_table_restore = efx_ef10_filter_table_restore,
6679 .filter_table_remove = efx_ef10_filter_table_remove,
6680 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6681 .filter_insert = efx_ef10_filter_insert,
6682 .filter_remove_safe = efx_ef10_filter_remove_safe,
6683 .filter_get_safe = efx_ef10_filter_get_safe,
6684 .filter_clear_rx = efx_ef10_filter_clear_rx,
6685 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6686 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6687 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6688 #ifdef CONFIG_RFS_ACCEL
6689 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6690 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6692 #ifdef CONFIG_SFC_MTD
6693 .mtd_probe = efx_port_dummy_op_int,
6695 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6696 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
6697 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6698 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
6699 #ifdef CONFIG_SFC_SRIOV
6700 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6701 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6702 .vswitching_remove = efx_ef10_vswitching_remove_vf,
6704 .get_mac_address = efx_ef10_get_mac_address_vf,
6705 .set_mac_address = efx_ef10_set_mac_address,
6707 .get_phys_port_id = efx_ef10_get_phys_port_id,
6708 .revision = EFX_REV_HUNT_A0,
6709 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6710 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6711 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6712 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6713 .can_rx_scatter = true,
6714 .always_rx_scatter = true,
6715 .min_interrupt_mode = EFX_INT_MODE_MSIX,
6716 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6717 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
6718 .offload_features = EF10_OFFLOAD_FEATURES,
6720 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6721 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6722 1 << HWTSTAMP_FILTER_ALL,
6723 .rx_hash_key_size = 40,
6726 const struct efx_nic_type efx_hunt_a0_nic_type = {
6728 .mem_bar = efx_ef10_pf_mem_bar,
6729 .mem_map_size = efx_ef10_mem_map_size,
6730 .probe = efx_ef10_probe_pf,
6731 .remove = efx_ef10_remove,
6732 .dimension_resources = efx_ef10_dimension_resources,
6733 .init = efx_ef10_init_nic,
6734 .fini = efx_port_dummy_op_void,
6735 .map_reset_reason = efx_ef10_map_reset_reason,
6736 .map_reset_flags = efx_ef10_map_reset_flags,
6737 .reset = efx_ef10_reset,
6738 .probe_port = efx_mcdi_port_probe,
6739 .remove_port = efx_mcdi_port_remove,
6740 .fini_dmaq = efx_ef10_fini_dmaq,
6741 .prepare_flr = efx_ef10_prepare_flr,
6742 .finish_flr = efx_port_dummy_op_void,
6743 .describe_stats = efx_ef10_describe_stats,
6744 .update_stats = efx_ef10_update_stats_pf,
6745 .start_stats = efx_mcdi_mac_start_stats,
6746 .pull_stats = efx_mcdi_mac_pull_stats,
6747 .stop_stats = efx_mcdi_mac_stop_stats,
6748 .set_id_led = efx_mcdi_set_id_led,
6749 .push_irq_moderation = efx_ef10_push_irq_moderation,
6750 .reconfigure_mac = efx_ef10_mac_reconfigure,
6751 .check_mac_fault = efx_mcdi_mac_check_fault,
6752 .reconfigure_port = efx_mcdi_port_reconfigure,
6753 .get_wol = efx_ef10_get_wol,
6754 .set_wol = efx_ef10_set_wol,
6755 .resume_wol = efx_port_dummy_op_void,
6756 .test_chip = efx_ef10_test_chip,
6757 .test_nvram = efx_mcdi_nvram_test_all,
6758 .mcdi_request = efx_ef10_mcdi_request,
6759 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6760 .mcdi_read_response = efx_ef10_mcdi_read_response,
6761 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
6762 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
6763 .irq_enable_master = efx_port_dummy_op_void,
6764 .irq_test_generate = efx_ef10_irq_test_generate,
6765 .irq_disable_non_ev = efx_port_dummy_op_void,
6766 .irq_handle_msi = efx_ef10_msi_interrupt,
6767 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6768 .tx_probe = efx_ef10_tx_probe,
6769 .tx_init = efx_ef10_tx_init,
6770 .tx_remove = efx_ef10_tx_remove,
6771 .tx_write = efx_ef10_tx_write,
6772 .tx_limit_len = efx_ef10_tx_limit_len,
6773 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
6774 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
6775 .rx_probe = efx_ef10_rx_probe,
6776 .rx_init = efx_ef10_rx_init,
6777 .rx_remove = efx_ef10_rx_remove,
6778 .rx_write = efx_ef10_rx_write,
6779 .rx_defer_refill = efx_ef10_rx_defer_refill,
6780 .ev_probe = efx_ef10_ev_probe,
6781 .ev_init = efx_ef10_ev_init,
6782 .ev_fini = efx_ef10_ev_fini,
6783 .ev_remove = efx_ef10_ev_remove,
6784 .ev_process = efx_ef10_ev_process,
6785 .ev_read_ack = efx_ef10_ev_read_ack,
6786 .ev_test_generate = efx_ef10_ev_test_generate,
6787 .filter_table_probe = efx_ef10_filter_table_probe,
6788 .filter_table_restore = efx_ef10_filter_table_restore,
6789 .filter_table_remove = efx_ef10_filter_table_remove,
6790 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6791 .filter_insert = efx_ef10_filter_insert,
6792 .filter_remove_safe = efx_ef10_filter_remove_safe,
6793 .filter_get_safe = efx_ef10_filter_get_safe,
6794 .filter_clear_rx = efx_ef10_filter_clear_rx,
6795 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6796 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6797 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6798 #ifdef CONFIG_RFS_ACCEL
6799 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6800 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6802 #ifdef CONFIG_SFC_MTD
6803 .mtd_probe = efx_ef10_mtd_probe,
6804 .mtd_rename = efx_mcdi_mtd_rename,
6805 .mtd_read = efx_mcdi_mtd_read,
6806 .mtd_erase = efx_mcdi_mtd_erase,
6807 .mtd_write = efx_mcdi_mtd_write,
6808 .mtd_sync = efx_mcdi_mtd_sync,
6810 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
6811 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6812 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
6813 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6814 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
6815 .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
6816 .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
6817 .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
6818 .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
6819 #ifdef CONFIG_SFC_SRIOV
6820 .sriov_configure = efx_ef10_sriov_configure,
6821 .sriov_init = efx_ef10_sriov_init,
6822 .sriov_fini = efx_ef10_sriov_fini,
6823 .sriov_wanted = efx_ef10_sriov_wanted,
6824 .sriov_reset = efx_ef10_sriov_reset,
6825 .sriov_flr = efx_ef10_sriov_flr,
6826 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6827 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6828 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6829 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
6830 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
6831 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6832 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6833 .vswitching_remove = efx_ef10_vswitching_remove_pf,
6835 .get_mac_address = efx_ef10_get_mac_address_pf,
6836 .set_mac_address = efx_ef10_set_mac_address,
6837 .tso_versions = efx_ef10_tso_versions,
6839 .get_phys_port_id = efx_ef10_get_phys_port_id,
6840 .revision = EFX_REV_HUNT_A0,
6841 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6842 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6843 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6844 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6845 .can_rx_scatter = true,
6846 .always_rx_scatter = true,
6847 .option_descriptors = true,
6848 .min_interrupt_mode = EFX_INT_MODE_LEGACY,
6849 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6850 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
6851 .offload_features = EF10_OFFLOAD_FEATURES,
6853 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6854 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6855 1 << HWTSTAMP_FILTER_ALL,
6856 .rx_hash_key_size = 40,