[S390] sclp: undo quiesce handler override on resume
[safe/jmp/linux-2.6] / drivers / net / ioc3-eth.c
index f56b00e..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:
@@ -48,6 +48,7 @@
 #ifdef CONFIG_SERIAL_8250
 #include <linux/serial_core.h>
 #include <linux/serial_8250.h>
+#include <linux/serial_reg.h>
 #endif
 
 #include <linux/netdevice.h>
 #include <net/ip.h>
 
 #include <asm/byteorder.h>
-#include <asm/checksum.h>
 #include <asm/io.h>
 #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  */
@@ -353,13 +351,12 @@ static u64 nic_find(struct ioc3 *ioc3, int *last)
 
 static int nic_init(struct ioc3 *ioc3)
 {
-       const char *type;
+       const char *unknown = "unknown";
+       const char *type = unknown;
        u8 crc;
        u8 serial[6];
        int save = 0, i;
 
-       type = "unknown";
-
        while (1) {
                u64 reg;
                reg = nic_find(ioc3, &save);
@@ -393,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;
@@ -446,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)
@@ -522,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);
@@ -547,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);
@@ -591,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)
 {
@@ -626,22 +608,19 @@ 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);
 
                        ip->rx_skbs[rx_entry] = NULL;   /* Poison  */
 
-                       new_skb->dev = priv_netdev(ip);
-
                        /* Because we reserve afterwards. */
                        skb_put(new_skb, (1664 + RX_OFFSET));
                        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 {
@@ -837,13 +816,17 @@ static int ioc3_mii_init(struct ioc3_private *ip)
        }
 
        ip->mii.phy_id = i;
+
+out:
+       return res;
+}
+
+static void ioc3_mii_start(struct ioc3_private *ip)
+{
        ip->ioc3_timer.expires = jiffies + (12 * HZ)/10;  /* 1.2 sec. */
        ip->ioc3_timer.data = (unsigned long) ip;
        ip->ioc3_timer.function = &ioc3_timer;
        add_timer(&ip->ioc3_timer);
-
-out:
-       return res;
 }
 
 static inline void ioc3_clean_rx_ring(struct ioc3_private *ip)
@@ -937,7 +920,6 @@ static void ioc3_alloc_rings(struct net_device *dev)
                        }
 
                        ip->rx_skbs[i] = skb;
-                       skb->dev = dev;
 
                        /* Because we reserve afterwards. */
                        skb_put(skb, (1664 + RX_OFFSET));
@@ -1072,6 +1054,7 @@ static int ioc3_open(struct net_device *dev)
        ip->ehar_h = 0;
        ip->ehar_l = 0;
        ioc3_init(dev);
+       ioc3_mii_start(ip);
 
        netif_start_queue(dev);
        return 0;
@@ -1102,20 +1085,28 @@ static int ioc3_close(struct net_device *dev)
  * MiniDINs; all other subdevices are left swinging in the wind, leave
  * them disabled.
  */
