DVB (2454): Port code for SU1278/SH2 (TUA6100) from pre-refactored code
[safe/jmp/linux-2.6] / drivers / net / sky2.c
index e1733aa..f5d697c 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/delay.h>
 #include <linux/workqueue.h>
 #include <linux/if_vlan.h>
+#include <linux/prefetch.h>
 #include <linux/mii.h>
 
 #include <asm/irq.h>
@@ -56,7 +57,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "0.9"
+#define DRV_VERSION            "0.11"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -480,6 +481,14 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
 }
 
+/* Force a renegotiation */
+static void sky2_phy_reinit(struct sky2_port *sky2)
+{
+       down(&sky2->phy_sema);
+       sky2_phy_init(sky2->hw, sky2->port);
+       up(&sky2->phy_sema);
+}
+
 static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 {
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
@@ -1013,18 +1022,22 @@ static int sky2_up(struct net_device *dev)
        return 0;
 
 err_out:
-       if (sky2->rx_le)
+       if (sky2->rx_le) {
                pci_free_consistent(hw->pdev, RX_LE_BYTES,
                                    sky2->rx_le, sky2->rx_le_map);
-       if (sky2->tx_le)
+               sky2->rx_le = NULL;
+       }
+       if (sky2->tx_le) {
                pci_free_consistent(hw->pdev,
                                    TX_RING_SIZE * sizeof(struct sky2_tx_le),
                                    sky2->tx_le, sky2->tx_le_map);
-       if (sky2->tx_ring)
-               kfree(sky2->tx_ring);
-       if (sky2->rx_ring)
-               kfree(sky2->rx_ring);
+               sky2->tx_le = NULL;
+       }
+       kfree(sky2->tx_ring);
+       kfree(sky2->rx_ring);
 
+       sky2->tx_ring = NULL;
+       sky2->rx_ring = NULL;
        return err;
 }
 
@@ -1081,11 +1094,16 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
                return NETDEV_TX_LOCKED;
 
        if (unlikely(tx_avail(sky2) < tx_le_req(skb))) {
-               netif_stop_queue(dev);
+               /* There is a known but harmless race with lockless tx
+                * and netif_stop_queue.
+                */
+               if (!netif_queue_stopped(dev)) {
+                       netif_stop_queue(dev);
+                       printk(KERN_WARNING PFX "%s: ring full when queue awake!\n",
+                              dev->name);
+               }
                spin_unlock(&sky2->tx_lock);
 
-               printk(KERN_WARNING PFX "%s: ring full when queue awake!\n",
-                      dev->name);
                return NETDEV_TX_BUSY;
        }
 
@@ -1243,6 +1261,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
 
                nxt = re->idx;
                BUG_ON(nxt >= TX_RING_SIZE);
+               prefetch(sky2->tx_ring + nxt);
 
                /* Check for partial status */
                if (tx_dist(put, done) < tx_dist(put, nxt))
@@ -1284,6 +1303,10 @@ static int sky2_down(struct net_device *dev)
        unsigned port = sky2->port;
        u16 ctrl;
 
+       /* Never really got started! */
+       if (!sky2->tx_le)
+               return 0;
+
        if (netif_msg_ifdown(sky2))
                printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
 
@@ -1358,6 +1381,12 @@ static int sky2_down(struct net_device *dev)
                            sky2->tx_le, sky2->tx_le_map);
        kfree(sky2->tx_ring);
 
+       sky2->tx_le = NULL;
+       sky2->rx_le = NULL;
+
+       sky2->rx_ring = NULL;
+       sky2->tx_ring = NULL;
+
        return 0;
 }
 
@@ -1449,8 +1478,6 @@ static void sky2_link_down(struct sky2_port *sky2)
                             | PHY_M_AN_ASP);
        }
 
-       sky2_phy_reset(hw, port);
-
        netif_carrier_off(sky2->netdev);
        netif_stop_queue(sky2->netdev);
 
@@ -1629,12 +1656,17 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD);
 
        err = sky2_rx_start(sky2);
-       gma_write16(hw, sky2->port, GM_GP_CTRL, ctl);
-
-       netif_poll_disable(hw->dev[0]);
-       netif_wake_queue(dev);
        sky2_write32(hw, B0_IMSK, hw->intr_mask);
 
+       if (err)
+               dev_close(dev);
+       else {
+               gma_write16(hw, sky2->port, GM_GP_CTRL, ctl);
+
+               netif_poll_enable(hw->dev[0]);
+               netif_wake_queue(dev);
+       }
+
        return err;
 }
 
@@ -1654,6 +1686,7 @@ static struct sk_buff *sky2_receive(struct sky2_port *sky2,
                       sky2->netdev->name, sky2->rx_next, status, length);
 
        sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
