1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/fcntl.h>
23#include <linux/gfp.h>
24#include <linux/interrupt.h>
25#include <linux/init.h>
26#include <linux/ioport.h>
27#include <linux/in.h>
28#include <linux/string.h>
29#include <linux/delay.h>
30#include <linux/errno.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h>
36#include <linux/slab.h>
37
38#include <asm/io.h>
39#include <asm/pgtable.h>
40#include <asm/dma.h>
41
42static char xtsonic_string[] = "xtsonic";
43
44extern unsigned xtboard_nvram_valid(void);
45extern void xtboard_get_ether_addr(unsigned char *buf);
46
47#include "sonic.h"
48
49
50
51
52
53
54
55
56
57
58#undef SONIC_RBSIZE
59#define SONIC_RBSIZE 1524
60
61
62
63
64#define SONIC_MEM_SIZE 0x100
65
66
67
68
69#define SONIC_READ(reg) \
70 (0xffff & *((volatile unsigned int *)dev->base_addr+reg))
71
72#define SONIC_WRITE(reg,val) \
73 *((volatile unsigned int *)dev->base_addr+reg) = val
74
75
76
77#ifdef SONIC_DEBUG
78static unsigned int sonic_debug = SONIC_DEBUG;
79#else
80static unsigned int sonic_debug = 1;
81#endif
82
83
84
85
86
87
88static unsigned short known_revisions[] =
89{
90 0x101,
91 0xffff
92};
93
94static int xtsonic_open(struct net_device *dev)
95{
96 int retval;
97
98 retval = request_irq(dev->irq, sonic_interrupt, IRQF_DISABLED,
99 "sonic", dev);
100 if (retval) {
101 printk(KERN_ERR "%s: unable to get IRQ %d.\n",
102 dev->name, dev->irq);
103 return -EAGAIN;
104 }
105
106 retval = sonic_open(dev);
107 if (retval)
108 free_irq(dev->irq, dev);
109 return retval;
110}
111
112static int xtsonic_close(struct net_device *dev)
113{
114 int err;
115 err = sonic_close(dev);
116 free_irq(dev->irq, dev);
117 return err;
118}
119
120static const struct net_device_ops xtsonic_netdev_ops = {
121 .ndo_open = xtsonic_open,
122 .ndo_stop = xtsonic_close,
123 .ndo_start_xmit = sonic_send_packet,
124 .ndo_get_stats = sonic_get_stats,
125 .ndo_set_rx_mode = sonic_multicast_list,
126 .ndo_tx_timeout = sonic_tx_timeout,
127 .ndo_validate_addr = eth_validate_addr,
128 .ndo_change_mtu = eth_change_mtu,
129 .ndo_set_mac_address = eth_mac_addr,
130};
131
132static int __init sonic_probe1(struct net_device *dev)
133{
134 static unsigned version_printed = 0;
135 unsigned int silicon_revision;
136 struct sonic_local *lp = netdev_priv(dev);
137 unsigned int base_addr = dev->base_addr;
138 int i;
139 int err = 0;
140
141 if (!request_mem_region(base_addr, 0x100, xtsonic_string))
142 return -EBUSY;
143
144
145
146
147
148
149 silicon_revision = SONIC_READ(SONIC_SR);
150 if (sonic_debug > 1)
151 printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
152
153 i = 0;
154 while ((known_revisions[i] != 0xffff) &&
155 (known_revisions[i] != silicon_revision))
156 i++;
157
158 if (known_revisions[i] == 0xffff) {
159 printk("SONIC ethernet controller not found (0x%4x)\n",
160 silicon_revision);
161 return -ENODEV;
162 }
163
164 if (sonic_debug && version_printed++ == 0)
165 printk(version);
166
167
168
169
170
171 SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
172 SONIC_WRITE(SONIC_DCR,
173 SONIC_DCR_WC0|SONIC_DCR_DW|SONIC_DCR_LBR|SONIC_DCR_SBUS);
174 SONIC_WRITE(SONIC_CEP,0);
175 SONIC_WRITE(SONIC_IMR,0);
176
177 SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
178 SONIC_WRITE(SONIC_CEP,0);
179
180 for (i=0; i<3; i++) {
181 unsigned int val = SONIC_READ(SONIC_CAP0-i);
182 dev->dev_addr[i*2] = val;
183 dev->dev_addr[i*2+1] = val >> 8;
184 }
185
186
187
188 lp->dma_bitmode = SONIC_BITMODE32;
189
190
191
192
193
194
195
196
197
198
199
200 lp->descriptors =
201 dma_alloc_coherent(lp->device,
202 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
203 &lp->descriptors_laddr, GFP_KERNEL);
204
205 if (lp->descriptors == NULL) {
206 printk(KERN_ERR "%s: couldn't alloc DMA memory for "
207 " descriptors.\n", dev_name(lp->device));
208 err = -ENOMEM;
209 goto out;
210 }
211
212 lp->cda = lp->descriptors;
213 lp->tda = lp->cda + (SIZEOF_SONIC_CDA
214 * SONIC_BUS_SCALE(lp->dma_bitmode));
215 lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
216 * SONIC_BUS_SCALE(lp->dma_bitmode));
217 lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
218 * SONIC_BUS_SCALE(lp->dma_bitmode));
219
220
221
222 lp->cda_laddr = lp->descriptors_laddr;
223 lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
224 * SONIC_BUS_SCALE(lp->dma_bitmode));
225 lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
226 * SONIC_BUS_SCALE(lp->dma_bitmode));
227 lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
228 * SONIC_BUS_SCALE(lp->dma_bitmode));
229
230 dev->netdev_ops = &xtsonic_netdev_ops;
231 dev->watchdog_timeo = TX_TIMEOUT;
232
233
234
235
236 SONIC_WRITE(SONIC_CRCT,0xffff);
237 SONIC_WRITE(SONIC_FAET,0xffff);
238 SONIC_WRITE(SONIC_MPT,0xffff);
239
240 return 0;
241out:
242 release_region(dev->base_addr, SONIC_MEM_SIZE);
243 return err;
244}
245
246
247
248
249
250
251
252int __devinit xtsonic_probe(struct platform_device *pdev)
253{
254 struct net_device *dev;
255 struct sonic_local *lp;
256 struct resource *resmem, *resirq;
257 int err = 0;
258
259 if ((resmem = platform_get_resource(pdev, IORESOURCE_MEM, 0)) == NULL)
260 return -ENODEV;
261
262 if ((resirq = platform_get_resource(pdev, IORESOURCE_IRQ, 0)) == NULL)
263 return -ENODEV;
264
265 if ((dev = alloc_etherdev(sizeof(struct sonic_local))) == NULL)
266 return -ENOMEM;
267
268 lp = netdev_priv(dev);
269 lp->device = &pdev->dev;
270 SET_NETDEV_DEV(dev, &pdev->dev);
271 netdev_boot_setup_check(dev);
272
273 dev->base_addr = resmem->start;
274 dev->irq = resirq->start;
275
276 if ((err = sonic_probe1(dev)))
277 goto out;
278 if ((err = register_netdev(dev)))
279 goto out1;
280
281 printk("%s: SONIC ethernet @%08lx, MAC %pM, IRQ %d\n", dev->name,
282 dev->base_addr, dev->dev_addr, dev->irq);
283
284 return 0;
285
286out1:
287 release_region(dev->base_addr, SONIC_MEM_SIZE);
288out:
289 free_netdev(dev);
290
291 return err;
292}
293
294MODULE_DESCRIPTION("Xtensa XT2000 SONIC ethernet driver");
295module_param(sonic_debug, int, 0);
296MODULE_PARM_DESC(sonic_debug, "xtsonic debug level (1-4)");
297
298#include "sonic.c"
299
300static int __devexit xtsonic_device_remove (struct platform_device *pdev)
301{
302 struct net_device *dev = platform_get_drvdata(pdev);
303 struct sonic_local *lp = netdev_priv(dev);
304
305 unregister_netdev(dev);
306 dma_free_coherent(lp->device,
307 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
308 lp->descriptors, lp->descriptors_laddr);
309 release_region (dev->base_addr, SONIC_MEM_SIZE);
310 free_netdev(dev);
311
312 return 0;
313}
314
315static struct platform_driver xtsonic_driver = {
316 .probe = xtsonic_probe,
317 .remove = __devexit_p(xtsonic_device_remove),
318 .driver = {
319 .name = xtsonic_string,
320 },
321};
322
323module_platform_driver(xtsonic_driver);
324