p54: Move TX/RX code
[safe/jmp/linux-2.6] / drivers / net / ioc3-eth.c
index 0834ef0..8ec15ab 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Driver for SGI's IOC3 based Ethernet cards as found in the PCI card.
  *
- * Copyright (C) 1999, 2000, 2001, 2003 Ralf Baechle
+ * Copyright (C) 1999, 2000, 01, 03, 06 Ralf Baechle
  * Copyright (C) 1995, 1999, 2000, 2001 by Silicon Graphics, Inc.
  *
  * References:
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/sn/types.h>
-#include <asm/sn/sn0/addrs.h>
-#include <asm/sn/sn0/hubni.h>
-#include <asm/sn/sn0/hubio.h>
-#include <asm/sn/klconfig.h>
 #include <asm/sn/ioc3.h>
-#include <asm/sn/sn0/ip27.h>
 #include <asm/pci/bridge.h>
 
 /*
@@ -95,6 +90,9 @@ struct ioc3_private {
        u32 emcr, ehar_h, ehar_l;
        spinlock_t ioc3_lock;
        struct mii_if_info mii;
+       unsigned long flags;
+#define IOC3_FLAG_RX_CHECKSUMS 1
+
        struct pci_dev *pdev;
 
        /* Members used by autonegotiation  */
@@ -392,11 +390,8 @@ static int nic_init(struct ioc3 *ioc3)
        }
 
        printk("Found %s NIC", type);
-       if (type != unknown) {
-               printk (" registration number %02x:%02x:%02x:%02x:%02x:%02x,"
-                       " CRC %02x", serial[0], serial[1], serial[2],
-                       serial[3], serial[4], serial[5], crc);
-       }
+       if (type != unknown)
+               printk (" registration number %pM, CRC %02x", serial, crc);
        printk(".\n");
 
        return 0;
@@ -445,18 +440,9 @@ static void ioc3_get_eaddr_nic(struct ioc3_private *ip)
  */
 static void ioc3_get_eaddr(struct ioc3_private *ip)
 {
-       int i;
-
-
        ioc3_get_eaddr_nic(ip);
 
-       printk("Ethernet address is ");
-       for (i = 0; i < 6; i++) {
-               printk("%02x", priv_netdev(ip)->dev_addr[i]);
-               if (i < 5)
-                       printk(":");
-       }
-       printk(".\n");
+       printk("Ethernet address is %pM.\n", priv_netdev(ip)->dev_addr);
 }
 
 static void __ioc3_set_mac_address(struct net_device *dev)
@@ -521,8 +507,6 @@ static struct net_device_stats *ioc3_get_stats(struct net_device *dev)
        return &ip->stats;
 }
 
-#ifdef CONFIG_SGI_IOC3_ETH_HW_RX_CSUM
-
 static void ioc3_tcpudp_checksum(struct sk_buff *skb, uint32_t hwsum, int len)
 {
        struct ethhdr *eh = eth_hdr(skb);
@@ -546,7 +530,7 @@ static void ioc3_tcpudp_checksum(struct sk_buff *skb, uint32_t hwsum, int len)
         *   case where the checksum is right the higher layers will still
         *   drop the packet as appropriate.
         */
-       if (eh->h_proto != ntohs(ETH_P_IP))
+       if (eh->h_proto != htons(ETH_P_IP))
                return;
 
        ih = (struct iphdr *) ((char *)eh + ETH_HLEN);
@@ -590,7 +574,6 @@ static void ioc3_tcpudp_checksum(struct sk_buff *skb, uint32_t hwsum, int len)
        if (csum == 0xffff)
                skb->ip_summed = CHECKSUM_UNNECESSARY;
 }
-#endif /* CONFIG_SGI_IOC3_ETH_HW_RX_CSUM */
 
 static inline void ioc3_rx(struct ioc3_private *ip)
 {
@@ -625,9 +608,9 @@ static inline void ioc3_rx(struct ioc3_private *ip)
                                goto next;
                        }
 
-#ifdef CONFIG_SGI_IOC3_ETH_HW_RX_CSUM
-                       ioc3_tcpudp_checksum(skb, w0 & ERXBUF_IPCKSUM_MASK,len);
-#endif
+                       if (likely(ip->flags & IOC3_FLAG_RX_CHECKSUMS))
+                               ioc3_tcpudp_checksum(skb,
+                                       w0 & ERXBUF_IPCKSUM_MASK, len);
 
                        netif_rx(skb);
 
@@ -638,7 +621,6 @@ static inline void ioc3_rx(struct ioc3_private *ip)
                        rxb = (struct ioc3_erxbuf *) new_skb->data;
                        skb_reserve(new_skb, RX_OFFSET);
 
-                       priv_netdev(ip)->last_rx = jiffies;
                        ip->stats.rx_packets++;         /* Statistics */
                        ip->stats.rx_bytes += len;
                } else {
@@ -1232,7 +1214,21 @@ static void __devinit ioc3_serial_probe(struct pci_dev *pdev, struct ioc3 *ioc3)
 }
 #endif
 
