Merge branch 'topic/core-cleanup' into for-linus
[safe/jmp/linux-2.6] / drivers / net / e100.c
index 5c0b457..7910803 100644 (file)
  *     FIXES:
  * 2005/12/02 - Michael O'Donnell <Michael.ODonnell at stratus dot com>
  *     - Stratus87247: protect MDI control register manipulations
+ * 2009/06/01 - Andreas Mohr <andi at lisas dot de>
+ *      - add clean lowlevel I/O emulation for cards with MII-lacking PHYs
  */
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/string.h>
 #include <linux/firmware.h>
+#include <linux/rtnetlink.h>
 #include <asm/unaligned.h>
 
 
@@ -204,7 +209,7 @@ MODULE_PARM_DESC(use_io, "Force use of i/o access mode");
 #define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\
        PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \
        PCI_CLASS_NETWORK_ETHERNET << 8, 0xFFFF00, ich }
-static struct pci_device_id e100_id_table[] = {
+static DEFINE_PCI_DEVICE_TABLE(e100_id_table) = {
        INTEL_8255X_ETHERNET_DEVICE(0x1029, 0),
        INTEL_8255X_ETHERNET_DEVICE(0x1030, 0),
        INTEL_8255X_ETHERNET_DEVICE(0x1031, 3),
@@ -372,6 +377,7 @@ enum eeprom_op {
 
 enum eeprom_offsets {
        eeprom_cnfg_mdix  = 0x03,
+       eeprom_phy_iface  = 0x06,
        eeprom_id         = 0x0A,
        eeprom_config_asf = 0x0D,
        eeprom_smbus_addr = 0x90,
@@ -381,6 +387,18 @@ enum eeprom_cnfg_mdix {
        eeprom_mdix_enabled = 0x0080,
 };
 
+enum eeprom_phy_iface {
+       NoSuchPhy = 0,
+       I82553AB,
+       I82553C,
+       I82503,
+       DP83840,
+       S80C240,
+       S80C24,
+       I82555,
+       DP83840A = 10,
+};
+
 enum eeprom_id {
        eeprom_id_wol = 0x0020,
 };
@@ -545,6 +563,7 @@ struct nic {
        u32 msg_enable                          ____cacheline_aligned;
        struct net_device *netdev;
        struct pci_dev *pdev;
+       u16 (*mdio_ctrl)(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data);
 
        struct rx *rxs                          ____cacheline_aligned;
        struct rx *rx_to_use;
@@ -585,6 +604,7 @@ struct nic {
        struct mem *mem;
        dma_addr_t dma_addr;
 
+       struct pci_pool *cbs_pool;
        dma_addr_t cbs_dma_addr;
        u8 adaptive_ifs;
        u8 tx_threshold;
@@ -605,6 +625,7 @@ struct nic {
        u16 eeprom_wc;
        __le16 eeprom[256];
        spinlock_t mdio_lock;
+       const struct firmware *fw;
 };
 
 static inline void e100_write_flush(struct nic *nic)
@@ -899,7 +920,21 @@ err_unlock:
        return err;
 }
 
-static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
+static int mdio_read(struct net_device *netdev, int addr, int reg)
+{
+       struct nic *nic = netdev_priv(netdev);
+       return nic->mdio_ctrl(nic, addr, mdi_read, reg, 0);
+}
+
+static void mdio_write(struct net_device *netdev, int addr, int reg, int data)
+{
+       struct nic *nic = netdev_priv(netdev);
+
+       nic->mdio_ctrl(nic, addr, mdi_write, reg, data);
+}
+
+/* the standard mdio_ctrl() function for usual MII-compliant hardware */
+static u16 mdio_ctrl_hw(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
 {
        u32 data_out = 0;
        unsigned int i;
@@ -938,30 +973,83 @@ static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
        return (u16)data_out;
 }
 
-static int mdio_read(struct net_device *netdev, int addr, int reg)
-{
-       return mdio_ctrl(netdev_priv(netdev), addr, mdi_read, reg, 0);
+/* slightly tweaked mdio_ctrl() function for phy_82552_v specifics */
+static u16 mdio_ctrl_phy_82552_v(struct nic *nic,
+                                u32 addr,
+                                u32 dir,
+                                u32 reg,
+                                u16 data)
+{
+       if ((reg == MII_BMCR) && (dir == mdi_write)) {
+               if (data & (BMCR_ANRESTART | BMCR_ANENABLE)) {
+                       u16 advert = mdio_read(nic->netdev, nic->mii.phy_id,
+                                                       MII_ADVERTISE);
+
+                       /*
+                        * Workaround Si issue where sometimes the part will not
+                        * autoneg to 100Mbps even when advertised.
+                        */
+                       if (advert & ADVERTISE_100FULL)
+                               data |= BMCR_SPEED100 | BMCR_FULLDPLX;
+                       else if (advert & ADVERTISE_100HALF)
+                               data |= BMCR_SPEED100;
+               }
+       }
+       return mdio_ctrl_hw(nic, addr, dir, reg, data);
 }
 
-static void mdio_write(struct net_device *netdev, int addr, int reg, int data)
-{
-       struct nic *nic = netdev_priv(netdev);
-
-       if  ((nic->phy == phy_82552_v) && (reg == MII_BMCR) &&
-            (data & (BMCR_ANRESTART | BMCR_ANENABLE))) {
-               u16 advert = mdio_read(netdev, nic->mii.phy_id, MII_ADVERTISE);
-
-               /*
-                * Workaround Si issue where sometimes the part will not
-                * autoneg to 100Mbps even when advertised.
-                */
-               if (advert & ADVERTISE_100FULL)
-                       data |= BMCR_SPEED100 | BMCR_FULLDPLX;
-               else if (advert & ADVERTISE_100HALF)
-                       data |= BMCR_SPEED100;
+/* Fully software-emulated mdio_ctrl() function for cards without
+ * MII-compliant PHYs.
+ * For now, this is mainly geared towards 80c24 support; in case of further
+ * requirements for other types (i82503, ...?) either extend this mechanism
+ * or split it, whichever is cleaner.
+ */
+static u16 mdio_ctrl_phy_mii_emulated(struct nic *nic,
+                                     u32 addr,
+                                     u32 dir,
+                                     u32 reg,
+                                     u16 data)
+{
+       /* might need to allocate a netdev_priv'ed register array eventually
+        * to be able to record state changes, but for now
+        * some fully hardcoded register handling ought to be ok I guess. */
+
+       if (dir == mdi_read) {
+               switch (reg) {
+               case MII_BMCR:
+                       /* Auto-negotiation, right? */
+                       return  BMCR_ANENABLE |
+                               BMCR_FULLDPLX;
+               case MII_BMSR:
+                       return  BMSR_LSTATUS /* for mii_link_ok() */ |
+                               BMSR_ANEGCAPABLE |
+                               BMSR_10FULL;
+               case MII_ADVERTISE:
+                       /* 80c24 is a "combo card" PHY, right? */
+                       return  ADVERTISE_10HALF |
+                               ADVERTISE_10FULL;
+               default:
+                       DPRINTK(HW, DEBUG,
+               "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n",
+               dir == mdi_read ? "READ" : "WRITE", addr, reg, data);
+                       return 0xFFFF;
+               }
+       } else {
+               switch (reg) {
+               default:
+                       DPRINTK(HW, DEBUG,
+               "%s:addr=%d, reg=%d, data=0x%04X: unimplemented emulation!\n",
+               dir == mdi_read ? "READ" : "WRITE", addr, reg, data);
+                       return 0xFFFF;
+               }
        }
-
-       mdio_ctrl(netdev_priv(netdev), addr, mdi_write, reg, data);
+}
+static inline int e100_phy_supports_mii(struct nic *nic)
+{
+       /* for now, just check it by comparing whether we
+          are using MII software emulation.
+       */
+       return (nic->mdio_ctrl != mdio_ctrl_phy_mii_emulated);
 }
 
 static void e100_get_defaults(struct nic *nic)
@@ -1013,7 +1101,8 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
        config->standard_stat_counter = 0x1;    /* 1=standard, 0=extended */
        config->rx_discard_short_frames = 0x1;  /* 1=discard, 0=pass */
        config->tx_underrun_retry = 0x3;        /* # of underrun retries */
-       config->mii_mode = 0x1;                 /* 1=MII mode, 0=503 mode */
+       if (e100_phy_supports_mii(nic))
+               config->mii_mode = 1;           /* 1=MII mode, 0=i82503 mode */
        config->pad10 = 0x6;
        config->no_source_addr_insertion = 0x1; /* 1=no, 0=yes */
        config->preamble_length = 0x2;          /* 0=1, 1=3, 2=7, 3=15 bytes */
@@ -1138,9 +1227,9 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
 static const struct firmware *e100_request_firmware(struct nic *nic)
 {
        const char *fw_name;
-       const struct firmware *fw;
+       const struct firmware *fw = nic->fw;
        u8 timer, bundle, min_size;
-       int err;
+       int err = 0;
 
        /* do not load u-code for ICH devices */
        if (nic->flags & ich)
@@ -1156,12 +1245,20 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
        else /* No ucode on other devices */
                return NULL;
 
-       err = request_firmware(&fw, fw_name, &nic->pdev->dev);
+       /* If the firmware has not previously been loaded, request a pointer
+        * to it. If it was previously loaded, we are reinitializing the
+        * adapter, possibly in a resume from hibernate, in which case
+        * request_firmware() cannot be used.
+        */
+       if (!fw)
+               err = request_firmware(&fw, fw_name, &nic->pdev->dev);
+
        if (err) {
                DPRINTK(PROBE, ERR, "Failed to load firmware \"%s\": %d\n",
                        fw_name, err);
                return ERR_PTR(err);
        }
+
        /* Firmware should be precisely UCODE_SIZE (words) plus three bytes
           indicating the offsets for BUNDLESMALL, BUNDLEMAX, INTDELAY */
        if (fw->size != UCODE_SIZE * 4 + 3) {
@@ -1184,7 +1281,10 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
                release_firmware(fw);
                return ERR_PTR(-EINVAL);
        }
-       /* OK, firmware is validated and ready to use... */
+
+       /* OK, firmware is validated and ready to use. Save a pointer
+        * to it in the nic */
+       nic->fw = fw;
        return fw;
 }
 
@@ -1270,6 +1370,42 @@ static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
                offsetof(struct mem, dump_buf));
 }
 
+static int e100_phy_check_without_mii(struct nic *nic)
+{
+       u8 phy_type;
+       int without_mii;
+
+       phy_type = (nic->eeprom[eeprom_phy_iface] >> 8) & 0x0f;
+
+       switch (phy_type) {
+       case NoSuchPhy: /* Non-MII PHY; UNTESTED! */
+       case I82503: /* Non-MII PHY; UNTESTED! */
+       case S80C24: /* Non-MII PHY; tested and working */
+               /* paragraph from the FreeBSD driver, "FXP_PHY_80C24":
+                * The Seeq 80c24 AutoDUPLEX(tm) Ethernet Interface Adapter
+                * doesn't have a programming interface of any sort.  The
+                * media is sensed automatically based on how the link partner
+                * is configured.  This is, in essence, manual configuration.
+                */
+               DPRINTK(PROBE, INFO,
+                        "found MII-less i82503 or 80c24 or other PHY\n");
+
+               nic->mdio_ctrl = mdio_ctrl_phy_mii_emulated;
+               nic->mii.phy_id = 0; /* is this ok for an MII-less PHY? */
+
+               /* these might be needed for certain MII-less cards...
+                * nic->flags |= ich;
+                * nic->flags |= ich_10h_workaround; */
+
+               without_mii = 1;
+               break;
+       default:
+               without_mii = 0;
+               break;
+       }
+       return without_mii;
+}
+
 #define NCONFIG_AUTO_SWITCH    0x0080
 #define MII_NSC_CONG           MII_RESV1
 #define NSC_CONG_ENABLE                0x0100
@@ -1290,16 +1426,21 @@ static int e100_phy_init(struct nic *nic)
                if (!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
                        break;
        }
-       DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
-       if (addr == 32)
-               return -EAGAIN;
-
-       /* Isolate all the PHY ids */
-       for (addr = 0; addr < 32; addr++)
-               mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
-       /* Select the discovered PHY */
-       bmcr &= ~BMCR_ISOLATE;
-       mdio_write(netdev, nic->mii.phy_id, MII_BMCR, bmcr);
+       if (addr == 32) {
+               /* uhoh, no PHY detected: check whether we seem to be some
+                * weird, rare variant which is *known* to not have any MII.
+                * But do this AFTER MII checking only, since this does
+                * lookup of EEPROM values which may easily be unreliable. */
+               if (e100_phy_check_without_mii(nic))
+                       return 0; /* simply return and hope for the best */
+               else {
+                       /* for unknown cases log a fatal error */
+                       DPRINTK(HW, ERR,
+                               "Failed to locate any known PHY, aborting.\n");
+                       return -EAGAIN;
+               }
+       } else
+               DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
 
        /* Get phy ID */
        id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1);
@@ -1307,6 +1448,25 @@ static int e100_phy_init(struct nic *nic)
        nic->phy = (u32)id_hi << 16 | (u32)id_lo;
        DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy);
 
+       /* Select the phy and isolate the rest */
+       for (addr = 0; addr < 32; addr++) {
+               if (addr != nic->mii.phy_id) {
+                       mdio_write(netdev, addr, MII_BMCR, BMCR_ISOLATE);
+               } else if (nic->phy != phy_82552_v) {
+                       bmcr = mdio_read(netdev, addr, MII_BMCR);
+                       mdio_write(netdev, addr, MII_BMCR,
+                               bmcr & ~BMCR_ISOLATE);
+               }
+       }
+       /*
+        * Workaround for 82552:
+        * Clear the ISOLATE bit on selected phy_id last (mirrored on all
+        * other phy_id's) using bmcr value from addr discovery loop above.
+        */
+       if (nic->phy == phy_82552_v)
+               mdio_write(netdev, nic->mii.phy_id, MII_BMCR,
+                       bmcr & ~BMCR_ISOLATE);
+
        /* Handle National tx phys */
 #define NCS_PHY_MODEL_MASK     0xFFF0FFFF
        if ((nic->phy & NCS_PHY_MODEL_MASK) == phy_nsc_tx) {
@@ -1320,6 +1480,9 @@ static int e100_phy_init(struct nic *nic)
        if (nic->phy == phy_82552_v) {
                u16 advert = mdio_read(netdev, nic->mii.phy_id, MII_ADVERTISE);
 
+               /* assign special tweaked mdio_ctrl() function */
+               nic->mdio_ctrl = mdio_ctrl_phy_82552_v;
+
                /* Workaround Si not advertising flow-control during autoneg */
                advert |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
                mdio_write(netdev, nic->mii.phy_id, MII_ADVERTISE, advert);
@@ -1375,14 +1538,18 @@ static int e100_hw_init(struct nic *nic)
 static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
 {
        struct net_device *netdev = nic->netdev;
-       struct dev_mc_list *list = netdev->mc_list;
-       u16 i, count = min(netdev->mc_count, E100_MAX_MULTICAST_ADDRS);
+       struct dev_mc_list *list;
+       u16 i, count = min(netdev_mc_count(netdev), E100_MAX_MULTICAST_ADDRS);
 
        cb->command = cpu_to_le16(cb_multi);
        cb->u.multi.count = cpu_to_le16(count * ETH_ALEN);
-       for (i = 0; list && i < count; i++, list = list->next)
-               memcpy(&cb->u.multi.addr[i*ETH_ALEN], &list->dmi_addr,
+       i = 0;
+       netdev_for_each_mc_addr(list, netdev) {
+               if (i == count)
+                       break;
+               memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &list->dmi_addr,
                        ETH_ALEN);
+       }
 }
 
 static void e100_set_multicast_list(struct net_device *netdev)
@@ -1390,7 +1557,7 @@ static void e100_set_multicast_list(struct net_device *netdev)
        struct nic *nic = netdev_priv(netdev);
 
        DPRINTK(HW, DEBUG, "mc_count=%d, flags=0x%04X\n",
-               netdev->mc_count, netdev->flags);
+               netdev_mc_count(netdev), netdev->flags);
 
        if (netdev->flags & IFF_PROMISC)
                nic->flags |= promiscuous;
@@ -1398,7 +1565,7 @@ static void e100_set_multicast_list(struct net_device *netdev)
                nic->flags &= ~promiscuous;
 
        if (netdev->flags & IFF_ALLMULTI ||
-               netdev->mc_count > E100_MAX_MULTICAST_ADDRS)
+               netdev_mc_count(netdev) > E100_MAX_MULTICAST_ADDRS)
                nic->flags |= multicast_all;
        else
                nic->flags &= ~multicast_all;
@@ -1555,7 +1722,8 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
        cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
 }
 
-static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
+static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
+                                  struct net_device *netdev)
 {
        struct nic *nic = netdev_priv(netdev);
        int err;
@@ -1581,11 +1749,11 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
                /* This is a hard error - log it. */
                DPRINTK(TX_ERR, DEBUG, "Out of Tx resources, returning skb\n");
                netif_stop_queue(netdev);
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        netdev->trans_start = jiffies;
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static int e100_tx_clean(struct nic *nic)
@@ -1644,9 +1812,7 @@ static void e100_clean_cbs(struct nic *nic)
                        nic->cb_to_clean = nic->cb_to_clean->next;
                        nic->cbs_avail++;
                }
-               pci_free_consistent(nic->pdev,
-                       sizeof(struct cb) * nic->params.cbs.count,
-                       nic->cbs, nic->cbs_dma_addr);
+               pci_pool_free(nic->cbs_pool, nic->cbs, nic->cbs_dma_addr);
                nic->cbs = NULL;
                nic->cbs_avail = 0;
        }
@@ -1664,10 +1830,11 @@ static int e100_alloc_cbs(struct nic *nic)
        nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = NULL;
        nic->cbs_avail = 0;
 
-       nic->cbs = pci_alloc_consistent(nic->pdev,
-               sizeof(struct cb) * count, &nic->cbs_dma_addr);
+       nic->cbs = pci_pool_alloc(nic->cbs_pool, GFP_KERNEL,
+                                 &nic->cbs_dma_addr);
        if (!nic->cbs)
                return -ENOMEM;
+       memset(nic->cbs, 0, count * sizeof(struct cb));
 
        for (cb = nic->cbs, i = 0; i < count; cb++, i++) {
                cb->next = (i + 1 < count) ? cb + 1 : nic->cbs;
@@ -1676,7 +1843,6 @@ static int e100_alloc_cbs(struct nic *nic)
                cb->dma_addr = nic->cbs_dma_addr + i * sizeof(struct cb);
                cb->link = cpu_to_le32(nic->cbs_dma_addr +
                        ((i+1) % count) * sizeof(struct cb));
-               cb->skb = NULL;
        }
 
        nic->cb_to_use = nic->cb_to_send = nic->cb_to_clean = nic->cbs;
@@ -1703,11 +1869,10 @@ static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
 static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
 {
-       if (!(rx->skb = netdev_alloc_skb(nic->netdev, RFD_BUF_LEN + NET_IP_ALIGN)))
+       if (!(rx->skb = netdev_alloc_skb_ip_align(nic->netdev, RFD_BUF_LEN)))
                return -ENOMEM;
 
-       /* Align, init, and map the RFD. */
-       skb_reserve(rx->skb, NET_IP_ALIGN);
+       /* Init, and map the RFD. */
        skb_copy_to_linear_data(rx->skb, &nic->blank_rfd, sizeof(struct rfd));
        rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
                RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
@@ -1762,6 +1927,9 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
 
                        if (ioread8(&nic->csr->scb.status) & rus_no_res)
                                nic->ru_running = RU_SUSPENDED;
+               pci_dma_sync_single_for_device(nic->pdev, rx->dma_addr,
+                                              sizeof(struct rfd),
+                                              PCI_DMA_FROMDEVICE);
                return -ENODATA;
        }
 
@@ -2098,8 +2266,13 @@ static void e100_tx_timeout_task(struct work_struct *work)
 
        DPRINTK(TX_ERR, DEBUG, "scb.status=0x%02X\n",
                ioread8(&nic->csr->scb.status));
-       e100_down(netdev_priv(netdev));
-       e100_up(netdev_priv(netdev));
+
+       rtnl_lock();
+       if (netif_running(netdev)) {
+               e100_down(netdev_priv(netdev));
+               e100_up(netdev_priv(netdev));
+       }
+       rtnl_unlock();
 }
 
 static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
@@ -2585,6 +2758,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        nic->netdev = netdev;
        nic->pdev = pdev;
        nic->msg_enable = (1 << debug) - 1;
+       nic->mdio_ctrl = mdio_ctrl_hw;
        pci_set_drvdata(pdev, netdev);
 
        if ((err = pci_enable_device(pdev))) {
@@ -2688,7 +2862,11 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n");
                goto err_out_free;
        }
-
+       nic->cbs_pool = pci_pool_create(netdev->name,
+                          nic->pdev,
+                          nic->params.cbs.max * sizeof(struct cb),
+                          sizeof(u32),
+                          0);
        DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %pM\n",
                (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0),
                pdev->irq, netdev->dev_addr);
