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 /* Per-VLAN filters information */
64 struct efx_ef10_filter_vlan {
65 struct list_head list;
67 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
68 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
74 struct efx_ef10_dev_addr {
78 struct efx_ef10_filter_table {
79 /* The MCDI match masks supported by this fw & hw, in order of priority */
80 u32 rx_match_mcdi_flags[
81 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
82 unsigned int rx_match_count;
85 unsigned long spec; /* pointer to spec plus flag bits */
86 /* BUSY flag indicates that an update is in progress. AUTO_OLD is
87 * used to mark and sweep MAC filters for the device address lists.
89 #define EFX_EF10_FILTER_FLAG_BUSY 1UL
90 #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
91 #define EFX_EF10_FILTER_FLAGS 3UL
92 u64 handle; /* firmware handle */
94 wait_queue_head_t waitq;
95 /* Shadow of net_device address lists, guarded by mac_lock */
96 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
97 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
102 /* Whether in multicast promiscuous mode when last changed */
103 bool mc_promisc_last;
105 struct list_head vlan_list;
108 /* An arbitrary search limit for the software hash table */
109 #define EFX_EF10_FILTER_SEARCH_LIMIT 200
111 static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
112 static void efx_ef10_filter_table_remove(struct efx_nic *efx);
113 static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
114 static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
115 struct efx_ef10_filter_vlan *vlan);
116 static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
118 static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
122 efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS);
123 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
124 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
127 static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
131 bar = efx->type->mem_bar;
132 return resource_size(&efx->pci_dev->resource[bar]);
135 static bool efx_ef10_is_vf(struct efx_nic *efx)
137 return efx->type->is_vf;
140 static int efx_ef10_get_pf_index(struct efx_nic *efx)
142 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
143 struct efx_ef10_nic_data *nic_data = efx->nic_data;
147 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
148 sizeof(outbuf), &outlen);
151 if (outlen < sizeof(outbuf))
154 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
158 #ifdef CONFIG_SFC_SRIOV
159 static int efx_ef10_get_vf_index(struct efx_nic *efx)
161 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
162 struct efx_ef10_nic_data *nic_data = efx->nic_data;
166 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
167 sizeof(outbuf), &outlen);
170 if (outlen < sizeof(outbuf))
173 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
178 static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
180 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V2_OUT_LEN);
181 struct efx_ef10_nic_data *nic_data = efx->nic_data;
185 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
187 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
188 outbuf, sizeof(outbuf), &outlen);
191 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
192 netif_err(efx, drv, efx->net_dev,
193 "unable to read datapath firmware capabilities\n");
197 nic_data->datapath_caps =
198 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
200 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)
201 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
202 GET_CAPABILITIES_V2_OUT_FLAGS2);
204 nic_data->datapath_caps2 = 0;
206 /* record the DPCPU firmware IDs to determine VEB vswitching support.
208 nic_data->rx_dpcpu_fw_id =
209 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
210 nic_data->tx_dpcpu_fw_id =
211 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
213 if (!(nic_data->datapath_caps &
214 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
215 netif_err(efx, probe, efx->net_dev,
216 "current firmware does not support an RX prefix\n");
223 static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
225 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
228 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
229 outbuf, sizeof(outbuf), NULL);
232 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
233 return rc > 0 ? rc : -ERANGE;
236 static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
238 struct efx_ef10_nic_data *nic_data = efx->nic_data;
239 unsigned int implemented;
240 unsigned int enabled;
243 nic_data->workaround_35388 = false;
244 nic_data->workaround_61265 = false;
246 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
249 /* Firmware without GET_WORKAROUNDS - not a problem. */
251 } else if (rc == 0) {
252 /* Bug61265 workaround is always enabled if implemented. */
253 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
254 nic_data->workaround_61265 = true;
256 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
257 nic_data->workaround_35388 = true;
258 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
259 /* Workaround is implemented but not enabled.
262 rc = efx_mcdi_set_workaround(efx,
263 MC_CMD_WORKAROUND_BUG35388,
266 nic_data->workaround_35388 = true;
267 /* If we failed to set the workaround just carry on. */
272 netif_dbg(efx, probe, efx->net_dev,
273 "workaround for bug 35388 is %sabled\n",
274 nic_data->workaround_35388 ? "en" : "dis");
275 netif_dbg(efx, probe, efx->net_dev,
276 "workaround for bug 61265 is %sabled\n",
277 nic_data->workaround_61265 ? "en" : "dis");
282 static void efx_ef10_process_timer_config(struct efx_nic *efx,
283 const efx_dword_t *data)
285 unsigned int max_count;
287 if (EFX_EF10_WORKAROUND_61265(efx)) {
288 efx->timer_quantum_ns = MCDI_DWORD(data,
289 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
290 efx->timer_max_ns = MCDI_DWORD(data,
291 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
292 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
293 efx->timer_quantum_ns = MCDI_DWORD(data,
294 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
295 max_count = MCDI_DWORD(data,
296 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
297 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
299 efx->timer_quantum_ns = MCDI_DWORD(data,
300 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
301 max_count = MCDI_DWORD(data,
302 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
303 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
306 netif_dbg(efx, probe, efx->net_dev,
307 "got timer properties from MC: quantum %u ns; max %u ns\n",
308 efx->timer_quantum_ns, efx->timer_max_ns);
311 static int efx_ef10_get_timer_config(struct efx_nic *efx)
313 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
316 rc = efx_ef10_get_timer_workarounds(efx);
320 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
321 outbuf, sizeof(outbuf), NULL);
324 efx_ef10_process_timer_config(efx, outbuf);
325 } else if (rc == -ENOSYS || rc == -EPERM) {
326 /* Not available - fall back to Huntington defaults. */
327 unsigned int quantum;
329 rc = efx_ef10_get_sysclk_freq(efx);
333 quantum = 1536000 / rc; /* 1536 cycles */
334 efx->timer_quantum_ns = quantum;
335 efx->timer_max_ns = efx->type->timer_period_max * quantum;
338 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
339 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
346 static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
348 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
352 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
354 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
355 outbuf, sizeof(outbuf), &outlen);
358 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
361 ether_addr_copy(mac_address,
362 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
366 static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
368 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
369 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
373 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
374 EVB_PORT_ID_ASSIGNED);
375 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
376 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
380 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
383 num_addrs = MCDI_DWORD(outbuf,
384 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
386 WARN_ON(num_addrs != 1);
388 ether_addr_copy(mac_address,
389 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
394 static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
395 struct device_attribute *attr,
398 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
400 return sprintf(buf, "%d\n",
401 ((efx->mcdi->fn_flags) &
402 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
406 static ssize_t efx_ef10_show_primary_flag(struct device *dev,
407 struct device_attribute *attr,
410 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
412 return sprintf(buf, "%d\n",
413 ((efx->mcdi->fn_flags) &
414 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
418 static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
420 struct efx_ef10_nic_data *nic_data = efx->nic_data;
421 struct efx_ef10_vlan *vlan;
423 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
425 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
426 if (vlan->vid == vid)
433 static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
435 struct efx_ef10_nic_data *nic_data = efx->nic_data;
436 struct efx_ef10_vlan *vlan;
439 mutex_lock(&nic_data->vlan_lock);
441 vlan = efx_ef10_find_vlan(efx, vid);
443 /* We add VID 0 on init. 8021q adds it on module init
444 * for all interfaces with VLAN filtring feature.
448 netif_warn(efx, drv, efx->net_dev,
449 "VLAN %u already added\n", vid);
455 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
461 list_add_tail(&vlan->list, &nic_data->vlan_list);
463 if (efx->filter_state) {
464 mutex_lock(&efx->mac_lock);
465 down_write(&efx->filter_sem);
466 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
467 up_write(&efx->filter_sem);
468 mutex_unlock(&efx->mac_lock);
470 goto fail_filter_add_vlan;
474 mutex_unlock(&nic_data->vlan_lock);
477 fail_filter_add_vlan:
478 list_del(&vlan->list);
482 mutex_unlock(&nic_data->vlan_lock);
486 static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
487 struct efx_ef10_vlan *vlan)
489 struct efx_ef10_nic_data *nic_data = efx->nic_data;
491 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
493 if (efx->filter_state) {
494 down_write(&efx->filter_sem);
495 efx_ef10_filter_del_vlan(efx, vlan->vid);
496 up_write(&efx->filter_sem);
499 list_del(&vlan->list);
503 static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
505 struct efx_ef10_nic_data *nic_data = efx->nic_data;
506 struct efx_ef10_vlan *vlan;
509 /* 8021q removes VID 0 on module unload for all interfaces
510 * with VLAN filtering feature. We need to keep it to receive
516 mutex_lock(&nic_data->vlan_lock);
518 vlan = efx_ef10_find_vlan(efx, vid);
520 netif_err(efx, drv, efx->net_dev,
521 "VLAN %u to be deleted not found\n", vid);
524 efx_ef10_del_vlan_internal(efx, vlan);
527 mutex_unlock(&nic_data->vlan_lock);
532 static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
534 struct efx_ef10_nic_data *nic_data = efx->nic_data;
535 struct efx_ef10_vlan *vlan, *next_vlan;
537 mutex_lock(&nic_data->vlan_lock);
538 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
539 efx_ef10_del_vlan_internal(efx, vlan);
540 mutex_unlock(&nic_data->vlan_lock);
543 static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
545 static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
547 static int efx_ef10_probe(struct efx_nic *efx)
549 struct efx_ef10_nic_data *nic_data;
550 struct net_device *net_dev = efx->net_dev;
553 /* We can have one VI for each 8K region. However, until we
554 * use TX option descriptors we need two TX queues per channel.
556 efx->max_channels = min_t(unsigned int,
558 efx_ef10_mem_map_size(efx) /
559 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
560 efx->max_tx_channels = efx->max_channels;
561 if (WARN_ON(efx->max_channels == 0))
564 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
567 efx->nic_data = nic_data;
569 /* we assume later that we can copy from this buffer in dwords */
570 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
572 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
573 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
577 /* Get the MC's warm boot count. In case it's rebooting right
578 * now, be prepared to retry.
582 rc = efx_ef10_get_warm_boot_count(efx);
589 nic_data->warm_boot_count = rc;
591 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
593 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
595 /* In case we're recovering from a crash (kexec), we want to
596 * cancel any outstanding request by the previous user of this
597 * function. We send a special message using the least
598 * significant bits of the 'high' (doorbell) register.
600 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
602 rc = efx_mcdi_init(efx);
606 /* Reset (most) configuration for this function */
607 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
611 /* Enable event logging */
612 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
616 rc = device_create_file(&efx->pci_dev->dev,
617 &dev_attr_link_control_flag);
621 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
625 rc = efx_ef10_get_pf_index(efx);
629 rc = efx_ef10_init_datapath_caps(efx);
633 efx->rx_packet_len_offset =
634 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
636 rc = efx_mcdi_port_get_number(efx);
640 net_dev->dev_port = rc;
642 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
646 rc = efx_ef10_get_timer_config(efx);
649 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
651 rc = efx_mcdi_mon_probe(efx);
652 if (rc && rc != -EPERM)
655 efx_ptp_probe(efx, NULL);
657 #ifdef CONFIG_SFC_SRIOV
658 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
659 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
660 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
662 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
665 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
667 INIT_LIST_HEAD(&nic_data->vlan_list);
668 mutex_init(&nic_data->vlan_lock);
670 /* Add unspecified VID to support VLAN filtering being disabled */
671 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
673 goto fail_add_vid_unspec;
675 /* If VLAN filtering is enabled, we need VID 0 to get untagged
676 * traffic. It is added automatically if 8021q module is loaded,
677 * but we can't rely on it since module may be not loaded.
679 rc = efx_ef10_add_vlan(efx, 0);
686 efx_ef10_cleanup_vlans(efx);
688 mutex_destroy(&nic_data->vlan_lock);
690 efx_mcdi_mon_remove(efx);
692 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
694 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
698 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
701 efx->nic_data = NULL;
705 static int efx_ef10_free_vis(struct efx_nic *efx)
707 MCDI_DECLARE_BUF_ERR(outbuf);
709 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
710 outbuf, sizeof(outbuf), &outlen);
712 /* -EALREADY means nothing to free, so ignore */
716 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
723 static void efx_ef10_free_piobufs(struct efx_nic *efx)
725 struct efx_ef10_nic_data *nic_data = efx->nic_data;
726 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
730 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
732 for (i = 0; i < nic_data->n_piobufs; i++) {
733 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
734 nic_data->piobuf_handle[i]);
735 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
740 nic_data->n_piobufs = 0;
743 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
745 struct efx_ef10_nic_data *nic_data = efx->nic_data;
746 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
751 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
753 for (i = 0; i < n; i++) {
754 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
755 outbuf, sizeof(outbuf), &outlen);
757 /* Don't display the MC error if we didn't have space
760 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
761 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
762 0, outbuf, outlen, rc);
765 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
769 nic_data->piobuf_handle[i] =
770 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
771 netif_dbg(efx, probe, efx->net_dev,
772 "allocated PIO buffer %u handle %x\n", i,
773 nic_data->piobuf_handle[i]);
776 nic_data->n_piobufs = i;
778 efx_ef10_free_piobufs(efx);
782 static int efx_ef10_link_piobufs(struct efx_nic *efx)
784 struct efx_ef10_nic_data *nic_data = efx->nic_data;
785 _MCDI_DECLARE_BUF(inbuf,
786 max(MC_CMD_LINK_PIOBUF_IN_LEN,
787 MC_CMD_UNLINK_PIOBUF_IN_LEN));
788 struct efx_channel *channel;
789 struct efx_tx_queue *tx_queue;
790 unsigned int offset, index;
793 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
794 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
796 memset(inbuf, 0, sizeof(inbuf));
798 /* Link a buffer to each VI in the write-combining mapping */
799 for (index = 0; index < nic_data->n_piobufs; ++index) {
800 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
801 nic_data->piobuf_handle[index]);
802 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
803 nic_data->pio_write_vi_base + index);
804 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
805 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
808 netif_err(efx, drv, efx->net_dev,
809 "failed to link VI %u to PIO buffer %u (%d)\n",
810 nic_data->pio_write_vi_base + index, index,
814 netif_dbg(efx, probe, efx->net_dev,
815 "linked VI %u to PIO buffer %u\n",
816 nic_data->pio_write_vi_base + index, index);
819 /* Link a buffer to each TX queue */
820 efx_for_each_channel(channel, efx) {
821 efx_for_each_channel_tx_queue(tx_queue, channel) {
822 /* We assign the PIO buffers to queues in
823 * reverse order to allow for the following
826 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
827 tx_queue->channel->channel - 1) *
829 index = offset / ER_DZ_TX_PIOBUF_SIZE;
830 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
832 /* When the host page size is 4K, the first
833 * host page in the WC mapping may be within
834 * the same VI page as the last TX queue. We
835 * can only link one buffer to each VI.
837 if (tx_queue->queue == nic_data->pio_write_vi_base) {
841 MCDI_SET_DWORD(inbuf,
842 LINK_PIOBUF_IN_PIOBUF_HANDLE,
843 nic_data->piobuf_handle[index]);
844 MCDI_SET_DWORD(inbuf,
845 LINK_PIOBUF_IN_TXQ_INSTANCE,
847 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
848 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
853 /* This is non-fatal; the TX path just
854 * won't use PIO for this queue
856 netif_err(efx, drv, efx->net_dev,
857 "failed to link VI %u to PIO buffer %u (%d)\n",
858 tx_queue->queue, index, rc);
859 tx_queue->piobuf = NULL;
862 nic_data->pio_write_base +
863 index * EFX_VI_PAGE_SIZE + offset;
864 tx_queue->piobuf_offset = offset;
865 netif_dbg(efx, probe, efx->net_dev,
866 "linked VI %u to PIO buffer %u offset %x addr %p\n",
867 tx_queue->queue, index,
868 tx_queue->piobuf_offset,
878 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
879 nic_data->pio_write_vi_base + index);
880 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
881 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
887 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
889 struct efx_channel *channel;
890 struct efx_tx_queue *tx_queue;
892 /* All our existing PIO buffers went away */
893 efx_for_each_channel(channel, efx)
894 efx_for_each_channel_tx_queue(tx_queue, channel)
895 tx_queue->piobuf = NULL;
898 #else /* !EFX_USE_PIO */
900 static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
902 return n == 0 ? 0 : -ENOBUFS;
905 static int efx_ef10_link_piobufs(struct efx_nic *efx)
910 static void efx_ef10_free_piobufs(struct efx_nic *efx)
914 static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
918 #endif /* EFX_USE_PIO */
920 static void efx_ef10_remove(struct efx_nic *efx)
922 struct efx_ef10_nic_data *nic_data = efx->nic_data;
925 #ifdef CONFIG_SFC_SRIOV
926 struct efx_ef10_nic_data *nic_data_pf;
927 struct pci_dev *pci_dev_pf;
928 struct efx_nic *efx_pf;
931 if (efx->pci_dev->is_virtfn) {
932 pci_dev_pf = efx->pci_dev->physfn;
934 efx_pf = pci_get_drvdata(pci_dev_pf);
935 nic_data_pf = efx_pf->nic_data;
936 vf = nic_data_pf->vf + nic_data->vf_index;
939 netif_info(efx, drv, efx->net_dev,
940 "Could not get the PF id from VF\n");
944 efx_ef10_cleanup_vlans(efx);
945 mutex_destroy(&nic_data->vlan_lock);
949 efx_mcdi_mon_remove(efx);
951 efx_ef10_rx_free_indir_table(efx);
953 if (nic_data->wc_membase)
954 iounmap(nic_data->wc_membase);
956 rc = efx_ef10_free_vis(efx);
959 if (!nic_data->must_restore_piobufs)
960 efx_ef10_free_piobufs(efx);
962 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
963 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
966 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
970 static int efx_ef10_probe_pf(struct efx_nic *efx)
972 return efx_ef10_probe(efx);
975 int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
976 u32 *port_flags, u32 *vadaptor_flags,
977 unsigned int *vlan_tags)
979 struct efx_ef10_nic_data *nic_data = efx->nic_data;
980 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
981 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
985 if (nic_data->datapath_caps &
986 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
987 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
990 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
991 outbuf, sizeof(outbuf), &outlen);
995 if (outlen < sizeof(outbuf)) {
1002 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1005 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1009 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1014 int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1016 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1018 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1019 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1023 int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1025 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1027 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1028 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1032 int efx_ef10_vport_add_mac(struct efx_nic *efx,
1033 unsigned int port_id, u8 *mac)
1035 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1037 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1038 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1040 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1041 sizeof(inbuf), NULL, 0, NULL);
1044 int efx_ef10_vport_del_mac(struct efx_nic *efx,
1045 unsigned int port_id, u8 *mac)
1047 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1049 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1050 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1052 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1053 sizeof(inbuf), NULL, 0, NULL);
1056 #ifdef CONFIG_SFC_SRIOV
1057 static int efx_ef10_probe_vf(struct efx_nic *efx)
1060 struct pci_dev *pci_dev_pf;
1062 /* If the parent PF has no VF data structure, it doesn't know about this
1063 * VF so fail probe. The VF needs to be re-created. This can happen
1064 * if the PF driver is unloaded while the VF is assigned to a guest.
1066 pci_dev_pf = efx->pci_dev->physfn;
1068 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1069 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1071 if (!nic_data_pf->vf) {
1072 netif_info(efx, drv, efx->net_dev,
1073 "The VF cannot link to its parent PF; "
1074 "please destroy and re-create the VF\n");
1079 rc = efx_ef10_probe(efx);
1083 rc = efx_ef10_get_vf_index(efx);
1087 if (efx->pci_dev->is_virtfn) {
1088 if (efx->pci_dev->physfn) {
1089 struct efx_nic *efx_pf =
1090 pci_get_drvdata(efx->pci_dev->physfn);
1091 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1092 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1094 nic_data_p->vf[nic_data->vf_index].efx = efx;
1095 nic_data_p->vf[nic_data->vf_index].pci_dev =
1098 netif_info(efx, drv, efx->net_dev,
1099 "Could not get the PF id from VF\n");
1105 efx_ef10_remove(efx);
1109 static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1115 static int efx_ef10_alloc_vis(struct efx_nic *efx,
1116 unsigned int min_vis, unsigned int max_vis)
1118 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1119 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1120 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1124 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1125 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1126 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1127 outbuf, sizeof(outbuf), &outlen);
1131 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1134 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1135 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1137 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1138 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1142 /* Note that the failure path of this function does not free
1143 * resources, as this will be done by efx_ef10_remove().
1145 static int efx_ef10_dimension_resources(struct efx_nic *efx)
1147 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1148 unsigned int uc_mem_map_size, wc_mem_map_size;
1149 unsigned int min_vis = max(EFX_TXQ_TYPES,
1150 efx_separate_tx_channels ? 2 : 1);
1151 unsigned int channel_vis, pio_write_vi_base, max_vis;
1152 void __iomem *membase;
1155 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
1158 /* Try to allocate PIO buffers if wanted and if the full
1159 * number of PIO buffers would be sufficient to allocate one
1160 * copy-buffer per TX channel. Failure is non-fatal, as there
1161 * are only a small number of PIO buffers shared between all
1162 * functions of the controller.
1164 if (efx_piobuf_size != 0 &&
1165 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
1166 efx->n_tx_channels) {
1167 unsigned int n_piobufs =
1168 DIV_ROUND_UP(efx->n_tx_channels,
1169 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
1171 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
1173 netif_err(efx, probe, efx->net_dev,
1174 "failed to allocate PIO buffers (%d)\n", rc);
1176 netif_dbg(efx, probe, efx->net_dev,
1177 "allocated %u PIO buffers\n", n_piobufs);
1180 nic_data->n_piobufs = 0;
1183 /* PIO buffers should be mapped with write-combining enabled,
1184 * and we want to make single UC and WC mappings rather than
1185 * several of each (in fact that's the only option if host
1186 * page size is >4K). So we may allocate some extra VIs just
1187 * for writing PIO buffers through.
1189 * The UC mapping contains (channel_vis - 1) complete VIs and the
1190 * first half of the next VI. Then the WC mapping begins with
1191 * the second half of this last VI.
1193 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * EFX_VI_PAGE_SIZE +
1195 if (nic_data->n_piobufs) {
1196 /* pio_write_vi_base rounds down to give the number of complete
1197 * VIs inside the UC mapping.
1199 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
1200 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1201 nic_data->n_piobufs) *
1204 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1206 pio_write_vi_base = 0;
1207 wc_mem_map_size = 0;
1208 max_vis = channel_vis;
1211 /* In case the last attached driver failed to free VIs, do it now */
1212 rc = efx_ef10_free_vis(efx);
1216 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1220 if (nic_data->n_allocated_vis < channel_vis) {
1221 netif_info(efx, drv, efx->net_dev,
1222 "Could not allocate enough VIs to satisfy RSS"
1223 " requirements. Performance may not be optimal.\n");
1224 /* We didn't get the VIs to populate our channels.
1225 * We could keep what we got but then we'd have more
1226 * interrupts than we need.
1227 * Instead calculate new max_channels and restart
1229 efx->max_channels = nic_data->n_allocated_vis;
1230 efx->max_tx_channels =
1231 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1233 efx_ef10_free_vis(efx);
1237 /* If we didn't get enough VIs to map all the PIO buffers, free the
1240 if (nic_data->n_piobufs &&
1241 nic_data->n_allocated_vis <
1242 pio_write_vi_base + nic_data->n_piobufs) {
1243 netif_dbg(efx, probe, efx->net_dev,
1244 "%u VIs are not sufficient to map %u PIO buffers\n",
1245 nic_data->n_allocated_vis, nic_data->n_piobufs);
1246 efx_ef10_free_piobufs(efx);
1249 /* Shrink the original UC mapping of the memory BAR */
1250 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1252 netif_err(efx, probe, efx->net_dev,
1253 "could not shrink memory BAR to %x\n",
1257 iounmap(efx->membase);
1258 efx->membase = membase;
1260 /* Set up the WC mapping if needed */
1261 if (wc_mem_map_size) {
1262 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1265 if (!nic_data->wc_membase) {
1266 netif_err(efx, probe, efx->net_dev,
1267 "could not allocate WC mapping of size %x\n",
1271 nic_data->pio_write_vi_base = pio_write_vi_base;
1272 nic_data->pio_write_base =
1273 nic_data->wc_membase +
1274 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
1277 rc = efx_ef10_link_piobufs(efx);
1279 efx_ef10_free_piobufs(efx);
1282 netif_dbg(efx, probe, efx->net_dev,
1283 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1284 &efx->membase_phys, efx->membase, uc_mem_map_size,
1285 nic_data->wc_membase, wc_mem_map_size);
1290 static int efx_ef10_init_nic(struct efx_nic *efx)
1292 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1295 if (nic_data->must_check_datapath_caps) {
1296 rc = efx_ef10_init_datapath_caps(efx);
1299 nic_data->must_check_datapath_caps = false;
1302 if (nic_data->must_realloc_vis) {
1303 /* We cannot let the number of VIs change now */
1304 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1305 nic_data->n_allocated_vis);
1308 nic_data->must_realloc_vis = false;
1311 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1312 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1314 rc = efx_ef10_link_piobufs(efx);
1316 efx_ef10_free_piobufs(efx);
1319 /* Log an error on failure, but this is non-fatal */
1321 netif_err(efx, drv, efx->net_dev,
1322 "failed to restore PIO buffers (%d)\n", rc);
1323 nic_data->must_restore_piobufs = false;
1326 /* don't fail init if RSS setup doesn't work */
1327 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
1332 static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1334 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1335 #ifdef CONFIG_SFC_SRIOV
1339 /* All our allocations have been reset */
1340 nic_data->must_realloc_vis = true;
1341 nic_data->must_restore_filters = true;
1342 nic_data->must_restore_piobufs = true;
1343 efx_ef10_forget_old_piobufs(efx);
1344 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1346 /* Driver-created vswitches and vports must be re-created */
1347 nic_data->must_probe_vswitching = true;
1348 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1349 #ifdef CONFIG_SFC_SRIOV
1351 for (i = 0; i < efx->vf_count; i++)
1352 nic_data->vf[i].vport_id = 0;
1356 static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1358 if (reason == RESET_TYPE_MC_FAILURE)
1359 return RESET_TYPE_DATAPATH;
1361 return efx_mcdi_map_reset_reason(reason);
1364 static int efx_ef10_map_reset_flags(u32 *flags)
1367 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1368 ETH_RESET_SHARED_SHIFT),
1369 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1370 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1371 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1372 ETH_RESET_SHARED_SHIFT)
1375 /* We assume for now that our PCI function is permitted to
1379 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1380 *flags &= ~EF10_RESET_MC;
1381 return RESET_TYPE_WORLD;
1384 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1385 *flags &= ~EF10_RESET_PORT;
1386 return RESET_TYPE_ALL;
1389 /* no invisible reset implemented */
1394 static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1396 int rc = efx_mcdi_reset(efx, reset_type);
1398 /* Unprivileged functions return -EPERM, but need to return success
1399 * here so that the datapath is brought back up.
1401 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1404 /* If it was a port reset, trigger reallocation of MC resources.
1405 * Note that on an MC reset nothing needs to be done now because we'll
1406 * detect the MC reset later and handle it then.
1407 * For an FLR, we never get an MC reset event, but the MC has reset all
1408 * resources assigned to us, so we have to trigger reallocation now.
1410 if ((reset_type == RESET_TYPE_ALL ||
1411 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
1412 efx_ef10_reset_mc_allocations(efx);
1416 #define EF10_DMA_STAT(ext_name, mcdi_name) \
1417 [EF10_STAT_ ## ext_name] = \
1418 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1419 #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1420 [EF10_STAT_ ## int_name] = \
1421 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1422 #define EF10_OTHER_STAT(ext_name) \
1423 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1424 #define GENERIC_SW_STAT(ext_name) \
1425 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
1427 static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
1428 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1429 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1430 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1431 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1432 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1433 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1434 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1435 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1436 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1437 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1438 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1439 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1440 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1441 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1442 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1443 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1444 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1445 EF10_OTHER_STAT(port_rx_good_bytes),
1446 EF10_OTHER_STAT(port_rx_bad_bytes),
1447 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1448 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1449 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1450 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1451 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1452 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1453 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1454 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1455 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1456 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1457 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1458 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1459 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1460 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1461 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1462 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1463 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1464 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1465 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1466 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1467 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1468 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
1469 GENERIC_SW_STAT(rx_nodesc_trunc),
1470 GENERIC_SW_STAT(rx_noskb_drops),
1471 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1472 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1473 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1474 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1475 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1476 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1477 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1478 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1479 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1480 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1481 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1482 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
1483 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1484 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1485 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1486 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1487 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1488 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1489 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1490 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1491 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1492 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1493 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1494 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1495 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1496 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1497 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1498 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1499 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1500 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
1503 #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1504 (1ULL << EF10_STAT_port_tx_packets) | \
1505 (1ULL << EF10_STAT_port_tx_pause) | \
1506 (1ULL << EF10_STAT_port_tx_unicast) | \
1507 (1ULL << EF10_STAT_port_tx_multicast) | \
1508 (1ULL << EF10_STAT_port_tx_broadcast) | \
1509 (1ULL << EF10_STAT_port_rx_bytes) | \
1511 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1512 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1513 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1514 (1ULL << EF10_STAT_port_rx_packets) | \
1515 (1ULL << EF10_STAT_port_rx_good) | \
1516 (1ULL << EF10_STAT_port_rx_bad) | \
1517 (1ULL << EF10_STAT_port_rx_pause) | \
1518 (1ULL << EF10_STAT_port_rx_control) | \
1519 (1ULL << EF10_STAT_port_rx_unicast) | \
1520 (1ULL << EF10_STAT_port_rx_multicast) | \
1521 (1ULL << EF10_STAT_port_rx_broadcast) | \
1522 (1ULL << EF10_STAT_port_rx_lt64) | \
1523 (1ULL << EF10_STAT_port_rx_64) | \
1524 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1525 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1526 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1527 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1528 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1529 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1530 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1531 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1532 (1ULL << EF10_STAT_port_rx_overflow) | \
1533 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
1534 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1535 (1ULL << GENERIC_STAT_rx_noskb_drops))
1537 /* These statistics are only provided by the 10G MAC. For a 10G/40G
1538 * switchable port we do not expose these because they might not
1539 * include all the packets they should.
1541 #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1542 (1ULL << EF10_STAT_port_tx_lt64) | \
1543 (1ULL << EF10_STAT_port_tx_64) | \
1544 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1545 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1546 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1547 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1548 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1549 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
1551 /* These statistics are only provided by the 40G MAC. For a 10G/40G
1552 * switchable port we do expose these because the errors will otherwise
1555 #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1556 (1ULL << EF10_STAT_port_rx_length_error))
1558 /* These statistics are only provided if the firmware supports the
1559 * capability PM_AND_RXDP_COUNTERS.
1561 #define HUNT_PM_AND_RXDP_STAT_MASK ( \
1562 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1563 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1564 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1565 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1566 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1567 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1568 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1569 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1570 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1571 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1572 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1573 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
1575 static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
1577 u64 raw_mask = HUNT_COMMON_STAT_MASK;
1578 u32 port_caps = efx_mcdi_phy_get_caps(efx);
1579 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1581 if (!(efx->mcdi->fn_flags &
1582 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1585 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
1586 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
1588 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1590 if (nic_data->datapath_caps &
1591 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1592 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1597 static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1599 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1602 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1604 /* Only show vadaptor stats when EVB capability is present */
1605 if (nic_data->datapath_caps &
1606 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1607 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
1608 raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
1613 #if BITS_PER_LONG == 64
1614 mask[0] = raw_mask[0];
1615 mask[1] = raw_mask[1];
1617 mask[0] = raw_mask[0] & 0xffffffff;
1618 mask[1] = raw_mask[0] >> 32;
1619 mask[2] = raw_mask[1] & 0xffffffff;
1620 mask[3] = raw_mask[1] >> 32;
1624 static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1626 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1628 efx_ef10_get_stat_mask(efx, mask);
1629 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
1633 static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1634 struct rtnl_link_stats64 *core_stats)
1636 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1637 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1638 u64 *stats = nic_data->stats;
1639 size_t stats_count = 0, index;
1641 efx_ef10_get_stat_mask(efx, mask);
1644 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1645 if (efx_ef10_stat_desc[index].name) {
1646 *full_stats++ = stats[index];
1655 if (nic_data->datapath_caps &
1656 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1657 /* Use vadaptor stats. */
1658 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1659 stats[EF10_STAT_rx_multicast] +
1660 stats[EF10_STAT_rx_broadcast];
1661 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1662 stats[EF10_STAT_tx_multicast] +
1663 stats[EF10_STAT_tx_broadcast];
1664 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1665 stats[EF10_STAT_rx_multicast_bytes] +
1666 stats[EF10_STAT_rx_broadcast_bytes];
1667 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1668 stats[EF10_STAT_tx_multicast_bytes] +
1669 stats[EF10_STAT_tx_broadcast_bytes];
1670 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
1671 stats[GENERIC_STAT_rx_noskb_drops];
1672 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1673 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1674 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1675 core_stats->rx_errors = core_stats->rx_crc_errors;
1676 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
1678 /* Use port stats. */
1679 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1680 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1681 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1682 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1683 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1684 stats[GENERIC_STAT_rx_nodesc_trunc] +
1685 stats[GENERIC_STAT_rx_noskb_drops];
1686 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1687 core_stats->rx_length_errors =
1688 stats[EF10_STAT_port_rx_gtjumbo] +
1689 stats[EF10_STAT_port_rx_length_error];
1690 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1691 core_stats->rx_frame_errors =
1692 stats[EF10_STAT_port_rx_align_error];
1693 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1694 core_stats->rx_errors = (core_stats->rx_length_errors +
1695 core_stats->rx_crc_errors +
1696 core_stats->rx_frame_errors);
1702 static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
1704 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1705 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1706 __le64 generation_start, generation_end;
1707 u64 *stats = nic_data->stats;
1710 efx_ef10_get_stat_mask(efx, mask);
1712 dma_stats = efx->stats_buffer.addr;
1713 nic_data = efx->nic_data;
1715 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1716 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1719 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1720 stats, efx->stats_buffer.addr, false);
1722 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1723 if (generation_end != generation_start)
1726 /* Update derived statistics */
1727 efx_nic_fix_nodesc_drop_stat(efx,
1728 &stats[EF10_STAT_port_rx_nodesc_drops]);
1729 stats[EF10_STAT_port_rx_good_bytes] =
1730 stats[EF10_STAT_port_rx_bytes] -
1731 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1732 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1733 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
1734 efx_update_sw_stats(efx, stats);
1739 static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1740 struct rtnl_link_stats64 *core_stats)
1744 /* If we're unlucky enough to read statistics during the DMA, wait
1745 * up to 10ms for it to finish (typically takes <500us)
1747 for (retry = 0; retry < 100; ++retry) {
1748 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
1753 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1756 static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1758 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1759 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1760 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1761 __le64 generation_start, generation_end;
1762 u64 *stats = nic_data->stats;
1763 u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
1764 struct efx_buffer stats_buf;
1768 spin_unlock_bh(&efx->stats_lock);
1770 if (in_interrupt()) {
1771 /* If in atomic context, cannot update stats. Just update the
1772 * software stats and return so the caller can continue.
1774 spin_lock_bh(&efx->stats_lock);
1775 efx_update_sw_stats(efx, stats);
1779 efx_ef10_get_stat_mask(efx, mask);
1781 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
1783 spin_lock_bh(&efx->stats_lock);
1787 dma_stats = stats_buf.addr;
1788 dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
1790 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
1791 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
1792 MAC_STATS_IN_DMA, 1);
1793 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1794 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
1796 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1798 spin_lock_bh(&efx->stats_lock);
1800 /* Expect ENOENT if DMA queues have not been set up */
1801 if (rc != -ENOENT || atomic_read(&efx->active_queues))
1802 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
1803 sizeof(inbuf), NULL, 0, rc);
1807 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1808 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
1813 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
1814 stats, stats_buf.addr, false);
1816 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1817 if (generation_end != generation_start) {
1822 efx_update_sw_stats(efx, stats);
1824 efx_nic_free_buffer(efx, &stats_buf);
1828 static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
1829 struct rtnl_link_stats64 *core_stats)
1831 if (efx_ef10_try_update_nic_stats_vf(efx))
1834 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1837 static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1839 struct efx_nic *efx = channel->efx;
1840 unsigned int mode, usecs;
1841 efx_dword_t timer_cmd;
1843 if (channel->irq_moderation_us) {
1845 usecs = channel->irq_moderation_us;
1851 if (EFX_EF10_WORKAROUND_61265(efx)) {
1852 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
1853 unsigned int ns = usecs * 1000;
1855 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
1857 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
1858 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
1859 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
1861 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
1862 inbuf, sizeof(inbuf), 0, NULL, 0);
1863 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
1864 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1866 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1867 EFE_DD_EVQ_IND_TIMER_FLAGS,
1868 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1869 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
1870 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1873 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
1875 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1876 ERF_DZ_TC_TIMER_VAL, ticks);
1877 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1882 static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1883 struct ethtool_wolinfo *wol) {}
1885 static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1890 static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1894 memset(&wol->sopass, 0, sizeof(wol->sopass));
1897 static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1904 static void efx_ef10_mcdi_request(struct efx_nic *efx,
1905 const efx_dword_t *hdr, size_t hdr_len,
1906 const efx_dword_t *sdu, size_t sdu_len)
1908 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1909 u8 *pdu = nic_data->mcdi_buf.addr;
1911 memcpy(pdu, hdr, hdr_len);
1912 memcpy(pdu + hdr_len, sdu, sdu_len);
1915 /* The hardware provides 'low' and 'high' (doorbell) registers
1916 * for passing the 64-bit address of an MCDI request to
1917 * firmware. However the dwords are swapped by firmware. The
1918 * least significant bits of the doorbell are then 0 for all
1919 * MCDI requests due to alignment.
1921 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1923 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1927 static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1929 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1930 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1933 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1937 efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1938 size_t offset, size_t outlen)
1940 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1941 const u8 *pdu = nic_data->mcdi_buf.addr;
1943 memcpy(outbuf, pdu + offset, outlen);
1946 static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
1948 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1950 /* All our allocations have been reset */
1951 efx_ef10_reset_mc_allocations(efx);
1953 /* The datapath firmware might have been changed */
1954 nic_data->must_check_datapath_caps = true;
1956 /* MAC statistics have been cleared on the NIC; clear the local
1957 * statistic that we update with efx_update_diff_stat().
1959 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
1962 static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1964 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1967 rc = efx_ef10_get_warm_boot_count(efx);
1969 /* The firmware is presumably in the process of
1970 * rebooting. However, we are supposed to report each
1971 * reboot just once, so we must only do that once we
1972 * can read and store the updated warm boot count.
1977 if (rc == nic_data->warm_boot_count)
1980 nic_data->warm_boot_count = rc;
1981 efx_ef10_mcdi_reboot_detected(efx);
1986 /* Handle an MSI interrupt
1988 * Handle an MSI hardware interrupt. This routine schedules event
1989 * queue processing. No interrupt acknowledgement cycle is necessary.
1990 * Also, we never need to check that the interrupt is for us, since
1991 * MSI interrupts cannot be shared.
1993 static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1995 struct efx_msi_context *context = dev_id;
1996 struct efx_nic *efx = context->efx;
1998 netif_vdbg(efx, intr, efx->net_dev,
1999 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2001 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
2002 /* Note test interrupts */
2003 if (context->index == efx->irq_level)
2004 efx->last_irq_cpu = raw_smp_processor_id();
2006 /* Schedule processing of the channel */
2007 efx_schedule_channel_irq(efx->channel[context->index]);
2013 static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2015 struct efx_nic *efx = dev_id;
2016 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
2017 struct efx_channel *channel;
2021 /* Read the ISR which also ACKs the interrupts */
2022 efx_readd(efx, ®, ER_DZ_BIU_INT_ISR);
2023 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2028 if (likely(soft_enabled)) {
2029 /* Note test interrupts */
2030 if (queues & (1U << efx->irq_level))
2031 efx->last_irq_cpu = raw_smp_processor_id();
2033 efx_for_each_channel(channel, efx) {
2035 efx_schedule_channel_irq(channel);
2040 netif_vdbg(efx, intr, efx->net_dev,
2041 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2042 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2047 static void efx_ef10_irq_test_generate(struct efx_nic *efx)
2049 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2051 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2053 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
2054 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
2055 inbuf, sizeof(inbuf), NULL, 0, NULL);
2058 static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2060 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2061 (tx_queue->ptr_mask + 1) *
2062 sizeof(efx_qword_t),
2066 /* This writes to the TX_DESC_WPTR and also pushes data */
2067 static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2068 const efx_qword_t *txd)
2070 unsigned int write_ptr;
2073 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2074 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2075 reg.qword[0] = *txd;
2076 efx_writeo_page(tx_queue->efx, ®,
2077 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2080 static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2082 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2084 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2085 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2086 struct efx_channel *channel = tx_queue->channel;
2087 struct efx_nic *efx = tx_queue->efx;
2088 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2090 dma_addr_t dma_addr;
2094 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
2096 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2097 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2098 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2099 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
2100 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
2101 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
2102 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2103 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
2104 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
2106 dma_addr = tx_queue->txd.buf.dma_addr;
2108 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2109 tx_queue->queue, entries, (u64)dma_addr);
2111 for (i = 0; i < entries; ++i) {
2112 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2113 dma_addr += EFX_BUF_SIZE;
2116 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2118 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2123 /* A previous user of this TX queue might have set us up the
2124 * bomb by writing a descriptor to the TX push collector but
2125 * not the doorbell. (Each collector belongs to a port, not a
2126 * queue or function, so cannot easily be reset.) We must
2127 * attempt to push a no-op descriptor in its place.
2129 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2130 tx_queue->insert_count = 1;
2131 txd = efx_tx_desc(tx_queue, 0);
2132 EFX_POPULATE_QWORD_4(*txd,
2133 ESF_DZ_TX_DESC_IS_OPT, true,
2134 ESF_DZ_TX_OPTION_TYPE,
2135 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2136 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2137 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
2138 tx_queue->write_count = 1;
2140 if (nic_data->datapath_caps &
2141 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2142 tx_queue->tso_version = 1;
2146 efx_ef10_push_tx_desc(tx_queue, txd);
2151 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2155 static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2157 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
2158 MCDI_DECLARE_BUF_ERR(outbuf);
2159 struct efx_nic *efx = tx_queue->efx;
2163 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2166 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
2167 outbuf, sizeof(outbuf), &outlen);
2169 if (rc && rc != -EALREADY)
2175 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2176 outbuf, outlen, rc);
2179 static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2181 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2184 /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2185 static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2187 unsigned int write_ptr;
2190 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2191 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2192 efx_writed_page(tx_queue->efx, ®,
2193 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2196 static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2198 unsigned int old_write_count = tx_queue->write_count;
2199 struct efx_tx_buffer *buffer;
2200 unsigned int write_ptr;
2203 tx_queue->xmit_more_available = false;
2204 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2208 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2209 buffer = &tx_queue->buffer[write_ptr];
2210 txd = efx_tx_desc(tx_queue, write_ptr);
2211 ++tx_queue->write_count;
2213 /* Create TX descriptor ring entry */
2214 if (buffer->flags & EFX_TX_BUF_OPTION) {
2215 *txd = buffer->option;
2217 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2218 EFX_POPULATE_QWORD_3(
2221 buffer->flags & EFX_TX_BUF_CONT,
2222 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2223 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2225 } while (tx_queue->write_count != tx_queue->insert_count);
2227 wmb(); /* Ensure descriptors are written before they are fetched */
2229 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2230 txd = efx_tx_desc(tx_queue,
2231 old_write_count & tx_queue->ptr_mask);
2232 efx_ef10_push_tx_desc(tx_queue, txd);
2235 efx_ef10_notify_tx_desc(tx_queue);
2239 static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2240 bool exclusive, unsigned *context_size)
2242 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2243 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
2244 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2247 u32 alloc_type = exclusive ?
2248 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2249 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2250 unsigned rss_spread = exclusive ?
2252 min(rounddown_pow_of_two(efx->rss_spread),
2253 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2255 if (!exclusive && rss_spread == 1) {
2256 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2262 if (nic_data->datapath_caps &
2263 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2266 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
2267 nic_data->vport_id);
2268 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2269 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
2271 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2272 outbuf, sizeof(outbuf), &outlen);
2276 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2279 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2282 *context_size = rss_spread;
2287 static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2289 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2292 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2295 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2300 static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
2301 const u32 *rx_indir_table)
2303 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2304 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2307 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2309 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2310 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2312 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2314 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
2315 (u8) rx_indir_table[i];
2317 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2318 sizeof(tablebuf), NULL, 0, NULL);
2322 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2324 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2325 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2326 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2327 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
2328 efx->rx_hash_key[i];
2330 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2331 sizeof(keybuf), NULL, 0, NULL);
2334 static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2336 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2338 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2339 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2340 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2343 static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2344 unsigned *context_size)
2346 u32 new_rx_rss_context;
2347 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2348 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2349 false, context_size);
2354 nic_data->rx_rss_context = new_rx_rss_context;
2355 nic_data->rx_rss_context_exclusive = false;
2356 efx_set_default_rx_indir_table(efx);
2360 static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
2361 const u32 *rx_indir_table)
2363 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2365 u32 new_rx_rss_context;
2367 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2368 !nic_data->rx_rss_context_exclusive) {
2369 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2371 if (rc == -EOPNOTSUPP)
2376 new_rx_rss_context = nic_data->rx_rss_context;
2379 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
2384 if (nic_data->rx_rss_context != new_rx_rss_context)
2385 efx_ef10_rx_free_indir_table(efx);
2386 nic_data->rx_rss_context = new_rx_rss_context;
2387 nic_data->rx_rss_context_exclusive = true;
2388 if (rx_indir_table != efx->rx_indir_table)
2389 memcpy(efx->rx_indir_table, rx_indir_table,
2390 sizeof(efx->rx_indir_table));
2394 if (new_rx_rss_context != nic_data->rx_rss_context)
2395 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2397 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2401 static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
2402 const u32 *rx_indir_table)
2406 if (efx->rss_spread == 1)
2409 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
2411 if (rc == -ENOBUFS && !user) {
2412 unsigned context_size;
2413 bool mismatch = false;
2416 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2418 mismatch = rx_indir_table[i] !=
2419 ethtool_rxfh_indir_default(i, efx->rss_spread);
2421 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2423 if (context_size != efx->rss_spread)
2424 netif_warn(efx, probe, efx->net_dev,
2425 "Could not allocate an exclusive RSS"
2426 " context; allocated a shared one of"
2428 " Wanted %u, got %u.\n",
2429 efx->rss_spread, context_size);
2431 netif_warn(efx, probe, efx->net_dev,
2432 "Could not allocate an exclusive RSS"
2433 " context; allocated a shared one but"
2434 " could not apply custom"
2437 netif_info(efx, probe, efx->net_dev,
2438 "Could not allocate an exclusive RSS"
2439 " context; allocated a shared one.\n");
2445 static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2446 const u32 *rx_indir_table
2447 __attribute__ ((unused)))
2449 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2453 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2455 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
2458 static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2460 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2461 (rx_queue->ptr_mask + 1) *
2462 sizeof(efx_qword_t),
2466 static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2468 MCDI_DECLARE_BUF(inbuf,
2469 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2471 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2472 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2473 struct efx_nic *efx = rx_queue->efx;
2474 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2476 dma_addr_t dma_addr;
2479 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
2481 rx_queue->scatter_n = 0;
2482 rx_queue->scatter_len = 0;
2484 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
2485 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
2486 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
2487 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
2488 efx_rx_queue_index(rx_queue));
2489 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
2490 INIT_RXQ_IN_FLAG_PREFIX, 1,
2491 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
2492 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
2493 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
2495 dma_addr = rx_queue->rxd.buf.dma_addr;
2497 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
2498 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
2500 for (i = 0; i < entries; ++i) {
2501 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
2502 dma_addr += EFX_BUF_SIZE;
2505 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
2507 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
2510 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
2511 efx_rx_queue_index(rx_queue));
2514 static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
2516 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
2517 MCDI_DECLARE_BUF_ERR(outbuf);
2518 struct efx_nic *efx = rx_queue->efx;
2522 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
2523 efx_rx_queue_index(rx_queue));
2525 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
2526 outbuf, sizeof(outbuf), &outlen);
2528 if (rc && rc != -EALREADY)
2534 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
2535 outbuf, outlen, rc);
2538 static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
2540 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
2543 /* This creates an entry in the RX descriptor queue */
2545 efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
2547 struct efx_rx_buffer *rx_buf;
2550 rxd = efx_rx_desc(rx_queue, index);
2551 rx_buf = efx_rx_buffer(rx_queue, index);
2552 EFX_POPULATE_QWORD_2(*rxd,
2553 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
2554 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
2557 static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
2559 struct efx_nic *efx = rx_queue->efx;
2560 unsigned int write_count;
2563 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
2564 write_count = rx_queue->added_count & ~7;
2565 if (rx_queue->notified_count == write_count)
2569 efx_ef10_build_rx_desc(
2571 rx_queue->notified_count & rx_queue->ptr_mask);
2572 while (++rx_queue->notified_count != write_count);
2575 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
2576 write_count & rx_queue->ptr_mask);
2577 efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD,
2578 efx_rx_queue_index(rx_queue));
2581 static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
2583 static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
2585 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2586 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2589 EFX_POPULATE_QWORD_2(event,
2590 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2591 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
2593 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2595 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2596 * already swapped the data to little-endian order.
2598 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2599 sizeof(efx_qword_t));
2601 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
2602 inbuf, sizeof(inbuf), 0,
2603 efx_ef10_rx_defer_refill_complete, 0);
2607 efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
2608 int rc, efx_dword_t *outbuf,
2609 size_t outlen_actual)
2614 static int efx_ef10_ev_probe(struct efx_channel *channel)
2616 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
2617 (channel->eventq_mask + 1) *
2618 sizeof(efx_qword_t),
2622 static void efx_ef10_ev_fini(struct efx_channel *channel)
2624 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
2625 MCDI_DECLARE_BUF_ERR(outbuf);
2626 struct efx_nic *efx = channel->efx;
2630 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2632 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
2633 outbuf, sizeof(outbuf), &outlen);
2635 if (rc && rc != -EALREADY)
2641 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2642 outbuf, outlen, rc);
2645 static int efx_ef10_ev_init(struct efx_channel *channel)
2647 MCDI_DECLARE_BUF(inbuf,
2648 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
2650 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
2651 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
2652 struct efx_nic *efx = channel->efx;
2653 struct efx_ef10_nic_data *nic_data;
2654 size_t inlen, outlen;
2655 unsigned int enabled, implemented;
2656 dma_addr_t dma_addr;
2660 nic_data = efx->nic_data;
2662 /* Fill event queue with all ones (i.e. empty events) */
2663 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
2665 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
2666 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
2667 /* INIT_EVQ expects index in vector table, not absolute */
2668 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
2669 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
2670 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
2671 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
2672 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
2673 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
2674 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
2675 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
2677 if (nic_data->datapath_caps2 &
2678 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
2679 /* Use the new generic approach to specifying event queue
2680 * configuration, requesting lower latency or higher throughput.
2681 * The options that actually get used appear in the output.
2683 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
2684 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
2685 INIT_EVQ_V2_IN_FLAG_TYPE,
2686 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
2688 bool cut_thru = !(nic_data->datapath_caps &
2689 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
2691 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
2692 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
2693 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
2694 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
2695 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
2698 dma_addr = channel->eventq.buf.dma_addr;
2699 for (i = 0; i < entries; ++i) {
2700 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
2701 dma_addr += EFX_BUF_SIZE;
2704 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
2706 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
2707 outbuf, sizeof(outbuf), &outlen);
2709 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
2710 netif_dbg(efx, drv, efx->net_dev,
2711 "Channel %d using event queue flags %08x\n",
2713 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
2715 /* IRQ return is ignored */
2716 if (channel->channel || rc)
2719 /* Successfully created event queue on channel 0 */
2720 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
2721 if (rc == -ENOSYS) {
2722 /* GET_WORKAROUNDS was implemented before this workaround,
2723 * thus it must be unavailable in this firmware.
2725 nic_data->workaround_26807 = false;
2730 nic_data->workaround_26807 =
2731 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
2733 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
2734 !nic_data->workaround_26807) {
2737 rc = efx_mcdi_set_workaround(efx,
2738 MC_CMD_WORKAROUND_BUG26807,
2743 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
2744 netif_info(efx, drv, efx->net_dev,
2745 "other functions on NIC have been reset\n");
2747 /* With MCFW v4.6.x and earlier, the
2748 * boot count will have incremented,
2749 * so re-read the warm_boot_count
2750 * value now to ensure this function
2751 * doesn't think it has changed next
2754 rc = efx_ef10_get_warm_boot_count(efx);
2756 nic_data->warm_boot_count = rc;
2760 nic_data->workaround_26807 = true;
2761 } else if (rc == -EPERM) {
2771 efx_ef10_ev_fini(channel);
2775 static void efx_ef10_ev_remove(struct efx_channel *channel)
2777 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2780 static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2781 unsigned int rx_queue_label)
2783 struct efx_nic *efx = rx_queue->efx;
2785 netif_info(efx, hw, efx->net_dev,
2786 "rx event arrived on queue %d labeled as queue %u\n",
2787 efx_rx_queue_index(rx_queue), rx_queue_label);
2789 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2793 efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2794 unsigned int actual, unsigned int expected)
2796 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2797 struct efx_nic *efx = rx_queue->efx;
2799 netif_info(efx, hw, efx->net_dev,
2800 "dropped %d events (index=%d expected=%d)\n",
2801 dropped, actual, expected);
2803 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2806 /* partially received RX was aborted. clean up. */
2807 static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2809 unsigned int rx_desc_ptr;
2811 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2812 "scattered RX aborted (dropping %u buffers)\n",
2813 rx_queue->scatter_n);
2815 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2817 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2818 0, EFX_RX_PKT_DISCARD);
2820 rx_queue->removed_count += rx_queue->scatter_n;
2821 rx_queue->scatter_n = 0;
2822 rx_queue->scatter_len = 0;
2823 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2826 static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2827 const efx_qword_t *event)
2829 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2830 unsigned int n_descs, n_packets, i;
2831 struct efx_nic *efx = channel->efx;
2832 struct efx_rx_queue *rx_queue;
2836 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2839 /* Basic packet information */
2840 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2841 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2842 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2843 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2844 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2846 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2847 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2849 EFX_QWORD_VAL(*event));
2851 rx_queue = efx_channel_get_rx_queue(channel);
2853 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2854 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2856 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2857 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2859 if (n_descs != rx_queue->scatter_n + 1) {
2860 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2862 /* detect rx abort */
2863 if (unlikely(n_descs == rx_queue->scatter_n)) {
2864 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2865 netdev_WARN(efx->net_dev,
2866 "invalid RX abort: scatter_n=%u event="
2868 rx_queue->scatter_n,
2869 EFX_QWORD_VAL(*event));
2870 efx_ef10_handle_rx_abort(rx_queue);
2874 /* Check that RX completion merging is valid, i.e.
2875 * the current firmware supports it and this is a
2876 * non-scattered packet.
2878 if (!(nic_data->datapath_caps &
2879 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2880 rx_queue->scatter_n != 0 || rx_cont) {
2881 efx_ef10_handle_rx_bad_lbits(
2882 rx_queue, next_ptr_lbits,
2883 (rx_queue->removed_count +
2884 rx_queue->scatter_n + 1) &
2885 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2889 /* Merged completion for multiple non-scattered packets */
2890 rx_queue->scatter_n = 1;
2891 rx_queue->scatter_len = 0;
2892 n_packets = n_descs;
2893 ++channel->n_rx_merge_events;
2894 channel->n_rx_merge_packets += n_packets;
2895 flags |= EFX_RX_PKT_PREFIX_LEN;
2897 ++rx_queue->scatter_n;
2898 rx_queue->scatter_len += rx_bytes;
2904 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2905 flags |= EFX_RX_PKT_DISCARD;
2907 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2908 channel->n_rx_ip_hdr_chksum_err += n_packets;
2909 } else if (unlikely(EFX_QWORD_FIELD(*event,
2910 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2911 channel->n_rx_tcp_udp_chksum_err += n_packets;
2912 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2913 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2914 flags |= EFX_RX_PKT_CSUMMED;
2917 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2918 flags |= EFX_RX_PKT_TCP;
2920 channel->irq_mod_score += 2 * n_packets;
2922 /* Handle received packet(s) */
2923 for (i = 0; i < n_packets; i++) {
2924 efx_rx_packet(rx_queue,
2925 rx_queue->removed_count & rx_queue->ptr_mask,
2926 rx_queue->scatter_n, rx_queue->scatter_len,
2928 rx_queue->removed_count += rx_queue->scatter_n;
2931 rx_queue->scatter_n = 0;
2932 rx_queue->scatter_len = 0;
2938 efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2940 struct efx_nic *efx = channel->efx;
2941 struct efx_tx_queue *tx_queue;
2942 unsigned int tx_ev_desc_ptr;
2943 unsigned int tx_ev_q_label;
2946 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2949 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2952 /* Transmit completion */
2953 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2954 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2955 tx_queue = efx_channel_get_tx_queue(channel,
2956 tx_ev_q_label % EFX_TXQ_TYPES);
2957 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2958 tx_queue->ptr_mask);
2959 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2965 efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2967 struct efx_nic *efx = channel->efx;
2970 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2973 case ESE_DZ_DRV_TIMER_EV:
2974 case ESE_DZ_DRV_WAKE_UP_EV:
2976 case ESE_DZ_DRV_START_UP_EV:
2977 /* event queue init complete. ok. */
2980 netif_err(efx, hw, efx->net_dev,
2981 "channel %d unknown driver event type %d"
2982 " (data " EFX_QWORD_FMT ")\n",
2983 channel->channel, subcode,
2984 EFX_QWORD_VAL(*event));
2989 static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2992 struct efx_nic *efx = channel->efx;
2995 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2999 channel->event_test_cpu = raw_smp_processor_id();
3001 case EFX_EF10_REFILL:
3002 /* The queue must be empty, so we won't receive any rx
3003 * events, so efx_process_channel() won't refill the
3004 * queue. Refill it here
3006 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
3009 netif_err(efx, hw, efx->net_dev,
3010 "channel %d unknown driver event type %u"
3011 " (data " EFX_QWORD_FMT ")\n",
3012 channel->channel, (unsigned) subcode,
3013 EFX_QWORD_VAL(*event));
3017 static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3019 struct efx_nic *efx = channel->efx;
3020 efx_qword_t event, *p_event;
3021 unsigned int read_ptr;
3029 read_ptr = channel->eventq_read_ptr;
3032 p_event = efx_event(channel, read_ptr);
3035 if (!efx_event_present(&event))
3038 EFX_SET_QWORD(*p_event);
3042 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3044 netif_vdbg(efx, drv, efx->net_dev,
3045 "processing event on %d " EFX_QWORD_FMT "\n",
3046 channel->channel, EFX_QWORD_VAL(event));
3049 case ESE_DZ_EV_CODE_MCDI_EV:
3050 efx_mcdi_process_event(channel, &event);
3052 case ESE_DZ_EV_CODE_RX_EV:
3053 spent += efx_ef10_handle_rx_event(channel, &event);
3054 if (spent >= quota) {
3055 /* XXX can we split a merged event to
3056 * avoid going over-quota?
3062 case ESE_DZ_EV_CODE_TX_EV:
3063 tx_descs += efx_ef10_handle_tx_event(channel, &event);
3064 if (tx_descs > efx->txq_entries) {
3067 } else if (++spent == quota) {
3071 case ESE_DZ_EV_CODE_DRIVER_EV:
3072 efx_ef10_handle_driver_event(channel, &event);
3073 if (++spent == quota)
3076 case EFX_EF10_DRVGEN_EV:
3077 efx_ef10_handle_driver_generated_event(channel, &event);
3080 netif_err(efx, hw, efx->net_dev,
3081 "channel %d unknown event type %d"
3082 " (data " EFX_QWORD_FMT ")\n",
3083 channel->channel, ev_code,
3084 EFX_QWORD_VAL(event));
3089 channel->eventq_read_ptr = read_ptr;
3093 static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3095 struct efx_nic *efx = channel->efx;
3098 if (EFX_EF10_WORKAROUND_35388(efx)) {
3099 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3100 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3101 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3102 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3104 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3105 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3106 ERF_DD_EVQ_IND_RPTR,
3107 (channel->eventq_read_ptr &
3108 channel->eventq_mask) >>
3109 ERF_DD_EVQ_IND_RPTR_WIDTH);
3110 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3112 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3113 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3114 ERF_DD_EVQ_IND_RPTR,
3115 channel->eventq_read_ptr &
3116 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3117 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3120 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3121 channel->eventq_read_ptr &
3122 channel->eventq_mask);
3123 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3127 static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3129 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3130 struct efx_nic *efx = channel->efx;
3134 EFX_POPULATE_QWORD_2(event,
3135 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3136 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3138 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3140 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3141 * already swapped the data to little-endian order.
3143 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3144 sizeof(efx_qword_t));
3146 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3155 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3158 void efx_ef10_handle_drain_event(struct efx_nic *efx)
3160 if (atomic_dec_and_test(&efx->active_queues))
3161 wake_up(&efx->flush_wq);
3163 WARN_ON(atomic_read(&efx->active_queues) < 0);
3166 static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3168 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3169 struct efx_channel *channel;
3170 struct efx_tx_queue *tx_queue;
3171 struct efx_rx_queue *rx_queue;
3174 /* If the MC has just rebooted, the TX/RX queues will have already been
3175 * torn down, but efx->active_queues needs to be set to zero.
3177 if (nic_data->must_realloc_vis) {
3178 atomic_set(&efx->active_queues, 0);
3182 /* Do not attempt to write to the NIC during EEH recovery */
3183 if (efx->state != STATE_RECOVERY) {
3184 efx_for_each_channel(channel, efx) {
3185 efx_for_each_channel_rx_queue(rx_queue, channel)
3186 efx_ef10_rx_fini(rx_queue);
3187 efx_for_each_channel_tx_queue(tx_queue, channel)
3188 efx_ef10_tx_fini(tx_queue);
3191 wait_event_timeout(efx->flush_wq,
3192 atomic_read(&efx->active_queues) == 0,
3193 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3194 pending = atomic_read(&efx->active_queues);
3196 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3205 static void efx_ef10_prepare_flr(struct efx_nic *efx)
3207 atomic_set(&efx->active_queues, 0);
3210 static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3211 const struct efx_filter_spec *right)
3213 if ((left->match_flags ^ right->match_flags) |
3214 ((left->flags ^ right->flags) &
3215 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3218 return memcmp(&left->outer_vid, &right->outer_vid,
3219 sizeof(struct efx_filter_spec) -
3220 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3223 static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3225 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3226 return jhash2((const u32 *)&spec->outer_vid,
3227 (sizeof(struct efx_filter_spec) -
3228 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3230 /* XXX should we randomise the initval? */
3233 /* Decide whether a filter should be exclusive or else should allow
3234 * delivery to additional recipients. Currently we decide that
3235 * filters for specific local unicast MAC and IP addresses are
3238 static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3240 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3241 !is_multicast_ether_addr(spec->loc_mac))
3244 if ((spec->match_flags &
3245 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3246 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3247 if (spec->ether_type == htons(ETH_P_IP) &&
3248 !ipv4_is_multicast(spec->loc_host[0]))
3250 if (spec->ether_type == htons(ETH_P_IPV6) &&
3251 ((const u8 *)spec->loc_host)[0] != 0xff)
3258 static struct efx_filter_spec *
3259 efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3260 unsigned int filter_idx)
3262 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3263 ~EFX_EF10_FILTER_FLAGS);
3267 efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3268 unsigned int filter_idx)
3270 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3274 efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3275 unsigned int filter_idx,
3276 const struct efx_filter_spec *spec,
3279 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3282 static void efx_ef10_filter_push_prep(struct efx_nic *efx,
3283 const struct efx_filter_spec *spec,
3284 efx_dword_t *inbuf, u64 handle,
3287 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3288 u32 flags = spec->flags;
3290 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
3292 /* Remove RSS flag if we don't have an RSS context. */
3293 if (flags & EFX_FILTER_FLAG_RX_RSS &&
3294 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
3295 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
3296 flags &= ~EFX_FILTER_FLAG_RX_RSS;
3299 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3300 MC_CMD_FILTER_OP_IN_OP_REPLACE);
3301 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
3303 u32 match_fields = 0;
3305 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3306 efx_ef10_filter_is_exclusive(spec) ?
3307 MC_CMD_FILTER_OP_IN_OP_INSERT :
3308 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3310 /* Convert match flags and values. Unlike almost
3311 * everything else in MCDI, these fields are in
3312 * network byte order.
3314 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
3316 is_multicast_ether_addr(spec->loc_mac) ?
3317 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
3318 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
3319 #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
3320 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
3322 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3323 mcdi_field ## _LBN; \
3325 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
3326 sizeof(spec->gen_field)); \
3327 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
3328 &spec->gen_field, sizeof(spec->gen_field)); \
3330 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
3331 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
3332 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
3333 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
3334 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
3335 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
3336 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
3337 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
3338 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
3339 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
3341 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
3345 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
3346 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
3347 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3348 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
3349 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
3350 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
3351 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
3352 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
3353 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
3354 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
3356 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
3357 (flags & EFX_FILTER_FLAG_RX_RSS) ?
3358 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
3359 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
3360 if (flags & EFX_FILTER_FLAG_RX_RSS)
3361 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
3362 spec->rss_context !=
3363 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
3364 spec->rss_context : nic_data->rx_rss_context);
3367 static int efx_ef10_filter_push(struct efx_nic *efx,
3368 const struct efx_filter_spec *spec,
3369 u64 *handle, bool replacing)
3371 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3372 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
3375 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
3376 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3377 outbuf, sizeof(outbuf), NULL);
3379 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3381 rc = -EBUSY; /* to match efx_farch_filter_insert() */
3385 static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
3387 unsigned int match_flags = spec->match_flags;
3390 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
3391 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
3393 is_multicast_ether_addr(spec->loc_mac) ?
3394 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN) :
3395 (1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN);
3398 #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field) { \
3399 unsigned int old_match_flags = match_flags; \
3400 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
3401 if (match_flags != old_match_flags) \
3403 (1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3404 mcdi_field ## _LBN); \
3406 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP);
3407 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP);
3408 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC);
3409 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT);
3410 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC);
3411 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT);
3412 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE);
3413 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN);
3414 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN);
3415 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO);
3416 #undef MAP_FILTER_TO_MCDI_FLAG
3418 /* Did we map them all? */
3419 WARN_ON_ONCE(match_flags);
3424 static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
3425 const struct efx_filter_spec *spec)
3427 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
3428 unsigned int match_pri;
3431 match_pri < table->rx_match_count;
3433 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
3436 return -EPROTONOSUPPORT;
3439 static s32 efx_ef10_filter_insert(struct efx_nic *efx,
3440 struct efx_filter_spec *spec,
3443 struct efx_ef10_filter_table *table = efx->filter_state;
3444 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3445 struct efx_filter_spec *saved_spec;
3446 unsigned int match_pri, hash;
3447 unsigned int priv_flags;
3448 bool replacing = false;
3454 /* For now, only support RX filters */
3455 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
3459 rc = efx_ef10_filter_pri(table, spec);
3464 hash = efx_ef10_filter_hash(spec);
3465 is_mc_recip = efx_filter_is_mc_recipient(spec);
3467 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
3469 /* Find any existing filters with the same match tuple or
3470 * else a free slot to insert at. If any of them are busy,
3471 * we have to wait and retry.
3474 unsigned int depth = 1;
3477 spin_lock_bh(&efx->filter_lock);
3480 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3481 saved_spec = efx_ef10_filter_entry_spec(table, i);
3486 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3487 if (table->entry[i].spec &
3488 EFX_EF10_FILTER_FLAG_BUSY)
3490 if (spec->priority < saved_spec->priority &&
3491 spec->priority != EFX_FILTER_PRI_AUTO) {
3496 /* This is the only one */
3497 if (spec->priority ==
3498 saved_spec->priority &&
3505 } else if (spec->priority >
3506 saved_spec->priority ||
3508 saved_spec->priority &&
3513 __set_bit(depth, mc_rem_map);
3517 /* Once we reach the maximum search depth, use
3518 * the first suitable slot or return -EBUSY if
3521 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3522 if (ins_index < 0) {
3532 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3533 spin_unlock_bh(&efx->filter_lock);
3538 /* Create a software table entry if necessary, and mark it
3539 * busy. We might yet fail to insert, but any attempt to
3540 * insert a conflicting filter while we're waiting for the
3541 * firmware must find the busy entry.
3543 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3545 if (spec->priority == EFX_FILTER_PRI_AUTO &&
3546 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
3547 /* Just make sure it won't be removed */
3548 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
3549 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
3550 table->entry[ins_index].spec &=
3551 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
3556 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
3558 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3563 *saved_spec = *spec;
3566 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3567 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
3569 /* Mark lower-priority multicast recipients busy prior to removal */
3571 unsigned int depth, i;
3573 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3574 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3575 if (test_bit(depth, mc_rem_map))
3576 table->entry[i].spec |=
3577 EFX_EF10_FILTER_FLAG_BUSY;
3581 spin_unlock_bh(&efx->filter_lock);
3583 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
3586 /* Finalise the software table entry */
3587 spin_lock_bh(&efx->filter_lock);
3590 /* Update the fields that may differ */
3591 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
3592 saved_spec->flags |=
3593 EFX_FILTER_FLAG_RX_OVER_AUTO;
3594 saved_spec->priority = spec->priority;
3595 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
3596 saved_spec->flags |= spec->flags;
3597 saved_spec->rss_context = spec->rss_context;
3598 saved_spec->dmaq_id = spec->dmaq_id;
3600 } else if (!replacing) {
3604 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
3606 /* Remove and finalise entries for lower-priority multicast
3610 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3611 unsigned int depth, i;
3613 memset(inbuf, 0, sizeof(inbuf));
3615 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
3616 if (!test_bit(depth, mc_rem_map))
3619 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3620 saved_spec = efx_ef10_filter_entry_spec(table, i);
3621 priv_flags = efx_ef10_filter_entry_flags(table, i);
3624 spin_unlock_bh(&efx->filter_lock);
3625 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3626 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3627 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3628 table->entry[i].handle);
3629 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3630 inbuf, sizeof(inbuf),
3632 spin_lock_bh(&efx->filter_lock);
3640 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
3642 efx_ef10_filter_set_entry(table, i, saved_spec,
3647 /* If successful, return the inserted filter ID */
3649 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
3651 wake_up_all(&table->waitq);
3653 spin_unlock_bh(&efx->filter_lock);
3654 finish_wait(&table->waitq, &wait);
3658 static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
3660 /* no need to do anything here on EF10 */
3664 * If !by_index, remove by ID
3665 * If by_index, remove by index
3666 * Filter ID may come from userland and must be range-checked.
3668 static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
3669 unsigned int priority_mask,
3670 u32 filter_id, bool by_index)
3672 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3673 struct efx_ef10_filter_table *table = efx->filter_state;
3674 MCDI_DECLARE_BUF(inbuf,
3675 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3676 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3677 struct efx_filter_spec *spec;
3681 /* Find the software table entry and mark it busy. Don't
3682 * remove it yet; any attempt to update while we're waiting
3683 * for the firmware must find the busy entry.
3686 spin_lock_bh(&efx->filter_lock);
3687 if (!(table->entry[filter_idx].spec &
3688 EFX_EF10_FILTER_FLAG_BUSY))
3690 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
3691 spin_unlock_bh(&efx->filter_lock);
3695 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3698 efx_ef10_filter_pri(table, spec) !=
3699 filter_id / HUNT_FILTER_TBL_ROWS)) {
3704 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
3705 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
3706 /* Just remove flags */
3707 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
3708 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
3713 if (!(priority_mask & (1U << spec->priority))) {
3718 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3719 spin_unlock_bh(&efx->filter_lock);
3721 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
3722 /* Reset to an automatic filter */
3724 struct efx_filter_spec new_spec = *spec;
3726 new_spec.priority = EFX_FILTER_PRI_AUTO;
3727 new_spec.flags = (EFX_FILTER_FLAG_RX |
3728 (efx_rss_enabled(efx) ?
3729 EFX_FILTER_FLAG_RX_RSS : 0));
3730 new_spec.dmaq_id = 0;
3731 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
3732 rc = efx_ef10_filter_push(efx, &new_spec,
3733 &table->entry[filter_idx].handle,
3736 spin_lock_bh(&efx->filter_lock);
3740 /* Really remove the filter */
3742 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3743 efx_ef10_filter_is_exclusive(spec) ?
3744 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3745 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3746 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3747 table->entry[filter_idx].handle);
3748 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
3749 inbuf, sizeof(inbuf), NULL, 0, NULL);
3751 spin_lock_bh(&efx->filter_lock);
3754 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3758 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3759 wake_up_all(&table->waitq);
3761 spin_unlock_bh(&efx->filter_lock);
3762 finish_wait(&table->waitq, &wait);
3766 static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
3767 enum efx_filter_priority priority,
3770 return efx_ef10_filter_remove_internal(efx, 1U << priority,
3774 static u32 efx_ef10_filter_get_unsafe_id(struct efx_nic *efx, u32 filter_id)
3776 return filter_id % HUNT_FILTER_TBL_ROWS;
3779 static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
3780 enum efx_filter_priority priority,
3783 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
3785 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
3788 static int efx_ef10_filter_get_safe(struct efx_nic *efx,
3789 enum efx_filter_priority priority,
3790 u32 filter_id, struct efx_filter_spec *spec)
3792 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
3793 struct efx_ef10_filter_table *table = efx->filter_state;
3794 const struct efx_filter_spec *saved_spec;
3797 spin_lock_bh(&efx->filter_lock);
3798 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
3799 if (saved_spec && saved_spec->priority == priority &&
3800 efx_ef10_filter_pri(table, saved_spec) ==
3801 filter_id / HUNT_FILTER_TBL_ROWS) {
3802 *spec = *saved_spec;
3807 spin_unlock_bh(&efx->filter_lock);
3811 static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
3812 enum efx_filter_priority priority)
3814 unsigned int priority_mask;
3818 priority_mask = (((1U << (priority + 1)) - 1) &
3819 ~(1U << EFX_FILTER_PRI_AUTO));
3821 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3822 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3824 if (rc && rc != -ENOENT)
3831 static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3832 enum efx_filter_priority priority)
3834 struct efx_ef10_filter_table *table = efx->filter_state;
3835 unsigned int filter_idx;
3838 spin_lock_bh(&efx->filter_lock);
3839 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3840 if (table->entry[filter_idx].spec &&
3841 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3845 spin_unlock_bh(&efx->filter_lock);
3849 static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3851 struct efx_ef10_filter_table *table = efx->filter_state;
3853 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3856 static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3857 enum efx_filter_priority priority,
3860 struct efx_ef10_filter_table *table = efx->filter_state;
3861 struct efx_filter_spec *spec;
3862 unsigned int filter_idx;
3865 spin_lock_bh(&efx->filter_lock);
3866 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3867 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3868 if (spec && spec->priority == priority) {
3869 if (count == size) {
3873 buf[count++] = (efx_ef10_filter_pri(table, spec) *
3874 HUNT_FILTER_TBL_ROWS +
3878 spin_unlock_bh(&efx->filter_lock);
3882 #ifdef CONFIG_RFS_ACCEL
3884 static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3886 static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3887 struct efx_filter_spec *spec)
3889 struct efx_ef10_filter_table *table = efx->filter_state;
3890 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3891 struct efx_filter_spec *saved_spec;
3892 unsigned int hash, i, depth = 1;
3893 bool replacing = false;
3898 /* Must be an RX filter without RSS and not for a multicast
3899 * destination address (RFS only works for connected sockets).
3900 * These restrictions allow us to pass only a tiny amount of
3901 * data through to the completion function.
3903 EFX_WARN_ON_PARANOID(spec->flags !=
3904 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3905 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3906 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3908 hash = efx_ef10_filter_hash(spec);
3910 spin_lock_bh(&efx->filter_lock);
3912 /* Find any existing filter with the same match tuple or else
3913 * a free slot to insert at. If an existing filter is busy,
3914 * we have to give up.
3917 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3918 saved_spec = efx_ef10_filter_entry_spec(table, i);
3923 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3924 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3928 if (spec->priority < saved_spec->priority) {
3936 /* Once we reach the maximum search depth, use the
3937 * first suitable slot or return -EBUSY if there was
3940 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3941 if (ins_index < 0) {
3951 /* Create a software table entry if necessary, and mark it
3952 * busy. We might yet fail to insert, but any attempt to
3953 * insert a conflicting filter while we're waiting for the
3954 * firmware must find the busy entry.
3956 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3960 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3965 *saved_spec = *spec;
3967 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3968 EFX_EF10_FILTER_FLAG_BUSY);
3970 spin_unlock_bh(&efx->filter_lock);
3972 /* Pack up the variables needed on completion */
3973 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3975 efx_ef10_filter_push_prep(efx, spec, inbuf,
3976 table->entry[ins_index].handle, replacing);
3977 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3978 MC_CMD_FILTER_OP_OUT_LEN,
3979 efx_ef10_filter_rfs_insert_complete, cookie);
3984 spin_unlock_bh(&efx->filter_lock);
3989 efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3990 int rc, efx_dword_t *outbuf,
3991 size_t outlen_actual)
3993 struct efx_ef10_filter_table *table = efx->filter_state;
3994 unsigned int ins_index, dmaq_id;
3995 struct efx_filter_spec *spec;
3998 /* Unpack the cookie */
3999 replacing = cookie >> 31;
4000 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4001 dmaq_id = cookie & 0xffff;
4003 spin_lock_bh(&efx->filter_lock);
4004 spec = efx_ef10_filter_entry_spec(table, ins_index);
4006 table->entry[ins_index].handle =
4007 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4009 spec->dmaq_id = dmaq_id;
4010 } else if (!replacing) {
4014 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4015 spin_unlock_bh(&efx->filter_lock);
4017 wake_up_all(&table->waitq);
4021 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4022 unsigned long filter_idx,
4023 int rc, efx_dword_t *outbuf,
4024 size_t outlen_actual);
4026 static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4027 unsigned int filter_idx)
4029 struct efx_ef10_filter_table *table = efx->filter_state;
4030 struct efx_filter_spec *spec =
4031 efx_ef10_filter_entry_spec(table, filter_idx);
4032 MCDI_DECLARE_BUF(inbuf,
4033 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4034 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4037 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4038 spec->priority != EFX_FILTER_PRI_HINT ||
4039 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4040 flow_id, filter_idx))
4043 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4044 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4045 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4046 table->entry[filter_idx].handle);
4047 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4048 efx_ef10_filter_rfs_expire_complete, filter_idx))
4051 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4056 efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4057 unsigned long filter_idx,
4058 int rc, efx_dword_t *outbuf,
4059 size_t outlen_actual)
4061 struct efx_ef10_filter_table *table = efx->filter_state;
4062 struct efx_filter_spec *spec =
4063 efx_ef10_filter_entry_spec(table, filter_idx);
4065 spin_lock_bh(&efx->filter_lock);
4068 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4070 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4071 wake_up_all(&table->waitq);
4072 spin_unlock_bh(&efx->filter_lock);
4075 #endif /* CONFIG_RFS_ACCEL */
4077 static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
4079 int match_flags = 0;
4081 #define MAP_FLAG(gen_flag, mcdi_field) { \
4082 u32 old_mcdi_flags = mcdi_flags; \
4083 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4084 mcdi_field ## _LBN); \
4085 if (mcdi_flags != old_mcdi_flags) \
4086 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
4088 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4089 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4090 MAP_FLAG(REM_HOST, SRC_IP);
4091 MAP_FLAG(LOC_HOST, DST_IP);
4092 MAP_FLAG(REM_MAC, SRC_MAC);
4093 MAP_FLAG(REM_PORT, SRC_PORT);
4094 MAP_FLAG(LOC_MAC, DST_MAC);
4095 MAP_FLAG(LOC_PORT, DST_PORT);
4096 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4097 MAP_FLAG(INNER_VID, INNER_VLAN);
4098 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4099 MAP_FLAG(IP_PROTO, IP_PROTO);
4102 /* Did we map them all? */
4109 static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4111 struct efx_ef10_filter_table *table = efx->filter_state;
4112 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4114 /* See comment in efx_ef10_filter_table_remove() */
4115 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4121 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4122 efx_ef10_filter_del_vlan_internal(efx, vlan);
4125 static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
4126 enum efx_filter_match_flags match_flags)
4128 unsigned int match_pri;
4132 match_pri < table->rx_match_count;
4134 mf = efx_ef10_filter_match_flags_from_mcdi(
4135 table->rx_match_mcdi_flags[match_pri]);
4136 if (mf == match_flags)
4143 static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4145 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4146 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4147 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4148 struct net_device *net_dev = efx->net_dev;
4149 unsigned int pd_match_pri, pd_match_count;
4150 struct efx_ef10_filter_table *table;
4151 struct efx_ef10_vlan *vlan;
4155 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4158 if (efx->filter_state) /* already probed */
4161 table = kzalloc(sizeof(*table), GFP_KERNEL);
4165 /* Find out which RX filter types are supported, and their priorities */
4166 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
4167 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4168 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4169 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4173 pd_match_count = MCDI_VAR_ARRAY_LEN(
4174 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
4175 table->rx_match_count = 0;
4177 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4181 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4183 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
4185 netif_dbg(efx, probe, efx->net_dev,
4186 "%s: fw flags %#x pri %u not supported in driver\n",
4187 __func__, mcdi_flags, pd_match_pri);
4189 netif_dbg(efx, probe, efx->net_dev,
4190 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4191 __func__, mcdi_flags, pd_match_pri,
4192 rc, table->rx_match_count);
4193 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4194 table->rx_match_count++;
4198 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4199 !(efx_ef10_filter_match_supported(table,
4200 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
4201 efx_ef10_filter_match_supported(table,
4202 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
4203 netif_info(efx, probe, net_dev,
4204 "VLAN filters are not supported in this firmware variant\n");
4205 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4206 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4207 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4210 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
4211 if (!table->entry) {
4216 table->mc_promisc_last = false;
4217 table->vlan_filter =
4218 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4219 INIT_LIST_HEAD(&table->vlan_list);
4221 efx->filter_state = table;
4222 init_waitqueue_head(&table->waitq);
4224 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
4225 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
4233 efx_ef10_filter_cleanup_vlans(efx);
4234 efx->filter_state = NULL;
4240 /* Caller must hold efx->filter_sem for read if race against
4241 * efx_ef10_filter_table_remove() is possible
4243 static void efx_ef10_filter_table_restore(struct efx_nic *efx)
4245 struct efx_ef10_filter_table *table = efx->filter_state;
4246 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4247 struct efx_filter_spec *spec;
4248 unsigned int filter_idx;
4249 bool failed = false;
4252 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4254 if (!nic_data->must_restore_filters)
4260 spin_lock_bh(&efx->filter_lock);
4262 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4263 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4267 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4268 spin_unlock_bh(&efx->filter_lock);
4270 rc = efx_ef10_filter_push(efx, spec,
4271 &table->entry[filter_idx].handle,
4276 spin_lock_bh(&efx->filter_lock);
4279 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4281 table->entry[filter_idx].spec &=
4282 ~EFX_EF10_FILTER_FLAG_BUSY;
4286 spin_unlock_bh(&efx->filter_lock);
4289 netif_err(efx, hw, efx->net_dev,
4290 "unable to restore all filters\n");
4292 nic_data->must_restore_filters = false;
4295 static void efx_ef10_filter_table_remove(struct efx_nic *efx)
4297 struct efx_ef10_filter_table *table = efx->filter_state;
4298 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
4299 struct efx_filter_spec *spec;
4300 unsigned int filter_idx;
4303 efx_ef10_filter_cleanup_vlans(efx);
4304 efx->filter_state = NULL;
4305 /* If we were called without locking, then it's not safe to free
4306 * the table as others might be using it. So we just WARN, leak
4307 * the memory, and potentially get an inconsistent filter table
4309 * This should never actually happen.
4311 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4317 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4318 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4322 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4323 efx_ef10_filter_is_exclusive(spec) ?
4324 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4325 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4326 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4327 table->entry[filter_idx].handle);
4328 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
4329 sizeof(inbuf), NULL, 0, NULL);
4331 netif_info(efx, drv, efx->net_dev,
4332 "%s: filter %04x remove failed\n",
4333 __func__, filter_idx);
4337 vfree(table->entry);
4341 static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
4343 struct efx_ef10_filter_table *table = efx->filter_state;
4344 unsigned int filter_idx;
4346 if (*id != EFX_EF10_FILTER_ID_INVALID) {
4347 filter_idx = efx_ef10_filter_get_unsafe_id(efx, *id);
4348 if (!table->entry[filter_idx].spec)
4349 netif_dbg(efx, drv, efx->net_dev,
4350 "marked null spec old %04x:%04x\n", *id,
4352 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
4353 *id = EFX_EF10_FILTER_ID_INVALID;
4357 /* Mark old per-VLAN filters that may need to be removed */
4358 static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
4359 struct efx_ef10_filter_vlan *vlan)
4361 struct efx_ef10_filter_table *table = efx->filter_state;
4364 for (i = 0; i < table->dev_uc_count; i++)
4365 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
4366 for (i = 0; i < table->dev_mc_count; i++)
4367 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
4368 efx_ef10_filter_mark_one_old(efx, &vlan->ucdef);
4369 efx_ef10_filter_mark_one_old(efx, &vlan->bcast);
4370 efx_ef10_filter_mark_one_old(efx, &vlan->mcdef);
4373 /* Mark old filters that may need to be removed.
4374 * Caller must hold efx->filter_sem for read if race against
4375 * efx_ef10_filter_table_remove() is possible
4377 static void efx_ef10_filter_mark_old(struct efx_nic *efx)
4379 struct efx_ef10_filter_table *table = efx->filter_state;
4380 struct efx_ef10_filter_vlan *vlan;
4382 spin_lock_bh(&efx->filter_lock);
4383 list_for_each_entry(vlan, &table->vlan_list, list)
4384 _efx_ef10_filter_vlan_mark_old(efx, vlan);
4385 spin_unlock_bh(&efx->filter_lock);
4388 static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
4390 struct efx_ef10_filter_table *table = efx->filter_state;
4391 struct net_device *net_dev = efx->net_dev;
4392 struct netdev_hw_addr *uc;
4396 addr_count = netdev_uc_count(net_dev);
4397 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
4398 table->dev_uc_count = 1 + addr_count;
4399 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
4401 netdev_for_each_uc_addr(uc, net_dev) {
4402 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
4403 table->uc_promisc = true;
4406 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
4411 static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
4413 struct efx_ef10_filter_table *table = efx->filter_state;
4414 struct net_device *net_dev = efx->net_dev;
4415 struct netdev_hw_addr *mc;
4416 unsigned int i, addr_count;
4418 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
4420 addr_count = netdev_mc_count(net_dev);
4422 netdev_for_each_mc_addr(mc, net_dev) {
4423 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
4424 table->mc_promisc = true;
4427 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
4431 table->dev_mc_count = i;
4434 static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
4435 struct efx_ef10_filter_vlan *vlan,
4436 bool multicast, bool rollback)
4438 struct efx_ef10_filter_table *table = efx->filter_state;
4439 struct efx_ef10_dev_addr *addr_list;
4440 enum efx_filter_flags filter_flags;
4441 struct efx_filter_spec spec;
4449 addr_list = table->dev_mc_list;
4450 addr_count = table->dev_mc_count;
4453 addr_list = table->dev_uc_list;
4454 addr_count = table->dev_uc_count;
4458 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4460 /* Insert/renew filters */
4461 for (i = 0; i < addr_count; i++) {
4462 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
4463 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
4464 rc = efx_ef10_filter_insert(efx, &spec, true);
4467 netif_info(efx, drv, efx->net_dev,
4468 "efx_ef10_filter_insert failed rc=%d\n",
4470 /* Fall back to promiscuous */
4471 for (j = 0; j < i; j++) {
4472 efx_ef10_filter_remove_unsafe(
4473 efx, EFX_FILTER_PRI_AUTO,
4475 ids[j] = EFX_EF10_FILTER_ID_INVALID;
4479 /* mark as not inserted, and carry on */
4480 rc = EFX_EF10_FILTER_ID_INVALID;
4483 ids[i] = efx_ef10_filter_get_unsafe_id(efx, rc);
4486 if (multicast && rollback) {
4487 /* Also need an Ethernet broadcast filter */
4488 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
4489 eth_broadcast_addr(baddr);
4490 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
4491 rc = efx_ef10_filter_insert(efx, &spec, true);
4493 netif_warn(efx, drv, efx->net_dev,
4494 "Broadcast filter insert failed rc=%d\n", rc);
4495 /* Fall back to promiscuous */
4496 for (j = 0; j < i; j++) {
4497 efx_ef10_filter_remove_unsafe(
4498 efx, EFX_FILTER_PRI_AUTO,
4500 ids[j] = EFX_EF10_FILTER_ID_INVALID;
4504 EFX_WARN_ON_PARANOID(vlan->bcast !=
4505 EFX_EF10_FILTER_ID_INVALID);
4506 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
4513 static int efx_ef10_filter_insert_def(struct efx_nic *efx,
4514 struct efx_ef10_filter_vlan *vlan,
4515 bool multicast, bool rollback)
4517 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4518 enum efx_filter_flags filter_flags;
4519 struct efx_filter_spec spec;
4523 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
4525 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
4528 efx_filter_set_mc_def(&spec);
4530 efx_filter_set_uc_def(&spec);
4532 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
4533 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
4535 rc = efx_ef10_filter_insert(efx, &spec, true);
4537 netif_printk(efx, drv, rc == -EPERM ? KERN_DEBUG : KERN_WARNING,
4539 "%scast mismatch filter insert failed rc=%d\n",
4540 multicast ? "Multi" : "Uni", rc);
4541 } else if (multicast) {
4542 EFX_WARN_ON_PARANOID(vlan->mcdef != EFX_EF10_FILTER_ID_INVALID);
4543 vlan->mcdef = efx_ef10_filter_get_unsafe_id(efx, rc);
4544 if (!nic_data->workaround_26807) {
4545 /* Also need an Ethernet broadcast filter */
4546 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
4548 eth_broadcast_addr(baddr);
4549 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
4550 rc = efx_ef10_filter_insert(efx, &spec, true);
4552 netif_warn(efx, drv, efx->net_dev,
4553 "Broadcast filter insert failed rc=%d\n",
4556 /* Roll back the mc_def filter */
4557 efx_ef10_filter_remove_unsafe(
4558 efx, EFX_FILTER_PRI_AUTO,
4560 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
4564 EFX_WARN_ON_PARANOID(vlan->bcast !=
4565 EFX_EF10_FILTER_ID_INVALID);
4566 vlan->bcast = efx_ef10_filter_get_unsafe_id(efx, rc);
4571 EFX_WARN_ON_PARANOID(vlan->ucdef != EFX_EF10_FILTER_ID_INVALID);
4578 /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
4579 * flag or removes these filters, we don't need to hold the filter_lock while
4580 * scanning for these filters.
4582 static void efx_ef10_filter_remove_old(struct efx_nic *efx)
4584 struct efx_ef10_filter_table *table = efx->filter_state;
4585 int remove_failed = 0;
4586 int remove_noent = 0;
4590 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4591 if (ACCESS_ONCE(table->entry[i].spec) &
4592 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
4593 rc = efx_ef10_filter_remove_internal(efx,
4594 1U << EFX_FILTER_PRI_AUTO, i, true);
4603 netif_info(efx, drv, efx->net_dev,
4604 "%s: failed to remove %d filters\n",
4605 __func__, remove_failed);
4607 netif_info(efx, drv, efx->net_dev,
4608 "%s: failed to remove %d non-existent filters\n",
4609 __func__, remove_noent);
4612 static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
4614 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4615 u8 mac_old[ETH_ALEN];
4618 /* Only reconfigure a PF-created vport */
4619 if (is_zero_ether_addr(nic_data->vport_mac))
4622 efx_device_detach_sync(efx);
4623 efx_net_stop(efx->net_dev);
4624 down_write(&efx->filter_sem);
4625 efx_ef10_filter_table_remove(efx);
4626 up_write(&efx->filter_sem);
4628 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
4630 goto restore_filters;
4632 ether_addr_copy(mac_old, nic_data->vport_mac);
4633 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
4634 nic_data->vport_mac);
4636 goto restore_vadaptor;
4638 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
4639 efx->net_dev->dev_addr);
4641 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
4643 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
4645 /* Failed to add original MAC, so clear vport_mac */
4646 eth_zero_addr(nic_data->vport_mac);
4652 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
4656 down_write(&efx->filter_sem);
4657 rc2 = efx_ef10_filter_table_probe(efx);
4658 up_write(&efx->filter_sem);
4662 rc2 = efx_net_open(efx->net_dev);
4666 netif_device_attach(efx->net_dev);
4671 netif_err(efx, drv, efx->net_dev,
4672 "Failed to restore when changing MAC address - scheduling reset\n");
4673 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
4675 return rc ? rc : rc2;
4678 /* Caller must hold efx->filter_sem for read if race against
4679 * efx_ef10_filter_table_remove() is possible
4681 static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
4682 struct efx_ef10_filter_vlan *vlan)
4684 struct efx_ef10_filter_table *table = efx->filter_state;
4685 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4687 /* Do not install unspecified VID if VLAN filtering is enabled.
4688 * Do not install all specified VIDs if VLAN filtering is disabled.
4690 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
4693 /* Insert/renew unicast filters */
4694 if (table->uc_promisc) {
4695 efx_ef10_filter_insert_def(efx, vlan, false, false);
4696 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
4698 /* If any of the filters failed to insert, fall back to
4699 * promiscuous mode - add in the uc_def filter. But keep
4700 * our individual unicast filters.
4702 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
4703 efx_ef10_filter_insert_def(efx, vlan, false, false);
4706 /* Insert/renew multicast filters */
4707 /* If changing promiscuous state with cascaded multicast filters, remove
4708 * old filters first, so that packets are dropped rather than duplicated
4710 if (nic_data->workaround_26807 &&
4711 table->mc_promisc_last != table->mc_promisc)
4712 efx_ef10_filter_remove_old(efx);
4713 if (table->mc_promisc) {
4714 if (nic_data->workaround_26807) {
4715 /* If we failed to insert promiscuous filters, rollback
4716 * and fall back to individual multicast filters
4718 if (efx_ef10_filter_insert_def(efx, vlan, true, true)) {
4719 /* Changing promisc state, so remove old filters */
4720 efx_ef10_filter_remove_old(efx);
4721 efx_ef10_filter_insert_addr_list(efx, vlan,
4725 /* If we failed to insert promiscuous filters, don't
4726 * rollback. Regardless, also insert the mc_list
4728 efx_ef10_filter_insert_def(efx, vlan, true, false);
4729 efx_ef10_filter_insert_addr_list(efx, vlan, true, false);
4732 /* If any filters failed to insert, rollback and fall back to
4733 * promiscuous mode - mc_def filter and maybe broadcast. If
4734 * that fails, roll back again and insert as many of our
4735 * individual multicast filters as we can.
4737 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
4738 /* Changing promisc state, so remove old filters */
4739 if (nic_data->workaround_26807)
4740 efx_ef10_filter_remove_old(efx);
4741 if (efx_ef10_filter_insert_def(efx, vlan, true, true))
4742 efx_ef10_filter_insert_addr_list(efx, vlan,
4748 /* Caller must hold efx->filter_sem for read if race against
4749 * efx_ef10_filter_table_remove() is possible
4751 static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
4753 struct efx_ef10_filter_table *table = efx->filter_state;
4754 struct net_device *net_dev = efx->net_dev;
4755 struct efx_ef10_filter_vlan *vlan;
4758 if (!efx_dev_registered(efx))
4764 efx_ef10_filter_mark_old(efx);
4766 /* Copy/convert the address lists; add the primary station
4767 * address and broadcast address
4769 netif_addr_lock_bh(net_dev);
4770 efx_ef10_filter_uc_addr_list(efx);
4771 efx_ef10_filter_mc_addr_list(efx);
4772 netif_addr_unlock_bh(net_dev);
4774 /* If VLAN filtering changes, all old filters are finally removed.
4775 * Do it in advance to avoid conflicts for unicast untagged and
4776 * VLAN 0 tagged filters.
4778 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
4779 if (table->vlan_filter != vlan_filter) {
4780 table->vlan_filter = vlan_filter;
4781 efx_ef10_filter_remove_old(efx);
4784 list_for_each_entry(vlan, &table->vlan_list, list)
4785 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
4787 efx_ef10_filter_remove_old(efx);
4788 table->mc_promisc_last = table->mc_promisc;
4791 static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
4793 struct efx_ef10_filter_table *table = efx->filter_state;
4794 struct efx_ef10_filter_vlan *vlan;
4796 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
4798 list_for_each_entry(vlan, &table->vlan_list, list) {
4799 if (vlan->vid == vid)
4806 static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
4808 struct efx_ef10_filter_table *table = efx->filter_state;
4809 struct efx_ef10_filter_vlan *vlan;
4812 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4815 vlan = efx_ef10_filter_find_vlan(efx, vid);
4816 if (WARN_ON(vlan)) {
4817 netif_err(efx, drv, efx->net_dev,
4818 "VLAN %u already added\n", vid);
4822 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
4828 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
4829 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
4830 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
4831 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
4832 vlan->ucdef = EFX_EF10_FILTER_ID_INVALID;
4833 vlan->bcast = EFX_EF10_FILTER_ID_INVALID;
4834 vlan->mcdef = EFX_EF10_FILTER_ID_INVALID;
4836 list_add_tail(&vlan->list, &table->vlan_list);
4838 if (efx_dev_registered(efx))
4839 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
4844 static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
4845 struct efx_ef10_filter_vlan *vlan)
4849 /* See comment in efx_ef10_filter_table_remove() */
4850 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4853 list_del(&vlan->list);
4855 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
4856 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
4858 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
4859 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
4861 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->ucdef);
4862 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->bcast);
4863 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO, vlan->mcdef);
4868 static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
4870 struct efx_ef10_filter_vlan *vlan;
4872 /* See comment in efx_ef10_filter_table_remove() */
4873 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4876 vlan = efx_ef10_filter_find_vlan(efx, vid);
4878 netif_err(efx, drv, efx->net_dev,
4879 "VLAN %u not found in filter state\n", vid);
4883 efx_ef10_filter_del_vlan_internal(efx, vlan);
4886 static int efx_ef10_set_mac_address(struct efx_nic *efx)
4888 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
4889 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4890 bool was_enabled = efx->port_enabled;
4893 efx_device_detach_sync(efx);
4894 efx_net_stop(efx->net_dev);
4896 mutex_lock(&efx->mac_lock);
4897 down_write(&efx->filter_sem);
4898 efx_ef10_filter_table_remove(efx);
4900 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
4901 efx->net_dev->dev_addr);
4902 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
4903 nic_data->vport_id);
4904 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
4905 sizeof(inbuf), NULL, 0, NULL);
4907 efx_ef10_filter_table_probe(efx);
4908 up_write(&efx->filter_sem);
4909 mutex_unlock(&efx->mac_lock);
4912 efx_net_open(efx->net_dev);
4913 netif_device_attach(efx->net_dev);
4915 #ifdef CONFIG_SFC_SRIOV
4916 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
4917 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
4920 struct efx_nic *efx_pf;
4922 /* Switch to PF and change MAC address on vport */
4923 efx_pf = pci_get_drvdata(pci_dev_pf);
4925 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
4927 efx->net_dev->dev_addr);
4929 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
4930 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
4933 /* MAC address successfully changed by VF (with MAC
4934 * spoofing) so update the parent PF if possible.
4936 for (i = 0; i < efx_pf->vf_count; ++i) {
4937 struct ef10_vf *vf = nic_data->vf + i;
4939 if (vf->efx == efx) {
4940 ether_addr_copy(vf->mac,
4941 efx->net_dev->dev_addr);
4949 netif_err(efx, drv, efx->net_dev,
4950 "Cannot change MAC address; use sfboot to enable"
4951 " mac-spoofing on this interface\n");
4952 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
4953 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
4954 * fall-back to the method of changing the MAC address on the
4955 * vport. This only applies to PFs because such versions of
4956 * MCFW do not support VFs.
4958 rc = efx_ef10_vport_set_mac_address(efx);
4960 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
4961 sizeof(inbuf), NULL, 0, rc);
4967 static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
4969 efx_ef10_filter_sync_rx_mode(efx);
4971 return efx_mcdi_set_mac(efx);
4974 static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
4976 efx_ef10_filter_sync_rx_mode(efx);
4981 static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
4983 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
4985 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
4986 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
4990 /* MC BISTs follow a different poll mechanism to phy BISTs.
4991 * The BIST is done in the poll handler on the MC, and the MCDI command
4992 * will block until the BIST is done.
4994 static int efx_ef10_poll_bist(struct efx_nic *efx)
4997 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5001 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5002 outbuf, sizeof(outbuf), &outlen);
5006 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5009 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5011 case MC_CMD_POLL_BIST_PASSED:
5012 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5014 case MC_CMD_POLL_BIST_TIMEOUT:
5015 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5017 case MC_CMD_POLL_BIST_FAILED:
5018 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
5021 netif_err(efx, hw, efx->net_dev,
5022 "BIST returned unknown result %u", result);
5027 static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
5031 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
5033 rc = efx_ef10_start_bist(efx, bist_type);
5037 return efx_ef10_poll_bist(efx);
5041 efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
5045 efx_reset_down(efx, RESET_TYPE_WORLD);
5047 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
5048 NULL, 0, NULL, 0, NULL);
5052 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
5053 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
5055 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
5060 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
5061 return rc ? rc : rc2;
5064 #ifdef CONFIG_SFC_MTD
5066 struct efx_ef10_nvram_type_info {
5067 u16 type, type_mask;
5072 static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
5073 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
5074 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
5075 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
5076 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
5077 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
5078 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
5079 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
5080 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
5081 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
5082 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
5083 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
5086 static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
5087 struct efx_mcdi_mtd_partition *part,
5090 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
5091 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
5092 const struct efx_ef10_nvram_type_info *info;
5093 size_t size, erase_size, outlen;
5097 for (info = efx_ef10_nvram_types; ; info++) {
5099 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
5101 if ((type & ~info->type_mask) == info->type)
5104 if (info->port != efx_port_num(efx))
5107 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
5111 return -ENODEV; /* hide it */
5113 part->nvram_type = type;
5115 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
5116 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
5117 outbuf, sizeof(outbuf), &outlen);
5120 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
5122 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
5123 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
5124 part->fw_subtype = MCDI_DWORD(outbuf,
5125 NVRAM_METADATA_OUT_SUBTYPE);
5127 part->common.dev_type_name = "EF10 NVRAM manager";
5128 part->common.type_name = info->name;
5130 part->common.mtd.type = MTD_NORFLASH;
5131 part->common.mtd.flags = MTD_CAP_NORFLASH;
5132 part->common.mtd.size = size;
5133 part->common.mtd.erasesize = erase_size;
5138 static int efx_ef10_mtd_probe(struct efx_nic *efx)
5140 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
5141 struct efx_mcdi_mtd_partition *parts;
5142 size_t outlen, n_parts_total, i, n_parts;
5148 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
5149 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
5150 outbuf, sizeof(outbuf), &outlen);
5153 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
5156 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
5158 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
5161 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
5166 for (i = 0; i < n_parts_total; i++) {
5167 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
5169 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
5172 else if (rc != -ENODEV)
5176 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
5183 #endif /* CONFIG_SFC_MTD */
5185 static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
5187 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
5190 static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
5193 static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
5196 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
5199 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
5200 channel->sync_events_state == SYNC_EVENTS_VALID ||
5201 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
5203 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
5205 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
5206 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5207 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
5210 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5211 inbuf, sizeof(inbuf), NULL, 0, NULL);
5214 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5215 SYNC_EVENTS_DISABLED;
5220 static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
5223 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
5226 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
5227 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
5229 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
5230 channel->sync_events_state = SYNC_EVENTS_DISABLED;
5233 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
5234 SYNC_EVENTS_DISABLED;
5236 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
5237 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
5238 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
5239 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
5240 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
5243 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
5244 inbuf, sizeof(inbuf), NULL, 0, NULL);
5249 static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
5252 int (*set)(struct efx_channel *channel, bool temp);
5253 struct efx_channel *channel;
5256 efx_ef10_rx_enable_timestamping :
5257 efx_ef10_rx_disable_timestamping;
5259 efx_for_each_channel(channel, efx) {
5260 int rc = set(channel, temp);
5261 if (en && rc != 0) {
5262 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
5270 static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
5271 struct hwtstamp_config *init)
5276 static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
5277 struct hwtstamp_config *init)
5281 switch (init->rx_filter) {
5282 case HWTSTAMP_FILTER_NONE:
5283 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
5284 /* if TX timestamping is still requested then leave PTP on */
5285 return efx_ptp_change_mode(efx,
5286 init->tx_type != HWTSTAMP_TX_OFF, 0);
5287 case HWTSTAMP_FILTER_ALL:
5288 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
5289 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
5290 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
5291 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
5292 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5293 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5294 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
5295 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5296 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5297 case HWTSTAMP_FILTER_PTP_V2_EVENT:
5298 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5299 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5300 init->rx_filter = HWTSTAMP_FILTER_ALL;
5301 rc = efx_ptp_change_mode(efx, true, 0);
5303 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
5305 efx_ptp_change_mode(efx, false, 0);
5312 static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5314 if (proto != htons(ETH_P_8021Q))
5317 return efx_ef10_add_vlan(efx, vid);
5320 static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
5322 if (proto != htons(ETH_P_8021Q))
5325 return efx_ef10_del_vlan(efx, vid);
5328 #define EF10_OFFLOAD_FEATURES \
5329 (NETIF_F_IP_CSUM | \
5330 NETIF_F_HW_VLAN_CTAG_FILTER | \
5331 NETIF_F_IPV6_CSUM | \
5335 const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
5337 .mem_bar = EFX_MEM_VF_BAR,
5338 .mem_map_size = efx_ef10_mem_map_size,
5339 .probe = efx_ef10_probe_vf,
5340 .remove = efx_ef10_remove,
5341 .dimension_resources = efx_ef10_dimension_resources,
5342 .init = efx_ef10_init_nic,
5343 .fini = efx_port_dummy_op_void,
5344 .map_reset_reason = efx_ef10_map_reset_reason,
5345 .map_reset_flags = efx_ef10_map_reset_flags,
5346 .reset = efx_ef10_reset,
5347 .probe_port = efx_mcdi_port_probe,
5348 .remove_port = efx_mcdi_port_remove,
5349 .fini_dmaq = efx_ef10_fini_dmaq,
5350 .prepare_flr = efx_ef10_prepare_flr,
5351 .finish_flr = efx_port_dummy_op_void,
5352 .describe_stats = efx_ef10_describe_stats,
5353 .update_stats = efx_ef10_update_stats_vf,
5354 .start_stats = efx_port_dummy_op_void,
5355 .pull_stats = efx_port_dummy_op_void,
5356 .stop_stats = efx_port_dummy_op_void,
5357 .set_id_led = efx_mcdi_set_id_led,
5358 .push_irq_moderation = efx_ef10_push_irq_moderation,
5359 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
5360 .check_mac_fault = efx_mcdi_mac_check_fault,
5361 .reconfigure_port = efx_mcdi_port_reconfigure,
5362 .get_wol = efx_ef10_get_wol_vf,
5363 .set_wol = efx_ef10_set_wol_vf,
5364 .resume_wol = efx_port_dummy_op_void,
5365 .mcdi_request = efx_ef10_mcdi_request,
5366 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5367 .mcdi_read_response = efx_ef10_mcdi_read_response,
5368 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
5369 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
5370 .irq_enable_master = efx_port_dummy_op_void,
5371 .irq_test_generate = efx_ef10_irq_test_generate,
5372 .irq_disable_non_ev = efx_port_dummy_op_void,
5373 .irq_handle_msi = efx_ef10_msi_interrupt,
5374 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5375 .tx_probe = efx_ef10_tx_probe,
5376 .tx_init = efx_ef10_tx_init,
5377 .tx_remove = efx_ef10_tx_remove,
5378 .tx_write = efx_ef10_tx_write,
5379 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
5380 .rx_probe = efx_ef10_rx_probe,
5381 .rx_init = efx_ef10_rx_init,
5382 .rx_remove = efx_ef10_rx_remove,
5383 .rx_write = efx_ef10_rx_write,
5384 .rx_defer_refill = efx_ef10_rx_defer_refill,
5385 .ev_probe = efx_ef10_ev_probe,
5386 .ev_init = efx_ef10_ev_init,
5387 .ev_fini = efx_ef10_ev_fini,
5388 .ev_remove = efx_ef10_ev_remove,
5389 .ev_process = efx_ef10_ev_process,
5390 .ev_read_ack = efx_ef10_ev_read_ack,
5391 .ev_test_generate = efx_ef10_ev_test_generate,
5392 .filter_table_probe = efx_ef10_filter_table_probe,
5393 .filter_table_restore = efx_ef10_filter_table_restore,
5394 .filter_table_remove = efx_ef10_filter_table_remove,
5395 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5396 .filter_insert = efx_ef10_filter_insert,
5397 .filter_remove_safe = efx_ef10_filter_remove_safe,
5398 .filter_get_safe = efx_ef10_filter_get_safe,
5399 .filter_clear_rx = efx_ef10_filter_clear_rx,
5400 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5401 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5402 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5403 #ifdef CONFIG_RFS_ACCEL
5404 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5405 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5407 #ifdef CONFIG_SFC_MTD
5408 .mtd_probe = efx_port_dummy_op_int,
5410 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
5411 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
5412 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5413 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
5414 #ifdef CONFIG_SFC_SRIOV
5415 .vswitching_probe = efx_ef10_vswitching_probe_vf,
5416 .vswitching_restore = efx_ef10_vswitching_restore_vf,
5417 .vswitching_remove = efx_ef10_vswitching_remove_vf,
5418 .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id,
5420 .get_mac_address = efx_ef10_get_mac_address_vf,
5421 .set_mac_address = efx_ef10_set_mac_address,
5423 .revision = EFX_REV_HUNT_A0,
5424 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5425 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5426 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5427 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5428 .can_rx_scatter = true,
5429 .always_rx_scatter = true,
5430 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5431 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
5432 .offload_features = EF10_OFFLOAD_FEATURES,
5434 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5435 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5436 1 << HWTSTAMP_FILTER_ALL,
5439 const struct efx_nic_type efx_hunt_a0_nic_type = {
5441 .mem_bar = EFX_MEM_BAR,
5442 .mem_map_size = efx_ef10_mem_map_size,
5443 .probe = efx_ef10_probe_pf,
5444 .remove = efx_ef10_remove,
5445 .dimension_resources = efx_ef10_dimension_resources,
5446 .init = efx_ef10_init_nic,
5447 .fini = efx_port_dummy_op_void,
5448 .map_reset_reason = efx_ef10_map_reset_reason,
5449 .map_reset_flags = efx_ef10_map_reset_flags,
5450 .reset = efx_ef10_reset,
5451 .probe_port = efx_mcdi_port_probe,
5452 .remove_port = efx_mcdi_port_remove,
5453 .fini_dmaq = efx_ef10_fini_dmaq,
5454 .prepare_flr = efx_ef10_prepare_flr,
5455 .finish_flr = efx_port_dummy_op_void,
5456 .describe_stats = efx_ef10_describe_stats,
5457 .update_stats = efx_ef10_update_stats_pf,
5458 .start_stats = efx_mcdi_mac_start_stats,
5459 .pull_stats = efx_mcdi_mac_pull_stats,
5460 .stop_stats = efx_mcdi_mac_stop_stats,
5461 .set_id_led = efx_mcdi_set_id_led,
5462 .push_irq_moderation = efx_ef10_push_irq_moderation,
5463 .reconfigure_mac = efx_ef10_mac_reconfigure,
5464 .check_mac_fault = efx_mcdi_mac_check_fault,
5465 .reconfigure_port = efx_mcdi_port_reconfigure,
5466 .get_wol = efx_ef10_get_wol,
5467 .set_wol = efx_ef10_set_wol,
5468 .resume_wol = efx_port_dummy_op_void,
5469 .test_chip = efx_ef10_test_chip,
5470 .test_nvram = efx_mcdi_nvram_test_all,
5471 .mcdi_request = efx_ef10_mcdi_request,
5472 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
5473 .mcdi_read_response = efx_ef10_mcdi_read_response,
5474 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
5475 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
5476 .irq_enable_master = efx_port_dummy_op_void,
5477 .irq_test_generate = efx_ef10_irq_test_generate,
5478 .irq_disable_non_ev = efx_port_dummy_op_void,
5479 .irq_handle_msi = efx_ef10_msi_interrupt,
5480 .irq_handle_legacy = efx_ef10_legacy_interrupt,
5481 .tx_probe = efx_ef10_tx_probe,
5482 .tx_init = efx_ef10_tx_init,
5483 .tx_remove = efx_ef10_tx_remove,
5484 .tx_write = efx_ef10_tx_write,
5485 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
5486 .rx_probe = efx_ef10_rx_probe,
5487 .rx_init = efx_ef10_rx_init,
5488 .rx_remove = efx_ef10_rx_remove,
5489 .rx_write = efx_ef10_rx_write,
5490 .rx_defer_refill = efx_ef10_rx_defer_refill,
5491 .ev_probe = efx_ef10_ev_probe,
5492 .ev_init = efx_ef10_ev_init,
5493 .ev_fini = efx_ef10_ev_fini,
5494 .ev_remove = efx_ef10_ev_remove,
5495 .ev_process = efx_ef10_ev_process,
5496 .ev_read_ack = efx_ef10_ev_read_ack,
5497 .ev_test_generate = efx_ef10_ev_test_generate,
5498 .filter_table_probe = efx_ef10_filter_table_probe,
5499 .filter_table_restore = efx_ef10_filter_table_restore,
5500 .filter_table_remove = efx_ef10_filter_table_remove,
5501 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
5502 .filter_insert = efx_ef10_filter_insert,
5503 .filter_remove_safe = efx_ef10_filter_remove_safe,
5504 .filter_get_safe = efx_ef10_filter_get_safe,
5505 .filter_clear_rx = efx_ef10_filter_clear_rx,
5506 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
5507 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
5508 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
5509 #ifdef CONFIG_RFS_ACCEL
5510 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
5511 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
5513 #ifdef CONFIG_SFC_MTD
5514 .mtd_probe = efx_ef10_mtd_probe,
5515 .mtd_rename = efx_mcdi_mtd_rename,
5516 .mtd_read = efx_mcdi_mtd_read,
5517 .mtd_erase = efx_mcdi_mtd_erase,
5518 .mtd_write = efx_mcdi_mtd_write,
5519 .mtd_sync = efx_mcdi_mtd_sync,
5521 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
5522 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
5523 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
5524 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
5525 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
5526 #ifdef CONFIG_SFC_SRIOV
5527 .sriov_configure = efx_ef10_sriov_configure,
5528 .sriov_init = efx_ef10_sriov_init,
5529 .sriov_fini = efx_ef10_sriov_fini,
5530 .sriov_wanted = efx_ef10_sriov_wanted,
5531 .sriov_reset = efx_ef10_sriov_reset,
5532 .sriov_flr = efx_ef10_sriov_flr,
5533 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
5534 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
5535 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
5536 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
5537 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
5538 .vswitching_probe = efx_ef10_vswitching_probe_pf,
5539 .vswitching_restore = efx_ef10_vswitching_restore_pf,
5540 .vswitching_remove = efx_ef10_vswitching_remove_pf,
5542 .get_mac_address = efx_ef10_get_mac_address_pf,
5543 .set_mac_address = efx_ef10_set_mac_address,
5545 .revision = EFX_REV_HUNT_A0,
5546 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
5547 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
5548 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
5549 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
5550 .can_rx_scatter = true,
5551 .always_rx_scatter = true,
5552 .max_interrupt_mode = EFX_INT_MODE_MSIX,
5553 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
5554 .offload_features = EF10_OFFLOAD_FEATURES,
5556 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
5557 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
5558 1 << HWTSTAMP_FILTER_ALL,