xref: /openbmc/linux/drivers/net/ethernet/sfc/efx.c (revision a83762d9)
1874aeea5SJeff Kirsher /****************************************************************************
2f7a6d2c4SBen Hutchings  * Driver for Solarflare network controllers and boards
3874aeea5SJeff Kirsher  * Copyright 2005-2006 Fen Systems Ltd.
4f7a6d2c4SBen Hutchings  * Copyright 2005-2013 Solarflare Communications Inc.
5874aeea5SJeff Kirsher  *
6874aeea5SJeff Kirsher  * This program is free software; you can redistribute it and/or modify it
7874aeea5SJeff Kirsher  * under the terms of the GNU General Public License version 2 as published
8874aeea5SJeff Kirsher  * by the Free Software Foundation, incorporated herein by reference.
9874aeea5SJeff Kirsher  */
10874aeea5SJeff Kirsher 
11874aeea5SJeff Kirsher #include <linux/module.h>
12874aeea5SJeff Kirsher #include <linux/pci.h>
13874aeea5SJeff Kirsher #include <linux/netdevice.h>
14874aeea5SJeff Kirsher #include <linux/etherdevice.h>
15874aeea5SJeff Kirsher #include <linux/delay.h>
16874aeea5SJeff Kirsher #include <linux/notifier.h>
17874aeea5SJeff Kirsher #include <linux/ip.h>
18874aeea5SJeff Kirsher #include <linux/tcp.h>
19874aeea5SJeff Kirsher #include <linux/in.h>
20874aeea5SJeff Kirsher #include <linux/ethtool.h>
21874aeea5SJeff Kirsher #include <linux/topology.h>
22874aeea5SJeff Kirsher #include <linux/gfp.h>
23626950dbSAlexandre Rames #include <linux/aer.h>
24b28405b0SAlexandre Rames #include <linux/interrupt.h>
25874aeea5SJeff Kirsher #include "net_driver.h"
26e5fbd977SJon Cooper #include <net/gre.h>
27e5fbd977SJon Cooper #include <net/udp_tunnel.h>
28874aeea5SJeff Kirsher #include "efx.h"
29874aeea5SJeff Kirsher #include "nic.h"
3071827443SEdward Cree #include "io.h"
31dd40781eSBen Hutchings #include "selftest.h"
327fa8d547SShradha Shah #include "sriov.h"
33874aeea5SJeff Kirsher 
34874aeea5SJeff Kirsher #include "mcdi.h"
35e5fbd977SJon Cooper #include "mcdi_pcol.h"
36874aeea5SJeff Kirsher #include "workarounds.h"
37874aeea5SJeff Kirsher 
38874aeea5SJeff Kirsher /**************************************************************************
39874aeea5SJeff Kirsher  *
40874aeea5SJeff Kirsher  * Type name strings
41874aeea5SJeff Kirsher  *
42874aeea5SJeff Kirsher  **************************************************************************
43874aeea5SJeff Kirsher  */
44874aeea5SJeff Kirsher 
45874aeea5SJeff Kirsher /* Loopback mode names (see LOOPBACK_MODE()) */
46874aeea5SJeff Kirsher const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
4718e83e4cSBen Hutchings const char *const efx_loopback_mode_names[] = {
48874aeea5SJeff Kirsher 	[LOOPBACK_NONE]		= "NONE",
49874aeea5SJeff Kirsher 	[LOOPBACK_DATA]		= "DATAPATH",
50874aeea5SJeff Kirsher 	[LOOPBACK_GMAC]		= "GMAC",
51874aeea5SJeff Kirsher 	[LOOPBACK_XGMII]	= "XGMII",
52874aeea5SJeff Kirsher 	[LOOPBACK_XGXS]		= "XGXS",
53874aeea5SJeff Kirsher 	[LOOPBACK_XAUI]		= "XAUI",
54874aeea5SJeff Kirsher 	[LOOPBACK_GMII]		= "GMII",
55874aeea5SJeff Kirsher 	[LOOPBACK_SGMII]	= "SGMII",
56874aeea5SJeff Kirsher 	[LOOPBACK_XGBR]		= "XGBR",
57874aeea5SJeff Kirsher 	[LOOPBACK_XFI]		= "XFI",
58874aeea5SJeff Kirsher 	[LOOPBACK_XAUI_FAR]	= "XAUI_FAR",
59874aeea5SJeff Kirsher 	[LOOPBACK_GMII_FAR]	= "GMII_FAR",
60874aeea5SJeff Kirsher 	[LOOPBACK_SGMII_FAR]	= "SGMII_FAR",
61874aeea5SJeff Kirsher 	[LOOPBACK_XFI_FAR]	= "XFI_FAR",
62874aeea5SJeff Kirsher 	[LOOPBACK_GPHY]		= "GPHY",
63874aeea5SJeff Kirsher 	[LOOPBACK_PHYXS]	= "PHYXS",
64874aeea5SJeff Kirsher 	[LOOPBACK_PCS]		= "PCS",
65874aeea5SJeff Kirsher 	[LOOPBACK_PMAPMD]	= "PMA/PMD",
66874aeea5SJeff Kirsher 	[LOOPBACK_XPORT]	= "XPORT",
67874aeea5SJeff Kirsher 	[LOOPBACK_XGMII_WS]	= "XGMII_WS",
68874aeea5SJeff Kirsher 	[LOOPBACK_XAUI_WS]	= "XAUI_WS",
69874aeea5SJeff Kirsher 	[LOOPBACK_XAUI_WS_FAR]  = "XAUI_WS_FAR",
70874aeea5SJeff Kirsher 	[LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
71874aeea5SJeff Kirsher 	[LOOPBACK_GMII_WS]	= "GMII_WS",
72874aeea5SJeff Kirsher 	[LOOPBACK_XFI_WS]	= "XFI_WS",
73874aeea5SJeff Kirsher 	[LOOPBACK_XFI_WS_FAR]	= "XFI_WS_FAR",
74874aeea5SJeff Kirsher 	[LOOPBACK_PHYXS_WS]	= "PHYXS_WS",
75874aeea5SJeff Kirsher };
76874aeea5SJeff Kirsher 
77874aeea5SJeff Kirsher const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
7818e83e4cSBen Hutchings const char *const efx_reset_type_names[] = {
79874aeea5SJeff Kirsher 	[RESET_TYPE_INVISIBLE]          = "INVISIBLE",
80874aeea5SJeff Kirsher 	[RESET_TYPE_ALL]                = "ALL",
81626950dbSAlexandre Rames 	[RESET_TYPE_RECOVER_OR_ALL]     = "RECOVER_OR_ALL",
82874aeea5SJeff Kirsher 	[RESET_TYPE_WORLD]              = "WORLD",
83626950dbSAlexandre Rames 	[RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
84087e9025SJon Cooper 	[RESET_TYPE_DATAPATH]           = "DATAPATH",
85e283546cSEdward Cree 	[RESET_TYPE_MC_BIST]		= "MC_BIST",
86874aeea5SJeff Kirsher 	[RESET_TYPE_DISABLE]            = "DISABLE",
87874aeea5SJeff Kirsher 	[RESET_TYPE_TX_WATCHDOG]        = "TX_WATCHDOG",
88874aeea5SJeff Kirsher 	[RESET_TYPE_INT_ERROR]          = "INT_ERROR",
893de82b91SAlexandre Rames 	[RESET_TYPE_DMA_ERROR]          = "DMA_ERROR",
90874aeea5SJeff Kirsher 	[RESET_TYPE_TX_SKIP]            = "TX_SKIP",
91874aeea5SJeff Kirsher 	[RESET_TYPE_MC_FAILURE]         = "MC_FAILURE",
92e283546cSEdward Cree 	[RESET_TYPE_MCDI_TIMEOUT]	= "MCDI_TIMEOUT (FLR)",
93874aeea5SJeff Kirsher };
94874aeea5SJeff Kirsher 
95e5fbd977SJon Cooper /* UDP tunnel type names */
96e5fbd977SJon Cooper static const char *const efx_udp_tunnel_type_names[] = {
97e5fbd977SJon Cooper 	[TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
98e5fbd977SJon Cooper 	[TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
99e5fbd977SJon Cooper };
100e5fbd977SJon Cooper 
101e5fbd977SJon Cooper void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
102e5fbd977SJon Cooper {
103e5fbd977SJon Cooper 	if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
104e5fbd977SJon Cooper 	    efx_udp_tunnel_type_names[type] != NULL)
105e5fbd977SJon Cooper 		snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
106e5fbd977SJon Cooper 	else
107e5fbd977SJon Cooper 		snprintf(buf, buflen, "type %d", type);
108e5fbd977SJon Cooper }
109e5fbd977SJon Cooper 
110874aeea5SJeff Kirsher /* Reset workqueue. If any NIC has a hardware failure then a reset will be
111874aeea5SJeff Kirsher  * queued onto this work queue. This is not a per-nic work queue, because
112874aeea5SJeff Kirsher  * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
113874aeea5SJeff Kirsher  */
114874aeea5SJeff Kirsher static struct workqueue_struct *reset_workqueue;
115874aeea5SJeff Kirsher 
11674cd60a4SJon Cooper /* How often and how many times to poll for a reset while waiting for a
11774cd60a4SJon Cooper  * BIST that another function started to complete.
11874cd60a4SJon Cooper  */
11974cd60a4SJon Cooper #define BIST_WAIT_DELAY_MS	100
12074cd60a4SJon Cooper #define BIST_WAIT_DELAY_COUNT	100
12174cd60a4SJon Cooper 
122874aeea5SJeff Kirsher /**************************************************************************
123874aeea5SJeff Kirsher  *
124874aeea5SJeff Kirsher  * Configurable values
125874aeea5SJeff Kirsher  *
126874aeea5SJeff Kirsher  *************************************************************************/
127874aeea5SJeff Kirsher 
128874aeea5SJeff Kirsher /*
129874aeea5SJeff Kirsher  * Use separate channels for TX and RX events
130874aeea5SJeff Kirsher  *
131874aeea5SJeff Kirsher  * Set this to 1 to use separate channels for TX and RX. It allows us
132874aeea5SJeff Kirsher  * to control interrupt affinity separately for TX and RX.
133874aeea5SJeff Kirsher  *
134874aeea5SJeff Kirsher  * This is only used in MSI-X interrupt mode
135874aeea5SJeff Kirsher  */
136b0fbdae1SShradha Shah bool efx_separate_tx_channels;
137b0fbdae1SShradha Shah module_param(efx_separate_tx_channels, bool, 0444);
138b0fbdae1SShradha Shah MODULE_PARM_DESC(efx_separate_tx_channels,
139874aeea5SJeff Kirsher 		 "Use separate channels for TX and RX");
140874aeea5SJeff Kirsher 
141874aeea5SJeff Kirsher /* This is the weight assigned to each of the (per-channel) virtual
142874aeea5SJeff Kirsher  * NAPI devices.
143874aeea5SJeff Kirsher  */
144874aeea5SJeff Kirsher static int napi_weight = 64;
145874aeea5SJeff Kirsher 
146874aeea5SJeff Kirsher /* This is the time (in jiffies) between invocations of the hardware
147626950dbSAlexandre Rames  * monitor.
148626950dbSAlexandre Rames  * On Falcon-based NICs, this will:
149874aeea5SJeff Kirsher  * - Check the on-board hardware monitor;
150874aeea5SJeff Kirsher  * - Poll the link state and reconfigure the hardware as necessary.
151626950dbSAlexandre Rames  * On Siena-based NICs for power systems with EEH support, this will give EEH a
152626950dbSAlexandre Rames  * chance to start.
153874aeea5SJeff Kirsher  */
154874aeea5SJeff Kirsher static unsigned int efx_monitor_interval = 1 * HZ;
155874aeea5SJeff Kirsher 
156874aeea5SJeff Kirsher /* Initial interrupt moderation settings.  They can be modified after
157874aeea5SJeff Kirsher  * module load with ethtool.
158874aeea5SJeff Kirsher  *
159874aeea5SJeff Kirsher  * The default for RX should strike a balance between increasing the
160874aeea5SJeff Kirsher  * round-trip latency and reducing overhead.
161874aeea5SJeff Kirsher  */
162874aeea5SJeff Kirsher static unsigned int rx_irq_mod_usec = 60;
163874aeea5SJeff Kirsher 
164874aeea5SJeff Kirsher /* Initial interrupt moderation settings.  They can be modified after
165874aeea5SJeff Kirsher  * module load with ethtool.
166874aeea5SJeff Kirsher  *
167874aeea5SJeff Kirsher  * This default is chosen to ensure that a 10G link does not go idle
168874aeea5SJeff Kirsher  * while a TX queue is stopped after it has become full.  A queue is
169874aeea5SJeff Kirsher  * restarted when it drops below half full.  The time this takes (assuming
170874aeea5SJeff Kirsher  * worst case 3 descriptors per packet and 1024 descriptors) is
171874aeea5SJeff Kirsher  *   512 / 3 * 1.2 = 205 usec.
172874aeea5SJeff Kirsher  */
173874aeea5SJeff Kirsher static unsigned int tx_irq_mod_usec = 150;
174874aeea5SJeff Kirsher 
175874aeea5SJeff Kirsher /* This is the first interrupt mode to try out of:
176874aeea5SJeff Kirsher  * 0 => MSI-X
177874aeea5SJeff Kirsher  * 1 => MSI
178874aeea5SJeff Kirsher  * 2 => legacy
179874aeea5SJeff Kirsher  */
180874aeea5SJeff Kirsher static unsigned int interrupt_mode;
181874aeea5SJeff Kirsher 
182874aeea5SJeff Kirsher /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
183874aeea5SJeff Kirsher  * i.e. the number of CPUs among which we may distribute simultaneous
184874aeea5SJeff Kirsher  * interrupt handling.
185874aeea5SJeff Kirsher  *
186874aeea5SJeff Kirsher  * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
187cdb08f8fSBen Hutchings  * The default (0) means to assign an interrupt to each core.
188874aeea5SJeff Kirsher  */
189874aeea5SJeff Kirsher static unsigned int rss_cpus;
190874aeea5SJeff Kirsher module_param(rss_cpus, uint, 0444);
191874aeea5SJeff Kirsher MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
192874aeea5SJeff Kirsher 
193b9cc977dSBen Hutchings static bool phy_flash_cfg;
194b9cc977dSBen Hutchings module_param(phy_flash_cfg, bool, 0644);
195874aeea5SJeff Kirsher MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
196874aeea5SJeff Kirsher 
197e7bed9c8SBen Hutchings static unsigned irq_adapt_low_thresh = 8000;
198874aeea5SJeff Kirsher module_param(irq_adapt_low_thresh, uint, 0644);
199874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_low_thresh,
200874aeea5SJeff Kirsher 		 "Threshold score for reducing IRQ moderation");
201874aeea5SJeff Kirsher 
202e7bed9c8SBen Hutchings static unsigned irq_adapt_high_thresh = 16000;
203874aeea5SJeff Kirsher module_param(irq_adapt_high_thresh, uint, 0644);
204874aeea5SJeff Kirsher MODULE_PARM_DESC(irq_adapt_high_thresh,
205874aeea5SJeff Kirsher 		 "Threshold score for increasing IRQ moderation");
206874aeea5SJeff Kirsher 
207874aeea5SJeff Kirsher static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
208874aeea5SJeff Kirsher 			 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
209874aeea5SJeff Kirsher 			 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
210874aeea5SJeff Kirsher 			 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
211874aeea5SJeff Kirsher module_param(debug, uint, 0);
212874aeea5SJeff Kirsher MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
213874aeea5SJeff Kirsher 
214874aeea5SJeff Kirsher /**************************************************************************
215874aeea5SJeff Kirsher  *
216874aeea5SJeff Kirsher  * Utility functions and prototypes
217874aeea5SJeff Kirsher  *
218874aeea5SJeff Kirsher  *************************************************************************/
219874aeea5SJeff Kirsher 
220261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx);
221d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx);
2227f967c01SBen Hutchings static void efx_remove_channel(struct efx_channel *channel);
223874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx);
2247f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type;
225874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx);
2267f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel);
227874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx);
228874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel);
229874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx);
230874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx);
231874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx);
232874aeea5SJeff Kirsher 
233874aeea5SJeff Kirsher #define EFX_ASSERT_RESET_SERIALISED(efx)		\
234874aeea5SJeff Kirsher 	do {						\
235f16aeea0SBen Hutchings 		if ((efx->state == STATE_READY) ||	\
236626950dbSAlexandre Rames 		    (efx->state == STATE_RECOVERY) ||	\
237874aeea5SJeff Kirsher 		    (efx->state == STATE_DISABLED))	\
238874aeea5SJeff Kirsher 			ASSERT_RTNL();			\
239874aeea5SJeff Kirsher 	} while (0)
240874aeea5SJeff Kirsher 
2418b7325b4SBen Hutchings static int efx_check_disabled(struct efx_nic *efx)
2428b7325b4SBen Hutchings {
243626950dbSAlexandre Rames 	if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
2448b7325b4SBen Hutchings 		netif_err(efx, drv, efx->net_dev,
2458b7325b4SBen Hutchings 			  "device is disabled due to earlier errors\n");
2468b7325b4SBen Hutchings 		return -EIO;
2478b7325b4SBen Hutchings 	}
2488b7325b4SBen Hutchings 	return 0;
2498b7325b4SBen Hutchings }
2508b7325b4SBen Hutchings 
251874aeea5SJeff Kirsher /**************************************************************************
252874aeea5SJeff Kirsher  *
253874aeea5SJeff Kirsher  * Event queue processing
254874aeea5SJeff Kirsher  *
255874aeea5SJeff Kirsher  *************************************************************************/
256874aeea5SJeff Kirsher 
257874aeea5SJeff Kirsher /* Process channel's event queue
258874aeea5SJeff Kirsher  *
259874aeea5SJeff Kirsher  * This function is responsible for processing the event queue of a
260874aeea5SJeff Kirsher  * single channel.  The caller must guarantee that this function will
261874aeea5SJeff Kirsher  * never be concurrently called more than once on the same channel,
262874aeea5SJeff Kirsher  * though different channels may be being processed concurrently.
263874aeea5SJeff Kirsher  */
264874aeea5SJeff Kirsher static int efx_process_channel(struct efx_channel *channel, int budget)
265874aeea5SJeff Kirsher {
266c936835cSPeter Dunning 	struct efx_tx_queue *tx_queue;
267874aeea5SJeff Kirsher 	int spent;
268874aeea5SJeff Kirsher 
2699f2cb71cSBen Hutchings 	if (unlikely(!channel->enabled))
270874aeea5SJeff Kirsher 		return 0;
271874aeea5SJeff Kirsher 
272c936835cSPeter Dunning 	efx_for_each_channel_tx_queue(tx_queue, channel) {
273c936835cSPeter Dunning 		tx_queue->pkts_compl = 0;
274c936835cSPeter Dunning 		tx_queue->bytes_compl = 0;
275c936835cSPeter Dunning 	}
276c936835cSPeter Dunning 
277874aeea5SJeff Kirsher 	spent = efx_nic_process_eventq(channel, budget);
278d9ab7007SBen Hutchings 	if (spent && efx_channel_has_rx_queue(channel)) {
279d9ab7007SBen Hutchings 		struct efx_rx_queue *rx_queue =
280d9ab7007SBen Hutchings 			efx_channel_get_rx_queue(channel);
281874aeea5SJeff Kirsher 
282ff734ef4SBen Hutchings 		efx_rx_flush_packet(channel);
283cce28794SJon Cooper 		efx_fast_push_rx_descriptors(rx_queue, true);
284d9ab7007SBen Hutchings 	}
285874aeea5SJeff Kirsher 
286c936835cSPeter Dunning 	/* Update BQL */
287c936835cSPeter Dunning 	efx_for_each_channel_tx_queue(tx_queue, channel) {
288c936835cSPeter Dunning 		if (tx_queue->bytes_compl) {
289c936835cSPeter Dunning 			netdev_tx_completed_queue(tx_queue->core_txq,
290c936835cSPeter Dunning 				tx_queue->pkts_compl, tx_queue->bytes_compl);
291c936835cSPeter Dunning 		}
292c936835cSPeter Dunning 	}
293c936835cSPeter Dunning 
294874aeea5SJeff Kirsher 	return spent;
295874aeea5SJeff Kirsher }
296874aeea5SJeff Kirsher 
297874aeea5SJeff Kirsher /* NAPI poll handler
298874aeea5SJeff Kirsher  *
299874aeea5SJeff Kirsher  * NAPI guarantees serialisation of polls of the same device, which
300874aeea5SJeff Kirsher  * provides the guarantee required by efx_process_channel().
301874aeea5SJeff Kirsher  */
302539de7c5SBert Kenward static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
303539de7c5SBert Kenward {
304539de7c5SBert Kenward 	int step = efx->irq_mod_step_us;
305539de7c5SBert Kenward 
306539de7c5SBert Kenward 	if (channel->irq_mod_score < irq_adapt_low_thresh) {
307539de7c5SBert Kenward 		if (channel->irq_moderation_us > step) {
308539de7c5SBert Kenward 			channel->irq_moderation_us -= step;
309539de7c5SBert Kenward 			efx->type->push_irq_moderation(channel);
310539de7c5SBert Kenward 		}
311539de7c5SBert Kenward 	} else if (channel->irq_mod_score > irq_adapt_high_thresh) {
312539de7c5SBert Kenward 		if (channel->irq_moderation_us <
313539de7c5SBert Kenward 		    efx->irq_rx_moderation_us) {
314539de7c5SBert Kenward 			channel->irq_moderation_us += step;
315539de7c5SBert Kenward 			efx->type->push_irq_moderation(channel);
316539de7c5SBert Kenward 		}
317539de7c5SBert Kenward 	}
318539de7c5SBert Kenward 
319539de7c5SBert Kenward 	channel->irq_count = 0;
320539de7c5SBert Kenward 	channel->irq_mod_score = 0;
321539de7c5SBert Kenward }
322539de7c5SBert Kenward 
323874aeea5SJeff Kirsher static int efx_poll(struct napi_struct *napi, int budget)
324874aeea5SJeff Kirsher {
325874aeea5SJeff Kirsher 	struct efx_channel *channel =
326874aeea5SJeff Kirsher 		container_of(napi, struct efx_channel, napi_str);
327874aeea5SJeff Kirsher 	struct efx_nic *efx = channel->efx;
328874aeea5SJeff Kirsher 	int spent;
329874aeea5SJeff Kirsher 
330874aeea5SJeff Kirsher 	netif_vdbg(efx, intr, efx->net_dev,
331874aeea5SJeff Kirsher 		   "channel %d NAPI poll executing on CPU %d\n",
332874aeea5SJeff Kirsher 		   channel->channel, raw_smp_processor_id());
333874aeea5SJeff Kirsher 
334874aeea5SJeff Kirsher 	spent = efx_process_channel(channel, budget);
335874aeea5SJeff Kirsher 
336874aeea5SJeff Kirsher 	if (spent < budget) {
3379d9a6973SBen Hutchings 		if (efx_channel_has_rx_queue(channel) &&
338874aeea5SJeff Kirsher 		    efx->irq_rx_adaptive &&
339874aeea5SJeff Kirsher 		    unlikely(++channel->irq_count == 1000)) {
340539de7c5SBert Kenward 			efx_update_irq_mod(efx, channel);
341874aeea5SJeff Kirsher 		}
342874aeea5SJeff Kirsher 
3433af0f342SEdward Cree #ifdef CONFIG_RFS_ACCEL
3443af0f342SEdward Cree 		/* Perhaps expire some ARFS filters */
3453af0f342SEdward Cree 		schedule_work(&channel->filter_work);
3463af0f342SEdward Cree #endif
347874aeea5SJeff Kirsher 
348874aeea5SJeff Kirsher 		/* There is no race here; although napi_disable() will
349874aeea5SJeff Kirsher 		 * only wait for napi_complete(), this isn't a problem
350514bedbcSBen Hutchings 		 * since efx_nic_eventq_read_ack() will have no effect if
351874aeea5SJeff Kirsher 		 * interrupts have already been disabled.
352874aeea5SJeff Kirsher 		 */
353f820c0acSBert Kenward 		if (napi_complete_done(napi, spent))
354514bedbcSBen Hutchings 			efx_nic_eventq_read_ack(channel);
355874aeea5SJeff Kirsher 	}
356874aeea5SJeff Kirsher 
357874aeea5SJeff Kirsher 	return spent;
358874aeea5SJeff Kirsher }
359874aeea5SJeff Kirsher 
360874aeea5SJeff Kirsher /* Create event queue
361874aeea5SJeff Kirsher  * Event queue memory allocations are done only once.  If the channel
362874aeea5SJeff Kirsher  * is reset, the memory buffer will be reused; this guards against
363874aeea5SJeff Kirsher  * errors during channel reset and also simplifies interrupt handling.
364874aeea5SJeff Kirsher  */
365874aeea5SJeff Kirsher static int efx_probe_eventq(struct efx_channel *channel)
366874aeea5SJeff Kirsher {
367874aeea5SJeff Kirsher 	struct efx_nic *efx = channel->efx;
368874aeea5SJeff Kirsher 	unsigned long entries;
369874aeea5SJeff Kirsher 
37086ee5302SBen Hutchings 	netif_dbg(efx, probe, efx->net_dev,
371874aeea5SJeff Kirsher 		  "chan %d create event queue\n", channel->channel);
372874aeea5SJeff Kirsher 
373874aeea5SJeff Kirsher 	/* Build an event queue with room for one event per tx and rx buffer,
374874aeea5SJeff Kirsher 	 * plus some extra for link state events and MCDI completions. */
375874aeea5SJeff Kirsher 	entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
376e01b16a7SEdward Cree 	EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
377874aeea5SJeff Kirsher 	channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
378874aeea5SJeff Kirsher 
379874aeea5SJeff Kirsher 	return efx_nic_probe_eventq(channel);
380874aeea5SJeff Kirsher }
381874aeea5SJeff Kirsher 
382874aeea5SJeff Kirsher /* Prepare channel's event queue */
383261e4d96SJon Cooper static int efx_init_eventq(struct efx_channel *channel)
384874aeea5SJeff Kirsher {
38515acb1ceSBen Hutchings 	struct efx_nic *efx = channel->efx;
386261e4d96SJon Cooper 	int rc;
387261e4d96SJon Cooper 
388261e4d96SJon Cooper 	EFX_WARN_ON_PARANOID(channel->eventq_init);
389261e4d96SJon Cooper 
39015acb1ceSBen Hutchings 	netif_dbg(efx, drv, efx->net_dev,
391874aeea5SJeff Kirsher 		  "chan %d init event queue\n", channel->channel);
392874aeea5SJeff Kirsher 
393261e4d96SJon Cooper 	rc = efx_nic_init_eventq(channel);
394261e4d96SJon Cooper 	if (rc == 0) {
39515acb1ceSBen Hutchings 		efx->type->push_irq_moderation(channel);
396874aeea5SJeff Kirsher 		channel->eventq_read_ptr = 0;
397be3fc09cSBen Hutchings 		channel->eventq_init = true;
398874aeea5SJeff Kirsher 	}
399261e4d96SJon Cooper 	return rc;
400261e4d96SJon Cooper }
401874aeea5SJeff Kirsher 
4029f2cb71cSBen Hutchings /* Enable event queue processing and NAPI */
40336763266SAlexandre Rames void efx_start_eventq(struct efx_channel *channel)
4049f2cb71cSBen Hutchings {
4059f2cb71cSBen Hutchings 	netif_dbg(channel->efx, ifup, channel->efx->net_dev,
4069f2cb71cSBen Hutchings 		  "chan %d start event queue\n", channel->channel);
4079f2cb71cSBen Hutchings 
408514bedbcSBen Hutchings 	/* Make sure the NAPI handler sees the enabled flag set */
4099f2cb71cSBen Hutchings 	channel->enabled = true;
4109f2cb71cSBen Hutchings 	smp_wmb();
4119f2cb71cSBen Hutchings 
4129f2cb71cSBen Hutchings 	napi_enable(&channel->napi_str);
4139f2cb71cSBen Hutchings 	efx_nic_eventq_read_ack(channel);
4149f2cb71cSBen Hutchings }
4159f2cb71cSBen Hutchings 
4169f2cb71cSBen Hutchings /* Disable event queue processing and NAPI */
41736763266SAlexandre Rames void efx_stop_eventq(struct efx_channel *channel)
4189f2cb71cSBen Hutchings {
4199f2cb71cSBen Hutchings 	if (!channel->enabled)
4209f2cb71cSBen Hutchings 		return;
4219f2cb71cSBen Hutchings 
4229f2cb71cSBen Hutchings 	napi_disable(&channel->napi_str);
4239f2cb71cSBen Hutchings 	channel->enabled = false;
4249f2cb71cSBen Hutchings }
4259f2cb71cSBen Hutchings 
426874aeea5SJeff Kirsher static void efx_fini_eventq(struct efx_channel *channel)
427874aeea5SJeff Kirsher {
428be3fc09cSBen Hutchings 	if (!channel->eventq_init)
429be3fc09cSBen Hutchings 		return;
430be3fc09cSBen Hutchings 
431874aeea5SJeff Kirsher 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
432874aeea5SJeff Kirsher 		  "chan %d fini event queue\n", channel->channel);
433874aeea5SJeff Kirsher 
434874aeea5SJeff Kirsher 	efx_nic_fini_eventq(channel);
435be3fc09cSBen Hutchings 	channel->eventq_init = false;
436874aeea5SJeff Kirsher }
437874aeea5SJeff Kirsher 
438874aeea5SJeff Kirsher static void efx_remove_eventq(struct efx_channel *channel)
439874aeea5SJeff Kirsher {
440874aeea5SJeff Kirsher 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
441874aeea5SJeff Kirsher 		  "chan %d remove event queue\n", channel->channel);
442874aeea5SJeff Kirsher 
443874aeea5SJeff Kirsher 	efx_nic_remove_eventq(channel);
444874aeea5SJeff Kirsher }
445874aeea5SJeff Kirsher 
446874aeea5SJeff Kirsher /**************************************************************************
447874aeea5SJeff Kirsher  *
448874aeea5SJeff Kirsher  * Channel handling
449874aeea5SJeff Kirsher  *
450874aeea5SJeff Kirsher  *************************************************************************/
451874aeea5SJeff Kirsher 
4527f967c01SBen Hutchings /* Allocate and initialise a channel structure. */
453874aeea5SJeff Kirsher static struct efx_channel *
454874aeea5SJeff Kirsher efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
455874aeea5SJeff Kirsher {
456874aeea5SJeff Kirsher 	struct efx_channel *channel;
457874aeea5SJeff Kirsher 	struct efx_rx_queue *rx_queue;
458874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
459874aeea5SJeff Kirsher 	int j;
460874aeea5SJeff Kirsher 
4617f967c01SBen Hutchings 	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
4627f967c01SBen Hutchings 	if (!channel)
4637f967c01SBen Hutchings 		return NULL;
4647f967c01SBen Hutchings 
4657f967c01SBen Hutchings 	channel->efx = efx;
4667f967c01SBen Hutchings 	channel->channel = i;
4677f967c01SBen Hutchings 	channel->type = &efx_default_channel_type;
4687f967c01SBen Hutchings 
4697f967c01SBen Hutchings 	for (j = 0; j < EFX_TXQ_TYPES; j++) {
4707f967c01SBen Hutchings 		tx_queue = &channel->tx_queue[j];
4717f967c01SBen Hutchings 		tx_queue->efx = efx;
4727f967c01SBen Hutchings 		tx_queue->queue = i * EFX_TXQ_TYPES + j;
4737f967c01SBen Hutchings 		tx_queue->channel = channel;
4747f967c01SBen Hutchings 	}
4757f967c01SBen Hutchings 
4763af0f342SEdward Cree #ifdef CONFIG_RFS_ACCEL
4773af0f342SEdward Cree 	INIT_WORK(&channel->filter_work, efx_filter_rfs_expire);
4783af0f342SEdward Cree #endif
4793af0f342SEdward Cree 
4807f967c01SBen Hutchings 	rx_queue = &channel->rx_queue;
4817f967c01SBen Hutchings 	rx_queue->efx = efx;
4827aa1402eSKees Cook 	timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
4837f967c01SBen Hutchings 
4847f967c01SBen Hutchings 	return channel;
4857f967c01SBen Hutchings }
4867f967c01SBen Hutchings 
4877f967c01SBen Hutchings /* Allocate and initialise a channel structure, copying parameters
4887f967c01SBen Hutchings  * (but not resources) from an old channel structure.
4897f967c01SBen Hutchings  */
4907f967c01SBen Hutchings static struct efx_channel *
4917f967c01SBen Hutchings efx_copy_channel(const struct efx_channel *old_channel)
4927f967c01SBen Hutchings {
4937f967c01SBen Hutchings 	struct efx_channel *channel;
4947f967c01SBen Hutchings 	struct efx_rx_queue *rx_queue;
4957f967c01SBen Hutchings 	struct efx_tx_queue *tx_queue;
4967f967c01SBen Hutchings 	int j;
4977f967c01SBen Hutchings 
498874aeea5SJeff Kirsher 	channel = kmalloc(sizeof(*channel), GFP_KERNEL);
499874aeea5SJeff Kirsher 	if (!channel)
500874aeea5SJeff Kirsher 		return NULL;
501874aeea5SJeff Kirsher 
502874aeea5SJeff Kirsher 	*channel = *old_channel;
503874aeea5SJeff Kirsher 
504874aeea5SJeff Kirsher 	channel->napi_dev = NULL;
50546d054f8SBert Kenward 	INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
50646d054f8SBert Kenward 	channel->napi_str.napi_id = 0;
50746d054f8SBert Kenward 	channel->napi_str.state = 0;
508874aeea5SJeff Kirsher 	memset(&channel->eventq, 0, sizeof(channel->eventq));
509874aeea5SJeff Kirsher 
510874aeea5SJeff Kirsher 	for (j = 0; j < EFX_TXQ_TYPES; j++) {
511874aeea5SJeff Kirsher 		tx_queue = &channel->tx_queue[j];
512874aeea5SJeff Kirsher 		if (tx_queue->channel)
513874aeea5SJeff Kirsher 			tx_queue->channel = channel;
514874aeea5SJeff Kirsher 		tx_queue->buffer = NULL;
515874aeea5SJeff Kirsher 		memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
516874aeea5SJeff Kirsher 	}
517874aeea5SJeff Kirsher 
518874aeea5SJeff Kirsher 	rx_queue = &channel->rx_queue;
5197f967c01SBen Hutchings 	rx_queue->buffer = NULL;
5207f967c01SBen Hutchings 	memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
5217aa1402eSKees Cook 	timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
5223af0f342SEdward Cree #ifdef CONFIG_RFS_ACCEL
5233af0f342SEdward Cree 	INIT_WORK(&channel->filter_work, efx_filter_rfs_expire);
5243af0f342SEdward Cree #endif
525874aeea5SJeff Kirsher 
526874aeea5SJeff Kirsher 	return channel;
527874aeea5SJeff Kirsher }
528874aeea5SJeff Kirsher 
529874aeea5SJeff Kirsher static int efx_probe_channel(struct efx_channel *channel)
530874aeea5SJeff Kirsher {
531874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
532874aeea5SJeff Kirsher 	struct efx_rx_queue *rx_queue;
533874aeea5SJeff Kirsher 	int rc;
534874aeea5SJeff Kirsher 
535874aeea5SJeff Kirsher 	netif_dbg(channel->efx, probe, channel->efx->net_dev,
536874aeea5SJeff Kirsher 		  "creating channel %d\n", channel->channel);
537874aeea5SJeff Kirsher 
5387f967c01SBen Hutchings 	rc = channel->type->pre_probe(channel);
5397f967c01SBen Hutchings 	if (rc)
5407f967c01SBen Hutchings 		goto fail;
5417f967c01SBen Hutchings 
542874aeea5SJeff Kirsher 	rc = efx_probe_eventq(channel);
543874aeea5SJeff Kirsher 	if (rc)
5447f967c01SBen Hutchings 		goto fail;
545874aeea5SJeff Kirsher 
546874aeea5SJeff Kirsher 	efx_for_each_channel_tx_queue(tx_queue, channel) {
547874aeea5SJeff Kirsher 		rc = efx_probe_tx_queue(tx_queue);
548874aeea5SJeff Kirsher 		if (rc)
5497f967c01SBen Hutchings 			goto fail;
550874aeea5SJeff Kirsher 	}
551874aeea5SJeff Kirsher 
552874aeea5SJeff Kirsher 	efx_for_each_channel_rx_queue(rx_queue, channel) {
553874aeea5SJeff Kirsher 		rc = efx_probe_rx_queue(rx_queue);
554874aeea5SJeff Kirsher 		if (rc)
5557f967c01SBen Hutchings 			goto fail;
556874aeea5SJeff Kirsher 	}
557874aeea5SJeff Kirsher 
558874aeea5SJeff Kirsher 	return 0;
559874aeea5SJeff Kirsher 
5607f967c01SBen Hutchings fail:
5617f967c01SBen Hutchings 	efx_remove_channel(channel);
562874aeea5SJeff Kirsher 	return rc;
563874aeea5SJeff Kirsher }
564874aeea5SJeff Kirsher 
5657f967c01SBen Hutchings static void
5667f967c01SBen Hutchings efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
5677f967c01SBen Hutchings {
5687f967c01SBen Hutchings 	struct efx_nic *efx = channel->efx;
5697f967c01SBen Hutchings 	const char *type;
5707f967c01SBen Hutchings 	int number;
5717f967c01SBen Hutchings 
5727f967c01SBen Hutchings 	number = channel->channel;
5737f967c01SBen Hutchings 	if (efx->tx_channel_offset == 0) {
5747f967c01SBen Hutchings 		type = "";
5757f967c01SBen Hutchings 	} else if (channel->channel < efx->tx_channel_offset) {
5767f967c01SBen Hutchings 		type = "-rx";
5777f967c01SBen Hutchings 	} else {
5787f967c01SBen Hutchings 		type = "-tx";
5797f967c01SBen Hutchings 		number -= efx->tx_channel_offset;
5807f967c01SBen Hutchings 	}
5817f967c01SBen Hutchings 	snprintf(buf, len, "%s%s-%d", efx->name, type, number);
5827f967c01SBen Hutchings }
583874aeea5SJeff Kirsher 
584874aeea5SJeff Kirsher static void efx_set_channel_names(struct efx_nic *efx)
585874aeea5SJeff Kirsher {
586874aeea5SJeff Kirsher 	struct efx_channel *channel;
587874aeea5SJeff Kirsher 
5887f967c01SBen Hutchings 	efx_for_each_channel(channel, efx)
5897f967c01SBen Hutchings 		channel->type->get_name(channel,
590d8291187SBen Hutchings 					efx->msi_context[channel->channel].name,
591d8291187SBen Hutchings 					sizeof(efx->msi_context[0].name));
592874aeea5SJeff Kirsher }
593874aeea5SJeff Kirsher 
594874aeea5SJeff Kirsher static int efx_probe_channels(struct efx_nic *efx)
595874aeea5SJeff Kirsher {
596874aeea5SJeff Kirsher 	struct efx_channel *channel;
597874aeea5SJeff Kirsher 	int rc;
598874aeea5SJeff Kirsher 
599874aeea5SJeff Kirsher 	/* Restart special buffer allocation */
600874aeea5SJeff Kirsher 	efx->next_buffer_table = 0;
601874aeea5SJeff Kirsher 
602c92aaff1SBen Hutchings 	/* Probe channels in reverse, so that any 'extra' channels
603c92aaff1SBen Hutchings 	 * use the start of the buffer table. This allows the traffic
604c92aaff1SBen Hutchings 	 * channels to be resized without moving them or wasting the
605c92aaff1SBen Hutchings 	 * entries before them.
606c92aaff1SBen Hutchings 	 */
607c92aaff1SBen Hutchings 	efx_for_each_channel_rev(channel, efx) {
608874aeea5SJeff Kirsher 		rc = efx_probe_channel(channel);
609874aeea5SJeff Kirsher 		if (rc) {
610874aeea5SJeff Kirsher 			netif_err(efx, probe, efx->net_dev,
611874aeea5SJeff Kirsher 				  "failed to create channel %d\n",
612874aeea5SJeff Kirsher 				  channel->channel);
613874aeea5SJeff Kirsher 			goto fail;
614874aeea5SJeff Kirsher 		}
615874aeea5SJeff Kirsher 	}
616874aeea5SJeff Kirsher 	efx_set_channel_names(efx);
617874aeea5SJeff Kirsher 
618874aeea5SJeff Kirsher 	return 0;
619874aeea5SJeff Kirsher 
620874aeea5SJeff Kirsher fail:
621874aeea5SJeff Kirsher 	efx_remove_channels(efx);
622874aeea5SJeff Kirsher 	return rc;
623874aeea5SJeff Kirsher }
624874aeea5SJeff Kirsher 
625874aeea5SJeff Kirsher /* Channels are shutdown and reinitialised whilst the NIC is running
626874aeea5SJeff Kirsher  * to propagate configuration changes (mtu, checksum offload), or
627874aeea5SJeff Kirsher  * to clear hardware error conditions
628874aeea5SJeff Kirsher  */
6299f2cb71cSBen Hutchings static void efx_start_datapath(struct efx_nic *efx)
630874aeea5SJeff Kirsher {
631ebfcd0fdSAndrew Rybchenko 	netdev_features_t old_features = efx->net_dev->features;
63285740cdfSBen Hutchings 	bool old_rx_scatter = efx->rx_scatter;
633874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
634874aeea5SJeff Kirsher 	struct efx_rx_queue *rx_queue;
635874aeea5SJeff Kirsher 	struct efx_channel *channel;
63685740cdfSBen Hutchings 	size_t rx_buf_len;
637874aeea5SJeff Kirsher 
638874aeea5SJeff Kirsher 	/* Calculate the rx buffer allocation parameters required to
639874aeea5SJeff Kirsher 	 * support the current MTU, including padding for header
640874aeea5SJeff Kirsher 	 * alignment and overruns.
641874aeea5SJeff Kirsher 	 */
64243a3739dSJon Cooper 	efx->rx_dma_len = (efx->rx_prefix_size +
643874aeea5SJeff Kirsher 			   EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
644874aeea5SJeff Kirsher 			   efx->type->rx_buffer_padding);
64585740cdfSBen Hutchings 	rx_buf_len = (sizeof(struct efx_rx_page_state) +
6462ec03014SAndrew Rybchenko 		      efx->rx_ip_align + efx->rx_dma_len);
64785740cdfSBen Hutchings 	if (rx_buf_len <= PAGE_SIZE) {
648e8c68c0aSJon Cooper 		efx->rx_scatter = efx->type->always_rx_scatter;
64985740cdfSBen Hutchings 		efx->rx_buffer_order = 0;
65085740cdfSBen Hutchings 	} else if (efx->type->can_rx_scatter) {
651950c54dfSBen Hutchings 		BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
65285740cdfSBen Hutchings 		BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
653950c54dfSBen Hutchings 			     2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
654950c54dfSBen Hutchings 				       EFX_RX_BUF_ALIGNMENT) >
655950c54dfSBen Hutchings 			     PAGE_SIZE);
65685740cdfSBen Hutchings 		efx->rx_scatter = true;
65785740cdfSBen Hutchings 		efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
65885740cdfSBen Hutchings 		efx->rx_buffer_order = 0;
65985740cdfSBen Hutchings 	} else {
66085740cdfSBen Hutchings 		efx->rx_scatter = false;
66185740cdfSBen Hutchings 		efx->rx_buffer_order = get_order(rx_buf_len);
66285740cdfSBen Hutchings 	}
66385740cdfSBen Hutchings 
6641648a23fSDaniel Pieczko 	efx_rx_config_page_split(efx);
6651648a23fSDaniel Pieczko 	if (efx->rx_buffer_order)
6661648a23fSDaniel Pieczko 		netif_dbg(efx, drv, efx->net_dev,
6671648a23fSDaniel Pieczko 			  "RX buf len=%u; page order=%u batch=%u\n",
6681648a23fSDaniel Pieczko 			  efx->rx_dma_len, efx->rx_buffer_order,
6691648a23fSDaniel Pieczko 			  efx->rx_pages_per_batch);
6701648a23fSDaniel Pieczko 	else
6711648a23fSDaniel Pieczko 		netif_dbg(efx, drv, efx->net_dev,
6721648a23fSDaniel Pieczko 			  "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
6731648a23fSDaniel Pieczko 			  efx->rx_dma_len, efx->rx_page_buf_step,
6741648a23fSDaniel Pieczko 			  efx->rx_bufs_per_page, efx->rx_pages_per_batch);
6752768935aSDaniel Pieczko 
676ebfcd0fdSAndrew Rybchenko 	/* Restore previously fixed features in hw_features and remove
677ebfcd0fdSAndrew Rybchenko 	 * features which are fixed now
678ebfcd0fdSAndrew Rybchenko 	 */
679ebfcd0fdSAndrew Rybchenko 	efx->net_dev->hw_features |= efx->net_dev->features;
680ebfcd0fdSAndrew Rybchenko 	efx->net_dev->hw_features &= ~efx->fixed_features;
681ebfcd0fdSAndrew Rybchenko 	efx->net_dev->features |= efx->fixed_features;
682ebfcd0fdSAndrew Rybchenko 	if (efx->net_dev->features != old_features)
683ebfcd0fdSAndrew Rybchenko 		netdev_features_change(efx->net_dev);
684ebfcd0fdSAndrew Rybchenko 
685e8c68c0aSJon Cooper 	/* RX filters may also have scatter-enabled flags */
68685740cdfSBen Hutchings 	if (efx->rx_scatter != old_rx_scatter)
687add72477SBen Hutchings 		efx->type->filter_update_rx_scatter(efx);
688874aeea5SJeff Kirsher 
68914bf718fSBen Hutchings 	/* We must keep at least one descriptor in a TX ring empty.
69014bf718fSBen Hutchings 	 * We could avoid this when the queue size does not exactly
69114bf718fSBen Hutchings 	 * match the hardware ring size, but it's not that important.
69214bf718fSBen Hutchings 	 * Therefore we stop the queue when one more skb might fill
69314bf718fSBen Hutchings 	 * the ring completely.  We wake it when half way back to
69414bf718fSBen Hutchings 	 * empty.
69514bf718fSBen Hutchings 	 */
69614bf718fSBen Hutchings 	efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
69714bf718fSBen Hutchings 	efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
69814bf718fSBen Hutchings 
699874aeea5SJeff Kirsher 	/* Initialise the channels */
700874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx) {
7013881d8abSAlexandre Rames 		efx_for_each_channel_tx_queue(tx_queue, channel) {
702874aeea5SJeff Kirsher 			efx_init_tx_queue(tx_queue);
7033881d8abSAlexandre Rames 			atomic_inc(&efx->active_queues);
7043881d8abSAlexandre Rames 		}
705874aeea5SJeff Kirsher 
7069f2cb71cSBen Hutchings 		efx_for_each_channel_rx_queue(rx_queue, channel) {
707874aeea5SJeff Kirsher 			efx_init_rx_queue(rx_queue);
7083881d8abSAlexandre Rames 			atomic_inc(&efx->active_queues);
709cce28794SJon Cooper 			efx_stop_eventq(channel);
710cce28794SJon Cooper 			efx_fast_push_rx_descriptors(rx_queue, false);
711cce28794SJon Cooper 			efx_start_eventq(channel);
7129f2cb71cSBen Hutchings 		}
713874aeea5SJeff Kirsher 
71485740cdfSBen Hutchings 		WARN_ON(channel->rx_pkt_n_frags);
715874aeea5SJeff Kirsher 	}
7169f2cb71cSBen Hutchings 
7172ea4dc28SAlexandre Rames 	efx_ptp_start_datapath(efx);
7182ea4dc28SAlexandre Rames 
7199f2cb71cSBen Hutchings 	if (netif_device_present(efx->net_dev))
7209f2cb71cSBen Hutchings 		netif_tx_wake_all_queues(efx->net_dev);
721874aeea5SJeff Kirsher }
722874aeea5SJeff Kirsher 
7239f2cb71cSBen Hutchings static void efx_stop_datapath(struct efx_nic *efx)
724874aeea5SJeff Kirsher {
725874aeea5SJeff Kirsher 	struct efx_channel *channel;
726874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
727874aeea5SJeff Kirsher 	struct efx_rx_queue *rx_queue;
728874aeea5SJeff Kirsher 	int rc;
729874aeea5SJeff Kirsher 
730874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
731874aeea5SJeff Kirsher 	BUG_ON(efx->port_enabled);
732874aeea5SJeff Kirsher 
7332ea4dc28SAlexandre Rames 	efx_ptp_stop_datapath(efx);
7342ea4dc28SAlexandre Rames 
735d8aec745SBen Hutchings 	/* Stop RX refill */
736d8aec745SBen Hutchings 	efx_for_each_channel(channel, efx) {
737d8aec745SBen Hutchings 		efx_for_each_channel_rx_queue(rx_queue, channel)
738d8aec745SBen Hutchings 			rx_queue->refill_enabled = false;
739d8aec745SBen Hutchings 	}
740d8aec745SBen Hutchings 
741874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx) {
7429f2cb71cSBen Hutchings 		/* RX packet processing is pipelined, so wait for the
7439f2cb71cSBen Hutchings 		 * NAPI handler to complete.  At least event queue 0
7449f2cb71cSBen Hutchings 		 * might be kept active by non-data events, so don't
7459f2cb71cSBen Hutchings 		 * use napi_synchronize() but actually disable NAPI
7469f2cb71cSBen Hutchings 		 * temporarily.
7479f2cb71cSBen Hutchings 		 */
7489f2cb71cSBen Hutchings 		if (efx_channel_has_rx_queue(channel)) {
7499f2cb71cSBen Hutchings 			efx_stop_eventq(channel);
7509f2cb71cSBen Hutchings 			efx_start_eventq(channel);
7519f2cb71cSBen Hutchings 		}
752e42c3d85SBen Hutchings 	}
753874aeea5SJeff Kirsher 
754e42c3d85SBen Hutchings 	rc = efx->type->fini_dmaq(efx);
7555a6681e2SEdward Cree 	if (rc) {
756e42c3d85SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
757e42c3d85SBen Hutchings 	} else {
758e42c3d85SBen Hutchings 		netif_dbg(efx, drv, efx->net_dev,
759e42c3d85SBen Hutchings 			  "successfully flushed all queues\n");
760e42c3d85SBen Hutchings 	}
761e42c3d85SBen Hutchings 
762e42c3d85SBen Hutchings 	efx_for_each_channel(channel, efx) {
763874aeea5SJeff Kirsher 		efx_for_each_channel_rx_queue(rx_queue, channel)
764874aeea5SJeff Kirsher 			efx_fini_rx_queue(rx_queue);
765874aeea5SJeff Kirsher 		efx_for_each_possible_channel_tx_queue(tx_queue, channel)
766874aeea5SJeff Kirsher 			efx_fini_tx_queue(tx_queue);
767874aeea5SJeff Kirsher 	}
768874aeea5SJeff Kirsher }
769874aeea5SJeff Kirsher 
770874aeea5SJeff Kirsher static void efx_remove_channel(struct efx_channel *channel)
771874aeea5SJeff Kirsher {
772874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
773874aeea5SJeff Kirsher 	struct efx_rx_queue *rx_queue;
774874aeea5SJeff Kirsher 
775874aeea5SJeff Kirsher 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
776874aeea5SJeff Kirsher 		  "destroy chan %d\n", channel->channel);
777874aeea5SJeff Kirsher 
778874aeea5SJeff Kirsher 	efx_for_each_channel_rx_queue(rx_queue, channel)
779874aeea5SJeff Kirsher 		efx_remove_rx_queue(rx_queue);
780874aeea5SJeff Kirsher 	efx_for_each_possible_channel_tx_queue(tx_queue, channel)
781874aeea5SJeff Kirsher 		efx_remove_tx_queue(tx_queue);
782874aeea5SJeff Kirsher 	efx_remove_eventq(channel);
783c31e5f9fSStuart Hodgson 	channel->type->post_remove(channel);
784874aeea5SJeff Kirsher }
785874aeea5SJeff Kirsher 
786874aeea5SJeff Kirsher static void efx_remove_channels(struct efx_nic *efx)
787874aeea5SJeff Kirsher {
788874aeea5SJeff Kirsher 	struct efx_channel *channel;
789874aeea5SJeff Kirsher 
790874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx)
791874aeea5SJeff Kirsher 		efx_remove_channel(channel);
792874aeea5SJeff Kirsher }
793874aeea5SJeff Kirsher 
794874aeea5SJeff Kirsher int
795874aeea5SJeff Kirsher efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
796874aeea5SJeff Kirsher {
797874aeea5SJeff Kirsher 	struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
798874aeea5SJeff Kirsher 	u32 old_rxq_entries, old_txq_entries;
7997f967c01SBen Hutchings 	unsigned i, next_buffer_table = 0;
800261e4d96SJon Cooper 	int rc, rc2;
8018b7325b4SBen Hutchings 
8028b7325b4SBen Hutchings 	rc = efx_check_disabled(efx);
8038b7325b4SBen Hutchings 	if (rc)
8048b7325b4SBen Hutchings 		return rc;
8057f967c01SBen Hutchings 
8067f967c01SBen Hutchings 	/* Not all channels should be reallocated. We must avoid
8077f967c01SBen Hutchings 	 * reallocating their buffer table entries.
8087f967c01SBen Hutchings 	 */
8097f967c01SBen Hutchings 	efx_for_each_channel(channel, efx) {
8107f967c01SBen Hutchings 		struct efx_rx_queue *rx_queue;
8117f967c01SBen Hutchings 		struct efx_tx_queue *tx_queue;
8127f967c01SBen Hutchings 
8137f967c01SBen Hutchings 		if (channel->type->copy)
8147f967c01SBen Hutchings 			continue;
8157f967c01SBen Hutchings 		next_buffer_table = max(next_buffer_table,
8167f967c01SBen Hutchings 					channel->eventq.index +
8177f967c01SBen Hutchings 					channel->eventq.entries);
8187f967c01SBen Hutchings 		efx_for_each_channel_rx_queue(rx_queue, channel)
8197f967c01SBen Hutchings 			next_buffer_table = max(next_buffer_table,
8207f967c01SBen Hutchings 						rx_queue->rxd.index +
8217f967c01SBen Hutchings 						rx_queue->rxd.entries);
8227f967c01SBen Hutchings 		efx_for_each_channel_tx_queue(tx_queue, channel)
8237f967c01SBen Hutchings 			next_buffer_table = max(next_buffer_table,
8247f967c01SBen Hutchings 						tx_queue->txd.index +
8257f967c01SBen Hutchings 						tx_queue->txd.entries);
8267f967c01SBen Hutchings 	}
827874aeea5SJeff Kirsher 
82829c69a48SBen Hutchings 	efx_device_detach_sync(efx);
829874aeea5SJeff Kirsher 	efx_stop_all(efx);
830d8291187SBen Hutchings 	efx_soft_disable_interrupts(efx);
831874aeea5SJeff Kirsher 
8327f967c01SBen Hutchings 	/* Clone channels (where possible) */
833874aeea5SJeff Kirsher 	memset(other_channel, 0, sizeof(other_channel));
834874aeea5SJeff Kirsher 	for (i = 0; i < efx->n_channels; i++) {
8357f967c01SBen Hutchings 		channel = efx->channel[i];
8367f967c01SBen Hutchings 		if (channel->type->copy)
8377f967c01SBen Hutchings 			channel = channel->type->copy(channel);
838874aeea5SJeff Kirsher 		if (!channel) {
839874aeea5SJeff Kirsher 			rc = -ENOMEM;
840874aeea5SJeff Kirsher 			goto out;
841874aeea5SJeff Kirsher 		}
842874aeea5SJeff Kirsher 		other_channel[i] = channel;
843874aeea5SJeff Kirsher 	}
844874aeea5SJeff Kirsher 
845874aeea5SJeff Kirsher 	/* Swap entry counts and channel pointers */
846874aeea5SJeff Kirsher 	old_rxq_entries = efx->rxq_entries;
847874aeea5SJeff Kirsher 	old_txq_entries = efx->txq_entries;
848874aeea5SJeff Kirsher 	efx->rxq_entries = rxq_entries;
849874aeea5SJeff Kirsher 	efx->txq_entries = txq_entries;
850874aeea5SJeff Kirsher 	for (i = 0; i < efx->n_channels; i++) {
851874aeea5SJeff Kirsher 		channel = efx->channel[i];
852874aeea5SJeff Kirsher 		efx->channel[i] = other_channel[i];
853874aeea5SJeff Kirsher 		other_channel[i] = channel;
854874aeea5SJeff Kirsher 	}
855874aeea5SJeff Kirsher 
8567f967c01SBen Hutchings 	/* Restart buffer table allocation */
8577f967c01SBen Hutchings 	efx->next_buffer_table = next_buffer_table;
8587f967c01SBen Hutchings 
8597f967c01SBen Hutchings 	for (i = 0; i < efx->n_channels; i++) {
8607f967c01SBen Hutchings 		channel = efx->channel[i];
8617f967c01SBen Hutchings 		if (!channel->type->copy)
8627f967c01SBen Hutchings 			continue;
8637f967c01SBen Hutchings 		rc = efx_probe_channel(channel);
864874aeea5SJeff Kirsher 		if (rc)
865874aeea5SJeff Kirsher 			goto rollback;
8667f967c01SBen Hutchings 		efx_init_napi_channel(efx->channel[i]);
867874aeea5SJeff Kirsher 	}
868874aeea5SJeff Kirsher 
8697f967c01SBen Hutchings out:
8707f967c01SBen Hutchings 	/* Destroy unused channel structures */
8717f967c01SBen Hutchings 	for (i = 0; i < efx->n_channels; i++) {
8727f967c01SBen Hutchings 		channel = other_channel[i];
8737f967c01SBen Hutchings 		if (channel && channel->type->copy) {
8747f967c01SBen Hutchings 			efx_fini_napi_channel(channel);
8757f967c01SBen Hutchings 			efx_remove_channel(channel);
8767f967c01SBen Hutchings 			kfree(channel);
8777f967c01SBen Hutchings 		}
8787f967c01SBen Hutchings 	}
8797f967c01SBen Hutchings 
880261e4d96SJon Cooper 	rc2 = efx_soft_enable_interrupts(efx);
881261e4d96SJon Cooper 	if (rc2) {
882261e4d96SJon Cooper 		rc = rc ? rc : rc2;
883261e4d96SJon Cooper 		netif_err(efx, drv, efx->net_dev,
884261e4d96SJon Cooper 			  "unable to restart interrupts on channel reallocation\n");
885261e4d96SJon Cooper 		efx_schedule_reset(efx, RESET_TYPE_DISABLE);
886261e4d96SJon Cooper 	} else {
887874aeea5SJeff Kirsher 		efx_start_all(efx);
8889c568fd8SPeter Dunning 		efx_device_attach_if_not_resetting(efx);
889261e4d96SJon Cooper 	}
890874aeea5SJeff Kirsher 	return rc;
891874aeea5SJeff Kirsher 
892874aeea5SJeff Kirsher rollback:
893874aeea5SJeff Kirsher 	/* Swap back */
894874aeea5SJeff Kirsher 	efx->rxq_entries = old_rxq_entries;
895874aeea5SJeff Kirsher 	efx->txq_entries = old_txq_entries;
896874aeea5SJeff Kirsher 	for (i = 0; i < efx->n_channels; i++) {
897874aeea5SJeff Kirsher 		channel = efx->channel[i];
898874aeea5SJeff Kirsher 		efx->channel[i] = other_channel[i];
899874aeea5SJeff Kirsher 		other_channel[i] = channel;
900874aeea5SJeff Kirsher 	}
901874aeea5SJeff Kirsher 	goto out;
902874aeea5SJeff Kirsher }
903874aeea5SJeff Kirsher 
904874aeea5SJeff Kirsher void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
905874aeea5SJeff Kirsher {
906874aeea5SJeff Kirsher 	mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
907874aeea5SJeff Kirsher }
908874aeea5SJeff Kirsher 
909e7345ba3Skbuild test robot static bool efx_default_channel_want_txqs(struct efx_channel *channel)
9102935e3c3SEdward Cree {
9112935e3c3SEdward Cree 	return channel->channel - channel->efx->tx_channel_offset <
9122935e3c3SEdward Cree 		channel->efx->n_tx_channels;
9132935e3c3SEdward Cree }
9142935e3c3SEdward Cree 
9157f967c01SBen Hutchings static const struct efx_channel_type efx_default_channel_type = {
9167f967c01SBen Hutchings 	.pre_probe		= efx_channel_dummy_op_int,
917c31e5f9fSStuart Hodgson 	.post_remove		= efx_channel_dummy_op_void,
9187f967c01SBen Hutchings 	.get_name		= efx_get_channel_name,
9197f967c01SBen Hutchings 	.copy			= efx_copy_channel,
9202935e3c3SEdward Cree 	.want_txqs		= efx_default_channel_want_txqs,
9217f967c01SBen Hutchings 	.keep_eventq		= false,
9222935e3c3SEdward Cree 	.want_pio		= true,
9237f967c01SBen Hutchings };
9247f967c01SBen Hutchings 
9257f967c01SBen Hutchings int efx_channel_dummy_op_int(struct efx_channel *channel)
9267f967c01SBen Hutchings {
9277f967c01SBen Hutchings 	return 0;
9287f967c01SBen Hutchings }
9297f967c01SBen Hutchings 
930c31e5f9fSStuart Hodgson void efx_channel_dummy_op_void(struct efx_channel *channel)
931c31e5f9fSStuart Hodgson {
932c31e5f9fSStuart Hodgson }
933c31e5f9fSStuart Hodgson 
934874aeea5SJeff Kirsher /**************************************************************************
935874aeea5SJeff Kirsher  *
936874aeea5SJeff Kirsher  * Port handling
937874aeea5SJeff Kirsher  *
938874aeea5SJeff Kirsher  **************************************************************************/
939874aeea5SJeff Kirsher 
940874aeea5SJeff Kirsher /* This ensures that the kernel is kept informed (via
941874aeea5SJeff Kirsher  * netif_carrier_on/off) of the link status, and also maintains the
942874aeea5SJeff Kirsher  * link status's stop on the port's TX queue.
943874aeea5SJeff Kirsher  */
944874aeea5SJeff Kirsher void efx_link_status_changed(struct efx_nic *efx)
945874aeea5SJeff Kirsher {
946874aeea5SJeff Kirsher 	struct efx_link_state *link_state = &efx->link_state;
947874aeea5SJeff Kirsher 
948874aeea5SJeff Kirsher 	/* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
949874aeea5SJeff Kirsher 	 * that no events are triggered between unregister_netdev() and the
950874aeea5SJeff Kirsher 	 * driver unloading. A more general condition is that NETDEV_CHANGE
951874aeea5SJeff Kirsher 	 * can only be generated between NETDEV_UP and NETDEV_DOWN */
952874aeea5SJeff Kirsher 	if (!netif_running(efx->net_dev))
953874aeea5SJeff Kirsher 		return;
954874aeea5SJeff Kirsher 
955874aeea5SJeff Kirsher 	if (link_state->up != netif_carrier_ok(efx->net_dev)) {
956874aeea5SJeff Kirsher 		efx->n_link_state_changes++;
957874aeea5SJeff Kirsher 
958874aeea5SJeff Kirsher 		if (link_state->up)
959874aeea5SJeff Kirsher 			netif_carrier_on(efx->net_dev);
960874aeea5SJeff Kirsher 		else
961874aeea5SJeff Kirsher 			netif_carrier_off(efx->net_dev);
962874aeea5SJeff Kirsher 	}
963874aeea5SJeff Kirsher 
964874aeea5SJeff Kirsher 	/* Status message for kernel log */
9652aa9ef11SBen Hutchings 	if (link_state->up)
966874aeea5SJeff Kirsher 		netif_info(efx, link, efx->net_dev,
967964e6135SBen Hutchings 			   "link up at %uMbps %s-duplex (MTU %d)\n",
968874aeea5SJeff Kirsher 			   link_state->speed, link_state->fd ? "full" : "half",
969964e6135SBen Hutchings 			   efx->net_dev->mtu);
9702aa9ef11SBen Hutchings 	else
971874aeea5SJeff Kirsher 		netif_info(efx, link, efx->net_dev, "link down\n");
972874aeea5SJeff Kirsher }
973874aeea5SJeff Kirsher 
974c2ab85d2SEdward Cree void efx_link_set_advertising(struct efx_nic *efx,
975c2ab85d2SEdward Cree 			      const unsigned long *advertising)
976874aeea5SJeff Kirsher {
977c2ab85d2SEdward Cree 	memcpy(efx->link_advertising, advertising,
978c2ab85d2SEdward Cree 	       sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
979c2ab85d2SEdward Cree 
980c2ab85d2SEdward Cree 	efx->link_advertising[0] |= ADVERTISED_Autoneg;
981c2ab85d2SEdward Cree 	if (advertising[0] & ADVERTISED_Pause)
982874aeea5SJeff Kirsher 		efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
983874aeea5SJeff Kirsher 	else
984874aeea5SJeff Kirsher 		efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
985c2ab85d2SEdward Cree 	if (advertising[0] & ADVERTISED_Asym_Pause)
986874aeea5SJeff Kirsher 		efx->wanted_fc ^= EFX_FC_TX;
987874aeea5SJeff Kirsher }
988c2ab85d2SEdward Cree 
989c2ab85d2SEdward Cree /* Equivalent to efx_link_set_advertising with all-zeroes, except does not
990c2ab85d2SEdward Cree  * force the Autoneg bit on.
991c2ab85d2SEdward Cree  */
992c2ab85d2SEdward Cree void efx_link_clear_advertising(struct efx_nic *efx)
993c2ab85d2SEdward Cree {
994c2ab85d2SEdward Cree 	bitmap_zero(efx->link_advertising, __ETHTOOL_LINK_MODE_MASK_NBITS);
995c2ab85d2SEdward Cree 	efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
996874aeea5SJeff Kirsher }
997874aeea5SJeff Kirsher 
998874aeea5SJeff Kirsher void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
999874aeea5SJeff Kirsher {
1000874aeea5SJeff Kirsher 	efx->wanted_fc = wanted_fc;
1001c2ab85d2SEdward Cree 	if (efx->link_advertising[0]) {
1002874aeea5SJeff Kirsher 		if (wanted_fc & EFX_FC_RX)
1003c2ab85d2SEdward Cree 			efx->link_advertising[0] |= (ADVERTISED_Pause |
1004874aeea5SJeff Kirsher 						     ADVERTISED_Asym_Pause);
1005874aeea5SJeff Kirsher 		else
1006c2ab85d2SEdward Cree 			efx->link_advertising[0] &= ~(ADVERTISED_Pause |
1007874aeea5SJeff Kirsher 						      ADVERTISED_Asym_Pause);
1008874aeea5SJeff Kirsher 		if (wanted_fc & EFX_FC_TX)
1009c2ab85d2SEdward Cree 			efx->link_advertising[0] ^= ADVERTISED_Asym_Pause;
1010874aeea5SJeff Kirsher 	}
1011874aeea5SJeff Kirsher }
1012874aeea5SJeff Kirsher 
1013874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx);
1014874aeea5SJeff Kirsher 
10150d322413SEdward Cree /* We assume that efx->type->reconfigure_mac will always try to sync RX
10160d322413SEdward Cree  * filters and therefore needs to read-lock the filter table against freeing
10170d322413SEdward Cree  */
10180d322413SEdward Cree void efx_mac_reconfigure(struct efx_nic *efx)
10190d322413SEdward Cree {
10200d322413SEdward Cree 	down_read(&efx->filter_sem);
10210d322413SEdward Cree 	efx->type->reconfigure_mac(efx);
10220d322413SEdward Cree 	up_read(&efx->filter_sem);
10230d322413SEdward Cree }
10240d322413SEdward Cree 
1025874aeea5SJeff Kirsher /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
1026874aeea5SJeff Kirsher  * the MAC appropriately. All other PHY configuration changes are pushed
1027874aeea5SJeff Kirsher  * through phy_op->set_settings(), and pushed asynchronously to the MAC
1028874aeea5SJeff Kirsher  * through efx_monitor().
1029874aeea5SJeff Kirsher  *
1030874aeea5SJeff Kirsher  * Callers must hold the mac_lock
1031874aeea5SJeff Kirsher  */
1032874aeea5SJeff Kirsher int __efx_reconfigure_port(struct efx_nic *efx)
1033874aeea5SJeff Kirsher {
1034874aeea5SJeff Kirsher 	enum efx_phy_mode phy_mode;
1035874aeea5SJeff Kirsher 	int rc;
1036874aeea5SJeff Kirsher 
1037874aeea5SJeff Kirsher 	WARN_ON(!mutex_is_locked(&efx->mac_lock));
1038874aeea5SJeff Kirsher 
1039874aeea5SJeff Kirsher 	/* Disable PHY transmit in mac level loopbacks */
1040874aeea5SJeff Kirsher 	phy_mode = efx->phy_mode;
1041874aeea5SJeff Kirsher 	if (LOOPBACK_INTERNAL(efx))
1042874aeea5SJeff Kirsher 		efx->phy_mode |= PHY_MODE_TX_DISABLED;
1043874aeea5SJeff Kirsher 	else
1044874aeea5SJeff Kirsher 		efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
1045874aeea5SJeff Kirsher 
1046874aeea5SJeff Kirsher 	rc = efx->type->reconfigure_port(efx);
1047874aeea5SJeff Kirsher 
1048874aeea5SJeff Kirsher 	if (rc)
1049874aeea5SJeff Kirsher 		efx->phy_mode = phy_mode;
1050874aeea5SJeff Kirsher 
1051874aeea5SJeff Kirsher 	return rc;
1052874aeea5SJeff Kirsher }
1053874aeea5SJeff Kirsher 
1054874aeea5SJeff Kirsher /* Reinitialise the MAC to pick up new PHY settings, even if the port is
1055874aeea5SJeff Kirsher  * disabled. */
1056874aeea5SJeff Kirsher int efx_reconfigure_port(struct efx_nic *efx)
1057874aeea5SJeff Kirsher {
1058874aeea5SJeff Kirsher 	int rc;
1059874aeea5SJeff Kirsher 
1060874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
1061874aeea5SJeff Kirsher 
1062874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
1063874aeea5SJeff Kirsher 	rc = __efx_reconfigure_port(efx);
1064874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1065874aeea5SJeff Kirsher 
1066874aeea5SJeff Kirsher 	return rc;
1067874aeea5SJeff Kirsher }
1068874aeea5SJeff Kirsher 
1069874aeea5SJeff Kirsher /* Asynchronous work item for changing MAC promiscuity and multicast
1070874aeea5SJeff Kirsher  * hash.  Avoid a drain/rx_ingress enable by reconfiguring the current
1071874aeea5SJeff Kirsher  * MAC directly. */
1072874aeea5SJeff Kirsher static void efx_mac_work(struct work_struct *data)
1073874aeea5SJeff Kirsher {
1074874aeea5SJeff Kirsher 	struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
1075874aeea5SJeff Kirsher 
1076874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
107730b81cdaSBen Hutchings 	if (efx->port_enabled)
10780d322413SEdward Cree 		efx_mac_reconfigure(efx);
1079874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1080874aeea5SJeff Kirsher }
1081874aeea5SJeff Kirsher 
1082874aeea5SJeff Kirsher static int efx_probe_port(struct efx_nic *efx)
1083874aeea5SJeff Kirsher {
1084874aeea5SJeff Kirsher 	int rc;
1085874aeea5SJeff Kirsher 
1086874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev, "create port\n");
1087874aeea5SJeff Kirsher 
1088874aeea5SJeff Kirsher 	if (phy_flash_cfg)
1089874aeea5SJeff Kirsher 		efx->phy_mode = PHY_MODE_SPECIAL;
1090874aeea5SJeff Kirsher 
1091874aeea5SJeff Kirsher 	/* Connect up MAC/PHY operations table */
1092874aeea5SJeff Kirsher 	rc = efx->type->probe_port(efx);
1093874aeea5SJeff Kirsher 	if (rc)
1094874aeea5SJeff Kirsher 		return rc;
1095874aeea5SJeff Kirsher 
1096e332bcb3SBen Hutchings 	/* Initialise MAC address to permanent address */
1097cd84ff4dSEdward Cree 	ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
1098874aeea5SJeff Kirsher 
1099874aeea5SJeff Kirsher 	return 0;
1100874aeea5SJeff Kirsher }
1101874aeea5SJeff Kirsher 
1102874aeea5SJeff Kirsher static int efx_init_port(struct efx_nic *efx)
1103874aeea5SJeff Kirsher {
1104874aeea5SJeff Kirsher 	int rc;
1105874aeea5SJeff Kirsher 
1106874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "init port\n");
1107874aeea5SJeff Kirsher 
1108874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
1109874aeea5SJeff Kirsher 
1110874aeea5SJeff Kirsher 	rc = efx->phy_op->init(efx);
1111874aeea5SJeff Kirsher 	if (rc)
1112874aeea5SJeff Kirsher 		goto fail1;
1113874aeea5SJeff Kirsher 
1114874aeea5SJeff Kirsher 	efx->port_initialized = true;
1115874aeea5SJeff Kirsher 
1116874aeea5SJeff Kirsher 	/* Reconfigure the MAC before creating dma queues (required for
1117874aeea5SJeff Kirsher 	 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
11180d322413SEdward Cree 	efx_mac_reconfigure(efx);
1119874aeea5SJeff Kirsher 
1120874aeea5SJeff Kirsher 	/* Ensure the PHY advertises the correct flow control settings */
1121874aeea5SJeff Kirsher 	rc = efx->phy_op->reconfigure(efx);
1122267d9d73SEdward Cree 	if (rc && rc != -EPERM)
1123874aeea5SJeff Kirsher 		goto fail2;
1124874aeea5SJeff Kirsher 
1125874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1126874aeea5SJeff Kirsher 	return 0;
1127874aeea5SJeff Kirsher 
1128874aeea5SJeff Kirsher fail2:
1129874aeea5SJeff Kirsher 	efx->phy_op->fini(efx);
1130874aeea5SJeff Kirsher fail1:
1131874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1132874aeea5SJeff Kirsher 	return rc;
1133874aeea5SJeff Kirsher }
1134874aeea5SJeff Kirsher 
1135874aeea5SJeff Kirsher static void efx_start_port(struct efx_nic *efx)
1136874aeea5SJeff Kirsher {
1137874aeea5SJeff Kirsher 	netif_dbg(efx, ifup, efx->net_dev, "start port\n");
1138874aeea5SJeff Kirsher 	BUG_ON(efx->port_enabled);
1139874aeea5SJeff Kirsher 
1140874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
1141874aeea5SJeff Kirsher 	efx->port_enabled = true;
1142874aeea5SJeff Kirsher 
1143d615c039SBen Hutchings 	/* Ensure MAC ingress/egress is enabled */
11440d322413SEdward Cree 	efx_mac_reconfigure(efx);
1145874aeea5SJeff Kirsher 
1146874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1147874aeea5SJeff Kirsher }
1148874aeea5SJeff Kirsher 
1149d615c039SBen Hutchings /* Cancel work for MAC reconfiguration, periodic hardware monitoring
1150d615c039SBen Hutchings  * and the async self-test, wait for them to finish and prevent them
1151d615c039SBen Hutchings  * being scheduled again.  This doesn't cover online resets, which
1152d615c039SBen Hutchings  * should only be cancelled when removing the device.
1153d615c039SBen Hutchings  */
1154874aeea5SJeff Kirsher static void efx_stop_port(struct efx_nic *efx)
1155874aeea5SJeff Kirsher {
1156874aeea5SJeff Kirsher 	netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
1157874aeea5SJeff Kirsher 
1158d615c039SBen Hutchings 	EFX_ASSERT_RESET_SERIALISED(efx);
1159d615c039SBen Hutchings 
1160874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
1161874aeea5SJeff Kirsher 	efx->port_enabled = false;
1162874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1163874aeea5SJeff Kirsher 
1164874aeea5SJeff Kirsher 	/* Serialise against efx_set_multicast_list() */
1165874aeea5SJeff Kirsher 	netif_addr_lock_bh(efx->net_dev);
1166874aeea5SJeff Kirsher 	netif_addr_unlock_bh(efx->net_dev);
1167d615c039SBen Hutchings 
1168d615c039SBen Hutchings 	cancel_delayed_work_sync(&efx->monitor_work);
1169d615c039SBen Hutchings 	efx_selftest_async_cancel(efx);
1170d615c039SBen Hutchings 	cancel_work_sync(&efx->mac_work);
1171874aeea5SJeff Kirsher }
1172874aeea5SJeff Kirsher 
1173874aeea5SJeff Kirsher static void efx_fini_port(struct efx_nic *efx)
1174874aeea5SJeff Kirsher {
1175874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
1176874aeea5SJeff Kirsher 
1177874aeea5SJeff Kirsher 	if (!efx->port_initialized)
1178874aeea5SJeff Kirsher 		return;
1179874aeea5SJeff Kirsher 
1180874aeea5SJeff Kirsher 	efx->phy_op->fini(efx);
1181874aeea5SJeff Kirsher 	efx->port_initialized = false;
1182874aeea5SJeff Kirsher 
1183874aeea5SJeff Kirsher 	efx->link_state.up = false;
1184874aeea5SJeff Kirsher 	efx_link_status_changed(efx);
1185874aeea5SJeff Kirsher }
1186874aeea5SJeff Kirsher 
1187874aeea5SJeff Kirsher static void efx_remove_port(struct efx_nic *efx)
1188874aeea5SJeff Kirsher {
1189874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
1190874aeea5SJeff Kirsher 
1191874aeea5SJeff Kirsher 	efx->type->remove_port(efx);
1192874aeea5SJeff Kirsher }
1193874aeea5SJeff Kirsher 
1194874aeea5SJeff Kirsher /**************************************************************************
1195874aeea5SJeff Kirsher  *
1196874aeea5SJeff Kirsher  * NIC handling
1197874aeea5SJeff Kirsher  *
1198874aeea5SJeff Kirsher  **************************************************************************/
1199874aeea5SJeff Kirsher 
12000bcf4a64SBen Hutchings static LIST_HEAD(efx_primary_list);
12010bcf4a64SBen Hutchings static LIST_HEAD(efx_unassociated_list);
12020bcf4a64SBen Hutchings 
12030bcf4a64SBen Hutchings static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
12040bcf4a64SBen Hutchings {
12050bcf4a64SBen Hutchings 	return left->type == right->type &&
12060bcf4a64SBen Hutchings 		left->vpd_sn && right->vpd_sn &&
12070bcf4a64SBen Hutchings 		!strcmp(left->vpd_sn, right->vpd_sn);
12080bcf4a64SBen Hutchings }
12090bcf4a64SBen Hutchings 
12100bcf4a64SBen Hutchings static void efx_associate(struct efx_nic *efx)
12110bcf4a64SBen Hutchings {
12120bcf4a64SBen Hutchings 	struct efx_nic *other, *next;
12130bcf4a64SBen Hutchings 
12140bcf4a64SBen Hutchings 	if (efx->primary == efx) {
12150bcf4a64SBen Hutchings 		/* Adding primary function; look for secondaries */
12160bcf4a64SBen Hutchings 
12170bcf4a64SBen Hutchings 		netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
12180bcf4a64SBen Hutchings 		list_add_tail(&efx->node, &efx_primary_list);
12190bcf4a64SBen Hutchings 
12200bcf4a64SBen Hutchings 		list_for_each_entry_safe(other, next, &efx_unassociated_list,
12210bcf4a64SBen Hutchings 					 node) {
12220bcf4a64SBen Hutchings 			if (efx_same_controller(efx, other)) {
12230bcf4a64SBen Hutchings 				list_del(&other->node);
12240bcf4a64SBen Hutchings 				netif_dbg(other, probe, other->net_dev,
12250bcf4a64SBen Hutchings 					  "moving to secondary list of %s %s\n",
12260bcf4a64SBen Hutchings 					  pci_name(efx->pci_dev),
12270bcf4a64SBen Hutchings 					  efx->net_dev->name);
12280bcf4a64SBen Hutchings 				list_add_tail(&other->node,
12290bcf4a64SBen Hutchings 					      &efx->secondary_list);
12300bcf4a64SBen Hutchings 				other->primary = efx;
12310bcf4a64SBen Hutchings 			}
12320bcf4a64SBen Hutchings 		}
12330bcf4a64SBen Hutchings 	} else {
12340bcf4a64SBen Hutchings 		/* Adding secondary function; look for primary */
12350bcf4a64SBen Hutchings 
12360bcf4a64SBen Hutchings 		list_for_each_entry(other, &efx_primary_list, node) {
12370bcf4a64SBen Hutchings 			if (efx_same_controller(efx, other)) {
12380bcf4a64SBen Hutchings 				netif_dbg(efx, probe, efx->net_dev,
12390bcf4a64SBen Hutchings 					  "adding to secondary list of %s %s\n",
12400bcf4a64SBen Hutchings 					  pci_name(other->pci_dev),
12410bcf4a64SBen Hutchings 					  other->net_dev->name);
12420bcf4a64SBen Hutchings 				list_add_tail(&efx->node,
12430bcf4a64SBen Hutchings 					      &other->secondary_list);
12440bcf4a64SBen Hutchings 				efx->primary = other;
12450bcf4a64SBen Hutchings 				return;
12460bcf4a64SBen Hutchings 			}
12470bcf4a64SBen Hutchings 		}
12480bcf4a64SBen Hutchings 
12490bcf4a64SBen Hutchings 		netif_dbg(efx, probe, efx->net_dev,
12500bcf4a64SBen Hutchings 			  "adding to unassociated list\n");
12510bcf4a64SBen Hutchings 		list_add_tail(&efx->node, &efx_unassociated_list);
12520bcf4a64SBen Hutchings 	}
12530bcf4a64SBen Hutchings }
12540bcf4a64SBen Hutchings 
12550bcf4a64SBen Hutchings static void efx_dissociate(struct efx_nic *efx)
12560bcf4a64SBen Hutchings {
12570bcf4a64SBen Hutchings 	struct efx_nic *other, *next;
12580bcf4a64SBen Hutchings 
12590bcf4a64SBen Hutchings 	list_del(&efx->node);
12600bcf4a64SBen Hutchings 	efx->primary = NULL;
12610bcf4a64SBen Hutchings 
12620bcf4a64SBen Hutchings 	list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
12630bcf4a64SBen Hutchings 		list_del(&other->node);
12640bcf4a64SBen Hutchings 		netif_dbg(other, probe, other->net_dev,
12650bcf4a64SBen Hutchings 			  "moving to unassociated list\n");
12660bcf4a64SBen Hutchings 		list_add_tail(&other->node, &efx_unassociated_list);
12670bcf4a64SBen Hutchings 		other->primary = NULL;
12680bcf4a64SBen Hutchings 	}
12690bcf4a64SBen Hutchings }
12700bcf4a64SBen Hutchings 
1271874aeea5SJeff Kirsher /* This configures the PCI device to enable I/O and DMA. */
1272874aeea5SJeff Kirsher static int efx_init_io(struct efx_nic *efx)
1273874aeea5SJeff Kirsher {
1274874aeea5SJeff Kirsher 	struct pci_dev *pci_dev = efx->pci_dev;
1275874aeea5SJeff Kirsher 	dma_addr_t dma_mask = efx->type->max_dma_mask;
1276b105798fSBen Hutchings 	unsigned int mem_map_size = efx->type->mem_map_size(efx);
127702246a7fSShradha Shah 	int rc, bar;
1278874aeea5SJeff Kirsher 
1279874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
1280874aeea5SJeff Kirsher 
128103714bbbSEdward Cree 	bar = efx->type->mem_bar(efx);
128202246a7fSShradha Shah 
1283874aeea5SJeff Kirsher 	rc = pci_enable_device(pci_dev);
1284874aeea5SJeff Kirsher 	if (rc) {
1285874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
1286874aeea5SJeff Kirsher 			  "failed to enable PCI device\n");
1287874aeea5SJeff Kirsher 		goto fail1;
1288874aeea5SJeff Kirsher 	}
1289874aeea5SJeff Kirsher 
1290874aeea5SJeff Kirsher 	pci_set_master(pci_dev);
1291874aeea5SJeff Kirsher 
1292874aeea5SJeff Kirsher 	/* Set the PCI DMA mask.  Try all possibilities from our
1293874aeea5SJeff Kirsher 	 * genuine mask down to 32 bits, because some architectures
1294874aeea5SJeff Kirsher 	 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1295874aeea5SJeff Kirsher 	 * masks event though they reject 46 bit masks.
1296874aeea5SJeff Kirsher 	 */
1297874aeea5SJeff Kirsher 	while (dma_mask > 0x7fffffffUL) {
12989663dedaSRussell King 		rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
1299e9e01846SBen Hutchings 		if (rc == 0)
1300874aeea5SJeff Kirsher 			break;
1301874aeea5SJeff Kirsher 		dma_mask >>= 1;
1302874aeea5SJeff Kirsher 	}
1303874aeea5SJeff Kirsher 	if (rc) {
1304874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
1305874aeea5SJeff Kirsher 			  "could not find a suitable DMA mask\n");
1306874aeea5SJeff Kirsher 		goto fail2;
1307874aeea5SJeff Kirsher 	}
1308874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev,
1309874aeea5SJeff Kirsher 		  "using DMA mask %llx\n", (unsigned long long) dma_mask);
1310874aeea5SJeff Kirsher 
131102246a7fSShradha Shah 	efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
131202246a7fSShradha Shah 	rc = pci_request_region(pci_dev, bar, "sfc");
1313874aeea5SJeff Kirsher 	if (rc) {
1314874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
1315874aeea5SJeff Kirsher 			  "request for memory BAR failed\n");
1316874aeea5SJeff Kirsher 		rc = -EIO;
1317874aeea5SJeff Kirsher 		goto fail3;
1318874aeea5SJeff Kirsher 	}
1319b105798fSBen Hutchings 	efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
1320874aeea5SJeff Kirsher 	if (!efx->membase) {
1321874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
1322874aeea5SJeff Kirsher 			  "could not map memory BAR at %llx+%x\n",
1323b105798fSBen Hutchings 			  (unsigned long long)efx->membase_phys, mem_map_size);
1324874aeea5SJeff Kirsher 		rc = -ENOMEM;
1325874aeea5SJeff Kirsher 		goto fail4;
1326874aeea5SJeff Kirsher 	}
1327874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev,
1328874aeea5SJeff Kirsher 		  "memory BAR at %llx+%x (virtual %p)\n",
1329b105798fSBen Hutchings 		  (unsigned long long)efx->membase_phys, mem_map_size,
1330b105798fSBen Hutchings 		  efx->membase);
1331874aeea5SJeff Kirsher 
1332874aeea5SJeff Kirsher 	return 0;
1333874aeea5SJeff Kirsher 
1334874aeea5SJeff Kirsher  fail4:
133502246a7fSShradha Shah 	pci_release_region(efx->pci_dev, bar);
1336874aeea5SJeff Kirsher  fail3:
1337874aeea5SJeff Kirsher 	efx->membase_phys = 0;
1338874aeea5SJeff Kirsher  fail2:
1339874aeea5SJeff Kirsher 	pci_disable_device(efx->pci_dev);
1340874aeea5SJeff Kirsher  fail1:
1341874aeea5SJeff Kirsher 	return rc;
1342874aeea5SJeff Kirsher }
1343874aeea5SJeff Kirsher 
1344874aeea5SJeff Kirsher static void efx_fini_io(struct efx_nic *efx)
1345874aeea5SJeff Kirsher {
134602246a7fSShradha Shah 	int bar;
134702246a7fSShradha Shah 
1348874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
1349874aeea5SJeff Kirsher 
1350874aeea5SJeff Kirsher 	if (efx->membase) {
1351874aeea5SJeff Kirsher 		iounmap(efx->membase);
1352874aeea5SJeff Kirsher 		efx->membase = NULL;
1353874aeea5SJeff Kirsher 	}
1354874aeea5SJeff Kirsher 
1355874aeea5SJeff Kirsher 	if (efx->membase_phys) {
135603714bbbSEdward Cree 		bar = efx->type->mem_bar(efx);
135702246a7fSShradha Shah 		pci_release_region(efx->pci_dev, bar);
1358874aeea5SJeff Kirsher 		efx->membase_phys = 0;
1359874aeea5SJeff Kirsher 	}
1360874aeea5SJeff Kirsher 
13616598dad2SDaniel Pieczko 	/* Don't disable bus-mastering if VFs are assigned */
13626598dad2SDaniel Pieczko 	if (!pci_vfs_assigned(efx->pci_dev))
1363874aeea5SJeff Kirsher 		pci_disable_device(efx->pci_dev);
1364874aeea5SJeff Kirsher }
1365874aeea5SJeff Kirsher 
136642356d9aSEdward Cree void efx_set_default_rx_indir_table(struct efx_nic *efx,
136742356d9aSEdward Cree 				    struct efx_rss_context *ctx)
1368267c0157SJon Cooper {
1369267c0157SJon Cooper 	size_t i;
1370267c0157SJon Cooper 
137142356d9aSEdward Cree 	for (i = 0; i < ARRAY_SIZE(ctx->rx_indir_table); i++)
137242356d9aSEdward Cree 		ctx->rx_indir_table[i] =
1373267c0157SJon Cooper 			ethtool_rxfh_indir_default(i, efx->rss_spread);
1374267c0157SJon Cooper }
1375267c0157SJon Cooper 
1376a9a52506SBen Hutchings static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
1377874aeea5SJeff Kirsher {
1378cdb08f8fSBen Hutchings 	cpumask_var_t thread_mask;
1379a16e5b24SBen Hutchings 	unsigned int count;
1380874aeea5SJeff Kirsher 	int cpu;
1381874aeea5SJeff Kirsher 
1382cd2d5b52SBen Hutchings 	if (rss_cpus) {
1383cd2d5b52SBen Hutchings 		count = rss_cpus;
1384cd2d5b52SBen Hutchings 	} else {
1385cdb08f8fSBen Hutchings 		if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1386a9a52506SBen Hutchings 			netif_warn(efx, probe, efx->net_dev,
1387a9a52506SBen Hutchings 				   "RSS disabled due to allocation failure\n");
1388874aeea5SJeff Kirsher 			return 1;
1389874aeea5SJeff Kirsher 		}
1390874aeea5SJeff Kirsher 
1391874aeea5SJeff Kirsher 		count = 0;
1392874aeea5SJeff Kirsher 		for_each_online_cpu(cpu) {
1393cdb08f8fSBen Hutchings 			if (!cpumask_test_cpu(cpu, thread_mask)) {
1394874aeea5SJeff Kirsher 				++count;
1395cdb08f8fSBen Hutchings 				cpumask_or(thread_mask, thread_mask,
139606931e62SBartosz Golaszewski 					   topology_sibling_cpumask(cpu));
1397874aeea5SJeff Kirsher 			}
1398874aeea5SJeff Kirsher 		}
1399874aeea5SJeff Kirsher 
1400cdb08f8fSBen Hutchings 		free_cpumask_var(thread_mask);
1401cd2d5b52SBen Hutchings 	}
1402cd2d5b52SBen Hutchings 
1403271a8b42SBert Kenward 	if (count > EFX_MAX_RX_QUEUES) {
1404271a8b42SBert Kenward 		netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1405271a8b42SBert Kenward 			       "Reducing number of rx queues from %u to %u.\n",
1406271a8b42SBert Kenward 			       count, EFX_MAX_RX_QUEUES);
1407271a8b42SBert Kenward 		count = EFX_MAX_RX_QUEUES;
1408271a8b42SBert Kenward 	}
1409271a8b42SBert Kenward 
1410cd2d5b52SBen Hutchings 	/* If RSS is requested for the PF *and* VFs then we can't write RSS
1411cd2d5b52SBen Hutchings 	 * table entries that are inaccessible to VFs
1412cd2d5b52SBen Hutchings 	 */
14137fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV
14147fa8d547SShradha Shah 	if (efx->type->sriov_wanted) {
1415d98a4ffeSShradha Shah 		if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
1416cd2d5b52SBen Hutchings 		    count > efx_vf_size(efx)) {
1417cd2d5b52SBen Hutchings 			netif_warn(efx, probe, efx->net_dev,
1418cd2d5b52SBen Hutchings 				   "Reducing number of RSS channels from %u to %u for "
1419cd2d5b52SBen Hutchings 				   "VF support. Increase vf-msix-limit to use more "
1420cd2d5b52SBen Hutchings 				   "channels on the PF.\n",
1421cd2d5b52SBen Hutchings 				   count, efx_vf_size(efx));
1422cd2d5b52SBen Hutchings 			count = efx_vf_size(efx);
1423cd2d5b52SBen Hutchings 		}
14247fa8d547SShradha Shah 	}
14257fa8d547SShradha Shah #endif
1426cd2d5b52SBen Hutchings 
1427874aeea5SJeff Kirsher 	return count;
1428874aeea5SJeff Kirsher }
1429874aeea5SJeff Kirsher 
1430874aeea5SJeff Kirsher /* Probe the number and type of interrupts we are able to obtain, and
1431874aeea5SJeff Kirsher  * the resulting numbers of channels and RX queues.
1432874aeea5SJeff Kirsher  */
1433874aeea5SJeff Kirsher static int efx_probe_interrupts(struct efx_nic *efx)
1434874aeea5SJeff Kirsher {
14357f967c01SBen Hutchings 	unsigned int extra_channels = 0;
14367f967c01SBen Hutchings 	unsigned int i, j;
1437a16e5b24SBen Hutchings 	int rc;
1438874aeea5SJeff Kirsher 
14397f967c01SBen Hutchings 	for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
14407f967c01SBen Hutchings 		if (efx->extra_channel_type[i])
14417f967c01SBen Hutchings 			++extra_channels;
14427f967c01SBen Hutchings 
1443874aeea5SJeff Kirsher 	if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
1444874aeea5SJeff Kirsher 		struct msix_entry xentries[EFX_MAX_CHANNELS];
1445a16e5b24SBen Hutchings 		unsigned int n_channels;
1446874aeea5SJeff Kirsher 
1447a9a52506SBen Hutchings 		n_channels = efx_wanted_parallelism(efx);
1448b0fbdae1SShradha Shah 		if (efx_separate_tx_channels)
1449874aeea5SJeff Kirsher 			n_channels *= 2;
14507f967c01SBen Hutchings 		n_channels += extra_channels;
1451b105798fSBen Hutchings 		n_channels = min(n_channels, efx->max_channels);
1452874aeea5SJeff Kirsher 
1453874aeea5SJeff Kirsher 		for (i = 0; i < n_channels; i++)
1454874aeea5SJeff Kirsher 			xentries[i].entry = i;
1455184603d8SAlexander Gordeev 		rc = pci_enable_msix_range(efx->pci_dev,
1456184603d8SAlexander Gordeev 					   xentries, 1, n_channels);
1457184603d8SAlexander Gordeev 		if (rc < 0) {
1458184603d8SAlexander Gordeev 			/* Fall back to single channel MSI */
1459184603d8SAlexander Gordeev 			netif_err(efx, drv, efx->net_dev,
1460184603d8SAlexander Gordeev 				  "could not enable MSI-X\n");
146162980cb6SAndrew Rybchenko 			if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
146262980cb6SAndrew Rybchenko 				efx->interrupt_mode = EFX_INT_MODE_MSI;
146362980cb6SAndrew Rybchenko 			else
146462980cb6SAndrew Rybchenko 				return rc;
1465184603d8SAlexander Gordeev 		} else if (rc < n_channels) {
1466874aeea5SJeff Kirsher 			netif_err(efx, drv, efx->net_dev,
1467874aeea5SJeff Kirsher 				  "WARNING: Insufficient MSI-X vectors"
1468a16e5b24SBen Hutchings 				  " available (%d < %u).\n", rc, n_channels);
1469874aeea5SJeff Kirsher 			netif_err(efx, drv, efx->net_dev,
1470874aeea5SJeff Kirsher 				  "WARNING: Performance may be reduced.\n");
1471874aeea5SJeff Kirsher 			n_channels = rc;
1472874aeea5SJeff Kirsher 		}
1473874aeea5SJeff Kirsher 
1474184603d8SAlexander Gordeev 		if (rc > 0) {
1475874aeea5SJeff Kirsher 			efx->n_channels = n_channels;
14767f967c01SBen Hutchings 			if (n_channels > extra_channels)
14777f967c01SBen Hutchings 				n_channels -= extra_channels;
1478b0fbdae1SShradha Shah 			if (efx_separate_tx_channels) {
1479b0fbdae1SShradha Shah 				efx->n_tx_channels = min(max(n_channels / 2,
1480b0fbdae1SShradha Shah 							     1U),
1481b0fbdae1SShradha Shah 							 efx->max_tx_channels);
14827f967c01SBen Hutchings 				efx->n_rx_channels = max(n_channels -
14837f967c01SBen Hutchings 							 efx->n_tx_channels,
14847f967c01SBen Hutchings 							 1U);
1485874aeea5SJeff Kirsher 			} else {
1486b0fbdae1SShradha Shah 				efx->n_tx_channels = min(n_channels,
1487b0fbdae1SShradha Shah 							 efx->max_tx_channels);
14887f967c01SBen Hutchings 				efx->n_rx_channels = n_channels;
1489874aeea5SJeff Kirsher 			}
14907f967c01SBen Hutchings 			for (i = 0; i < efx->n_channels; i++)
1491874aeea5SJeff Kirsher 				efx_get_channel(efx, i)->irq =
1492874aeea5SJeff Kirsher 					xentries[i].vector;
1493874aeea5SJeff Kirsher 		}
1494874aeea5SJeff Kirsher 	}
1495874aeea5SJeff Kirsher 
1496874aeea5SJeff Kirsher 	/* Try single interrupt MSI */
1497874aeea5SJeff Kirsher 	if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
1498874aeea5SJeff Kirsher 		efx->n_channels = 1;
1499874aeea5SJeff Kirsher 		efx->n_rx_channels = 1;
1500874aeea5SJeff Kirsher 		efx->n_tx_channels = 1;
1501874aeea5SJeff Kirsher 		rc = pci_enable_msi(efx->pci_dev);
1502874aeea5SJeff Kirsher 		if (rc == 0) {
1503874aeea5SJeff Kirsher 			efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
1504874aeea5SJeff Kirsher 		} else {
1505874aeea5SJeff Kirsher 			netif_err(efx, drv, efx->net_dev,
1506874aeea5SJeff Kirsher 				  "could not enable MSI\n");
150762980cb6SAndrew Rybchenko 			if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
1508874aeea5SJeff Kirsher 				efx->interrupt_mode = EFX_INT_MODE_LEGACY;
150962980cb6SAndrew Rybchenko 			else
151062980cb6SAndrew Rybchenko 				return rc;
1511874aeea5SJeff Kirsher 		}
1512874aeea5SJeff Kirsher 	}
1513874aeea5SJeff Kirsher 
1514874aeea5SJeff Kirsher 	/* Assume legacy interrupts */
1515874aeea5SJeff Kirsher 	if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
1516b0fbdae1SShradha Shah 		efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
1517874aeea5SJeff Kirsher 		efx->n_rx_channels = 1;
1518874aeea5SJeff Kirsher 		efx->n_tx_channels = 1;
1519874aeea5SJeff Kirsher 		efx->legacy_irq = efx->pci_dev->irq;
1520874aeea5SJeff Kirsher 	}
1521874aeea5SJeff Kirsher 
15227f967c01SBen Hutchings 	/* Assign extra channels if possible */
15232935e3c3SEdward Cree 	efx->n_extra_tx_channels = 0;
15247f967c01SBen Hutchings 	j = efx->n_channels;
15257f967c01SBen Hutchings 	for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
15267f967c01SBen Hutchings 		if (!efx->extra_channel_type[i])
15277f967c01SBen Hutchings 			continue;
15287f967c01SBen Hutchings 		if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
15297f967c01SBen Hutchings 		    efx->n_channels <= extra_channels) {
15307f967c01SBen Hutchings 			efx->extra_channel_type[i]->handle_no_channel(efx);
15317f967c01SBen Hutchings 		} else {
15327f967c01SBen Hutchings 			--j;
15337f967c01SBen Hutchings 			efx_get_channel(efx, j)->type =
15347f967c01SBen Hutchings 				efx->extra_channel_type[i];
15352935e3c3SEdward Cree 			if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
15362935e3c3SEdward Cree 				efx->n_extra_tx_channels++;
15377f967c01SBen Hutchings 		}
15387f967c01SBen Hutchings 	}
15397f967c01SBen Hutchings 
1540cd2d5b52SBen Hutchings 	/* RSS might be usable on VFs even if it is disabled on the PF */
15417fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV
15427fa8d547SShradha Shah 	if (efx->type->sriov_wanted) {
1543327c685eSShradha Shah 		efx->rss_spread = ((efx->n_rx_channels > 1 ||
1544d98a4ffeSShradha Shah 				    !efx->type->sriov_wanted(efx)) ?
1545cd2d5b52SBen Hutchings 				   efx->n_rx_channels : efx_vf_size(efx));
15467fa8d547SShradha Shah 		return 0;
15477fa8d547SShradha Shah 	}
15487fa8d547SShradha Shah #endif
15497fa8d547SShradha Shah 	efx->rss_spread = efx->n_rx_channels;
1550cd2d5b52SBen Hutchings 
1551874aeea5SJeff Kirsher 	return 0;
1552874aeea5SJeff Kirsher }
1553874aeea5SJeff Kirsher 
1554a83762d9SBert Kenward #if defined(CONFIG_SMP)
1555a83762d9SBert Kenward static void efx_set_interrupt_affinity(struct efx_nic *efx)
1556a83762d9SBert Kenward {
1557a83762d9SBert Kenward 	struct efx_channel *channel;
1558a83762d9SBert Kenward 	unsigned int cpu;
1559a83762d9SBert Kenward 
1560a83762d9SBert Kenward 	efx_for_each_channel(channel, efx) {
1561a83762d9SBert Kenward 		cpu = cpumask_local_spread(channel->channel,
1562a83762d9SBert Kenward 					   pcibus_to_node(efx->pci_dev->bus));
1563a83762d9SBert Kenward 		irq_set_affinity_hint(channel->irq, cpumask_of(cpu));
1564a83762d9SBert Kenward 	}
1565a83762d9SBert Kenward }
1566a83762d9SBert Kenward 
1567a83762d9SBert Kenward static void efx_clear_interrupt_affinity(struct efx_nic *efx)
1568a83762d9SBert Kenward {
1569a83762d9SBert Kenward 	struct efx_channel *channel;
1570a83762d9SBert Kenward 
1571a83762d9SBert Kenward 	efx_for_each_channel(channel, efx)
1572a83762d9SBert Kenward 		irq_set_affinity_hint(channel->irq, NULL);
1573a83762d9SBert Kenward }
1574a83762d9SBert Kenward #else
1575a83762d9SBert Kenward static void
1576a83762d9SBert Kenward efx_set_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
1577a83762d9SBert Kenward {
1578a83762d9SBert Kenward }
1579a83762d9SBert Kenward 
1580a83762d9SBert Kenward static void
1581a83762d9SBert Kenward efx_clear_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
1582a83762d9SBert Kenward {
1583a83762d9SBert Kenward }
1584a83762d9SBert Kenward #endif /* CONFIG_SMP */
1585a83762d9SBert Kenward 
1586261e4d96SJon Cooper static int efx_soft_enable_interrupts(struct efx_nic *efx)
1587d8291187SBen Hutchings {
1588261e4d96SJon Cooper 	struct efx_channel *channel, *end_channel;
1589261e4d96SJon Cooper 	int rc;
1590d8291187SBen Hutchings 
1591d8291187SBen Hutchings 	BUG_ON(efx->state == STATE_DISABLED);
1592d8291187SBen Hutchings 
1593d8291187SBen Hutchings 	efx->irq_soft_enabled = true;
1594d8291187SBen Hutchings 	smp_wmb();
1595d8291187SBen Hutchings 
1596d8291187SBen Hutchings 	efx_for_each_channel(channel, efx) {
1597261e4d96SJon Cooper 		if (!channel->type->keep_eventq) {
1598261e4d96SJon Cooper 			rc = efx_init_eventq(channel);
1599261e4d96SJon Cooper 			if (rc)
1600261e4d96SJon Cooper 				goto fail;
1601261e4d96SJon Cooper 		}
1602d8291187SBen Hutchings 		efx_start_eventq(channel);
1603d8291187SBen Hutchings 	}
1604d8291187SBen Hutchings 
1605d8291187SBen Hutchings 	efx_mcdi_mode_event(efx);
1606261e4d96SJon Cooper 
1607261e4d96SJon Cooper 	return 0;
1608261e4d96SJon Cooper fail:
1609261e4d96SJon Cooper 	end_channel = channel;
1610261e4d96SJon Cooper 	efx_for_each_channel(channel, efx) {
1611261e4d96SJon Cooper 		if (channel == end_channel)
1612261e4d96SJon Cooper 			break;
1613261e4d96SJon Cooper 		efx_stop_eventq(channel);
1614261e4d96SJon Cooper 		if (!channel->type->keep_eventq)
1615261e4d96SJon Cooper 			efx_fini_eventq(channel);
1616261e4d96SJon Cooper 	}
1617261e4d96SJon Cooper 
1618261e4d96SJon Cooper 	return rc;
1619d8291187SBen Hutchings }
1620d8291187SBen Hutchings 
1621d8291187SBen Hutchings static void efx_soft_disable_interrupts(struct efx_nic *efx)
1622d8291187SBen Hutchings {
1623d8291187SBen Hutchings 	struct efx_channel *channel;
1624d8291187SBen Hutchings 
1625d8291187SBen Hutchings 	if (efx->state == STATE_DISABLED)
1626d8291187SBen Hutchings 		return;
1627d8291187SBen Hutchings 
1628d8291187SBen Hutchings 	efx_mcdi_mode_poll(efx);
1629d8291187SBen Hutchings 
1630d8291187SBen Hutchings 	efx->irq_soft_enabled = false;
1631d8291187SBen Hutchings 	smp_wmb();
1632d8291187SBen Hutchings 
1633d8291187SBen Hutchings 	if (efx->legacy_irq)
1634d8291187SBen Hutchings 		synchronize_irq(efx->legacy_irq);
1635d8291187SBen Hutchings 
1636d8291187SBen Hutchings 	efx_for_each_channel(channel, efx) {
1637d8291187SBen Hutchings 		if (channel->irq)
1638d8291187SBen Hutchings 			synchronize_irq(channel->irq);
1639d8291187SBen Hutchings 
1640d8291187SBen Hutchings 		efx_stop_eventq(channel);
1641d8291187SBen Hutchings 		if (!channel->type->keep_eventq)
1642d8291187SBen Hutchings 			efx_fini_eventq(channel);
1643d8291187SBen Hutchings 	}
1644cade715fSBen Hutchings 
1645cade715fSBen Hutchings 	/* Flush the asynchronous MCDI request queue */
1646cade715fSBen Hutchings 	efx_mcdi_flush_async(efx);
1647d8291187SBen Hutchings }
1648d8291187SBen Hutchings 
1649261e4d96SJon Cooper static int efx_enable_interrupts(struct efx_nic *efx)
16509f2cb71cSBen Hutchings {
1651261e4d96SJon Cooper 	struct efx_channel *channel, *end_channel;
1652261e4d96SJon Cooper 	int rc;
16539f2cb71cSBen Hutchings 
16548b7325b4SBen Hutchings 	BUG_ON(efx->state == STATE_DISABLED);
16558b7325b4SBen Hutchings 
1656b28405b0SAlexandre Rames 	if (efx->eeh_disabled_legacy_irq) {
1657b28405b0SAlexandre Rames 		enable_irq(efx->legacy_irq);
1658b28405b0SAlexandre Rames 		efx->eeh_disabled_legacy_irq = false;
1659b28405b0SAlexandre Rames 	}
1660d8291187SBen Hutchings 
166186094f7fSBen Hutchings 	efx->type->irq_enable_master(efx);
16629f2cb71cSBen Hutchings 
16639f2cb71cSBen Hutchings 	efx_for_each_channel(channel, efx) {
1664261e4d96SJon Cooper 		if (channel->type->keep_eventq) {
1665261e4d96SJon Cooper 			rc = efx_init_eventq(channel);
1666261e4d96SJon Cooper 			if (rc)
1667261e4d96SJon Cooper 				goto fail;
1668261e4d96SJon Cooper 		}
16699f2cb71cSBen Hutchings 	}
16709f2cb71cSBen Hutchings 
1671261e4d96SJon Cooper 	rc = efx_soft_enable_interrupts(efx);
1672261e4d96SJon Cooper 	if (rc)
1673261e4d96SJon Cooper 		goto fail;
1674261e4d96SJon Cooper 
1675261e4d96SJon Cooper 	return 0;
1676261e4d96SJon Cooper 
1677261e4d96SJon Cooper fail:
1678261e4d96SJon Cooper 	end_channel = channel;
1679261e4d96SJon Cooper 	efx_for_each_channel(channel, efx) {
1680261e4d96SJon Cooper 		if (channel == end_channel)
1681261e4d96SJon Cooper 			break;
1682261e4d96SJon Cooper 		if (channel->type->keep_eventq)
1683261e4d96SJon Cooper 			efx_fini_eventq(channel);
1684261e4d96SJon Cooper 	}
1685261e4d96SJon Cooper 
1686261e4d96SJon Cooper 	efx->type->irq_disable_non_ev(efx);
1687261e4d96SJon Cooper 
1688261e4d96SJon Cooper 	return rc;
16899f2cb71cSBen Hutchings }
16909f2cb71cSBen Hutchings 
1691d8291187SBen Hutchings static void efx_disable_interrupts(struct efx_nic *efx)
16929f2cb71cSBen Hutchings {
16939f2cb71cSBen Hutchings 	struct efx_channel *channel;
16949f2cb71cSBen Hutchings 
1695d8291187SBen Hutchings 	efx_soft_disable_interrupts(efx);
16969f2cb71cSBen Hutchings 
16979f2cb71cSBen Hutchings 	efx_for_each_channel(channel, efx) {
1698d8291187SBen Hutchings 		if (channel->type->keep_eventq)
16999f2cb71cSBen Hutchings 			efx_fini_eventq(channel);
17009f2cb71cSBen Hutchings 	}
1701d8291187SBen Hutchings 
170286094f7fSBen Hutchings 	efx->type->irq_disable_non_ev(efx);
17039f2cb71cSBen Hutchings }
17049f2cb71cSBen Hutchings 
1705874aeea5SJeff Kirsher static void efx_remove_interrupts(struct efx_nic *efx)
1706874aeea5SJeff Kirsher {
1707874aeea5SJeff Kirsher 	struct efx_channel *channel;
1708874aeea5SJeff Kirsher 
1709874aeea5SJeff Kirsher 	/* Remove MSI/MSI-X interrupts */
1710874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx)
1711874aeea5SJeff Kirsher 		channel->irq = 0;
1712874aeea5SJeff Kirsher 	pci_disable_msi(efx->pci_dev);
1713874aeea5SJeff Kirsher 	pci_disable_msix(efx->pci_dev);
1714874aeea5SJeff Kirsher 
1715874aeea5SJeff Kirsher 	/* Remove legacy interrupt */
1716874aeea5SJeff Kirsher 	efx->legacy_irq = 0;
1717874aeea5SJeff Kirsher }
1718874aeea5SJeff Kirsher 
1719874aeea5SJeff Kirsher static void efx_set_channels(struct efx_nic *efx)
1720874aeea5SJeff Kirsher {
1721874aeea5SJeff Kirsher 	struct efx_channel *channel;
1722874aeea5SJeff Kirsher 	struct efx_tx_queue *tx_queue;
1723874aeea5SJeff Kirsher 
1724874aeea5SJeff Kirsher 	efx->tx_channel_offset =
1725b0fbdae1SShradha Shah 		efx_separate_tx_channels ?
1726b0fbdae1SShradha Shah 		efx->n_channels - efx->n_tx_channels : 0;
1727874aeea5SJeff Kirsher 
172879d68b37SStuart Hodgson 	/* We need to mark which channels really have RX and TX
172979d68b37SStuart Hodgson 	 * queues, and adjust the TX queue numbers if we have separate
1730874aeea5SJeff Kirsher 	 * RX-only and TX-only channels.
1731874aeea5SJeff Kirsher 	 */
1732874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx) {
173379d68b37SStuart Hodgson 		if (channel->channel < efx->n_rx_channels)
173479d68b37SStuart Hodgson 			channel->rx_queue.core_index = channel->channel;
173579d68b37SStuart Hodgson 		else
173679d68b37SStuart Hodgson 			channel->rx_queue.core_index = -1;
173779d68b37SStuart Hodgson 
1738874aeea5SJeff Kirsher 		efx_for_each_channel_tx_queue(tx_queue, channel)
1739874aeea5SJeff Kirsher 			tx_queue->queue -= (efx->tx_channel_offset *
1740874aeea5SJeff Kirsher 					    EFX_TXQ_TYPES);
1741874aeea5SJeff Kirsher 	}
1742874aeea5SJeff Kirsher }
1743874aeea5SJeff Kirsher 
1744874aeea5SJeff Kirsher static int efx_probe_nic(struct efx_nic *efx)
1745874aeea5SJeff Kirsher {
1746874aeea5SJeff Kirsher 	int rc;
1747874aeea5SJeff Kirsher 
1748874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
1749874aeea5SJeff Kirsher 
1750874aeea5SJeff Kirsher 	/* Carry out hardware-type specific initialisation */
1751874aeea5SJeff Kirsher 	rc = efx->type->probe(efx);
1752874aeea5SJeff Kirsher 	if (rc)
1753874aeea5SJeff Kirsher 		return rc;
1754874aeea5SJeff Kirsher 
1755b0fbdae1SShradha Shah 	do {
1756b0fbdae1SShradha Shah 		if (!efx->max_channels || !efx->max_tx_channels) {
1757b0fbdae1SShradha Shah 			netif_err(efx, drv, efx->net_dev,
1758b0fbdae1SShradha Shah 				  "Insufficient resources to allocate"
1759b0fbdae1SShradha Shah 				  " any channels\n");
1760b0fbdae1SShradha Shah 			rc = -ENOSPC;
1761b0fbdae1SShradha Shah 			goto fail1;
1762b0fbdae1SShradha Shah 		}
1763b0fbdae1SShradha Shah 
1764b0fbdae1SShradha Shah 		/* Determine the number of channels and queues by trying
1765b0fbdae1SShradha Shah 		 * to hook in MSI-X interrupts.
1766b0fbdae1SShradha Shah 		 */
1767874aeea5SJeff Kirsher 		rc = efx_probe_interrupts(efx);
1768874aeea5SJeff Kirsher 		if (rc)
1769c15eed22SBen Hutchings 			goto fail1;
1770874aeea5SJeff Kirsher 
177152ad762bSDaniel Pieczko 		efx_set_channels(efx);
177252ad762bSDaniel Pieczko 
1773b0fbdae1SShradha Shah 		/* dimension_resources can fail with EAGAIN */
1774c15eed22SBen Hutchings 		rc = efx->type->dimension_resources(efx);
1775b0fbdae1SShradha Shah 		if (rc != 0 && rc != -EAGAIN)
1776c15eed22SBen Hutchings 			goto fail2;
177728e47c49SBen Hutchings 
1778b0fbdae1SShradha Shah 		if (rc == -EAGAIN)
1779b0fbdae1SShradha Shah 			/* try again with new max_channels */
1780b0fbdae1SShradha Shah 			efx_remove_interrupts(efx);
1781b0fbdae1SShradha Shah 
1782b0fbdae1SShradha Shah 	} while (rc == -EAGAIN);
1783b0fbdae1SShradha Shah 
1784874aeea5SJeff Kirsher 	if (efx->n_channels > 1)
178542356d9aSEdward Cree 		netdev_rss_key_fill(efx->rss_context.rx_hash_key,
178642356d9aSEdward Cree 				    sizeof(efx->rss_context.rx_hash_key));
178742356d9aSEdward Cree 	efx_set_default_rx_indir_table(efx, &efx->rss_context);
1788874aeea5SJeff Kirsher 
1789874aeea5SJeff Kirsher 	netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1790874aeea5SJeff Kirsher 	netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
1791874aeea5SJeff Kirsher 
1792874aeea5SJeff Kirsher 	/* Initialise the interrupt moderation settings */
1793539de7c5SBert Kenward 	efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
17949e393b30SBen Hutchings 	efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
17959e393b30SBen Hutchings 				true);
1796874aeea5SJeff Kirsher 
1797874aeea5SJeff Kirsher 	return 0;
1798874aeea5SJeff Kirsher 
1799c15eed22SBen Hutchings fail2:
1800c15eed22SBen Hutchings 	efx_remove_interrupts(efx);
1801c15eed22SBen Hutchings fail1:
1802874aeea5SJeff Kirsher 	efx->type->remove(efx);
1803874aeea5SJeff Kirsher 	return rc;
1804874aeea5SJeff Kirsher }
1805874aeea5SJeff Kirsher 
1806874aeea5SJeff Kirsher static void efx_remove_nic(struct efx_nic *efx)
1807874aeea5SJeff Kirsher {
1808874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
1809874aeea5SJeff Kirsher 
1810874aeea5SJeff Kirsher 	efx_remove_interrupts(efx);
1811874aeea5SJeff Kirsher 	efx->type->remove(efx);
1812874aeea5SJeff Kirsher }
1813874aeea5SJeff Kirsher 
1814add72477SBen Hutchings static int efx_probe_filters(struct efx_nic *efx)
1815add72477SBen Hutchings {
1816add72477SBen Hutchings 	int rc;
1817add72477SBen Hutchings 
18180d322413SEdward Cree 	init_rwsem(&efx->filter_sem);
1819d248953aSMartin Habets 	mutex_lock(&efx->mac_lock);
18200d322413SEdward Cree 	down_write(&efx->filter_sem);
1821add72477SBen Hutchings 	rc = efx->type->filter_table_probe(efx);
1822add72477SBen Hutchings 	if (rc)
18230d322413SEdward Cree 		goto out_unlock;
1824add72477SBen Hutchings 
1825add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
1826add72477SBen Hutchings 	if (efx->type->offload_features & NETIF_F_NTUPLE) {
1827faf8dcc1SJon Cooper 		struct efx_channel *channel;
1828faf8dcc1SJon Cooper 		int i, success = 1;
1829faf8dcc1SJon Cooper 
1830faf8dcc1SJon Cooper 		efx_for_each_channel(channel, efx) {
1831faf8dcc1SJon Cooper 			channel->rps_flow_id =
1832faf8dcc1SJon Cooper 				kcalloc(efx->type->max_rx_ip_filters,
1833faf8dcc1SJon Cooper 					sizeof(*channel->rps_flow_id),
1834add72477SBen Hutchings 					GFP_KERNEL);
1835faf8dcc1SJon Cooper 			if (!channel->rps_flow_id)
1836faf8dcc1SJon Cooper 				success = 0;
1837faf8dcc1SJon Cooper 			else
1838faf8dcc1SJon Cooper 				for (i = 0;
1839faf8dcc1SJon Cooper 				     i < efx->type->max_rx_ip_filters;
1840faf8dcc1SJon Cooper 				     ++i)
1841faf8dcc1SJon Cooper 					channel->rps_flow_id[i] =
1842faf8dcc1SJon Cooper 						RPS_FLOW_ID_INVALID;
1843faf8dcc1SJon Cooper 		}
1844faf8dcc1SJon Cooper 
1845faf8dcc1SJon Cooper 		if (!success) {
1846faf8dcc1SJon Cooper 			efx_for_each_channel(channel, efx)
1847faf8dcc1SJon Cooper 				kfree(channel->rps_flow_id);
1848add72477SBen Hutchings 			efx->type->filter_table_remove(efx);
18490d322413SEdward Cree 			rc = -ENOMEM;
18500d322413SEdward Cree 			goto out_unlock;
1851add72477SBen Hutchings 		}
1852faf8dcc1SJon Cooper 
1853faf8dcc1SJon Cooper 		efx->rps_expire_index = efx->rps_expire_channel = 0;
1854add72477SBen Hutchings 	}
1855add72477SBen Hutchings #endif
18560d322413SEdward Cree out_unlock:
18570d322413SEdward Cree 	up_write(&efx->filter_sem);
1858d248953aSMartin Habets 	mutex_unlock(&efx->mac_lock);
18590d322413SEdward Cree 	return rc;
1860add72477SBen Hutchings }
1861add72477SBen Hutchings 
1862add72477SBen Hutchings static void efx_remove_filters(struct efx_nic *efx)
1863add72477SBen Hutchings {
1864add72477SBen Hutchings #ifdef CONFIG_RFS_ACCEL
1865faf8dcc1SJon Cooper 	struct efx_channel *channel;
1866faf8dcc1SJon Cooper 
1867faf8dcc1SJon Cooper 	efx_for_each_channel(channel, efx)
1868faf8dcc1SJon Cooper 		kfree(channel->rps_flow_id);
1869add72477SBen Hutchings #endif
18700d322413SEdward Cree 	down_write(&efx->filter_sem);
1871add72477SBen Hutchings 	efx->type->filter_table_remove(efx);
18720d322413SEdward Cree 	up_write(&efx->filter_sem);
1873add72477SBen Hutchings }
1874add72477SBen Hutchings 
1875add72477SBen Hutchings static void efx_restore_filters(struct efx_nic *efx)
1876add72477SBen Hutchings {
18770d322413SEdward Cree 	down_read(&efx->filter_sem);
1878add72477SBen Hutchings 	efx->type->filter_table_restore(efx);
18790d322413SEdward Cree 	up_read(&efx->filter_sem);
1880add72477SBen Hutchings }
1881add72477SBen Hutchings 
1882874aeea5SJeff Kirsher /**************************************************************************
1883874aeea5SJeff Kirsher  *
1884874aeea5SJeff Kirsher  * NIC startup/shutdown
1885874aeea5SJeff Kirsher  *
1886874aeea5SJeff Kirsher  *************************************************************************/
1887874aeea5SJeff Kirsher 
1888874aeea5SJeff Kirsher static int efx_probe_all(struct efx_nic *efx)
1889874aeea5SJeff Kirsher {
1890874aeea5SJeff Kirsher 	int rc;
1891874aeea5SJeff Kirsher 
1892874aeea5SJeff Kirsher 	rc = efx_probe_nic(efx);
1893874aeea5SJeff Kirsher 	if (rc) {
1894874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
1895874aeea5SJeff Kirsher 		goto fail1;
1896874aeea5SJeff Kirsher 	}
1897874aeea5SJeff Kirsher 
1898874aeea5SJeff Kirsher 	rc = efx_probe_port(efx);
1899874aeea5SJeff Kirsher 	if (rc) {
1900874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev, "failed to create port\n");
1901874aeea5SJeff Kirsher 		goto fail2;
1902874aeea5SJeff Kirsher 	}
1903874aeea5SJeff Kirsher 
19047e6d06f0SBen Hutchings 	BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
19057e6d06f0SBen Hutchings 	if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
19067e6d06f0SBen Hutchings 		rc = -EINVAL;
19077e6d06f0SBen Hutchings 		goto fail3;
19087e6d06f0SBen Hutchings 	}
1909874aeea5SJeff Kirsher 	efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
1910874aeea5SJeff Kirsher 
19116d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV
19126d8aaaf6SDaniel Pieczko 	rc = efx->type->vswitching_probe(efx);
19136d8aaaf6SDaniel Pieczko 	if (rc) /* not fatal; the PF will still work fine */
19146d8aaaf6SDaniel Pieczko 		netif_warn(efx, probe, efx->net_dev,
19156d8aaaf6SDaniel Pieczko 			   "failed to setup vswitching rc=%d;"
19166d8aaaf6SDaniel Pieczko 			   " VFs may not function\n", rc);
19176d8aaaf6SDaniel Pieczko #endif
19186d8aaaf6SDaniel Pieczko 
1919874aeea5SJeff Kirsher 	rc = efx_probe_filters(efx);
1920874aeea5SJeff Kirsher 	if (rc) {
1921874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
1922874aeea5SJeff Kirsher 			  "failed to create filter tables\n");
19236d8aaaf6SDaniel Pieczko 		goto fail4;
1924874aeea5SJeff Kirsher 	}
1925874aeea5SJeff Kirsher 
19267f967c01SBen Hutchings 	rc = efx_probe_channels(efx);
19277f967c01SBen Hutchings 	if (rc)
19286d8aaaf6SDaniel Pieczko 		goto fail5;
19297f967c01SBen Hutchings 
1930874aeea5SJeff Kirsher 	return 0;
1931874aeea5SJeff Kirsher 
19326d8aaaf6SDaniel Pieczko  fail5:
19337f967c01SBen Hutchings 	efx_remove_filters(efx);
19346d8aaaf6SDaniel Pieczko  fail4:
19356d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV
19366d8aaaf6SDaniel Pieczko 	efx->type->vswitching_remove(efx);
19376d8aaaf6SDaniel Pieczko #endif
1938874aeea5SJeff Kirsher  fail3:
1939874aeea5SJeff Kirsher 	efx_remove_port(efx);
1940874aeea5SJeff Kirsher  fail2:
1941874aeea5SJeff Kirsher 	efx_remove_nic(efx);
1942874aeea5SJeff Kirsher  fail1:
1943874aeea5SJeff Kirsher 	return rc;
1944874aeea5SJeff Kirsher }
1945874aeea5SJeff Kirsher 
19468b7325b4SBen Hutchings /* If the interface is supposed to be running but is not, start
19478b7325b4SBen Hutchings  * the hardware and software data path, regular activity for the port
19488b7325b4SBen Hutchings  * (MAC statistics, link polling, etc.) and schedule the port to be
19498b7325b4SBen Hutchings  * reconfigured.  Interrupts must already be enabled.  This function
19508b7325b4SBen Hutchings  * is safe to call multiple times, so long as the NIC is not disabled.
19518b7325b4SBen Hutchings  * Requires the RTNL lock.
19529f2cb71cSBen Hutchings  */
1953874aeea5SJeff Kirsher static void efx_start_all(struct efx_nic *efx)
1954874aeea5SJeff Kirsher {
1955874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
19568b7325b4SBen Hutchings 	BUG_ON(efx->state == STATE_DISABLED);
1957874aeea5SJeff Kirsher 
1958874aeea5SJeff Kirsher 	/* Check that it is appropriate to restart the interface. All
1959874aeea5SJeff Kirsher 	 * of these flags are safe to read under just the rtnl lock */
1960e283546cSEdward Cree 	if (efx->port_enabled || !netif_running(efx->net_dev) ||
1961e283546cSEdward Cree 	    efx->reset_pending)
1962874aeea5SJeff Kirsher 		return;
1963874aeea5SJeff Kirsher 
1964874aeea5SJeff Kirsher 	efx_start_port(efx);
19659f2cb71cSBen Hutchings 	efx_start_datapath(efx);
1966874aeea5SJeff Kirsher 
1967626950dbSAlexandre Rames 	/* Start the hardware monitor if there is one */
1968626950dbSAlexandre Rames 	if (efx->type->monitor != NULL)
1969874aeea5SJeff Kirsher 		queue_delayed_work(efx->workqueue, &efx->monitor_work,
1970874aeea5SJeff Kirsher 				   efx_monitor_interval);
1971626950dbSAlexandre Rames 
19725a6681e2SEdward Cree 	/* Link state detection is normally event-driven; we have
1973626950dbSAlexandre Rames 	 * to poll now because we could have missed a change
1974626950dbSAlexandre Rames 	 */
1975874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
1976874aeea5SJeff Kirsher 	if (efx->phy_op->poll(efx))
1977874aeea5SJeff Kirsher 		efx_link_status_changed(efx);
1978874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
1979874aeea5SJeff Kirsher 
1980874aeea5SJeff Kirsher 	efx->type->start_stats(efx);
1981f8f3b5aeSJon Cooper 	efx->type->pull_stats(efx);
1982f8f3b5aeSJon Cooper 	spin_lock_bh(&efx->stats_lock);
1983f8f3b5aeSJon Cooper 	efx->type->update_stats(efx, NULL, NULL);
1984f8f3b5aeSJon Cooper 	spin_unlock_bh(&efx->stats_lock);
1985874aeea5SJeff Kirsher }
1986874aeea5SJeff Kirsher 
19878b7325b4SBen Hutchings /* Quiesce the hardware and software data path, and regular activity
19888b7325b4SBen Hutchings  * for the port without bringing the link down.  Safe to call multiple
19898b7325b4SBen Hutchings  * times with the NIC in almost any state, but interrupts should be
19908b7325b4SBen Hutchings  * enabled.  Requires the RTNL lock.
19918b7325b4SBen Hutchings  */
1992874aeea5SJeff Kirsher static void efx_stop_all(struct efx_nic *efx)
1993874aeea5SJeff Kirsher {
1994874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
1995874aeea5SJeff Kirsher 
1996874aeea5SJeff Kirsher 	/* port_enabled can be read safely under the rtnl lock */
1997874aeea5SJeff Kirsher 	if (!efx->port_enabled)
1998874aeea5SJeff Kirsher 		return;
1999874aeea5SJeff Kirsher 
2000f8f3b5aeSJon Cooper 	/* update stats before we go down so we can accurately count
2001f8f3b5aeSJon Cooper 	 * rx_nodesc_drops
2002f8f3b5aeSJon Cooper 	 */
2003f8f3b5aeSJon Cooper 	efx->type->pull_stats(efx);
2004f8f3b5aeSJon Cooper 	spin_lock_bh(&efx->stats_lock);
2005f8f3b5aeSJon Cooper 	efx->type->update_stats(efx, NULL, NULL);
2006f8f3b5aeSJon Cooper 	spin_unlock_bh(&efx->stats_lock);
2007874aeea5SJeff Kirsher 	efx->type->stop_stats(efx);
2008874aeea5SJeff Kirsher 	efx_stop_port(efx);
2009874aeea5SJeff Kirsher 
201029c69a48SBen Hutchings 	/* Stop the kernel transmit interface.  This is only valid if
201129c69a48SBen Hutchings 	 * the device is stopped or detached; otherwise the watchdog
201229c69a48SBen Hutchings 	 * may fire immediately.
201329c69a48SBen Hutchings 	 */
201429c69a48SBen Hutchings 	WARN_ON(netif_running(efx->net_dev) &&
201529c69a48SBen Hutchings 		netif_device_present(efx->net_dev));
20169f2cb71cSBen Hutchings 	netif_tx_disable(efx->net_dev);
20179f2cb71cSBen Hutchings 
20189f2cb71cSBen Hutchings 	efx_stop_datapath(efx);
2019874aeea5SJeff Kirsher }
2020874aeea5SJeff Kirsher 
2021874aeea5SJeff Kirsher static void efx_remove_all(struct efx_nic *efx)
2022874aeea5SJeff Kirsher {
2023874aeea5SJeff Kirsher 	efx_remove_channels(efx);
20247f967c01SBen Hutchings 	efx_remove_filters(efx);
20256d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV
20266d8aaaf6SDaniel Pieczko 	efx->type->vswitching_remove(efx);
20276d8aaaf6SDaniel Pieczko #endif
2028874aeea5SJeff Kirsher 	efx_remove_port(efx);
2029874aeea5SJeff Kirsher 	efx_remove_nic(efx);
2030874aeea5SJeff Kirsher }
2031874aeea5SJeff Kirsher 
2032874aeea5SJeff Kirsher /**************************************************************************
2033874aeea5SJeff Kirsher  *
2034874aeea5SJeff Kirsher  * Interrupt moderation
2035874aeea5SJeff Kirsher  *
2036874aeea5SJeff Kirsher  **************************************************************************/
2037539de7c5SBert Kenward unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
2038874aeea5SJeff Kirsher {
2039b548f976SBen Hutchings 	if (usecs == 0)
2040b548f976SBen Hutchings 		return 0;
2041539de7c5SBert Kenward 	if (usecs * 1000 < efx->timer_quantum_ns)
2042874aeea5SJeff Kirsher 		return 1; /* never round down to 0 */
2043539de7c5SBert Kenward 	return usecs * 1000 / efx->timer_quantum_ns;
2044539de7c5SBert Kenward }
2045539de7c5SBert Kenward 
2046539de7c5SBert Kenward unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
2047539de7c5SBert Kenward {
2048539de7c5SBert Kenward 	/* We must round up when converting ticks to microseconds
2049539de7c5SBert Kenward 	 * because we round down when converting the other way.
2050539de7c5SBert Kenward 	 */
2051539de7c5SBert Kenward 	return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
2052874aeea5SJeff Kirsher }
2053874aeea5SJeff Kirsher 
2054874aeea5SJeff Kirsher /* Set interrupt moderation parameters */
20559e393b30SBen Hutchings int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
20569e393b30SBen Hutchings 			    unsigned int rx_usecs, bool rx_adaptive,
20579e393b30SBen Hutchings 			    bool rx_may_override_tx)
2058874aeea5SJeff Kirsher {
2059874aeea5SJeff Kirsher 	struct efx_channel *channel;
2060d95e329aSBert Kenward 	unsigned int timer_max_us;
2061d95e329aSBert Kenward 
2062874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
2063874aeea5SJeff Kirsher 
2064d95e329aSBert Kenward 	timer_max_us = efx->timer_max_ns / 1000;
2065d95e329aSBert Kenward 
2066d95e329aSBert Kenward 	if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
20679e393b30SBen Hutchings 		return -EINVAL;
20689e393b30SBen Hutchings 
2069539de7c5SBert Kenward 	if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
20709e393b30SBen Hutchings 	    !rx_may_override_tx) {
20719e393b30SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Channels are shared. "
20729e393b30SBen Hutchings 			  "RX and TX IRQ moderation must be equal\n");
20739e393b30SBen Hutchings 		return -EINVAL;
20749e393b30SBen Hutchings 	}
20759e393b30SBen Hutchings 
2076874aeea5SJeff Kirsher 	efx->irq_rx_adaptive = rx_adaptive;
2077539de7c5SBert Kenward 	efx->irq_rx_moderation_us = rx_usecs;
2078874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx) {
2079874aeea5SJeff Kirsher 		if (efx_channel_has_rx_queue(channel))
2080539de7c5SBert Kenward 			channel->irq_moderation_us = rx_usecs;
2081874aeea5SJeff Kirsher 		else if (efx_channel_has_tx_queues(channel))
2082539de7c5SBert Kenward 			channel->irq_moderation_us = tx_usecs;
2083874aeea5SJeff Kirsher 	}
20849e393b30SBen Hutchings 
20859e393b30SBen Hutchings 	return 0;
2086874aeea5SJeff Kirsher }
2087874aeea5SJeff Kirsher 
2088a0c4faf5SBen Hutchings void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
2089a0c4faf5SBen Hutchings 			    unsigned int *rx_usecs, bool *rx_adaptive)
2090a0c4faf5SBen Hutchings {
2091a0c4faf5SBen Hutchings 	*rx_adaptive = efx->irq_rx_adaptive;
2092539de7c5SBert Kenward 	*rx_usecs = efx->irq_rx_moderation_us;
2093a0c4faf5SBen Hutchings 
2094a0c4faf5SBen Hutchings 	/* If channels are shared between RX and TX, so is IRQ
2095a0c4faf5SBen Hutchings 	 * moderation.  Otherwise, IRQ moderation is the same for all
2096a0c4faf5SBen Hutchings 	 * TX channels and is not adaptive.
2097a0c4faf5SBen Hutchings 	 */
2098539de7c5SBert Kenward 	if (efx->tx_channel_offset == 0) {
2099a0c4faf5SBen Hutchings 		*tx_usecs = *rx_usecs;
2100539de7c5SBert Kenward 	} else {
2101539de7c5SBert Kenward 		struct efx_channel *tx_channel;
2102539de7c5SBert Kenward 
2103539de7c5SBert Kenward 		tx_channel = efx->channel[efx->tx_channel_offset];
2104539de7c5SBert Kenward 		*tx_usecs = tx_channel->irq_moderation_us;
2105539de7c5SBert Kenward 	}
2106a0c4faf5SBen Hutchings }
2107a0c4faf5SBen Hutchings 
2108874aeea5SJeff Kirsher /**************************************************************************
2109874aeea5SJeff Kirsher  *
2110874aeea5SJeff Kirsher  * Hardware monitor
2111874aeea5SJeff Kirsher  *
2112874aeea5SJeff Kirsher  **************************************************************************/
2113874aeea5SJeff Kirsher 
2114874aeea5SJeff Kirsher /* Run periodically off the general workqueue */
2115874aeea5SJeff Kirsher static void efx_monitor(struct work_struct *data)
2116874aeea5SJeff Kirsher {
2117874aeea5SJeff Kirsher 	struct efx_nic *efx = container_of(data, struct efx_nic,
2118874aeea5SJeff Kirsher 					   monitor_work.work);
2119874aeea5SJeff Kirsher 
2120874aeea5SJeff Kirsher 	netif_vdbg(efx, timer, efx->net_dev,
2121874aeea5SJeff Kirsher 		   "hardware monitor executing on CPU %d\n",
2122874aeea5SJeff Kirsher 		   raw_smp_processor_id());
2123874aeea5SJeff Kirsher 	BUG_ON(efx->type->monitor == NULL);
2124874aeea5SJeff Kirsher 
2125874aeea5SJeff Kirsher 	/* If the mac_lock is already held then it is likely a port
2126874aeea5SJeff Kirsher 	 * reconfiguration is already in place, which will likely do
2127874aeea5SJeff Kirsher 	 * most of the work of monitor() anyway. */
2128874aeea5SJeff Kirsher 	if (mutex_trylock(&efx->mac_lock)) {
2129874aeea5SJeff Kirsher 		if (efx->port_enabled)
2130874aeea5SJeff Kirsher 			efx->type->monitor(efx);
2131874aeea5SJeff Kirsher 		mutex_unlock(&efx->mac_lock);
2132874aeea5SJeff Kirsher 	}
2133874aeea5SJeff Kirsher 
2134874aeea5SJeff Kirsher 	queue_delayed_work(efx->workqueue, &efx->monitor_work,
2135874aeea5SJeff Kirsher 			   efx_monitor_interval);
2136874aeea5SJeff Kirsher }
2137874aeea5SJeff Kirsher 
2138874aeea5SJeff Kirsher /**************************************************************************
2139874aeea5SJeff Kirsher  *
2140874aeea5SJeff Kirsher  * ioctls
2141874aeea5SJeff Kirsher  *
2142874aeea5SJeff Kirsher  *************************************************************************/
2143874aeea5SJeff Kirsher 
2144874aeea5SJeff Kirsher /* Net device ioctl
2145874aeea5SJeff Kirsher  * Context: process, rtnl_lock() held.
2146874aeea5SJeff Kirsher  */
2147874aeea5SJeff Kirsher static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
2148874aeea5SJeff Kirsher {
2149874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2150874aeea5SJeff Kirsher 	struct mii_ioctl_data *data = if_mii(ifr);
2151874aeea5SJeff Kirsher 
21527c236c43SStuart Hodgson 	if (cmd == SIOCSHWTSTAMP)
2153433dc9b3SBen Hutchings 		return efx_ptp_set_ts_config(efx, ifr);
2154433dc9b3SBen Hutchings 	if (cmd == SIOCGHWTSTAMP)
2155433dc9b3SBen Hutchings 		return efx_ptp_get_ts_config(efx, ifr);
21567c236c43SStuart Hodgson 
2157874aeea5SJeff Kirsher 	/* Convert phy_id from older PRTAD/DEVAD format */
2158874aeea5SJeff Kirsher 	if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
2159874aeea5SJeff Kirsher 	    (data->phy_id & 0xfc00) == 0x0400)
2160874aeea5SJeff Kirsher 		data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
2161874aeea5SJeff Kirsher 
2162874aeea5SJeff Kirsher 	return mdio_mii_ioctl(&efx->mdio, data, cmd);
2163874aeea5SJeff Kirsher }
2164874aeea5SJeff Kirsher 
2165874aeea5SJeff Kirsher /**************************************************************************
2166874aeea5SJeff Kirsher  *
2167874aeea5SJeff Kirsher  * NAPI interface
2168874aeea5SJeff Kirsher  *
2169874aeea5SJeff Kirsher  **************************************************************************/
2170874aeea5SJeff Kirsher 
21717f967c01SBen Hutchings static void efx_init_napi_channel(struct efx_channel *channel)
2172874aeea5SJeff Kirsher {
21737f967c01SBen Hutchings 	struct efx_nic *efx = channel->efx;
2174874aeea5SJeff Kirsher 
2175874aeea5SJeff Kirsher 	channel->napi_dev = efx->net_dev;
2176874aeea5SJeff Kirsher 	netif_napi_add(channel->napi_dev, &channel->napi_str,
2177874aeea5SJeff Kirsher 		       efx_poll, napi_weight);
2178874aeea5SJeff Kirsher }
21797f967c01SBen Hutchings 
21807f967c01SBen Hutchings static void efx_init_napi(struct efx_nic *efx)
21817f967c01SBen Hutchings {
21827f967c01SBen Hutchings 	struct efx_channel *channel;
21837f967c01SBen Hutchings 
21847f967c01SBen Hutchings 	efx_for_each_channel(channel, efx)
21857f967c01SBen Hutchings 		efx_init_napi_channel(channel);
2186874aeea5SJeff Kirsher }
2187874aeea5SJeff Kirsher 
2188874aeea5SJeff Kirsher static void efx_fini_napi_channel(struct efx_channel *channel)
2189874aeea5SJeff Kirsher {
2190973334a1SEric Dumazet 	if (channel->napi_dev)
2191874aeea5SJeff Kirsher 		netif_napi_del(&channel->napi_str);
2192973334a1SEric Dumazet 
2193874aeea5SJeff Kirsher 	channel->napi_dev = NULL;
2194874aeea5SJeff Kirsher }
2195874aeea5SJeff Kirsher 
2196874aeea5SJeff Kirsher static void efx_fini_napi(struct efx_nic *efx)
2197874aeea5SJeff Kirsher {
2198874aeea5SJeff Kirsher 	struct efx_channel *channel;
2199874aeea5SJeff Kirsher 
2200874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx)
2201874aeea5SJeff Kirsher 		efx_fini_napi_channel(channel);
2202874aeea5SJeff Kirsher }
2203874aeea5SJeff Kirsher 
2204874aeea5SJeff Kirsher /**************************************************************************
2205874aeea5SJeff Kirsher  *
2206874aeea5SJeff Kirsher  * Kernel netpoll interface
2207874aeea5SJeff Kirsher  *
2208874aeea5SJeff Kirsher  *************************************************************************/
2209874aeea5SJeff Kirsher 
2210874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER
2211874aeea5SJeff Kirsher 
2212874aeea5SJeff Kirsher /* Although in the common case interrupts will be disabled, this is not
2213874aeea5SJeff Kirsher  * guaranteed. However, all our work happens inside the NAPI callback,
2214874aeea5SJeff Kirsher  * so no locking is required.
2215874aeea5SJeff Kirsher  */
2216874aeea5SJeff Kirsher static void efx_netpoll(struct net_device *net_dev)
2217874aeea5SJeff Kirsher {
2218874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2219874aeea5SJeff Kirsher 	struct efx_channel *channel;
2220874aeea5SJeff Kirsher 
2221874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx)
2222874aeea5SJeff Kirsher 		efx_schedule_channel(channel);
2223874aeea5SJeff Kirsher }
2224874aeea5SJeff Kirsher 
2225874aeea5SJeff Kirsher #endif
2226874aeea5SJeff Kirsher 
2227874aeea5SJeff Kirsher /**************************************************************************
2228874aeea5SJeff Kirsher  *
2229874aeea5SJeff Kirsher  * Kernel net device interface
2230874aeea5SJeff Kirsher  *
2231874aeea5SJeff Kirsher  *************************************************************************/
2232874aeea5SJeff Kirsher 
2233874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */
2234e340be92SShradha Shah int efx_net_open(struct net_device *net_dev)
2235874aeea5SJeff Kirsher {
2236874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
22378b7325b4SBen Hutchings 	int rc;
22388b7325b4SBen Hutchings 
2239874aeea5SJeff Kirsher 	netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
2240874aeea5SJeff Kirsher 		  raw_smp_processor_id());
2241874aeea5SJeff Kirsher 
22428b7325b4SBen Hutchings 	rc = efx_check_disabled(efx);
22438b7325b4SBen Hutchings 	if (rc)
22448b7325b4SBen Hutchings 		return rc;
2245874aeea5SJeff Kirsher 	if (efx->phy_mode & PHY_MODE_SPECIAL)
2246874aeea5SJeff Kirsher 		return -EBUSY;
2247874aeea5SJeff Kirsher 	if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
2248874aeea5SJeff Kirsher 		return -EIO;
2249874aeea5SJeff Kirsher 
2250874aeea5SJeff Kirsher 	/* Notify the kernel of the link state polled during driver load,
2251874aeea5SJeff Kirsher 	 * before the monitor starts running */
2252874aeea5SJeff Kirsher 	efx_link_status_changed(efx);
2253874aeea5SJeff Kirsher 
2254874aeea5SJeff Kirsher 	efx_start_all(efx);
22559c568fd8SPeter Dunning 	if (efx->state == STATE_DISABLED || efx->reset_pending)
22569c568fd8SPeter Dunning 		netif_device_detach(efx->net_dev);
2257dd40781eSBen Hutchings 	efx_selftest_async_start(efx);
2258874aeea5SJeff Kirsher 	return 0;
2259874aeea5SJeff Kirsher }
2260874aeea5SJeff Kirsher 
2261874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held.
2262874aeea5SJeff Kirsher  * Note that the kernel will ignore our return code; this method
2263874aeea5SJeff Kirsher  * should really be a void.
2264874aeea5SJeff Kirsher  */
2265e340be92SShradha Shah int efx_net_stop(struct net_device *net_dev)
2266874aeea5SJeff Kirsher {
2267874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2268874aeea5SJeff Kirsher 
2269874aeea5SJeff Kirsher 	netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
2270874aeea5SJeff Kirsher 		  raw_smp_processor_id());
2271874aeea5SJeff Kirsher 
2272874aeea5SJeff Kirsher 	/* Stop the device and flush all the channels */
2273874aeea5SJeff Kirsher 	efx_stop_all(efx);
2274874aeea5SJeff Kirsher 
2275874aeea5SJeff Kirsher 	return 0;
2276874aeea5SJeff Kirsher }
2277874aeea5SJeff Kirsher 
2278874aeea5SJeff Kirsher /* Context: process, dev_base_lock or RTNL held, non-blocking. */
2279bc1f4470Sstephen hemminger static void efx_net_stats(struct net_device *net_dev,
22802aa9ef11SBen Hutchings 			  struct rtnl_link_stats64 *stats)
2281874aeea5SJeff Kirsher {
2282874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2283874aeea5SJeff Kirsher 
2284874aeea5SJeff Kirsher 	spin_lock_bh(&efx->stats_lock);
2285cd0ecc9aSBen Hutchings 	efx->type->update_stats(efx, NULL, stats);
22861cb34522SBen Hutchings 	spin_unlock_bh(&efx->stats_lock);
2287874aeea5SJeff Kirsher }
2288874aeea5SJeff Kirsher 
2289874aeea5SJeff Kirsher /* Context: netif_tx_lock held, BHs disabled. */
2290874aeea5SJeff Kirsher static void efx_watchdog(struct net_device *net_dev)
2291874aeea5SJeff Kirsher {
2292874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2293874aeea5SJeff Kirsher 
2294874aeea5SJeff Kirsher 	netif_err(efx, tx_err, efx->net_dev,
2295874aeea5SJeff Kirsher 		  "TX stuck with port_enabled=%d: resetting channels\n",
2296874aeea5SJeff Kirsher 		  efx->port_enabled);
2297874aeea5SJeff Kirsher 
2298874aeea5SJeff Kirsher 	efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
2299874aeea5SJeff Kirsher }
2300874aeea5SJeff Kirsher 
2301874aeea5SJeff Kirsher 
2302874aeea5SJeff Kirsher /* Context: process, rtnl_lock() held. */
2303874aeea5SJeff Kirsher static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
2304874aeea5SJeff Kirsher {
2305874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
23068b7325b4SBen Hutchings 	int rc;
2307874aeea5SJeff Kirsher 
23088b7325b4SBen Hutchings 	rc = efx_check_disabled(efx);
23098b7325b4SBen Hutchings 	if (rc)
23108b7325b4SBen Hutchings 		return rc;
2311874aeea5SJeff Kirsher 
2312874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
2313874aeea5SJeff Kirsher 
231429c69a48SBen Hutchings 	efx_device_detach_sync(efx);
231529c69a48SBen Hutchings 	efx_stop_all(efx);
231629c69a48SBen Hutchings 
2317874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
2318874aeea5SJeff Kirsher 	net_dev->mtu = new_mtu;
23190d322413SEdward Cree 	efx_mac_reconfigure(efx);
2320874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
2321874aeea5SJeff Kirsher 
2322874aeea5SJeff Kirsher 	efx_start_all(efx);
23239c568fd8SPeter Dunning 	efx_device_attach_if_not_resetting(efx);
23246c8eef4aSBen Hutchings 	return 0;
2325874aeea5SJeff Kirsher }
2326874aeea5SJeff Kirsher 
2327874aeea5SJeff Kirsher static int efx_set_mac_address(struct net_device *net_dev, void *data)
2328874aeea5SJeff Kirsher {
2329874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2330874aeea5SJeff Kirsher 	struct sockaddr *addr = data;
2331e0b3ae30SBen Hutchings 	u8 *new_addr = addr->sa_data;
2332cfc77c2fSShradha Shah 	u8 old_addr[6];
2333cfc77c2fSShradha Shah 	int rc;
2334874aeea5SJeff Kirsher 
2335874aeea5SJeff Kirsher 	if (!is_valid_ether_addr(new_addr)) {
2336874aeea5SJeff Kirsher 		netif_err(efx, drv, efx->net_dev,
2337874aeea5SJeff Kirsher 			  "invalid ethernet MAC address requested: %pM\n",
2338874aeea5SJeff Kirsher 			  new_addr);
2339504f9b5aSDanny Kukawka 		return -EADDRNOTAVAIL;
2340874aeea5SJeff Kirsher 	}
2341874aeea5SJeff Kirsher 
2342cfc77c2fSShradha Shah 	/* save old address */
2343cfc77c2fSShradha Shah 	ether_addr_copy(old_addr, net_dev->dev_addr);
2344cd84ff4dSEdward Cree 	ether_addr_copy(net_dev->dev_addr, new_addr);
2345910c8789SShradha Shah 	if (efx->type->set_mac_address) {
2346910c8789SShradha Shah 		rc = efx->type->set_mac_address(efx);
2347cfc77c2fSShradha Shah 		if (rc) {
2348cfc77c2fSShradha Shah 			ether_addr_copy(net_dev->dev_addr, old_addr);
2349cfc77c2fSShradha Shah 			return rc;
2350cfc77c2fSShradha Shah 		}
2351cfc77c2fSShradha Shah 	}
2352874aeea5SJeff Kirsher 
2353874aeea5SJeff Kirsher 	/* Reconfigure the MAC */
2354874aeea5SJeff Kirsher 	mutex_lock(&efx->mac_lock);
23550d322413SEdward Cree 	efx_mac_reconfigure(efx);
2356874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
2357874aeea5SJeff Kirsher 
2358874aeea5SJeff Kirsher 	return 0;
2359874aeea5SJeff Kirsher }
2360874aeea5SJeff Kirsher 
2361874aeea5SJeff Kirsher /* Context: netif_addr_lock held, BHs disabled. */
23620fca8c97SBen Hutchings static void efx_set_rx_mode(struct net_device *net_dev)
2363874aeea5SJeff Kirsher {
2364874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
2365874aeea5SJeff Kirsher 
2366874aeea5SJeff Kirsher 	if (efx->port_enabled)
2367874aeea5SJeff Kirsher 		queue_work(efx->workqueue, &efx->mac_work);
2368874aeea5SJeff Kirsher 	/* Otherwise efx_start_port() will do this */
2369874aeea5SJeff Kirsher }
2370874aeea5SJeff Kirsher 
2371c8f44affSMichał Mirosław static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
2372874aeea5SJeff Kirsher {
2373874aeea5SJeff Kirsher 	struct efx_nic *efx = netdev_priv(net_dev);
23744a53ea8aSAndrew Rybchenko 	int rc;
2375874aeea5SJeff Kirsher 
2376874aeea5SJeff Kirsher 	/* If disabling RX n-tuple filtering, clear existing filters */
23774a53ea8aSAndrew Rybchenko 	if (net_dev->features & ~data & NETIF_F_NTUPLE) {
23784a53ea8aSAndrew Rybchenko 		rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
23794a53ea8aSAndrew Rybchenko 		if (rc)
23804a53ea8aSAndrew Rybchenko 			return rc;
23814a53ea8aSAndrew Rybchenko 	}
23824a53ea8aSAndrew Rybchenko 
23836978729fSEdward Cree 	/* If Rx VLAN filter is changed, update filters via mac_reconfigure.
23846978729fSEdward Cree 	 * If rx-fcs is changed, mac_reconfigure updates that too.
23856978729fSEdward Cree 	 */
23866978729fSEdward Cree 	if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
23876978729fSEdward Cree 					  NETIF_F_RXFCS)) {
23884a53ea8aSAndrew Rybchenko 		/* efx_set_rx_mode() will schedule MAC work to update filters
23894a53ea8aSAndrew Rybchenko 		 * when a new features are finally set in net_dev.
23904a53ea8aSAndrew Rybchenko 		 */
23914a53ea8aSAndrew Rybchenko 		efx_set_rx_mode(net_dev);
23924a53ea8aSAndrew Rybchenko 	}
2393874aeea5SJeff Kirsher 
2394874aeea5SJeff Kirsher 	return 0;
2395874aeea5SJeff Kirsher }
2396874aeea5SJeff Kirsher 
2397b40296fcSWei Yongjun static int efx_get_phys_port_id(struct net_device *net_dev,
239808a7b29bSBert Kenward 				struct netdev_phys_item_id *ppid)
239908a7b29bSBert Kenward {
240008a7b29bSBert Kenward 	struct efx_nic *efx = netdev_priv(net_dev);
240108a7b29bSBert Kenward 
240208a7b29bSBert Kenward 	if (efx->type->get_phys_port_id)
240308a7b29bSBert Kenward 		return efx->type->get_phys_port_id(efx, ppid);
240408a7b29bSBert Kenward 	else
240508a7b29bSBert Kenward 		return -EOPNOTSUPP;
240608a7b29bSBert Kenward }
240708a7b29bSBert Kenward 
2408ac019f08SBert Kenward static int efx_get_phys_port_name(struct net_device *net_dev,
2409ac019f08SBert Kenward 				  char *name, size_t len)
2410ac019f08SBert Kenward {
2411ac019f08SBert Kenward 	struct efx_nic *efx = netdev_priv(net_dev);
2412ac019f08SBert Kenward 
2413ac019f08SBert Kenward 	if (snprintf(name, len, "p%u", efx->port_num) >= len)
2414ac019f08SBert Kenward 		return -EINVAL;
2415ac019f08SBert Kenward 	return 0;
2416ac019f08SBert Kenward }
2417ac019f08SBert Kenward 
24184a53ea8aSAndrew Rybchenko static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
24194a53ea8aSAndrew Rybchenko {
24204a53ea8aSAndrew Rybchenko 	struct efx_nic *efx = netdev_priv(net_dev);
24214a53ea8aSAndrew Rybchenko 
24224a53ea8aSAndrew Rybchenko 	if (efx->type->vlan_rx_add_vid)
24234a53ea8aSAndrew Rybchenko 		return efx->type->vlan_rx_add_vid(efx, proto, vid);
24244a53ea8aSAndrew Rybchenko 	else
24254a53ea8aSAndrew Rybchenko 		return -EOPNOTSUPP;
24264a53ea8aSAndrew Rybchenko }
24274a53ea8aSAndrew Rybchenko 
24284a53ea8aSAndrew Rybchenko static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
24294a53ea8aSAndrew Rybchenko {
24304a53ea8aSAndrew Rybchenko 	struct efx_nic *efx = netdev_priv(net_dev);
24314a53ea8aSAndrew Rybchenko 
24324a53ea8aSAndrew Rybchenko 	if (efx->type->vlan_rx_kill_vid)
24334a53ea8aSAndrew Rybchenko 		return efx->type->vlan_rx_kill_vid(efx, proto, vid);
24344a53ea8aSAndrew Rybchenko 	else
24354a53ea8aSAndrew Rybchenko 		return -EOPNOTSUPP;
24364a53ea8aSAndrew Rybchenko }
24374a53ea8aSAndrew Rybchenko 
2438e5fbd977SJon Cooper static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
2439e5fbd977SJon Cooper {
2440e5fbd977SJon Cooper 	switch (in) {
2441e5fbd977SJon Cooper 	case UDP_TUNNEL_TYPE_VXLAN:
2442e5fbd977SJon Cooper 		return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
2443e5fbd977SJon Cooper 	case UDP_TUNNEL_TYPE_GENEVE:
2444e5fbd977SJon Cooper 		return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
2445e5fbd977SJon Cooper 	default:
2446e5fbd977SJon Cooper 		return -1;
2447e5fbd977SJon Cooper 	}
2448e5fbd977SJon Cooper }
2449e5fbd977SJon Cooper 
2450e5fbd977SJon Cooper static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
2451e5fbd977SJon Cooper {
2452e5fbd977SJon Cooper 	struct efx_nic *efx = netdev_priv(dev);
2453e5fbd977SJon Cooper 	struct efx_udp_tunnel tnl;
2454e5fbd977SJon Cooper 	int efx_tunnel_type;
2455e5fbd977SJon Cooper 
2456e5fbd977SJon Cooper 	efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2457e5fbd977SJon Cooper 	if (efx_tunnel_type < 0)
2458e5fbd977SJon Cooper 		return;
2459e5fbd977SJon Cooper 
2460e5fbd977SJon Cooper 	tnl.type = (u16)efx_tunnel_type;
2461e5fbd977SJon Cooper 	tnl.port = ti->port;
2462e5fbd977SJon Cooper 
2463e5fbd977SJon Cooper 	if (efx->type->udp_tnl_add_port)
2464e5fbd977SJon Cooper 		(void)efx->type->udp_tnl_add_port(efx, tnl);
2465e5fbd977SJon Cooper }
2466e5fbd977SJon Cooper 
2467e5fbd977SJon Cooper static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
2468e5fbd977SJon Cooper {
2469e5fbd977SJon Cooper 	struct efx_nic *efx = netdev_priv(dev);
2470e5fbd977SJon Cooper 	struct efx_udp_tunnel tnl;
2471e5fbd977SJon Cooper 	int efx_tunnel_type;
2472e5fbd977SJon Cooper 
2473e5fbd977SJon Cooper 	efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
2474e5fbd977SJon Cooper 	if (efx_tunnel_type < 0)
2475e5fbd977SJon Cooper 		return;
2476e5fbd977SJon Cooper 
2477e5fbd977SJon Cooper 	tnl.type = (u16)efx_tunnel_type;
2478e5fbd977SJon Cooper 	tnl.port = ti->port;
2479e5fbd977SJon Cooper 
2480c04ca616SDan Carpenter 	if (efx->type->udp_tnl_del_port)
2481e5fbd977SJon Cooper 		(void)efx->type->udp_tnl_del_port(efx, tnl);
2482e5fbd977SJon Cooper }
2483e5fbd977SJon Cooper 
24847fa8d547SShradha Shah static const struct net_device_ops efx_netdev_ops = {
2485874aeea5SJeff Kirsher 	.ndo_open		= efx_net_open,
2486874aeea5SJeff Kirsher 	.ndo_stop		= efx_net_stop,
2487874aeea5SJeff Kirsher 	.ndo_get_stats64	= efx_net_stats,
2488874aeea5SJeff Kirsher 	.ndo_tx_timeout		= efx_watchdog,
2489874aeea5SJeff Kirsher 	.ndo_start_xmit		= efx_hard_start_xmit,
2490874aeea5SJeff Kirsher 	.ndo_validate_addr	= eth_validate_addr,
2491874aeea5SJeff Kirsher 	.ndo_do_ioctl		= efx_ioctl,
2492874aeea5SJeff Kirsher 	.ndo_change_mtu		= efx_change_mtu,
2493874aeea5SJeff Kirsher 	.ndo_set_mac_address	= efx_set_mac_address,
24940fca8c97SBen Hutchings 	.ndo_set_rx_mode	= efx_set_rx_mode,
2495874aeea5SJeff Kirsher 	.ndo_set_features	= efx_set_features,
24964a53ea8aSAndrew Rybchenko 	.ndo_vlan_rx_add_vid	= efx_vlan_rx_add_vid,
24974a53ea8aSAndrew Rybchenko 	.ndo_vlan_rx_kill_vid	= efx_vlan_rx_kill_vid,
2498cd2d5b52SBen Hutchings #ifdef CONFIG_SFC_SRIOV
24997fa8d547SShradha Shah 	.ndo_set_vf_mac		= efx_sriov_set_vf_mac,
25007fa8d547SShradha Shah 	.ndo_set_vf_vlan	= efx_sriov_set_vf_vlan,
25017fa8d547SShradha Shah 	.ndo_set_vf_spoofchk	= efx_sriov_set_vf_spoofchk,
25027fa8d547SShradha Shah 	.ndo_get_vf_config	= efx_sriov_get_vf_config,
25034392dc69SEdward Cree 	.ndo_set_vf_link_state  = efx_sriov_set_vf_link_state,
2504cd2d5b52SBen Hutchings #endif
250508a7b29bSBert Kenward 	.ndo_get_phys_port_id   = efx_get_phys_port_id,
2506ac019f08SBert Kenward 	.ndo_get_phys_port_name	= efx_get_phys_port_name,
2507874aeea5SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER
2508874aeea5SJeff Kirsher 	.ndo_poll_controller = efx_netpoll,
2509874aeea5SJeff Kirsher #endif
2510874aeea5SJeff Kirsher 	.ndo_setup_tc		= efx_setup_tc,
2511874aeea5SJeff Kirsher #ifdef CONFIG_RFS_ACCEL
2512874aeea5SJeff Kirsher 	.ndo_rx_flow_steer	= efx_filter_rfs,
2513874aeea5SJeff Kirsher #endif
2514e5fbd977SJon Cooper 	.ndo_udp_tunnel_add	= efx_udp_tunnel_add,
2515e5fbd977SJon Cooper 	.ndo_udp_tunnel_del	= efx_udp_tunnel_del,
2516874aeea5SJeff Kirsher };
2517874aeea5SJeff Kirsher 
2518874aeea5SJeff Kirsher static void efx_update_name(struct efx_nic *efx)
2519874aeea5SJeff Kirsher {
2520874aeea5SJeff Kirsher 	strcpy(efx->name, efx->net_dev->name);
2521874aeea5SJeff Kirsher 	efx_mtd_rename(efx);
2522874aeea5SJeff Kirsher 	efx_set_channel_names(efx);
2523874aeea5SJeff Kirsher }
2524874aeea5SJeff Kirsher 
2525874aeea5SJeff Kirsher static int efx_netdev_event(struct notifier_block *this,
2526874aeea5SJeff Kirsher 			    unsigned long event, void *ptr)
2527874aeea5SJeff Kirsher {
2528351638e7SJiri Pirko 	struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
2529874aeea5SJeff Kirsher 
25307fa8d547SShradha Shah 	if ((net_dev->netdev_ops == &efx_netdev_ops) &&
2531874aeea5SJeff Kirsher 	    event == NETDEV_CHANGENAME)
2532874aeea5SJeff Kirsher 		efx_update_name(netdev_priv(net_dev));
2533874aeea5SJeff Kirsher 
2534874aeea5SJeff Kirsher 	return NOTIFY_DONE;
2535874aeea5SJeff Kirsher }
2536874aeea5SJeff Kirsher 
2537874aeea5SJeff Kirsher static struct notifier_block efx_netdev_notifier = {
2538874aeea5SJeff Kirsher 	.notifier_call = efx_netdev_event,
2539874aeea5SJeff Kirsher };
2540874aeea5SJeff Kirsher 
2541874aeea5SJeff Kirsher static ssize_t
2542874aeea5SJeff Kirsher show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
2543874aeea5SJeff Kirsher {
2544874aeea5SJeff Kirsher 	struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2545874aeea5SJeff Kirsher 	return sprintf(buf, "%d\n", efx->phy_type);
2546874aeea5SJeff Kirsher }
2547776fbcc9SBen Hutchings static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
2548874aeea5SJeff Kirsher 
2549e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING
2550e7fef9b4SEdward Cree static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
2551e7fef9b4SEdward Cree 			     char *buf)
2552e7fef9b4SEdward Cree {
2553e7fef9b4SEdward Cree 	struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2554e7fef9b4SEdward Cree 	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2555e7fef9b4SEdward Cree 
2556e7fef9b4SEdward Cree 	return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
2557e7fef9b4SEdward Cree }
2558e7fef9b4SEdward Cree static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
2559e7fef9b4SEdward Cree 			    const char *buf, size_t count)
2560e7fef9b4SEdward Cree {
2561e7fef9b4SEdward Cree 	struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2562e7fef9b4SEdward Cree 	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
2563e7fef9b4SEdward Cree 	bool enable = count > 0 && *buf != '0';
2564e7fef9b4SEdward Cree 
2565e7fef9b4SEdward Cree 	mcdi->logging_enabled = enable;
2566e7fef9b4SEdward Cree 	return count;
2567e7fef9b4SEdward Cree }
2568e7fef9b4SEdward Cree static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
2569e7fef9b4SEdward Cree #endif
2570e7fef9b4SEdward Cree 
2571874aeea5SJeff Kirsher static int efx_register_netdev(struct efx_nic *efx)
2572874aeea5SJeff Kirsher {
2573874aeea5SJeff Kirsher 	struct net_device *net_dev = efx->net_dev;
2574874aeea5SJeff Kirsher 	struct efx_channel *channel;
2575874aeea5SJeff Kirsher 	int rc;
2576874aeea5SJeff Kirsher 
2577874aeea5SJeff Kirsher 	net_dev->watchdog_timeo = 5 * HZ;
2578874aeea5SJeff Kirsher 	net_dev->irq = efx->pci_dev->irq;
25797fa8d547SShradha Shah 	net_dev->netdev_ops = &efx_netdev_ops;
25807fa8d547SShradha Shah 	if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
25818127d661SBen Hutchings 		net_dev->priv_flags |= IFF_UNICAST_FLT;
25827ad24ea4SWilfried Klaebe 	net_dev->ethtool_ops = &efx_ethtool_ops;
25837e6d06f0SBen Hutchings 	net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
2584cd94e519SBert Kenward 	net_dev->min_mtu = EFX_MIN_MTU;
2585cd94e519SBert Kenward 	net_dev->max_mtu = EFX_MAX_MTU;
2586874aeea5SJeff Kirsher 
2587874aeea5SJeff Kirsher 	rtnl_lock();
2588874aeea5SJeff Kirsher 
25897153f623SBen Hutchings 	/* Enable resets to be scheduled and check whether any were
25907153f623SBen Hutchings 	 * already requested.  If so, the NIC is probably hosed so we
25917153f623SBen Hutchings 	 * abort.
25927153f623SBen Hutchings 	 */
25937153f623SBen Hutchings 	efx->state = STATE_READY;
25947153f623SBen Hutchings 	smp_mb(); /* ensure we change state before checking reset_pending */
25957153f623SBen Hutchings 	if (efx->reset_pending) {
25967153f623SBen Hutchings 		netif_err(efx, probe, efx->net_dev,
25977153f623SBen Hutchings 			  "aborting probe due to scheduled reset\n");
25987153f623SBen Hutchings 		rc = -EIO;
25997153f623SBen Hutchings 		goto fail_locked;
26007153f623SBen Hutchings 	}
26017153f623SBen Hutchings 
2602874aeea5SJeff Kirsher 	rc = dev_alloc_name(net_dev, net_dev->name);
2603874aeea5SJeff Kirsher 	if (rc < 0)
2604874aeea5SJeff Kirsher 		goto fail_locked;
2605874aeea5SJeff Kirsher 	efx_update_name(efx);
2606874aeea5SJeff Kirsher 
26078f8b3d51SBen Hutchings 	/* Always start with carrier off; PHY events will detect the link */
26088f8b3d51SBen Hutchings 	netif_carrier_off(net_dev);
26098f8b3d51SBen Hutchings 
2610874aeea5SJeff Kirsher 	rc = register_netdevice(net_dev);
2611874aeea5SJeff Kirsher 	if (rc)
2612874aeea5SJeff Kirsher 		goto fail_locked;
2613874aeea5SJeff Kirsher 
2614874aeea5SJeff Kirsher 	efx_for_each_channel(channel, efx) {
2615874aeea5SJeff Kirsher 		struct efx_tx_queue *tx_queue;
2616874aeea5SJeff Kirsher 		efx_for_each_channel_tx_queue(tx_queue, channel)
2617874aeea5SJeff Kirsher 			efx_init_tx_queue_core_txq(tx_queue);
2618874aeea5SJeff Kirsher 	}
2619874aeea5SJeff Kirsher 
26200bcf4a64SBen Hutchings 	efx_associate(efx);
26210bcf4a64SBen Hutchings 
2622874aeea5SJeff Kirsher 	rtnl_unlock();
2623874aeea5SJeff Kirsher 
2624874aeea5SJeff Kirsher 	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2625874aeea5SJeff Kirsher 	if (rc) {
2626874aeea5SJeff Kirsher 		netif_err(efx, drv, efx->net_dev,
2627874aeea5SJeff Kirsher 			  "failed to init net dev attributes\n");
2628874aeea5SJeff Kirsher 		goto fail_registered;
2629874aeea5SJeff Kirsher 	}
2630e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING
2631e7fef9b4SEdward Cree 	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2632e7fef9b4SEdward Cree 	if (rc) {
2633e7fef9b4SEdward Cree 		netif_err(efx, drv, efx->net_dev,
2634e7fef9b4SEdward Cree 			  "failed to init net dev attributes\n");
2635e7fef9b4SEdward Cree 		goto fail_attr_mcdi_logging;
2636e7fef9b4SEdward Cree 	}
2637e7fef9b4SEdward Cree #endif
2638874aeea5SJeff Kirsher 
2639874aeea5SJeff Kirsher 	return 0;
2640874aeea5SJeff Kirsher 
2641e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING
2642e7fef9b4SEdward Cree fail_attr_mcdi_logging:
2643e7fef9b4SEdward Cree 	device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2644e7fef9b4SEdward Cree #endif
26457153f623SBen Hutchings fail_registered:
26467153f623SBen Hutchings 	rtnl_lock();
26470bcf4a64SBen Hutchings 	efx_dissociate(efx);
26487153f623SBen Hutchings 	unregister_netdevice(net_dev);
2649874aeea5SJeff Kirsher fail_locked:
26507153f623SBen Hutchings 	efx->state = STATE_UNINIT;
2651874aeea5SJeff Kirsher 	rtnl_unlock();
2652874aeea5SJeff Kirsher 	netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
2653874aeea5SJeff Kirsher 	return rc;
2654874aeea5SJeff Kirsher }
2655874aeea5SJeff Kirsher 
2656874aeea5SJeff Kirsher static void efx_unregister_netdev(struct efx_nic *efx)
2657874aeea5SJeff Kirsher {
2658874aeea5SJeff Kirsher 	if (!efx->net_dev)
2659874aeea5SJeff Kirsher 		return;
2660874aeea5SJeff Kirsher 
2661874aeea5SJeff Kirsher 	BUG_ON(netdev_priv(efx->net_dev) != efx);
2662874aeea5SJeff Kirsher 
2663e7fef9b4SEdward Cree 	if (efx_dev_registered(efx)) {
2664874aeea5SJeff Kirsher 		strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2665e7fef9b4SEdward Cree #ifdef CONFIG_SFC_MCDI_LOGGING
2666e7fef9b4SEdward Cree 		device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
2667e7fef9b4SEdward Cree #endif
2668874aeea5SJeff Kirsher 		device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2669e7fef9b4SEdward Cree 		unregister_netdev(efx->net_dev);
2670e7fef9b4SEdward Cree 	}
2671874aeea5SJeff Kirsher }
2672874aeea5SJeff Kirsher 
2673874aeea5SJeff Kirsher /**************************************************************************
2674874aeea5SJeff Kirsher  *
2675874aeea5SJeff Kirsher  * Device reset and suspend
2676874aeea5SJeff Kirsher  *
2677874aeea5SJeff Kirsher  **************************************************************************/
2678874aeea5SJeff Kirsher 
2679874aeea5SJeff Kirsher /* Tears down the entire software state and most of the hardware state
2680874aeea5SJeff Kirsher  * before reset.  */
2681874aeea5SJeff Kirsher void efx_reset_down(struct efx_nic *efx, enum reset_type method)
2682874aeea5SJeff Kirsher {
2683874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
2684874aeea5SJeff Kirsher 
2685e283546cSEdward Cree 	if (method == RESET_TYPE_MCDI_TIMEOUT)
2686e283546cSEdward Cree 		efx->type->prepare_flr(efx);
2687e283546cSEdward Cree 
2688874aeea5SJeff Kirsher 	efx_stop_all(efx);
2689d8291187SBen Hutchings 	efx_disable_interrupts(efx);
26905642ceefSBen Hutchings 
26915642ceefSBen Hutchings 	mutex_lock(&efx->mac_lock);
2692e0a65e3cSEdward Cree 	mutex_lock(&efx->rss_lock);
2693087e9025SJon Cooper 	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2694087e9025SJon Cooper 	    method != RESET_TYPE_DATAPATH)
2695874aeea5SJeff Kirsher 		efx->phy_op->fini(efx);
2696874aeea5SJeff Kirsher 	efx->type->fini(efx);
2697874aeea5SJeff Kirsher }
2698874aeea5SJeff Kirsher 
2699874aeea5SJeff Kirsher /* This function will always ensure that the locks acquired in
2700874aeea5SJeff Kirsher  * efx_reset_down() are released. A failure return code indicates
2701874aeea5SJeff Kirsher  * that we were unable to reinitialise the hardware, and the
2702874aeea5SJeff Kirsher  * driver should be disabled. If ok is false, then the rx and tx
2703874aeea5SJeff Kirsher  * engines are not restarted, pending a RESET_DISABLE. */
2704874aeea5SJeff Kirsher int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
2705874aeea5SJeff Kirsher {
2706874aeea5SJeff Kirsher 	int rc;
2707874aeea5SJeff Kirsher 
2708874aeea5SJeff Kirsher 	EFX_ASSERT_RESET_SERIALISED(efx);
2709874aeea5SJeff Kirsher 
2710e283546cSEdward Cree 	if (method == RESET_TYPE_MCDI_TIMEOUT)
2711e283546cSEdward Cree 		efx->type->finish_flr(efx);
2712e283546cSEdward Cree 
2713e283546cSEdward Cree 	/* Ensure that SRAM is initialised even if we're disabling the device */
2714874aeea5SJeff Kirsher 	rc = efx->type->init(efx);
2715874aeea5SJeff Kirsher 	if (rc) {
2716874aeea5SJeff Kirsher 		netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
2717874aeea5SJeff Kirsher 		goto fail;
2718874aeea5SJeff Kirsher 	}
2719874aeea5SJeff Kirsher 
2720874aeea5SJeff Kirsher 	if (!ok)
2721874aeea5SJeff Kirsher 		goto fail;
2722874aeea5SJeff Kirsher 
2723087e9025SJon Cooper 	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2724087e9025SJon Cooper 	    method != RESET_TYPE_DATAPATH) {
2725874aeea5SJeff Kirsher 		rc = efx->phy_op->init(efx);
2726874aeea5SJeff Kirsher 		if (rc)
2727874aeea5SJeff Kirsher 			goto fail;
2728267d9d73SEdward Cree 		rc = efx->phy_op->reconfigure(efx);
2729267d9d73SEdward Cree 		if (rc && rc != -EPERM)
2730874aeea5SJeff Kirsher 			netif_err(efx, drv, efx->net_dev,
2731874aeea5SJeff Kirsher 				  "could not restore PHY settings\n");
2732874aeea5SJeff Kirsher 	}
2733874aeea5SJeff Kirsher 
2734261e4d96SJon Cooper 	rc = efx_enable_interrupts(efx);
2735261e4d96SJon Cooper 	if (rc)
2736261e4d96SJon Cooper 		goto fail;
27376d8aaaf6SDaniel Pieczko 
27386d8aaaf6SDaniel Pieczko #ifdef CONFIG_SFC_SRIOV
27396d8aaaf6SDaniel Pieczko 	rc = efx->type->vswitching_restore(efx);
27406d8aaaf6SDaniel Pieczko 	if (rc) /* not fatal; the PF will still work fine */
27416d8aaaf6SDaniel Pieczko 		netif_warn(efx, probe, efx->net_dev,
27426d8aaaf6SDaniel Pieczko 			   "failed to restore vswitching rc=%d;"
27436d8aaaf6SDaniel Pieczko 			   " VFs may not function\n", rc);
27446d8aaaf6SDaniel Pieczko #endif
27456d8aaaf6SDaniel Pieczko 
274642356d9aSEdward Cree 	if (efx->type->rx_restore_rss_contexts)
274742356d9aSEdward Cree 		efx->type->rx_restore_rss_contexts(efx);
2748e0a65e3cSEdward Cree 	mutex_unlock(&efx->rss_lock);
27490d322413SEdward Cree 	down_read(&efx->filter_sem);
2750874aeea5SJeff Kirsher 	efx_restore_filters(efx);
27510d322413SEdward Cree 	up_read(&efx->filter_sem);
27527fa8d547SShradha Shah 	if (efx->type->sriov_reset)
2753d98a4ffeSShradha Shah 		efx->type->sriov_reset(efx);
2754874aeea5SJeff Kirsher 
2755874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
2756874aeea5SJeff Kirsher 
2757874aeea5SJeff Kirsher 	efx_start_all(efx);
2758874aeea5SJeff Kirsher 
2759e5fbd977SJon Cooper 	if (efx->type->udp_tnl_push_ports)
2760e5fbd977SJon Cooper 		efx->type->udp_tnl_push_ports(efx);
2761e5fbd977SJon Cooper 
2762874aeea5SJeff Kirsher 	return 0;
2763874aeea5SJeff Kirsher 
2764874aeea5SJeff Kirsher fail:
2765874aeea5SJeff Kirsher 	efx->port_initialized = false;
2766874aeea5SJeff Kirsher 
2767e0a65e3cSEdward Cree 	mutex_unlock(&efx->rss_lock);
2768874aeea5SJeff Kirsher 	mutex_unlock(&efx->mac_lock);
2769874aeea5SJeff Kirsher 
2770874aeea5SJeff Kirsher 	return rc;
2771874aeea5SJeff Kirsher }
2772874aeea5SJeff Kirsher 
2773874aeea5SJeff Kirsher /* Reset the NIC using the specified method.  Note that the reset may
2774874aeea5SJeff Kirsher  * fail, in which case the card will be left in an unusable state.
2775874aeea5SJeff Kirsher  *
2776874aeea5SJeff Kirsher  * Caller must hold the rtnl_lock.
2777874aeea5SJeff Kirsher  */
2778874aeea5SJeff Kirsher int efx_reset(struct efx_nic *efx, enum reset_type method)
2779874aeea5SJeff Kirsher {
2780874aeea5SJeff Kirsher 	int rc, rc2;
2781874aeea5SJeff Kirsher 	bool disabled;
2782874aeea5SJeff Kirsher 
2783874aeea5SJeff Kirsher 	netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2784874aeea5SJeff Kirsher 		   RESET_TYPE(method));
2785874aeea5SJeff Kirsher 
2786c2f3b8e3SDaniel Pieczko 	efx_device_detach_sync(efx);
2787874aeea5SJeff Kirsher 	efx_reset_down(efx, method);
2788874aeea5SJeff Kirsher 
2789874aeea5SJeff Kirsher 	rc = efx->type->reset(efx, method);
2790874aeea5SJeff Kirsher 	if (rc) {
2791874aeea5SJeff Kirsher 		netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
2792874aeea5SJeff Kirsher 		goto out;
2793874aeea5SJeff Kirsher 	}
2794874aeea5SJeff Kirsher 
2795874aeea5SJeff Kirsher 	/* Clear flags for the scopes we covered.  We assume the NIC and
2796874aeea5SJeff Kirsher 	 * driver are now quiescent so that there is no race here.
2797874aeea5SJeff Kirsher 	 */
2798e283546cSEdward Cree 	if (method < RESET_TYPE_MAX_METHOD)
2799874aeea5SJeff Kirsher 		efx->reset_pending &= -(1 << (method + 1));
2800e283546cSEdward Cree 	else /* it doesn't fit into the well-ordered scope hierarchy */
2801e283546cSEdward Cree 		__clear_bit(method, &efx->reset_pending);
2802874aeea5SJeff Kirsher 
2803874aeea5SJeff Kirsher 	/* Reinitialise bus-mastering, which may have been turned off before
2804874aeea5SJeff Kirsher 	 * the reset was scheduled. This is still appropriate, even in the
2805874aeea5SJeff Kirsher 	 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2806874aeea5SJeff Kirsher 	 * can respond to requests. */
2807874aeea5SJeff Kirsher 	pci_set_master(efx->pci_dev);
2808874aeea5SJeff Kirsher 
2809874aeea5SJeff Kirsher out:
2810874aeea5SJeff Kirsher 	/* Leave device stopped if necessary */
2811626950dbSAlexandre Rames 	disabled = rc ||
2812626950dbSAlexandre Rames 		method == RESET_TYPE_DISABLE ||
2813626950dbSAlexandre Rames 		method == RESET_TYPE_RECOVER_OR_DISABLE;
2814874aeea5SJeff Kirsher 	rc2 = efx_reset_up(efx, method, !disabled);
2815874aeea5SJeff Kirsher 	if (rc2) {
2816874aeea5SJeff Kirsher 		disabled = true;
2817874aeea5SJeff Kirsher 		if (!rc)
2818874aeea5SJeff Kirsher 			rc = rc2;
2819874aeea5SJeff Kirsher 	}
2820874aeea5SJeff Kirsher 
2821874aeea5SJeff Kirsher 	if (disabled) {
2822874aeea5SJeff Kirsher 		dev_close(efx->net_dev);
2823874aeea5SJeff Kirsher 		netif_err(efx, drv, efx->net_dev, "has been disabled\n");
2824874aeea5SJeff Kirsher 		efx->state = STATE_DISABLED;
2825874aeea5SJeff Kirsher 	} else {
2826874aeea5SJeff Kirsher 		netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
28279c568fd8SPeter Dunning 		efx_device_attach_if_not_resetting(efx);
2828874aeea5SJeff Kirsher 	}
2829874aeea5SJeff Kirsher 	return rc;
2830874aeea5SJeff Kirsher }
2831874aeea5SJeff Kirsher 
2832626950dbSAlexandre Rames /* Try recovery mechanisms.
2833626950dbSAlexandre Rames  * For now only EEH is supported.
2834626950dbSAlexandre Rames  * Returns 0 if the recovery mechanisms are unsuccessful.
2835626950dbSAlexandre Rames  * Returns a non-zero value otherwise.
2836626950dbSAlexandre Rames  */
2837b28405b0SAlexandre Rames int efx_try_recovery(struct efx_nic *efx)
2838626950dbSAlexandre Rames {
2839626950dbSAlexandre Rames #ifdef CONFIG_EEH
2840626950dbSAlexandre Rames 	/* A PCI error can occur and not be seen by EEH because nothing
2841626950dbSAlexandre Rames 	 * happens on the PCI bus. In this case the driver may fail and
2842626950dbSAlexandre Rames 	 * schedule a 'recover or reset', leading to this recovery handler.
2843626950dbSAlexandre Rames 	 * Manually call the eeh failure check function.
2844626950dbSAlexandre Rames 	 */
284512a89dbaSBenjamin Herrenschmidt 	struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
2846626950dbSAlexandre Rames 	if (eeh_dev_check_failure(eehdev)) {
2847626950dbSAlexandre Rames 		/* The EEH mechanisms will handle the error and reset the
2848626950dbSAlexandre Rames 		 * device if necessary.
2849626950dbSAlexandre Rames 		 */
2850626950dbSAlexandre Rames 		return 1;
2851626950dbSAlexandre Rames 	}
2852626950dbSAlexandre Rames #endif
2853626950dbSAlexandre Rames 	return 0;
2854626950dbSAlexandre Rames }
2855626950dbSAlexandre Rames 
285674cd60a4SJon Cooper static void efx_wait_for_bist_end(struct efx_nic *efx)
285774cd60a4SJon Cooper {
285874cd60a4SJon Cooper 	int i;
285974cd60a4SJon Cooper 
286074cd60a4SJon Cooper 	for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
286174cd60a4SJon Cooper 		if (efx_mcdi_poll_reboot(efx))
286274cd60a4SJon Cooper 			goto out;
286374cd60a4SJon Cooper 		msleep(BIST_WAIT_DELAY_MS);
286474cd60a4SJon Cooper 	}
286574cd60a4SJon Cooper 
286674cd60a4SJon Cooper 	netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
286774cd60a4SJon Cooper out:
286874cd60a4SJon Cooper 	/* Either way unset the BIST flag. If we found no reboot we probably
286974cd60a4SJon Cooper 	 * won't recover, but we should try.
287074cd60a4SJon Cooper 	 */
287174cd60a4SJon Cooper 	efx->mc_bist_for_other_fn = false;
287274cd60a4SJon Cooper }
287374cd60a4SJon Cooper 
2874874aeea5SJeff Kirsher /* The worker thread exists so that code that cannot sleep can
2875874aeea5SJeff Kirsher  * schedule a reset for later.
2876874aeea5SJeff Kirsher  */
2877874aeea5SJeff Kirsher static void efx_reset_work(struct work_struct *data)
2878874aeea5SJeff Kirsher {
2879874aeea5SJeff Kirsher 	struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
2880626950dbSAlexandre Rames 	unsigned long pending;
2881626950dbSAlexandre Rames 	enum reset_type method;
2882626950dbSAlexandre Rames 
28836aa7de05SMark Rutland 	pending = READ_ONCE(efx->reset_pending);
2884626950dbSAlexandre Rames 	method = fls(pending) - 1;
2885626950dbSAlexandre Rames 
288674cd60a4SJon Cooper 	if (method == RESET_TYPE_MC_BIST)
288774cd60a4SJon Cooper 		efx_wait_for_bist_end(efx);
288874cd60a4SJon Cooper 
2889626950dbSAlexandre Rames 	if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
2890626950dbSAlexandre Rames 	     method == RESET_TYPE_RECOVER_OR_ALL) &&
2891626950dbSAlexandre Rames 	    efx_try_recovery(efx))
2892626950dbSAlexandre Rames 		return;
2893874aeea5SJeff Kirsher 
2894874aeea5SJeff Kirsher 	if (!pending)
2895874aeea5SJeff Kirsher 		return;
2896874aeea5SJeff Kirsher 
2897874aeea5SJeff Kirsher 	rtnl_lock();
28987153f623SBen Hutchings 
28997153f623SBen Hutchings 	/* We checked the state in efx_schedule_reset() but it may
29007153f623SBen Hutchings 	 * have changed by now.  Now that we have the RTNL lock,
29017153f623SBen Hutchings 	 * it cannot change again.
29027153f623SBen Hutchings 	 */
29037153f623SBen Hutchings 	if (efx->state == STATE_READY)
2904626950dbSAlexandre Rames 		(void)efx_reset(efx, method);
29057153f623SBen Hutchings 
2906874aeea5SJeff Kirsher 	rtnl_unlock();
2907874aeea5SJeff Kirsher }
2908874aeea5SJeff Kirsher 
2909874aeea5SJeff Kirsher void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
2910874aeea5SJeff Kirsher {
2911874aeea5SJeff Kirsher 	enum reset_type method;
2912874aeea5SJeff Kirsher 
2913626950dbSAlexandre Rames 	if (efx->state == STATE_RECOVERY) {
2914626950dbSAlexandre Rames 		netif_dbg(efx, drv, efx->net_dev,
2915626950dbSAlexandre Rames 			  "recovering: skip scheduling %s reset\n",
2916626950dbSAlexandre Rames 			  RESET_TYPE(type));
2917626950dbSAlexandre Rames 		return;
2918626950dbSAlexandre Rames 	}
2919626950dbSAlexandre Rames 
2920874aeea5SJeff Kirsher 	switch (type) {
2921874aeea5SJeff Kirsher 	case RESET_TYPE_INVISIBLE:
2922874aeea5SJeff Kirsher 	case RESET_TYPE_ALL:
2923626950dbSAlexandre Rames 	case RESET_TYPE_RECOVER_OR_ALL:
2924874aeea5SJeff Kirsher 	case RESET_TYPE_WORLD:
2925874aeea5SJeff Kirsher 	case RESET_TYPE_DISABLE:
2926626950dbSAlexandre Rames 	case RESET_TYPE_RECOVER_OR_DISABLE:
2927087e9025SJon Cooper 	case RESET_TYPE_DATAPATH:
292874cd60a4SJon Cooper 	case RESET_TYPE_MC_BIST:
2929e283546cSEdward Cree 	case RESET_TYPE_MCDI_TIMEOUT:
2930874aeea5SJeff Kirsher 		method = type;
2931874aeea5SJeff Kirsher 		netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2932874aeea5SJeff Kirsher 			  RESET_TYPE(method));
2933874aeea5SJeff Kirsher 		break;
2934874aeea5SJeff Kirsher 	default:
2935874aeea5SJeff Kirsher 		method = efx->type->map_reset_reason(type);
2936874aeea5SJeff Kirsher 		netif_dbg(efx, drv, efx->net_dev,
2937874aeea5SJeff Kirsher 			  "scheduling %s reset for %s\n",
2938874aeea5SJeff Kirsher 			  RESET_TYPE(method), RESET_TYPE(type));
2939874aeea5SJeff Kirsher 		break;
2940874aeea5SJeff Kirsher 	}
2941874aeea5SJeff Kirsher 
2942874aeea5SJeff Kirsher 	set_bit(method, &efx->reset_pending);
29437153f623SBen Hutchings 	smp_mb(); /* ensure we change reset_pending before checking state */
29447153f623SBen Hutchings 
29457153f623SBen Hutchings 	/* If we're not READY then just leave the flags set as the cue
29467153f623SBen Hutchings 	 * to abort probing or reschedule the reset later.
29477153f623SBen Hutchings 	 */
29486aa7de05SMark Rutland 	if (READ_ONCE(efx->state) != STATE_READY)
29497153f623SBen Hutchings 		return;
2950874aeea5SJeff Kirsher 
2951874aeea5SJeff Kirsher 	/* efx_process_channel() will no longer read events once a
2952874aeea5SJeff Kirsher 	 * reset is scheduled. So switch back to poll'd MCDI completions. */
2953874aeea5SJeff Kirsher 	efx_mcdi_mode_poll(efx);
2954874aeea5SJeff Kirsher 
2955874aeea5SJeff Kirsher 	queue_work(reset_workqueue, &efx->reset_work);
2956874aeea5SJeff Kirsher }
2957874aeea5SJeff Kirsher 
2958874aeea5SJeff Kirsher /**************************************************************************
2959874aeea5SJeff Kirsher  *
2960874aeea5SJeff Kirsher  * List of NICs we support
2961874aeea5SJeff Kirsher  *
2962874aeea5SJeff Kirsher  **************************************************************************/
2963874aeea5SJeff Kirsher 
2964874aeea5SJeff Kirsher /* PCI device ID table */
29659baa3c34SBenoit Taine static const struct pci_device_id efx_pci_table[] = {
2966547c474fSBen Hutchings 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803),	/* SFC9020 */
2967874aeea5SJeff Kirsher 	 .driver_data = (unsigned long) &siena_a0_nic_type},
2968547c474fSBen Hutchings 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813),	/* SFL9021 */
2969874aeea5SJeff Kirsher 	 .driver_data = (unsigned long) &siena_a0_nic_type},
29708127d661SBen Hutchings 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903),  /* SFC9120 PF */
29718127d661SBen Hutchings 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
29726f7f8aa6SShradha Shah 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903),  /* SFC9120 VF */
29736f7f8aa6SShradha Shah 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
29743b06a00eSMateusz Wrzesinski 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923),  /* SFC9140 PF */
29753b06a00eSMateusz Wrzesinski 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2976dd248f1bSBert Kenward 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923),  /* SFC9140 VF */
2977dd248f1bSBert Kenward 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2978dd248f1bSBert Kenward 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03),  /* SFC9220 PF */
2979dd248f1bSBert Kenward 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2980dd248f1bSBert Kenward 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03),  /* SFC9220 VF */
2981dd248f1bSBert Kenward 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2982aae5a316SEdward Cree 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03),  /* SFC9250 PF */
2983aae5a316SEdward Cree 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2984aae5a316SEdward Cree 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03),  /* SFC9250 VF */
2985aae5a316SEdward Cree 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2986874aeea5SJeff Kirsher 	{0}			/* end of list */
2987874aeea5SJeff Kirsher };
2988874aeea5SJeff Kirsher 
2989874aeea5SJeff Kirsher /**************************************************************************
2990874aeea5SJeff Kirsher  *
2991874aeea5SJeff Kirsher  * Dummy PHY/MAC operations
2992874aeea5SJeff Kirsher  *
2993874aeea5SJeff Kirsher  * Can be used for some unimplemented operations
2994874aeea5SJeff Kirsher  * Needed so all function pointers are valid and do not have to be tested
2995874aeea5SJeff Kirsher  * before use
2996874aeea5SJeff Kirsher  *
2997874aeea5SJeff Kirsher  **************************************************************************/
2998874aeea5SJeff Kirsher int efx_port_dummy_op_int(struct efx_nic *efx)
2999874aeea5SJeff Kirsher {
3000874aeea5SJeff Kirsher 	return 0;
3001874aeea5SJeff Kirsher }
3002874aeea5SJeff Kirsher void efx_port_dummy_op_void(struct efx_nic *efx) {}
3003874aeea5SJeff Kirsher 
3004874aeea5SJeff Kirsher static bool efx_port_dummy_op_poll(struct efx_nic *efx)
3005874aeea5SJeff Kirsher {
3006874aeea5SJeff Kirsher 	return false;
3007874aeea5SJeff Kirsher }
3008874aeea5SJeff Kirsher 
3009874aeea5SJeff Kirsher static const struct efx_phy_operations efx_dummy_phy_operations = {
3010874aeea5SJeff Kirsher 	.init		 = efx_port_dummy_op_int,
3011874aeea5SJeff Kirsher 	.reconfigure	 = efx_port_dummy_op_int,
3012874aeea5SJeff Kirsher 	.poll		 = efx_port_dummy_op_poll,
3013874aeea5SJeff Kirsher 	.fini		 = efx_port_dummy_op_void,
3014874aeea5SJeff Kirsher };
3015874aeea5SJeff Kirsher 
3016874aeea5SJeff Kirsher /**************************************************************************
3017874aeea5SJeff Kirsher  *
3018874aeea5SJeff Kirsher  * Data housekeeping
3019874aeea5SJeff Kirsher  *
3020874aeea5SJeff Kirsher  **************************************************************************/
3021874aeea5SJeff Kirsher 
3022874aeea5SJeff Kirsher /* This zeroes out and then fills in the invariants in a struct
3023874aeea5SJeff Kirsher  * efx_nic (including all sub-structures).
3024874aeea5SJeff Kirsher  */
3025adeb15aaSBen Hutchings static int efx_init_struct(struct efx_nic *efx,
3026874aeea5SJeff Kirsher 			   struct pci_dev *pci_dev, struct net_device *net_dev)
3027874aeea5SJeff Kirsher {
30286f9f6ec2SAndrew Rybchenko 	int rc = -ENOMEM, i;
3029874aeea5SJeff Kirsher 
3030874aeea5SJeff Kirsher 	/* Initialise common structures */
30310bcf4a64SBen Hutchings 	INIT_LIST_HEAD(&efx->node);
30320bcf4a64SBen Hutchings 	INIT_LIST_HEAD(&efx->secondary_list);
3033874aeea5SJeff Kirsher 	spin_lock_init(&efx->biu_lock);
3034874aeea5SJeff Kirsher #ifdef CONFIG_SFC_MTD
3035874aeea5SJeff Kirsher 	INIT_LIST_HEAD(&efx->mtd_list);
3036874aeea5SJeff Kirsher #endif
3037874aeea5SJeff Kirsher 	INIT_WORK(&efx->reset_work, efx_reset_work);
3038874aeea5SJeff Kirsher 	INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
3039dd40781eSBen Hutchings 	INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
3040874aeea5SJeff Kirsher 	efx->pci_dev = pci_dev;
3041874aeea5SJeff Kirsher 	efx->msg_enable = debug;
3042f16aeea0SBen Hutchings 	efx->state = STATE_UNINIT;
3043874aeea5SJeff Kirsher 	strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
3044874aeea5SJeff Kirsher 
3045874aeea5SJeff Kirsher 	efx->net_dev = net_dev;
304643a3739dSJon Cooper 	efx->rx_prefix_size = efx->type->rx_prefix_size;
30472ec03014SAndrew Rybchenko 	efx->rx_ip_align =
30482ec03014SAndrew Rybchenko 		NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
304943a3739dSJon Cooper 	efx->rx_packet_hash_offset =
305043a3739dSJon Cooper 		efx->type->rx_hash_offset - efx->type->rx_prefix_size;
3051bd9a265dSJon Cooper 	efx->rx_packet_ts_offset =
3052bd9a265dSJon Cooper 		efx->type->rx_ts_offset - efx->type->rx_prefix_size;
305342356d9aSEdward Cree 	INIT_LIST_HEAD(&efx->rss_context.list);
3054e0a65e3cSEdward Cree 	mutex_init(&efx->rss_lock);
3055874aeea5SJeff Kirsher 	spin_lock_init(&efx->stats_lock);
305671827443SEdward Cree 	efx->vi_stride = EFX_DEFAULT_VI_STRIDE;
3057c1be4821SEdward Cree 	efx->num_mac_stats = MC_CMD_MAC_NSTATS;
3058c1be4821SEdward Cree 	BUILD_BUG_ON(MC_CMD_MAC_NSTATS - 1 != MC_CMD_MAC_GENERATION_END);
3059874aeea5SJeff Kirsher 	mutex_init(&efx->mac_lock);
30603af0f342SEdward Cree #ifdef CONFIG_RFS_ACCEL
30613af0f342SEdward Cree 	mutex_init(&efx->rps_mutex);
30623af0f342SEdward Cree #endif
3063874aeea5SJeff Kirsher 	efx->phy_op = &efx_dummy_phy_operations;
3064874aeea5SJeff Kirsher 	efx->mdio.dev = net_dev;
3065874aeea5SJeff Kirsher 	INIT_WORK(&efx->mac_work, efx_mac_work);
30669f2cb71cSBen Hutchings 	init_waitqueue_head(&efx->flush_wq);
3067874aeea5SJeff Kirsher 
3068874aeea5SJeff Kirsher 	for (i = 0; i < EFX_MAX_CHANNELS; i++) {
3069874aeea5SJeff Kirsher 		efx->channel[i] = efx_alloc_channel(efx, i, NULL);
3070874aeea5SJeff Kirsher 		if (!efx->channel[i])
3071874aeea5SJeff Kirsher 			goto fail;
3072d8291187SBen Hutchings 		efx->msi_context[i].efx = efx;
3073d8291187SBen Hutchings 		efx->msi_context[i].index = i;
3074874aeea5SJeff Kirsher 	}
3075874aeea5SJeff Kirsher 
3076874aeea5SJeff Kirsher 	/* Higher numbered interrupt modes are less capable! */
30776f9f6ec2SAndrew Rybchenko 	if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
30786f9f6ec2SAndrew Rybchenko 			 efx->type->min_interrupt_mode)) {
30796f9f6ec2SAndrew Rybchenko 		rc = -EIO;
30806f9f6ec2SAndrew Rybchenko 		goto fail;
30816f9f6ec2SAndrew Rybchenko 	}
3082874aeea5SJeff Kirsher 	efx->interrupt_mode = max(efx->type->max_interrupt_mode,
3083874aeea5SJeff Kirsher 				  interrupt_mode);
30846f9f6ec2SAndrew Rybchenko 	efx->interrupt_mode = min(efx->type->min_interrupt_mode,
30856f9f6ec2SAndrew Rybchenko 				  interrupt_mode);
3086874aeea5SJeff Kirsher 
3087874aeea5SJeff Kirsher 	/* Would be good to use the net_dev name, but we're too early */
3088874aeea5SJeff Kirsher 	snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
3089874aeea5SJeff Kirsher 		 pci_name(pci_dev));
3090874aeea5SJeff Kirsher 	efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
3091874aeea5SJeff Kirsher 	if (!efx->workqueue)
3092874aeea5SJeff Kirsher 		goto fail;
3093874aeea5SJeff Kirsher 
3094874aeea5SJeff Kirsher 	return 0;
3095874aeea5SJeff Kirsher 
3096874aeea5SJeff Kirsher fail:
3097874aeea5SJeff Kirsher 	efx_fini_struct(efx);
30986f9f6ec2SAndrew Rybchenko 	return rc;
3099874aeea5SJeff Kirsher }
3100874aeea5SJeff Kirsher 
3101874aeea5SJeff Kirsher static void efx_fini_struct(struct efx_nic *efx)
3102874aeea5SJeff Kirsher {
3103874aeea5SJeff Kirsher 	int i;
3104874aeea5SJeff Kirsher 
3105874aeea5SJeff Kirsher 	for (i = 0; i < EFX_MAX_CHANNELS; i++)
3106874aeea5SJeff Kirsher 		kfree(efx->channel[i]);
3107874aeea5SJeff Kirsher 
3108ef215e64SBen Hutchings 	kfree(efx->vpd_sn);
3109ef215e64SBen Hutchings 
3110874aeea5SJeff Kirsher 	if (efx->workqueue) {
3111874aeea5SJeff Kirsher 		destroy_workqueue(efx->workqueue);
3112874aeea5SJeff Kirsher 		efx->workqueue = NULL;
3113874aeea5SJeff Kirsher 	}
3114874aeea5SJeff Kirsher }
3115874aeea5SJeff Kirsher 
3116e4d112e4SEdward Cree void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
3117e4d112e4SEdward Cree {
3118e4d112e4SEdward Cree 	u64 n_rx_nodesc_trunc = 0;
3119e4d112e4SEdward Cree 	struct efx_channel *channel;
3120e4d112e4SEdward Cree 
3121e4d112e4SEdward Cree 	efx_for_each_channel(channel, efx)
3122e4d112e4SEdward Cree 		n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
3123e4d112e4SEdward Cree 	stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
3124e4d112e4SEdward Cree 	stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
3125e4d112e4SEdward Cree }
3126e4d112e4SEdward Cree 
312742356d9aSEdward Cree /* RSS contexts.  We're using linked lists and crappy O(n) algorithms, because
312842356d9aSEdward Cree  * (a) this is an infrequent control-plane operation and (b) n is small (max 64)
312942356d9aSEdward Cree  */
3130e0a65e3cSEdward Cree struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
313142356d9aSEdward Cree {
3132e0a65e3cSEdward Cree 	struct list_head *head = &efx->rss_context.list;
313342356d9aSEdward Cree 	struct efx_rss_context *ctx, *new;
313442356d9aSEdward Cree 	u32 id = 1; /* Don't use zero, that refers to the master RSS context */
313542356d9aSEdward Cree 
3136e0a65e3cSEdward Cree 	WARN_ON(!mutex_is_locked(&efx->rss_lock));
3137e0a65e3cSEdward Cree 
313842356d9aSEdward Cree 	/* Search for first gap in the numbering */
313942356d9aSEdward Cree 	list_for_each_entry(ctx, head, list) {
314042356d9aSEdward Cree 		if (ctx->user_id != id)
314142356d9aSEdward Cree 			break;
314242356d9aSEdward Cree 		id++;
314342356d9aSEdward Cree 		/* Check for wrap.  If this happens, we have nearly 2^32
314442356d9aSEdward Cree 		 * allocated RSS contexts, which seems unlikely.
314542356d9aSEdward Cree 		 */
314642356d9aSEdward Cree 		if (WARN_ON_ONCE(!id))
314742356d9aSEdward Cree 			return NULL;
314842356d9aSEdward Cree 	}
314942356d9aSEdward Cree 
315042356d9aSEdward Cree 	/* Create the new entry */
315142356d9aSEdward Cree 	new = kmalloc(sizeof(struct efx_rss_context), GFP_KERNEL);
315242356d9aSEdward Cree 	if (!new)
315342356d9aSEdward Cree 		return NULL;
315442356d9aSEdward Cree 	new->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
315542356d9aSEdward Cree 	new->rx_hash_udp_4tuple = false;
315642356d9aSEdward Cree 
315742356d9aSEdward Cree 	/* Insert the new entry into the gap */
315842356d9aSEdward Cree 	new->user_id = id;
315942356d9aSEdward Cree 	list_add_tail(&new->list, &ctx->list);
316042356d9aSEdward Cree 	return new;
316142356d9aSEdward Cree }
316242356d9aSEdward Cree 
3163e0a65e3cSEdward Cree struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id)
316442356d9aSEdward Cree {
3165e0a65e3cSEdward Cree 	struct list_head *head = &efx->rss_context.list;
316642356d9aSEdward Cree 	struct efx_rss_context *ctx;
316742356d9aSEdward Cree 
3168e0a65e3cSEdward Cree 	WARN_ON(!mutex_is_locked(&efx->rss_lock));
3169e0a65e3cSEdward Cree 
317042356d9aSEdward Cree 	list_for_each_entry(ctx, head, list)
317142356d9aSEdward Cree 		if (ctx->user_id == id)
317242356d9aSEdward Cree 			return ctx;
317342356d9aSEdward Cree 	return NULL;
317442356d9aSEdward Cree }
317542356d9aSEdward Cree 
317642356d9aSEdward Cree void efx_free_rss_context_entry(struct efx_rss_context *ctx)
317742356d9aSEdward Cree {
317842356d9aSEdward Cree 	list_del(&ctx->list);
317942356d9aSEdward Cree 	kfree(ctx);
318042356d9aSEdward Cree }
318142356d9aSEdward Cree 
3182874aeea5SJeff Kirsher /**************************************************************************
3183874aeea5SJeff Kirsher  *
3184874aeea5SJeff Kirsher  * PCI interface
3185874aeea5SJeff Kirsher  *
3186874aeea5SJeff Kirsher  **************************************************************************/
3187874aeea5SJeff Kirsher 
3188874aeea5SJeff Kirsher /* Main body of final NIC shutdown code
3189874aeea5SJeff Kirsher  * This is called only at module unload (or hotplug removal).
3190874aeea5SJeff Kirsher  */
3191874aeea5SJeff Kirsher static void efx_pci_remove_main(struct efx_nic *efx)
3192874aeea5SJeff Kirsher {
31937153f623SBen Hutchings 	/* Flush reset_work. It can no longer be scheduled since we
31947153f623SBen Hutchings 	 * are not READY.
31957153f623SBen Hutchings 	 */
31967153f623SBen Hutchings 	BUG_ON(efx->state == STATE_READY);
31977153f623SBen Hutchings 	cancel_work_sync(&efx->reset_work);
31987153f623SBen Hutchings 
3199d8291187SBen Hutchings 	efx_disable_interrupts(efx);
3200a83762d9SBert Kenward 	efx_clear_interrupt_affinity(efx);
3201874aeea5SJeff Kirsher 	efx_nic_fini_interrupt(efx);
3202874aeea5SJeff Kirsher 	efx_fini_port(efx);
3203874aeea5SJeff Kirsher 	efx->type->fini(efx);
3204874aeea5SJeff Kirsher 	efx_fini_napi(efx);
3205874aeea5SJeff Kirsher 	efx_remove_all(efx);
3206874aeea5SJeff Kirsher }
3207874aeea5SJeff Kirsher 
3208874aeea5SJeff Kirsher /* Final NIC shutdown
32092a3fc311SDaniel Pieczko  * This is called only at module unload (or hotplug removal).  A PF can call
32102a3fc311SDaniel Pieczko  * this on its VFs to ensure they are unbound first.
3211874aeea5SJeff Kirsher  */
3212874aeea5SJeff Kirsher static void efx_pci_remove(struct pci_dev *pci_dev)
3213874aeea5SJeff Kirsher {
3214874aeea5SJeff Kirsher 	struct efx_nic *efx;
3215874aeea5SJeff Kirsher 
3216874aeea5SJeff Kirsher 	efx = pci_get_drvdata(pci_dev);
3217874aeea5SJeff Kirsher 	if (!efx)
3218874aeea5SJeff Kirsher 		return;
3219874aeea5SJeff Kirsher 
3220874aeea5SJeff Kirsher 	/* Mark the NIC as fini, then stop the interface */
3221874aeea5SJeff Kirsher 	rtnl_lock();
32220bcf4a64SBen Hutchings 	efx_dissociate(efx);
3223874aeea5SJeff Kirsher 	dev_close(efx->net_dev);
3224d8291187SBen Hutchings 	efx_disable_interrupts(efx);
3225ea6bb99eSEdward Cree 	efx->state = STATE_UNINIT;
3226874aeea5SJeff Kirsher 	rtnl_unlock();
3227874aeea5SJeff Kirsher 
32287fa8d547SShradha Shah 	if (efx->type->sriov_fini)
3229d98a4ffeSShradha Shah 		efx->type->sriov_fini(efx);
32307fa8d547SShradha Shah 
3231874aeea5SJeff Kirsher 	efx_unregister_netdev(efx);
3232874aeea5SJeff Kirsher 
3233874aeea5SJeff Kirsher 	efx_mtd_remove(efx);
3234874aeea5SJeff Kirsher 
3235874aeea5SJeff Kirsher 	efx_pci_remove_main(efx);
3236874aeea5SJeff Kirsher 
3237874aeea5SJeff Kirsher 	efx_fini_io(efx);
3238874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
3239874aeea5SJeff Kirsher 
3240874aeea5SJeff Kirsher 	efx_fini_struct(efx);
3241874aeea5SJeff Kirsher 	free_netdev(efx->net_dev);
3242626950dbSAlexandre Rames 
3243626950dbSAlexandre Rames 	pci_disable_pcie_error_reporting(pci_dev);
3244874aeea5SJeff Kirsher };
3245874aeea5SJeff Kirsher 
3246460eeaa0SBen Hutchings /* NIC VPD information
3247460eeaa0SBen Hutchings  * Called during probe to display the part number of the
3248460eeaa0SBen Hutchings  * installed NIC.  VPD is potentially very large but this should
3249460eeaa0SBen Hutchings  * always appear within the first 512 bytes.
3250460eeaa0SBen Hutchings  */
3251460eeaa0SBen Hutchings #define SFC_VPD_LEN 512
3252ef215e64SBen Hutchings static void efx_probe_vpd_strings(struct efx_nic *efx)
3253460eeaa0SBen Hutchings {
3254460eeaa0SBen Hutchings 	struct pci_dev *dev = efx->pci_dev;
3255460eeaa0SBen Hutchings 	char vpd_data[SFC_VPD_LEN];
3256460eeaa0SBen Hutchings 	ssize_t vpd_size;
3257ef215e64SBen Hutchings 	int ro_start, ro_size, i, j;
3258460eeaa0SBen Hutchings 
3259460eeaa0SBen Hutchings 	/* Get the vpd data from the device */
3260460eeaa0SBen Hutchings 	vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
3261460eeaa0SBen Hutchings 	if (vpd_size <= 0) {
3262460eeaa0SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
3263460eeaa0SBen Hutchings 		return;
3264460eeaa0SBen Hutchings 	}
3265460eeaa0SBen Hutchings 
3266460eeaa0SBen Hutchings 	/* Get the Read only section */
3267ef215e64SBen Hutchings 	ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
3268ef215e64SBen Hutchings 	if (ro_start < 0) {
3269460eeaa0SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
3270460eeaa0SBen Hutchings 		return;
3271460eeaa0SBen Hutchings 	}
3272460eeaa0SBen Hutchings 
3273ef215e64SBen Hutchings 	ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
3274ef215e64SBen Hutchings 	j = ro_size;
3275ef215e64SBen Hutchings 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
3276460eeaa0SBen Hutchings 	if (i + j > vpd_size)
3277460eeaa0SBen Hutchings 		j = vpd_size - i;
3278460eeaa0SBen Hutchings 
3279460eeaa0SBen Hutchings 	/* Get the Part number */
3280460eeaa0SBen Hutchings 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
3281460eeaa0SBen Hutchings 	if (i < 0) {
3282460eeaa0SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Part number not found\n");
3283460eeaa0SBen Hutchings 		return;
3284460eeaa0SBen Hutchings 	}
3285460eeaa0SBen Hutchings 
3286460eeaa0SBen Hutchings 	j = pci_vpd_info_field_size(&vpd_data[i]);
3287460eeaa0SBen Hutchings 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
3288460eeaa0SBen Hutchings 	if (i + j > vpd_size) {
3289460eeaa0SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
3290460eeaa0SBen Hutchings 		return;
3291460eeaa0SBen Hutchings 	}
3292460eeaa0SBen Hutchings 
3293460eeaa0SBen Hutchings 	netif_info(efx, drv, efx->net_dev,
3294460eeaa0SBen Hutchings 		   "Part Number : %.*s\n", j, &vpd_data[i]);
3295ef215e64SBen Hutchings 
3296ef215e64SBen Hutchings 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
3297ef215e64SBen Hutchings 	j = ro_size;
3298ef215e64SBen Hutchings 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
3299ef215e64SBen Hutchings 	if (i < 0) {
3300ef215e64SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
3301ef215e64SBen Hutchings 		return;
3302ef215e64SBen Hutchings 	}
3303ef215e64SBen Hutchings 
3304ef215e64SBen Hutchings 	j = pci_vpd_info_field_size(&vpd_data[i]);
3305ef215e64SBen Hutchings 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
3306ef215e64SBen Hutchings 	if (i + j > vpd_size) {
3307ef215e64SBen Hutchings 		netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
3308ef215e64SBen Hutchings 		return;
3309ef215e64SBen Hutchings 	}
3310ef215e64SBen Hutchings 
3311ef215e64SBen Hutchings 	efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
3312ef215e64SBen Hutchings 	if (!efx->vpd_sn)
3313ef215e64SBen Hutchings 		return;
3314ef215e64SBen Hutchings 
3315ef215e64SBen Hutchings 	snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
3316460eeaa0SBen Hutchings }
3317460eeaa0SBen Hutchings 
3318460eeaa0SBen Hutchings 
3319874aeea5SJeff Kirsher /* Main body of NIC initialisation
3320874aeea5SJeff Kirsher  * This is called at module load (or hotplug insertion, theoretically).
3321874aeea5SJeff Kirsher  */
3322874aeea5SJeff Kirsher static int efx_pci_probe_main(struct efx_nic *efx)
3323874aeea5SJeff Kirsher {
3324874aeea5SJeff Kirsher 	int rc;
3325874aeea5SJeff Kirsher 
3326874aeea5SJeff Kirsher 	/* Do start-of-day initialisation */
3327874aeea5SJeff Kirsher 	rc = efx_probe_all(efx);
3328874aeea5SJeff Kirsher 	if (rc)
3329874aeea5SJeff Kirsher 		goto fail1;
3330874aeea5SJeff Kirsher 
3331874aeea5SJeff Kirsher 	efx_init_napi(efx);
3332874aeea5SJeff Kirsher 
3333874aeea5SJeff Kirsher 	rc = efx->type->init(efx);
3334874aeea5SJeff Kirsher 	if (rc) {
3335874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
3336874aeea5SJeff Kirsher 			  "failed to initialise NIC\n");
3337874aeea5SJeff Kirsher 		goto fail3;
3338874aeea5SJeff Kirsher 	}
3339874aeea5SJeff Kirsher 
3340874aeea5SJeff Kirsher 	rc = efx_init_port(efx);
3341874aeea5SJeff Kirsher 	if (rc) {
3342874aeea5SJeff Kirsher 		netif_err(efx, probe, efx->net_dev,
3343874aeea5SJeff Kirsher 			  "failed to initialise port\n");
3344874aeea5SJeff Kirsher 		goto fail4;
3345874aeea5SJeff Kirsher 	}
3346874aeea5SJeff Kirsher 
3347874aeea5SJeff Kirsher 	rc = efx_nic_init_interrupt(efx);
3348874aeea5SJeff Kirsher 	if (rc)
3349874aeea5SJeff Kirsher 		goto fail5;
3350a83762d9SBert Kenward 
3351a83762d9SBert Kenward 	efx_set_interrupt_affinity(efx);
3352261e4d96SJon Cooper 	rc = efx_enable_interrupts(efx);
3353261e4d96SJon Cooper 	if (rc)
3354261e4d96SJon Cooper 		goto fail6;
3355874aeea5SJeff Kirsher 
3356874aeea5SJeff Kirsher 	return 0;
3357874aeea5SJeff Kirsher 
3358261e4d96SJon Cooper  fail6:
3359a83762d9SBert Kenward 	efx_clear_interrupt_affinity(efx);
3360261e4d96SJon Cooper 	efx_nic_fini_interrupt(efx);
3361874aeea5SJeff Kirsher  fail5:
3362874aeea5SJeff Kirsher 	efx_fini_port(efx);
3363874aeea5SJeff Kirsher  fail4:
3364874aeea5SJeff Kirsher 	efx->type->fini(efx);
3365874aeea5SJeff Kirsher  fail3:
3366874aeea5SJeff Kirsher 	efx_fini_napi(efx);
3367874aeea5SJeff Kirsher 	efx_remove_all(efx);
3368874aeea5SJeff Kirsher  fail1:
3369874aeea5SJeff Kirsher 	return rc;
3370874aeea5SJeff Kirsher }
3371874aeea5SJeff Kirsher 
33728a531400SJon Cooper static int efx_pci_probe_post_io(struct efx_nic *efx)
33738a531400SJon Cooper {
33748a531400SJon Cooper 	struct net_device *net_dev = efx->net_dev;
33758a531400SJon Cooper 	int rc = efx_pci_probe_main(efx);
33768a531400SJon Cooper 
33778a531400SJon Cooper 	if (rc)
33788a531400SJon Cooper 		return rc;
33798a531400SJon Cooper 
33808a531400SJon Cooper 	if (efx->type->sriov_init) {
33818a531400SJon Cooper 		rc = efx->type->sriov_init(efx);
33828a531400SJon Cooper 		if (rc)
33838a531400SJon Cooper 			netif_err(efx, probe, efx->net_dev,
33848a531400SJon Cooper 				  "SR-IOV can't be enabled rc %d\n", rc);
33858a531400SJon Cooper 	}
33868a531400SJon Cooper 
33878a531400SJon Cooper 	/* Determine netdevice features */
33888a531400SJon Cooper 	net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
33896978729fSEdward Cree 			      NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
33908a531400SJon Cooper 	if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
33918a531400SJon Cooper 		net_dev->features |= NETIF_F_TSO6;
33928a531400SJon Cooper 	/* Check whether device supports TSO */
33938a531400SJon Cooper 	if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
33948a531400SJon Cooper 		net_dev->features &= ~NETIF_F_ALL_TSO;
33958a531400SJon Cooper 	/* Mask for features that also apply to VLAN devices */
33968a531400SJon Cooper 	net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
33978a531400SJon Cooper 				   NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
33988a531400SJon Cooper 				   NETIF_F_RXCSUM);
33998a531400SJon Cooper 
34006978729fSEdward Cree 	net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
34016978729fSEdward Cree 
34026978729fSEdward Cree 	/* Disable receiving frames with bad FCS, by default. */
34036978729fSEdward Cree 	net_dev->features &= ~NETIF_F_RXALL;
34048a531400SJon Cooper 
34058a531400SJon Cooper 	/* Disable VLAN filtering by default.  It may be enforced if
34068a531400SJon Cooper 	 * the feature is fixed (i.e. VLAN filters are required to
34078a531400SJon Cooper 	 * receive VLAN tagged packets due to vPort restrictions).
34088a531400SJon Cooper 	 */
34098a531400SJon Cooper 	net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
34108a531400SJon Cooper 	net_dev->features |= efx->fixed_features;
34118a531400SJon Cooper 
34128a531400SJon Cooper 	rc = efx_register_netdev(efx);
34138a531400SJon Cooper 	if (!rc)
34148a531400SJon Cooper 		return 0;
34158a531400SJon Cooper 
34168a531400SJon Cooper 	efx_pci_remove_main(efx);
34178a531400SJon Cooper 	return rc;
34188a531400SJon Cooper }
34198a531400SJon Cooper 
3420874aeea5SJeff Kirsher /* NIC initialisation
3421874aeea5SJeff Kirsher  *
3422874aeea5SJeff Kirsher  * This is called at module load (or hotplug insertion,
342373ba7b68SBen Hutchings  * theoretically).  It sets up PCI mappings, resets the NIC,
3424874aeea5SJeff Kirsher  * sets up and registers the network devices with the kernel and hooks
3425874aeea5SJeff Kirsher  * the interrupt service routine.  It does not prepare the device for
3426874aeea5SJeff Kirsher  * transmission; this is left to the first time one of the network
3427874aeea5SJeff Kirsher  * interfaces is brought up (i.e. efx_net_open).
3428874aeea5SJeff Kirsher  */
342987d1fc11SBill Pemberton static int efx_pci_probe(struct pci_dev *pci_dev,
3430874aeea5SJeff Kirsher 			 const struct pci_device_id *entry)
3431874aeea5SJeff Kirsher {
3432874aeea5SJeff Kirsher 	struct net_device *net_dev;
3433874aeea5SJeff Kirsher 	struct efx_nic *efx;
3434fadac6aaSBen Hutchings 	int rc;
3435874aeea5SJeff Kirsher 
3436874aeea5SJeff Kirsher 	/* Allocate and initialise a struct net_device and struct efx_nic */
3437874aeea5SJeff Kirsher 	net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
3438874aeea5SJeff Kirsher 				     EFX_MAX_RX_QUEUES);
3439874aeea5SJeff Kirsher 	if (!net_dev)
3440874aeea5SJeff Kirsher 		return -ENOMEM;
3441adeb15aaSBen Hutchings 	efx = netdev_priv(net_dev);
3442adeb15aaSBen Hutchings 	efx->type = (const struct efx_nic_type *) entry->driver_data;
3443ebfcd0fdSAndrew Rybchenko 	efx->fixed_features |= NETIF_F_HIGHDMA;
3444eb7cfd8cSAndrew Rybchenko 
3445874aeea5SJeff Kirsher 	pci_set_drvdata(pci_dev, efx);
3446874aeea5SJeff Kirsher 	SET_NETDEV_DEV(net_dev, &pci_dev->dev);
3447adeb15aaSBen Hutchings 	rc = efx_init_struct(efx, pci_dev, net_dev);
3448874aeea5SJeff Kirsher 	if (rc)
3449874aeea5SJeff Kirsher 		goto fail1;
3450874aeea5SJeff Kirsher 
3451874aeea5SJeff Kirsher 	netif_info(efx, probe, efx->net_dev,
3452874aeea5SJeff Kirsher 		   "Solarflare NIC detected\n");
3453874aeea5SJeff Kirsher 
34546f7f8aa6SShradha Shah 	if (!efx->type->is_vf)
3455ef215e64SBen Hutchings 		efx_probe_vpd_strings(efx);
3456460eeaa0SBen Hutchings 
3457874aeea5SJeff Kirsher 	/* Set up basic I/O (BAR mappings etc) */
3458874aeea5SJeff Kirsher 	rc = efx_init_io(efx);
3459874aeea5SJeff Kirsher 	if (rc)
3460874aeea5SJeff Kirsher 		goto fail2;
3461874aeea5SJeff Kirsher 
34628a531400SJon Cooper 	rc = efx_pci_probe_post_io(efx);
34638a531400SJon Cooper 	if (rc) {
34648a531400SJon Cooper 		/* On failure, retry once immediately.
34658a531400SJon Cooper 		 * If we aborted probe due to a scheduled reset, dismiss it.
34668a531400SJon Cooper 		 */
34678a531400SJon Cooper 		efx->reset_pending = 0;
34688a531400SJon Cooper 		rc = efx_pci_probe_post_io(efx);
34698a531400SJon Cooper 		if (rc) {
34708a531400SJon Cooper 			/* On another failure, retry once more
34718a531400SJon Cooper 			 * after a 50-305ms delay.
34728a531400SJon Cooper 			 */
34738a531400SJon Cooper 			unsigned char r;
34748a531400SJon Cooper 
34758a531400SJon Cooper 			get_random_bytes(&r, 1);
34768a531400SJon Cooper 			msleep((unsigned int)r + 50);
34778a531400SJon Cooper 			efx->reset_pending = 0;
34788a531400SJon Cooper 			rc = efx_pci_probe_post_io(efx);
34798a531400SJon Cooper 		}
34808a531400SJon Cooper 	}
3481fadac6aaSBen Hutchings 	if (rc)
3482874aeea5SJeff Kirsher 		goto fail3;
3483874aeea5SJeff Kirsher 
3484874aeea5SJeff Kirsher 	netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
3485874aeea5SJeff Kirsher 
34867c43161cSBen Hutchings 	/* Try to create MTDs, but allow this to fail */
3487874aeea5SJeff Kirsher 	rtnl_lock();
34887c43161cSBen Hutchings 	rc = efx_mtd_probe(efx);
3489874aeea5SJeff Kirsher 	rtnl_unlock();
349009a04204SBert Kenward 	if (rc && rc != -EPERM)
34917c43161cSBen Hutchings 		netif_warn(efx, probe, efx->net_dev,
34927c43161cSBen Hutchings 			   "failed to create MTDs (%d)\n", rc);
34937c43161cSBen Hutchings 
3494626950dbSAlexandre Rames 	rc = pci_enable_pcie_error_reporting(pci_dev);
3495626950dbSAlexandre Rames 	if (rc && rc != -EINVAL)
349609a04204SBert Kenward 		netif_notice(efx, probe, efx->net_dev,
349709a04204SBert Kenward 			     "PCIE error reporting unavailable (%d).\n",
349809a04204SBert Kenward 			     rc);
3499626950dbSAlexandre Rames 
3500e5fbd977SJon Cooper 	if (efx->type->udp_tnl_push_ports)
3501e5fbd977SJon Cooper 		efx->type->udp_tnl_push_ports(efx);
3502e5fbd977SJon Cooper 
3503874aeea5SJeff Kirsher 	return 0;
3504874aeea5SJeff Kirsher 
3505874aeea5SJeff Kirsher  fail3:
3506874aeea5SJeff Kirsher 	efx_fini_io(efx);
3507874aeea5SJeff Kirsher  fail2:
3508874aeea5SJeff Kirsher 	efx_fini_struct(efx);
3509874aeea5SJeff Kirsher  fail1:
3510874aeea5SJeff Kirsher 	WARN_ON(rc > 0);
3511874aeea5SJeff Kirsher 	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
3512874aeea5SJeff Kirsher 	free_netdev(net_dev);
3513874aeea5SJeff Kirsher 	return rc;
3514874aeea5SJeff Kirsher }
3515874aeea5SJeff Kirsher 
3516834e23ddSShradha Shah /* efx_pci_sriov_configure returns the actual number of Virtual Functions
3517834e23ddSShradha Shah  * enabled on success
3518834e23ddSShradha Shah  */
3519834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV
3520834e23ddSShradha Shah static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
3521834e23ddSShradha Shah {
3522834e23ddSShradha Shah 	int rc;
3523834e23ddSShradha Shah 	struct efx_nic *efx = pci_get_drvdata(dev);
3524834e23ddSShradha Shah 
3525834e23ddSShradha Shah 	if (efx->type->sriov_configure) {
3526834e23ddSShradha Shah 		rc = efx->type->sriov_configure(efx, num_vfs);
3527834e23ddSShradha Shah 		if (rc)
3528834e23ddSShradha Shah 			return rc;
3529834e23ddSShradha Shah 		else
3530834e23ddSShradha Shah 			return num_vfs;
3531834e23ddSShradha Shah 	} else
3532834e23ddSShradha Shah 		return -EOPNOTSUPP;
3533834e23ddSShradha Shah }
3534834e23ddSShradha Shah #endif
3535834e23ddSShradha Shah 
3536874aeea5SJeff Kirsher static int efx_pm_freeze(struct device *dev)
3537874aeea5SJeff Kirsher {
3538874aeea5SJeff Kirsher 	struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3539874aeea5SJeff Kirsher 
354061da026dSBen Hutchings 	rtnl_lock();
354161da026dSBen Hutchings 
35426032fb56SBen Hutchings 	if (efx->state != STATE_DISABLED) {
3543f16aeea0SBen Hutchings 		efx->state = STATE_UNINIT;
3544874aeea5SJeff Kirsher 
3545c2f3b8e3SDaniel Pieczko 		efx_device_detach_sync(efx);
3546874aeea5SJeff Kirsher 
3547874aeea5SJeff Kirsher 		efx_stop_all(efx);
3548d8291187SBen Hutchings 		efx_disable_interrupts(efx);
35496032fb56SBen Hutchings 	}
3550874aeea5SJeff Kirsher 
355161da026dSBen Hutchings 	rtnl_unlock();
355261da026dSBen Hutchings 
3553874aeea5SJeff Kirsher 	return 0;
3554874aeea5SJeff Kirsher }
3555874aeea5SJeff Kirsher 
3556874aeea5SJeff Kirsher static int efx_pm_thaw(struct device *dev)
3557874aeea5SJeff Kirsher {
3558261e4d96SJon Cooper 	int rc;
3559874aeea5SJeff Kirsher 	struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
3560874aeea5SJeff Kirsher 
356161da026dSBen Hutchings 	rtnl_lock();
356261da026dSBen Hutchings 
35636032fb56SBen Hutchings 	if (efx->state != STATE_DISABLED) {
3564261e4d96SJon Cooper 		rc = efx_enable_interrupts(efx);
3565261e4d96SJon Cooper 		if (rc)
3566261e4d96SJon Cooper 			goto fail;
3567874aeea5SJeff Kirsher 
3568874aeea5SJeff Kirsher 		mutex_lock(&efx->mac_lock);
3569874aeea5SJeff Kirsher 		efx->phy_op->reconfigure(efx);
3570874aeea5SJeff Kirsher 		mutex_unlock(&efx->mac_lock);
3571874aeea5SJeff Kirsher 
3572874aeea5SJeff Kirsher 		efx_start_all(efx);
3573874aeea5SJeff Kirsher 
35749c568fd8SPeter Dunning 		efx_device_attach_if_not_resetting(efx);
3575874aeea5SJeff Kirsher 
3576f16aeea0SBen Hutchings 		efx->state = STATE_READY;
3577874aeea5SJeff Kirsher 
3578874aeea5SJeff Kirsher 		efx->type->resume_wol(efx);
35796032fb56SBen Hutchings 	}
3580874aeea5SJeff Kirsher 
358161da026dSBen Hutchings 	rtnl_unlock();
358261da026dSBen Hutchings 
3583874aeea5SJeff Kirsher 	/* Reschedule any quenched resets scheduled during efx_pm_freeze() */
3584874aeea5SJeff Kirsher 	queue_work(reset_workqueue, &efx->reset_work);
3585874aeea5SJeff Kirsher 
3586874aeea5SJeff Kirsher 	return 0;
3587261e4d96SJon Cooper 
3588261e4d96SJon Cooper fail:
3589261e4d96SJon Cooper 	rtnl_unlock();
3590261e4d96SJon Cooper 
3591261e4d96SJon Cooper 	return rc;
3592874aeea5SJeff Kirsher }
3593874aeea5SJeff Kirsher 
3594874aeea5SJeff Kirsher static int efx_pm_poweroff(struct device *dev)
3595874aeea5SJeff Kirsher {
3596874aeea5SJeff Kirsher 	struct pci_dev *pci_dev = to_pci_dev(dev);
3597874aeea5SJeff Kirsher 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
3598874aeea5SJeff Kirsher 
3599874aeea5SJeff Kirsher 	efx->type->fini(efx);
3600874aeea5SJeff Kirsher 
3601874aeea5SJeff Kirsher 	efx->reset_pending = 0;
3602874aeea5SJeff Kirsher 
3603874aeea5SJeff Kirsher 	pci_save_state(pci_dev);
3604874aeea5SJeff Kirsher 	return pci_set_power_state(pci_dev, PCI_D3hot);
3605874aeea5SJeff Kirsher }
3606874aeea5SJeff Kirsher 
3607874aeea5SJeff Kirsher /* Used for both resume and restore */
3608874aeea5SJeff Kirsher static int efx_pm_resume(struct device *dev)
3609874aeea5SJeff Kirsher {
3610874aeea5SJeff Kirsher 	struct pci_dev *pci_dev = to_pci_dev(dev);
3611874aeea5SJeff Kirsher 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
3612874aeea5SJeff Kirsher 	int rc;
3613874aeea5SJeff Kirsher 
3614874aeea5SJeff Kirsher 	rc = pci_set_power_state(pci_dev, PCI_D0);
3615874aeea5SJeff Kirsher 	if (rc)
3616874aeea5SJeff Kirsher 		return rc;
3617874aeea5SJeff Kirsher 	pci_restore_state(pci_dev);
3618874aeea5SJeff Kirsher 	rc = pci_enable_device(pci_dev);
3619874aeea5SJeff Kirsher 	if (rc)
3620874aeea5SJeff Kirsher 		return rc;
3621874aeea5SJeff Kirsher 	pci_set_master(efx->pci_dev);
3622874aeea5SJeff Kirsher 	rc = efx->type->reset(efx, RESET_TYPE_ALL);
3623874aeea5SJeff Kirsher 	if (rc)
3624874aeea5SJeff Kirsher 		return rc;
3625874aeea5SJeff Kirsher 	rc = efx->type->init(efx);
3626874aeea5SJeff Kirsher 	if (rc)
3627874aeea5SJeff Kirsher 		return rc;
3628261e4d96SJon Cooper 	rc = efx_pm_thaw(dev);
3629261e4d96SJon Cooper 	return rc;
3630874aeea5SJeff Kirsher }
3631874aeea5SJeff Kirsher 
3632874aeea5SJeff Kirsher static int efx_pm_suspend(struct device *dev)
3633874aeea5SJeff Kirsher {
3634874aeea5SJeff Kirsher 	int rc;
3635874aeea5SJeff Kirsher 
3636874aeea5SJeff Kirsher 	efx_pm_freeze(dev);
3637874aeea5SJeff Kirsher 	rc = efx_pm_poweroff(dev);
3638874aeea5SJeff Kirsher 	if (rc)
3639874aeea5SJeff Kirsher 		efx_pm_resume(dev);
3640874aeea5SJeff Kirsher 	return rc;
3641874aeea5SJeff Kirsher }
3642874aeea5SJeff Kirsher 
364318e83e4cSBen Hutchings static const struct dev_pm_ops efx_pm_ops = {
3644874aeea5SJeff Kirsher 	.suspend	= efx_pm_suspend,
3645874aeea5SJeff Kirsher 	.resume		= efx_pm_resume,
3646874aeea5SJeff Kirsher 	.freeze		= efx_pm_freeze,
3647874aeea5SJeff Kirsher 	.thaw		= efx_pm_thaw,
3648874aeea5SJeff Kirsher 	.poweroff	= efx_pm_poweroff,
3649874aeea5SJeff Kirsher 	.restore	= efx_pm_resume,
3650874aeea5SJeff Kirsher };
3651874aeea5SJeff Kirsher 
3652626950dbSAlexandre Rames /* A PCI error affecting this device was detected.
3653626950dbSAlexandre Rames  * At this point MMIO and DMA may be disabled.
3654626950dbSAlexandre Rames  * Stop the software path and request a slot reset.
3655626950dbSAlexandre Rames  */
3656debd0034Sstephen hemminger static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
3657626950dbSAlexandre Rames 					      enum pci_channel_state state)
3658626950dbSAlexandre Rames {
3659626950dbSAlexandre Rames 	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3660626950dbSAlexandre Rames 	struct efx_nic *efx = pci_get_drvdata(pdev);
3661626950dbSAlexandre Rames 
3662626950dbSAlexandre Rames 	if (state == pci_channel_io_perm_failure)
3663626950dbSAlexandre Rames 		return PCI_ERS_RESULT_DISCONNECT;
3664626950dbSAlexandre Rames 
3665626950dbSAlexandre Rames 	rtnl_lock();
3666626950dbSAlexandre Rames 
3667626950dbSAlexandre Rames 	if (efx->state != STATE_DISABLED) {
3668626950dbSAlexandre Rames 		efx->state = STATE_RECOVERY;
3669626950dbSAlexandre Rames 		efx->reset_pending = 0;
3670626950dbSAlexandre Rames 
3671626950dbSAlexandre Rames 		efx_device_detach_sync(efx);
3672626950dbSAlexandre Rames 
3673626950dbSAlexandre Rames 		efx_stop_all(efx);
3674d8291187SBen Hutchings 		efx_disable_interrupts(efx);
3675626950dbSAlexandre Rames 
3676626950dbSAlexandre Rames 		status = PCI_ERS_RESULT_NEED_RESET;
3677626950dbSAlexandre Rames 	} else {
3678626950dbSAlexandre Rames 		/* If the interface is disabled we don't want to do anything
3679626950dbSAlexandre Rames 		 * with it.
3680626950dbSAlexandre Rames 		 */
3681626950dbSAlexandre Rames 		status = PCI_ERS_RESULT_RECOVERED;
3682626950dbSAlexandre Rames 	}
3683626950dbSAlexandre Rames 
3684626950dbSAlexandre Rames 	rtnl_unlock();
3685626950dbSAlexandre Rames 
3686626950dbSAlexandre Rames 	pci_disable_device(pdev);
3687626950dbSAlexandre Rames 
3688626950dbSAlexandre Rames 	return status;
3689626950dbSAlexandre Rames }
3690626950dbSAlexandre Rames 
3691dbedd44eSJoe Perches /* Fake a successful reset, which will be performed later in efx_io_resume. */
3692debd0034Sstephen hemminger static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
3693626950dbSAlexandre Rames {
3694626950dbSAlexandre Rames 	struct efx_nic *efx = pci_get_drvdata(pdev);
3695626950dbSAlexandre Rames 	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3696626950dbSAlexandre Rames 	int rc;
3697626950dbSAlexandre Rames 
3698626950dbSAlexandre Rames 	if (pci_enable_device(pdev)) {
3699626950dbSAlexandre Rames 		netif_err(efx, hw, efx->net_dev,
3700626950dbSAlexandre Rames 			  "Cannot re-enable PCI device after reset.\n");
3701626950dbSAlexandre Rames 		status =  PCI_ERS_RESULT_DISCONNECT;
3702626950dbSAlexandre Rames 	}
3703626950dbSAlexandre Rames 
3704626950dbSAlexandre Rames 	rc = pci_cleanup_aer_uncorrect_error_status(pdev);
3705626950dbSAlexandre Rames 	if (rc) {
3706626950dbSAlexandre Rames 		netif_err(efx, hw, efx->net_dev,
3707626950dbSAlexandre Rames 		"pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
3708626950dbSAlexandre Rames 		/* Non-fatal error. Continue. */
3709626950dbSAlexandre Rames 	}
3710626950dbSAlexandre Rames 
3711626950dbSAlexandre Rames 	return status;
3712626950dbSAlexandre Rames }
3713626950dbSAlexandre Rames 
3714626950dbSAlexandre Rames /* Perform the actual reset and resume I/O operations. */
3715626950dbSAlexandre Rames static void efx_io_resume(struct pci_dev *pdev)
3716626950dbSAlexandre Rames {
3717626950dbSAlexandre Rames 	struct efx_nic *efx = pci_get_drvdata(pdev);
3718626950dbSAlexandre Rames 	int rc;
3719626950dbSAlexandre Rames 
3720626950dbSAlexandre Rames 	rtnl_lock();
3721626950dbSAlexandre Rames 
3722626950dbSAlexandre Rames 	if (efx->state == STATE_DISABLED)
3723626950dbSAlexandre Rames 		goto out;
3724626950dbSAlexandre Rames 
3725626950dbSAlexandre Rames 	rc = efx_reset(efx, RESET_TYPE_ALL);
3726626950dbSAlexandre Rames 	if (rc) {
3727626950dbSAlexandre Rames 		netif_err(efx, hw, efx->net_dev,
3728626950dbSAlexandre Rames 			  "efx_reset failed after PCI error (%d)\n", rc);
3729626950dbSAlexandre Rames 	} else {
3730626950dbSAlexandre Rames 		efx->state = STATE_READY;
3731626950dbSAlexandre Rames 		netif_dbg(efx, hw, efx->net_dev,
3732626950dbSAlexandre Rames 			  "Done resetting and resuming IO after PCI error.\n");
3733626950dbSAlexandre Rames 	}
3734626950dbSAlexandre Rames 
3735626950dbSAlexandre Rames out:
3736626950dbSAlexandre Rames 	rtnl_unlock();
3737626950dbSAlexandre Rames }
3738626950dbSAlexandre Rames 
3739626950dbSAlexandre Rames /* For simplicity and reliability, we always require a slot reset and try to
3740626950dbSAlexandre Rames  * reset the hardware when a pci error affecting the device is detected.
3741626950dbSAlexandre Rames  * We leave both the link_reset and mmio_enabled callback unimplemented:
3742626950dbSAlexandre Rames  * with our request for slot reset the mmio_enabled callback will never be
3743626950dbSAlexandre Rames  * called, and the link_reset callback is not used by AER or EEH mechanisms.
3744626950dbSAlexandre Rames  */
3745c300366bSJulia Lawall static const struct pci_error_handlers efx_err_handlers = {
3746626950dbSAlexandre Rames 	.error_detected = efx_io_error_detected,
3747626950dbSAlexandre Rames 	.slot_reset	= efx_io_slot_reset,
3748626950dbSAlexandre Rames 	.resume		= efx_io_resume,
3749626950dbSAlexandre Rames };
3750626950dbSAlexandre Rames 
3751874aeea5SJeff Kirsher static struct pci_driver efx_pci_driver = {
3752874aeea5SJeff Kirsher 	.name		= KBUILD_MODNAME,
3753874aeea5SJeff Kirsher 	.id_table	= efx_pci_table,
3754874aeea5SJeff Kirsher 	.probe		= efx_pci_probe,
3755874aeea5SJeff Kirsher 	.remove		= efx_pci_remove,
3756874aeea5SJeff Kirsher 	.driver.pm	= &efx_pm_ops,
3757626950dbSAlexandre Rames 	.err_handler	= &efx_err_handlers,
3758834e23ddSShradha Shah #ifdef CONFIG_SFC_SRIOV
3759834e23ddSShradha Shah 	.sriov_configure = efx_pci_sriov_configure,
3760834e23ddSShradha Shah #endif
3761874aeea5SJeff Kirsher };
3762874aeea5SJeff Kirsher 
3763874aeea5SJeff Kirsher /**************************************************************************
3764874aeea5SJeff Kirsher  *
3765874aeea5SJeff Kirsher  * Kernel module interface
3766874aeea5SJeff Kirsher  *
3767874aeea5SJeff Kirsher  *************************************************************************/
3768874aeea5SJeff Kirsher 
3769874aeea5SJeff Kirsher module_param(interrupt_mode, uint, 0444);
3770874aeea5SJeff Kirsher MODULE_PARM_DESC(interrupt_mode,
3771874aeea5SJeff Kirsher 		 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3772874aeea5SJeff Kirsher 
3773874aeea5SJeff Kirsher static int __init efx_init_module(void)
3774874aeea5SJeff Kirsher {
3775874aeea5SJeff Kirsher 	int rc;
3776874aeea5SJeff Kirsher 
3777874aeea5SJeff Kirsher 	printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
3778874aeea5SJeff Kirsher 
3779874aeea5SJeff Kirsher 	rc = register_netdevice_notifier(&efx_netdev_notifier);
3780874aeea5SJeff Kirsher 	if (rc)
3781874aeea5SJeff Kirsher 		goto err_notifier;
3782874aeea5SJeff Kirsher 
37837fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV
3784cd2d5b52SBen Hutchings 	rc = efx_init_sriov();
3785cd2d5b52SBen Hutchings 	if (rc)
3786cd2d5b52SBen Hutchings 		goto err_sriov;
37877fa8d547SShradha Shah #endif
3788cd2d5b52SBen Hutchings 
3789874aeea5SJeff Kirsher 	reset_workqueue = create_singlethread_workqueue("sfc_reset");
3790874aeea5SJeff Kirsher 	if (!reset_workqueue) {
3791874aeea5SJeff Kirsher 		rc = -ENOMEM;
3792874aeea5SJeff Kirsher 		goto err_reset;
3793874aeea5SJeff Kirsher 	}
3794874aeea5SJeff Kirsher 
3795874aeea5SJeff Kirsher 	rc = pci_register_driver(&efx_pci_driver);
3796874aeea5SJeff Kirsher 	if (rc < 0)
3797874aeea5SJeff Kirsher 		goto err_pci;
3798874aeea5SJeff Kirsher 
3799874aeea5SJeff Kirsher 	return 0;
3800874aeea5SJeff Kirsher 
3801874aeea5SJeff Kirsher  err_pci:
3802874aeea5SJeff Kirsher 	destroy_workqueue(reset_workqueue);
3803874aeea5SJeff Kirsher  err_reset:
38047fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV
3805cd2d5b52SBen Hutchings 	efx_fini_sriov();
3806cd2d5b52SBen Hutchings  err_sriov:
38077fa8d547SShradha Shah #endif
3808874aeea5SJeff Kirsher 	unregister_netdevice_notifier(&efx_netdev_notifier);
3809874aeea5SJeff Kirsher  err_notifier:
3810874aeea5SJeff Kirsher 	return rc;
3811874aeea5SJeff Kirsher }
3812874aeea5SJeff Kirsher 
3813874aeea5SJeff Kirsher static void __exit efx_exit_module(void)
3814874aeea5SJeff Kirsher {
3815874aeea5SJeff Kirsher 	printk(KERN_INFO "Solarflare NET driver unloading\n");
3816874aeea5SJeff Kirsher 
3817874aeea5SJeff Kirsher 	pci_unregister_driver(&efx_pci_driver);
3818874aeea5SJeff Kirsher 	destroy_workqueue(reset_workqueue);
38197fa8d547SShradha Shah #ifdef CONFIG_SFC_SRIOV
3820cd2d5b52SBen Hutchings 	efx_fini_sriov();
38217fa8d547SShradha Shah #endif
3822874aeea5SJeff Kirsher 	unregister_netdevice_notifier(&efx_netdev_notifier);
3823874aeea5SJeff Kirsher 
3824874aeea5SJeff Kirsher }
3825874aeea5SJeff Kirsher 
3826874aeea5SJeff Kirsher module_init(efx_init_module);
3827874aeea5SJeff Kirsher module_exit(efx_exit_module);
3828874aeea5SJeff Kirsher 
3829874aeea5SJeff Kirsher MODULE_AUTHOR("Solarflare Communications and "
3830874aeea5SJeff Kirsher 	      "Michael Brown <mbrown@fensystems.co.uk>");
38316a350fdbSBen Hutchings MODULE_DESCRIPTION("Solarflare network driver");
3832874aeea5SJeff Kirsher MODULE_LICENSE("GPL");
3833874aeea5SJeff Kirsher MODULE_DEVICE_TABLE(pci, efx_pci_table);
383414077e9eSEdward Cree MODULE_VERSION(EFX_DRIVER_VERSION);
3835