sky2: fix VLAN receive processing (resend)
[powerpc.git] / drivers / net / sky2.c
index b0950e1..8b15654 100644 (file)
@@ -51,7 +51,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.15"
+#define DRV_VERSION            "1.17"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -77,6 +77,9 @@
 #define NAPI_WEIGHT            64
 #define PHY_RETRIES            1000
 
+#define SKY2_EEPROM_MAGIC      0x9955aabb
+
+
 #define RING_NEXT(x,s) (((x)+1) & ((s)-1))
 
 static const u32 default_msg =
@@ -96,10 +99,6 @@ static int disable_msi = 0;
 module_param(disable_msi, int, 0);
 MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
 
-static int idle_timeout = 100;
-module_param(idle_timeout, int, 0);
-MODULE_PARM_DESC(idle_timeout, "Watchdog timer for lost interrupts (ms)");
-
 static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, /* SK-9Sxx */
        { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
@@ -150,6 +149,8 @@ static const char *yukon2_name[] = {
        "FE",           /* 0xb7 */
 };
 
+static void sky2_set_multicast(struct net_device *dev);
+
 /* Access to external PHY */
 static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
 {
@@ -216,9 +217,12 @@ static void sky2_power_on(struct sky2_hw *hw)
        else
                sky2_write8(hw, B2_Y2_CLK_GATE, 0);
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U ||
+           hw->chip_id == CHIP_ID_YUKON_EX) {
                u32 reg;
 
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+
                reg = sky2_pci_read32(hw, PCI_DEV_REG4);
                /* set all bits to 0 except bits 15..12 and 8 */
                reg &= P_ASPM_CONTROL_MSK;
@@ -235,6 +239,8 @@ static void sky2_power_on(struct sky2_hw *hw)
                reg = sky2_read32(hw, B2_GP_IO);
                reg |= GLB_GPIO_STAT_RACE_DIS;
                sky2_write32(hw, B2_GP_IO, reg);
+
+               sky2_read32(hw, B2_GP_IO);
        }
 }
 
@@ -689,11 +695,12 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 {
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
        u16 reg;
+       u32 rx_reg;
        int i;
        const u8 *addr = hw->dev[port]->dev_addr;
 
-       sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
-       sky2_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
+       sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
+       sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
 
        sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
 
@@ -765,11 +772,11 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 
        /* Configure Rx MAC FIFO */
        sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
-       reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
+       rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
        if (hw->chip_id == CHIP_ID_YUKON_EX)
-               reg |= GMF_RX_OVER_ON;
+               rx_reg |= GMF_RX_OVER_ON;
 
-       sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
+       sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
 
        /* Flush Rx MAC FIFO on any flow control or error */
        sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
@@ -890,24 +897,18 @@ static inline struct sky2_rx_le *sky2_next_rx(struct sky2_port *sky2)
        return le;
 }
 
