2 * Comtrol SV11 card driver
4 * This is a slightly odd Z85230 synchronous driver. All you need to
9 * It supports DMA using two DMA channels in SYNC mode. The driver doesn't
10 * use these facilities
12 * The control port is at io+1, the data at io+3 and turning off the DMA
13 * is done by writing 0 to io+4
15 * The hardware does the bus handling to avoid the need for delays between
16 * touching control registers.
18 * Port B isnt wired (why - beats me)
21 #include <linux/module.h>
22 #include <linux/kernel.h>
24 #include <linux/net.h>
25 #include <linux/skbuff.h>
26 #include <linux/netdevice.h>
27 #include <linux/if_arp.h>
28 #include <linux/delay.h>
29 #include <linux/ioport.h>
35 #include <asm/byteorder.h>
36 #include <net/syncppp.h>
43 void *if_ptr; /* General purpose pointer (used by SPPP) */
44 struct z8530_dev sync;
45 struct ppp_device netdev;
49 * Network driver support routines
53 * Frame receive. Simple for our card as we do sync ppp and there
54 * is no funny garbage involved
57 static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
59 /* Drop the CRC - it's not a good idea to try and negotiate it ;) */
60 skb_trim(skb, skb->len-2);
61 skb->protocol=__constant_htons(ETH_P_WAN_PPP);
62 skb_reset_mac_header(skb);
63 skb->dev=c->netdevice;
65 * Send it to the PPP layer. We don't have time to process
69 c->netdevice->last_rx = jiffies;
73 * We've been placed in the UP state
76 static int hostess_open(struct net_device *d)
78 struct sv11_device *sv11=d->priv;
87 err=z8530_sync_open(d, &sv11->sync.chanA);
90 err=z8530_sync_dma_open(d, &sv11->sync.chanA);
93 err=z8530_sync_txdma_open(d, &sv11->sync.chanA);
108 z8530_sync_close(d, &sv11->sync.chanA);
111 z8530_sync_dma_close(d, &sv11->sync.chanA);
114 z8530_sync_txdma_close(d, &sv11->sync.chanA);
119 sv11->sync.chanA.rx_function=hostess_input;
125 netif_start_queue(d);
129 static int hostess_close(struct net_device *d)
131 struct sv11_device *sv11=d->priv;
135 sv11->sync.chanA.rx_function=z8530_null_rx;
148 z8530_sync_close(d, &sv11->sync.chanA);
151 z8530_sync_dma_close(d, &sv11->sync.chanA);
154 z8530_sync_txdma_close(d, &sv11->sync.chanA);
160 static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
162 /* struct sv11_device *sv11=d->priv;
163 z8530_ioctl(d,&sv11->sync.chanA,ifr,cmd) */
164 return sppp_do_ioctl(d, ifr,cmd);
167 static struct net_device_stats *hostess_get_stats(struct net_device *d)
169 struct sv11_device *sv11=d->priv;
171 return z8530_get_stats(&sv11->sync.chanA);
177 * Passed PPP frames, fire them downwind.
180 static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d)
182 struct sv11_device *sv11=d->priv;
183 return z8530_queue_xmit(&sv11->sync.chanA, skb);
186 static int hostess_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 hostess_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
197 if (p->tbl->family == AF_INET) {
198 p->neigh_setup = hostess_neigh_setup;
205 static void sv11_setup(struct net_device *dev)
207 dev->open = hostess_open;
208 dev->stop = hostess_close;
209 dev->hard_start_xmit = hostess_queue_xmit;
210 dev->get_stats = hostess_get_stats;
211 dev->do_ioctl = hostess_ioctl;
212 dev->neigh_setup = hostess_neigh_setup_dev;
216 * Description block for a Comtrol Hostess SV11 card
219 static struct sv11_device *sv11_init(int iobase, int irq)
221 struct z8530_dev *dev;
222 struct sv11_device *sv;
225 * Get the needed I/O space
228 if(!request_region(iobase, 8, "Comtrol SV11"))
230 printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", iobase);
234 sv = kzalloc(sizeof(struct sv11_device), GFP_KERNEL);
238 sv->if_ptr=&sv->netdev;
240 sv->netdev.dev = alloc_netdev(0, "hdlc%d", sv11_setup);
247 * Stuff in the I/O addressing
252 dev->chanA.ctrlio=iobase+1;
253 dev->chanA.dataio=iobase+3;
254 dev->chanB.ctrlio=-1;
255 dev->chanB.dataio=-1;
256 dev->chanA.irqs=&z8530_nop;
257 dev->chanB.irqs=&z8530_nop;
259 outb(0, iobase+4); /* DMA off */
261 /* We want a fast IRQ for this device. Actually we'd like an even faster
262 IRQ ;) - This is one driver RtLinux is made for */
264 if(request_irq(irq, &z8530_interrupt, IRQF_DISABLED, "Hostess SV11", dev)<0)
266 printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
271 dev->chanA.private=sv;
272 dev->chanA.netdevice=sv->netdev.dev;
279 * You can have DMA off or 1 and 3 thats the lot
284 outb(0x03|0x08, iobase+4); /* DMA on */
285 if(request_dma(dev->chanA.txdma, "Hostess SV/11 (TX)")!=0)
290 if(request_dma(dev->chanA.rxdma, "Hostess SV/11 (RX)")!=0)
295 /* Kill our private IRQ line the hostess can end up chattering
296 until the configuration is set */
300 * Begin normal initialise
303 if(z8530_init(dev)!=0)
305 printk(KERN_ERR "Z8530 series device not found.\n");
309 z8530_channel_load(&dev->chanB, z8530_dead_port);
310 if(dev->type==Z85C30)
311 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
313 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
319 * Now we can take the IRQ
321 if(dev_alloc_name(dev->chanA.netdevice,"hdlc%d")>=0)
323 struct net_device *d=dev->chanA.netdevice;
326 * Initialise the PPP components
328 sppp_attach(&sv->netdev);
334 d->base_addr = iobase;
338 if(register_netdev(d))
340 printk(KERN_ERR "%s: unable to register device.\n",
346 z8530_describe(dev, "I/O", iobase);
352 free_dma(dev->chanA.rxdma);
355 free_dma(dev->chanA.txdma);
359 free_netdev(sv->netdev.dev);
363 release_region(iobase,8);
367 static void sv11_shutdown(struct sv11_device *dev)
369 sppp_detach(dev->netdev.dev);
370 unregister_netdev(dev->netdev.dev);
371 z8530_shutdown(&dev->sync);
372 free_irq(dev->sync.irq, dev);
376 free_dma(dev->sync.chanA.rxdma);
377 free_dma(dev->sync.chanA.txdma);
379 release_region(dev->sync.chanA.ctrlio-1, 8);
380 free_netdev(dev->netdev.dev);
389 module_param(io, int, 0);
390 MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
391 module_param(dma, int, 0);
392 MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
393 module_param(irq, int, 0);
394 MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
396 MODULE_AUTHOR("Alan Cox");
397 MODULE_LICENSE("GPL");
398 MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
400 static struct sv11_device *sv11_unit;
402 int init_module(void)
404 printk(KERN_INFO "SV-11 Z85230 Synchronous Driver v 0.03.\n");
405 printk(KERN_INFO "(c) Copyright 2001, Red Hat Inc.\n");
406 if((sv11_unit=sv11_init(io,irq))==NULL)
411 void cleanup_module(void)
414 sv11_shutdown(sv11_unit);