USB: remove leftover references to udev->autosuspend_disabled
[safe/jmp/linux-2.6] / drivers / net / sis190.c
index d470b19..b30ce75 100644 (file)
@@ -17,7 +17,9 @@
 
    See the file COPYING in this distribution for more information.
 
- */
+*/
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/delay.h>
 #include <linux/crc32.h>
 #include <linux/dma-mapping.h>
+#include <linux/slab.h>
 #include <asm/irq.h>
 
-#define net_drv(p, arg...)     if (netif_msg_drv(p)) \
-                                       printk(arg)
-#define net_probe(p, arg...)   if (netif_msg_probe(p)) \
-                                       printk(arg)
-#define net_link(p, arg...)    if (netif_msg_link(p)) \
-                                       printk(arg)
-#define net_intr(p, arg...)    if (netif_msg_intr(p)) \
-                                       printk(arg)
-#define net_tx_err(p, arg...)  if (netif_msg_tx_err(p)) \
-                                       printk(arg)
-
 #define PHY_MAX_ADDR           32
 #define PHY_ID_ANY             0x1f
 #define MII_REG_ANY            0x1f
 
-#ifdef CONFIG_SIS190_NAPI
-#define NAPI_SUFFIX    "-NAPI"
-#else
-#define NAPI_SUFFIX    ""
-#endif
-
-#define DRV_VERSION            "1.2" NAPI_SUFFIX
+#define DRV_VERSION            "1.4"
 #define DRV_NAME               "sis190"
 #define SIS190_DRIVER_NAME     DRV_NAME " Gigabit Ethernet driver " DRV_VERSION
-#define PFX DRV_NAME ": "
 
-#ifdef CONFIG_SIS190_NAPI
-#define sis190_rx_skb                  netif_receive_skb
-#define sis190_rx_quota(count, quota)  min(count, quota)
-#else
 #define sis190_rx_skb                  netif_rx
 #define sis190_rx_quota(count, quota)  count
-#endif
 
 #define MAC_ADDR_LEN           6
 