-static inline int ioc3_is_menet(struct pci_dev *pdev)
+
+static int ioc3_adjacent_is_ioc3(struct pci_dev *pdev, int slot)
 {
-       struct pci_dev *dev;
-
-       return pdev->bus->parent == NULL
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(0, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(1, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(2, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3;
+       struct pci_dev *dev = pci_get_slot(pdev->bus, PCI_DEVFN(slot, 0));
+       int ret = 0;
+
+       if (dev) {
+               if (dev->vendor == PCI_VENDOR_ID_SGI &&
+                       dev->device == PCI_DEVICE_ID_SGI_IOC3)
+                       ret = 1;
+               pci_dev_put(dev);
+       }
+
+       return ret;
+}
+
+static int ioc3_is_menet(struct pci_dev *pdev)
+{
+       return pdev->bus->parent == NULL &&
+              ioc3_adjacent_is_ioc3(pdev, 0) &&
+              ioc3_adjacent_is_ioc3(pdev, 1) &&
+              ioc3_adjacent_is_ioc3(pdev, 2);
 }
 
 #ifdef CONFIG_SERIAL_8250
@@ -1143,13 +1134,41 @@ static inline int ioc3_is_menet(struct pci_dev *pdev)
  * Also look in ip27-pci.c:pci_fixup_ioc3() for some comments on working
  * around ioc3 oddities in this respect.
  *
- * The IOC3 serials use a 22MHz clock rate with an additional divider by 3.
+ * The IOC3 serials use a 22MHz clock rate with an additional divider which
+ * can be programmed in the SCR register if the DLAB bit is set.
+ *
+ * Register to interrupt zero because we share the interrupt with
+ * the serial driver which we don't properly support yet.
+ *
+ * Can't use UPF_IOREMAP as the whole of IOC3 resources have already been
+ * registered.
  */
+static void __devinit ioc3_8250_register(struct ioc3_uartregs __iomem *uart)
+{
+#define COSMISC_CONSTANT 6
+
+       struct uart_port port = {
+               .irq            = 0,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 0,
+               .uartclk        = (22000000 << 1) / COSMISC_CONSTANT,
+
+               .membase        = (unsigned char __iomem *) uart,
+               .mapbase        = (unsigned long) uart,
+       };
+       unsigned char lcr;
+
+       lcr = uart->iu_lcr;
+       uart->iu_lcr = lcr | UART_LCR_DLAB;
+       uart->iu_scr = COSMISC_CONSTANT,
+       uart->iu_lcr = lcr;
+       uart->iu_lcr;
+       serial8250_register_port(&port);
+}
 
 static void __devinit ioc3_serial_probe(struct pci_dev *pdev, struct ioc3 *ioc3)
 {
-       struct uart_port port;
-
        /*
         * We need to recognice and treat the fourth MENET serial as it
         * does not have an SuperIO chip attached to it, therefore attempting
@@ -1163,28 +1182,53 @@ static void __devinit ioc3_serial_probe(struct pci_dev *pdev, struct ioc3 *ioc3)
                return;
 
        /*
-        * Register to interrupt zero because we share the interrupt with
-        * the serial driver which we don't properly support yet.
-        *
-        * Can't use UPF_IOREMAP as the whole of IOC3 resources have already
-        * been registered.
+        * Switch IOC3 to PIO mode.  It probably already was but let's be
+        * paranoid
         */
-       memset(&port, 0, sizeof(port));
-       port.irq      = 0;
-       port.flags    = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
-       port.iotype   = UPIO_MEM;
-       port.regshift = 0;
-       port.uartclk  = 22000000 / 3;
-
-       port.membase  = (unsigned char *) &ioc3->sregs.uarta;
-       serial8250_register_port(&port);
-
-       port.membase  = (unsigned char *) &ioc3->sregs.uartb;
-       serial8250_register_port(&port);
+       ioc3->gpcr_s = GPCR_UARTA_MODESEL | GPCR_UARTB_MODESEL;
+       ioc3->gpcr_s;
+       ioc3->gppr_6 = 0;
+       ioc3->gppr_6;
+       ioc3->gppr_7 = 0;
+       ioc3->gppr_7;
+       ioc3->sscr_a = ioc3->sscr_a & ~SSCR_DMA_EN;
+       ioc3->sscr_a;
+       ioc3->sscr_b = ioc3->sscr_b & ~SSCR_DMA_EN;
+       ioc3->sscr_b;
+       /* Disable all SA/B interrupts except for SA/B_INT in SIO_IEC. */
+       ioc3->sio_iec &= ~ (SIO_IR_SA_TX_MT | SIO_IR_SA_RX_FULL |
+                           SIO_IR_SA_RX_HIGH | SIO_IR_SA_RX_TIMER |
+                           SIO_IR_SA_DELTA_DCD | SIO_IR_SA_DELTA_CTS |
+                           SIO_IR_SA_TX_EXPLICIT | SIO_IR_SA_MEMERR);
+       ioc3->sio_iec |= SIO_IR_SA_INT;
+       ioc3->sscr_a = 0;
+       ioc3->sio_iec &= ~ (SIO_IR_SB_TX_MT | SIO_IR_SB_RX_FULL |
+                           SIO_IR_SB_RX_HIGH | SIO_IR_SB_RX_TIMER |
+                           SIO_IR_SB_DELTA_DCD | SIO_IR_SB_DELTA_CTS |
+                           SIO_IR_SB_TX_EXPLICIT | SIO_IR_SB_MEMERR);
+       ioc3->sio_iec |= SIO_IR_SB_INT;
+       ioc3->sscr_b = 0;
+
+       ioc3_8250_register(&ioc3->sregs.uarta);
+       ioc3_8250_register(&ioc3->sregs.uartb);
 }
 #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;
@@ -1195,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));
@@ -1230,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);
@@ -1275,23 +1318,15 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto out_stop;
        }
 
+       ioc3_mii_start(ip);
        ioc3_ssram_disc(ip);
        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);
@@ -1315,6 +1350,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 out_stop:
        ioc3_stop(ip);
+       del_timer_sync(&ip->ioc3_timer);
        ioc3_free_rings(ip);
 out_res:
        pci_release_regions(pdev);
@@ -1336,6 +1372,8 @@ static void __devexit ioc3_remove_one (struct pci_dev *pdev)
        struct ioc3 *ioc3 = ip->regs;
 
        unregister_netdev(dev);
+       del_timer_sync(&ip->ioc3_timer);
+
        iounmap(ioc3);
        pci_release_regions(pdev);
        free_netdev(dev);
@@ -1378,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
@@ -1388,9 +1425,9 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
         * manually.
         */
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               int proto = ntohs(skb->nh.iph->protocol);
+               const struct iphdr *ih = ip_hdr(skb);
+               const int proto = ntohs(ih->protocol);
                unsigned int csoff;
-               struct iphdr *ih = skb->nh.iph;
                uint32_t csum, ehsum;
                uint16_t *eh;
 
@@ -1417,16 +1454,15 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
                csoff = ETH_HLEN + (ih->ihl << 2);
                if (proto == IPPROTO_UDP) {
                        csoff += offsetof(struct udphdr, check);
-                       skb->h.uh->check = csum;
+                       udp_hdr(skb)->check = csum;
                }
                if (proto == IPPROTO_TCP) {
                        csoff += offsetof(struct tcphdr, check);
-                       skb->h.th->check = csum;
+                       tcp_hdr(skb)->check = csum;
                }
 
                w0 = ETXD_DOCHECKSUM | (csoff << ETXD_CHKOFF_SHIFT);
        }
-#endif /* CONFIG_SGI_IOC3_ETH_HW_TX_CSUM */
 
        spin_lock_irq(&ip->ioc3_lock);
 
@@ -1438,7 +1474,7 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        if (len <= 104) {
                /* Short packet, let's copy it directly into the ring.  */
-               memcpy(desc->data, skb->data, skb->len);
+               skb_copy_from_linear_data(skb, desc->data, skb->len);
                if (len < ETH_ZLEN) {
                        /* Very short packet, pad with zeros at the end. */
                        memset(desc->data + len, 0, ETH_ZLEN - len);
@@ -1479,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)
@@ -1493,6 +1529,7 @@ static void ioc3_timeout(struct net_device *dev)
        ioc3_stop(ip);
        ioc3_init(dev);
        ioc3_mii_init(ip);
+       ioc3_mii_start(ip);
 
        spin_unlock_irq(&ip->ioc3_lock);
 
@@ -1580,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)