2 * Sealevel Systems 4021 driver.
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.
9 * (c) Copyright 1999, 2001 Alan Cox
10 * (c) Copyright 2001 Red Hat Inc.
14 #include <linux/module.h>
15 #include <linux/kernel.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 <linux/init.h>
29 #include <asm/byteorder.h>
30 #include <net/syncppp.h>
36 void *if_ptr; /* General purpose pointer (used by SPPP) */
37 struct z8530_channel *chan;
38 struct ppp_device pppdev;
45 struct slvl_device *dev[2];
46 struct z8530_dev board;
51 * Network driver support routines
55 * Frame receive. Simple for our card as we do sync ppp and there
56 * is no funny garbage involved
59 static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb)
61 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
62 skb_trim(skb, skb->len-2);
63 skb->protocol=htons(ETH_P_WAN_PPP);
64 skb_reset_mac_header(skb);
65 skb->dev=c->netdevice;
67 * Send it to the PPP layer. We don't have time to process
71 c->netdevice->last_rx = jiffies;
75 * We've been placed in the UP state
78 static int sealevel_open(struct net_device *d)
80 struct slvl_device *slvl=d->priv;
82 int unit = slvl->channel;
91 err=z8530_sync_dma_open(d, slvl->chan);
94 err=z8530_sync_open(d, slvl->chan);
109 z8530_sync_dma_close(d, slvl->chan);
112 z8530_sync_close(d, slvl->chan);
118 slvl->chan->rx_function=sealevel_input;
123 netif_start_queue(d);
127 static int sealevel_close(struct net_device *d)
129 struct slvl_device *slvl=d->priv;
130 int unit = slvl->channel;
136 slvl->chan->rx_function=z8530_null_rx;
151 z8530_sync_dma_close(d, slvl->chan);
154 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);
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;
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;
205 static int sealevel_attach(struct net_device *dev)
207 struct slvl_device *sv = dev->priv;
208 sppp_attach(&sv->pppdev);
212 static void sealevel_detach(struct net_device *dev)
217 static void slvl_setup(struct net_device *d)
219 d->open = sealevel_open;
220 d->stop = sealevel_close;
221 d->init = sealevel_attach;
222 d->uninit = sealevel_detach;
223 d->hard_start_xmit = sealevel_queue_xmit;
224 d->get_stats = sealevel_get_stats;
225 d->set_multicast_list = NULL;
226 d->do_ioctl = sealevel_ioctl;
227 d->neigh_setup = sealevel_neigh_setup_dev;
228 d->set_mac_address = NULL;
232 static inline struct slvl_device *slvl_alloc(int iobase, int irq)
234 struct net_device *d;
235 struct slvl_device *sv;
237 d = alloc_netdev(sizeof(struct slvl_device), "hdlc%d",
244 sv->if_ptr = &sv->pppdev;
246 d->base_addr = iobase;
254 * Allocate and setup Sealevel board.
257 static __init struct slvl_board *slvl_init(int iobase, int irq,
258 int txdma, int rxdma, int slow)
260 struct z8530_dev *dev;
261 struct slvl_board *b;
264 * Get the needed I/O space
267 if(!request_region(iobase, 8, "Sealevel 4021"))
269 printk(KERN_WARNING "sealevel: I/O 0x%X already in use.\n", iobase);
273 b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
277 if (!(b->dev[0]= slvl_alloc(iobase, irq)))
280 b->dev[0]->chan = &b->board.chanA;
281 b->dev[0]->channel = 0;
283 if (!(b->dev[1] = slvl_alloc(iobase, irq)))
286 b->dev[1]->chan = &b->board.chanB;
287 b->dev[1]->channel = 1;
292 * Stuff in the I/O addressing
300 * Select 8530 delays for the old board
304 iobase |= Z8530_PORT_SLEEP;
306 dev->chanA.ctrlio=iobase+1;
307 dev->chanA.dataio=iobase;
308 dev->chanB.ctrlio=iobase+3;
309 dev->chanB.dataio=iobase+2;
311 dev->chanA.irqs=&z8530_nop;
312 dev->chanB.irqs=&z8530_nop;
315 * Assert DTR enable DMA
318 outb(3|(1<<7), b->iobase+4);
321 /* We want a fast IRQ for this device. Actually we'd like an even faster
322 IRQ ;) - This is one driver RtLinux is made for */
324 if(request_irq(irq, &z8530_interrupt, IRQF_DISABLED, "SeaLevel", dev)<0)
326 printk(KERN_WARNING "sealevel: IRQ %d already in use.\n", irq);
331 dev->chanA.private=&b->dev[0];
332 dev->chanB.private=&b->dev[1];
333 dev->chanA.netdevice=b->dev[0]->pppdev.dev;
334 dev->chanB.netdevice=b->dev[1]->pppdev.dev;
340 if(request_dma(dev->chanA.txdma, "SeaLevel (TX)")!=0)
343 if(request_dma(dev->chanA.rxdma, "SeaLevel (RX)")!=0)
349 * Begin normal initialise
352 if(z8530_init(dev)!=0)
354 printk(KERN_ERR "Z8530 series device not found.\n");
358 if(dev->type==Z85C30)
360 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
361 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream);
365 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
366 z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230);
370 * Now we can take the IRQ
375 if (register_netdev(b->dev[0]->pppdev.dev))
378 if (register_netdev(b->dev[1]->pppdev.dev))
381 z8530_describe(dev, "I/O", iobase);
386 unregister_netdev(b->dev[0]->pppdev.dev);
389 free_dma(dev->chanA.rxdma);
391 free_dma(dev->chanA.txdma);
395 free_netdev(b->dev[1]->pppdev.dev);
397 free_netdev(b->dev[0]->pppdev.dev);
401 release_region(iobase,8);
405 static void __exit slvl_shutdown(struct slvl_board *b)
409 z8530_shutdown(&b->board);
413 struct net_device *d = b->dev[u]->pppdev.dev;
414 unregister_netdev(d);
418 free_irq(b->board.irq, &b->board);
419 free_dma(b->board.chanA.rxdma);
420 free_dma(b->board.chanA.txdma);
421 /* DMA off on the card, drop DTR */
423 release_region(b->iobase, 8);
434 module_param(io, int, 0);
435 MODULE_PARM_DESC(io, "The I/O base of the Sealevel card");
436 module_param(txdma, int, 0);
437 MODULE_PARM_DESC(txdma, "Transmit DMA channel");
438 module_param(rxdma, int, 0);
439 MODULE_PARM_DESC(rxdma, "Receive DMA channel");
440 module_param(irq, int, 0);
441 MODULE_PARM_DESC(irq, "The interrupt line setting for the SeaLevel card");
442 module_param(slow, bool, 0);
443 MODULE_PARM_DESC(slow, "Set this for an older Sealevel card such as the 4012");
445 MODULE_AUTHOR("Alan Cox");
446 MODULE_LICENSE("GPL");
447 MODULE_DESCRIPTION("Modular driver for the SeaLevel 4021");
449 static struct slvl_board *slvl_unit;
451 static int __init slvl_init_module(void)
454 printk(KERN_INFO "SeaLevel Z85230 Synchronous Driver v 0.02.\n");
455 printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
457 slvl_unit = slvl_init(io, irq, txdma, rxdma, slow);
459 return slvl_unit ? 0 : -ENODEV;
462 static void __exit slvl_cleanup_module(void)
465 slvl_shutdown(slvl_unit);
468 module_init(slvl_init_module);
469 module_exit(slvl_cleanup_module);