@@ -223,6 +203,12 @@ enum _DescStatusBit {
        THOL2           = 0x20000000,
        THOL1           = 0x10000000,
        THOL0           = 0x00000000,
+
+       WND             = 0x00080000,
+       TABRT           = 0x00040000,
+       FIFO            = 0x00020000,
+       LINK            = 0x00010000,
+       ColCountMask    = 0x0000ffff,
        /* RxDesc.status */
        IPON            = 0x20000000,
        TCPON           = 0x10000000,
@@ -281,7 +267,6 @@ struct sis190_private {
        void __iomem *mmio_addr;
        struct pci_dev *pci_dev;
        struct net_device *dev;
-       struct net_device_stats stats;
        spinlock_t lock;
        u32 rx_buf_sz;
        u32 cur_rx;
@@ -300,6 +285,12 @@ struct sis190_private {
        struct mii_if_info mii_if;
        struct list_head first_phy;
        u32 features;
+       u32 negotiated_lpa;
+       enum {
+               LNK_OFF,
+               LNK_ON,
+               LNK_AUTONEG,
+       } link_status;
 };
 
 struct sis190_phy {
@@ -323,6 +314,8 @@ static struct mii_chip_info {
         unsigned int type;
        u32 feature;
 } mii_chip_table[] = {
+       { "Atheros PHY",          { 0x004d, 0xd010 }, LAN, 0 },
+       { "Atheros PHY AR8012",   { 0x004d, 0xd020 }, LAN, 0 },
        { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN, F_PHY_BCM5461 },
        { "Broadcom PHY AC131",   { 0x0143, 0xbc70 }, LAN, 0 },
        { "Agere PHY ET1101B",    { 0x0282, 0xf010 }, LAN, 0 },
@@ -338,7 +331,7 @@ static const struct {
        { "SiS 191 PCI Gigabit Ethernet adapter" },
 };
 
-static struct pci_device_id sis190_pci_tbl[] __devinitdata = {
+static DEFINE_PCI_DEVICE_TABLE(sis190_pci_tbl) = {
        { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 },
        { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0191), 0, 0, 1 },
        { 0, },
@@ -352,7 +345,7 @@ static struct {
        u32 msg_enable;
 } debug = { -1 };
 
-MODULE_DESCRIPTION("SiS sis190 Gigabit Ethernet driver");
+MODULE_DESCRIPTION("SiS sis190/191 Gigabit Ethernet driver");
 module_param(rx_copybreak, int, 0);
 MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
 module_param_named(debug, debug.msg_enable, int, 0);
@@ -384,8 +377,8 @@ static void __mdio_cmd(void __iomem *ioaddr, u32 ctl)
                msleep(1);
        }
 
-       if (i > 999)
-               printk(KERN_ERR PFX "PHY command failed !\n");
+       if (i > 99)
+               pr_err("PHY command failed !\n");
 }
 
 static void mdio_write(void __iomem *ioaddr, int phy_id, int reg, int val)
@@ -486,36 +479,35 @@ static inline void sis190_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
 static inline void sis190_make_unusable_by_asic(struct RxDesc *desc)
 {
        desc->PSize = 0x0;
-       desc->addr = 0xdeadbeef;
+       desc->addr = cpu_to_le32(0xdeadbeef);
        desc->size &= cpu_to_le32(RingEnd);
        wmb();
        desc->status = 0x0;
 }
 
-static int sis190_alloc_rx_skb(struct pci_dev *pdev, struct sk_buff **sk_buff,
-                              struct RxDesc *desc, u32 rx_buf_sz)
+static struct sk_buff *sis190_alloc_rx_skb(struct sis190_private *tp,
+                                          struct RxDesc *desc)
 {
+       u32 rx_buf_sz = tp->rx_buf_sz;
        struct sk_buff *skb;
        dma_addr_t mapping;
-       int ret = 0;
-
-       skb = dev_alloc_skb(rx_buf_sz);
-       if (!skb)
-               goto err_out;
 
-       *sk_buff = skb;
+       skb = netdev_alloc_skb(tp->dev, rx_buf_sz);
+       if (unlikely(!skb))
+               goto skb_alloc_failed;
+       mapping = pci_map_single(tp->pci_dev, skb->data, tp->rx_buf_sz,
+                       PCI_DMA_FROMDEVICE);
+       if (pci_dma_mapping_error(tp->pci_dev, mapping))
+               goto out;
+       sis190_map_to_asic(desc, mapping, rx_buf_sz);
 
-       mapping = pci_map_single(pdev, skb->data, rx_buf_sz,
-                                PCI_DMA_FROMDEVICE);
+       return skb;
 
-       sis190_map_to_asic(desc, mapping, rx_buf_sz);
 out:
-       return ret;
-
-err_out:
-       ret = -ENOMEM;
+       dev_kfree_skb_any(skb);
+skb_alloc_failed:
        sis190_make_unusable_by_asic(desc);
-       goto out;
+       return NULL;
 }
 
 static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev,
@@ -524,37 +516,40 @@ static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev,
        u32 cur;
 
        for (cur = start; cur < end; cur++) {
-               int ret, i = cur % NUM_RX_DESC;
+               unsigned int i = cur % NUM_RX_DESC;
 
                if (tp->Rx_skbuff[i])
                        continue;
 
-               ret = sis190_alloc_rx_skb(tp->pci_dev, tp->Rx_skbuff + i,
-                                         tp->RxDescRing + i, tp->rx_buf_sz);
-               if (ret < 0)
+               tp->Rx_skbuff[i] = sis190_alloc_rx_skb(tp, tp->RxDescRing + i);
+
+               if (!tp->Rx_skbuff[i])
                        break;
        }
        return cur - start;
 }
 
-static inline int sis190_try_rx_copy(struct sk_buff **sk_buff, int pkt_size,
-                                    struct RxDesc *desc, int rx_buf_sz)
+static bool sis190_try_rx_copy(struct sis190_private *tp,
+                              struct sk_buff **sk_buff, int pkt_size,
+                              dma_addr_t addr)
 {
-       int ret = -1;
+       struct sk_buff *skb;
+       bool done = false;
 
-       if (pkt_size < rx_copybreak) {
-               struct sk_buff *skb;
+       if (pkt_size >= rx_copybreak)
+               goto out;
 
-               skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
-               if (skb) {
-                       skb_reserve(skb, NET_IP_ALIGN);
-                       skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
-                       *sk_buff = skb;
-                       sis190_give_to_asic(desc, rx_buf_sz);
-                       ret = 0;
-               }
-       }
-       return ret;
+       skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size);
+       if (!skb)
+               goto out;
+
+       pci_dma_sync_single_for_cpu(tp->pci_dev, addr, tp->rx_buf_sz,
+                               PCI_DMA_FROMDEVICE);
+       skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
+       *sk_buff = skb;
+       done = true;
+out:
+       return done;
 }
 
 static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats)
