[PATCH] b44: increase version to 1.00
[safe/jmp/linux-2.6] / drivers / net / b44.c
index ecc2e32..aa1ef74 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
+ * Copyright (C) 2006 Broadcom Corporation.
  *
  * Distribute under GPL.
  */
@@ -18,7 +19,6 @@
 #include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/init.h>
-#include <linux/version.h>
 #include <linux/dma-mapping.h>
 
 #include <asm/uaccess.h>
@@ -29,8 +29,8 @@
 
 #define DRV_MODULE_NAME                "b44"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "0.95"
-#define DRV_MODULE_RELDATE     "Aug 3, 2004"
+#define DRV_MODULE_VERSION     "1.00"
+#define DRV_MODULE_RELDATE     "Apr 7, 2006"
 
 #define B44_DEF_MSG_ENABLE       \
        (NETIF_MSG_DRV          | \
@@ -411,25 +411,18 @@ static void __b44_set_flow_ctrl(struct b44 *bp, u32 pause_flags)
 
 static void b44_set_flow_ctrl(struct b44 *bp, u32 local, u32 remote)
 {
-       u32 pause_enab = bp->flags & (B44_FLAG_TX_PAUSE |
-                                     B44_FLAG_RX_PAUSE);
+       u32 pause_enab = 0; 
 
-       if (local & ADVERTISE_PAUSE_CAP) {
-               if (local & ADVERTISE_PAUSE_ASYM) {
-                       if (remote & LPA_PAUSE_CAP)
-                               pause_enab |= (B44_FLAG_TX_PAUSE |
-                                              B44_FLAG_RX_PAUSE);
-                       else if (remote & LPA_PAUSE_ASYM)
-                               pause_enab |= B44_FLAG_RX_PAUSE;
-               } else {
-                       if (remote & LPA_PAUSE_CAP)
-                               pause_enab |= (B44_FLAG_TX_PAUSE |
-                                              B44_FLAG_RX_PAUSE);
-               }
-       } else if (local & ADVERTISE_PAUSE_ASYM) {
-               if ((remote & LPA_PAUSE_CAP) &&
-                   (remote & LPA_PAUSE_ASYM))
-                       pause_enab |= B44_FLAG_TX_PAUSE;
+       /* The driver supports only rx pause by default because
+          the b44 mac tx pause mechanism generates excessive 
+          pause frames.           
+          Use ethtool to turn on b44 tx pause if necessary.
+        */
+       if ((local & ADVERTISE_PAUSE_CAP) &&
+           (local & ADVERTISE_PAUSE_ASYM)){ 
+               if ((remote & LPA_PAUSE_ASYM) &&
+                   !(remote & LPA_PAUSE_CAP))
+                       pause_enab |= B44_FLAG_RX_PAUSE;
        }
 
        __b44_set_flow_ctrl(bp, pause_enab);
@@ -609,8 +602,7 @@ static void b44_tx(struct b44 *bp)
                struct ring_info *rp = &bp->tx_buffers[cons];
                struct sk_buff *skb = rp->skb;
 
-               if (unlikely(skb == NULL))
-                       BUG();
+               BUG_ON(skb == NULL);
 
                pci_unmap_single(bp->pdev,
                                 pci_unmap_addr(rp, mapping),
@@ -909,6 +901,12 @@ static irqreturn_t b44_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        istat &= imask;
        if (istat) {
                handled = 1;
+
+               if (unlikely(!netif_running(dev))) {
+                       printk(KERN_INFO "%s: late interrupt.\n", dev->name);
+                       goto irq_ack;
+               }
+
                if (netif_rx_schedule_prep(dev)) {
                        /* NOTE: These writes are posted by the readback of
                         *       the ISTAT register below.
@@ -921,6 +919,7 @@ static irqreturn_t b44_interrupt(int irq, void *dev_id, struct pt_regs *regs)
                               dev->name);
                }
 
+irq_ack:
                bw32(bp, B44_ISTAT, istat);
                br32(bp, B44_ISTAT);
        }
@@ -1333,6 +1332,9 @@ static int b44_set_mac_addr(struct net_device *dev, void *p)
        if (netif_running(dev))
                return -EBUSY;
 
+       if (!is_valid_ether_addr(addr->sa_data))
+               return -EINVAL;
+
        memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
 
        spin_lock_irq(&bp->lock);
@@ -1392,9 +1394,7 @@ static int b44_open(struct net_device *dev)
 
        b44_init_rings(bp);
        b44_init_hw(bp);
-       bp->flags |= B44_FLAG_INIT_COMPLETE;
 
-       netif_carrier_off(dev);
        b44_check_phy(bp);
 
        err = request_irq(dev->irq, b44_interrupt, SA_SHIRQ, dev->name, dev);
@@ -1412,6 +1412,7 @@ static int b44_open(struct net_device *dev)
        add_timer(&bp->timer);
 
        b44_enable_ints(bp);
+       netif_start_queue(dev);
 out:
        return err;
 }
@@ -1447,6 +1448,8 @@ static int b44_close(struct net_device *dev)
 
        netif_stop_queue(dev);
 
+       netif_poll_disable(dev);
+
        del_timer_sync(&bp->timer);
 
        spin_lock_irq(&bp->lock);
@@ -1456,13 +1459,14 @@ static int b44_close(struct net_device *dev)
 #endif
        b44_halt(bp);
        b44_free_rings(bp);
-       bp->flags &= ~B44_FLAG_INIT_COMPLETE;
-       netif_carrier_off(bp->dev);
+       netif_carrier_off(dev);
 
        spin_unlock_irq(&bp->lock);
 
        free_irq(dev->irq, dev);
 
+       netif_poll_enable(dev);
+
        b44_free_consistent(bp);
 
        return 0;
@@ -1608,7 +1612,7 @@ static int b44_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct b44 *bp = netdev_priv(dev);
 
-       if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
+       if (!netif_running(dev))
                return -EAGAIN;
        cmd->supported = (SUPPORTED_Autoneg);
        cmd->supported |= (SUPPORTED_100baseT_Half |
@@ -1646,7 +1650,7 @@ static int b44_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct b44 *bp = netdev_priv(dev);
 
-       if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
+       if (!netif_running(dev))
                return -EAGAIN;
 
        /* We do not support gigabit. */
@@ -1829,12 +1833,15 @@ static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
        struct mii_ioctl_data *data = if_mii(ifr);
        struct b44 *bp = netdev_priv(dev);
-       int err;
+       int err = -EINVAL;
+
+       if (!netif_running(dev))
+               goto out;
 
        spin_lock_irq(&bp->lock);
        err = generic_mii_ioctl(&bp->mii_if, data, cmd, NULL);
        spin_unlock_irq(&bp->lock);
-
+out:
        return err;
 }
 
@@ -1865,6 +1872,12 @@ static int __devinit b44_get_invariants(struct b44 *bp)
        bp->dev->dev_addr[3] = eeprom[80];
        bp->dev->dev_addr[4] = eeprom[83];
        bp->dev->dev_addr[5] = eeprom[82];
+
+       if (!is_valid_ether_addr(&bp->dev->dev_addr[0])){
+               printk(KERN_ERR PFX "Invalid MAC address found in EEPROM\n");
+               return -EINVAL;
+       }
+
        memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len);
 
        bp->phy_addr = eeprom[90] & 0x1f;
@@ -1988,6 +2001,8 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
        dev->irq = pdev->irq;
        SET_ETHTOOL_OPS(dev, &b44_ethtool_ops);
 
+       netif_carrier_off(dev);
+
        err = b44_get_invariants(bp);
        if (err) {
                printk(KERN_ERR PFX "Problem fetching invariants of chip, "
@@ -2020,6 +2035,11 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
 
        pci_save_state(bp->pdev);
 
+       /* Chip reset provides power to the b44 MAC & PCI cores, which 
+        * is necessary for MAC register access.
+        */ 
+       b44_chip_reset(bp);
+
        printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
        for (i = 0; i < 6; i++)
                printk("%2.2x%c", dev->dev_addr[i],
@@ -2105,6 +2125,7 @@ static int b44_resume(struct pci_dev *pdev)
        add_timer(&bp->timer);
 
        b44_enable_ints(bp);
+       netif_wake_queue(dev);
        return 0;
 }
 
@@ -2123,7 +2144,7 @@ static int __init b44_init(void)
 
        /* Setup paramaters for syncing RX/TX DMA descriptors */
        dma_desc_align_mask = ~(dma_desc_align_size - 1);
-       dma_desc_sync_size = max(dma_desc_align_size, sizeof(struct dma_desc));
+       dma_desc_sync_size = max_t(unsigned int, dma_desc_align_size, sizeof(struct dma_desc));
 
        return pci_module_init(&b44_driver);
 }