-/* Return high part of DMA address (could be 32 or 64 bit) */
-static inline u32 high32(dma_addr_t a)
-{
-       return sizeof(a) > sizeof(u32) ? (a >> 16) >> 16 : 0;
-}
-
 /* Build description to hardware for one receive segment */
 static void sky2_rx_add(struct sky2_port *sky2,  u8 op,
                        dma_addr_t map, unsigned len)
 {
        struct sky2_rx_le *le;
-       u32 hi = high32(map);
+       u32 hi = upper_32_bits(map);
 
        if (sky2->rx_addr64 != hi) {
                le = sky2_next_rx(sky2);
                le->addr = cpu_to_le32(hi);
                le->opcode = OP_ADDR64 | HW_OWNER;
-               sky2->rx_addr64 = high32(map + len);
+               sky2->rx_addr64 = upper_32_bits(map + len);
        }
 
        le = sky2_next_rx(sky2);
@@ -1177,8 +1178,7 @@ static int sky2_rx_start(struct sky2_port *sky2)
        rx_set_checksum(sky2);
 
        /* Space needed for frame data + headers rounded up */
-       size = ALIGN(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8)
-               + 8;
+       size = roundup(sky2->netdev->mtu + ETH_HLEN + VLAN_HLEN, 8);
 
        /* Stopping point for hardware truncation */
        thresh = (size - 8) / sizeof(u32);
@@ -1422,14 +1422,15 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
 
        len = skb_headlen(skb);
        mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
-       addr64 = high32(mapping);
+       addr64 = upper_32_bits(mapping);
 
        /* Send high bits if changed or crosses boundary */
-       if (addr64 != sky2->tx_addr64 || high32(mapping + len) != sky2->tx_addr64) {
+       if (addr64 != sky2->tx_addr64 ||
+           upper_32_bits(mapping + len) != sky2->tx_addr64) {
                le = get_tx_le(sky2);
                le->addr = cpu_to_le32(addr64);
                le->opcode = OP_ADDR64 | HW_OWNER;
-               sky2->tx_addr64 = high32(mapping + len);
+               sky2->tx_addr64 = upper_32_bits(mapping + len);
        }
 
        /* Check for TCP Segmentation Offload */
@@ -1509,7 +1510,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
 
                mapping = pci_map_page(hw->pdev, frag->page, frag->page_offset,
                                       frag->size, PCI_DMA_TODEVICE);
-               addr64 = high32(mapping);
+               addr64 = upper_32_bits(mapping);
                if (addr64 != sky2->tx_addr64) {
                        le = get_tx_le(sky2);
                        le->addr = cpu_to_le32(addr64);
@@ -1621,6 +1622,9 @@ static int sky2_down(struct net_device *dev)
        if (netif_msg_ifdown(sky2))
                printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
 
+       if (netif_carrier_ok(dev) && --hw->active == 0)
+               del_timer(&hw->watchdog_timer);
+
        /* Stop more packets from being queued */
        netif_stop_queue(dev);
 
@@ -1741,6 +1745,10 @@ static void sky2_link_up(struct sky2_port *sky2)
 
        netif_carrier_on(sky2->netdev);
 
+       if (hw->active++ == 0)
+               mod_timer(&hw->watchdog_timer, jiffies + 1);
+
+
        /* Turn on link LED */
        sky2_write8(hw, SK_REG(port, LNK_LED_REG),
                    LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
@@ -1792,6 +1800,11 @@ static void sky2_link_down(struct sky2_port *sky2)
 
        netif_carrier_off(sky2->netdev);
 
+       /* Stop watchdog if both ports are not active */
+       if (--hw->active == 0)
+               del_timer(&hw->watchdog_timer);
+
+
        /* Turn on link LED */
        sky2_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
 
@@ -2061,8 +2074,6 @@ static struct sk_buff *receive_new(struct sky2_port *sky2,
        struct sk_buff *skb, *nskb;
        unsigned hdr_space = sky2->rx_data_size;
 
-       pr_debug(PFX "receive new length=%d\n", length);
-
        /* Don't be tricky about reusing pages (yet) */
        nskb = sky2_rx_alloc(sky2);
        if (unlikely(!nskb))
@@ -2092,6 +2103,13 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
        struct sky2_port *sky2 = netdev_priv(dev);
        struct rx_ring_info *re = sky2->rx_ring + sky2->rx_next;
        struct sk_buff *skb = NULL;
+       u16 count = (status & GMR_FS_LEN) >> 16;
+
+#ifdef SKY2_VLAN_TAG_USED
+       /* Account for vlan tag */
+       if (sky2->vlgrp && (status & GMR_FS_VLAN))
+               count -= VLAN_HLEN;
+#endif
 
        if (unlikely(netif_msg_rx_status(sky2)))
                printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n",
@@ -2106,6 +2124,10 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
        if (!(status & GMR_FS_RX_OK))
                goto resubmit;
 
+       /* if length reported by DMA does not match PHY, packet was truncated */
+       if (length != count)
+               goto len_mismatch;
+
        if (length < copybreak)
                skb = receive_copy(sky2, re, length);
        else
@@ -2115,6 +2137,15 @@ resubmit:
 
        return skb;
 
+len_mismatch:
+       /* Truncation of overlength packets
+          causes PHY length to not match MAC length */
+       ++sky2->net_stats.rx_length_errors;
+       if (netif_msg_rx_err(sky2) && net_ratelimit())
+               pr_info(PFX "%s: rx length mismatch: length %d status %#x\n",
+                       dev->name, length, status);
+       goto resubmit;
+
 error:
        ++sky2->net_stats.rx_errors;
        if (status & GMR_FS_RX_FF_OV) {
@@ -2417,25 +2448,20 @@ static void sky2_le_error(struct sky2_hw *hw, unsigned port,
        sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK);
 }
 
-/* If idle then force a fake soft NAPI poll once a second
- * to work around cases where sharing an edge triggered interrupt.
- */
-static inline void sky2_idle_start(struct sky2_hw *hw)
-{
-       if (idle_timeout > 0)
-               mod_timer(&hw->idle_timer,
-                         jiffies + msecs_to_jiffies(idle_timeout));
-}
-
-static void sky2_idle(unsigned long arg)
+/* Check for lost IRQ once a second */
+static void sky2_watchdog(unsigned long arg)
 {
        struct sky2_hw *hw = (struct sky2_hw *) arg;
-       struct net_device *dev = hw->dev[0];
 
-       if (__netif_rx_schedule_prep(dev))
-               __netif_rx_schedule(dev);
+       if (sky2_read32(hw, B0_ISRC)) {
+               struct net_device *dev = hw->dev[0];
 
-       mod_timer(&hw->idle_timer, jiffies + msecs_to_jiffies(idle_timeout));
+               if (__netif_rx_schedule_prep(dev))
+                       __netif_rx_schedule(dev);
+       }
+
+       if (hw->active > 0)
+               mod_timer(&hw->watchdog_timer, round_jiffies(jiffies + HZ));
 }
 
 /* Hardware/software error handling */
@@ -2723,10 +2749,6 @@ static void sky2_restart(struct work_struct *work)
        struct net_device *dev;
        int i, err;
 
-       dev_dbg(&hw->pdev->dev, "restarting\n");
-
-       del_timer_sync(&hw->idle_timer);
-
        rtnl_lock();
        sky2_write32(hw, B0_IMSK, 0);
        sky2_read32(hw, B0_IMSK);
@@ -2755,8 +2777,6 @@ static void sky2_restart(struct work_struct *work)
                }
        }
 
-       sky2_idle_start(hw);
-
        rtnl_unlock();
 }
 
@@ -2894,8 +2914,10 @@ 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))
+       if (netif_running(dev)) {
                sky2_phy_reinit(sky2);
+               sky2_set_multicast(dev);
+       }
 
        return 0;
 }
