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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [dgrs.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *      Digi RightSwitch SE-X loadable device driver for Linux
3
 *
4
 *      The RightSwitch is a 4 (EISA) or 6 (PCI) port etherswitch and
5
 *      a NIC on an internal board.
6
 *
7
 *      Author: Rick Richardson, rick@remotepoint.com
8
 *      Derived from the SVR4.2 (UnixWare) driver for the same card.
9
 *
10
 *      Copyright 1995-1996 Digi International Inc.
11
 *
12
 *      This software may be used and distributed according to the terms
13
 *      of the GNU General Public License, incorporated herein by reference.
14
 *
15
 *      For information on purchasing a RightSwitch SE-4 or SE-6
16
 *      board, please contact Digi's sales department at 1-612-912-3444
17
 *      or 1-800-DIGIBRD.  Outside the U.S., please check our Web page
18
 *      at http://www.dgii.com for sales offices worldwide.
19
 *
20
 *      OPERATION:
21
 *      When compiled as a loadable module, this driver can operate
22
 *      the board as either a 4/6 port switch with a 5th or 7th port
23
 *      that is a conventional NIC interface as far as the host is
24
 *      concerned, OR as 4/6 independent NICs.  To select multi-NIC
25
 *      mode, add "nicmode=1" on the insmod load line for the driver.
26
 *
27
 *      This driver uses the "dev" common ethernet device structure
28
 *      and a private "priv" (dev->priv) structure that contains
29
 *      mostly DGRS-specific information and statistics.  To keep
30
 *      the code for both the switch mode and the multi-NIC mode
31
 *      as similar as possible, I have introduced the concept of
32
 *      "dev0"/"priv0" and "devN"/"privN"  pointer pairs in subroutines
33
 *      where needed.  The first pair of pointers points to the
34
 *      "dev" and "priv" structures of the zeroth (0th) device
35
 *      interface associated with a board.  The second pair of
36
 *      pointers points to the current (Nth) device interface
37
 *      for the board: the one for which we are processing data.
38
 *
39
 *      In switch mode, the pairs of pointers are always the same,
40
 *      that is, dev0 == devN and priv0 == privN.  This is just
41
 *      like previous releases of this driver which did not support
42
 *      NIC mode.
43
 *
44
 *      In multi-NIC mode, the pairs of pointers may be different.
45
 *      We use the devN and privN pointers to reference just the
46
 *      name, port number, and statistics for the current interface.
47
 *      We use the dev0 and priv0 pointers to access the variables
48
 *      that control access to the board, such as board address
49
 *      and simulated 82596 variables.  This is because there is
50
 *      only one "fake" 82596 that serves as the interface to
51
 *      the board.  We do not want to try to keep the variables
52
 *      associated with this 82596 in sync across all devices.
53
 *
54
 *      This scheme works well.  As you will see, except for
55
 *      initialization, there is very little difference between
56
 *      the two modes as far as this driver is concerned.  On the
57
 *      receive side in NIC mode, the interrupt *always* comes in on
58
 *      the 0th interface (dev0/priv0).  We then figure out which
59
 *      real 82596 port it came in on from looking at the "chan"
60
 *      member that the board firmware adds at the end of each
61
 *      RBD (a.k.a. TBD). We get the channel number like this:
62
 *              int chan = ((I596_RBD *) S2H(cbp->xmit.tbdp))->chan;
63
 *
64
 *      On the transmit side in multi-NIC mode, we specify the
65
 *      output 82596 port by setting the new "dstchan" structure
66
 *      member that is at the end of the RFD, like this:
67
 *              priv0->rfdp->dstchan = privN->chan;
68
 *
69
 *      TODO:
70
 *      - Multi-NIC mode is not yet supported when the driver is linked
71
 *        into the kernel.
72
 *      - Better handling of multicast addresses.
73
 *
74
 *      Fixes:
75
 *      Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 11/01/2001
76
 *      - fix dgrs_found_device wrt checking kmalloc return and
77
 *      rollbacking the partial steps of the whole process when
78
 *      one of the devices can't be allocated. Fix SET_MODULE_OWNER
79
 *      on the loop to use devN instead of repeated calls to dev.
80
 *
81
 *      davej <davej@suse.de> - 9/2/2001
82
 *      - Enable PCI device before reading ioaddr/irq
83
 *
84
 */
85
 
86
#include <linux/module.h>
87
#include <linux/kernel.h>
88
#include <linux/sched.h>
89
#include <linux/string.h>
90
#include <linux/delay.h>
91
#include <linux/errno.h>
92
#include <linux/ioport.h>
93
#include <linux/slab.h>
94
#include <linux/interrupt.h>
95
#include <linux/pci.h>
96
#include <linux/init.h>
97
#include <linux/netdevice.h>
98
#include <linux/etherdevice.h>
99
#include <linux/skbuff.h>
100
 
101
#include <asm/bitops.h>
102
#include <asm/io.h>
103
#include <asm/byteorder.h>
104
#include <asm/uaccess.h>
105
 
106
static char version[] __initdata =
107
        "$Id: dgrs.c,v 1.1.1.1 2004-04-15 01:43:13 phoenix Exp $";
108
 
109
/*
110
 *      DGRS include files
111
 */
112
typedef unsigned char uchar;
113
typedef unsigned int bool;
114
#define vol volatile
115
 
116
#include "dgrs.h"
117
#include "dgrs_es4h.h"
118
#include "dgrs_plx9060.h"
119
#include "dgrs_i82596.h"
120
#include "dgrs_ether.h"
121
#include "dgrs_asstruct.h"
122
#include "dgrs_bcomm.h"
123
 
124
static struct pci_device_id dgrs_pci_tbl[] __initdata = {
125
        { SE6_PCI_VENDOR_ID, SE6_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, },
126
        { }                     /* Terminating entry */
127
};
128
MODULE_DEVICE_TABLE(pci, dgrs_pci_tbl);
129
MODULE_LICENSE("GPL");
130
 
131
 
132
/*
133
 *      Firmware.  Compiled separately for local compilation,
134
 *      but #included for Linux distribution.
135
 */
136
#ifndef NOFW
137
        #include "dgrs_firmware.c"
138
#else
139
        extern int      dgrs_firmnum;
140
        extern char     dgrs_firmver[];
141
        extern char     dgrs_firmdate[];
142
        extern uchar    dgrs_code[];
143
        extern int      dgrs_ncode;
144
#endif
145
 
146
/*
147
 *      Linux out*() is backwards from all other operating systems
148
 */
149
#define OUTB(ADDR, VAL) outb(VAL, ADDR)
150
#define OUTW(ADDR, VAL) outw(VAL, ADDR)
151
#define OUTL(ADDR, VAL) outl(VAL, ADDR)
152
 
153
/*
154
 *      Macros to convert switch to host and host to switch addresses
155
 *      (assumes a local variable priv points to board dependent struct)
156
 */
157
#define S2H(A)  ( ((unsigned long)(A)&0x00ffffff) + priv0->vmem )
158
#define S2HN(A) ( ((unsigned long)(A)&0x00ffffff) + privN->vmem )
159
#define H2S(A)  ( ((char *) (A) - priv0->vmem) + 0xA3000000 )
160
 
161
/*
162
 *      Convert a switch address to a "safe" address for use with the
163
 *      PLX 9060 DMA registers and the associated HW kludge that allows
164
 *      for host access of the DMA registers.
165
 */
166
#define S2DMA(A)        ( (unsigned long)(A) & 0x00ffffff)
167
 
168
/*
169
 *      "Space.c" variables, now settable from module interface
170
 *      Use the name below, minus the "dgrs_" prefix.  See init_module().
171
 */
172
static int      dgrs_debug = 1;
173
static int      dgrs_dma = 1;
174
static int      dgrs_spantree = -1;
175
static int      dgrs_hashexpire = -1;
176
static uchar    dgrs_ipaddr[4] = { 0xff, 0xff, 0xff, 0xff};
177
static uchar    dgrs_iptrap[4] = { 0xff, 0xff, 0xff, 0xff};
178
static __u32    dgrs_ipxnet = -1;
179
static int      dgrs_nicmode;
180
 
181
/*
182
 *      Chain of device structures
183
 */
184
static struct net_device *dgrs_root_dev;
185
 
186
/*
187
 *      Private per-board data structure (dev->priv)
188
 */
189
typedef struct
190
{
191
        /*
192
         *      Stuff for generic ethercard I/F
193
         */
194
        struct net_device               *next_dev;
195
        struct net_device_stats stats;
196
 
197
        /*
198
         *      DGRS specific data
199
         */
200
        char            *vmem;
201
 
202
        struct bios_comm *bcomm;        /* Firmware BIOS comm structure */
203
        PORT            *port;          /* Ptr to PORT[0] struct in VM */
204
        I596_SCB        *scbp;          /* Ptr to SCB struct in VM */
205
        I596_RFD        *rfdp;          /* Current RFD list */
206
        I596_RBD        *rbdp;          /* Current RBD list */
207
 
208
        volatile int    intrcnt;        /* Count of interrupts */
209
 
210
        /*
211
         *      SE-4 (EISA) board variables
212
         */
213
        uchar           is_reg;         /* EISA: Value for ES4H_IS reg */
214
 
215
        /*
216
         *      SE-6 (PCI) board variables
217
         *
218
         *      The PLX "expansion rom" space is used for DMA register
219
         *      access from the host on the SE-6.  These are the physical
220
         *      and virtual addresses of that space.
221
         */
222
        ulong           plxreg;         /* Phys address of PLX chip */
223
        char            *vplxreg;       /* Virtual address of PLX chip */
224
        ulong           plxdma;         /* Phys addr of PLX "expansion rom" */
225
        ulong volatile  *vplxdma;       /* Virtual addr of "expansion rom" */
226
        int             use_dma;        /* Flag: use DMA */
227
        DMACHAIN        *dmadesc_s;     /* area for DMA chains (SW addr.) */
228
        DMACHAIN        *dmadesc_h;     /* area for DMA chains (Host Virtual) */
229
 
230
        /*
231
         *      Multi-NIC mode variables
232
         *
233
         *      All entries of the devtbl[] array are valid for the 0th
234
         *      device (i.e. eth0, but not eth1...eth5).  devtbl[0] is
235
         *      valid for all devices (i.e. eth0, eth1, ..., eth5).
236
         */
237
        int             nports;         /* Number of physical ports (4 or 6) */
238
        int             chan;           /* Channel # (1-6) for this device */
239
        struct net_device       *devtbl[6];     /* Ptrs to N device structs */
240
 
241
} DGRS_PRIV;
242
 
243
 
244
/*
245
 *      reset or un-reset the IDT processor
246
 */
247
static void
248
proc_reset(struct net_device *dev0, int reset)
249
{
250
        DGRS_PRIV       *priv0 = (DGRS_PRIV *) dev0->priv;
251
 
252
        if (priv0->plxreg)
253
        {
254
                ulong           val;
255
                val = inl(dev0->base_addr + PLX_MISC_CSR);
256
                if (reset)
257
                        val |= SE6_RESET;
258
                else
259
                        val &= ~SE6_RESET;
260
                OUTL(dev0->base_addr + PLX_MISC_CSR, val);
261
        }
262
        else
263
        {
264
                OUTB(dev0->base_addr + ES4H_PC, reset ? ES4H_PC_RESET : 0);
265
        }
266
}
267
 
268
/*
269
 *      See if the board supports bus master DMA
270
 */
271
static int
272
check_board_dma(struct net_device *dev0)
273
{
274
        DGRS_PRIV       *priv0 = (DGRS_PRIV *) dev0->priv;
275
        ulong   x;
276
 
277
        /*
278
         *      If Space.c says not to use DMA, or if its not a PLX based
279
         *      PCI board, or if the expansion ROM space is not PCI
280
         *      configured, then return false.
281
         */
282
        if (!dgrs_dma || !priv0->plxreg || !priv0->plxdma)
283
                return (0);
284
 
285
        /*
286
         *      Set the local address remap register of the "expansion rom"
287
         *      area to 0x80000000 so that we can use it to access the DMA
288
         *      registers from the host side.
289
         */
290
        OUTL(dev0->base_addr + PLX_ROM_BASE_ADDR, 0x80000000);
291
 
292
        /*
293
         * Set the PCI region descriptor to:
294
         *      Space 0:
295
         *              disable read-prefetch
296
         *              enable READY
297
         *              enable BURST
298
         *              0 internal wait states
299
         *      Expansion ROM: (used for host DMA register access)
300
         *              disable read-prefetch
301
         *              enable READY
302
         *              disable BURST
303
         *              0 internal wait states
304
         */
305
        OUTL(dev0->base_addr + PLX_BUS_REGION, 0x49430343);
306
 
307
        /*
308
         *      Now map the DMA registers into our virtual space
309
         */
310
        priv0->vplxdma = (ulong *) ioremap (priv0->plxdma, 256);
311
        if (!priv0->vplxdma)
312
        {
313
                printk("%s: can't *remap() the DMA regs\n", dev0->name);
314
                return (0);
315
        }
316
 
317
        /*
318
         *      Now test to see if we can access the DMA registers
319
         *      If we write -1 and get back 1FFF, then we accessed the
320
         *      DMA register.  Otherwise, we probably have an old board
321
         *      and wrote into regular RAM.
322
         */
323
        priv0->vplxdma[PLX_DMA0_MODE/4] = 0xFFFFFFFF;
324
        x = priv0->vplxdma[PLX_DMA0_MODE/4];
325
        if (x != 0x00001FFF)
326
                return (0);
327
 
328
        return (1);
329
}
330
 
331
/*
332
 *      Initiate DMA using PLX part on PCI board.  Spin the
333
 *      processor until completed.  All addresses are physical!
334
 *
335
 *      If pciaddr is NULL, then its a chaining DMA, and lcladdr is
336
 *      the address of the first DMA descriptor in the chain.
337
 *
338
 *      If pciaddr is not NULL, then its a single DMA.
339
 *
340
 *      In either case, "lcladdr" must have been fixed up to make
341
 *      sure the MSB isn't set using the S2DMA macro before passing
342
 *      the address to this routine.
343
 */
344
static int
345
do_plx_dma(
346
        struct net_device *dev,
347
        ulong pciaddr,
348
        ulong lcladdr,
349
        int len,
350
        int to_host
351
)
352
{
353
        int             i;
354
        ulong           csr = 0;
355
        DGRS_PRIV       *priv = (DGRS_PRIV *) dev->priv;
356
 
357
        if (pciaddr)
358
        {
359
                /*
360
                 *      Do a single, non-chain DMA
361
                 */
362
                priv->vplxdma[PLX_DMA0_PCI_ADDR/4] = pciaddr;
363
                priv->vplxdma[PLX_DMA0_LCL_ADDR/4] = lcladdr;
364
                priv->vplxdma[PLX_DMA0_SIZE/4] = len;
365
                priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = to_host
366
                                        ? PLX_DMA_DESC_TO_HOST
367
                                        : PLX_DMA_DESC_TO_BOARD;
368
                priv->vplxdma[PLX_DMA0_MODE/4] =
369
                                          PLX_DMA_MODE_WIDTH32
370
                                        | PLX_DMA_MODE_WAITSTATES(0)
371
                                        | PLX_DMA_MODE_READY
372
                                        | PLX_DMA_MODE_NOBTERM
373
                                        | PLX_DMA_MODE_BURST
374
                                        | PLX_DMA_MODE_NOCHAIN;
375
        }
376
        else
377
        {
378
                /*
379
                 *      Do a chaining DMA
380
                 */
381
                priv->vplxdma[PLX_DMA0_MODE/4] =
382
                                          PLX_DMA_MODE_WIDTH32
383
                                        | PLX_DMA_MODE_WAITSTATES(0)
384
                                        | PLX_DMA_MODE_READY
385
                                        | PLX_DMA_MODE_NOBTERM
386
                                        | PLX_DMA_MODE_BURST
387
                                        | PLX_DMA_MODE_CHAIN;
388
                priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = lcladdr;
389
        }
390
 
391
        priv->vplxdma[PLX_DMA_CSR/4] =
392
                                PLX_DMA_CSR_0_ENABLE | PLX_DMA_CSR_0_START;
393
 
394
        /*
395
         *      Wait for DMA to complete
396
         */
397
        for (i = 0; i < 1000000; ++i)
398
        {
399
                /*
400
                 *      Spin the host CPU for 1 usec, so we don't thrash
401
                 *      the PCI bus while the PLX 9060 is doing DMA.
402
                 */
403
                udelay(1);
404
 
405
                csr = (volatile unsigned long) priv->vplxdma[PLX_DMA_CSR/4];
406
 
407
                if (csr & PLX_DMA_CSR_0_DONE)
408
                        break;
409
        }
410
 
411
        if ( ! (csr & PLX_DMA_CSR_0_DONE) )
412
        {
413
                printk("%s: DMA done never occurred. DMA disabled.\n",
414
                        dev->name);
415
                priv->use_dma = 0;
416
                return 1;
417
        }
418
        return 0;
419
}
420
 
421
/*
422
 *      dgrs_rcv_frame()
423
 *
424
 *      Process a received frame.  This is called from the interrupt
425
 *      routine, and works for both switch mode and multi-NIC mode.
426
 *
427
 *      Note that when in multi-NIC mode, we want to always access the
428
 *      hardware using the dev and priv structures of the first port,
429
 *      so that we are using only one set of variables to maintain
430
 *      the board interface status, but we want to use the Nth port
431
 *      dev and priv structures to maintain statistics and to pass
432
 *      the packet up.
433
 *
434
 *      Only the first device structure is attached to the interrupt.
435
 *      We use the special "chan" variable at the end of the first RBD
436
 *      to select the Nth device in multi-NIC mode.
437
 *
438
 *      We currently do chained DMA on a per-packet basis when the
439
 *      packet is "long", and we spin the CPU a short time polling
440
 *      for DMA completion.  This avoids a second interrupt overhead,
441
 *      and gives the best performance for light traffic to the host.
442
 *
443
 *      However, a better scheme that could be implemented would be
444
 *      to see how many packets are outstanding for the host, and if
445
 *      the number is "large", create a long chain to DMA several
446
 *      packets into the host in one go.  In this case, we would set
447
 *      up some state variables to let the host CPU continue doing
448
 *      other things until a DMA completion interrupt comes along.
449
 */
450
void
451
dgrs_rcv_frame(
452
        struct net_device       *dev0,
453
        DGRS_PRIV       *priv0,
454
        I596_CB         *cbp
455
)
456
{
457
        int             len;
458
        I596_TBD        *tbdp;
459
        struct sk_buff  *skb;
460
        uchar           *putp;
461
        uchar           *p;
462
        struct net_device       *devN;
463
        DGRS_PRIV       *privN;
464
 
465
        /*
466
         *      Determine Nth priv and dev structure pointers
467
         */
468
        if (dgrs_nicmode)
469
        {       /* Multi-NIC mode */
470
                int chan = ((I596_RBD *) S2H(cbp->xmit.tbdp))->chan;
471
 
472
                devN = priv0->devtbl[chan-1];
473
                /*
474
                 * If devN is null, we got an interrupt before the I/F
475
                 * has been initialized.  Pitch the packet.
476
                 */
477
                if (devN == NULL)
478
                        goto out;
479
                privN = (DGRS_PRIV *) devN->priv;
480
        }
481
        else
482
        {       /* Switch mode */
483
                devN = dev0;
484
                privN = priv0;
485
        }
486
 
487
        if (0) printk("%s: rcv len=%ld\n", devN->name, cbp->xmit.count);
488
 
489
        /*
490
         *      Allocate a message block big enough to hold the whole frame
491
         */
492
        len = cbp->xmit.count;
493
        if ((skb = dev_alloc_skb(len+5)) == NULL)
494
        {
495
                printk("%s: dev_alloc_skb failed for rcv buffer\n", devN->name);
496
                ++privN->stats.rx_dropped;
497
                /* discarding the frame */
498
                goto out;
499
        }
500
        skb->dev = devN;
501
        skb_reserve(skb, 2);    /* Align IP header */
502
 
503
again:
504
        putp = p = skb_put(skb, len);
505
 
506
        /*
507
         *      There are three modes here for doing the packet copy.
508
         *      If we have DMA, and the packet is "long", we use the
509
         *      chaining mode of DMA.  If it's shorter, we use single
510
         *      DMA's.  Otherwise, we use memcpy().
511
         */
512
        if (priv0->use_dma && priv0->dmadesc_h && len > 64)
513
        {
514
                /*
515
                 *      If we can use DMA and its a long frame, copy it using
516
                 *      DMA chaining.
517
                 */
518
                DMACHAIN        *ddp_h; /* Host virtual DMA desc. pointer */
519
                DMACHAIN        *ddp_s; /* Switch physical DMA desc. pointer */
520
                uchar           *phys_p;
521
 
522
                /*
523
                 *      Get the physical address of the STREAMS buffer.
524
                 *      NOTE: allocb() guarantees that the whole buffer
525
                 *      is in a single page if the length < 4096.
526
                 */
527
                phys_p = (uchar *) virt_to_phys(putp);
528
 
529
                ddp_h = priv0->dmadesc_h;
530
                ddp_s = priv0->dmadesc_s;
531
                tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
532
                for (;;)
533
                {
534
                        int     count;
535
                        int     amt;
536
 
537
                        count = tbdp->count;
538
                        amt = count & 0x3fff;
539
                        if (amt == 0)
540
                                break; /* For safety */
541
                        if ( (p-putp) >= len)
542
                        {
543
                                printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
544
                                proc_reset(dev0, 1);    /* Freeze IDT */
545
                                break; /* For Safety */
546
                        }
547
 
548
                        ddp_h->pciaddr = (ulong) phys_p;
549
                        ddp_h->lcladdr = S2DMA(tbdp->buf);
550
                        ddp_h->len = amt;
551
 
552
                        phys_p += amt;
553
                        p += amt;
554
 
555
                        if (count & I596_TBD_EOF)
556
                        {
557
                                ddp_h->next = PLX_DMA_DESC_TO_HOST
558
                                                | PLX_DMA_DESC_EOC;
559
                                ++ddp_h;
560
                                break;
561
                        }
562
                        else
563
                        {
564
                                ++ddp_s;
565
                                ddp_h->next = PLX_DMA_DESC_TO_HOST
566
                                                | (ulong) ddp_s;
567
                                tbdp = (I596_TBD *) S2H(tbdp->next);
568
                                ++ddp_h;
569
                        }
570
                }
571
                if (ddp_h - priv0->dmadesc_h)
572
                {
573
                        int     rc;
574
 
575
                        rc = do_plx_dma(dev0,
576
                                0, (ulong) priv0->dmadesc_s, len, 0);
577
                        if (rc)
578
                        {
579
                                printk("%s: Chained DMA failure\n", devN->name);
580
                                goto again;
581
                        }
582
                }
583
        }
584
        else if (priv0->use_dma)
585
        {
586
                /*
587
                 *      If we can use DMA and its a shorter frame, copy it
588
                 *      using single DMA transfers.
589
                 */
590
                uchar           *phys_p;
591
 
592
                /*
593
                 *      Get the physical address of the STREAMS buffer.
594
                 *      NOTE: allocb() guarantees that the whole buffer
595
                 *      is in a single page if the length < 4096.
596
                 */
597
                phys_p = (uchar *) virt_to_phys(putp);
598
 
599
                tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
600
                for (;;)
601
                {
602
                        int     count;
603
                        int     amt;
604
                        int     rc;
605
 
606
                        count = tbdp->count;
607
                        amt = count & 0x3fff;
608
                        if (amt == 0)
609
                                break; /* For safety */
610
                        if ( (p-putp) >= len)
611
                        {
612
                                printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
613
                                proc_reset(dev0, 1);    /* Freeze IDT */
614
                                break; /* For Safety */
615
                        }
616
                        rc = do_plx_dma(dev0, (ulong) phys_p,
617
                                                S2DMA(tbdp->buf), amt, 1);
618
                        if (rc)
619
                        {
620
                                memcpy(p, S2H(tbdp->buf), amt);
621
                                printk("%s: Single DMA failed\n", devN->name);
622
                        }
623
                        phys_p += amt;
624
                        p += amt;
625
                        if (count & I596_TBD_EOF)
626
                                break;
627
                        tbdp = (I596_TBD *) S2H(tbdp->next);
628
                }
629
        }
630
        else
631
        {
632
                /*
633
                 *      Otherwise, copy it piece by piece using memcpy()
634
                 */
635
                tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
636
                for (;;)
637
                {
638
                        int     count;
639
                        int     amt;
640
 
641
                        count = tbdp->count;
642
                        amt = count & 0x3fff;
643
                        if (amt == 0)
644
                                break; /* For safety */
645
                        if ( (p-putp) >= len)
646
                        {
647
                                printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
648
                                proc_reset(dev0, 1);    /* Freeze IDT */
649
                                break; /* For Safety */
650
                        }
651
                        memcpy(p, S2H(tbdp->buf), amt);
652
                        p += amt;
653
                        if (count & I596_TBD_EOF)
654
                                break;
655
                        tbdp = (I596_TBD *) S2H(tbdp->next);
656
                }
657
        }
658
 
659
        /*
660
         *      Pass the frame to upper half
661
         */
662
        skb->protocol = eth_type_trans(skb, devN);
663
        netif_rx(skb);
664
        devN->last_rx = jiffies;
665
        ++privN->stats.rx_packets;
666
        privN->stats.rx_bytes += len;
667
 
668
out:
669
        cbp->xmit.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
670
}
671
 
672
/*
673
 *      Start transmission of a frame
674
 *
675
 *      The interface to the board is simple: we pretend that we are
676
 *      a fifth 82596 ethernet controller 'receiving' data, and copy the
677
 *      data into the same structures that a real 82596 would.  This way,
678
 *      the board firmware handles the host 'port' the same as any other.
679
 *
680
 *      NOTE: we do not use Bus master DMA for this routine.  Turns out
681
 *      that it is not needed.  Slave writes over the PCI bus are about
682
 *      as fast as DMA, due to the fact that the PLX part can do burst
683
 *      writes.  The same is not true for data being read from the board.
684
 *
685
 *      For multi-NIC mode, we tell the firmware the desired 82596
686
 *      output port by setting the special "dstchan" member at the
687
 *      end of the traditional 82596 RFD structure.
688
 */
689
 
690
static int dgrs_start_xmit(struct sk_buff *skb, struct net_device *devN)
691
{
692
        DGRS_PRIV       *privN = (DGRS_PRIV *) devN->priv;
693
        struct net_device       *dev0;
694
        DGRS_PRIV       *priv0;
695
        I596_RBD        *rbdp;
696
        int             count;
697
        int             i, len, amt;
698
 
699
        /*
700
         *      Determine 0th priv and dev structure pointers
701
         */
702
        if (dgrs_nicmode)
703
        {
704
                dev0 = privN->devtbl[0];
705
                priv0 = (DGRS_PRIV *) dev0->priv;
706
        }
707
        else
708
        {
709
                dev0 = devN;
710
                priv0 = privN;
711
        }
712
 
713
        if (dgrs_debug > 1)
714
                printk("%s: xmit len=%d\n", devN->name, (int) skb->len);
715
 
716
        devN->trans_start = jiffies;
717
        netif_start_queue(devN);
718
 
719
        if (priv0->rfdp->cmd & I596_RFD_EL)
720
        {       /* Out of RFD's */
721
                if (0) printk("%s: NO RFD's\n", devN->name);
722
                goto no_resources;
723
        }
724
 
725
        rbdp = priv0->rbdp;
726
        count = 0;
727
        priv0->rfdp->rbdp = (I596_RBD *) H2S(rbdp);
728
 
729
        i = 0; len = skb->len;
730
        for (;;)
731
        {
732
                if (rbdp->size & I596_RBD_EL)
733
                {       /* Out of RBD's */
734
                        if (0) printk("%s: NO RBD's\n", devN->name);
735
                        goto no_resources;
736
                }
737
 
738
                amt = min_t(unsigned int, len, rbdp->size - count);
739
                memcpy( (char *) S2H(rbdp->buf) + count, skb->data + i, amt);
740
                i += amt;
741
                count += amt;
742
                len -= amt;
743
                if (len == 0)
744
                {
745
                        if (skb->len < 60)
746
                                rbdp->count = 60 | I596_RBD_EOF;
747
                        else
748
                                rbdp->count = count | I596_RBD_EOF;
749
                        rbdp = (I596_RBD *) S2H(rbdp->next);
750
                        goto frame_done;
751
                }
752
                else if (count < 32)
753
                {
754
                        /* More data to come, but we used less than 32
755
                         * bytes of this RBD.  Keep filling this RBD.
756
                         */
757
                        {}      /* Yes, we do nothing here */
758
                }
759
                else
760
                {
761
                        rbdp->count = count;
762
                        rbdp = (I596_RBD *) S2H(rbdp->next);
763
                        count = 0;
764
                }
765
        }
766
 
767
frame_done:
768
        priv0->rbdp = rbdp;
769
        if (dgrs_nicmode)
770
                priv0->rfdp->dstchan = privN->chan;
771
        priv0->rfdp->status = I596_RFD_C | I596_RFD_OK;
772
        priv0->rfdp = (I596_RFD *) S2H(priv0->rfdp->next);
773
 
774
        ++privN->stats.tx_packets;
775
 
776
        dev_kfree_skb (skb);
777
        return (0);
778
 
779
no_resources:
780
        priv0->scbp->status |= I596_SCB_RNR;    /* simulate I82596 */
781
        return (-EAGAIN);
782
}
783
 
784
/*
785
 *      Open the interface
786
 */
787
static int
788
dgrs_open( struct net_device *dev )
789
{
790
        netif_start_queue(dev);
791
        return (0);
792
}
793
 
794
/*
795
 *      Close the interface
796
 */
797
static int dgrs_close( struct net_device *dev )
798
{
799
        netif_stop_queue(dev);
800
        return (0);
801
}
802
 
803
/*
804
 *      Get statistics
805
 */
806
static struct net_device_stats *dgrs_get_stats( struct net_device *dev )
807
{
808
        DGRS_PRIV       *priv = (DGRS_PRIV *) dev->priv;
809
 
810
        return (&priv->stats);
811
}
812
 
813
/*
814
 *      Set multicast list and/or promiscuous mode
815
 */
816
 
817
static void dgrs_set_multicast_list( struct net_device *dev)
818
{
819
        DGRS_PRIV       *priv = (DGRS_PRIV *) dev->priv;
820
 
821
        priv->port->is_promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
822
}
823
 
824
/*
825
 *      Unique ioctl's
826
 */
827
static int dgrs_ioctl(struct net_device *devN, struct ifreq *ifr, int cmd)
828
{
829
        DGRS_PRIV       *privN = (DGRS_PRIV *) devN->priv;
830
        DGRS_IOCTL      ioc;
831
        int             i;
832
 
833
        if (cmd != DGRSIOCTL)
834
                return -EINVAL;
835
 
836
        if(copy_from_user(&ioc, ifr->ifr_data, sizeof(DGRS_IOCTL)))
837
                return -EFAULT;
838
 
839
        switch (ioc.cmd)
840
        {
841
                case DGRS_GETMEM:
842
                        if (ioc.len != sizeof(ulong))
843
                                return -EINVAL;
844
                        if(copy_to_user(ioc.data, &devN->mem_start, ioc.len))
845
                                return -EFAULT;
846
                        return (0);
847
                case DGRS_SETFILTER:
848
                        if (!capable(CAP_NET_ADMIN))
849
                                return -EPERM;
850
                        if (ioc.port > privN->bcomm->bc_nports)
851
                                return -EINVAL;
852
                        if (ioc.filter >= NFILTERS)
853
                                return -EINVAL;
854
                        if (ioc.len > privN->bcomm->bc_filter_area_len)
855
                                return -EINVAL;
856
 
857
                        /* Wait for old command to finish */
858
                        for (i = 0; i < 1000; ++i)
859
                        {
860
                                if ( (volatile long) privN->bcomm->bc_filter_cmd <= 0 )
861
                                        break;
862
                                udelay(1);
863
                        }
864
                        if (i >= 1000)
865
                                return -EIO;
866
 
867
                        privN->bcomm->bc_filter_port = ioc.port;
868
                        privN->bcomm->bc_filter_num = ioc.filter;
869
                        privN->bcomm->bc_filter_len = ioc.len;
870
 
871
                        if (ioc.len)
872
                        {
873
                                if(copy_from_user(S2HN(privN->bcomm->bc_filter_area),
874
                                        ioc.data, ioc.len))
875
                                        return -EFAULT;
876
                                privN->bcomm->bc_filter_cmd = BC_FILTER_SET;
877
                        }
878
                        else
879
                                privN->bcomm->bc_filter_cmd = BC_FILTER_CLR;
880
                        return(0);
881
                default:
882
                        return -EOPNOTSUPP;
883
        }
884
}
885
 
886
/*
887
 *      Process interrupts
888
 *
889
 *      dev, priv will always refer to the 0th device in Multi-NIC mode.
890
 */
891
 
892
static void dgrs_intr(int irq, void *dev_id, struct pt_regs *regs)
893
{
894
        struct net_device       *dev0 = (struct net_device *) dev_id;
895
        DGRS_PRIV       *priv0 = (DGRS_PRIV *) dev0->priv;
896
        I596_CB         *cbp;
897
        int             cmd;
898
        int             i;
899
 
900
        ++priv0->intrcnt;
901
        if (1) ++priv0->bcomm->bc_cnt[4];
902
        if (0)
903
        {
904
                static int cnt = 100;
905
                if (--cnt > 0)
906
                printk("%s: interrupt: irq %d\n", dev0->name, irq);
907
        }
908
 
909
        /*
910
         *      Get 596 command
911
         */
912
        cmd = priv0->scbp->cmd;
913
 
914
        /*
915
         *      See if RU has been restarted
916
         */
917
        if ( (cmd & I596_SCB_RUC) == I596_SCB_RUC_START)
918
        {
919
                if (0) printk("%s: RUC start\n", dev0->name);
920
                priv0->rfdp = (I596_RFD *) S2H(priv0->scbp->rfdp);
921
                priv0->rbdp = (I596_RBD *) S2H(priv0->rfdp->rbdp);
922
                priv0->scbp->status &= ~(I596_SCB_RNR|I596_SCB_RUS);
923
                /*
924
                 * Tell upper half (halves)
925
                 */
926
                if (dgrs_nicmode)
927
                {
928
                        for (i = 0; i < priv0->nports; ++i)
929
                                netif_wake_queue (priv0->devtbl[i]);
930
                }
931
                else
932
                        netif_wake_queue (dev0);
933
                /* if (bd->flags & TX_QUEUED)
934
                        DL_sched(bd, bdd); */
935
        }
936
 
937
        /*
938
         *      See if any CU commands to process
939
         */
940
        if ( (cmd & I596_SCB_CUC) != I596_SCB_CUC_START)
941
        {
942
                priv0->scbp->cmd = 0;    /* Ignore all other commands */
943
                goto ack_intr;
944
        }
945
        priv0->scbp->status &= ~(I596_SCB_CNA|I596_SCB_CUS);
946
 
947
        /*
948
         *      Process a command
949
         */
950
        cbp = (I596_CB *) S2H(priv0->scbp->cbp);
951
        priv0->scbp->cmd = 0;    /* Safe to clear the command */
952
        for (;;)
953
        {
954
                switch (cbp->nop.cmd & I596_CB_CMD)
955
                {
956
                case I596_CB_CMD_XMIT:
957
                        dgrs_rcv_frame(dev0, priv0, cbp);
958
                        break;
959
                default:
960
                        cbp->nop.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
961
                        break;
962
                }
963
                if (cbp->nop.cmd & I596_CB_CMD_EL)
964
                        break;
965
                cbp = (I596_CB *) S2H(cbp->nop.next);
966
        }
967
        priv0->scbp->status |= I596_SCB_CNA;
968
 
969
        /*
970
         * Ack the interrupt
971
         */
972
ack_intr:
973
        if (priv0->plxreg)
974
                OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL, 1);
975
}
976
 
