OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [wan/] [hostess_sv11.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *      Comtrol SV11 card driver
3
 *
4
 *      This is a slightly odd Z85230 synchronous driver. All you need to
5
 *      know basically is
6
 *
7
 *      Its a genuine Z85230
8
 *
9
 *      It supports DMA using two DMA channels in SYNC mode. The driver doesn't
10
 *      use these facilities
11
 *
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
14
 *
15
 *      The hardware does the bus handling to avoid the need for delays between
16
 *      touching control registers.
17
 *
18
 *      Port B isnt wired (why - beats me)
19
 */
20
 
21
#include <linux/module.h>
22
#include <linux/kernel.h>
23
#include <linux/mm.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>
30
#include <net/arp.h>
31
 
32
#include <asm/io.h>
33
#include <asm/dma.h>
34
#include <asm/byteorder.h>
35
#include <net/syncppp.h>
36
#include "z85230.h"
37
 
38
static int dma;
39
 
40
struct sv11_device
41
{
42
        void *if_ptr;   /* General purpose pointer (used by SPPP) */
43
        struct z8530_dev sync;
44
        struct ppp_device netdev;
45
};
46
 
47
/*
48
 *      Network driver support routines
49
 */
50
 
51
/*
52
 *      Frame receive. Simple for our card as we do sync ppp and there
53
 *      is no funny garbage involved
54
 */
55
 
56
static void hostess_input(struct z8530_channel *c, struct sk_buff *skb)
57
{
58
        /* Drop the CRC - its not a good idea to try and negotiate it ;) */
59
        skb_trim(skb, skb->len-2);
60
        skb->protocol=__constant_htons(ETH_P_WAN_PPP);
61
        skb->mac.raw=skb->data;
62
        skb->dev=c->netdevice;
63
        /*
64
         *      Send it to the PPP layer. We dont have time to process
65
         *      it right now.
66
         */
67
        netif_rx(skb);
68
        c->netdevice->last_rx = jiffies;
69
}
70
 
71
/*
72
 *      We've been placed in the UP state
73
 */
74
 
75
static int hostess_open(struct net_device *d)
76
{
77
        struct sv11_device *sv11=d->priv;
78
        int err = -1;
79
 
80
        /*
81
         *      Link layer up
82
         */
83
        switch(dma)
84
        {
85
                case 0:
86
                        err=z8530_sync_open(d, &sv11->sync.chanA);
87
                        break;
88
                case 1:
89
                        err=z8530_sync_dma_open(d, &sv11->sync.chanA);
90
                        break;
91
                case 2:
92
                        err=z8530_sync_txdma_open(d, &sv11->sync.chanA);
93
                        break;
94
        }
95
 
96
        if(err)
97
                return err;
98
        /*
99
         *      Begin PPP
100
         */
101
        err=sppp_open(d);
102
        if(err)
103
        {
104
                switch(dma)
105
                {
106
                        case 0:
107
                                z8530_sync_close(d, &sv11->sync.chanA);
108
                                break;
109
                        case 1:
110
                                z8530_sync_dma_close(d, &sv11->sync.chanA);
111
                                break;
112
                        case 2:
113
                                z8530_sync_txdma_close(d, &sv11->sync.chanA);
114
                                break;
115
                }
116
                return err;
117
        }
118
        sv11->sync.chanA.rx_function=hostess_input;
119
 
120
        /*
121
         *      Go go go
122
         */
123
 
124
        netif_start_queue(d);
125
        MOD_INC_USE_COUNT;
126
        return 0;
127
}
128
 
129
static int hostess_close(struct net_device *d)
130
{
131
        struct sv11_device *sv11=d->priv;
132
        /*
133
         *      Discard new frames
134
         */
135
        sv11->sync.chanA.rx_function=z8530_null_rx;
136
        /*
137
         *      PPP off
138
         */
139
        sppp_close(d);
140
        /*
141
         *      Link layer down
142
         */
143
        netif_stop_queue(d);
144
 
145
        switch(dma)
146
        {
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;
156
        }
157
        MOD_DEC_USE_COUNT;
158
        return 0;
159
}
160
 
161
static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd)
162
{
163
        /* struct sv11_device *sv11=d->priv;
164
           z8530_ioctl(d,&sv11->sync.chanA,ifr,cmd) */
165
        return sppp_do_ioctl(d, ifr,cmd);
166
}
167
 