@@ -580,7 +575,7 @@ static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats)
 static int sis190_rx_interrupt(struct net_device *dev,
                               struct sis190_private *tp, void __iomem *ioaddr)
 {
-       struct net_device_stats *stats = &tp->stats;
+       struct net_device_stats *stats = &dev->stats;
        u32 rx_left, cur_rx = tp->cur_rx;
        u32 delta, count;
 
@@ -592,52 +587,47 @@ static int sis190_rx_interrupt(struct net_device *dev,
                struct RxDesc *desc = tp->RxDescRing + entry;
                u32 status;
 
-               if (desc->status & OWNbit)
+               if (le32_to_cpu(desc->status) & OWNbit)
                        break;
 
                status = le32_to_cpu(desc->PSize);
 
-               // net_intr(tp, KERN_INFO "%s: Rx PSize = %08x.\n", dev->name,
-               //       status);
+               //netif_info(tp, intr, dev, "Rx PSize = %08x\n", status);
 
                if (sis190_rx_pkt_err(status, stats) < 0)
                        sis190_give_to_asic(desc, tp->rx_buf_sz);
                else {
                        struct sk_buff *skb = tp->Rx_skbuff[entry];
+                       dma_addr_t addr = le32_to_cpu(desc->addr);
                        int pkt_size = (status & RxSizeMask) - 4;
-                       void (*pci_action)(struct pci_dev *, dma_addr_t,
-                               size_t, int) = pci_dma_sync_single_for_device;
+                       struct pci_dev *pdev = tp->pci_dev;
 
                        if (unlikely(pkt_size > tp->rx_buf_sz)) {
-                               net_intr(tp, KERN_INFO
-                                        "%s: (frag) status = %08x.\n",
-                                        dev->name, status);
+                               netif_info(tp, intr, dev,
+                                          "(frag) status = %08x\n", status);
                                stats->rx_dropped++;
                                stats->rx_length_errors++;
                                sis190_give_to_asic(desc, tp->rx_buf_sz);
                                continue;
                        }
 
-                       pci_dma_sync_single_for_cpu(tp->pci_dev,
-                               le32_to_cpu(desc->addr), tp->rx_buf_sz,
-                               PCI_DMA_FROMDEVICE);
 
-                       if (sis190_try_rx_copy(&skb, pkt_size, desc,
-                                              tp->rx_buf_sz)) {
-                               pci_action = pci_unmap_single;
+                       if (sis190_try_rx_copy(tp, &skb, pkt_size, addr)) {
+                               pci_dma_sync_single_for_device(pdev, addr,
+                                       tp->rx_buf_sz, PCI_DMA_FROMDEVICE);
+                               sis190_give_to_asic(desc, tp->rx_buf_sz);
+                       } else {
+                               pci_unmap_single(pdev, addr, tp->rx_buf_sz,
+                                                PCI_DMA_FROMDEVICE);
                                tp->Rx_skbuff[entry] = NULL;
                                sis190_make_unusable_by_asic(desc);
                        }
 
-                       pci_action(tp->pci_dev, le32_to_cpu(desc->addr),
-                                  tp->rx_buf_sz, PCI_DMA_FROMDEVICE);
-
                        skb_put(skb, pkt_size);
                        skb->protocol = eth_type_trans(skb, dev);
 
                        sis190_rx_skb(skb);
 
-                       dev->last_rx = jiffies;
                        stats->rx_packets++;
                        stats->rx_bytes += pkt_size;
                        if ((status & BCAST) == MCAST)
@@ -648,12 +638,12 @@ static int sis190_rx_interrupt(struct net_device *dev,
        tp->cur_rx = cur_rx;
 
        delta = sis190_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx);
-       if (!delta && count && netif_msg_intr(tp))
-               printk(KERN_INFO "%s: no Rx buffer allocated.\n", dev->name);
+       if (!delta && count)
+               netif_info(tp, intr, dev, "no Rx buffer allocated\n");
        tp->dirty_rx += delta;
 
-       if (((tp->dirty_rx + NUM_RX_DESC) == tp->cur_rx) && netif_msg_intr(tp))
-               printk(KERN_EMERG "%s: Rx buffers exhausted.\n", dev->name);
+       if ((tp->dirty_rx + NUM_RX_DESC) == tp->cur_rx)
+               netif_emerg(tp, intr, dev, "Rx buffers exhausted\n");
 
        return count;
 }
@@ -670,9 +660,31 @@ static void sis190_unmap_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
        memset(desc, 0x00, sizeof(*desc));
 }
 
+static inline int sis190_tx_pkt_err(u32 status, struct net_device_stats *stats)
+{
+#define TxErrMask      (WND | TABRT | FIFO | LINK)
+
+       if (!unlikely(status & TxErrMask))
+               return 0;
+
+       if (status & WND)
+               stats->tx_window_errors++;
+       if (status & TABRT)
+               stats->tx_aborted_errors++;
+       if (status & FIFO)
+               stats->tx_fifo_errors++;
+       if (status & LINK)
+               stats->tx_carrier_errors++;
+
+       stats->tx_errors++;
+
+       return -1;
+}
+
 static void sis190_tx_interrupt(struct net_device *dev,
                                struct sis190_private *tp, void __iomem *ioaddr)
 {
+       struct net_device_stats *stats = &dev->stats;
        u32 pending, dirty_tx = tp->dirty_tx;
        /*
         * It would not be needed if queueing was allowed to be enabled
@@ -687,15 +699,19 @@ static void sis190_tx_interrupt(struct net_device *dev,
        for (; pending; pending--, dirty_tx++) {
                unsigned int entry = dirty_tx % NUM_TX_DESC;
                struct TxDesc *txd = tp->TxDescRing + entry;
+               u32 status = le32_to_cpu(txd->status);
                struct sk_buff *skb;
 
-               if (le32_to_cpu(txd->status) & OWNbit)
+               if (status & OWNbit)
                        break;
 
                skb = tp->Tx_skbuff[entry];
 
-               tp->stats.tx_packets++;
-               tp->stats.tx_bytes += skb->len;
+               if (likely(sis190_tx_pkt_err(status, stats) == 0)) {
+                       stats->tx_packets++;
+                       stats->tx_bytes += skb->len;
+                       stats->collisions += ((status & ColCountMask) - 1);
+               }
 
                sis190_unmap_tx_skb(tp->pci_dev, skb, txd);
                tp->Tx_skbuff[entry] = NULL;
@@ -736,10 +752,11 @@ static irqreturn_t sis190_interrupt(int irq, void *__dev)
 
        SIS_W32(IntrStatus, status);
 
-       // net_intr(tp, KERN_INFO "%s: status = %08x.\n", dev->name, status);
+//     netif_info(tp, intr, dev, "status = %08x\n", status);
 
        if (status & LinkChange) {
-               net_intr(tp, KERN_INFO "%s: link change.\n", dev->name);
+               netif_info(tp, intr, dev, "link change\n");
+               del_timer(&tp->timer);
                schedule_work(&tp->phy_task);
        }
 
@@ -826,19 +843,17 @@ static void sis190_set_rx_mode(struct net_device *dev)
                        AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
                        AcceptAllPhys;
                mc_filter[1] = mc_filter[0] = 0xffffffff;
-       } else if ((dev->mc_count > multicast_filter_limit) ||
+       } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
                   (dev->flags & IFF_ALLMULTI)) {
                /* Too many to filter perfectly -- accept all multicasts. */
                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
                mc_filter[1] = mc_filter[0] = 0xffffffff;
        } else {
                struct dev_mc_list *mclist;
-               unsigned int i;
 
                rx_mode = AcceptBroadcast | AcceptMyPhys;
                mc_filter[1] = mc_filter[0] = 0;
-               for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
-                    i++, mclist = mclist->next) {
+               netdev_for_each_mc_addr(mclist, dev) {
                        int bit_nr =
                                ether_crc(ETH_ALEN, mclist->dmi_addr) & 0x3f;
                        mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
@@ -859,10 +874,8 @@ static void sis190_soft_reset(void __iomem *ioaddr)
 {
        SIS_W32(IntrControl, 0x8000);
        SIS_PCI_COMMIT();
-       msleep(1);
        SIS_W32(IntrControl, 0x0);
        sis190_asic_down(ioaddr);
-       msleep(1);
 }
 
 static void sis190_hw_start(struct net_device *dev)
@@ -916,23 +929,24 @@ static void sis190_phy_task(struct work_struct *work)
        if (val & BMCR_RESET) {
                // FIXME: needlessly high ?  -- FR 02/07/2005
                mod_timer(&tp->timer, jiffies + HZ/10);
-       } else if (!(mdio_read_latched(ioaddr, phy_id, MII_BMSR) &
-                    BMSR_ANEGCOMPLETE)) {
-               net_link(tp, KERN_WARNING "%s: PHY reset until link up.\n",
-                        dev->name);
+               goto out_unlock;
+       }
+
+       val = mdio_read_latched(ioaddr, phy_id, MII_BMSR);
+       if (!(val & BMSR_ANEGCOMPLETE) && tp->link_status != LNK_AUTONEG) {
                netif_carrier_off(dev);
-               mdio_write(ioaddr, phy_id, MII_BMCR, val | BMCR_RESET);
-               mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT);
-       } else {
+               netif_warn(tp, link, dev, "auto-negotiating...\n");
+               tp->link_status = LNK_AUTONEG;
+       } else if ((val & BMSR_LSTATUS) && tp->link_status != LNK_ON) {
                /* Rejoice ! */
                struct {
                        int val;
                        u32 ctl;
                        const char *msg;
                } reg31[] = {
-                       { LPA_1000XFULL | LPA_SLCT, 0x07000c00 | 0x00001000,
+                       { LPA_1000FULL, 0x07000c00 | 0x00001000,
                                "1000 Mbps Full Duplex" },
-                       { LPA_1000XHALF | LPA_SLCT, 0x07000c00,
+                       { LPA_1000HALF, 0x07000c00,
                                "1000 Mbps Half Duplex" },
                        { LPA_100FULL, 0x04000800 | 0x00001000,
                                "100 Mbps Full Duplex" },
@@ -943,22 +957,35 @@ static void sis190_phy_task(struct work_struct *work)
                        { LPA_10HALF, 0x04000400,
                                "10 Mbps Half Duplex" },
                        { 0, 0x04000400, "unknown" }
-               }, *p;
-               u16 adv;
+               }, *p = NULL;
+               u16 adv, autoexp, gigadv, gigrec;
 
                val = mdio_read(ioaddr, phy_id, 0x1f);
-               net_link(tp, KERN_INFO "%s: mii ext = %04x.\n", dev->name, val);
+               netif_info(tp, link, dev, "mii ext = %04x\n", val);
 
                val = mdio_read(ioaddr, phy_id, MII_LPA);
                adv = mdio_read(ioaddr, phy_id, MII_ADVERTISE);
-               net_link(tp, KERN_INFO "%s: mii lpa = %04x adv = %04x.\n",
-                        dev->name, val, adv);
-
-               val &= adv;
+               autoexp = mdio_read(ioaddr, phy_id, MII_EXPANSION);
+               netif_info(tp, link, dev, "mii lpa=%04x adv=%04x exp=%04x\n",
+                          val, adv, autoexp);
+
+               if (val & LPA_NPAGE && autoexp & EXPANSION_NWAY) {
+                       /* check for gigabit speed */
+                       gigadv = mdio_read(ioaddr, phy_id, MII_CTRL1000);
+                       gigrec = mdio_read(ioaddr, phy_id, MII_STAT1000);
+                       val = (gigadv & (gigrec >> 2));
+                       if (val & ADVERTISE_1000FULL)
+                               p = reg31;
+                       else if (val & ADVERTISE_1000HALF)
+                               p = reg31 + 1;
+               }
+               if (!p) {
+                       val &= adv;
 
-               for (p = reg31; p->val; p++) {
-                       if ((val & p->val) == p->val)
-                               break;
+                       for (p = reg31; p->val; p++) {
+                               if ((val & p->val) == p->val)
+                                       break;
+                       }
                }
 
                p->ctl |= SIS_R32(StationControl) & ~0x0f001c00;
@@ -979,10 +1006,14 @@ static void sis190_phy_task(struct work_struct *work)
                        SIS_W32(RGDelay, 0x0440);
                }
 
-               net_link(tp, KERN_INFO "%s: link on %s mode.\n", dev->name,
-                        p->msg);
+               tp->negotiated_lpa = p->val;
+
+               netif_info(tp, link, dev, "link on %s mode\n", p->msg);
                netif_carrier_on(dev);
-       }
+               tp->link_status = LNK_ON;
+       } else if (!(val & BMSR_LSTATUS) && tp->link_status != LNK_AUTONEG)
+               tp->link_status = LNK_OFF;
+       mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT);
 
 out_unlock:
        rtnl_unlock();
@@ -1053,8 +1084,6 @@ static int sis190_open(struct net_device *dev)
        if (rc < 0)
                goto err_free_rx_1;
 
-       INIT_WORK(&tp->phy_task, sis190_phy_task);
-
        sis190_request_timer(dev);
 
        rc = request_irq(dev->irq, sis190_interrupt, IRQF_SHARED, dev->name, dev);
@@ -1091,7 +1120,7 @@ static void sis190_tx_clear(struct sis190_private *tp)
                tp->Tx_skbuff[i] = NULL;
                dev_kfree_skb(skb);
 
-               tp->stats.tx_dropped++;
+               tp->dev->stats.tx_dropped++;
        }
        tp->cur_tx = tp->dirty_tx = 0;
 }
