powerpc: Change u64/s64 to a long long integer type
[safe/jmp/linux-2.6] / drivers / net / pasemi_mac.c
index 5ee7e4a..d0349e7 100644 (file)
  * - Multiqueue RX/TX
  */
 
-
-/* Must be a power of two */
-#define RX_RING_SIZE 2048
-#define TX_RING_SIZE 4096
-#define CS_RING_SIZE (TX_RING_SIZE*2)
-
 #define LRO_MAX_AGGR 64
 
 #define PE_MIN_MTU     64
         NETIF_MSG_RX_ERR       | \
         NETIF_MSG_TX_ERR)
 
-#define TX_DESC(tx, num)       ((tx)->chan.ring_virt[(num) & (TX_RING_SIZE-1)])
-#define TX_DESC_INFO(tx, num)  ((tx)->ring_info[(num) & (TX_RING_SIZE-1)])
-#define RX_DESC(rx, num)       ((rx)->chan.ring_virt[(num) & (RX_RING_SIZE-1)])
-#define RX_DESC_INFO(rx, num)  ((rx)->ring_info[(num) & (RX_RING_SIZE-1)])
-#define RX_BUFF(rx, num)       ((rx)->buffers[(num) & (RX_RING_SIZE-1)])
-#define CS_DESC(cs, num)       ((cs)->chan.ring_virt[(num) & (CS_RING_SIZE-1)])
-
-#define RING_USED(ring)                (((ring)->next_to_fill - (ring)->next_to_clean) \
-                                & ((ring)->size - 1))
-#define RING_AVAIL(ring)       ((ring->size) - RING_USED(ring))
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
 MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
@@ -96,6 +79,8 @@ static int debug = -1;        /* -1 == use DEFAULT_MSG_ENABLE as value */
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
 
+extern const struct ethtool_ops pasemi_mac_ethtool_ops;
+
 static int translation_enabled(void)
 {
 #if defined(CONFIG_PPC_PASEMI_IOMMU_DMA_FORCE)
@@ -292,7 +277,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;
@@ -419,6 +404,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)
@@ -664,7 +650,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;
                }
@@ -726,7 +712,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",
@@ -744,8 +730,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);
 }
@@ -968,7 +954,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;
 
@@ -985,7 +970,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);
+       netif_rx_schedule(&mac->napi);
 
        write_iob_reg(PAS_IOB_DMA_RXCH_RESET(chan->chno), reg);
 
@@ -1025,7 +1010,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);
+       netif_rx_schedule(&mac->napi);
 
        if (reg)
                write_iob_reg(PAS_IOB_DMA_TXCH_RESET(chan->chno), reg);
@@ -1119,7 +1104,8 @@ static int pasemi_mac_phy_init(struct net_device *dev)
                goto err;
 
        phy_id = *prop;
-       snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
+       snprintf(mac->phy_id, sizeof(mac->phy_id), "%x:%02x",
+                (int)r.start, phy_id);
 
        of_node_put(phy_dn);
 
@@ -1148,7 +1134,7 @@ static int pasemi_mac_open(struct net_device *dev)
 {
        struct pasemi_mac *mac = netdev_priv(dev);
        unsigned int flags;
-       int ret;
+       int i, ret;
 
        flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
                PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
@@ -1165,12 +1151,19 @@ 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;
        }
 
+       /* Zero out rmon counters */
+       for (i = 0; i < 32; i++)
+               write_mac_reg(mac, PAS_MAC_RMON(i), 0);
+
        /* 0x3ff with 33MHz clock is about 31us */
        write_iob_reg(PAS_IOB_DMA_COM_TIMEOUTCFG,
                      PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0x3ff));
@@ -1399,8 +1392,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);
@@ -1522,7 +1519,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++) {
@@ -1532,7 +1529,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;
                }
@@ -1636,14 +1633,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);
+               netif_rx_complete(napi);
 
                pasemi_mac_restart_rx_intr(mac);
                pasemi_mac_restart_tx_intr(mac);
@@ -1651,6 +1647,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);
@@ -1725,7 +1741,6 @@ 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);
 
        err = pci_enable_device(pdev);
        if (err)
@@ -1810,8 +1825,12 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        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;
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       dev->poll_controller = pasemi_mac_netpoll;
+#endif
 
        dev->change_mtu = pasemi_mac_change_mtu;
+       dev->ethtool_ops = &pasemi_mac_ethtool_ops;
 
        if (err)
                goto out;
@@ -1828,9 +1847,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;