xref: /openbmc/linux/drivers/net/ethernet/sfc/efx.c (revision b8265621)
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 <net/gre.h>
24 #include <net/udp_tunnel.h>
25 #include "efx.h"
26 #include "efx_common.h"
27 #include "efx_channels.h"
28 #include "ef100.h"
29 #include "rx_common.h"
30 #include "tx_common.h"
31 #include "nic.h"
32 #include "io.h"
33 #include "selftest.h"
34 #include "sriov.h"
35 
36 #include "mcdi.h"
37 #include "mcdi_pcol.h"
38 #include "workarounds.h"
39 
40 /**************************************************************************
41  *
42  * Configurable values
43  *
44  *************************************************************************/
45 
46 module_param_named(interrupt_mode, efx_interrupt_mode, uint, 0444);
47 MODULE_PARM_DESC(interrupt_mode,
48 		 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
49 
50 module_param(rss_cpus, uint, 0444);
51 MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
52 
53 /*
54  * Use separate channels for TX and RX events
55  *
56  * Set this to 1 to use separate channels for TX and RX. It allows us
57  * to control interrupt affinity separately for TX and RX.
58  *
59  * This is only used in MSI-X interrupt mode
60  */
61 bool efx_separate_tx_channels;
62 module_param(efx_separate_tx_channels, bool, 0444);
63 MODULE_PARM_DESC(efx_separate_tx_channels,
64 		 "Use separate channels for TX and RX");
65 
66 /* Initial interrupt moderation settings.  They can be modified after
67  * module load with ethtool.
68  *
69  * The default for RX should strike a balance between increasing the
70  * round-trip latency and reducing overhead.
71  */
72 static unsigned int rx_irq_mod_usec = 60;
73 
74 /* Initial interrupt moderation settings.  They can be modified after
75  * module load with ethtool.
76  *
77  * This default is chosen to ensure that a 10G link does not go idle
78  * while a TX queue is stopped after it has become full.  A queue is
79  * restarted when it drops below half full.  The time this takes (assuming
80  * worst case 3 descriptors per packet and 1024 descriptors) is
81  *   512 / 3 * 1.2 = 205 usec.
82  */
83 static unsigned int tx_irq_mod_usec = 150;
84 
85 static bool phy_flash_cfg;
86 module_param(phy_flash_cfg, bool, 0644);
87 MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
88 
89 static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
90 			 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
91 			 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
92 			 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
93 module_param(debug, uint, 0);
94 MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
95 
96 /**************************************************************************
97  *
98  * Utility functions and prototypes
99  *
100  *************************************************************************/
101 
102 static void efx_remove_port(struct efx_nic *efx);
103 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
104 static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp);
105 static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
106 			u32 flags);
107 
108 #define EFX_ASSERT_RESET_SERIALISED(efx)		\
109 	do {						\
110 		if ((efx->state == STATE_READY) ||	\
111 		    (efx->state == STATE_RECOVERY) ||	\
112 		    (efx->state == STATE_DISABLED))	\
113 			ASSERT_RTNL();			\
114 	} while (0)
115 
116 /**************************************************************************
117  *
118  * Port handling
119  *
120  **************************************************************************/
121 
122 static void efx_fini_port(struct efx_nic *efx);
123 
124 static int efx_probe_port(struct efx_nic *efx)
125 {
126 	int rc;
127 
128 	netif_dbg(efx, probe, efx->net_dev, "create port\n");
129 
130 	if (phy_flash_cfg)
131 		efx->phy_mode = PHY_MODE_SPECIAL;
132 
133 	/* Connect up MAC/PHY operations table */
134 	rc = efx->type->probe_port(efx);
135 	if (rc)
136 		return rc;
137 
138 	/* Initialise MAC address to permanent address */
139 	ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
140 
141 	return 0;
142 }
143 
144 static int efx_init_port(struct efx_nic *efx)
145 {
146 	int rc;
147 
148 	netif_dbg(efx, drv, efx->net_dev, "init port\n");
149 
150 	mutex_lock(&efx->mac_lock);
151 
152 	rc = efx->phy_op->init(efx);
153 	if (rc)
154 		goto fail1;
155 
156 	efx->port_initialized = true;
157 
158 	/* Ensure the PHY advertises the correct flow control settings */
159 	rc = efx->phy_op->reconfigure(efx);
160 	if (rc && rc != -EPERM)
161 		goto fail2;
162 
163 	mutex_unlock(&efx->mac_lock);
164 	return 0;
165 
166 fail2:
167 	efx->phy_op->fini(efx);
168 fail1:
169 	mutex_unlock(&efx->mac_lock);
170 	return rc;
171 }
172 
173 static void efx_fini_port(struct efx_nic *efx)
174 {
175 	netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
176 
177 	if (!efx->port_initialized)
178 		return;
179 
180 	efx->phy_op->fini(efx);
181 	efx->port_initialized = false;
182 
183 	efx->link_state.up = false;
184 	efx_link_status_changed(efx);
185 }
186 
187 static void efx_remove_port(struct efx_nic *efx)
188 {
189 	netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
190 
191 	efx->type->remove_port(efx);
192 }
193 
194 /**************************************************************************
195  *
196  * NIC handling
197  *
198  **************************************************************************/
199 
200 static LIST_HEAD(efx_primary_list);
201 static LIST_HEAD(efx_unassociated_list);
202 
203 static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
204 {
205 	return left->type == right->type &&
206 		left->vpd_sn && right->vpd_sn &&
207 		!strcmp(left->vpd_sn, right->vpd_sn);
208 }
209 
210 static void efx_associate(struct efx_nic *efx)
211 {
212 	struct efx_nic *other, *next;
213 
214 	if (efx->primary == efx) {
215 		/* Adding primary function; look for secondaries */
216 
217 		netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
218 		list_add_tail(&efx->node, &efx_primary_list);
219 
220 		list_for_each_entry_safe(other, next, &efx_unassociated_list,
221 					 node) {
222 			if (efx_same_controller(efx, other)) {
223 				list_del(&other->node);
224 				netif_dbg(other, probe, other->net_dev,
225 					  "moving to secondary list of %s %s\n",
226 					  pci_name(efx->pci_dev),
227 					  efx->net_dev->name);
228 				list_add_tail(&other->node,
229 					      &efx->secondary_list);
230 				other->primary = efx;
231 			}
232 		}
233 	} else {
234 		/* Adding secondary function; look for primary */
235 
236 		list_for_each_entry(other, &efx_primary_list, node) {
237 			if (efx_same_controller(efx, other)) {
238 				netif_dbg(efx, probe, efx->net_dev,
239 					  "adding to secondary list of %s %s\n",
240 					  pci_name(other->pci_dev),
241 					  other->net_dev->name);
242 				list_add_tail(&efx->node,
243 					      &other->secondary_list);
244 				efx->primary = other;
245 				return;
246 			}
247 		}
248 
249 		netif_dbg(efx, probe, efx->net_dev,
250 			  "adding to unassociated list\n");
251 		list_add_tail(&efx->node, &efx_unassociated_list);
252 	}
253 }
254 
255 static void efx_dissociate(struct efx_nic *efx)
256 {
257 	struct efx_nic *other, *next;
258 
259 	list_del(&efx->node);
260 	efx->primary = NULL;
261 
262 	list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
263 		list_del(&other->node);
264 		netif_dbg(other, probe, other->net_dev,
265 			  "moving to unassociated list\n");
266 		list_add_tail(&other->node, &efx_unassociated_list);
267 		other->primary = NULL;
268 	}
269 }
270 
271 static int efx_probe_nic(struct efx_nic *efx)
272 {
273 	int rc;
274 
275 	netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
276 
277 	/* Carry out hardware-type specific initialisation */
278 	rc = efx->type->probe(efx);
279 	if (rc)
280 		return rc;
281 
282 	do {
283 		if (!efx->max_channels || !efx->max_tx_channels) {
284 			netif_err(efx, drv, efx->net_dev,
285 				  "Insufficient resources to allocate"
286 				  " any channels\n");
287 			rc = -ENOSPC;
288 			goto fail1;
289 		}
290 
291 		/* Determine the number of channels and queues by trying
292 		 * to hook in MSI-X interrupts.
293 		 */
294 		rc = efx_probe_interrupts(efx);
295 		if (rc)
296 			goto fail1;
297 
298 		rc = efx_set_channels(efx);
299 		if (rc)
300 			goto fail1;
301 
302 		/* dimension_resources can fail with EAGAIN */
303 		rc = efx->type->dimension_resources(efx);
304 		if (rc != 0 && rc != -EAGAIN)
305 			goto fail2;
306 
307 		if (rc == -EAGAIN)
308 			/* try again with new max_channels */
309 			efx_remove_interrupts(efx);
310 
311 	} while (rc == -EAGAIN);
312 
313 	if (efx->n_channels > 1)
314 		netdev_rss_key_fill(efx->rss_context.rx_hash_key,
315 				    sizeof(efx->rss_context.rx_hash_key));
316 	efx_set_default_rx_indir_table(efx, &efx->rss_context);
317 
318 	/* Initialise the interrupt moderation settings */
319 	efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
320 	efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
321 				true);
322 
323 	return 0;
324 
325 fail2:
326 	efx_remove_interrupts(efx);
327 fail1:
328 	efx->type->remove(efx);
329 	return rc;
330 }
331 
332 static void efx_remove_nic(struct efx_nic *efx)
333 {
334 	netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
335 
336 	efx_remove_interrupts(efx);
337 	efx->type->remove(efx);
338 }
339 
340 /**************************************************************************
341  *
342  * NIC startup/shutdown
343  *
344  *************************************************************************/
345 
346 static int efx_probe_all(struct efx_nic *efx)
347 {
348 	int rc;
349 
350 	rc = efx_probe_nic(efx);
351 	if (rc) {
352 		netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
353 		goto fail1;
354 	}
355 
356 	rc = efx_probe_port(efx);
357 	if (rc) {
358 		netif_err(efx, probe, efx->net_dev, "failed to create port\n");
359 		goto fail2;
360 	}
361 
362 	BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
363 	if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
364 		rc = -EINVAL;
365 		goto fail3;
366 	}
367 
368 #ifdef CONFIG_SFC_SRIOV
369 	rc = efx->type->vswitching_probe(efx);
370 	if (rc) /* not fatal; the PF will still work fine */
371 		netif_warn(efx, probe, efx->net_dev,
372 			   "failed to setup vswitching rc=%d;"
373 			   " VFs may not function\n", rc);
374 #endif
375 
376 	rc = efx_probe_filters(efx);
377 	if (rc) {
378 		netif_err(efx, probe, efx->net_dev,
379 			  "failed to create filter tables\n");
380 		goto fail4;
381 	}
382 
383 	rc = efx_probe_channels(efx);
384 	if (rc)
385 		goto fail5;
386 
387 	return 0;
388 
389  fail5:
390 	efx_remove_filters(efx);
391  fail4:
392 #ifdef CONFIG_SFC_SRIOV
393 	efx->type->vswitching_remove(efx);
394 #endif
395  fail3:
396 	efx_remove_port(efx);
397  fail2:
398 	efx_remove_nic(efx);
399  fail1:
400 	return rc;
401 }
402 
403 static void efx_remove_all(struct efx_nic *efx)
404 {
405 	rtnl_lock();
406 	efx_xdp_setup_prog(efx, NULL);
407 	rtnl_unlock();
408 
409 	efx_remove_channels(efx);
410 	efx_remove_filters(efx);
411 #ifdef CONFIG_SFC_SRIOV
412 	efx->type->vswitching_remove(efx);
413 #endif
414 	efx_remove_port(efx);
415 	efx_remove_nic(efx);
416 }
417 
418 /**************************************************************************
419  *
420  * Interrupt moderation
421  *
422  **************************************************************************/
423 unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
424 {
425 	if (usecs == 0)
426 		return 0;
427 	if (usecs * 1000 < efx->timer_quantum_ns)
428 		return 1; /* never round down to 0 */
429 	return usecs * 1000 / efx->timer_quantum_ns;
430 }
431 
432 unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
433 {
434 	/* We must round up when converting ticks to microseconds
435 	 * because we round down when converting the other way.
436 	 */
437 	return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
438 }
439 
440 /* Set interrupt moderation parameters */
441 int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
442 			    unsigned int rx_usecs, bool rx_adaptive,
443 			    bool rx_may_override_tx)
444 {
445 	struct efx_channel *channel;
446 	unsigned int timer_max_us;
447 
448 	EFX_ASSERT_RESET_SERIALISED(efx);
449 
450 	timer_max_us = efx->timer_max_ns / 1000;
451 
452 	if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
453 		return -EINVAL;
454 
455 	if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
456 	    !rx_may_override_tx) {
457 		netif_err(efx, drv, efx->net_dev, "Channels are shared. "
458 			  "RX and TX IRQ moderation must be equal\n");
459 		return -EINVAL;
460 	}
461 
462 	efx->irq_rx_adaptive = rx_adaptive;
463 	efx->irq_rx_moderation_us = rx_usecs;
464 	efx_for_each_channel(channel, efx) {
465 		if (efx_channel_has_rx_queue(channel))
466 			channel->irq_moderation_us = rx_usecs;
467 		else if (efx_channel_has_tx_queues(channel))
468 			channel->irq_moderation_us = tx_usecs;
469 		else if (efx_channel_is_xdp_tx(channel))
470 			channel->irq_moderation_us = tx_usecs;
471 	}
472 
473 	return 0;
474 }
475 
476 void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
477 			    unsigned int *rx_usecs, bool *rx_adaptive)
478 {
479 	*rx_adaptive = efx->irq_rx_adaptive;
480 	*rx_usecs = efx->irq_rx_moderation_us;
481 
482 	/* If channels are shared between RX and TX, so is IRQ
483 	 * moderation.  Otherwise, IRQ moderation is the same for all
484 	 * TX channels and is not adaptive.
485 	 */
486 	if (efx->tx_channel_offset == 0) {
487 		*tx_usecs = *rx_usecs;
488 	} else {
489 		struct efx_channel *tx_channel;
490 
491 		tx_channel = efx->channel[efx->tx_channel_offset];
492 		*tx_usecs = tx_channel->irq_moderation_us;
493 	}
494 }
495 
496 /**************************************************************************
497  *
498  * ioctls
499  *
500  *************************************************************************/
501 
502 /* Net device ioctl
503  * Context: process, rtnl_lock() held.
504  */
505 static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
506 {
507 	struct efx_nic *efx = netdev_priv(net_dev);
508 	struct mii_ioctl_data *data = if_mii(ifr);
509 
510 	if (cmd == SIOCSHWTSTAMP)
511 		return efx_ptp_set_ts_config(efx, ifr);
512 	if (cmd == SIOCGHWTSTAMP)
513 		return efx_ptp_get_ts_config(efx, ifr);
514 
515 	/* Convert phy_id from older PRTAD/DEVAD format */
516 	if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
517 	    (data->phy_id & 0xfc00) == 0x0400)
518 		data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
519 
520 	return mdio_mii_ioctl(&efx->mdio, data, cmd);
521 }
522 
523 /**************************************************************************
524  *
525  * Kernel net device interface
526  *
527  *************************************************************************/
528 
529 /* Context: process, rtnl_lock() held. */
530 int efx_net_open(struct net_device *net_dev)
531 {
532 	struct efx_nic *efx = netdev_priv(net_dev);
533 	int rc;
534 
535 	netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
536 		  raw_smp_processor_id());
537 
538 	rc = efx_check_disabled(efx);
539 	if (rc)
540 		return rc;
541 	if (efx->phy_mode & PHY_MODE_SPECIAL)
542 		return -EBUSY;
543 	if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
544 		return -EIO;
545 
546 	/* Notify the kernel of the link state polled during driver load,
547 	 * before the monitor starts running */
548 	efx_link_status_changed(efx);
549 
550 	efx_start_all(efx);
551 	if (efx->state == STATE_DISABLED || efx->reset_pending)
552 		netif_device_detach(efx->net_dev);
553 	efx_selftest_async_start(efx);
554 	return 0;
555 }
556 
557 /* Context: process, rtnl_lock() held.
558  * Note that the kernel will ignore our return code; this method
559  * should really be a void.
560  */
561 int efx_net_stop(struct net_device *net_dev)
562 {
563 	struct efx_nic *efx = netdev_priv(net_dev);
564 
565 	netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
566 		  raw_smp_processor_id());
567 
568 	/* Stop the device and flush all the channels */
569 	efx_stop_all(efx);
570 
571 	return 0;
572 }
573 
574 static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
575 {
576 	struct efx_nic *efx = netdev_priv(net_dev);
577 
578 	if (efx->type->vlan_rx_add_vid)
579 		return efx->type->vlan_rx_add_vid(efx, proto, vid);
580 	else
581 		return -EOPNOTSUPP;
582 }
583 
584 static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
585 {
586 	struct efx_nic *efx = netdev_priv(net_dev);
587 
588 	if (efx->type->vlan_rx_kill_vid)
589 		return efx->type->vlan_rx_kill_vid(efx, proto, vid);
590 	else
591 		return -EOPNOTSUPP;
592 }
593 
594 static const struct net_device_ops efx_netdev_ops = {
595 	.ndo_open		= efx_net_open,
596 	.ndo_stop		= efx_net_stop,
597 	.ndo_get_stats64	= efx_net_stats,
598 	.ndo_tx_timeout		= efx_watchdog,
599 	.ndo_start_xmit		= efx_hard_start_xmit,
600 	.ndo_validate_addr	= eth_validate_addr,
601 	.ndo_do_ioctl		= efx_ioctl,
602 	.ndo_change_mtu		= efx_change_mtu,
603 	.ndo_set_mac_address	= efx_set_mac_address,
604 	.ndo_set_rx_mode	= efx_set_rx_mode,
605 	.ndo_set_features	= efx_set_features,
606 	.ndo_vlan_rx_add_vid	= efx_vlan_rx_add_vid,
607 	.ndo_vlan_rx_kill_vid	= efx_vlan_rx_kill_vid,
608 #ifdef CONFIG_SFC_SRIOV
609 	.ndo_set_vf_mac		= efx_sriov_set_vf_mac,
610 	.ndo_set_vf_vlan	= efx_sriov_set_vf_vlan,
611 	.ndo_set_vf_spoofchk	= efx_sriov_set_vf_spoofchk,
612 	.ndo_get_vf_config	= efx_sriov_get_vf_config,
613 	.ndo_set_vf_link_state  = efx_sriov_set_vf_link_state,
614 #endif
615 	.ndo_get_phys_port_id   = efx_get_phys_port_id,
616 	.ndo_get_phys_port_name	= efx_get_phys_port_name,
617 	.ndo_setup_tc		= efx_setup_tc,
618 #ifdef CONFIG_RFS_ACCEL
619 	.ndo_rx_flow_steer	= efx_filter_rfs,
620 #endif
621 	.ndo_udp_tunnel_add	= udp_tunnel_nic_add_port,
622 	.ndo_udp_tunnel_del	= udp_tunnel_nic_del_port,
623 	.ndo_xdp_xmit		= efx_xdp_xmit,
624 	.ndo_bpf		= efx_xdp
625 };
626 
627 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
628 {
629 	struct bpf_prog *old_prog;
630 
631 	if (efx->xdp_rxq_info_failed) {
632 		netif_err(efx, drv, efx->net_dev,
633 			  "Unable to bind XDP program due to previous failure of rxq_info\n");
634 		return -EINVAL;
635 	}
636 
637 	if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
638 		netif_err(efx, drv, efx->net_dev,
639 			  "Unable to configure XDP with MTU of %d (max: %d)\n",
640 			  efx->net_dev->mtu, efx_xdp_max_mtu(efx));
641 		return -EINVAL;
642 	}
643 
644 	old_prog = rtnl_dereference(efx->xdp_prog);
645 	rcu_assign_pointer(efx->xdp_prog, prog);
646 	/* Release the reference that was originally passed by the caller. */
647 	if (old_prog)
648 		bpf_prog_put(old_prog);
649 
650 	return 0;
651 }
652 
653 /* Context: process, rtnl_lock() held. */
654 static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
655 {
656 	struct efx_nic *efx = netdev_priv(dev);
657 	struct bpf_prog *xdp_prog;
658 
659 	switch (xdp->command) {
660 	case XDP_SETUP_PROG:
661 		return efx_xdp_setup_prog(efx, xdp->prog);
662 	case XDP_QUERY_PROG:
663 		xdp_prog = rtnl_dereference(efx->xdp_prog);
664 		xdp->prog_id = xdp_prog ? xdp_prog->aux->id : 0;
665 		return 0;
666 	default:
667 		return -EINVAL;
668 	}
669 }
670 
671 static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
672 			u32 flags)
673 {
674 	struct efx_nic *efx = netdev_priv(dev);
675 
676 	if (!netif_running(dev))
677 		return -EINVAL;
678 
679 	return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
680 }
681 
682 static void efx_update_name(struct efx_nic *efx)
683 {
684 	strcpy(efx->name, efx->net_dev->name);
685 	efx_mtd_rename(efx);
686 	efx_set_channel_names(efx);
687 }
688 
689 static int efx_netdev_event(struct notifier_block *this,
690 			    unsigned long event, void *ptr)
691 {
692 	struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
693 
694 	if ((net_dev->netdev_ops == &efx_netdev_ops) &&
695 	    event == NETDEV_CHANGENAME)
696 		efx_update_name(netdev_priv(net_dev));
697 
698 	return NOTIFY_DONE;
699 }
700 
701 static struct notifier_block efx_netdev_notifier = {
702 	.notifier_call = efx_netdev_event,
703 };
704 
705 static ssize_t
706 show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
707 {
708 	struct efx_nic *efx = dev_get_drvdata(dev);
709 	return sprintf(buf, "%d\n", efx->phy_type);
710 }
711 static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
712 
713 static int efx_register_netdev(struct efx_nic *efx)
714 {
715 	struct net_device *net_dev = efx->net_dev;
716 	struct efx_channel *channel;
717 	int rc;
718 
719 	net_dev->watchdog_timeo = 5 * HZ;
720 	net_dev->irq = efx->pci_dev->irq;
721 	net_dev->netdev_ops = &efx_netdev_ops;
722 	if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
723 		net_dev->priv_flags |= IFF_UNICAST_FLT;
724 	net_dev->ethtool_ops = &efx_ethtool_ops;
725 	net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
726 	net_dev->min_mtu = EFX_MIN_MTU;
727 	net_dev->max_mtu = EFX_MAX_MTU;
728 
729 	rtnl_lock();
730 
731 	/* Enable resets to be scheduled and check whether any were
732 	 * already requested.  If so, the NIC is probably hosed so we
733 	 * abort.
734 	 */
735 	efx->state = STATE_READY;
736 	smp_mb(); /* ensure we change state before checking reset_pending */
737 	if (efx->reset_pending) {
738 		netif_err(efx, probe, efx->net_dev,
739 			  "aborting probe due to scheduled reset\n");
740 		rc = -EIO;
741 		goto fail_locked;
742 	}
743 
744 	rc = dev_alloc_name(net_dev, net_dev->name);
745 	if (rc < 0)
746 		goto fail_locked;
747 	efx_update_name(efx);
748 
749 	/* Always start with carrier off; PHY events will detect the link */
750 	netif_carrier_off(net_dev);
751 
752 	rc = register_netdevice(net_dev);
753 	if (rc)
754 		goto fail_locked;
755 
756 	efx_for_each_channel(channel, efx) {
757 		struct efx_tx_queue *tx_queue;
758 		efx_for_each_channel_tx_queue(tx_queue, channel)
759 			efx_init_tx_queue_core_txq(tx_queue);
760 	}
761 
762 	efx_associate(efx);
763 
764 	rtnl_unlock();
765 
766 	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
767 	if (rc) {
768 		netif_err(efx, drv, efx->net_dev,
769 			  "failed to init net dev attributes\n");
770 		goto fail_registered;
771 	}
772 
773 	efx_init_mcdi_logging(efx);
774 
775 	return 0;
776 
777 fail_registered:
778 	rtnl_lock();
779 	efx_dissociate(efx);
780 	unregister_netdevice(net_dev);
781 fail_locked:
782 	efx->state = STATE_UNINIT;
783 	rtnl_unlock();
784 	netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
785 	return rc;
786 }
787 
788 static void efx_unregister_netdev(struct efx_nic *efx)
789 {
790 	if (!efx->net_dev)
791 		return;
792 
793 	BUG_ON(netdev_priv(efx->net_dev) != efx);
794 
795 	if (efx_dev_registered(efx)) {
796 		strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
797 		efx_fini_mcdi_logging(efx);
798 		device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
799 		unregister_netdev(efx->net_dev);
800 	}
801 }
802 
803 /**************************************************************************
804  *
805  * List of NICs we support
806  *
807  **************************************************************************/
808 
809 /* PCI device ID table */
810 static const struct pci_device_id efx_pci_table[] = {
811 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803),	/* SFC9020 */
812 	 .driver_data = (unsigned long) &siena_a0_nic_type},
813 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813),	/* SFL9021 */
814 	 .driver_data = (unsigned long) &siena_a0_nic_type},
815 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903),  /* SFC9120 PF */
816 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
817 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903),  /* SFC9120 VF */
818 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
819 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923),  /* SFC9140 PF */
820 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
821 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923),  /* SFC9140 VF */
822 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
823 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03),  /* SFC9220 PF */
824 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
825 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03),  /* SFC9220 VF */
826 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
827 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03),  /* SFC9250 PF */
828 	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
829 	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03),  /* SFC9250 VF */
830 	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
831 	{0}			/* end of list */
832 };
833 
834 /**************************************************************************
835  *
836  * Data housekeeping
837  *
838  **************************************************************************/
839 
840 void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
841 {
842 	u64 n_rx_nodesc_trunc = 0;
843 	struct efx_channel *channel;
844 
845 	efx_for_each_channel(channel, efx)
846 		n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
847 	stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
848 	stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
849 }
850 
851 /**************************************************************************
852  *
853  * PCI interface
854  *
855  **************************************************************************/
856 
857 /* Main body of final NIC shutdown code
858  * This is called only at module unload (or hotplug removal).
859  */
860 static void efx_pci_remove_main(struct efx_nic *efx)
861 {
862 	/* Flush reset_work. It can no longer be scheduled since we
863 	 * are not READY.
864 	 */
865 	BUG_ON(efx->state == STATE_READY);
866 	efx_flush_reset_workqueue(efx);
867 
868 	efx_disable_interrupts(efx);
869 	efx_clear_interrupt_affinity(efx);
870 	efx_nic_fini_interrupt(efx);
871 	efx_fini_port(efx);
872 	efx->type->fini(efx);
873 	efx_fini_napi(efx);
874 	efx_remove_all(efx);
875 }
876 
877 /* Final NIC shutdown
878  * This is called only at module unload (or hotplug removal).  A PF can call
879  * this on its VFs to ensure they are unbound first.
880  */
881 static void efx_pci_remove(struct pci_dev *pci_dev)
882 {
883 	struct efx_nic *efx;
884 
885 	efx = pci_get_drvdata(pci_dev);
886 	if (!efx)
887 		return;
888 
889 	/* Mark the NIC as fini, then stop the interface */
890 	rtnl_lock();
891 	efx_dissociate(efx);
892 	dev_close(efx->net_dev);
893 	efx_disable_interrupts(efx);
894 	efx->state = STATE_UNINIT;
895 	rtnl_unlock();
896 
897 	if (efx->type->sriov_fini)
898 		efx->type->sriov_fini(efx);
899 
900 	efx_unregister_netdev(efx);
901 
902 	efx_mtd_remove(efx);
903 
904 	efx_pci_remove_main(efx);
905 
906 	efx_fini_io(efx);
907 	netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
908 
909 	efx_fini_struct(efx);
910 	free_netdev(efx->net_dev);
911 
912 	pci_disable_pcie_error_reporting(pci_dev);
913 };
914 
915 /* NIC VPD information
916  * Called during probe to display the part number of the
917  * installed NIC.  VPD is potentially very large but this should
918  * always appear within the first 512 bytes.
919  */
920 #define SFC_VPD_LEN 512
921 static void efx_probe_vpd_strings(struct efx_nic *efx)
922 {
923 	struct pci_dev *dev = efx->pci_dev;
924 	char vpd_data[SFC_VPD_LEN];
925 	ssize_t vpd_size;
926 	int ro_start, ro_size, i, j;
927 
928 	/* Get the vpd data from the device */
929 	vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
930 	if (vpd_size <= 0) {
931 		netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
932 		return;
933 	}
934 
935 	/* Get the Read only section */
936 	ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
937 	if (ro_start < 0) {
938 		netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
939 		return;
940 	}
941 
942 	ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
943 	j = ro_size;
944 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
945 	if (i + j > vpd_size)
946 		j = vpd_size - i;
947 
948 	/* Get the Part number */
949 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
950 	if (i < 0) {
951 		netif_err(efx, drv, efx->net_dev, "Part number not found\n");
952 		return;
953 	}
954 
955 	j = pci_vpd_info_field_size(&vpd_data[i]);
956 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
957 	if (i + j > vpd_size) {
958 		netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
959 		return;
960 	}
961 
962 	netif_info(efx, drv, efx->net_dev,
963 		   "Part Number : %.*s\n", j, &vpd_data[i]);
964 
965 	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
966 	j = ro_size;
967 	i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
968 	if (i < 0) {
969 		netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
970 		return;
971 	}
972 
973 	j = pci_vpd_info_field_size(&vpd_data[i]);
974 	i += PCI_VPD_INFO_FLD_HDR_SIZE;
975 	if (i + j > vpd_size) {
976 		netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
977 		return;
978 	}
979 
980 	efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
981 	if (!efx->vpd_sn)
982 		return;
983 
984 	snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
985 }
986 
987 
988 /* Main body of NIC initialisation
989  * This is called at module load (or hotplug insertion, theoretically).
990  */
991 static int efx_pci_probe_main(struct efx_nic *efx)
992 {
993 	int rc;
994 
995 	/* Do start-of-day initialisation */
996 	rc = efx_probe_all(efx);
997 	if (rc)
998 		goto fail1;
999 
1000 	efx_init_napi(efx);
1001 
1002 	down_write(&efx->filter_sem);
1003 	rc = efx->type->init(efx);
1004 	up_write(&efx->filter_sem);
1005 	if (rc) {
1006 		netif_err(efx, probe, efx->net_dev,
1007 			  "failed to initialise NIC\n");
1008 		goto fail3;
1009 	}
1010 
1011 	rc = efx_init_port(efx);
1012 	if (rc) {
1013 		netif_err(efx, probe, efx->net_dev,
1014 			  "failed to initialise port\n");
1015 		goto fail4;
1016 	}
1017 
1018 	rc = efx_nic_init_interrupt(efx);
1019 	if (rc)
1020 		goto fail5;
1021 
1022 	efx_set_interrupt_affinity(efx);
1023 	rc = efx_enable_interrupts(efx);
1024 	if (rc)
1025 		goto fail6;
1026 
1027 	return 0;
1028 
1029  fail6:
1030 	efx_clear_interrupt_affinity(efx);
1031 	efx_nic_fini_interrupt(efx);
1032  fail5:
1033 	efx_fini_port(efx);
1034  fail4:
1035 	efx->type->fini(efx);
1036  fail3:
1037 	efx_fini_napi(efx);
1038 	efx_remove_all(efx);
1039  fail1:
1040 	return rc;
1041 }
1042 
1043 static int efx_pci_probe_post_io(struct efx_nic *efx)
1044 {
1045 	struct net_device *net_dev = efx->net_dev;
1046 	int rc = efx_pci_probe_main(efx);
1047 
1048 	if (rc)
1049 		return rc;
1050 
1051 	if (efx->type->sriov_init) {
1052 		rc = efx->type->sriov_init(efx);
1053 		if (rc)
1054 			netif_err(efx, probe, efx->net_dev,
1055 				  "SR-IOV can't be enabled rc %d\n", rc);
1056 	}
1057 
1058 	/* Determine netdevice features */
1059 	net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
1060 			      NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
1061 	if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
1062 		net_dev->features |= NETIF_F_TSO6;
1063 	/* Check whether device supports TSO */
1064 	if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
1065 		net_dev->features &= ~NETIF_F_ALL_TSO;
1066 	/* Mask for features that also apply to VLAN devices */
1067 	net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
1068 				   NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
1069 				   NETIF_F_RXCSUM);
1070 
1071 	net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
1072 
1073 	/* Disable receiving frames with bad FCS, by default. */
1074 	net_dev->features &= ~NETIF_F_RXALL;
1075 
1076 	/* Disable VLAN filtering by default.  It may be enforced if
1077 	 * the feature is fixed (i.e. VLAN filters are required to
1078 	 * receive VLAN tagged packets due to vPort restrictions).
1079 	 */
1080 	net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
1081 	net_dev->features |= efx->fixed_features;
1082 
1083 	rc = efx_register_netdev(efx);
1084 	if (!rc)
1085 		return 0;
1086 
1087 	efx_pci_remove_main(efx);
1088 	return rc;
1089 }
1090 
1091 /* NIC initialisation
1092  *
1093  * This is called at module load (or hotplug insertion,
1094  * theoretically).  It sets up PCI mappings, resets the NIC,
1095  * sets up and registers the network devices with the kernel and hooks
1096  * the interrupt service routine.  It does not prepare the device for
1097  * transmission; this is left to the first time one of the network
1098  * interfaces is brought up (i.e. efx_net_open).
1099  */
1100 static int efx_pci_probe(struct pci_dev *pci_dev,
1101 			 const struct pci_device_id *entry)
1102 {
1103 	struct net_device *net_dev;
1104 	struct efx_nic *efx;
1105 	int rc;
1106 
1107 	/* Allocate and initialise a struct net_device and struct efx_nic */
1108 	net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
1109 				     EFX_MAX_RX_QUEUES);
1110 	if (!net_dev)
1111 		return -ENOMEM;
1112 	efx = netdev_priv(net_dev);
1113 	efx->type = (const struct efx_nic_type *) entry->driver_data;
1114 	efx->fixed_features |= NETIF_F_HIGHDMA;
1115 
1116 	pci_set_drvdata(pci_dev, efx);
1117 	SET_NETDEV_DEV(net_dev, &pci_dev->dev);
1118 	rc = efx_init_struct(efx, pci_dev, net_dev);
1119 	if (rc)
1120 		goto fail1;
1121 
1122 	netif_info(efx, probe, efx->net_dev,
1123 		   "Solarflare NIC detected\n");
1124 
1125 	if (!efx->type->is_vf)
1126 		efx_probe_vpd_strings(efx);
1127 
1128 	/* Set up basic I/O (BAR mappings etc) */
1129 	rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
1130 			 efx->type->mem_map_size(efx));
1131 	if (rc)
1132 		goto fail2;
1133 
1134 	rc = efx_pci_probe_post_io(efx);
1135 	if (rc) {
1136 		/* On failure, retry once immediately.
1137 		 * If we aborted probe due to a scheduled reset, dismiss it.
1138 		 */
1139 		efx->reset_pending = 0;
1140 		rc = efx_pci_probe_post_io(efx);
1141 		if (rc) {
1142 			/* On another failure, retry once more
1143 			 * after a 50-305ms delay.
1144 			 */
1145 			unsigned char r;
1146 
1147 			get_random_bytes(&r, 1);
1148 			msleep((unsigned int)r + 50);
1149 			efx->reset_pending = 0;
1150 			rc = efx_pci_probe_post_io(efx);
1151 		}
1152 	}
1153 	if (rc)
1154 		goto fail3;
1155 
1156 	netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
1157 
1158 	/* Try to create MTDs, but allow this to fail */
1159 	rtnl_lock();
1160 	rc = efx_mtd_probe(efx);
1161 	rtnl_unlock();
1162 	if (rc && rc != -EPERM)
1163 		netif_warn(efx, probe, efx->net_dev,
1164 			   "failed to create MTDs (%d)\n", rc);
1165 
1166 	(void)pci_enable_pcie_error_reporting(pci_dev);
1167 
1168 	if (efx->type->udp_tnl_push_ports)
1169 		efx->type->udp_tnl_push_ports(efx);
1170 
1171 	return 0;
1172 
1173  fail3:
1174 	efx_fini_io(efx);
1175  fail2:
1176 	efx_fini_struct(efx);
1177  fail1:
1178 	WARN_ON(rc > 0);
1179 	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
1180 	free_netdev(net_dev);
1181 	return rc;
1182 }
1183 
1184 /* efx_pci_sriov_configure returns the actual number of Virtual Functions
1185  * enabled on success
1186  */
1187 #ifdef CONFIG_SFC_SRIOV
1188 static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
1189 {
1190 	int rc;
1191 	struct efx_nic *efx = pci_get_drvdata(dev);
1192 
1193 	if (efx->type->sriov_configure) {
1194 		rc = efx->type->sriov_configure(efx, num_vfs);
1195 		if (rc)
1196 			return rc;
1197 		else
1198 			return num_vfs;
1199 	} else
1200 		return -EOPNOTSUPP;
1201 }
1202 #endif
1203 
1204 static int efx_pm_freeze(struct device *dev)
1205 {
1206 	struct efx_nic *efx = dev_get_drvdata(dev);
1207 
1208 	rtnl_lock();
1209 
1210 	if (efx->state != STATE_DISABLED) {
1211 		efx->state = STATE_UNINIT;
1212 
1213 		efx_device_detach_sync(efx);
1214 
1215 		efx_stop_all(efx);
1216 		efx_disable_interrupts(efx);
1217 	}
1218 
1219 	rtnl_unlock();
1220 
1221 	return 0;
1222 }
1223 
1224 static int efx_pm_thaw(struct device *dev)
1225 {
1226 	int rc;
1227 	struct efx_nic *efx = dev_get_drvdata(dev);
1228 
1229 	rtnl_lock();
1230 
1231 	if (efx->state != STATE_DISABLED) {
1232 		rc = efx_enable_interrupts(efx);
1233 		if (rc)
1234 			goto fail;
1235 
1236 		mutex_lock(&efx->mac_lock);
1237 		efx->phy_op->reconfigure(efx);
1238 		mutex_unlock(&efx->mac_lock);
1239 
1240 		efx_start_all(efx);
1241 
1242 		efx_device_attach_if_not_resetting(efx);
1243 
1244 		efx->state = STATE_READY;
1245 
1246 		efx->type->resume_wol(efx);
1247 	}
1248 
1249 	rtnl_unlock();
1250 
1251 	/* Reschedule any quenched resets scheduled during efx_pm_freeze() */
1252 	efx_queue_reset_work(efx);
1253 
1254 	return 0;
1255 
1256 fail:
1257 	rtnl_unlock();
1258 
1259 	return rc;
1260 }
1261 
1262 static int efx_pm_poweroff(struct device *dev)
1263 {
1264 	struct pci_dev *pci_dev = to_pci_dev(dev);
1265 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
1266 
1267 	efx->type->fini(efx);
1268 
1269 	efx->reset_pending = 0;
1270 
1271 	pci_save_state(pci_dev);
1272 	return pci_set_power_state(pci_dev, PCI_D3hot);
1273 }
1274 
1275 /* Used for both resume and restore */
1276 static int efx_pm_resume(struct device *dev)
1277 {
1278 	struct pci_dev *pci_dev = to_pci_dev(dev);
1279 	struct efx_nic *efx = pci_get_drvdata(pci_dev);
1280 	int rc;
1281 
1282 	rc = pci_set_power_state(pci_dev, PCI_D0);
1283 	if (rc)
1284 		return rc;
1285 	pci_restore_state(pci_dev);
1286 	rc = pci_enable_device(pci_dev);
1287 	if (rc)
1288 		return rc;
1289 	pci_set_master(efx->pci_dev);
1290 	rc = efx->type->reset(efx, RESET_TYPE_ALL);
1291 	if (rc)
1292 		return rc;
1293 	down_write(&efx->filter_sem);
1294 	rc = efx->type->init(efx);
1295 	up_write(&efx->filter_sem);
1296 	if (rc)
1297 		return rc;
1298 	rc = efx_pm_thaw(dev);
1299 	return rc;
1300 }
1301 
1302 static int efx_pm_suspend(struct device *dev)
1303 {
1304 	int rc;
1305 
1306 	efx_pm_freeze(dev);
1307 	rc = efx_pm_poweroff(dev);
1308 	if (rc)
1309 		efx_pm_resume(dev);
1310 	return rc;
1311 }
1312 
1313 static const struct dev_pm_ops efx_pm_ops = {
1314 	.suspend	= efx_pm_suspend,
1315 	.resume		= efx_pm_resume,
1316 	.freeze		= efx_pm_freeze,
1317 	.thaw		= efx_pm_thaw,
1318 	.poweroff	= efx_pm_poweroff,
1319 	.restore	= efx_pm_resume,
1320 };
1321 
1322 static struct pci_driver efx_pci_driver = {
1323 	.name		= KBUILD_MODNAME,
1324 	.id_table	= efx_pci_table,
1325 	.probe		= efx_pci_probe,
1326 	.remove		= efx_pci_remove,
1327 	.driver.pm	= &efx_pm_ops,
1328 	.err_handler	= &efx_err_handlers,
1329 #ifdef CONFIG_SFC_SRIOV
1330 	.sriov_configure = efx_pci_sriov_configure,
1331 #endif
1332 };
1333 
1334 /**************************************************************************
1335  *
1336  * Kernel module interface
1337  *
1338  *************************************************************************/
1339 
1340 static int __init efx_init_module(void)
1341 {
1342 	int rc;
1343 
1344 	printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
1345 
1346 	rc = register_netdevice_notifier(&efx_netdev_notifier);
1347 	if (rc)
1348 		goto err_notifier;
1349 
1350 #ifdef CONFIG_SFC_SRIOV
1351 	rc = efx_init_sriov();
1352 	if (rc)
1353 		goto err_sriov;
1354 #endif
1355 
1356 	rc = efx_create_reset_workqueue();
1357 	if (rc)
1358 		goto err_reset;
1359 
1360 	rc = pci_register_driver(&efx_pci_driver);
1361 	if (rc < 0)
1362 		goto err_pci;
1363 
1364 	rc = pci_register_driver(&ef100_pci_driver);
1365 	if (rc < 0)
1366 		goto err_pci_ef100;
1367 
1368 	return 0;
1369 
1370  err_pci_ef100:
1371 	pci_unregister_driver(&efx_pci_driver);
1372  err_pci:
1373 	efx_destroy_reset_workqueue();
1374  err_reset:
1375 #ifdef CONFIG_SFC_SRIOV
1376 	efx_fini_sriov();
1377  err_sriov:
1378 #endif
1379 	unregister_netdevice_notifier(&efx_netdev_notifier);
1380  err_notifier:
1381 	return rc;
1382 }
1383 
1384 static void __exit efx_exit_module(void)
1385 {
1386 	printk(KERN_INFO "Solarflare NET driver unloading\n");
1387 
1388 	pci_unregister_driver(&ef100_pci_driver);
1389 	pci_unregister_driver(&efx_pci_driver);
1390 	efx_destroy_reset_workqueue();
1391 #ifdef CONFIG_SFC_SRIOV
1392 	efx_fini_sriov();
1393 #endif
1394 	unregister_netdevice_notifier(&efx_netdev_notifier);
1395 
1396 }
1397 
1398 module_init(efx_init_module);
1399 module_exit(efx_exit_module);
1400 
1401 MODULE_AUTHOR("Solarflare Communications and "
1402 	      "Michael Brown <mbrown@fensystems.co.uk>");
1403 MODULE_DESCRIPTION("Solarflare network driver");
1404 MODULE_LICENSE("GPL");
1405 MODULE_DEVICE_TABLE(pci, efx_pci_table);
1406 MODULE_VERSION(EFX_DRIVER_VERSION);
1407