977
/*
978
 *      Download the board firmware
979
 */
980
static int __init
981
dgrs_download(struct net_device *dev0)
982
{
983
        DGRS_PRIV       *priv0 = (DGRS_PRIV *) dev0->priv;
984
        int             is;
985
        unsigned long   i;
986
 
987
        static int      iv2is[16] = {
988
                                0, 0, 0, ES4H_IS_INT3,
989
                                0, ES4H_IS_INT5, 0, ES4H_IS_INT7,
990
                                0, 0, ES4H_IS_INT10, ES4H_IS_INT11,
991
                                ES4H_IS_INT12, 0, 0, ES4H_IS_INT15 };
992
 
993
        /*
994
         * Map in the dual port memory
995
         */
996
        priv0->vmem = ioremap(dev0->mem_start, 2048*1024);
997
        if (!priv0->vmem)
998
        {
999
                printk("%s: cannot map in board memory\n", dev0->name);
1000
                return -ENXIO;
1001
        }
1002
 
1003
        /*
1004
         *      Hold the processor and configure the board addresses
1005
         */
1006
        if (priv0->plxreg)
1007
        {       /* PCI bus */
1008
                proc_reset(dev0, 1);
1009
        }
1010
        else
1011
        {       /* EISA bus */
1012
                is = iv2is[dev0->irq & 0x0f];
1013
                if (!is)
1014
                {
1015
                        printk("%s: Illegal IRQ %d\n", dev0->name, dev0->irq);
1016
                        return -ENXIO;
1017
                }
1018
                OUTB(dev0->base_addr + ES4H_AS_31_24,
1019
                        (uchar) (dev0->mem_start >> 24) );
1020
                OUTB(dev0->base_addr + ES4H_AS_23_16,
1021
                        (uchar) (dev0->mem_start >> 16) );
1022
                priv0->is_reg = ES4H_IS_LINEAR | is |
1023
                        ((uchar) (dev0->mem_start >> 8) & ES4H_IS_AS15);
1024
                OUTB(dev0->base_addr + ES4H_IS, priv0->is_reg);
1025
                OUTB(dev0->base_addr + ES4H_EC, ES4H_EC_ENABLE);
1026
                OUTB(dev0->base_addr + ES4H_PC, ES4H_PC_RESET);
1027
                OUTB(dev0->base_addr + ES4H_MW, ES4H_MW_ENABLE | 0x00);
1028
        }
1029
 
1030
        /*
1031
         *      See if we can do DMA on the SE-6
1032
         */
1033
        priv0->use_dma = check_board_dma(dev0);
1034
        if (priv0->use_dma)
1035
                printk("%s: Bus Master DMA is enabled.\n", dev0->name);
1036
 
1037
        /*
1038
         * Load and verify the code at the desired address
1039
         */
1040
        memcpy(priv0->vmem, dgrs_code, dgrs_ncode);     /* Load code */
1041
        if (memcmp(priv0->vmem, dgrs_code, dgrs_ncode))
1042
        {
1043
                iounmap(priv0->vmem);
1044
                priv0->vmem = NULL;
1045
                printk("%s: download compare failed\n", dev0->name);
1046
                return -ENXIO;
1047
        }
1048
 
1049
        /*
1050
         * Configurables
1051
         */
1052
        priv0->bcomm = (struct bios_comm *) (priv0->vmem + 0x0100);
1053
        priv0->bcomm->bc_nowait = 1;    /* Tell board to make printf not wait */
1054
        priv0->bcomm->bc_squelch = 0;    /* Flag from Space.c */
1055
        priv0->bcomm->bc_150ohm = 0;     /* Flag from Space.c */
1056
 
1057
        priv0->bcomm->bc_spew = 0;       /* Debug flag from Space.c */
1058
        priv0->bcomm->bc_maxrfd = 0;     /* Debug flag from Space.c */
1059
        priv0->bcomm->bc_maxrbd = 0;     /* Debug flag from Space.c */
1060
 
1061
        /*
1062
         * Tell board we are operating in switch mode (1) or in
1063
         * multi-NIC mode (2).
1064
         */
1065
        priv0->bcomm->bc_host = dgrs_nicmode ? BC_MULTINIC : BC_SWITCH;
1066
 
1067
        /*
1068
         * Request memory space on board for DMA chains
1069
         */
1070
        if (priv0->use_dma)
1071
                priv0->bcomm->bc_hostarea_len = (2048/64) * 16;
1072
 
1073
        /*
1074
         * NVRAM configurables from Space.c
1075
         */
1076
        priv0->bcomm->bc_spantree = dgrs_spantree;
1077
        priv0->bcomm->bc_hashexpire = dgrs_hashexpire;
1078
        memcpy(priv0->bcomm->bc_ipaddr, dgrs_ipaddr, 4);
1079
        memcpy(priv0->bcomm->bc_iptrap, dgrs_iptrap, 4);
1080
        memcpy(priv0->bcomm->bc_ipxnet, &dgrs_ipxnet, 4);
1081
 
1082
        /*
1083
         * Release processor, wait 8 seconds for board to initialize
1084
         */
1085
        proc_reset(dev0, 0);
1086
 
1087
        for (i = jiffies + 8 * HZ; time_after(i, jiffies); )
1088
        {
1089
                barrier();              /* Gcc 2.95 needs this */
1090
                if (priv0->bcomm->bc_status >= BC_RUN)
1091
                        break;
1092
        }
1093
 
1094
        if (priv0->bcomm->bc_status < BC_RUN)
1095
        {
1096
                printk("%s: board not operating\n", dev0->name);
1097
                return -ENXIO;
1098
        }
1099
 
1100
        priv0->port = (PORT *) S2H(priv0->bcomm->bc_port);
1101
        priv0->scbp = (I596_SCB *) S2H(priv0->port->scbp);
1102
        priv0->rfdp = (I596_RFD *) S2H(priv0->scbp->rfdp);
1103
        priv0->rbdp = (I596_RBD *) S2H(priv0->rfdp->rbdp);
1104
 
1105
        priv0->scbp->status = I596_SCB_CNA;     /* CU is idle */
1106
 
1107
        /*
1108
         *      Get switch physical and host virtual pointers to DMA
1109
         *      chaining area.  NOTE: the MSB of the switch physical
1110
         *      address *must* be turned off.  Otherwise, the HW kludge
1111
         *      that allows host access of the PLX DMA registers will
1112
         *      erroneously select the PLX registers.
1113
         */
1114
        priv0->dmadesc_s = (DMACHAIN *) S2DMA(priv0->bcomm->bc_hostarea);
1115
        if (priv0->dmadesc_s)
1116
                priv0->dmadesc_h = (DMACHAIN *) S2H(priv0->dmadesc_s);
1117
        else
1118
                priv0->dmadesc_h = NULL;
1119
 
1120
        /*
1121
         *      Enable board interrupts
1122
         */
1123
        if (priv0->plxreg)
1124
        {       /* PCI bus */
1125
                OUTL(dev0->base_addr + PLX_INT_CSR,
1126
                        inl(dev0->base_addr + PLX_INT_CSR)
1127
                        | PLX_PCI_DOORBELL_IE); /* Enable intr to host */
1128
                OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL, 1);
1129
        }