@@ -2718,6 +2896,7 @@ static void __devexit e100_remove(struct pci_dev *pdev)
                unregister_netdev(netdev);
                e100_free(nic);
                pci_iounmap(pdev, nic->csr);
+               pci_pool_destroy(nic->cbs_pool);
                free_netdev(netdev);
                pci_release_regions(pdev);
                pci_disable_device(pdev);
@@ -2728,7 +2907,7 @@ static void __devexit e100_remove(struct pci_dev *pdev)
 #define E100_82552_SMARTSPEED   0x14   /* SmartSpeed Ctrl register */
 #define E100_82552_REV_ANEG     0x0200 /* Reverse auto-negotiation */
 #define E100_82552_ANEG_NOW     0x0400 /* Auto-negotiate now */
-static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
+static void __e100_shutdown(struct pci_dev *pdev, bool *enable_wake)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct nic *nic = netdev_priv(netdev);
@@ -2749,19 +2928,33 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
                                   E100_82552_SMARTSPEED, smartspeed |
                                   E100_82552_REV_ANEG | E100_82552_ANEG_NOW);
                }
-               if (pci_enable_wake(pdev, PCI_D3cold, true))
-                       pci_enable_wake(pdev, PCI_D3hot, true);
+               *enable_wake = true;
        } else {
-               pci_enable_wake(pdev, PCI_D3hot, false);
+               *enable_wake = false;
        }
 
        pci_disable_device(pdev);
