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.
8 #include <linux/module.h>
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/delay.h>
13 #include <linux/notifier.h>
15 #include <linux/tcp.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"
24 #include <net/udp_tunnel.h>
26 #include "efx_common.h"
27 #include "efx_channels.h"
28 #include "rx_common.h"
29 #include "tx_common.h"
36 #include "mcdi_pcol.h"
37 #include "workarounds.h"
39 /**************************************************************************
43 **************************************************************************
46 /* UDP tunnel type names */
47 static const char *const efx_udp_tunnel_type_names
[] = {
48 [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN
] = "vxlan",
49 [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE
] = "geneve",
52 void efx_get_udp_tunnel_type_name(u16 type
, char *buf
, size_t buflen
)
54 if (type
< ARRAY_SIZE(efx_udp_tunnel_type_names
) &&
55 efx_udp_tunnel_type_names
[type
] != NULL
)
56 snprintf(buf
, buflen
, "%s", efx_udp_tunnel_type_names
[type
]);
58 snprintf(buf
, buflen
, "type %d", type
);
61 /**************************************************************************
65 *************************************************************************/
68 * Use separate channels for TX and RX events
70 * Set this to 1 to use separate channels for TX and RX. It allows us
71 * to control interrupt affinity separately for TX and RX.
73 * This is only used in MSI-X interrupt mode
75 bool efx_separate_tx_channels
;
76 module_param(efx_separate_tx_channels
, bool, 0444);
77 MODULE_PARM_DESC(efx_separate_tx_channels
,
78 "Use separate channels for TX and RX");
80 /* Initial interrupt moderation settings. They can be modified after
81 * module load with ethtool.
83 * The default for RX should strike a balance between increasing the
84 * round-trip latency and reducing overhead.
86 static unsigned int rx_irq_mod_usec
= 60;
88 /* Initial interrupt moderation settings. They can be modified after
89 * module load with ethtool.
91 * This default is chosen to ensure that a 10G link does not go idle
92 * while a TX queue is stopped after it has become full. A queue is
93 * restarted when it drops below half full. The time this takes (assuming
94 * worst case 3 descriptors per packet and 1024 descriptors) is
95 * 512 / 3 * 1.2 = 205 usec.
97 static unsigned int tx_irq_mod_usec
= 150;
99 static bool phy_flash_cfg
;
100 module_param(phy_flash_cfg
, bool, 0644);
101 MODULE_PARM_DESC(phy_flash_cfg
, "Set PHYs into reflash mode initially");
103 static unsigned debug
= (NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
104 NETIF_MSG_LINK
| NETIF_MSG_IFDOWN
|
105 NETIF_MSG_IFUP
| NETIF_MSG_RX_ERR
|
106 NETIF_MSG_TX_ERR
| NETIF_MSG_HW
);
107 module_param(debug
, uint
, 0);
108 MODULE_PARM_DESC(debug
, "Bitmapped debugging message enable value");
110 /**************************************************************************
112 * Utility functions and prototypes
114 *************************************************************************/
116 static void efx_remove_port(struct efx_nic
*efx
);
117 static int efx_xdp_setup_prog(struct efx_nic
*efx
, struct bpf_prog
*prog
);
118 static int efx_xdp(struct net_device
*dev
, struct netdev_bpf
*xdp
);
119 static int efx_xdp_xmit(struct net_device
*dev
, int n
, struct xdp_frame
**xdpfs
,
122 #define EFX_ASSERT_RESET_SERIALISED(efx) \
124 if ((efx->state == STATE_READY) || \
125 (efx->state == STATE_RECOVERY) || \
126 (efx->state == STATE_DISABLED)) \
130 /**************************************************************************
134 **************************************************************************/
136 /* Equivalent to efx_link_set_advertising with all-zeroes, except does not
137 * force the Autoneg bit on.
139 void efx_link_clear_advertising(struct efx_nic
*efx
)
141 bitmap_zero(efx
->link_advertising
, __ETHTOOL_LINK_MODE_MASK_NBITS
);
142 efx
->wanted_fc
&= ~(EFX_FC_TX
| EFX_FC_RX
);
145 void efx_link_set_wanted_fc(struct efx_nic
*efx
, u8 wanted_fc
)
147 efx
->wanted_fc
= wanted_fc
;
148 if (efx
->link_advertising
[0]) {
149 if (wanted_fc
& EFX_FC_RX
)
150 efx
->link_advertising
[0] |= (ADVERTISED_Pause
|
151 ADVERTISED_Asym_Pause
);
153 efx
->link_advertising
[0] &= ~(ADVERTISED_Pause
|
154 ADVERTISED_Asym_Pause
);
155 if (wanted_fc
& EFX_FC_TX
)
156 efx
->link_advertising
[0] ^= ADVERTISED_Asym_Pause
;
160 static void efx_fini_port(struct efx_nic
*efx
);
162 static int efx_probe_port(struct efx_nic
*efx
)
166 netif_dbg(efx
, probe
, efx
->net_dev
, "create port\n");
169 efx
->phy_mode
= PHY_MODE_SPECIAL
;
171 /* Connect up MAC/PHY operations table */
172 rc
= efx
->type
->probe_port(efx
);
176 /* Initialise MAC address to permanent address */
177 ether_addr_copy(efx
->net_dev
->dev_addr
, efx
->net_dev
->perm_addr
);
182 static int efx_init_port(struct efx_nic
*efx
)
186 netif_dbg(efx
, drv
, efx
->net_dev
, "init port\n");
188 mutex_lock(&efx
->mac_lock
);
190 rc
= efx
->phy_op
->init(efx
);
194 efx
->port_initialized
= true;
196 /* Reconfigure the MAC before creating dma queues (required for
197 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
198 efx_mac_reconfigure(efx
);
200 /* Ensure the PHY advertises the correct flow control settings */
201 rc
= efx
->phy_op
->reconfigure(efx
);
202 if (rc
&& rc
!= -EPERM
)
205 mutex_unlock(&efx
->mac_lock
);
209 efx
->phy_op
->fini(efx
);
211 mutex_unlock(&efx
->mac_lock
);
215 static void efx_fini_port(struct efx_nic
*efx
)
217 netif_dbg(efx
, drv
, efx
->net_dev
, "shut down port\n");
219 if (!efx
->port_initialized
)
222 efx
->phy_op
->fini(efx
);
223 efx
->port_initialized
= false;
225 efx
->link_state
.up
= false;
226 efx_link_status_changed(efx
);
229 static void efx_remove_port(struct efx_nic
*efx
)
231 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying port\n");
233 efx
->type
->remove_port(efx
);
236 /**************************************************************************
240 **************************************************************************/
242 static LIST_HEAD(efx_primary_list
);
243 static LIST_HEAD(efx_unassociated_list
);
245 static bool efx_same_controller(struct efx_nic
*left
, struct efx_nic
*right
)
247 return left
->type
== right
->type
&&
248 left
->vpd_sn
&& right
->vpd_sn
&&
249 !strcmp(left
->vpd_sn
, right
->vpd_sn
);
252 static void efx_associate(struct efx_nic
*efx
)
254 struct efx_nic
*other
, *next
;
256 if (efx
->primary
== efx
) {
257 /* Adding primary function; look for secondaries */
259 netif_dbg(efx
, probe
, efx
->net_dev
, "adding to primary list\n");
260 list_add_tail(&efx
->node
, &efx_primary_list
);
262 list_for_each_entry_safe(other
, next
, &efx_unassociated_list
,
264 if (efx_same_controller(efx
, other
)) {
265 list_del(&other
->node
);
266 netif_dbg(other
, probe
, other
->net_dev
,
267 "moving to secondary list of %s %s\n",
268 pci_name(efx
->pci_dev
),
270 list_add_tail(&other
->node
,
271 &efx
->secondary_list
);
272 other
->primary
= efx
;
276 /* Adding secondary function; look for primary */
278 list_for_each_entry(other
, &efx_primary_list
, node
) {
279 if (efx_same_controller(efx
, other
)) {
280 netif_dbg(efx
, probe
, efx
->net_dev
,
281 "adding to secondary list of %s %s\n",
282 pci_name(other
->pci_dev
),
283 other
->net_dev
->name
);
284 list_add_tail(&efx
->node
,
285 &other
->secondary_list
);
286 efx
->primary
= other
;
291 netif_dbg(efx
, probe
, efx
->net_dev
,
292 "adding to unassociated list\n");
293 list_add_tail(&efx
->node
, &efx_unassociated_list
);
297 static void efx_dissociate(struct efx_nic
*efx
)
299 struct efx_nic
*other
, *next
;
301 list_del(&efx
->node
);
304 list_for_each_entry_safe(other
, next
, &efx
->secondary_list
, node
) {
305 list_del(&other
->node
);
306 netif_dbg(other
, probe
, other
->net_dev
,
307 "moving to unassociated list\n");
308 list_add_tail(&other
->node
, &efx_unassociated_list
);
309 other
->primary
= NULL
;
313 static int efx_probe_nic(struct efx_nic
*efx
)
317 netif_dbg(efx
, probe
, efx
->net_dev
, "creating NIC\n");
319 /* Carry out hardware-type specific initialisation */
320 rc
= efx
->type
->probe(efx
);
325 if (!efx
->max_channels
|| !efx
->max_tx_channels
) {
326 netif_err(efx
, drv
, efx
->net_dev
,
327 "Insufficient resources to allocate"
333 /* Determine the number of channels and queues by trying
334 * to hook in MSI-X interrupts.
336 rc
= efx_probe_interrupts(efx
);
340 rc
= efx_set_channels(efx
);
344 /* dimension_resources can fail with EAGAIN */
345 rc
= efx
->type
->dimension_resources(efx
);
346 if (rc
!= 0 && rc
!= -EAGAIN
)
350 /* try again with new max_channels */
351 efx_remove_interrupts(efx
);
353 } while (rc
== -EAGAIN
);
355 if (efx
->n_channels
> 1)
356 netdev_rss_key_fill(efx
->rss_context
.rx_hash_key
,
357 sizeof(efx
->rss_context
.rx_hash_key
));
358 efx_set_default_rx_indir_table(efx
, &efx
->rss_context
);
360 netif_set_real_num_tx_queues(efx
->net_dev
, efx
->n_tx_channels
);
361 netif_set_real_num_rx_queues(efx
->net_dev
, efx
->n_rx_channels
);
363 /* Initialise the interrupt moderation settings */
364 efx
->irq_mod_step_us
= DIV_ROUND_UP(efx
->timer_quantum_ns
, 1000);
365 efx_init_irq_moderation(efx
, tx_irq_mod_usec
, rx_irq_mod_usec
, true,
371 efx_remove_interrupts(efx
);
373 efx
->type
->remove(efx
);
377 static void efx_remove_nic(struct efx_nic
*efx
)
379 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying NIC\n");
381 efx_remove_interrupts(efx
);
382 efx
->type
->remove(efx
);
385 /**************************************************************************
387 * NIC startup/shutdown
389 *************************************************************************/
391 static int efx_probe_all(struct efx_nic
*efx
)
395 rc
= efx_probe_nic(efx
);
397 netif_err(efx
, probe
, efx
->net_dev
, "failed to create NIC\n");
401 rc
= efx_probe_port(efx
);
403 netif_err(efx
, probe
, efx
->net_dev
, "failed to create port\n");
407 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_RXQ_MIN_ENT
);
408 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_TXQ_MIN_ENT(efx
))) {
412 efx
->rxq_entries
= efx
->txq_entries
= EFX_DEFAULT_DMAQ_SIZE
;
414 #ifdef CONFIG_SFC_SRIOV
415 rc
= efx
->type
->vswitching_probe(efx
);
416 if (rc
) /* not fatal; the PF will still work fine */
417 netif_warn(efx
, probe
, efx
->net_dev
,
418 "failed to setup vswitching rc=%d;"
419 " VFs may not function\n", rc
);
422 rc
= efx_probe_filters(efx
);
424 netif_err(efx
, probe
, efx
->net_dev
,
425 "failed to create filter tables\n");
429 rc
= efx_probe_channels(efx
);
436 efx_remove_filters(efx
);
438 #ifdef CONFIG_SFC_SRIOV
439 efx
->type
->vswitching_remove(efx
);
442 efx_remove_port(efx
);
449 static void efx_remove_all(struct efx_nic
*efx
)
452 efx_xdp_setup_prog(efx
, NULL
);
455 efx_remove_channels(efx
);
456 efx_remove_filters(efx
);
457 #ifdef CONFIG_SFC_SRIOV
458 efx
->type
->vswitching_remove(efx
);
460 efx_remove_port(efx
);
464 /**************************************************************************
466 * Interrupt moderation
468 **************************************************************************/
469 unsigned int efx_usecs_to_ticks(struct efx_nic
*efx
, unsigned int usecs
)
473 if (usecs
* 1000 < efx
->timer_quantum_ns
)
474 return 1; /* never round down to 0 */
475 return usecs
* 1000 / efx
->timer_quantum_ns
;
478 unsigned int efx_ticks_to_usecs(struct efx_nic
*efx
, unsigned int ticks
)
480 /* We must round up when converting ticks to microseconds
481 * because we round down when converting the other way.
483 return DIV_ROUND_UP(ticks
* efx
->timer_quantum_ns
, 1000);
486 /* Set interrupt moderation parameters */
487 int efx_init_irq_moderation(struct efx_nic
*efx
, unsigned int tx_usecs
,
488 unsigned int rx_usecs
, bool rx_adaptive
,
489 bool rx_may_override_tx
)
491 struct efx_channel
*channel
;
492 unsigned int timer_max_us
;
494 EFX_ASSERT_RESET_SERIALISED(efx
);
496 timer_max_us
= efx
->timer_max_ns
/ 1000;
498 if (tx_usecs
> timer_max_us
|| rx_usecs
> timer_max_us
)
501 if (tx_usecs
!= rx_usecs
&& efx
->tx_channel_offset
== 0 &&
502 !rx_may_override_tx
) {
503 netif_err(efx
, drv
, efx
->net_dev
, "Channels are shared. "
504 "RX and TX IRQ moderation must be equal\n");
508 efx
->irq_rx_adaptive
= rx_adaptive
;
509 efx
->irq_rx_moderation_us
= rx_usecs
;
510 efx_for_each_channel(channel
, efx
) {
511 if (efx_channel_has_rx_queue(channel
))
512 channel
->irq_moderation_us
= rx_usecs
;
513 else if (efx_channel_has_tx_queues(channel
))
514 channel
->irq_moderation_us
= tx_usecs
;
515 else if (efx_channel_is_xdp_tx(channel
))
516 channel
->irq_moderation_us
= tx_usecs
;
522 void efx_get_irq_moderation(struct efx_nic
*efx
, unsigned int *tx_usecs
,
523 unsigned int *rx_usecs
, bool *rx_adaptive
)
525 *rx_adaptive
= efx
->irq_rx_adaptive
;
526 *rx_usecs
= efx
->irq_rx_moderation_us
;
528 /* If channels are shared between RX and TX, so is IRQ
529 * moderation. Otherwise, IRQ moderation is the same for all
530 * TX channels and is not adaptive.
532 if (efx
->tx_channel_offset
== 0) {
533 *tx_usecs
= *rx_usecs
;
535 struct efx_channel
*tx_channel
;
537 tx_channel
= efx
->channel
[efx
->tx_channel_offset
];
538 *tx_usecs
= tx_channel
->irq_moderation_us
;
542 /**************************************************************************
546 *************************************************************************/
549 * Context: process, rtnl_lock() held.
551 static int efx_ioctl(struct net_device
*net_dev
, struct ifreq
*ifr
, int cmd
)
553 struct efx_nic
*efx
= netdev_priv(net_dev
);
554 struct mii_ioctl_data
*data
= if_mii(ifr
);
556 if (cmd
== SIOCSHWTSTAMP
)
557 return efx_ptp_set_ts_config(efx
, ifr
);
558 if (cmd
== SIOCGHWTSTAMP
)
559 return efx_ptp_get_ts_config(efx
, ifr
);
561 /* Convert phy_id from older PRTAD/DEVAD format */
562 if ((cmd
== SIOCGMIIREG
|| cmd
== SIOCSMIIREG
) &&
563 (data
->phy_id
& 0xfc00) == 0x0400)
564 data
->phy_id
^= MDIO_PHY_ID_C45
| 0x0400;
566 return mdio_mii_ioctl(&efx
->mdio
, data
, cmd
);
569 /**************************************************************************
571 * Kernel net device interface
573 *************************************************************************/
575 /* Context: process, rtnl_lock() held. */
576 int efx_net_open(struct net_device
*net_dev
)
578 struct efx_nic
*efx
= netdev_priv(net_dev
);
581 netif_dbg(efx
, ifup
, efx
->net_dev
, "opening device on CPU %d\n",
582 raw_smp_processor_id());
584 rc
= efx_check_disabled(efx
);
587 if (efx
->phy_mode
& PHY_MODE_SPECIAL
)
589 if (efx_mcdi_poll_reboot(efx
) && efx_reset(efx
, RESET_TYPE_ALL
))
592 /* Notify the kernel of the link state polled during driver load,
593 * before the monitor starts running */
594 efx_link_status_changed(efx
);
597 if (efx
->state
== STATE_DISABLED
|| efx
->reset_pending
)
598 netif_device_detach(efx
->net_dev
);
599 efx_selftest_async_start(efx
);
603 /* Context: process, rtnl_lock() held.
604 * Note that the kernel will ignore our return code; this method
605 * should really be a void.
607 int efx_net_stop(struct net_device
*net_dev
)
609 struct efx_nic
*efx
= netdev_priv(net_dev
);
611 netif_dbg(efx
, ifdown
, efx
->net_dev
, "closing on CPU %d\n",
612 raw_smp_processor_id());
614 /* Stop the device and flush all the channels */
620 /* Context: netif_tx_lock held, BHs disabled. */
621 static void efx_watchdog(struct net_device
*net_dev
, unsigned int txqueue
)
623 struct efx_nic
*efx
= netdev_priv(net_dev
);
625 netif_err(efx
, tx_err
, efx
->net_dev
,
626 "TX stuck with port_enabled=%d: resetting channels\n",
629 efx_schedule_reset(efx
, RESET_TYPE_TX_WATCHDOG
);
632 static int efx_set_mac_address(struct net_device
*net_dev
, void *data
)
634 struct efx_nic
*efx
= netdev_priv(net_dev
);
635 struct sockaddr
*addr
= data
;
636 u8
*new_addr
= addr
->sa_data
;
640 if (!is_valid_ether_addr(new_addr
)) {
641 netif_err(efx
, drv
, efx
->net_dev
,
642 "invalid ethernet MAC address requested: %pM\n",
644 return -EADDRNOTAVAIL
;
647 /* save old address */
648 ether_addr_copy(old_addr
, net_dev
->dev_addr
);
649 ether_addr_copy(net_dev
->dev_addr
, new_addr
);
650 if (efx
->type
->set_mac_address
) {
651 rc
= efx
->type
->set_mac_address(efx
);
653 ether_addr_copy(net_dev
->dev_addr
, old_addr
);
658 /* Reconfigure the MAC */
659 mutex_lock(&efx
->mac_lock
);
660 efx_mac_reconfigure(efx
);
661 mutex_unlock(&efx
->mac_lock
);
666 /* Context: netif_addr_lock held, BHs disabled. */
667 static void efx_set_rx_mode(struct net_device
*net_dev
)
669 struct efx_nic
*efx
= netdev_priv(net_dev
);
671 if (efx
->port_enabled
)
672 queue_work(efx
->workqueue
, &efx
->mac_work
);
673 /* Otherwise efx_start_port() will do this */
676 static int efx_set_features(struct net_device
*net_dev
, netdev_features_t data
)
678 struct efx_nic
*efx
= netdev_priv(net_dev
);
681 /* If disabling RX n-tuple filtering, clear existing filters */
682 if (net_dev
->features
& ~data
& NETIF_F_NTUPLE
) {
683 rc
= efx
->type
->filter_clear_rx(efx
, EFX_FILTER_PRI_MANUAL
);
688 /* If Rx VLAN filter is changed, update filters via mac_reconfigure.
689 * If rx-fcs is changed, mac_reconfigure updates that too.
691 if ((net_dev
->features
^ data
) & (NETIF_F_HW_VLAN_CTAG_FILTER
|
693 /* efx_set_rx_mode() will schedule MAC work to update filters
694 * when a new features are finally set in net_dev.
696 efx_set_rx_mode(net_dev
);
702 static int efx_get_phys_port_id(struct net_device
*net_dev
,
703 struct netdev_phys_item_id
*ppid
)
705 struct efx_nic
*efx
= netdev_priv(net_dev
);
707 if (efx
->type
->get_phys_port_id
)
708 return efx
->type
->get_phys_port_id(efx
, ppid
);
713 static int efx_get_phys_port_name(struct net_device
*net_dev
,
714 char *name
, size_t len
)
716 struct efx_nic
*efx
= netdev_priv(net_dev
);
718 if (snprintf(name
, len
, "p%u", efx
->port_num
) >= len
)
723 static int efx_vlan_rx_add_vid(struct net_device
*net_dev
, __be16 proto
, u16 vid
)
725 struct efx_nic
*efx
= netdev_priv(net_dev
);
727 if (efx
->type
->vlan_rx_add_vid
)
728 return efx
->type
->vlan_rx_add_vid(efx
, proto
, vid
);
733 static int efx_vlan_rx_kill_vid(struct net_device
*net_dev
, __be16 proto
, u16 vid
)
735 struct efx_nic
*efx
= netdev_priv(net_dev
);
737 if (efx
->type
->vlan_rx_kill_vid
)
738 return efx
->type
->vlan_rx_kill_vid(efx
, proto
, vid
);
743 static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in
)
746 case UDP_TUNNEL_TYPE_VXLAN
:
747 return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN
;
748 case UDP_TUNNEL_TYPE_GENEVE
:
749 return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE
;
755 static void efx_udp_tunnel_add(struct net_device
*dev
, struct udp_tunnel_info
*ti
)
757 struct efx_nic
*efx
= netdev_priv(dev
);
758 struct efx_udp_tunnel tnl
;
761 efx_tunnel_type
= efx_udp_tunnel_type_map(ti
->type
);
762 if (efx_tunnel_type
< 0)
765 tnl
.type
= (u16
)efx_tunnel_type
;
768 if (efx
->type
->udp_tnl_add_port
)
769 (void)efx
->type
->udp_tnl_add_port(efx
, tnl
);
772 static void efx_udp_tunnel_del(struct net_device
*dev
, struct udp_tunnel_info
*ti
)
774 struct efx_nic
*efx
= netdev_priv(dev
);
775 struct efx_udp_tunnel tnl
;
778 efx_tunnel_type
= efx_udp_tunnel_type_map(ti
->type
);
779 if (efx_tunnel_type
< 0)
782 tnl
.type
= (u16
)efx_tunnel_type
;
785 if (efx
->type
->udp_tnl_del_port
)
786 (void)efx
->type
->udp_tnl_del_port(efx
, tnl
);
789 static const struct net_device_ops efx_netdev_ops
= {
790 .ndo_open
= efx_net_open
,
791 .ndo_stop
= efx_net_stop
,
792 .ndo_get_stats64
= efx_net_stats
,
793 .ndo_tx_timeout
= efx_watchdog
,
794 .ndo_start_xmit
= efx_hard_start_xmit
,
795 .ndo_validate_addr
= eth_validate_addr
,
796 .ndo_do_ioctl
= efx_ioctl
,
797 .ndo_change_mtu
= efx_change_mtu
,
798 .ndo_set_mac_address
= efx_set_mac_address
,
799 .ndo_set_rx_mode
= efx_set_rx_mode
,
800 .ndo_set_features
= efx_set_features
,
801 .ndo_vlan_rx_add_vid
= efx_vlan_rx_add_vid
,
802 .ndo_vlan_rx_kill_vid
= efx_vlan_rx_kill_vid
,
803 #ifdef CONFIG_SFC_SRIOV
804 .ndo_set_vf_mac
= efx_sriov_set_vf_mac
,
805 .ndo_set_vf_vlan
= efx_sriov_set_vf_vlan
,
806 .ndo_set_vf_spoofchk
= efx_sriov_set_vf_spoofchk
,
807 .ndo_get_vf_config
= efx_sriov_get_vf_config
,
808 .ndo_set_vf_link_state
= efx_sriov_set_vf_link_state
,
810 .ndo_get_phys_port_id
= efx_get_phys_port_id
,
811 .ndo_get_phys_port_name
= efx_get_phys_port_name
,
812 .ndo_setup_tc
= efx_setup_tc
,
813 #ifdef CONFIG_RFS_ACCEL
814 .ndo_rx_flow_steer
= efx_filter_rfs
,
816 .ndo_udp_tunnel_add
= efx_udp_tunnel_add
,
817 .ndo_udp_tunnel_del
= efx_udp_tunnel_del
,
818 .ndo_xdp_xmit
= efx_xdp_xmit
,
822 static int efx_xdp_setup_prog(struct efx_nic
*efx
, struct bpf_prog
*prog
)
824 struct bpf_prog
*old_prog
;
826 if (efx
->xdp_rxq_info_failed
) {
827 netif_err(efx
, drv
, efx
->net_dev
,
828 "Unable to bind XDP program due to previous failure of rxq_info\n");
832 if (prog
&& efx
->net_dev
->mtu
> efx_xdp_max_mtu(efx
)) {
833 netif_err(efx
, drv
, efx
->net_dev
,
834 "Unable to configure XDP with MTU of %d (max: %d)\n",
835 efx
->net_dev
->mtu
, efx_xdp_max_mtu(efx
));
839 old_prog
= rtnl_dereference(efx
->xdp_prog
);
840 rcu_assign_pointer(efx
->xdp_prog
, prog
);
841 /* Release the reference that was originally passed by the caller. */
843 bpf_prog_put(old_prog
);
848 /* Context: process, rtnl_lock() held. */
849 static int efx_xdp(struct net_device
*dev
, struct netdev_bpf
*xdp
)
851 struct efx_nic
*efx
= netdev_priv(dev
);
852 struct bpf_prog
*xdp_prog
;
854 switch (xdp
->command
) {
856 return efx_xdp_setup_prog(efx
, xdp
->prog
);
858 xdp_prog
= rtnl_dereference(efx
->xdp_prog
);
859 xdp
->prog_id
= xdp_prog
? xdp_prog
->aux
->id
: 0;
866 static int efx_xdp_xmit(struct net_device
*dev
, int n
, struct xdp_frame
**xdpfs
,
869 struct efx_nic
*efx
= netdev_priv(dev
);
871 if (!netif_running(dev
))
874 return efx_xdp_tx_buffers(efx
, n
, xdpfs
, flags
& XDP_XMIT_FLUSH
);
877 static void efx_update_name(struct efx_nic
*efx
)
879 strcpy(efx
->name
, efx
->net_dev
->name
);
881 efx_set_channel_names(efx
);
884 static int efx_netdev_event(struct notifier_block
*this,
885 unsigned long event
, void *ptr
)
887 struct net_device
*net_dev
= netdev_notifier_info_to_dev(ptr
);
889 if ((net_dev
->netdev_ops
== &efx_netdev_ops
) &&
890 event
== NETDEV_CHANGENAME
)
891 efx_update_name(netdev_priv(net_dev
));
896 static struct notifier_block efx_netdev_notifier
= {
897 .notifier_call
= efx_netdev_event
,
901 show_phy_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
903 struct efx_nic
*efx
= dev_get_drvdata(dev
);
904 return sprintf(buf
, "%d\n", efx
->phy_type
);
906 static DEVICE_ATTR(phy_type
, 0444, show_phy_type
, NULL
);
908 static int efx_register_netdev(struct efx_nic
*efx
)
910 struct net_device
*net_dev
= efx
->net_dev
;
911 struct efx_channel
*channel
;
914 net_dev
->watchdog_timeo
= 5 * HZ
;
915 net_dev
->irq
= efx
->pci_dev
->irq
;
916 net_dev
->netdev_ops
= &efx_netdev_ops
;
917 if (efx_nic_rev(efx
) >= EFX_REV_HUNT_A0
)
918 net_dev
->priv_flags
|= IFF_UNICAST_FLT
;
919 net_dev
->ethtool_ops
= &efx_ethtool_ops
;
920 net_dev
->gso_max_segs
= EFX_TSO_MAX_SEGS
;
921 net_dev
->min_mtu
= EFX_MIN_MTU
;
922 net_dev
->max_mtu
= EFX_MAX_MTU
;
926 /* Enable resets to be scheduled and check whether any were
927 * already requested. If so, the NIC is probably hosed so we
930 efx
->state
= STATE_READY
;
931 smp_mb(); /* ensure we change state before checking reset_pending */
932 if (efx
->reset_pending
) {
933 netif_err(efx
, probe
, efx
->net_dev
,
934 "aborting probe due to scheduled reset\n");
939 rc
= dev_alloc_name(net_dev
, net_dev
->name
);
942 efx_update_name(efx
);
944 /* Always start with carrier off; PHY events will detect the link */
945 netif_carrier_off(net_dev
);
947 rc
= register_netdevice(net_dev
);
951 efx_for_each_channel(channel
, efx
) {
952 struct efx_tx_queue
*tx_queue
;
953 efx_for_each_channel_tx_queue(tx_queue
, channel
)
954 efx_init_tx_queue_core_txq(tx_queue
);
961 rc
= device_create_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
963 netif_err(efx
, drv
, efx
->net_dev
,
964 "failed to init net dev attributes\n");
965 goto fail_registered
;
968 efx_init_mcdi_logging(efx
);
975 unregister_netdevice(net_dev
);
977 efx
->state
= STATE_UNINIT
;
979 netif_err(efx
, drv
, efx
->net_dev
, "could not register net dev\n");
983 static void efx_unregister_netdev(struct efx_nic
*efx
)
988 BUG_ON(netdev_priv(efx
->net_dev
) != efx
);
990 if (efx_dev_registered(efx
)) {
991 strlcpy(efx
->name
, pci_name(efx
->pci_dev
), sizeof(efx
->name
));
992 efx_fini_mcdi_logging(efx
);
993 device_remove_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
994 unregister_netdev(efx
->net_dev
);
998 /**************************************************************************
1000 * List of NICs we support
1002 **************************************************************************/
1004 /* PCI device ID table */
1005 static const struct pci_device_id efx_pci_table
[] = {
1006 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0803), /* SFC9020 */
1007 .driver_data
= (unsigned long) &siena_a0_nic_type
},
1008 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0813), /* SFL9021 */
1009 .driver_data
= (unsigned long) &siena_a0_nic_type
},
1010 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0903), /* SFC9120 PF */
1011 .driver_data
= (unsigned long) &efx_hunt_a0_nic_type
},
1012 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x1903), /* SFC9120 VF */
1013 .driver_data
= (unsigned long) &efx_hunt_a0_vf_nic_type
},
1014 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0923), /* SFC9140 PF */
1015 .driver_data
= (unsigned long) &efx_hunt_a0_nic_type
},
1016 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x1923), /* SFC9140 VF */
1017 .driver_data
= (unsigned long) &efx_hunt_a0_vf_nic_type
},
1018 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0a03), /* SFC9220 PF */
1019 .driver_data
= (unsigned long) &efx_hunt_a0_nic_type
},
1020 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x1a03), /* SFC9220 VF */
1021 .driver_data
= (unsigned long) &efx_hunt_a0_vf_nic_type
},
1022 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0b03), /* SFC9250 PF */
1023 .driver_data
= (unsigned long) &efx_hunt_a0_nic_type
},
1024 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x1b03), /* SFC9250 VF */
1025 .driver_data
= (unsigned long) &efx_hunt_a0_vf_nic_type
},
1026 {0} /* end of list */
1029 /**************************************************************************
1033 **************************************************************************/
1035 void efx_update_sw_stats(struct efx_nic
*efx
, u64
*stats
)
1037 u64 n_rx_nodesc_trunc
= 0;
1038 struct efx_channel
*channel
;
1040 efx_for_each_channel(channel
, efx
)
1041 n_rx_nodesc_trunc
+= channel
->n_rx_nodesc_trunc
;
1042 stats
[GENERIC_STAT_rx_nodesc_trunc
] = n_rx_nodesc_trunc
;
1043 stats
[GENERIC_STAT_rx_noskb_drops
] = atomic_read(&efx
->n_rx_noskb_drops
);
1046 /**************************************************************************
1050 **************************************************************************/
1052 /* Main body of final NIC shutdown code
1053 * This is called only at module unload (or hotplug removal).
1055 static void efx_pci_remove_main(struct efx_nic
*efx
)
1057 /* Flush reset_work. It can no longer be scheduled since we
1060 BUG_ON(efx
->state
== STATE_READY
);
1061 efx_flush_reset_workqueue(efx
);
1063 efx_disable_interrupts(efx
);
1064 efx_clear_interrupt_affinity(efx
);
1065 efx_nic_fini_interrupt(efx
);
1067 efx
->type
->fini(efx
);
1069 efx_remove_all(efx
);
1072 /* Final NIC shutdown
1073 * This is called only at module unload (or hotplug removal). A PF can call
1074 * this on its VFs to ensure they are unbound first.
1076 static void efx_pci_remove(struct pci_dev
*pci_dev
)
1078 struct efx_nic
*efx
;
1080 efx
= pci_get_drvdata(pci_dev
);
1084 /* Mark the NIC as fini, then stop the interface */
1086 efx_dissociate(efx
);
1087 dev_close(efx
->net_dev
);
1088 efx_disable_interrupts(efx
);
1089 efx
->state
= STATE_UNINIT
;
1092 if (efx
->type
->sriov_fini
)
1093 efx
->type
->sriov_fini(efx
);
1095 efx_unregister_netdev(efx
);
1097 efx_mtd_remove(efx
);
1099 efx_pci_remove_main(efx
);
1101 efx_fini_io(efx
, efx
->type
->mem_bar(efx
));
1102 netif_dbg(efx
, drv
, efx
->net_dev
, "shutdown successful\n");
1104 efx_fini_struct(efx
);
1105 free_netdev(efx
->net_dev
);
1107 pci_disable_pcie_error_reporting(pci_dev
);
1110 /* NIC VPD information
1111 * Called during probe to display the part number of the
1112 * installed NIC. VPD is potentially very large but this should
1113 * always appear within the first 512 bytes.
1115 #define SFC_VPD_LEN 512
1116 static void efx_probe_vpd_strings(struct efx_nic
*efx
)
1118 struct pci_dev
*dev
= efx
->pci_dev
;
1119 char vpd_data
[SFC_VPD_LEN
];
1121 int ro_start
, ro_size
, i
, j
;
1123 /* Get the vpd data from the device */
1124 vpd_size
= pci_read_vpd(dev
, 0, sizeof(vpd_data
), vpd_data
);
1125 if (vpd_size
<= 0) {
1126 netif_err(efx
, drv
, efx
->net_dev
, "Unable to read VPD\n");
1130 /* Get the Read only section */
1131 ro_start
= pci_vpd_find_tag(vpd_data
, 0, vpd_size
, PCI_VPD_LRDT_RO_DATA
);
1133 netif_err(efx
, drv
, efx
->net_dev
, "VPD Read-only not found\n");
1137 ro_size
= pci_vpd_lrdt_size(&vpd_data
[ro_start
]);
1139 i
= ro_start
+ PCI_VPD_LRDT_TAG_SIZE
;
1140 if (i
+ j
> vpd_size
)
1143 /* Get the Part number */
1144 i
= pci_vpd_find_info_keyword(vpd_data
, i
, j
, "PN");
1146 netif_err(efx
, drv
, efx
->net_dev
, "Part number not found\n");
1150 j
= pci_vpd_info_field_size(&vpd_data
[i
]);
1151 i
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
1152 if (i
+ j
> vpd_size
) {
1153 netif_err(efx
, drv
, efx
->net_dev
, "Incomplete part number\n");
1157 netif_info(efx
, drv
, efx
->net_dev
,
1158 "Part Number : %.*s\n", j
, &vpd_data
[i
]);
1160 i
= ro_start
+ PCI_VPD_LRDT_TAG_SIZE
;
1162 i
= pci_vpd_find_info_keyword(vpd_data
, i
, j
, "SN");
1164 netif_err(efx
, drv
, efx
->net_dev
, "Serial number not found\n");
1168 j
= pci_vpd_info_field_size(&vpd_data
[i
]);
1169 i
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
1170 if (i
+ j
> vpd_size
) {
1171 netif_err(efx
, drv
, efx
->net_dev
, "Incomplete serial number\n");
1175 efx
->vpd_sn
= kmalloc(j
+ 1, GFP_KERNEL
);
1179 snprintf(efx
->vpd_sn
, j
+ 1, "%s", &vpd_data
[i
]);
1183 /* Main body of NIC initialisation
1184 * This is called at module load (or hotplug insertion, theoretically).
1186 static int efx_pci_probe_main(struct efx_nic
*efx
)
1190 /* Do start-of-day initialisation */
1191 rc
= efx_probe_all(efx
);
1197 down_write(&efx
->filter_sem
);
1198 rc
= efx
->type
->init(efx
);
1199 up_write(&efx
->filter_sem
);
1201 netif_err(efx
, probe
, efx
->net_dev
,
1202 "failed to initialise NIC\n");
1206 rc
= efx_init_port(efx
);
1208 netif_err(efx
, probe
, efx
->net_dev
,
1209 "failed to initialise port\n");
1213 rc
= efx_nic_init_interrupt(efx
);
1217 efx_set_interrupt_affinity(efx
);
1218 rc
= efx_enable_interrupts(efx
);
1225 efx_clear_interrupt_affinity(efx
);
1226 efx_nic_fini_interrupt(efx
);
1230 efx
->type
->fini(efx
);
1233 efx_remove_all(efx
);
1238 static int efx_pci_probe_post_io(struct efx_nic
*efx
)
1240 struct net_device
*net_dev
= efx
->net_dev
;
1241 int rc
= efx_pci_probe_main(efx
);
1246 if (efx
->type
->sriov_init
) {
1247 rc
= efx
->type
->sriov_init(efx
);
1249 netif_err(efx
, probe
, efx
->net_dev
,
1250 "SR-IOV can't be enabled rc %d\n", rc
);
1253 /* Determine netdevice features */
1254 net_dev
->features
|= (efx
->type
->offload_features
| NETIF_F_SG
|
1255 NETIF_F_TSO
| NETIF_F_RXCSUM
| NETIF_F_RXALL
);
1256 if (efx
->type
->offload_features
& (NETIF_F_IPV6_CSUM
| NETIF_F_HW_CSUM
))
1257 net_dev
->features
|= NETIF_F_TSO6
;
1258 /* Check whether device supports TSO */
1259 if (!efx
->type
->tso_versions
|| !efx
->type
->tso_versions(efx
))
1260 net_dev
->features
&= ~NETIF_F_ALL_TSO
;
1261 /* Mask for features that also apply to VLAN devices */
1262 net_dev
->vlan_features
|= (NETIF_F_HW_CSUM
| NETIF_F_SG
|
1263 NETIF_F_HIGHDMA
| NETIF_F_ALL_TSO
|
1266 net_dev
->hw_features
|= net_dev
->features
& ~efx
->fixed_features
;
1268 /* Disable receiving frames with bad FCS, by default. */
1269 net_dev
->features
&= ~NETIF_F_RXALL
;
1271 /* Disable VLAN filtering by default. It may be enforced if
1272 * the feature is fixed (i.e. VLAN filters are required to
1273 * receive VLAN tagged packets due to vPort restrictions).
1275 net_dev
->features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
1276 net_dev
->features
|= efx
->fixed_features
;
1278 rc
= efx_register_netdev(efx
);
1282 efx_pci_remove_main(efx
);
1286 /* NIC initialisation
1288 * This is called at module load (or hotplug insertion,
1289 * theoretically). It sets up PCI mappings, resets the NIC,
1290 * sets up and registers the network devices with the kernel and hooks
1291 * the interrupt service routine. It does not prepare the device for
1292 * transmission; this is left to the first time one of the network
1293 * interfaces is brought up (i.e. efx_net_open).
1295 static int efx_pci_probe(struct pci_dev
*pci_dev
,
1296 const struct pci_device_id
*entry
)
1298 struct net_device
*net_dev
;
1299 struct efx_nic
*efx
;
1302 /* Allocate and initialise a struct net_device and struct efx_nic */
1303 net_dev
= alloc_etherdev_mqs(sizeof(*efx
), EFX_MAX_CORE_TX_QUEUES
,
1307 efx
= netdev_priv(net_dev
);
1308 efx
->type
= (const struct efx_nic_type
*) entry
->driver_data
;
1309 efx
->fixed_features
|= NETIF_F_HIGHDMA
;
1311 pci_set_drvdata(pci_dev
, efx
);
1312 SET_NETDEV_DEV(net_dev
, &pci_dev
->dev
);
1313 rc
= efx_init_struct(efx
, pci_dev
, net_dev
);
1317 netif_info(efx
, probe
, efx
->net_dev
,
1318 "Solarflare NIC detected\n");
1320 if (!efx
->type
->is_vf
)
1321 efx_probe_vpd_strings(efx
);
1323 /* Set up basic I/O (BAR mappings etc) */
1324 rc
= efx_init_io(efx
, efx
->type
->mem_bar(efx
), efx
->type
->max_dma_mask
,
1325 efx
->type
->mem_map_size(efx
));
1329 rc
= efx_pci_probe_post_io(efx
);
1331 /* On failure, retry once immediately.
1332 * If we aborted probe due to a scheduled reset, dismiss it.
1334 efx
->reset_pending
= 0;
1335 rc
= efx_pci_probe_post_io(efx
);
1337 /* On another failure, retry once more
1338 * after a 50-305ms delay.
1342 get_random_bytes(&r
, 1);
1343 msleep((unsigned int)r
+ 50);
1344 efx
->reset_pending
= 0;
1345 rc
= efx_pci_probe_post_io(efx
);
1351 netif_dbg(efx
, probe
, efx
->net_dev
, "initialisation successful\n");
1353 /* Try to create MTDs, but allow this to fail */
1355 rc
= efx_mtd_probe(efx
);
1357 if (rc
&& rc
!= -EPERM
)
1358 netif_warn(efx
, probe
, efx
->net_dev
,
1359 "failed to create MTDs (%d)\n", rc
);
1361 (void)pci_enable_pcie_error_reporting(pci_dev
);
1363 if (efx
->type
->udp_tnl_push_ports
)
1364 efx
->type
->udp_tnl_push_ports(efx
);
1369 efx_fini_io(efx
, efx
->type
->mem_bar(efx
));
1371 efx_fini_struct(efx
);
1374 netif_dbg(efx
, drv
, efx
->net_dev
, "initialisation failed. rc=%d\n", rc
);
1375 free_netdev(net_dev
);
1379 /* efx_pci_sriov_configure returns the actual number of Virtual Functions
1380 * enabled on success
1382 #ifdef CONFIG_SFC_SRIOV
1383 static int efx_pci_sriov_configure(struct pci_dev
*dev
, int num_vfs
)
1386 struct efx_nic
*efx
= pci_get_drvdata(dev
);
1388 if (efx
->type
->sriov_configure
) {
1389 rc
= efx
->type
->sriov_configure(efx
, num_vfs
);
1399 static int efx_pm_freeze(struct device
*dev
)
1401 struct efx_nic
*efx
= dev_get_drvdata(dev
);
1405 if (efx
->state
!= STATE_DISABLED
) {
1406 efx
->state
= STATE_UNINIT
;
1408 efx_device_detach_sync(efx
);
1411 efx_disable_interrupts(efx
);
1419 static int efx_pm_thaw(struct device
*dev
)
1422 struct efx_nic
*efx
= dev_get_drvdata(dev
);
1426 if (efx
->state
!= STATE_DISABLED
) {
1427 rc
= efx_enable_interrupts(efx
);
1431 mutex_lock(&efx
->mac_lock
);
1432 efx
->phy_op
->reconfigure(efx
);
1433 mutex_unlock(&efx
->mac_lock
);
1437 efx_device_attach_if_not_resetting(efx
);
1439 efx
->state
= STATE_READY
;
1441 efx
->type
->resume_wol(efx
);
1446 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
1447 efx_queue_reset_work(efx
);
1457 static int efx_pm_poweroff(struct device
*dev
)
1459 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
1460 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
1462 efx
->type
->fini(efx
);
1464 efx
->reset_pending
= 0;
1466 pci_save_state(pci_dev
);
1467 return pci_set_power_state(pci_dev
, PCI_D3hot
);
1470 /* Used for both resume and restore */
1471 static int efx_pm_resume(struct device
*dev
)
1473 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
1474 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
1477 rc
= pci_set_power_state(pci_dev
, PCI_D0
);
1480 pci_restore_state(pci_dev
);
1481 rc
= pci_enable_device(pci_dev
);
1484 pci_set_master(efx
->pci_dev
);
1485 rc
= efx
->type
->reset(efx
, RESET_TYPE_ALL
);
1488 down_write(&efx
->filter_sem
);
1489 rc
= efx
->type
->init(efx
);
1490 up_write(&efx
->filter_sem
);
1493 rc
= efx_pm_thaw(dev
);
1497 static int efx_pm_suspend(struct device
*dev
)
1502 rc
= efx_pm_poweroff(dev
);
1508 static const struct dev_pm_ops efx_pm_ops
= {
1509 .suspend
= efx_pm_suspend
,
1510 .resume
= efx_pm_resume
,
1511 .freeze
= efx_pm_freeze
,
1512 .thaw
= efx_pm_thaw
,
1513 .poweroff
= efx_pm_poweroff
,
1514 .restore
= efx_pm_resume
,
1517 /* A PCI error affecting this device was detected.
1518 * At this point MMIO and DMA may be disabled.
1519 * Stop the software path and request a slot reset.
1521 static pci_ers_result_t
efx_io_error_detected(struct pci_dev
*pdev
,
1522 enum pci_channel_state state
)
1524 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
1525 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
1527 if (state
== pci_channel_io_perm_failure
)
1528 return PCI_ERS_RESULT_DISCONNECT
;
1532 if (efx
->state
!= STATE_DISABLED
) {
1533 efx
->state
= STATE_RECOVERY
;
1534 efx
->reset_pending
= 0;
1536 efx_device_detach_sync(efx
);
1539 efx_disable_interrupts(efx
);
1541 status
= PCI_ERS_RESULT_NEED_RESET
;
1543 /* If the interface is disabled we don't want to do anything
1546 status
= PCI_ERS_RESULT_RECOVERED
;
1551 pci_disable_device(pdev
);
1556 /* Fake a successful reset, which will be performed later in efx_io_resume. */
1557 static pci_ers_result_t
efx_io_slot_reset(struct pci_dev
*pdev
)
1559 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
1560 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
1562 if (pci_enable_device(pdev
)) {
1563 netif_err(efx
, hw
, efx
->net_dev
,
1564 "Cannot re-enable PCI device after reset.\n");
1565 status
= PCI_ERS_RESULT_DISCONNECT
;
1571 /* Perform the actual reset and resume I/O operations. */
1572 static void efx_io_resume(struct pci_dev
*pdev
)
1574 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
1579 if (efx
->state
== STATE_DISABLED
)
1582 rc
= efx_reset(efx
, RESET_TYPE_ALL
);
1584 netif_err(efx
, hw
, efx
->net_dev
,
1585 "efx_reset failed after PCI error (%d)\n", rc
);
1587 efx
->state
= STATE_READY
;
1588 netif_dbg(efx
, hw
, efx
->net_dev
,
1589 "Done resetting and resuming IO after PCI error.\n");
1596 /* For simplicity and reliability, we always require a slot reset and try to
1597 * reset the hardware when a pci error affecting the device is detected.
1598 * We leave both the link_reset and mmio_enabled callback unimplemented:
1599 * with our request for slot reset the mmio_enabled callback will never be
1600 * called, and the link_reset callback is not used by AER or EEH mechanisms.
1602 static const struct pci_error_handlers efx_err_handlers
= {
1603 .error_detected
= efx_io_error_detected
,
1604 .slot_reset
= efx_io_slot_reset
,
1605 .resume
= efx_io_resume
,
1608 static struct pci_driver efx_pci_driver
= {
1609 .name
= KBUILD_MODNAME
,
1610 .id_table
= efx_pci_table
,
1611 .probe
= efx_pci_probe
,
1612 .remove
= efx_pci_remove
,
1613 .driver
.pm
= &efx_pm_ops
,
1614 .err_handler
= &efx_err_handlers
,
1615 #ifdef CONFIG_SFC_SRIOV
1616 .sriov_configure
= efx_pci_sriov_configure
,
1620 /**************************************************************************
1622 * Kernel module interface
1624 *************************************************************************/
1626 static int __init
efx_init_module(void)
1630 printk(KERN_INFO
"Solarflare NET driver v" EFX_DRIVER_VERSION
"\n");
1632 rc
= register_netdevice_notifier(&efx_netdev_notifier
);
1636 #ifdef CONFIG_SFC_SRIOV
1637 rc
= efx_init_sriov();
1642 rc
= efx_create_reset_workqueue();
1646 rc
= pci_register_driver(&efx_pci_driver
);
1653 efx_destroy_reset_workqueue();
1655 #ifdef CONFIG_SFC_SRIOV
1659 unregister_netdevice_notifier(&efx_netdev_notifier
);
1664 static void __exit
efx_exit_module(void)
1666 printk(KERN_INFO
"Solarflare NET driver unloading\n");
1668 pci_unregister_driver(&efx_pci_driver
);
1669 efx_destroy_reset_workqueue();
1670 #ifdef CONFIG_SFC_SRIOV
1673 unregister_netdevice_notifier(&efx_netdev_notifier
);
1677 module_init(efx_init_module
);
1678 module_exit(efx_exit_module
);
1680 MODULE_AUTHOR("Solarflare Communications and "
1681 "Michael Brown <mbrown@fensystems.co.uk>");
1682 MODULE_DESCRIPTION("Solarflare network driver");
1683 MODULE_LICENSE("GPL");
1684 MODULE_DEVICE_TABLE(pci
, efx_pci_table
);
1685 MODULE_VERSION(EFX_DRIVER_VERSION
);