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_V3_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",
312 static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
314 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
317 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
318 outbuf, sizeof(outbuf), NULL);
321 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
322 return rc > 0 ? rc : -ERANGE;
325 static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
327 struct efx_ef10_nic_data *nic_data = efx->nic_data;
328 unsigned int implemented;
329 unsigned int enabled;
332 nic_data->workaround_35388 = false;
333 nic_data->workaround_61265 = false;
335 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
338 /* Firmware without GET_WORKAROUNDS - not a problem. */
340 } else if (rc == 0) {
341 /* Bug61265 workaround is always enabled if implemented. */
342 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
343 nic_data->workaround_61265 = true;
345 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
346 nic_data->workaround_35388 = true;
347 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
348 /* Workaround is implemented but not enabled.
351 rc = efx_mcdi_set_workaround(efx,
352 MC_CMD_WORKAROUND_BUG35388,
355 nic_data->workaround_35388 = true;
356 /* If we failed to set the workaround just carry on. */
361 netif_dbg(efx, probe, efx->net_dev,
362 "workaround for bug 35388 is %sabled\n",
363 nic_data->workaround_35388 ? "en" : "dis");
364 netif_dbg(efx, probe, efx->net_dev,
365 "workaround for bug 61265 is %sabled\n",
366 nic_data->workaround_61265 ? "en" : "dis");
371 static void efx_ef10_process_timer_config(struct efx_nic *efx,
372 const efx_dword_t *data)
374 unsigned int max_count;
376 if (EFX_EF10_WORKAROUND_61265(efx)) {
377 efx->timer_quantum_ns = MCDI_DWORD(data,
378 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
379 efx->timer_max_ns = MCDI_DWORD(data,
380 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
381 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
382 efx->timer_quantum_ns = MCDI_DWORD(data,
383 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
384 max_count = MCDI_DWORD(data,
385 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
386 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
388 efx->timer_quantum_ns = MCDI_DWORD(data,
389 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
390 max_count = MCDI_DWORD(data,
391 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
392 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
395 netif_dbg(efx, probe, efx->net_dev,
396 "got timer properties from MC: quantum %u ns; max %u ns\n",
397 efx->timer_quantum_ns, efx->timer_max_ns);
400 static int efx_ef10_get_timer_config(struct efx_nic *efx)
402 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
405 rc = efx_ef10_get_timer_workarounds(efx);
409 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
410 outbuf, sizeof(outbuf), NULL);
413 efx_ef10_process_timer_config(efx, outbuf);
414 } else if (rc == -ENOSYS || rc == -EPERM) {
415 /* Not available - fall back to Huntington defaults. */
416 unsigned int quantum;
418 rc = efx_ef10_get_sysclk_freq(efx);
422 quantum = 1536000 / rc; /* 1536 cycles */
423 efx->timer_quantum_ns = quantum;
424 efx->timer_max_ns = efx->type->timer_period_max * quantum;
427 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
428 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
435 static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
437 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
441 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
443 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
444 outbuf, sizeof(outbuf), &outlen);
447 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
450 ether_addr_copy(mac_address,
451 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
455 static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
457 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
458 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
462 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
463 EVB_PORT_ID_ASSIGNED);
464 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
465 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
469 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
472 num_addrs = MCDI_DWORD(outbuf,
473 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
475 WARN_ON(num_addrs != 1);
477 ether_addr_copy(mac_address,
478 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
483 static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
484 struct device_attribute *attr,
487 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
489 return sprintf(buf, "%d\n",
490 ((efx->mcdi->fn_flags) &
491 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
495 static ssize_t efx_ef10_show_primary_flag(struct device *dev,
496 struct device_attribute *attr,
499 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
501 return sprintf(buf, "%d\n",
502 ((efx->mcdi->fn_flags) &
503 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
507 static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
509 struct efx_ef10_nic_data *nic_data = efx->nic_data;
510 struct efx_ef10_vlan *vlan;
512 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
514 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
515 if (vlan->vid == vid)
522 static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
524 struct efx_ef10_nic_data *nic_data = efx->nic_data;
525 struct efx_ef10_vlan *vlan;
528 mutex_lock(&nic_data->vlan_lock);
530 vlan = efx_ef10_find_vlan(efx, vid);
532 /* We add VID 0 on init. 8021q adds it on module init
533 * for all interfaces with VLAN filtring feature.
537 netif_warn(efx, drv, efx->net_dev,
538 "VLAN %u already added\n", vid);
544 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
550 list_add_tail(&vlan->list, &nic_data->vlan_list);
552 if (efx->filter_state) {
553 mutex_lock(&efx->mac_lock);
554 down_write(&efx->filter_sem);
555 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
556 up_write(&efx->filter_sem);
557 mutex_unlock(&efx->mac_lock);
559 goto fail_filter_add_vlan;
563 mutex_unlock(&nic_data->vlan_lock);
566 fail_filter_add_vlan:
567 list_del(&vlan->list);
571 mutex_unlock(&nic_data->vlan_lock);
575 static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
576 struct efx_ef10_vlan *vlan)
578 struct efx_ef10_nic_data *nic_data = efx->nic_data;
580 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
582 if (efx->filter_state) {
583 down_write(&efx->filter_sem);
584 efx_ef10_filter_del_vlan(efx, vlan->vid);
585 up_write(&efx->filter_sem);
588 list_del(&vlan->list);
592 static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
594 struct efx_ef10_nic_data *nic_data = efx->nic_data;
595 struct efx_ef10_vlan *vlan;
598 /* 8021q removes VID 0 on module unload for all interfaces
599 * with VLAN filtering feature. We need to keep it to receive
605 mutex_lock(&nic_data->vlan_lock);
607 vlan = efx_ef10_find_vlan(efx, vid);
609 netif_err(efx, drv, efx->net_dev,
610 "VLAN %u to be deleted not found\n", vid);
613 efx_ef10_del_vlan_internal(efx, vlan);
616 mutex_unlock(&nic_data->vlan_lock);
621 static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
623 struct efx_ef10_nic_data *nic_data = efx->nic_data;
624 struct efx_ef10_vlan *vlan, *next_vlan;
626 mutex_lock(&nic_data->vlan_lock);
627 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
628 efx_ef10_del_vlan_internal(efx, vlan);
629 mutex_unlock(&nic_data->vlan_lock);
632 static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
634 static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
636 static int efx_ef10_probe(struct efx_nic *efx)
638 struct efx_ef10_nic_data *nic_data;
641 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
644 efx->nic_data = nic_data;
646 /* we assume later that we can copy from this buffer in dwords */
647 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
649 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
650 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
654 /* Get the MC's warm boot count. In case it's rebooting right
655 * now, be prepared to retry.
659 rc = efx_ef10_get_warm_boot_count(efx);
666 nic_data->warm_boot_count = rc;
668 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
670 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
672 /* In case we're recovering from a crash (kexec), we want to
673 * cancel any outstanding request by the previous user of this
674 * function. We send a special message using the least
675 * significant bits of the 'high' (doorbell) register.
677 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
679 rc = efx_mcdi_init(efx);
683 mutex_init(&nic_data->udp_tunnels_lock);
685 /* Reset (most) configuration for this function */
686 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
690 /* Enable event logging */
691 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
695 rc = device_create_file(&efx->pci_dev->dev,
696 &dev_attr_link_control_flag);
700 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
704 rc = efx_ef10_get_pf_index(efx);
708 rc = efx_ef10_init_datapath_caps(efx);
712 /* We can have one VI for each vi_stride-byte region.
713 * However, until we use TX option descriptors we need two TX queues
716 efx->max_channels = min_t(unsigned int,
718 efx_ef10_mem_map_size(efx) /
719 (efx->vi_stride * EFX_TXQ_TYPES));
720 efx->max_tx_channels = efx->max_channels;
721 if (WARN_ON(efx->max_channels == 0)) {
726 efx->rx_packet_len_offset =
727 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
729 if (nic_data->datapath_caps &
730 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
731 efx->net_dev->hw_features |= NETIF_F_RXFCS;
733 rc = efx_mcdi_port_get_number(efx);
738 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
742 rc = efx_ef10_get_timer_config(efx);
746 rc = efx_mcdi_mon_probe(efx);
747 if (rc && rc != -EPERM)
750 efx_ptp_probe(efx, NULL);
752 #ifdef CONFIG_SFC_SRIOV
753 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
754 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
755 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
757 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
760 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
762 INIT_LIST_HEAD(&nic_data->vlan_list);
763 mutex_init(&nic_data->vlan_lock);
765 /* Add unspecified VID to support VLAN filtering being disabled */
766 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
768 goto fail_add_vid_unspec;
770 /* If VLAN filtering is enabled, we need VID 0 to get untagged
771 * traffic. It is added automatically if 8021q module is loaded,
772 * but we can't rely on it since module may be not loaded.
774 rc = efx_ef10_add_vlan(efx, 0);
781 efx_ef10_cleanup_vlans(efx);
783 mutex_destroy(&nic_data->vlan_lock);
785 efx_mcdi_mon_remove(efx);
787 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
789 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
791 efx_mcdi_detach(efx);
793 mutex_lock(&nic_data->udp_tunnels_lock);
794 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
795 (void)efx_ef10_set_udp_tnl_ports(efx, true);
796 mutex_unlock(&nic_data->udp_tunnels_lock);
797 mutex_destroy(&nic_data->udp_tunnels_lock);
801 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
804 efx->nic_data = NULL;
808 static int efx_ef10_free_vis(struct efx_nic *efx)
810 MCDI_DECLARE_BUF_ERR(outbuf);
812 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
813 outbuf, sizeof(outbuf), &outlen);
815 /* -EALREADY means nothing to free, so ignore */
819 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
826 static void efx_ef10_free_piobufs(struct efx_nic *efx)
828 struct efx_ef10_nic_data *nic_data = efx->nic_data;
829 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
833 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
835 for (i = 0; i < nic_data->n_piobufs; i++) {
836 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
837 nic_data->piobuf_handle[i]);
838 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
843 nic_data->n_piobufs = 0;
846 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
848 struct efx_ef10_nic_data *nic_data = efx->nic_data;
849 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
854 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
856 for (i = 0; i < n; i++) {
857 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
858 outbuf, sizeof(outbuf), &outlen);
860 /* Don't display the MC error if we didn't have space
863 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
864 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
865 0, outbuf, outlen, rc);
868 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
872 nic_data->piobuf_handle[i] =
873 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
874 netif_dbg(efx, probe, efx->net_dev,
875 "allocated PIO buffer %u handle %x\n", i,
876 nic_data->piobuf_handle[i]);
879 nic_data->n_piobufs = i;
881 efx_ef10_free_piobufs(efx);
885 static int efx_ef10_link_piobufs(struct efx_nic *efx)
887 struct efx_ef10_nic_data *nic_data = efx->nic_data;
888 MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
889 struct efx_channel *channel;
890 struct efx_tx_queue *tx_queue;
891 unsigned int offset, index;
894 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
895 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
897 /* Link a buffer to each VI in the write-combining mapping */
898 for (index = 0; index < nic_data->n_piobufs; ++index) {
899 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
900 nic_data->piobuf_handle[index]);
901 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
902 nic_data->pio_write_vi_base + index);
903 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
904 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
907 netif_err(efx, drv, efx->net_dev,
908 "failed to link VI %u to PIO buffer %u (%d)\n",
909 nic_data->pio_write_vi_base + index, index,
913 netif_dbg(efx, probe, efx->net_dev,
914 "linked VI %u to PIO buffer %u\n",
915 nic_data->pio_write_vi_base + index, index);
918 /* Link a buffer to each TX queue */
919 efx_for_each_channel(channel, efx) {
920 efx_for_each_channel_tx_queue(tx_queue, channel) {
921 /* We assign the PIO buffers to queues in
922 * reverse order to allow for the following
925 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
926 tx_queue->channel->channel - 1) *
928 index = offset / nic_data->piobuf_size;
929 offset = offset % nic_data->piobuf_size;
931 /* When the host page size is 4K, the first
932 * host page in the WC mapping may be within
933 * the same VI page as the last TX queue. We
934 * can only link one buffer to each VI.
936 if (tx_queue->queue == nic_data->pio_write_vi_base) {
940 MCDI_SET_DWORD(inbuf,
941 LINK_PIOBUF_IN_PIOBUF_HANDLE,
942 nic_data->piobuf_handle[index]);
943 MCDI_SET_DWORD(inbuf,
944 LINK_PIOBUF_IN_TXQ_INSTANCE,
946 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
947 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
952 /* This is non-fatal; the TX path just
953 * won't use PIO for this queue
955 netif_err(efx, drv, efx->net_dev,
956 "failed to link VI %u to PIO buffer %u (%d)\n",
957 tx_queue->queue, index, rc);
958 tx_queue->piobuf = NULL;
961 nic_data->pio_write_base +
962 index * efx->vi_stride + offset;
963 tx_queue->piobuf_offset = offset;
964 netif_dbg(efx, probe, efx->net_dev,
965 "linked VI %u to PIO buffer %u offset %x addr %p\n",
966 tx_queue->queue, index,
967 tx_queue->piobuf_offset,
976 /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
977 * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
979 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
981 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
982 nic_data->pio_write_vi_base + index);
983 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
984 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
990 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
992 struct efx_channel *channel;
993 struct efx_tx_queue *tx_queue;
995 /* All our existing PIO buffers went away */
996 efx_for_each_channel(channel, efx)
997 efx_for_each_channel_tx_queue(tx_queue, channel)
998 tx_queue->piobuf = NULL;
1001 #else /* !EFX_USE_PIO */
1003 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
1005 return n == 0 ? 0 : -ENOBUFS;
1008 static int efx_ef10_link_piobufs(struct efx_nic *efx)
1013 static void efx_ef10_free_piobufs(struct efx_nic *efx)
1017 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1021 #endif /* EFX_USE_PIO */
1023 static void efx_ef10_remove(struct efx_nic *efx)
1025 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1028 #ifdef CONFIG_SFC_SRIOV
1029 struct efx_ef10_nic_data *nic_data_pf;
1030 struct pci_dev *pci_dev_pf;
1031 struct efx_nic *efx_pf;
1034 if (efx->pci_dev->is_virtfn) {
1035 pci_dev_pf = efx->pci_dev->physfn;
1037 efx_pf = pci_get_drvdata(pci_dev_pf);
1038 nic_data_pf = efx_pf->nic_data;
1039 vf = nic_data_pf->vf + nic_data->vf_index;
1042 netif_info(efx, drv, efx->net_dev,
1043 "Could not get the PF id from VF\n");
1047 efx_ef10_cleanup_vlans(efx);
1048 mutex_destroy(&nic_data->vlan_lock);
1050 efx_ptp_remove(efx);
1052 efx_mcdi_mon_remove(efx);
1054 efx_ef10_rx_free_indir_table(efx);
1056 if (nic_data->wc_membase)
1057 iounmap(nic_data->wc_membase);
1059 rc = efx_ef10_free_vis(efx);
1062 if (!nic_data->must_restore_piobufs)
1063 efx_ef10_free_piobufs(efx);
1065 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
1066 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
1068 efx_mcdi_detach(efx);
1070 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
1071 mutex_lock(&nic_data->udp_tunnels_lock);
1072 (void)efx_ef10_set_udp_tnl_ports(efx, true);
1073 mutex_unlock(&nic_data->udp_tunnels_lock);
1075 mutex_destroy(&nic_data->udp_tunnels_lock);
1078 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
1082 static int efx_ef10_probe_pf(struct efx_nic *efx)
1084 return efx_ef10_probe(efx);
1087 int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
1088 u32 *port_flags, u32 *vadaptor_flags,
1089 unsigned int *vlan_tags)
1091 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1092 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
1093 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
1097 if (nic_data->datapath_caps &
1098 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
1099 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
1102 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
1103 outbuf, sizeof(outbuf), &outlen);
1107 if (outlen < sizeof(outbuf)) {
1114 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1117 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1121 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1126 int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1128 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1130 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1131 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1135 int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1137 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1139 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1140 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1144 int efx_ef10_vport_add_mac(struct efx_nic *efx,
1145 unsigned int port_id, u8 *mac)
1147 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1149 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1150 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1152 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1153 sizeof(inbuf), NULL, 0, NULL);
1156 int efx_ef10_vport_del_mac(struct efx_nic *efx,
1157 unsigned int port_id, u8 *mac)
1159 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1161 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1162 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1164 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1165 sizeof(inbuf), NULL, 0, NULL);
1168 #ifdef CONFIG_SFC_SRIOV
1169 static int efx_ef10_probe_vf(struct efx_nic *efx)
1172 struct pci_dev *pci_dev_pf;
1174 /* If the parent PF has no VF data structure, it doesn't know about this
1175 * VF so fail probe. The VF needs to be re-created. This can happen
1176 * if the PF driver is unloaded while the VF is assigned to a guest.
1178 pci_dev_pf = efx->pci_dev->physfn;
1180 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1181 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1183 if (!nic_data_pf->vf) {
1184 netif_info(efx, drv, efx->net_dev,
1185 "The VF cannot link to its parent PF; "
1186 "please destroy and re-create the VF\n");
1191 rc = efx_ef10_probe(efx);
1195 rc = efx_ef10_get_vf_index(efx);
1199 if (efx->pci_dev->is_virtfn) {
1200 if (efx->pci_dev->physfn) {
1201 struct efx_nic *efx_pf =
1202 pci_get_drvdata(efx->pci_dev->physfn);
1203 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1204 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1206 nic_data_p->vf[nic_data->vf_index].efx = efx;
1207 nic_data_p->vf[nic_data->vf_index].pci_dev =
1210 netif_info(efx, drv, efx->net_dev,
1211 "Could not get the PF id from VF\n");
1217 efx_ef10_remove(efx);
1221 static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1227 static int efx_ef10_alloc_vis(struct efx_nic *efx,
1228 unsigned int min_vis, unsigned int max_vis)
1230 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1231 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1232 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1236 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1237 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1238 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1239 outbuf, sizeof(outbuf), &outlen);
1243 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1246 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1247 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1249 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1250 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1254 /* Note that the failure path of this function does not free
1255 * resources, as this will be done by efx_ef10_remove().
1257 static int efx_ef10_dimension_resources(struct efx_nic *efx)
1259 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1260 unsigned int uc_mem_map_size, wc_mem_map_size;
1261 unsigned int min_vis = max(EFX_TXQ_TYPES,
1262 efx_separate_tx_channels ? 2 : 1);
1263 unsigned int channel_vis, pio_write_vi_base, max_vis;
1264 void __iomem *membase;
1267 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
1270 /* Try to allocate PIO buffers if wanted and if the full
1271 * number of PIO buffers would be sufficient to allocate one
1272 * copy-buffer per TX channel. Failure is non-fatal, as there
1273 * are only a small number of PIO buffers shared between all
1274 * functions of the controller.
1276 if (efx_piobuf_size != 0 &&
1277 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1278 efx->n_tx_channels) {
1279 unsigned int n_piobufs =
1280 DIV_ROUND_UP(efx->n_tx_channels,
1281 nic_data->piobuf_size / efx_piobuf_size);
1283 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1285 netif_dbg(efx, probe, efx->net_dev,
1286 "out of PIO buffers; cannot allocate more\n");
1287 else if (rc == -EPERM)
1288 netif_dbg(efx, probe, efx->net_dev,
1289 "not permitted to allocate PIO buffers\n");
1291 netif_err(efx, probe, efx->net_dev,
1292 "failed to allocate PIO buffers (%d)\n", rc);
1294 netif_dbg(efx, probe, efx->net_dev,
1295 "allocated %u PIO buffers\n", n_piobufs);
1298 nic_data->n_piobufs = 0;
1301 /* PIO buffers should be mapped with write-combining enabled,
1302 * and we want to make single UC and WC mappings rather than
1303 * several of each (in fact that's the only option if host
1304 * page size is >4K). So we may allocate some extra VIs just
1305 * for writing PIO buffers through.
1307 * The UC mapping contains (channel_vis - 1) complete VIs and the
1308 * first 4K of the next VI. Then the WC mapping begins with
1309 * the remainder of this last VI.
1311 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
1313 if (nic_data->n_piobufs) {
1314 /* pio_write_vi_base rounds down to give the number of complete
1315 * VIs inside the UC mapping.
1317 pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
1318 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1319 nic_data->n_piobufs) *
1322 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1324 pio_write_vi_base = 0;
1325 wc_mem_map_size = 0;
1326 max_vis = channel_vis;
1329 /* In case the last attached driver failed to free VIs, do it now */
1330 rc = efx_ef10_free_vis(efx);
1334 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1338 if (nic_data->n_allocated_vis < channel_vis) {
1339 netif_info(efx, drv, efx->net_dev,
1340 "Could not allocate enough VIs to satisfy RSS"
1341 " requirements. Performance may not be optimal.\n");
1342 /* We didn't get the VIs to populate our channels.
1343 * We could keep what we got but then we'd have more
1344 * interrupts than we need.
1345 * Instead calculate new max_channels and restart
1347 efx->max_channels = nic_data->n_allocated_vis;
1348 efx->max_tx_channels =
1349 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1351 efx_ef10_free_vis(efx);
1355 /* If we didn't get enough VIs to map all the PIO buffers, free the
1358 if (nic_data->n_piobufs &&
1359 nic_data->n_allocated_vis <
1360 pio_write_vi_base + nic_data->n_piobufs) {
1361 netif_dbg(efx, probe, efx->net_dev,
1362 "%u VIs are not sufficient to map %u PIO buffers\n",
1363 nic_data->n_allocated_vis, nic_data->n_piobufs);
1364 efx_ef10_free_piobufs(efx);
1367 /* Shrink the original UC mapping of the memory BAR */
1368 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1370 netif_err(efx, probe, efx->net_dev,
1371 "could not shrink memory BAR to %x\n",
1375 iounmap(efx->membase);
1376 efx->membase = membase;
1378 /* Set up the WC mapping if needed */
1379 if (wc_mem_map_size) {
1380 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1383 if (!nic_data->wc_membase) {
1384 netif_err(efx, probe, efx->net_dev,
1385 "could not allocate WC mapping of size %x\n",
1389 nic_data->pio_write_vi_base = pio_write_vi_base;
1390 nic_data->pio_write_base =
1391 nic_data->wc_membase +
1392 (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
1395 rc = efx_ef10_link_piobufs(efx);
1397 efx_ef10_free_piobufs(efx);
1400 netif_dbg(efx, probe, efx->net_dev,
1401 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1402 &efx->membase_phys, efx->membase, uc_mem_map_size,
1403 nic_data->wc_membase, wc_mem_map_size);
1408 static int efx_ef10_init_nic(struct efx_nic *efx)
1410 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1413 if (nic_data->must_check_datapath_caps) {
1414 rc = efx_ef10_init_datapath_caps(efx);
1417 nic_data->must_check_datapath_caps = false;
1420 if (nic_data->must_realloc_vis) {
1421 /* We cannot let the number of VIs change now */
1422 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1423 nic_data->n_allocated_vis);
1426 nic_data->must_realloc_vis = false;
1429 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1430 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1432 rc = efx_ef10_link_piobufs(efx);
1434 efx_ef10_free_piobufs(efx);
1437 /* Log an error on failure, but this is non-fatal.
1438 * Permission errors are less important - we've presumably
1439 * had the PIO buffer licence removed.
1442 netif_dbg(efx, drv, efx->net_dev,
1443 "not permitted to restore PIO buffers\n");
1445 netif_err(efx, drv, efx->net_dev,
1446 "failed to restore PIO buffers (%d)\n", rc);
1447 nic_data->must_restore_piobufs = false;
1450 /* don't fail init if RSS setup doesn't work */
1451 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
1452 efx->rss_active = (rc == 0);
1457 static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1459 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1460 #ifdef CONFIG_SFC_SRIOV
1464 /* All our allocations have been reset */
1465 nic_data->must_realloc_vis = true;
1466 nic_data->must_restore_filters = true;
1467 nic_data->must_restore_piobufs = true;
1468 efx_ef10_forget_old_piobufs(efx);
1469 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1471 /* Driver-created vswitches and vports must be re-created */
1472 nic_data->must_probe_vswitching = true;
1473 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1474 #ifdef CONFIG_SFC_SRIOV
1476 for (i = 0; i < efx->vf_count; i++)
1477 nic_data->vf[i].vport_id = 0;
1481 static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1483 if (reason == RESET_TYPE_MC_FAILURE)
1484 return RESET_TYPE_DATAPATH;
1486 return efx_mcdi_map_reset_reason(reason);
1489 static int efx_ef10_map_reset_flags(u32 *flags)
1492 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1493 ETH_RESET_SHARED_SHIFT),
1494 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1495 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1496 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1497 ETH_RESET_SHARED_SHIFT)
1500 /* We assume for now that our PCI function is permitted to
1504 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1505 *flags &= ~EF10_RESET_MC;
1506 return RESET_TYPE_WORLD;
1509 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1510 *flags &= ~EF10_RESET_PORT;
1511 return RESET_TYPE_ALL;
1514 /* no invisible reset implemented */
1519 static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1521 int rc = efx_mcdi_reset(efx, reset_type);
1523 /* Unprivileged functions return -EPERM, but need to return success
1524 * here so that the datapath is brought back up.
1526 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1529 /* If it was a port reset, trigger reallocation of MC resources.
1530 * Note that on an MC reset nothing needs to be done now because we'll
1531 * detect the MC reset later and handle it then.
1532 * For an FLR, we never get an MC reset event, but the MC has reset all
1533 * resources assigned to us, so we have to trigger reallocation now.
1535 if ((reset_type == RESET_TYPE_ALL ||
1536 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
1537 efx_ef10_reset_mc_allocations(efx);
1541 #define EF10_DMA_STAT(ext_name, mcdi_name) \
1542 [EF10_STAT_ ## ext_name] = \
1543 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1544 #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1545 [EF10_STAT_ ## int_name] = \
1546 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1547 #define EF10_OTHER_STAT(ext_name) \
1548 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1549 #define GENERIC_SW_STAT(ext_name) \
1550 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1552 static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
1553 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1554 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1555 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1556 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1557 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1558 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1559 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1560 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1561 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1562 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1563 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1564 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1565 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1566 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1567 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1568 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1569 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1570 EF10_OTHER_STAT(port_rx_good_bytes),
1571 EF10_OTHER_STAT(port_rx_bad_bytes),
1572 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1573 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1574 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1575 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1576 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1577 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1578 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1579 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1580 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1581 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1582 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1583 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1584 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1585 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1586 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1587 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1588 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1589 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1590 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1591 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1592 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1593 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
1594 GENERIC_SW_STAT(rx_nodesc_trunc),
1595 GENERIC_SW_STAT(rx_noskb_drops),
1596 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1597 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1598 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1599 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1600 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1601 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1602 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1603 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1604 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1605 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1606 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1607 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
1608 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1609 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1610 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1611 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1612 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1613 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1614 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1615 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1616 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1617 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1618 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1619 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1620 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1621 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1622 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1623 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1624 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1625 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
1628 #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1629 (1ULL << EF10_STAT_port_tx_packets) | \
1630 (1ULL << EF10_STAT_port_tx_pause) | \
1631 (1ULL << EF10_STAT_port_tx_unicast) | \
1632 (1ULL << EF10_STAT_port_tx_multicast) | \
1633 (1ULL << EF10_STAT_port_tx_broadcast) | \
1634 (1ULL << EF10_STAT_port_rx_bytes) | \
1636 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1637 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1638 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1639 (1ULL << EF10_STAT_port_rx_packets) | \
1640 (1ULL << EF10_STAT_port_rx_good) | \
1641 (1ULL << EF10_STAT_port_rx_bad) | \
1642 (1ULL << EF10_STAT_port_rx_pause) | \
1643 (1ULL << EF10_STAT_port_rx_control) | \
1644 (1ULL << EF10_STAT_port_rx_unicast) | \
1645 (1ULL << EF10_STAT_port_rx_multicast) | \
1646 (1ULL << EF10_STAT_port_rx_broadcast) | \
1647 (1ULL << EF10_STAT_port_rx_lt64) | \
1648 (1ULL << EF10_STAT_port_rx_64) | \
1649 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1650 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1651 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1652 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1653 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1654 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1655 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1656 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1657 (1ULL << EF10_STAT_port_rx_overflow) | \
1658 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
1659 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1660 (1ULL << GENERIC_STAT_rx_noskb_drops))
1662 /* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1663 * For a 10G/40G switchable port we do not expose these because they might
1664 * not include all the packets they should.
1665 * On 8000 series NICs these statistics are always provided.
1667 #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1668 (1ULL << EF10_STAT_port_tx_lt64) | \
1669 (1ULL << EF10_STAT_port_tx_64) | \
1670 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1671 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1672 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1673 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1674 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1675 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
1677 /* These statistics are only provided by the 40G MAC. For a 10G/40G
1678 * switchable port we do expose these because the errors will otherwise
1681 #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1682 (1ULL << EF10_STAT_port_rx_length_error))
1684 /* These statistics are only provided if the firmware supports the
1685 * capability PM_AND_RXDP_COUNTERS.
1687 #define HUNT_PM_AND_RXDP_STAT_MASK ( \
1688 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1689 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1690 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1691 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1692 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1693 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1694 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1695 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1696 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1697 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1698 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1699 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
1701 static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
1703 u64 raw_mask = HUNT_COMMON_STAT_MASK;
1704 u32 port_caps = efx_mcdi_phy_get_caps(efx);
1705 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1707 if (!(efx->mcdi->fn_flags &
1708 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1711 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
1712 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
1713 /* 8000 series have everything even at 40G */
1714 if (nic_data->datapath_caps2 &
1715 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1716 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1718 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1721 if (nic_data->datapath_caps &
1722 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1723 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1728 static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1730 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1733 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1735 /* Only show vadaptor stats when EVB capability is present */
1736 if (nic_data->datapath_caps &
1737 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1738 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1739 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1744 #if BITS_PER_LONG == 64
1745 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
1746 mask[0] = raw_mask[0];
1747 mask[1] = raw_mask[1];
1749 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
1750 mask[0] = raw_mask[0] & 0xffffffff;
1751 mask[1] = raw_mask[0] >> 32;
1752 mask[2] = raw_mask[1] & 0xffffffff;
1756 static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1758 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1760 efx_ef10_get_stat_mask(efx, mask);
1761 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
1765 static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1766 struct rtnl_link_stats64 *core_stats)
1768 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1769 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1770 u64 *stats = nic_data->stats;
1771 size_t stats_count = 0, index;
1773 efx_ef10_get_stat_mask(efx, mask);
1776 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1777 if (efx_ef10_stat_desc[index].name) {
1778 *full_stats++ = stats[index];
1787 if (nic_data->datapath_caps &
1788 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1789 /* Use vadaptor stats. */
1790 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1791 stats[EF10_STAT_rx_multicast] +
1792 stats[EF10_STAT_rx_broadcast];
1793 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1794 stats[EF10_STAT_tx_multicast] +
1795 stats[EF10_STAT_tx_broadcast];
1796 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1797 stats[EF10_STAT_rx_multicast_bytes] +
1798 stats[EF10_STAT_rx_broadcast_bytes];
1799 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1800 stats[EF10_STAT_tx_multicast_bytes] +
1801 stats[EF10_STAT_tx_broadcast_bytes];
1802 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
1803 stats[GENERIC_STAT_rx_noskb_drops];
1804 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1805 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1806 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1807 core_stats->rx_errors = core_stats->rx_crc_errors;
1808 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
1810 /* Use port stats. */
1811 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1812 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1813 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1814 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1815 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1816 stats[GENERIC_STAT_rx_nodesc_trunc] +
1817 stats[GENERIC_STAT_rx_noskb_drops];
1818 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1819 core_stats->rx_length_errors =
1820 stats[EF10_STAT_port_rx_gtjumbo] +
1821 stats[EF10_STAT_port_rx_length_error];
1822 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1823 core_stats->rx_frame_errors =
1824 stats[EF10_STAT_port_rx_align_error];
1825 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1826 core_stats->rx_errors = (core_stats->rx_length_errors +
1827 core_stats->rx_crc_errors +
1828 core_stats->rx_frame_errors);
1834 static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
1836 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1837 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1838 __le64 generation_start, generation_end;
1839 u64 *stats = nic_data->stats;
1842 efx_ef10_get_stat_mask(efx, mask);
1844 dma_stats = efx->stats_buffer.addr;
1846 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1847 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1850 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1851 stats, efx->stats_buffer.addr, false);
1853 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1854 if (generation_end != generation_start)
1857 /* Update derived statistics */
1858 efx_nic_fix_nodesc_drop_stat(efx,
1859 &stats[EF10_STAT_port_rx_nodesc_drops]);
1860 stats[EF10_STAT_port_rx_good_bytes] =
1861 stats[EF10_STAT_port_rx_bytes] -
1862 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1863 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1864 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
1865 efx_update_sw_stats(efx, stats);
1870 static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1871 struct rtnl_link_stats64 *core_stats)
1875 /* If we're unlucky enough to read statistics during the DMA, wait
1876 * up to 10ms for it to finish (typically takes <500us)
1878 for (retry = 0; retry < 100; ++retry) {
1879 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
1884 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1887 static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1889 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1890 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1891 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1892 __le64 generation_start, generation_end;
1893 u64 *stats = nic_data->stats;
1894 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1895 struct efx_buffer stats_buf;
1899 spin_unlock_bh(&efx->stats_lock);
1901 if (in_interrupt()) {
1902 /* If in atomic context, cannot update stats. Just update the
1903 * software stats and return so the caller can continue.
1905 spin_lock_bh(&efx->stats_lock);
1906 efx_update_sw_stats(efx, stats);
1910 efx_ef10_get_stat_mask(efx, mask);
1912 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
1914 spin_lock_bh(&efx->stats_lock);
1918 dma_stats = stats_buf.addr;
1919 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1921 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1922 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
1923 MAC_STATS_IN_DMA, 1);
1924 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1925 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1927 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1929 spin_lock_bh(&efx->stats_lock);
1931 /* Expect ENOENT if DMA queues have not been set up */
1932 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1933 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1934 sizeof(inbuf), NULL, 0, rc);
1938 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1939 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1944 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1945 stats, stats_buf.addr, false);
1947 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1948 if (generation_end != generation_start) {
1953 efx_update_sw_stats(efx, stats);
1955 efx_nic_free_buffer(efx, &stats_buf);
1959 static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1960 struct rtnl_link_stats64 *core_stats)
1962 if (efx_ef10_try_update_nic_stats_vf(efx))
1965 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1968 static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1970 struct efx_nic *efx = channel->efx;
1971 unsigned int mode, usecs;
1972 efx_dword_t timer_cmd;
1974 if (channel->irq_moderation_us) {
1976 usecs = channel->irq_moderation_us;
1982 if (EFX_EF10_WORKAROUND_61265(efx)) {
1983 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1984 unsigned int ns = usecs * 1000;
1986 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1988 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1989 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1990 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1992 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1993 inbuf, sizeof(inbuf), 0, NULL, 0);
1994 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1995 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1997 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1998 EFE_DD_EVQ_IND_TIMER_FLAGS,
1999 ERF_DD_EVQ_IND_TIMER_MODE, mode,
2000 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
2001 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
2004 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2006 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
2007 ERF_DZ_TC_TIMER_VAL, ticks);
2008 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
2013 static void efx_ef10_get_wol_vf(struct efx_nic *efx,
2014 struct ethtool_wolinfo *wol) {}
2016 static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
2021 static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
2025 memset(&wol->sopass, 0, sizeof(wol->sopass));
2028 static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
2035 static void efx_ef10_mcdi_request(struct efx_nic *efx,
2036 const efx_dword_t *hdr, size_t hdr_len,
2037 const efx_dword_t *sdu, size_t sdu_len)
2039 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2040 u8 *pdu = nic_data->mcdi_buf.addr;
2042 memcpy(pdu, hdr, hdr_len);
2043 memcpy(pdu + hdr_len, sdu, sdu_len);
2046 /* The hardware provides 'low' and 'high' (doorbell) registers
2047 * for passing the 64-bit address of an MCDI request to
2048 * firmware. However the dwords are swapped by firmware. The
2049 * least significant bits of the doorbell are then 0 for all
2050 * MCDI requests due to alignment.
2052 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
2054 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
2058 static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
2060 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2061 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
2064 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
2068 efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
2069 size_t offset, size_t outlen)
2071 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2072 const u8 *pdu = nic_data->mcdi_buf.addr;
2074 memcpy(outbuf, pdu + offset, outlen);
2077 static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
2079 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2081 /* All our allocations have been reset */
2082 efx_ef10_reset_mc_allocations(efx);
2084 /* The datapath firmware might have been changed */
2085 nic_data->must_check_datapath_caps = true;
2087 /* MAC statistics have been cleared on the NIC; clear the local
2088 * statistic that we update with efx_update_diff_stat().
2090 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
2093 static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2095 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2098 rc = efx_ef10_get_warm_boot_count(efx);
2100 /* The firmware is presumably in the process of
2101 * rebooting. However, we are supposed to report each
2102 * reboot just once, so we must only do that once we
2103 * can read and store the updated warm boot count.
2108 if (rc == nic_data->warm_boot_count)
2111 nic_data->warm_boot_count = rc;
2112 efx_ef10_mcdi_reboot_detected(efx);
2117 /* Handle an MSI interrupt
2119 * Handle an MSI hardware interrupt. This routine schedules event
2120 * queue processing. No interrupt acknowledgement cycle is necessary.
2121 * Also, we never need to check that the interrupt is for us, since
2122 * MSI interrupts cannot be shared.
2124 static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2126 struct efx_msi_context *context = dev_id;
2127 struct efx_nic *efx = context->efx;
2129 netif_vdbg(efx, intr, efx->net_dev,
2130 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2132 if (likely(READ_ONCE(efx->irq_soft_enabled))) {
2133 /* Note test interrupts */
2134 if (context->index == efx->irq_level)
2135 efx->last_irq_cpu = raw_smp_processor_id();
2137 /* Schedule processing of the channel */
2138 efx_schedule_channel_irq(efx->channel[context->index]);
2144 static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2146 struct efx_nic *efx = dev_id;
2147 bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
2148 struct efx_channel *channel;
2152 /* Read the ISR which also ACKs the interrupts */
2153 efx_readd(efx, ®, ER_DZ_BIU_INT_ISR);
2154 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2159 if (likely(soft_enabled)) {
2160 /* Note test interrupts */
2161 if (queues & (1U << efx->irq_level))
2162 efx->last_irq_cpu = raw_smp_processor_id();
2164 efx_for_each_channel(channel, efx) {
2166 efx_schedule_channel_irq(channel);
2171 netif_vdbg(efx, intr, efx->net_dev,
2172 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2173 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2178 static int efx_ef10_irq_test_generate(struct efx_nic *efx)
2180 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2182 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2186 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2188 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
2189 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
2190 inbuf, sizeof(inbuf), NULL, 0, NULL);
2193 static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2195 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2196 (tx_queue->ptr_mask + 1) *
2197 sizeof(efx_qword_t),
2201 /* This writes to the TX_DESC_WPTR and also pushes data */
2202 static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2203 const efx_qword_t *txd)
2205 unsigned int write_ptr;
2208 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2209 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2210 reg.qword[0] = *txd;
2211 efx_writeo_page(tx_queue->efx, ®,
2212 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2215 /* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2217 static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2218 struct sk_buff *skb,
2221 struct efx_tx_buffer *buffer;
2229 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
2231 mss = skb_shinfo(skb)->gso_size;
2233 if (unlikely(mss < 4)) {
2234 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2239 if (ip->version == 4) {
2240 /* Modify IPv4 header if needed. */
2243 ipv4_id = ntohs(ip->id);
2245 /* Modify IPv6 header if needed. */
2246 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2248 ipv6->payload_len = 0;
2253 seqnum = ntohl(tcp->seq);
2255 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2257 buffer->flags = EFX_TX_BUF_OPTION;
2259 buffer->unmap_len = 0;
2260 EFX_POPULATE_QWORD_5(buffer->option,
2261 ESF_DZ_TX_DESC_IS_OPT, 1,
2262 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2263 ESF_DZ_TX_TSO_OPTION_TYPE,
2264 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2265 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2266 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2268 ++tx_queue->insert_count;
2270 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2272 buffer->flags = EFX_TX_BUF_OPTION;
2274 buffer->unmap_len = 0;
2275 EFX_POPULATE_QWORD_4(buffer->option,
2276 ESF_DZ_TX_DESC_IS_OPT, 1,
2277 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2278 ESF_DZ_TX_TSO_OPTION_TYPE,
2279 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2280 ESF_DZ_TX_TSO_TCP_MSS, mss
2282 ++tx_queue->insert_count;
2287 static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2289 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2290 u32 tso_versions = 0;
2292 if (nic_data->datapath_caps &
2293 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2294 tso_versions |= BIT(1);
2295 if (nic_data->datapath_caps2 &
2296 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2297 tso_versions |= BIT(2);
2298 return tso_versions;
2301 static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2303 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2305 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2306 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2307 struct efx_channel *channel = tx_queue->channel;
2308 struct efx_nic *efx = tx_queue->efx;
2309 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2310 bool tso_v2 = false;
2312 dma_addr_t dma_addr;
2316 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
2318 /* TSOv2 is a limited resource that can only be configured on a limited
2319 * number of queues. TSO without checksum offload is not really a thing,
2320 * so we only enable it for those queues.
2322 if (csum_offload && (nic_data->datapath_caps2 &
2323 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2325 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2329 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2330 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2331 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2332 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
2333 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
2334 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
2336 dma_addr = tx_queue->txd.buf.dma_addr;
2338 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2339 tx_queue->queue, entries, (u64)dma_addr);
2341 for (i = 0; i < entries; ++i) {
2342 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2343 dma_addr += EFX_BUF_SIZE;
2346 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2349 MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2350 /* This flag was removed from mcdi_pcol.h for
2351 * the non-_EXT version of INIT_TXQ. However,
2352 * firmware still honours it.
2354 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2355 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2356 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2358 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2360 if (rc == -ENOSPC && tso_v2) {
2361 /* Retry without TSOv2 if we're short on contexts. */
2363 netif_warn(efx, probe, efx->net_dev,
2364 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2366 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2367 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2373 /* A previous user of this TX queue might have set us up the
2374 * bomb by writing a descriptor to the TX push collector but
2375 * not the doorbell. (Each collector belongs to a port, not a
2376 * queue or function, so cannot easily be reset.) We must
2377 * attempt to push a no-op descriptor in its place.
2379 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2380 tx_queue->insert_count = 1;
2381 txd = efx_tx_desc(tx_queue, 0);
2382 EFX_POPULATE_QWORD_4(*txd,
2383 ESF_DZ_TX_DESC_IS_OPT, true,
2384 ESF_DZ_TX_OPTION_TYPE,
2385 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2386 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2387 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2388 tx_queue->write_count = 1;
2391 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2392 tx_queue->tso_version = 2;
2393 } else if (nic_data->datapath_caps &
2394 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2395 tx_queue->tso_version = 1;
2399 efx_ef10_push_tx_desc(tx_queue, txd);
2404 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2408 static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2410 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
2411 MCDI_DECLARE_BUF_ERR(outbuf);
2412 struct efx_nic *efx = tx_queue->efx;
2416 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2419 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
2420 outbuf, sizeof(outbuf), &outlen);
2422 if (rc && rc != -EALREADY)
2428 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2429 outbuf, outlen, rc);
2432 static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2434 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2437 /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2438 static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2440 unsigned int write_ptr;
2443 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2444 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2445 efx_writed_page(tx_queue->efx, ®,
2446 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2449 #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2451 static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2452 dma_addr_t dma_addr, unsigned int len)
2454 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2455 /* If we need to break across multiple descriptors we should
2456 * stop at a page boundary. This assumes the length limit is
2457 * greater than the page size.
2459 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2461 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2462 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2468 static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2470 unsigned int old_write_count = tx_queue->write_count;
2471 struct efx_tx_buffer *buffer;
2472 unsigned int write_ptr;
2475 tx_queue->xmit_more_available = false;
2476 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2480 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2481 buffer = &tx_queue->buffer[write_ptr];
2482 txd = efx_tx_desc(tx_queue, write_ptr);
2483 ++tx_queue->write_count;
2485 /* Create TX descriptor ring entry */
2486 if (buffer->flags & EFX_TX_BUF_OPTION) {
2487 *txd = buffer->option;
2488 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2489 /* PIO descriptor */
2490 tx_queue->packet_write_count = tx_queue->write_count;
2492 tx_queue->packet_write_count = tx_queue->write_count;
2493 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2494 EFX_POPULATE_QWORD_3(
2497 buffer->flags & EFX_TX_BUF_CONT,
2498 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2499 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2501 } while (tx_queue->write_count != tx_queue->insert_count);
2503 wmb(); /* Ensure descriptors are written before they are fetched */
2505 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2506 txd = efx_tx_desc(tx_queue,
2507 old_write_count & tx_queue->ptr_mask);
2508 efx_ef10_push_tx_desc(tx_queue, txd);
2511 efx_ef10_notify_tx_desc(tx_queue);
2515 #define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2516 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2517 #define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2518 1 << RSS_MODE_HASH_DST_PORT_LBN)
2519 #define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2520 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2521 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2522 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2523 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2524 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2525 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2526 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2527 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2528 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2530 static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2532 /* Firmware had a bug (sfc bug 61952) where it would not actually
2533 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2534 * This meant that it would always contain whatever was previously
2535 * in the MCDI buffer. Fortunately, all firmware versions with
2536 * this bug have the same default flags value for a newly-allocated
2537 * RSS context, and the only time we want to get the flags is just
2538 * after allocating. Moreover, the response has a 32-bit hole
2539 * where the context ID would be in the request, so we can use an
2540 * overlength buffer in the request and pre-fill the flags field
2541 * with what we believe the default to be. Thus if the firmware
2542 * has the bug, it will leave our pre-filled value in the flags
2543 * field of the response, and we will get the right answer.
2545 * However, this does mean that this function should NOT be used if
2546 * the RSS context flags might not be their defaults - it is ONLY
2547 * reliably correct for a newly-allocated RSS context.
2549 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2550 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2554 /* Check we have a hole for the context ID */
2555 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2556 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2557 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2558 RSS_CONTEXT_FLAGS_DEFAULT);
2559 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2560 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2562 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2565 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2570 /* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2571 * If we fail, we just leave the RSS context at its default hash settings,
2572 * which is safe but may slightly reduce performance.
2573 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2574 * just need to set the UDP ports flags (for both IP versions).
2576 static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2578 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2581 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2583 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2585 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2586 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2587 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2588 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
2589 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2591 /* Succeeded, so UDP 4-tuple is now enabled */
2592 efx->rx_hash_udp_4tuple = true;
2595 static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2596 bool exclusive, unsigned *context_size)
2598 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2599 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
2600 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2603 u32 alloc_type = exclusive ?
2604 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2605 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2606 unsigned rss_spread = exclusive ?
2608 min(rounddown_pow_of_two(efx->rss_spread),
2609 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2611 if (!exclusive && rss_spread == 1) {
2612 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2618 if (nic_data->datapath_caps &
2619 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2622 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
2623 nic_data->vport_id);
2624 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2625 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
2627 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2628 outbuf, sizeof(outbuf), &outlen);
2632 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2635 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2638 *context_size = rss_spread;
2640 if (nic_data->datapath_caps &
2641 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2642 efx_ef10_set_rss_flags(efx, *context);
2647 static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2649 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2652 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2655 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2660 static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2661 const u32 *rx_indir_table, const u8 *key)
2663 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2664 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2667 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2669 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2670 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2672 /* This iterates over the length of efx->rx_indir_table, but copies
2673 * bytes from rx_indir_table. That's because the latter is a pointer
2674 * rather than an array, but should have the same length.
2675 * The efx->rx_hash_key loop below is similar.
2677 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2679 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
2680 (u8) rx_indir_table[i];
2682 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2683 sizeof(tablebuf), NULL, 0, NULL);
2687 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2689 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2690 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2691 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2692 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
2694 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2695 sizeof(keybuf), NULL, 0, NULL);
2698 static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2700 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2702 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2703 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2704 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2707 static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2708 unsigned *context_size)
2710 u32 new_rx_rss_context;
2711 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2712 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2713 false, context_size);
2718 nic_data->rx_rss_context = new_rx_rss_context;
2719 nic_data->rx_rss_context_exclusive = false;
2720 efx_set_default_rx_indir_table(efx);
2724 static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2725 const u32 *rx_indir_table,
2728 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2730 u32 new_rx_rss_context;
2732 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2733 !nic_data->rx_rss_context_exclusive) {
2734 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2736 if (rc == -EOPNOTSUPP)
2741 new_rx_rss_context = nic_data->rx_rss_context;
2744 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2745 rx_indir_table, key);
2749 if (nic_data->rx_rss_context != new_rx_rss_context)
2750 efx_ef10_rx_free_indir_table(efx);
2751 nic_data->rx_rss_context = new_rx_rss_context;
2752 nic_data->rx_rss_context_exclusive = true;
2753 if (rx_indir_table != efx->rx_indir_table)
2754 memcpy(efx->rx_indir_table, rx_indir_table,
2755 sizeof(efx->rx_indir_table));
2756 if (key != efx->rx_hash_key)
2757 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2762 if (new_rx_rss_context != nic_data->rx_rss_context)
2763 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2765 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2769 static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2771 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2772 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2773 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2774 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2778 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2779 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2781 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2784 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2785 nic_data->rx_rss_context);
2786 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2787 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2788 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2789 tablebuf, sizeof(tablebuf), &outlen);
2793 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2796 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2797 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2798 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2800 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2801 nic_data->rx_rss_context);
2802 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2803 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2804 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2805 keybuf, sizeof(keybuf), &outlen);
2809 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2812 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2813 efx->rx_hash_key[i] = MCDI_PTR(
2814 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2819 static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2820 const u32 *rx_indir_table,
2825 if (efx->rss_spread == 1)
2829 key = efx->rx_hash_key;
2831 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
2833 if (rc == -ENOBUFS && !user) {
2834 unsigned context_size;
2835 bool mismatch = false;
2838 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2840 mismatch = rx_indir_table[i] !=
2841 ethtool_rxfh_indir_default(i, efx->rss_spread);
2843 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2845 if (context_size != efx->rss_spread)
2846 netif_warn(efx, probe, efx->net_dev,
2847 "Could not allocate an exclusive RSS"
2848 " context; allocated a shared one of"
2850 " Wanted %u, got %u.\n",
2851 efx->rss_spread, context_size);
2853 netif_warn(efx, probe, efx->net_dev,
2854 "Could not allocate an exclusive RSS"
2855 " context; allocated a shared one but"
2856 " could not apply custom"
2859 netif_info(efx, probe, efx->net_dev,
2860 "Could not allocate an exclusive RSS"
2861 " context; allocated a shared one.\n");
2867 static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2868 const u32 *rx_indir_table
2869 __attribute__ ((unused)),
2871 __attribute__ ((unused)))
2873 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2877 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2879 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
2882 static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2884 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2885 (rx_queue->ptr_mask + 1) *
2886 sizeof(efx_qword_t),
2890 static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2892 MCDI_DECLARE_BUF(inbuf,
2893 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2895 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2896 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2897 struct efx_nic *efx = rx_queue->efx;
2898 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2900 dma_addr_t dma_addr;
2903 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
2905 rx_queue->scatter_n = 0;
2906 rx_queue->scatter_len = 0;
2908 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2909 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2910 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2911 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2912 efx_rx_queue_index(rx_queue));
2913 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2914 INIT_RXQ_IN_FLAG_PREFIX, 1,
2915 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
2916 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
2917 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
2919 dma_addr = rx_queue->rxd.buf.dma_addr;
2921 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2922 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2924 for (i = 0; i < entries; ++i) {
2925 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2926 dma_addr += EFX_BUF_SIZE;
2929 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2931 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
2934 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2935 efx_rx_queue_index(rx_queue));
2938 static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2940 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
2941 MCDI_DECLARE_BUF_ERR(outbuf);
2942 struct efx_nic *efx = rx_queue->efx;
2946 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2947 efx_rx_queue_index(rx_queue));
2949 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
2950 outbuf, sizeof(outbuf), &outlen);
2952 if (rc && rc != -EALREADY)
2958 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2959 outbuf, outlen, rc);
2962 static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2964 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2967 /* This creates an entry in the RX descriptor queue */
2969 efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2971 struct efx_rx_buffer *rx_buf;
2974 rxd = efx_rx_desc(rx_queue, index);
2975 rx_buf = efx_rx_buffer(rx_queue, index);
2976 EFX_POPULATE_QWORD_2(*rxd,
2977 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2978 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2981 static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2983 struct efx_nic *efx = rx_queue->efx;
2984 unsigned int write_count;
2987 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2988 write_count = rx_queue->added_count & ~7;
2989 if (rx_queue->notified_count == write_count)
2993 efx_ef10_build_rx_desc(
2995 rx_queue->notified_count & rx_queue->ptr_mask);
2996 while (++rx_queue->notified_count != write_count);
2999 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
3000 write_count & rx_queue->ptr_mask);
3001 efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD,
3002 efx_rx_queue_index(rx_queue));
3005 static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
3007 static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
3009 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3010 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3013 EFX_POPULATE_QWORD_2(event,
3014 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3015 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
3017 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3019 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3020 * already swapped the data to little-endian order.
3022 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3023 sizeof(efx_qword_t));
3025 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
3026 inbuf, sizeof(inbuf), 0,
3027 efx_ef10_rx_defer_refill_complete, 0);
3031 efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
3032 int rc, efx_dword_t *outbuf,
3033 size_t outlen_actual)
3038 static int efx_ef10_ev_probe(struct efx_channel *channel)
3040 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
3041 (channel->eventq_mask + 1) *
3042 sizeof(efx_qword_t),
3046 static void efx_ef10_ev_fini(struct efx_channel *channel)
3048 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
3049 MCDI_DECLARE_BUF_ERR(outbuf);
3050 struct efx_nic *efx = channel->efx;
3054 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
3056 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
3057 outbuf, sizeof(outbuf), &outlen);
3059 if (rc && rc != -EALREADY)
3065 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
3066 outbuf, outlen, rc);
3069 static int efx_ef10_ev_init(struct efx_channel *channel)
3071 MCDI_DECLARE_BUF(inbuf,
3072 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
3074 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
3075 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
3076 struct efx_nic *efx = channel->efx;
3077 struct efx_ef10_nic_data *nic_data;
3078 size_t inlen, outlen;
3079 unsigned int enabled, implemented;
3080 dma_addr_t dma_addr;
3084 nic_data = efx->nic_data;
3086 /* Fill event queue with all ones (i.e. empty events) */
3087 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
3089 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
3090 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
3091 /* INIT_EVQ expects index in vector table, not absolute */
3092 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
3093 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3094 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3095 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3096 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3097 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3098 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3099 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3101 if (nic_data->datapath_caps2 &
3102 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3103 /* Use the new generic approach to specifying event queue
3104 * configuration, requesting lower latency or higher throughput.
3105 * The options that actually get used appear in the output.
3107 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3108 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3109 INIT_EVQ_V2_IN_FLAG_TYPE,
3110 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3112 bool cut_thru = !(nic_data->datapath_caps &
3113 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3115 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3116 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3117 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3118 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3119 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3122 dma_addr = channel->eventq.buf.dma_addr;
3123 for (i = 0; i < entries; ++i) {
3124 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3125 dma_addr += EFX_BUF_SIZE;
3128 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3130 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3131 outbuf, sizeof(outbuf), &outlen);
3133 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3134 netif_dbg(efx, drv, efx->net_dev,
3135 "Channel %d using event queue flags %08x\n",
3137 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3139 /* IRQ return is ignored */
3140 if (channel->channel || rc)
3143 /* Successfully created event queue on channel 0 */
3144 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
3145 if (rc == -ENOSYS) {
3146 /* GET_WORKAROUNDS was implemented before this workaround,
3147 * thus it must be unavailable in this firmware.
3149 nic_data->workaround_26807 = false;
3154 nic_data->workaround_26807 =
3155 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
3157 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3158 !nic_data->workaround_26807) {
3161 rc = efx_mcdi_set_workaround(efx,
3162 MC_CMD_WORKAROUND_BUG26807,
3167 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3168 netif_info(efx, drv, efx->net_dev,
3169 "other functions on NIC have been reset\n");
3171 /* With MCFW v4.6.x and earlier, the
3172 * boot count will have incremented,
3173 * so re-read the warm_boot_count
3174 * value now to ensure this function
3175 * doesn't think it has changed next
3178 rc = efx_ef10_get_warm_boot_count(efx);
3180 nic_data->warm_boot_count = rc;
3184 nic_data->workaround_26807 = true;
3185 } else if (rc == -EPERM) {
3195 efx_ef10_ev_fini(channel);
3199 static void efx_ef10_ev_remove(struct efx_channel *channel)
3201 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3204 static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3205 unsigned int rx_queue_label)
3207 struct efx_nic *efx = rx_queue->efx;
3209 netif_info(efx, hw, efx->net_dev,
3210 "rx event arrived on queue %d labeled as queue %u\n",
3211 efx_rx_queue_index(rx_queue), rx_queue_label);
3213 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3217 efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3218 unsigned int actual, unsigned int expected)
3220 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3221 struct efx_nic *efx = rx_queue->efx;
3223 netif_info(efx, hw, efx->net_dev,
3224 "dropped %d events (index=%d expected=%d)\n",
3225 dropped, actual, expected);
3227 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3230 /* partially received RX was aborted. clean up. */
3231 static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3233 unsigned int rx_desc_ptr;
3235 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3236 "scattered RX aborted (dropping %u buffers)\n",
3237 rx_queue->scatter_n);
3239 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3241 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3242 0, EFX_RX_PKT_DISCARD);
3244 rx_queue->removed_count += rx_queue->scatter_n;
3245 rx_queue->scatter_n = 0;
3246 rx_queue->scatter_len = 0;
3247 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3250 static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3251 unsigned int n_packets,
3252 unsigned int rx_encap_hdr,
3253 unsigned int rx_l3_class,
3254 unsigned int rx_l4_class,
3255 const efx_qword_t *event)
3257 struct efx_nic *efx = channel->efx;
3258 bool handled = false;
3260 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
3261 if (!(efx->net_dev->features & NETIF_F_RXALL)) {
3262 if (!efx->loopback_selftest)
3263 channel->n_rx_eth_crc_err += n_packets;
3264 return EFX_RX_PKT_DISCARD;
3268 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3269 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3270 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3271 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3272 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3273 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3274 netdev_WARN(efx->net_dev,
3275 "invalid class for RX_IPCKSUM_ERR: event="
3277 EFX_QWORD_VAL(*event));
3278 if (!efx->loopback_selftest)
3280 &channel->n_rx_outer_ip_hdr_chksum_err :
3281 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3284 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3285 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3286 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3287 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3288 (rx_l4_class != ESE_DZ_L4_CLASS_TCP &&
3289 rx_l4_class != ESE_DZ_L4_CLASS_UDP))))
3290 netdev_WARN(efx->net_dev,
3291 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3293 EFX_QWORD_VAL(*event));
3294 if (!efx->loopback_selftest)
3296 &channel->n_rx_outer_tcp_udp_chksum_err :
3297 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3300 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3301 if (unlikely(!rx_encap_hdr))
3302 netdev_WARN(efx->net_dev,
3303 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3305 EFX_QWORD_VAL(*event));
3306 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3307 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3308 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3309 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3310 netdev_WARN(efx->net_dev,
3311 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3313 EFX_QWORD_VAL(*event));
3314 if (!efx->loopback_selftest)
3315 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3318 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3319 if (unlikely(!rx_encap_hdr))
3320 netdev_WARN(efx->net_dev,
3321 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3323 EFX_QWORD_VAL(*event));
3324 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3325 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
3326 (rx_l4_class != ESE_DZ_L4_CLASS_TCP &&
3327 rx_l4_class != ESE_DZ_L4_CLASS_UDP)))
3328 netdev_WARN(efx->net_dev,
3329 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3331 EFX_QWORD_VAL(*event));
3332 if (!efx->loopback_selftest)
3333 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3337 WARN_ON(!handled); /* No error bits were recognised */
3341 static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3342 const efx_qword_t *event)
3344 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3345 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
3346 unsigned int n_descs, n_packets, i;
3347 struct efx_nic *efx = channel->efx;
3348 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3349 struct efx_rx_queue *rx_queue;
3354 if (unlikely(READ_ONCE(efx->reset_pending)))
3357 /* Basic packet information */
3358 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3359 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3360 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
3361 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
3362 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
3363 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
3365 nic_data->datapath_caps &
3366 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3367 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3368 ESE_EZ_ENCAP_HDR_NONE;
3370 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3371 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3373 EFX_QWORD_VAL(*event));
3375 rx_queue = efx_channel_get_rx_queue(channel);
3377 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3378 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3380 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3381 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3383 if (n_descs != rx_queue->scatter_n + 1) {
3384 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3386 /* detect rx abort */
3387 if (unlikely(n_descs == rx_queue->scatter_n)) {
3388 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3389 netdev_WARN(efx->net_dev,
3390 "invalid RX abort: scatter_n=%u event="
3392 rx_queue->scatter_n,
3393 EFX_QWORD_VAL(*event));
3394 efx_ef10_handle_rx_abort(rx_queue);
3398 /* Check that RX completion merging is valid, i.e.
3399 * the current firmware supports it and this is a
3400 * non-scattered packet.
3402 if (!(nic_data->datapath_caps &
3403 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3404 rx_queue->scatter_n != 0 || rx_cont) {
3405 efx_ef10_handle_rx_bad_lbits(
3406 rx_queue, next_ptr_lbits,
3407 (rx_queue->removed_count +
3408 rx_queue->scatter_n + 1) &
3409 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3413 /* Merged completion for multiple non-scattered packets */
3414 rx_queue->scatter_n = 1;
3415 rx_queue->scatter_len = 0;
3416 n_packets = n_descs;
3417 ++channel->n_rx_merge_events;
3418 channel->n_rx_merge_packets += n_packets;
3419 flags |= EFX_RX_PKT_PREFIX_LEN;
3421 ++rx_queue->scatter_n;
3422 rx_queue->scatter_len += rx_bytes;
3428 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3429 ESF_DZ_RX_IPCKSUM_ERR, 1,
3430 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3431 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3432 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3433 EFX_AND_QWORD(errors, *event, errors);
3434 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3435 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
3437 rx_l3_class, rx_l4_class,
3440 bool tcpudp = rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
3441 rx_l4_class == ESE_DZ_L4_CLASS_UDP;
3443 switch (rx_encap_hdr) {
3444 case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
3445 flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
3447 flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
3449 case ESE_EZ_ENCAP_HDR_GRE:
3450 case ESE_EZ_ENCAP_HDR_NONE:
3452 flags |= EFX_RX_PKT_CSUMMED;
3455 netdev_WARN(efx->net_dev,
3456 "unknown encapsulation type: event="
3458 EFX_QWORD_VAL(*event));
3462 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
3463 flags |= EFX_RX_PKT_TCP;
3465 channel->irq_mod_score += 2 * n_packets;
3467 /* Handle received packet(s) */
3468 for (i = 0; i < n_packets; i++) {
3469 efx_rx_packet(rx_queue,
3470 rx_queue->removed_count & rx_queue->ptr_mask,
3471 rx_queue->scatter_n, rx_queue->scatter_len,
3473 rx_queue->removed_count += rx_queue->scatter_n;
3476 rx_queue->scatter_n = 0;
3477 rx_queue->scatter_len = 0;
3483 efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3485 struct efx_nic *efx = channel->efx;
3486 struct efx_tx_queue *tx_queue;
3487 unsigned int tx_ev_desc_ptr;
3488 unsigned int tx_ev_q_label;
3491 if (unlikely(READ_ONCE(efx->reset_pending)))
3494 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
3497 /* Transmit completion */
3498 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3499 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3500 tx_queue = efx_channel_get_tx_queue(channel,
3501 tx_ev_q_label % EFX_TXQ_TYPES);
3502 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
3503 tx_queue->ptr_mask);
3504 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3510 efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3512 struct efx_nic *efx = channel->efx;
3515 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3518 case ESE_DZ_DRV_TIMER_EV:
3519 case ESE_DZ_DRV_WAKE_UP_EV:
3521 case ESE_DZ_DRV_START_UP_EV:
3522 /* event queue init complete. ok. */
3525 netif_err(efx, hw, efx->net_dev,
3526 "channel %d unknown driver event type %d"
3527 " (data " EFX_QWORD_FMT ")\n",
3528 channel->channel, subcode,
3529 EFX_QWORD_VAL(*event));
3534 static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3537 struct efx_nic *efx = channel->efx;
3540 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3544 channel->event_test_cpu = raw_smp_processor_id();
3546 case EFX_EF10_REFILL:
3547 /* The queue must be empty, so we won't receive any rx
3548 * events, so efx_process_channel() won't refill the
3549 * queue. Refill it here
3551 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
3554 netif_err(efx, hw, efx->net_dev,
3555 "channel %d unknown driver event type %u"
3556 " (data " EFX_QWORD_FMT ")\n",
3557 channel->channel, (unsigned) subcode,
3558 EFX_QWORD_VAL(*event));
3562 static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3564 struct efx_nic *efx = channel->efx;
3565 efx_qword_t event, *p_event;
3566 unsigned int read_ptr;
3574 read_ptr = channel->eventq_read_ptr;
3577 p_event = efx_event(channel, read_ptr);
3580 if (!efx_event_present(&event))
3583 EFX_SET_QWORD(*p_event);
3587 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3589 netif_vdbg(efx, drv, efx->net_dev,
3590 "processing event on %d " EFX_QWORD_FMT "\n",
3591 channel->channel, EFX_QWORD_VAL(event));
3594 case ESE_DZ_EV_CODE_MCDI_EV:
3595 efx_mcdi_process_event(channel, &event);
3597 case ESE_DZ_EV_CODE_RX_EV:
3598 spent += efx_ef10_handle_rx_event(channel, &event);
3599 if (spent >= quota) {
3600 /* XXX can we split a merged event to
3601 * avoid going over-quota?
3607 case ESE_DZ_EV_CODE_TX_EV:
3608 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3609 if (tx_descs > efx->txq_entries) {
3612 } else if (++spent == quota) {
3616 case ESE_DZ_EV_CODE_DRIVER_EV:
3617 efx_ef10_handle_driver_event(channel, &event);
3618 if (++spent == quota)
3621 case EFX_EF10_DRVGEN_EV:
3622 efx_ef10_handle_driver_generated_event(channel, &event);
3625 netif_err(efx, hw, efx->net_dev,
3626 "channel %d unknown event type %d"
3627 " (data " EFX_QWORD_FMT ")\n",
3628 channel->channel, ev_code,
3629 EFX_QWORD_VAL(event));
3634 channel->eventq_read_ptr = read_ptr;
3638 static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3640 struct efx_nic *efx = channel->efx;
3643 if (EFX_EF10_WORKAROUND_35388(efx)) {
3644 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3645 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3646 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3647 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3649 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3650 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3651 ERF_DD_EVQ_IND_RPTR,
3652 (channel->eventq_read_ptr &
3653 channel->eventq_mask) >>
3654 ERF_DD_EVQ_IND_RPTR_WIDTH);
3655 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3657 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3658 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3659 ERF_DD_EVQ_IND_RPTR,
3660 channel->eventq_read_ptr &
3661 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3662 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3665 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3666 channel->eventq_read_ptr &
3667 channel->eventq_mask);
3668 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3672 static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3674 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3675 struct efx_nic *efx = channel->efx;
3679 EFX_POPULATE_QWORD_2(event,
3680 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3681 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3683 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3685 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3686 * already swapped the data to little-endian order.
3688 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3689 sizeof(efx_qword_t));
3691 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3700 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3703 void efx_ef10_handle_drain_event(struct efx_nic *efx)
3705 if (atomic_dec_and_test(&efx->active_queues))
3706 wake_up(&efx->flush_wq);
3708 WARN_ON(atomic_read(&efx->active_queues) < 0);
3711 static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3713 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3714 struct efx_channel *channel;
3715 struct efx_tx_queue *tx_queue;
3716 struct efx_rx_queue *rx_queue;
3719 /* If the MC has just rebooted, the TX/RX queues will have already been
3720 * torn down, but efx->active_queues needs to be set to zero.
3722 if (nic_data->must_realloc_vis) {
3723 atomic_set(&efx->active_queues, 0);
3727 /* Do not attempt to write to the NIC during EEH recovery */
3728 if (efx->state != STATE_RECOVERY) {
3729 efx_for_each_channel(channel, efx) {
3730 efx_for_each_channel_rx_queue(rx_queue, channel)
3731 efx_ef10_rx_fini(rx_queue);
3732 efx_for_each_channel_tx_queue(tx_queue, channel)
3733 efx_ef10_tx_fini(tx_queue);
3736 wait_event_timeout(efx->flush_wq,
3737 atomic_read(&efx->active_queues) == 0,
3738 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3739 pending = atomic_read(&efx->active_queues);
3741 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3750 static void efx_ef10_prepare_flr(struct efx_nic *efx)
3752 atomic_set(&efx->active_queues, 0);
3755 static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3756 const struct efx_filter_spec *right)
3758 if ((left->match_flags ^ right->match_flags) |
3759 ((left->flags ^ right->flags) &
3760 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3763 return memcmp(&left->outer_vid, &right->outer_vid,
3764 sizeof(struct efx_filter_spec) -
3765 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3768 static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3770 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3771 return jhash2((const u32 *)&spec->outer_vid,
3772 (sizeof(struct efx_filter_spec) -
3773 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3775 /* XXX should we randomise the initval? */
3778 /* Decide whether a filter should be exclusive or else should allow
3779 * delivery to additional recipients. Currently we decide that
3780 * filters for specific local unicast MAC and IP addresses are
3783 static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3785 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3786 !is_multicast_ether_addr(spec->loc_mac))
3789 if ((spec->match_flags &
3790 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3791 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3792 if (spec->ether_type == htons(ETH_P_IP) &&
3793 !ipv4_is_multicast(spec->loc_host[0]))
3795 if (spec->ether_type == htons(ETH_P_IPV6) &&
3796 ((const u8 *)spec->loc_host)[0] != 0xff)
3803 static struct efx_filter_spec *
3804 efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3805 unsigned int filter_idx)
3807 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3808 ~EFX_EF10_FILTER_FLAGS);
3812 efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3813 unsigned int filter_idx)
3815 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3819 efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3820 unsigned int filter_idx,
3821 const struct efx_filter_spec *spec,
3824 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3828 efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
3829 const struct efx_filter_spec *spec,
3832 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
3833 u32 match_fields = 0, uc_match, mc_match;
3835 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3836 efx_ef10_filter_is_exclusive(spec) ?
3837 MC_CMD_FILTER_OP_IN_OP_INSERT :
3838 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3840 /* Convert match flags and values. Unlike almost
3841 * everything else in MCDI, these fields are in
3842 * network byte order.
3844 #define COPY_VALUE(value, mcdi_field) \
3847 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3848 mcdi_field ## _LBN; \
3850 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3852 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3853 &value, sizeof(value)); \
3855 #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3856 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3857 COPY_VALUE(spec->gen_field, mcdi_field); \
3859 /* Handle encap filters first. They will always be mismatch
3860 * (unknown UC or MC) filters
3863 /* ether_type and outer_ip_proto need to be variables
3864 * because COPY_VALUE wants to memcpy them
3867 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
3868 ETH_P_IPV6 : ETH_P_IP);
3869 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
3872 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
3873 case EFX_ENCAP_TYPE_VXLAN:
3874 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
3876 case EFX_ENCAP_TYPE_GENEVE:
3877 COPY_VALUE(ether_type, ETHER_TYPE);
3878 outer_ip_proto = IPPROTO_UDP;
3879 COPY_VALUE(outer_ip_proto, IP_PROTO);
3880 /* We always need to set the type field, even
3881 * though we're not matching on the TNI.
3883 MCDI_POPULATE_DWORD_1(inbuf,
3884 FILTER_OP_EXT_IN_VNI_OR_VSID,
3885 FILTER_OP_EXT_IN_VNI_TYPE,
3888 case EFX_ENCAP_TYPE_NVGRE:
3889 COPY_VALUE(ether_type, ETHER_TYPE);
3890 outer_ip_proto = IPPROTO_GRE;
3891 COPY_VALUE(outer_ip_proto, IP_PROTO);
3897 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
3898 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
3900 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3901 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
3904 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3906 is_multicast_ether_addr(spec->loc_mac) ?
3909 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3910 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3911 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3912 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3913 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3914 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3915 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3916 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3917 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3918 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3921 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3925 static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3926 const struct efx_filter_spec *spec,
3927 efx_dword_t *inbuf, u64 handle,
3930 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3931 u32 flags = spec->flags;
3933 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
3935 /* Remove RSS flag if we don't have an RSS context. */
3936 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3937 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3938 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3939 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3942 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3943 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3944 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3946 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
3949 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
3950 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3951 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3952 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3953 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
3954 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
3955 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3956 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
3957 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3958 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3960 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
3961 (flags & EFX_FILTER_FLAG_RX_RSS) ?
3962 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3963 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
3964 if (flags & EFX_FILTER_FLAG_RX_RSS)
3965 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3966 spec->rss_context !=
3967 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3968 spec->rss_context : nic_data->rx_rss_context);
3971 static int efx_ef10_filter_push(struct efx_nic *efx,
3972 const struct efx_filter_spec *spec,
3973 u64 *handle, bool replacing)
3975 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
3976 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
3979 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3980 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3981 outbuf, sizeof(outbuf), NULL);
3983 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3985 rc = -EBUSY; /* to match efx_farch_filter_insert() */
3989 static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
3991 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
3992 unsigned int match_flags = spec->match_flags;
3993 unsigned int uc_match, mc_match;
3996 #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
3997 unsigned int old_match_flags = match_flags; \
3998 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3999 if (match_flags != old_match_flags) \
4002 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
4003 mcdi_field ## _LBN : \
4004 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
4005 mcdi_field ## _LBN)); \
4007 /* inner or outer based on encap type */
4008 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
4009 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
4010 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
4011 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
4012 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
4013 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
4014 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
4015 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
4017 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
4018 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
4019 #undef MAP_FILTER_TO_MCDI_FLAG
4021 /* special handling for encap type, and mismatch */
4023 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
4025 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4026 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4028 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4029 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4031 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4032 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4035 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
4036 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
4038 is_multicast_ether_addr(spec->loc_mac) ?
4043 /* Did we map them all? */
4044 WARN_ON_ONCE(match_flags);
4049 static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
4050 const struct efx_filter_spec *spec)
4052 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4053 unsigned int match_pri;
4056 match_pri < table->rx_match_count;
4058 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
4061 return -EPROTONOSUPPORT;
4064 static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4065 struct efx_filter_spec *spec,
4068 struct efx_ef10_filter_table *table = efx->filter_state;
4069 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4070 struct efx_filter_spec *saved_spec;
4071 unsigned int match_pri, hash;
4072 unsigned int priv_flags;
4073 bool replacing = false;
4079 /* For now, only support RX filters */
4080 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4084 rc = efx_ef10_filter_pri(table, spec);
4089 hash = efx_ef10_filter_hash(spec);
4090 is_mc_recip = efx_filter_is_mc_recipient(spec);
4092 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4094 /* Find any existing filters with the same match tuple or
4095 * else a free slot to insert at. If any of them are busy,
4096 * we have to wait and retry.
4099 unsigned int depth = 1;
4102 spin_lock_bh(&efx->filter_lock);
4105 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4106 saved_spec = efx_ef10_filter_entry_spec(table, i);
4111 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4112 if (table->entry[i].spec &
4113 EFX_EF10_FILTER_FLAG_BUSY)
4115 if (spec->priority < saved_spec->priority &&
4116 spec->priority != EFX_FILTER_PRI_AUTO) {
4121 /* This is the only one */
4122 if (spec->priority ==
4123 saved_spec->priority &&
4130 } else if (spec->priority >
4131 saved_spec->priority ||
4133 saved_spec->priority &&
4138 __set_bit(depth, mc_rem_map);
4142 /* Once we reach the maximum search depth, use
4143 * the first suitable slot or return -EBUSY if
4146 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4147 if (ins_index < 0) {
4157 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4158 spin_unlock_bh(&efx->filter_lock);
4163 /* Create a software table entry if necessary, and mark it
4164 * busy. We might yet fail to insert, but any attempt to
4165 * insert a conflicting filter while we're waiting for the
4166 * firmware must find the busy entry.
4168 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4170 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4171 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
4172 /* Just make sure it won't be removed */
4173 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4174 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
4175 table->entry[ins_index].spec &=
4176 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
4181 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4183 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4188 *saved_spec = *spec;
4191 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4192 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4194 /* Mark lower-priority multicast recipients busy prior to removal */
4196 unsigned int depth, i;
4198 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4199 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4200 if (test_bit(depth, mc_rem_map))
4201 table->entry[i].spec |=
4202 EFX_EF10_FILTER_FLAG_BUSY;
4206 spin_unlock_bh(&efx->filter_lock);
4208 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4211 /* Finalise the software table entry */
4212 spin_lock_bh(&efx->filter_lock);
4215 /* Update the fields that may differ */
4216 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4217 saved_spec->flags |=
4218 EFX_FILTER_FLAG_RX_OVER_AUTO;
4219 saved_spec->priority = spec->priority;
4220 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
4221 saved_spec->flags |= spec->flags;
4222 saved_spec->rss_context = spec->rss_context;
4223 saved_spec->dmaq_id = spec->dmaq_id;
4225 } else if (!replacing) {
4229 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4231 /* Remove and finalise entries for lower-priority multicast
4235 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4236 unsigned int depth, i;
4238 memset(inbuf, 0, sizeof(inbuf));
4240 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4241 if (!test_bit(depth, mc_rem_map))
4244 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4245 saved_spec = efx_ef10_filter_entry_spec(table, i);
4246 priv_flags = efx_ef10_filter_entry_flags(table, i);
4249 spin_unlock_bh(&efx->filter_lock);
4250 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4251 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4252 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4253 table->entry[i].handle);
4254 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4255 inbuf, sizeof(inbuf),
4257 spin_lock_bh(&efx->filter_lock);
4265 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4267 efx_ef10_filter_set_entry(table, i, saved_spec,
4272 /* If successful, return the inserted filter ID */
4274 rc = efx_ef10_make_filter_id(match_pri, ins_index);
4276 wake_up_all(&table->waitq);
4278 spin_unlock_bh(&efx->filter_lock);
4279 finish_wait(&table->waitq, &wait);
4283 static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
4285 /* no need to do anything here on EF10 */
4289 * If !by_index, remove by ID
4290 * If by_index, remove by index
4291 * Filter ID may come from userland and must be range-checked.
4293 static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
4294 unsigned int priority_mask,
4295 u32 filter_id, bool by_index)
4297 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
4298 struct efx_ef10_filter_table *table = efx->filter_state;
4299 MCDI_DECLARE_BUF(inbuf,
4300 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4301 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4302 struct efx_filter_spec *spec;
4306 /* Find the software table entry and mark it busy. Don't
4307 * remove it yet; any attempt to update while we're waiting
4308 * for the firmware must find the busy entry.
4311 spin_lock_bh(&efx->filter_lock);
4312 if (!(table->entry[filter_idx].spec &
4313 EFX_EF10_FILTER_FLAG_BUSY))
4315 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4316 spin_unlock_bh(&efx->filter_lock);
4320 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4323 efx_ef10_filter_pri(table, spec) !=
4324 efx_ef10_filter_get_unsafe_pri(filter_id))) {
4329 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
4330 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
4331 /* Just remove flags */
4332 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
4333 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
4338 if (!(priority_mask & (1U << spec->priority))) {
4343 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4344 spin_unlock_bh(&efx->filter_lock);
4346 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
4347 /* Reset to an automatic filter */
4349 struct efx_filter_spec new_spec = *spec;
4351 new_spec.priority = EFX_FILTER_PRI_AUTO;
4352 new_spec.flags = (EFX_FILTER_FLAG_RX |
4353 (efx_rss_enabled(efx) ?
4354 EFX_FILTER_FLAG_RX_RSS : 0));
4355 new_spec.dmaq_id = 0;
4356 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4357 rc = efx_ef10_filter_push(efx, &new_spec,
4358 &table->entry[filter_idx].handle,
4361 spin_lock_bh(&efx->filter_lock);
4365 /* Really remove the filter */
4367 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4368 efx_ef10_filter_is_exclusive(spec) ?
4369 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4370 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4371 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4372 table->entry[filter_idx].handle);
4373 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4374 inbuf, sizeof(inbuf), NULL, 0, NULL);
4376 spin_lock_bh(&efx->filter_lock);
4377 if ((rc == 0) || (rc == -ENOENT)) {
4378 /* Filter removed OK or didn't actually exist */
4380 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4382 efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
4383 MC_CMD_FILTER_OP_EXT_IN_LEN,
4388 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4389 wake_up_all(&table->waitq);
4391 spin_unlock_bh(&efx->filter_lock);
4392 finish_wait(&table->waitq, &wait);
4396 static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4397 enum efx_filter_priority priority,
4400 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4404 static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4405 enum efx_filter_priority priority,
4408 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4410 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
4413 static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4414 enum efx_filter_priority priority,
4415 u32 filter_id, struct efx_filter_spec *spec)
4417 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
4418 struct efx_ef10_filter_table *table = efx->filter_state;
4419 const struct efx_filter_spec *saved_spec;
4422 spin_lock_bh(&efx->filter_lock);
4423 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4424 if (saved_spec && saved_spec->priority == priority &&
4425 efx_ef10_filter_pri(table, saved_spec) ==
4426 efx_ef10_filter_get_unsafe_pri(filter_id)) {
4427 *spec = *saved_spec;
4432 spin_unlock_bh(&efx->filter_lock);
4436 static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
4437 enum efx_filter_priority priority)
4439 unsigned int priority_mask;
4443 priority_mask = (((1U << (priority + 1)) - 1) &
4444 ~(1U << EFX_FILTER_PRI_AUTO));
4446 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4447 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4449 if (rc && rc != -ENOENT)
4456 static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4457 enum efx_filter_priority priority)
4459 struct efx_ef10_filter_table *table = efx->filter_state;
4460 unsigned int filter_idx;
4463 spin_lock_bh(&efx->filter_lock);
4464 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4465 if (table->entry[filter_idx].spec &&
4466 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4470 spin_unlock_bh(&efx->filter_lock);
4474 static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4476 struct efx_ef10_filter_table *table = efx->filter_state;
4478 return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
4481 static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4482 enum efx_filter_priority priority,
4485 struct efx_ef10_filter_table *table = efx->filter_state;
4486 struct efx_filter_spec *spec;
4487 unsigned int filter_idx;
4490 spin_lock_bh(&efx->filter_lock);
4491 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4492 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4493 if (spec && spec->priority == priority) {
4494 if (count == size) {
4499 efx_ef10_make_filter_id(
4500 efx_ef10_filter_pri(table, spec),
4504 spin_unlock_bh(&efx->filter_lock);
4508 #ifdef CONFIG_RFS_ACCEL
4510 static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4512 static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4513 struct efx_filter_spec *spec)
4515 struct efx_ef10_filter_table *table = efx->filter_state;
4516 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4517 struct efx_filter_spec *saved_spec;
4518 unsigned int hash, i, depth = 1;
4519 bool replacing = false;
4524 /* Must be an RX filter without RSS and not for a multicast
4525 * destination address (RFS only works for connected sockets).
4526 * These restrictions allow us to pass only a tiny amount of
4527 * data through to the completion function.
4529 EFX_WARN_ON_PARANOID(spec->flags !=
4530 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4531 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4532 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4534 hash = efx_ef10_filter_hash(spec);
4536 spin_lock_bh(&efx->filter_lock);
4538 /* Find any existing filter with the same match tuple or else
4539 * a free slot to insert at. If an existing filter is busy,
4540 * we have to give up.
4543 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4544 saved_spec = efx_ef10_filter_entry_spec(table, i);
4549 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4550 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4554 if (spec->priority < saved_spec->priority) {
4562 /* Once we reach the maximum search depth, use the
4563 * first suitable slot or return -EBUSY if there was
4566 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4567 if (ins_index < 0) {
4577 /* Create a software table entry if necessary, and mark it
4578 * busy. We might yet fail to insert, but any attempt to
4579 * insert a conflicting filter while we're waiting for the
4580 * firmware must find the busy entry.
4582 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4586 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4591 *saved_spec = *spec;
4593 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4594 EFX_EF10_FILTER_FLAG_BUSY);
4596 spin_unlock_bh(&efx->filter_lock);
4598 /* Pack up the variables needed on completion */
4599 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4601 efx_ef10_filter_push_prep(efx, spec, inbuf,
4602 table->entry[ins_index].handle, replacing);
4603 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4604 MC_CMD_FILTER_OP_OUT_LEN,
4605 efx_ef10_filter_rfs_insert_complete, cookie);
4610 spin_unlock_bh(&efx->filter_lock);
4615 efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4616 int rc, efx_dword_t *outbuf,
4617 size_t outlen_actual)
4619 struct efx_ef10_filter_table *table = efx->filter_state;
4620 unsigned int ins_index, dmaq_id;
4621 struct efx_filter_spec *spec;
4624 /* Unpack the cookie */
4625 replacing = cookie >> 31;
4626 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4627 dmaq_id = cookie & 0xffff;
4629 spin_lock_bh(&efx->filter_lock);
4630 spec = efx_ef10_filter_entry_spec(table, ins_index);
4632 table->entry[ins_index].handle =
4633 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4635 spec->dmaq_id = dmaq_id;
4636 } else if (!replacing) {
4640 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4641 spin_unlock_bh(&efx->filter_lock);
4643 wake_up_all(&table->waitq);
4647 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4648 unsigned long filter_idx,
4649 int rc, efx_dword_t *outbuf,
4650 size_t outlen_actual);
4652 static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4653 unsigned int filter_idx)
4655 struct efx_ef10_filter_table *table = efx->filter_state;
4656 struct efx_filter_spec *spec =
4657 efx_ef10_filter_entry_spec(table, filter_idx);
4658 MCDI_DECLARE_BUF(inbuf,
4659 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4660 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4663 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4664 spec->priority != EFX_FILTER_PRI_HINT ||
4665 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4666 flow_id, filter_idx))
4669 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4670 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4671 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4672 table->entry[filter_idx].handle);
4673 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4674 efx_ef10_filter_rfs_expire_complete, filter_idx))
4677 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4682 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4683 unsigned long filter_idx,
4684 int rc, efx_dword_t *outbuf,
4685 size_t outlen_actual)
4687 struct efx_ef10_filter_table *table = efx->filter_state;
4688 struct efx_filter_spec *spec =
4689 efx_ef10_filter_entry_spec(table, filter_idx);
4691 spin_lock_bh(&efx->filter_lock);
4694 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4696 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4697 wake_up_all(&table->waitq);
4698 spin_unlock_bh(&efx->filter_lock);
4701 #endif /* CONFIG_RFS_ACCEL */
4703 static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
4705 int match_flags = 0;
4707 #define MAP_FLAG(gen_flag, mcdi_field) do { \
4708 u32 old_mcdi_flags = mcdi_flags; \
4709 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4710 mcdi_field ## _LBN); \
4711 if (mcdi_flags != old_mcdi_flags) \
4712 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4716 /* encap filters must specify encap type */
4717 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4718 /* and imply ethertype and ip proto */
4720 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4722 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4723 /* VLAN tags refer to the outer packet */
4724 MAP_FLAG(INNER_VID, INNER_VLAN);
4725 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4726 /* everything else refers to the inner packet */
4727 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4728 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4729 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4730 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4731 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4732 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4733 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4734 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4735 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4736 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4738 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4739 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4740 MAP_FLAG(REM_HOST, SRC_IP);
4741 MAP_FLAG(LOC_HOST, DST_IP);
4742 MAP_FLAG(REM_MAC, SRC_MAC);
4743 MAP_FLAG(REM_PORT, SRC_PORT);
4744 MAP_FLAG(LOC_MAC, DST_MAC);
4745 MAP_FLAG(LOC_PORT, DST_PORT);
4746 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4747 MAP_FLAG(INNER_VID, INNER_VLAN);
4748 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4749 MAP_FLAG(IP_PROTO, IP_PROTO);
4753 /* Did we map them all? */
4760 static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4762 struct efx_ef10_filter_table *table = efx->filter_state;
4763 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4765 /* See comment in efx_ef10_filter_table_remove() */
4766 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4772 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4773 efx_ef10_filter_del_vlan_internal(efx, vlan);
4776 static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4778 enum efx_filter_match_flags match_flags)
4780 unsigned int match_pri;
4784 match_pri < table->rx_match_count;
4786 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
4787 table->rx_match_mcdi_flags[match_pri]);
4788 if (mf == match_flags)
4796 efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4797 struct efx_ef10_filter_table *table,
4800 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4801 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4802 unsigned int pd_match_pri, pd_match_count;
4806 /* Find out which RX filter types are supported, and their priorities */
4807 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4809 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
4810 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4811 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4812 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4817 pd_match_count = MCDI_VAR_ARRAY_LEN(
4818 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4820 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4824 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4826 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
4828 netif_dbg(efx, probe, efx->net_dev,
4829 "%s: fw flags %#x pri %u not supported in driver\n",
4830 __func__, mcdi_flags, pd_match_pri);
4832 netif_dbg(efx, probe, efx->net_dev,
4833 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4834 __func__, mcdi_flags, pd_match_pri,
4835 rc, table->rx_match_count);
4836 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4837 table->rx_match_count++;
4844 static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4846 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4847 struct net_device *net_dev = efx->net_dev;
4848 struct efx_ef10_filter_table *table;
4849 struct efx_ef10_vlan *vlan;
4852 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4855 if (efx->filter_state) /* already probed */
4858 table = kzalloc(sizeof(*table), GFP_KERNEL);
4862 table->rx_match_count = 0;
4863 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
4866 if (nic_data->datapath_caps &
4867 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
4868 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
4871 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4872 !(efx_ef10_filter_match_supported(table, false,
4873 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4874 efx_ef10_filter_match_supported(table, false,
4875 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4876 netif_info(efx, probe, net_dev,
4877 "VLAN filters are not supported in this firmware variant\n");
4878 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4879 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4880 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4883 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4884 if (!table->entry) {
4889 table->mc_promisc_last = false;
4890 table->vlan_filter =
4891 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4892 INIT_LIST_HEAD(&table->vlan_list);
4894 efx->filter_state = table;
4895 init_waitqueue_head(&table->waitq);
4897 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4898 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4906 efx_ef10_filter_cleanup_vlans(efx);
4907 efx->filter_state = NULL;
4913 /* Caller must hold efx->filter_sem for read if race against
4914 * efx_ef10_filter_table_remove() is possible
4916 static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4918 struct efx_ef10_filter_table *table = efx->filter_state;
4919 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4920 unsigned int invalid_filters = 0, failed = 0;
4921 struct efx_ef10_filter_vlan *vlan;
4922 struct efx_filter_spec *spec;
4923 unsigned int filter_idx;
4928 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4930 if (!nic_data->must_restore_filters)
4936 spin_lock_bh(&efx->filter_lock);
4938 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4939 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4943 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
4945 while (match_pri < table->rx_match_count &&
4946 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
4948 if (match_pri >= table->rx_match_count) {
4952 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4953 spec->rss_context != nic_data->rx_rss_context)
4954 netif_warn(efx, drv, efx->net_dev,
4955 "Warning: unable to restore a filter with specific RSS context.\n");
4957 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4958 spin_unlock_bh(&efx->filter_lock);
4960 rc = efx_ef10_filter_push(efx, spec,
4961 &table->entry[filter_idx].handle,
4965 spin_lock_bh(&efx->filter_lock);
4969 list_for_each_entry(vlan, &table->vlan_list, list)
4970 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
4971 if (vlan->default_filters[i] == filter_idx)
4972 vlan->default_filters[i] =
4973 EFX_EF10_FILTER_ID_INVALID;
4976 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4978 table->entry[filter_idx].spec &=
4979 ~EFX_EF10_FILTER_FLAG_BUSY;
4983 spin_unlock_bh(&efx->filter_lock);
4985 /* This can happen validly if the MC's capabilities have changed, so
4988 if (invalid_filters)
4989 netif_dbg(efx, drv, efx->net_dev,
4990 "Did not restore %u filters that are now unsupported.\n",
4994 netif_err(efx, hw, efx->net_dev,
4995 "unable to restore %u filters\n", failed);
4997 nic_data->must_restore_filters = false;
5000 static void efx_ef10_filter_table_remove(struct efx_nic *efx)
5002 struct efx_ef10_filter_table *table = efx->filter_state;
5003 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
5004 struct efx_filter_spec *spec;
5005 unsigned int filter_idx;
5008 efx_ef10_filter_cleanup_vlans(efx);
5009 efx->filter_state = NULL;
5010 /* If we were called without locking, then it's not safe to free
5011 * the table as others might be using it. So we just WARN, leak
5012 * the memory, and potentially get an inconsistent filter table
5014 * This should never actually happen.
5016 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5022 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5023 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5027 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
5028 efx_ef10_filter_is_exclusive(spec) ?
5029 MC_CMD_FILTER_OP_IN_OP_REMOVE :
5030 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
5031 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
5032 table->entry[filter_idx].handle);
5033 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
5034 sizeof(inbuf), NULL, 0, NULL);
5036 netif_info(efx, drv, efx->net_dev,
5037 "%s: filter %04x remove failed\n",
5038 __func__, filter_idx);
5042 vfree(table->entry);
5046 static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5048 struct efx_ef10_filter_table *table = efx->filter_state;
5049 unsigned int filter_idx;
5051 if (*id != EFX_EF10_FILTER_ID_INVALID) {
5052 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
5053 if (!table->entry[filter_idx].spec)
5054 netif_dbg(efx, drv, efx->net_dev,
5055 "marked null spec old %04x:%04x\n", *id,
5057 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
5058 *id = EFX_EF10_FILTER_ID_INVALID;
5062 /* Mark old per-VLAN filters that may need to be removed */
5063 static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
5064 struct efx_ef10_filter_vlan *vlan)
5066 struct efx_ef10_filter_table *table = efx->filter_state;
5069 for (i = 0; i < table->dev_uc_count; i++)
5070 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
5071 for (i = 0; i < table->dev_mc_count; i++)
5072 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
5073 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5074 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
5077 /* Mark old filters that may need to be removed.
5078 * Caller must hold efx->filter_sem for read if race against
5079 * efx_ef10_filter_table_remove() is possible
5081 static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5083 struct efx_ef10_filter_table *table = efx->filter_state;
5084 struct efx_ef10_filter_vlan *vlan;
5086 spin_lock_bh(&efx->filter_lock);
5087 list_for_each_entry(vlan, &table->vlan_list, list)
5088 _efx_ef10_filter_vlan_mark_old(efx, vlan);
5089 spin_unlock_bh(&efx->filter_lock);
5092 static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
5094 struct efx_ef10_filter_table *table = efx->filter_state;
5095 struct net_device *net_dev = efx->net_dev;
5096 struct netdev_hw_addr *uc;
5099 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
5100 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
5102 netdev_for_each_uc_addr(uc, net_dev) {
5103 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
5104 table->uc_promisc = true;
5107 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
5111 table->dev_uc_count = i;
5114 static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
5116 struct efx_ef10_filter_table *table = efx->filter_state;
5117 struct net_device *net_dev = efx->net_dev;
5118 struct netdev_hw_addr *mc;
5121 table->mc_overflow = false;
5122 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
5125 netdev_for_each_mc_addr(mc, net_dev) {
5126 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
5127 table->mc_promisc = true;
5128 table->mc_overflow = true;
5131 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5135 table->dev_mc_count = i;
5138 static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
5139 struct efx_ef10_filter_vlan *vlan,
5140 bool multicast, bool rollback)
5142 struct efx_ef10_filter_table *table = efx->filter_state;
5143 struct efx_ef10_dev_addr *addr_list;
5144 enum efx_filter_flags filter_flags;
5145 struct efx_filter_spec spec;
5153 addr_list = table->dev_mc_list;
5154 addr_count = table->dev_mc_count;
5157 addr_list = table->dev_uc_list;
5158 addr_count = table->dev_uc_count;
5162 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5164 /* Insert/renew filters */
5165 for (i = 0; i < addr_count; i++) {
5166 EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
5167 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5168 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
5169 rc = efx_ef10_filter_insert(efx, &spec, true);
5172 netif_info(efx, drv, efx->net_dev,
5173 "efx_ef10_filter_insert failed rc=%d\n",
5175 /* Fall back to promiscuous */
5176 for (j = 0; j < i; j++) {
5177 efx_ef10_filter_remove_unsafe(
5178 efx, EFX_FILTER_PRI_AUTO,
5180 ids[j] = EFX_EF10_FILTER_ID_INVALID;
5184 /* keep invalid ID, and carry on */
5187 ids[i] = efx_ef10_filter_get_unsafe_id(rc);
5191 if (multicast && rollback) {
5192 /* Also need an Ethernet broadcast filter */
5193 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5194 EFX_EF10_FILTER_ID_INVALID);
5195 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5196 eth_broadcast_addr(baddr);
5197 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
5198 rc = efx_ef10_filter_insert(efx, &spec, true);
5200 netif_warn(efx, drv, efx->net_dev,
5201 "Broadcast filter insert failed rc=%d\n", rc);
5202 /* Fall back to promiscuous */
5203 for (j = 0; j < i; j++) {
5204 efx_ef10_filter_remove_unsafe(
5205 efx, EFX_FILTER_PRI_AUTO,
5207 ids[j] = EFX_EF10_FILTER_ID_INVALID;
5211 vlan->default_filters[EFX_EF10_BCAST] =
5212 efx_ef10_filter_get_unsafe_id(rc);
5219 static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5220 struct efx_ef10_filter_vlan *vlan,
5221 enum efx_encap_type encap_type,
5222 bool multicast, bool rollback)
5224 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5225 enum efx_filter_flags filter_flags;
5226 struct efx_filter_spec spec;
5231 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5233 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
5236 efx_filter_set_mc_def(&spec);
5238 efx_filter_set_uc_def(&spec);
5241 if (nic_data->datapath_caps &
5242 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5243 efx_filter_set_encap_type(&spec, encap_type);
5245 /* don't insert encap filters on non-supporting
5246 * platforms. ID will be left as INVALID.
5251 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5252 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5254 rc = efx_ef10_filter_insert(efx, &spec, true);
5256 const char *um = multicast ? "Multicast" : "Unicast";
5257 const char *encap_name = "";
5258 const char *encap_ipv = "";
5260 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5261 EFX_ENCAP_TYPE_VXLAN)
5262 encap_name = "VXLAN ";
5263 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5264 EFX_ENCAP_TYPE_NVGRE)
5265 encap_name = "NVGRE ";
5266 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5267 EFX_ENCAP_TYPE_GENEVE)
5268 encap_name = "GENEVE ";
5269 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5270 encap_ipv = "IPv6 ";
5271 else if (encap_type)
5272 encap_ipv = "IPv4 ";
5274 /* unprivileged functions can't insert mismatch filters
5275 * for encapsulated or unicast traffic, so downgrade
5276 * those warnings to debug.
5278 netif_cond_dbg(efx, drv, efx->net_dev,
5279 rc == -EPERM && (encap_type || !multicast), warn,
5280 "%s%s%s mismatch filter insert failed rc=%d\n",
5281 encap_name, encap_ipv, um, rc);
5282 } else if (multicast) {
5283 /* mapping from encap types to default filter IDs (multicast) */
5284 static enum efx_ef10_default_filters map[] = {
5285 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5286 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5287 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5288 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5289 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5290 EFX_EF10_VXLAN6_MCDEF,
5291 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5292 EFX_EF10_NVGRE6_MCDEF,
5293 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5294 EFX_EF10_GENEVE6_MCDEF,
5297 /* quick bounds check (BCAST result impossible) */
5298 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
5299 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
5303 /* then follow map */
5304 id = &vlan->default_filters[map[encap_type]];
5306 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5307 *id = efx_ef10_filter_get_unsafe_id(rc);
5308 if (!nic_data->workaround_26807 && !encap_type) {
5309 /* Also need an Ethernet broadcast filter */
5310 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
5312 eth_broadcast_addr(baddr);
5313 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
5314 rc = efx_ef10_filter_insert(efx, &spec, true);
5316 netif_warn(efx, drv, efx->net_dev,
5317 "Broadcast filter insert failed rc=%d\n",
5320 /* Roll back the mc_def filter */
5321 efx_ef10_filter_remove_unsafe(
5322 efx, EFX_FILTER_PRI_AUTO,
5324 *id = EFX_EF10_FILTER_ID_INVALID;
5328 EFX_WARN_ON_PARANOID(
5329 vlan->default_filters[EFX_EF10_BCAST] !=
5330 EFX_EF10_FILTER_ID_INVALID);
5331 vlan->default_filters[EFX_EF10_BCAST] =
5332 efx_ef10_filter_get_unsafe_id(rc);
5337 /* mapping from encap types to default filter IDs (unicast) */
5338 static enum efx_ef10_default_filters map[] = {
5339 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5340 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5341 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5342 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5343 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5344 EFX_EF10_VXLAN6_UCDEF,
5345 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5346 EFX_EF10_NVGRE6_UCDEF,
5347 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5348 EFX_EF10_GENEVE6_UCDEF,
5351 /* quick bounds check (BCAST result impossible) */
5352 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
5353 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
5357 /* then follow map */
5358 id = &vlan->default_filters[map[encap_type]];
5359 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5366 /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5367 * flag or removes these filters, we don't need to hold the filter_lock while
5368 * scanning for these filters.
5370 static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5372 struct efx_ef10_filter_table *table = efx->filter_state;
5373 int remove_failed = 0;
5374 int remove_noent = 0;
5378 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
5379 if (READ_ONCE(table->entry[i].spec) &
5380 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
5381 rc = efx_ef10_filter_remove_internal(efx,
5382 1U << EFX_FILTER_PRI_AUTO, i, true);
5391 netif_info(efx, drv, efx->net_dev,
5392 "%s: failed to remove %d filters\n",
5393 __func__, remove_failed);
5395 netif_info(efx, drv, efx->net_dev,
5396 "%s: failed to remove %d non-existent filters\n",
5397 __func__, remove_noent);
5400 static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5402 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5403 u8 mac_old[ETH_ALEN];
5406 /* Only reconfigure a PF-created vport */
5407 if (is_zero_ether_addr(nic_data->vport_mac))
5410 efx_device_detach_sync(efx);
5411 efx_net_stop(efx->net_dev);
5412 down_write(&efx->filter_sem);
5413 efx_ef10_filter_table_remove(efx);
5414 up_write(&efx->filter_sem);
5416 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5418 goto restore_filters;
5420 ether_addr_copy(mac_old, nic_data->vport_mac);
5421 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5422 nic_data->vport_mac);
5424 goto restore_vadaptor;
5426 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5427 efx->net_dev->dev_addr);
5429 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5431 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5433 /* Failed to add original MAC, so clear vport_mac */
5434 eth_zero_addr(nic_data->vport_mac);
5440 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5444 down_write(&efx->filter_sem);
5445 rc2 = efx_ef10_filter_table_probe(efx);
5446 up_write(&efx->filter_sem);
5450 rc2 = efx_net_open(efx->net_dev);
5454 efx_device_attach_if_not_resetting(efx);
5459 netif_err(efx, drv, efx->net_dev,
5460 "Failed to restore when changing MAC address - scheduling reset\n");
5461 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5463 return rc ? rc : rc2;
5466 /* Caller must hold efx->filter_sem for read if race against
5467 * efx_ef10_filter_table_remove() is possible
5469 static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5470 struct efx_ef10_filter_vlan *vlan)
5472 struct efx_ef10_filter_table *table = efx->filter_state;
5473 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5475 /* Do not install unspecified VID if VLAN filtering is enabled.
5476 * Do not install all specified VIDs if VLAN filtering is disabled.
5478 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5481 /* Insert/renew unicast filters */
5482 if (table->uc_promisc) {
5483 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5485 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
5487 /* If any of the filters failed to insert, fall back to
5488 * promiscuous mode - add in the uc_def filter. But keep
5489 * our individual unicast filters.
5491 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
5492 efx_ef10_filter_insert_def(efx, vlan,
5493 EFX_ENCAP_TYPE_NONE,
5496 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5498 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5499 EFX_ENCAP_FLAG_IPV6,
5501 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5503 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5504 EFX_ENCAP_FLAG_IPV6,
5506 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5508 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5509 EFX_ENCAP_FLAG_IPV6,
5512 /* Insert/renew multicast filters */
5513 /* If changing promiscuous state with cascaded multicast filters, remove
5514 * old filters first, so that packets are dropped rather than duplicated
5516 if (nic_data->workaround_26807 &&
5517 table->mc_promisc_last != table->mc_promisc)
5518 efx_ef10_filter_remove_old(efx);
5519 if (table->mc_promisc) {
5520 if (nic_data->workaround_26807) {
5521 /* If we failed to insert promiscuous filters, rollback
5522 * and fall back to individual multicast filters
5524 if (efx_ef10_filter_insert_def(efx, vlan,
5525 EFX_ENCAP_TYPE_NONE,
5527 /* Changing promisc state, so remove old filters */
5528 efx_ef10_filter_remove_old(efx);
5529 efx_ef10_filter_insert_addr_list(efx, vlan,
5533 /* If we failed to insert promiscuous filters, don't
5534 * rollback. Regardless, also insert the mc_list,
5535 * unless it's incomplete due to overflow
5537 efx_ef10_filter_insert_def(efx, vlan,
5538 EFX_ENCAP_TYPE_NONE,
5540 if (!table->mc_overflow)
5541 efx_ef10_filter_insert_addr_list(efx, vlan,
5545 /* If any filters failed to insert, rollback and fall back to
5546 * promiscuous mode - mc_def filter and maybe broadcast. If
5547 * that fails, roll back again and insert as many of our
5548 * individual multicast filters as we can.
5550 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
5551 /* Changing promisc state, so remove old filters */
5552 if (nic_data->workaround_26807)
5553 efx_ef10_filter_remove_old(efx);
5554 if (efx_ef10_filter_insert_def(efx, vlan,
5555 EFX_ENCAP_TYPE_NONE,
5557 efx_ef10_filter_insert_addr_list(efx, vlan,
5561 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5563 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5564 EFX_ENCAP_FLAG_IPV6,
5566 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5568 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5569 EFX_ENCAP_FLAG_IPV6,
5571 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5573 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5574 EFX_ENCAP_FLAG_IPV6,
5578 /* Caller must hold efx->filter_sem for read if race against
5579 * efx_ef10_filter_table_remove() is possible
5581 static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5583 struct efx_ef10_filter_table *table = efx->filter_state;
5584 struct net_device *net_dev = efx->net_dev;
5585 struct efx_ef10_filter_vlan *vlan;
5588 if (!efx_dev_registered(efx))
5594 efx_ef10_filter_mark_old(efx);
5596 /* Copy/convert the address lists; add the primary station
5597 * address and broadcast address
5599 netif_addr_lock_bh(net_dev);
5600 efx_ef10_filter_uc_addr_list(efx);
5601 efx_ef10_filter_mc_addr_list(efx);
5602 netif_addr_unlock_bh(net_dev);
5604 /* If VLAN filtering changes, all old filters are finally removed.
5605 * Do it in advance to avoid conflicts for unicast untagged and
5606 * VLAN 0 tagged filters.
5608 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5609 if (table->vlan_filter != vlan_filter) {
5610 table->vlan_filter = vlan_filter;
5611 efx_ef10_filter_remove_old(efx);
5614 list_for_each_entry(vlan, &table->vlan_list, list)
5615 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5617 efx_ef10_filter_remove_old(efx);
5618 table->mc_promisc_last = table->mc_promisc;
5621 static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5623 struct efx_ef10_filter_table *table = efx->filter_state;
5624 struct efx_ef10_filter_vlan *vlan;
5626 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5628 list_for_each_entry(vlan, &table->vlan_list, list) {
5629 if (vlan->vid == vid)
5636 static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5638 struct efx_ef10_filter_table *table = efx->filter_state;
5639 struct efx_ef10_filter_vlan *vlan;
5642 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5645 vlan = efx_ef10_filter_find_vlan(efx, vid);
5646 if (WARN_ON(vlan)) {
5647 netif_err(efx, drv, efx->net_dev,
5648 "VLAN %u already added\n", vid);
5652 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5658 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5659 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5660 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5661 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
5662 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5663 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
5665 list_add_tail(&vlan->list, &table->vlan_list);
5667 if (efx_dev_registered(efx))
5668 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5673 static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5674 struct efx_ef10_filter_vlan *vlan)
5678 /* See comment in efx_ef10_filter_table_remove() */
5679 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5682 list_del(&vlan->list);
5684 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5685 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5687 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5688 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5690 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5691 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5692 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5693 vlan->default_filters[i]);
5698 static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5700 struct efx_ef10_filter_vlan *vlan;
5702 /* See comment in efx_ef10_filter_table_remove() */
5703 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5706 vlan = efx_ef10_filter_find_vlan(efx, vid);
5708 netif_err(efx, drv, efx->net_dev,
5709 "VLAN %u not found in filter state\n", vid);
5713 efx_ef10_filter_del_vlan_internal(efx, vlan);
5716 static int efx_ef10_set_mac_address(struct efx_nic *efx)
5718 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5719 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5720 bool was_enabled = efx->port_enabled;
5723 efx_device_detach_sync(efx);
5724 efx_net_stop(efx->net_dev);
5726 mutex_lock(&efx->mac_lock);
5727 down_write(&efx->filter_sem);
5728 efx_ef10_filter_table_remove(efx);
5730 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5731 efx->net_dev->dev_addr);
5732 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5733 nic_data->vport_id);
5734 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5735 sizeof(inbuf), NULL, 0, NULL);
5737 efx_ef10_filter_table_probe(efx);
5738 up_write(&efx->filter_sem);
5739 mutex_unlock(&efx->mac_lock);
5742 efx_net_open(efx->net_dev);
5743 efx_device_attach_if_not_resetting(efx);
5745 #ifdef CONFIG_SFC_SRIOV
5746 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
5747 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5750 struct efx_nic *efx_pf;
5752 /* Switch to PF and change MAC address on vport */
5753 efx_pf = pci_get_drvdata(pci_dev_pf);
5755 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
5757 efx->net_dev->dev_addr);
5759 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5760 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5763 /* MAC address successfully changed by VF (with MAC
5764 * spoofing) so update the parent PF if possible.
5766 for (i = 0; i < efx_pf->vf_count; ++i) {
5767 struct ef10_vf *vf = nic_data->vf + i;
5769 if (vf->efx == efx) {
5770 ether_addr_copy(vf->mac,
5771 efx->net_dev->dev_addr);
5779 netif_err(efx, drv, efx->net_dev,
5780 "Cannot change MAC address; use sfboot to enable"
5781 " mac-spoofing on this interface\n");
5782 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5783 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5784 * fall-back to the method of changing the MAC address on the
5785 * vport. This only applies to PFs because such versions of
5786 * MCFW do not support VFs.
5788 rc = efx_ef10_vport_set_mac_address(efx);
5790 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5791 sizeof(inbuf), NULL, 0, rc);
5797 static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5799 efx_ef10_filter_sync_rx_mode(efx);
5801 return efx_mcdi_set_mac(efx);
5804 static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5806 efx_ef10_filter_sync_rx_mode(efx);
5811 static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5813 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5815 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5816 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5820 /* MC BISTs follow a different poll mechanism to phy BISTs.
5821 * The BIST is done in the poll handler on the MC, and the MCDI command
5822 * will block until the BIST is done.
5824 static int efx_ef10_poll_bist(struct efx_nic *efx)
5827 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5831 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5832 outbuf, sizeof(outbuf), &outlen);
5836 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5839 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5841 case MC_CMD_POLL_BIST_PASSED:
5842 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5844 case MC_CMD_POLL_BIST_TIMEOUT:
5845 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5847 case MC_CMD_POLL_BIST_FAILED:
5848 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5851 netif_err(efx, hw, efx->net_dev,
5852 "BIST returned unknown result %u", result);
5857 static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5861 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5863 rc = efx_ef10_start_bist(efx, bist_type);
5867 return efx_ef10_poll_bist(efx);
5871 efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5875 efx_reset_down(efx, RESET_TYPE_WORLD);
5877 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5878 NULL, 0, NULL, 0, NULL);
5882 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5883 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5885 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5890 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5891 return rc ? rc : rc2;
5894 #ifdef CONFIG_SFC_MTD
5896 struct efx_ef10_nvram_type_info {
5897 u16 type, type_mask;
5902 static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5903 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5904 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5905 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5906 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5907 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5908 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5909 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5910 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5911 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
5912 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
5913 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5916 static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5917 struct efx_mcdi_mtd_partition *part,
5920 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5921 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5922 const struct efx_ef10_nvram_type_info *info;
5923 size_t size, erase_size, outlen;
5927 for (info = efx_ef10_nvram_types; ; info++) {
5929 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5931 if ((type & ~info->type_mask) == info->type)
5934 if (info->port != efx_port_num(efx))
5937 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5941 return -ENODEV; /* hide it */
5943 part->nvram_type = type;
5945 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5946 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5947 outbuf, sizeof(outbuf), &outlen);
5950 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5952 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5953 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5954 part->fw_subtype = MCDI_DWORD(outbuf,
5955 NVRAM_METADATA_OUT_SUBTYPE);
5957 part->common.dev_type_name = "EF10 NVRAM manager";
5958 part->common.type_name = info->name;
5960 part->common.mtd.type = MTD_NORFLASH;
5961 part->common.mtd.flags = MTD_CAP_NORFLASH;
5962 part->common.mtd.size = size;
5963 part->common.mtd.erasesize = erase_size;
5968 static int efx_ef10_mtd_probe(struct efx_nic *efx)
5970 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5971 struct efx_mcdi_mtd_partition *parts;
5972 size_t outlen, n_parts_total, i, n_parts;
5978 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5979 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5980 outbuf, sizeof(outbuf), &outlen);
5983 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5986 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5988 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5991 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5996 for (i = 0; i < n_parts_total; i++) {
5997 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5999 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
6002 else if (rc != -ENODEV)
6006 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
6013 #endif /* CONFIG_SFC_MTD */
6015 static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
6017 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
6020 static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
6023 static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
6026 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
6029 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
6030 channel->sync_events_state == SYNC_EVENTS_VALID ||
6031 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
6033 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
6035 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
6036 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6037 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
6040 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6041 inbuf, sizeof(inbuf), NULL, 0, NULL);
6044 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6045 SYNC_EVENTS_DISABLED;
6050 static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
6053 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
6056 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
6057 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
6059 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
6060 channel->sync_events_state = SYNC_EVENTS_DISABLED;
6063 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6064 SYNC_EVENTS_DISABLED;
6066 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
6067 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6068 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
6069 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
6070 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
6073 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6074 inbuf, sizeof(inbuf), NULL, 0, NULL);
6079 static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
6082 int (*set)(struct efx_channel *channel, bool temp);
6083 struct efx_channel *channel;
6086 efx_ef10_rx_enable_timestamping :
6087 efx_ef10_rx_disable_timestamping;
6089 efx_for_each_channel(channel, efx) {
6090 int rc = set(channel, temp);
6091 if (en && rc != 0) {
6092 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
6100 static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
6101 struct hwtstamp_config *init)
6106 static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
6107 struct hwtstamp_config *init)
6111 switch (init->rx_filter) {
6112 case HWTSTAMP_FILTER_NONE:
6113 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
6114 /* if TX timestamping is still requested then leave PTP on */
6115 return efx_ptp_change_mode(efx,
6116 init->tx_type != HWTSTAMP_TX_OFF, 0);
6117 case HWTSTAMP_FILTER_ALL:
6118 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6119 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6120 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6121 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6122 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6123 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6124 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6125 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6126 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6127 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6128 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6129 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
6130 case HWTSTAMP_FILTER_NTP_ALL:
6131 init->rx_filter = HWTSTAMP_FILTER_ALL;
6132 rc = efx_ptp_change_mode(efx, true, 0);
6134 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6136 efx_ptp_change_mode(efx, false, 0);
6143 static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6144 struct netdev_phys_item_id *ppid)
6146 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6148 if (!is_valid_ether_addr(nic_data->port_id))
6151 ppid->id_len = ETH_ALEN;
6152 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6157 static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6159 if (proto != htons(ETH_P_8021Q))
6162 return efx_ef10_add_vlan(efx, vid);
6165 static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6167 if (proto != htons(ETH_P_8021Q))
6170 return efx_ef10_del_vlan(efx, vid);
6173 /* We rely on the MCDI wiping out our TX rings if it made any changes to the
6174 * ports table, ensuring that any TSO descriptors that were made on a now-
6175 * removed tunnel port will be blown away and won't break things when we try
6176 * to transmit them using the new ports table.
6178 static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
6180 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6181 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
6182 MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
6183 bool will_reset = false;
6184 size_t num_entries = 0;
6185 size_t inlen, outlen;
6188 efx_dword_t flags_and_num_entries;
6190 WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
6192 nic_data->udp_tunnels_dirty = false;
6194 if (!(nic_data->datapath_caps &
6195 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
6196 efx_device_attach_if_not_resetting(efx);
6200 BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
6201 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
6203 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6204 if (nic_data->udp_tunnels[i].count &&
6205 nic_data->udp_tunnels[i].port) {
6208 EFX_POPULATE_DWORD_2(entry,
6209 TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
6210 ntohs(nic_data->udp_tunnels[i].port),
6211 TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
6212 nic_data->udp_tunnels[i].type);
6213 *_MCDI_ARRAY_DWORD(inbuf,
6214 SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
6215 num_entries++) = entry;
6219 BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
6220 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
6222 BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
6224 EFX_POPULATE_DWORD_2(flags_and_num_entries,
6225 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
6227 EFX_WORD_1, num_entries);
6228 *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
6229 flags_and_num_entries;
6231 inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
6233 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
6234 inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
6236 /* Most likely the MC rebooted due to another function also
6237 * setting its tunnel port list. Mark the tunnel port list as
6238 * dirty, so it will be pushed upon coming up from the reboot.
6240 nic_data->udp_tunnels_dirty = true;
6245 /* expected not available on unprivileged functions */
6247 netif_warn(efx, drv, efx->net_dev,
6248 "Unable to set UDP tunnel ports; rc=%d.\n", rc);
6249 } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
6250 (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
6251 netif_info(efx, drv, efx->net_dev,
6252 "Rebooting MC due to UDP tunnel port list change\n");
6255 /* Delay for the MC reset to complete. This will make
6256 * unloading other functions a bit smoother. This is a
6257 * race, but the other unload will work whichever way
6258 * it goes, this just avoids an unnecessary error
6263 if (!will_reset && !unloading) {
6264 /* The caller will have detached, relying on the MC reset to
6265 * trigger a re-attach. Since there won't be an MC reset, we
6266 * have to do the attach ourselves.
6268 efx_device_attach_if_not_resetting(efx);
6274 static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
6276 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6279 mutex_lock(&nic_data->udp_tunnels_lock);
6280 if (nic_data->udp_tunnels_dirty) {
6281 /* Make sure all TX are stopped while we modify the table, else
6282 * we might race against an efx_features_check().
6284 efx_device_detach_sync(efx);
6285 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6287 mutex_unlock(&nic_data->udp_tunnels_lock);
6291 static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
6294 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6297 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6298 if (!nic_data->udp_tunnels[i].count)
6300 if (nic_data->udp_tunnels[i].port == port)
6301 return &nic_data->udp_tunnels[i];
6306 static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
6307 struct efx_udp_tunnel tnl)
6309 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6310 struct efx_udp_tunnel *match;
6315 if (!(nic_data->datapath_caps &
6316 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6319 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6320 netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
6321 typebuf, ntohs(tnl.port));
6323 mutex_lock(&nic_data->udp_tunnels_lock);
6324 /* Make sure all TX are stopped while we add to the table, else we
6325 * might race against an efx_features_check().
6327 efx_device_detach_sync(efx);
6329 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6330 if (match != NULL) {
6331 if (match->type == tnl.type) {
6332 netif_dbg(efx, drv, efx->net_dev,
6333 "Referencing existing tunnel entry\n");
6335 /* No need to cause an MCDI update */
6339 efx_get_udp_tunnel_type_name(match->type,
6340 typebuf, sizeof(typebuf));
6341 netif_dbg(efx, drv, efx->net_dev,
6342 "UDP port %d is already in use by %s\n",
6343 ntohs(tnl.port), typebuf);
6348 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
6349 if (!nic_data->udp_tunnels[i].count) {
6350 nic_data->udp_tunnels[i] = tnl;
6351 nic_data->udp_tunnels[i].count = 1;
6352 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6356 netif_dbg(efx, drv, efx->net_dev,
6357 "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
6358 typebuf, ntohs(tnl.port));
6363 mutex_unlock(&nic_data->udp_tunnels_lock);
6367 /* Called under the TX lock with the TX queue running, hence no-one can be
6368 * in the middle of updating the UDP tunnels table. However, they could
6369 * have tried and failed the MCDI, in which case they'll have set the dirty
6370 * flag before dropping their locks.
6372 static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
6374 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6376 if (!(nic_data->datapath_caps &
6377 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6380 if (nic_data->udp_tunnels_dirty)
6381 /* SW table may not match HW state, so just assume we can't
6382 * use any UDP tunnel offloads.
6386 return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
6389 static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
6390 struct efx_udp_tunnel tnl)
6392 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6393 struct efx_udp_tunnel *match;
6397 if (!(nic_data->datapath_caps &
6398 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6401 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6402 netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
6403 typebuf, ntohs(tnl.port));
6405 mutex_lock(&nic_data->udp_tunnels_lock);
6406 /* Make sure all TX are stopped while we remove from the table, else we
6407 * might race against an efx_features_check().
6409 efx_device_detach_sync(efx);
6411 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6412 if (match != NULL) {
6413 if (match->type == tnl.type) {
6414 if (--match->count) {
6415 /* Port is still in use, so nothing to do */
6416 netif_dbg(efx, drv, efx->net_dev,
6417 "UDP tunnel port %d remains active\n",
6422 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6425 efx_get_udp_tunnel_type_name(match->type,
6426 typebuf, sizeof(typebuf));
6427 netif_warn(efx, drv, efx->net_dev,
6428 "UDP port %d is actually in use by %s, not removing\n",
6429 ntohs(tnl.port), typebuf);
6434 mutex_unlock(&nic_data->udp_tunnels_lock);
6438 #define EF10_OFFLOAD_FEATURES \
6439 (NETIF_F_IP_CSUM | \
6440 NETIF_F_HW_VLAN_CTAG_FILTER | \
6441 NETIF_F_IPV6_CSUM | \
6445 const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
6447 .mem_bar = efx_ef10_vf_mem_bar,
6448 .mem_map_size = efx_ef10_mem_map_size,
6449 .probe = efx_ef10_probe_vf,
6450 .remove = efx_ef10_remove,
6451 .dimension_resources = efx_ef10_dimension_resources,
6452 .init = efx_ef10_init_nic,
6453 .fini = efx_port_dummy_op_void,
6454 .map_reset_reason = efx_ef10_map_reset_reason,
6455 .map_reset_flags = efx_ef10_map_reset_flags,
6456 .reset = efx_ef10_reset,
6457 .probe_port = efx_mcdi_port_probe,
6458 .remove_port = efx_mcdi_port_remove,
6459 .fini_dmaq = efx_ef10_fini_dmaq,
6460 .prepare_flr = efx_ef10_prepare_flr,
6461 .finish_flr = efx_port_dummy_op_void,
6462 .describe_stats = efx_ef10_describe_stats,
6463 .update_stats = efx_ef10_update_stats_vf,
6464 .start_stats = efx_port_dummy_op_void,
6465 .pull_stats = efx_port_dummy_op_void,
6466 .stop_stats = efx_port_dummy_op_void,
6467 .set_id_led = efx_mcdi_set_id_led,
6468 .push_irq_moderation = efx_ef10_push_irq_moderation,
6469 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
6470 .check_mac_fault = efx_mcdi_mac_check_fault,
6471 .reconfigure_port = efx_mcdi_port_reconfigure,
6472 .get_wol = efx_ef10_get_wol_vf,
6473 .set_wol = efx_ef10_set_wol_vf,
6474 .resume_wol = efx_port_dummy_op_void,
6475 .mcdi_request = efx_ef10_mcdi_request,
6476 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6477 .mcdi_read_response = efx_ef10_mcdi_read_response,
6478 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
6479 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
6480 .irq_enable_master = efx_port_dummy_op_void,
6481 .irq_test_generate = efx_ef10_irq_test_generate,
6482 .irq_disable_non_ev = efx_port_dummy_op_void,
6483 .irq_handle_msi = efx_ef10_msi_interrupt,
6484 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6485 .tx_probe = efx_ef10_tx_probe,
6486 .tx_init = efx_ef10_tx_init,
6487 .tx_remove = efx_ef10_tx_remove,
6488 .tx_write = efx_ef10_tx_write,
6489 .tx_limit_len = efx_ef10_tx_limit_len,
6490 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
6491 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
6492 .rx_probe = efx_ef10_rx_probe,
6493 .rx_init = efx_ef10_rx_init,
6494 .rx_remove = efx_ef10_rx_remove,
6495 .rx_write = efx_ef10_rx_write,
6496 .rx_defer_refill = efx_ef10_rx_defer_refill,
6497 .ev_probe = efx_ef10_ev_probe,
6498 .ev_init = efx_ef10_ev_init,
6499 .ev_fini = efx_ef10_ev_fini,
6500 .ev_remove = efx_ef10_ev_remove,
6501 .ev_process = efx_ef10_ev_process,
6502 .ev_read_ack = efx_ef10_ev_read_ack,
6503 .ev_test_generate = efx_ef10_ev_test_generate,
6504 .filter_table_probe = efx_ef10_filter_table_probe,
6505 .filter_table_restore = efx_ef10_filter_table_restore,
6506 .filter_table_remove = efx_ef10_filter_table_remove,
6507 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6508 .filter_insert = efx_ef10_filter_insert,
6509 .filter_remove_safe = efx_ef10_filter_remove_safe,
6510 .filter_get_safe = efx_ef10_filter_get_safe,
6511 .filter_clear_rx = efx_ef10_filter_clear_rx,
6512 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6513 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6514 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6515 #ifdef CONFIG_RFS_ACCEL
6516 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6517 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6519 #ifdef CONFIG_SFC_MTD
6520 .mtd_probe = efx_port_dummy_op_int,
6522 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6523 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
6524 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6525 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
6526 #ifdef CONFIG_SFC_SRIOV
6527 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6528 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6529 .vswitching_remove = efx_ef10_vswitching_remove_vf,
6531 .get_mac_address = efx_ef10_get_mac_address_vf,
6532 .set_mac_address = efx_ef10_set_mac_address,
6534 .get_phys_port_id = efx_ef10_get_phys_port_id,
6535 .revision = EFX_REV_HUNT_A0,
6536 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6537 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6538 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6539 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6540 .can_rx_scatter = true,
6541 .always_rx_scatter = true,
6542 .min_interrupt_mode = EFX_INT_MODE_MSIX,
6543 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6544 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
6545 .offload_features = EF10_OFFLOAD_FEATURES,
6547 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6548 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6549 1 << HWTSTAMP_FILTER_ALL,
6550 .rx_hash_key_size = 40,
6553 const struct efx_nic_type efx_hunt_a0_nic_type = {
6555 .mem_bar = efx_ef10_pf_mem_bar,
6556 .mem_map_size = efx_ef10_mem_map_size,
6557 .probe = efx_ef10_probe_pf,
6558 .remove = efx_ef10_remove,
6559 .dimension_resources = efx_ef10_dimension_resources,
6560 .init = efx_ef10_init_nic,
6561 .fini = efx_port_dummy_op_void,
6562 .map_reset_reason = efx_ef10_map_reset_reason,
6563 .map_reset_flags = efx_ef10_map_reset_flags,
6564 .reset = efx_ef10_reset,
6565 .probe_port = efx_mcdi_port_probe,
6566 .remove_port = efx_mcdi_port_remove,
6567 .fini_dmaq = efx_ef10_fini_dmaq,
6568 .prepare_flr = efx_ef10_prepare_flr,
6569 .finish_flr = efx_port_dummy_op_void,
6570 .describe_stats = efx_ef10_describe_stats,
6571 .update_stats = efx_ef10_update_stats_pf,
6572 .start_stats = efx_mcdi_mac_start_stats,
6573 .pull_stats = efx_mcdi_mac_pull_stats,
6574 .stop_stats = efx_mcdi_mac_stop_stats,
6575 .set_id_led = efx_mcdi_set_id_led,
6576 .push_irq_moderation = efx_ef10_push_irq_moderation,
6577 .reconfigure_mac = efx_ef10_mac_reconfigure,
6578 .check_mac_fault = efx_mcdi_mac_check_fault,
6579 .reconfigure_port = efx_mcdi_port_reconfigure,
6580 .get_wol = efx_ef10_get_wol,
6581 .set_wol = efx_ef10_set_wol,
6582 .resume_wol = efx_port_dummy_op_void,
6583 .test_chip = efx_ef10_test_chip,
6584 .test_nvram = efx_mcdi_nvram_test_all,
6585 .mcdi_request = efx_ef10_mcdi_request,
6586 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6587 .mcdi_read_response = efx_ef10_mcdi_read_response,
6588 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
6589 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
6590 .irq_enable_master = efx_port_dummy_op_void,
6591 .irq_test_generate = efx_ef10_irq_test_generate,
6592 .irq_disable_non_ev = efx_port_dummy_op_void,
6593 .irq_handle_msi = efx_ef10_msi_interrupt,
6594 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6595 .tx_probe = efx_ef10_tx_probe,
6596 .tx_init = efx_ef10_tx_init,
6597 .tx_remove = efx_ef10_tx_remove,
6598 .tx_write = efx_ef10_tx_write,
6599 .tx_limit_len = efx_ef10_tx_limit_len,
6600 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
6601 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
6602 .rx_probe = efx_ef10_rx_probe,
6603 .rx_init = efx_ef10_rx_init,
6604 .rx_remove = efx_ef10_rx_remove,
6605 .rx_write = efx_ef10_rx_write,
6606 .rx_defer_refill = efx_ef10_rx_defer_refill,
6607 .ev_probe = efx_ef10_ev_probe,
6608 .ev_init = efx_ef10_ev_init,
6609 .ev_fini = efx_ef10_ev_fini,
6610 .ev_remove = efx_ef10_ev_remove,
6611 .ev_process = efx_ef10_ev_process,
6612 .ev_read_ack = efx_ef10_ev_read_ack,
6613 .ev_test_generate = efx_ef10_ev_test_generate,
6614 .filter_table_probe = efx_ef10_filter_table_probe,
6615 .filter_table_restore = efx_ef10_filter_table_restore,
6616 .filter_table_remove = efx_ef10_filter_table_remove,
6617 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6618 .filter_insert = efx_ef10_filter_insert,
6619 .filter_remove_safe = efx_ef10_filter_remove_safe,
6620 .filter_get_safe = efx_ef10_filter_get_safe,
6621 .filter_clear_rx = efx_ef10_filter_clear_rx,
6622 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6623 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6624 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6625 #ifdef CONFIG_RFS_ACCEL
6626 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6627 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6629 #ifdef CONFIG_SFC_MTD
6630 .mtd_probe = efx_ef10_mtd_probe,
6631 .mtd_rename = efx_mcdi_mtd_rename,
6632 .mtd_read = efx_mcdi_mtd_read,
6633 .mtd_erase = efx_mcdi_mtd_erase,
6634 .mtd_write = efx_mcdi_mtd_write,
6635 .mtd_sync = efx_mcdi_mtd_sync,
6637 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
6638 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6639 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
6640 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6641 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
6642 .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
6643 .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
6644 .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
6645 .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
6646 #ifdef CONFIG_SFC_SRIOV
6647 .sriov_configure = efx_ef10_sriov_configure,
6648 .sriov_init = efx_ef10_sriov_init,
6649 .sriov_fini = efx_ef10_sriov_fini,
6650 .sriov_wanted = efx_ef10_sriov_wanted,
6651 .sriov_reset = efx_ef10_sriov_reset,
6652 .sriov_flr = efx_ef10_sriov_flr,
6653 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6654 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6655 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6656 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
6657 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
6658 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6659 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6660 .vswitching_remove = efx_ef10_vswitching_remove_pf,
6662 .get_mac_address = efx_ef10_get_mac_address_pf,
6663 .set_mac_address = efx_ef10_set_mac_address,
6664 .tso_versions = efx_ef10_tso_versions,
6666 .get_phys_port_id = efx_ef10_get_phys_port_id,
6667 .revision = EFX_REV_HUNT_A0,
6668 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6669 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6670 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6671 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6672 .can_rx_scatter = true,
6673 .always_rx_scatter = true,
6674 .option_descriptors = true,
6675 .min_interrupt_mode = EFX_INT_MODE_LEGACY,
6676 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6677 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
6678 .offload_features = EF10_OFFLOAD_FEATURES,
6680 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6681 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6682 1 << HWTSTAMP_FILTER_ALL,
6683 .rx_hash_key_size = 40,