168
static struct net_device_stats *hostess_get_stats(struct net_device *d)
169
{
170
        struct sv11_device *sv11=d->priv;
171
        if(sv11)
172
                return z8530_get_stats(&sv11->sync.chanA);
173
        else
174
                return NULL;
175
}
176
 
177
/*
178
 *      Passed PPP frames, fire them downwind.
179
 */
180
 
181
static int hostess_queue_xmit(struct sk_buff *skb, struct net_device *d)
182
{
183
        struct sv11_device *sv11=d->priv;
184
        return z8530_queue_xmit(&sv11->sync.chanA, skb);
185
}
186
 
187
static int hostess_neigh_setup(struct neighbour *n)
188
{
189
        if (n->nud_state == NUD_NONE) {
190
                n->ops = &arp_broken_ops;
191
                n->output = n->ops->output;
192
        }
193
        return 0;
194
}
195
 
196
static int hostess_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
197
{
198
        if (p->tbl->family == AF_INET) {
199
                p->neigh_setup = hostess_neigh_setup;
200
                p->ucast_probes = 0;
201
                p->mcast_probes = 0;
202
        }
203
        return 0;
204
}
205
 
206
/*
207
 *      Description block for a Comtrol Hostess SV11 card
208
 */
209
 
210
static struct sv11_device *sv11_init(int iobase, int irq)
211
{
212
        struct z8530_dev *dev;
213
        struct sv11_device *sv;
214
        unsigned long flags;
215
 
216
        /*
217
         *      Get the needed I/O space
218
         */
219
 
220
        if(!request_region(iobase, 8, "Comtrol SV11"))
221
        {
222
                printk(KERN_WARNING "hostess: I/O 0x%X already in use.\n", iobase);
223
                return NULL;
224
        }
225
 
226
        sv=(struct sv11_device *)kmalloc(sizeof(struct sv11_device), GFP_KERNEL);
227
        if(!sv)
228
                goto fail3;
229
 
230
        memset(sv, 0, sizeof(*sv));
231
        sv->if_ptr=&sv->netdev;
232
 
233
        sv->netdev.dev=(struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
234
        if(!sv->netdev.dev)
235
                goto fail2;
236
 
237
        dev=&sv->sync;
238
 
239
        /*
240
         *      Stuff in the I/O addressing
241
         */
242
 
243
        dev->active = 0;
244
 
245
        dev->chanA.ctrlio=iobase+1;
246
        dev->chanA.dataio=iobase+3;
247
        dev->chanB.ctrlio=-1;
248
        dev->chanB.dataio=-1;
249
        dev->chanA.irqs=&z8530_nop;
250
        dev->chanB.irqs=&z8530_nop;
251
 
252
        outb(0, iobase+4);               /* DMA off */
253
 
254
        /* We want a fast IRQ for this device. Actually we'd like an even faster
255
           IRQ ;) - This is one driver RtLinux is made for */
256
 
257
        if(request_irq(irq, &z8530_interrupt, SA_INTERRUPT, "Hostess SV/11", dev)<0)
258
        {
259
                printk(KERN_WARNING "hostess: IRQ %d already in use.\n", irq);
260
                goto fail1;
261
        }
262
 
263
        dev->irq=irq;
264
        dev->chanA.private=sv;
265
        dev->chanA.netdevice=sv->netdev.dev;
266
        dev->chanA.dev=dev;
267
        dev->chanB.dev=dev;
268
 
269
        if(dma)
270
        {
271
                /*
272
                 *      You can have DMA off or 1 and 3 thats the lot
273
                 *      on the Comtrol.
274
                 */
275
                dev->chanA.txdma=3;
276
                dev->chanA.rxdma=1;
277
                outb(0x03|0x08, iobase+4);              /* DMA on */
278
                if(request_dma(dev->chanA.txdma, "Hostess SV/11 (TX)")!=0)
279
                        goto fail;
280
 
281
                if(dma==1)
282
                {
283
                        if(request_dma(dev->chanA.rxdma, "Hostess SV/11 (RX)")!=0)
284
                                goto dmafail;
285
                }
286
        }
287
        save_flags(flags);
288
        cli();
289
 
290
        /*
291
         *      Begin normal initialise
292
         */
293
 
294
        if(z8530_init(dev)!=0)
295
        {
296
                printk(KERN_ERR "Z8530 series device not found.\n");
297
                restore_flags(flags);
298
                goto dmafail2;
299
        }
300
        z8530_channel_load(&dev->chanB, z8530_dead_port);
301
        if(dev->type==Z85C30)
302
                z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream);
303
        else
304
                z8530_channel_load(&dev->chanA, z8530_hdlc_kilostream_85230);
305
 
306
        restore_flags(flags);
307
 
308
 
309
        /*
310
         *      Now we can take the IRQ
311
         */
312
        if(dev_alloc_name(dev->chanA.netdevice,"hdlc%d")>=0)
313
        {
314
                struct net_device *d=dev->chanA.netdevice;
315
 
316
                /*
317
                 *      Initialise the PPP components
318
                 */
319
                sppp_attach(&sv->netdev);
320
 
321
                /*
322
                 *      Local fields
323
                 */
324
 
325
                d->base_addr = iobase;
326
                d->irq = irq;
327
                d->priv = sv;
328
                d->init = NULL;
329
 
330
                d->open = hostess_open;
331
                d->stop = hostess_close;
332
                d->hard_start_xmit = hostess_queue_xmit;
333
                d->get_stats = hostess_get_stats;
334
                d->set_multicast_list = NULL;
335
                d->do_ioctl = hostess_ioctl;
336
                d->neigh_setup = hostess_neigh_setup_dev;
337
                d->set_mac_address = NULL;
338
 
339
                if(register_netdev(d)==-1)
340
                {
341
                        printk(KERN_ERR "%s: unable to register device.\n",
342
                                d->name);
343
                        goto fail;
344
                }
345
 
346
                z8530_describe(dev, "I/O", iobase);
347
                dev->active=1;
348
                return sv;
349
        }
350
dmafail2:
351
        if(dma==1)
352
                free_dma(dev->chanA.rxdma);
353
dmafail:
354
        if(dma)
355
                free_dma(dev->chanA.txdma);
356
fail:
357
        free_irq(irq, dev);
358
fail1:
359
        kfree(sv->netdev.dev);
360
fail2:
361
        kfree(sv);
362
fail3:
363
        release_region(iobase,8);
364
        return NULL;
365
}
366
 