1130
        else
1131
        {       /* EISA bus */
1132
        }
1133
 
1134
        return (0);
1135
}
1136
 
1137
/*
1138
 *      Probe (init) a board
1139
 */
1140
int __init
1141
dgrs_probe1(struct net_device *dev)
1142
{
1143
        DGRS_PRIV       *priv = (DGRS_PRIV *) dev->priv;
1144
        unsigned long   i;
1145
        int             rc;
1146
 
1147
        printk(KERN_INFO "%s: Digi RightSwitch io=%lx mem=%lx irq=%d plx=%lx dma=%lx\n",
1148
                dev->name, dev->base_addr, dev->mem_start, dev->irq,
1149
                priv->plxreg, priv->plxdma);
1150
 
1151
        /*
1152
         *      Download the firmware and light the processor
1153
         */
1154
        rc = dgrs_download(dev);
1155
        if (rc)
1156
                goto err_out;
1157
 
1158
        /*
1159
         * Get ether address of board
1160
         */
1161
        printk(KERN_INFO "%s: Ethernet address", dev->name);
1162
        memcpy(dev->dev_addr, priv->port->ethaddr, 6);
1163
        for (i = 0; i < 6; ++i)
1164
                printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
1165
        printk("\n");
1166
 
1167
        if (dev->dev_addr[0] & 1)
1168
        {
1169
                printk("%s: Illegal Ethernet Address\n", dev->name);
1170
                rc = -ENXIO;
1171
                goto err_out;
1172
        }
1173
 
1174
        /*
1175
         *      ACK outstanding interrupts, hook the interrupt,
1176
         *      and verify that we are getting interrupts from the board.
1177
         */
1178
        if (priv->plxreg)
1179
                OUTL(dev->base_addr + PLX_LCL2PCI_DOORBELL, 1);
1180
 
1181
        rc = request_irq(dev->irq, &dgrs_intr, SA_SHIRQ, "RightSwitch", dev);
1182
        if (rc)
1183
                goto err_out;
1184
 
1185
        priv->intrcnt = 0;
1186
        for (i = jiffies + 2*HZ + HZ/2; time_after(i, jiffies); )
1187
        {
1188
                barrier();              /* gcc 2.95 needs this */
1189
                if (priv->intrcnt >= 2)
1190
                        break;
1191
        }
1192
        if (priv->intrcnt < 2)
1193
        {
1194
                printk(KERN_ERR "%s: Not interrupting on IRQ %d (%d)\n",
1195
                                dev->name, dev->irq, priv->intrcnt);
1196
                rc = -ENXIO;
1197
                goto err_free_irq;
1198
        }
1199
 
1200
        /*
1201
         *      Register the /proc/ioports information...
1202
         */
1203
        if (!request_region(dev->base_addr, 256, "RightSwitch")) {
1204
                printk(KERN_ERR "%s: io 0x%3lX, which is busy.\n", dev->name,
1205
                                dev->base_addr);
1206
                rc = -EBUSY;
1207
                goto err_free_irq;
1208
        }
1209
 
1210
        /*
1211
         *      Entry points...
1212
         */
1213
        dev->open = &dgrs_open;
1214
        dev->stop = &dgrs_close;
1215
        dev->get_stats = &dgrs_get_stats;
1216
        dev->hard_start_xmit = &dgrs_start_xmit;
1217
        dev->set_multicast_list = &dgrs_set_multicast_list;
1218
        dev->do_ioctl = &dgrs_ioctl;
1219
 
1220
        return rc;
1221
 
1222
err_free_irq:
1223
        free_irq(dev->irq, dev);
1224
err_out:
1225
        return rc;
1226
}
1227
 
