tg3: Turn off multiple DMA reads for 5717
[safe/jmp/linux-2.6] / drivers / net / pasemi_mac.c
index c50f0f4..d44d4a2 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/dmaengine.h>
 #include <linux/delay.h>
 #include <linux/netdevice.h>
+#include <linux/of_mdio.h>
 #include <linux/etherdevice.h>
 #include <asm/dma-mapping.h>
 #include <linux/in.h>
@@ -277,7 +278,7 @@ static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
        *tcph = tcp_hdr(skb);
 
        /* check if ip header and tcp header are complete */
-       if (iph->tot_len < ip_len + tcp_hdrlen(skb))
+       if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
                return -1;
 
        *hdr_flags = LRO_IPV4 | LRO_TCP;
@@ -404,6 +405,7 @@ static void pasemi_mac_free_csring(struct pasemi_mac_csring *csring)
        pasemi_dma_free_flag(csring->events[1]);
        pasemi_dma_free_ring(&csring->chan);
        pasemi_dma_free_chan(&csring->chan);
+       pasemi_dma_free_fun(csring->fun);
 }
 
 static int pasemi_mac_setup_rx_resources(const struct net_device *dev)
@@ -649,7 +651,7 @@ static void pasemi_mac_replenish_rx_ring(const struct net_device *dev,
                                     mac->bufsz - LOCAL_SKB_ALIGN,
                                     PCI_DMA_FROMDEVICE);
 
-               if (unlikely(dma_mapping_error(dma))) {
+               if (unlikely(pci_dma_mapping_error(mac->dma_pdev, dma))) {
                        dev_kfree_skb_irq(info->skb);
                        break;
                }
@@ -711,7 +713,7 @@ static inline void pasemi_mac_rx_error(const struct pasemi_mac *mac,
        rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
        ccmdsta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(chan->chno));
 
-       printk(KERN_ERR "pasemi_mac: rx error. macrx %016lx, rx status %lx\n",
+       printk(KERN_ERR "pasemi_mac: rx error. macrx %016llx, rx status %llx\n",
                macrx, *chan->status);
 
        printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n",
@@ -729,8 +731,8 @@ static inline void pasemi_mac_tx_error(const struct pasemi_mac *mac,
 
        cmdsta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(chan->chno));
 
-       printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016lx, "\
-               "tx status 0x%016lx\n", mactx, *chan->status);
+       printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016llx, "\
+               "tx status 0x%016llx\n", mactx, *chan->status);
 
        printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta);
 }
@@ -953,7 +955,6 @@ static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
 {
        const struct pasemi_mac_rxring *rxring = data;
        struct pasemi_mac *mac = rxring->mac;
-       struct net_device *dev = mac->netdev;
        const struct pasemi_dmachan *chan = &rxring->chan;
        unsigned int reg;
 
@@ -970,7 +971,7 @@ static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
        if (*chan->status & PAS_STATUS_ERROR)
                reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
 
-       netif_rx_schedule(dev, &mac->napi);
+       napi_schedule(&mac->napi);
 
        write_iob_reg(PAS_IOB_DMA_RXCH_RESET(chan->chno), reg);
 
@@ -1010,7 +1011,7 @@ static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
 
        mod_timer(&txring->clean_timer, jiffies + (TX_CLEAN_INTERVAL)*2);
 
-       netif_rx_schedule(mac->netdev, &mac->napi);
+       napi_schedule(&mac->napi);
 
        if (reg)
                write_iob_reg(PAS_IOB_DMA_TXCH_RESET(chan->chno), reg);
@@ -1086,33 +1087,17 @@ static int pasemi_mac_phy_init(struct net_device *dev)
        struct pasemi_mac *mac = netdev_priv(dev);
        struct device_node *dn, *phy_dn;
        struct phy_device *phydev;
-       unsigned int phy_id;
-       const phandle *ph;
-       const unsigned int *prop;
-       struct resource r;
-       int ret;
 
        dn = pci_device_to_OF_node(mac->pdev);
-       ph = of_get_property(dn, "phy-handle", NULL);
-       if (!ph)
-               return -ENODEV;
-       phy_dn = of_find_node_by_phandle(*ph);
-
-       prop = of_get_property(phy_dn, "reg", NULL);
-       ret = of_address_to_resource(phy_dn->parent, 0, &r);
-       if (ret)
-               goto err;
-
-       phy_id = *prop;
-       snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
-
+       phy_dn = of_parse_phandle(dn, "phy-handle", 0);
        of_node_put(phy_dn);
 
        mac->link = 0;
        mac->speed = 0;
        mac->duplex = -1;
 
-       phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
+       phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
+                               PHY_INTERFACE_MODE_SGMII);
 
        if (IS_ERR(phydev)) {
                printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
@@ -1122,10 +1107,6 @@ static int pasemi_mac_phy_init(struct net_device *dev)
        mac->phydev = phydev;
 
        return 0;
-
-err:
-       of_node_put(phy_dn);
-       return -ENODEV;
 }
 
 
