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>
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>
28 #include <asm/byteorder.h>
35 void *if_ptr; /* General purpose pointer (used by SPPP) */
36 struct z8530_channel *chan;
37 struct ppp_device netdev;
44 struct slvl_device dev[2];
45 struct z8530_dev board;
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
73 * We've been placed in the UP state
76 static int sealevel_open(struct net_device *d)
78 struct slvl_device *slvl=d->priv;
80 int unit = slvl->channel;
89 err=z8530_sync_dma_open(d, slvl->chan);
92 err=z8530_sync_open(d, slvl->chan);
107 z8530_sync_dma_close(d, slvl->chan);
110 z8530_sync_close(d, slvl->chan);
116 slvl->chan->rx_function=sealevel_input;
121 netif_start_queue(d);
126 static int sealevel_close(struct net_device *d)
128 struct slvl_device *slvl=d->priv;
129 int unit = slvl->channel;
135 slvl->chan->rx_function=z8530_null_rx;
150 z8530_sync_dma_close(d, slvl->chan);
153 z8530_sync_close(d, slvl->chan);
160 static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
162 /* struct slvl_device *slvl=d->priv;
163 z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */
164 return sppp_do_ioctl(d, ifr,cmd);
167 static struct net_device_stats *sealevel_get_stats(struct net_device *d)
169 struct slvl_device *slvl=d->priv;
171 return z8530_get_stats(slvl->chan);
177 * Passed PPP frames, fire them downwind.
180 static int sealevel_queue_xmit(struct sk_buff *skb, struct net_device *d)
182 struct slvl_device *slvl=d->priv;
183 return z8530_queue_xmit(slvl->chan, skb);
187 static int sealevel_neigh_setup(struct neighbour *n)
189 if (n->nud_state == NUD_NONE) {
190 n->ops = &arp_broken_ops;
191 n->output = n->ops->output;
196 static int sealevel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
198 if (p->tbl->family == AF_INET) {
199 p->neigh_setup = sealevel_neigh_setup;
208 static int return_0(struct net_device *d)
216 * Description block for a Comtrol Hostess SV11 card
219 static struct slvl_board *slvl_init(int iobase, int irq, int txdma, int rxdma, int slow)
221 struct z8530_dev *dev;
222 struct slvl_device *sv;
223 struct slvl_board *b;
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);
237 request_region(iobase, 8, "Sealevel 4021");
239 b=(struct slvl_board *)kmalloc(sizeof(struct slvl_board), GFP_KERNEL);
243 memset(b, 0, sizeof(*sv));
245 b->dev[0].chan = &b->board.chanA;
246 b->dev[0].if_ptr = &b->dev[0].netdev;
247 b->dev[0].netdev.dev=(struct net_device *)
248 kmalloc(sizeof(struct net_device), GFP_KERNEL);
249 if(!b->dev[0].netdev.dev)
252 b->dev[1].chan = &b->board.chanB;
253 b->dev[1].if_ptr = &b->dev[1].netdev;
254 b->dev[1].netdev.dev=(struct net_device *)
255 kmalloc(sizeof(struct net_device), GFP_KERNEL);
256 if(!b->dev[1].netdev.dev)
262 * Stuff in the I/O addressing
270 * Select 8530 delays for the old board
274 iobase |= Z8530_PORT_SLEEP;
276 dev->chanA.ctrlio=iobase+1;
277 dev->chanA.dataio=iobase;
278 dev->chanB.ctrlio=iobase+3;
279 dev->chanB.dataio=iobase+2;
281 dev->chanA.irqs=&z8530_nop;
282 dev->chanB.irqs=&z8530_nop;
285 * Assert DTR enable DMA
288 outb(3|(1<<7), b->iobase+4);
291 /* We want a fast IRQ for this device. Actually we'd like an even faster
292 IRQ ;) - This is one driver RtLinux is made for */
294 if(request_irq(irq, &z8530_interrupt, SA_INTERRUPT, "SeaLevel", dev)<0)
296 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
301 dev->chanA.private=&b->dev[0];
302 dev->chanB.private=&b->dev[1];
303 dev->chanA.netdevice=b->dev[0].netdev.dev;
304 dev->chanB.netdevice=b->dev[1].netdev.dev;
310 if(request_dma(dev->chanA.txdma, "SeaLevel (TX)")!=0)
313 if(request_dma(dev->chanA.rxdma, "SeaLevel (RX)")!=0)
320 * Begin normal initialise
323 if(z8530_init(dev)!=0)
325 printk(KERN_ERR "Z8530 series device not found.\n");
326 restore_flags(flags);
329 if(dev->type==Z85C30)
331 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
332 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
336 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
337 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
341 * Now we can take the IRQ
344 restore_flags(flags);
351 if(dev_alloc_name(sv->chan->netdevice,"hdlc%d")>=0)
353 struct net_device *d=sv->chan->netdevice;
356 * Initialise the PPP components
358 sppp_attach(&sv->netdev);
364 d->base_addr = iobase;
369 d->open = sealevel_open;
370 d->stop = sealevel_close;
371 d->hard_start_xmit = sealevel_queue_xmit;
372 d->get_stats = sealevel_get_stats;
373 d->set_multicast_list = NULL;
374 d->do_ioctl = sealevel_ioctl;
376 d->neigh_setup = sealevel_neigh_setup_dev;
381 d->set_mac_address = NULL;
383 if(register_netdev(d)==-1)
385 printk(KERN_ERR "%s: unable to register device.\n",
393 z8530_describe(dev, "I/O", iobase);
399 unregister_netdev(b->dev[0].chan->netdevice);
402 free_dma(dev->chanA.rxdma);
404 free_dma(dev->chanA.txdma);
408 kfree(b->dev[1].netdev.dev);
410 kfree(b->dev[0].netdev.dev);
414 release_region(iobase,8);
418 static void slvl_shutdown(struct slvl_board *b)
422 z8530_shutdown(&b->board);
426 sppp_detach(b->dev[u].netdev.dev);
427 unregister_netdev(b->dev[u].netdev.dev);
430 free_irq(b->board.irq, &b->board);
431 free_dma(b->board.chanA.rxdma);
432 free_dma(b->board.chanA.txdma);
433 /* DMA off on the card, drop DTR */
435 release_region(b->iobase, 8);
448 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
449 MODULE_PARM(txdma,"i");
450 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
451 MODULE_PARM(rxdma,"i");
452 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
453 MODULE_PARM(irq,"i");
454 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
455 MODULE_PARM(slow,"i");
456 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
458 MODULE_AUTHOR("Bulding Number Three Ltd");
459 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
462 static struct slvl_board *slvl_unit;
464 int init_module(void)
466 printk(KERN_INFO "SeaLevel Z85230 Synchronous Driver v 0.01.\n");
467 printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
468 if((slvl_unit=slvl_init(io,irq, txdma, rxdma, slow))==NULL)
473 void cleanup_module(void)
476 slvl_shutdown(slvl_unit);