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/cpu_rmap.h>
25 #include <linux/aer.h>
26 #include "net_driver.h"
32 #include "workarounds.h"
34 /**************************************************************************
38 **************************************************************************
41 /* Loopback mode names (see LOOPBACK_MODE()) */
42 const unsigned int efx_loopback_mode_max
= LOOPBACK_MAX
;
43 const char *const efx_loopback_mode_names
[] = {
44 [LOOPBACK_NONE
] = "NONE",
45 [LOOPBACK_DATA
] = "DATAPATH",
46 [LOOPBACK_GMAC
] = "GMAC",
47 [LOOPBACK_XGMII
] = "XGMII",
48 [LOOPBACK_XGXS
] = "XGXS",
49 [LOOPBACK_XAUI
] = "XAUI",
50 [LOOPBACK_GMII
] = "GMII",
51 [LOOPBACK_SGMII
] = "SGMII",
52 [LOOPBACK_XGBR
] = "XGBR",
53 [LOOPBACK_XFI
] = "XFI",
54 [LOOPBACK_XAUI_FAR
] = "XAUI_FAR",
55 [LOOPBACK_GMII_FAR
] = "GMII_FAR",
56 [LOOPBACK_SGMII_FAR
] = "SGMII_FAR",
57 [LOOPBACK_XFI_FAR
] = "XFI_FAR",
58 [LOOPBACK_GPHY
] = "GPHY",
59 [LOOPBACK_PHYXS
] = "PHYXS",
60 [LOOPBACK_PCS
] = "PCS",
61 [LOOPBACK_PMAPMD
] = "PMA/PMD",
62 [LOOPBACK_XPORT
] = "XPORT",
63 [LOOPBACK_XGMII_WS
] = "XGMII_WS",
64 [LOOPBACK_XAUI_WS
] = "XAUI_WS",
65 [LOOPBACK_XAUI_WS_FAR
] = "XAUI_WS_FAR",
66 [LOOPBACK_XAUI_WS_NEAR
] = "XAUI_WS_NEAR",
67 [LOOPBACK_GMII_WS
] = "GMII_WS",
68 [LOOPBACK_XFI_WS
] = "XFI_WS",
69 [LOOPBACK_XFI_WS_FAR
] = "XFI_WS_FAR",
70 [LOOPBACK_PHYXS_WS
] = "PHYXS_WS",
73 const unsigned int efx_reset_type_max
= RESET_TYPE_MAX
;
74 const char *const efx_reset_type_names
[] = {
75 [RESET_TYPE_INVISIBLE
] = "INVISIBLE",
76 [RESET_TYPE_ALL
] = "ALL",
77 [RESET_TYPE_RECOVER_OR_ALL
] = "RECOVER_OR_ALL",
78 [RESET_TYPE_WORLD
] = "WORLD",
79 [RESET_TYPE_RECOVER_OR_DISABLE
] = "RECOVER_OR_DISABLE",
80 [RESET_TYPE_DISABLE
] = "DISABLE",
81 [RESET_TYPE_TX_WATCHDOG
] = "TX_WATCHDOG",
82 [RESET_TYPE_INT_ERROR
] = "INT_ERROR",
83 [RESET_TYPE_RX_RECOVERY
] = "RX_RECOVERY",
84 [RESET_TYPE_RX_DESC_FETCH
] = "RX_DESC_FETCH",
85 [RESET_TYPE_TX_DESC_FETCH
] = "TX_DESC_FETCH",
86 [RESET_TYPE_TX_SKIP
] = "TX_SKIP",
87 [RESET_TYPE_MC_FAILURE
] = "MC_FAILURE",
90 /* Reset workqueue. If any NIC has a hardware failure then a reset will be
91 * queued onto this work queue. This is not a per-nic work queue, because
92 * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
94 static struct workqueue_struct
*reset_workqueue
;
96 /**************************************************************************
100 *************************************************************************/
103 * Use separate channels for TX and RX events
105 * Set this to 1 to use separate channels for TX and RX. It allows us
106 * to control interrupt affinity separately for TX and RX.
108 * This is only used in MSI-X interrupt mode
110 static bool separate_tx_channels
;
111 module_param(separate_tx_channels
, bool, 0444);
112 MODULE_PARM_DESC(separate_tx_channels
,
113 "Use separate channels for TX and RX");
115 /* This is the weight assigned to each of the (per-channel) virtual
118 static int napi_weight
= 64;
120 /* This is the time (in jiffies) between invocations of the hardware
122 * On Falcon-based NICs, this will:
123 * - Check the on-board hardware monitor;
124 * - Poll the link state and reconfigure the hardware as necessary.
125 * On Siena-based NICs for power systems with EEH support, this will give EEH a
128 static unsigned int efx_monitor_interval
= 1 * HZ
;
130 /* Initial interrupt moderation settings. They can be modified after
131 * module load with ethtool.
133 * The default for RX should strike a balance between increasing the
134 * round-trip latency and reducing overhead.
136 static unsigned int rx_irq_mod_usec
= 60;
138 /* Initial interrupt moderation settings. They can be modified after
139 * module load with ethtool.
141 * This default is chosen to ensure that a 10G link does not go idle
142 * while a TX queue is stopped after it has become full. A queue is
143 * restarted when it drops below half full. The time this takes (assuming
144 * worst case 3 descriptors per packet and 1024 descriptors) is
145 * 512 / 3 * 1.2 = 205 usec.
147 static unsigned int tx_irq_mod_usec
= 150;
149 /* This is the first interrupt mode to try out of:
154 static unsigned int interrupt_mode
;
156 /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
157 * i.e. the number of CPUs among which we may distribute simultaneous
158 * interrupt handling.
160 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
161 * The default (0) means to assign an interrupt to each core.
163 static unsigned int rss_cpus
;
164 module_param(rss_cpus
, uint
, 0444);
165 MODULE_PARM_DESC(rss_cpus
, "Number of CPUs to use for Receive-Side Scaling");
167 static bool phy_flash_cfg
;
168 module_param(phy_flash_cfg
, bool, 0644);
169 MODULE_PARM_DESC(phy_flash_cfg
, "Set PHYs into reflash mode initially");
171 static unsigned irq_adapt_low_thresh
= 8000;
172 module_param(irq_adapt_low_thresh
, uint
, 0644);
173 MODULE_PARM_DESC(irq_adapt_low_thresh
,
174 "Threshold score for reducing IRQ moderation");
176 static unsigned irq_adapt_high_thresh
= 16000;
177 module_param(irq_adapt_high_thresh
, uint
, 0644);
178 MODULE_PARM_DESC(irq_adapt_high_thresh
,
179 "Threshold score for increasing IRQ moderation");
181 static unsigned debug
= (NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
182 NETIF_MSG_LINK
| NETIF_MSG_IFDOWN
|
183 NETIF_MSG_IFUP
| NETIF_MSG_RX_ERR
|
184 NETIF_MSG_TX_ERR
| NETIF_MSG_HW
);
185 module_param(debug
, uint
, 0);
186 MODULE_PARM_DESC(debug
, "Bitmapped debugging message enable value");
188 /**************************************************************************
190 * Utility functions and prototypes
192 *************************************************************************/
194 static void efx_start_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
);
195 static void efx_stop_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
);
196 static void efx_remove_channel(struct efx_channel
*channel
);
197 static void efx_remove_channels(struct efx_nic
*efx
);
198 static const struct efx_channel_type efx_default_channel_type
;
199 static void efx_remove_port(struct efx_nic
*efx
);
200 static void efx_init_napi_channel(struct efx_channel
*channel
);
201 static void efx_fini_napi(struct efx_nic
*efx
);
202 static void efx_fini_napi_channel(struct efx_channel
*channel
);
203 static void efx_fini_struct(struct efx_nic
*efx
);
204 static void efx_start_all(struct efx_nic
*efx
);
205 static void efx_stop_all(struct efx_nic
*efx
);
207 #define EFX_ASSERT_RESET_SERIALISED(efx) \
209 if ((efx->state == STATE_READY) || \
210 (efx->state == STATE_RECOVERY) || \
211 (efx->state == STATE_DISABLED)) \
215 static int efx_check_disabled(struct efx_nic
*efx
)
217 if (efx
->state
== STATE_DISABLED
|| efx
->state
== STATE_RECOVERY
) {
218 netif_err(efx
, drv
, efx
->net_dev
,
219 "device is disabled due to earlier errors\n");
225 /**************************************************************************
227 * Event queue processing
229 *************************************************************************/
231 /* Process channel's event queue
233 * This function is responsible for processing the event queue of a
234 * single channel. The caller must guarantee that this function will
235 * never be concurrently called more than once on the same channel,
236 * though different channels may be being processed concurrently.
238 static int efx_process_channel(struct efx_channel
*channel
, int budget
)
242 if (unlikely(!channel
->enabled
))
245 spent
= efx_nic_process_eventq(channel
, budget
);
246 if (spent
&& efx_channel_has_rx_queue(channel
)) {
247 struct efx_rx_queue
*rx_queue
=
248 efx_channel_get_rx_queue(channel
);
250 efx_rx_flush_packet(channel
);
251 if (rx_queue
->enabled
)
252 efx_fast_push_rx_descriptors(rx_queue
);
258 /* Mark channel as finished processing
260 * Note that since we will not receive further interrupts for this
261 * channel before we finish processing and call the eventq_read_ack()
262 * method, there is no need to use the interrupt hold-off timers.
264 static inline void efx_channel_processed(struct efx_channel
*channel
)
266 /* The interrupt handler for this channel may set work_pending
267 * as soon as we acknowledge the events we've seen. Make sure
268 * it's cleared before then. */
269 channel
->work_pending
= false;
272 efx_nic_eventq_read_ack(channel
);
277 * NAPI guarantees serialisation of polls of the same device, which
278 * provides the guarantee required by efx_process_channel().
280 static int efx_poll(struct napi_struct
*napi
, int budget
)
282 struct efx_channel
*channel
=
283 container_of(napi
, struct efx_channel
, napi_str
);
284 struct efx_nic
*efx
= channel
->efx
;
287 netif_vdbg(efx
, intr
, efx
->net_dev
,
288 "channel %d NAPI poll executing on CPU %d\n",
289 channel
->channel
, raw_smp_processor_id());
291 spent
= efx_process_channel(channel
, budget
);
293 if (spent
< budget
) {
294 if (efx_channel_has_rx_queue(channel
) &&
295 efx
->irq_rx_adaptive
&&
296 unlikely(++channel
->irq_count
== 1000)) {
297 if (unlikely(channel
->irq_mod_score
<
298 irq_adapt_low_thresh
)) {
299 if (channel
->irq_moderation
> 1) {
300 channel
->irq_moderation
-= 1;
301 efx
->type
->push_irq_moderation(channel
);
303 } else if (unlikely(channel
->irq_mod_score
>
304 irq_adapt_high_thresh
)) {
305 if (channel
->irq_moderation
<
306 efx
->irq_rx_moderation
) {
307 channel
->irq_moderation
+= 1;
308 efx
->type
->push_irq_moderation(channel
);
311 channel
->irq_count
= 0;
312 channel
->irq_mod_score
= 0;
315 efx_filter_rfs_expire(channel
);
317 /* There is no race here; although napi_disable() will
318 * only wait for napi_complete(), this isn't a problem
319 * since efx_channel_processed() will have no effect if
320 * interrupts have already been disabled.
323 efx_channel_processed(channel
);
329 /* Process the eventq of the specified channel immediately on this CPU
331 * Disable hardware generated interrupts, wait for any existing
332 * processing to finish, then directly poll (and ack ) the eventq.
333 * Finally reenable NAPI and interrupts.
335 * This is for use only during a loopback self-test. It must not
336 * deliver any packets up the stack as this can result in deadlock.
338 void efx_process_channel_now(struct efx_channel
*channel
)
340 struct efx_nic
*efx
= channel
->efx
;
342 BUG_ON(channel
->channel
>= efx
->n_channels
);
343 BUG_ON(!channel
->enabled
);
344 BUG_ON(!efx
->loopback_selftest
);
346 /* Disable interrupts and wait for ISRs to complete */
347 efx_nic_disable_interrupts(efx
);
348 if (efx
->legacy_irq
) {
349 synchronize_irq(efx
->legacy_irq
);
350 efx
->legacy_irq_enabled
= false;
353 synchronize_irq(channel
->irq
);
355 /* Wait for any NAPI processing to complete */
356 napi_disable(&channel
->napi_str
);
358 /* Poll the channel */
359 efx_process_channel(channel
, channel
->eventq_mask
+ 1);
361 /* Ack the eventq. This may cause an interrupt to be generated
362 * when they are reenabled */
363 efx_channel_processed(channel
);
365 napi_enable(&channel
->napi_str
);
367 efx
->legacy_irq_enabled
= true;
368 efx_nic_enable_interrupts(efx
);
371 /* Create event queue
372 * Event queue memory allocations are done only once. If the channel
373 * is reset, the memory buffer will be reused; this guards against
374 * errors during channel reset and also simplifies interrupt handling.
376 static int efx_probe_eventq(struct efx_channel
*channel
)
378 struct efx_nic
*efx
= channel
->efx
;
379 unsigned long entries
;
381 netif_dbg(efx
, probe
, efx
->net_dev
,
382 "chan %d create event queue\n", channel
->channel
);
384 /* Build an event queue with room for one event per tx and rx buffer,
385 * plus some extra for link state events and MCDI completions. */
386 entries
= roundup_pow_of_two(efx
->rxq_entries
+ efx
->txq_entries
+ 128);
387 EFX_BUG_ON_PARANOID(entries
> EFX_MAX_EVQ_SIZE
);
388 channel
->eventq_mask
= max(entries
, EFX_MIN_EVQ_SIZE
) - 1;
390 return efx_nic_probe_eventq(channel
);
393 /* Prepare channel's event queue */
394 static void efx_init_eventq(struct efx_channel
*channel
)
396 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
397 "chan %d init event queue\n", channel
->channel
);
399 channel
->eventq_read_ptr
= 0;
401 efx_nic_init_eventq(channel
);
404 /* Enable event queue processing and NAPI */
405 static void efx_start_eventq(struct efx_channel
*channel
)
407 netif_dbg(channel
->efx
, ifup
, channel
->efx
->net_dev
,
408 "chan %d start event queue\n", channel
->channel
);
410 /* The interrupt handler for this channel may set work_pending
411 * as soon as we enable it. Make sure it's cleared before
412 * then. Similarly, make sure it sees the enabled flag set.
414 channel
->work_pending
= false;
415 channel
->enabled
= true;
418 napi_enable(&channel
->napi_str
);
419 efx_nic_eventq_read_ack(channel
);
422 /* Disable event queue processing and NAPI */
423 static void efx_stop_eventq(struct efx_channel
*channel
)
425 if (!channel
->enabled
)
428 napi_disable(&channel
->napi_str
);
429 channel
->enabled
= false;
432 static void efx_fini_eventq(struct efx_channel
*channel
)
434 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
435 "chan %d fini event queue\n", channel
->channel
);
437 efx_nic_fini_eventq(channel
);
440 static void efx_remove_eventq(struct efx_channel
*channel
)
442 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
443 "chan %d remove event queue\n", channel
->channel
);
445 efx_nic_remove_eventq(channel
);
448 /**************************************************************************
452 *************************************************************************/
454 /* Allocate and initialise a channel structure. */
455 static struct efx_channel
*
456 efx_alloc_channel(struct efx_nic
*efx
, int i
, struct efx_channel
*old_channel
)
458 struct efx_channel
*channel
;
459 struct efx_rx_queue
*rx_queue
;
460 struct efx_tx_queue
*tx_queue
;
463 channel
= kzalloc(sizeof(*channel
), GFP_KERNEL
);
468 channel
->channel
= i
;
469 channel
->type
= &efx_default_channel_type
;
471 for (j
= 0; j
< EFX_TXQ_TYPES
; j
++) {
472 tx_queue
= &channel
->tx_queue
[j
];
474 tx_queue
->queue
= i
* EFX_TXQ_TYPES
+ j
;
475 tx_queue
->channel
= channel
;
478 rx_queue
= &channel
->rx_queue
;
480 setup_timer(&rx_queue
->slow_fill
, efx_rx_slow_fill
,
481 (unsigned long)rx_queue
);
486 /* Allocate and initialise a channel structure, copying parameters
487 * (but not resources) from an old channel structure.
489 static struct efx_channel
*
490 efx_copy_channel(const struct efx_channel
*old_channel
)
492 struct efx_channel
*channel
;
493 struct efx_rx_queue
*rx_queue
;
494 struct efx_tx_queue
*tx_queue
;
497 channel
= kmalloc(sizeof(*channel
), GFP_KERNEL
);
501 *channel
= *old_channel
;
503 channel
->napi_dev
= NULL
;
504 memset(&channel
->eventq
, 0, sizeof(channel
->eventq
));
506 for (j
= 0; j
< EFX_TXQ_TYPES
; j
++) {
507 tx_queue
= &channel
->tx_queue
[j
];
508 if (tx_queue
->channel
)
509 tx_queue
->channel
= channel
;
510 tx_queue
->buffer
= NULL
;
511 memset(&tx_queue
->txd
, 0, sizeof(tx_queue
->txd
));
514 rx_queue
= &channel
->rx_queue
;
515 rx_queue
->buffer
= NULL
;
516 memset(&rx_queue
->rxd
, 0, sizeof(rx_queue
->rxd
));
517 setup_timer(&rx_queue
->slow_fill
, efx_rx_slow_fill
,
518 (unsigned long)rx_queue
);
523 static int efx_probe_channel(struct efx_channel
*channel
)
525 struct efx_tx_queue
*tx_queue
;
526 struct efx_rx_queue
*rx_queue
;
529 netif_dbg(channel
->efx
, probe
, channel
->efx
->net_dev
,
530 "creating channel %d\n", channel
->channel
);
532 rc
= channel
->type
->pre_probe(channel
);
536 rc
= efx_probe_eventq(channel
);
540 efx_for_each_channel_tx_queue(tx_queue
, channel
) {
541 rc
= efx_probe_tx_queue(tx_queue
);
546 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
547 rc
= efx_probe_rx_queue(rx_queue
);
552 channel
->n_rx_frm_trunc
= 0;
557 efx_remove_channel(channel
);
562 efx_get_channel_name(struct efx_channel
*channel
, char *buf
, size_t len
)
564 struct efx_nic
*efx
= channel
->efx
;
568 number
= channel
->channel
;
569 if (efx
->tx_channel_offset
== 0) {
571 } else if (channel
->channel
< efx
->tx_channel_offset
) {
575 number
-= efx
->tx_channel_offset
;
577 snprintf(buf
, len
, "%s%s-%d", efx
->name
, type
, number
);
580 static void efx_set_channel_names(struct efx_nic
*efx
)
582 struct efx_channel
*channel
;
584 efx_for_each_channel(channel
, efx
)
585 channel
->type
->get_name(channel
,
586 efx
->channel_name
[channel
->channel
],
587 sizeof(efx
->channel_name
[0]));
590 static int efx_probe_channels(struct efx_nic
*efx
)
592 struct efx_channel
*channel
;
595 /* Restart special buffer allocation */
596 efx
->next_buffer_table
= 0;
598 /* Probe channels in reverse, so that any 'extra' channels
599 * use the start of the buffer table. This allows the traffic
600 * channels to be resized without moving them or wasting the
601 * entries before them.
603 efx_for_each_channel_rev(channel
, efx
) {
604 rc
= efx_probe_channel(channel
);
606 netif_err(efx
, probe
, efx
->net_dev
,
607 "failed to create channel %d\n",
612 efx_set_channel_names(efx
);
617 efx_remove_channels(efx
);
621 /* Channels are shutdown and reinitialised whilst the NIC is running
622 * to propagate configuration changes (mtu, checksum offload), or
623 * to clear hardware error conditions
625 static void efx_start_datapath(struct efx_nic
*efx
)
627 bool old_rx_scatter
= efx
->rx_scatter
;
628 struct efx_tx_queue
*tx_queue
;
629 struct efx_rx_queue
*rx_queue
;
630 struct efx_channel
*channel
;
633 /* Calculate the rx buffer allocation parameters required to
634 * support the current MTU, including padding for header
635 * alignment and overruns.
637 efx
->rx_dma_len
= (efx
->type
->rx_buffer_hash_size
+
638 EFX_MAX_FRAME_LEN(efx
->net_dev
->mtu
) +
639 efx
->type
->rx_buffer_padding
);
640 rx_buf_len
= (sizeof(struct efx_rx_page_state
) +
641 NET_IP_ALIGN
+ efx
->rx_dma_len
);
642 if (rx_buf_len
<= PAGE_SIZE
) {
643 efx
->rx_scatter
= false;
644 efx
->rx_buffer_order
= 0;
645 } else if (efx
->type
->can_rx_scatter
) {
646 BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE
% L1_CACHE_BYTES
);
647 BUILD_BUG_ON(sizeof(struct efx_rx_page_state
) +
648 2 * ALIGN(NET_IP_ALIGN
+ EFX_RX_USR_BUF_SIZE
,
649 EFX_RX_BUF_ALIGNMENT
) >
651 efx
->rx_scatter
= true;
652 efx
->rx_dma_len
= EFX_RX_USR_BUF_SIZE
;
653 efx
->rx_buffer_order
= 0;
655 efx
->rx_scatter
= false;
656 efx
->rx_buffer_order
= get_order(rx_buf_len
);
659 efx_rx_config_page_split(efx
);
660 if (efx
->rx_buffer_order
)
661 netif_dbg(efx
, drv
, efx
->net_dev
,
662 "RX buf len=%u; page order=%u batch=%u\n",
663 efx
->rx_dma_len
, efx
->rx_buffer_order
,
664 efx
->rx_pages_per_batch
);
666 netif_dbg(efx
, drv
, efx
->net_dev
,
667 "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
668 efx
->rx_dma_len
, efx
->rx_page_buf_step
,
669 efx
->rx_bufs_per_page
, efx
->rx_pages_per_batch
);
671 /* RX filters also have scatter-enabled flags */
672 if (efx
->rx_scatter
!= old_rx_scatter
)
673 efx_filter_update_rx_scatter(efx
);
675 /* We must keep at least one descriptor in a TX ring empty.
676 * We could avoid this when the queue size does not exactly
677 * match the hardware ring size, but it's not that important.
678 * Therefore we stop the queue when one more skb might fill
679 * the ring completely. We wake it when half way back to
682 efx
->txq_stop_thresh
= efx
->txq_entries
- efx_tx_max_skb_descs(efx
);
683 efx
->txq_wake_thresh
= efx
->txq_stop_thresh
/ 2;
685 /* Initialise the channels */
686 efx_for_each_channel(channel
, efx
) {
687 efx_for_each_channel_tx_queue(tx_queue
, channel
)
688 efx_init_tx_queue(tx_queue
);
690 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
691 efx_init_rx_queue(rx_queue
);
692 efx_nic_generate_fill_event(rx_queue
);
695 WARN_ON(channel
->rx_pkt_n_frags
);
698 if (netif_device_present(efx
->net_dev
))
699 netif_tx_wake_all_queues(efx
->net_dev
);
702 static void efx_stop_datapath(struct efx_nic
*efx
)
704 struct efx_channel
*channel
;
705 struct efx_tx_queue
*tx_queue
;
706 struct efx_rx_queue
*rx_queue
;
707 struct pci_dev
*dev
= efx
->pci_dev
;
710 EFX_ASSERT_RESET_SERIALISED(efx
);
711 BUG_ON(efx
->port_enabled
);
713 /* Only perform flush if dma is enabled */
714 if (dev
->is_busmaster
&& efx
->state
!= STATE_RECOVERY
) {
715 rc
= efx_nic_flush_queues(efx
);
717 if (rc
&& EFX_WORKAROUND_7803(efx
)) {
718 /* Schedule a reset to recover from the flush failure. The
719 * descriptor caches reference memory we're about to free,
720 * but falcon_reconfigure_mac_wrapper() won't reconnect
721 * the MACs because of the pending reset. */
722 netif_err(efx
, drv
, efx
->net_dev
,
723 "Resetting to recover from flush failure\n");
724 efx_schedule_reset(efx
, RESET_TYPE_ALL
);
726 netif_err(efx
, drv
, efx
->net_dev
, "failed to flush queues\n");
728 netif_dbg(efx
, drv
, efx
->net_dev
,
729 "successfully flushed all queues\n");
733 efx_for_each_channel(channel
, efx
) {
734 /* RX packet processing is pipelined, so wait for the
735 * NAPI handler to complete. At least event queue 0
736 * might be kept active by non-data events, so don't
737 * use napi_synchronize() but actually disable NAPI
740 if (efx_channel_has_rx_queue(channel
)) {
741 efx_stop_eventq(channel
);
742 efx_start_eventq(channel
);
745 efx_for_each_channel_rx_queue(rx_queue
, channel
)
746 efx_fini_rx_queue(rx_queue
);
747 efx_for_each_possible_channel_tx_queue(tx_queue
, channel
)
748 efx_fini_tx_queue(tx_queue
);
752 static void efx_remove_channel(struct efx_channel
*channel
)
754 struct efx_tx_queue
*tx_queue
;
755 struct efx_rx_queue
*rx_queue
;
757 netif_dbg(channel
->efx
, drv
, channel
->efx
->net_dev
,
758 "destroy chan %d\n", channel
->channel
);
760 efx_for_each_channel_rx_queue(rx_queue
, channel
)
761 efx_remove_rx_queue(rx_queue
);
762 efx_for_each_possible_channel_tx_queue(tx_queue
, channel
)
763 efx_remove_tx_queue(tx_queue
);
764 efx_remove_eventq(channel
);
765 channel
->type
->post_remove(channel
);
768 static void efx_remove_channels(struct efx_nic
*efx
)
770 struct efx_channel
*channel
;
772 efx_for_each_channel(channel
, efx
)
773 efx_remove_channel(channel
);
777 efx_realloc_channels(struct efx_nic
*efx
, u32 rxq_entries
, u32 txq_entries
)
779 struct efx_channel
*other_channel
[EFX_MAX_CHANNELS
], *channel
;
780 u32 old_rxq_entries
, old_txq_entries
;
781 unsigned i
, next_buffer_table
= 0;
784 rc
= efx_check_disabled(efx
);
788 /* Not all channels should be reallocated. We must avoid
789 * reallocating their buffer table entries.
791 efx_for_each_channel(channel
, efx
) {
792 struct efx_rx_queue
*rx_queue
;
793 struct efx_tx_queue
*tx_queue
;
795 if (channel
->type
->copy
)
797 next_buffer_table
= max(next_buffer_table
,
798 channel
->eventq
.index
+
799 channel
->eventq
.entries
);
800 efx_for_each_channel_rx_queue(rx_queue
, channel
)
801 next_buffer_table
= max(next_buffer_table
,
802 rx_queue
->rxd
.index
+
803 rx_queue
->rxd
.entries
);
804 efx_for_each_channel_tx_queue(tx_queue
, channel
)
805 next_buffer_table
= max(next_buffer_table
,
806 tx_queue
->txd
.index
+
807 tx_queue
->txd
.entries
);
810 efx_device_detach_sync(efx
);
812 efx_stop_interrupts(efx
, true);
814 /* Clone channels (where possible) */
815 memset(other_channel
, 0, sizeof(other_channel
));
816 for (i
= 0; i
< efx
->n_channels
; i
++) {
817 channel
= efx
->channel
[i
];
818 if (channel
->type
->copy
)
819 channel
= channel
->type
->copy(channel
);
824 other_channel
[i
] = channel
;
827 /* Swap entry counts and channel pointers */
828 old_rxq_entries
= efx
->rxq_entries
;
829 old_txq_entries
= efx
->txq_entries
;
830 efx
->rxq_entries
= rxq_entries
;
831 efx
->txq_entries
= txq_entries
;
832 for (i
= 0; i
< efx
->n_channels
; i
++) {
833 channel
= efx
->channel
[i
];
834 efx
->channel
[i
] = other_channel
[i
];
835 other_channel
[i
] = channel
;
838 /* Restart buffer table allocation */
839 efx
->next_buffer_table
= next_buffer_table
;
841 for (i
= 0; i
< efx
->n_channels
; i
++) {
842 channel
= efx
->channel
[i
];
843 if (!channel
->type
->copy
)
845 rc
= efx_probe_channel(channel
);
848 efx_init_napi_channel(efx
->channel
[i
]);
852 /* Destroy unused channel structures */
853 for (i
= 0; i
< efx
->n_channels
; i
++) {
854 channel
= other_channel
[i
];
855 if (channel
&& channel
->type
->copy
) {
856 efx_fini_napi_channel(channel
);
857 efx_remove_channel(channel
);
862 efx_start_interrupts(efx
, true);
864 netif_device_attach(efx
->net_dev
);
869 efx
->rxq_entries
= old_rxq_entries
;
870 efx
->txq_entries
= old_txq_entries
;
871 for (i
= 0; i
< efx
->n_channels
; i
++) {
872 channel
= efx
->channel
[i
];
873 efx
->channel
[i
] = other_channel
[i
];
874 other_channel
[i
] = channel
;
879 void efx_schedule_slow_fill(struct efx_rx_queue
*rx_queue
)
881 mod_timer(&rx_queue
->slow_fill
, jiffies
+ msecs_to_jiffies(100));
884 static const struct efx_channel_type efx_default_channel_type
= {
885 .pre_probe
= efx_channel_dummy_op_int
,
886 .post_remove
= efx_channel_dummy_op_void
,
887 .get_name
= efx_get_channel_name
,
888 .copy
= efx_copy_channel
,
889 .keep_eventq
= false,
892 int efx_channel_dummy_op_int(struct efx_channel
*channel
)
897 void efx_channel_dummy_op_void(struct efx_channel
*channel
)
901 /**************************************************************************
905 **************************************************************************/
907 /* This ensures that the kernel is kept informed (via
908 * netif_carrier_on/off) of the link status, and also maintains the
909 * link status's stop on the port's TX queue.
911 void efx_link_status_changed(struct efx_nic
*efx
)
913 struct efx_link_state
*link_state
= &efx
->link_state
;
915 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
916 * that no events are triggered between unregister_netdev() and the
917 * driver unloading. A more general condition is that NETDEV_CHANGE
918 * can only be generated between NETDEV_UP and NETDEV_DOWN */
919 if (!netif_running(efx
->net_dev
))
922 if (link_state
->up
!= netif_carrier_ok(efx
->net_dev
)) {
923 efx
->n_link_state_changes
++;
926 netif_carrier_on(efx
->net_dev
);
928 netif_carrier_off(efx
->net_dev
);
931 /* Status message for kernel log */
933 netif_info(efx
, link
, efx
->net_dev
,
934 "link up at %uMbps %s-duplex (MTU %d)%s\n",
935 link_state
->speed
, link_state
->fd
? "full" : "half",
937 (efx
->promiscuous
? " [PROMISC]" : ""));
939 netif_info(efx
, link
, efx
->net_dev
, "link down\n");
942 void efx_link_set_advertising(struct efx_nic
*efx
, u32 advertising
)
944 efx
->link_advertising
= advertising
;
946 if (advertising
& ADVERTISED_Pause
)
947 efx
->wanted_fc
|= (EFX_FC_TX
| EFX_FC_RX
);
949 efx
->wanted_fc
&= ~(EFX_FC_TX
| EFX_FC_RX
);
950 if (advertising
& ADVERTISED_Asym_Pause
)
951 efx
->wanted_fc
^= EFX_FC_TX
;
955 void efx_link_set_wanted_fc(struct efx_nic
*efx
, u8 wanted_fc
)
957 efx
->wanted_fc
= wanted_fc
;
958 if (efx
->link_advertising
) {
959 if (wanted_fc
& EFX_FC_RX
)
960 efx
->link_advertising
|= (ADVERTISED_Pause
|
961 ADVERTISED_Asym_Pause
);
963 efx
->link_advertising
&= ~(ADVERTISED_Pause
|
964 ADVERTISED_Asym_Pause
);
965 if (wanted_fc
& EFX_FC_TX
)
966 efx
->link_advertising
^= ADVERTISED_Asym_Pause
;
970 static void efx_fini_port(struct efx_nic
*efx
);
972 /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
973 * the MAC appropriately. All other PHY configuration changes are pushed
974 * through phy_op->set_settings(), and pushed asynchronously to the MAC
975 * through efx_monitor().
977 * Callers must hold the mac_lock
979 int __efx_reconfigure_port(struct efx_nic
*efx
)
981 enum efx_phy_mode phy_mode
;
984 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
986 /* Serialise the promiscuous flag with efx_set_rx_mode. */
987 netif_addr_lock_bh(efx
->net_dev
);
988 netif_addr_unlock_bh(efx
->net_dev
);
990 /* Disable PHY transmit in mac level loopbacks */
991 phy_mode
= efx
->phy_mode
;
992 if (LOOPBACK_INTERNAL(efx
))
993 efx
->phy_mode
|= PHY_MODE_TX_DISABLED
;
995 efx
->phy_mode
&= ~PHY_MODE_TX_DISABLED
;
997 rc
= efx
->type
->reconfigure_port(efx
);
1000 efx
->phy_mode
= phy_mode
;
1005 /* Reinitialise the MAC to pick up new PHY settings, even if the port is
1007 int efx_reconfigure_port(struct efx_nic
*efx
)
1011 EFX_ASSERT_RESET_SERIALISED(efx
);
1013 mutex_lock(&efx
->mac_lock
);
1014 rc
= __efx_reconfigure_port(efx
);
1015 mutex_unlock(&efx
->mac_lock
);
1020 /* Asynchronous work item for changing MAC promiscuity and multicast
1021 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
1023 static void efx_mac_work(struct work_struct
*data
)
1025 struct efx_nic
*efx
= container_of(data
, struct efx_nic
, mac_work
);
1027 mutex_lock(&efx
->mac_lock
);
1028 if (efx
->port_enabled
)
1029 efx
->type
->reconfigure_mac(efx
);
1030 mutex_unlock(&efx
->mac_lock
);
1033 static int efx_probe_port(struct efx_nic
*efx
)
1037 netif_dbg(efx
, probe
, efx
->net_dev
, "create port\n");
1040 efx
->phy_mode
= PHY_MODE_SPECIAL
;
1042 /* Connect up MAC/PHY operations table */
1043 rc
= efx
->type
->probe_port(efx
);
1047 /* Initialise MAC address to permanent address */
1048 memcpy(efx
->net_dev
->dev_addr
, efx
->net_dev
->perm_addr
, ETH_ALEN
);
1053 static int efx_init_port(struct efx_nic
*efx
)
1057 netif_dbg(efx
, drv
, efx
->net_dev
, "init port\n");
1059 mutex_lock(&efx
->mac_lock
);
1061 rc
= efx
->phy_op
->init(efx
);
1065 efx
->port_initialized
= true;
1067 /* Reconfigure the MAC before creating dma queues (required for
1068 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
1069 efx
->type
->reconfigure_mac(efx
);
1071 /* Ensure the PHY advertises the correct flow control settings */
1072 rc
= efx
->phy_op
->reconfigure(efx
);
1076 mutex_unlock(&efx
->mac_lock
);
1080 efx
->phy_op
->fini(efx
);
1082 mutex_unlock(&efx
->mac_lock
);
1086 static void efx_start_port(struct efx_nic
*efx
)
1088 netif_dbg(efx
, ifup
, efx
->net_dev
, "start port\n");
1089 BUG_ON(efx
->port_enabled
);
1091 mutex_lock(&efx
->mac_lock
);
1092 efx
->port_enabled
= true;
1094 /* efx_mac_work() might have been scheduled after efx_stop_port(),
1095 * and then cancelled by efx_flush_all() */
1096 efx
->type
->reconfigure_mac(efx
);
1098 mutex_unlock(&efx
->mac_lock
);
1101 /* Prevent efx_mac_work() and efx_monitor() from working */
1102 static void efx_stop_port(struct efx_nic
*efx
)
1104 netif_dbg(efx
, ifdown
, efx
->net_dev
, "stop port\n");
1106 mutex_lock(&efx
->mac_lock
);
1107 efx
->port_enabled
= false;
1108 mutex_unlock(&efx
->mac_lock
);
1110 /* Serialise against efx_set_multicast_list() */
1111 netif_addr_lock_bh(efx
->net_dev
);
1112 netif_addr_unlock_bh(efx
->net_dev
);
1115 static void efx_fini_port(struct efx_nic
*efx
)
1117 netif_dbg(efx
, drv
, efx
->net_dev
, "shut down port\n");
1119 if (!efx
->port_initialized
)
1122 efx
->phy_op
->fini(efx
);
1123 efx
->port_initialized
= false;
1125 efx
->link_state
.up
= false;
1126 efx_link_status_changed(efx
);
1129 static void efx_remove_port(struct efx_nic
*efx
)
1131 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying port\n");
1133 efx
->type
->remove_port(efx
);
1136 /**************************************************************************
1140 **************************************************************************/
1142 /* This configures the PCI device to enable I/O and DMA. */
1143 static int efx_init_io(struct efx_nic
*efx
)
1145 struct pci_dev
*pci_dev
= efx
->pci_dev
;
1146 dma_addr_t dma_mask
= efx
->type
->max_dma_mask
;
1149 netif_dbg(efx
, probe
, efx
->net_dev
, "initialising I/O\n");
1151 rc
= pci_enable_device(pci_dev
);
1153 netif_err(efx
, probe
, efx
->net_dev
,
1154 "failed to enable PCI device\n");
1158 pci_set_master(pci_dev
);
1160 /* Set the PCI DMA mask. Try all possibilities from our
1161 * genuine mask down to 32 bits, because some architectures
1162 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
1163 * masks event though they reject 46 bit masks.
1165 while (dma_mask
> 0x7fffffffUL
) {
1166 if (dma_supported(&pci_dev
->dev
, dma_mask
)) {
1167 rc
= dma_set_mask(&pci_dev
->dev
, dma_mask
);
1174 netif_err(efx
, probe
, efx
->net_dev
,
1175 "could not find a suitable DMA mask\n");
1178 netif_dbg(efx
, probe
, efx
->net_dev
,
1179 "using DMA mask %llx\n", (unsigned long long) dma_mask
);
1180 rc
= dma_set_coherent_mask(&pci_dev
->dev
, dma_mask
);
1182 /* dma_set_coherent_mask() is not *allowed* to
1183 * fail with a mask that dma_set_mask() accepted,
1184 * but just in case...
1186 netif_err(efx
, probe
, efx
->net_dev
,
1187 "failed to set consistent DMA mask\n");
1191 efx
->membase_phys
= pci_resource_start(efx
->pci_dev
, EFX_MEM_BAR
);
1192 rc
= pci_request_region(pci_dev
, EFX_MEM_BAR
, "sfc");
1194 netif_err(efx
, probe
, efx
->net_dev
,
1195 "request for memory BAR failed\n");
1199 efx
->membase
= ioremap_nocache(efx
->membase_phys
,
1200 efx
->type
->mem_map_size
);
1201 if (!efx
->membase
) {
1202 netif_err(efx
, probe
, efx
->net_dev
,
1203 "could not map memory BAR at %llx+%x\n",
1204 (unsigned long long)efx
->membase_phys
,
1205 efx
->type
->mem_map_size
);
1209 netif_dbg(efx
, probe
, efx
->net_dev
,
1210 "memory BAR at %llx+%x (virtual %p)\n",
1211 (unsigned long long)efx
->membase_phys
,
1212 efx
->type
->mem_map_size
, efx
->membase
);
1217 pci_release_region(efx
->pci_dev
, EFX_MEM_BAR
);
1219 efx
->membase_phys
= 0;
1221 pci_disable_device(efx
->pci_dev
);
1226 static void efx_fini_io(struct efx_nic
*efx
)
1228 netif_dbg(efx
, drv
, efx
->net_dev
, "shutting down I/O\n");
1231 iounmap(efx
->membase
);
1232 efx
->membase
= NULL
;
1235 if (efx
->membase_phys
) {
1236 pci_release_region(efx
->pci_dev
, EFX_MEM_BAR
);
1237 efx
->membase_phys
= 0;
1240 pci_disable_device(efx
->pci_dev
);
1243 static unsigned int efx_wanted_parallelism(struct efx_nic
*efx
)
1245 cpumask_var_t thread_mask
;
1252 if (unlikely(!zalloc_cpumask_var(&thread_mask
, GFP_KERNEL
))) {
1253 netif_warn(efx
, probe
, efx
->net_dev
,
1254 "RSS disabled due to allocation failure\n");
1259 for_each_online_cpu(cpu
) {
1260 if (!cpumask_test_cpu(cpu
, thread_mask
)) {
1262 cpumask_or(thread_mask
, thread_mask
,
1263 topology_thread_cpumask(cpu
));
1267 free_cpumask_var(thread_mask
);
1270 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1271 * table entries that are inaccessible to VFs
1273 if (efx_sriov_wanted(efx
) && efx_vf_size(efx
) > 1 &&
1274 count
> efx_vf_size(efx
)) {
1275 netif_warn(efx
, probe
, efx
->net_dev
,
1276 "Reducing number of RSS channels from %u to %u for "
1277 "VF support. Increase vf-msix-limit to use more "
1278 "channels on the PF.\n",
1279 count
, efx_vf_size(efx
));
1280 count
= efx_vf_size(efx
);
1287 efx_init_rx_cpu_rmap(struct efx_nic
*efx
, struct msix_entry
*xentries
)
1289 #ifdef CONFIG_RFS_ACCEL
1293 efx
->net_dev
->rx_cpu_rmap
= alloc_irq_cpu_rmap(efx
->n_rx_channels
);
1294 if (!efx
->net_dev
->rx_cpu_rmap
)
1296 for (i
= 0; i
< efx
->n_rx_channels
; i
++) {
1297 rc
= irq_cpu_rmap_add(efx
->net_dev
->rx_cpu_rmap
,
1298 xentries
[i
].vector
);
1300 free_irq_cpu_rmap(efx
->net_dev
->rx_cpu_rmap
);
1301 efx
->net_dev
->rx_cpu_rmap
= NULL
;
1309 /* Probe the number and type of interrupts we are able to obtain, and
1310 * the resulting numbers of channels and RX queues.
1312 static int efx_probe_interrupts(struct efx_nic
*efx
)
1314 unsigned int max_channels
=
1315 min(efx
->type
->phys_addr_channels
, EFX_MAX_CHANNELS
);
1316 unsigned int extra_channels
= 0;
1320 for (i
= 0; i
< EFX_MAX_EXTRA_CHANNELS
; i
++)
1321 if (efx
->extra_channel_type
[i
])
1324 if (efx
->interrupt_mode
== EFX_INT_MODE_MSIX
) {
1325 struct msix_entry xentries
[EFX_MAX_CHANNELS
];
1326 unsigned int n_channels
;
1328 n_channels
= efx_wanted_parallelism(efx
);
1329 if (separate_tx_channels
)
1331 n_channels
+= extra_channels
;
1332 n_channels
= min(n_channels
, max_channels
);
1334 for (i
= 0; i
< n_channels
; i
++)
1335 xentries
[i
].entry
= i
;
1336 rc
= pci_enable_msix(efx
->pci_dev
, xentries
, n_channels
);
1338 netif_err(efx
, drv
, efx
->net_dev
,
1339 "WARNING: Insufficient MSI-X vectors"
1340 " available (%d < %u).\n", rc
, n_channels
);
1341 netif_err(efx
, drv
, efx
->net_dev
,
1342 "WARNING: Performance may be reduced.\n");
1343 EFX_BUG_ON_PARANOID(rc
>= n_channels
);
1345 rc
= pci_enable_msix(efx
->pci_dev
, xentries
,
1350 efx
->n_channels
= n_channels
;
1351 if (n_channels
> extra_channels
)
1352 n_channels
-= extra_channels
;
1353 if (separate_tx_channels
) {
1354 efx
->n_tx_channels
= max(n_channels
/ 2, 1U);
1355 efx
->n_rx_channels
= max(n_channels
-
1359 efx
->n_tx_channels
= n_channels
;
1360 efx
->n_rx_channels
= n_channels
;
1362 rc
= efx_init_rx_cpu_rmap(efx
, xentries
);
1364 pci_disable_msix(efx
->pci_dev
);
1367 for (i
= 0; i
< efx
->n_channels
; i
++)
1368 efx_get_channel(efx
, i
)->irq
=
1371 /* Fall back to single channel MSI */
1372 efx
->interrupt_mode
= EFX_INT_MODE_MSI
;
1373 netif_err(efx
, drv
, efx
->net_dev
,
1374 "could not enable MSI-X\n");
1378 /* Try single interrupt MSI */
1379 if (efx
->interrupt_mode
== EFX_INT_MODE_MSI
) {
1380 efx
->n_channels
= 1;
1381 efx
->n_rx_channels
= 1;
1382 efx
->n_tx_channels
= 1;
1383 rc
= pci_enable_msi(efx
->pci_dev
);
1385 efx_get_channel(efx
, 0)->irq
= efx
->pci_dev
->irq
;
1387 netif_err(efx
, drv
, efx
->net_dev
,
1388 "could not enable MSI\n");
1389 efx
->interrupt_mode
= EFX_INT_MODE_LEGACY
;
1393 /* Assume legacy interrupts */
1394 if (efx
->interrupt_mode
== EFX_INT_MODE_LEGACY
) {
1395 efx
->n_channels
= 1 + (separate_tx_channels
? 1 : 0);
1396 efx
->n_rx_channels
= 1;
1397 efx
->n_tx_channels
= 1;
1398 efx
->legacy_irq
= efx
->pci_dev
->irq
;
1401 /* Assign extra channels if possible */
1402 j
= efx
->n_channels
;
1403 for (i
= 0; i
< EFX_MAX_EXTRA_CHANNELS
; i
++) {
1404 if (!efx
->extra_channel_type
[i
])
1406 if (efx
->interrupt_mode
!= EFX_INT_MODE_MSIX
||
1407 efx
->n_channels
<= extra_channels
) {
1408 efx
->extra_channel_type
[i
]->handle_no_channel(efx
);
1411 efx_get_channel(efx
, j
)->type
=
1412 efx
->extra_channel_type
[i
];
1416 /* RSS might be usable on VFs even if it is disabled on the PF */
1417 efx
->rss_spread
= ((efx
->n_rx_channels
> 1 || !efx_sriov_wanted(efx
)) ?
1418 efx
->n_rx_channels
: efx_vf_size(efx
));
1423 /* Enable interrupts, then probe and start the event queues */
1424 static void efx_start_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
)
1426 struct efx_channel
*channel
;
1428 BUG_ON(efx
->state
== STATE_DISABLED
);
1430 if (efx
->legacy_irq
)
1431 efx
->legacy_irq_enabled
= true;
1432 efx_nic_enable_interrupts(efx
);
1434 efx_for_each_channel(channel
, efx
) {
1435 if (!channel
->type
->keep_eventq
|| !may_keep_eventq
)
1436 efx_init_eventq(channel
);
1437 efx_start_eventq(channel
);
1440 efx_mcdi_mode_event(efx
);
1443 static void efx_stop_interrupts(struct efx_nic
*efx
, bool may_keep_eventq
)
1445 struct efx_channel
*channel
;
1447 if (efx
->state
== STATE_DISABLED
)
1450 efx_mcdi_mode_poll(efx
);
1452 efx_nic_disable_interrupts(efx
);
1453 if (efx
->legacy_irq
) {
1454 synchronize_irq(efx
->legacy_irq
);
1455 efx
->legacy_irq_enabled
= false;
1458 efx_for_each_channel(channel
, efx
) {
1460 synchronize_irq(channel
->irq
);
1462 efx_stop_eventq(channel
);
1463 if (!channel
->type
->keep_eventq
|| !may_keep_eventq
)
1464 efx_fini_eventq(channel
);
1468 static void efx_remove_interrupts(struct efx_nic
*efx
)
1470 struct efx_channel
*channel
;
1472 /* Remove MSI/MSI-X interrupts */
1473 efx_for_each_channel(channel
, efx
)
1475 pci_disable_msi(efx
->pci_dev
);
1476 pci_disable_msix(efx
->pci_dev
);
1478 /* Remove legacy interrupt */
1479 efx
->legacy_irq
= 0;
1482 static void efx_set_channels(struct efx_nic
*efx
)
1484 struct efx_channel
*channel
;
1485 struct efx_tx_queue
*tx_queue
;
1487 efx
->tx_channel_offset
=
1488 separate_tx_channels
? efx
->n_channels
- efx
->n_tx_channels
: 0;
1490 /* We need to mark which channels really have RX and TX
1491 * queues, and adjust the TX queue numbers if we have separate
1492 * RX-only and TX-only channels.
1494 efx_for_each_channel(channel
, efx
) {
1495 if (channel
->channel
< efx
->n_rx_channels
)
1496 channel
->rx_queue
.core_index
= channel
->channel
;
1498 channel
->rx_queue
.core_index
= -1;
1500 efx_for_each_channel_tx_queue(tx_queue
, channel
)
1501 tx_queue
->queue
-= (efx
->tx_channel_offset
*
1506 static int efx_probe_nic(struct efx_nic
*efx
)
1511 netif_dbg(efx
, probe
, efx
->net_dev
, "creating NIC\n");
1513 /* Carry out hardware-type specific initialisation */
1514 rc
= efx
->type
->probe(efx
);
1518 /* Determine the number of channels and queues by trying to hook
1519 * in MSI-X interrupts. */
1520 rc
= efx_probe_interrupts(efx
);
1524 efx
->type
->dimension_resources(efx
);
1526 if (efx
->n_channels
> 1)
1527 get_random_bytes(&efx
->rx_hash_key
, sizeof(efx
->rx_hash_key
));
1528 for (i
= 0; i
< ARRAY_SIZE(efx
->rx_indir_table
); i
++)
1529 efx
->rx_indir_table
[i
] =
1530 ethtool_rxfh_indir_default(i
, efx
->rss_spread
);
1532 efx_set_channels(efx
);
1533 netif_set_real_num_tx_queues(efx
->net_dev
, efx
->n_tx_channels
);
1534 netif_set_real_num_rx_queues(efx
->net_dev
, efx
->n_rx_channels
);
1536 /* Initialise the interrupt moderation settings */
1537 efx_init_irq_moderation(efx
, tx_irq_mod_usec
, rx_irq_mod_usec
, true,
1543 efx
->type
->remove(efx
);
1547 static void efx_remove_nic(struct efx_nic
*efx
)
1549 netif_dbg(efx
, drv
, efx
->net_dev
, "destroying NIC\n");
1551 efx_remove_interrupts(efx
);
1552 efx
->type
->remove(efx
);
1555 /**************************************************************************
1557 * NIC startup/shutdown
1559 *************************************************************************/
1561 static int efx_probe_all(struct efx_nic
*efx
)
1565 rc
= efx_probe_nic(efx
);
1567 netif_err(efx
, probe
, efx
->net_dev
, "failed to create NIC\n");
1571 rc
= efx_probe_port(efx
);
1573 netif_err(efx
, probe
, efx
->net_dev
, "failed to create port\n");
1577 BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_RXQ_MIN_ENT
);
1578 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE
< EFX_TXQ_MIN_ENT(efx
))) {
1582 efx
->rxq_entries
= efx
->txq_entries
= EFX_DEFAULT_DMAQ_SIZE
;
1584 rc
= efx_probe_filters(efx
);
1586 netif_err(efx
, probe
, efx
->net_dev
,
1587 "failed to create filter tables\n");
1591 rc
= efx_probe_channels(efx
);
1598 efx_remove_filters(efx
);
1600 efx_remove_port(efx
);
1602 efx_remove_nic(efx
);
1607 /* If the interface is supposed to be running but is not, start
1608 * the hardware and software data path, regular activity for the port
1609 * (MAC statistics, link polling, etc.) and schedule the port to be
1610 * reconfigured. Interrupts must already be enabled. This function
1611 * is safe to call multiple times, so long as the NIC is not disabled.
1612 * Requires the RTNL lock.
1614 static void efx_start_all(struct efx_nic
*efx
)
1616 EFX_ASSERT_RESET_SERIALISED(efx
);
1617 BUG_ON(efx
->state
== STATE_DISABLED
);
1619 /* Check that it is appropriate to restart the interface. All
1620 * of these flags are safe to read under just the rtnl lock */
1621 if (efx
->port_enabled
|| !netif_running(efx
->net_dev
))
1624 efx_start_port(efx
);
1625 efx_start_datapath(efx
);
1627 /* Start the hardware monitor if there is one */
1628 if (efx
->type
->monitor
!= NULL
)
1629 queue_delayed_work(efx
->workqueue
, &efx
->monitor_work
,
1630 efx_monitor_interval
);
1632 /* If link state detection is normally event-driven, we have
1633 * to poll now because we could have missed a change
1635 if (efx_nic_rev(efx
) >= EFX_REV_SIENA_A0
) {
1636 mutex_lock(&efx
->mac_lock
);
1637 if (efx
->phy_op
->poll(efx
))
1638 efx_link_status_changed(efx
);
1639 mutex_unlock(&efx
->mac_lock
);
1642 efx
->type
->start_stats(efx
);
1645 /* Flush all delayed work. Should only be called when no more delayed work
1646 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1647 * since we're holding the rtnl_lock at this point. */
1648 static void efx_flush_all(struct efx_nic
*efx
)
1650 /* Make sure the hardware monitor and event self-test are stopped */
1651 cancel_delayed_work_sync(&efx
->monitor_work
);
1652 efx_selftest_async_cancel(efx
);
1653 /* Stop scheduled port reconfigurations */
1654 cancel_work_sync(&efx
->mac_work
);
1657 /* Quiesce the hardware and software data path, and regular activity
1658 * for the port without bringing the link down. Safe to call multiple
1659 * times with the NIC in almost any state, but interrupts should be
1660 * enabled. Requires the RTNL lock.
1662 static void efx_stop_all(struct efx_nic
*efx
)
1664 EFX_ASSERT_RESET_SERIALISED(efx
);
1666 /* port_enabled can be read safely under the rtnl lock */
1667 if (!efx
->port_enabled
)
1670 efx
->type
->stop_stats(efx
);
1673 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
1676 /* Stop the kernel transmit interface. This is only valid if
1677 * the device is stopped or detached; otherwise the watchdog
1678 * may fire immediately.
1680 WARN_ON(netif_running(efx
->net_dev
) &&
1681 netif_device_present(efx
->net_dev
));
1682 netif_tx_disable(efx
->net_dev
);
1684 efx_stop_datapath(efx
);
1687 static void efx_remove_all(struct efx_nic
*efx
)
1689 efx_remove_channels(efx
);
1690 efx_remove_filters(efx
);
1691 efx_remove_port(efx
);
1692 efx_remove_nic(efx
);
1695 /**************************************************************************
1697 * Interrupt moderation
1699 **************************************************************************/
1701 static unsigned int irq_mod_ticks(unsigned int usecs
, unsigned int quantum_ns
)
1705 if (usecs
* 1000 < quantum_ns
)
1706 return 1; /* never round down to 0 */
1707 return usecs
* 1000 / quantum_ns
;
1710 /* Set interrupt moderation parameters */
1711 int efx_init_irq_moderation(struct efx_nic
*efx
, unsigned int tx_usecs
,
1712 unsigned int rx_usecs
, bool rx_adaptive
,
1713 bool rx_may_override_tx
)
1715 struct efx_channel
*channel
;
1716 unsigned int irq_mod_max
= DIV_ROUND_UP(efx
->type
->timer_period_max
*
1717 efx
->timer_quantum_ns
,
1719 unsigned int tx_ticks
;
1720 unsigned int rx_ticks
;
1722 EFX_ASSERT_RESET_SERIALISED(efx
);
1724 if (tx_usecs
> irq_mod_max
|| rx_usecs
> irq_mod_max
)
1727 tx_ticks
= irq_mod_ticks(tx_usecs
, efx
->timer_quantum_ns
);
1728 rx_ticks
= irq_mod_ticks(rx_usecs
, efx
->timer_quantum_ns
);
1730 if (tx_ticks
!= rx_ticks
&& efx
->tx_channel_offset
== 0 &&
1731 !rx_may_override_tx
) {
1732 netif_err(efx
, drv
, efx
->net_dev
, "Channels are shared. "
1733 "RX and TX IRQ moderation must be equal\n");
1737 efx
->irq_rx_adaptive
= rx_adaptive
;
1738 efx
->irq_rx_moderation
= rx_ticks
;
1739 efx_for_each_channel(channel
, efx
) {
1740 if (efx_channel_has_rx_queue(channel
))
1741 channel
->irq_moderation
= rx_ticks
;
1742 else if (efx_channel_has_tx_queues(channel
))
1743 channel
->irq_moderation
= tx_ticks
;
1749 void efx_get_irq_moderation(struct efx_nic
*efx
, unsigned int *tx_usecs
,
1750 unsigned int *rx_usecs
, bool *rx_adaptive
)
1752 /* We must round up when converting ticks to microseconds
1753 * because we round down when converting the other way.
1756 *rx_adaptive
= efx
->irq_rx_adaptive
;
1757 *rx_usecs
= DIV_ROUND_UP(efx
->irq_rx_moderation
*
1758 efx
->timer_quantum_ns
,
1761 /* If channels are shared between RX and TX, so is IRQ
1762 * moderation. Otherwise, IRQ moderation is the same for all
1763 * TX channels and is not adaptive.
1765 if (efx
->tx_channel_offset
== 0)
1766 *tx_usecs
= *rx_usecs
;
1768 *tx_usecs
= DIV_ROUND_UP(
1769 efx
->channel
[efx
->tx_channel_offset
]->irq_moderation
*
1770 efx
->timer_quantum_ns
,
1774 /**************************************************************************
1778 **************************************************************************/
1780 /* Run periodically off the general workqueue */
1781 static void efx_monitor(struct work_struct
*data
)
1783 struct efx_nic
*efx
= container_of(data
, struct efx_nic
,
1786 netif_vdbg(efx
, timer
, efx
->net_dev
,
1787 "hardware monitor executing on CPU %d\n",
1788 raw_smp_processor_id());
1789 BUG_ON(efx
->type
->monitor
== NULL
);
1791 /* If the mac_lock is already held then it is likely a port
1792 * reconfiguration is already in place, which will likely do
1793 * most of the work of monitor() anyway. */
1794 if (mutex_trylock(&efx
->mac_lock
)) {
1795 if (efx
->port_enabled
)
1796 efx
->type
->monitor(efx
);
1797 mutex_unlock(&efx
->mac_lock
);
1800 queue_delayed_work(efx
->workqueue
, &efx
->monitor_work
,
1801 efx_monitor_interval
);
1804 /**************************************************************************
1808 *************************************************************************/
1811 * Context: process, rtnl_lock() held.
1813 static int efx_ioctl(struct net_device
*net_dev
, struct ifreq
*ifr
, int cmd
)
1815 struct efx_nic
*efx
= netdev_priv(net_dev
);
1816 struct mii_ioctl_data
*data
= if_mii(ifr
);
1818 if (cmd
== SIOCSHWTSTAMP
)
1819 return efx_ptp_ioctl(efx
, ifr
, cmd
);
1821 /* Convert phy_id from older PRTAD/DEVAD format */
1822 if ((cmd
== SIOCGMIIREG
|| cmd
== SIOCSMIIREG
) &&
1823 (data
->phy_id
& 0xfc00) == 0x0400)
1824 data
->phy_id
^= MDIO_PHY_ID_C45
| 0x0400;
1826 return mdio_mii_ioctl(&efx
->mdio
, data
, cmd
);
1829 /**************************************************************************
1833 **************************************************************************/
1835 static void efx_init_napi_channel(struct efx_channel
*channel
)
1837 struct efx_nic
*efx
= channel
->efx
;
1839 channel
->napi_dev
= efx
->net_dev
;
1840 netif_napi_add(channel
->napi_dev
, &channel
->napi_str
,
1841 efx_poll
, napi_weight
);
1844 static void efx_init_napi(struct efx_nic
*efx
)
1846 struct efx_channel
*channel
;
1848 efx_for_each_channel(channel
, efx
)
1849 efx_init_napi_channel(channel
);
1852 static void efx_fini_napi_channel(struct efx_channel
*channel
)
1854 if (channel
->napi_dev
)
1855 netif_napi_del(&channel
->napi_str
);
1856 channel
->napi_dev
= NULL
;
1859 static void efx_fini_napi(struct efx_nic
*efx
)
1861 struct efx_channel
*channel
;
1863 efx_for_each_channel(channel
, efx
)
1864 efx_fini_napi_channel(channel
);
1867 /**************************************************************************
1869 * Kernel netpoll interface
1871 *************************************************************************/
1873 #ifdef CONFIG_NET_POLL_CONTROLLER
1875 /* Although in the common case interrupts will be disabled, this is not
1876 * guaranteed. However, all our work happens inside the NAPI callback,
1877 * so no locking is required.
1879 static void efx_netpoll(struct net_device
*net_dev
)
1881 struct efx_nic
*efx
= netdev_priv(net_dev
);
1882 struct efx_channel
*channel
;
1884 efx_for_each_channel(channel
, efx
)
1885 efx_schedule_channel(channel
);
1890 /**************************************************************************
1892 * Kernel net device interface
1894 *************************************************************************/
1896 /* Context: process, rtnl_lock() held. */
1897 static int efx_net_open(struct net_device
*net_dev
)
1899 struct efx_nic
*efx
= netdev_priv(net_dev
);
1902 netif_dbg(efx
, ifup
, efx
->net_dev
, "opening device on CPU %d\n",
1903 raw_smp_processor_id());
1905 rc
= efx_check_disabled(efx
);
1908 if (efx
->phy_mode
& PHY_MODE_SPECIAL
)
1910 if (efx_mcdi_poll_reboot(efx
) && efx_reset(efx
, RESET_TYPE_ALL
))
1913 /* Notify the kernel of the link state polled during driver load,
1914 * before the monitor starts running */
1915 efx_link_status_changed(efx
);
1918 efx_selftest_async_start(efx
);
1922 /* Context: process, rtnl_lock() held.
1923 * Note that the kernel will ignore our return code; this method
1924 * should really be a void.
1926 static int efx_net_stop(struct net_device
*net_dev
)
1928 struct efx_nic
*efx
= netdev_priv(net_dev
);
1930 netif_dbg(efx
, ifdown
, efx
->net_dev
, "closing on CPU %d\n",
1931 raw_smp_processor_id());
1933 /* Stop the device and flush all the channels */
1939 /* Context: process, dev_base_lock or RTNL held, non-blocking. */
1940 static struct rtnl_link_stats64
*efx_net_stats(struct net_device
*net_dev
,
1941 struct rtnl_link_stats64
*stats
)
1943 struct efx_nic
*efx
= netdev_priv(net_dev
);
1944 struct efx_mac_stats
*mac_stats
= &efx
->mac_stats
;
1946 spin_lock_bh(&efx
->stats_lock
);
1948 efx
->type
->update_stats(efx
);
1950 stats
->rx_packets
= mac_stats
->rx_packets
;
1951 stats
->tx_packets
= mac_stats
->tx_packets
;
1952 stats
->rx_bytes
= mac_stats
->rx_bytes
;
1953 stats
->tx_bytes
= mac_stats
->tx_bytes
;
1954 stats
->rx_dropped
= efx
->n_rx_nodesc_drop_cnt
;
1955 stats
->multicast
= mac_stats
->rx_multicast
;
1956 stats
->collisions
= mac_stats
->tx_collision
;
1957 stats
->rx_length_errors
= (mac_stats
->rx_gtjumbo
+
1958 mac_stats
->rx_length_error
);
1959 stats
->rx_crc_errors
= mac_stats
->rx_bad
;
1960 stats
->rx_frame_errors
= mac_stats
->rx_align_error
;
1961 stats
->rx_fifo_errors
= mac_stats
->rx_overflow
;
1962 stats
->rx_missed_errors
= mac_stats
->rx_missed
;
1963 stats
->tx_window_errors
= mac_stats
->tx_late_collision
;
1965 stats
->rx_errors
= (stats
->rx_length_errors
+
1966 stats
->rx_crc_errors
+
1967 stats
->rx_frame_errors
+
1968 mac_stats
->rx_symbol_error
);
1969 stats
->tx_errors
= (stats
->tx_window_errors
+
1972 spin_unlock_bh(&efx
->stats_lock
);
1977 /* Context: netif_tx_lock held, BHs disabled. */
1978 static void efx_watchdog(struct net_device
*net_dev
)
1980 struct efx_nic
*efx
= netdev_priv(net_dev
);
1982 netif_err(efx
, tx_err
, efx
->net_dev
,
1983 "TX stuck with port_enabled=%d: resetting channels\n",
1986 efx_schedule_reset(efx
, RESET_TYPE_TX_WATCHDOG
);
1990 /* Context: process, rtnl_lock() held. */
1991 static int efx_change_mtu(struct net_device
*net_dev
, int new_mtu
)
1993 struct efx_nic
*efx
= netdev_priv(net_dev
);
1996 rc
= efx_check_disabled(efx
);
1999 if (new_mtu
> EFX_MAX_MTU
)
2002 netif_dbg(efx
, drv
, efx
->net_dev
, "changing MTU to %d\n", new_mtu
);
2004 efx_device_detach_sync(efx
);
2007 mutex_lock(&efx
->mac_lock
);
2008 net_dev
->mtu
= new_mtu
;
2009 efx
->type
->reconfigure_mac(efx
);
2010 mutex_unlock(&efx
->mac_lock
);
2013 netif_device_attach(efx
->net_dev
);
2017 static int efx_set_mac_address(struct net_device
*net_dev
, void *data
)
2019 struct efx_nic
*efx
= netdev_priv(net_dev
);
2020 struct sockaddr
*addr
= data
;
2021 char *new_addr
= addr
->sa_data
;
2023 if (!is_valid_ether_addr(new_addr
)) {
2024 netif_err(efx
, drv
, efx
->net_dev
,
2025 "invalid ethernet MAC address requested: %pM\n",
2027 return -EADDRNOTAVAIL
;
2030 memcpy(net_dev
->dev_addr
, new_addr
, net_dev
->addr_len
);
2031 efx_sriov_mac_address_changed(efx
);
2033 /* Reconfigure the MAC */
2034 mutex_lock(&efx
->mac_lock
);
2035 efx
->type
->reconfigure_mac(efx
);
2036 mutex_unlock(&efx
->mac_lock
);
2041 /* Context: netif_addr_lock held, BHs disabled. */
2042 static void efx_set_rx_mode(struct net_device
*net_dev
)
2044 struct efx_nic
*efx
= netdev_priv(net_dev
);
2045 struct netdev_hw_addr
*ha
;
2046 union efx_multicast_hash
*mc_hash
= &efx
->multicast_hash
;
2050 efx
->promiscuous
= !!(net_dev
->flags
& IFF_PROMISC
);
2052 /* Build multicast hash table */
2053 if (efx
->promiscuous
|| (net_dev
->flags
& IFF_ALLMULTI
)) {
2054 memset(mc_hash
, 0xff, sizeof(*mc_hash
));
2056 memset(mc_hash
, 0x00, sizeof(*mc_hash
));
2057 netdev_for_each_mc_addr(ha
, net_dev
) {
2058 crc
= ether_crc_le(ETH_ALEN
, ha
->addr
);
2059 bit
= crc
& (EFX_MCAST_HASH_ENTRIES
- 1);
2060 __set_bit_le(bit
, mc_hash
);
2063 /* Broadcast packets go through the multicast hash filter.
2064 * ether_crc_le() of the broadcast address is 0xbe2612ff
2065 * so we always add bit 0xff to the mask.
2067 __set_bit_le(0xff, mc_hash
);
2070 if (efx
->port_enabled
)
2071 queue_work(efx
->workqueue
, &efx
->mac_work
);
2072 /* Otherwise efx_start_port() will do this */
2075 static int efx_set_features(struct net_device
*net_dev
, netdev_features_t data
)
2077 struct efx_nic
*efx
= netdev_priv(net_dev
);
2079 /* If disabling RX n-tuple filtering, clear existing filters */
2080 if (net_dev
->features
& ~data
& NETIF_F_NTUPLE
)
2081 efx_filter_clear_rx(efx
, EFX_FILTER_PRI_MANUAL
);
2086 static const struct net_device_ops efx_netdev_ops
= {
2087 .ndo_open
= efx_net_open
,
2088 .ndo_stop
= efx_net_stop
,
2089 .ndo_get_stats64
= efx_net_stats
,
2090 .ndo_tx_timeout
= efx_watchdog
,
2091 .ndo_start_xmit
= efx_hard_start_xmit
,
2092 .ndo_validate_addr
= eth_validate_addr
,
2093 .ndo_do_ioctl
= efx_ioctl
,
2094 .ndo_change_mtu
= efx_change_mtu
,
2095 .ndo_set_mac_address
= efx_set_mac_address
,
2096 .ndo_set_rx_mode
= efx_set_rx_mode
,
2097 .ndo_set_features
= efx_set_features
,
2098 #ifdef CONFIG_SFC_SRIOV
2099 .ndo_set_vf_mac
= efx_sriov_set_vf_mac
,
2100 .ndo_set_vf_vlan
= efx_sriov_set_vf_vlan
,
2101 .ndo_set_vf_spoofchk
= efx_sriov_set_vf_spoofchk
,
2102 .ndo_get_vf_config
= efx_sriov_get_vf_config
,
2104 #ifdef CONFIG_NET_POLL_CONTROLLER
2105 .ndo_poll_controller
= efx_netpoll
,
2107 .ndo_setup_tc
= efx_setup_tc
,
2108 #ifdef CONFIG_RFS_ACCEL
2109 .ndo_rx_flow_steer
= efx_filter_rfs
,
2113 static void efx_update_name(struct efx_nic
*efx
)
2115 strcpy(efx
->name
, efx
->net_dev
->name
);
2116 efx_mtd_rename(efx
);
2117 efx_set_channel_names(efx
);
2120 static int efx_netdev_event(struct notifier_block
*this,
2121 unsigned long event
, void *ptr
)
2123 struct net_device
*net_dev
= ptr
;
2125 if (net_dev
->netdev_ops
== &efx_netdev_ops
&&
2126 event
== NETDEV_CHANGENAME
)
2127 efx_update_name(netdev_priv(net_dev
));
2132 static struct notifier_block efx_netdev_notifier
= {
2133 .notifier_call
= efx_netdev_event
,
2137 show_phy_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2139 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2140 return sprintf(buf
, "%d\n", efx
->phy_type
);
2142 static DEVICE_ATTR(phy_type
, 0444, show_phy_type
, NULL
);
2144 static int efx_register_netdev(struct efx_nic
*efx
)
2146 struct net_device
*net_dev
= efx
->net_dev
;
2147 struct efx_channel
*channel
;
2150 net_dev
->watchdog_timeo
= 5 * HZ
;
2151 net_dev
->irq
= efx
->pci_dev
->irq
;
2152 net_dev
->netdev_ops
= &efx_netdev_ops
;
2153 SET_ETHTOOL_OPS(net_dev
, &efx_ethtool_ops
);
2154 net_dev
->gso_max_segs
= EFX_TSO_MAX_SEGS
;
2158 /* Enable resets to be scheduled and check whether any were
2159 * already requested. If so, the NIC is probably hosed so we
2162 efx
->state
= STATE_READY
;
2163 smp_mb(); /* ensure we change state before checking reset_pending */
2164 if (efx
->reset_pending
) {
2165 netif_err(efx
, probe
, efx
->net_dev
,
2166 "aborting probe due to scheduled reset\n");
2171 rc
= dev_alloc_name(net_dev
, net_dev
->name
);
2174 efx_update_name(efx
);
2176 /* Always start with carrier off; PHY events will detect the link */
2177 netif_carrier_off(net_dev
);
2179 rc
= register_netdevice(net_dev
);
2183 efx_for_each_channel(channel
, efx
) {
2184 struct efx_tx_queue
*tx_queue
;
2185 efx_for_each_channel_tx_queue(tx_queue
, channel
)
2186 efx_init_tx_queue_core_txq(tx_queue
);
2191 rc
= device_create_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
2193 netif_err(efx
, drv
, efx
->net_dev
,
2194 "failed to init net dev attributes\n");
2195 goto fail_registered
;
2202 unregister_netdevice(net_dev
);
2204 efx
->state
= STATE_UNINIT
;
2206 netif_err(efx
, drv
, efx
->net_dev
, "could not register net dev\n");
2210 static void efx_unregister_netdev(struct efx_nic
*efx
)
2212 struct efx_channel
*channel
;
2213 struct efx_tx_queue
*tx_queue
;
2218 BUG_ON(netdev_priv(efx
->net_dev
) != efx
);
2220 /* Free up any skbs still remaining. This has to happen before
2221 * we try to unregister the netdev as running their destructors
2222 * may be needed to get the device ref. count to 0. */
2223 efx_for_each_channel(channel
, efx
) {
2224 efx_for_each_channel_tx_queue(tx_queue
, channel
)
2225 efx_release_tx_buffers(tx_queue
);
2228 strlcpy(efx
->name
, pci_name(efx
->pci_dev
), sizeof(efx
->name
));
2229 device_remove_file(&efx
->pci_dev
->dev
, &dev_attr_phy_type
);
2232 unregister_netdevice(efx
->net_dev
);
2233 efx
->state
= STATE_UNINIT
;
2237 /**************************************************************************
2239 * Device reset and suspend
2241 **************************************************************************/
2243 /* Tears down the entire software state and most of the hardware state
2245 void efx_reset_down(struct efx_nic
*efx
, enum reset_type method
)
2247 EFX_ASSERT_RESET_SERIALISED(efx
);
2250 efx_stop_interrupts(efx
, false);
2252 mutex_lock(&efx
->mac_lock
);
2253 if (efx
->port_initialized
&& method
!= RESET_TYPE_INVISIBLE
)
2254 efx
->phy_op
->fini(efx
);
2255 efx
->type
->fini(efx
);
2258 /* This function will always ensure that the locks acquired in
2259 * efx_reset_down() are released. A failure return code indicates
2260 * that we were unable to reinitialise the hardware, and the
2261 * driver should be disabled. If ok is false, then the rx and tx
2262 * engines are not restarted, pending a RESET_DISABLE. */
2263 int efx_reset_up(struct efx_nic
*efx
, enum reset_type method
, bool ok
)
2267 EFX_ASSERT_RESET_SERIALISED(efx
);
2269 rc
= efx
->type
->init(efx
);
2271 netif_err(efx
, drv
, efx
->net_dev
, "failed to initialise NIC\n");
2278 if (efx
->port_initialized
&& method
!= RESET_TYPE_INVISIBLE
) {
2279 rc
= efx
->phy_op
->init(efx
);
2282 if (efx
->phy_op
->reconfigure(efx
))
2283 netif_err(efx
, drv
, efx
->net_dev
,
2284 "could not restore PHY settings\n");
2287 efx
->type
->reconfigure_mac(efx
);
2289 efx_start_interrupts(efx
, false);
2290 efx_restore_filters(efx
);
2291 efx_sriov_reset(efx
);
2293 mutex_unlock(&efx
->mac_lock
);
2300 efx
->port_initialized
= false;
2302 mutex_unlock(&efx
->mac_lock
);
2307 /* Reset the NIC using the specified method. Note that the reset may
2308 * fail, in which case the card will be left in an unusable state.
2310 * Caller must hold the rtnl_lock.
2312 int efx_reset(struct efx_nic
*efx
, enum reset_type method
)
2317 netif_info(efx
, drv
, efx
->net_dev
, "resetting (%s)\n",
2318 RESET_TYPE(method
));
2320 efx_device_detach_sync(efx
);
2321 efx_reset_down(efx
, method
);
2323 rc
= efx
->type
->reset(efx
, method
);
2325 netif_err(efx
, drv
, efx
->net_dev
, "failed to reset hardware\n");
2329 /* Clear flags for the scopes we covered. We assume the NIC and
2330 * driver are now quiescent so that there is no race here.
2332 efx
->reset_pending
&= -(1 << (method
+ 1));
2334 /* Reinitialise bus-mastering, which may have been turned off before
2335 * the reset was scheduled. This is still appropriate, even in the
2336 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
2337 * can respond to requests. */
2338 pci_set_master(efx
->pci_dev
);
2341 /* Leave device stopped if necessary */
2343 method
== RESET_TYPE_DISABLE
||
2344 method
== RESET_TYPE_RECOVER_OR_DISABLE
;
2345 rc2
= efx_reset_up(efx
, method
, !disabled
);
2353 dev_close(efx
->net_dev
);
2354 netif_err(efx
, drv
, efx
->net_dev
, "has been disabled\n");
2355 efx
->state
= STATE_DISABLED
;
2357 netif_dbg(efx
, drv
, efx
->net_dev
, "reset complete\n");
2358 netif_device_attach(efx
->net_dev
);
2363 /* Try recovery mechanisms.
2364 * For now only EEH is supported.
2365 * Returns 0 if the recovery mechanisms are unsuccessful.
2366 * Returns a non-zero value otherwise.
2368 static int efx_try_recovery(struct efx_nic
*efx
)
2371 /* A PCI error can occur and not be seen by EEH because nothing
2372 * happens on the PCI bus. In this case the driver may fail and
2373 * schedule a 'recover or reset', leading to this recovery handler.
2374 * Manually call the eeh failure check function.
2376 struct eeh_dev
*eehdev
=
2377 of_node_to_eeh_dev(pci_device_to_OF_node(efx
->pci_dev
));
2379 if (eeh_dev_check_failure(eehdev
)) {
2380 /* The EEH mechanisms will handle the error and reset the
2381 * device if necessary.
2389 /* The worker thread exists so that code that cannot sleep can
2390 * schedule a reset for later.
2392 static void efx_reset_work(struct work_struct
*data
)
2394 struct efx_nic
*efx
= container_of(data
, struct efx_nic
, reset_work
);
2395 unsigned long pending
;
2396 enum reset_type method
;
2398 pending
= ACCESS_ONCE(efx
->reset_pending
);
2399 method
= fls(pending
) - 1;
2401 if ((method
== RESET_TYPE_RECOVER_OR_DISABLE
||
2402 method
== RESET_TYPE_RECOVER_OR_ALL
) &&
2403 efx_try_recovery(efx
))
2411 /* We checked the state in efx_schedule_reset() but it may
2412 * have changed by now. Now that we have the RTNL lock,
2413 * it cannot change again.
2415 if (efx
->state
== STATE_READY
)
2416 (void)efx_reset(efx
, method
);
2421 void efx_schedule_reset(struct efx_nic
*efx
, enum reset_type type
)
2423 enum reset_type method
;
2425 if (efx
->state
== STATE_RECOVERY
) {
2426 netif_dbg(efx
, drv
, efx
->net_dev
,
2427 "recovering: skip scheduling %s reset\n",
2433 case RESET_TYPE_INVISIBLE
:
2434 case RESET_TYPE_ALL
:
2435 case RESET_TYPE_RECOVER_OR_ALL
:
2436 case RESET_TYPE_WORLD
:
2437 case RESET_TYPE_DISABLE
:
2438 case RESET_TYPE_RECOVER_OR_DISABLE
:
2440 netif_dbg(efx
, drv
, efx
->net_dev
, "scheduling %s reset\n",
2441 RESET_TYPE(method
));
2444 method
= efx
->type
->map_reset_reason(type
);
2445 netif_dbg(efx
, drv
, efx
->net_dev
,
2446 "scheduling %s reset for %s\n",
2447 RESET_TYPE(method
), RESET_TYPE(type
));
2451 set_bit(method
, &efx
->reset_pending
);
2452 smp_mb(); /* ensure we change reset_pending before checking state */
2454 /* If we're not READY then just leave the flags set as the cue
2455 * to abort probing or reschedule the reset later.
2457 if (ACCESS_ONCE(efx
->state
) != STATE_READY
)
2460 /* efx_process_channel() will no longer read events once a
2461 * reset is scheduled. So switch back to poll'd MCDI completions. */
2462 efx_mcdi_mode_poll(efx
);
2464 queue_work(reset_workqueue
, &efx
->reset_work
);
2467 /**************************************************************************
2469 * List of NICs we support
2471 **************************************************************************/
2473 /* PCI device ID table */
2474 static DEFINE_PCI_DEVICE_TABLE(efx_pci_table
) = {
2475 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
,
2476 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0
),
2477 .driver_data
= (unsigned long) &falcon_a1_nic_type
},
2478 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
,
2479 PCI_DEVICE_ID_SOLARFLARE_SFC4000B
),
2480 .driver_data
= (unsigned long) &falcon_b0_nic_type
},
2481 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0803), /* SFC9020 */
2482 .driver_data
= (unsigned long) &siena_a0_nic_type
},
2483 {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE
, 0x0813), /* SFL9021 */
2484 .driver_data
= (unsigned long) &siena_a0_nic_type
},
2485 {0} /* end of list */
2488 /**************************************************************************
2490 * Dummy PHY/MAC operations
2492 * Can be used for some unimplemented operations
2493 * Needed so all function pointers are valid and do not have to be tested
2496 **************************************************************************/
2497 int efx_port_dummy_op_int(struct efx_nic
*efx
)
2501 void efx_port_dummy_op_void(struct efx_nic
*efx
) {}
2503 static bool efx_port_dummy_op_poll(struct efx_nic
*efx
)
2508 static const struct efx_phy_operations efx_dummy_phy_operations
= {
2509 .init
= efx_port_dummy_op_int
,
2510 .reconfigure
= efx_port_dummy_op_int
,
2511 .poll
= efx_port_dummy_op_poll
,
2512 .fini
= efx_port_dummy_op_void
,
2515 /**************************************************************************
2519 **************************************************************************/
2521 /* This zeroes out and then fills in the invariants in a struct
2522 * efx_nic (including all sub-structures).
2524 static int efx_init_struct(struct efx_nic
*efx
,
2525 struct pci_dev
*pci_dev
, struct net_device
*net_dev
)
2529 /* Initialise common structures */
2530 spin_lock_init(&efx
->biu_lock
);
2531 #ifdef CONFIG_SFC_MTD
2532 INIT_LIST_HEAD(&efx
->mtd_list
);
2534 INIT_WORK(&efx
->reset_work
, efx_reset_work
);
2535 INIT_DELAYED_WORK(&efx
->monitor_work
, efx_monitor
);
2536 INIT_DELAYED_WORK(&efx
->selftest_work
, efx_selftest_async_work
);
2537 efx
->pci_dev
= pci_dev
;
2538 efx
->msg_enable
= debug
;
2539 efx
->state
= STATE_UNINIT
;
2540 strlcpy(efx
->name
, pci_name(pci_dev
), sizeof(efx
->name
));
2542 efx
->net_dev
= net_dev
;
2543 spin_lock_init(&efx
->stats_lock
);
2544 mutex_init(&efx
->mac_lock
);
2545 efx
->phy_op
= &efx_dummy_phy_operations
;
2546 efx
->mdio
.dev
= net_dev
;
2547 INIT_WORK(&efx
->mac_work
, efx_mac_work
);
2548 init_waitqueue_head(&efx
->flush_wq
);
2550 for (i
= 0; i
< EFX_MAX_CHANNELS
; i
++) {
2551 efx
->channel
[i
] = efx_alloc_channel(efx
, i
, NULL
);
2552 if (!efx
->channel
[i
])
2556 EFX_BUG_ON_PARANOID(efx
->type
->phys_addr_channels
> EFX_MAX_CHANNELS
);
2558 /* Higher numbered interrupt modes are less capable! */
2559 efx
->interrupt_mode
= max(efx
->type
->max_interrupt_mode
,
2562 /* Would be good to use the net_dev name, but we're too early */
2563 snprintf(efx
->workqueue_name
, sizeof(efx
->workqueue_name
), "sfc%s",
2565 efx
->workqueue
= create_singlethread_workqueue(efx
->workqueue_name
);
2566 if (!efx
->workqueue
)
2572 efx_fini_struct(efx
);
2576 static void efx_fini_struct(struct efx_nic
*efx
)
2580 for (i
= 0; i
< EFX_MAX_CHANNELS
; i
++)
2581 kfree(efx
->channel
[i
]);
2583 if (efx
->workqueue
) {
2584 destroy_workqueue(efx
->workqueue
);
2585 efx
->workqueue
= NULL
;
2589 /**************************************************************************
2593 **************************************************************************/
2595 /* Main body of final NIC shutdown code
2596 * This is called only at module unload (or hotplug removal).
2598 static void efx_pci_remove_main(struct efx_nic
*efx
)
2600 /* Flush reset_work. It can no longer be scheduled since we
2603 BUG_ON(efx
->state
== STATE_READY
);
2604 cancel_work_sync(&efx
->reset_work
);
2606 #ifdef CONFIG_RFS_ACCEL
2607 free_irq_cpu_rmap(efx
->net_dev
->rx_cpu_rmap
);
2608 efx
->net_dev
->rx_cpu_rmap
= NULL
;
2610 efx_stop_interrupts(efx
, false);
2611 efx_nic_fini_interrupt(efx
);
2613 efx
->type
->fini(efx
);
2615 efx_remove_all(efx
);
2618 /* Final NIC shutdown
2619 * This is called only at module unload (or hotplug removal).
2621 static void efx_pci_remove(struct pci_dev
*pci_dev
)
2623 struct efx_nic
*efx
;
2625 efx
= pci_get_drvdata(pci_dev
);
2629 /* Mark the NIC as fini, then stop the interface */
2631 dev_close(efx
->net_dev
);
2632 efx_stop_interrupts(efx
, false);
2635 efx_sriov_fini(efx
);
2636 efx_unregister_netdev(efx
);
2638 efx_mtd_remove(efx
);
2640 efx_pci_remove_main(efx
);
2643 netif_dbg(efx
, drv
, efx
->net_dev
, "shutdown successful\n");
2645 efx_fini_struct(efx
);
2646 pci_set_drvdata(pci_dev
, NULL
);
2647 free_netdev(efx
->net_dev
);
2649 pci_disable_pcie_error_reporting(pci_dev
);
2652 /* NIC VPD information
2653 * Called during probe to display the part number of the
2654 * installed NIC. VPD is potentially very large but this should
2655 * always appear within the first 512 bytes.
2657 #define SFC_VPD_LEN 512
2658 static void efx_print_product_vpd(struct efx_nic
*efx
)
2660 struct pci_dev
*dev
= efx
->pci_dev
;
2661 char vpd_data
[SFC_VPD_LEN
];
2665 /* Get the vpd data from the device */
2666 vpd_size
= pci_read_vpd(dev
, 0, sizeof(vpd_data
), vpd_data
);
2667 if (vpd_size
<= 0) {
2668 netif_err(efx
, drv
, efx
->net_dev
, "Unable to read VPD\n");
2672 /* Get the Read only section */
2673 i
= pci_vpd_find_tag(vpd_data
, 0, vpd_size
, PCI_VPD_LRDT_RO_DATA
);
2675 netif_err(efx
, drv
, efx
->net_dev
, "VPD Read-only not found\n");
2679 j
= pci_vpd_lrdt_size(&vpd_data
[i
]);
2680 i
+= PCI_VPD_LRDT_TAG_SIZE
;
2681 if (i
+ j
> vpd_size
)
2684 /* Get the Part number */
2685 i
= pci_vpd_find_info_keyword(vpd_data
, i
, j
, "PN");
2687 netif_err(efx
, drv
, efx
->net_dev
, "Part number not found\n");
2691 j
= pci_vpd_info_field_size(&vpd_data
[i
]);
2692 i
+= PCI_VPD_INFO_FLD_HDR_SIZE
;
2693 if (i
+ j
> vpd_size
) {
2694 netif_err(efx
, drv
, efx
->net_dev
, "Incomplete part number\n");
2698 netif_info(efx
, drv
, efx
->net_dev
,
2699 "Part Number : %.*s\n", j
, &vpd_data
[i
]);
2703 /* Main body of NIC initialisation
2704 * This is called at module load (or hotplug insertion, theoretically).
2706 static int efx_pci_probe_main(struct efx_nic
*efx
)
2710 /* Do start-of-day initialisation */
2711 rc
= efx_probe_all(efx
);
2717 rc
= efx
->type
->init(efx
);
2719 netif_err(efx
, probe
, efx
->net_dev
,
2720 "failed to initialise NIC\n");
2724 rc
= efx_init_port(efx
);
2726 netif_err(efx
, probe
, efx
->net_dev
,
2727 "failed to initialise port\n");
2731 rc
= efx_nic_init_interrupt(efx
);
2734 efx_start_interrupts(efx
, false);
2741 efx
->type
->fini(efx
);
2744 efx_remove_all(efx
);
2749 /* NIC initialisation
2751 * This is called at module load (or hotplug insertion,
2752 * theoretically). It sets up PCI mappings, resets the NIC,
2753 * sets up and registers the network devices with the kernel and hooks
2754 * the interrupt service routine. It does not prepare the device for
2755 * transmission; this is left to the first time one of the network
2756 * interfaces is brought up (i.e. efx_net_open).
2758 static int efx_pci_probe(struct pci_dev
*pci_dev
,
2759 const struct pci_device_id
*entry
)
2761 struct net_device
*net_dev
;
2762 struct efx_nic
*efx
;
2765 /* Allocate and initialise a struct net_device and struct efx_nic */
2766 net_dev
= alloc_etherdev_mqs(sizeof(*efx
), EFX_MAX_CORE_TX_QUEUES
,
2770 efx
= netdev_priv(net_dev
);
2771 efx
->type
= (const struct efx_nic_type
*) entry
->driver_data
;
2772 net_dev
->features
|= (efx
->type
->offload_features
| NETIF_F_SG
|
2773 NETIF_F_HIGHDMA
| NETIF_F_TSO
|
2775 if (efx
->type
->offload_features
& NETIF_F_V6_CSUM
)
2776 net_dev
->features
|= NETIF_F_TSO6
;
2777 /* Mask for features that also apply to VLAN devices */
2778 net_dev
->vlan_features
|= (NETIF_F_ALL_CSUM
| NETIF_F_SG
|
2779 NETIF_F_HIGHDMA
| NETIF_F_ALL_TSO
|
2781 /* All offloads can be toggled */
2782 net_dev
->hw_features
= net_dev
->features
& ~NETIF_F_HIGHDMA
;
2783 pci_set_drvdata(pci_dev
, efx
);
2784 SET_NETDEV_DEV(net_dev
, &pci_dev
->dev
);
2785 rc
= efx_init_struct(efx
, pci_dev
, net_dev
);
2789 netif_info(efx
, probe
, efx
->net_dev
,
2790 "Solarflare NIC detected\n");
2792 efx_print_product_vpd(efx
);
2794 /* Set up basic I/O (BAR mappings etc) */
2795 rc
= efx_init_io(efx
);
2799 rc
= efx_pci_probe_main(efx
);
2803 rc
= efx_register_netdev(efx
);
2807 rc
= efx_sriov_init(efx
);
2809 netif_err(efx
, probe
, efx
->net_dev
,
2810 "SR-IOV can't be enabled rc %d\n", rc
);
2812 netif_dbg(efx
, probe
, efx
->net_dev
, "initialisation successful\n");
2814 /* Try to create MTDs, but allow this to fail */
2816 rc
= efx_mtd_probe(efx
);
2819 netif_warn(efx
, probe
, efx
->net_dev
,
2820 "failed to create MTDs (%d)\n", rc
);
2822 rc
= pci_enable_pcie_error_reporting(pci_dev
);
2823 if (rc
&& rc
!= -EINVAL
)
2824 netif_warn(efx
, probe
, efx
->net_dev
,
2825 "pci_enable_pcie_error_reporting failed (%d)\n", rc
);
2830 efx_pci_remove_main(efx
);
2834 efx_fini_struct(efx
);
2836 pci_set_drvdata(pci_dev
, NULL
);
2838 netif_dbg(efx
, drv
, efx
->net_dev
, "initialisation failed. rc=%d\n", rc
);
2839 free_netdev(net_dev
);
2843 static int efx_pm_freeze(struct device
*dev
)
2845 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2849 if (efx
->state
!= STATE_DISABLED
) {
2850 efx
->state
= STATE_UNINIT
;
2852 efx_device_detach_sync(efx
);
2855 efx_stop_interrupts(efx
, false);
2863 static int efx_pm_thaw(struct device
*dev
)
2865 struct efx_nic
*efx
= pci_get_drvdata(to_pci_dev(dev
));
2869 if (efx
->state
!= STATE_DISABLED
) {
2870 efx_start_interrupts(efx
, false);
2872 mutex_lock(&efx
->mac_lock
);
2873 efx
->phy_op
->reconfigure(efx
);
2874 mutex_unlock(&efx
->mac_lock
);
2878 netif_device_attach(efx
->net_dev
);
2880 efx
->state
= STATE_READY
;
2882 efx
->type
->resume_wol(efx
);
2887 /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2888 queue_work(reset_workqueue
, &efx
->reset_work
);
2893 static int efx_pm_poweroff(struct device
*dev
)
2895 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
2896 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
2898 efx
->type
->fini(efx
);
2900 efx
->reset_pending
= 0;
2902 pci_save_state(pci_dev
);
2903 return pci_set_power_state(pci_dev
, PCI_D3hot
);
2906 /* Used for both resume and restore */
2907 static int efx_pm_resume(struct device
*dev
)
2909 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
2910 struct efx_nic
*efx
= pci_get_drvdata(pci_dev
);
2913 rc
= pci_set_power_state(pci_dev
, PCI_D0
);
2916 pci_restore_state(pci_dev
);
2917 rc
= pci_enable_device(pci_dev
);
2920 pci_set_master(efx
->pci_dev
);
2921 rc
= efx
->type
->reset(efx
, RESET_TYPE_ALL
);
2924 rc
= efx
->type
->init(efx
);
2931 static int efx_pm_suspend(struct device
*dev
)
2936 rc
= efx_pm_poweroff(dev
);
2942 static const struct dev_pm_ops efx_pm_ops
= {
2943 .suspend
= efx_pm_suspend
,
2944 .resume
= efx_pm_resume
,
2945 .freeze
= efx_pm_freeze
,
2946 .thaw
= efx_pm_thaw
,
2947 .poweroff
= efx_pm_poweroff
,
2948 .restore
= efx_pm_resume
,
2951 /* A PCI error affecting this device was detected.
2952 * At this point MMIO and DMA may be disabled.
2953 * Stop the software path and request a slot reset.
2955 static pci_ers_result_t
efx_io_error_detected(struct pci_dev
*pdev
,
2956 enum pci_channel_state state
)
2958 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
2959 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
2961 if (state
== pci_channel_io_perm_failure
)
2962 return PCI_ERS_RESULT_DISCONNECT
;
2966 if (efx
->state
!= STATE_DISABLED
) {
2967 efx
->state
= STATE_RECOVERY
;
2968 efx
->reset_pending
= 0;
2970 efx_device_detach_sync(efx
);
2973 efx_stop_interrupts(efx
, false);
2975 status
= PCI_ERS_RESULT_NEED_RESET
;
2977 /* If the interface is disabled we don't want to do anything
2980 status
= PCI_ERS_RESULT_RECOVERED
;
2985 pci_disable_device(pdev
);
2990 /* Fake a successfull reset, which will be performed later in efx_io_resume. */
2991 static pci_ers_result_t
efx_io_slot_reset(struct pci_dev
*pdev
)
2993 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
2994 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
2997 if (pci_enable_device(pdev
)) {
2998 netif_err(efx
, hw
, efx
->net_dev
,
2999 "Cannot re-enable PCI device after reset.\n");
3000 status
= PCI_ERS_RESULT_DISCONNECT
;
3003 rc
= pci_cleanup_aer_uncorrect_error_status(pdev
);
3005 netif_err(efx
, hw
, efx
->net_dev
,
3006 "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc
);
3007 /* Non-fatal error. Continue. */
3013 /* Perform the actual reset and resume I/O operations. */
3014 static void efx_io_resume(struct pci_dev
*pdev
)
3016 struct efx_nic
*efx
= pci_get_drvdata(pdev
);
3021 if (efx
->state
== STATE_DISABLED
)
3024 rc
= efx_reset(efx
, RESET_TYPE_ALL
);
3026 netif_err(efx
, hw
, efx
->net_dev
,
3027 "efx_reset failed after PCI error (%d)\n", rc
);
3029 efx
->state
= STATE_READY
;
3030 netif_dbg(efx
, hw
, efx
->net_dev
,
3031 "Done resetting and resuming IO after PCI error.\n");
3038 /* For simplicity and reliability, we always require a slot reset and try to
3039 * reset the hardware when a pci error affecting the device is detected.
3040 * We leave both the link_reset and mmio_enabled callback unimplemented:
3041 * with our request for slot reset the mmio_enabled callback will never be
3042 * called, and the link_reset callback is not used by AER or EEH mechanisms.
3044 static struct pci_error_handlers efx_err_handlers
= {
3045 .error_detected
= efx_io_error_detected
,
3046 .slot_reset
= efx_io_slot_reset
,
3047 .resume
= efx_io_resume
,
3050 static struct pci_driver efx_pci_driver
= {
3051 .name
= KBUILD_MODNAME
,
3052 .id_table
= efx_pci_table
,
3053 .probe
= efx_pci_probe
,
3054 .remove
= efx_pci_remove
,
3055 .driver
.pm
= &efx_pm_ops
,
3056 .err_handler
= &efx_err_handlers
,
3059 /**************************************************************************
3061 * Kernel module interface
3063 *************************************************************************/
3065 module_param(interrupt_mode
, uint
, 0444);
3066 MODULE_PARM_DESC(interrupt_mode
,
3067 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
3069 static int __init
efx_init_module(void)
3073 printk(KERN_INFO
"Solarflare NET driver v" EFX_DRIVER_VERSION
"\n");
3075 rc
= register_netdevice_notifier(&efx_netdev_notifier
);
3079 rc
= efx_init_sriov();
3083 reset_workqueue
= create_singlethread_workqueue("sfc_reset");
3084 if (!reset_workqueue
) {
3089 rc
= pci_register_driver(&efx_pci_driver
);
3096 destroy_workqueue(reset_workqueue
);
3100 unregister_netdevice_notifier(&efx_netdev_notifier
);
3105 static void __exit
efx_exit_module(void)
3107 printk(KERN_INFO
"Solarflare NET driver unloading\n");
3109 pci_unregister_driver(&efx_pci_driver
);
3110 destroy_workqueue(reset_workqueue
);
3112 unregister_netdevice_notifier(&efx_netdev_notifier
);
3116 module_init(efx_init_module
);
3117 module_exit(efx_exit_module
);
3119 MODULE_AUTHOR("Solarflare Communications and "
3120 "Michael Brown <mbrown@fensystems.co.uk>");
3121 MODULE_DESCRIPTION("Solarflare Communications network driver");
3122 MODULE_LICENSE("GPL");
3123 MODULE_DEVICE_TABLE(pci
, efx_pci_table
);