1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2011 Solarflare Communications Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/delay.h>
16 #include <linux/notifier.h>
18 #include <linux/tcp.h>
20 #include <linux/crc32.h>
21 #include <linux/ethtool.h>
22 #include <linux/topology.h>
23 #include <linux/gfp.h>
24 #include <linux/pci.h>
25 #include <linux/cpu_rmap.h>
26 #include <linux/aer.h>
27 #include "net_driver.h"
33 #include "workarounds.h"
35 /**************************************************************************
39 **************************************************************************
42 /* Loopback mode names (see LOOPBACK_MODE()) */
43 const unsigned int efx_loopback_mode_max
= LOOPBACK_MAX
;
44 const char *const efx_loopback_mode_names
[] = {
45 [LOOPBACK_NONE
] = "NONE",
46 [LOOPBACK_DATA
] = "DATAPATH",
47 [LOOPBACK_GMAC
] = "GMAC",
48 [LOOPBACK_XGMII
] = "XGMII",
49 [LOOPBACK_XGXS
] = "XGXS",
50 [LOOPBACK_XAUI
] = "XAUI",
51 [LOOPBACK_GMII
] = "GMII",
52 [LOOPBACK_SGMII
] = "SGMII",
53 [LOOPBACK_XGBR
] = "XGBR",
54 [LOOPBACK_XFI
] = "XFI",
55 [LOOPBACK_XAUI_FAR
] = "XAUI_FAR",
56 [LOOPBACK_GMII_FAR
] = "GMII_FAR",
57 [LOOPBACK_SGMII_FAR
] = "SGMII_FAR",
58 [LOOPBACK_XFI_FAR
] = "XFI_FAR",
59 [LOOPBACK_GPHY
] = "GPHY",
60 [LOOPBACK_PHYXS
] = "PHYXS",
61 [LOOPBACK_PCS
] = "PCS",
62 [LOOPBACK_PMAPMD
] = "PMA/PMD",
63 [LOOPBACK_XPORT
] = "XPORT",
64 [LOOPBACK_XGMII_WS
] = "XGMII_WS",
65 [LOOPBACK_XAUI_WS
] = "XAUI_WS",
66 [LOOPBACK_XAUI_WS_FAR
] = "XAUI_WS_FAR",
67 [LOOPBACK_XAUI_WS_NEAR
] = "XAUI_WS_NEAR",
68 [LOOPBACK_GMII_WS
] = "GMII_WS",
69 [LOOPBACK_XFI_WS
] = "XFI_WS",
70 [LOOPBACK_XFI_WS_FAR
] = "XFI_WS_FAR",
71 [LOOPBACK_PHYXS_WS
] = "PHYXS_WS",
74 const unsigned int efx_reset_type_max
= RESET_TYPE_MAX
;
75 const char *const efx_reset_type_names
[] = {
76 [RESET_TYPE_INVISIBLE
] = "INVISIBLE",
77 [RESET_TYPE_ALL
] = "ALL",
78 [RESET_TYPE_RECOVER_OR_ALL
] = "RECOVER_OR_ALL",
79 [RESET_TYPE_WORLD
] = "WORLD",
80 [RESET_TYPE_RECOVER_OR_DISABLE
] = "RECOVER_OR_DISABLE",
81 [RESET_TYPE_DISABLE
] = "DISABLE",
82 [RESET_TYPE_TX_WATCHDOG
] = "TX_WATCHDOG",
83 [RESET_TYPE_INT_ERROR
] = "INT_ERROR",
84 [RESET_TYPE_RX_RECOVERY
] = "RX_RECOVERY",
85 [RESET_TYPE_RX_DESC_FETCH
] = "RX_DESC_FETCH",
86 [RESET_TYPE_TX_DESC_FETCH
] = "TX_DESC_FETCH",
87 [RESET_TYPE_TX_SKIP
] = "TX_SKIP",
88 [RESET_TYPE_MC_FAILURE
] = "MC_FAILURE",
91 /* Reset workqueue. If any NIC has a hardware failure then a reset will be
92 * queued onto this work queue. This is not a per-nic work queue, because
93 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
95 static struct workqueue_struct
*reset_workqueue
;
97 /**************************************************************************
101 *************************************************************************/
104 * Use separate channels for TX and RX events
106 * Set this to 1 to use separate channels for TX and RX. It allows us
107 * to control interrupt affinity separately for TX and RX.
109 * This is only used in MSI-X interrupt mode
111 static bool separate_tx_channels
;
112 module_param(separate_tx_channels
, bool, 0444);
113 MODULE_PARM_DESC(separate_tx_channels
,
114 "Use separate channels for TX and RX");
116 /* This is the weight assigned to each of the (per-channel) virtual
119 static int napi_weight
= 64;
121 /* This is the time (in jiffies) between invocations of the hardware
123 * On Falcon-based NICs, this will:
124 * - Check the on-board hardware monitor;
125 * - Poll the link state and reconfigure the hardware as necessary.
126 * On Siena-based NICs for power systems with EEH support, this will give EEH a
129 static unsigned int efx_monitor_interval
= 1 * HZ
;
131 /* Initial interrupt moderation settings. They can be modified after
132 * module load with ethtool.
134 * The default for RX should strike a balance between increasing the
135 * round-trip latency and reducing overhead.
137 static unsigned int rx_irq_mod_usec
= 60;
139 /* Initial interrupt moderation settings. They can be modified after
140 * module load with ethtool.
142 * This default is chosen to ensure that a 10G link does not go idle
143 * while a TX queue is stopped after it has become full. A queue is
144 * restarted when it drops below half full. The time this takes (assuming
145 * worst case 3 descriptors per packet and 1024 descriptors) is
146 * 512 / 3 * 1.2 = 205 usec.
148 static unsigned int tx_irq_mod_usec
= 150;
150 /* This is the first interrupt mode to try out of:
155 static unsigned int interrupt_mode
;
157 /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
158 * i.e. the number of CPUs among which we may distribute simultaneous
159 * interrupt handling.
161 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
162 * The default (0) means to assign an interrupt to each core.
164 static unsigned int rss_cpus
;
165 module_param(rss_cpus
, uint
, 0444);
166 MODULE_PARM_DESC(rss_cpus
, "Number of CPUs to use for Receive-Side Scaling");
168 static bool phy_flash_cfg
;
169 module_param(phy_flash_cfg
, bool, 0644);
170 MODULE_PARM_DESC(phy_flash_cfg
, "Set PHYs into reflash mode initially");
172 static unsigned irq_adapt_low_thresh
= 8000;
173 module_param(irq_adapt_low_thresh
, uint
, 0644);
174 MODULE_PARM_DESC(irq_adapt_low_thresh
,
175 "Threshold score for reducing IRQ moderation");
177 static unsigned irq_adapt_high_thresh
= 16000;
178 module_param(irq_adapt_high_thresh
, uint
, 0644);
179 MODULE_PARM_DESC(irq_adapt_high_thresh
,
180 "Threshold score for increasing IRQ moderation");
182 static unsigned debug
= (NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
183 NETIF_MSG_LINK
| NETIF_MSG_IFDOWN
|
184 NETIF_MSG_IFUP
| NETIF_MSG_RX_ERR
|
185 NETIF_MSG_TX_ERR
| NETIF_MSG_HW
);
186 module_param(debug
, uint
, 0);
187 MODULE_PARM_DESC(debug
, "Bitmapped debugging message enable value");
189 /**************************************************************************
191 * Utility functions and prototypes
193 *************************************************************************/
195 static void efx_start_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
);
196 static void efx_stop_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
);
197 static void efx_remove_channel(struct efx_channel
*channel
);
198 static void efx_remove_channels(struct efx_nic
*efx
);
199 static const struct efx_channel_type efx_default_channel_type
;
200 static void efx_remove_port(struct efx_nic
*efx
);
201 static void efx_init_napi_channel(struct efx_channel
*channel
);
202 static void efx_fini_napi(struct efx_nic
*efx
);
203 static void efx_fini_napi_channel(struct efx_channel
*channel
);
204 static void efx_fini_struct(struct efx_nic
*efx
);
205 static void efx_start_all(struct efx_nic
*efx
);
206 static void efx_stop_all(struct efx_nic
*efx
);
208 #define EFX_ASSERT_RESET_SERIALISED(efx) \
210 if ((efx->state == STATE_READY) || \
211 (efx->state == STATE_RECOVERY) || \
212 (efx->state == STATE_DISABLED)) \
216 static int efx_check_disabled(struct efx_nic
*efx
)
218 if (efx
->state
== STATE_DISABLED
|| efx
->state
== STATE_RECOVERY
) {
219 netif_err(efx
, drv
, efx
->net_dev
,
220 "device is disabled due to earlier errors\n");
226 /**************************************************************************
228 * Event queue processing
230 *************************************************************************/
232 /* Process channel's event queue
234 * This function is responsible for processing the event queue of a
235 * single channel. The caller must guarantee that this function will
236 * never be concurrently called more than once on the same channel,
237 * though different channels may be being processed concurrently.
239 static int efx_process_channel(struct efx_channel
*channel
, int budget
)
243 if (unlikely(!channel
->enabled
))
246 spent
= efx_nic_process_eventq(channel
, budget
);
247 if (spent
&& efx_channel_has_rx_queue(channel
)) {
248 struct efx_rx_queue
*rx_queue
=
249 efx_channel_get_rx_queue(channel
);
251 efx_rx_flush_packet(channel
);
252 if (rx_queue
->enabled
)
253 efx_fast_push_rx_descriptors(rx_queue
);
259 /* Mark channel as finished processing
261 * Note that since we will not receive further interrupts for this
262 * channel before we finish processing and call the eventq_read_ack()
263 * method, there is no need to use the interrupt hold-off timers.
265 static inline void efx_channel_processed(struct efx_channel
*channel
)
267 /* The interrupt handler for this channel may set work_pending
268 * as soon as we acknowledge the events we've seen. Make sure
269 * it's cleared before then. */
270 channel
->work_pending
= false;
273 efx_nic_eventq_read_ack(channel
);
278 * NAPI guarantees serialisation of polls of the same device, which
279 * provides the guarantee required by efx_process_channel().
281 static int efx_poll(struct napi_struct
*napi
, int budget
)
283 struct efx_channel
*channel
=
284 container_of(napi
, struct efx_channel
, napi_str
);
285 struct efx_nic
*efx
= channel
->efx
;
288 netif_vdbg(efx
, intr
, efx
->net_dev
,
289 "channel %d NAPI poll executing on CPU %d\n",
290 channel
->channel
, raw_smp_processor_id());
292 spent
= efx_process_channel(channel
, budget
);
294 if (spent
< budget
) {
295 if (efx_channel_has_rx_queue(channel
) &&
296 efx
->irq_rx_adaptive
&&
297 unlikely(++channel
->irq_count
== 1000)) {
298 if (unlikely(channel
->irq_mod_score
<
299 irq_adapt_low_thresh
)) {
300 if (channel
->irq_moderation
> 1) {
301 channel
->irq_moderation
-= 1;
302 efx
->type
->push_irq_moderation(channel
);
304 } else if (unlikely(channel
->irq_mod_score
>
305 irq_adapt_high_thresh
)) {
306 if (channel
->irq_moderation
<
307 efx
->irq_rx_moderation
) {
308 channel
->irq_moderation
+= 1;
309 efx
->type
->push_irq_moderation(channel
);
312 channel
->irq_count
= 0;
313 channel
->irq_mod_score
= 0;
316 efx_filter_rfs_expire(channel
);
318 /* There is no race here; although napi_disable() will
319 * only wait for napi_complete(), this isn't a problem
320 * since efx_channel_processed() will have no effect if
321 * interrupts have already been disabled.
324 efx_channel_processed(channel
);
330 /* Process the eventq of the specified channel immediately on this CPU
332 * Disable hardware generated interrupts, wait for any existing
333 * processing to finish, then directly poll (and ack ) the eventq.
334 * Finally reenable NAPI and interrupts.
336 * This is for use only during a loopback self-test. It must not
337 * deliver any packets up the stack as this can result in deadlock.
339 void efx_process_channel_now(struct efx_channel
*channel
)
341 struct efx_nic
*efx
= channel
->efx
;
343 BUG_ON(channel
->channel
>= efx
->n_channels
);
344 BUG_ON(!channel
->enabled
);
345 BUG_ON(!efx
->loopback_selftest
);
347 /* Disable interrupts and wait for ISRs to complete */
348 efx_nic_disable_interrupts(efx
);
349 if (efx
->legacy_irq
) {
350 synchronize_irq(efx
->legacy_irq
);
351 efx
->legacy_irq_enabled
= false;
354 synchronize_irq(channel
->irq
);
356 /* Wait for any NAPI processing to complete */
357 napi_disable(&channel
->napi_str
);
359 /* Poll the channel */
360 efx_process_channel(channel
, channel
->eventq_mask
+ 1);
362 /* Ack the eventq. This may cause an interrupt to be generated
363 * when they are reenabled */
364 efx_channel_processed(channel
);
366 napi_enable(&channel
->napi_str
);
368 efx
->legacy_irq_enabled
= true;
369 efx_nic_enable_interrupts(efx
);
372 /* Create event queue
373 * Event queue memory allocations are done only once. If the channel
374 * is reset, the memory buffer will be reused; this guards against
375 * errors during channel reset and also simplifies interrupt handling.
377 static int efx_probe_eventq(struct efx_channel
*channel
)
379 struct efx_nic
*efx
= channel
->efx
;
380 unsigned long entries
;
382 netif_dbg(efx
, probe
, efx
->net_dev
,
383 "chan %d create event queue\n", channel
->channel
);
385 /* Build an event queue with room for one event per tx and rx buffer,
386 * plus some extra for link state events and MCDI completions. */
387 entries
= roundup_pow_of_two(efx
->rxq_entries
+ efx
->txq_entries
+ 128);
388 EFX_BUG_ON_PARANOID(entries
> EFX_MAX_EVQ_SIZE
);
389 channel
->eventq_mask
= max(entries
, EFX_MIN_EVQ_SIZE
) - 1;
391 return efx_nic_probe_eventq(channel
);
394 /* Prepare channel's event queue */
395 static void efx_init_eventq(struct efx_channel
*channel
)
397 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
398 "chan %d init event queue\n", channel
->channel
);
400 channel
->eventq_read_ptr
= 0;
402 efx_nic_init_eventq(channel
);
405 /* Enable event queue processing and NAPI */
406 static void efx_start_eventq(struct efx_channel
*channel
)
408 netif_dbg(channel
->efx
, ifup
, channel
->efx
->net_dev
,
409 "chan %d start event queue\n", channel
->channel
);
411 /* The interrupt handler for this channel may set work_pending
412 * as soon as we enable it. Make sure it's cleared before
413 * then. Similarly, make sure it sees the enabled flag set.
415 channel
->work_pending
= false;
416 channel
->enabled
= true;
419 napi_enable(&channel
->napi_str
);
420 efx_nic_eventq_read_ack(channel
);
423 /* Disable event queue processing and NAPI */
424 static void efx_stop_eventq(struct efx_channel
*channel
)
426 if (!channel
->enabled
)
429 napi_disable(&channel
->napi_str
);
430 channel
->enabled
= false;
433 static void efx_fini_eventq(struct efx_channel
*channel
)
435 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
436 "chan %d fini event queue\n", channel
->channel
);
438 efx_nic_fini_eventq(channel
);
441 static void efx_remove_eventq(struct efx_channel
*channel
)
443 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
444 "chan %d remove event queue\n", channel
->channel
);
446 efx_nic_remove_eventq(channel
);
449 /**************************************************************************
453 *************************************************************************/
455 /* Allocate and initialise a channel structure. */
456 static struct efx_channel
*
457 efx_alloc_channel(struct efx_nic
*efx
, int i
, struct efx_channel
*old_channel
)
459 struct efx_channel
*channel
;
460 struct efx_rx_queue
*rx_queue
;
461 struct efx_tx_queue
*tx_queue
;
464 channel
= kzalloc(sizeof(*channel
), GFP_KERNEL
);
469 channel
->channel
= i
;
470 channel
->type
= &efx_default_channel_type
;
472 for (j
= 0; j
< EFX_TXQ_TYPES
; j
++) {
473 tx_queue
= &channel
->tx_queue
[j
];
475 tx_queue
->queue
= i
* EFX_TXQ_TYPES
+ j
;
476 tx_queue
->channel
= channel
;
479 rx_queue
= &channel
->rx_queue
;
481 setup_timer(&rx_queue
->slow_fill
, efx_rx_slow_fill
,
482 (unsigned long)rx_queue
);
487 /* Allocate and initialise a channel structure, copying parameters
488 * (but not resources) from an old channel structure.
490 static struct efx_channel
*
491 efx_copy_channel(const struct efx_channel
*old_channel
)
493 struct efx_channel
*channel
;
494 struct efx_rx_queue
*rx_queue
;
495 struct efx_tx_queue
*tx_queue
;
498 channel
= kmalloc(sizeof(*channel
), GFP_KERNEL
);
502 *channel
= *old_channel
;
504 channel
->napi_dev
= NULL
;
505 memset(&channel
->eventq
, 0, sizeof(channel
->eventq
));
507 for (j
= 0; j
< EFX_TXQ_TYPES
; j
++) {
508 tx_queue
= &channel
->tx_queue
[j
];
509 if (tx_queue
->channel
)
510 tx_queue
->channel
= channel
;
511 tx_queue
->buffer
= NULL
;
512 memset(&tx_queue
->txd
, 0, sizeof(tx_queue
->txd
));
515 rx_queue
= &channel
->rx_queue
;
516 rx_queue
->buffer
= NULL
;
517 memset(&rx_queue
->rxd
, 0, sizeof(rx_queue
->rxd
));
518 setup_timer(&rx_queue
->slow_fill
, efx_rx_slow_fill
,
519 (unsigned long)rx_queue
);
524 static int efx_probe_channel(struct efx_channel
*channel
)
526 struct efx_tx_queue
*tx_queue
;
527 struct efx_rx_queue
*rx_queue
;
530 netif_dbg(channel
->efx
, probe
, channel
->efx
->net_dev
,
531 "creating channel %d\n", channel
->channel
);
533 rc
= channel
->type
->pre_probe(channel
);
537 rc
= efx_probe_eventq(channel
);
541 efx_for_each_channel_tx_queue(tx_queue
, channel
) {
542 rc
= efx_probe_tx_queue(tx_queue
);
547 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
548 rc
= efx_probe_rx_queue(rx_queue
);
553 channel
->n_rx_frm_trunc
= 0;
558 efx_remove_channel(channel
);
563 efx_get_channel_name(struct efx_channel
*channel
, char *buf
, size_t len
)
565 struct efx_nic
*efx
= channel
->efx
;
569 number
= channel
->channel
;
570 if (efx
->tx_channel_offset
== 0) {
572 } else if (channel
->channel
< efx
->tx_channel_offset
) {
576 number
-= efx
->tx_channel_offset
;
578 snprintf(buf
, len
, "%s%s-%d", efx
->name
, type
, number
);
581 static void efx_set_channel_names(struct efx_nic
*efx
)
583 struct efx_channel
*channel
;
585 efx_for_each_channel(channel
, efx
)
586 channel
->type
->get_name(channel
,
587 efx
->channel_name
[channel
->channel
],
588 sizeof(efx
->channel_name
[0]));
591 static int efx_probe_channels(struct efx_nic
*efx
)
593 struct efx_channel
*channel
;
596 /* Restart special buffer allocation */
597 efx
->next_buffer_table
= 0;
599 /* Probe channels in reverse, so that any 'extra' channels
600 * use the start of the buffer table. This allows the traffic
601 * channels to be resized without moving them or wasting the
602 * entries before them.
604 efx_for_each_channel_rev(channel
, efx
) {
605 rc
= efx_probe_channel(channel
);
607 netif_err(efx
, probe
, efx
->net_dev
,
608 "failed to create channel %d\n",
613 efx_set_channel_names(efx
);
618 efx_remove_channels(efx
);
622 /* Channels are shutdown and reinitialised whilst the NIC is running
623 * to propagate configuration changes (mtu, checksum offload), or
624 * to clear hardware error conditions
626 static void efx_start_datapath(struct efx_nic
*efx
)
628 bool old_rx_scatter
= efx
->rx_scatter
;
629 struct efx_tx_queue
*tx_queue
;
630 struct efx_rx_queue
*rx_queue
;
631 struct efx_channel
*channel
;
634 /* Calculate the rx buffer allocation parameters required to
635 * support the current MTU, including padding for header
636 * alignment and overruns.
638 efx
->rx_dma_len
= (efx
->type
->rx_buffer_hash_size
+
639 EFX_MAX_FRAME_LEN(efx
->net_dev
->mtu
) +
640 efx
->type
->rx_buffer_padding
);
641 rx_buf_len
= (sizeof(struct efx_rx_page_state
) +
642 EFX_PAGE_IP_ALIGN
+ efx
->rx_dma_len
);
643 if (rx_buf_len
<= PAGE_SIZE
) {
644 efx
->rx_scatter
= false;
645 efx
->rx_buffer_order
= 0;
646 if (rx_buf_len
<= PAGE_SIZE
/ 2)
647 efx
->rx_buffer_truesize
= PAGE_SIZE
/ 2;
649 efx
->rx_buffer_truesize
= PAGE_SIZE
;
650 } else if (efx
->type
->can_rx_scatter
) {
651 BUILD_BUG_ON(sizeof(struct efx_rx_page_state
) +
652 EFX_PAGE_IP_ALIGN
+ EFX_RX_USR_BUF_SIZE
>
654 efx
->rx_scatter
= true;
655 efx
->rx_dma_len
= EFX_RX_USR_BUF_SIZE
;
656 efx
->rx_buffer_order
= 0;
657 efx
->rx_buffer_truesize
= PAGE_SIZE
/ 2;
659 efx
->rx_scatter
= false;
660 efx
->rx_buffer_order
= get_order(rx_buf_len
);
661 efx
->rx_buffer_truesize
= PAGE_SIZE
<< efx
->rx_buffer_order
;
664 /* RX filters also have scatter-enabled flags */
665 if (efx
->rx_scatter
!= old_rx_scatter
)
666 efx_filter_update_rx_scatter(efx
);
668 /* We must keep at least one descriptor in a TX ring empty.
669 * We could avoid this when the queue size does not exactly
670 * match the hardware ring size, but it's not that important.
671 * Therefore we stop the queue when one more skb might fill
672 * the ring completely. We wake it when half way back to
675 efx
->txq_stop_thresh
= efx
->txq_entries
- efx_tx_max_skb_descs(efx
);
676 efx
->txq_wake_thresh
= efx
->txq_stop_thresh
/ 2;
678 /* Initialise the channels */
679 efx_for_each_channel(channel
, efx
) {
680 efx_for_each_channel_tx_queue(tx_queue
, channel
)
681 efx_init_tx_queue(tx_queue
);
683 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
684 efx_init_rx_queue(rx_queue
);
685 efx_nic_generate_fill_event(rx_queue
);
688 WARN_ON(channel
->rx_pkt_n_frags
);
691 if (netif_device_present(efx
->net_dev
))
692 netif_tx_wake_all_queues(efx
->net_dev
);
695 static void efx_stop_datapath(struct efx_nic
*efx
)
697 struct efx_channel
*channel
;
698 struct efx_tx_queue
*tx_queue
;
699 struct efx_rx_queue
*rx_queue
;
700 struct pci_dev
*dev
= efx
->pci_dev
;
703 EFX_ASSERT_RESET_SERIALISED(efx
);
704 BUG_ON(efx
->port_enabled
);
706 /* Only perform flush if dma is enabled */
707 if (dev
->is_busmaster
&& efx
->state
!= STATE_RECOVERY
) {
708 rc
= efx_nic_flush_queues(efx
);
710 if (rc
&& EFX_WORKAROUND_7803(efx
)) {
711 /* Schedule a reset to recover from the flush failure. The
712 * descriptor caches reference memory we're about to free,
713 * but falcon_reconfigure_mac_wrapper() won't reconnect
714 * the MACs because of the pending reset. */
715 netif_err(efx
, drv
, efx
->net_dev
,
716 "Resetting to recover from flush failure\n");
717 efx_schedule_reset(efx
, RESET_TYPE_ALL
);
719 netif_err(efx
, drv
, efx
->net_dev
, "failed to flush queues\n");
721 netif_dbg(efx
, drv
, efx
->net_dev
,
722 "successfully flushed all queues\n");
726 efx_for_each_channel(channel
, efx
) {
727 /* RX packet processing is pipelined, so wait for the
728 * NAPI handler to complete. At least event queue 0
729 * might be kept active by non-data events, so don't
730 * use napi_synchronize() but actually disable NAPI
733 if (efx_channel_has_rx_queue(channel
)) {
734 efx_stop_eventq(channel
);
735 efx_start_eventq(channel
);
738 efx_for_each_channel_rx_queue(rx_queue
, channel
)
739 efx_fini_rx_queue(rx_queue
);
740 efx_for_each_possible_channel_tx_queue(tx_queue
, channel
)
741 efx_fini_tx_queue(tx_queue
);
745 static void efx_remove_channel(struct efx_channel
*channel
)
747 struct efx_tx_queue
*tx_queue
;
748 struct efx_rx_queue
*rx_queue
;
750 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
751 "destroy chan %d\n", channel
->channel
);
753 efx_for_each_channel_rx_queue(rx_queue
, channel
)
754 efx_remove_rx_queue(rx_queue
);
755 efx_for_each_possible_channel_tx_queue(tx_queue
, channel
)
756 efx_remove_tx_queue(tx_queue
);
757 efx_remove_eventq(channel
);
758 channel
->type
->post_remove(channel
);
761 static void efx_remove_channels(struct efx_nic
*efx
)
763 struct efx_channel
*channel
;
765 efx_for_each_channel(channel
, efx
)
766 efx_remove_channel(channel
);
770 efx_realloc_channels(struct efx_nic
*efx
, u32 rxq_entries
, u32 txq_entries
)
772 struct efx_channel
*other_channel
[EFX_MAX_CHANNELS
], *channel
;
773 u32 old_rxq_entries
, old_txq_entries
;
774 unsigned i
, next_buffer_table
= 0;
777 rc
= efx_check_disabled(efx
);
781 /* Not all channels should be reallocated. We must avoid
782 * reallocating their buffer table entries.
784 efx_for_each_channel(channel
, efx
) {
785 struct efx_rx_queue
*rx_queue
;
786 struct efx_tx_queue
*tx_queue
;
788 if (channel
->type
->copy
)
790 next_buffer_table
= max(next_buffer_table
,
791 channel
->eventq
.index
+
792 channel
->eventq
.entries
);
793 efx_for_each_channel_rx_queue(rx_queue
, channel
)
794 next_buffer_table
= max(next_buffer_table
,
795 rx_queue
->rxd
.index
+
796 rx_queue
->rxd
.entries
);
797 efx_for_each_channel_tx_queue(tx_queue
, channel
)
798 next_buffer_table
= max(next_buffer_table
,
799 tx_queue
->txd
.index
+
800 tx_queue
->txd
.entries
);
803 efx_device_detach_sync(efx
);
805 efx_stop_interrupts(efx
, true);
807 /* Clone channels (where possible) */
808 memset(other_channel
, 0, sizeof(other_channel
));
809 for (i
= 0; i
< efx
->n_channels
; i
++) {
810 channel
= efx
->channel
[i
];
811 if (channel
->type
->copy
)
812 channel
= channel
->type
->copy(channel
);
817 other_channel
[i
] = channel
;
820 /* Swap entry counts and channel pointers */
821 old_rxq_entries
= efx
->rxq_entries
;
822 old_txq_entries
= efx
->txq_entries
;
823 efx
->rxq_entries
= rxq_entries
;
824 efx
->txq_entries
= txq_entries
;
825 for (i
= 0; i
< efx
->n_channels
; i
++) {
826 channel
= efx
->channel
[i
];
827 efx
->channel
[i
] = other_channel
[i
];
828 other_channel
[i
] = channel
;
831 /* Restart buffer table allocation */
832 efx
->next_buffer_table
= next_buffer_table
;
834 for (i
= 0; i
< efx
->n_channels
; i
++) {
835 channel
= efx
->channel
[i
];
836 if (!channel
->type
->copy
)
838 rc
= efx_probe_channel(channel
);
841 efx_init_napi_channel(efx
->channel
[i
]);
845 /* Destroy unused channel structures */
846 for (i
= 0; i
< efx
->n_channels
; i
++) {
847 channel
= other_channel
[i
];
848 if (channel
&& channel
->type
->copy
) {
849 efx_fini_napi_channel(channel
);
850 efx_remove_channel(channel
);
855 efx_start_interrupts(efx
, true);
857 netif_device_attach(efx
->net_dev
);
862 efx
->rxq_entries
= old_rxq_entries
;
863 efx
->txq_entries
= old_txq_entries
;
864 for (i
= 0; i
< efx
->n_channels
; i
++) {
865 channel
= efx
->channel
[i
];
866 efx
->channel
[i
] = other_channel
[i
];
867 other_channel
[i
] = channel
;
872 void efx_schedule_slow_fill(struct efx_rx_queue
*rx_queue
)
874 mod_timer(&rx_queue
->slow_fill
, jiffies
+ msecs_to_jiffies(100));
877 static const struct efx_channel_type efx_default_channel_type
= {
878 .pre_probe
= efx_channel_dummy_op_int
,
879 .post_remove
= efx_channel_dummy_op_void
,
880 .get_name
= efx_get_channel_name
,
881 .copy
= efx_copy_channel
,
882 .keep_eventq
= false,
885 int efx_channel_dummy_op_int(struct efx_channel
*channel
)
890 void efx_channel_dummy_op_void(struct efx_channel
*channel
)
894 /**************************************************************************
898 **************************************************************************/
900 /* This ensures that the kernel is kept informed (via
901 * netif_carrier_on/off) of the link status, and also maintains the
902 * link status's stop on the port's TX queue.
904 void efx_link_status_changed(struct efx_nic
*efx
)
906 struct efx_link_state
*link_state
= &efx
->link_state
;
908 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
909 * that no events are triggered between unregister_netdev() and the
910 * driver unloading. A more general condition is that NETDEV_CHANGE
911 * can only be generated between NETDEV_UP and NETDEV_DOWN */
912 if (!netif_running(efx
->net_dev
))
915 if (link_state
->up
!= netif_carrier_ok(efx
->net_dev
)) {
916 efx
->n_link_state_changes
++;
919 netif_carrier_on(efx
->net_dev
);
921 netif_carrier_off(efx
->net_dev
);
924 /* Status message for kernel log */
926 netif_info(efx
, link
, efx
->net_dev
,
927 "link up at %uMbps %s-duplex (MTU %d)%s\n",
928 link_state
->speed
, link_state
->fd
? "full" : "half",
930 (efx
->promiscuous
? " [PROMISC]" : ""));
932 netif_info(efx
, link
, efx
->net_dev
, "link down\n");
935 void efx_link_set_advertising(struct efx_nic
*efx
, u32 advertising
)
937 efx
->link_advertising
= advertising
;
939 if (advertising
& ADVERTISED_Pause
)
940 efx
->wanted_fc
|= (EFX_FC_TX
| EFX_FC_RX
);
942 efx
->wanted_fc
&= ~(EFX_FC_TX
| EFX_FC_RX
);
943 if (advertising
& ADVERTISED_Asym_Pause
)
944 efx
->wanted_fc
^= EFX_FC_TX
;
948 void efx_link_set_wanted_fc(struct efx_nic
*efx
, u8 wanted_fc
)
950 efx
->wanted_fc
= wanted_fc
;
951 if (efx
->link_advertising
) {
952 if (wanted_fc
& EFX_FC_RX
)
953 efx
->link_advertising
|= (ADVERTISED_Pause
|
954 ADVERTISED_Asym_Pause
);
956 efx
->link_advertising
&= ~(ADVERTISED_Pause
|
957 ADVERTISED_Asym_Pause
);
958 if (wanted_fc
& EFX_FC_TX
)
959 efx
->link_advertising
^= ADVERTISED_Asym_Pause
;
963 static void efx_fini_port(struct efx_nic
*efx
);
965 /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
966 * the MAC appropriately. All other PHY configuration changes are pushed
967 * through phy_op->set_settings(), and pushed asynchronously to the MAC
968 * through efx_monitor().
970 * Callers must hold the mac_lock
972 int __efx_reconfigure_port(struct efx_nic
*efx
)
974 enum efx_phy_mode phy_mode
;
977 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
979 /* Serialise the promiscuous flag with efx_set_rx_mode. */
980 netif_addr_lock_bh(efx
->net_dev
);
981 netif_addr_unlock_bh(efx
->net_dev
);
983 /* Disable PHY transmit in mac level loopbacks */
984 phy_mode
= efx
->phy_mode
;
985 if (LOOPBACK_INTERNAL(efx
))
986 efx
->phy_mode
|= PHY_MODE_TX_DISABLED
;
988 efx
->phy_mode
&= ~PHY_MODE_TX_DISABLED
;
990 rc
= efx
->type
->reconfigure_port(efx
);
993 efx
->phy_mode
= phy_mode
;
998 /* Reinitialise the MAC to pick up new PHY settings, even if the port is
1000 int efx_reconfigure_port(struct efx_nic
*efx
)
1004 EFX_ASSERT_RESET_SERIALISED(efx
);
1006 mutex_lock(&efx
->mac_lock
);
1007 rc
= __efx_reconfigure_port(efx
);
1008 mutex_unlock(&efx
->mac_lock
);
1013 /* Asynchronous work item for changing MAC promiscuity and multicast
1014 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
1016 static void efx_mac_work(struct work_struct
*data
)
1018 struct efx_nic
*efx
= container_of(data
, struct efx_nic
, mac_work
);
1020 mutex_lock(&efx
->mac_lock
);
1021 if (efx
->port_enabled
)
1022 efx
->type
->reconfigure_mac(efx
);
1023 mutex_unlock(&efx
->mac_lock
);
1026 static int efx_probe_port(struct efx_nic
*efx
)
1030 netif_dbg(efx
, probe
, efx
->net_dev
, "create port\n");
1033 efx
->phy_mode
= PHY_MODE_SPECIAL
;
1035 /* Connect up MAC/PHY operations table */
1036 rc
= efx
->type
->probe_port(efx
);
1040 /* Initialise MAC address to permanent address */
1041 memcpy(efx
->net_dev
->dev_addr
, efx
->net_dev
->perm_addr
, ETH_ALEN
);
1046 static int efx_init_port(struct efx_nic
*efx
)
1050 netif_dbg(efx
, drv
, efx
->net_dev
, "init port\n");
1052 mutex_lock(&efx
->mac_lock
);
1054 rc
= efx
->phy_op
->init(efx
);
1058 efx
->port_initialized
= true;
1060 /* Reconfigure the MAC before creating dma queues (required for
1061 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
1062 efx
->type
->reconfigure_mac(efx
);
1064 /* Ensure the PHY advertises the correct flow control settings */
1065 rc
= efx
->phy_op
->reconfigure(efx
);
1069 mutex_unlock(&efx
->mac_lock
);
1073 efx
->phy_op
->fini(efx
);
1075 mutex_unlock(&efx
->mac_lock
);
1079 static void efx_start_port(struct efx_nic
*efx
)
1081 netif_dbg(efx
, ifup
, efx
->net_dev
, "start port\n");
1082 BUG_ON(efx
->port_enabled
);
1084 mutex_lock(&efx
->mac_lock
);
1085 efx
->port_enabled
= true;
1087 /* efx_mac_work() might have been scheduled after efx_stop_port(),
1088 * and then cancelled by efx_flush_all() */
1089 efx
->type
->reconfigure_mac(efx
);
1091 mutex_unlock(&efx
->mac_lock
);
1094 /* Prevent efx_mac_work() and efx_monitor() from working */
1095 static void efx_stop_port(struct efx_nic
*efx
)
1097 netif_dbg(efx
, ifdown
, efx
->net_dev
, "stop port\n");
1099 mutex_lock(&efx
->mac_lock
);
1100 efx
->port_enabled
= false;
1101 mutex_unlock(&efx
->mac_lock
);
1103 /* Serialise against efx_set_multicast_list() */
1104 netif_addr_lock_bh(efx
->net_dev
);
1105 netif_addr_unlock_bh(efx
->net_dev
);
1108 static void efx_fini_port(struct efx_nic
*efx
)
1110 netif_dbg(efx
, drv
, efx
->net_dev
, "shut down port\n");
1112 if (!efx
->port_initialized
)
1115 efx
->phy_op
->fini(efx
);
1116 efx
->port_initialized
= false;
1118 efx
->link_state
.up
= false;
1119 efx_link_status_changed(efx
);
1122 static void efx_remove_port(struct efx_nic
*efx
)
1124 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying port\n");
1126 efx
->type
->remove_port(efx
);
1129 /**************************************************************************
1133 **************************************************************************/
1135 /* This configures the PCI device to enable I/O and DMA. */
1136 static int efx_init_io(struct efx_nic
*efx
)
1138 struct pci_dev
*pci_dev
= efx
->pci_dev
;
1139 dma_addr_t dma_mask
= efx
->type
->max_dma_mask
;
1142 netif_dbg(efx
, probe
, efx
->net_dev
, "initialising I/O\n");
1144 rc
= pci_enable_device(pci_dev
);
1146 netif_err(efx
, probe
, efx
->net_dev
,
1147 "failed to enable PCI device\n");
1151 pci_set_master(pci_dev
);
1153 /* Set the PCI DMA mask. Try all possibilities from our
1154 * genuine mask down to 32 bits, because some architectures
1155 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1156 * masks event though they reject 46 bit masks.
1158 while (dma_mask
> 0x7fffffffUL
) {
1159 if (dma_supported(&pci_dev
->dev
, dma_mask
)) {
1160 rc
= dma_set_mask(&pci_dev
->dev
, dma_mask
);
1167 netif_err(efx
, probe
, efx
->net_dev
,
1168 "could not find a suitable DMA mask\n");
1171 netif_dbg(efx
, probe
, efx
->net_dev
,
1172 "using DMA mask %llx\n", (unsigned long long) dma_mask
);
1173 rc
= dma_set_coherent_mask(&pci_dev
->dev
, dma_mask
);
1175 /* dma_set_coherent_mask() is not *allowed* to
1176 * fail with a mask that dma_set_mask() accepted,
1177 * but just in case...
1179 netif_err(efx
, probe
, efx
->net_dev
,
1180 "failed to set consistent DMA mask\n");
1184 efx
->membase_phys
= pci_resource_start(efx
->pci_dev
, EFX_MEM_BAR
);
1185 rc
= pci_request_region(pci_dev
, EFX_MEM_BAR
, "sfc");
1187 netif_err(efx
, probe
, efx
->net_dev
,
1188 "request for memory BAR failed\n");
1192 efx
->membase
= ioremap_nocache(efx
->membase_phys
,
1193 efx
->type
->mem_map_size
);
1194 if (!efx
->membase
) {
1195 netif_err(efx
, probe
, efx
->net_dev
,
1196 "could not map memory BAR at %llx+%x\n",
1197 (unsigned long long)efx
->membase_phys
,
1198 efx
->type
->mem_map_size
);
1202 netif_dbg(efx
, probe
, efx
->net_dev
,
1203 "memory BAR at %llx+%x (virtual %p)\n",
1204 (unsigned long long)efx
->membase_phys
,
1205 efx
->type
->mem_map_size
, efx
->membase
);
1210 pci_release_region(efx
->pci_dev
, EFX_MEM_BAR
);
1212 efx
->membase_phys
= 0;
1214 pci_disable_device(efx
->pci_dev
);
1219 static void efx_fini_io(struct efx_nic
*efx
)
1221 netif_dbg(efx
, drv
, efx
->net_dev
, "shutting down I/O\n");
1224 iounmap(efx
->membase
);
1225 efx
->membase
= NULL
;
1228 if (efx
->membase_phys
) {
1229 pci_release_region(efx
->pci_dev
, EFX_MEM_BAR
);
1230 efx
->membase_phys
= 0;
1233 pci_disable_device(efx
->pci_dev
);
1236 static unsigned int efx_wanted_parallelism(struct efx_nic
*efx
)
1238 cpumask_var_t thread_mask
;
1245 if (unlikely(!zalloc_cpumask_var(&thread_mask
, GFP_KERNEL
))) {
1246 netif_warn(efx
, probe
, efx
->net_dev
,
1247 "RSS disabled due to allocation failure\n");
1252 for_each_online_cpu(cpu
) {
1253 if (!cpumask_test_cpu(cpu
, thread_mask
)) {
1255 cpumask_or(thread_mask
, thread_mask
,
1256 topology_thread_cpumask(cpu
));
1260 free_cpumask_var(thread_mask
);
1263 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1264 * table entries that are inaccessible to VFs
1266 if (efx_sriov_wanted(efx
) && efx_vf_size(efx
) > 1 &&
1267 count
> efx_vf_size(efx
)) {
1268 netif_warn(efx
, probe
, efx
->net_dev
,
1269 "Reducing number of RSS channels from %u to %u for "
1270 "VF support. Increase vf-msix-limit to use more "
1271 "channels on the PF.\n",
1272 count
, efx_vf_size(efx
));
1273 count
= efx_vf_size(efx
);
1280 efx_init_rx_cpu_rmap(struct efx_nic
*efx
, struct msix_entry
*xentries
)
1282 #ifdef CONFIG_RFS_ACCEL
1286 efx
->net_dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(efx
->n_rx_channels
);
1287 if (!efx
->net_dev
->rx_cpu_rmap
)
1289 for (i
= 0; i
< efx
->n_rx_channels
; i
++) {
1290 rc
= irq_cpu_rmap_add(efx
->net_dev
->rx_cpu_rmap
,
1291 xentries
[i
].vector
);
1293 free_irq_cpu_rmap(efx
->net_dev
->rx_cpu_rmap
);
1294 efx
->net_dev
->rx_cpu_rmap
= NULL
;
1302 /* Probe the number and type of interrupts we are able to obtain, and
1303 * the resulting numbers of channels and RX queues.
1305 static int efx_probe_interrupts(struct efx_nic
*efx
)
1307 unsigned int max_channels
=
1308 min(efx
->type
->phys_addr_channels
, EFX_MAX_CHANNELS
);
1309 unsigned int extra_channels
= 0;
1313 for (i
= 0; i
< EFX_MAX_EXTRA_CHANNELS
; i
++)
1314 if (efx
->extra_channel_type
[i
])
1317 if (efx
->interrupt_mode
== EFX_INT_MODE_MSIX
) {
1318 struct msix_entry xentries
[EFX_MAX_CHANNELS
];
1319 unsigned int n_channels
;
1321 n_channels
= efx_wanted_parallelism(efx
);
1322 if (separate_tx_channels
)
1324 n_channels
+= extra_channels
;
1325 n_channels
= min(n_channels
, max_channels
);
1327 for (i
= 0; i
< n_channels
; i
++)
1328 xentries
[i
].entry
= i
;
1329 rc
= pci_enable_msix(efx
->pci_dev
, xentries
, n_channels
);
1331 netif_err(efx
, drv
, efx
->net_dev
,
1332 "WARNING: Insufficient MSI-X vectors"
1333 " available (%d < %u).\n", rc
, n_channels
);
1334 netif_err(efx
, drv
, efx
->net_dev
,
1335 "WARNING: Performance may be reduced.\n");
1336 EFX_BUG_ON_PARANOID(rc
>= n_channels
);
1338 rc
= pci_enable_msix(efx
->pci_dev
, xentries
,
1343 efx
->n_channels
= n_channels
;
1344 if (n_channels
> extra_channels
)
1345 n_channels
-= extra_channels
;
1346 if (separate_tx_channels
) {
1347 efx
->n_tx_channels
= max(n_channels
/ 2, 1U);
1348 efx
->n_rx_channels
= max(n_channels
-
1352 efx
->n_tx_channels
= n_channels
;
1353 efx
->n_rx_channels
= n_channels
;
1355 rc
= efx_init_rx_cpu_rmap(efx
, xentries
);
1357 pci_disable_msix(efx
->pci_dev
);
1360 for (i
= 0; i
< efx
->n_channels
; i
++)
1361 efx_get_channel(efx
, i
)->irq
=
1364 /* Fall back to single channel MSI */
1365 efx
->interrupt_mode
= EFX_INT_MODE_MSI
;
1366 netif_err(efx
, drv
, efx
->net_dev
,
1367 "could not enable MSI-X\n");
1371 /* Try single interrupt MSI */
1372 if (efx
->interrupt_mode
== EFX_INT_MODE_MSI
) {
1373 efx
->n_channels
= 1;
1374 efx
->n_rx_channels
= 1;
1375 efx
->n_tx_channels
= 1;
1376 rc
= pci_enable_msi(efx
->pci_dev
);
1378 efx_get_channel(efx
, 0)->irq
= efx
->pci_dev
->irq
;
1380 netif_err(efx
, drv
, efx
->net_dev
,
1381 "could not enable MSI\n");
1382 efx
->interrupt_mode
= EFX_INT_MODE_LEGACY
;
1386 /* Assume legacy interrupts */
1387 if (efx
->interrupt_mode
== EFX_INT_MODE_LEGACY
) {
1388 efx
->n_channels
= 1 + (separate_tx_channels
? 1 : 0);
1389 efx
->n_rx_channels
= 1;
1390 efx
->n_tx_channels
= 1;
1391 efx
->legacy_irq
= efx
->pci_dev
->irq
;
1394 /* Assign extra channels if possible */
1395 j
= efx
->n_channels
;
1396 for (i
= 0; i
< EFX_MAX_EXTRA_CHANNELS
; i
++) {
1397 if (!efx
->extra_channel_type
[i
])
1399 if (efx
->interrupt_mode
!= EFX_INT_MODE_MSIX
||
1400 efx
->n_channels
<= extra_channels
) {
1401 efx
->extra_channel_type
[i
]->handle_no_channel(efx
);
1404 efx_get_channel(efx
, j
)->type
=
1405 efx
->extra_channel_type
[i
];
1409 /* RSS might be usable on VFs even if it is disabled on the PF */
1410 efx
->rss_spread
= ((efx
->n_rx_channels
> 1 || !efx_sriov_wanted(efx
)) ?
1411 efx
->n_rx_channels
: efx_vf_size(efx
));
1416 /* Enable interrupts, then probe and start the event queues */
1417 static void efx_start_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
)
1419 struct efx_channel
*channel
;
1421 BUG_ON(efx
->state
== STATE_DISABLED
);
1423 if (efx
->legacy_irq
)
1424 efx
->legacy_irq_enabled
= true;
1425 efx_nic_enable_interrupts(efx
);
1427 efx_for_each_channel(channel
, efx
) {
1428 if (!channel
->type
->keep_eventq
|| !may_keep_eventq
)
1429 efx_init_eventq(channel
);
1430 efx_start_eventq(channel
);
1433 efx_mcdi_mode_event(efx
);
1436 static void efx_stop_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
)
1438 struct efx_channel
*channel
;
1440 if (efx
->state
== STATE_DISABLED
)
1443 efx_mcdi_mode_poll(efx
);
1445 efx_nic_disable_interrupts(efx
);
1446 if (efx
->legacy_irq
) {
1447 synchronize_irq(efx
->legacy_irq
);
1448 efx
->legacy_irq_enabled
= false;
1451 efx_for_each_channel(channel
, efx
) {
1453 synchronize_irq(channel
->irq
);
1455 efx_stop_eventq(channel
);
1456 if (!channel
->type
->keep_eventq
|| !may_keep_eventq
)
1457 efx_fini_eventq(channel
);
1461 static void efx_remove_interrupts(struct efx_nic
*efx
)
1463 struct efx_channel
*channel
;
1465 /* Remove MSI/MSI-X interrupts */
1466 efx_for_each_channel(channel
, efx
)
1468 pci_disable_msi(efx
->pci_dev
);
1469 pci_disable_msix(efx
->pci_dev
);
1471 /* Remove legacy interrupt */
1472 efx
->legacy_irq
= 0;
1475 static void efx_set_channels(struct efx_nic
*efx
)
1477 struct efx_channel
*channel
;
1478 struct efx_tx_queue
*tx_queue
;
1480 efx
->tx_channel_offset
=
1481 separate_tx_channels
? efx
->n_channels
- efx
->n_tx_channels
: 0;
1483 /* We need to mark which channels really have RX and TX
1484 * queues, and adjust the TX queue numbers if we have separate
1485 * RX-only and TX-only channels.
1487 efx_for_each_channel(channel
, efx
) {
1488 if (channel
->channel
< efx
->n_rx_channels
)
1489 channel
->rx_queue
.core_index
= channel
->channel
;
1491 channel
->rx_queue
.core_index
= -1;
1493 efx_for_each_channel_tx_queue(tx_queue
, channel
)
1494 tx_queue
->queue
-= (efx
->tx_channel_offset
*
1499 static int efx_probe_nic(struct efx_nic
*efx
)
1504 netif_dbg(efx
, probe
, efx
->net_dev
, "creating NIC\n");
1506 /* Carry out hardware-type specific initialisation */
1507 rc
= efx
->type
->probe(efx
);
1511 /* Determine the number of channels and queues by trying to hook
1512 * in MSI-X interrupts. */
1513 rc
= efx_probe_interrupts(efx
);
1517 efx
->type
->dimension_resources(efx
);
1519 if (efx
->n_channels
> 1)
1520 get_random_bytes(&efx
->rx_hash_key
, sizeof(efx
->rx_hash_key
));
1521 for (i
= 0; i
< ARRAY_SIZE(efx
->rx_indir_table
); i
++)
1522 efx
->rx_indir_table
[i
] =
1523 ethtool_rxfh_indir_default(i
, efx
->rss_spread
);
1525 efx_set_channels(efx
);
1526 netif_set_real_num_tx_queues(efx
->net_dev
, efx
->n_tx_channels
);
1527 netif_set_real_num_rx_queues(efx
->net_dev
, efx
->n_rx_channels
);
1529 /* Initialise the interrupt moderation settings */
1530 efx_init_irq_moderation(efx
, tx_irq_mod_usec
, rx_irq_mod_usec
, true,
1536 efx
->type
->remove(efx
);
1540 static void efx_remove_nic(struct efx_nic
*efx
)
1542 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying NIC\n");
1544 efx_remove_interrupts(efx
);
1545 efx
->type
->remove(efx
);
1548 /**************************************************************************
1550 * NIC startup/shutdown
1552 *************************************************************************/
1554 static int efx_probe_all(struct efx_nic
*efx
)
1558 rc
= efx_probe_nic(efx
);
1560 netif_err(efx
, probe
, efx
->net_dev
, "failed to create NIC\n");
1564 rc
= efx_probe_port(efx
);
1566 netif_err(efx
, probe
, efx
->net_dev
, "failed to create port\n");
1570 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_RXQ_MIN_ENT
);
1571 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_TXQ_MIN_ENT(efx
))) {
1575 efx
->rxq_entries
= efx
->txq_entries
= EFX_DEFAULT_DMAQ_SIZE
;
1577 rc
= efx_probe_filters(efx
);
1579 netif_err(efx
, probe
, efx
->net_dev
,
1580 "failed to create filter tables\n");
1584 rc
= efx_probe_channels(efx
);
1591 efx_remove_filters(efx
);
1593 efx_remove_port(efx
);
1595 efx_remove_nic(efx
);
1600 /* If the interface is supposed to be running but is not, start
1601 * the hardware and software data path, regular activity for the port
1602 * (MAC statistics, link polling, etc.) and schedule the port to be
1603 * reconfigured. Interrupts must already be enabled. This function
1604 * is safe to call multiple times, so long as the NIC is not disabled.
1605 * Requires the RTNL lock.
1607 static void efx_start_all(struct efx_nic
*efx
)
1609 EFX_ASSERT_RESET_SERIALISED(efx
);
1610 BUG_ON(efx
->state
== STATE_DISABLED
);
1612 /* Check that it is appropriate to restart the interface. All
1613 * of these flags are safe to read under just the rtnl lock */
1614 if (efx
->port_enabled
|| !netif_running(efx
->net_dev
))
1617 efx_start_port(efx
);
1618 efx_start_datapath(efx
);
1620 /* Start the hardware monitor if there is one */
1621 if (efx
->type
->monitor
!= NULL
)
1622 queue_delayed_work(efx
->workqueue
, &efx
->monitor_work
,
1623 efx_monitor_interval
);
1625 /* If link state detection is normally event-driven, we have
1626 * to poll now because we could have missed a change
1628 if (efx_nic_rev(efx
) >= EFX_REV_SIENA_A0
) {
1629 mutex_lock(&efx
->mac_lock
);
1630 if (efx
->phy_op
->poll(efx
))
1631 efx_link_status_changed(efx
);
1632 mutex_unlock(&efx
->mac_lock
);
1635 efx
->type
->start_stats(efx
);
1638 /* Flush all delayed work. Should only be called when no more delayed work
1639 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1640 * since we're holding the rtnl_lock at this point. */
1641 static void efx_flush_all(struct efx_nic
*efx
)
1643 /* Make sure the hardware monitor and event self-test are stopped */
1644 cancel_delayed_work_sync(&efx
->monitor_work
);
1645 efx_selftest_async_cancel(efx
);
1646 /* Stop scheduled port reconfigurations */
1647 cancel_work_sync(&efx
->mac_work
);
1650 /* Quiesce the hardware and software data path, and regular activity
1651 * for the port without bringing the link down. Safe to call multiple
1652 * times with the NIC in almost any state, but interrupts should be
1653 * enabled. Requires the RTNL lock.
1655 static void efx_stop_all(struct efx_nic
*efx
)
1657 EFX_ASSERT_RESET_SERIALISED(efx
);
1659 /* port_enabled can be read safely under the rtnl lock */
1660 if (!efx
->port_enabled
)
1663 efx
->type
->stop_stats(efx
);
1666 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
1669 /* Stop the kernel transmit interface. This is only valid if
1670 * the device is stopped or detached; otherwise the watchdog
1671 * may fire immediately.
1673 WARN_ON(netif_running(efx
->net_dev
) &&
1674 netif_device_present(efx
->net_dev
));
1675 netif_tx_disable(efx
->net_dev
);
1677 efx_stop_datapath(efx
);
1680 static void efx_remove_all(struct efx_nic
*efx
)
1682 efx_remove_channels(efx
);
1683 efx_remove_filters(efx
);
1684 efx_remove_port(efx
);
1685 efx_remove_nic(efx
);
1688 /**************************************************************************
1690 * Interrupt moderation
1692 **************************************************************************/
1694 static unsigned int irq_mod_ticks(unsigned int usecs
, unsigned int quantum_ns
)
1698 if (usecs
* 1000 < quantum_ns
)
1699 return 1; /* never round down to 0 */
1700 return usecs
* 1000 / quantum_ns
;
1703 /* Set interrupt moderation parameters */
1704 int efx_init_irq_moderation(struct efx_nic
*efx
, unsigned int tx_usecs
,
1705 unsigned int rx_usecs
, bool rx_adaptive
,
1706 bool rx_may_override_tx
)
1708 struct efx_channel
*channel
;
1709 unsigned int irq_mod_max
= DIV_ROUND_UP(efx
->type
->timer_period_max
*
1710 efx
->timer_quantum_ns
,
1712 unsigned int tx_ticks
;
1713 unsigned int rx_ticks
;
1715 EFX_ASSERT_RESET_SERIALISED(efx
);
1717 if (tx_usecs
> irq_mod_max
|| rx_usecs
> irq_mod_max
)
1720 tx_ticks
= irq_mod_ticks(tx_usecs
, efx
->timer_quantum_ns
);
1721 rx_ticks
= irq_mod_ticks(rx_usecs
, efx
->timer_quantum_ns
);
1723 if (tx_ticks
!= rx_ticks
&& efx
->tx_channel_offset
== 0 &&
1724 !rx_may_override_tx
) {
1725 netif_err(efx
, drv
, efx
->net_dev
, "Channels are shared. "
1726 "RX and TX IRQ moderation must be equal\n");
1730 efx
->irq_rx_adaptive
= rx_adaptive
;
1731 efx
->irq_rx_moderation
= rx_ticks
;
1732 efx_for_each_channel(channel
, efx
) {
1733 if (efx_channel_has_rx_queue(channel
))
1734 channel
->irq_moderation
= rx_ticks
;
1735 else if (efx_channel_has_tx_queues(channel
))
1736 channel
->irq_moderation
= tx_ticks
;
1742 void efx_get_irq_moderation(struct efx_nic
*efx
, unsigned int *tx_usecs
,
1743 unsigned int *rx_usecs
, bool *rx_adaptive
)
1745 /* We must round up when converting ticks to microseconds
1746 * because we round down when converting the other way.
1749 *rx_adaptive
= efx
->irq_rx_adaptive
;
1750 *rx_usecs
= DIV_ROUND_UP(efx
->irq_rx_moderation
*
1751 efx
->timer_quantum_ns
,
1754 /* If channels are shared between RX and TX, so is IRQ
1755 * moderation. Otherwise, IRQ moderation is the same for all
1756 * TX channels and is not adaptive.
1758 if (efx
->tx_channel_offset
== 0)
1759 *tx_usecs
= *rx_usecs
;
1761 *tx_usecs
= DIV_ROUND_UP(
1762 efx
->channel
[efx
->tx_channel_offset
]->irq_moderation
*
1763 efx
->timer_quantum_ns
,
1767 /**************************************************************************
1771 **************************************************************************/
1773 /* Run periodically off the general workqueue */
1774 static void efx_monitor(struct work_struct
*data
)
1776 struct efx_nic
*efx
= container_of(data
, struct efx_nic
,
1779 netif_vdbg(efx
, timer
, efx
->net_dev
,
1780 "hardware monitor executing on CPU %d\n",
1781 raw_smp_processor_id());
1782 BUG_ON(efx
->type
->monitor
== NULL
);
1784 /* If the mac_lock is already held then it is likely a port
1785 * reconfiguration is already in place, which will likely do
1786 * most of the work of monitor() anyway. */
1787 if (mutex_trylock(&efx
->mac_lock
)) {
1788 if (efx
->port_enabled
)
1789 efx
->type
->monitor(efx
);
1790 mutex_unlock(&efx
->mac_lock
);
1793 queue_delayed_work(efx
->workqueue
, &efx
->monitor_work
,
1794 efx_monitor_interval
);
1797 /**************************************************************************
1801 *************************************************************************/
1804 * Context: process, rtnl_lock() held.
1806 static int efx_ioctl(struct net_device
*net_dev
, struct ifreq
*ifr
, int cmd
)
1808 struct efx_nic
*efx
= netdev_priv(net_dev
);
1809 struct mii_ioctl_data
*data
= if_mii(ifr
);
1811 if (cmd
== SIOCSHWTSTAMP
)
1812 return efx_ptp_ioctl(efx
, ifr
, cmd
);
1814 /* Convert phy_id from older PRTAD/DEVAD format */
1815 if ((cmd
== SIOCGMIIREG
|| cmd
== SIOCSMIIREG
) &&
1816 (data
->phy_id
& 0xfc00) == 0x0400)
1817 data
->phy_id
^= MDIO_PHY_ID_C45
| 0x0400;
1819 return mdio_mii_ioctl(&efx
->mdio
, data
, cmd
);
1822 /**************************************************************************
1826 **************************************************************************/
1828 static void efx_init_napi_channel(struct efx_channel
*channel
)
1830 struct efx_nic
*efx
= channel
->efx
;
1832 channel
->napi_dev
= efx
->net_dev
;
1833 netif_napi_add(channel
->napi_dev
, &channel
->napi_str
,
1834 efx_poll
, napi_weight
);
1837 static void efx_init_napi(struct efx_nic
*efx
)
1839 struct efx_channel
*channel
;
1841 efx_for_each_channel(channel
, efx
)
1842 efx_init_napi_channel(channel
);
1845 static void efx_fini_napi_channel(struct efx_channel
*channel
)
1847 if (channel
->napi_dev
)
1848 netif_napi_del(&channel
->napi_str
);
1849 channel
->napi_dev
= NULL
;
1852 static void efx_fini_napi(struct efx_nic
*efx
)
1854 struct efx_channel
*channel
;
1856 efx_for_each_channel(channel
, efx
)
1857 efx_fini_napi_channel(channel
);
1860 /**************************************************************************
1862 * Kernel netpoll interface
1864 *************************************************************************/
1866 #ifdef CONFIG_NET_POLL_CONTROLLER
1868 /* Although in the common case interrupts will be disabled, this is not
1869 * guaranteed. However, all our work happens inside the NAPI callback,
1870 * so no locking is required.
1872 static void efx_netpoll(struct net_device
*net_dev
)
1874 struct efx_nic
*efx
= netdev_priv(net_dev
);
1875 struct efx_channel
*channel
;
1877 efx_for_each_channel(channel
, efx
)
1878 efx_schedule_channel(channel
);
1883 /**************************************************************************
1885 * Kernel net device interface
1887 *************************************************************************/
1889 /* Context: process, rtnl_lock() held. */
1890 static int efx_net_open(struct net_device
*net_dev
)
1892 struct efx_nic
*efx
= netdev_priv(net_dev
);
1895 netif_dbg(efx
, ifup
, efx
->net_dev
, "opening device on CPU %d\n",
1896 raw_smp_processor_id());
1898 rc
= efx_check_disabled(efx
);
1901 if (efx
->phy_mode
& PHY_MODE_SPECIAL
)
1903 if (efx_mcdi_poll_reboot(efx
) && efx_reset(efx
, RESET_TYPE_ALL
))
1906 /* Notify the kernel of the link state polled during driver load,
1907 * before the monitor starts running */
1908 efx_link_status_changed(efx
);
1911 efx_selftest_async_start(efx
);
1915 /* Context: process, rtnl_lock() held.
1916 * Note that the kernel will ignore our return code; this method
1917 * should really be a void.
1919 static int efx_net_stop(struct net_device
*net_dev
)
1921 struct efx_nic
*efx
= netdev_priv(net_dev
);
1923 netif_dbg(efx
, ifdown
, efx
->net_dev
, "closing on CPU %d\n",
1924 raw_smp_processor_id());
1926 /* Stop the device and flush all the channels */
1932 /* Context: process, dev_base_lock or RTNL held, non-blocking. */
1933 static struct rtnl_link_stats64
*efx_net_stats(struct net_device
*net_dev
,
1934 struct rtnl_link_stats64
*stats
)
1936 struct efx_nic
*efx
= netdev_priv(net_dev
);
1937 struct efx_mac_stats
*mac_stats
= &efx
->mac_stats
;
1939 spin_lock_bh(&efx
->stats_lock
);
1941 efx
->type
->update_stats(efx
);
1943 stats
->rx_packets
= mac_stats
->rx_packets
;
1944 stats
->tx_packets
= mac_stats
->tx_packets
;
1945 stats
->rx_bytes
= mac_stats
->rx_bytes
;
1946 stats
->tx_bytes
= mac_stats
->tx_bytes
;
1947 stats
->rx_dropped
= efx
->n_rx_nodesc_drop_cnt
;
1948 stats
->multicast
= mac_stats
->rx_multicast
;
1949 stats
->collisions
= mac_stats
->tx_collision
;
1950 stats
->rx_length_errors
= (mac_stats
->rx_gtjumbo
+
1951 mac_stats
->rx_length_error
);
1952 stats
->rx_crc_errors
= mac_stats
->rx_bad
;
1953 stats
->rx_frame_errors
= mac_stats
->rx_align_error
;
1954 stats
->rx_fifo_errors
= mac_stats
->rx_overflow
;
1955 stats
->rx_missed_errors
= mac_stats
->rx_missed
;
1956 stats
->tx_window_errors
= mac_stats
->tx_late_collision
;
1958 stats
->rx_errors
= (stats
->rx_length_errors
+
1959 stats
->rx_crc_errors
+
1960 stats
->rx_frame_errors
+
1961 mac_stats
->rx_symbol_error
);
1962 stats
->tx_errors
= (stats
->tx_window_errors
+
1965 spin_unlock_bh(&efx
->stats_lock
);
1970 /* Context: netif_tx_lock held, BHs disabled. */
1971 static void efx_watchdog(struct net_device
*net_dev
)
1973 struct efx_nic
*efx
= netdev_priv(net_dev
);
1975 netif_err(efx
, tx_err
, efx
->net_dev
,
1976 "TX stuck with port_enabled=%d: resetting channels\n",
1979 efx_schedule_reset(efx
, RESET_TYPE_TX_WATCHDOG
);
1983 /* Context: process, rtnl_lock() held. */
1984 static int efx_change_mtu(struct net_device
*net_dev
, int new_mtu
)
1986 struct efx_nic
*efx
= netdev_priv(net_dev
);
1989 rc
= efx_check_disabled(efx
);
1992 if (new_mtu
> EFX_MAX_MTU
)
1995 netif_dbg(efx
, drv
, efx
->net_dev
, "changing MTU to %d\n", new_mtu
);
1997 efx_device_detach_sync(efx
);
2000 mutex_lock(&efx
->mac_lock
);
2001 net_dev
->mtu
= new_mtu
;
2002 efx
->type
->reconfigure_mac(efx
);
2003 mutex_unlock(&efx
->mac_lock
);
2006 netif_device_attach(efx
->net_dev
);
2010 static int efx_set_mac_address(struct net_device
*net_dev
, void *data
)
2012 struct efx_nic
*efx
= netdev_priv(net_dev
);
2013 struct sockaddr
*addr
= data
;
2014 char *new_addr
= addr
->sa_data
;
2016 if (!is_valid_ether_addr(new_addr
)) {
2017 netif_err(efx
, drv
, efx
->net_dev
,
2018 "invalid ethernet MAC address requested: %pM\n",
2020 return -EADDRNOTAVAIL
;
2023 memcpy(net_dev
->dev_addr
, new_addr
, net_dev
->addr_len
);
2024 efx_sriov_mac_address_changed(efx
);
2026 /* Reconfigure the MAC */
2027 mutex_lock(&efx
->mac_lock
);
2028 efx
->type
->reconfigure_mac(efx
);
2029 mutex_unlock(&efx
->mac_lock
);
2034 /* Context: netif_addr_lock held, BHs disabled. */
2035 static void efx_set_rx_mode(struct net_device
*net_dev
)
2037 struct efx_nic
*efx
= netdev_priv(net_dev
);
2038 struct netdev_hw_addr
*ha
;
2039 union efx_multicast_hash
*mc_hash
= &efx
->multicast_hash
;
2043 efx
->promiscuous
= !!(net_dev
->flags
& IFF_PROMISC
);
2045 /* Build multicast hash table */
2046 if (efx
->promiscuous
|| (net_dev
->flags
& IFF_ALLMULTI
)) {
2047 memset(mc_hash
, 0xff, sizeof(*mc_hash
));
2049 memset(mc_hash
, 0x00, sizeof(*mc_hash
));
2050 netdev_for_each_mc_addr(ha
, net_dev
) {
2051 crc
= ether_crc_le(ETH_ALEN
, ha
->addr
);
2052 bit
= crc
& (EFX_MCAST_HASH_ENTRIES
- 1);
2053 __set_bit_le(bit
, mc_hash
);
2056 /* Broadcast packets go through the multicast hash filter.
2057 * ether_crc_le() of the broadcast address is 0xbe2612ff
2058 * so we always add bit 0xff to the mask.
2060 __set_bit_le(0xff, mc_hash
);
2063 if (efx
->port_enabled
)
2064 queue_work(efx
->workqueue
, &efx
->mac_work
);
2065 /* Otherwise efx_start_port() will do this */
2068 static int efx_set_features(struct net_device
*net_dev
, netdev_features_t data
)
2070 struct efx_nic
*efx
= netdev_priv(net_dev
);
2072 /* If disabling RX n-tuple filtering, clear existing filters */
2073 if (net_dev
->features
& ~data
& NETIF_F_NTUPLE
)
2074 efx_filter_clear_rx(efx
, EFX_FILTER_PRI_MANUAL
);
2079 static const struct net_device_ops efx_netdev_ops
= {
2080 .ndo_open
= efx_net_open
,
2081 .ndo_stop
= efx_net_stop
,
2082 .ndo_get_stats64
= efx_net_stats
,
2083 .ndo_tx_timeout
= efx_watchdog
,
2084 .ndo_start_xmit
= efx_hard_start_xmit
,
2085 .ndo_validate_addr
= eth_validate_addr
,
2086 .ndo_do_ioctl
= efx_ioctl
,
2087 .ndo_change_mtu
= efx_change_mtu
,
2088 .ndo_set_mac_address
= efx_set_mac_address
,
2089 .ndo_set_rx_mode
= efx_set_rx_mode
,
2090 .ndo_set_features
= efx_set_features
,
2091 #ifdef CONFIG_SFC_SRIOV
2092 .ndo_set_vf_mac
= efx_sriov_set_vf_mac
,
2093 .ndo_set_vf_vlan
= efx_sriov_set_vf_vlan
,
2094 .ndo_set_vf_spoofchk
= efx_sriov_set_vf_spoofchk
,
2095 .ndo_get_vf_config
= efx_sriov_get_vf_config
,
2097 #ifdef CONFIG_NET_POLL_CONTROLLER
2098 .ndo_poll_controller
= efx_netpoll
,
2100 .ndo_setup_tc
= efx_setup_tc
,
2101 #ifdef CONFIG_RFS_ACCEL
2102 .ndo_rx_flow_steer
= efx_filter_rfs
,
2106 static void efx_update_name(struct efx_nic
*efx
)
2108 strcpy(efx
->name
, efx
->net_dev
->name
);
2109 efx_mtd_rename(efx
);
2110 efx_set_channel_names(efx
);
2113 static int efx_netdev_event(struct notifier_block
*this,
2114 unsigned long event
, void *ptr
)
2116 struct net_device
*net_dev
= ptr
;
2118 if (net_dev
->netdev_ops
== &efx_netdev_ops
&&
2119 event
== NETDEV_CHANGENAME
)
2120 efx_update_name(netdev_priv(net_dev
));
2125 static struct notifier_block efx_netdev_notifier
= {
2126 .notifier_call
= efx_netdev_event
,
2130 show_phy_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2132 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2133 return sprintf(buf
, "%d\n", efx
->phy_type
);
2135 static DEVICE_ATTR(phy_type
, 0644, show_phy_type
, NULL
);
2137 static int efx_register_netdev(struct efx_nic
*efx
)
2139 struct net_device
*net_dev
= efx
->net_dev
;
2140 struct efx_channel
*channel
;
2143 net_dev
->watchdog_timeo
= 5 * HZ
;
2144 net_dev
->irq
= efx
->pci_dev
->irq
;
2145 net_dev
->netdev_ops
= &efx_netdev_ops
;
2146 SET_ETHTOOL_OPS(net_dev
, &efx_ethtool_ops
);
2147 net_dev
->gso_max_segs
= EFX_TSO_MAX_SEGS
;
2151 /* Enable resets to be scheduled and check whether any were
2152 * already requested. If so, the NIC is probably hosed so we
2155 efx
->state
= STATE_READY
;
2156 smp_mb(); /* ensure we change state before checking reset_pending */
2157 if (efx
->reset_pending
) {
2158 netif_err(efx
, probe
, efx
->net_dev
,
2159 "aborting probe due to scheduled reset\n");
2164 rc
= dev_alloc_name(net_dev
, net_dev
->name
);
2167 efx_update_name(efx
);
2169 /* Always start with carrier off; PHY events will detect the link */
2170 netif_carrier_off(net_dev
);
2172 rc
= register_netdevice(net_dev
);
2176 efx_for_each_channel(channel
, efx
) {
2177 struct efx_tx_queue
*tx_queue
;
2178 efx_for_each_channel_tx_queue(tx_queue
, channel
)
2179 efx_init_tx_queue_core_txq(tx_queue
);
2184 rc
= device_create_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
2186 netif_err(efx
, drv
, efx
->net_dev
,
2187 "failed to init net dev attributes\n");
2188 goto fail_registered
;
2195 unregister_netdevice(net_dev
);
2197 efx
->state
= STATE_UNINIT
;
2199 netif_err(efx
, drv
, efx
->net_dev
, "could not register net dev\n");
2203 static void efx_unregister_netdev(struct efx_nic
*efx
)
2205 struct efx_channel
*channel
;
2206 struct efx_tx_queue
*tx_queue
;
2211 BUG_ON(netdev_priv(efx
->net_dev
) != efx
);
2213 /* Free up any skbs still remaining. This has to happen before
2214 * we try to unregister the netdev as running their destructors
2215 * may be needed to get the device ref. count to 0. */
2216 efx_for_each_channel(channel
, efx
) {
2217 efx_for_each_channel_tx_queue(tx_queue
, channel
)
2218 efx_release_tx_buffers(tx_queue
);
2221 strlcpy(efx
->name
, pci_name(efx
->pci_dev
), sizeof(efx
->name
));
2222 device_remove_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
2225 unregister_netdevice(efx
->net_dev
);
2226 efx
->state
= STATE_UNINIT
;
2230 /**************************************************************************
2232 * Device reset and suspend
2234 **************************************************************************/
2236 /* Tears down the entire software state and most of the hardware state
2238 void efx_reset_down(struct efx_nic
*efx
, enum reset_type method
)
2240 EFX_ASSERT_RESET_SERIALISED(efx
);
2243 efx_stop_interrupts(efx
, false);
2245 mutex_lock(&efx
->mac_lock
);
2246 if (efx
->port_initialized
&& method
!= RESET_TYPE_INVISIBLE
)
2247 efx
->phy_op
->fini(efx
);
2248 efx
->type
->fini(efx
);
2251 /* This function will always ensure that the locks acquired in
2252 * efx_reset_down() are released. A failure return code indicates
2253 * that we were unable to reinitialise the hardware, and the
2254 * driver should be disabled. If ok is false, then the rx and tx
2255 * engines are not restarted, pending a RESET_DISABLE. */
2256 int efx_reset_up(struct efx_nic
*efx
, enum reset_type method
, bool ok
)
2260 EFX_ASSERT_RESET_SERIALISED(efx
);
2262 rc
= efx
->type
->init(efx
);
2264 netif_err(efx
, drv
, efx
->net_dev
, "failed to initialise NIC\n");
2271 if (efx
->port_initialized
&& method
!= RESET_TYPE_INVISIBLE
) {
2272 rc
= efx
->phy_op
->init(efx
);
2275 if (efx
->phy_op
->reconfigure(efx
))
2276 netif_err(efx
, drv
, efx
->net_dev
,
2277 "could not restore PHY settings\n");
2280 efx
->type
->reconfigure_mac(efx
);
2282 efx_start_interrupts(efx
, false);
2283 efx_restore_filters(efx
);
2284 efx_sriov_reset(efx
);
2286 mutex_unlock(&efx
->mac_lock
);
2293 efx
->port_initialized
= false;
2295 mutex_unlock(&efx
->mac_lock
);
2300 /* Reset the NIC using the specified method. Note that the reset may
2301 * fail, in which case the card will be left in an unusable state.
2303 * Caller must hold the rtnl_lock.
2305 int efx_reset(struct efx_nic
*efx
, enum reset_type method
)
2310 netif_info(efx
, drv
, efx
->net_dev
, "resetting (%s)\n",
2311 RESET_TYPE(method
));
2313 efx_device_detach_sync(efx
);
2314 efx_reset_down(efx
, method
);
2316 rc
= efx
->type
->reset(efx
, method
);
2318 netif_err(efx
, drv
, efx
->net_dev
, "failed to reset hardware\n");
2322 /* Clear flags for the scopes we covered. We assume the NIC and
2323 * driver are now quiescent so that there is no race here.
2325 efx
->reset_pending
&= -(1 << (method
+ 1));
2327 /* Reinitialise bus-mastering, which may have been turned off before
2328 * the reset was scheduled. This is still appropriate, even in the
2329 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2330 * can respond to requests. */
2331 pci_set_master(efx
->pci_dev
);
2334 /* Leave device stopped if necessary */
2336 method
== RESET_TYPE_DISABLE
||
2337 method
== RESET_TYPE_RECOVER_OR_DISABLE
;
2338 rc2
= efx_reset_up(efx
, method
, !disabled
);
2346 dev_close(efx
->net_dev
);
2347 netif_err(efx
, drv
, efx
->net_dev
, "has been disabled\n");
2348 efx
->state
= STATE_DISABLED
;
2350 netif_dbg(efx
, drv
, efx
->net_dev
, "reset complete\n");
2351 netif_device_attach(efx
->net_dev
);
2356 /* Try recovery mechanisms.
2357 * For now only EEH is supported.
2358 * Returns 0 if the recovery mechanisms are unsuccessful.
2359 * Returns a non-zero value otherwise.
2361 static int efx_try_recovery(struct efx_nic
*efx
)
2364 /* A PCI error can occur and not be seen by EEH because nothing
2365 * happens on the PCI bus. In this case the driver may fail and
2366 * schedule a 'recover or reset', leading to this recovery handler.
2367 * Manually call the eeh failure check function.
2369 struct eeh_dev
*eehdev
=
2370 of_node_to_eeh_dev(pci_device_to_OF_node(efx
->pci_dev
));
2372 if (eeh_dev_check_failure(eehdev
)) {
2373 /* The EEH mechanisms will handle the error and reset the
2374 * device if necessary.
2382 /* The worker thread exists so that code that cannot sleep can
2383 * schedule a reset for later.
2385 static void efx_reset_work(struct work_struct
*data
)
2387 struct efx_nic
*efx
= container_of(data
, struct efx_nic
, reset_work
);
2388 unsigned long pending
;
2389 enum reset_type method
;
2391 pending
= ACCESS_ONCE(efx
->reset_pending
);
2392 method
= fls(pending
) - 1;
2394 if ((method
== RESET_TYPE_RECOVER_OR_DISABLE
||
2395 method
== RESET_TYPE_RECOVER_OR_ALL
) &&
2396 efx_try_recovery(efx
))
2404 /* We checked the state in efx_schedule_reset() but it may
2405 * have changed by now. Now that we have the RTNL lock,
2406 * it cannot change again.
2408 if (efx
->state
== STATE_READY
)
2409 (void)efx_reset(efx
, method
);
2414 void efx_schedule_reset(struct efx_nic
*efx
, enum reset_type type
)
2416 enum reset_type method
;
2418 if (efx
->state
== STATE_RECOVERY
) {
2419 netif_dbg(efx
, drv
, efx
->net_dev
,
2420 "recovering: skip scheduling %s reset\n",
2426 case RESET_TYPE_INVISIBLE
:
2427 case RESET_TYPE_ALL
:
2428 case RESET_TYPE_RECOVER_OR_ALL
:
2429 case RESET_TYPE_WORLD
:
2430 case RESET_TYPE_DISABLE
:
2431 case RESET_TYPE_RECOVER_OR_DISABLE
:
2433 netif_dbg(efx
, drv
, efx
->net_dev
, "scheduling %s reset\n",
2434 RESET_TYPE(method
));
2437 method
= efx
->type
->map_reset_reason(type
);
2438 netif_dbg(efx
, drv
, efx
->net_dev
,
2439 "scheduling %s reset for %s\n",
2440 RESET_TYPE(method
), RESET_TYPE(type
));
2444 set_bit(method
, &efx
->reset_pending
);
2445 smp_mb(); /* ensure we change reset_pending before checking state */
2447 /* If we're not READY then just leave the flags set as the cue
2448 * to abort probing or reschedule the reset later.
2450 if (ACCESS_ONCE(efx
->state
) != STATE_READY
)
2453 /* efx_process_channel() will no longer read events once a
2454 * reset is scheduled. So switch back to poll'd MCDI completions. */
2455 efx_mcdi_mode_poll(efx
);
2457 queue_work(reset_workqueue
, &efx
->reset_work
);
2460 /**************************************************************************
2462 * List of NICs we support
2464 **************************************************************************/
2466 /* PCI device ID table */
2467 static DEFINE_PCI_DEVICE_TABLE(efx_pci_table
) = {
2468 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
,
2469 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0
),
2470 .driver_data
= (unsigned long) &falcon_a1_nic_type
},
2471 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
,
2472 PCI_DEVICE_ID_SOLARFLARE_SFC4000B
),
2473 .driver_data
= (unsigned long) &falcon_b0_nic_type
},
2474 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0803), /* SFC9020 */
2475 .driver_data
= (unsigned long) &siena_a0_nic_type
},
2476 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0813), /* SFL9021 */
2477 .driver_data
= (unsigned long) &siena_a0_nic_type
},
2478 {0} /* end of list */
2481 /**************************************************************************
2483 * Dummy PHY/MAC operations
2485 * Can be used for some unimplemented operations
2486 * Needed so all function pointers are valid and do not have to be tested
2489 **************************************************************************/
2490 int efx_port_dummy_op_int(struct efx_nic
*efx
)
2494 void efx_port_dummy_op_void(struct efx_nic
*efx
) {}
2496 static bool efx_port_dummy_op_poll(struct efx_nic
*efx
)
2501 static const struct efx_phy_operations efx_dummy_phy_operations
= {
2502 .init
= efx_port_dummy_op_int
,
2503 .reconfigure
= efx_port_dummy_op_int
,
2504 .poll
= efx_port_dummy_op_poll
,
2505 .fini
= efx_port_dummy_op_void
,
2508 /**************************************************************************
2512 **************************************************************************/
2514 /* This zeroes out and then fills in the invariants in a struct
2515 * efx_nic (including all sub-structures).
2517 static int efx_init_struct(struct efx_nic
*efx
,
2518 struct pci_dev
*pci_dev
, struct net_device
*net_dev
)
2522 /* Initialise common structures */
2523 spin_lock_init(&efx
->biu_lock
);
2524 #ifdef CONFIG_SFC_MTD
2525 INIT_LIST_HEAD(&efx
->mtd_list
);
2527 INIT_WORK(&efx
->reset_work
, efx_reset_work
);
2528 INIT_DELAYED_WORK(&efx
->monitor_work
, efx_monitor
);
2529 INIT_DELAYED_WORK(&efx
->selftest_work
, efx_selftest_async_work
);
2530 efx
->pci_dev
= pci_dev
;
2531 efx
->msg_enable
= debug
;
2532 efx
->state
= STATE_UNINIT
;
2533 strlcpy(efx
->name
, pci_name(pci_dev
), sizeof(efx
->name
));
2535 efx
->net_dev
= net_dev
;
2536 spin_lock_init(&efx
->stats_lock
);
2537 mutex_init(&efx
->mac_lock
);
2538 efx
->phy_op
= &efx_dummy_phy_operations
;
2539 efx
->mdio
.dev
= net_dev
;
2540 INIT_WORK(&efx
->mac_work
, efx_mac_work
);
2541 init_waitqueue_head(&efx
->flush_wq
);
2543 for (i
= 0; i
< EFX_MAX_CHANNELS
; i
++) {
2544 efx
->channel
[i
] = efx_alloc_channel(efx
, i
, NULL
);
2545 if (!efx
->channel
[i
])
2549 EFX_BUG_ON_PARANOID(efx
->type
->phys_addr_channels
> EFX_MAX_CHANNELS
);
2551 /* Higher numbered interrupt modes are less capable! */
2552 efx
->interrupt_mode
= max(efx
->type
->max_interrupt_mode
,
2555 /* Would be good to use the net_dev name, but we're too early */
2556 snprintf(efx
->workqueue_name
, sizeof(efx
->workqueue_name
), "sfc%s",
2558 efx
->workqueue
= create_singlethread_workqueue(efx
->workqueue_name
);
2559 if (!efx
->workqueue
)
2565 efx_fini_struct(efx
);
2569 static void efx_fini_struct(struct efx_nic
*efx
)
2573 for (i
= 0; i
< EFX_MAX_CHANNELS
; i
++)
2574 kfree(efx
->channel
[i
]);
2576 if (efx
->workqueue
) {
2577 destroy_workqueue(efx
->workqueue
);
2578 efx
->workqueue
= NULL
;
2582 /**************************************************************************
2586 **************************************************************************/
2588 /* Main body of final NIC shutdown code
2589 * This is called only at module unload (or hotplug removal).
2591 static void efx_pci_remove_main(struct efx_nic
*efx
)
2593 /* Flush reset_work. It can no longer be scheduled since we
2596 BUG_ON(efx
->state
== STATE_READY
);
2597 cancel_work_sync(&efx
->reset_work
);
2599 #ifdef CONFIG_RFS_ACCEL
2600 free_irq_cpu_rmap(efx
->net_dev
->rx_cpu_rmap
);
2601 efx
->net_dev
->rx_cpu_rmap
= NULL
;
2603 efx_stop_interrupts(efx
, false);
2604 efx_nic_fini_interrupt(efx
);
2606 efx
->type
->fini(efx
);
2608 efx_remove_all(efx
);
2611 /* Final NIC shutdown
2612 * This is called only at module unload (or hotplug removal).
2614 static void efx_pci_remove(struct pci_dev
*pci_dev
)
2616 struct efx_nic
*efx
;
2618 efx
= pci_get_drvdata(pci_dev
);
2622 /* Mark the NIC as fini, then stop the interface */
2624 dev_close(efx
->net_dev
);
2625 efx_stop_interrupts(efx
, false);
2628 efx_sriov_fini(efx
);
2629 efx_unregister_netdev(efx
);
2631 efx_mtd_remove(efx
);
2633 efx_pci_remove_main(efx
);
2636 netif_dbg(efx
, drv
, efx
->net_dev
, "shutdown successful\n");
2638 efx_fini_struct(efx
);
2639 pci_set_drvdata(pci_dev
, NULL
);
2640 free_netdev(efx
->net_dev
);
2642 pci_disable_pcie_error_reporting(pci_dev
);
2645 /* NIC VPD information
2646 * Called during probe to display the part number of the
2647 * installed NIC. VPD is potentially very large but this should
2648 * always appear within the first 512 bytes.
2650 #define SFC_VPD_LEN 512
2651 static void efx_print_product_vpd(struct efx_nic
*efx
)
2653 struct pci_dev
*dev
= efx
->pci_dev
;
2654 char vpd_data
[SFC_VPD_LEN
];
2658 /* Get the vpd data from the device */
2659 vpd_size
= pci_read_vpd(dev
, 0, sizeof(vpd_data
), vpd_data
);
2660 if (vpd_size
<= 0) {
2661 netif_err(efx
, drv
, efx
->net_dev
, "Unable to read VPD\n");
2665 /* Get the Read only section */
2666 i
= pci_vpd_find_tag(vpd_data
, 0, vpd_size
, PCI_VPD_LRDT_RO_DATA
);
2668 netif_err(efx
, drv
, efx
->net_dev
, "VPD Read-only not found\n");
2672 j
= pci_vpd_lrdt_size(&vpd_data
[i
]);
2673 i
+= PCI_VPD_LRDT_TAG_SIZE
;
2674 if (i
+ j
> vpd_size
)
2677 /* Get the Part number */
2678 i
= pci_vpd_find_info_keyword(vpd_data
, i
, j
, "PN");
2680 netif_err(efx
, drv
, efx
->net_dev
, "Part number not found\n");
2684 j
= pci_vpd_info_field_size(&vpd_data
[i
]);
2685 i
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
2686 if (i
+ j
> vpd_size
) {
2687 netif_err(efx
, drv
, efx
->net_dev
, "Incomplete part number\n");
2691 netif_info(efx
, drv
, efx
->net_dev
,
2692 "Part Number : %.*s\n", j
, &vpd_data
[i
]);
2696 /* Main body of NIC initialisation
2697 * This is called at module load (or hotplug insertion, theoretically).
2699 static int efx_pci_probe_main(struct efx_nic
*efx
)
2703 /* Do start-of-day initialisation */
2704 rc
= efx_probe_all(efx
);
2710 rc
= efx
->type
->init(efx
);
2712 netif_err(efx
, probe
, efx
->net_dev
,
2713 "failed to initialise NIC\n");
2717 rc
= efx_init_port(efx
);
2719 netif_err(efx
, probe
, efx
->net_dev
,
2720 "failed to initialise port\n");
2724 rc
= efx_nic_init_interrupt(efx
);
2727 efx_start_interrupts(efx
, false);
2734 efx
->type
->fini(efx
);
2737 efx_remove_all(efx
);
2742 /* NIC initialisation
2744 * This is called at module load (or hotplug insertion,
2745 * theoretically). It sets up PCI mappings, resets the NIC,
2746 * sets up and registers the network devices with the kernel and hooks
2747 * the interrupt service routine. It does not prepare the device for
2748 * transmission; this is left to the first time one of the network
2749 * interfaces is brought up (i.e. efx_net_open).
2751 static int efx_pci_probe(struct pci_dev
*pci_dev
,
2752 const struct pci_device_id
*entry
)
2754 struct net_device
*net_dev
;
2755 struct efx_nic
*efx
;
2758 /* Allocate and initialise a struct net_device and struct efx_nic */
2759 net_dev
= alloc_etherdev_mqs(sizeof(*efx
), EFX_MAX_CORE_TX_QUEUES
,
2763 efx
= netdev_priv(net_dev
);
2764 efx
->type
= (const struct efx_nic_type
*) entry
->driver_data
;
2765 net_dev
->features
|= (efx
->type
->offload_features
| NETIF_F_SG
|
2766 NETIF_F_HIGHDMA
| NETIF_F_TSO
|
2768 if (efx
->type
->offload_features
& NETIF_F_V6_CSUM
)
2769 net_dev
->features
|= NETIF_F_TSO6
;
2770 /* Mask for features that also apply to VLAN devices */
2771 net_dev
->vlan_features
|= (NETIF_F_ALL_CSUM
| NETIF_F_SG
|
2772 NETIF_F_HIGHDMA
| NETIF_F_ALL_TSO
|
2774 /* All offloads can be toggled */
2775 net_dev
->hw_features
= net_dev
->features
& ~NETIF_F_HIGHDMA
;
2776 pci_set_drvdata(pci_dev
, efx
);
2777 SET_NETDEV_DEV(net_dev
, &pci_dev
->dev
);
2778 rc
= efx_init_struct(efx
, pci_dev
, net_dev
);
2782 netif_info(efx
, probe
, efx
->net_dev
,
2783 "Solarflare NIC detected\n");
2785 efx_print_product_vpd(efx
);
2787 /* Set up basic I/O (BAR mappings etc) */
2788 rc
= efx_init_io(efx
);
2792 rc
= efx_pci_probe_main(efx
);
2796 rc
= efx_register_netdev(efx
);
2800 rc
= efx_sriov_init(efx
);
2802 netif_err(efx
, probe
, efx
->net_dev
,
2803 "SR-IOV can't be enabled rc %d\n", rc
);
2805 netif_dbg(efx
, probe
, efx
->net_dev
, "initialisation successful\n");
2807 /* Try to create MTDs, but allow this to fail */
2809 rc
= efx_mtd_probe(efx
);
2812 netif_warn(efx
, probe
, efx
->net_dev
,
2813 "failed to create MTDs (%d)\n", rc
);
2815 rc
= pci_enable_pcie_error_reporting(pci_dev
);
2816 if (rc
&& rc
!= -EINVAL
)
2817 netif_warn(efx
, probe
, efx
->net_dev
,
2818 "pci_enable_pcie_error_reporting failed (%d)\n", rc
);
2823 efx_pci_remove_main(efx
);
2827 efx_fini_struct(efx
);
2829 pci_set_drvdata(pci_dev
, NULL
);
2831 netif_dbg(efx
, drv
, efx
->net_dev
, "initialisation failed. rc=%d\n", rc
);
2832 free_netdev(net_dev
);
2836 static int efx_pm_freeze(struct device
*dev
)
2838 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2842 if (efx
->state
!= STATE_DISABLED
) {
2843 efx
->state
= STATE_UNINIT
;
2845 efx_device_detach_sync(efx
);
2848 efx_stop_interrupts(efx
, false);
2856 static int efx_pm_thaw(struct device
*dev
)
2858 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2862 if (efx
->state
!= STATE_DISABLED
) {
2863 efx_start_interrupts(efx
, false);
2865 mutex_lock(&efx
->mac_lock
);
2866 efx
->phy_op
->reconfigure(efx
);
2867 mutex_unlock(&efx
->mac_lock
);
2871 netif_device_attach(efx
->net_dev
);
2873 efx
->state
= STATE_READY
;
2875 efx
->type
->resume_wol(efx
);
2880 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2881 queue_work(reset_workqueue
, &efx
->reset_work
);
2886 static int efx_pm_poweroff(struct device
*dev
)
2888 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
2889 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
2891 efx
->type
->fini(efx
);
2893 efx
->reset_pending
= 0;
2895 pci_save_state(pci_dev
);
2896 return pci_set_power_state(pci_dev
, PCI_D3hot
);
2899 /* Used for both resume and restore */
2900 static int efx_pm_resume(struct device
*dev
)
2902 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
2903 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
2906 rc
= pci_set_power_state(pci_dev
, PCI_D0
);
2909 pci_restore_state(pci_dev
);
2910 rc
= pci_enable_device(pci_dev
);
2913 pci_set_master(efx
->pci_dev
);
2914 rc
= efx
->type
->reset(efx
, RESET_TYPE_ALL
);
2917 rc
= efx
->type
->init(efx
);
2924 static int efx_pm_suspend(struct device
*dev
)
2929 rc
= efx_pm_poweroff(dev
);
2935 static const struct dev_pm_ops efx_pm_ops
= {
2936 .suspend
= efx_pm_suspend
,
2937 .resume
= efx_pm_resume
,
2938 .freeze
= efx_pm_freeze
,
2939 .thaw
= efx_pm_thaw
,
2940 .poweroff
= efx_pm_poweroff
,
2941 .restore
= efx_pm_resume
,
2944 /* A PCI error affecting this device was detected.
2945 * At this point MMIO and DMA may be disabled.
2946 * Stop the software path and request a slot reset.
2948 pci_ers_result_t
efx_io_error_detected(struct pci_dev
*pdev
,
2949 enum pci_channel_state state
)
2951 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
2952 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
2954 if (state
== pci_channel_io_perm_failure
)
2955 return PCI_ERS_RESULT_DISCONNECT
;
2959 if (efx
->state
!= STATE_DISABLED
) {
2960 efx
->state
= STATE_RECOVERY
;
2961 efx
->reset_pending
= 0;
2963 efx_device_detach_sync(efx
);
2966 efx_stop_interrupts(efx
, false);
2968 status
= PCI_ERS_RESULT_NEED_RESET
;
2970 /* If the interface is disabled we don't want to do anything
2973 status
= PCI_ERS_RESULT_RECOVERED
;
2978 pci_disable_device(pdev
);
2983 /* Fake a successfull reset, which will be performed later in efx_io_resume. */
2984 pci_ers_result_t
efx_io_slot_reset(struct pci_dev
*pdev
)
2986 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
2987 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
2990 if (pci_enable_device(pdev
)) {
2991 netif_err(efx
, hw
, efx
->net_dev
,
2992 "Cannot re-enable PCI device after reset.\n");
2993 status
= PCI_ERS_RESULT_DISCONNECT
;
2996 rc
= pci_cleanup_aer_uncorrect_error_status(pdev
);
2998 netif_err(efx
, hw
, efx
->net_dev
,
2999 "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc
);
3000 /* Non-fatal error. Continue. */
3006 /* Perform the actual reset and resume I/O operations. */
3007 static void efx_io_resume(struct pci_dev
*pdev
)
3009 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
3014 if (efx
->state
== STATE_DISABLED
)
3017 rc
= efx_reset(efx
, RESET_TYPE_ALL
);
3019 netif_err(efx
, hw
, efx
->net_dev
,
3020 "efx_reset failed after PCI error (%d)\n", rc
);
3022 efx
->state
= STATE_READY
;
3023 netif_dbg(efx
, hw
, efx
->net_dev
,
3024 "Done resetting and resuming IO after PCI error.\n");
3031 /* For simplicity and reliability, we always require a slot reset and try to
3032 * reset the hardware when a pci error affecting the device is detected.
3033 * We leave both the link_reset and mmio_enabled callback unimplemented:
3034 * with our request for slot reset the mmio_enabled callback will never be
3035 * called, and the link_reset callback is not used by AER or EEH mechanisms.
3037 static struct pci_error_handlers efx_err_handlers
= {
3038 .error_detected
= efx_io_error_detected
,
3039 .slot_reset
= efx_io_slot_reset
,
3040 .resume
= efx_io_resume
,
3043 static struct pci_driver efx_pci_driver
= {
3044 .name
= KBUILD_MODNAME
,
3045 .id_table
= efx_pci_table
,
3046 .probe
= efx_pci_probe
,
3047 .remove
= efx_pci_remove
,
3048 .driver
.pm
= &efx_pm_ops
,
3049 .err_handler
= &efx_err_handlers
,
3052 /**************************************************************************
3054 * Kernel module interface
3056 *************************************************************************/
3058 module_param(interrupt_mode
, uint
, 0444);
3059 MODULE_PARM_DESC(interrupt_mode
,
3060 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3062 static int __init
efx_init_module(void)
3066 printk(KERN_INFO
"Solarflare NET driver v" EFX_DRIVER_VERSION
"\n");
3068 rc
= register_netdevice_notifier(&efx_netdev_notifier
);
3072 rc
= efx_init_sriov();
3076 reset_workqueue
= create_singlethread_workqueue("sfc_reset");
3077 if (!reset_workqueue
) {
3082 rc
= pci_register_driver(&efx_pci_driver
);
3089 destroy_workqueue(reset_workqueue
);
3093 unregister_netdevice_notifier(&efx_netdev_notifier
);
3098 static void __exit
efx_exit_module(void)
3100 printk(KERN_INFO
"Solarflare NET driver unloading\n");
3102 pci_unregister_driver(&efx_pci_driver
);
3103 destroy_workqueue(reset_workqueue
);
3105 unregister_netdevice_notifier(&efx_netdev_notifier
);
3109 module_init(efx_init_module
);
3110 module_exit(efx_exit_module
);
3112 MODULE_AUTHOR("Solarflare Communications and "
3113 "Michael Brown <mbrown@fensystems.co.uk>");
3114 MODULE_DESCRIPTION("Solarflare Communications network driver");
3115 MODULE_LICENSE("GPL");
3116 MODULE_DEVICE_TABLE(pci
, efx_pci_table
);