xref: /openbmc/linux/drivers/net/ethernet/sfc/falcon/efx.c (revision a1117495)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3  * Driver for Solarflare network controllers and boards
4  * Copyright 2005-2006 Fen Systems Ltd.
5  * Copyright 2005-2013 Solarflare Communications Inc.
6  */
7 
8 #include <linux/module.h>
9 #include <linux/pci.h>
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/delay.h>
13 #include <linux/notifier.h>
14 #include <linux/ip.h>
15 #include <linux/tcp.h>
16 #include <linux/in.h>
17 #include <linux/ethtool.h>
18 #include <linux/topology.h>
19 #include <linux/gfp.h>
20 #include <linux/aer.h>
21 #include <linux/interrupt.h>
22 #include "net_driver.h"
23 #include "efx.h"
24 #include "nic.h"
25 #include "selftest.h"
26 
27 #include "workarounds.h"
28 
29 /**************************************************************************
30  *
31  * Type name strings
32  *
33  **************************************************************************
34  */
35 
36 /* Loopback mode names (see LOOPBACK_MODE()) */
37 const unsigned int ef4_loopback_mode_max = LOOPBACK_MAX;
38 const char *const ef4_loopback_mode_names[] = {
39 	[LOOPBACK_NONE]		= "NONE",
40 	[LOOPBACK_DATA]		= "DATAPATH",
41 	[LOOPBACK_GMAC]		= "GMAC",
42 	[LOOPBACK_XGMII]	= "XGMII",
43 	[LOOPBACK_XGXS]		= "XGXS",
44 	[LOOPBACK_XAUI]		= "XAUI",
45 	[LOOPBACK_GMII]		= "GMII",
46 	[LOOPBACK_SGMII]	= "SGMII",
47 	[LOOPBACK_XGBR]		= "XGBR",
48 	[LOOPBACK_XFI]		= "XFI",
49 	[LOOPBACK_XAUI_FAR]	= "XAUI_FAR",
50 	[LOOPBACK_GMII_FAR]	= "GMII_FAR",
51 	[LOOPBACK_SGMII_FAR]	= "SGMII_FAR",
52 	[LOOPBACK_XFI_FAR]	= "XFI_FAR",
53 	[LOOPBACK_GPHY]		= "GPHY",
54 	[LOOPBACK_PHYXS]	= "PHYXS",
55 	[LOOPBACK_PCS]		= "PCS",
56 	[LOOPBACK_PMAPMD]	= "PMA/PMD",
57 	[LOOPBACK_XPORT]	= "XPORT",
58 	[LOOPBACK_XGMII_WS]	= "XGMII_WS",
59 	[LOOPBACK_XAUI_WS]	= "XAUI_WS",
60 	[LOOPBACK_XAUI_WS_FAR]  = "XAUI_WS_FAR",
61 	[LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
62 	[LOOPBACK_GMII_WS]	= "GMII_WS",
63 	[LOOPBACK_XFI_WS]	= "XFI_WS",
64 	[LOOPBACK_XFI_WS_FAR]	= "XFI_WS_FAR",
65 	[LOOPBACK_PHYXS_WS]	= "PHYXS_WS",
66 };
67 
68 const unsigned int ef4_reset_type_max = RESET_TYPE_MAX;
69 const char *const ef4_reset_type_names[] = {
70 	[RESET_TYPE_INVISIBLE]          = "INVISIBLE",
71 	[RESET_TYPE_ALL]                = "ALL",
72 	[RESET_TYPE_RECOVER_OR_ALL]     = "RECOVER_OR_ALL",
73 	[RESET_TYPE_WORLD]              = "WORLD",
74 	[RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
75 	[RESET_TYPE_DATAPATH]           = "DATAPATH",
76 	[RESET_TYPE_DISABLE]            = "DISABLE",
77 	[RESET_TYPE_TX_WATCHDOG]        = "TX_WATCHDOG",
78 	[RESET_TYPE_INT_ERROR]          = "INT_ERROR",
79 	[RESET_TYPE_RX_RECOVERY]        = "RX_RECOVERY",
80 	[RESET_TYPE_DMA_ERROR]          = "DMA_ERROR",
81 	[RESET_TYPE_TX_SKIP]            = "TX_SKIP",
82 };
83 
84 /* Reset workqueue. If any NIC has a hardware failure then a reset will be
85  * queued onto this work queue. This is not a per-nic work queue, because
86  * ef4_reset_work() acquires the rtnl lock, so resets are naturally serialised.
87  */
88 static struct workqueue_struct *reset_workqueue;
89 
90 /* How often and how many times to poll for a reset while waiting for a
91  * BIST that another function started to complete.
92  */
93 #define BIST_WAIT_DELAY_MS	100
94 #define BIST_WAIT_DELAY_COUNT	100
95 
96 /**************************************************************************
97  *
98  * Configurable values
99  *
100  *************************************************************************/
101 
102 /*
103  * Use separate channels for TX and RX events
104  *
105  * Set this to 1 to use separate channels for TX and RX. It allows us
106  * to control interrupt affinity separately for TX and RX.
107  *
108  * This is only used in MSI-X interrupt mode
109  */
110 bool ef4_separate_tx_channels;
111 module_param(ef4_separate_tx_channels, bool, 0444);
112 MODULE_PARM_DESC(ef4_separate_tx_channels,
113 		 "Use separate channels for TX and RX");
114 
115 /* This is the weight assigned to each of the (per-channel) virtual
116  * NAPI devices.
117  */
118 static int napi_weight = 64;
119 
120 /* This is the time (in jiffies) between invocations of the hardware
121  * monitor.
122  * On Falcon-based NICs, this will:
123  * - Check the on-board hardware monitor;
124  * - Poll the link state and reconfigure the hardware as necessary.
125  * On Siena-based NICs for power systems with EEH support, this will give EEH a
126  * chance to start.
127  */
128 static unsigned int ef4_monitor_interval = 1 * HZ;
129 
130 /* Initial interrupt moderation settings.  They can be modified after
131  * module load with ethtool.
132  *
133  * The default for RX should strike a balance between increasing the
134  * round-trip latency and reducing overhead.
135  */
136 static unsigned int rx_irq_mod_usec = 60;
137 
138 /* Initial interrupt moderation settings.  They can be modified after
139  * module load with ethtool.
140  *
141  * This default is chosen to ensure that a 10G link does not go idle
142  * while a TX queue is stopped after it has become full.  A queue is
143  * restarted when it drops below half full.  The time this takes (assuming
144  * worst case 3 descriptors per packet and 1024 descriptors) is
145  *   512 / 3 * 1.2 = 205 usec.
146  */
147 static unsigned int tx_irq_mod_usec = 150;
148 
149 /* This is the first interrupt mode to try out of:
150  * 0 => MSI-X
151  * 1 => MSI
152  * 2 => legacy
153  */
154 static unsigned int interrupt_mode;
155 
156 /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
157  * i.e. the number of CPUs among which we may distribute simultaneous
158  * interrupt handling.
159  *
160  * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
161  * The default (0) means to assign an interrupt to each core.
162  */
163 static unsigned int rss_cpus;
164 module_param(rss_cpus, uint, 0444);
165 MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
166 
167 static bool phy_flash_cfg;
168 module_param(phy_flash_cfg, bool, 0644);
169 MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
170 
171 static unsigned irq_adapt_low_thresh = 8000;
172 module_param(irq_adapt_low_thresh, uint, 0644);
173 MODULE_PARM_DESC(irq_adapt_low_thresh,
174 		 "Threshold score for reducing IRQ moderation");
175 
176 static unsigned irq_adapt_high_thresh = 16000;
177 module_param(irq_adapt_high_thresh, uint, 0644);
178 MODULE_PARM_DESC(irq_adapt_high_thresh,
179 		 "Threshold score for increasing IRQ moderation");
180 
181 static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
182 			 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
183 			 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
184 			 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
185 module_param(debug, uint, 0);
186 MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
187 
188 /**************************************************************************
189  *
190  * Utility functions and prototypes
191  *
192  *************************************************************************/
193 
194 static int ef4_soft_enable_interrupts(struct ef4_nic *efx);
195 static void ef4_soft_disable_interrupts(struct ef4_nic *efx);
196 static void ef4_remove_channel(struct ef4_channel *channel);
197 static void ef4_remove_channels(struct ef4_nic *efx);
198 static const struct ef4_channel_type ef4_default_channel_type;
199 static void ef4_remove_port(struct ef4_nic *efx);
200 static void ef4_init_napi_channel(struct ef4_channel *channel);
201 static void ef4_fini_napi(struct ef4_nic *efx);
202 static void ef4_fini_napi_channel(struct ef4_channel *channel);
203 static void ef4_fini_struct(struct ef4_nic *efx);
204 static void ef4_start_all(struct ef4_nic *efx);
205 static void ef4_stop_all(struct ef4_nic *efx);
206 
207 #define EF4_ASSERT_RESET_SERIALISED(efx)		\
208 	do {						\
209 		if ((efx->state == STATE_READY) ||	\
210 		    (efx->state == STATE_RECOVERY) ||	\
211 		    (efx->state == STATE_DISABLED))	\
212 			ASSERT_RTNL();			\
213 	} while (0)
214 
215 static int ef4_check_disabled(struct ef4_nic *efx)
216 {
217 	if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
218 		netif_err(efx, drv, efx->net_dev,
219 			  "device is disabled due to earlier errors\n");
220 		return -EIO;
221 	}
222 	return 0;
223 }
224 
225 /**************************************************************************
226  *
227  * Event queue processing
228  *
229  *************************************************************************/
230 
231 /* Process channel's event queue
232  *
233  * This function is responsible for processing the event queue of a
234  * single channel.  The caller must guarantee that this function will
235  * never be concurrently called more than once on the same channel,
236  * though different channels may be being processed concurrently.
237  */
238 static int ef4_process_channel(struct ef4_channel *channel, int budget)
239 {
240 	struct ef4_tx_queue *tx_queue;
241 	int spent;
242 
243 	if (unlikely(!channel->enabled))
244 		return 0;
245 
246 	ef4_for_each_channel_tx_queue(tx_queue, channel) {
247 		tx_queue->pkts_compl = 0;
248 		tx_queue->bytes_compl = 0;
249 	}
250 
251 	spent = ef4_nic_process_eventq(channel, budget);
252 	if (spent && ef4_channel_has_rx_queue(channel)) {
253 		struct ef4_rx_queue *rx_queue =
254 			ef4_channel_get_rx_queue(channel);
255 
256 		ef4_rx_flush_packet(channel);
257 		ef4_fast_push_rx_descriptors(rx_queue, true);
258 	}
259 
260 	/* Update BQL */
261 	ef4_for_each_channel_tx_queue(tx_queue, channel) {
262 		if (tx_queue->bytes_compl) {
263 			netdev_tx_completed_queue(tx_queue->core_txq,
264 				tx_queue->pkts_compl, tx_queue->bytes_compl);
265 		}
266 	}
267 
268 	return spent;
269 }
270 
271 /* NAPI poll handler
272  *
273  * NAPI guarantees serialisation of polls of the same device, which
274  * provides the guarantee required by ef4_process_channel().
275  */
276 static void ef4_update_irq_mod(struct ef4_nic *efx, struct ef4_channel *channel)
277 {
278 	int step = efx->irq_mod_step_us;
279 
280 	if (channel->irq_mod_score < irq_adapt_low_thresh) {
281 		if (channel->irq_moderation_us > step) {
282 			channel->irq_moderation_us -= step;
283 			efx->type->push_irq_moderation(channel);
284 		}
285 	} else if (channel->irq_mod_score > irq_adapt_high_thresh) {
286 		if (channel->irq_moderation_us <
287 		    efx->irq_rx_moderation_us) {
288 			channel->irq_moderation_us += step;
289 			efx->type->push_irq_moderation(channel);
290 		}
291 	}
292 
293 	channel->irq_count = 0;
294 	channel->irq_mod_score = 0;
295 }
296 
297 static int ef4_poll(struct napi_struct *napi, int budget)
298 {
299 	struct ef4_channel *channel =
300 		container_of(napi, struct ef4_channel, napi_str);
301 	struct ef4_nic *efx = channel->efx;
302 	int spent;
303 
304 	netif_vdbg(efx, intr, efx->net_dev,
305 		   "channel %d NAPI poll executing on CPU %d\n",
306 		   channel->channel, raw_smp_processor_id());
307 
308 	spent = ef4_process_channel(channel, budget);
309 
310 	if (spent < budget) {
311 		if (ef4_channel_has_rx_queue(channel) &&
312 		    efx->irq_rx_adaptive &&
313 		    unlikely(++channel->irq_count == 1000)) {
314 			ef4_update_irq_mod(efx, channel);
315 		}
316 
317 		ef4_filter_rfs_expire(channel);
318 
319 		/* There is no race here; although napi_disable() will
320 		 * only wait for napi_complete(), this isn't a problem
321 		 * since ef4_nic_eventq_read_ack() will have no effect if
322 		 * interrupts have already been disabled.
323 		 */
324 		napi_complete_done(napi, spent);
325 		ef4_nic_eventq_read_ack(channel);
326 	}
327 
328 	return spent;
329 }
330 
331 /* Create event queue
332  * Event queue memory allocations are done only once.  If the channel
333  * is reset, the memory buffer will be reused; this guards against
334  * errors during channel reset and also simplifies interrupt handling.
335  */
336 static int ef4_probe_eventq(struct ef4_channel *channel)
337 {
338 	struct ef4_nic *efx = channel->efx;
339 	unsigned long entries;
340 
341 	netif_dbg(efx, probe, efx->net_dev,
342 		  "chan %d create event queue\n", channel->channel);
343 
344 	/* Build an event queue with room for one event per tx and rx buffer,
345 	 * plus some extra for link state events and MCDI completions. */
346 	entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
347 	EF4_BUG_ON_PARANOID(entries > EF4_MAX_EVQ_SIZE);
348 	channel->eventq_mask = max(entries, EF4_MIN_EVQ_SIZE) - 1;
349 
350 	return ef4_nic_probe_eventq(channel);
351 }
352 
353 /* Prepare channel's event queue */
354 static int ef4_init_eventq(struct ef4_channel *channel)
355 {
356 	struct ef4_nic *efx = channel->efx;
357 	int rc;
358 
359 	EF4_WARN_ON_PARANOID(channel->eventq_init);
360 
361 	netif_dbg(efx, drv, efx->net_dev,
362 		  "chan %d init event queue\n", channel->channel);
363 
364 	rc = ef4_nic_init_eventq(channel);
365 	if (rc == 0) {
366 		efx->type->push_irq_moderation(channel);
367 		channel->eventq_read_ptr = 0;
368 		channel->eventq_init = true;
369 	}
370 	return rc;
371 }
372 
373 /* Enable event queue processing and NAPI */
374 void ef4_start_eventq(struct ef4_channel *channel)
375 {
376 	netif_dbg(channel->efx, ifup, channel->efx->net_dev,
377 		  "chan %d start event queue\n", channel->channel);
378 
379 	/* Make sure the NAPI handler sees the enabled flag set */
380 	channel->enabled = true;
381 	smp_wmb();
382 
383 	napi_enable(&channel->napi_str);
384 	ef4_nic_eventq_read_ack(channel);
385 }
386 
387 /* Disable event queue processing and NAPI */
388 void ef4_stop_eventq(struct ef4_channel *channel)
389 {
390 	if (!channel->enabled)
391 		return;
392 
393 	napi_disable(&channel->napi_str);
394 	channel->enabled = false;
395 }
396 
397 static void ef4_fini_eventq(struct ef4_channel *channel)
398 {
399 	if (!channel->eventq_init)
400 		return;
401 
402 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
403 		  "chan %d fini event queue\n", channel->channel);
404 
405 	ef4_nic_fini_eventq(channel);
406 	channel->eventq_init = false;
407 }
408 
409 static void ef4_remove_eventq(struct ef4_channel *channel)
410 {
411 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
412 		  "chan %d remove event queue\n", channel->channel);
413 
414 	ef4_nic_remove_eventq(channel);
415 }
416 
417 /**************************************************************************
418  *
419  * Channel handling
420  *
421  *************************************************************************/
422 
423 /* Allocate and initialise a channel structure. */
424 static struct ef4_channel *
425 ef4_alloc_channel(struct ef4_nic *efx, int i, struct ef4_channel *old_channel)
426 {
427 	struct ef4_channel *channel;
428 	struct ef4_rx_queue *rx_queue;
429 	struct ef4_tx_queue *tx_queue;
430 	int j;
431 
432 	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
433 	if (!channel)
434 		return NULL;
435 
436 	channel->efx = efx;
437 	channel->channel = i;
438 	channel->type = &ef4_default_channel_type;
439 
440 	for (j = 0; j < EF4_TXQ_TYPES; j++) {
441 		tx_queue = &channel->tx_queue[j];
442 		tx_queue->efx = efx;
443 		tx_queue->queue = i * EF4_TXQ_TYPES + j;
444 		tx_queue->channel = channel;
445 	}
446 
447 	rx_queue = &channel->rx_queue;
448 	rx_queue->efx = efx;
449 	timer_setup(&rx_queue->slow_fill, ef4_rx_slow_fill, 0);
450 
451 	return channel;
452 }
453 
454 /* Allocate and initialise a channel structure, copying parameters
455  * (but not resources) from an old channel structure.
456  */
457 static struct ef4_channel *
458 ef4_copy_channel(const struct ef4_channel *old_channel)
459 {
460 	struct ef4_channel *channel;
461 	struct ef4_rx_queue *rx_queue;
462 	struct ef4_tx_queue *tx_queue;
463 	int j;
464 
465 	channel = kmalloc(sizeof(*channel), GFP_KERNEL);
466 	if (!channel)
467 		return NULL;
468 
469 	*channel = *old_channel;
470 
471 	channel->napi_dev = NULL;
472 	INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
473 	channel->napi_str.napi_id = 0;
474 	channel->napi_str.state = 0;
475 	memset(&channel->eventq, 0, sizeof(channel->eventq));
476 
477 	for (j = 0; j < EF4_TXQ_TYPES; j++) {
478 		tx_queue = &channel->tx_queue[j];
479 		if (tx_queue->channel)
480 			tx_queue->channel = channel;
481 		tx_queue->buffer = NULL;
482 		memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
483 	}
484 
485 	rx_queue = &channel->rx_queue;
486 	rx_queue->buffer = NULL;
487 	memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
488 	timer_setup(&rx_queue->slow_fill, ef4_rx_slow_fill, 0);
489 
490 	return channel;
491 }
492 
493 static int ef4_probe_channel(struct ef4_channel *channel)
494 {
495 	struct ef4_tx_queue *tx_queue;
496 	struct ef4_rx_queue *rx_queue;
497 	int rc;
498 
499 	netif_dbg(channel->efx, probe, channel->efx->net_dev,
500 		  "creating channel %d\n", channel->channel);
501 
502 	rc = channel->type->pre_probe(channel);
503 	if (rc)
504 		goto fail;
505 
506 	rc = ef4_probe_eventq(channel);
507 	if (rc)
508 		goto fail;
509 
510 	ef4_for_each_channel_tx_queue(tx_queue, channel) {
511 		rc = ef4_probe_tx_queue(tx_queue);
512 		if (rc)
513 			goto fail;
514 	}
515 
516 	ef4_for_each_channel_rx_queue(rx_queue, channel) {
517 		rc = ef4_probe_rx_queue(rx_queue);
518 		if (rc)
519 			goto fail;
520 	}
521 
522 	return 0;
523 
524 fail:
525 	ef4_remove_channel(channel);
526 	return rc;
527 }
528 
529 static void
530 ef4_get_channel_name(struct ef4_channel *channel, char *buf, size_t len)
531 {
532 	struct ef4_nic *efx = channel->efx;
533 	const char *type;
534 	int number;
535 
536 	number = channel->channel;
537 	if (efx->tx_channel_offset == 0) {
538 		type = "";
539 	} else if (channel->channel < efx->tx_channel_offset) {
540 		type = "-rx";
541 	} else {
542 		type = "-tx";
543 		number -= efx->tx_channel_offset;
544 	}
545 	snprintf(buf, len, "%s%s-%d", efx->name, type, number);
546 }
547 
548 static void ef4_set_channel_names(struct ef4_nic *efx)
549 {
550 	struct ef4_channel *channel;
551 
552 	ef4_for_each_channel(channel, efx)
553 		channel->type->get_name(channel,
554 					efx->msi_context[channel->channel].name,
555 					sizeof(efx->msi_context[0].name));
556 }
557 
558 static int ef4_probe_channels(struct ef4_nic *efx)
559 {
560 	struct ef4_channel *channel;
561 	int rc;
562 
563 	/* Restart special buffer allocation */
564 	efx->next_buffer_table = 0;
565 
566 	/* Probe channels in reverse, so that any 'extra' channels
567 	 * use the start of the buffer table. This allows the traffic
568 	 * channels to be resized without moving them or wasting the
569 	 * entries before them.
570 	 */
571 	ef4_for_each_channel_rev(channel, efx) {
572 		rc = ef4_probe_channel(channel);
573 		if (rc) {
574 			netif_err(efx, probe, efx->net_dev,
575 				  "failed to create channel %d\n",
576 				  channel->channel);
577 			goto fail;
578 		}
579 	}
580 	ef4_set_channel_names(efx);
581 
582 	return 0;
583 
584 fail:
585 	ef4_remove_channels(efx);
586 	return rc;
587 }
588 
589 /* Channels are shutdown and reinitialised whilst the NIC is running
590  * to propagate configuration changes (mtu, checksum offload), or
591  * to clear hardware error conditions
592  */
593 static void ef4_start_datapath(struct ef4_nic *efx)
594 {
595 	netdev_features_t old_features = efx->net_dev->features;
596 	bool old_rx_scatter = efx->rx_scatter;
597 	struct ef4_tx_queue *tx_queue;
598 	struct ef4_rx_queue *rx_queue;
599 	struct ef4_channel *channel;
600 	size_t rx_buf_len;
601 
602 	/* Calculate the rx buffer allocation parameters required to
603 	 * support the current MTU, including padding for header
604 	 * alignment and overruns.
605 	 */
606 	efx->rx_dma_len = (efx->rx_prefix_size +
607 			   EF4_MAX_FRAME_LEN(efx->net_dev->mtu) +
608 			   efx->type->rx_buffer_padding);
609 	rx_buf_len = (sizeof(struct ef4_rx_page_state) +
610 		      efx->rx_ip_align + efx->rx_dma_len);
611 	if (rx_buf_len <= PAGE_SIZE) {
612 		efx->rx_scatter = efx->type->always_rx_scatter;
613 		efx->rx_buffer_order = 0;
614 	} else if (efx->type->can_rx_scatter) {
615 		BUILD_BUG_ON(EF4_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
616 		BUILD_BUG_ON(sizeof(struct ef4_rx_page_state) +
617 			     2 * ALIGN(NET_IP_ALIGN + EF4_RX_USR_BUF_SIZE,
618 				       EF4_RX_BUF_ALIGNMENT) >
619 			     PAGE_SIZE);
620 		efx->rx_scatter = true;
621 		efx->rx_dma_len = EF4_RX_USR_BUF_SIZE;
622 		efx->rx_buffer_order = 0;
623 	} else {
624 		efx->rx_scatter = false;
625 		efx->rx_buffer_order = get_order(rx_buf_len);
626 	}
627 
628 	ef4_rx_config_page_split(efx);
629 	if (efx->rx_buffer_order)
630 		netif_dbg(efx, drv, efx->net_dev,
631 			  "RX buf len=%u; page order=%u batch=%u\n",
632 			  efx->rx_dma_len, efx->rx_buffer_order,
633 			  efx->rx_pages_per_batch);
634 	else
635 		netif_dbg(efx, drv, efx->net_dev,
636 			  "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
637 			  efx->rx_dma_len, efx->rx_page_buf_step,
638 			  efx->rx_bufs_per_page, efx->rx_pages_per_batch);
639 
640 	/* Restore previously fixed features in hw_features and remove
641 	 * features which are fixed now
642 	 */
643 	efx->net_dev->hw_features |= efx->net_dev->features;
644 	efx->net_dev->hw_features &= ~efx->fixed_features;
645 	efx->net_dev->features |= efx->fixed_features;
646 	if (efx->net_dev->features != old_features)
647 		netdev_features_change(efx->net_dev);
648 
649 	/* RX filters may also have scatter-enabled flags */
650 	if (efx->rx_scatter != old_rx_scatter)
651 		efx->type->filter_update_rx_scatter(efx);
652 
653 	/* We must keep at least one descriptor in a TX ring empty.
654 	 * We could avoid this when the queue size does not exactly
655 	 * match the hardware ring size, but it's not that important.
656 	 * Therefore we stop the queue when one more skb might fill
657 	 * the ring completely.  We wake it when half way back to
658 	 * empty.
659 	 */
660 	efx->txq_stop_thresh = efx->txq_entries - ef4_tx_max_skb_descs(efx);
661 	efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
662 
663 	/* Initialise the channels */
664 	ef4_for_each_channel(channel, efx) {
665 		ef4_for_each_channel_tx_queue(tx_queue, channel) {
666 			ef4_init_tx_queue(tx_queue);
667 			atomic_inc(&efx->active_queues);
668 		}
669 
670 		ef4_for_each_channel_rx_queue(rx_queue, channel) {
671 			ef4_init_rx_queue(rx_queue);
672 			atomic_inc(&efx->active_queues);
673 			ef4_stop_eventq(channel);
674 			ef4_fast_push_rx_descriptors(rx_queue, false);
675 			ef4_start_eventq(channel);
676 		}
677 
678 		WARN_ON(channel->rx_pkt_n_frags);
679 	}
680 
681 	if (netif_device_present(efx->net_dev))
682 		netif_tx_wake_all_queues(efx->net_dev);
683 }
684 
685 static void ef4_stop_datapath(struct ef4_nic *efx)
686 {
687 	struct ef4_channel *channel;
688 	struct ef4_tx_queue *tx_queue;
689 	struct ef4_rx_queue *rx_queue;
690 	int rc;
691 
692 	EF4_ASSERT_RESET_SERIALISED(efx);
693 	BUG_ON(efx->port_enabled);
694 
695 	/* Stop RX refill */
696 	ef4_for_each_channel(channel, efx) {
697 		ef4_for_each_channel_rx_queue(rx_queue, channel)
698 			rx_queue->refill_enabled = false;
699 	}
700 
701 	ef4_for_each_channel(channel, efx) {
702 		/* RX packet processing is pipelined, so wait for the
703 		 * NAPI handler to complete.  At least event queue 0
704 		 * might be kept active by non-data events, so don't
705 		 * use napi_synchronize() but actually disable NAPI
706 		 * temporarily.
707 		 */
708 		if (ef4_channel_has_rx_queue(channel)) {
709 			ef4_stop_eventq(channel);
710 			ef4_start_eventq(channel);
711 		}
712 	}
713 
714 	rc = efx->type->fini_dmaq(efx);
715 	if (rc && EF4_WORKAROUND_7803(efx)) {
716 		/* Schedule a reset to recover from the flush failure. The
717 		 * descriptor caches reference memory we're about to free,
718 		 * but falcon_reconfigure_mac_wrapper() won't reconnect
719 		 * the MACs because of the pending reset.
720 		 */
721 		netif_err(efx, drv, efx->net_dev,
722 			  "Resetting to recover from flush failure\n");
723 		ef4_schedule_reset(efx, RESET_TYPE_ALL);
724 	} else if (rc) {
725 		netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
726 	} else {
727 		netif_dbg(efx, drv, efx->net_dev,
728 			  "successfully flushed all queues\n");
729 	}
730 
731 	ef4_for_each_channel(channel, efx) {
732 		ef4_for_each_channel_rx_queue(rx_queue, channel)
733 			ef4_fini_rx_queue(rx_queue);
734 		ef4_for_each_possible_channel_tx_queue(tx_queue, channel)
735 			ef4_fini_tx_queue(tx_queue);
736 	}
737 }
738 
739 static void ef4_remove_channel(struct ef4_channel *channel)
740 {
741 	struct ef4_tx_queue *tx_queue;
742 	struct ef4_rx_queue *rx_queue;
743 
744 	netif_dbg(channel->efx, drv, channel->efx->net_dev,
745 		  "destroy chan %d\n", channel->channel);
746 
747 	ef4_for_each_channel_rx_queue(rx_queue, channel)
748 		ef4_remove_rx_queue(rx_queue);
749 	ef4_for_each_possible_channel_tx_queue(tx_queue, channel)
750 		ef4_remove_tx_queue(tx_queue);
751 	ef4_remove_eventq(channel);
752 	channel->type->post_remove(channel);
753 }
754 
755 static void ef4_remove_channels(struct ef4_nic *efx)
756 {
757 	struct ef4_channel *channel;
758 
759 	ef4_for_each_channel(channel, efx)
760 		ef4_remove_channel(channel);
761 }
762 
763 int
764 ef4_realloc_channels(struct ef4_nic *efx, u32 rxq_entries, u32 txq_entries)
765 {
766 	struct ef4_channel *other_channel[EF4_MAX_CHANNELS], *channel;
767 	u32 old_rxq_entries, old_txq_entries;
768 	unsigned i, next_buffer_table = 0;
769 	int rc, rc2;
770 
771 	rc = ef4_check_disabled(efx);
772 	if (rc)
773 		return rc;
774 
775 	/* Not all channels should be reallocated. We must avoid
776 	 * reallocating their buffer table entries.
777 	 */
778 	ef4_for_each_channel(channel, efx) {
779 		struct ef4_rx_queue *rx_queue;
780 		struct ef4_tx_queue *tx_queue;
781 
782 		if (channel->type->copy)
783 			continue;
784 		next_buffer_table = max(next_buffer_table,
785 					channel->eventq.index +
786 					channel->eventq.entries);
787 		ef4_for_each_channel_rx_queue(rx_queue, channel)
788 			next_buffer_table = max(next_buffer_table,
789 						rx_queue->rxd.index +
790 						rx_queue->rxd.entries);
791 		ef4_for_each_channel_tx_queue(tx_queue, channel)
792 			next_buffer_table = max(next_buffer_table,
793 						tx_queue->txd.index +
794 						tx_queue->txd.entries);
795 	}
796 
797 	ef4_device_detach_sync(efx);
798 	ef4_stop_all(efx);
799 	ef4_soft_disable_interrupts(efx);
800 
801 	/* Clone channels (where possible) */
802 	memset(other_channel, 0, sizeof(other_channel));
803 	for (i = 0; i < efx->n_channels; i++) {
804 		channel = efx->channel[i];
805 		if (channel->type->copy)
806 			channel = channel->type->copy(channel);
807 		if (!channel) {
808 			rc = -ENOMEM;
809 			goto out;
810 		}
811 		other_channel[i] = channel;
812 	}
813 
814 	/* Swap entry counts and channel pointers */
815 	old_rxq_entries = efx->rxq_entries;
816 	old_txq_entries = efx->txq_entries;
817 	efx->rxq_entries = rxq_entries;
818 	efx->txq_entries = txq_entries;
819 	for (i = 0; i < efx->n_channels; i++) {
820 		swap(efx->channel[i], other_channel[i]);
821 	}
822 
823 	/* Restart buffer table allocation */
824 	efx->next_buffer_table = next_buffer_table;
825 
826 	for (i = 0; i < efx->n_channels; i++) {
827 		channel = efx->channel[i];
828 		if (!channel->type->copy)
829 			continue;
830 		rc = ef4_probe_channel(channel);
831 		if (rc)
832 			goto rollback;
833 		ef4_init_napi_channel(efx->channel[i]);
834 	}
835 
836 out:
837 	/* Destroy unused channel structures */
838 	for (i = 0; i < efx->n_channels; i++) {
839 		channel = other_channel[i];
840 		if (channel && channel->type->copy) {
841 			ef4_fini_napi_channel(channel);
842 			ef4_remove_channel(channel);
843 			kfree(channel);
844 		}
845 	}
846 
847 	rc2 = ef4_soft_enable_interrupts(efx);
848 	if (rc2) {
849 		rc = rc ? rc : rc2;
850 		netif_err(efx, drv, efx->net_dev,
851 			  "unable to restart interrupts on channel reallocation\n");
852 		ef4_schedule_reset(efx, RESET_TYPE_DISABLE);
853 	} else {
854 		ef4_start_all(efx);
855 		netif_device_attach(efx->net_dev);
856 	}
857 	return rc;
858 
859 rollback:
860 	/* Swap back */
861 	efx->rxq_entries = old_rxq_entries;
862 	efx->txq_entries = old_txq_entries;
863 	for (i = 0; i < efx->n_channels; i++) {
864 		swap(efx->channel[i], other_channel[i]);
865 	}
866 	goto out;
867 }
868 
869 void ef4_schedule_slow_fill(struct ef4_rx_queue *rx_queue)
870 {
871 	mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
872 }
873 
874 static const struct ef4_channel_type ef4_default_channel_type = {
875 	.pre_probe		= ef4_channel_dummy_op_int,
876 	.post_remove		= ef4_channel_dummy_op_void,
877 	.get_name		= ef4_get_channel_name,
878 	.copy			= ef4_copy_channel,
879 	.keep_eventq		= false,
880 };
881 
882 int ef4_channel_dummy_op_int(struct ef4_channel *channel)
883 {
884 	return 0;
885 }
886 
887 void ef4_channel_dummy_op_void(struct ef4_channel *channel)
888 {
889 }
890 
891 /**************************************************************************
892  *
893  * Port handling
894  *
895  **************************************************************************/
896 
897 /* This ensures that the kernel is kept informed (via
898  * netif_carrier_on/off) of the link status, and also maintains the
899  * link status's stop on the port's TX queue.
900  */
901 void ef4_link_status_changed(struct ef4_nic *efx)
902 {
903 	struct ef4_link_state *link_state = &efx->link_state;
904 
905 	/* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
906 	 * that no events are triggered between unregister_netdev() and the
907 	 * driver unloading. A more general condition is that NETDEV_CHANGE
908 	 * can only be generated between NETDEV_UP and NETDEV_DOWN */
909 	if (!netif_running(efx->net_dev))
910 		return;
911 
912 	if (link_state->up != netif_carrier_ok(efx->net_dev)) {
913 		efx->n_link_state_changes++;
914 
915 		if (link_state->up)
916 			netif_carrier_on(efx->net_dev);
917 		else
918 			netif_carrier_off(efx->net_dev);
919 	}
920 
921 	/* Status message for kernel log */
922 	if (link_state->up)
923 		netif_info(efx, link, efx->net_dev,
924 			   "link up at %uMbps %s-duplex (MTU %d)\n",
925 			   link_state->speed, link_state->fd ? "full" : "half",
926 			   efx->net_dev->mtu);
927 	else
928 		netif_info(efx, link, efx->net_dev, "link down\n");
929 }
930 
931 void ef4_link_set_advertising(struct ef4_nic *efx, u32 advertising)
932 {
933 	efx->link_advertising = advertising;
934 	if (advertising) {
935 		if (advertising & ADVERTISED_Pause)
936 			efx->wanted_fc |= (EF4_FC_TX | EF4_FC_RX);
937 		else
938 			efx->wanted_fc &= ~(EF4_FC_TX | EF4_FC_RX);
939 		if (advertising & ADVERTISED_Asym_Pause)
940 			efx->wanted_fc ^= EF4_FC_TX;
941 	}
942 }
943 
944 void ef4_link_set_wanted_fc(struct ef4_nic *efx, u8 wanted_fc)
945 {
946 	efx->wanted_fc = wanted_fc;
947 	if (efx->link_advertising) {
948 		if (wanted_fc & EF4_FC_RX)
949 			efx->link_advertising |= (ADVERTISED_Pause |
950 						  ADVERTISED_Asym_Pause);
951 		else
952 			efx->link_advertising &= ~(ADVERTISED_Pause |
953 						   ADVERTISED_Asym_Pause);
954 		if (wanted_fc & EF4_FC_TX)
955 			efx->link_advertising ^= ADVERTISED_Asym_Pause;
956 	}
957 }
958 
959 static void ef4_fini_port(struct ef4_nic *efx);
960 
961 /* We assume that efx->type->reconfigure_mac will always try to sync RX
962  * filters and therefore needs to read-lock the filter table against freeing
963  */
964 void ef4_mac_reconfigure(struct ef4_nic *efx)
965 {
966 	down_read(&efx->filter_sem);
967 	efx->type->reconfigure_mac(efx);
968 	up_read(&efx->filter_sem);
969 }
970 
971 /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
972  * the MAC appropriately. All other PHY configuration changes are pushed
973  * through phy_op->set_link_ksettings(), and pushed asynchronously to the MAC
974  * through ef4_monitor().
975  *
976  * Callers must hold the mac_lock
977  */
978 int __ef4_reconfigure_port(struct ef4_nic *efx)
979 {
980 	enum ef4_phy_mode phy_mode;
981 	int rc;
982 
983 	WARN_ON(!mutex_is_locked(&efx->mac_lock));
984 
985 	/* Disable PHY transmit in mac level loopbacks */
986 	phy_mode = efx->phy_mode;
987 	if (LOOPBACK_INTERNAL(efx))
988 		efx->phy_mode |= PHY_MODE_TX_DISABLED;
989 	else
990 		efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
991 
992 	rc = efx->type->reconfigure_port(efx);
993 
994 	if (rc)
995 		efx->phy_mode = phy_mode;
996 
997 	return rc;
998 }
999 
1000 /* Reinitialise the MAC to pick up new PHY settings, even if the port is
1001  * disabled. */
1002 int ef4_reconfigure_port(struct ef4_nic *efx)
1003 {
1004 	int rc;
1005 
1006 	EF4_ASSERT_RESET_SERIALISED(efx);
1007 
1008 	mutex_lock(&efx->mac_lock);
1009 	rc = __ef4_reconfigure_port(efx);
1010 	mutex_unlock(&efx->mac_lock);
1011 
1012 	return rc;
1013 }
1014 
1015 /* Asynchronous work item for changing MAC promiscuity and multicast
1016  * hash.  Avoid a drain/rx_ingress enable by reconfiguring the current
1017  * MAC directly. */
1018 static void ef4_mac_work(struct work_struct *data)
1019 {
1020 	struct ef4_nic *efx = container_of(data, struct ef4_nic, mac_work);
1021 
1022 	mutex_lock(&efx->mac_lock);
1023 	if (efx->port_enabled)
1024 		ef4_mac_reconfigure(efx);
1025 	mutex_unlock(&efx->mac_lock);
1026 }
1027 
1028 static int ef4_probe_port(struct ef4_nic *efx)
1029 {
1030 	int rc;
1031 
1032 	netif_dbg(efx, probe, efx->net_dev, "create port\n");
1033 
1034 	if (phy_flash_cfg)
1035 		efx->phy_mode = PHY_MODE_SPECIAL;
1036 
1037 	/* Connect up MAC/PHY operations table */
1038 	rc = efx->type->probe_port(efx);
1039 	if (rc)
1040 		return rc;
1041 
1042 	/* Initialise MAC address to permanent address */
1043 	eth_hw_addr_set(efx->net_dev, efx->net_dev->perm_addr);
1044 
1045 	return 0;
1046 }
1047 
1048 static int ef4_init_port(struct ef4_nic *efx)
1049 {
1050 	int rc;
1051 
1052 	netif_dbg(efx, drv, efx->net_dev, "init port\n");
1053 
1054 	mutex_lock(&efx->mac_lock);
1055 
1056 	rc = efx->phy_op->init(efx);
1057 	if (rc)
1058 		goto fail1;
1059 
1060 	efx->port_initialized = true;
1061 
1062 	/* Reconfigure the MAC before creating dma queues (required for
1063 	 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
1064 	ef4_mac_reconfigure(efx);
1065 
1066 	/* Ensure the PHY advertises the correct flow control settings */
1067 	rc = efx->phy_op->reconfigure(efx);
1068 	if (rc && rc != -EPERM)
1069 		goto fail2;
1070 
1071 	mutex_unlock(&efx->mac_lock);
1072 	return 0;
1073 
1074 fail2:
1075 	efx->phy_op->fini(efx);
1076 fail1:
1077 	mutex_unlock(&efx->mac_lock);
1078 	return rc;
1079 }
1080 
1081 static void ef4_start_port(struct ef4_nic *efx)
1082 {
1083 	netif_dbg(efx, ifup, efx->net_dev, "start port\n");
1084 	BUG_ON(efx->port_enabled);
1085 
1086 	mutex_lock(&efx->mac_lock);
1087 	efx->port_enabled = true;
1088 
1089 	/* Ensure MAC ingress/egress is enabled */
1090 	ef4_mac_reconfigure(efx);
1091 
1092 	mutex_unlock(&efx->mac_lock);
1093 }
1094 
1095 /* Cancel work for MAC reconfiguration, periodic hardware monitoring
1096  * and the async self-test, wait for them to finish and prevent them
1097  * being scheduled again.  This doesn't cover online resets, which
1098  * should only be cancelled when removing the device.
1099  */
1100 static void ef4_stop_port(struct ef4_nic *efx)
1101 {
1102 	netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
1103 
1104 	EF4_ASSERT_RESET_SERIALISED(efx);
1105 
1106 	mutex_lock(&efx->mac_lock);
1107 	efx->port_enabled = false;
1108 	mutex_unlock(&efx->mac_lock);
1109 
1110 	/* Serialise against ef4_set_multicast_list() */
1111 	netif_addr_lock_bh(efx->net_dev);
1112 	netif_addr_unlock_bh(efx->net_dev);
1113 
1114 	cancel_delayed_work_sync(&efx->monitor_work);
1115 	ef4_selftest_async_cancel(efx);
1116 	cancel_work_sync(&efx->mac_work);
1117 }
1118 
1119 static void ef4_fini_port(struct ef4_nic *efx)
1120 {
1121 	netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
1122 
1123 	if (!efx->port_initialized)
1124 		return;
1125 
1126 	efx->phy_op->fini(efx);
1127 	efx->port_initialized = false;
1128 
1129 	efx->link_state.up = false;
1130 	ef4_link_status_changed(efx);
1131 }
1132 
1133 static void ef4_remove_port(struct ef4_nic *efx)
1134 {
1135 	netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
1136 
1137 	efx->type->remove_port(efx);
1138 }
1139 
1140 /**************************************************************************
1141  *
1142  * NIC handling
1143  *
1144  **************************************************************************/
1145 
1146 static LIST_HEAD(ef4_primary_list);
1147 static LIST_HEAD(ef4_unassociated_list);
1148 
1149 static bool ef4_same_controller(struct ef4_nic *left, struct ef4_nic *right)
1150 {
1151 	return left->type == right->type &&
1152 		left->vpd_sn && right->vpd_sn &&
1153 		!strcmp(left->vpd_sn, right->vpd_sn);
1154 }
1155 
1156 static void ef4_associate(struct ef4_nic *efx)
1157 {
1158 	struct ef4_nic *other, *next;
1159 
1160 	if (efx->primary == efx) {
1161 		/* Adding primary function; look for secondaries */
1162 
1163 		netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
1164 		list_add_tail(&efx->node, &ef4_primary_list);
1165 
1166 		list_for_each_entry_safe(other, next, &ef4_unassociated_list,
1167 					 node) {
1168 			if (ef4_same_controller(efx, other)) {
1169 				list_del(&other->node);
1170 				netif_dbg(other, probe, other->net_dev,
1171 					  "moving to secondary list of %s %s\n",
1172 					  pci_name(efx->pci_dev),
1173 					  efx->net_dev->name);
1174 				list_add_tail(&other->node,
1175 					      &efx->secondary_list);
1176 				other->primary = efx;
1177 			}
1178 		}
1179 	} else {
1180 		/* Adding secondary function; look for primary */
1181 
1182 		list_for_each_entry(other, &ef4_primary_list, node) {
1183 			if (ef4_same_controller(efx, other)) {
1184 				netif_dbg(efx, probe, efx->net_dev,
1185 					  "adding to secondary list of %s %s\n",
1186 					  pci_name(other->pci_dev),
1187 					  other->net_dev->name);
1188 				list_add_tail(&efx->node,
1189 					      &other->secondary_list);
1190 				efx->primary = other;
1191 				return;
1192 			}
1193 		}
1194 
1195 		netif_dbg(efx, probe, efx->net_dev,
1196 			  "adding to unassociated list\n");
1197 		list_add_tail(&efx->node, &ef4_unassociated_list);
1198 	}
1199 }
1200 
1201 static void ef4_dissociate(struct ef4_nic *efx)
1202 {
1203 	struct ef4_nic *other, *next;
1204 
1205 	list_del(&efx->node);
1206 	efx->primary = NULL;
1207 
1208 	list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
1209 		list_del(&other->node);
1210 		netif_dbg(other, probe, other->net_dev,
1211 			  "moving to unassociated list\n");
1212 		list_add_tail(&other->node, &ef4_unassociated_list);
1213 		other->primary = NULL;
1214 	}
1215 }
1216 
1217 /* This configures the PCI device to enable I/O and DMA. */
1218 static int ef4_init_io(struct ef4_nic *efx)
1219 {
1220 	struct pci_dev *pci_dev = efx->pci_dev;
1221 	dma_addr_t dma_mask = efx->type->max_dma_mask;
1222 	unsigned int mem_map_size = efx->type->mem_map_size(efx);
1223 	int rc, bar;
1224 
1225 	netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
1226 
1227 	bar = efx->type->mem_bar;
1228 
1229 	rc = pci_enable_device(pci_dev);
1230 	if (rc) {
1231 		netif_err(efx, probe, efx->net_dev,
1232 			  "failed to enable PCI device\n");
1233 		goto fail1;
1234 	}
1235 
1236 	pci_set_master(pci_dev);
1237 
1238 	/* Set the PCI DMA mask.  Try all possibilities from our genuine mask
1239 	 * down to 32 bits, because some architectures will allow 40 bit
1240 	 * masks event though they reject 46 bit masks.
1241 	 */
1242 	while (dma_mask > 0x7fffffffUL) {
1243 		rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
1244 		if (rc == 0)
1245 			break;
1246 		dma_mask >>= 1;
1247 	}
1248 	if (rc) {
1249 		netif_err(efx, probe, efx->net_dev,
1250 			  "could not find a suitable DMA mask\n");
1251 		goto fail2;
1252 	}
1253 	netif_dbg(efx, probe, efx->net_dev,
1254 		  "using DMA mask %llx\n", (unsigned long long) dma_mask);
1255 
1256 	efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
1257 	rc = pci_request_region(pci_dev, bar, "sfc");
1258 	if (rc) {
1259 		netif_err(efx, probe, efx->net_dev,
1260 			  "request for memory BAR failed\n");
1261 		rc = -EIO;
1262 		goto fail3;
1263 	}
1264 	efx->membase = ioremap(efx->membase_phys, mem_map_size);
1265 	if (!efx->membase) {
1266 		netif_err(efx, probe, efx->net_dev,
1267 			  "could not map memory BAR at %llx+%x\n",
1268 			  (unsigned long long)efx->membase_phys, mem_map_size);
1269 		rc = -ENOMEM;
1270 		goto fail4;
1271 	}
1272 	netif_dbg(efx, probe, efx->net_dev,
1273 		  "memory BAR at %llx+%x (virtual %p)\n",
1274 		  (unsigned long long)efx->membase_phys, mem_map_size,
1275 		  efx->membase);
1276 
1277 	return 0;
1278 
1279  fail4:
1280 	pci_release_region(efx->pci_dev, bar);
1281  fail3:
1282 	efx->membase_phys = 0;
1283  fail2:
1284 	pci_disable_device(efx->pci_dev);
1285  fail1:
1286 	return rc;
1287 }
1288 
1289 static void ef4_fini_io(struct ef4_nic *efx)
1290 {
1291 	int bar;
1292 
1293 	netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
1294 
1295 	if (efx->membase) {
1296 		iounmap(efx->membase);
1297 		efx->membase = NULL;
1298 	}
1299 
1300 	if (efx->membase_phys) {
1301 		bar = efx->type->mem_bar;
1302 		pci_release_region(efx->pci_dev, bar);
1303 		efx->membase_phys = 0;
1304 	}
1305 
1306 	/* Don't disable bus-mastering if VFs are assigned */
1307 	if (!pci_vfs_assigned(efx->pci_dev))
1308 		pci_disable_device(efx->pci_dev);
1309 }
1310 
1311 void ef4_set_default_rx_indir_table(struct ef4_nic *efx)
1312 {
1313 	size_t i;
1314 
1315 	for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
1316 		efx->rx_indir_table[i] =
1317 			ethtool_rxfh_indir_default(i, efx->rss_spread);
1318 }
1319 
1320 static unsigned int ef4_wanted_parallelism(struct ef4_nic *efx)
1321 {
1322 	cpumask_var_t thread_mask;
1323 	unsigned int count;
1324 	int cpu;
1325 
1326 	if (rss_cpus) {
1327 		count = rss_cpus;
1328 	} else {
1329 		if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
1330 			netif_warn(efx, probe, efx->net_dev,
1331 				   "RSS disabled due to allocation failure\n");
1332 			return 1;
1333 		}
1334 
1335 		count = 0;
1336 		for_each_online_cpu(cpu) {
1337 			if (!cpumask_test_cpu(cpu, thread_mask)) {
1338 				++count;
1339 				cpumask_or(thread_mask, thread_mask,
1340 					   topology_sibling_cpumask(cpu));
1341 			}
1342 		}
1343 
1344 		free_cpumask_var(thread_mask);
1345 	}
1346 
1347 	if (count > EF4_MAX_RX_QUEUES) {
1348 		netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1349 			       "Reducing number of rx queues from %u to %u.\n",
1350 			       count, EF4_MAX_RX_QUEUES);
1351 		count = EF4_MAX_RX_QUEUES;
1352 	}
1353 
1354 	return count;
1355 }
1356 
1357 /* Probe the number and type of interrupts we are able to obtain, and
1358  * the resulting numbers of channels and RX queues.
1359  */
1360 static int ef4_probe_interrupts(struct ef4_nic *efx)
1361 {
1362 	unsigned int extra_channels = 0;
1363 	unsigned int i, j;
1364 	int rc;
1365 
1366 	for (i = 0; i < EF4_MAX_EXTRA_CHANNELS; i++)
1367 		if (efx->extra_channel_type[i])
1368 			++extra_channels;
1369 
1370 	if (efx->interrupt_mode == EF4_INT_MODE_MSIX) {
1371 		struct msix_entry xentries[EF4_MAX_CHANNELS];
1372 		unsigned int n_channels;
1373 
1374 		n_channels = ef4_wanted_parallelism(efx);
1375 		if (ef4_separate_tx_channels)
1376 			n_channels *= 2;
1377 		n_channels += extra_channels;
1378 		n_channels = min(n_channels, efx->max_channels);
1379 
1380 		for (i = 0; i < n_channels; i++)
1381 			xentries[i].entry = i;
1382 		rc = pci_enable_msix_range(efx->pci_dev,
1383 					   xentries, 1, n_channels);
1384 		if (rc < 0) {
1385 			/* Fall back to single channel MSI */
1386 			efx->interrupt_mode = EF4_INT_MODE_MSI;
1387 			netif_err(efx, drv, efx->net_dev,
1388 				  "could not enable MSI-X\n");
1389 		} else if (rc < n_channels) {
1390 			netif_err(efx, drv, efx->net_dev,
1391 				  "WARNING: Insufficient MSI-X vectors"
1392 				  " available (%d < %u).\n", rc, n_channels);
1393 			netif_err(efx, drv, efx->net_dev,
1394 				  "WARNING: Performance may be reduced.\n");
1395 			n_channels = rc;
1396 		}
1397 
1398 		if (rc > 0) {
1399 			efx->n_channels = n_channels;
1400 			if (n_channels > extra_channels)
1401 				n_channels -= extra_channels;
1402 			if (ef4_separate_tx_channels) {
1403 				efx->n_tx_channels = min(max(n_channels / 2,
1404 							     1U),
1405 							 efx->max_tx_channels);
1406 				efx->n_rx_channels = max(n_channels -
1407 							 efx->n_tx_channels,
1408 							 1U);
1409 			} else {
1410 				efx->n_tx_channels = min(n_channels,
1411 							 efx->max_tx_channels);
1412 				efx->n_rx_channels = n_channels;
1413 			}
1414 			for (i = 0; i < efx->n_channels; i++)
1415 				ef4_get_channel(efx, i)->irq =
1416 					xentries[i].vector;
1417 		}
1418 	}
1419 
1420 	/* Try single interrupt MSI */
1421 	if (efx->interrupt_mode == EF4_INT_MODE_MSI) {
1422 		efx->n_channels = 1;
1423 		efx->n_rx_channels = 1;
1424 		efx->n_tx_channels = 1;
1425 		rc = pci_enable_msi(efx->pci_dev);
1426 		if (rc == 0) {
1427 			ef4_get_channel(efx, 0)->irq = efx->pci_dev->irq;
1428 		} else {
1429 			netif_err(efx, drv, efx->net_dev,
1430 				  "could not enable MSI\n");
1431 			efx->interrupt_mode = EF4_INT_MODE_LEGACY;
1432 		}
1433 	}
1434 
1435 	/* Assume legacy interrupts */
1436 	if (efx->interrupt_mode == EF4_INT_MODE_LEGACY) {
1437 		efx->n_channels = 1 + (ef4_separate_tx_channels ? 1 : 0);
1438 		efx->n_rx_channels = 1;
1439 		efx->n_tx_channels = 1;
1440 		efx->legacy_irq = efx->pci_dev->irq;
1441 	}
1442 
1443 	/* Assign extra channels if possible */
1444 	j = efx->n_channels;
1445 	for (i = 0; i < EF4_MAX_EXTRA_CHANNELS; i++) {
1446 		if (!efx->extra_channel_type[i])
1447 			continue;
1448 		if (efx->interrupt_mode != EF4_INT_MODE_MSIX ||
1449 		    efx->n_channels <= extra_channels) {
1450 			efx->extra_channel_type[i]->handle_no_channel(efx);
1451 		} else {
1452 			--j;
1453 			ef4_get_channel(efx, j)->type =
1454 				efx->extra_channel_type[i];
1455 		}
1456 	}
1457 
1458 	efx->rss_spread = efx->n_rx_channels;
1459 
1460 	return 0;
1461 }
1462 
1463 static int ef4_soft_enable_interrupts(struct ef4_nic *efx)
1464 {
1465 	struct ef4_channel *channel, *end_channel;
1466 	int rc;
1467 
1468 	BUG_ON(efx->state == STATE_DISABLED);
1469 
1470 	efx->irq_soft_enabled = true;
1471 	smp_wmb();
1472 
1473 	ef4_for_each_channel(channel, efx) {
1474 		if (!channel->type->keep_eventq) {
1475 			rc = ef4_init_eventq(channel);
1476 			if (rc)
1477 				goto fail;
1478 		}
1479 		ef4_start_eventq(channel);
1480 	}
1481 
1482 	return 0;
1483 fail:
1484 	end_channel = channel;
1485 	ef4_for_each_channel(channel, efx) {
1486 		if (channel == end_channel)
1487 			break;
1488 		ef4_stop_eventq(channel);
1489 		if (!channel->type->keep_eventq)
1490 			ef4_fini_eventq(channel);
1491 	}
1492 
1493 	return rc;
1494 }
1495 
1496 static void ef4_soft_disable_interrupts(struct ef4_nic *efx)
1497 {
1498 	struct ef4_channel *channel;
1499 
1500 	if (efx->state == STATE_DISABLED)
1501 		return;
1502 
1503 	efx->irq_soft_enabled = false;
1504 	smp_wmb();
1505 
1506 	if (efx->legacy_irq)
1507 		synchronize_irq(efx->legacy_irq);
1508 
1509 	ef4_for_each_channel(channel, efx) {
1510 		if (channel->irq)
1511 			synchronize_irq(channel->irq);
1512 
1513 		ef4_stop_eventq(channel);
1514 		if (!channel->type->keep_eventq)
1515 			ef4_fini_eventq(channel);
1516 	}
1517 }
1518 
1519 static int ef4_enable_interrupts(struct ef4_nic *efx)
1520 {
1521 	struct ef4_channel *channel, *end_channel;
1522 	int rc;
1523 
1524 	BUG_ON(efx->state == STATE_DISABLED);
1525 
1526 	if (efx->eeh_disabled_legacy_irq) {
1527 		enable_irq(efx->legacy_irq);
1528 		efx->eeh_disabled_legacy_irq = false;
1529 	}
1530 
1531 	efx->type->irq_enable_master(efx);
1532 
1533 	ef4_for_each_channel(channel, efx) {
1534 		if (channel->type->keep_eventq) {
1535 			rc = ef4_init_eventq(channel);
1536 			if (rc)
1537 				goto fail;
1538 		}
1539 	}
1540 
1541 	rc = ef4_soft_enable_interrupts(efx);
1542 	if (rc)
1543 		goto fail;
1544 
1545 	return 0;
1546 
1547 fail:
1548 	end_channel = channel;
1549 	ef4_for_each_channel(channel, efx) {
1550 		if (channel == end_channel)
1551 			break;
1552 		if (channel->type->keep_eventq)
1553 			ef4_fini_eventq(channel);
1554 	}
1555 
1556 	efx->type->irq_disable_non_ev(efx);
1557 
1558 	return rc;
1559 }
1560 
1561 static void ef4_disable_interrupts(struct ef4_nic *efx)
1562 {
1563 	struct ef4_channel *channel;
1564 
1565 	ef4_soft_disable_interrupts(efx);
1566 
1567 	ef4_for_each_channel(channel, efx) {
1568 		if (channel->type->keep_eventq)
1569 			ef4_fini_eventq(channel);
1570 	}
1571 
1572 	efx->type->irq_disable_non_ev(efx);
1573 }
1574 
1575 static void ef4_remove_interrupts(struct ef4_nic *efx)
1576 {
1577 	struct ef4_channel *channel;
1578 
1579 	/* Remove MSI/MSI-X interrupts */
1580 	ef4_for_each_channel(channel, efx)
1581 		channel->irq = 0;
1582 	pci_disable_msi(efx->pci_dev);
1583 	pci_disable_msix(efx->pci_dev);
1584 
1585 	/* Remove legacy interrupt */
1586 	efx->legacy_irq = 0;
1587 }
1588 
1589 static void ef4_set_channels(struct ef4_nic *efx)
1590 {
1591 	struct ef4_channel *channel;
1592 	struct ef4_tx_queue *tx_queue;
1593 
1594 	efx->tx_channel_offset =
1595 		ef4_separate_tx_channels ?
1596 		efx->n_channels - efx->n_tx_channels : 0;
1597 
1598 	/* We need to mark which channels really have RX and TX
1599 	 * queues, and adjust the TX queue numbers if we have separate
1600 	 * RX-only and TX-only channels.
1601 	 */
1602 	ef4_for_each_channel(channel, efx) {
1603 		if (channel->channel < efx->n_rx_channels)
1604 			channel->rx_queue.core_index = channel->channel;
1605 		else
1606 			channel->rx_queue.core_index = -1;
1607 
1608 		ef4_for_each_channel_tx_queue(tx_queue, channel)
1609 			tx_queue->queue -= (efx->tx_channel_offset *
1610 					    EF4_TXQ_TYPES);
1611 	}
1612 }
1613 
1614 static int ef4_probe_nic(struct ef4_nic *efx)
1615 {
1616 	int rc;
1617 
1618 	netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
1619 
1620 	/* Carry out hardware-type specific initialisation */
1621 	rc = efx->type->probe(efx);
1622 	if (rc)
1623 		return rc;
1624 
1625 	do {
1626 		if (!efx->max_channels || !efx->max_tx_channels) {
1627 			netif_err(efx, drv, efx->net_dev,
1628 				  "Insufficient resources to allocate"
1629 				  " any channels\n");
1630 			rc = -ENOSPC;
1631 			goto fail1;
1632 		}
1633 
1634 		/* Determine the number of channels and queues by trying
1635 		 * to hook in MSI-X interrupts.
1636 		 */
1637 		rc = ef4_probe_interrupts(efx);
1638 		if (rc)
1639 			goto fail1;
1640 
1641 		ef4_set_channels(efx);
1642 
1643 		/* dimension_resources can fail with EAGAIN */
1644 		rc = efx->type->dimension_resources(efx);
1645 		if (rc != 0 && rc != -EAGAIN)
1646 			goto fail2;
1647 
1648 		if (rc == -EAGAIN)
1649 			/* try again with new max_channels */
1650 			ef4_remove_interrupts(efx);
1651 
1652 	} while (rc == -EAGAIN);
1653 
1654 	if (efx->n_channels > 1)
1655 		netdev_rss_key_fill(&efx->rx_hash_key,
1656 				    sizeof(efx->rx_hash_key));
1657 	ef4_set_default_rx_indir_table(efx);
1658 
1659 	netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
1660 	netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
1661 
1662 	/* Initialise the interrupt moderation settings */
1663 	efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
1664 	ef4_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
1665 				true);
1666 
1667 	return 0;
1668 
1669 fail2:
1670 	ef4_remove_interrupts(efx);
1671 fail1:
1672 	efx->type->remove(efx);
1673 	return rc;
1674 }
1675 
1676 static void ef4_remove_nic(struct ef4_nic *efx)
1677 {
1678 	netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
1679 
1680 	ef4_remove_interrupts(efx);
1681 	efx->type->remove(efx);
1682 }
1683 
1684 static int ef4_probe_filters(struct ef4_nic *efx)
1685 {
1686 	int rc;
1687 
1688 	spin_lock_init(&efx->filter_lock);
1689 	init_rwsem(&efx->filter_sem);
1690 	mutex_lock(&efx->mac_lock);
1691 	down_write(&efx->filter_sem);
1692 	rc = efx->type->filter_table_probe(efx);
1693 	if (rc)
1694 		goto out_unlock;
1695 
1696 #ifdef CONFIG_RFS_ACCEL
1697 	if (efx->type->offload_features & NETIF_F_NTUPLE) {
1698 		struct ef4_channel *channel;
1699 		int i, success = 1;
1700 
1701 		ef4_for_each_channel(channel, efx) {
1702 			channel->rps_flow_id =
1703 				kcalloc(efx->type->max_rx_ip_filters,
1704 					sizeof(*channel->rps_flow_id),
1705 					GFP_KERNEL);
1706 			if (!channel->rps_flow_id)
1707 				success = 0;
1708 			else
1709 				for (i = 0;
1710 				     i < efx->type->max_rx_ip_filters;
1711 				     ++i)
1712 					channel->rps_flow_id[i] =
1713 						RPS_FLOW_ID_INVALID;
1714 		}
1715 
1716 		if (!success) {
1717 			ef4_for_each_channel(channel, efx)
1718 				kfree(channel->rps_flow_id);
1719 			efx->type->filter_table_remove(efx);
1720 			rc = -ENOMEM;
1721 			goto out_unlock;
1722 		}
1723 
1724 		efx->rps_expire_index = efx->rps_expire_channel = 0;
1725 	}
1726 #endif
1727 out_unlock:
1728 	up_write(&efx->filter_sem);
1729 	mutex_unlock(&efx->mac_lock);
1730 	return rc;
1731 }
1732 
1733 static void ef4_remove_filters(struct ef4_nic *efx)
1734 {
1735 #ifdef CONFIG_RFS_ACCEL
1736 	struct ef4_channel *channel;
1737 
1738 	ef4_for_each_channel(channel, efx)
1739 		kfree(channel->rps_flow_id);
1740 #endif
1741 	down_write(&efx->filter_sem);
1742 	efx->type->filter_table_remove(efx);
1743 	up_write(&efx->filter_sem);
1744 }
1745 
1746 static void ef4_restore_filters(struct ef4_nic *efx)
1747 {
1748 	down_read(&efx->filter_sem);
1749 	efx->type->filter_table_restore(efx);
1750 	up_read(&efx->filter_sem);
1751 }
1752 
1753 /**************************************************************************
1754  *
1755  * NIC startup/shutdown
1756  *
1757  *************************************************************************/
1758 
1759 static int ef4_probe_all(struct ef4_nic *efx)
1760 {
1761 	int rc;
1762 
1763 	rc = ef4_probe_nic(efx);
1764 	if (rc) {
1765 		netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
1766 		goto fail1;
1767 	}
1768 
1769 	rc = ef4_probe_port(efx);
1770 	if (rc) {
1771 		netif_err(efx, probe, efx->net_dev, "failed to create port\n");
1772 		goto fail2;
1773 	}
1774 
1775 	BUILD_BUG_ON(EF4_DEFAULT_DMAQ_SIZE < EF4_RXQ_MIN_ENT);
1776 	if (WARN_ON(EF4_DEFAULT_DMAQ_SIZE < EF4_TXQ_MIN_ENT(efx))) {
1777 		rc = -EINVAL;
1778 		goto fail3;
1779 	}
1780 	efx->rxq_entries = efx->txq_entries = EF4_DEFAULT_DMAQ_SIZE;
1781 
1782 	rc = ef4_probe_filters(efx);
1783 	if (rc) {
1784 		netif_err(efx, probe, efx->net_dev,
1785 			  "failed to create filter tables\n");
1786 		goto fail4;
1787 	}
1788 
1789 	rc = ef4_probe_channels(efx);
1790 	if (rc)
1791 		goto fail5;
1792 
1793 	return 0;
1794 
1795  fail5:
1796 	ef4_remove_filters(efx);
1797  fail4:
1798  fail3:
1799 	ef4_remove_port(efx);
1800  fail2:
1801 	ef4_remove_nic(efx);
1802  fail1:
1803 	return rc;
1804 }
1805 
1806 /* If the interface is supposed to be running but is not, start
1807  * the hardware and software data path, regular activity for the port
1808  * (MAC statistics, link polling, etc.) and schedule the port to be
1809  * reconfigured.  Interrupts must already be enabled.  This function
1810  * is safe to call multiple times, so long as the NIC is not disabled.
1811  * Requires the RTNL lock.
1812  */
1813 static void ef4_start_all(struct ef4_nic *efx)
1814 {
1815 	EF4_ASSERT_RESET_SERIALISED(efx);
1816 	BUG_ON(efx->state == STATE_DISABLED);
1817 
1818 	/* Check that it is appropriate to restart the interface. All
1819 	 * of these flags are safe to read under just the rtnl lock */
1820 	if (efx->port_enabled || !netif_running(efx->net_dev) ||
1821 	    efx->reset_pending)
1822 		return;
1823 
1824 	ef4_start_port(efx);
1825 	ef4_start_datapath(efx);
1826 
1827 	/* Start the hardware monitor if there is one */
1828 	if (efx->type->monitor != NULL)
1829 		queue_delayed_work(efx->workqueue, &efx->monitor_work,
1830 				   ef4_monitor_interval);
1831 
1832 	efx->type->start_stats(efx);
1833 	efx->type->pull_stats(efx);
1834 	spin_lock_bh(&efx->stats_lock);
1835 	efx->type->update_stats(efx, NULL, NULL);
1836 	spin_unlock_bh(&efx->stats_lock);
1837 }
1838 
1839 /* Quiesce the hardware and software data path, and regular activity
1840  * for the port without bringing the link down.  Safe to call multiple
1841  * times with the NIC in almost any state, but interrupts should be
1842  * enabled.  Requires the RTNL lock.
1843  */
1844 static void ef4_stop_all(struct ef4_nic *efx)
1845 {
1846 	EF4_ASSERT_RESET_SERIALISED(efx);
1847 
1848 	/* port_enabled can be read safely under the rtnl lock */
1849 	if (!efx->port_enabled)
1850 		return;
1851 
1852 	/* update stats before we go down so we can accurately count
1853 	 * rx_nodesc_drops
1854 	 */
1855 	efx->type->pull_stats(efx);
1856 	spin_lock_bh(&efx->stats_lock);
1857 	efx->type->update_stats(efx, NULL, NULL);
1858 	spin_unlock_bh(&efx->stats_lock);
1859 	efx->type->stop_stats(efx);
1860 	ef4_stop_port(efx);
1861 
1862 	/* Stop the kernel transmit interface.  This is only valid if
1863 	 * the device is stopped or detached; otherwise the watchdog
1864 	 * may fire immediately.
1865 	 */
1866 	WARN_ON(netif_running(efx->net_dev) &&
1867 		netif_device_present(efx->net_dev));
1868 	netif_tx_disable(efx->net_dev);
1869 
1870 	ef4_stop_datapath(efx);
1871 }
1872 
1873 static void ef4_remove_all(struct ef4_nic *efx)
1874 {
1875 	ef4_remove_channels(efx);
1876 	ef4_remove_filters(efx);
1877 	ef4_remove_port(efx);
1878 	ef4_remove_nic(efx);
1879 }
1880 
1881 /**************************************************************************
1882  *
1883  * Interrupt moderation
1884  *
1885  **************************************************************************/
1886 unsigned int ef4_usecs_to_ticks(struct ef4_nic *efx, unsigned int usecs)
1887 {
1888 	if (usecs == 0)
1889 		return 0;
1890 	if (usecs * 1000 < efx->timer_quantum_ns)
1891 		return 1; /* never round down to 0 */
1892 	return usecs * 1000 / efx->timer_quantum_ns;
1893 }
1894 
1895 unsigned int ef4_ticks_to_usecs(struct ef4_nic *efx, unsigned int ticks)
1896 {
1897 	/* We must round up when converting ticks to microseconds
1898 	 * because we round down when converting the other way.
1899 	 */
1900 	return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
1901 }
1902 
1903 /* Set interrupt moderation parameters */
1904 int ef4_init_irq_moderation(struct ef4_nic *efx, unsigned int tx_usecs,
1905 			    unsigned int rx_usecs, bool rx_adaptive,
1906 			    bool rx_may_override_tx)
1907 {
1908 	struct ef4_channel *channel;
1909 	unsigned int timer_max_us;
1910 
1911 	EF4_ASSERT_RESET_SERIALISED(efx);
1912 
1913 	timer_max_us = efx->timer_max_ns / 1000;
1914 
1915 	if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
1916 		return -EINVAL;
1917 
1918 	if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
1919 	    !rx_may_override_tx) {
1920 		netif_err(efx, drv, efx->net_dev, "Channels are shared. "
1921 			  "RX and TX IRQ moderation must be equal\n");
1922 		return -EINVAL;
1923 	}
1924 
1925 	efx->irq_rx_adaptive = rx_adaptive;
1926 	efx->irq_rx_moderation_us = rx_usecs;
1927 	ef4_for_each_channel(channel, efx) {
1928 		if (ef4_channel_has_rx_queue(channel))
1929 			channel->irq_moderation_us = rx_usecs;
1930 		else if (ef4_channel_has_tx_queues(channel))
1931 			channel->irq_moderation_us = tx_usecs;
1932 	}
1933 
1934 	return 0;
1935 }
1936 
1937 void ef4_get_irq_moderation(struct ef4_nic *efx, unsigned int *tx_usecs,
1938 			    unsigned int *rx_usecs, bool *rx_adaptive)
1939 {
1940 	*rx_adaptive = efx->irq_rx_adaptive;
1941 	*rx_usecs = efx->irq_rx_moderation_us;
1942 
1943 	/* If channels are shared between RX and TX, so is IRQ
1944 	 * moderation.  Otherwise, IRQ moderation is the same for all
1945 	 * TX channels and is not adaptive.
1946 	 */
1947 	if (efx->tx_channel_offset == 0) {
1948 		*tx_usecs = *rx_usecs;
1949 	} else {
1950 		struct ef4_channel *tx_channel;
1951 
1952 		tx_channel = efx->channel[efx->tx_channel_offset];
1953 		*tx_usecs = tx_channel->irq_moderation_us;
1954 	}
1955 }
1956 
1957 /**************************************************************************
1958  *
1959  * Hardware monitor
1960  *
1961  **************************************************************************/
1962 
1963 /* Run periodically off the general workqueue */
1964 static void ef4_monitor(struct work_struct *data)
1965 {
1966 	struct ef4_nic *efx = container_of(data, struct ef4_nic,
1967 					   monitor_work.work);
1968 
1969 	netif_vdbg(efx, timer, efx->net_dev,
1970 		   "hardware monitor executing on CPU %d\n",
1971 		   raw_smp_processor_id());
1972 	BUG_ON(efx->type->monitor == NULL);
1973 
1974 	/* If the mac_lock is already held then it is likely a port
1975 	 * reconfiguration is already in place, which will likely do
1976 	 * most of the work of monitor() anyway. */
1977 	if (mutex_trylock(&efx->mac_lock)) {
1978 		if (efx->port_enabled)
1979 			efx->type->monitor(efx);
1980 		mutex_unlock(&efx->mac_lock);
1981 	}
1982 
1983 	queue_delayed_work(efx->workqueue, &efx->monitor_work,
1984 			   ef4_monitor_interval);
1985 }
1986 
1987 /**************************************************************************
1988  *
1989  * ioctls
1990  *
1991  *************************************************************************/
1992 
1993 /* Net device ioctl
1994  * Context: process, rtnl_lock() held.
1995  */
1996 static int ef4_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1997 {
1998 	struct ef4_nic *efx = netdev_priv(net_dev);
1999 	struct mii_ioctl_data *data = if_mii(ifr);
2000 
2001 	/* Convert phy_id from older PRTAD/DEVAD format */
2002 	if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
2003 	    (data->phy_id & 0xfc00) == 0x0400)
2004 		data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
2005 
2006 	return mdio_mii_ioctl(&efx->mdio, data, cmd);
2007 }
2008 
2009 /**************************************************************************
2010  *
2011  * NAPI interface
2012  *
2013  **************************************************************************/
2014 
2015 static void ef4_init_napi_channel(struct ef4_channel *channel)
2016 {
2017 	struct ef4_nic *efx = channel->efx;
2018 
2019 	channel->napi_dev = efx->net_dev;
2020 	netif_napi_add(channel->napi_dev, &channel->napi_str,
2021 		       ef4_poll, napi_weight);
2022 }
2023 
2024 static void ef4_init_napi(struct ef4_nic *efx)
2025 {
2026 	struct ef4_channel *channel;
2027 
2028 	ef4_for_each_channel(channel, efx)
2029 		ef4_init_napi_channel(channel);
2030 }
2031 
2032 static void ef4_fini_napi_channel(struct ef4_channel *channel)
2033 {
2034 	if (channel->napi_dev)
2035 		netif_napi_del(&channel->napi_str);
2036 
2037 	channel->napi_dev = NULL;
2038 }
2039 
2040 static void ef4_fini_napi(struct ef4_nic *efx)
2041 {
2042 	struct ef4_channel *channel;
2043 
2044 	ef4_for_each_channel(channel, efx)
2045 		ef4_fini_napi_channel(channel);
2046 }
2047 
2048 /**************************************************************************
2049  *
2050  * Kernel net device interface
2051  *
2052  *************************************************************************/
2053 
2054 /* Context: process, rtnl_lock() held. */
2055 int ef4_net_open(struct net_device *net_dev)
2056 {
2057 	struct ef4_nic *efx = netdev_priv(net_dev);
2058 	int rc;
2059 
2060 	netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
2061 		  raw_smp_processor_id());
2062 
2063 	rc = ef4_check_disabled(efx);
2064 	if (rc)
2065 		return rc;
2066 	if (efx->phy_mode & PHY_MODE_SPECIAL)
2067 		return -EBUSY;
2068 
2069 	/* Notify the kernel of the link state polled during driver load,
2070 	 * before the monitor starts running */
2071 	ef4_link_status_changed(efx);
2072 
2073 	ef4_start_all(efx);
2074 	ef4_selftest_async_start(efx);
2075 	return 0;
2076 }
2077 
2078 /* Context: process, rtnl_lock() held.
2079  * Note that the kernel will ignore our return code; this method
2080  * should really be a void.
2081  */
2082 int ef4_net_stop(struct net_device *net_dev)
2083 {
2084 	struct ef4_nic *efx = netdev_priv(net_dev);
2085 
2086 	netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
2087 		  raw_smp_processor_id());
2088 
2089 	/* Stop the device and flush all the channels */
2090 	ef4_stop_all(efx);
2091 
2092 	return 0;
2093 }
2094 
2095 /* Context: process, dev_base_lock or RTNL held, non-blocking. */
2096 static void ef4_net_stats(struct net_device *net_dev,
2097 			  struct rtnl_link_stats64 *stats)
2098 {
2099 	struct ef4_nic *efx = netdev_priv(net_dev);
2100 
2101 	spin_lock_bh(&efx->stats_lock);
2102 	efx->type->update_stats(efx, NULL, stats);
2103 	spin_unlock_bh(&efx->stats_lock);
2104 }
2105 
2106 /* Context: netif_tx_lock held, BHs disabled. */
2107 static void ef4_watchdog(struct net_device *net_dev, unsigned int txqueue)
2108 {
2109 	struct ef4_nic *efx = netdev_priv(net_dev);
2110 
2111 	netif_err(efx, tx_err, efx->net_dev,
2112 		  "TX stuck with port_enabled=%d: resetting channels\n",
2113 		  efx->port_enabled);
2114 
2115 	ef4_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
2116 }
2117 
2118 
2119 /* Context: process, rtnl_lock() held. */
2120 static int ef4_change_mtu(struct net_device *net_dev, int new_mtu)
2121 {
2122 	struct ef4_nic *efx = netdev_priv(net_dev);
2123 	int rc;
2124 
2125 	rc = ef4_check_disabled(efx);
2126 	if (rc)
2127 		return rc;
2128 
2129 	netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
2130 
2131 	ef4_device_detach_sync(efx);
2132 	ef4_stop_all(efx);
2133 
2134 	mutex_lock(&efx->mac_lock);
2135 	net_dev->mtu = new_mtu;
2136 	ef4_mac_reconfigure(efx);
2137 	mutex_unlock(&efx->mac_lock);
2138 
2139 	ef4_start_all(efx);
2140 	netif_device_attach(efx->net_dev);
2141 	return 0;
2142 }
2143 
2144 static int ef4_set_mac_address(struct net_device *net_dev, void *data)
2145 {
2146 	struct ef4_nic *efx = netdev_priv(net_dev);
2147 	struct sockaddr *addr = data;
2148 	u8 *new_addr = addr->sa_data;
2149 	u8 old_addr[6];
2150 	int rc;
2151 
2152 	if (!is_valid_ether_addr(new_addr)) {
2153 		netif_err(efx, drv, efx->net_dev,
2154 			  "invalid ethernet MAC address requested: %pM\n",
2155 			  new_addr);
2156 		return -EADDRNOTAVAIL;
2157 	}
2158 
2159 	/* save old address */
2160 	ether_addr_copy(old_addr, net_dev->dev_addr);
2161 	eth_hw_addr_set(net_dev, new_addr);
2162 	if (efx->type->set_mac_address) {
2163 		rc = efx->type->set_mac_address(efx);
2164 		if (rc) {
2165 			eth_hw_addr_set(net_dev, old_addr);
2166 			return rc;
2167 		}
2168 	}
2169 
2170 	/* Reconfigure the MAC */
2171 	mutex_lock(&efx->mac_lock);
2172 	ef4_mac_reconfigure(efx);
2173 	mutex_unlock(&efx->mac_lock);
2174 
2175 	return 0;
2176 }
2177 
2178 /* Context: netif_addr_lock held, BHs disabled. */
2179 static void ef4_set_rx_mode(struct net_device *net_dev)
2180 {
2181 	struct ef4_nic *efx = netdev_priv(net_dev);
2182 
2183 	if (efx->port_enabled)
2184 		queue_work(efx->workqueue, &efx->mac_work);
2185 	/* Otherwise ef4_start_port() will do this */
2186 }
2187 
2188 static int ef4_set_features(struct net_device *net_dev, netdev_features_t data)
2189 {
2190 	struct ef4_nic *efx = netdev_priv(net_dev);
2191 	int rc;
2192 
2193 	/* If disabling RX n-tuple filtering, clear existing filters */
2194 	if (net_dev->features & ~data & NETIF_F_NTUPLE) {
2195 		rc = efx->type->filter_clear_rx(efx, EF4_FILTER_PRI_MANUAL);
2196 		if (rc)
2197 			return rc;
2198 	}
2199 
2200 	/* If Rx VLAN filter is changed, update filters via mac_reconfigure */
2201 	if ((net_dev->features ^ data) & NETIF_F_HW_VLAN_CTAG_FILTER) {
2202 		/* ef4_set_rx_mode() will schedule MAC work to update filters
2203 		 * when a new features are finally set in net_dev.
2204 		 */
2205 		ef4_set_rx_mode(net_dev);
2206 	}
2207 
2208 	return 0;
2209 }
2210 
2211 static const struct net_device_ops ef4_netdev_ops = {
2212 	.ndo_open		= ef4_net_open,
2213 	.ndo_stop		= ef4_net_stop,
2214 	.ndo_get_stats64	= ef4_net_stats,
2215 	.ndo_tx_timeout		= ef4_watchdog,
2216 	.ndo_start_xmit		= ef4_hard_start_xmit,
2217 	.ndo_validate_addr	= eth_validate_addr,
2218 	.ndo_eth_ioctl		= ef4_ioctl,
2219 	.ndo_change_mtu		= ef4_change_mtu,
2220 	.ndo_set_mac_address	= ef4_set_mac_address,
2221 	.ndo_set_rx_mode	= ef4_set_rx_mode,
2222 	.ndo_set_features	= ef4_set_features,
2223 	.ndo_setup_tc		= ef4_setup_tc,
2224 #ifdef CONFIG_RFS_ACCEL
2225 	.ndo_rx_flow_steer	= ef4_filter_rfs,
2226 #endif
2227 };
2228 
2229 static void ef4_update_name(struct ef4_nic *efx)
2230 {
2231 	strcpy(efx->name, efx->net_dev->name);
2232 	ef4_mtd_rename(efx);
2233 	ef4_set_channel_names(efx);
2234 }
2235 
2236 static int ef4_netdev_event(struct notifier_block *this,
2237 			    unsigned long event, void *ptr)
2238 {
2239 	struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
2240 
2241 	if ((net_dev->netdev_ops == &ef4_netdev_ops) &&
2242 	    event == NETDEV_CHANGENAME)
2243 		ef4_update_name(netdev_priv(net_dev));
2244 
2245 	return NOTIFY_DONE;
2246 }
2247 
2248 static struct notifier_block ef4_netdev_notifier = {
2249 	.notifier_call = ef4_netdev_event,
2250 };
2251 
2252 static ssize_t
2253 phy_type_show(struct device *dev, struct device_attribute *attr, char *buf)
2254 {
2255 	struct ef4_nic *efx = dev_get_drvdata(dev);
2256 	return sprintf(buf, "%d\n", efx->phy_type);
2257 }
2258 static DEVICE_ATTR_RO(phy_type);
2259 
2260 static int ef4_register_netdev(struct ef4_nic *efx)
2261 {
2262 	struct net_device *net_dev = efx->net_dev;
2263 	struct ef4_channel *channel;
2264 	int rc;
2265 
2266 	net_dev->watchdog_timeo = 5 * HZ;
2267 	net_dev->irq = efx->pci_dev->irq;
2268 	net_dev->netdev_ops = &ef4_netdev_ops;
2269 	net_dev->ethtool_ops = &ef4_ethtool_ops;
2270 	net_dev->gso_max_segs = EF4_TSO_MAX_SEGS;
2271 	net_dev->min_mtu = EF4_MIN_MTU;
2272 	net_dev->max_mtu = EF4_MAX_MTU;
2273 
2274 	rtnl_lock();
2275 
2276 	/* Enable resets to be scheduled and check whether any were
2277 	 * already requested.  If so, the NIC is probably hosed so we
2278 	 * abort.
2279 	 */
2280 	efx->state = STATE_READY;
2281 	smp_mb(); /* ensure we change state before checking reset_pending */
2282 	if (efx->reset_pending) {
2283 		netif_err(efx, probe, efx->net_dev,
2284 			  "aborting probe due to scheduled reset\n");
2285 		rc = -EIO;
2286 		goto fail_locked;
2287 	}
2288 
2289 	rc = dev_alloc_name(net_dev, net_dev->name);
2290 	if (rc < 0)
2291 		goto fail_locked;
2292 	ef4_update_name(efx);
2293 
2294 	/* Always start with carrier off; PHY events will detect the link */
2295 	netif_carrier_off(net_dev);
2296 
2297 	rc = register_netdevice(net_dev);
2298 	if (rc)
2299 		goto fail_locked;
2300 
2301 	ef4_for_each_channel(channel, efx) {
2302 		struct ef4_tx_queue *tx_queue;
2303 		ef4_for_each_channel_tx_queue(tx_queue, channel)
2304 			ef4_init_tx_queue_core_txq(tx_queue);
2305 	}
2306 
2307 	ef4_associate(efx);
2308 
2309 	rtnl_unlock();
2310 
2311 	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2312 	if (rc) {
2313 		netif_err(efx, drv, efx->net_dev,
2314 			  "failed to init net dev attributes\n");
2315 		goto fail_registered;
2316 	}
2317 	return 0;
2318 
2319 fail_registered:
2320 	rtnl_lock();
2321 	ef4_dissociate(efx);
2322 	unregister_netdevice(net_dev);
2323 fail_locked:
2324 	efx->state = STATE_UNINIT;
2325 	rtnl_unlock();
2326 	netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
2327 	return rc;
2328 }
2329 
2330 static void ef4_unregister_netdev(struct ef4_nic *efx)
2331 {
2332 	if (!efx->net_dev)
2333 		return;
2334 
2335 	BUG_ON(netdev_priv(efx->net_dev) != efx);
2336 
2337 	if (ef4_dev_registered(efx)) {
2338 		strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
2339 		device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
2340 		unregister_netdev(efx->net_dev);
2341 	}
2342 }
2343 
2344 /**************************************************************************
2345  *
2346  * Device reset and suspend
2347  *
2348  **************************************************************************/
2349 
2350 /* Tears down the entire software state and most of the hardware state
2351  * before reset.  */
2352 void ef4_reset_down(struct ef4_nic *efx, enum reset_type method)
2353 {
2354 	EF4_ASSERT_RESET_SERIALISED(efx);
2355 
2356 	ef4_stop_all(efx);
2357 	ef4_disable_interrupts(efx);
2358 
2359 	mutex_lock(&efx->mac_lock);
2360 	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2361 	    method != RESET_TYPE_DATAPATH)
2362 		efx->phy_op->fini(efx);
2363 	efx->type->fini(efx);
2364 }
2365 
2366 /* This function will always ensure that the locks acquired in
2367  * ef4_reset_down() are released. A failure return code indicates
2368  * that we were unable to reinitialise the hardware, and the
2369  * driver should be disabled. If ok is false, then the rx and tx
2370  * engines are not restarted, pending a RESET_DISABLE. */
2371 int ef4_reset_up(struct ef4_nic *efx, enum reset_type method, bool ok)
2372 {
2373 	int rc;
2374 
2375 	EF4_ASSERT_RESET_SERIALISED(efx);
2376 
2377 	/* Ensure that SRAM is initialised even if we're disabling the device */
2378 	rc = efx->type->init(efx);
2379 	if (rc) {
2380 		netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
2381 		goto fail;
2382 	}
2383 
2384 	if (!ok)
2385 		goto fail;
2386 
2387 	if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
2388 	    method != RESET_TYPE_DATAPATH) {
2389 		rc = efx->phy_op->init(efx);
2390 		if (rc)
2391 			goto fail;
2392 		rc = efx->phy_op->reconfigure(efx);
2393 		if (rc && rc != -EPERM)
2394 			netif_err(efx, drv, efx->net_dev,
2395 				  "could not restore PHY settings\n");
2396 	}
2397 
2398 	rc = ef4_enable_interrupts(efx);
2399 	if (rc)
2400 		goto fail;
2401 
2402 	down_read(&efx->filter_sem);
2403 	ef4_restore_filters(efx);
2404 	up_read(&efx->filter_sem);
2405 
2406 	mutex_unlock(&efx->mac_lock);
2407 
2408 	ef4_start_all(efx);
2409 
2410 	return 0;
2411 
2412 fail:
2413 	efx->port_initialized = false;
2414 
2415 	mutex_unlock(&efx->mac_lock);
2416 
2417 	return rc;
2418 }
2419 
2420 /* Reset the NIC using the specified method.  Note that the reset may
2421  * fail, in which case the card will be left in an unusable state.
2422  *
2423  * Caller must hold the rtnl_lock.
2424  */
2425 int ef4_reset(struct ef4_nic *efx, enum reset_type method)
2426 {
2427 	int rc, rc2;
2428 	bool disabled;
2429 
2430 	netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
2431 		   RESET_TYPE(method));
2432 
2433 	ef4_device_detach_sync(efx);
2434 	ef4_reset_down(efx, method);
2435 
2436 	rc = efx->type->reset(efx, method);
2437 	if (rc) {
2438 		netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
2439 		goto out;
2440 	}
2441 
2442 	/* Clear flags for the scopes we covered.  We assume the NIC and
2443 	 * driver are now quiescent so that there is no race here.
2444 	 */
2445 	if (method < RESET_TYPE_MAX_METHOD)
2446 		efx->reset_pending &= -(1 << (method + 1));
2447 	else /* it doesn't fit into the well-ordered scope hierarchy */
2448 		__clear_bit(method, &efx->reset_pending);
2449 
2450 	/* Reinitialise bus-mastering, which may have been turned off before
2451 	 * the reset was scheduled. This is still appropriate, even in the
2452 	 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2453 	 * can respond to requests. */
2454 	pci_set_master(efx->pci_dev);
2455 
2456 out:
2457 	/* Leave device stopped if necessary */
2458 	disabled = rc ||
2459 		method == RESET_TYPE_DISABLE ||
2460 		method == RESET_TYPE_RECOVER_OR_DISABLE;
2461 	rc2 = ef4_reset_up(efx, method, !disabled);
2462 	if (rc2) {
2463 		disabled = true;
2464 		if (!rc)
2465 			rc = rc2;
2466 	}
2467 
2468 	if (disabled) {
2469 		dev_close(efx->net_dev);
2470 		netif_err(efx, drv, efx->net_dev, "has been disabled\n");
2471 		efx->state = STATE_DISABLED;
2472 	} else {
2473 		netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
2474 		netif_device_attach(efx->net_dev);
2475 	}
2476 	return rc;
2477 }
2478 
2479 /* Try recovery mechanisms.
2480  * For now only EEH is supported.
2481  * Returns 0 if the recovery mechanisms are unsuccessful.
2482  * Returns a non-zero value otherwise.
2483  */
2484 int ef4_try_recovery(struct ef4_nic *efx)
2485 {
2486 #ifdef CONFIG_EEH
2487 	/* A PCI error can occur and not be seen by EEH because nothing
2488 	 * happens on the PCI bus. In this case the driver may fail and
2489 	 * schedule a 'recover or reset', leading to this recovery handler.
2490 	 * Manually call the eeh failure check function.
2491 	 */
2492 	struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
2493 	if (eeh_dev_check_failure(eehdev)) {
2494 		/* The EEH mechanisms will handle the error and reset the
2495 		 * device if necessary.
2496 		 */
2497 		return 1;
2498 	}
2499 #endif
2500 	return 0;
2501 }
2502 
2503 /* The worker thread exists so that code that cannot sleep can
2504  * schedule a reset for later.
2505  */
2506 static void ef4_reset_work(struct work_struct *data)
2507 {
2508 	struct ef4_nic *efx = container_of(data, struct ef4_nic, reset_work);
2509 	unsigned long pending;
2510 	enum reset_type method;
2511 
2512 	pending = READ_ONCE(efx->reset_pending);
2513 	method = fls(pending) - 1;
2514 
2515 	if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
2516 	     method == RESET_TYPE_RECOVER_OR_ALL) &&
2517 	    ef4_try_recovery(efx))
2518 		return;
2519 
2520 	if (!pending)
2521 		return;
2522 
2523 	rtnl_lock();
2524 
2525 	/* We checked the state in ef4_schedule_reset() but it may
2526 	 * have changed by now.  Now that we have the RTNL lock,
2527 	 * it cannot change again.
2528 	 */
2529 	if (efx->state == STATE_READY)
2530 		(void)ef4_reset(efx, method);
2531 
2532 	rtnl_unlock();
2533 }
2534 
2535 void ef4_schedule_reset(struct ef4_nic *efx, enum reset_type type)
2536 {
2537 	enum reset_type method;
2538 
2539 	if (efx->state == STATE_RECOVERY) {
2540 		netif_dbg(efx, drv, efx->net_dev,
2541 			  "recovering: skip scheduling %s reset\n",
2542 			  RESET_TYPE(type));
2543 		return;
2544 	}
2545 
2546 	switch (type) {
2547 	case RESET_TYPE_INVISIBLE:
2548 	case RESET_TYPE_ALL:
2549 	case RESET_TYPE_RECOVER_OR_ALL:
2550 	case RESET_TYPE_WORLD:
2551 	case RESET_TYPE_DISABLE:
2552 	case RESET_TYPE_RECOVER_OR_DISABLE:
2553 	case RESET_TYPE_DATAPATH:
2554 		method = type;
2555 		netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
2556 			  RESET_TYPE(method));
2557 		break;
2558 	default:
2559 		method = efx->type->map_reset_reason(type);
2560 		netif_dbg(efx, drv, efx->net_dev,
2561 			  "scheduling %s reset for %s\n",
2562 			  RESET_TYPE(method), RESET_TYPE(type));
2563 		break;
2564 	}
2565 
2566 	set_bit(method, &efx->reset_pending);
2567 	smp_mb(); /* ensure we change reset_pending before checking state */
2568 
2569 	/* If we're not READY then just leave the flags set as the cue
2570 	 * to abort probing or reschedule the reset later.
2571 	 */
2572 	if (READ_ONCE(efx->state) != STATE_READY)
2573 		return;
2574 
2575 	queue_work(reset_workqueue, &efx->reset_work);
2576 }
2577 
2578 /**************************************************************************
2579  *
2580  * List of NICs we support
2581  *
2582  **************************************************************************/
2583 
2584 /* PCI device ID table */
2585 static const struct pci_device_id ef4_pci_table[] = {
2586 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2587 		    PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0),
2588 	 .driver_data = (unsigned long) &falcon_a1_nic_type},
2589 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE,
2590 		    PCI_DEVICE_ID_SOLARFLARE_SFC4000B),
2591 	 .driver_data = (unsigned long) &falcon_b0_nic_type},
2592 	{0}			/* end of list */
2593 };
2594 
2595 /**************************************************************************
2596  *
2597  * Dummy PHY/MAC operations
2598  *
2599  * Can be used for some unimplemented operations
2600  * Needed so all function pointers are valid and do not have to be tested
2601  * before use
2602  *
2603  **************************************************************************/
2604 int ef4_port_dummy_op_int(struct ef4_nic *efx)
2605 {
2606 	return 0;
2607 }
2608 void ef4_port_dummy_op_void(struct ef4_nic *efx) {}
2609 
2610 static bool ef4_port_dummy_op_poll(struct ef4_nic *efx)
2611 {
2612 	return false;
2613 }
2614 
2615 static const struct ef4_phy_operations ef4_dummy_phy_operations = {
2616 	.init		 = ef4_port_dummy_op_int,
2617 	.reconfigure	 = ef4_port_dummy_op_int,
2618 	.poll		 = ef4_port_dummy_op_poll,
2619 	.fini		 = ef4_port_dummy_op_void,
2620 };
2621 
2622 /**************************************************************************
2623  *
2624  * Data housekeeping
2625  *
2626  **************************************************************************/
2627 
2628 /* This zeroes out and then fills in the invariants in a struct
2629  * ef4_nic (including all sub-structures).
2630  */
2631 static int ef4_init_struct(struct ef4_nic *efx,
2632 			   struct pci_dev *pci_dev, struct net_device *net_dev)
2633 {
2634 	int i;
2635 
2636 	/* Initialise common structures */
2637 	INIT_LIST_HEAD(&efx->node);
2638 	INIT_LIST_HEAD(&efx->secondary_list);
2639 	spin_lock_init(&efx->biu_lock);
2640 #ifdef CONFIG_SFC_FALCON_MTD
2641 	INIT_LIST_HEAD(&efx->mtd_list);
2642 #endif
2643 	INIT_WORK(&efx->reset_work, ef4_reset_work);
2644 	INIT_DELAYED_WORK(&efx->monitor_work, ef4_monitor);
2645 	INIT_DELAYED_WORK(&efx->selftest_work, ef4_selftest_async_work);
2646 	efx->pci_dev = pci_dev;
2647 	efx->msg_enable = debug;
2648 	efx->state = STATE_UNINIT;
2649 	strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
2650 
2651 	efx->net_dev = net_dev;
2652 	efx->rx_prefix_size = efx->type->rx_prefix_size;
2653 	efx->rx_ip_align =
2654 		NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
2655 	efx->rx_packet_hash_offset =
2656 		efx->type->rx_hash_offset - efx->type->rx_prefix_size;
2657 	efx->rx_packet_ts_offset =
2658 		efx->type->rx_ts_offset - efx->type->rx_prefix_size;
2659 	spin_lock_init(&efx->stats_lock);
2660 	mutex_init(&efx->mac_lock);
2661 	efx->phy_op = &ef4_dummy_phy_operations;
2662 	efx->mdio.dev = net_dev;
2663 	INIT_WORK(&efx->mac_work, ef4_mac_work);
2664 	init_waitqueue_head(&efx->flush_wq);
2665 
2666 	for (i = 0; i < EF4_MAX_CHANNELS; i++) {
2667 		efx->channel[i] = ef4_alloc_channel(efx, i, NULL);
2668 		if (!efx->channel[i])
2669 			goto fail;
2670 		efx->msi_context[i].efx = efx;
2671 		efx->msi_context[i].index = i;
2672 	}
2673 
2674 	/* Higher numbered interrupt modes are less capable! */
2675 	efx->interrupt_mode = max(efx->type->max_interrupt_mode,
2676 				  interrupt_mode);
2677 
2678 	/* Would be good to use the net_dev name, but we're too early */
2679 	snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
2680 		 pci_name(pci_dev));
2681 	efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
2682 	if (!efx->workqueue)
2683 		goto fail;
2684 
2685 	return 0;
2686 
2687 fail:
2688 	ef4_fini_struct(efx);
2689 	return -ENOMEM;
2690 }
2691 
2692 static void ef4_fini_struct(struct ef4_nic *efx)
2693 {
2694 	int i;
2695 
2696 	for (i = 0; i < EF4_MAX_CHANNELS; i++)
2697 		kfree(efx->channel[i]);
2698 
2699 	kfree(efx->vpd_sn);
2700 
2701 	if (efx->workqueue) {
2702 		destroy_workqueue(efx->workqueue);
2703 		efx->workqueue = NULL;
2704 	}
2705 }
2706 
2707 void ef4_update_sw_stats(struct ef4_nic *efx, u64 *stats)
2708 {
2709 	u64 n_rx_nodesc_trunc = 0;
2710 	struct ef4_channel *channel;
2711 
2712 	ef4_for_each_channel(channel, efx)
2713 		n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
2714 	stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
2715 	stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
2716 }
2717 
2718 /**************************************************************************
2719  *
2720  * PCI interface
2721  *
2722  **************************************************************************/
2723 
2724 /* Main body of final NIC shutdown code
2725  * This is called only at module unload (or hotplug removal).
2726  */
2727 static void ef4_pci_remove_main(struct ef4_nic *efx)
2728 {
2729 	/* Flush reset_work. It can no longer be scheduled since we
2730 	 * are not READY.
2731 	 */
2732 	BUG_ON(efx->state == STATE_READY);
2733 	cancel_work_sync(&efx->reset_work);
2734 
2735 	ef4_disable_interrupts(efx);
2736 	ef4_nic_fini_interrupt(efx);
2737 	ef4_fini_port(efx);
2738 	efx->type->fini(efx);
2739 	ef4_fini_napi(efx);
2740 	ef4_remove_all(efx);
2741 }
2742 
2743 /* Final NIC shutdown
2744  * This is called only at module unload (or hotplug removal).  A PF can call
2745  * this on its VFs to ensure they are unbound first.
2746  */
2747 static void ef4_pci_remove(struct pci_dev *pci_dev)
2748 {
2749 	struct ef4_nic *efx;
2750 
2751 	efx = pci_get_drvdata(pci_dev);
2752 	if (!efx)
2753 		return;
2754 
2755 	/* Mark the NIC as fini, then stop the interface */
2756 	rtnl_lock();
2757 	ef4_dissociate(efx);
2758 	dev_close(efx->net_dev);
2759 	ef4_disable_interrupts(efx);
2760 	efx->state = STATE_UNINIT;
2761 	rtnl_unlock();
2762 
2763 	ef4_unregister_netdev(efx);
2764 
2765 	ef4_mtd_remove(efx);
2766 
2767 	ef4_pci_remove_main(efx);
2768 
2769 	ef4_fini_io(efx);
2770 	netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
2771 
2772 	ef4_fini_struct(efx);
2773 	free_netdev(efx->net_dev);
2774 
2775 	pci_disable_pcie_error_reporting(pci_dev);
2776 };
2777 
2778 /* NIC VPD information
2779  * Called during probe to display the part number of the installed NIC.
2780  */
2781 static void ef4_probe_vpd_strings(struct ef4_nic *efx)
2782 {
2783 	struct pci_dev *dev = efx->pci_dev;
2784 	unsigned int vpd_size, kw_len;
2785 	u8 *vpd_data;
2786 	int start;
2787 
2788 	vpd_data = pci_vpd_alloc(dev, &vpd_size);
2789 	if (IS_ERR(vpd_data)) {
2790 		pci_warn(dev, "Unable to read VPD\n");
2791 		return;
2792 	}
2793 
2794 	start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
2795 					     PCI_VPD_RO_KEYWORD_PARTNO, &kw_len);
2796 	if (start < 0)
2797 		pci_warn(dev, "Part number not found or incomplete\n");
2798 	else
2799 		pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start);
2800 
2801 	start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
2802 					     PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len);
2803 	if (start < 0)
2804 		pci_warn(dev, "Serial number not found or incomplete\n");
2805 	else
2806 		efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL);
2807 
2808 	kfree(vpd_data);
2809 }
2810 
2811 
2812 /* Main body of NIC initialisation
2813  * This is called at module load (or hotplug insertion, theoretically).
2814  */
2815 static int ef4_pci_probe_main(struct ef4_nic *efx)
2816 {
2817 	int rc;
2818 
2819 	/* Do start-of-day initialisation */
2820 	rc = ef4_probe_all(efx);
2821 	if (rc)
2822 		goto fail1;
2823 
2824 	ef4_init_napi(efx);
2825 
2826 	rc = efx->type->init(efx);
2827 	if (rc) {
2828 		netif_err(efx, probe, efx->net_dev,
2829 			  "failed to initialise NIC\n");
2830 		goto fail3;
2831 	}
2832 
2833 	rc = ef4_init_port(efx);
2834 	if (rc) {
2835 		netif_err(efx, probe, efx->net_dev,
2836 			  "failed to initialise port\n");
2837 		goto fail4;
2838 	}
2839 
2840 	rc = ef4_nic_init_interrupt(efx);
2841 	if (rc)
2842 		goto fail5;
2843 	rc = ef4_enable_interrupts(efx);
2844 	if (rc)
2845 		goto fail6;
2846 
2847 	return 0;
2848 
2849  fail6:
2850 	ef4_nic_fini_interrupt(efx);
2851  fail5:
2852 	ef4_fini_port(efx);
2853  fail4:
2854 	efx->type->fini(efx);
2855  fail3:
2856 	ef4_fini_napi(efx);
2857 	ef4_remove_all(efx);
2858  fail1:
2859 	return rc;
2860 }
2861 
2862 /* NIC initialisation
2863  *
2864  * This is called at module load (or hotplug insertion,
2865  * theoretically).  It sets up PCI mappings, resets the NIC,
2866  * sets up and registers the network devices with the kernel and hooks
2867  * the interrupt service routine.  It does not prepare the device for
2868  * transmission; this is left to the first time one of the network
2869  * interfaces is brought up (i.e. ef4_net_open).
2870  */
2871 static int ef4_pci_probe(struct pci_dev *pci_dev,
2872 			 const struct pci_device_id *entry)
2873 {
2874 	struct net_device *net_dev;
2875 	struct ef4_nic *efx;
2876 	int rc;
2877 
2878 	/* Allocate and initialise a struct net_device and struct ef4_nic */
2879 	net_dev = alloc_etherdev_mqs(sizeof(*efx), EF4_MAX_CORE_TX_QUEUES,
2880 				     EF4_MAX_RX_QUEUES);
2881 	if (!net_dev)
2882 		return -ENOMEM;
2883 	efx = netdev_priv(net_dev);
2884 	efx->type = (const struct ef4_nic_type *) entry->driver_data;
2885 	efx->fixed_features |= NETIF_F_HIGHDMA;
2886 
2887 	pci_set_drvdata(pci_dev, efx);
2888 	SET_NETDEV_DEV(net_dev, &pci_dev->dev);
2889 	rc = ef4_init_struct(efx, pci_dev, net_dev);
2890 	if (rc)
2891 		goto fail1;
2892 
2893 	netif_info(efx, probe, efx->net_dev,
2894 		   "Solarflare NIC detected\n");
2895 
2896 	ef4_probe_vpd_strings(efx);
2897 
2898 	/* Set up basic I/O (BAR mappings etc) */
2899 	rc = ef4_init_io(efx);
2900 	if (rc)
2901 		goto fail2;
2902 
2903 	rc = ef4_pci_probe_main(efx);
2904 	if (rc)
2905 		goto fail3;
2906 
2907 	net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
2908 			      NETIF_F_RXCSUM);
2909 	/* Mask for features that also apply to VLAN devices */
2910 	net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
2911 				   NETIF_F_HIGHDMA | NETIF_F_RXCSUM);
2912 
2913 	net_dev->hw_features = net_dev->features & ~efx->fixed_features;
2914 
2915 	/* Disable VLAN filtering by default.  It may be enforced if
2916 	 * the feature is fixed (i.e. VLAN filters are required to
2917 	 * receive VLAN tagged packets due to vPort restrictions).
2918 	 */
2919 	net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
2920 	net_dev->features |= efx->fixed_features;
2921 
2922 	rc = ef4_register_netdev(efx);
2923 	if (rc)
2924 		goto fail4;
2925 
2926 	netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
2927 
2928 	/* Try to create MTDs, but allow this to fail */
2929 	rtnl_lock();
2930 	rc = ef4_mtd_probe(efx);
2931 	rtnl_unlock();
2932 	if (rc && rc != -EPERM)
2933 		netif_warn(efx, probe, efx->net_dev,
2934 			   "failed to create MTDs (%d)\n", rc);
2935 
2936 	rc = pci_enable_pcie_error_reporting(pci_dev);
2937 	if (rc && rc != -EINVAL)
2938 		netif_notice(efx, probe, efx->net_dev,
2939 			     "PCIE error reporting unavailable (%d).\n",
2940 			     rc);
2941 
2942 	return 0;
2943 
2944  fail4:
2945 	ef4_pci_remove_main(efx);
2946  fail3:
2947 	ef4_fini_io(efx);
2948  fail2:
2949 	ef4_fini_struct(efx);
2950  fail1:
2951 	WARN_ON(rc > 0);
2952 	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
2953 	free_netdev(net_dev);
2954 	return rc;
2955 }
2956 
2957 static int ef4_pm_freeze(struct device *dev)
2958 {
2959 	struct ef4_nic *efx = dev_get_drvdata(dev);
2960 
2961 	rtnl_lock();
2962 
2963 	if (efx->state != STATE_DISABLED) {
2964 		efx->state = STATE_UNINIT;
2965 
2966 		ef4_device_detach_sync(efx);
2967 
2968 		ef4_stop_all(efx);
2969 		ef4_disable_interrupts(efx);
2970 	}
2971 
2972 	rtnl_unlock();
2973 
2974 	return 0;
2975 }
2976 
2977 static int ef4_pm_thaw(struct device *dev)
2978 {
2979 	int rc;
2980 	struct ef4_nic *efx = dev_get_drvdata(dev);
2981 
2982 	rtnl_lock();
2983 
2984 	if (efx->state != STATE_DISABLED) {
2985 		rc = ef4_enable_interrupts(efx);
2986 		if (rc)
2987 			goto fail;
2988 
2989 		mutex_lock(&efx->mac_lock);
2990 		efx->phy_op->reconfigure(efx);
2991 		mutex_unlock(&efx->mac_lock);
2992 
2993 		ef4_start_all(efx);
2994 
2995 		netif_device_attach(efx->net_dev);
2996 
2997 		efx->state = STATE_READY;
2998 
2999 		efx->type->resume_wol(efx);
3000 	}
3001 
3002 	rtnl_unlock();
3003 
3004 	/* Reschedule any quenched resets scheduled during ef4_pm_freeze() */
3005 	queue_work(reset_workqueue, &efx->reset_work);
3006 
3007 	return 0;
3008 
3009 fail:
3010 	rtnl_unlock();
3011 
3012 	return rc;
3013 }
3014 
3015 static int ef4_pm_poweroff(struct device *dev)
3016 {
3017 	struct pci_dev *pci_dev = to_pci_dev(dev);
3018 	struct ef4_nic *efx = pci_get_drvdata(pci_dev);
3019 
3020 	efx->type->fini(efx);
3021 
3022 	efx->reset_pending = 0;
3023 
3024 	pci_save_state(pci_dev);
3025 	return pci_set_power_state(pci_dev, PCI_D3hot);
3026 }
3027 
3028 /* Used for both resume and restore */
3029 static int ef4_pm_resume(struct device *dev)
3030 {
3031 	struct pci_dev *pci_dev = to_pci_dev(dev);
3032 	struct ef4_nic *efx = pci_get_drvdata(pci_dev);
3033 	int rc;
3034 
3035 	rc = pci_set_power_state(pci_dev, PCI_D0);
3036 	if (rc)
3037 		return rc;
3038 	pci_restore_state(pci_dev);
3039 	rc = pci_enable_device(pci_dev);
3040 	if (rc)
3041 		return rc;
3042 	pci_set_master(efx->pci_dev);
3043 	rc = efx->type->reset(efx, RESET_TYPE_ALL);
3044 	if (rc)
3045 		return rc;
3046 	rc = efx->type->init(efx);
3047 	if (rc)
3048 		return rc;
3049 	rc = ef4_pm_thaw(dev);
3050 	return rc;
3051 }
3052 
3053 static int ef4_pm_suspend(struct device *dev)
3054 {
3055 	int rc;
3056 
3057 	ef4_pm_freeze(dev);
3058 	rc = ef4_pm_poweroff(dev);
3059 	if (rc)
3060 		ef4_pm_resume(dev);
3061 	return rc;
3062 }
3063 
3064 static const struct dev_pm_ops ef4_pm_ops = {
3065 	.suspend	= ef4_pm_suspend,
3066 	.resume		= ef4_pm_resume,
3067 	.freeze		= ef4_pm_freeze,
3068 	.thaw		= ef4_pm_thaw,
3069 	.poweroff	= ef4_pm_poweroff,
3070 	.restore	= ef4_pm_resume,
3071 };
3072 
3073 /* A PCI error affecting this device was detected.
3074  * At this point MMIO and DMA may be disabled.
3075  * Stop the software path and request a slot reset.
3076  */
3077 static pci_ers_result_t ef4_io_error_detected(struct pci_dev *pdev,
3078 					      pci_channel_state_t state)
3079 {
3080 	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3081 	struct ef4_nic *efx = pci_get_drvdata(pdev);
3082 
3083 	if (state == pci_channel_io_perm_failure)
3084 		return PCI_ERS_RESULT_DISCONNECT;
3085 
3086 	rtnl_lock();
3087 
3088 	if (efx->state != STATE_DISABLED) {
3089 		efx->state = STATE_RECOVERY;
3090 		efx->reset_pending = 0;
3091 
3092 		ef4_device_detach_sync(efx);
3093 
3094 		ef4_stop_all(efx);
3095 		ef4_disable_interrupts(efx);
3096 
3097 		status = PCI_ERS_RESULT_NEED_RESET;
3098 	} else {
3099 		/* If the interface is disabled we don't want to do anything
3100 		 * with it.
3101 		 */
3102 		status = PCI_ERS_RESULT_RECOVERED;
3103 	}
3104 
3105 	rtnl_unlock();
3106 
3107 	pci_disable_device(pdev);
3108 
3109 	return status;
3110 }
3111 
3112 /* Fake a successful reset, which will be performed later in ef4_io_resume. */
3113 static pci_ers_result_t ef4_io_slot_reset(struct pci_dev *pdev)
3114 {
3115 	struct ef4_nic *efx = pci_get_drvdata(pdev);
3116 	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
3117 
3118 	if (pci_enable_device(pdev)) {
3119 		netif_err(efx, hw, efx->net_dev,
3120 			  "Cannot re-enable PCI device after reset.\n");
3121 		status =  PCI_ERS_RESULT_DISCONNECT;
3122 	}
3123 
3124 	return status;
3125 }
3126 
3127 /* Perform the actual reset and resume I/O operations. */
3128 static void ef4_io_resume(struct pci_dev *pdev)
3129 {
3130 	struct ef4_nic *efx = pci_get_drvdata(pdev);
3131 	int rc;
3132 
3133 	rtnl_lock();
3134 
3135 	if (efx->state == STATE_DISABLED)
3136 		goto out;
3137 
3138 	rc = ef4_reset(efx, RESET_TYPE_ALL);
3139 	if (rc) {
3140 		netif_err(efx, hw, efx->net_dev,
3141 			  "ef4_reset failed after PCI error (%d)\n", rc);
3142 	} else {
3143 		efx->state = STATE_READY;
3144 		netif_dbg(efx, hw, efx->net_dev,
3145 			  "Done resetting and resuming IO after PCI error.\n");
3146 	}
3147 
3148 out:
3149 	rtnl_unlock();
3150 }
3151 
3152 /* For simplicity and reliability, we always require a slot reset and try to
3153  * reset the hardware when a pci error affecting the device is detected.
3154  * We leave both the link_reset and mmio_enabled callback unimplemented:
3155  * with our request for slot reset the mmio_enabled callback will never be
3156  * called, and the link_reset callback is not used by AER or EEH mechanisms.
3157  */
3158 static const struct pci_error_handlers ef4_err_handlers = {
3159 	.error_detected = ef4_io_error_detected,
3160 	.slot_reset	= ef4_io_slot_reset,
3161 	.resume		= ef4_io_resume,
3162 };
3163 
3164 static struct pci_driver ef4_pci_driver = {
3165 	.name		= KBUILD_MODNAME,
3166 	.id_table	= ef4_pci_table,
3167 	.probe		= ef4_pci_probe,
3168 	.remove		= ef4_pci_remove,
3169 	.driver.pm	= &ef4_pm_ops,
3170 	.err_handler	= &ef4_err_handlers,
3171 };
3172 
3173 /**************************************************************************
3174  *
3175  * Kernel module interface
3176  *
3177  *************************************************************************/
3178 
3179 module_param(interrupt_mode, uint, 0444);
3180 MODULE_PARM_DESC(interrupt_mode,
3181 		 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3182 
3183 static int __init ef4_init_module(void)
3184 {
3185 	int rc;
3186 
3187 	printk(KERN_INFO "Solarflare Falcon driver v" EF4_DRIVER_VERSION "\n");
3188 
3189 	rc = register_netdevice_notifier(&ef4_netdev_notifier);
3190 	if (rc)
3191 		goto err_notifier;
3192 
3193 	reset_workqueue = create_singlethread_workqueue("sfc_reset");
3194 	if (!reset_workqueue) {
3195 		rc = -ENOMEM;
3196 		goto err_reset;
3197 	}
3198 
3199 	rc = pci_register_driver(&ef4_pci_driver);
3200 	if (rc < 0)
3201 		goto err_pci;
3202 
3203 	return 0;
3204 
3205  err_pci:
3206 	destroy_workqueue(reset_workqueue);
3207  err_reset:
3208 	unregister_netdevice_notifier(&ef4_netdev_notifier);
3209  err_notifier:
3210 	return rc;
3211 }
3212 
3213 static void __exit ef4_exit_module(void)
3214 {
3215 	printk(KERN_INFO "Solarflare Falcon driver unloading\n");
3216 
3217 	pci_unregister_driver(&ef4_pci_driver);
3218 	destroy_workqueue(reset_workqueue);
3219 	unregister_netdevice_notifier(&ef4_netdev_notifier);
3220 
3221 }
3222 
3223 module_init(ef4_init_module);
3224 module_exit(ef4_exit_module);
3225 
3226 MODULE_AUTHOR("Solarflare Communications and "
3227 	      "Michael Brown <mbrown@fensystems.co.uk>");
3228 MODULE_DESCRIPTION("Solarflare Falcon network driver");
3229 MODULE_LICENSE("GPL");
3230 MODULE_DEVICE_TABLE(pci, ef4_pci_table);
3231 MODULE_VERSION(EF4_DRIVER_VERSION);
3232