@@ -2988,6 +3010,7 @@ static int sky2_nway_reset(struct net_device *dev)
                return -EINVAL;
 
        sky2_phy_reinit(sky2);
+       sky2_set_multicast(dev);
 
        return 0;
 }
@@ -3429,37 +3452,123 @@ static int sky2_set_tso(struct net_device *dev, u32 data)
        return ethtool_op_set_tso(dev, data);
 }
 
+static int sky2_get_eeprom_len(struct net_device *dev)
+{
+       struct sky2_port *sky2 = netdev_priv(dev);
+       u16 reg2;
+
+       reg2 = sky2_pci_read32(sky2->hw, PCI_DEV_REG2);
+       return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
+}
+
+static u32 sky2_vpd_read(struct sky2_hw *hw, int cap, u16 offset)
+{
+       sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
+
+       while (!(sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F))
+                       cpu_relax();
+       return sky2_pci_read32(hw, cap + PCI_VPD_DATA);
+}
+
+static void sky2_vpd_write(struct sky2_hw *hw, int cap, u16 offset, u32 val)
+{
+       sky2_pci_write32(hw, cap + PCI_VPD_DATA, val);
+       sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
+       do {
+               cpu_relax();
+       } while (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F);
+}
+
+static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
+                          u8 *data)
+{
+       struct sky2_port *sky2 = netdev_priv(dev);
+       int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
+       int length = eeprom->len;
+       u16 offset = eeprom->offset;
+
+       if (!cap)
+               return -EINVAL;
+
+       eeprom->magic = SKY2_EEPROM_MAGIC;
+
+       while (length > 0) {
+               u32 val = sky2_vpd_read(sky2->hw, cap, offset);
+               int n = min_t(int, length, sizeof(val));
+
+               memcpy(data, &val, n);
+               length -= n;
+               data += n;
+               offset += n;
+       }
+       return 0;
+}
+
+static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
+                          u8 *data)
+{
+       struct sky2_port *sky2 = netdev_priv(dev);
+       int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
+       int length = eeprom->len;
+       u16 offset = eeprom->offset;
+
+       if (!cap)
+               return -EINVAL;
+
+       if (eeprom->magic != SKY2_EEPROM_MAGIC)
+               return -EINVAL;
+
+       while (length > 0) {
+               u32 val;
+               int n = min_t(int, length, sizeof(val));
+
+               if (n < sizeof(val))
+                       val = sky2_vpd_read(sky2->hw, cap, offset);
+               memcpy(&val, data, n);
+
+               sky2_vpd_write(sky2->hw, cap, offset, val);
+
+               length -= n;
+               data += n;
+               offset += n;
+       }
+       return 0;
+}
+
+
 static const struct ethtool_ops sky2_ethtool_ops = {
-       .get_settings = sky2_get_settings,
-       .set_settings = sky2_set_settings,
-       .get_drvinfo  = sky2_get_drvinfo,
-       .get_wol      = sky2_get_wol,
-       .set_wol      = sky2_set_wol,
-       .get_msglevel = sky2_get_msglevel,
-       .set_msglevel = sky2_set_msglevel,
-       .nway_reset   = sky2_nway_reset,
-       .get_regs_len = sky2_get_regs_len,
-       .get_regs = sky2_get_regs,
-       .get_link = ethtool_op_get_link,
-       .get_sg = ethtool_op_get_sg,
-       .set_sg = ethtool_op_set_sg,
-       .get_tx_csum = ethtool_op_get_tx_csum,
-       .set_tx_csum = sky2_set_tx_csum,
-       .get_tso = ethtool_op_get_tso,
-       .set_tso = sky2_set_tso,
-       .get_rx_csum = sky2_get_rx_csum,
-       .set_rx_csum = sky2_set_rx_csum,
-       .get_strings = sky2_get_strings,
-       .get_coalesce = sky2_get_coalesce,
-       .set_coalesce = sky2_set_coalesce,
-       .get_ringparam = sky2_get_ringparam,
-       .set_ringparam = sky2_set_ringparam,
+       .get_settings   = sky2_get_settings,
+       .set_settings   = sky2_set_settings,
+       .get_drvinfo    = sky2_get_drvinfo,
+       .get_wol        = sky2_get_wol,
+       .set_wol        = sky2_set_wol,
+       .get_msglevel   = sky2_get_msglevel,
+       .set_msglevel   = sky2_set_msglevel,
+       .nway_reset     = sky2_nway_reset,
+       .get_regs_len   = sky2_get_regs_len,
+       .get_regs       = sky2_get_regs,
+       .get_link       = ethtool_op_get_link,
+       .get_eeprom_len = sky2_get_eeprom_len,
+       .get_eeprom     = sky2_get_eeprom,
+       .set_eeprom     = sky2_set_eeprom,
+       .get_sg         = ethtool_op_get_sg,
+       .set_sg         = ethtool_op_set_sg,
+       .get_tx_csum    = ethtool_op_get_tx_csum,
+       .set_tx_csum    = sky2_set_tx_csum,
+       .get_tso        = ethtool_op_get_tso,
+       .set_tso        = sky2_set_tso,
+       .get_rx_csum    = sky2_get_rx_csum,
+       .set_rx_csum    = sky2_set_rx_csum,
+       .get_strings    = sky2_get_strings,
+       .get_coalesce   = sky2_get_coalesce,
+       .set_coalesce   = sky2_set_coalesce,
+       .get_ringparam  = sky2_get_ringparam,
+       .set_ringparam  = sky2_set_ringparam,
        .get_pauseparam = sky2_get_pauseparam,
        .set_pauseparam = sky2_set_pauseparam,
-       .phys_id = sky2_phys_id,
+       .phys_id        = sky2_phys_id,
        .get_stats_count = sky2_get_stats_count,
        .get_ethtool_stats = sky2_get_ethtool_stats,
-       .get_perm_addr  = ethtool_op_get_perm_addr,
 };
 
 #ifdef CONFIG_SKY2_DEBUG
