[PATCH] sky2: add PCI for 88ec033
[safe/jmp/linux-2.6] / drivers / net / sky2.c
index b8f2021..a0563e0 100644 (file)
@@ -10,8 +10,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation; either version 2 of the License.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -50,7 +49,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.9"
+#define DRV_VERSION            "1.10"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -105,6 +104,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) },
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },    /* DGE-560T */
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) },    /* DGE-550SX */
+       { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) },    /* DGE-560SX */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) },
@@ -117,6 +117,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4351) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4352) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) },
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) },
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) },
@@ -677,17 +678,15 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
        /* Flush Rx MAC FIFO on any flow control or error */
        sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
 
-       /* Set threshold to 0xa (64 bytes)
-        *  ASF disabled so no need to do WA dev #4.30
-        */
-       sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
+       /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug  */
+       sky2_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF+1);
 
        /* Configure Tx MAC FIFO */
        sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
        sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
 
        if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
-               sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 512/8);
+               sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8);
                sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8);
                if (hw->dev[port]->mtu > ETH_DATA_LEN) {
                        /* set Tx GMAC FIFO Almost Empty Threshold */
@@ -699,16 +698,10 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 
 }
 
-/* Assign Ram Buffer allocation.
- * start and end are in units of 4k bytes
- * ram registers are in units of 64bit words
- */
-static void sky2_ramset(struct sky2_hw *hw, u16 q, u8 startk, u8 endk)
+/* Assign Ram Buffer allocation in units of 64bit (8 bytes) */
+static void sky2_ramset(struct sky2_hw *hw, u16 q, u32 start, u32 end)
 {
-       u32 start, end;
-
-       start = startk * 4096/8;
-       end = (endk * 4096/8) - 1;
+       pr_debug(PFX "q %d %#x %#x\n", q, start, end);
 
        sky2_write8(hw, RB_ADDR(q, RB_CTRL), RB_RST_CLR);
        sky2_write32(hw, RB_ADDR(q, RB_START), start);
@@ -717,7 +710,7 @@ static void sky2_ramset(struct sky2_hw *hw, u16 q, u8 startk, u8 endk)
        sky2_write32(hw, RB_ADDR(q, RB_RP), start);
 
        if (q == Q_R1 || q == Q_R2) {
-               u32 space = (endk - startk) * 4096/8;
+               u32 space = end - start + 1;
                u32 tp = space - space/4;
 
                /* On receive queue's set the thresholds
@@ -1067,7 +1060,8 @@ static int sky2_rx_start(struct sky2_port *sky2)
        sky2->rx_put = sky2->rx_next = 0;
        sky2_qset(hw, rxq);
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev >= 2) {
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
+           (hw->chip_rev == CHIP_REV_YU_EC_U_A1 || hw->chip_rev == CHIP_REV_YU_EC_U_B0)) {
                /* MAC Rx RAM Read is controlled by hardware */
                sky2_write32(hw, Q_ADDR(rxq, Q_F), F_M_RX_RAM_DIS);
        }
@@ -1199,19 +1193,16 @@ static int sky2_up(struct net_device *dev)
 
        sky2_mac_init(hw, port);
 
-       /* Determine available ram buffer space (in 4K blocks).
-        * Note: not sure about the FE setting below yet
-        */
-       if (hw->chip_id == CHIP_ID_YUKON_FE)
-               ramsize = 4;
-       else
-               ramsize = sky2_read8(hw, B2_E_0);
+       /* Determine available ram buffer space in qwords.  */
+       ramsize = sky2_read8(hw, B2_E_0) * 4096/8;
 
-       /* Give transmitter one third (rounded up) */
-       rxspace = ramsize - (ramsize + 2) / 3;
+       if (ramsize > 6*1024/8)
+               rxspace = ramsize - (ramsize + 2) / 3;
+       else
+               rxspace = ramsize / 2;
 
-       sky2_ramset(hw, rxqaddr[port], 0, rxspace);
-       sky2_ramset(hw, txqaddr[port], rxspace, ramsize);
+       sky2_ramset(hw, rxqaddr[port], 0, rxspace-1);
+       sky2_ramset(hw, txqaddr[port], rxspace, ramsize-1);
 
        /* Make sure SyncQ is disabled */
        sky2_write8(hw, RB_ADDR(port == 0 ? Q_XS1 : Q_XS2, RB_CTRL),
@@ -1360,7 +1351,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
                u32 tcpsum;
 
                tcpsum = offset << 16;          /* sum start */
-               tcpsum |= offset + skb->csum;   /* sum write */
+               tcpsum |= offset + skb->csum_offset;    /* sum write */
 
                ctrl = CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
                if (skb->nh.iph->protocol == IPPROTO_UDP)
@@ -1463,7 +1454,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
                        if (unlikely(netif_msg_tx_done(sky2)))
                                printk(KERN_DEBUG "%s: tx done %u\n",
                                       dev->name, idx);
-                       dev_kfree_skb(re->skb);
+                       dev_kfree_skb_any(re->skb);
                }
 
                le->opcode = 0; /* paranoia */
@@ -1519,7 +1510,7 @@ static int sky2_down(struct net_device *dev)
 
        /* WA for dev. #4.209 */
        if (hw->chip_id == CHIP_ID_YUKON_EC_U
-           && hw->chip_rev == CHIP_REV_YU_EC_U_A1)
+           && (hw->chip_rev == CHIP_REV_YU_EC_U_A1 || hw->chip_rev == CHIP_REV_YU_EC_U_B0))
                sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
                             sky2->speed != SPEED_1000 ?
                             TX_STFW_ENA : TX_STFW_DIS);
