aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/efx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/sfc/efx.c')
-rw-r--r--drivers/net/sfc/efx.c809
1 files changed, 474 insertions, 335 deletions
diff --git a/drivers/net/sfc/efx.c b/drivers/net/sfc/efx.c
index cc4b2f99989d..649a264d6a81 100644
--- a/drivers/net/sfc/efx.c
+++ b/drivers/net/sfc/efx.c
@@ -1,7 +1,7 @@
1/**************************************************************************** 1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards 2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd. 3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc. 4 * Copyright 2005-2009 Solarflare Communications Inc.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 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 7 * under the terms of the GNU General Public License version 2 as published
@@ -20,13 +20,75 @@
20#include <linux/crc32.h> 20#include <linux/crc32.h>
21#include <linux/ethtool.h> 21#include <linux/ethtool.h>
22#include <linux/topology.h> 22#include <linux/topology.h>
23#include <linux/gfp.h>
23#include "net_driver.h" 24#include "net_driver.h"
24#include "ethtool.h"
25#include "tx.h"
26#include "rx.h"
27#include "efx.h" 25#include "efx.h"
28#include "mdio_10g.h" 26#include "mdio_10g.h"
29#include "falcon.h" 27#include "nic.h"
28
29#include "mcdi.h"
30
31/**************************************************************************
32 *
33 * Type name strings
34 *
35 **************************************************************************
36 */
37
38/* Loopback mode names (see LOOPBACK_MODE()) */
39const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
40const char *efx_loopback_mode_names[] = {
41 [LOOPBACK_NONE] = "NONE",
42 [LOOPBACK_DATA] = "DATAPATH",
43 [LOOPBACK_GMAC] = "GMAC",
44 [LOOPBACK_XGMII] = "XGMII",
45 [LOOPBACK_XGXS] = "XGXS",
46 [LOOPBACK_XAUI] = "XAUI",
47 [LOOPBACK_GMII] = "GMII",
48 [LOOPBACK_SGMII] = "SGMII",
49 [LOOPBACK_XGBR] = "XGBR",
50 [LOOPBACK_XFI] = "XFI",
51 [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
52 [LOOPBACK_GMII_FAR] = "GMII_FAR",
53 [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
54 [LOOPBACK_XFI_FAR] = "XFI_FAR",
55 [LOOPBACK_GPHY] = "GPHY",
56 [LOOPBACK_PHYXS] = "PHYXS",
57 [LOOPBACK_PCS] = "PCS",
58 [LOOPBACK_PMAPMD] = "PMA/PMD",
59 [LOOPBACK_XPORT] = "XPORT",
60 [LOOPBACK_XGMII_WS] = "XGMII_WS",
61 [LOOPBACK_XAUI_WS] = "XAUI_WS",
62 [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
63 [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
64 [LOOPBACK_GMII_WS] = "GMII_WS",
65 [LOOPBACK_XFI_WS] = "XFI_WS",
66 [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
67 [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
68};
69
70/* Interrupt mode names (see INT_MODE())) */
71const unsigned int efx_interrupt_mode_max = EFX_INT_MODE_MAX;
72const char *efx_interrupt_mode_names[] = {
73 [EFX_INT_MODE_MSIX] = "MSI-X",
74 [EFX_INT_MODE_MSI] = "MSI",
75 [EFX_INT_MODE_LEGACY] = "legacy",
76};
77
78const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
79const char *efx_reset_type_names[] = {
80 [RESET_TYPE_INVISIBLE] = "INVISIBLE",
81 [RESET_TYPE_ALL] = "ALL",
82 [RESET_TYPE_WORLD] = "WORLD",
83 [RESET_TYPE_DISABLE] = "DISABLE",
84 [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
85 [RESET_TYPE_INT_ERROR] = "INT_ERROR",
86 [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
87 [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH",
88 [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH",
89 [RESET_TYPE_TX_SKIP] = "TX_SKIP",
90 [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
91};
30 92
31#define EFX_MAX_MTU (9 * 1024) 93#define EFX_MAX_MTU (9 * 1024)
32 94
@@ -145,7 +207,8 @@ static void efx_fini_channels(struct efx_nic *efx);
145 207
146#define EFX_ASSERT_RESET_SERIALISED(efx) \ 208#define EFX_ASSERT_RESET_SERIALISED(efx) \
147 do { \ 209 do { \
148 if (efx->state == STATE_RUNNING) \ 210 if ((efx->state == STATE_RUNNING) || \
211 (efx->state == STATE_DISABLED)) \
149 ASSERT_RTNL(); \ 212 ASSERT_RTNL(); \
150 } while (0) 213 } while (0)
151 214
@@ -171,7 +234,7 @@ static int efx_process_channel(struct efx_channel *channel, int rx_quota)
171 !channel->enabled)) 234 !channel->enabled))
172 return 0; 235 return 0;
173 236
174 rx_packets = falcon_process_eventq(channel, rx_quota); 237 rx_packets = efx_nic_process_eventq(channel, rx_quota);
175 if (rx_packets == 0) 238 if (rx_packets == 0)
176 return 0; 239 return 0;
177 240
@@ -203,7 +266,7 @@ static inline void efx_channel_processed(struct efx_channel *channel)
203 channel->work_pending = false; 266 channel->work_pending = false;
204 smp_wmb(); 267 smp_wmb();
205 268
206 falcon_eventq_read_ack(channel); 269 efx_nic_eventq_read_ack(channel);
207} 270}
208 271
209/* NAPI poll handler 272/* NAPI poll handler
@@ -228,26 +291,20 @@ static int efx_poll(struct napi_struct *napi, int budget)
228 if (channel->used_flags & EFX_USED_BY_RX && 291 if (channel->used_flags & EFX_USED_BY_RX &&
229 efx->irq_rx_adaptive && 292 efx->irq_rx_adaptive &&
230 unlikely(++channel->irq_count == 1000)) { 293 unlikely(++channel->irq_count == 1000)) {
231 unsigned old_irq_moderation = channel->irq_moderation;
232
233 if (unlikely(channel->irq_mod_score < 294 if (unlikely(channel->irq_mod_score <
234 irq_adapt_low_thresh)) { 295 irq_adapt_low_thresh)) {
235 channel->irq_moderation = 296 if (channel->irq_moderation > 1) {
236 max_t(int, 297 channel->irq_moderation -= 1;
237 channel->irq_moderation - 298 efx->type->push_irq_moderation(channel);
238 FALCON_IRQ_MOD_RESOLUTION, 299 }
239 FALCON_IRQ_MOD_RESOLUTION);
240 } else if (unlikely(channel->irq_mod_score > 300 } else if (unlikely(channel->irq_mod_score >
241 irq_adapt_high_thresh)) { 301 irq_adapt_high_thresh)) {
242 channel->irq_moderation = 302 if (channel->irq_moderation <
243 min(channel->irq_moderation + 303 efx->irq_rx_moderation) {
244 FALCON_IRQ_MOD_RESOLUTION, 304 channel->irq_moderation += 1;
245 efx->irq_rx_moderation); 305 efx->type->push_irq_moderation(channel);
306 }
246 } 307 }
247
248 if (channel->irq_moderation != old_irq_moderation)
249 falcon_set_int_moderation(channel);
250
251 channel->irq_count = 0; 308 channel->irq_count = 0;
252 channel->irq_mod_score = 0; 309 channel->irq_mod_score = 0;
253 } 310 }
@@ -280,7 +337,7 @@ void efx_process_channel_now(struct efx_channel *channel)
280 BUG_ON(!channel->enabled); 337 BUG_ON(!channel->enabled);
281 338
282 /* Disable interrupts and wait for ISRs to complete */ 339 /* Disable interrupts and wait for ISRs to complete */
283 falcon_disable_interrupts(efx); 340 efx_nic_disable_interrupts(efx);
284 if (efx->legacy_irq) 341 if (efx->legacy_irq)
285 synchronize_irq(efx->legacy_irq); 342 synchronize_irq(efx->legacy_irq);
286 if (channel->irq) 343 if (channel->irq)
@@ -290,14 +347,14 @@ void efx_process_channel_now(struct efx_channel *channel)
290 napi_disable(&channel->napi_str); 347 napi_disable(&channel->napi_str);
291 348
292 /* Poll the channel */ 349 /* Poll the channel */
293 efx_process_channel(channel, efx->type->evq_size); 350 efx_process_channel(channel, EFX_EVQ_SIZE);
294 351
295 /* Ack the eventq. This may cause an interrupt to be generated 352 /* Ack the eventq. This may cause an interrupt to be generated
296 * when they are reenabled */ 353 * when they are reenabled */
297 efx_channel_processed(channel); 354 efx_channel_processed(channel);
298 355
299 napi_enable(&channel->napi_str); 356 napi_enable(&channel->napi_str);
300 falcon_enable_interrupts(efx); 357 efx_nic_enable_interrupts(efx);
301} 358}
302 359
303/* Create event queue 360/* Create event queue
@@ -309,7 +366,7 @@ static int efx_probe_eventq(struct efx_channel *channel)
309{ 366{
310 EFX_LOG(channel->efx, "chan %d create event queue\n", channel->channel); 367 EFX_LOG(channel->efx, "chan %d create event queue\n", channel->channel);
311 368
312 return falcon_probe_eventq(channel); 369 return efx_nic_probe_eventq(channel);
313} 370}
314 371
315/* Prepare channel's event queue */ 372/* Prepare channel's event queue */
@@ -319,21 +376,21 @@ static void efx_init_eventq(struct efx_channel *channel)
319 376
320 channel->eventq_read_ptr = 0; 377 channel->eventq_read_ptr = 0;
321 378
322 falcon_init_eventq(channel); 379 efx_nic_init_eventq(channel);
323} 380}
324 381
325static void efx_fini_eventq(struct efx_channel *channel) 382static void efx_fini_eventq(struct efx_channel *channel)
326{ 383{
327 EFX_LOG(channel->efx, "chan %d fini event queue\n", channel->channel); 384 EFX_LOG(channel->efx, "chan %d fini event queue\n", channel->channel);
328 385
329 falcon_fini_eventq(channel); 386 efx_nic_fini_eventq(channel);
330} 387}
331 388
332static void efx_remove_eventq(struct efx_channel *channel) 389static void efx_remove_eventq(struct efx_channel *channel)
333{ 390{
334 EFX_LOG(channel->efx, "chan %d remove event queue\n", channel->channel); 391 EFX_LOG(channel->efx, "chan %d remove event queue\n", channel->channel);
335 392
336 falcon_remove_eventq(channel); 393 efx_nic_remove_eventq(channel);
337} 394}
338 395
339/************************************************************************** 396/**************************************************************************
@@ -499,7 +556,7 @@ static void efx_fini_channels(struct efx_nic *efx)
499 EFX_ASSERT_RESET_SERIALISED(efx); 556 EFX_ASSERT_RESET_SERIALISED(efx);
500 BUG_ON(efx->port_enabled); 557 BUG_ON(efx->port_enabled);
501 558
502 rc = falcon_flush_queues(efx); 559 rc = efx_nic_flush_queues(efx);
503 if (rc) 560 if (rc)
504 EFX_ERR(efx, "failed to flush queues\n"); 561 EFX_ERR(efx, "failed to flush queues\n");
505 else 562 else
@@ -547,8 +604,10 @@ void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay)
547 * netif_carrier_on/off) of the link status, and also maintains the 604 * netif_carrier_on/off) of the link status, and also maintains the
548 * link status's stop on the port's TX queue. 605 * link status's stop on the port's TX queue.
549 */ 606 */
550static void efx_link_status_changed(struct efx_nic *efx) 607void efx_link_status_changed(struct efx_nic *efx)
551{ 608{
609 struct efx_link_state *link_state = &efx->link_state;
610
552 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure 611 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
553 * that no events are triggered between unregister_netdev() and the 612 * that no events are triggered between unregister_netdev() and the
554 * driver unloading. A more general condition is that NETDEV_CHANGE 613 * driver unloading. A more general condition is that NETDEV_CHANGE
@@ -561,19 +620,19 @@ static void efx_link_status_changed(struct efx_nic *efx)
561 return; 620 return;
562 } 621 }
563 622
564 if (efx->link_up != netif_carrier_ok(efx->net_dev)) { 623 if (link_state->up != netif_carrier_ok(efx->net_dev)) {
565 efx->n_link_state_changes++; 624 efx->n_link_state_changes++;
566 625
567 if (efx->link_up) 626 if (link_state->up)
568 netif_carrier_on(efx->net_dev); 627 netif_carrier_on(efx->net_dev);
569 else 628 else
570 netif_carrier_off(efx->net_dev); 629 netif_carrier_off(efx->net_dev);
571 } 630 }
572 631
573 /* Status message for kernel log */ 632 /* Status message for kernel log */
574 if (efx->link_up) { 633 if (link_state->up) {
575 EFX_INFO(efx, "link up at %uMbps %s-duplex (MTU %d)%s\n", 634 EFX_INFO(efx, "link up at %uMbps %s-duplex (MTU %d)%s\n",
576 efx->link_speed, efx->link_fd ? "full" : "half", 635 link_state->speed, link_state->fd ? "full" : "half",
577 efx->net_dev->mtu, 636 efx->net_dev->mtu,
578 (efx->promiscuous ? " [PROMISC]" : "")); 637 (efx->promiscuous ? " [PROMISC]" : ""));
579 } else { 638 } else {
@@ -582,16 +641,49 @@ static void efx_link_status_changed(struct efx_nic *efx)
582 641
583} 642}
584 643
644void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
645{
646 efx->link_advertising = advertising;
647 if (advertising) {
648 if (advertising & ADVERTISED_Pause)
649 efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
650 else
651 efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
652 if (advertising & ADVERTISED_Asym_Pause)
653 efx->wanted_fc ^= EFX_FC_TX;
654 }
655}
656
657void efx_link_set_wanted_fc(struct efx_nic *efx, enum efx_fc_type wanted_fc)
658{
659 efx->wanted_fc = wanted_fc;
660 if (efx->link_advertising) {
661 if (wanted_fc & EFX_FC_RX)
662 efx->link_advertising |= (ADVERTISED_Pause |
663 ADVERTISED_Asym_Pause);
664 else
665 efx->link_advertising &= ~(ADVERTISED_Pause |
666 ADVERTISED_Asym_Pause);
667 if (wanted_fc & EFX_FC_TX)
668 efx->link_advertising ^= ADVERTISED_Asym_Pause;
669 }
670}
671
585static void efx_fini_port(struct efx_nic *efx); 672static void efx_fini_port(struct efx_nic *efx);
586 673
587/* This call reinitialises the MAC to pick up new PHY settings. The 674/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
588 * caller must hold the mac_lock */ 675 * the MAC appropriately. All other PHY configuration changes are pushed
589void __efx_reconfigure_port(struct efx_nic *efx) 676 * through phy_op->set_settings(), and pushed asynchronously to the MAC
677 * through efx_monitor().
678 *
679 * Callers must hold the mac_lock
680 */
681int __efx_reconfigure_port(struct efx_nic *efx)
590{ 682{
591 WARN_ON(!mutex_is_locked(&efx->mac_lock)); 683 enum efx_phy_mode phy_mode;
684 int rc;
592 685
593 EFX_LOG(efx, "reconfiguring MAC from PHY settings on CPU %d\n", 686 WARN_ON(!mutex_is_locked(&efx->mac_lock));
594 raw_smp_processor_id());
595 687
596 /* Serialise the promiscuous flag with efx_set_multicast_list. */ 688 /* Serialise the promiscuous flag with efx_set_multicast_list. */
597 if (efx_dev_registered(efx)) { 689 if (efx_dev_registered(efx)) {
@@ -599,61 +691,48 @@ void __efx_reconfigure_port(struct efx_nic *efx)
599 netif_addr_unlock_bh(efx->net_dev); 691 netif_addr_unlock_bh(efx->net_dev);
600 } 692 }
601 693
602 falcon_deconfigure_mac_wrapper(efx); 694 /* Disable PHY transmit in mac level loopbacks */
603 695 phy_mode = efx->phy_mode;
604 /* Reconfigure the PHY, disabling transmit in mac level loopback. */
605 if (LOOPBACK_INTERNAL(efx)) 696 if (LOOPBACK_INTERNAL(efx))
606 efx->phy_mode |= PHY_MODE_TX_DISABLED; 697 efx->phy_mode |= PHY_MODE_TX_DISABLED;
607 else 698 else
608 efx->phy_mode &= ~PHY_MODE_TX_DISABLED; 699 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
609 efx->phy_op->reconfigure(efx);
610
611 if (falcon_switch_mac(efx))
612 goto fail;
613 700
614 efx->mac_op->reconfigure(efx); 701 rc = efx->type->reconfigure_port(efx);
615 702
616 /* Inform kernel of loss/gain of carrier */ 703 if (rc)
617 efx_link_status_changed(efx); 704 efx->phy_mode = phy_mode;
618 return;
619 705
620fail: 706 return rc;
621 EFX_ERR(efx, "failed to reconfigure MAC\n");
622 efx->port_enabled = false;
623 efx_fini_port(efx);
624} 707}
625 708
626/* Reinitialise the MAC to pick up new PHY settings, even if the port is 709/* Reinitialise the MAC to pick up new PHY settings, even if the port is
627 * disabled. */ 710 * disabled. */
628void efx_reconfigure_port(struct efx_nic *efx) 711int efx_reconfigure_port(struct efx_nic *efx)
629{ 712{
713 int rc;
714
630 EFX_ASSERT_RESET_SERIALISED(efx); 715 EFX_ASSERT_RESET_SERIALISED(efx);
631 716
632 mutex_lock(&efx->mac_lock); 717 mutex_lock(&efx->mac_lock);
633 __efx_reconfigure_port(efx); 718 rc = __efx_reconfigure_port(efx);
634 mutex_unlock(&efx->mac_lock); 719 mutex_unlock(&efx->mac_lock);
635}
636
637/* Asynchronous efx_reconfigure_port work item. To speed up efx_flush_all()
638 * we don't efx_reconfigure_port() if the port is disabled. Care is taken
639 * in efx_stop_all() and efx_start_port() to prevent PHY events being lost */
640static void efx_phy_work(struct work_struct *data)
641{
642 struct efx_nic *efx = container_of(data, struct efx_nic, phy_work);
643 720
644 mutex_lock(&efx->mac_lock); 721 return rc;
645 if (efx->port_enabled)
646 __efx_reconfigure_port(efx);
647 mutex_unlock(&efx->mac_lock);
648} 722}
649 723
724/* Asynchronous work item for changing MAC promiscuity and multicast
725 * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
726 * MAC directly. */
650static void efx_mac_work(struct work_struct *data) 727static void efx_mac_work(struct work_struct *data)
651{ 728{
652 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work); 729 struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
653 730
654 mutex_lock(&efx->mac_lock); 731 mutex_lock(&efx->mac_lock);
655 if (efx->port_enabled) 732 if (efx->port_enabled) {
656 efx->mac_op->irq(efx); 733 efx->type->push_multicast_hash(efx);
734 efx->mac_op->reconfigure(efx);
735 }
657 mutex_unlock(&efx->mac_lock); 736 mutex_unlock(&efx->mac_lock);
658} 737}
659 738
@@ -663,14 +742,14 @@ static int efx_probe_port(struct efx_nic *efx)
663 742
664 EFX_LOG(efx, "create port\n"); 743 EFX_LOG(efx, "create port\n");
665 744
666 /* Connect up MAC/PHY operations table and read MAC address */
667 rc = falcon_probe_port(efx);
668 if (rc)
669 goto err;
670
671 if (phy_flash_cfg) 745 if (phy_flash_cfg)
672 efx->phy_mode = PHY_MODE_SPECIAL; 746 efx->phy_mode = PHY_MODE_SPECIAL;
673 747
748 /* Connect up MAC/PHY operations table */
749 rc = efx->type->probe_port(efx);
750 if (rc)
751 goto err;
752
674 /* Sanity check MAC address */ 753 /* Sanity check MAC address */
675 if (is_valid_ether_addr(efx->mac_address)) { 754 if (is_valid_ether_addr(efx->mac_address)) {
676 memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN); 755 memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN);
@@ -699,29 +778,33 @@ static int efx_init_port(struct efx_nic *efx)
699 778
700 EFX_LOG(efx, "init port\n"); 779 EFX_LOG(efx, "init port\n");
701 780
702 rc = efx->phy_op->init(efx);
703 if (rc)
704 return rc;
705 mutex_lock(&efx->mac_lock); 781 mutex_lock(&efx->mac_lock);
706 efx->phy_op->reconfigure(efx); 782
707 rc = falcon_switch_mac(efx); 783 rc = efx->phy_op->init(efx);
708 mutex_unlock(&efx->mac_lock);
709 if (rc) 784 if (rc)
710 goto fail; 785 goto fail1;
711 efx->mac_op->reconfigure(efx);
712 786
713 efx->port_initialized = true; 787 efx->port_initialized = true;
714 efx_stats_enable(efx); 788
789 /* Reconfigure the MAC before creating dma queues (required for
790 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
791 efx->mac_op->reconfigure(efx);
792
793 /* Ensure the PHY advertises the correct flow control settings */
794 rc = efx->phy_op->reconfigure(efx);
795 if (rc)
796 goto fail2;
797
798 mutex_unlock(&efx->mac_lock);
715 return 0; 799 return 0;
716 800
717fail: 801fail2:
718 efx->phy_op->fini(efx); 802 efx->phy_op->fini(efx);
803fail1:
804 mutex_unlock(&efx->mac_lock);
719 return rc; 805 return rc;
720} 806}
721 807
722/* Allow efx_reconfigure_port() to be scheduled, and close the window
723 * between efx_stop_port and efx_flush_all whereby a previously scheduled
724 * efx_phy_work()/efx_mac_work() may have been cancelled */
725static void efx_start_port(struct efx_nic *efx) 808static void efx_start_port(struct efx_nic *efx)
726{ 809{
727 EFX_LOG(efx, "start port\n"); 810 EFX_LOG(efx, "start port\n");
@@ -729,15 +812,16 @@ static void efx_start_port(struct efx_nic *efx)
729 812
730 mutex_lock(&efx->mac_lock); 813 mutex_lock(&efx->mac_lock);
731 efx->port_enabled = true; 814 efx->port_enabled = true;
732 __efx_reconfigure_port(efx); 815
733 efx->mac_op->irq(efx); 816 /* efx_mac_work() might have been scheduled after efx_stop_port(),
817 * and then cancelled by efx_flush_all() */
818 efx->type->push_multicast_hash(efx);
819 efx->mac_op->reconfigure(efx);
820
734 mutex_unlock(&efx->mac_lock); 821 mutex_unlock(&efx->mac_lock);
735} 822}
736 823
737/* Prevent efx_phy_work, efx_mac_work, and efx_monitor() from executing, 824/* Prevent efx_mac_work() and efx_monitor() from working */
738 * and efx_set_multicast_list() from scheduling efx_phy_work. efx_phy_work
739 * and efx_mac_work may still be scheduled via NAPI processing until
740 * efx_flush_all() is called */
741static void efx_stop_port(struct efx_nic *efx) 825static void efx_stop_port(struct efx_nic *efx)
742{ 826{
743 EFX_LOG(efx, "stop port\n"); 827 EFX_LOG(efx, "stop port\n");
@@ -760,11 +844,10 @@ static void efx_fini_port(struct efx_nic *efx)
760 if (!efx->port_initialized) 844 if (!efx->port_initialized)
761 return; 845 return;
762 846
763 efx_stats_disable(efx);
764 efx->phy_op->fini(efx); 847 efx->phy_op->fini(efx);
765 efx->port_initialized = false; 848 efx->port_initialized = false;
766 849
767 efx->link_up = false; 850 efx->link_state.up = false;
768 efx_link_status_changed(efx); 851 efx_link_status_changed(efx);
769} 852}
770 853
@@ -772,7 +855,7 @@ static void efx_remove_port(struct efx_nic *efx)
772{ 855{
773 EFX_LOG(efx, "destroying port\n"); 856 EFX_LOG(efx, "destroying port\n");
774 857
775 falcon_remove_port(efx); 858 efx->type->remove_port(efx);
776} 859}
777 860
778/************************************************************************** 861/**************************************************************************
@@ -824,9 +907,8 @@ static int efx_init_io(struct efx_nic *efx)
824 goto fail2; 907 goto fail2;
825 } 908 }
826 909
827 efx->membase_phys = pci_resource_start(efx->pci_dev, 910 efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
828 efx->type->mem_bar); 911 rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
829 rc = pci_request_region(pci_dev, efx->type->mem_bar, "sfc");
830 if (rc) { 912 if (rc) {
831 EFX_ERR(efx, "request for memory BAR failed\n"); 913 EFX_ERR(efx, "request for memory BAR failed\n");
832 rc = -EIO; 914 rc = -EIO;
@@ -835,21 +917,20 @@ static int efx_init_io(struct efx_nic *efx)
835 efx->membase = ioremap_nocache(efx->membase_phys, 917 efx->membase = ioremap_nocache(efx->membase_phys,
836 efx->type->mem_map_size); 918 efx->type->mem_map_size);
837 if (!efx->membase) { 919 if (!efx->membase) {
838 EFX_ERR(efx, "could not map memory BAR %d at %llx+%x\n", 920 EFX_ERR(efx, "could not map memory BAR at %llx+%x\n",
839 efx->type->mem_bar,
840 (unsigned long long)efx->membase_phys, 921 (unsigned long long)efx->membase_phys,
841 efx->type->mem_map_size); 922 efx->type->mem_map_size);
842 rc = -ENOMEM; 923 rc = -ENOMEM;
843 goto fail4; 924 goto fail4;
844 } 925 }
845 EFX_LOG(efx, "memory BAR %u at %llx+%x (virtual %p)\n", 926 EFX_LOG(efx, "memory BAR at %llx+%x (virtual %p)\n",
846 efx->type->mem_bar, (unsigned long long)efx->membase_phys, 927 (unsigned long long)efx->membase_phys,
847 efx->type->mem_map_size, efx->membase); 928 efx->type->mem_map_size, efx->membase);
848 929
849 return 0; 930 return 0;
850 931
851 fail4: 932 fail4:
852 pci_release_region(efx->pci_dev, efx->type->mem_bar); 933 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
853 fail3: 934 fail3:
854 efx->membase_phys = 0; 935 efx->membase_phys = 0;
855 fail2: 936 fail2:
@@ -868,7 +949,7 @@ static void efx_fini_io(struct efx_nic *efx)
868 } 949 }
869 950
870 if (efx->membase_phys) { 951 if (efx->membase_phys) {
871 pci_release_region(efx->pci_dev, efx->type->mem_bar); 952 pci_release_region(efx->pci_dev, EFX_MEM_BAR);
872 efx->membase_phys = 0; 953 efx->membase_phys = 0;
873 } 954 }
874 955
@@ -1011,7 +1092,7 @@ static int efx_probe_nic(struct efx_nic *efx)
1011 EFX_LOG(efx, "creating NIC\n"); 1092 EFX_LOG(efx, "creating NIC\n");
1012 1093
1013 /* Carry out hardware-type specific initialisation */ 1094 /* Carry out hardware-type specific initialisation */
1014 rc = falcon_probe_nic(efx); 1095 rc = efx->type->probe(efx);
1015 if (rc) 1096 if (rc)
1016 return rc; 1097 return rc;
1017 1098
@@ -1032,7 +1113,7 @@ static void efx_remove_nic(struct efx_nic *efx)
1032 EFX_LOG(efx, "destroying NIC\n"); 1113 EFX_LOG(efx, "destroying NIC\n");
1033 1114
1034 efx_remove_interrupts(efx); 1115 efx_remove_interrupts(efx);
1035 falcon_remove_nic(efx); 1116 efx->type->remove(efx);
1036} 1117}
1037 1118
1038/************************************************************************** 1119/**************************************************************************
@@ -1112,12 +1193,31 @@ static void efx_start_all(struct efx_nic *efx)
1112 efx_for_each_channel(channel, efx) 1193 efx_for_each_channel(channel, efx)
1113 efx_start_channel(channel); 1194 efx_start_channel(channel);
1114 1195
1115 falcon_enable_interrupts(efx); 1196 efx_nic_enable_interrupts(efx);
1116 1197
1117 /* Start hardware monitor if we're in RUNNING */ 1198 /* Switch to event based MCDI completions after enabling interrupts.
1118 if (efx->state == STATE_RUNNING) 1199 * If a reset has been scheduled, then we need to stay in polled mode.
1200 * Rather than serialising efx_mcdi_mode_event() [which sleeps] and
1201 * reset_pending [modified from an atomic context], we instead guarantee
1202 * that efx_mcdi_mode_poll() isn't reverted erroneously */
1203 efx_mcdi_mode_event(efx);
1204 if (efx->reset_pending != RESET_TYPE_NONE)
1205 efx_mcdi_mode_poll(efx);
1206
1207 /* Start the hardware monitor if there is one. Otherwise (we're link
1208 * event driven), we have to poll the PHY because after an event queue
1209 * flush, we could have a missed a link state change */
1210 if (efx->type->monitor != NULL) {
1119 queue_delayed_work(efx->workqueue, &efx->monitor_work, 1211 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1120 efx_monitor_interval); 1212 efx_monitor_interval);
1213 } else {
1214 mutex_lock(&efx->mac_lock);
1215 if (efx->phy_op->poll(efx))
1216 efx_link_status_changed(efx);
1217 mutex_unlock(&efx->mac_lock);
1218 }
1219
1220 efx->type->start_stats(efx);
1121} 1221}
1122 1222
1123/* Flush all delayed work. Should only be called when no more delayed work 1223/* Flush all delayed work. Should only be called when no more delayed work
@@ -1136,8 +1236,6 @@ static void efx_flush_all(struct efx_nic *efx)
1136 1236
1137 /* Stop scheduled port reconfigurations */ 1237 /* Stop scheduled port reconfigurations */
1138 cancel_work_sync(&efx->mac_work); 1238 cancel_work_sync(&efx->mac_work);
1139 cancel_work_sync(&efx->phy_work);
1140
1141} 1239}
1142 1240
1143/* Quiesce hardware and software without bringing the link down. 1241/* Quiesce hardware and software without bringing the link down.
@@ -1155,8 +1253,13 @@ static void efx_stop_all(struct efx_nic *efx)
1155 if (!efx->port_enabled) 1253 if (!efx->port_enabled)
1156 return; 1254 return;
1157 1255
1256 efx->type->stop_stats(efx);
1257
1258 /* Switch to MCDI polling on Siena before disabling interrupts */
1259 efx_mcdi_mode_poll(efx);
1260
1158 /* Disable interrupts and wait for ISR to complete */ 1261 /* Disable interrupts and wait for ISR to complete */
1159 falcon_disable_interrupts(efx); 1262 efx_nic_disable_interrupts(efx);
1160 if (efx->legacy_irq) 1263 if (efx->legacy_irq)
1161 synchronize_irq(efx->legacy_irq); 1264 synchronize_irq(efx->legacy_irq);
1162 efx_for_each_channel(channel, efx) { 1265 efx_for_each_channel(channel, efx) {
@@ -1173,15 +1276,9 @@ static void efx_stop_all(struct efx_nic *efx)
1173 * window to loose phy events */ 1276 * window to loose phy events */
1174 efx_stop_port(efx); 1277 efx_stop_port(efx);
1175 1278
1176 /* Flush efx_phy_work, efx_mac_work, refill_workqueue, monitor_work */ 1279 /* Flush efx_mac_work(), refill_workqueue, monitor_work */
1177 efx_flush_all(efx); 1280 efx_flush_all(efx);
1178 1281
1179 /* Isolate the MAC from the TX and RX engines, so that queue
1180 * flushes will complete in a timely fashion. */
1181 falcon_deconfigure_mac_wrapper(efx);
1182 msleep(10); /* Let the Rx FIFO drain */
1183 falcon_drain_tx_fifo(efx);
1184
1185 /* Stop the kernel transmit interface late, so the watchdog 1282 /* Stop the kernel transmit interface late, so the watchdog
1186 * timer isn't ticking over the flush */ 1283 * timer isn't ticking over the flush */
1187 if (efx_dev_registered(efx)) { 1284 if (efx_dev_registered(efx)) {
@@ -1201,41 +1298,39 @@ static void efx_remove_all(struct efx_nic *efx)
1201 efx_remove_nic(efx); 1298 efx_remove_nic(efx);
1202} 1299}
1203 1300
1204/* A convinience function to safely flush all the queues */
1205void efx_flush_queues(struct efx_nic *efx)
1206{
1207 EFX_ASSERT_RESET_SERIALISED(efx);
1208
1209 efx_stop_all(efx);
1210
1211 efx_fini_channels(efx);
1212 efx_init_channels(efx);
1213
1214 efx_start_all(efx);
1215}
1216
1217/************************************************************************** 1301/**************************************************************************
1218 * 1302 *
1219 * Interrupt moderation 1303 * Interrupt moderation
1220 * 1304 *
1221 **************************************************************************/ 1305 **************************************************************************/
1222 1306
1307static unsigned irq_mod_ticks(int usecs, int resolution)
1308{
1309 if (usecs <= 0)
1310 return 0; /* cannot receive interrupts ahead of time :-) */
1311 if (usecs < resolution)
1312 return 1; /* never round down to 0 */
1313 return usecs / resolution;
1314}
1315
1223/* Set interrupt moderation parameters */ 1316/* Set interrupt moderation parameters */
1224void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs, 1317void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs,
1225 bool rx_adaptive) 1318 bool rx_adaptive)
1226{ 1319{
1227 struct efx_tx_queue *tx_queue; 1320 struct efx_tx_queue *tx_queue;
1228 struct efx_rx_queue *rx_queue; 1321 struct efx_rx_queue *rx_queue;
1322 unsigned tx_ticks = irq_mod_ticks(tx_usecs, EFX_IRQ_MOD_RESOLUTION);
1323 unsigned rx_ticks = irq_mod_ticks(rx_usecs, EFX_IRQ_MOD_RESOLUTION);
1229 1324
1230 EFX_ASSERT_RESET_SERIALISED(efx); 1325 EFX_ASSERT_RESET_SERIALISED(efx);
1231 1326
1232 efx_for_each_tx_queue(tx_queue, efx) 1327 efx_for_each_tx_queue(tx_queue, efx)
1233 tx_queue->channel->irq_moderation = tx_usecs; 1328 tx_queue->channel->irq_moderation = tx_ticks;
1234 1329
1235 efx->irq_rx_adaptive = rx_adaptive; 1330 efx->irq_rx_adaptive = rx_adaptive;
1236 efx->irq_rx_moderation = rx_usecs; 1331 efx->irq_rx_moderation = rx_ticks;
1237 efx_for_each_rx_queue(rx_queue, efx) 1332 efx_for_each_rx_queue(rx_queue, efx)
1238 rx_queue->channel->irq_moderation = rx_usecs; 1333 rx_queue->channel->irq_moderation = rx_ticks;
1239} 1334}
1240 1335
1241/************************************************************************** 1336/**************************************************************************
@@ -1250,10 +1345,10 @@ static void efx_monitor(struct work_struct *data)
1250{ 1345{
1251 struct efx_nic *efx = container_of(data, struct efx_nic, 1346 struct efx_nic *efx = container_of(data, struct efx_nic,
1252 monitor_work.work); 1347 monitor_work.work);
1253 int rc;
1254 1348
1255 EFX_TRACE(efx, "hardware monitor executing on CPU %d\n", 1349 EFX_TRACE(efx, "hardware monitor executing on CPU %d\n",
1256 raw_smp_processor_id()); 1350 raw_smp_processor_id());
1351 BUG_ON(efx->type->monitor == NULL);
1257 1352
1258 /* If the mac_lock is already held then it is likely a port 1353 /* If the mac_lock is already held then it is likely a port
1259 * reconfiguration is already in place, which will likely do 1354 * reconfiguration is already in place, which will likely do
@@ -1262,15 +1357,7 @@ static void efx_monitor(struct work_struct *data)
1262 goto out_requeue; 1357 goto out_requeue;
1263 if (!efx->port_enabled) 1358 if (!efx->port_enabled)
1264 goto out_unlock; 1359 goto out_unlock;
1265 rc = efx->board_info.monitor(efx); 1360 efx->type->monitor(efx);
1266 if (rc) {
1267 EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
1268 (rc == -ERANGE) ? "reported fault" : "failed");
1269 efx->phy_mode |= PHY_MODE_LOW_POWER;
1270 falcon_sim_phy_event(efx);
1271 }
1272 efx->phy_op->poll(efx);
1273 efx->mac_op->poll(efx);
1274 1361
1275out_unlock: 1362out_unlock:
1276 mutex_unlock(&efx->mac_lock); 1363 mutex_unlock(&efx->mac_lock);
@@ -1374,6 +1461,12 @@ static int efx_net_open(struct net_device *net_dev)
1374 return -EIO; 1461 return -EIO;
1375 if (efx->phy_mode & PHY_MODE_SPECIAL) 1462 if (efx->phy_mode & PHY_MODE_SPECIAL)
1376 return -EBUSY; 1463 return -EBUSY;
1464 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
1465 return -EIO;
1466
1467 /* Notify the kernel of the link state polled during driver load,
1468 * before the monitor starts running */
1469 efx_link_status_changed(efx);
1377 1470
1378 efx_start_all(efx); 1471 efx_start_all(efx);
1379 return 0; 1472 return 0;
@@ -1400,20 +1493,6 @@ static int efx_net_stop(struct net_device *net_dev)
1400 return 0; 1493 return 0;
1401} 1494}
1402 1495
1403void efx_stats_disable(struct efx_nic *efx)
1404{
1405 spin_lock(&efx->stats_lock);
1406 ++efx->stats_disable_count;
1407 spin_unlock(&efx->stats_lock);
1408}
1409
1410void efx_stats_enable(struct efx_nic *efx)
1411{
1412 spin_lock(&efx->stats_lock);
1413 --efx->stats_disable_count;
1414 spin_unlock(&efx->stats_lock);
1415}
1416
1417/* Context: process, dev_base_lock or RTNL held, non-blocking. */ 1496/* Context: process, dev_base_lock or RTNL held, non-blocking. */
1418static struct net_device_stats *efx_net_stats(struct net_device *net_dev) 1497static struct net_device_stats *efx_net_stats(struct net_device *net_dev)
1419{ 1498{
@@ -1421,17 +1500,9 @@ static struct net_device_stats *efx_net_stats(struct net_device *net_dev)
1421 struct efx_mac_stats *mac_stats = &efx->mac_stats; 1500 struct efx_mac_stats *mac_stats = &efx->mac_stats;
1422 struct net_device_stats *stats = &net_dev->stats; 1501 struct net_device_stats *stats = &net_dev->stats;
1423 1502
1424 /* Update stats if possible, but do not wait if another thread 1503 spin_lock_bh(&efx->stats_lock);
1425 * is updating them or if MAC stats fetches are temporarily 1504 efx->type->update_stats(efx);
1426 * disabled; slightly stale stats are acceptable. 1505 spin_unlock_bh(&efx->stats_lock);
1427 */
1428 if (!spin_trylock(&efx->stats_lock))
1429 return stats;
1430 if (!efx->stats_disable_count) {
1431 efx->mac_op->update_stats(efx);
1432 falcon_update_nic_stats(efx);
1433 }
1434 spin_unlock(&efx->stats_lock);
1435 1506
1436 stats->rx_packets = mac_stats->rx_packets; 1507 stats->rx_packets = mac_stats->rx_packets;
1437 stats->tx_packets = mac_stats->tx_packets; 1508 stats->tx_packets = mac_stats->tx_packets;
@@ -1490,7 +1561,14 @@ static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1490 EFX_LOG(efx, "changing MTU to %d\n", new_mtu); 1561 EFX_LOG(efx, "changing MTU to %d\n", new_mtu);
1491 1562
1492 efx_fini_channels(efx); 1563 efx_fini_channels(efx);
1564
1565 mutex_lock(&efx->mac_lock);
1566 /* Reconfigure the MAC before enabling the dma queues so that
1567 * the RX buffers don't overflow */
1493 net_dev->mtu = new_mtu; 1568 net_dev->mtu = new_mtu;
1569 efx->mac_op->reconfigure(efx);
1570 mutex_unlock(&efx->mac_lock);
1571
1494 efx_init_channels(efx); 1572 efx_init_channels(efx);
1495 1573
1496 efx_start_all(efx); 1574 efx_start_all(efx);
@@ -1514,7 +1592,9 @@ static int efx_set_mac_address(struct net_device *net_dev, void *data)
1514 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len); 1592 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
1515 1593
1516 /* Reconfigure the MAC */ 1594 /* Reconfigure the MAC */
1517 efx_reconfigure_port(efx); 1595 mutex_lock(&efx->mac_lock);
1596 efx->mac_op->reconfigure(efx);
1597 mutex_unlock(&efx->mac_lock);
1518 1598
1519 return 0; 1599 return 0;
1520} 1600}
@@ -1523,38 +1603,34 @@ static int efx_set_mac_address(struct net_device *net_dev, void *data)
1523static void efx_set_multicast_list(struct net_device *net_dev) 1603static void efx_set_multicast_list(struct net_device *net_dev)
1524{ 1604{
1525 struct efx_nic *efx = netdev_priv(net_dev); 1605 struct efx_nic *efx = netdev_priv(net_dev);
1526 struct dev_mc_list *mc_list = net_dev->mc_list; 1606 struct dev_mc_list *mc_list;
1527 union efx_multicast_hash *mc_hash = &efx->multicast_hash; 1607 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
1528 bool promiscuous = !!(net_dev->flags & IFF_PROMISC);
1529 bool changed = (efx->promiscuous != promiscuous);
1530 u32 crc; 1608 u32 crc;
1531 int bit; 1609 int bit;
1532 int i;
1533 1610
1534 efx->promiscuous = promiscuous; 1611 efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
1535 1612
1536 /* Build multicast hash table */ 1613 /* Build multicast hash table */
1537 if (promiscuous || (net_dev->flags & IFF_ALLMULTI)) { 1614 if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
1538 memset(mc_hash, 0xff, sizeof(*mc_hash)); 1615 memset(mc_hash, 0xff, sizeof(*mc_hash));
1539 } else { 1616 } else {
1540 memset(mc_hash, 0x00, sizeof(*mc_hash)); 1617 memset(mc_hash, 0x00, sizeof(*mc_hash));
1541 for (i = 0; i < net_dev->mc_count; i++) { 1618 netdev_for_each_mc_addr(mc_list, net_dev) {
1542 crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr); 1619 crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr);
1543 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1); 1620 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1544 set_bit_le(bit, mc_hash->byte); 1621 set_bit_le(bit, mc_hash->byte);
1545 mc_list = mc_list->next;
1546 } 1622 }
1547 }
1548
1549 if (!efx->port_enabled)
1550 /* Delay pushing settings until efx_start_port() */
1551 return;
1552 1623
1553 if (changed) 1624 /* Broadcast packets go through the multicast hash filter.
1554 queue_work(efx->workqueue, &efx->phy_work); 1625 * ether_crc_le() of the broadcast address is 0xbe2612ff
1626 * so we always add bit 0xff to the mask.
1627 */
1628 set_bit_le(0xff, mc_hash->byte);
1629 }
1555 1630
1556 /* Create and activate new global multicast hash table */ 1631 if (efx->port_enabled)
1557 falcon_set_multicast_hash(efx); 1632 queue_work(efx->workqueue, &efx->mac_work);
1633 /* Otherwise efx_start_port() will do this */
1558} 1634}
1559 1635
1560static const struct net_device_ops efx_netdev_ops = { 1636static const struct net_device_ops efx_netdev_ops = {
@@ -1683,21 +1759,18 @@ static void efx_unregister_netdev(struct efx_nic *efx)
1683 1759
1684/* Tears down the entire software state and most of the hardware state 1760/* Tears down the entire software state and most of the hardware state
1685 * before reset. */ 1761 * before reset. */
1686void efx_reset_down(struct efx_nic *efx, enum reset_type method, 1762void efx_reset_down(struct efx_nic *efx, enum reset_type method)
1687 struct ethtool_cmd *ecmd)
1688{ 1763{
1689 EFX_ASSERT_RESET_SERIALISED(efx); 1764 EFX_ASSERT_RESET_SERIALISED(efx);
1690 1765
1691 efx_stats_disable(efx);
1692 efx_stop_all(efx); 1766 efx_stop_all(efx);
1693 mutex_lock(&efx->mac_lock); 1767 mutex_lock(&efx->mac_lock);
1694 mutex_lock(&efx->spi_lock); 1768 mutex_lock(&efx->spi_lock);
1695 1769
1696 efx->phy_op->get_settings(efx, ecmd);
1697
1698 efx_fini_channels(efx); 1770 efx_fini_channels(efx);
1699 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) 1771 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
1700 efx->phy_op->fini(efx); 1772 efx->phy_op->fini(efx);
1773 efx->type->fini(efx);
1701} 1774}
1702 1775
1703/* This function will always ensure that the locks acquired in 1776/* This function will always ensure that the locks acquired in
@@ -1705,79 +1778,67 @@ void efx_reset_down(struct efx_nic *efx, enum reset_type method,
1705 * that we were unable to reinitialise the hardware, and the 1778 * that we were unable to reinitialise the hardware, and the
1706 * driver should be disabled. If ok is false, then the rx and tx 1779 * driver should be disabled. If ok is false, then the rx and tx
1707 * engines are not restarted, pending a RESET_DISABLE. */ 1780 * engines are not restarted, pending a RESET_DISABLE. */
1708int efx_reset_up(struct efx_nic *efx, enum reset_type method, 1781int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
1709 struct ethtool_cmd *ecmd, bool ok)
1710{ 1782{
1711 int rc; 1783 int rc;
1712 1784
1713 EFX_ASSERT_RESET_SERIALISED(efx); 1785 EFX_ASSERT_RESET_SERIALISED(efx);
1714 1786
1715 rc = falcon_init_nic(efx); 1787 rc = efx->type->init(efx);
1716 if (rc) { 1788 if (rc) {
1717 EFX_ERR(efx, "failed to initialise NIC\n"); 1789 EFX_ERR(efx, "failed to initialise NIC\n");
1718 ok = false; 1790 goto fail;
1719 } 1791 }
1720 1792
1793 if (!ok)
1794 goto fail;
1795
1721 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) { 1796 if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
1722 if (ok) { 1797 rc = efx->phy_op->init(efx);
1723 rc = efx->phy_op->init(efx); 1798 if (rc)
1724 if (rc) 1799 goto fail;
1725 ok = false; 1800 if (efx->phy_op->reconfigure(efx))
1726 } 1801 EFX_ERR(efx, "could not restore PHY settings\n");
1727 if (!ok)
1728 efx->port_initialized = false;
1729 } 1802 }
1730 1803
1731 if (ok) { 1804 efx->mac_op->reconfigure(efx);
1732 efx_init_channels(efx);
1733 1805
1734 if (efx->phy_op->set_settings(efx, ecmd)) 1806 efx_init_channels(efx);
1735 EFX_ERR(efx, "could not restore PHY settings\n"); 1807
1736 } 1808 mutex_unlock(&efx->spi_lock);
1809 mutex_unlock(&efx->mac_lock);
1810
1811 efx_start_all(efx);
1812
1813 return 0;
1814
1815fail:
1816 efx->port_initialized = false;
1737 1817
1738 mutex_unlock(&efx->spi_lock); 1818 mutex_unlock(&efx->spi_lock);
1739 mutex_unlock(&efx->mac_lock); 1819 mutex_unlock(&efx->mac_lock);
1740 1820
1741 if (ok) {
1742 efx_start_all(efx);
1743 efx_stats_enable(efx);
1744 }
1745 return rc; 1821 return rc;
1746} 1822}
1747 1823
1748/* Reset the NIC as transparently as possible. Do not reset the PHY 1824/* Reset the NIC using the specified method. Note that the reset may
1749 * Note that the reset may fail, in which case the card will be left 1825 * fail, in which case the card will be left in an unusable state.
1750 * in a most-probably-unusable state.
1751 *
1752 * This function will sleep. You cannot reset from within an atomic
1753 * state; use efx_schedule_reset() instead.
1754 * 1826 *
1755 * Grabs the rtnl_lock. 1827 * Caller must hold the rtnl_lock.
1756 */ 1828 */
1757static int efx_reset(struct efx_nic *efx) 1829int efx_reset(struct efx_nic *efx, enum reset_type method)
1758{ 1830{
1759 struct ethtool_cmd ecmd; 1831 int rc, rc2;
1760 enum reset_type method = efx->reset_pending; 1832 bool disabled;
1761 int rc = 0;
1762
1763 /* Serialise with kernel interfaces */
1764 rtnl_lock();
1765
1766 /* If we're not RUNNING then don't reset. Leave the reset_pending
1767 * flag set so that efx_pci_probe_main will be retried */
1768 if (efx->state != STATE_RUNNING) {
1769 EFX_INFO(efx, "scheduled reset quenched. NIC not RUNNING\n");
1770 goto out_unlock;
1771 }
1772 1833
1773 EFX_INFO(efx, "resetting (%d)\n", method); 1834 EFX_INFO(efx, "resetting (%s)\n", RESET_TYPE(method));
1774 1835
1775 efx_reset_down(efx, method, &ecmd); 1836 efx_reset_down(efx, method);
1776 1837
1777 rc = falcon_reset_hw(efx, method); 1838 rc = efx->type->reset(efx, method);
1778 if (rc) { 1839 if (rc) {
1779 EFX_ERR(efx, "failed to reset hardware\n"); 1840 EFX_ERR(efx, "failed to reset hardware\n");
1780 goto out_disable; 1841 goto out;
1781 } 1842 }
1782 1843
1783 /* Allow resets to be rescheduled. */ 1844 /* Allow resets to be rescheduled. */
@@ -1789,25 +1850,23 @@ static int efx_reset(struct efx_nic *efx)
1789 * can respond to requests. */ 1850 * can respond to requests. */
1790 pci_set_master(efx->pci_dev); 1851 pci_set_master(efx->pci_dev);
1791 1852
1853out:
1792 /* Leave device stopped if necessary */ 1854 /* Leave device stopped if necessary */
1793 if (method == RESET_TYPE_DISABLE) { 1855 disabled = rc || method == RESET_TYPE_DISABLE;
1794 efx_reset_up(efx, method, &ecmd, false); 1856 rc2 = efx_reset_up(efx, method, !disabled);
1795 rc = -EIO; 1857 if (rc2) {
1796 } else { 1858 disabled = true;
1797 rc = efx_reset_up(efx, method, &ecmd, true); 1859 if (!rc)
1860 rc = rc2;
1798 } 1861 }
1799 1862
1800out_disable: 1863 if (disabled) {
1801 if (rc) { 1864 dev_close(efx->net_dev);
1802 EFX_ERR(efx, "has been disabled\n"); 1865 EFX_ERR(efx, "has been disabled\n");
1803 efx->state = STATE_DISABLED; 1866 efx->state = STATE_DISABLED;
1804 dev_close(efx->net_dev);
1805 } else { 1867 } else {
1806 EFX_LOG(efx, "reset complete\n"); 1868 EFX_LOG(efx, "reset complete\n");
1807 } 1869 }
1808
1809out_unlock:
1810 rtnl_unlock();
1811 return rc; 1870 return rc;
1812} 1871}
1813 1872
@@ -1816,9 +1875,18 @@ out_unlock:
1816 */ 1875 */
1817static void efx_reset_work(struct work_struct *data) 1876static void efx_reset_work(struct work_struct *data)
1818{ 1877{
1819 struct efx_nic *nic = container_of(data, struct efx_nic, reset_work); 1878 struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
1879
1880 /* If we're not RUNNING then don't reset. Leave the reset_pending
1881 * flag set so that efx_pci_probe_main will be retried */
1882 if (efx->state != STATE_RUNNING) {
1883 EFX_INFO(efx, "scheduled reset quenched. NIC not RUNNING\n");
1884 return;
1885 }
1820 1886
1821 efx_reset(nic); 1887 rtnl_lock();
1888 (void)efx_reset(efx, efx->reset_pending);
1889 rtnl_unlock();
1822} 1890}
1823 1891
1824void efx_schedule_reset(struct efx_nic *efx, enum reset_type type) 1892void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
@@ -1843,18 +1911,24 @@ void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
1843 case RESET_TYPE_TX_SKIP: 1911 case RESET_TYPE_TX_SKIP:
1844 method = RESET_TYPE_INVISIBLE; 1912 method = RESET_TYPE_INVISIBLE;
1845 break; 1913 break;
1914 case RESET_TYPE_MC_FAILURE:
1846 default: 1915 default:
1847 method = RESET_TYPE_ALL; 1916 method = RESET_TYPE_ALL;
1848 break; 1917 break;
1849 } 1918 }
1850 1919
1851 if (method != type) 1920 if (method != type)
1852 EFX_LOG(efx, "scheduling reset (%d:%d)\n", type, method); 1921 EFX_LOG(efx, "scheduling %s reset for %s\n",
1922 RESET_TYPE(method), RESET_TYPE(type));
1853 else 1923 else
1854 EFX_LOG(efx, "scheduling reset (%d)\n", method); 1924 EFX_LOG(efx, "scheduling %s reset\n", RESET_TYPE(method));
1855 1925
1856 efx->reset_pending = method; 1926 efx->reset_pending = method;
1857 1927
1928 /* efx_process_channel() will no longer read events once a
1929 * reset is scheduled. So switch back to poll'd MCDI completions. */
1930 efx_mcdi_mode_poll(efx);
1931
1858 queue_work(reset_workqueue, &efx->reset_work); 1932 queue_work(reset_workqueue, &efx->reset_work);
1859} 1933}
1860 1934
@@ -1865,17 +1939,21 @@ void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
1865 **************************************************************************/ 1939 **************************************************************************/
1866 1940
1867/* PCI device ID table */ 1941/* PCI device ID table */
1868static struct pci_device_id efx_pci_table[] __devinitdata = { 1942static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
1869 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID), 1943 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
1870 .driver_data = (unsigned long) &falcon_a_nic_type}, 1944 .driver_data = (unsigned long) &falcon_a1_nic_type},
1871 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID), 1945 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
1872 .driver_data = (unsigned long) &falcon_b_nic_type}, 1946 .driver_data = (unsigned long) &falcon_b0_nic_type},
1947 {PCI_DEVICE(EFX_VENDID_SFC, BETHPAGE_A_P_DEVID),
1948 .driver_data = (unsigned long) &siena_a0_nic_type},
1949 {PCI_DEVICE(EFX_VENDID_SFC, SIENA_A_P_DEVID),
1950 .driver_data = (unsigned long) &siena_a0_nic_type},
1873 {0} /* end of list */ 1951 {0} /* end of list */
1874}; 1952};
1875 1953
1876/************************************************************************** 1954/**************************************************************************
1877 * 1955 *
1878 * Dummy PHY/MAC/Board operations 1956 * Dummy PHY/MAC operations
1879 * 1957 *
1880 * Can be used for some unimplemented operations 1958 * Can be used for some unimplemented operations
1881 * Needed so all function pointers are valid and do not have to be tested 1959 * Needed so all function pointers are valid and do not have to be tested
@@ -1887,29 +1965,19 @@ int efx_port_dummy_op_int(struct efx_nic *efx)
1887 return 0; 1965 return 0;
1888} 1966}
1889void efx_port_dummy_op_void(struct efx_nic *efx) {} 1967void efx_port_dummy_op_void(struct efx_nic *efx) {}
1890void efx_port_dummy_op_blink(struct efx_nic *efx, bool blink) {} 1968void efx_port_dummy_op_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
1891 1969{
1892static struct efx_mac_operations efx_dummy_mac_operations = { 1970}
1893 .reconfigure = efx_port_dummy_op_void, 1971bool efx_port_dummy_op_poll(struct efx_nic *efx)
1894 .poll = efx_port_dummy_op_void, 1972{
1895 .irq = efx_port_dummy_op_void, 1973 return false;
1896}; 1974}
1897 1975
1898static struct efx_phy_operations efx_dummy_phy_operations = { 1976static struct efx_phy_operations efx_dummy_phy_operations = {
1899 .init = efx_port_dummy_op_int, 1977 .init = efx_port_dummy_op_int,
1900 .reconfigure = efx_port_dummy_op_void, 1978 .reconfigure = efx_port_dummy_op_int,
1901 .poll = efx_port_dummy_op_void, 1979 .poll = efx_port_dummy_op_poll,
1902 .fini = efx_port_dummy_op_void, 1980 .fini = efx_port_dummy_op_void,
1903 .clear_interrupt = efx_port_dummy_op_void,
1904};
1905
1906static struct efx_board efx_dummy_board_info = {
1907 .init = efx_port_dummy_op_int,
1908 .init_leds = efx_port_dummy_op_void,
1909 .set_id_led = efx_port_dummy_op_blink,
1910 .monitor = efx_port_dummy_op_int,
1911 .blink = efx_port_dummy_op_blink,
1912 .fini = efx_port_dummy_op_void,
1913}; 1981};
1914 1982
1915/************************************************************************** 1983/**************************************************************************
@@ -1932,26 +2000,26 @@ static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
1932 /* Initialise common structures */ 2000 /* Initialise common structures */
1933 memset(efx, 0, sizeof(*efx)); 2001 memset(efx, 0, sizeof(*efx));
1934 spin_lock_init(&efx->biu_lock); 2002 spin_lock_init(&efx->biu_lock);
1935 spin_lock_init(&efx->phy_lock); 2003 mutex_init(&efx->mdio_lock);
1936 mutex_init(&efx->spi_lock); 2004 mutex_init(&efx->spi_lock);
2005#ifdef CONFIG_SFC_MTD
2006 INIT_LIST_HEAD(&efx->mtd_list);
2007#endif
1937 INIT_WORK(&efx->reset_work, efx_reset_work); 2008 INIT_WORK(&efx->reset_work, efx_reset_work);
1938 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); 2009 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
1939 efx->pci_dev = pci_dev; 2010 efx->pci_dev = pci_dev;
1940 efx->state = STATE_INIT; 2011 efx->state = STATE_INIT;
1941 efx->reset_pending = RESET_TYPE_NONE; 2012 efx->reset_pending = RESET_TYPE_NONE;
1942 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name)); 2013 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
1943 efx->board_info = efx_dummy_board_info;
1944 2014
1945 efx->net_dev = net_dev; 2015 efx->net_dev = net_dev;
1946 efx->rx_checksum_enabled = true; 2016 efx->rx_checksum_enabled = true;
1947 spin_lock_init(&efx->netif_stop_lock); 2017 spin_lock_init(&efx->netif_stop_lock);
1948 spin_lock_init(&efx->stats_lock); 2018 spin_lock_init(&efx->stats_lock);
1949 efx->stats_disable_count = 1;
1950 mutex_init(&efx->mac_lock); 2019 mutex_init(&efx->mac_lock);
1951 efx->mac_op = &efx_dummy_mac_operations; 2020 efx->mac_op = type->default_mac_ops;
1952 efx->phy_op = &efx_dummy_phy_operations; 2021 efx->phy_op = &efx_dummy_phy_operations;
1953 efx->mdio.dev = net_dev; 2022 efx->mdio.dev = net_dev;
1954 INIT_WORK(&efx->phy_work, efx_phy_work);
1955 INIT_WORK(&efx->mac_work, efx_mac_work); 2023 INIT_WORK(&efx->mac_work, efx_mac_work);
1956 atomic_set(&efx->netif_stop_count, 1); 2024 atomic_set(&efx->netif_stop_count, 1);
1957 2025
@@ -1981,17 +2049,9 @@ static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
1981 2049
1982 efx->type = type; 2050 efx->type = type;
1983 2051
1984 /* Sanity-check NIC type */
1985 EFX_BUG_ON_PARANOID(efx->type->txd_ring_mask &
1986 (efx->type->txd_ring_mask + 1));
1987 EFX_BUG_ON_PARANOID(efx->type->rxd_ring_mask &
1988 (efx->type->rxd_ring_mask + 1));
1989 EFX_BUG_ON_PARANOID(efx->type->evq_size &
1990 (efx->type->evq_size - 1));
1991 /* As close as we can get to guaranteeing that we don't overflow */ 2052 /* As close as we can get to guaranteeing that we don't overflow */
1992 EFX_BUG_ON_PARANOID(efx->type->evq_size < 2053 BUILD_BUG_ON(EFX_EVQ_SIZE < EFX_TXQ_SIZE + EFX_RXQ_SIZE);
1993 (efx->type->txd_ring_mask + 1 + 2054
1994 efx->type->rxd_ring_mask + 1));
1995 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS); 2055 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
1996 2056
1997 /* Higher numbered interrupt modes are less capable! */ 2057 /* Higher numbered interrupt modes are less capable! */
@@ -2027,19 +2087,10 @@ static void efx_fini_struct(struct efx_nic *efx)
2027 */ 2087 */
2028static void efx_pci_remove_main(struct efx_nic *efx) 2088static void efx_pci_remove_main(struct efx_nic *efx)
2029{ 2089{
2030 EFX_ASSERT_RESET_SERIALISED(efx); 2090 efx_nic_fini_interrupt(efx);
2031
2032 /* Skip everything if we never obtained a valid membase */
2033 if (!efx->membase)
2034 return;
2035
2036 efx_fini_channels(efx); 2091 efx_fini_channels(efx);
2037 efx_fini_port(efx); 2092 efx_fini_port(efx);
2038 2093 efx->type->fini(efx);
2039 /* Shutdown the board, then the NIC and board state */
2040 efx->board_info.fini(efx);
2041 falcon_fini_interrupt(efx);
2042
2043 efx_fini_napi(efx); 2094 efx_fini_napi(efx);
2044 efx_remove_all(efx); 2095 efx_remove_all(efx);
2045} 2096}
@@ -2063,9 +2114,6 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
2063 /* Allow any queued efx_resets() to complete */ 2114 /* Allow any queued efx_resets() to complete */
2064 rtnl_unlock(); 2115 rtnl_unlock();
2065 2116
2066 if (efx->membase == NULL)
2067 goto out;
2068
2069 efx_unregister_netdev(efx); 2117 efx_unregister_netdev(efx);
2070 2118
2071 efx_mtd_remove(efx); 2119 efx_mtd_remove(efx);
@@ -2078,7 +2126,6 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
2078 2126
2079 efx_pci_remove_main(efx); 2127 efx_pci_remove_main(efx);
2080 2128
2081out:
2082 efx_fini_io(efx); 2129 efx_fini_io(efx);
2083 EFX_LOG(efx, "shutdown successful\n"); 2130 EFX_LOG(efx, "shutdown successful\n");
2084 2131
@@ -2103,39 +2150,31 @@ static int efx_pci_probe_main(struct efx_nic *efx)
2103 if (rc) 2150 if (rc)
2104 goto fail2; 2151 goto fail2;
2105 2152
2106 /* Initialise the board */ 2153 rc = efx->type->init(efx);
2107 rc = efx->board_info.init(efx);
2108 if (rc) {
2109 EFX_ERR(efx, "failed to initialise board\n");
2110 goto fail3;
2111 }
2112
2113 rc = falcon_init_nic(efx);
2114 if (rc) { 2154 if (rc) {
2115 EFX_ERR(efx, "failed to initialise NIC\n"); 2155 EFX_ERR(efx, "failed to initialise NIC\n");
2116 goto fail4; 2156 goto fail3;
2117 } 2157 }
2118 2158
2119 rc = efx_init_port(efx); 2159 rc = efx_init_port(efx);
2120 if (rc) { 2160 if (rc) {
2121 EFX_ERR(efx, "failed to initialise port\n"); 2161 EFX_ERR(efx, "failed to initialise port\n");
2122 goto fail5; 2162 goto fail4;
2123 } 2163 }
2124 2164
2125 efx_init_channels(efx); 2165 efx_init_channels(efx);
2126 2166
2127 rc = falcon_init_interrupt(efx); 2167 rc = efx_nic_init_interrupt(efx);
2128 if (rc) 2168 if (rc)
2129 goto fail6; 2169 goto fail5;
2130 2170
2131 return 0; 2171 return 0;
2132 2172
2133 fail6: 2173 fail5:
2134 efx_fini_channels(efx); 2174 efx_fini_channels(efx);
2135 efx_fini_port(efx); 2175 efx_fini_port(efx);
2136 fail5:
2137 fail4: 2176 fail4:
2138 efx->board_info.fini(efx); 2177 efx->type->fini(efx);
2139 fail3: 2178 fail3:
2140 efx_fini_napi(efx); 2179 efx_fini_napi(efx);
2141 fail2: 2180 fail2:
@@ -2165,9 +2204,11 @@ static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2165 net_dev = alloc_etherdev(sizeof(*efx)); 2204 net_dev = alloc_etherdev(sizeof(*efx));
2166 if (!net_dev) 2205 if (!net_dev)
2167 return -ENOMEM; 2206 return -ENOMEM;
2168 net_dev->features |= (NETIF_F_IP_CSUM | NETIF_F_SG | 2207 net_dev->features |= (type->offload_features | NETIF_F_SG |
2169 NETIF_F_HIGHDMA | NETIF_F_TSO | 2208 NETIF_F_HIGHDMA | NETIF_F_TSO |
2170 NETIF_F_GRO); 2209 NETIF_F_GRO);
2210 if (type->offload_features & NETIF_F_V6_CSUM)
2211 net_dev->features |= NETIF_F_TSO6;
2171 /* Mask for features that also apply to VLAN devices */ 2212 /* Mask for features that also apply to VLAN devices */
2172 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG | 2213 net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
2173 NETIF_F_HIGHDMA | NETIF_F_TSO); 2214 NETIF_F_HIGHDMA | NETIF_F_TSO);
@@ -2219,18 +2260,19 @@ static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2219 goto fail4; 2260 goto fail4;
2220 } 2261 }
2221 2262
2222 /* Switch to the running state before we expose the device to 2263 /* Switch to the running state before we expose the device to the OS,
2223 * the OS. This is to ensure that the initial gathering of 2264 * so that dev_open()|efx_start_all() will actually start the device */
2224 * MAC stats succeeds. */
2225 efx->state = STATE_RUNNING; 2265 efx->state = STATE_RUNNING;
2226 2266
2227 efx_mtd_probe(efx); /* allowed to fail */
2228
2229 rc = efx_register_netdev(efx); 2267 rc = efx_register_netdev(efx);
2230 if (rc) 2268 if (rc)
2231 goto fail5; 2269 goto fail5;
2232 2270
2233 EFX_LOG(efx, "initialisation successful\n"); 2271 EFX_LOG(efx, "initialisation successful\n");
2272
2273 rtnl_lock();
2274 efx_mtd_probe(efx); /* allowed to fail */
2275 rtnl_unlock();
2234 return 0; 2276 return 0;
2235 2277
2236 fail5: 2278 fail5:
@@ -2241,16 +2283,113 @@ static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2241 fail2: 2283 fail2:
2242 efx_fini_struct(efx); 2284 efx_fini_struct(efx);
2243 fail1: 2285 fail1:
2286 WARN_ON(rc > 0);
2244 EFX_LOG(efx, "initialisation failed. rc=%d\n", rc); 2287 EFX_LOG(efx, "initialisation failed. rc=%d\n", rc);
2245 free_netdev(net_dev); 2288 free_netdev(net_dev);
2246 return rc; 2289 return rc;
2247} 2290}
2248 2291
2292static int efx_pm_freeze(struct device *dev)
2293{
2294 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2295
2296 efx->state = STATE_FINI;
2297
2298 netif_device_detach(efx->net_dev);
2299
2300 efx_stop_all(efx);
2301 efx_fini_channels(efx);
2302
2303 return 0;
2304}
2305
2306static int efx_pm_thaw(struct device *dev)
2307{
2308 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
2309
2310 efx->state = STATE_INIT;
2311
2312 efx_init_channels(efx);
2313
2314 mutex_lock(&efx->mac_lock);
2315 efx->phy_op->reconfigure(efx);
2316 mutex_unlock(&efx->mac_lock);
2317
2318 efx_start_all(efx);
2319
2320 netif_device_attach(efx->net_dev);
2321
2322 efx->state = STATE_RUNNING;
2323
2324 efx->type->resume_wol(efx);
2325
2326 return 0;
2327}
2328
2329static int efx_pm_poweroff(struct device *dev)
2330{
2331 struct pci_dev *pci_dev = to_pci_dev(dev);
2332 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2333
2334 efx->type->fini(efx);
2335
2336 efx->reset_pending = RESET_TYPE_NONE;
2337
2338 pci_save_state(pci_dev);
2339 return pci_set_power_state(pci_dev, PCI_D3hot);
2340}
2341
2342/* Used for both resume and restore */
2343static int efx_pm_resume(struct device *dev)
2344{
2345 struct pci_dev *pci_dev = to_pci_dev(dev);
2346 struct efx_nic *efx = pci_get_drvdata(pci_dev);
2347 int rc;
2348
2349 rc = pci_set_power_state(pci_dev, PCI_D0);
2350 if (rc)
2351 return rc;
2352 pci_restore_state(pci_dev);
2353 rc = pci_enable_device(pci_dev);
2354 if (rc)
2355 return rc;
2356 pci_set_master(efx->pci_dev);
2357 rc = efx->type->reset(efx, RESET_TYPE_ALL);
2358 if (rc)
2359 return rc;
2360 rc = efx->type->init(efx);
2361 if (rc)
2362 return rc;
2363 efx_pm_thaw(dev);
2364 return 0;
2365}
2366
2367static int efx_pm_suspend(struct device *dev)
2368{
2369 int rc;
2370
2371 efx_pm_freeze(dev);
2372 rc = efx_pm_poweroff(dev);
2373 if (rc)
2374 efx_pm_resume(dev);
2375 return rc;
2376}
2377
2378static struct dev_pm_ops efx_pm_ops = {
2379 .suspend = efx_pm_suspend,
2380 .resume = efx_pm_resume,
2381 .freeze = efx_pm_freeze,
2382 .thaw = efx_pm_thaw,
2383 .poweroff = efx_pm_poweroff,
2384 .restore = efx_pm_resume,
2385};
2386
2249static struct pci_driver efx_pci_driver = { 2387static struct pci_driver efx_pci_driver = {
2250 .name = EFX_DRIVER_NAME, 2388 .name = EFX_DRIVER_NAME,
2251 .id_table = efx_pci_table, 2389 .id_table = efx_pci_table,
2252 .probe = efx_pci_probe, 2390 .probe = efx_pci_probe,
2253 .remove = efx_pci_remove, 2391 .remove = efx_pci_remove,
2392 .driver.pm = &efx_pm_ops,
2254}; 2393};
2255 2394
2256/************************************************************************** 2395/**************************************************************************
@@ -2314,8 +2453,8 @@ static void __exit efx_exit_module(void)
2314module_init(efx_init_module); 2453module_init(efx_init_module);
2315module_exit(efx_exit_module); 2454module_exit(efx_exit_module);
2316 2455
2317MODULE_AUTHOR("Michael Brown <mbrown@fensystems.co.uk> and " 2456MODULE_AUTHOR("Solarflare Communications and "
2318 "Solarflare Communications"); 2457 "Michael Brown <mbrown@fensystems.co.uk>");
2319MODULE_DESCRIPTION("Solarflare Communications network driver"); 2458MODULE_DESCRIPTION("Solarflare Communications network driver");
2320MODULE_LICENSE("GPL"); 2459MODULE_LICENSE("GPL");
2321MODULE_DEVICE_TABLE(pci, efx_pci_table); 2460MODULE_DEVICE_TABLE(pci, efx_pci_table);