@@ -1150,7 +1131,10 @@ static int pasemi_mac_open(struct net_device *dev)
        if (!mac->tx)
                goto out_tx_ring;
 
-       if (dev->mtu > 1500) {
+       /* We might already have allocated rings in case mtu was changed
+        * before interface was brought up.
+        */
+       if (dev->mtu > 1500 && !mac->num_cs) {
                pasemi_mac_setup_csrings(mac);
                if (!mac->num_cs)
                        goto out_tx_ring;
@@ -1232,7 +1216,7 @@ static int pasemi_mac_open(struct net_device *dev)
        snprintf(mac->tx_irq_name, sizeof(mac->tx_irq_name), "%s tx",
                 dev->name);
 
-       ret = request_irq(mac->tx->chan.irq, &pasemi_mac_tx_intr, IRQF_DISABLED,
+       ret = request_irq(mac->tx->chan.irq, pasemi_mac_tx_intr, IRQF_DISABLED,
                          mac->tx_irq_name, mac->tx);
        if (ret) {
                dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
@@ -1243,7 +1227,7 @@ static int pasemi_mac_open(struct net_device *dev)
        snprintf(mac->rx_irq_name, sizeof(mac->rx_irq_name), "%s rx",
                 dev->name);
 
-       ret = request_irq(mac->rx->chan.irq, &pasemi_mac_rx_intr, IRQF_DISABLED,
+       ret = request_irq(mac->rx->chan.irq, pasemi_mac_rx_intr, IRQF_DISABLED,
                          mac->rx_irq_name, mac->rx);
        if (ret) {
                dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
@@ -1388,8 +1372,12 @@ static int pasemi_mac_close(struct net_device *dev)
        free_irq(mac->tx->chan.irq, mac->tx);
        free_irq(mac->rx->chan.irq, mac->rx);
 
-       for (i = 0; i < mac->num_cs; i++)
+       for (i = 0; i < mac->num_cs; i++) {
                pasemi_mac_free_csring(mac->cs[i]);
+               mac->cs[i] = NULL;
+       }
+
+       mac->num_cs = 0;
 
        /* Free resources */
        pasemi_mac_free_rx_resources(mac);
@@ -1511,7 +1499,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
        map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
                                PCI_DMA_TODEVICE);
        map_size[0] = skb_headlen(skb);
-       if (dma_mapping_error(map[0]))
+       if (pci_dma_mapping_error(mac->dma_pdev, map[0]))
                goto out_err_nolock;
 
        for (i = 0; i < nfrags; i++) {
@@ -1521,7 +1509,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
                                        frag->page_offset, frag->size,
                                        PCI_DMA_TODEVICE);
                map_size[i+1] = frag->size;
-               if (dma_mapping_error(map[i+1])) {
+               if (pci_dma_mapping_error(mac->dma_pdev, map[i+1])) {
                        nfrags = i;
                        goto out_err_nolock;
                }
@@ -1625,14 +1613,13 @@ static void pasemi_mac_set_rx_mode(struct net_device *dev)
 static int pasemi_mac_poll(struct napi_struct *napi, int budget)
 {
        struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
-       struct net_device *dev = mac->netdev;
        int pkts;
 
        pasemi_mac_clean_tx(tx_ring(mac));
        pkts = pasemi_mac_clean_rx(rx_ring(mac), budget);
        if (pkts < budget) {
                /* all done, no more packets present */
-               netif_rx_complete(dev, napi);
+               napi_complete(napi);
 
                pasemi_mac_restart_rx_intr(mac);
                pasemi_mac_restart_tx_intr(mac);
@@ -1640,6 +1627,26 @@ static int pasemi_mac_poll(struct napi_struct *napi, int budget)
        return pkts;
 }
 
+#ifdef CONFIG_NET_POLL_CONTROLLER
+/*
+ * Polling 'interrupt' - used by things like netconsole to send skbs
+ * without having to re-enable interrupts. It's not called while
+ * the interrupt routine is executing.
+ */
+static void pasemi_mac_netpoll(struct net_device *dev)
+{
+       const struct pasemi_mac *mac = netdev_priv(dev);
+
+       disable_irq(mac->tx->chan.irq);
+       pasemi_mac_tx_intr(mac->tx->chan.irq, mac->tx);
+       enable_irq(mac->tx->chan.irq);
+
+       disable_irq(mac->rx->chan.irq);
+       pasemi_mac_rx_intr(mac->rx->chan.irq, mac->rx);
+       enable_irq(mac->rx->chan.irq);
+}
+#endif
+
 static int pasemi_mac_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct pasemi_mac *mac = netdev_priv(dev);
@@ -1708,13 +1715,25 @@ out:
        return ret;
 }
 
+static const struct net_device_ops pasemi_netdev_ops = {
+       .ndo_open               = pasemi_mac_open,
+       .ndo_stop               = pasemi_mac_close,
+       .ndo_start_xmit         = pasemi_mac_start_tx,
+       .ndo_set_multicast_list = pasemi_mac_set_rx_mode,
+       .ndo_set_mac_address    = pasemi_mac_set_mac_addr,
+       .ndo_change_mtu         = pasemi_mac_change_mtu,
+       .ndo_validate_addr      = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = pasemi_mac_netpoll,
+#endif
+};
+
 static int __devinit
 pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        struct net_device *dev;
        struct pasemi_mac *mac;
-       int err;
-       DECLARE_MAC_BUF(mac_buf);
+       int err, ret;
 
        err = pci_enable_device(pdev);
        if (err)
@@ -1772,12 +1791,13 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
        memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
 
-       mac->dma_if = mac_to_intf(mac);
-       if (mac->dma_if < 0) {
+       ret = mac_to_intf(mac);
+       if (ret < 0) {
                dev_err(&mac->pdev->dev, "Can't map DMA interface\n");
                err = -ENODEV;
                goto out;
        }
+       mac->dma_if = ret;
 
        switch (pdev->device) {
        case 0xa005:
@@ -1791,16 +1811,11 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto out;
        }
 
-       dev->open = pasemi_mac_open;
-       dev->stop = pasemi_mac_close;
-       dev->hard_start_xmit = pasemi_mac_start_tx;
-       dev->set_multicast_list = pasemi_mac_set_rx_mode;
-       dev->set_mac_address = pasemi_mac_set_mac_addr;
+       dev->netdev_ops = &pasemi_netdev_ops;
        dev->mtu = PE_DEF_MTU;
        /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
        mac->bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
 
-       dev->change_mtu = pasemi_mac_change_mtu;
        dev->ethtool_ops = &pasemi_mac_ethtool_ops;
 
        if (err)
@@ -1818,9 +1833,9 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                        err);
                goto out;
        } else if netif_msg_probe(mac)
-               printk(KERN_INFO "%s: PA Semi %s: intf %d, hw addr %s\n",
+               printk(KERN_INFO "%s: PA Semi %s: intf %d, hw addr %pM\n",
                       dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
-                      mac->dma_if, print_mac(mac_buf, dev->dev_addr));
+                      mac->dma_if, dev->dev_addr);
 
        return err;
 
@@ -1860,7 +1875,7 @@ static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
        free_netdev(netdev);
 }
 
-static struct pci_device_id pasemi_mac_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(pasemi_mac_pci_tbl) = {
        { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
        { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
        { },