Initial commit
[wrt350n-kernel.git] / drivers / net / sni_82596.c
blob2cf6794acb4f9368a8f99ca94952c3766395fc97
1 /*
2 * sni_82596.c -- driver for intel 82596 ethernet controller, as
3 * used in older SNI RM machines
4 */
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>
24 #define SNI_82596_DRIVER_VERSION "SNI RM 82596 driver - Revision: 0.01"
26 static const char sni_82596_string[] = "snirm_82596";
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)
34 #define SYSBUS 0x00004400
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))
40 #define OPT_MPU_16BIT 0x01
42 #include "lib82596.c"
44 MODULE_AUTHOR("Thomas Bogendoerfer");
45 MODULE_DESCRIPTION("i82596 driver");
46 MODULE_LICENSE("GPL");
47 module_param(i596_debug, int, 0);
48 MODULE_PARM_DESC(i596_debug, "82596 debug mask");
50 static inline void ca(struct net_device *dev)
52 struct i596_private *lp = netdev_priv(dev);
54 writel(0, lp->ca);
58 static void mpu_port(struct net_device *dev, int c, dma_addr_t x)
60 struct i596_private *lp = netdev_priv(dev);
62 u32 v = (u32) (c) | (u32) (x);
64 if (lp->options & OPT_MPU_16BIT) {
65 writew(v & 0xffff, lp->mpu_port);
66 wmb(); /* order writes to MPU port */
67 udelay(1);
68 writew(v >> 16, lp->mpu_port);
69 } else {
70 writel(v, lp->mpu_port);
71 wmb(); /* order writes to MPU port */
72 udelay(1);
73 writel(v, lp->mpu_port);
78 static int __devinit sni_82596_probe(struct platform_device *dev)
80 struct net_device *netdevice;
81 struct i596_private *lp;
82 struct resource *res, *ca, *idprom, *options;
83 int retval = -ENOMEM;
84 void __iomem *mpu_addr;
85 void __iomem *ca_addr;
86 u8 __iomem *eth_addr;
88 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
89 ca = platform_get_resource(dev, IORESOURCE_MEM, 1);
90 options = platform_get_resource(dev, 0, 0);
91 idprom = platform_get_resource(dev, IORESOURCE_MEM, 2);
92 if (!res || !ca || !options || !idprom)
93 return -ENODEV;
94 mpu_addr = ioremap_nocache(res->start, 4);
95 if (!mpu_addr)
96 return -ENOMEM;
97 ca_addr = ioremap_nocache(ca->start, 4);
98 if (!ca_addr)
99 goto probe_failed_free_mpu;
101 printk(KERN_INFO "Found i82596 at 0x%x\n", res->start);
103 netdevice = alloc_etherdev(sizeof(struct i596_private));
104 if (!netdevice)
105 goto probe_failed_free_ca;
107 SET_NETDEV_DEV(netdevice, &dev->dev);
108 platform_set_drvdata (dev, netdevice);
110 netdevice->base_addr = res->start;
111 netdevice->irq = platform_get_irq(dev, 0);
113 eth_addr = ioremap_nocache(idprom->start, 0x10);
114 if (!eth_addr)
115 goto probe_failed;
117 /* someone seems to like messed up stuff */
118 netdevice->dev_addr[0] = readb(eth_addr + 0x0b);
119 netdevice->dev_addr[1] = readb(eth_addr + 0x0a);
120 netdevice->dev_addr[2] = readb(eth_addr + 0x09);
121 netdevice->dev_addr[3] = readb(eth_addr + 0x08);
122 netdevice->dev_addr[4] = readb(eth_addr + 0x07);
123 netdevice->dev_addr[5] = readb(eth_addr + 0x06);
124 iounmap(eth_addr);
126 if (!netdevice->irq) {
127 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
128 __FILE__, netdevice->base_addr);
129 goto probe_failed;
132 lp = netdev_priv(netdevice);
133 lp->options = options->flags & IORESOURCE_BITS;
134 lp->ca = ca_addr;
135 lp->mpu_port = mpu_addr;
137 retval = i82596_probe(netdevice);
138 if (retval == 0)
139 return 0;
141 probe_failed:
142 free_netdev(netdevice);
143 probe_failed_free_ca:
144 iounmap(ca_addr);
145 probe_failed_free_mpu:
146 iounmap(mpu_addr);
147 return retval;
150 static int __devexit sni_82596_driver_remove(struct platform_device *pdev)
152 struct net_device *dev = platform_get_drvdata(pdev);
153 struct i596_private *lp = netdev_priv(dev);
155 unregister_netdev(dev);
156 DMA_FREE(dev->dev.parent, sizeof(struct i596_private),
157 lp->dma, lp->dma_addr);
158 iounmap(lp->ca);
159 iounmap(lp->mpu_port);
160 free_netdev (dev);
161 return 0;
164 static struct platform_driver sni_82596_driver = {
165 .probe = sni_82596_probe,
166 .remove = __devexit_p(sni_82596_driver_remove),
167 .driver = {
168 .name = sni_82596_string,
172 static int __devinit sni_82596_init(void)
174 printk(KERN_INFO SNI_82596_DRIVER_VERSION "\n");
175 return platform_driver_register(&sni_82596_driver);
179 static void __exit sni_82596_exit(void)
181 platform_driver_unregister(&sni_82596_driver);
184 module_init(sni_82596_init);
185 module_exit(sni_82596_exit);