trivial: fix typos s/paramter/parameter/ and s/excute/execute/ in documentation and...
[sfrench/cifs-2.6.git] / drivers / net / sni_82596.c
1 /*
2  * sni_82596.c -- driver for intel 82596 ethernet controller, as
3  *                used in older SNI RM machines
4  */
5
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include <linux/errno.h>
10 #include <linux/ioport.h>
11 #include <linux/slab.h>
12 #include <linux/interrupt.h>
13 #include <linux/delay.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/skbuff.h>
17 #include <linux/init.h>
18 #include <linux/types.h>
19 #include <linux/bitops.h>
20 #include <linux/platform_device.h>
21 #include <linux/io.h>
22 #include <linux/irq.h>
23
24 #define SNI_82596_DRIVER_VERSION "SNI RM 82596 driver - Revision: 0.01"
25
26 static const char sni_82596_string[] = "snirm_82596";
27
28 #define DMA_ALLOC                      dma_alloc_coherent
29 #define DMA_FREE                       dma_free_coherent
30 #define DMA_WBACK(priv, addr, len)     do { } while (0)
31 #define DMA_INV(priv, addr, len)       do { } while (0)
32 #define DMA_WBACK_INV(priv, addr, len) do { } while (0)
33
34 #define SYSBUS      0x00004400
35
36 /* big endian CPU, 82596 little endian */
37 #define SWAP32(x)   cpu_to_le32((u32)(x))
38 #define SWAP16(x)   cpu_to_le16((u16)(x))
39
40 #define OPT_MPU_16BIT    0x01
41
42 #include "lib82596.c"
43
44 MODULE_AUTHOR("Thomas Bogendoerfer");
45 MODULE_DESCRIPTION("i82596 driver");
46 MODULE_LICENSE("GPL");
47 MODULE_ALIAS("platform:snirm_82596");
48 module_param(i596_debug, int, 0);
49 MODULE_PARM_DESC(i596_debug, "82596 debug mask");
50
51 static inline void ca(struct net_device *dev)
52 {
53         struct i596_private *lp = netdev_priv(dev);
54
55         writel(0, lp->ca);
56 }
57
58
59 static void mpu_port(struct net_device *dev, int c, dma_addr_t x)
60 {
61         struct i596_private *lp = netdev_priv(dev);
62
63         u32 v = (u32) (c) | (u32) (x);
64
65         if (lp->options & OPT_MPU_16BIT) {
66                 writew(v & 0xffff, lp->mpu_port);
67                 wmb();  /* order writes to MPU port */
68                 udelay(1);
69                 writew(v >> 16, lp->mpu_port);
70         } else {
71                 writel(v, lp->mpu_port);
72                 wmb();  /* order writes to MPU port */
73                 udelay(1);
74                 writel(v, lp->mpu_port);
75         }
76 }
77
78
79 static int __devinit sni_82596_probe(struct platform_device *dev)
80 {
81         struct  net_device *netdevice;
82         struct i596_private *lp;
83         struct  resource *res, *ca, *idprom, *options;
84         int     retval = -ENOMEM;
85         void __iomem *mpu_addr;
86         void __iomem *ca_addr;
87         u8 __iomem *eth_addr;
88
89         res = platform_get_resource(dev, IORESOURCE_MEM, 0);
90         ca = platform_get_resource(dev, IORESOURCE_MEM, 1);
91         options = platform_get_resource(dev, 0, 0);
92         idprom = platform_get_resource(dev, IORESOURCE_MEM, 2);
93         if (!res || !ca || !options || !idprom)
94                 return -ENODEV;
95         mpu_addr = ioremap_nocache(res->start, 4);
96         if (!mpu_addr)
97                 return -ENOMEM;
98         ca_addr = ioremap_nocache(ca->start, 4);
99         if (!ca_addr)
100                 goto probe_failed_free_mpu;
101
102         printk(KERN_INFO "Found i82596 at 0x%x\n", res->start);
103
104         netdevice = alloc_etherdev(sizeof(struct i596_private));
105         if (!netdevice)
106                 goto probe_failed_free_ca;
107
108         SET_NETDEV_DEV(netdevice, &dev->dev);
109         platform_set_drvdata (dev, netdevice);
110
111         netdevice->base_addr = res->start;
112         netdevice->irq = platform_get_irq(dev, 0);
113
114         eth_addr = ioremap_nocache(idprom->start, 0x10);
115         if (!eth_addr)
116                 goto probe_failed;
117
118         /* someone seems to like messed up stuff */
119         netdevice->dev_addr[0] = readb(eth_addr + 0x0b);
120         netdevice->dev_addr[1] = readb(eth_addr + 0x0a);
121         netdevice->dev_addr[2] = readb(eth_addr + 0x09);
122         netdevice->dev_addr[3] = readb(eth_addr + 0x08);
123         netdevice->dev_addr[4] = readb(eth_addr + 0x07);
124         netdevice->dev_addr[5] = readb(eth_addr + 0x06);
125         iounmap(eth_addr);
126
127         if (!netdevice->irq) {
128                 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
129                         __FILE__, netdevice->base_addr);
130                 goto probe_failed;
131         }
132
133         lp = netdev_priv(netdevice);
134         lp->options = options->flags & IORESOURCE_BITS;
135         lp->ca = ca_addr;
136         lp->mpu_port = mpu_addr;
137
138         retval = i82596_probe(netdevice);
139         if (retval == 0)
140                 return 0;
141
142 probe_failed:
143         free_netdev(netdevice);
144 probe_failed_free_ca:
145         iounmap(ca_addr);
146 probe_failed_free_mpu:
147         iounmap(mpu_addr);
148         return retval;
149 }
150
151 static int __devexit sni_82596_driver_remove(struct platform_device *pdev)
152 {
153         struct net_device *dev = platform_get_drvdata(pdev);
154         struct i596_private *lp = netdev_priv(dev);
155
156         unregister_netdev(dev);
157         DMA_FREE(dev->dev.parent, sizeof(struct i596_private),
158                  lp->dma, lp->dma_addr);
159         iounmap(lp->ca);
160         iounmap(lp->mpu_port);
161         free_netdev (dev);
162         return 0;
163 }
164
165 static struct platform_driver sni_82596_driver = {
166         .probe  = sni_82596_probe,
167         .remove = __devexit_p(sni_82596_driver_remove),
168         .driver = {
169                 .name   = sni_82596_string,
170                 .owner  = THIS_MODULE,
171         },
172 };
173
174 static int __devinit sni_82596_init(void)
175 {
176         printk(KERN_INFO SNI_82596_DRIVER_VERSION "\n");
177         return platform_driver_register(&sni_82596_driver);
178 }
179
180
181 static void __exit sni_82596_exit(void)
182 {
183         platform_driver_unregister(&sni_82596_driver);
184 }
185
186 module_init(sni_82596_init);
187 module_exit(sni_82596_exit);