1228
int __init
1229
dgrs_initclone(struct net_device *dev)
1230
{
1231
        DGRS_PRIV       *priv = (DGRS_PRIV *) dev->priv;
1232
        int             i;
1233
 
1234
        printk("%s: Digi RightSwitch port %d ",
1235
                dev->name, priv->chan);
1236
        for (i = 0; i < 6; ++i)
1237
                printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
1238
        printk("\n");
1239
 
1240
        return (0);
1241
}
1242
 
1243
static int __init
1244
dgrs_found_device(
1245
        int             io,
1246
        ulong           mem,
1247
        int             irq,
1248
        ulong           plxreg,
1249
        ulong           plxdma
1250
)
1251
{
1252
        DGRS_PRIV       *priv;
1253
        struct net_device *dev, *aux;
1254
 
1255
        /* Allocate and fill new device structure. */
1256
        int dev_size = sizeof(struct net_device) + sizeof(DGRS_PRIV);
1257
        int i, ret;
1258
 
1259
        dev = (struct net_device *) kmalloc(dev_size, GFP_KERNEL);
1260
 
1261
        if (!dev)
1262
                return -ENOMEM;
1263
 
1264
        memset(dev, 0, dev_size);
1265
        dev->priv = ((void *)dev) + sizeof(struct net_device);
1266
        priv = (DGRS_PRIV *)dev->priv;
1267
 
1268
        dev->base_addr = io;
1269
        dev->mem_start = mem;
1270
        dev->mem_end = mem + 2048 * 1024 - 1;
1271
        dev->irq = irq;
1272
        priv->plxreg = plxreg;
1273
        priv->plxdma = plxdma;
1274
        priv->vplxdma = NULL;
1275
 
1276
        priv->chan = 1;
1277
        priv->devtbl[0] = dev;
1278
 
1279
        dev->init = dgrs_probe1;
1280
        SET_MODULE_OWNER(dev);
1281
        ether_setup(dev);
1282
        if (register_netdev(dev) != 0) {
1283
                kfree(dev);
1284
                return -EIO;
1285
        }
1286
 
1287
        priv->next_dev = dgrs_root_dev;
1288
        dgrs_root_dev = dev;
1289
 
1290
        if ( !dgrs_nicmode )
1291
                return (0);      /* Switch mode, we are done */
1292
 
1293
        /*
1294
         * Operating card as N separate NICs
1295
         */
1296
 
1297
        priv->nports = priv->bcomm->bc_nports;
1298
 
1299
        for (i = 1; i < priv->nports; ++i)
1300
        {
1301
                struct net_device       *devN;
1302
                DGRS_PRIV       *privN;
1303
                        /* Allocate new dev and priv structures */
1304
                devN = (struct net_device *) kmalloc(dev_size, GFP_KERNEL);
1305
                        /* Make it an exact copy of dev[0]... */
1306
                ret = -ENOMEM;
1307
                if (!devN)
1308
                        goto fail;
1309
                memcpy(devN, dev, dev_size);
1310
                memset(devN->name, 0, sizeof(devN->name));
1311
                devN->priv = ((void *)devN) + sizeof(struct net_device);
1312
                privN = (DGRS_PRIV *)devN->priv;
1313
                        /* ... and zero out VM areas */
1314
                privN->vmem = 0;
1315
                privN->vplxdma = 0;
1316
                        /* ... and zero out IRQ */
1317
                devN->irq = 0;
1318
                        /* ... and base MAC address off address of 1st port */
1319
                devN->dev_addr[5] += i;
1320
                devN->init = dgrs_initclone;
1321
                SET_MODULE_OWNER(devN);
1322
                ether_setup(devN);
1323
                ret = -EIO;
1324
                if (register_netdev(devN)) {
1325
                        kfree(devN);
1326
                        goto fail;
1327
                }
1328
                privN->chan = i+1;
1329
                priv->devtbl[i] = devN;
1330
                privN->next_dev = dgrs_root_dev;
1331
                dgrs_root_dev = devN;
1332
        }
1333
        return 0;
1334
fail:   aux = priv->next_dev;
1335
        while (dgrs_root_dev != aux) {
1336
                struct net_device *d = dgrs_root_dev;
1337
 
1338
                dgrs_root_dev = ((DGRS_PRIV *)d->priv)->next_dev;
1339
                unregister_netdev(d);
1340
                kfree(d);
1341
        }
1342
        return ret;
1343
}
1344
 
