Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.git] / drivers / net / myri_sbus.c
index 14a14f3..1b965a2 100644 (file)
@@ -1,13 +1,12 @@
-/* myri_sbus.h: MyriCOM MyriNET SBUS card driver.
+/* myri_sbus.c: MyriCOM MyriNET SBUS card driver.
  *
- * Copyright (C) 1996, 1999 David S. Miller (davem@redhat.com)
+ * Copyright (C) 1996, 1999, 2006 David S. Miller (davem@davemloft.net)
  */
 
 static char version[] =
-        "myri_sbus.c:v1.9 12/Sep/99 David S. Miller (davem@redhat.com)\n";
+        "myri_sbus.c:v2.0 June 23, 2006 David S. Miller (davem@davemloft.net)\n";
 
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -22,6 +21,7 @@ static char version[] =
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/bitops.h>
 
 #include <net/dst.h>
 #include <net/arp.h>
@@ -29,7 +29,6 @@ static char version[] =
 #include <net/ipv6.h>
 
 #include <asm/system.h>
-#include <asm/bitops.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/byteorder.h>
@@ -81,11 +80,7 @@ static char version[] =
 #define DHDR(x)
 #endif
 
-#ifdef MODULE
-static struct myri_eth *root_myri_dev;
-#endif
-
-static void myri_reset_off(unsigned long lp, unsigned long cregs)
+static void myri_reset_off(void __iomem *lp, void __iomem *cregs)
 {
        /* Clear IRQ mask. */
        sbus_writel(0, lp + LANAI_EIMASK);
@@ -94,7 +89,7 @@ static void myri_reset_off(unsigned long lp, unsigned long cregs)
        sbus_writel(CONTROL_ROFF, cregs + MYRICTRL_CTRL);
 }
 
-static void myri_reset_on(unsigned long cregs)
+static void myri_reset_on(void __iomem *cregs)
 {
        /* Enable RESET function. */
        sbus_writel(CONTROL_RON, cregs + MYRICTRL_CTRL);
@@ -103,14 +98,14 @@ static void myri_reset_on(unsigned long cregs)
        sbus_writel(CONTROL_DIRQ, cregs + MYRICTRL_CTRL);
 }
 
-static void myri_disable_irq(unsigned long lp, unsigned long cregs)
+static void myri_disable_irq(void __iomem *lp, void __iomem *cregs)
 {
        sbus_writel(CONTROL_DIRQ, cregs + MYRICTRL_CTRL);
        sbus_writel(0, lp + LANAI_EIMASK);
        sbus_writel(ISTAT_HOST, lp + LANAI_ISTAT);
 }
 
