1 // SPDX-License-Identifier: GPL-2.0-only
3 * sni_82596.c -- driver for intel 82596 ethernet controller, as
4 * used in older SNI RM machines
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/string.h>
10 #include <linux/errno.h>
11 #include <linux/ioport.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/types.h>
18 #include <linux/bitops.h>
19 #include <linux/platform_device.h>
21 #include <linux/irq.h>
23 #define SNI_82596_DRIVER_VERSION "SNI RM 82596 driver - Revision: 0.01"
25 static const char sni_82596_string
[] = "snirm_82596";
27 #define SYSBUS 0x00004400
29 /* big endian CPU, 82596 little endian */
30 #define SWAP32(x) cpu_to_le32((u32)(x))
31 #define SWAP16(x) cpu_to_le16((u16)(x))
33 #define OPT_MPU_16BIT 0x01
37 MODULE_AUTHOR("Thomas Bogendoerfer");
38 MODULE_DESCRIPTION("i82596 driver");
39 MODULE_LICENSE("GPL");
40 MODULE_ALIAS("platform:snirm_82596");
41 module_param(i596_debug
, int, 0);
42 MODULE_PARM_DESC(i596_debug
, "82596 debug mask");
44 static inline void ca(struct net_device
*dev
)
46 struct i596_private
*lp
= netdev_priv(dev
);
52 static void mpu_port(struct net_device
*dev
, int c
, dma_addr_t x
)
54 struct i596_private
*lp
= netdev_priv(dev
);
56 u32 v
= (u32
) (c
) | (u32
) (x
);
58 if (lp
->options
& OPT_MPU_16BIT
) {
59 writew(v
& 0xffff, lp
->mpu_port
);
60 wmb(); /* order writes to MPU port */
62 writew(v
>> 16, lp
->mpu_port
);
64 writel(v
, lp
->mpu_port
);
65 wmb(); /* order writes to MPU port */
67 writel(v
, lp
->mpu_port
);
72 static int sni_82596_probe(struct platform_device
*dev
)
74 struct net_device
*netdevice
;
75 struct i596_private
*lp
;
76 struct resource
*res
, *ca
, *idprom
, *options
;
78 void __iomem
*mpu_addr
;
79 void __iomem
*ca_addr
;
83 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
84 ca
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
85 options
= platform_get_resource(dev
, 0, 0);
86 idprom
= platform_get_resource(dev
, IORESOURCE_MEM
, 2);
87 if (!res
|| !ca
|| !options
|| !idprom
)
89 mpu_addr
= ioremap(res
->start
, 4);
92 ca_addr
= ioremap(ca
->start
, 4);
94 goto probe_failed_free_mpu
;
96 printk(KERN_INFO
"Found i82596 at 0x%x\n", res
->start
);
98 netdevice
= alloc_etherdev(sizeof(struct i596_private
));
100 goto probe_failed_free_ca
;
102 SET_NETDEV_DEV(netdevice
, &dev
->dev
);
103 platform_set_drvdata (dev
, netdevice
);
105 netdevice
->base_addr
= res
->start
;
106 netdevice
->irq
= platform_get_irq(dev
, 0);
108 eth_addr
= ioremap(idprom
->start
, 0x10);
112 /* someone seems to like messed up stuff */
113 mac
[0] = readb(eth_addr
+ 0x0b);
114 mac
[1] = readb(eth_addr
+ 0x0a);
115 mac
[2] = readb(eth_addr
+ 0x09);
116 mac
[3] = readb(eth_addr
+ 0x08);
117 mac
[4] = readb(eth_addr
+ 0x07);
118 mac
[5] = readb(eth_addr
+ 0x06);
119 eth_hw_addr_set(netdevice
, mac
);
122 if (netdevice
->irq
< 0) {
123 printk(KERN_ERR
"%s: IRQ not found for i82596 at 0x%lx\n",
124 __FILE__
, netdevice
->base_addr
);
125 retval
= netdevice
->irq
;
129 lp
= netdev_priv(netdevice
);
130 lp
->options
= options
->flags
& IORESOURCE_BITS
;
132 lp
->mpu_port
= mpu_addr
;
134 lp
->dma
= dma_alloc_coherent(&dev
->dev
, sizeof(struct i596_dma
),
135 &lp
->dma_addr
, GFP_KERNEL
);
139 retval
= i82596_probe(netdevice
);
141 goto probe_failed_free_dma
;
144 probe_failed_free_dma
:
145 dma_free_coherent(&dev
->dev
, sizeof(struct i596_dma
), lp
->dma
,
148 free_netdev(netdevice
);
149 probe_failed_free_ca
:
151 probe_failed_free_mpu
:
156 static void sni_82596_driver_remove(struct platform_device
*pdev
)
158 struct net_device
*dev
= platform_get_drvdata(pdev
);
159 struct i596_private
*lp
= netdev_priv(dev
);
161 unregister_netdev(dev
);
162 dma_free_coherent(&pdev
->dev
, sizeof(struct i596_private
), lp
->dma
,
165 iounmap(lp
->mpu_port
);
169 static struct platform_driver sni_82596_driver
= {
170 .probe
= sni_82596_probe
,
171 .remove
= sni_82596_driver_remove
,
173 .name
= sni_82596_string
,
177 static int sni_82596_init(void)
179 printk(KERN_INFO SNI_82596_DRIVER_VERSION
"\n");
180 return platform_driver_register(&sni_82596_driver
);
184 static void __exit
sni_82596_exit(void)
186 platform_driver_unregister(&sni_82596_driver
);
189 module_init(sni_82596_init
);
190 module_exit(sni_82596_exit
);