fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / net / b44.c
index e83c73e..4a59965 100644 (file)
@@ -111,6 +111,11 @@ MODULE_DEVICE_TABLE(pci, b44_pci_tbl);
 
 static void b44_halt(struct b44 *);
 static void b44_init_rings(struct b44 *);
+
+#define B44_FULL_RESET         1
+#define B44_FULL_RESET_SKIP_PHY        2
+#define B44_PARTIAL_RESET      3
+
 static void b44_init_hw(struct b44 *, int);
 
 static int dma_desc_align_mask;
@@ -753,7 +758,7 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
                                             dest_idx * sizeof(dest_desc),
                                             DMA_BIDIRECTIONAL);
 
-       pci_dma_sync_single_for_device(bp->pdev, src_desc->addr,
+       pci_dma_sync_single_for_device(bp->pdev, le32_to_cpu(src_desc->addr),
                                       RX_PKT_BUF_SZ,
                                       PCI_DMA_FROMDEVICE);
 }
@@ -880,12 +885,14 @@ static int b44_poll(struct net_device *netdev, int *budget)
        }
 
        if (bp->istat & ISTAT_ERRORS) {
-               spin_lock_irq(&bp->lock);
+               unsigned long flags;
+
+               spin_lock_irqsave(&bp->lock, flags);
                b44_halt(bp);
                b44_init_rings(bp);
-               b44_init_hw(bp, 1);
+               b44_init_hw(bp, B44_FULL_RESET_SKIP_PHY);
                netif_wake_queue(bp->dev);
-               spin_unlock_irq(&bp->lock);
+               spin_unlock_irqrestore(&bp->lock, flags);
                done = 1;
        }
 
@@ -897,7 +904,7 @@ static int b44_poll(struct net_device *netdev, int *budget)
        return (done ? 0 : 1);
 }
 