@@ -2014,6 +2005,10 @@ oversize:
 
 error:
        ++sky2->net_stats.rx_errors;
+       if (status & GMR_FS_RX_FF_OV) {
+               sky2->net_stats.rx_fifo_errors++;
+               goto resubmit;
+       }
 
        if (netif_msg_rx_err(sky2) && net_ratelimit())
                printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
@@ -2025,8 +2020,6 @@ error:
                sky2->net_stats.rx_frame_errors++;
        if (status & GMR_FS_CRC_ERR)
                sky2->net_stats.rx_crc_errors++;
-       if (status & GMR_FS_RX_FF_OV)
-               sky2->net_stats.rx_fifo_errors++;
 
        goto resubmit;
 }
@@ -2073,7 +2066,7 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                case OP_RXSTAT:
                        skb = sky2_receive(dev, length, status);
                        if (!skb)
-                               break;
+                               goto force_update;
 
                        skb->protocol = eth_type_trans(skb, dev);
                        dev->last_rx = jiffies;
@@ -2089,8 +2082,8 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
 
                        /* Update receiver after 16 frames */
                        if (++buf_write[le->link] == RX_BUF_WRITE) {
-                               sky2_put_idx(hw, rxqaddr[le->link],
-                                            sky2->rx_put);
+force_update:
+                               sky2_put_idx(hw, rxqaddr[le->link], sky2->rx_put);
                                buf_write[le->link] = 0;
                        }
 
@@ -2848,6 +2841,14 @@ static int sky2_set_mac_address(struct net_device *dev, void *p)
        return 0;
 }
 
+static void inline sky2_add_filter(u8 filter[8], const u8 *addr)
+{
+       u32 bit;
+
+       bit = ether_crc(ETH_ALEN, addr) & 63;
+       filter[bit >> 3] |= 1 << (bit & 7);
+}
+
 static void sky2_set_multicast(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
@@ -2856,7 +2857,10 @@ static void sky2_set_multicast(struct net_device *dev)
        struct dev_mc_list *list = dev->mc_list;
        u16 reg;
        u8 filter[8];
+       int rx_pause;
+       static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 };
 
+       rx_pause = (sky2->flow_status == FC_RX || sky2->flow_status == FC_BOTH);
        memset(filter, 0, sizeof(filter));
 
        reg = gma_read16(hw, port, GM_RX_CTRL);
