Import 2.3.18pre1
[davej-history.git] / drivers / net / hostess_sv11.c
blob7b24901ce40ce1936b9e1276048f64c03656f488
1 #define LINUX_21
3 /*
4 * Comtrol SV11 card driver
6 * This is a slightly odd Z85230 synchronous driver. All you need to
7 * know basically is
9 * Its a genuine Z85230
11 * It supports DMA using two DMA channels in SYNC mode. The driver doesn't
12 * use these facilities
14 * The control port is at io+1, the data at io+3 and turning off the DMA
15 * is done by writing 0 to io+4
17 * The hardware does the bus handling to avoid the need for delays between
18 * touching control registers.
20 * Port B isnt wired (why - beats me)
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/mm.h>
26 #include <linux/net.h>
27 #include <linux/skbuff.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_arp.h>
30 #include <linux/delay.h>
31 #include <linux/ioport.h>
32 #include <net/arp.h>
34 #include <asm/io.h>
35 #include <asm/dma.h>
36 #include <asm/byteorder.h>
37 #include "syncppp.h"
38 #include "z85230.h"
40 static int dma;
42 struct sv11_device
44 struct z8530_dev sync;
45 struct ppp_device netdev;
46 char name[16];
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 hostess_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 hostess_open(struct net_device *d)
78 struct sv11_device *sv11=d->priv;
79 int err = -1;
82 * Link layer up
84 switch(dma)
86 case 0:
87 err=z8530_sync_open(d, &sv11->sync.chanA);
88 break;
89 case 1:
90 err=z8530_sync_dma_open(d, &sv11->sync.chanA);
91 break;
92 case 2:
93 err=z8530_sync_txdma_open(d, &sv11->sync.chanA);
94 break;
97 if(err)
98 return err;
100 * Begin PPP
102 err=sppp_open(d);
103 if(err)
105 switch(dma)
107 case 0:
108 z8530_sync_close(d, &sv11->sync.chanA);
109 break;
110 case 1:
111 z8530_sync_dma_close(d, &sv11->sync.chanA);
112 break;
113 case 2:
114 z8530_sync_txdma_close(d, &sv11->sync.chanA);
115 break;
117 return err;
119 sv11->sync.chanA.rx_function=hostess_input;
122 * Go go go
124 d->tbusy=0;
125 MOD_INC_USE_COUNT;
126 return 0;
129 static int hostess_close(struct net_device *d)
131 struct sv11_device *sv11=d->priv;
133 * Discard new frames
135 sv11->sync.chanA.rx_function=z8530_null_rx;
137 * PPP off
139 sppp_close(d);
141 * Link layer down
143 d->tbusy=1;
145 switch(dma)
147 case 0:
148 z8530_sync_close(d, &sv11->sync.chanA);
149 break;
150 case 1:
151 z8530_sync_dma_close(d, &sv11->sync.chanA);
152 break;
153 case 2:
154 z8530_sync_txdma_close(d, &sv11->sync.chanA);
155 break;
157 MOD_DEC_USE_COUNT;
158 return 0;
161 static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
163 /* struct sv11_device *sv11=d->priv;
164 z8530_ioctl(d,&sv11->sync.chanA,ifr,cmd) */
165 return sppp_do_ioctl(d, ifr,cmd);
168 static struct enet_statistics *hostess_get_stats(struct net_device *d)
170 struct sv11_device *sv11=d->priv;
171 if(sv11)
172 return z8530_get_stats(&sv11->sync.chanA);
173 else
174 return NULL;
178 * Passed PPP frames, fire them downwind.
181 static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d)
183 struct sv11_device *sv11=d->priv;
184 return z8530_queue_xmit(&sv11->sync.chanA, skb);
187 #ifdef LINUX_21
188 static int hostess_neigh_setup(struct neighbour *n)
190 if (n->nud_state == NUD_NONE) {
191 n->ops = &arp_broken_ops;
192 n->output = n->ops->output;
194 return 0;
197 static int hostess_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
199 if (p->tbl->family == AF_INET) {
200 p->neigh_setup = hostess_neigh_setup;
201 p->ucast_probes = 0;
202 p->mcast_probes = 0;
204 return 0;
207 #else
209 static int return_0(struct net_device *d)
211 return 0;
214 #endif
217 * Description block for a Comtrol Hostess SV11 card
220 static struct sv11_device *sv11_init(int iobase, int irq)
222 struct z8530_dev *dev;
223 struct sv11_device *sv;
224 int i;
225 unsigned long flags;
228 * Get the needed I/O space
231 if(check_region(iobase, 8))
233 printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", iobase);
234 return NULL;
236 request_region(iobase, 8, "Comtrol SV11");
238 sv=(struct sv11_device *)kmalloc(sizeof(struct sv11_device), GFP_KERNEL);
239 if(!sv)
240 goto fail3;
242 memset(sv, 0, sizeof(*sv));
244 dev=&sv->sync;
247 * Stuff in the I/O addressing
250 dev->active = 0;
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, SA_INTERRUPT, "Hostess SV/11", dev)<0)
266 printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
267 goto fail2;
270 dev->irq=irq;
271 dev->chanA.private=sv;
272 dev->chanA.netdevice=&sv->netdev.dev;
273 dev->chanA.dev=dev;
274 dev->chanB.dev=dev;
275 dev->name=sv->name;
277 if(dma)
280 * You can have DMA off or 1 and 3 thats the lot
281 * on the Comtrol.
283 dev->chanA.txdma=3;
284 dev->chanA.rxdma=1;
285 outb(0x03|0x08, iobase+4); /* DMA on */
286 if(request_dma(dev->chanA.txdma, "Hostess SV/11 (TX)")!=0)
287 goto fail;
289 if(dma==1)
291 if(request_dma(dev->chanA.rxdma, "Hostess SV/11 (RX)")!=0)
292 goto dmafail;
295 save_flags(flags);
296 cli();
299 * Begin normal initialise
302 if(z8530_init(dev)!=0)
304 printk(KERN_ERR "Z8530 series device not found.\n");
305 goto dmafail2;
307 z8530_channel_load(&dev->chanB, z8530_dead_port);
308 if(dev->type==Z85C30)
309 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
310 else
311 z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
313 restore_flags(flags);
317 * Now we can take the IRQ
320 for(i=0;i<999;i++)
322 sprintf(sv->name,"hdlc%d", i);
323 if(dev_get(sv->name)==NULL)
325 struct net_device *d=dev->chanA.netdevice;
328 * Initialise the PPP components
330 sppp_attach(&sv->netdev);
333 * Local fields
335 sprintf(sv->name,"hdlc%d", i);
337 d->name = sv->name;
338 d->base_addr = iobase;
339 d->irq = irq;
340 d->priv = sv;
341 d->init = NULL;
343 d->open = hostess_open;
344 d->stop = hostess_close;
345 d->hard_start_xmit = hostess_queue_xmit;
346 d->get_stats = hostess_get_stats;
347 d->set_multicast_list = NULL;
348 d->do_ioctl = hostess_ioctl;
349 #ifdef LINUX_21
350 d->neigh_setup = hostess_neigh_setup_dev;
351 dev_init_buffers(d);
352 #else
353 d->init = return_0;
354 #endif
355 d->set_mac_address = NULL;
357 if(register_netdev(d)==-1)
359 printk(KERN_ERR "%s: unable to register device.\n",
360 sv->name);
361 goto fail;
364 z8530_describe(dev, "I/O", iobase);
365 dev->active=1;
366 return sv;
369 dmafail2:
370 if(dma==1)
371 free_dma(dev->chanA.rxdma);
372 dmafail:
373 if(dma)
374 free_dma(dev->chanA.txdma);
375 fail:
376 free_irq(irq, dev);
377 fail2:
378 kfree(sv);
379 fail3:
380 release_region(iobase,8);
381 return NULL;
384 static void sv11_shutdown(struct sv11_device *dev)
386 sppp_detach(&dev->netdev.dev);
387 z8530_shutdown(&dev->sync);
388 unregister_netdev(&dev->netdev.dev);
389 free_irq(dev->sync.irq, dev);
390 if(dma)
392 if(dma==1)
393 free_dma(dev->sync.chanA.rxdma);
394 free_dma(dev->sync.chanA.txdma);
396 release_region(dev->sync.chanA.ctrlio-1, 8);
399 #ifdef MODULE
401 static int io=0x200;
402 static int irq=9;
404 #ifdef LINUX_21
405 MODULE_PARM(io,"i");
406 MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
407 MODULE_PARM(dma,"i");
408 MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
409 MODULE_PARM(irq,"i");
410 MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
412 MODULE_AUTHOR("Bulding Number Three Ltd");
413 MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
414 #endif
416 static struct sv11_device *sv11_unit;
418 int init_module(void)
420 printk(KERN_INFO "SV-11 Z85230 Synchronous Driver v 0.02.\n");
421 printk(KERN_INFO "(c) Copyright 1998, Building Number Three Ltd.\n");
422 if((sv11_unit=sv11_init(io,irq))==NULL)
423 return -ENODEV;
424 return 0;
427 void cleanup_module(void)
429 if(sv11_unit)
430 sv11_shutdown(sv11_unit);
433 #endif