@@ -1115,10 +1144,8 @@ static void sis190_down(struct net_device *dev)
 
                synchronize_irq(dev->irq);
 
-               if (!poll_locked) {
-                       netif_poll_disable(dev);
+               if (!poll_locked)
                        poll_locked++;
-               }
 
                synchronize_sched();
 
@@ -1137,8 +1164,6 @@ static int sis190_close(struct net_device *dev)
 
        free_irq(dev->irq, dev);
 
-       netif_poll_enable(dev);
-
        pci_free_consistent(pdev, TX_RING_BYTES, tp->TxDescRing, tp->tx_dma);
        pci_free_consistent(pdev, RX_RING_BYTES, tp->RxDescRing, tp->rx_dma);
 
@@ -1148,7 +1173,8 @@ static int sis190_close(struct net_device *dev)
        return 0;
 }
 
-static int sis190_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t sis190_start_xmit(struct sk_buff *skb,
+                                    struct net_device *dev)
 {
        struct sis190_private *tp = netdev_priv(dev);
        void __iomem *ioaddr = tp->mmio_addr;
@@ -1158,7 +1184,7 @@ static int sis190_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        if (unlikely(skb->len < ETH_ZLEN)) {
                if (skb_padto(skb, ETH_ZLEN)) {
-                       tp->stats.tx_dropped++;
+                       dev->stats.tx_dropped++;
                        goto out;
                }
                len = ETH_ZLEN;
@@ -1171,13 +1197,17 @@ static int sis190_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        if (unlikely(le32_to_cpu(desc->status) & OWNbit)) {
                netif_stop_queue(dev);
-               net_tx_err(tp, KERN_ERR PFX
-                          "%s: BUG! Tx Ring full when queue awake!\n",
-                          dev->name);
+               netif_err(tp, tx_err, dev,
+                         "BUG! Tx Ring full when queue awake!\n");
                return NETDEV_TX_BUSY;
        }
 
        mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE);
+       if (pci_dma_mapping_error(tp->pci_dev, mapping)) {
+               netif_err(tp, tx_err, dev,
+                               "PCI mapping failed, dropping packet");
+               return NETDEV_TX_BUSY;
+       }
 
        tp->Tx_skbuff[entry] = skb;
 
@@ -1191,6 +1221,12 @@ static int sis190_start_xmit(struct sk_buff *skb, struct net_device *dev)
        wmb();
 
        desc->status = cpu_to_le32(OWNbit | INTbit | DEFbit | CRCbit | PADbit);
+       if (tp->negotiated_lpa & (LPA_1000HALF | LPA_100HALF | LPA_10HALF)) {
+               /* Half Duplex */
+               desc->status |= cpu_to_le32(COLEN | CRSEN | BKFEN);
+               if (tp->negotiated_lpa & (LPA_1000HALF | LPA_1000FULL))
+                       desc->status |= cpu_to_le32(EXTEN | BSTEN); /* gigabit HD */
+       }
 
        tp->cur_tx++;
 
@@ -1198,8 +1234,6 @@ static int sis190_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        SIS_W32(TxControl, 0x1a00 | CmdReset | CmdTxEnb);
 
-       dev->trans_start = jiffies;
-
        dirty_tx = tp->dirty_tx;
        if ((tp->cur_tx - NUM_TX_DESC) == dirty_tx) {
                netif_stop_queue(dev);
@@ -1211,13 +1245,6 @@ out:
        return NETDEV_TX_OK;
 }
 
-static struct net_device_stats *sis190_get_stats(struct net_device *dev)
-{
-       struct sis190_private *tp = netdev_priv(dev);
-
-       return &tp->stats;
-}
-
 static void sis190_free_phy(struct list_head *first_phy)
 {
        struct sis190_phy *cur, *next;
@@ -1270,15 +1297,15 @@ static u16 sis190_default_phy(struct net_device *dev)
                else if (phy_lan)
                        phy_default = phy_lan;
                else
-                       phy_default = list_entry(&tp->first_phy,
+                       phy_default = list_first_entry(&tp->first_phy,
                                                 struct sis190_phy, list);
        }
 
        if (mii_if->phy_id != phy_default->phy_id) {
                mii_if->phy_id = phy_default->phy_id;
-               net_probe(tp, KERN_INFO
-                      "%s: Using transceiver at address %d as default.\n",
-                      pci_name(tp->pci_dev), mii_if->phy_id);
+               if (netif_msg_probe(tp))
+                       pr_info("%s: Using transceiver at address %d as default\n",
+                               pci_name(tp->pci_dev), mii_if->phy_id);
        }
 
        status = mdio_read(ioaddr, mii_if->phy_id, MII_BMCR);
@@ -1316,12 +1343,16 @@ static void sis190_init_phy(struct net_device *dev, struct sis190_private *tp,
                        ((mii_status & (BMSR_100FULL | BMSR_100HALF)) ?
                                LAN : HOME) : p->type;
                tp->features |= p->feature;
-       } else
+               if (netif_msg_probe(tp))
+                       pr_info("%s: %s transceiver at address %d\n",
+                               pci_name(tp->pci_dev), p->name, phy_id);
+       } else {
                phy->type = UNKNOWN;
-
-       net_probe(tp, KERN_INFO "%s: %s transceiver at address %d.\n",
-                 pci_name(tp->pci_dev),
-                 (phy->type == UNKNOWN) ? "Unknown PHY" : p->name, phy_id);
+               if (netif_msg_probe(tp))
+                       pr_info("%s: unknown PHY 0x%x:0x%x transceiver at address %d\n",
+                               pci_name(tp->pci_dev),
+                               phy->id[0], (phy->id[1] & 0xfff0), phy_id);
+       }
 }
 
 static void sis190_mii_probe_88e1111_fixup(struct sis190_private *tp)
