1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71#include <linux/module.h>
72#include <linux/kernel.h>
73#include <linux/string.h>
74#include <linux/ptrace.h>
75#include <linux/errno.h>
76#include <linux/ioport.h>
77#include <linux/interrupt.h>
78#include <linux/delay.h>
79#include <linux/netdevice.h>
80#include <linux/etherdevice.h>
81#include <linux/skbuff.h>
82#include <linux/types.h>
83#include <linux/bitops.h>
84#include <linux/dma-mapping.h>
85
86#include <asm/io.h>
87#include <asm/irq.h>
88#include <asm/pdc.h>
89#include <asm/parisc-device.h>
90
91#define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30"
92
93#define PA_I82596_RESET 0
94#define PA_CPU_PORT_L_ACCESS 4
95#define PA_CHANNEL_ATTENTION 8
96
97#define OPT_SWAP_PORT 0x0001
98
99#define SYSBUS 0x0000006c
100
101
102#define SWAP32(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
103#define SWAP16(x) (x)
104
105#define NONCOHERENT_DMA 1
106
107#include "lib82596.c"
108
109MODULE_AUTHOR("Richard Hirst");
110MODULE_DESCRIPTION("i82596 driver");
111MODULE_LICENSE("GPL");
112module_param(i596_debug, int, 0);
113MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
114
115static inline void ca(struct net_device *dev)
116{
117 gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION);
118}
119
120
121static void mpu_port(struct net_device *dev, int c, dma_addr_t x)
122{
123 struct i596_private *lp = netdev_priv(dev);
124
125 u32 v = (u32) (c) | (u32) (x);
126 u16 a, b;
127
128 if (lp->options & OPT_SWAP_PORT) {
129 a = v >> 16;
130 b = v & 0xffff;
131 } else {
132 a = v & 0xffff;
133 b = v >> 16;
134 }
135
136 gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS);
137 if (!running_on_qemu)
138 udelay(1);
139 gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
140}
141
142#define LAN_PROM_ADDR 0xF0810000
143
144static int __init
145lan_init_chip(struct parisc_device *dev)
146{
147 struct net_device *netdevice;
148 struct i596_private *lp;
149 int retval = -ENOMEM;
150 int i;
151
152 if (!dev->irq) {
153 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
154 __FILE__, (unsigned long)dev->hpa.start);
155 return -ENODEV;
156 }
157
158 printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n",
159 (unsigned long)dev->hpa.start, dev->irq);
160
161 netdevice = alloc_etherdev(sizeof(struct i596_private));
162 if (!netdevice)
163 return -ENOMEM;
164 SET_NETDEV_DEV(netdevice, &dev->dev);
165 parisc_set_drvdata (dev, netdevice);
166
167 netdevice->base_addr = dev->hpa.start;
168 netdevice->irq = dev->irq;
169
170 if (pdc_lan_station_id(netdevice->dev_addr, netdevice->base_addr)) {
171 for (i = 0; i < 6; i++) {
172 netdevice->dev_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
173 }
174 printk(KERN_INFO
175 "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
176 }
177
178 lp = netdev_priv(netdevice);
179 lp->options = dev->id.sversion == 0x72 ? OPT_SWAP_PORT : 0;
180 lp->dma = dma_alloc_noncoherent(&dev->dev,
181 sizeof(struct i596_dma), &lp->dma_addr,
182 DMA_BIDIRECTIONAL, GFP_KERNEL);
183 if (!lp->dma)
184 goto out_free_netdev;
185
186 retval = i82596_probe(netdevice);
187 if (retval)
188 goto out_free_dma;
189 return 0;
190
191out_free_dma:
192 dma_free_noncoherent(&dev->dev, sizeof(struct i596_dma),
193 lp->dma, lp->dma_addr, DMA_BIDIRECTIONAL);
194out_free_netdev:
195 free_netdev(netdevice);
196 return retval;
197}
198
199static void __exit lan_remove_chip(struct parisc_device *pdev)
200{
201 struct net_device *dev = parisc_get_drvdata(pdev);
202 struct i596_private *lp = netdev_priv(dev);
203
204 unregister_netdev (dev);
205 dma_free_noncoherent(&pdev->dev, sizeof(struct i596_private), lp->dma,
206 lp->dma_addr, DMA_BIDIRECTIONAL);
207 free_netdev (dev);
208}
209
210static const struct parisc_device_id lan_tbl[] __initconst = {
211 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
212 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
213 { 0, }
214};
215
216MODULE_DEVICE_TABLE(parisc, lan_tbl);
217
218static struct parisc_driver lan_driver __refdata = {
219 .name = "lasi_82596",
220 .id_table = lan_tbl,
221 .probe = lan_init_chip,
222 .remove = __exit_p(lan_remove_chip),
223};
224
225static int lasi_82596_init(void)
226{
227 printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
228 return register_parisc_driver(&lan_driver);
229}
230
231module_init(lasi_82596_init);
232
233static void __exit lasi_82596_exit(void)
234{
235 unregister_parisc_driver(&lan_driver);
236}
237
238module_exit(lasi_82596_exit);
239