+       prefetch(sky2->rx_ring + sky2->rx_next);
 
        if (status & GMR_FS_ANY_ERR)
                goto error;
@@ -1661,6 +1694,9 @@ static struct sk_buff *sky2_receive(struct sky2_port *sky2,
        if (!(status & GMR_FS_RX_OK))
                goto resubmit;
 
+       if ((status >> 16) != length || length > sky2->rx_bufsize)
+               goto oversize;
+
        if (length < copybreak) {
                skb = alloc_skb(length + 2, GFP_ATOMIC);
                if (!skb)
@@ -1702,7 +1738,13 @@ resubmit:
 
        return skb;
 
+oversize:
+       ++sky2->net_stats.rx_over_errors;
+       goto resubmit;
+
 error:
+       ++sky2->net_stats.rx_errors;
+
        if (netif_msg_rx_err(sky2))
                printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
                       sky2->netdev->name, status, length);
@@ -2307,10 +2349,8 @@ static int sky2_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
        sky2->autoneg = ecmd->autoneg;
        sky2->advertising = ecmd->advertising;
 
-       if (netif_running(dev)) {
-               sky2_down(dev);
-               sky2_up(dev);
-       }
+       if (netif_running(dev))
+               sky2_phy_reinit(sky2);
 
        return 0;
 }
@@ -2381,17 +2421,11 @@ static u32 sky2_get_msglevel(struct net_device *netdev)
 static int sky2_nway_reset(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
-       struct sky2_hw *hw = sky2->hw;
 
        if (sky2->autoneg != AUTONEG_ENABLE)
                return -EINVAL;
 
-       netif_stop_queue(dev);
-
-       down(&sky2->phy_sema);
-       sky2_phy_reset(hw, sky2->port);
-       sky2_phy_init(hw, sky2->port);
-       up(&sky2->phy_sema);
+       sky2_phy_reinit(sky2);
 
        return 0;
 }
@@ -2469,20 +2503,20 @@ static int sky2_set_mac_address(struct net_device *dev, void *p)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
        struct sockaddr *addr = p;
-       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
-       sky2_down(dev);
        memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
        memcpy_toio(sky2->hw->regs + B2_MAC_1 + sky2->port * 8,
                    dev->dev_addr, ETH_ALEN);
        memcpy_toio(sky2->hw->regs + B2_MAC_2 + sky2->port * 8,
                    dev->dev_addr, ETH_ALEN);
-       if (dev->flags & IFF_UP)
-               err = sky2_up(dev);
-       return err;
+
+       if (netif_running(dev))
+               sky2_phy_reinit(sky2);
+
+       return 0;
 }
 
 static void sky2_set_multicast(struct net_device *dev)
@@ -2640,10 +2674,7 @@ static int sky2_set_pauseparam(struct net_device *dev,
        sky2->tx_pause = ecmd->tx_pause != 0;
        sky2->rx_pause = ecmd->rx_pause != 0;
 
-       if (netif_running(dev)) {
-               sky2_down(dev);
-               err = sky2_up(dev);
-       }
+       sky2_phy_reinit(sky2);
 
        return err;
 }
@@ -2805,8 +2836,13 @@ static int sky2_set_ringparam(struct net_device *dev,
        sky2->rx_pending = ering->rx_pending;
        sky2->tx_pending = ering->tx_pending;
 
-       if (netif_running(dev))
+       if (netif_running(dev)) {
                err = sky2_up(dev);
+               if (err)
+                       dev_close(dev);
+               else
+                       sky2_set_multicast(dev);
+       }
 
        return err;
 }
@@ -2913,12 +2949,18 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        spin_lock_init(&sky2->tx_lock);
        /* Auto speed and flow control */
        sky2->autoneg = AUTONEG_ENABLE;
-       sky2->tx_pause = 0;
+       sky2->tx_pause = 1;
        sky2->rx_pause = 1;
        sky2->duplex = -1;
        sky2->speed = -1;
        sky2->advertising = sky2_supported_modes(hw);
-       sky2->rx_csum = 1;
+
+       /* Receive checksum disabled for Yukon XL
+        * because of observed problems with incorrect
+        * values when multiple packets are received in one interrupt
+        */
+       sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
+
        INIT_WORK(&sky2->phy_task, sky2_phy_task, sky2);
        init_MUTEX(&sky2->phy_sema);
        sky2->tx_pending = TX_DEF_PENDING;
@@ -3181,7 +3223,8 @@ static int sky2_resume(struct pci_dev *pdev)
                if (dev) {
                        if (netif_running(dev)) {
                                netif_device_attach(dev);
-                               sky2_up(dev);
+                               if (sky2_up(dev))
+                                       dev_close(dev);
                        }
                }
        }