1345
/*
1346
 *      Scan for all boards
1347
 */
1348
static int is2iv[8] __initdata = { 0, 3, 5, 7, 10, 11, 12, 15 };
1349
 
1350
static int __init  dgrs_scan(void)
1351
{
1352
        int     cards_found = 0;
1353
        uint    io;
1354
        uint    mem;
1355
        uint    irq;
1356
        uint    plxreg;
1357
        uint    plxdma;
1358
 
1359
        /*
1360
         *      First, check for PCI boards
1361
         */
1362
        if (pci_present())
1363
        {
1364
                struct pci_dev *pdev = NULL;
1365
 
1366
                while ((pdev = pci_find_device(SE6_PCI_VENDOR_ID, SE6_PCI_DEVICE_ID, pdev)) != NULL)
1367
                {
1368
                        /*
1369
                         * Get and check the bus-master and latency values.
1370
                         * Some PCI BIOSes fail to set the master-enable bit,
1371
                         * and the latency timer must be set to the maximum
1372
                         * value to avoid data corruption that occurs when the
1373
                         * timer expires during a transfer.  Yes, it's a bug.
1374
                         */
1375
                        if (pci_enable_device(pdev))
1376
                                continue;
1377
                        pci_set_master(pdev);
1378
 
1379
                        plxreg = pci_resource_start (pdev, 0);
1380
                        io = pci_resource_start (pdev, 1);
1381
                        mem = pci_resource_start (pdev, 2);
1382
                        pci_read_config_dword(pdev, 0x30, &plxdma);
1383
                        irq = pdev->irq;
1384
                        plxdma &= ~15;
1385
 
1386
                        /*
1387
                         * On some BIOSES, the PLX "expansion rom" (used for DMA)
1388
                         * address comes up as "0".  This is probably because
1389
                         * the BIOS doesn't see a valid 55 AA ROM signature at
1390
                         * the "ROM" start and zeroes the address.  To get
1391
                         * around this problem the SE-6 is configured to ask
1392
                         * for 4 MB of space for the dual port memory.  We then
1393
                         * must set its range back to 2 MB, and use the upper
1394
                         * half for DMA register access
1395
                         */
1396
                        OUTL(io + PLX_SPACE0_RANGE, 0xFFE00000L);
1397
                        if (plxdma == 0)
1398
                                plxdma = mem + (2048L * 1024L);
1399
                        pci_write_config_dword(pdev, 0x30, plxdma + 1);
1400
                        pci_read_config_dword(pdev, 0x30, &plxdma);
1401
                        plxdma &= ~15;
1402
 
1403
                        dgrs_found_device(io, mem, irq, plxreg, plxdma);
1404
 
1405
                        cards_found++;
1406
                }
1407
        }
1408
 
1409
        /*
1410
         *      Second, check for EISA boards
1411
         */
1412
        if (EISA_bus)
1413
        {
1414
                for (io = 0x1000; io < 0x9000; io += 0x1000)
1415
                {
1416
                        if (inb(io+ES4H_MANUFmsb) != 0x10
1417
                                || inb(io+ES4H_MANUFlsb) != 0x49
1418
                                || inb(io+ES4H_PRODUCT) != ES4H_PRODUCT_CODE)
1419
                                continue;
1420
 
1421
                        if ( ! (inb(io+ES4H_EC) & ES4H_EC_ENABLE) )
1422
                                continue; /* Not EISA configured */
1423
 
1424
                        mem = (inb(io+ES4H_AS_31_24) << 24)
1425
                                + (inb(io+ES4H_AS_23_16) << 16);
1426
 
1427
                        irq = is2iv[ inb(io+ES4H_IS) & ES4H_IS_INTMASK ];
1428
 
1429
                        dgrs_found_device(io, mem, irq, 0L, 0L);
1430
 
1431
                        ++cards_found;
1432
                }
1433
        }
1434
 
1435
        return cards_found;
1436
}
1437
 