-static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+static const struct net_device_ops ioc3_netdev_ops = {
+       .ndo_open               = ioc3_open,
+       .ndo_stop               = ioc3_close,
+       .ndo_start_xmit         = ioc3_start_xmit,
+       .ndo_tx_timeout         = ioc3_timeout,
+       .ndo_get_stats          = ioc3_get_stats,
+       .ndo_set_multicast_list = ioc3_set_multicast_list,
+       .ndo_do_ioctl           = ioc3_ioctl,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = ioc3_set_mac_address,
+       .ndo_change_mtu         = eth_change_mtu,
+};
+
+static int __devinit ioc3_probe(struct pci_dev *pdev,
+       const struct pci_device_id *ent)
 {
        unsigned int sw_physid1, sw_physid2;
        struct net_device *dev = NULL;
@@ -1243,17 +1239,17 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        int err, pci_using_dac;
 
        /* Configure DMA attributes. */
-       err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
+       err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
        if (!err) {
                pci_using_dac = 1;
-               err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
+               err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
                if (err < 0) {
                        printk(KERN_ERR "%s: Unable to obtain 64 bit DMA "
                               "for consistent allocations\n", pci_name(pdev));
                        goto out;
                }
        } else {
-               err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+               err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (err) {
                        printk(KERN_ERR "%s: No usable DMA configuration, "
                               "aborting.\n", pci_name(pdev));
@@ -1278,7 +1274,6 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (err)
                goto out_free;
 
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
 
        ip = netdev_priv(dev);
@@ -1328,19 +1323,10 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        ioc3_get_eaddr(ip);
 
        /* The IOC3-specific entries in the device structure. */
-       dev->open               = ioc3_open;
-       dev->hard_start_xmit    = ioc3_start_xmit;
-       dev->tx_timeout         = ioc3_timeout;
        dev->watchdog_timeo     = 5 * HZ;
-       dev->stop               = ioc3_close;
-       dev->get_stats          = ioc3_get_stats;
-       dev->do_ioctl           = ioc3_ioctl;
-       dev->set_multicast_list = ioc3_set_multicast_list;
-       dev->set_mac_address    = ioc3_set_mac_address;
+       dev->netdev_ops         = &ioc3_netdev_ops;
        dev->ethtool_ops        = &ioc3_ethtool_ops;
-#ifdef CONFIG_SGI_IOC3_ETH_HW_TX_CSUM
        dev->features           = NETIF_F_IP_CSUM;
-#endif
 
        sw_physid1 = ioc3_mdio_read(dev, ip->mii.phy_id, MII_PHYSID1);
        sw_physid2 = ioc3_mdio_read(dev, ip->mii.phy_id, MII_PHYSID2);
@@ -1430,7 +1416,6 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
        uint32_t w0 = 0;
        int produce;
 
-#ifdef CONFIG_SGI_IOC3_ETH_HW_TX_CSUM
        /*
         * IOC3 has a fairly simple minded checksumming hardware which simply
         * adds up the 1's complement checksum for the entire packet and
@@ -1478,7 +1463,6 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
                w0 = ETXD_DOCHECKSUM | (csoff << ETXD_CHKOFF_SHIFT);
        }
-#endif /* CONFIG_SGI_IOC3_ETH_HW_TX_CSUM */
 
        spin_lock_irq(&ip->ioc3_lock);
 
@@ -1531,7 +1515,7 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        spin_unlock_irq(&ip->ioc3_lock);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void ioc3_timeout(struct net_device *dev)
@@ -1633,12 +1617,37 @@ static u32 ioc3_get_link(struct net_device *dev)
        return rc;
 }
 
+static u32 ioc3_get_rx_csum(struct net_device *dev)
+{
+       struct ioc3_private *ip = netdev_priv(dev);
+
+       return ip->flags & IOC3_FLAG_RX_CHECKSUMS;
+}
+
+static int ioc3_set_rx_csum(struct net_device *dev, u32 data)
+{
+       struct ioc3_private *ip = netdev_priv(dev);
+
+       spin_lock_bh(&ip->ioc3_lock);
+       if (data)
+               ip->flags |= IOC3_FLAG_RX_CHECKSUMS;
+       else
+               ip->flags &= ~IOC3_FLAG_RX_CHECKSUMS;
+       spin_unlock_bh(&ip->ioc3_lock);
+
+       return 0;
+}
+
 static const struct ethtool_ops ioc3_ethtool_ops = {
        .get_drvinfo            = ioc3_get_drvinfo,
        .get_settings           = ioc3_get_settings,
        .set_settings           = ioc3_set_settings,
        .nway_reset             = ioc3_nway_reset,
        .get_link               = ioc3_get_link,
+       .get_rx_csum            = ioc3_get_rx_csum,
+       .set_rx_csum            = ioc3_set_rx_csum,
+       .get_tx_csum            = ethtool_op_get_tx_csum,
+       .set_tx_csum            = ethtool_op_set_tx_csum
 };
 
 static int ioc3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)