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