1 /*
2 * Sealevel Systems 4021 driver.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * (c) Copyright 1999, 2001 Alan Cox
10 * (c) Copyright 2001 Red Hat Inc.
11 *
12 */
13
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/mm.h>
17 #include <linux/net.h>
18 #include <linux/skbuff.h>
19 #include <linux/netdevice.h>
20 #include <linux/if_arp.h>
21 #include <linux/delay.h>
22 #include <linux/ioport.h>
23 #include <net/arp.h>
24
25 #include <asm/io.h>
26 #include <asm/dma.h>
27 #include <asm/byteorder.h>
28 #include <net/syncppp.h>
29 #include "z85230.h"
30
31
32 struct slvl_device
33 {
34 void *if_ptr; /* General purpose pointer (used by SPPP) */
35 struct z8530_channel *chan;
36 struct ppp_device netdev;
37 int channel;
38 };
39
40
41 struct slvl_board
42 {
43 struct slvl_device dev[2];
44 struct z8530_dev board;
45 int iobase;
46 };
47
48 /*
49 * Network driver support routines
50 */
51
52 /*
53 * Frame receive. Simple for our card as we do sync ppp and there
54 * is no funny garbage involved
55 */
56
sealevel_input(struct z8530_channel * c,struct sk_buff * skb)57 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
58 {
59 /* Drop the CRC - its not a good idea to try and negotiate it ;) */
60 skb_trim(skb, skb->len-2);
61 skb->protocol=htons(ETH_P_WAN_PPP);
62 skb->mac.raw=skb->data;
63 skb->dev=c->netdevice;
64 /*
65 * Send it to the PPP layer. We dont have time to process
66 * it right now.
67 */
68 netif_rx(skb);
69 c->netdevice->last_rx = jiffies;
70 }
71
72 /*
73 * We've been placed in the UP state
74 */
75
sealevel_open(struct net_device * d)76 static int sealevel_open(struct net_device *d)
77 {
78 struct slvl_device *slvl=d->priv;
79 int err = -1;
80 int unit = slvl->channel;
81
82 /*
83 * Link layer up.
84 */
85
86 switch(unit)
87 {
88 case 0:
89 err=z8530_sync_dma_open(d, slvl->chan);
90 break;
91 case 1:
92 err=z8530_sync_open(d, slvl->chan);
93 break;
94 }
95
96 if(err)
97 return err;
98 /*
99 * Begin PPP
100 */
101 err=sppp_open(d);
102 if(err)
103 {
104 switch(unit)
105 {
106 case 0:
107 z8530_sync_dma_close(d, slvl->chan);
108 break;
109 case 1:
110 z8530_sync_close(d, slvl->chan);
111 break;
112 }
113 return err;
114 }
115
116 slvl->chan->rx_function=sealevel_input;
117
118 /*
119 * Go go go
120 */
121 netif_start_queue(d);
122 MOD_INC_USE_COUNT;
123 return 0;
124 }
125
sealevel_close(struct net_device * d)126 static int sealevel_close(struct net_device *d)
127 {
128 struct slvl_device *slvl=d->priv;
129 int unit = slvl->channel;
130
131 /*
132 * Discard new frames
133 */
134
135 slvl->chan->rx_function=z8530_null_rx;
136
137 /*
138 * PPP off
139 */
140 sppp_close(d);
141 /*
142 * Link layer down
143 */
144
145 netif_stop_queue(d);
146
147 switch(unit)
148 {
149 case 0:
150 z8530_sync_dma_close(d, slvl->chan);
151 break;
152 case 1:
153 z8530_sync_close(d, slvl->chan);
154 break;
155 }
156 MOD_DEC_USE_COUNT;
157 return 0;
158 }
159
sealevel_ioctl(struct net_device * d,struct ifreq * ifr,int cmd)160 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
161 {
162 /* struct slvl_device *slvl=d->priv;
163 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
164 return sppp_do_ioctl(d, ifr,cmd);
165 }
166
sealevel_get_stats(struct net_device * d)167 static struct net_device_stats *sealevel_get_stats(struct net_device *d)
168 {
169 struct slvl_device *slvl=d->priv;
170 if(slvl)
171 return z8530_get_stats(slvl->chan);
172 else
173 return NULL;
174 }
175
176 /*
177 * Passed PPP frames, fire them downwind.
178 */
179
sealevel_queue_xmit(struct sk_buff * skb,struct net_device * d)180 static int sealevel_queue_xmit(struct sk_buff *skb, struct net_device *d)
181 {
182 struct slvl_device *slvl=d->priv;
183 return z8530_queue_xmit(slvl->chan, skb);
184 }
185
sealevel_neigh_setup(struct neighbour * n)186 static int sealevel_neigh_setup(struct neighbour *n)
187 {
188 if (n->nud_state == NUD_NONE) {
189 n->ops = &arp_broken_ops;
190 n->output = n->ops->output;
191 }
192 return 0;
193 }
194
sealevel_neigh_setup_dev(struct net_device * dev,struct neigh_parms * p)195 static int sealevel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
196 {
197 if (p->tbl->family == AF_INET) {
198 p->neigh_setup = sealevel_neigh_setup;
199 p->ucast_probes = 0;
200 p->mcast_probes = 0;
201 }
202 return 0;
203 }
204
205 /*
206 * Description block for a Comtrol Hostess SV11 card
207 */
208
slvl_init(int iobase,int irq,int txdma,int rxdma,int slow)209 static struct slvl_board *slvl_init(int iobase, int irq, int txdma, int rxdma, int slow)
210 {
211 struct z8530_dev *dev;
212 struct slvl_device *sv;
213 struct slvl_board *b;
214
215 unsigned long flags;
216 int u;
217
218 /*
219 * Get the needed I/O space
220 */
221
222 if(!request_region(iobase, 8, "Sealevel 4021"))
223 {
224 printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n", iobase);
225 return NULL;
226 }
227
228 b=(struct slvl_board *)kmalloc(sizeof(struct slvl_board), GFP_KERNEL);
229 if(!b)
230 goto fail3;
231
232 memset(b, 0, sizeof(*sv));
233
234 b->dev[0].chan = &b->board.chanA;
235 b->dev[0].if_ptr = &b->dev[0].netdev;
236 b->dev[0].netdev.dev=(struct net_device *)
237 kmalloc(sizeof(struct net_device), GFP_KERNEL);
238 if(!b->dev[0].netdev.dev)
239 goto fail2;
240
241 b->dev[1].chan = &b->board.chanB;
242 b->dev[1].if_ptr = &b->dev[1].netdev;
243 b->dev[1].netdev.dev=(struct net_device *)
244 kmalloc(sizeof(struct net_device), GFP_KERNEL);
245 if(!b->dev[1].netdev.dev)
246 goto fail1_0;
247
248 dev=&b->board;
249
250 /*
251 * Stuff in the I/O addressing
252 */
253
254 dev->active = 0;
255
256 b->iobase = iobase;
257
258 /*
259 * Select 8530 delays for the old board
260 */
261
262 if(slow)
263 iobase |= Z8530_PORT_SLEEP;
264
265 dev->chanA.ctrlio=iobase+1;
266 dev->chanA.dataio=iobase;
267 dev->chanB.ctrlio=iobase+3;
268 dev->chanB.dataio=iobase+2;
269
270 dev->chanA.irqs=&z8530_nop;
271 dev->chanB.irqs=&z8530_nop;
272
273 /*
274 * Assert DTR enable DMA
275 */
276
277 outb(3|(1<<7), b->iobase+4);
278
279
280 /* We want a fast IRQ for this device. Actually we'd like an even faster
281 IRQ ;) - This is one driver RtLinux is made for */
282
283 if(request_irq(irq, &z8530_interrupt, SA_INTERRUPT, "SeaLevel", dev)<0)
284 {
285 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
286 goto fail1_1;
287 }
288
289 dev->irq=irq;
290 dev->chanA.private=&b->dev[0];
291 dev->chanB.private=&b->dev[1];
292 dev->chanA.netdevice=b->dev[0].netdev.dev;
293 dev->chanB.netdevice=b->dev[1].netdev.dev;
294 dev->chanA.dev=dev;
295 dev->chanB.dev=dev;
296
297 dev->chanA.txdma=3;
298 dev->chanA.rxdma=1;
299 if(request_dma(dev->chanA.txdma, "SeaLevel (TX)")!=0)
300 goto fail;
301
302 if(request_dma(dev->chanA.rxdma, "SeaLevel (RX)")!=0)
303 goto dmafail;
304
305 save_flags(flags);
306 cli();
307
308 /*
309 * Begin normal initialise
310 */
311
312 if(z8530_init(dev)!=0)
313 {
314 printk(KERN_ERR "Z8530 series device not found.\n");
315 restore_flags(flags);
316 goto dmafail2;
317 }
318 if(dev->type==Z85C30)
319 {
320 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
321 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
322 }
323 else
324 {
325 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
326 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
327 }
328
329 /*
330 * Now we can take the IRQ
331 */
332
333 restore_flags(flags);
334
335 for(u=0; u<2; u++)
336 {
337 sv=&b->dev[u];
338 sv->channel = u;
339
340 if(dev_alloc_name(sv->chan->netdevice,"hdlc%d")>=0)
341 {
342 struct net_device *d=sv->chan->netdevice;
343
344 /*
345 * Initialise the PPP components
346 */
347 sppp_attach(&sv->netdev);
348
349 /*
350 * Local fields
351 */
352
353 d->base_addr = iobase;
354 d->irq = irq;
355 d->priv = sv;
356 d->init = NULL;
357
358 d->open = sealevel_open;
359 d->stop = sealevel_close;
360 d->hard_start_xmit = sealevel_queue_xmit;
361 d->get_stats = sealevel_get_stats;
362 d->set_multicast_list = NULL;
363 d->do_ioctl = sealevel_ioctl;
364 d->neigh_setup = sealevel_neigh_setup_dev;
365 d->set_mac_address = NULL;
366
367 if(register_netdev(d)==-1)
368 {
369 printk(KERN_ERR "%s: unable to register device.\n",
370 d->name);
371 goto fail_unit;
372 }
373
374 break;
375 }
376 }
377 z8530_describe(dev, "I/O", iobase);
378 dev->active=1;
379 return b;
380
381 fail_unit:
382 if(u==1)
383 unregister_netdev(b->dev[0].chan->netdevice);
384
385 dmafail2:
386 free_dma(dev->chanA.rxdma);
387 dmafail:
388 free_dma(dev->chanA.txdma);
389 fail:
390 free_irq(irq, dev);
391 fail1_1:
392 kfree(b->dev[1].netdev.dev);
393 fail1_0:
394 kfree(b->dev[0].netdev.dev);
395 fail2:
396 kfree(b);
397 fail3:
398 release_region(iobase,8);
399 return NULL;
400 }
401
slvl_shutdown(struct slvl_board * b)402 static void slvl_shutdown(struct slvl_board *b)
403 {
404 int u;
405
406 z8530_shutdown(&b->board);
407
408 for(u=0; u<2; u++)
409 {
410 sppp_detach(b->dev[u].netdev.dev);
411 unregister_netdev(b->dev[u].netdev.dev);
412 }
413
414 free_irq(b->board.irq, &b->board);
415 free_dma(b->board.chanA.rxdma);
416 free_dma(b->board.chanA.txdma);
417 /* DMA off on the card, drop DTR */
418 outb(0, b->iobase);
419 release_region(b->iobase, 8);
420 }
421
422 #ifdef MODULE
423
424 static int io=0x238;
425 static int txdma=1;
426 static int rxdma=3;
427 static int irq=5;
428 static int slow=0;
429
430 MODULE_PARM(io,"i");
431 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
432 MODULE_PARM(txdma,"i");
433 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
434 MODULE_PARM(rxdma,"i");
435 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
436 MODULE_PARM(irq,"i");
437 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
438 MODULE_PARM(slow,"i");
439 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
440
441 MODULE_AUTHOR("Alan Cox");
442 MODULE_LICENSE("GPL");
443 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
444
445 static struct slvl_board *slvl_unit;
446
init_module(void)447 int init_module(void)
448 {
449 printk(KERN_INFO "SeaLevel Z85230 Synchronous Driver v 0.01.\n");
450 printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
451 if((slvl_unit=slvl_init(io,irq, txdma, rxdma, slow))==NULL)
452 return -ENODEV;
453 return 0;
454 }
455
cleanup_module(void)456 void cleanup_module(void)
457 {
458 if(slvl_unit)
459 slvl_shutdown(slvl_unit);
460 }
461
462 #endif
463
464