@@ -2864,18 +2868,19 @@ static void sky2_set_multicast(struct net_device *dev)
 
        if (dev->flags & IFF_PROMISC)   /* promiscuous */
                reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
-       else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > 16)     /* all multicast */
+       else if (dev->flags & IFF_ALLMULTI)
                memset(filter, 0xff, sizeof(filter));
-       else if (dev->mc_count == 0)    /* no multicast */
+       else if (dev->mc_count == 0 && !rx_pause)
                reg &= ~GM_RXCR_MCF_ENA;
        else {
                int i;
                reg |= GM_RXCR_MCF_ENA;
 
-               for (i = 0; list && i < dev->mc_count; i++, list = list->next) {
-                       u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f;
-                       filter[bit / 8] |= 1 << (bit % 8);
-               }
+               if (rx_pause)
+                       sky2_add_filter(filter, pause_mc_addr);
+
+               for (i = 0; list && i < dev->mc_count; i++, list = list->next)
+                       sky2_add_filter(filter, list->dmi_addr);
        }
 
        gma_write16(hw, port, GM_MC_ADDR_H1,
@@ -3234,7 +3239,11 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
                dev->poll = sky2_poll;
        dev->weight = NAPI_WEIGHT;
 #ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = sky2_netpoll;
+       /* Network console (only works on port 0)
+        * because netpoll makes assumptions about NAPI
+        */
+       if (port == 0)
+               dev->poll_controller = sky2_netpoll;
 #endif
 
        sky2 = netdev_priv(dev);
@@ -3303,7 +3312,7 @@ static irqreturn_t __devinit sky2_test_intr(int irq, void *dev_id)
                return IRQ_NONE;
 
        if (status & Y2_IS_IRQ_SW) {
-               hw->msi_detected = 1;
+               hw->msi = 1;
                wake_up(&hw->msi_wait);
                sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
        }
@@ -3322,7 +3331,7 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 
        sky2_write32(hw, B0_IMSK, Y2_IS_IRQ_SW);
 
-       err = request_irq(pdev->irq, sky2_test_intr, IRQF_SHARED, DRV_NAME, hw);
+       err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
        if (err) {
                printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
                       pci_name(pdev), pdev->irq);
@@ -3332,9 +3341,9 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
        sky2_write8(hw, B0_CTST, CS_ST_SW_IRQ);
        sky2_read8(hw, B0_CTST);
 
-       wait_event_timeout(hw->msi_wait, hw->msi_detected, HZ/10);
+       wait_event_timeout(hw->msi_wait, hw->msi, HZ/10);
 
-       if (!hw->msi_detected) {
+       if (!hw->msi) {
                /* MSI test failed, go back to INTx mode */
                printk(KERN_INFO PFX "%s: No interrupt generated using MSI, "
                       "switching to INTx mode.\n",
@@ -3467,7 +3476,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
                goto err_out_free_netdev;
        }
 
-       err = request_irq(pdev->irq,  sky2_intr, IRQF_SHARED, dev->name, hw);
+       err = request_irq(pdev->irq,  sky2_intr, hw->msi ? 0 : IRQF_SHARED,
+                         dev->name, hw);
        if (err) {
                printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
                       pci_name(pdev), pdev->irq);
@@ -3497,7 +3507,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
        return 0;
 
 err_out_unregister:
-       pci_disable_msi(pdev);
+       if (hw->msi)
+               pci_disable_msi(pdev);
        unregister_netdev(dev);
 err_out_free_netdev:
        free_netdev(dev);
@@ -3540,7 +3551,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
        sky2_read8(hw, B0_CTST);
 
        free_irq(pdev->irq, hw);
-       pci_disable_msi(pdev);
+       if (hw->msi)
+               pci_disable_msi(pdev);
        pci_free_consistent(pdev, STATUS_LE_BYTES, hw->st_le, hw->st_dma);
        pci_release_regions(pdev);
        pci_disable_device(pdev);