-static void myri_enable_irq(unsigned long lp, unsigned long cregs)
+static void myri_enable_irq(void __iomem *lp, void __iomem *cregs)
 {
        sbus_writel(CONTROL_EIRQ, cregs + MYRICTRL_CTRL);
        sbus_writel(ISTAT_HOST, lp + LANAI_EIMASK);
@@ -118,8 +113,8 @@ static void myri_enable_irq(unsigned long lp, unsigned long cregs)
 
 static inline void bang_the_chip(struct myri_eth *mp)
 {
-       struct myri_shmem *shmem        = mp->shmem;
-       unsigned long cregs             = mp->cregs;
+       struct myri_shmem __iomem *shmem = mp->shmem;
+       void __iomem *cregs             = mp->cregs;
 
        sbus_writel(1, &shmem->send);
        sbus_writel(CONTROL_WON, cregs + MYRICTRL_CTRL);
@@ -127,9 +122,9 @@ static inline void bang_the_chip(struct myri_eth *mp)
 
 static int myri_do_handshake(struct myri_eth *mp)
 {
-       struct myri_shmem *shmem        = mp->shmem;
-       unsigned long cregs = mp->cregs;
-       struct myri_channel *chan       = &shmem->channel;
+       struct myri_shmem __iomem *shmem = mp->shmem;
+       void __iomem *cregs = mp->cregs;
+       struct myri_channel __iomem *chan = &shmem->channel;
        int tick                        = 0;
 
        DET(("myri_do_handshake: "));
@@ -176,27 +171,27 @@ static int myri_do_handshake(struct myri_eth *mp)
 static int myri_load_lanai(struct myri_eth *mp)
 {
        struct net_device       *dev = mp->dev;
-       struct myri_shmem       *shmem = mp->shmem;
-       unsigned char           *rptr;
+       struct myri_shmem __iomem *shmem = mp->shmem;
+       void __iomem            *rptr;
        int                     i;
 
        myri_disable_irq(mp->lregs, mp->cregs);
        myri_reset_on(mp->cregs);
 
-       rptr = (unsigned char *) mp->lanai;
+       rptr = mp->lanai;
        for (i = 0; i < mp->eeprom.ramsz; i++)
-               sbus_writeb(0, &rptr[i]);
+               sbus_writeb(0, rptr + i);
 
        if (mp->eeprom.cpuvers >= CPUVERS_3_0)
                sbus_writel(mp->eeprom.cval, mp->lregs + LANAI_CVAL);
 
        /* Load executable code. */
        for (i = 0; i < sizeof(lanai4_code); i++)
-               sbus_writeb(lanai4_code[i], &rptr[(lanai4_code_off * 2) + i]);
+               sbus_writeb(lanai4_code[i], rptr + (lanai4_code_off * 2) + i);
 
        /* Load data segment. */
        for (i = 0; i < sizeof(lanai4_data); i++)
-               sbus_writeb(lanai4_data[i], &rptr[(lanai4_data_off * 2) + i]);
+               sbus_writeb(lanai4_data[i], rptr + (lanai4_data_off * 2) + i);
 
        /* Set device address. */
        sbus_writeb(0, &shmem->addr[0]);
@@ -237,15 +232,15 @@ static int myri_load_lanai(struct myri_eth *mp)
 
 static void myri_clean_rings(struct myri_eth *mp)
 {
-       struct sendq *sq = mp->sq;
-       struct recvq *rq = mp->rq;
+       struct sendq __iomem *sq = mp->sq;
+       struct recvq __iomem *rq = mp->rq;
        int i;
 
        sbus_writel(0, &rq->tail);
        sbus_writel(0, &rq->head);
        for (i = 0; i < (RX_RING_SIZE+1); i++) {
                if (mp->rx_skbs[i] != NULL) {
-                       struct myri_rxd *rxd = &rq->myri_rxd[i];
+                       struct myri_rxd __iomem *rxd = &rq->myri_rxd[i];
                        u32 dma_addr;
 
                        dma_addr = sbus_readl(&rxd->myri_scatters[0].addr);
@@ -261,7 +256,7 @@ static void myri_clean_rings(struct myri_eth *mp)
        for (i = 0; i < TX_RING_SIZE; i++) {
                if (mp->tx_skbs[i] != NULL) {
                        struct sk_buff *skb = mp->tx_skbs[i];
-                       struct myri_txd *txd = &sq->myri_txd[i];
+                       struct myri_txd __iomem *txd = &sq->myri_txd[i];
                        u32 dma_addr;
 
                        dma_addr = sbus_readl(&txd->myri_gathers[0].addr);
@@ -274,10 +269,10 @@ static void myri_clean_rings(struct myri_eth *mp)
 
 static void myri_init_rings(struct myri_eth *mp, int from_irq)
 {
-       struct recvq *rq = mp->rq;
-       struct myri_rxd *rxd = &rq->myri_rxd[0];
+       struct recvq __iomem *rq = mp->rq;
+       struct myri_rxd __iomem *rxd = &rq->myri_rxd[0];
        struct net_device *dev = mp->dev;
-       int gfp_flags = GFP_KERNEL;
+       gfp_t gfp_flags = GFP_KERNEL;
        int i;
 
        if (from_irq || in_interrupt())
@@ -343,7 +338,7 @@ static void dump_ehdr_and_myripad(unsigned char *stuff)
 
 static void myri_tx(struct myri_eth *mp, struct net_device *dev)
 {
-       struct sendq *sq        = mp->sq;
+       struct sendq __iomem *sq= mp->sq;
        int entry               = mp->tx_old;
        int limit               = sbus_readl(&sq->head);
 
@@ -369,14 +364,14 @@ static void myri_tx(struct myri_eth *mp, struct net_device *dev)
  * assume 802.3 if the type field is short enough to be a length.
  * This is normal practice and works for any 'now in use' protocol.
  */
-static unsigned short myri_type_trans(struct sk_buff *skb, struct net_device *dev)
+static __be16 myri_type_trans(struct sk_buff *skb, struct net_device *dev)
 {
        struct ethhdr *eth;
        unsigned char *rawp;
        
        skb->mac.raw = (((unsigned char *)skb->data) + MYRI_PAD_LEN);
        skb_pull(skb, dev->hard_header_len);
-       eth = skb->mac.ethernet;
+       eth = eth_hdr(skb);
        
 #ifdef DEBUG_HEADER
        DHDR(("myri_type_trans: "));
@@ -411,8 +406,8 @@ static unsigned short myri_type_trans(struct sk_buff *skb, struct net_device *de
 
 static void myri_rx(struct myri_eth *mp, struct net_device *dev)
 {
-       struct recvq *rq        = mp->rq;
-       struct recvq *rqa       = mp->rqack;
+       struct recvq __iomem *rq = mp->rq;
+       struct recvq __iomem *rqa = mp->rqack;
        int entry               = sbus_readl(&rqa->head);
        int limit               = sbus_readl(&rqa->tail);
        int drops;
@@ -423,11 +418,11 @@ static void myri_rx(struct myri_eth *mp, struct net_device *dev)
        drops = 0;
        DRX(("\n"));
        while (entry != limit) {
-               struct myri_rxd *rxdack = &rqa->myri_rxd[entry];
+               struct myri_rxd __iomem *rxdack = &rqa->myri_rxd[entry];
                u32 csum                = sbus_readl(&rxdack->csum);
                int len                 = sbus_readl(&rxdack->myri_scatters[0].len);
                int index               = sbus_readl(&rxdack->ctx);
-               struct myri_rxd *rxd    = &rq->myri_rxd[rq->tail];
+               struct myri_rxd __iomem *rxd = &rq->myri_rxd[sbus_readl(&rq->tail)];
                struct sk_buff *skb     = mp->rx_skbs[index];
 
                /* Ack it. */
@@ -545,8 +540,8 @@ static irqreturn_t myri_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
        struct net_device *dev          = (struct net_device *) dev_id;
        struct myri_eth *mp             = (struct myri_eth *) dev->priv;
-       unsigned long lregs             = mp->lregs;
-       struct myri_channel *chan       = &mp->shmem->channel;
+       void __iomem *lregs             = mp->lregs;
+       struct myri_channel __iomem *chan = &mp->shmem->channel;
        unsigned long flags;
        u32 status;
        int handled = 0;
@@ -610,8 +605,8 @@ static void myri_tx_timeout(struct net_device *dev)
 static int myri_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct myri_eth *mp = (struct myri_eth *) dev->priv;
-       struct sendq *sq = mp->sq;
-       struct myri_txd *txd;
+       struct sendq __iomem *sq = mp->sq;
+       struct myri_txd __iomem *txd;
        unsigned long flags;
        unsigned int head, tail;
        int len, entry;
@@ -896,8 +891,9 @@ static void dump_eeprom(struct myri_eth *mp)
 }
 #endif
 
-static int __init myri_ether_init(struct sbus_dev *sdev, int num)
+static int __init myri_ether_init(struct sbus_dev *sdev)
 {
+       static int num;
        static unsigned version_printed;
        struct net_device *dev;
        struct myri_eth *mp;
@@ -913,6 +909,9 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
        if (version_printed++ == 0)
                printk(version);
 
+       SET_MODULE_OWNER(dev);
+       SET_NETDEV_DEV(dev, &sdev->ofdev.dev);
+
        mp = (struct myri_eth *) dev->priv;
        spin_lock_init(&mp->irq_lock);
        mp->myri_sdev = sdev;
@@ -998,22 +997,20 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
                        printk("MyriCOM: Cannot map MyriCOM registers.\n");
                        goto err;
                }
-               mp->lanai = (unsigned short *) (mp->regs + (256 * 1024));
-               mp->lanai3 = (unsigned int *) mp->lanai;
-               mp->lregs = (unsigned long) &mp->lanai[0x10000];
+               mp->lanai = mp->regs + (256 * 1024);
+               mp->lregs = mp->lanai + (0x10000 * 2);
        } else {
                DET(("Mapping regs for cpuvers >= CPUVERS_4_0\n"));
                mp->cregs = sbus_ioremap(&sdev->resource[0], 0,
                                         PAGE_SIZE, "MyriCOM Control Regs");
                mp->lregs = sbus_ioremap(&sdev->resource[0], (256 * 1024),
                                         PAGE_SIZE, "MyriCOM LANAI Regs");
-               mp->lanai = (unsigned short *)
+               mp->lanai =
                        sbus_ioremap(&sdev->resource[0], (512 * 1024),
                                     mp->eeprom.ramsz, "MyriCOM SRAM");
-               mp->lanai3 = (unsigned int *) mp->lanai;
        }
-       DET(("Registers mapped: cregs[%lx] lregs[%lx] lanai[%p] lanai3[%p]\n",
-            mp->cregs, mp->lregs, mp->lanai, mp->lanai3));
+       DET(("Registers mapped: cregs[%p] lregs[%p] lanai[%p]\n",
+            mp->cregs, mp->lregs, mp->lanai));
 
        if (mp->eeprom.cpuvers >= CPUVERS_4_0)
                mp->shmem_base = 0xf000;
@@ -1022,7 +1019,8 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
 
        DET(("Shared memory base is %04x, ", mp->shmem_base));
 
-       mp->shmem = (struct myri_shmem *) &mp->lanai[mp->shmem_base];
+       mp->shmem = (struct myri_shmem __iomem *)
+               (mp->lanai + (mp->shmem_base * 2));
        DET(("shmem mapped at %p\n", mp->shmem));
 
        mp->rqack       = &mp->shmem->channel.recvqa;
@@ -1071,7 +1069,7 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
        /* Register interrupt handler now. */
        DET(("Requesting MYRIcom IRQ line.\n"));
        if (request_irq(dev->irq, &myri_interrupt,
-                       SA_SHIRQ, "MyriCOM Ethernet", (void *) dev)) {
+                       IRQF_SHARED, "MyriCOM Ethernet", (void *) dev)) {
                printk("MyriCOM: Cannot register interrupt handler.\n");
                goto err;
        }
@@ -1093,10 +1091,9 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
                goto err_free_irq;
        }
 
-#ifdef MODULE
-       mp->next_module = root_myri_dev;
-       root_myri_dev = mp;
-#endif
+       dev_set_drvdata(&sdev->ofdev.dev, mp);
+
+       num++;
 
        printk("%s: MyriCOM MyriNET Ethernet ", dev->name);
 
@@ -1115,61 +1112,68 @@ err:
        return -ENODEV;
 }
 
-static int __init myri_sbus_match(struct sbus_dev *sdev)
-{
-       char *name = sdev->prom_name;
 
-       if (!strcmp(name, "MYRICOM,mlanai") ||
-           !strcmp(name, "myri"))
-               return 1;
+static int __devinit myri_sbus_probe(struct of_device *dev, const struct of_device_id *match)
+{
+       struct sbus_dev *sdev = to_sbus_device(&dev->dev);
 
-       return 0;
+       return myri_ether_init(sdev);
 }
 
-static int __init myri_sbus_probe(void)
+static int __devexit myri_sbus_remove(struct of_device *dev)
 {
-       struct sbus_bus *bus;
-       struct sbus_dev *sdev = 0;
-       static int called;
-       int cards = 0, v;
+       struct myri_eth *mp = dev_get_drvdata(&dev->dev);
+       struct net_device *net_dev = mp->dev;
 
-#ifdef MODULE
-       root_myri_dev = NULL;
-#endif
+       unregister_netdevice(net_dev);
 
-       if (called)
-               return -ENODEV;
-       called++;
-
-       for_each_sbus(bus) {
-               for_each_sbusdev(sdev, bus) {
-                       if (myri_sbus_match(sdev)) {
-                               cards++;
-                               DET(("Found myricom myrinet as %s\n", sdev->prom_name));
-                               if ((v = myri_ether_init(sdev, (cards - 1))))
-                                       return v;
-                       }
-               }
+       free_irq(net_dev->irq, net_dev);
+
+       if (mp->eeprom.cpuvers < CPUVERS_4_0) {
+               sbus_iounmap(mp->regs, mp->reg_size);
+       } else {
+               sbus_iounmap(mp->cregs, PAGE_SIZE);
+               sbus_iounmap(mp->lregs, (256 * 1024));
+               sbus_iounmap(mp->lanai, (512 * 1024));
        }
-       if (!cards)
-               return -ENODEV;
+
+       free_netdev(net_dev);
+
+       dev_set_drvdata(&dev->dev, NULL);
+
        return 0;
 }
 
-static void __exit myri_sbus_cleanup(void)
+static struct of_device_id myri_sbus_match[] = {
+       {
+               .name = "MYRICOM,mlanai",
+       },
+       {
+               .name = "myri",
+       },
+       {},
+};
+
+MODULE_DEVICE_TABLE(of, myri_sbus_match);
+
+static struct of_platform_driver myri_sbus_driver = {
+       .name           = "myri",
+       .match_table    = myri_sbus_match,
+       .probe          = myri_sbus_probe,
+       .remove         = __devexit_p(myri_sbus_remove),
+};
+
+static int __init myri_sbus_init(void)
+{
+       return of_register_driver(&myri_sbus_driver, &sbus_bus_type);
+}
+
+static void __exit myri_sbus_exit(void)
 {
-#ifdef MODULE
-       while (root_myri_dev) {
-               struct myri_eth *next = root_myri_dev->next_module;
-
-               unregister_netdev(root_myri_dev->dev);
-               /* this will also free the co-allocated 'root_myri_dev' */
-               free_netdev(root_myri_dev->dev);
-               root_myri_dev = next;
-       }
-#endif /* MODULE */
+       of_unregister_driver(&myri_sbus_driver);
 }
 
-module_init(myri_sbus_probe);
-module_exit(myri_sbus_cleanup);
+module_init(myri_sbus_init);
+module_exit(myri_sbus_exit);
+
 MODULE_LICENSE("GPL");