+}
+
+static int __e100_power_off(struct pci_dev *pdev, bool wake)
+{
+       if (wake)
+               return pci_prepare_to_sleep(pdev);
+
+       pci_wake_from_d3(pdev, false);
        pci_set_power_state(pdev, PCI_D3hot);
 
        return 0;
 }
 
 #ifdef CONFIG_PM
+static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       bool wake;
+       __e100_shutdown(pdev, &wake);
+       return __e100_power_off(pdev, wake);
+}
+
 static int e100_resume(struct pci_dev *pdev)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
@@ -2772,7 +2965,7 @@ static int e100_resume(struct pci_dev *pdev)
        /* ack any pending wake events, disable PME */
        pci_enable_wake(pdev, 0, 0);
 
-       /* disbale reverse auto-negotiation */
+       /* disable reverse auto-negotiation */
        if (nic->phy == phy_82552_v) {
                u16 smartspeed = mdio_read(netdev, nic->mii.phy_id,
                                           E100_82552_SMARTSPEED);
@@ -2792,7 +2985,10 @@ static int e100_resume(struct pci_dev *pdev)
 
 static void e100_shutdown(struct pci_dev *pdev)
 {
-       e100_suspend(pdev, PMSG_SUSPEND);
+       bool wake;
+       __e100_shutdown(pdev, &wake);
+       if (system_state == SYSTEM_POWER_OFF)
+               __e100_power_off(pdev, wake);
 }
 
 /* ------------------ PCI Error Recovery infrastructure  -------------- */
@@ -2806,12 +3002,13 @@ static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct nic *nic = netdev_priv(netdev);
 
-       /* Similar to calling e100_down(), but avoids adapter I/O. */
-       e100_close(netdev);
-
-       /* Detach; put netif into a state similar to hotplug unplug. */
-       napi_enable(&nic->napi);
        netif_device_detach(netdev);
+
+       if (state == pci_channel_io_perm_failure)
+               return PCI_ERS_RESULT_DISCONNECT;
+
+       if (netif_running(netdev))
+               e100_down(nic);
        pci_disable_device(pdev);
 
        /* Request a slot reset. */