xref: /linux/drivers/net/ethernet/sfc/siena/siena.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
136ff6393SMartin Habets // SPDX-License-Identifier: GPL-2.0-only
236ff6393SMartin Habets /****************************************************************************
336ff6393SMartin Habets  * Driver for Solarflare network controllers and boards
436ff6393SMartin Habets  * Copyright 2005-2006 Fen Systems Ltd.
536ff6393SMartin Habets  * Copyright 2006-2013 Solarflare Communications Inc.
636ff6393SMartin Habets  */
736ff6393SMartin Habets 
836ff6393SMartin Habets #include <linux/bitops.h>
936ff6393SMartin Habets #include <linux/delay.h>
1036ff6393SMartin Habets #include <linux/pci.h>
1136ff6393SMartin Habets #include <linux/module.h>
1236ff6393SMartin Habets #include <linux/slab.h>
1336ff6393SMartin Habets #include <linux/random.h>
1436ff6393SMartin Habets #include "net_driver.h"
1536ff6393SMartin Habets #include "bitfield.h"
1636ff6393SMartin Habets #include "efx.h"
1736ff6393SMartin Habets #include "efx_common.h"
1836ff6393SMartin Habets #include "nic.h"
1936ff6393SMartin Habets #include "farch_regs.h"
2036ff6393SMartin Habets #include "io.h"
2136ff6393SMartin Habets #include "workarounds.h"
2236ff6393SMartin Habets #include "mcdi.h"
2336ff6393SMartin Habets #include "mcdi_pcol.h"
2436ff6393SMartin Habets #include "mcdi_port.h"
2536ff6393SMartin Habets #include "mcdi_port_common.h"
2636ff6393SMartin Habets #include "selftest.h"
2736ff6393SMartin Habets #include "siena_sriov.h"
2836ff6393SMartin Habets #include "rx_common.h"
2936ff6393SMartin Habets 
3036ff6393SMartin Habets /* Hardware control for SFC9000 family including SFL9021 (aka Siena). */
3136ff6393SMartin Habets 
3236ff6393SMartin Habets static void siena_init_wol(struct efx_nic *efx);
3336ff6393SMartin Habets 
3436ff6393SMartin Habets 
siena_push_irq_moderation(struct efx_channel * channel)3536ff6393SMartin Habets static void siena_push_irq_moderation(struct efx_channel *channel)
3636ff6393SMartin Habets {
3736ff6393SMartin Habets 	struct efx_nic *efx = channel->efx;
3836ff6393SMartin Habets 	efx_dword_t timer_cmd;
3936ff6393SMartin Habets 
4036ff6393SMartin Habets 	if (channel->irq_moderation_us) {
4136ff6393SMartin Habets 		unsigned int ticks;
4236ff6393SMartin Habets 
4371ad88f6SMartin Habets 		ticks = efx_siena_usecs_to_ticks(efx, channel->irq_moderation_us);
4436ff6393SMartin Habets 		EFX_POPULATE_DWORD_2(timer_cmd,
4536ff6393SMartin Habets 				     FRF_CZ_TC_TIMER_MODE,
4636ff6393SMartin Habets 				     FFE_CZ_TIMER_MODE_INT_HLDOFF,
4736ff6393SMartin Habets 				     FRF_CZ_TC_TIMER_VAL,
4836ff6393SMartin Habets 				     ticks - 1);
4936ff6393SMartin Habets 	} else {
5036ff6393SMartin Habets 		EFX_POPULATE_DWORD_2(timer_cmd,
5136ff6393SMartin Habets 				     FRF_CZ_TC_TIMER_MODE,
5236ff6393SMartin Habets 				     FFE_CZ_TIMER_MODE_DIS,
5336ff6393SMartin Habets 				     FRF_CZ_TC_TIMER_VAL, 0);
5436ff6393SMartin Habets 	}
5536ff6393SMartin Habets 	efx_writed_page_locked(channel->efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
5636ff6393SMartin Habets 			       channel->channel);
5736ff6393SMartin Habets }
5836ff6393SMartin Habets 
efx_siena_prepare_flush(struct efx_nic * efx)59956f2d86SMartin Habets void efx_siena_prepare_flush(struct efx_nic *efx)
6036ff6393SMartin Habets {
6136ff6393SMartin Habets 	if (efx->fc_disable++ == 0)
624d49e5cdSMartin Habets 		efx_siena_mcdi_set_mac(efx);
6336ff6393SMartin Habets }
6436ff6393SMartin Habets 
siena_finish_flush(struct efx_nic * efx)6536ff6393SMartin Habets void siena_finish_flush(struct efx_nic *efx)
6636ff6393SMartin Habets {
6736ff6393SMartin Habets 	if (--efx->fc_disable == 0)
684d49e5cdSMartin Habets 		efx_siena_mcdi_set_mac(efx);
6936ff6393SMartin Habets }
7036ff6393SMartin Habets 
7136ff6393SMartin Habets static const struct efx_farch_register_test siena_register_tests[] = {
7236ff6393SMartin Habets 	{ FR_AZ_ADR_REGION,
7336ff6393SMartin Habets 	  EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
7436ff6393SMartin Habets 	{ FR_CZ_USR_EV_CFG,
7536ff6393SMartin Habets 	  EFX_OWORD32(0x000103FF, 0x00000000, 0x00000000, 0x00000000) },
7636ff6393SMartin Habets 	{ FR_AZ_RX_CFG,
7736ff6393SMartin Habets 	  EFX_OWORD32(0xFFFFFFFE, 0xFFFFFFFF, 0x0003FFFF, 0x00000000) },
7836ff6393SMartin Habets 	{ FR_AZ_TX_CFG,
7936ff6393SMartin Habets 	  EFX_OWORD32(0x7FFF0037, 0xFFFF8000, 0xFFFFFFFF, 0x03FFFFFF) },
8036ff6393SMartin Habets 	{ FR_AZ_TX_RESERVED,
8136ff6393SMartin Habets 	  EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
8236ff6393SMartin Habets 	{ FR_AZ_SRM_TX_DC_CFG,
8336ff6393SMartin Habets 	  EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
8436ff6393SMartin Habets 	{ FR_AZ_RX_DC_CFG,
8536ff6393SMartin Habets 	  EFX_OWORD32(0x00000003, 0x00000000, 0x00000000, 0x00000000) },
8636ff6393SMartin Habets 	{ FR_AZ_RX_DC_PF_WM,
8736ff6393SMartin Habets 	  EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
8836ff6393SMartin Habets 	{ FR_BZ_DP_CTRL,
8936ff6393SMartin Habets 	  EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
9036ff6393SMartin Habets 	{ FR_BZ_RX_RSS_TKEY,
9136ff6393SMartin Habets 	  EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
9236ff6393SMartin Habets 	{ FR_CZ_RX_RSS_IPV6_REG1,
9336ff6393SMartin Habets 	  EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
9436ff6393SMartin Habets 	{ FR_CZ_RX_RSS_IPV6_REG2,
9536ff6393SMartin Habets 	  EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
9636ff6393SMartin Habets 	{ FR_CZ_RX_RSS_IPV6_REG3,
9736ff6393SMartin Habets 	  EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0x00000007, 0x00000000) },
9836ff6393SMartin Habets };
9936ff6393SMartin Habets 
siena_test_chip(struct efx_nic * efx,struct efx_self_tests * tests)10036ff6393SMartin Habets static int siena_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
10136ff6393SMartin Habets {
10236ff6393SMartin Habets 	enum reset_type reset_method = RESET_TYPE_ALL;
10336ff6393SMartin Habets 	int rc, rc2;
10436ff6393SMartin Habets 
10571ad88f6SMartin Habets 	efx_siena_reset_down(efx, reset_method);
10636ff6393SMartin Habets 
10736ff6393SMartin Habets 	/* Reset the chip immediately so that it is completely
10836ff6393SMartin Habets 	 * quiescent regardless of what any VF driver does.
10936ff6393SMartin Habets 	 */
1104d49e5cdSMartin Habets 	rc = efx_siena_mcdi_reset(efx, reset_method);
11136ff6393SMartin Habets 	if (rc)
11236ff6393SMartin Habets 		goto out;
11336ff6393SMartin Habets 
11436ff6393SMartin Habets 	tests->registers =
11536ff6393SMartin Habets 		efx_farch_test_registers(efx, siena_register_tests,
11636ff6393SMartin Habets 					 ARRAY_SIZE(siena_register_tests))
11736ff6393SMartin Habets 		? -1 : 1;
11836ff6393SMartin Habets 
1194d49e5cdSMartin Habets 	rc = efx_siena_mcdi_reset(efx, reset_method);
12036ff6393SMartin Habets out:
12171ad88f6SMartin Habets 	rc2 = efx_siena_reset_up(efx, reset_method, rc == 0);
12236ff6393SMartin Habets 	return rc ? rc : rc2;
12336ff6393SMartin Habets }
12436ff6393SMartin Habets 
12536ff6393SMartin Habets /**************************************************************************
12636ff6393SMartin Habets  *
12736ff6393SMartin Habets  * PTP
12836ff6393SMartin Habets  *
12936ff6393SMartin Habets  **************************************************************************
13036ff6393SMartin Habets  */
13136ff6393SMartin Habets 
siena_ptp_write_host_time(struct efx_nic * efx,u32 host_time)13236ff6393SMartin Habets static void siena_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
13336ff6393SMartin Habets {
13436ff6393SMartin Habets 	_efx_writed(efx, cpu_to_le32(host_time),
13536ff6393SMartin Habets 		    FR_CZ_MC_TREG_SMEM + MC_SMEM_P0_PTP_TIME_OFST);
13636ff6393SMartin Habets }
13736ff6393SMartin Habets 
siena_ptp_set_ts_config(struct efx_nic * efx,struct kernel_hwtstamp_config * init)13836ff6393SMartin Habets static int siena_ptp_set_ts_config(struct efx_nic *efx,
139*d82afc80SAlex Austin 				   struct kernel_hwtstamp_config *init)
14036ff6393SMartin Habets {
14136ff6393SMartin Habets 	int rc;
14236ff6393SMartin Habets 
14336ff6393SMartin Habets 	switch (init->rx_filter) {
14436ff6393SMartin Habets 	case HWTSTAMP_FILTER_NONE:
14536ff6393SMartin Habets 		/* if TX timestamping is still requested then leave PTP on */
14695e96f77SMartin Habets 		return efx_siena_ptp_change_mode(efx,
14736ff6393SMartin Habets 					init->tx_type != HWTSTAMP_TX_OFF,
14895e96f77SMartin Habets 					efx_siena_ptp_get_mode(efx));
14936ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
15036ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
15136ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
15236ff6393SMartin Habets 		init->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
15395e96f77SMartin Habets 		return efx_siena_ptp_change_mode(efx, true, MC_CMD_PTP_MODE_V1);
15436ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
15536ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
15636ff6393SMartin Habets 	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
15736ff6393SMartin Habets 		init->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
15895e96f77SMartin Habets 		rc = efx_siena_ptp_change_mode(efx, true,
15936ff6393SMartin Habets 					       MC_CMD_PTP_MODE_V2_ENHANCED);
16036ff6393SMartin Habets 		/* bug 33070 - old versions of the firmware do not support the
16136ff6393SMartin Habets 		 * improved UUID filtering option. Similarly old versions of the
16236ff6393SMartin Habets 		 * application do not expect it to be enabled. If the firmware
16336ff6393SMartin Habets 		 * does not accept the enhanced mode, fall back to the standard
16436ff6393SMartin Habets 		 * PTP v2 UUID filtering. */
16536ff6393SMartin Habets 		if (rc != 0)
16695e96f77SMartin Habets 			rc = efx_siena_ptp_change_mode(efx, true,
16795e96f77SMartin Habets 						       MC_CMD_PTP_MODE_V2);
16836ff6393SMartin Habets 		return rc;
16936ff6393SMartin Habets 	default:
17036ff6393SMartin Habets 		return -ERANGE;
17136ff6393SMartin Habets 	}
17236ff6393SMartin Habets }
17336ff6393SMartin Habets 
17436ff6393SMartin Habets /**************************************************************************
17536ff6393SMartin Habets  *
17636ff6393SMartin Habets  * Device reset
17736ff6393SMartin Habets  *
17836ff6393SMartin Habets  **************************************************************************
17936ff6393SMartin Habets  */
18036ff6393SMartin Habets 
siena_map_reset_flags(u32 * flags)18136ff6393SMartin Habets static int siena_map_reset_flags(u32 *flags)
18236ff6393SMartin Habets {
18336ff6393SMartin Habets 	enum {
18436ff6393SMartin Habets 		SIENA_RESET_PORT = (ETH_RESET_DMA | ETH_RESET_FILTER |
18536ff6393SMartin Habets 				    ETH_RESET_OFFLOAD | ETH_RESET_MAC |
18636ff6393SMartin Habets 				    ETH_RESET_PHY),
18736ff6393SMartin Habets 		SIENA_RESET_MC = (SIENA_RESET_PORT |
18836ff6393SMartin Habets 				  ETH_RESET_MGMT << ETH_RESET_SHARED_SHIFT),
18936ff6393SMartin Habets 	};
19036ff6393SMartin Habets 
19136ff6393SMartin Habets 	if ((*flags & SIENA_RESET_MC) == SIENA_RESET_MC) {
19236ff6393SMartin Habets 		*flags &= ~SIENA_RESET_MC;
19336ff6393SMartin Habets 		return RESET_TYPE_WORLD;
19436ff6393SMartin Habets 	}
19536ff6393SMartin Habets 
19636ff6393SMartin Habets 	if ((*flags & SIENA_RESET_PORT) == SIENA_RESET_PORT) {
19736ff6393SMartin Habets 		*flags &= ~SIENA_RESET_PORT;
19836ff6393SMartin Habets 		return RESET_TYPE_ALL;
19936ff6393SMartin Habets 	}
20036ff6393SMartin Habets 
20136ff6393SMartin Habets 	/* no invisible reset implemented */
20236ff6393SMartin Habets 
20336ff6393SMartin Habets 	return -EINVAL;
20436ff6393SMartin Habets }
20536ff6393SMartin Habets 
20636ff6393SMartin Habets #ifdef CONFIG_EEH
20736ff6393SMartin Habets /* When a PCI device is isolated from the bus, a subsequent MMIO read is
20836ff6393SMartin Habets  * required for the kernel EEH mechanisms to notice. As the Solarflare driver
20936ff6393SMartin Habets  * was written to minimise MMIO read (for latency) then a periodic call to check
21036ff6393SMartin Habets  * the EEH status of the device is required so that device recovery can happen
21136ff6393SMartin Habets  * in a timely fashion.
21236ff6393SMartin Habets  */
siena_monitor(struct efx_nic * efx)21336ff6393SMartin Habets static void siena_monitor(struct efx_nic *efx)
21436ff6393SMartin Habets {
21536ff6393SMartin Habets 	struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
21636ff6393SMartin Habets 
21736ff6393SMartin Habets 	eeh_dev_check_failure(eehdev);
21836ff6393SMartin Habets }
21936ff6393SMartin Habets #endif
22036ff6393SMartin Habets 
siena_probe_nvconfig(struct efx_nic * efx)22136ff6393SMartin Habets static int siena_probe_nvconfig(struct efx_nic *efx)
22236ff6393SMartin Habets {
22336ff6393SMartin Habets 	u32 caps = 0;
22436ff6393SMartin Habets 	int rc;
22536ff6393SMartin Habets 
2264d49e5cdSMartin Habets 	rc = efx_siena_mcdi_get_board_cfg(efx, efx->net_dev->perm_addr, NULL,
2274d49e5cdSMartin Habets 					  &caps);
22836ff6393SMartin Habets 
22936ff6393SMartin Habets 	efx->timer_quantum_ns =
23036ff6393SMartin Habets 		(caps & (1 << MC_CMD_CAPABILITIES_TURBO_ACTIVE_LBN)) ?
23136ff6393SMartin Habets 		3072 : 6144; /* 768 cycles */
23236ff6393SMartin Habets 	efx->timer_max_ns = efx->type->timer_period_max *
23336ff6393SMartin Habets 			    efx->timer_quantum_ns;
23436ff6393SMartin Habets 
23536ff6393SMartin Habets 	return rc;
23636ff6393SMartin Habets }
23736ff6393SMartin Habets 
siena_dimension_resources(struct efx_nic * efx)23836ff6393SMartin Habets static int siena_dimension_resources(struct efx_nic *efx)
23936ff6393SMartin Habets {
24036ff6393SMartin Habets 	/* Each port has a small block of internal SRAM dedicated to
24136ff6393SMartin Habets 	 * the buffer table and descriptor caches.  In theory we can
24236ff6393SMartin Habets 	 * map both blocks to one port, but we don't.
24336ff6393SMartin Habets 	 */
24436ff6393SMartin Habets 	efx_farch_dimension_resources(efx, FR_CZ_BUF_FULL_TBL_ROWS / 2);
24536ff6393SMartin Habets 	return 0;
24636ff6393SMartin Habets }
24736ff6393SMartin Habets 
24836ff6393SMartin Habets /* On all Falcon-architecture NICs, PFs use BAR 0 for I/O space and BAR 2(&3)
24936ff6393SMartin Habets  * for memory.
25036ff6393SMartin Habets  */
siena_mem_bar(struct efx_nic * efx)25136ff6393SMartin Habets static unsigned int siena_mem_bar(struct efx_nic *efx)
25236ff6393SMartin Habets {
25336ff6393SMartin Habets 	return 2;
25436ff6393SMartin Habets }
25536ff6393SMartin Habets 
siena_mem_map_size(struct efx_nic * efx)25636ff6393SMartin Habets static unsigned int siena_mem_map_size(struct efx_nic *efx)
25736ff6393SMartin Habets {
25836ff6393SMartin Habets 	return FR_CZ_MC_TREG_SMEM +
25936ff6393SMartin Habets 		FR_CZ_MC_TREG_SMEM_STEP * FR_CZ_MC_TREG_SMEM_ROWS;
26036ff6393SMartin Habets }
26136ff6393SMartin Habets 
siena_probe_nic(struct efx_nic * efx)26236ff6393SMartin Habets static int siena_probe_nic(struct efx_nic *efx)
26336ff6393SMartin Habets {
26436ff6393SMartin Habets 	struct siena_nic_data *nic_data;
26536ff6393SMartin Habets 	efx_oword_t reg;
26636ff6393SMartin Habets 	int rc;
26736ff6393SMartin Habets 
26836ff6393SMartin Habets 	/* Allocate storage for hardware specific data */
26936ff6393SMartin Habets 	nic_data = kzalloc(sizeof(struct siena_nic_data), GFP_KERNEL);
27036ff6393SMartin Habets 	if (!nic_data)
27136ff6393SMartin Habets 		return -ENOMEM;
27236ff6393SMartin Habets 	nic_data->efx = efx;
27336ff6393SMartin Habets 	efx->nic_data = nic_data;
27436ff6393SMartin Habets 
27536ff6393SMartin Habets 	if (efx_farch_fpga_ver(efx) != 0) {
27636ff6393SMartin Habets 		netif_err(efx, probe, efx->net_dev,
27736ff6393SMartin Habets 			  "Siena FPGA not supported\n");
27836ff6393SMartin Habets 		rc = -ENODEV;
27936ff6393SMartin Habets 		goto fail1;
28036ff6393SMartin Habets 	}
28136ff6393SMartin Habets 
28236ff6393SMartin Habets 	efx->max_channels = EFX_MAX_CHANNELS;
28336ff6393SMartin Habets 	efx->max_vis = EFX_MAX_CHANNELS;
28436ff6393SMartin Habets 	efx->max_tx_channels = EFX_MAX_CHANNELS;
28536ff6393SMartin Habets 	efx->tx_queues_per_channel = 4;
28636ff6393SMartin Habets 
28736ff6393SMartin Habets 	efx_reado(efx, &reg, FR_AZ_CS_DEBUG);
28836ff6393SMartin Habets 	efx->port_num = EFX_OWORD_FIELD(reg, FRF_CZ_CS_PORT_NUM) - 1;
28936ff6393SMartin Habets 
2904d49e5cdSMartin Habets 	rc = efx_siena_mcdi_init(efx);
29136ff6393SMartin Habets 	if (rc)
29236ff6393SMartin Habets 		goto fail1;
29336ff6393SMartin Habets 
29436ff6393SMartin Habets 	/* Now we can reset the NIC */
2954d49e5cdSMartin Habets 	rc = efx_siena_mcdi_reset(efx, RESET_TYPE_ALL);
29636ff6393SMartin Habets 	if (rc) {
29736ff6393SMartin Habets 		netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
29836ff6393SMartin Habets 		goto fail3;
29936ff6393SMartin Habets 	}
30036ff6393SMartin Habets 
30136ff6393SMartin Habets 	siena_init_wol(efx);
30236ff6393SMartin Habets 
30336ff6393SMartin Habets 	/* Allocate memory for INT_KER */
304c8443b69SMartin Habets 	rc = efx_siena_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t),
30536ff6393SMartin Habets 				    GFP_KERNEL);
30636ff6393SMartin Habets 	if (rc)
30736ff6393SMartin Habets 		goto fail4;
30836ff6393SMartin Habets 	BUG_ON(efx->irq_status.dma_addr & 0x0f);
30936ff6393SMartin Habets 
31036ff6393SMartin Habets 	netif_dbg(efx, probe, efx->net_dev,
31136ff6393SMartin Habets 		  "INT_KER at %llx (virt %p phys %llx)\n",
31236ff6393SMartin Habets 		  (unsigned long long)efx->irq_status.dma_addr,
31336ff6393SMartin Habets 		  efx->irq_status.addr,
31436ff6393SMartin Habets 		  (unsigned long long)virt_to_phys(efx->irq_status.addr));
31536ff6393SMartin Habets 
31636ff6393SMartin Habets 	/* Read in the non-volatile configuration */
31736ff6393SMartin Habets 	rc = siena_probe_nvconfig(efx);
31836ff6393SMartin Habets 	if (rc == -EINVAL) {
31936ff6393SMartin Habets 		netif_err(efx, probe, efx->net_dev,
32036ff6393SMartin Habets 			  "NVRAM is invalid therefore using defaults\n");
32136ff6393SMartin Habets 		efx->phy_type = PHY_TYPE_NONE;
32236ff6393SMartin Habets 		efx->mdio.prtad = MDIO_PRTAD_NONE;
32336ff6393SMartin Habets 	} else if (rc) {
32436ff6393SMartin Habets 		goto fail5;
32536ff6393SMartin Habets 	}
32636ff6393SMartin Habets 
3274d49e5cdSMartin Habets 	rc = efx_siena_mcdi_mon_probe(efx);
32836ff6393SMartin Habets 	if (rc)
32936ff6393SMartin Habets 		goto fail5;
33036ff6393SMartin Habets 
331dfb1cfbdSMartin Habets #ifdef CONFIG_SFC_SIENA_SRIOV
33236ff6393SMartin Habets 	efx_siena_sriov_probe(efx);
33336ff6393SMartin Habets #endif
33495e96f77SMartin Habets 	efx_siena_ptp_defer_probe_with_channel(efx);
33536ff6393SMartin Habets 
33636ff6393SMartin Habets 	return 0;
33736ff6393SMartin Habets 
33836ff6393SMartin Habets fail5:
339c8443b69SMartin Habets 	efx_siena_free_buffer(efx, &efx->irq_status);
34036ff6393SMartin Habets fail4:
34136ff6393SMartin Habets fail3:
3424d49e5cdSMartin Habets 	efx_siena_mcdi_detach(efx);
3434d49e5cdSMartin Habets 	efx_siena_mcdi_fini(efx);
34436ff6393SMartin Habets fail1:
34536ff6393SMartin Habets 	kfree(efx->nic_data);
34636ff6393SMartin Habets 	return rc;
34736ff6393SMartin Habets }
34836ff6393SMartin Habets 
siena_rx_pull_rss_config(struct efx_nic * efx)34936ff6393SMartin Habets static int siena_rx_pull_rss_config(struct efx_nic *efx)
35036ff6393SMartin Habets {
35136ff6393SMartin Habets 	efx_oword_t temp;
35236ff6393SMartin Habets 
35336ff6393SMartin Habets 	/* Read from IPv6 RSS key as that's longer (the IPv4 key is just the
35436ff6393SMartin Habets 	 * first 128 bits of the same key, assuming it's been set by
35536ff6393SMartin Habets 	 * siena_rx_push_rss_config, below)
35636ff6393SMartin Habets 	 */
35736ff6393SMartin Habets 	efx_reado(efx, &temp, FR_CZ_RX_RSS_IPV6_REG1);
35836ff6393SMartin Habets 	memcpy(efx->rss_context.rx_hash_key, &temp, sizeof(temp));
35936ff6393SMartin Habets 	efx_reado(efx, &temp, FR_CZ_RX_RSS_IPV6_REG2);
36036ff6393SMartin Habets 	memcpy(efx->rss_context.rx_hash_key + sizeof(temp), &temp, sizeof(temp));
36136ff6393SMartin Habets 	efx_reado(efx, &temp, FR_CZ_RX_RSS_IPV6_REG3);
36236ff6393SMartin Habets 	memcpy(efx->rss_context.rx_hash_key + 2 * sizeof(temp), &temp,
36336ff6393SMartin Habets 	       FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8);
36436ff6393SMartin Habets 	efx_farch_rx_pull_indir_table(efx);
36536ff6393SMartin Habets 	return 0;
36636ff6393SMartin Habets }
36736ff6393SMartin Habets 
siena_rx_push_rss_config(struct efx_nic * efx,bool user,const u32 * rx_indir_table,const u8 * key)36836ff6393SMartin Habets static int siena_rx_push_rss_config(struct efx_nic *efx, bool user,
36936ff6393SMartin Habets 				    const u32 *rx_indir_table, const u8 *key)
37036ff6393SMartin Habets {
37136ff6393SMartin Habets 	efx_oword_t temp;
37236ff6393SMartin Habets 
37336ff6393SMartin Habets 	/* Set hash key for IPv4 */
37436ff6393SMartin Habets 	if (key)
37536ff6393SMartin Habets 		memcpy(efx->rss_context.rx_hash_key, key, sizeof(temp));
37636ff6393SMartin Habets 	memcpy(&temp, efx->rss_context.rx_hash_key, sizeof(temp));
37736ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
37836ff6393SMartin Habets 
37936ff6393SMartin Habets 	/* Enable IPv6 RSS */
38036ff6393SMartin Habets 	BUILD_BUG_ON(sizeof(efx->rss_context.rx_hash_key) <
38136ff6393SMartin Habets 		     2 * sizeof(temp) + FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8 ||
38236ff6393SMartin Habets 		     FRF_CZ_RX_RSS_IPV6_TKEY_HI_LBN != 0);
38336ff6393SMartin Habets 	memcpy(&temp, efx->rss_context.rx_hash_key, sizeof(temp));
38436ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG1);
38536ff6393SMartin Habets 	memcpy(&temp, efx->rss_context.rx_hash_key + sizeof(temp), sizeof(temp));
38636ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG2);
38736ff6393SMartin Habets 	EFX_POPULATE_OWORD_2(temp, FRF_CZ_RX_RSS_IPV6_THASH_ENABLE, 1,
38836ff6393SMartin Habets 			     FRF_CZ_RX_RSS_IPV6_IP_THASH_ENABLE, 1);
38936ff6393SMartin Habets 	memcpy(&temp, efx->rss_context.rx_hash_key + 2 * sizeof(temp),
39036ff6393SMartin Habets 	       FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8);
39136ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG3);
39236ff6393SMartin Habets 
39336ff6393SMartin Habets 	memcpy(efx->rss_context.rx_indir_table, rx_indir_table,
39436ff6393SMartin Habets 	       sizeof(efx->rss_context.rx_indir_table));
39536ff6393SMartin Habets 	efx_farch_rx_push_indir_table(efx);
39636ff6393SMartin Habets 
39736ff6393SMartin Habets 	return 0;
39836ff6393SMartin Habets }
39936ff6393SMartin Habets 
40036ff6393SMartin Habets /* This call performs hardware-specific global initialisation, such as
40136ff6393SMartin Habets  * defining the descriptor cache sizes and number of RSS channels.
40236ff6393SMartin Habets  * It does not set up any buffers, descriptor rings or event queues.
40336ff6393SMartin Habets  */
siena_init_nic(struct efx_nic * efx)40436ff6393SMartin Habets static int siena_init_nic(struct efx_nic *efx)
40536ff6393SMartin Habets {
40636ff6393SMartin Habets 	efx_oword_t temp;
40736ff6393SMartin Habets 	int rc;
40836ff6393SMartin Habets 
40936ff6393SMartin Habets 	/* Recover from a failed assertion post-reset */
4104d49e5cdSMartin Habets 	rc = efx_siena_mcdi_handle_assertion(efx);
41136ff6393SMartin Habets 	if (rc)
41236ff6393SMartin Habets 		return rc;
41336ff6393SMartin Habets 
41436ff6393SMartin Habets 	/* Squash TX of packets of 16 bytes or less */
41536ff6393SMartin Habets 	efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
41636ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
41736ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
41836ff6393SMartin Habets 
41936ff6393SMartin Habets 	/* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
42036ff6393SMartin Habets 	 * descriptors (which is bad).
42136ff6393SMartin Habets 	 */
42236ff6393SMartin Habets 	efx_reado(efx, &temp, FR_AZ_TX_CFG);
42336ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
42436ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_CZ_TX_FILTER_EN_BIT, 1);
42536ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_AZ_TX_CFG);
42636ff6393SMartin Habets 
42736ff6393SMartin Habets 	efx_reado(efx, &temp, FR_AZ_RX_CFG);
42836ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_DESC_PUSH_EN, 0);
42936ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_INGR_EN, 1);
43036ff6393SMartin Habets 	/* Enable hash insertion. This is broken for the 'Falcon' hash
43136ff6393SMartin Habets 	 * if IPv6 hashing is also enabled, so also select Toeplitz
43236ff6393SMartin Habets 	 * TCP/IPv4 and IPv4 hashes. */
43336ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_HASH_INSRT_HDR, 1);
43436ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_HASH_ALG, 1);
43536ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_IP_HASH, 1);
43636ff6393SMartin Habets 	EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_USR_BUF_SIZE,
43736ff6393SMartin Habets 			    EFX_RX_USR_BUF_SIZE >> 5);
43836ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_AZ_RX_CFG);
43936ff6393SMartin Habets 
44036ff6393SMartin Habets 	siena_rx_push_rss_config(efx, false, efx->rss_context.rx_indir_table, NULL);
44136ff6393SMartin Habets 	efx->rss_context.context_id = 0; /* indicates RSS is active */
44236ff6393SMartin Habets 
44336ff6393SMartin Habets 	/* Enable event logging */
4444d49e5cdSMartin Habets 	rc = efx_siena_mcdi_log_ctrl(efx, true, false, 0);
44536ff6393SMartin Habets 	if (rc)
44636ff6393SMartin Habets 		return rc;
44736ff6393SMartin Habets 
44836ff6393SMartin Habets 	/* Set destination of both TX and RX Flush events */
44936ff6393SMartin Habets 	EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
45036ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
45136ff6393SMartin Habets 
45236ff6393SMartin Habets 	EFX_POPULATE_OWORD_1(temp, FRF_CZ_USREV_DIS, 1);
45336ff6393SMartin Habets 	efx_writeo(efx, &temp, FR_CZ_USR_EV_CFG);
45436ff6393SMartin Habets 
45536ff6393SMartin Habets 	efx_farch_init_common(efx);
45636ff6393SMartin Habets 	return 0;
45736ff6393SMartin Habets }
45836ff6393SMartin Habets 
siena_remove_nic(struct efx_nic * efx)45936ff6393SMartin Habets static void siena_remove_nic(struct efx_nic *efx)
46036ff6393SMartin Habets {
4614d49e5cdSMartin Habets 	efx_siena_mcdi_mon_remove(efx);
46236ff6393SMartin Habets 
463c8443b69SMartin Habets 	efx_siena_free_buffer(efx, &efx->irq_status);
46436ff6393SMartin Habets 
4654d49e5cdSMartin Habets 	efx_siena_mcdi_reset(efx, RESET_TYPE_ALL);
46636ff6393SMartin Habets 
4674d49e5cdSMartin Habets 	efx_siena_mcdi_detach(efx);
4684d49e5cdSMartin Habets 	efx_siena_mcdi_fini(efx);
46936ff6393SMartin Habets 
47036ff6393SMartin Habets 	/* Tear down the private nic state */
47136ff6393SMartin Habets 	kfree(efx->nic_data);
47236ff6393SMartin Habets 	efx->nic_data = NULL;
47336ff6393SMartin Habets }
47436ff6393SMartin Habets 
47536ff6393SMartin Habets #define SIENA_DMA_STAT(ext_name, mcdi_name)			\
47636ff6393SMartin Habets 	[SIENA_STAT_ ## ext_name] =				\
47736ff6393SMartin Habets 	{ #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
47836ff6393SMartin Habets #define SIENA_OTHER_STAT(ext_name)				\
47936ff6393SMartin Habets 	[SIENA_STAT_ ## ext_name] = { #ext_name, 0, 0 }
48036ff6393SMartin Habets #define GENERIC_SW_STAT(ext_name)				\
48136ff6393SMartin Habets 	[GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
48236ff6393SMartin Habets 
48336ff6393SMartin Habets static const struct efx_hw_stat_desc siena_stat_desc[SIENA_STAT_COUNT] = {
48436ff6393SMartin Habets 	SIENA_DMA_STAT(tx_bytes, TX_BYTES),
48536ff6393SMartin Habets 	SIENA_OTHER_STAT(tx_good_bytes),
48636ff6393SMartin Habets 	SIENA_DMA_STAT(tx_bad_bytes, TX_BAD_BYTES),
48736ff6393SMartin Habets 	SIENA_DMA_STAT(tx_packets, TX_PKTS),
48836ff6393SMartin Habets 	SIENA_DMA_STAT(tx_bad, TX_BAD_FCS_PKTS),
48936ff6393SMartin Habets 	SIENA_DMA_STAT(tx_pause, TX_PAUSE_PKTS),
49036ff6393SMartin Habets 	SIENA_DMA_STAT(tx_control, TX_CONTROL_PKTS),
49136ff6393SMartin Habets 	SIENA_DMA_STAT(tx_unicast, TX_UNICAST_PKTS),
49236ff6393SMartin Habets 	SIENA_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS),
49336ff6393SMartin Habets 	SIENA_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS),
49436ff6393SMartin Habets 	SIENA_DMA_STAT(tx_lt64, TX_LT64_PKTS),
49536ff6393SMartin Habets 	SIENA_DMA_STAT(tx_64, TX_64_PKTS),
49636ff6393SMartin Habets 	SIENA_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS),
49736ff6393SMartin Habets 	SIENA_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS),
49836ff6393SMartin Habets 	SIENA_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS),
49936ff6393SMartin Habets 	SIENA_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS),
50036ff6393SMartin Habets 	SIENA_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
50136ff6393SMartin Habets 	SIENA_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
50236ff6393SMartin Habets 	SIENA_DMA_STAT(tx_gtjumbo, TX_GTJUMBO_PKTS),
50336ff6393SMartin Habets 	SIENA_OTHER_STAT(tx_collision),
50436ff6393SMartin Habets 	SIENA_DMA_STAT(tx_single_collision, TX_SINGLE_COLLISION_PKTS),
50536ff6393SMartin Habets 	SIENA_DMA_STAT(tx_multiple_collision, TX_MULTIPLE_COLLISION_PKTS),
50636ff6393SMartin Habets 	SIENA_DMA_STAT(tx_excessive_collision, TX_EXCESSIVE_COLLISION_PKTS),
50736ff6393SMartin Habets 	SIENA_DMA_STAT(tx_deferred, TX_DEFERRED_PKTS),
50836ff6393SMartin Habets 	SIENA_DMA_STAT(tx_late_collision, TX_LATE_COLLISION_PKTS),
50936ff6393SMartin Habets 	SIENA_DMA_STAT(tx_excessive_deferred, TX_EXCESSIVE_DEFERRED_PKTS),
51036ff6393SMartin Habets 	SIENA_DMA_STAT(tx_non_tcpudp, TX_NON_TCPUDP_PKTS),
51136ff6393SMartin Habets 	SIENA_DMA_STAT(tx_mac_src_error, TX_MAC_SRC_ERR_PKTS),
51236ff6393SMartin Habets 	SIENA_DMA_STAT(tx_ip_src_error, TX_IP_SRC_ERR_PKTS),
51336ff6393SMartin Habets 	SIENA_DMA_STAT(rx_bytes, RX_BYTES),
51436ff6393SMartin Habets 	SIENA_OTHER_STAT(rx_good_bytes),
51536ff6393SMartin Habets 	SIENA_DMA_STAT(rx_bad_bytes, RX_BAD_BYTES),
51636ff6393SMartin Habets 	SIENA_DMA_STAT(rx_packets, RX_PKTS),
51736ff6393SMartin Habets 	SIENA_DMA_STAT(rx_good, RX_GOOD_PKTS),
51836ff6393SMartin Habets 	SIENA_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS),
51936ff6393SMartin Habets 	SIENA_DMA_STAT(rx_pause, RX_PAUSE_PKTS),
52036ff6393SMartin Habets 	SIENA_DMA_STAT(rx_control, RX_CONTROL_PKTS),
52136ff6393SMartin Habets 	SIENA_DMA_STAT(rx_unicast, RX_UNICAST_PKTS),
52236ff6393SMartin Habets 	SIENA_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS),
52336ff6393SMartin Habets 	SIENA_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS),
52436ff6393SMartin Habets 	SIENA_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS),
52536ff6393SMartin Habets 	SIENA_DMA_STAT(rx_64, RX_64_PKTS),
52636ff6393SMartin Habets 	SIENA_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS),
52736ff6393SMartin Habets 	SIENA_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS),
52836ff6393SMartin Habets 	SIENA_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS),
52936ff6393SMartin Habets 	SIENA_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS),
53036ff6393SMartin Habets 	SIENA_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
53136ff6393SMartin Habets 	SIENA_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
53236ff6393SMartin Habets 	SIENA_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS),
53336ff6393SMartin Habets 	SIENA_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS),
53436ff6393SMartin Habets 	SIENA_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS),
53536ff6393SMartin Habets 	SIENA_DMA_STAT(rx_false_carrier, RX_FALSE_CARRIER_PKTS),
53636ff6393SMartin Habets 	SIENA_DMA_STAT(rx_symbol_error, RX_SYMBOL_ERROR_PKTS),
53736ff6393SMartin Habets 	SIENA_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
53836ff6393SMartin Habets 	SIENA_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
53936ff6393SMartin Habets 	SIENA_DMA_STAT(rx_internal_error, RX_INTERNAL_ERROR_PKTS),
54036ff6393SMartin Habets 	SIENA_DMA_STAT(rx_nodesc_drop_cnt, RX_NODESC_DROPS),
54136ff6393SMartin Habets 	GENERIC_SW_STAT(rx_nodesc_trunc),
54236ff6393SMartin Habets 	GENERIC_SW_STAT(rx_noskb_drops),
54336ff6393SMartin Habets };
54436ff6393SMartin Habets static const unsigned long siena_stat_mask[] = {
54536ff6393SMartin Habets 	[0 ... BITS_TO_LONGS(SIENA_STAT_COUNT) - 1] = ~0UL,
54636ff6393SMartin Habets };
54736ff6393SMartin Habets 
siena_describe_nic_stats(struct efx_nic * efx,u8 * names)54836ff6393SMartin Habets static size_t siena_describe_nic_stats(struct efx_nic *efx, u8 *names)
54936ff6393SMartin Habets {
550c8443b69SMartin Habets 	return efx_siena_describe_stats(siena_stat_desc, SIENA_STAT_COUNT,
55136ff6393SMartin Habets 					siena_stat_mask, names);
55236ff6393SMartin Habets }
55336ff6393SMartin Habets 
siena_try_update_nic_stats(struct efx_nic * efx)55436ff6393SMartin Habets static int siena_try_update_nic_stats(struct efx_nic *efx)
55536ff6393SMartin Habets {
55636ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
55736ff6393SMartin Habets 	u64 *stats = nic_data->stats;
55836ff6393SMartin Habets 	__le64 *dma_stats;
55936ff6393SMartin Habets 	__le64 generation_start, generation_end;
56036ff6393SMartin Habets 
56136ff6393SMartin Habets 	dma_stats = efx->stats_buffer.addr;
56236ff6393SMartin Habets 
56336ff6393SMartin Habets 	generation_end = dma_stats[efx->num_mac_stats - 1];
56436ff6393SMartin Habets 	if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
56536ff6393SMartin Habets 		return 0;
56636ff6393SMartin Habets 	rmb();
567c8443b69SMartin Habets 	efx_siena_update_stats(siena_stat_desc, SIENA_STAT_COUNT, siena_stat_mask,
56836ff6393SMartin Habets 			       stats, efx->stats_buffer.addr, false);
56936ff6393SMartin Habets 	rmb();
57036ff6393SMartin Habets 	generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
57136ff6393SMartin Habets 	if (generation_end != generation_start)
57236ff6393SMartin Habets 		return -EAGAIN;
57336ff6393SMartin Habets 
57436ff6393SMartin Habets 	/* Update derived statistics */
575c8443b69SMartin Habets 	efx_siena_fix_nodesc_drop_stat(efx,
57636ff6393SMartin Habets 				       &stats[SIENA_STAT_rx_nodesc_drop_cnt]);
57736ff6393SMartin Habets 	efx_update_diff_stat(&stats[SIENA_STAT_tx_good_bytes],
57836ff6393SMartin Habets 			     stats[SIENA_STAT_tx_bytes] -
57936ff6393SMartin Habets 			     stats[SIENA_STAT_tx_bad_bytes]);
58036ff6393SMartin Habets 	stats[SIENA_STAT_tx_collision] =
58136ff6393SMartin Habets 		stats[SIENA_STAT_tx_single_collision] +
58236ff6393SMartin Habets 		stats[SIENA_STAT_tx_multiple_collision] +
58336ff6393SMartin Habets 		stats[SIENA_STAT_tx_excessive_collision] +
58436ff6393SMartin Habets 		stats[SIENA_STAT_tx_late_collision];
58536ff6393SMartin Habets 	efx_update_diff_stat(&stats[SIENA_STAT_rx_good_bytes],
58636ff6393SMartin Habets 			     stats[SIENA_STAT_rx_bytes] -
58736ff6393SMartin Habets 			     stats[SIENA_STAT_rx_bad_bytes]);
58871ad88f6SMartin Habets 	efx_siena_update_sw_stats(efx, stats);
58936ff6393SMartin Habets 	return 0;
59036ff6393SMartin Habets }
59136ff6393SMartin Habets 
siena_update_nic_stats(struct efx_nic * efx,u64 * full_stats,struct rtnl_link_stats64 * core_stats)59236ff6393SMartin Habets static size_t siena_update_nic_stats(struct efx_nic *efx, u64 *full_stats,
59336ff6393SMartin Habets 				     struct rtnl_link_stats64 *core_stats)
59436ff6393SMartin Habets {
59536ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
59636ff6393SMartin Habets 	u64 *stats = nic_data->stats;
59736ff6393SMartin Habets 	int retry;
59836ff6393SMartin Habets 
59936ff6393SMartin Habets 	/* If we're unlucky enough to read statistics wduring the DMA, wait
60036ff6393SMartin Habets 	 * up to 10ms for it to finish (typically takes <500us) */
60136ff6393SMartin Habets 	for (retry = 0; retry < 100; ++retry) {
60236ff6393SMartin Habets 		if (siena_try_update_nic_stats(efx) == 0)
60336ff6393SMartin Habets 			break;
60436ff6393SMartin Habets 		udelay(100);
60536ff6393SMartin Habets 	}
60636ff6393SMartin Habets 
60736ff6393SMartin Habets 	if (full_stats)
60836ff6393SMartin Habets 		memcpy(full_stats, stats, sizeof(u64) * SIENA_STAT_COUNT);
60936ff6393SMartin Habets 
61036ff6393SMartin Habets 	if (core_stats) {
61136ff6393SMartin Habets 		core_stats->rx_packets = stats[SIENA_STAT_rx_packets];
61236ff6393SMartin Habets 		core_stats->tx_packets = stats[SIENA_STAT_tx_packets];
61336ff6393SMartin Habets 		core_stats->rx_bytes = stats[SIENA_STAT_rx_bytes];
61436ff6393SMartin Habets 		core_stats->tx_bytes = stats[SIENA_STAT_tx_bytes];
61536ff6393SMartin Habets 		core_stats->rx_dropped = stats[SIENA_STAT_rx_nodesc_drop_cnt] +
61636ff6393SMartin Habets 					 stats[GENERIC_STAT_rx_nodesc_trunc] +
61736ff6393SMartin Habets 					 stats[GENERIC_STAT_rx_noskb_drops];
61836ff6393SMartin Habets 		core_stats->multicast = stats[SIENA_STAT_rx_multicast];
61936ff6393SMartin Habets 		core_stats->collisions = stats[SIENA_STAT_tx_collision];
62036ff6393SMartin Habets 		core_stats->rx_length_errors =
62136ff6393SMartin Habets 			stats[SIENA_STAT_rx_gtjumbo] +
62236ff6393SMartin Habets 			stats[SIENA_STAT_rx_length_error];
62336ff6393SMartin Habets 		core_stats->rx_crc_errors = stats[SIENA_STAT_rx_bad];
62436ff6393SMartin Habets 		core_stats->rx_frame_errors = stats[SIENA_STAT_rx_align_error];
62536ff6393SMartin Habets 		core_stats->rx_fifo_errors = stats[SIENA_STAT_rx_overflow];
62636ff6393SMartin Habets 		core_stats->tx_window_errors =
62736ff6393SMartin Habets 			stats[SIENA_STAT_tx_late_collision];
62836ff6393SMartin Habets 
62936ff6393SMartin Habets 		core_stats->rx_errors = (core_stats->rx_length_errors +
63036ff6393SMartin Habets 					 core_stats->rx_crc_errors +
63136ff6393SMartin Habets 					 core_stats->rx_frame_errors +
63236ff6393SMartin Habets 					 stats[SIENA_STAT_rx_symbol_error]);
63336ff6393SMartin Habets 		core_stats->tx_errors = (core_stats->tx_window_errors +
63436ff6393SMartin Habets 					 stats[SIENA_STAT_tx_bad]);
63536ff6393SMartin Habets 	}
63636ff6393SMartin Habets 
63736ff6393SMartin Habets 	return SIENA_STAT_COUNT;
63836ff6393SMartin Habets }
63936ff6393SMartin Habets 
siena_mac_reconfigure(struct efx_nic * efx,bool mtu_only __always_unused)64036ff6393SMartin Habets static int siena_mac_reconfigure(struct efx_nic *efx, bool mtu_only __always_unused)
64136ff6393SMartin Habets {
64236ff6393SMartin Habets 	MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_MCAST_HASH_IN_LEN);
64336ff6393SMartin Habets 	int rc;
64436ff6393SMartin Habets 
64536ff6393SMartin Habets 	BUILD_BUG_ON(MC_CMD_SET_MCAST_HASH_IN_LEN !=
64636ff6393SMartin Habets 		     MC_CMD_SET_MCAST_HASH_IN_HASH0_OFST +
64736ff6393SMartin Habets 		     sizeof(efx->multicast_hash));
64836ff6393SMartin Habets 
64936ff6393SMartin Habets 	efx_farch_filter_sync_rx_mode(efx);
65036ff6393SMartin Habets 
65136ff6393SMartin Habets 	WARN_ON(!mutex_is_locked(&efx->mac_lock));
65236ff6393SMartin Habets 
6534d49e5cdSMartin Habets 	rc = efx_siena_mcdi_set_mac(efx);
65436ff6393SMartin Habets 	if (rc != 0)
65536ff6393SMartin Habets 		return rc;
65636ff6393SMartin Habets 
65736ff6393SMartin Habets 	memcpy(MCDI_PTR(inbuf, SET_MCAST_HASH_IN_HASH0),
65836ff6393SMartin Habets 	       efx->multicast_hash.byte, sizeof(efx->multicast_hash));
6594d49e5cdSMartin Habets 	return efx_siena_mcdi_rpc(efx, MC_CMD_SET_MCAST_HASH,
66036ff6393SMartin Habets 				  inbuf, sizeof(inbuf), NULL, 0, NULL);
66136ff6393SMartin Habets }
66236ff6393SMartin Habets 
66336ff6393SMartin Habets /**************************************************************************
66436ff6393SMartin Habets  *
66536ff6393SMartin Habets  * Wake on LAN
66636ff6393SMartin Habets  *
66736ff6393SMartin Habets  **************************************************************************
66836ff6393SMartin Habets  */
66936ff6393SMartin Habets 
siena_get_wol(struct efx_nic * efx,struct ethtool_wolinfo * wol)67036ff6393SMartin Habets static void siena_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
67136ff6393SMartin Habets {
67236ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
67336ff6393SMartin Habets 
67436ff6393SMartin Habets 	wol->supported = WAKE_MAGIC;
67536ff6393SMartin Habets 	if (nic_data->wol_filter_id != -1)
67636ff6393SMartin Habets 		wol->wolopts = WAKE_MAGIC;
67736ff6393SMartin Habets 	else
67836ff6393SMartin Habets 		wol->wolopts = 0;
67936ff6393SMartin Habets 	memset(&wol->sopass, 0, sizeof(wol->sopass));
68036ff6393SMartin Habets }
68136ff6393SMartin Habets 
68236ff6393SMartin Habets 
siena_set_wol(struct efx_nic * efx,u32 type)68336ff6393SMartin Habets static int siena_set_wol(struct efx_nic *efx, u32 type)
68436ff6393SMartin Habets {
68536ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
68636ff6393SMartin Habets 	int rc;
68736ff6393SMartin Habets 
68836ff6393SMartin Habets 	if (type & ~WAKE_MAGIC)
68936ff6393SMartin Habets 		return -EINVAL;
69036ff6393SMartin Habets 
69136ff6393SMartin Habets 	if (type & WAKE_MAGIC) {
69236ff6393SMartin Habets 		if (nic_data->wol_filter_id != -1)
6934d49e5cdSMartin Habets 			efx_siena_mcdi_wol_filter_remove(efx,
69436ff6393SMartin Habets 						nic_data->wol_filter_id);
6954d49e5cdSMartin Habets 		rc = efx_siena_mcdi_wol_filter_set_magic(efx,
6964d49e5cdSMartin Habets 						efx->net_dev->dev_addr,
69736ff6393SMartin Habets 						&nic_data->wol_filter_id);
69836ff6393SMartin Habets 		if (rc)
69936ff6393SMartin Habets 			goto fail;
70036ff6393SMartin Habets 
70136ff6393SMartin Habets 		pci_wake_from_d3(efx->pci_dev, true);
70236ff6393SMartin Habets 	} else {
7034d49e5cdSMartin Habets 		rc = efx_siena_mcdi_wol_filter_reset(efx);
70436ff6393SMartin Habets 		nic_data->wol_filter_id = -1;
70536ff6393SMartin Habets 		pci_wake_from_d3(efx->pci_dev, false);
70636ff6393SMartin Habets 		if (rc)
70736ff6393SMartin Habets 			goto fail;
70836ff6393SMartin Habets 	}
70936ff6393SMartin Habets 
71036ff6393SMartin Habets 	return 0;
71136ff6393SMartin Habets  fail:
71236ff6393SMartin Habets 	netif_err(efx, hw, efx->net_dev, "%s failed: type=%d rc=%d\n",
71336ff6393SMartin Habets 		  __func__, type, rc);
71436ff6393SMartin Habets 	return rc;
71536ff6393SMartin Habets }
71636ff6393SMartin Habets 
71736ff6393SMartin Habets 
siena_init_wol(struct efx_nic * efx)71836ff6393SMartin Habets static void siena_init_wol(struct efx_nic *efx)
71936ff6393SMartin Habets {
72036ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
72136ff6393SMartin Habets 	int rc;
72236ff6393SMartin Habets 
7234d49e5cdSMartin Habets 	rc = efx_siena_mcdi_wol_filter_get_magic(efx, &nic_data->wol_filter_id);
72436ff6393SMartin Habets 
72536ff6393SMartin Habets 	if (rc != 0) {
72636ff6393SMartin Habets 		/* If it failed, attempt to get into a synchronised
72736ff6393SMartin Habets 		 * state with MC by resetting any set WoL filters */
7284d49e5cdSMartin Habets 		efx_siena_mcdi_wol_filter_reset(efx);
72936ff6393SMartin Habets 		nic_data->wol_filter_id = -1;
73036ff6393SMartin Habets 	} else if (nic_data->wol_filter_id != -1) {
73136ff6393SMartin Habets 		pci_wake_from_d3(efx->pci_dev, true);
73236ff6393SMartin Habets 	}
73336ff6393SMartin Habets }
73436ff6393SMartin Habets 
73536ff6393SMartin Habets /**************************************************************************
73636ff6393SMartin Habets  *
73736ff6393SMartin Habets  * MCDI
73836ff6393SMartin Habets  *
73936ff6393SMartin Habets  **************************************************************************
74036ff6393SMartin Habets  */
74136ff6393SMartin Habets 
74236ff6393SMartin Habets #define MCDI_PDU(efx)							\
74336ff6393SMartin Habets 	(efx_port_num(efx) ? MC_SMEM_P1_PDU_OFST : MC_SMEM_P0_PDU_OFST)
74436ff6393SMartin Habets #define MCDI_DOORBELL(efx)						\
74536ff6393SMartin Habets 	(efx_port_num(efx) ? MC_SMEM_P1_DOORBELL_OFST : MC_SMEM_P0_DOORBELL_OFST)
74636ff6393SMartin Habets #define MCDI_STATUS(efx)						\
74736ff6393SMartin Habets 	(efx_port_num(efx) ? MC_SMEM_P1_STATUS_OFST : MC_SMEM_P0_STATUS_OFST)
74836ff6393SMartin Habets 
siena_mcdi_request(struct efx_nic * efx,const efx_dword_t * hdr,size_t hdr_len,const efx_dword_t * sdu,size_t sdu_len)74936ff6393SMartin Habets static void siena_mcdi_request(struct efx_nic *efx,
75036ff6393SMartin Habets 			       const efx_dword_t *hdr, size_t hdr_len,
75136ff6393SMartin Habets 			       const efx_dword_t *sdu, size_t sdu_len)
75236ff6393SMartin Habets {
75336ff6393SMartin Habets 	unsigned pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
75436ff6393SMartin Habets 	unsigned doorbell = FR_CZ_MC_TREG_SMEM + MCDI_DOORBELL(efx);
75536ff6393SMartin Habets 	unsigned int i;
75636ff6393SMartin Habets 	unsigned int inlen_dw = DIV_ROUND_UP(sdu_len, 4);
75736ff6393SMartin Habets 
75836ff6393SMartin Habets 	EFX_WARN_ON_PARANOID(hdr_len != 4);
75936ff6393SMartin Habets 
76036ff6393SMartin Habets 	efx_writed(efx, hdr, pdu);
76136ff6393SMartin Habets 
76236ff6393SMartin Habets 	for (i = 0; i < inlen_dw; i++)
76336ff6393SMartin Habets 		efx_writed(efx, &sdu[i], pdu + hdr_len + 4 * i);
76436ff6393SMartin Habets 
76536ff6393SMartin Habets 	/* Ensure the request is written out before the doorbell */
76636ff6393SMartin Habets 	wmb();
76736ff6393SMartin Habets 
76836ff6393SMartin Habets 	/* ring the doorbell with a distinctive value */
76936ff6393SMartin Habets 	_efx_writed(efx, (__force __le32) 0x45789abc, doorbell);
77036ff6393SMartin Habets }
77136ff6393SMartin Habets 
siena_mcdi_poll_response(struct efx_nic * efx)77236ff6393SMartin Habets static bool siena_mcdi_poll_response(struct efx_nic *efx)
77336ff6393SMartin Habets {
77436ff6393SMartin Habets 	unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
77536ff6393SMartin Habets 	efx_dword_t hdr;
77636ff6393SMartin Habets 
77736ff6393SMartin Habets 	efx_readd(efx, &hdr, pdu);
77836ff6393SMartin Habets 
77936ff6393SMartin Habets 	/* All 1's indicates that shared memory is in reset (and is
78036ff6393SMartin Habets 	 * not a valid hdr). Wait for it to come out reset before
78136ff6393SMartin Habets 	 * completing the command
78236ff6393SMartin Habets 	 */
78336ff6393SMartin Habets 	return EFX_DWORD_FIELD(hdr, EFX_DWORD_0) != 0xffffffff &&
78436ff6393SMartin Habets 		EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
78536ff6393SMartin Habets }
78636ff6393SMartin Habets 
siena_mcdi_read_response(struct efx_nic * efx,efx_dword_t * outbuf,size_t offset,size_t outlen)78736ff6393SMartin Habets static void siena_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
78836ff6393SMartin Habets 				     size_t offset, size_t outlen)
78936ff6393SMartin Habets {
79036ff6393SMartin Habets 	unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
79136ff6393SMartin Habets 	unsigned int outlen_dw = DIV_ROUND_UP(outlen, 4);
79236ff6393SMartin Habets 	int i;
79336ff6393SMartin Habets 
79436ff6393SMartin Habets 	for (i = 0; i < outlen_dw; i++)
79536ff6393SMartin Habets 		efx_readd(efx, &outbuf[i], pdu + offset + 4 * i);
79636ff6393SMartin Habets }
79736ff6393SMartin Habets 
siena_mcdi_poll_reboot(struct efx_nic * efx)79836ff6393SMartin Habets static int siena_mcdi_poll_reboot(struct efx_nic *efx)
79936ff6393SMartin Habets {
80036ff6393SMartin Habets 	struct siena_nic_data *nic_data = efx->nic_data;
80136ff6393SMartin Habets 	unsigned int addr = FR_CZ_MC_TREG_SMEM + MCDI_STATUS(efx);
80236ff6393SMartin Habets 	efx_dword_t reg;
80336ff6393SMartin Habets 	u32 value;
80436ff6393SMartin Habets 
80536ff6393SMartin Habets 	efx_readd(efx, &reg, addr);
80636ff6393SMartin Habets 	value = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
80736ff6393SMartin Habets 
80836ff6393SMartin Habets 	if (value == 0)
80936ff6393SMartin Habets 		return 0;
81036ff6393SMartin Habets 
81136ff6393SMartin Habets 	EFX_ZERO_DWORD(reg);
81236ff6393SMartin Habets 	efx_writed(efx, &reg, addr);
81336ff6393SMartin Habets 
81436ff6393SMartin Habets 	/* MAC statistics have been cleared on the NIC; clear the local
81536ff6393SMartin Habets 	 * copies that we update with efx_update_diff_stat().
81636ff6393SMartin Habets 	 */
81736ff6393SMartin Habets 	nic_data->stats[SIENA_STAT_tx_good_bytes] = 0;
81836ff6393SMartin Habets 	nic_data->stats[SIENA_STAT_rx_good_bytes] = 0;
81936ff6393SMartin Habets 
82036ff6393SMartin Habets 	if (value == MC_STATUS_DWORD_ASSERT)
82136ff6393SMartin Habets 		return -EINTR;
82236ff6393SMartin Habets 	else
82336ff6393SMartin Habets 		return -EIO;
82436ff6393SMartin Habets }
82536ff6393SMartin Habets 
82636ff6393SMartin Habets /**************************************************************************
82736ff6393SMartin Habets  *
82836ff6393SMartin Habets  * MTD
82936ff6393SMartin Habets  *
83036ff6393SMartin Habets  **************************************************************************
83136ff6393SMartin Habets  */
83236ff6393SMartin Habets 
83365d4b471SMartin Habets #ifdef CONFIG_SFC_SIENA_MTD
83436ff6393SMartin Habets 
83536ff6393SMartin Habets struct siena_nvram_type_info {
83636ff6393SMartin Habets 	int port;
83736ff6393SMartin Habets 	const char *name;
83836ff6393SMartin Habets };
83936ff6393SMartin Habets 
84036ff6393SMartin Habets static const struct siena_nvram_type_info siena_nvram_types[] = {
84136ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_DISABLED_CALLISTO]	= { 0, "sfc_dummy_phy" },
84236ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_MC_FW]		= { 0, "sfc_mcfw" },
84336ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_MC_FW_BACKUP]	= { 0, "sfc_mcfw_backup" },
84436ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_STATIC_CFG_PORT0]	= { 0, "sfc_static_cfg" },
84536ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_STATIC_CFG_PORT1]	= { 1, "sfc_static_cfg" },
84636ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT0]	= { 0, "sfc_dynamic_cfg" },
84736ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT1]	= { 1, "sfc_dynamic_cfg" },
84836ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_EXP_ROM]		= { 0, "sfc_exp_rom" },
84936ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_EXP_ROM_CFG_PORT0]	= { 0, "sfc_exp_rom_cfg" },
85036ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_EXP_ROM_CFG_PORT1]	= { 1, "sfc_exp_rom_cfg" },
85136ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_PHY_PORT0]		= { 0, "sfc_phy_fw" },
85236ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_PHY_PORT1]		= { 1, "sfc_phy_fw" },
85336ff6393SMartin Habets 	[MC_CMD_NVRAM_TYPE_FPGA]		= { 0, "sfc_fpga" },
85436ff6393SMartin Habets };
85536ff6393SMartin Habets 
siena_mtd_probe_partition(struct efx_nic * efx,struct efx_mcdi_mtd_partition * part,unsigned int type)85636ff6393SMartin Habets static int siena_mtd_probe_partition(struct efx_nic *efx,
85736ff6393SMartin Habets 				     struct efx_mcdi_mtd_partition *part,
85836ff6393SMartin Habets 				     unsigned int type)
85936ff6393SMartin Habets {
86036ff6393SMartin Habets 	const struct siena_nvram_type_info *info;
86136ff6393SMartin Habets 	size_t size, erase_size;
86236ff6393SMartin Habets 	bool protected;
86336ff6393SMartin Habets 	int rc;
86436ff6393SMartin Habets 
86536ff6393SMartin Habets 	if (type >= ARRAY_SIZE(siena_nvram_types) ||
86636ff6393SMartin Habets 	    siena_nvram_types[type].name == NULL)
86736ff6393SMartin Habets 		return -ENODEV;
86836ff6393SMartin Habets 
86936ff6393SMartin Habets 	info = &siena_nvram_types[type];
87036ff6393SMartin Habets 
87136ff6393SMartin Habets 	if (info->port != efx_port_num(efx))
87236ff6393SMartin Habets 		return -ENODEV;
87336ff6393SMartin Habets 
8744d49e5cdSMartin Habets 	rc = efx_siena_mcdi_nvram_info(efx, type, &size, &erase_size,
8754d49e5cdSMartin Habets 				       &protected);
87636ff6393SMartin Habets 	if (rc)
87736ff6393SMartin Habets 		return rc;
87836ff6393SMartin Habets 	if (protected)
87936ff6393SMartin Habets 		return -ENODEV; /* hide it */
88036ff6393SMartin Habets 
88136ff6393SMartin Habets 	part->nvram_type = type;
88236ff6393SMartin Habets 	part->common.dev_type_name = "Siena NVRAM manager";
88336ff6393SMartin Habets 	part->common.type_name = info->name;
88436ff6393SMartin Habets 
88536ff6393SMartin Habets 	part->common.mtd.type = MTD_NORFLASH;
88636ff6393SMartin Habets 	part->common.mtd.flags = MTD_CAP_NORFLASH;
88736ff6393SMartin Habets 	part->common.mtd.size = size;
88836ff6393SMartin Habets 	part->common.mtd.erasesize = erase_size;
88936ff6393SMartin Habets 
89036ff6393SMartin Habets 	return 0;
89136ff6393SMartin Habets }
89236ff6393SMartin Habets 
siena_mtd_get_fw_subtypes(struct efx_nic * efx,struct efx_mcdi_mtd_partition * parts,size_t n_parts)89336ff6393SMartin Habets static int siena_mtd_get_fw_subtypes(struct efx_nic *efx,
89436ff6393SMartin Habets 				     struct efx_mcdi_mtd_partition *parts,
89536ff6393SMartin Habets 				     size_t n_parts)
89636ff6393SMartin Habets {
89736ff6393SMartin Habets 	uint16_t fw_subtype_list[
89836ff6393SMartin Habets 		MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MAXNUM];
89936ff6393SMartin Habets 	size_t i;
90036ff6393SMartin Habets 	int rc;
90136ff6393SMartin Habets 
9024d49e5cdSMartin Habets 	rc = efx_siena_mcdi_get_board_cfg(efx, NULL, fw_subtype_list, NULL);
90336ff6393SMartin Habets 	if (rc)
90436ff6393SMartin Habets 		return rc;
90536ff6393SMartin Habets 
90636ff6393SMartin Habets 	for (i = 0; i < n_parts; i++)
90736ff6393SMartin Habets 		parts[i].fw_subtype = fw_subtype_list[parts[i].nvram_type];
90836ff6393SMartin Habets 
90936ff6393SMartin Habets 	return 0;
91036ff6393SMartin Habets }
91136ff6393SMartin Habets 
siena_mtd_probe(struct efx_nic * efx)91236ff6393SMartin Habets static int siena_mtd_probe(struct efx_nic *efx)
91336ff6393SMartin Habets {
91436ff6393SMartin Habets 	struct efx_mcdi_mtd_partition *parts;
91536ff6393SMartin Habets 	u32 nvram_types;
91636ff6393SMartin Habets 	unsigned int type;
91736ff6393SMartin Habets 	size_t n_parts;
91836ff6393SMartin Habets 	int rc;
91936ff6393SMartin Habets 
92036ff6393SMartin Habets 	ASSERT_RTNL();
92136ff6393SMartin Habets 
9224d49e5cdSMartin Habets 	rc = efx_siena_mcdi_nvram_types(efx, &nvram_types);
92336ff6393SMartin Habets 	if (rc)
92436ff6393SMartin Habets 		return rc;
92536ff6393SMartin Habets 
92636ff6393SMartin Habets 	parts = kcalloc(hweight32(nvram_types), sizeof(*parts), GFP_KERNEL);
92736ff6393SMartin Habets 	if (!parts)
92836ff6393SMartin Habets 		return -ENOMEM;
92936ff6393SMartin Habets 
93036ff6393SMartin Habets 	type = 0;
93136ff6393SMartin Habets 	n_parts = 0;
93236ff6393SMartin Habets 
93336ff6393SMartin Habets 	while (nvram_types != 0) {
93436ff6393SMartin Habets 		if (nvram_types & 1) {
93536ff6393SMartin Habets 			rc = siena_mtd_probe_partition(efx, &parts[n_parts],
93636ff6393SMartin Habets 						       type);
93736ff6393SMartin Habets 			if (rc == 0)
93836ff6393SMartin Habets 				n_parts++;
93936ff6393SMartin Habets 			else if (rc != -ENODEV)
94036ff6393SMartin Habets 				goto fail;
94136ff6393SMartin Habets 		}
94236ff6393SMartin Habets 		type++;
94336ff6393SMartin Habets 		nvram_types >>= 1;
94436ff6393SMartin Habets 	}
94536ff6393SMartin Habets 
94636ff6393SMartin Habets 	rc = siena_mtd_get_fw_subtypes(efx, parts, n_parts);
94736ff6393SMartin Habets 	if (rc)
94836ff6393SMartin Habets 		goto fail;
94936ff6393SMartin Habets 
95071ad88f6SMartin Habets 	rc = efx_siena_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
95136ff6393SMartin Habets fail:
95236ff6393SMartin Habets 	if (rc)
95336ff6393SMartin Habets 		kfree(parts);
95436ff6393SMartin Habets 	return rc;
95536ff6393SMartin Habets }
95636ff6393SMartin Habets 
95765d4b471SMartin Habets #endif /* CONFIG_SFC_SIENA_MTD */
95836ff6393SMartin Habets 
siena_check_caps(const struct efx_nic * efx,u8 flag,u32 offset)95936ff6393SMartin Habets static unsigned int siena_check_caps(const struct efx_nic *efx,
96036ff6393SMartin Habets 				     u8 flag, u32 offset)
96136ff6393SMartin Habets {
96236ff6393SMartin Habets 	/* Siena did not support MC_CMD_GET_CAPABILITIES */
96336ff6393SMartin Habets 	return 0;
96436ff6393SMartin Habets }
96536ff6393SMartin Habets 
efx_siena_recycle_ring_size(const struct efx_nic * efx)96636ff6393SMartin Habets static unsigned int efx_siena_recycle_ring_size(const struct efx_nic *efx)
96736ff6393SMartin Habets {
96836ff6393SMartin Habets 	/* Maximum link speed is 10G */
96936ff6393SMartin Habets 	return EFX_RECYCLE_RING_SIZE_10G;
97036ff6393SMartin Habets }
97136ff6393SMartin Habets 
97236ff6393SMartin Habets /**************************************************************************
97336ff6393SMartin Habets  *
97436ff6393SMartin Habets  * Revision-dependent attributes used by efx.c and nic.c
97536ff6393SMartin Habets  *
97636ff6393SMartin Habets  **************************************************************************
97736ff6393SMartin Habets  */
97836ff6393SMartin Habets 
97936ff6393SMartin Habets const struct efx_nic_type siena_a0_nic_type = {
98036ff6393SMartin Habets 	.is_vf = false,
98136ff6393SMartin Habets 	.mem_bar = siena_mem_bar,
98236ff6393SMartin Habets 	.mem_map_size = siena_mem_map_size,
98336ff6393SMartin Habets 	.probe = siena_probe_nic,
98436ff6393SMartin Habets 	.remove = siena_remove_nic,
98536ff6393SMartin Habets 	.init = siena_init_nic,
98636ff6393SMartin Habets 	.dimension_resources = siena_dimension_resources,
98771ad88f6SMartin Habets 	.fini = efx_siena_port_dummy_op_void,
98836ff6393SMartin Habets #ifdef CONFIG_EEH
98936ff6393SMartin Habets 	.monitor = siena_monitor,
99036ff6393SMartin Habets #else
99136ff6393SMartin Habets 	.monitor = NULL,
99236ff6393SMartin Habets #endif
9934d49e5cdSMartin Habets 	.map_reset_reason = efx_siena_mcdi_map_reset_reason,
99436ff6393SMartin Habets 	.map_reset_flags = siena_map_reset_flags,
9954d49e5cdSMartin Habets 	.reset = efx_siena_mcdi_reset,
9964d49e5cdSMartin Habets 	.probe_port = efx_siena_mcdi_port_probe,
9974d49e5cdSMartin Habets 	.remove_port = efx_siena_mcdi_port_remove,
99836ff6393SMartin Habets 	.fini_dmaq = efx_farch_fini_dmaq,
999956f2d86SMartin Habets 	.prepare_flush = efx_siena_prepare_flush,
100036ff6393SMartin Habets 	.finish_flush = siena_finish_flush,
100171ad88f6SMartin Habets 	.prepare_flr = efx_siena_port_dummy_op_void,
100236ff6393SMartin Habets 	.finish_flr = efx_farch_finish_flr,
100336ff6393SMartin Habets 	.describe_stats = siena_describe_nic_stats,
100436ff6393SMartin Habets 	.update_stats = siena_update_nic_stats,
10054d49e5cdSMartin Habets 	.start_stats = efx_siena_mcdi_mac_start_stats,
10064d49e5cdSMartin Habets 	.pull_stats = efx_siena_mcdi_mac_pull_stats,
10074d49e5cdSMartin Habets 	.stop_stats = efx_siena_mcdi_mac_stop_stats,
100836ff6393SMartin Habets 	.push_irq_moderation = siena_push_irq_moderation,
100936ff6393SMartin Habets 	.reconfigure_mac = siena_mac_reconfigure,
10104d49e5cdSMartin Habets 	.check_mac_fault = efx_siena_mcdi_mac_check_fault,
10114d49e5cdSMartin Habets 	.reconfigure_port = efx_siena_mcdi_port_reconfigure,
101236ff6393SMartin Habets 	.get_wol = siena_get_wol,
101336ff6393SMartin Habets 	.set_wol = siena_set_wol,
101436ff6393SMartin Habets 	.resume_wol = siena_init_wol,
101536ff6393SMartin Habets 	.test_chip = siena_test_chip,
10164d49e5cdSMartin Habets 	.test_nvram = efx_siena_mcdi_nvram_test_all,
101736ff6393SMartin Habets 	.mcdi_request = siena_mcdi_request,
101836ff6393SMartin Habets 	.mcdi_poll_response = siena_mcdi_poll_response,
101936ff6393SMartin Habets 	.mcdi_read_response = siena_mcdi_read_response,
102036ff6393SMartin Habets 	.mcdi_poll_reboot = siena_mcdi_poll_reboot,
102136ff6393SMartin Habets 	.irq_enable_master = efx_farch_irq_enable_master,
102236ff6393SMartin Habets 	.irq_test_generate = efx_farch_irq_test_generate,
102336ff6393SMartin Habets 	.irq_disable_non_ev = efx_farch_irq_disable_master,
102436ff6393SMartin Habets 	.irq_handle_msi = efx_farch_msi_interrupt,
102536ff6393SMartin Habets 	.irq_handle_legacy = efx_farch_legacy_interrupt,
102636ff6393SMartin Habets 	.tx_probe = efx_farch_tx_probe,
102736ff6393SMartin Habets 	.tx_init = efx_farch_tx_init,
102836ff6393SMartin Habets 	.tx_remove = efx_farch_tx_remove,
102936ff6393SMartin Habets 	.tx_write = efx_farch_tx_write,
103036ff6393SMartin Habets 	.tx_limit_len = efx_farch_tx_limit_len,
103171ad88f6SMartin Habets 	.tx_enqueue = __efx_siena_enqueue_skb,
103236ff6393SMartin Habets 	.rx_push_rss_config = siena_rx_push_rss_config,
103336ff6393SMartin Habets 	.rx_pull_rss_config = siena_rx_pull_rss_config,
103436ff6393SMartin Habets 	.rx_probe = efx_farch_rx_probe,
103536ff6393SMartin Habets 	.rx_init = efx_farch_rx_init,
103636ff6393SMartin Habets 	.rx_remove = efx_farch_rx_remove,
103736ff6393SMartin Habets 	.rx_write = efx_farch_rx_write,
103836ff6393SMartin Habets 	.rx_defer_refill = efx_farch_rx_defer_refill,
103971ad88f6SMartin Habets 	.rx_packet = __efx_siena_rx_packet,
104036ff6393SMartin Habets 	.ev_probe = efx_farch_ev_probe,
104136ff6393SMartin Habets 	.ev_init = efx_farch_ev_init,
104236ff6393SMartin Habets 	.ev_fini = efx_farch_ev_fini,
104336ff6393SMartin Habets 	.ev_remove = efx_farch_ev_remove,
104436ff6393SMartin Habets 	.ev_process = efx_farch_ev_process,
104536ff6393SMartin Habets 	.ev_read_ack = efx_farch_ev_read_ack,
104636ff6393SMartin Habets 	.ev_test_generate = efx_farch_ev_test_generate,
104736ff6393SMartin Habets 	.filter_table_probe = efx_farch_filter_table_probe,
104836ff6393SMartin Habets 	.filter_table_restore = efx_farch_filter_table_restore,
104936ff6393SMartin Habets 	.filter_table_remove = efx_farch_filter_table_remove,
105036ff6393SMartin Habets 	.filter_update_rx_scatter = efx_farch_filter_update_rx_scatter,
105136ff6393SMartin Habets 	.filter_insert = efx_farch_filter_insert,
105236ff6393SMartin Habets 	.filter_remove_safe = efx_farch_filter_remove_safe,
105336ff6393SMartin Habets 	.filter_get_safe = efx_farch_filter_get_safe,
105436ff6393SMartin Habets 	.filter_clear_rx = efx_farch_filter_clear_rx,
105536ff6393SMartin Habets 	.filter_count_rx_used = efx_farch_filter_count_rx_used,
105636ff6393SMartin Habets 	.filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
105736ff6393SMartin Habets 	.filter_get_rx_ids = efx_farch_filter_get_rx_ids,
105836ff6393SMartin Habets #ifdef CONFIG_RFS_ACCEL
105936ff6393SMartin Habets 	.filter_rfs_expire_one = efx_farch_filter_rfs_expire_one,
106036ff6393SMartin Habets #endif
106165d4b471SMartin Habets #ifdef CONFIG_SFC_SIENA_MTD
106236ff6393SMartin Habets 	.mtd_probe = siena_mtd_probe,
10634d49e5cdSMartin Habets 	.mtd_rename = efx_siena_mcdi_mtd_rename,
10644d49e5cdSMartin Habets 	.mtd_read = efx_siena_mcdi_mtd_read,
10654d49e5cdSMartin Habets 	.mtd_erase = efx_siena_mcdi_mtd_erase,
10664d49e5cdSMartin Habets 	.mtd_write = efx_siena_mcdi_mtd_write,
10674d49e5cdSMartin Habets 	.mtd_sync = efx_siena_mcdi_mtd_sync,
106836ff6393SMartin Habets #endif
106936ff6393SMartin Habets 	.ptp_write_host_time = siena_ptp_write_host_time,
107036ff6393SMartin Habets 	.ptp_set_ts_config = siena_ptp_set_ts_config,
1071dfb1cfbdSMartin Habets #ifdef CONFIG_SFC_SIENA_SRIOV
107236ff6393SMartin Habets 	.sriov_configure = efx_siena_sriov_configure,
107336ff6393SMartin Habets 	.sriov_init = efx_siena_sriov_init,
107436ff6393SMartin Habets 	.sriov_fini = efx_siena_sriov_fini,
107536ff6393SMartin Habets 	.sriov_wanted = efx_siena_sriov_wanted,
107636ff6393SMartin Habets 	.sriov_reset = efx_siena_sriov_reset,
107736ff6393SMartin Habets 	.sriov_flr = efx_siena_sriov_flr,
107836ff6393SMartin Habets 	.sriov_set_vf_mac = efx_siena_sriov_set_vf_mac,
107936ff6393SMartin Habets 	.sriov_set_vf_vlan = efx_siena_sriov_set_vf_vlan,
108036ff6393SMartin Habets 	.sriov_set_vf_spoofchk = efx_siena_sriov_set_vf_spoofchk,
108136ff6393SMartin Habets 	.sriov_get_vf_config = efx_siena_sriov_get_vf_config,
108271ad88f6SMartin Habets 	.vswitching_probe = efx_siena_port_dummy_op_int,
108371ad88f6SMartin Habets 	.vswitching_restore = efx_siena_port_dummy_op_int,
108471ad88f6SMartin Habets 	.vswitching_remove = efx_siena_port_dummy_op_void,
108536ff6393SMartin Habets 	.set_mac_address = efx_siena_sriov_mac_address_changed,
108636ff6393SMartin Habets #endif
108736ff6393SMartin Habets 
108836ff6393SMartin Habets 	.revision = EFX_REV_SIENA_A0,
108936ff6393SMartin Habets 	.txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
109036ff6393SMartin Habets 	.rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
109136ff6393SMartin Habets 	.buf_tbl_base = FR_BZ_BUF_FULL_TBL,
109236ff6393SMartin Habets 	.evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
109336ff6393SMartin Habets 	.evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
109436ff6393SMartin Habets 	.max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
109536ff6393SMartin Habets 	.rx_prefix_size = FS_BZ_RX_PREFIX_SIZE,
109636ff6393SMartin Habets 	.rx_hash_offset = FS_BZ_RX_PREFIX_HASH_OFST,
109736ff6393SMartin Habets 	.rx_buffer_padding = 0,
109836ff6393SMartin Habets 	.can_rx_scatter = true,
109936ff6393SMartin Habets 	.option_descriptors = false,
110036ff6393SMartin Habets 	.min_interrupt_mode = EFX_INT_MODE_LEGACY,
110136ff6393SMartin Habets 	.timer_period_max = 1 << FRF_CZ_TC_TIMER_VAL_WIDTH,
110236ff6393SMartin Habets 	.offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
110336ff6393SMartin Habets 			     NETIF_F_RXHASH | NETIF_F_NTUPLE),
110436ff6393SMartin Habets 	.mcdi_max_ver = 1,
110536ff6393SMartin Habets 	.max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS,
110636ff6393SMartin Habets 	.hwtstamp_filters = (1 << HWTSTAMP_FILTER_NONE |
110736ff6393SMartin Habets 			     1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT |
110836ff6393SMartin Habets 			     1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT),
110936ff6393SMartin Habets 	.rx_hash_key_size = 16,
111036ff6393SMartin Habets 	.check_caps = siena_check_caps,
11114d49e5cdSMartin Habets 	.sensor_event = efx_siena_mcdi_sensor_event,
111236ff6393SMartin Habets 	.rx_recycle_ring_size = efx_siena_recycle_ring_size,
111336ff6393SMartin Habets };
1114