367
static void sv11_shutdown(struct sv11_device *dev)
368
{
369
        sppp_detach(dev->netdev.dev);
370
        z8530_shutdown(&dev->sync);
371
        unregister_netdev(dev->netdev.dev);
372
        free_irq(dev->sync.irq, dev);
373
        if(dma)
374
        {
375
                if(dma==1)
376
                        free_dma(dev->sync.chanA.rxdma);
377
                free_dma(dev->sync.chanA.txdma);
378
        }
379
        release_region(dev->sync.chanA.ctrlio-1, 8);
380
}
381
 
382
#ifdef MODULE
383
 
384
static int io=0x200;
385
static int irq=9;
386
 
387
MODULE_PARM(io,"i");
388
MODULE_PARM_DESC(io, "The I/O base of the Comtrol Hostess SV11 card");
389
MODULE_PARM(dma,"i");
390
MODULE_PARM_DESC(dma, "Set this to 1 to use DMA1/DMA3 for TX/RX");
391
MODULE_PARM(irq,"i");
392
MODULE_PARM_DESC(irq, "The interrupt line setting for the Comtrol Hostess SV11 card");
393
 
394
MODULE_AUTHOR("Alan Cox");
395
MODULE_LICENSE("GPL");
396
MODULE_DESCRIPTION("Modular driver for the Comtrol Hostess SV11");
397
 
398
static struct sv11_device *sv11_unit;
399
 
400
int init_module(void)
401
{
402
        printk(KERN_INFO "SV-11 Z85230 Synchronous Driver v 0.02.\n");
403
        printk(KERN_INFO "(c) Copyright 2001, Red Hat Inc.\n");
404
        if((sv11_unit=sv11_init(io,irq))==NULL)
405
                return -ENODEV;
406
        return 0;
407
}
408
 
409
void cleanup_module(void)
410
{
411
        if(sv11_unit)
412
                sv11_shutdown(sv11_unit);
413
}
414
 
415
#endif
416
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.