1438
 
1439
/*
1440
 *      Variables that can be overriden from module command line
1441
 */
1442
static int      debug = -1;
1443
static int      dma = -1;
1444
static int      hashexpire = -1;
1445
static int      spantree = -1;
1446
static int      ipaddr[4] = { -1 };
1447
static int      iptrap[4] = { -1 };
1448
static __u32    ipxnet = -1;
1449
static int      nicmode = -1;
1450
 
1451
MODULE_PARM(debug, "i");
1452
MODULE_PARM(dma, "i");
1453
MODULE_PARM(hashexpire, "i");
1454
MODULE_PARM(spantree, "i");
1455
MODULE_PARM(ipaddr, "1-4i");
1456
MODULE_PARM(iptrap, "1-4i");
1457
MODULE_PARM(ipxnet, "i");
1458
MODULE_PARM(nicmode, "i");
1459
MODULE_PARM_DESC(debug, "Digi RightSwitch enable debugging (0-1)");
1460
MODULE_PARM_DESC(dma, "Digi RightSwitch enable BM DMA (0-1)");
1461
MODULE_PARM_DESC(nicmode, "Digi RightSwitch operating mode (1: switch, 2: multi-NIC)");
1462
 
1463
static int __init dgrs_init_module (void)
1464
{
1465
        int     cards_found;
1466
        int     i;
1467
 
1468
        /*
1469
         *      Command line variable overrides
1470
         *              debug=NNN
1471
         *              dma=0/1
1472
         *              spantree=0/1
1473
         *              hashexpire=NNN
1474
         *              ipaddr=A,B,C,D
1475
         *              iptrap=A,B,C,D
1476
         *              ipxnet=NNN
1477
         *              nicmode=NNN
1478
         */
1479
        if (debug >= 0)
1480
                dgrs_debug = debug;
1481
        if (dma >= 0)
1482
                dgrs_dma = dma;
1483
        if (nicmode >= 0)
1484
                dgrs_nicmode = nicmode;
1485
        if (hashexpire >= 0)
1486
                dgrs_hashexpire = hashexpire;
1487
        if (spantree >= 0)
1488
                dgrs_spantree = spantree;
1489
        if (ipaddr[0] != -1)
1490
                for (i = 0; i < 4; ++i)
1491
                        dgrs_ipaddr[i] = ipaddr[i];
1492
        if (iptrap[0] != -1)
1493
                for (i = 0; i < 4; ++i)
1494
                        dgrs_iptrap[i] = iptrap[i];
1495
        if (ipxnet != -1)
1496
                dgrs_ipxnet = htonl( ipxnet );
1497
 
1498
        if (dgrs_debug)
1499
        {
1500
                printk(KERN_INFO "dgrs: SW=%s FW=Build %d %s\nFW Version=%s\n",
1501
                       version, dgrs_firmnum, dgrs_firmdate, dgrs_firmver);
1502
        }
1503
 
1504
        /*
1505
         *      Find and configure all the cards
1506
         */
1507
        dgrs_root_dev = NULL;
1508
        cards_found = dgrs_scan();
1509
 
1510
        return cards_found ? 0 : -ENODEV;
1511
}
1512
 
1513
static void __exit dgrs_cleanup_module (void)
1514
{
1515
        while (dgrs_root_dev)
1516
        {
1517
                struct net_device       *next_dev;
1518
                DGRS_PRIV       *priv;
1519
 
1520
                priv = (DGRS_PRIV *) dgrs_root_dev->priv;
1521
                next_dev = priv->next_dev;
1522
                unregister_netdev(dgrs_root_dev);
1523
 
1524
                proc_reset(priv->devtbl[0], 1);
1525
 
1526
                if (priv->vmem)
1527
                        iounmap(priv->vmem);
1528
                if (priv->vplxdma)
1529
                        iounmap((uchar *) priv->vplxdma);
1530
 
1531
                release_region(dgrs_root_dev->base_addr, 256);
1532
 
1533
                if (dgrs_root_dev->irq)
1534
                        free_irq(dgrs_root_dev->irq, dgrs_root_dev);
1535
 
1536
                kfree(dgrs_root_dev);
1537
                dgrs_root_dev = next_dev;
1538
        }
1539
}
1540
 
1541
module_init(dgrs_init_module);
1542
module_exit(dgrs_cleanup_module);

powered by: WebSVN 2.1.0

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