@@ -1384,8 +1415,9 @@ static int __devinit sis190_mii_probe(struct net_device *dev)
        }
 
        if (list_empty(&tp->first_phy)) {
-               net_probe(tp, KERN_INFO "%s: No MII transceivers found!\n",
-                         pci_name(tp->pci_dev));
+               if (netif_msg_probe(tp))
+                       pr_info("%s: No MII transceivers found!\n",
+                               pci_name(tp->pci_dev));
                rc = -EIO;
                goto out;
        }
@@ -1404,7 +1436,7 @@ out:
        return rc;
 }
 
-static void __devexit sis190_mii_remove(struct net_device *dev)
+static void sis190_mii_remove(struct net_device *dev)
 {
        struct sis190_private *tp = netdev_priv(dev);
 
@@ -1431,12 +1463,12 @@ static struct net_device * __devinit sis190_init_board(struct pci_dev *pdev)
 
        dev = alloc_etherdev(sizeof(*tp));
        if (!dev) {
-               net_drv(&debug, KERN_ERR PFX "unable to alloc new ethernet\n");
+               if (netif_msg_drv(&debug))
+                       pr_err("unable to alloc new ethernet\n");
                rc = -ENOMEM;
                goto err_out_0;
        }
 
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
 
        tp = netdev_priv(dev);
@@ -1445,34 +1477,39 @@ static struct net_device * __devinit sis190_init_board(struct pci_dev *pdev)
 
        rc = pci_enable_device(pdev);
        if (rc < 0) {
-               net_probe(tp, KERN_ERR "%s: enable failure\n", pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: enable failure\n", pci_name(pdev));
                goto err_free_dev_1;
        }
 
        rc = -ENODEV;
 
        if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
-               net_probe(tp, KERN_ERR "%s: region #0 is no MMIO resource.\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: region #0 is no MMIO resource\n",
+                              pci_name(pdev));
                goto err_pci_disable_2;
        }
        if (pci_resource_len(pdev, 0) < SIS190_REGS_SIZE) {
-               net_probe(tp, KERN_ERR "%s: invalid PCI region size(s).\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: invalid PCI region size(s)\n",
+                              pci_name(pdev));
                goto err_pci_disable_2;
        }
 
        rc = pci_request_regions(pdev, DRV_NAME);
        if (rc < 0) {
-               net_probe(tp, KERN_ERR PFX "%s: could not request regions.\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: could not request regions\n",
+                              pci_name(pdev));
                goto err_pci_disable_2;
        }
 
-       rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+       rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
        if (rc < 0) {
-               net_probe(tp, KERN_ERR "%s: DMA configuration failed.\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: DMA configuration failed\n",
+                              pci_name(pdev));
                goto err_free_res_3;
        }
 
@@ -1480,14 +1517,16 @@ static struct net_device * __devinit sis190_init_board(struct pci_dev *pdev)
 
        ioaddr = ioremap(pci_resource_start(pdev, 0), SIS190_REGS_SIZE);
        if (!ioaddr) {
-               net_probe(tp, KERN_ERR "%s: cannot remap MMIO, aborting\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_err("%s: cannot remap MMIO, aborting\n",
+                              pci_name(pdev));
                rc = -EIO;
                goto err_free_res_3;
        }
 
        tp->pci_dev = pdev;
        tp->mmio_addr = ioaddr;
+       tp->link_status = LNK_OFF;
 
        sis190_irq_mask_and_ack(ioaddr);
 
@@ -1517,9 +1556,8 @@ static void sis190_tx_timeout(struct net_device *dev)
        if (tmp8 & CmdTxEnb)
                SIS_W8(TxControl, tmp8 & ~CmdTxEnb);
 
-
-       net_tx_err(tp, KERN_INFO "%s: Transmit timeout, status %08x %08x.\n",
-                  dev->name, SIS_R32(TxControl), SIS_R32(TxSts));
+       netif_info(tp, tx_err, dev, "Transmit timeout, status %08x %08x\n",
+                  SIS_R32(TxControl), SIS_R32(TxSts));
 
        /* Disable interrupts by clearing the interrupt mask. */
        SIS_W32(IntrMask, 0x0000);
@@ -1548,23 +1586,24 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
        u16 sig;
        int i;
 
-       net_probe(tp, KERN_INFO "%s: Read MAC address from EEPROM\n",
-                 pci_name(pdev));
+       if (netif_msg_probe(tp))
+               pr_info("%s: Read MAC address from EEPROM\n", pci_name(pdev));
 
        /* Check to see if there is a sane EEPROM */
        sig = (u16) sis190_read_eeprom(ioaddr, EEPROMSignature);
 
        if ((sig == 0xffff) || (sig == 0x0000)) {
-               net_probe(tp, KERN_INFO "%s: Error EEPROM read %x.\n",
-                         pci_name(pdev), sig);
+               if (netif_msg_probe(tp))
+                       pr_info("%s: Error EEPROM read %x\n",
+                               pci_name(pdev), sig);
                return -EIO;
        }
 
        /* Get MAC address from EEPROM */
        for (i = 0; i < MAC_ADDR_LEN / 2; i++) {
-               __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
+               u16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
 
-               ((u16 *)dev->dev_addr)[i] = le16_to_cpu(w);
+               ((__le16 *)dev->dev_addr)[i] = cpu_to_le16(w);
        }
 
        sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
@@ -1573,32 +1612,36 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
 }
 
 /**
- *     sis190_get_mac_addr_from_apc - Get MAC address for SiS965 model
+ *     sis190_get_mac_addr_from_apc - Get MAC address for SiS96x model
  *     @pdev: PCI device
  *     @dev:  network device to get address for
  *
- *     SiS965 model, use APC CMOS RAM to store MAC address.
+ *     SiS96x model, use APC CMOS RAM to store MAC address.
  *     APC CMOS RAM is accessed through ISA bridge.
  *     MAC address is read into @net_dev->dev_addr.
  */
 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
                                                  struct net_device *dev)
 {
+       static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
        struct sis190_private *tp = netdev_priv(dev);
        struct pci_dev *isa_bridge;
        u8 reg, tmp8;
-       int i;
+       unsigned int i;
 
-       net_probe(tp, KERN_INFO "%s: Read MAC address from APC.\n",
-                 pci_name(pdev));
+       if (netif_msg_probe(tp))
+               pr_info("%s: Read MAC address from APC\n", pci_name(pdev));
 
-       isa_bridge = pci_get_device(PCI_VENDOR_ID_SI, 0x0965, NULL);
-       if (!isa_bridge)
-               isa_bridge = pci_get_device(PCI_VENDOR_ID_SI, 0x0966, NULL);
+       for (i = 0; i < ARRAY_SIZE(ids); i++) {
+               isa_bridge = pci_get_device(PCI_VENDOR_ID_SI, ids[i], NULL);
+               if (isa_bridge)
+                       break;
+       }
 
        if (!isa_bridge) {
-               net_probe(tp, KERN_INFO "%s: Can not find ISA bridge.\n",
-                         pci_name(pdev));
+               if (netif_msg_probe(tp))
+                       pr_info("%s: Can not find ISA bridge\n",
+                               pci_name(pdev));
                return -EIO;
        }
 
@@ -1655,15 +1698,21 @@ static inline void sis190_init_rxfilter(struct net_device *dev)
        SIS_PCI_COMMIT();
 }
 