@@ -3937,11 +4046,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
                        sky2_show_addr(dev1);
        }
 
-       setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
+       setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);
        INIT_WORK(&hw->restart_work, sky2_restart);
 
-       sky2_idle_start(hw);
-
        pci_set_drvdata(pdev, hw);
 
        return 0;
@@ -3976,7 +4083,7 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
        if (!hw)
                return;
 
-       del_timer_sync(&hw->idle_timer);
+       del_timer_sync(&hw->watchdog_timer);
 
        flush_scheduled_work();
 
@@ -4020,7 +4127,6 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
        if (!hw)
                return 0;
 
-       del_timer_sync(&hw->idle_timer);
        netif_poll_disable(hw->dev[0]);
 
        for (i = 0; i < hw->ports; i++) {
@@ -4082,11 +4188,13 @@ static int sky2_resume(struct pci_dev *pdev)
                                dev_close(dev);
                                goto out;
                        }
+
+                       sky2_set_multicast(dev);
                }
        }
 
        netif_poll_enable(hw->dev[0]);
-       sky2_idle_start(hw);
+
        return 0;
 out:
        dev_err(&pdev->dev, "resume failed (%d)\n", err);
@@ -4103,7 +4211,6 @@ static void sky2_shutdown(struct pci_dev *pdev)
        if (!hw)
                return;
 
-       del_timer_sync(&hw->idle_timer);
        netif_poll_disable(hw->dev[0]);
 
        for (i = 0; i < hw->ports; i++) {