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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [dgrs.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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