-static int sis190_get_mac_addr(struct pci_dev *pdev, struct net_device *dev)
+static int __devinit sis190_get_mac_addr(struct pci_dev *pdev,
+                                        struct net_device *dev)
 {
-       u8 from;
+       int rc;
+
+       rc = sis190_get_mac_addr_from_eeprom(pdev, dev);
+       if (rc < 0) {
+               u8 reg;
 
-       pci_read_config_byte(pdev, 0x73, &from);
+               pci_read_config_byte(pdev, 0x73, &reg);
 
-       return (from & 0x00000001) ?
-               sis190_get_mac_addr_from_apc(pdev, dev) :
-               sis190_get_mac_addr_from_eeprom(pdev, dev);
+               if (reg & 0x00000001)
+                       rc = sis190_get_mac_addr_from_apc(pdev, dev);
+       }
+       return rc;
 }
 
 static void sis190_set_speed_auto(struct net_device *dev)
@@ -1673,7 +1722,7 @@ static void sis190_set_speed_auto(struct net_device *dev)
        int phy_id = tp->mii_if.phy_id;
        int val;
 
-       net_link(tp, KERN_INFO "%s: Enabling Auto-negotiation.\n", dev->name);
+       netif_info(tp, link, dev, "Enabling Auto-negotiation\n");
 
        val = mdio_read(ioaddr, phy_id, MII_ADVERTISE);
 
