Import 2.3.18pre1
[davej-history.git] / drivers / net / sealevel.c
blob1dc146711dfd8fe52a7187930d104cfbf464d386
1 #define LINUX_21
3 /*
4 * Sealevel Systems 4021 driver.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * (c) Copyright 1999 Building Number Three Ltd
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/net.h>
19 #include <linux/skbuff.h>
20 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/delay.h>
23 #include <linux/ioport.h>
24 #include <net/arp.h>
26 #include <asm/io.h>
27 #include <asm/dma.h>
28 #include <asm/byteorder.h>
29 #include "syncppp.h"
30 #include "z85230.h"
33 struct slvl_device
35 struct z8530_channel *chan;
36 struct ppp_device netdev;
37 char name[16];
38 int channel;
42 struct slvl_board
44 struct slvl_device dev[2];
45 struct z8530_dev board;
46 int iobase;
50 * Network driver support routines
54 * Frame receive. Simple for our card as we do sync ppp and there
55 * is no funny garbage involved
58 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
60 /* Drop the CRC - its not a good idea to try and negotiate it ;) */
61 skb_trim(skb, skb->len-2);
62 skb->protocol=htons(ETH_P_WAN_PPP);
63 skb->mac.raw=skb->data;
64 skb->dev=c->netdevice;
66 * Send it to the PPP layer. We dont have time to process
67 * it right now.
69 netif_rx(skb);
73 * We've been placed in the UP state
74 */
76 static int sealevel_open(struct net_device *d)
78 struct slvl_device *slvl=d->priv;
79 int err = -1;
80 int unit = slvl->channel;
83 * Link layer up.
86 switch(unit)
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;
96 if(err)
97 return err;
99 * Begin PPP
101 err=sppp_open(d);
102 if(err)
104 switch(unit)
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;
113 return err;
116 slvl->chan->rx_function=sealevel_input;
119 * Go go go
121 d->tbusy=0;
122 MOD_INC_USE_COUNT;
123 return 0;
126 static int sealevel_close(struct net_device *d)
128 struct slvl_device *slvl=d->priv;
129 int unit = slvl->channel;
132 * Discard new frames
135 slvl->chan->rx_function=z8530_null_rx;
138 * PPP off
140 sppp_close(d);
142 * Link layer down
144 d->tbusy=1;
146 switch(unit)
148 case 0:
149 z8530_sync_dma_close(d, slvl->chan);
150 break;
151 case 1:
152 z8530_sync_close(d, slvl->chan);
153 break;
155 MOD_DEC_USE_COUNT;
156 return 0;
159 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
161 /* struct slvl_device *slvl=d->priv;
162 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
163 return sppp_do_ioctl(d, ifr,cmd);
166 static struct enet_statistics *sealevel_get_stats(struct net_device *d)
168 struct slvl_device *slvl=d->priv;
169 if(slvl)
170 return z8530_get_stats(slvl->chan);
171 else
172 return NULL;
176 * Passed PPP frames, fire them downwind.
179 static int sealevel_queue_xmit(struct sk_buff *skb, struct net_device *d)
181 struct slvl_device *slvl=d->priv;
182 return z8530_queue_xmit(slvl->chan, skb);
185 #ifdef LINUX_21
186 static int sealevel_neigh_setup(struct neighbour *n)
188 if (n->nud_state == NUD_NONE) {
189 n->ops = &arp_broken_ops;
190 n->output = n->ops->output;
192 return 0;
195 static int sealevel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
197 if (p->tbl->family == AF_INET) {
198 p->neigh_setup = sealevel_neigh_setup;
199 p->ucast_probes = 0;
200 p->mcast_probes = 0;
202 return 0;
205 #else
207 static int return_0(struct net_device *d)
209 return 0;
212 #endif
215 * Description block for a Comtrol Hostess SV11 card
218 static struct slvl_board *slvl_init(int iobase, int irq, int txdma, int rxdma, int slow)
220 struct z8530_dev *dev;
221 struct slvl_device *sv;
222 struct slvl_board *b;
224 int i;
225 unsigned long flags;
226 int u;
229 * Get the needed I/O space
232 if(check_region(iobase, 8))
234 printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n", iobase);
235 return NULL;
237 request_region(iobase, 8, "Sealevel 4021");
239 b=(struct slvl_board *)kmalloc(sizeof(struct slvl_board), GFP_KERNEL);
240 if(!b)
241 goto fail3;
243 memset(b, 0, sizeof(*sv));
245 b->dev[0].chan = &b->board.chanA;
246 b->dev[1].chan = &b->board.chanB;
248 dev=&b->board;
251 * Stuff in the I/O addressing
254 dev->active = 0;
256 b->iobase = iobase;
259 * Select 8530 delays for the old board
262 if(slow)
263 iobase |= Z8530_PORT_SLEEP;
265 dev->chanA.ctrlio=iobase+1;
266 dev->chanA.dataio=iobase;
267 dev->chanB.ctrlio=iobase+3;
268 dev->chanB.dataio=iobase+2;
270 dev->chanA.irqs=&z8530_nop;
271 dev->chanB.irqs=&z8530_nop;
274 * Assert DTR enable DMA
277 outb(3|(1<<7), b->iobase+4);
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 */
283 if(request_irq(irq, &z8530_interrupt, SA_INTERRUPT, "SeaLevel", dev)<0)
285 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
286 goto fail2;
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 dev->name=b->dev[0].name;
298 dev->chanA.txdma=3;
299 dev->chanA.rxdma=1;
300 if(request_dma(dev->chanA.txdma, "SeaLevel (TX)")!=0)
301 goto fail;
303 if(request_dma(dev->chanA.rxdma, "SeaLevel (RX)")!=0)
304 goto dmafail;
306 save_flags(flags);
307 cli();
310 * Begin normal initialise
313 if(z8530_init(dev)!=0)
315 printk(KERN_ERR "Z8530 series device not found.\n");
316 goto dmafail2;
318 if(dev->type==Z85C30)
320 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
321 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
323 else
325 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
326 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
330 * Now we can take the IRQ
333 restore_flags(flags);
335 for(u=0; u<2; u++)
337 sv=&b->dev[u];
338 sv->channel = u;
340 for(i=0;i<999;i++)
342 sprintf(sv->name,"hdlc%d", i);
343 if(dev_get(sv->name)==NULL)
345 struct net_device *d=sv->chan->netdevice;
348 * Initialise the PPP components
350 sppp_attach(&sv->netdev);
353 * Local fields
355 sprintf(sv->name,"hdlc%d", i);
357 d->name = sv->name;
358 d->base_addr = iobase;
359 d->irq = irq;
360 d->priv = sv;
361 d->init = NULL;
363 d->open = sealevel_open;
364 d->stop = sealevel_close;
365 d->hard_start_xmit = sealevel_queue_xmit;
366 d->get_stats = sealevel_get_stats;
367 d->set_multicast_list = NULL;
368 d->do_ioctl = sealevel_ioctl;
369 #ifdef LINUX_21
370 d->neigh_setup = sealevel_neigh_setup_dev;
371 dev_init_buffers(d);
372 #else
373 d->init = return_0;
374 #endif
375 d->set_mac_address = NULL;
377 if(register_netdev(d)==-1)
379 printk(KERN_ERR "%s: unable to register device.\n",
380 sv->name);
381 goto fail_unit;
384 break;
388 z8530_describe(dev, "I/O", iobase);
389 dev->active=1;
390 return b;
392 fail_unit:
393 if(u==1)
394 unregister_netdev(b->dev[0].chan->netdevice);
396 dmafail2:
397 free_dma(dev->chanA.rxdma);
398 dmafail:
399 free_dma(dev->chanA.txdma);
400 fail:
401 free_irq(irq, dev);
402 fail2:
403 kfree(b);
404 fail3:
405 release_region(iobase,8);
406 return NULL;
409 static void slvl_shutdown(struct slvl_board *b)
411 int u;
413 z8530_shutdown(&b->board);
415 for(u=0; u<2; u++)
417 sppp_detach(&b->dev[u].netdev.dev);
418 unregister_netdev(&b->dev[u].netdev.dev);
421 free_irq(b->board.irq, &b->board);
422 free_dma(b->board.chanA.rxdma);
423 free_dma(b->board.chanA.txdma);
424 /* DMA off on the card, drop DTR */
425 outb(0, b->iobase);
426 release_region(b->iobase, 8);
429 #ifdef MODULE
431 static int io=0x238;
432 static int txdma=1;
433 static int rxdma=3;
434 static int irq=5;
435 static int slow=0;
437 #ifdef LINUX_21
438 MODULE_PARM(io,"i");
439 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
440 MODULE_PARM(txdma,"i");
441 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
442 MODULE_PARM(rxdma,"i");
443 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
444 MODULE_PARM(irq,"i");
445 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
446 MODULE_PARM(slow,"i");
447 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
449 MODULE_AUTHOR("Bulding Number Three Ltd");
450 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
451 #endif
453 static struct slvl_board *slvl_unit;
455 int init_module(void)
457 printk(KERN_INFO "SeaLevel Z85230 Synchronous Driver v 0.01.\n");
458 printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
459 if((slvl_unit=slvl_init(io,irq, txdma, rxdma, slow))==NULL)
460 return -ENODEV;
461 return 0;
464 void cleanup_module(void)
466 if(slvl_unit)
467 slvl_shutdown(slvl_unit);
470 #endif