-static irqreturn_t b44_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t b44_interrupt(int irq, void *dev_id)
 {
        struct net_device *dev = dev_id;
        struct b44 *bp = netdev_priv(dev);
@@ -909,8 +916,9 @@ static irqreturn_t b44_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        istat = br32(bp, B44_ISTAT);
        imask = br32(bp, B44_IMASK);
 
-       /* ??? What the fuck is the purpose of the interrupt mask
-        * ??? register if we have to mask it out by hand anyways?
+       /* The interrupt mask register controls which interrupt bits
+        * will actually raise an interrupt to the CPU when set by hw/firmware,
+        * but doesn't mask off the bits.
         */
        istat &= imask;
        if (istat) {
@@ -952,7 +960,7 @@ static void b44_tx_timeout(struct net_device *dev)
 
        b44_halt(bp);
        b44_init_rings(bp);
-       b44_init_hw(bp, 1);
+       b44_init_hw(bp, B44_FULL_RESET);
 
        spin_unlock_irq(&bp->lock);
 
@@ -1069,7 +1077,7 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
        b44_halt(bp);
        dev->mtu = new_mtu;
        b44_init_rings(bp);
-       b44_init_hw(bp, 1);
+       b44_init_hw(bp, B44_FULL_RESET);
        spin_unlock_irq(&bp->lock);
 
        b44_enable_ints(bp);
@@ -1366,12 +1374,12 @@ static int b44_set_mac_addr(struct net_device *dev, void *p)
  * packet processing.  Invoked with bp->lock held.
  */
 static void __b44_set_rx_mode(struct net_device *);
-static void b44_init_hw(struct b44 *bp, int full_reset)
+static void b44_init_hw(struct b44 *bp, int reset_kind)
 {
        u32 val;
 
        b44_chip_reset(bp);
-       if (full_reset) {
+       if (reset_kind == B44_FULL_RESET) {
                b44_phy_reset(bp);
                b44_setup_phy(bp);
        }
@@ -1388,7 +1396,10 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
        bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
 
        bw32(bp, B44_TX_WMARK, 56); /* XXX magic */
-       if (full_reset) {
+       if (reset_kind == B44_PARTIAL_RESET) {
+               bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
+                                     (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
+       } else {
                bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE);
                bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset);
                bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
@@ -1399,9 +1410,6 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
                bp->rx_prod = bp->rx_pending;
 
                bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
-       } else {
-               bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
-                                     (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
        }
 
        val = br32(bp, B44_ENET_CTRL);
@@ -1418,7 +1426,7 @@ static int b44_open(struct net_device *dev)
                goto out;
 
        b44_init_rings(bp);
-       b44_init_hw(bp, 1);
+       b44_init_hw(bp, B44_FULL_RESET);
 
        b44_check_phy(bp);
 
@@ -1462,7 +1470,7 @@ out:
 static void b44_poll_controller(struct net_device *dev)
 {
        disable_irq(dev->irq);
-       b44_interrupt(dev->irq, dev, NULL);
+       b44_interrupt(dev->irq, dev);
        enable_irq(dev->irq);
 }
 #endif
@@ -1627,7 +1635,7 @@ static int b44_close(struct net_device *dev)
        netif_poll_enable(dev);
 
        if (bp->flags & B44_FLAG_WOL_ENABLE) {
-               b44_init_hw(bp, 0);
+               b44_init_hw(bp, B44_PARTIAL_RESET);
                b44_setup_wol(bp);
        }
 
@@ -1707,14 +1715,15 @@ static void __b44_set_rx_mode(struct net_device *dev)
 
                __b44_set_mac_addr(bp);
 
-               if (dev->flags & IFF_ALLMULTI)
+               if ((dev->flags & IFF_ALLMULTI) ||
+                   (dev->mc_count > B44_MCAST_TABLE_SIZE))
                        val |= RXCONFIG_ALLMULTI;
                else
                        i = __b44_load_mcast(bp, dev);
 
-               for (; i < 64; i++) {
+               for (; i < 64; i++)
                        __b44_cam_write(bp, zero, i);
-               }
+
                bw32(bp, B44_RXCONFIG, val);
                val = br32(bp, B44_CAM_CTRL);
                bw32(bp, B44_CAM_CTRL, val | CAM_CTRL_ENABLE);
@@ -1902,7 +1911,7 @@ static int b44_set_ringparam(struct net_device *dev,
 
        b44_halt(bp);
        b44_init_rings(bp);
-       b44_init_hw(bp, 1);
+       b44_init_hw(bp, B44_FULL_RESET);
        netif_wake_queue(bp->dev);
        spin_unlock_irq(&bp->lock);
 
@@ -1945,7 +1954,7 @@ static int b44_set_pauseparam(struct net_device *dev,
        if (bp->flags & B44_FLAG_PAUSE_AUTO) {
                b44_halt(bp);
                b44_init_rings(bp);
-               b44_init_hw(bp, 1);
+               b44_init_hw(bp, B44_FULL_RESET);
        } else {
                __b44_set_flow_ctrl(bp, bp->flags);
        }
@@ -2013,7 +2022,7 @@ static int b44_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
        return 0;
 }
 
-static struct ethtool_ops b44_ethtool_ops = {
+static const struct ethtool_ops b44_ethtool_ops = {
        .get_drvinfo            = b44_get_drvinfo,
        .get_settings           = b44_get_settings,
        .set_settings           = b44_set_settings,
@@ -2056,7 +2065,7 @@ static int b44_read_eeprom(struct b44 *bp, u8 *data)
        u16 *ptr = (u16 *) data;
 
        for (i = 0; i < 128; i += 2)
-               ptr[i / 2] = readw(bp->regs + 4096 + i);
+               ptr[i / 2] = cpu_to_le16(readw(bp->regs + 4096 + i));
 
        return 0;
 }
@@ -2301,7 +2310,7 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
 
        free_irq(dev->irq, dev);
        if (bp->flags & B44_FLAG_WOL_ENABLE) {
-               b44_init_hw(bp, 0);
+               b44_init_hw(bp, B44_PARTIAL_RESET);
                b44_setup_wol(bp);
        }
        pci_disable_device(pdev);
@@ -2312,21 +2321,32 @@ static int b44_resume(struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct b44 *bp = netdev_priv(dev);
+       int rc = 0;
 
        pci_restore_state(pdev);
-       pci_enable_device(pdev);
+       rc = pci_enable_device(pdev);
+       if (rc) {
+               printk(KERN_ERR PFX "%s: pci_enable_device failed\n",
+                       dev->name);
+               return rc;
+       }
+
        pci_set_master(pdev);
 
        if (!netif_running(dev))
                return 0;
 
-       if (request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev))
+       rc = request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev);
+       if (rc) {
                printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name);
+               pci_disable_device(pdev);
+               return rc;
+       }
 
        spin_lock_irq(&bp->lock);
 
        b44_init_rings(bp);
-       b44_init_hw(bp, 1);
+       b44_init_hw(bp, B44_FULL_RESET);
        netif_device_attach(bp->dev);
        spin_unlock_irq(&bp->lock);
 
@@ -2355,7 +2375,7 @@ static int __init b44_init(void)
        dma_desc_align_mask = ~(dma_desc_align_size - 1);
        dma_desc_sync_size = max_t(unsigned int, dma_desc_align_size, sizeof(struct dma_desc));
 
-       return pci_module_init(&b44_driver);
+       return pci_register_driver(&b44_driver);
 }
 
 static void __exit b44_cleanup(void)