@@ -1775,6 +1824,21 @@ static int sis190_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                generic_mii_ioctl(&tp->mii_if, if_mii(ifr), cmd, NULL);
 }
 
+static const struct net_device_ops sis190_netdev_ops = {
+       .ndo_open               = sis190_open,
+       .ndo_stop               = sis190_close,
+       .ndo_do_ioctl           = sis190_ioctl,
+       .ndo_start_xmit         = sis190_start_xmit,
+       .ndo_tx_timeout         = sis190_tx_timeout,
+       .ndo_set_multicast_list = sis190_set_rx_mode,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller     = sis190_netpoll,
+#endif
+};
+
 static int __devinit sis190_init_one(struct pci_dev *pdev,
                                     const struct pci_device_id *ent)
 {
@@ -1785,7 +1849,8 @@ static int __devinit sis190_init_one(struct pci_dev *pdev,
        int rc;
 
        if (!printed_version) {
-               net_drv(&debug, KERN_INFO SIS190_DRIVER_NAME " loaded.\n");
+               if (netif_msg_drv(&debug))
+                       pr_info(SIS190_DRIVER_NAME " loaded\n");
                printed_version = 1;
        }
 
@@ -1808,20 +1873,12 @@ static int __devinit sis190_init_one(struct pci_dev *pdev,
 
        INIT_WORK(&tp->phy_task, sis190_phy_task);
 
-       dev->open = sis190_open;
-       dev->stop = sis190_close;
-       dev->do_ioctl = sis190_ioctl;
-       dev->get_stats = sis190_get_stats;
-       dev->tx_timeout = sis190_tx_timeout;
-       dev->watchdog_timeo = SIS190_TX_TIMEOUT;
-       dev->hard_start_xmit = sis190_start_xmit;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = sis190_netpoll;
-#endif
-       dev->set_multicast_list = sis190_set_rx_mode;
+       dev->netdev_ops = &sis190_netdev_ops;
+
        SET_ETHTOOL_OPS(dev, &sis190_ethtool_ops);
        dev->irq = pdev->irq;
        dev->base_addr = (unsigned long) 0xdead;
+       dev->watchdog_timeo = SIS190_TX_TIMEOUT;
 
        spin_lock_init(&tp->lock);
 
@@ -1833,16 +1890,14 @@ static int __devinit sis190_init_one(struct pci_dev *pdev,
        if (rc < 0)
                goto err_remove_mii;
 
-       net_probe(tp, KERN_INFO "%s: %s at %p (IRQ: %d), "
-              "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
-              pci_name(pdev), sis_chip_info[ent->driver_data].name,
-              ioaddr, dev->irq,
-              dev->dev_addr[0], dev->dev_addr[1],
-              dev->dev_addr[2], dev->dev_addr[3],
-              dev->dev_addr[4], dev->dev_addr[5]);
-
-       net_probe(tp, KERN_INFO "%s: %s mode.\n", dev->name,
-                 (tp->features & F_HAS_RGMII) ? "RGMII" : "GMII");
+       if (netif_msg_probe(tp)) {
+               netdev_info(dev, "%s: %s at %p (IRQ: %d), %pM\n",
+                           pci_name(pdev),
+                           sis_chip_info[ent->driver_data].name,
+                           ioaddr, dev->irq, dev->dev_addr);
+               netdev_info(dev, "%s mode.\n",
+                           (tp->features & F_HAS_RGMII) ? "RGMII" : "GMII");
+       }
 
        netif_carrier_off(dev);