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 struct z8530_channel
*chan
;
36 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
;
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
;
149 z8530_sync_dma_close(d
, slvl
->chan
);
152 z8530_sync_close(d
, slvl
->chan
);
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
;
170 return z8530_get_stats(slvl
->chan
);
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
);
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
;
207 static int return_0(struct net_device
*d
)
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
;
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
[1].chan
= &b
->board
.chanB
;
251 * Stuff in the I/O addressing
259 * Select 8530 delays for the old board
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
);
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
;
296 dev
->name
=b
->dev
[0].name
;
300 if(request_dma(dev
->chanA
.txdma
, "SeaLevel (TX)")!=0)
303 if(request_dma(dev
->chanA
.rxdma
, "SeaLevel (RX)")!=0)
310 * Begin normal initialise
313 if(z8530_init(dev
)!=0)
315 printk(KERN_ERR
"Z8530 series device not found.\n");
318 if(dev
->type
==Z85C30
)
320 z8530_channel_load(&dev
->chanA
, z8530_hdlc_kilostream
);
321 z8530_channel_load(&dev
->chanB
, z8530_hdlc_kilostream
);
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
);
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
);
355 sprintf(sv
->name
,"hdlc%d", i
);
358 d
->base_addr
= iobase
;
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
;
370 d
->neigh_setup
= sealevel_neigh_setup_dev
;
375 d
->set_mac_address
= NULL
;
377 if(register_netdev(d
)==-1)
379 printk(KERN_ERR
"%s: unable to register device.\n",
388 z8530_describe(dev
, "I/O", iobase
);
394 unregister_netdev(b
->dev
[0].chan
->netdevice
);
397 free_dma(dev
->chanA
.rxdma
);
399 free_dma(dev
->chanA
.txdma
);
405 release_region(iobase
,8);
409 static void slvl_shutdown(struct slvl_board
*b
)
413 z8530_shutdown(&b
->board
);
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 */
426 release_region(b
->iobase
, 8);
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");
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
)
464 void cleanup_module(void)
467 slvl_shutdown(slvl_unit
);