2 * Digi RightSwitch SE-X loadable device driver for Linux
4 * The RightSwitch is a 4 (EISA) or 6 (PCI) port etherswitch and
5 * a NIC on an internal board.
7 * Author: Rick Richardson, rick@dgii.com, rick_richardson@dgii.com
8 * Derived from the SVR4.2 (UnixWare) driver for the same card.
10 * Copyright 1995-1996 Digi International Inc.
12 * This software may be used and distributed according to the terms
13 * of the GNU General Public License, incorporated herein by reference.
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.
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.
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.
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
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.
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;
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;
70 * - Multi-NIC mode is not yet supported when the driver is linked
72 * - Better handling of multicast addresses.
76 static char *version
= "$Id: dgrs.c,v 1.12 1996/12/21 13:43:58 rick Exp $";
78 #include <linux/version.h>
79 #include <linux/module.h>
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/init.h>
91 #include <asm/bitops.h>
93 #include <asm/byteorder.h>
95 #include <linux/netdevice.h>
96 #include <linux/etherdevice.h>
97 #include <linux/skbuff.h>
99 #include <linux/types.h>
102 * API changed at linux version 2.1.0
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)
111 #include <linux/bios32.h>
112 #define IOREMAP(ADDR, LEN) vremap(ADDR, LEN)
113 #define IOUNMAP(ADDR) vfree(ADDR)
114 #define COPY_FROM_USER(DST,SRC,LEN) memcpy_fromfs(DST,SRC,LEN)
115 #define COPY_TO_USER(DST,SRC,LEN) memcpy_tofs(DST,SRC,LEN)
121 typedef unsigned char uchar
;
122 typedef unsigned int bool;
126 #include "dgrs_es4h.h"
127 #include "dgrs_plx9060.h"
128 #include "dgrs_i82596.h"
129 #include "dgrs_ether.h"
130 #include "dgrs_asstruct.h"
131 #include "dgrs_bcomm.h"
134 * Firmware. Compiled separately for local compilation,
135 * but #included for Linux distribution.
138 #include "dgrs_firmware.c"
140 extern int dgrs_firmnum
;
141 extern char dgrs_firmver
[];
142 extern char dgrs_firmdate
[];
143 extern uchar dgrs_code
[];
144 extern int dgrs_ncode
;
148 * Linux out*() is backwards from all other operating systems
150 #define OUTB(ADDR, VAL) outb(VAL, ADDR)
151 #define OUTW(ADDR, VAL) outw(VAL, ADDR)
152 #define OUTL(ADDR, VAL) outl(VAL, ADDR)
155 * Macros to convert switch to host and host to switch addresses
156 * (assumes a local variable priv points to board dependent struct)
158 #define S2H(A) ( ((unsigned long)(A)&0x00ffffff) + priv0->vmem )
159 #define S2HN(A) ( ((unsigned long)(A)&0x00ffffff) + privN->vmem )
160 #define H2S(A) ( ((char *) (A) - priv0->vmem) + 0xA3000000 )
163 * Convert a switch address to a "safe" address for use with the
164 * PLX 9060 DMA registers and the associated HW kludge that allows
165 * for host access of the DMA registers.
167 #define S2DMA(A) ( (unsigned long)(A) & 0x00ffffff)
170 * "Space.c" variables, now settable from module interface
171 * Use the name below, minus the "dgrs_" prefix. See init_module().
175 int dgrs_spantree
= -1;
176 int dgrs_hashexpire
= -1;
177 uchar dgrs_ipaddr
[4] = { 0xff, 0xff, 0xff, 0xff};
178 uchar dgrs_iptrap
[4] = { 0xff, 0xff, 0xff, 0xff};
179 __u32 dgrs_ipxnet
= -1;
180 int dgrs_nicmode
= 0;
183 * Chain of device structures
186 static struct net_device
*dgrs_root_dev
= NULL
;
190 * Private per-board data structure (dev->priv)
195 * Stuff for generic ethercard I/F
197 char devname
[8]; /* "ethN" string */
198 struct net_device
*next_dev
;
199 struct net_device_stats stats
;
206 struct bios_comm
*bcomm
; /* Firmware BIOS comm structure */
207 PORT
*port
; /* Ptr to PORT[0] struct in VM */
208 I596_SCB
*scbp
; /* Ptr to SCB struct in VM */
209 I596_RFD
*rfdp
; /* Current RFD list */
210 I596_RBD
*rbdp
; /* Current RBD list */
212 int intrcnt
; /* Count of interrupts */
215 * SE-4 (EISA) board variables
217 uchar is_reg
; /* EISA: Value for ES4H_IS reg */
220 * SE-6 (PCI) board variables
222 * The PLX "expansion rom" space is used for DMA register
223 * access from the host on the SE-6. These are the physical
224 * and virtual addresses of that space.
226 ulong plxreg
; /* Phys address of PLX chip */
227 char *vplxreg
; /* Virtual address of PLX chip */
228 ulong plxdma
; /* Phys addr of PLX "expansion rom" */
229 ulong
volatile *vplxdma
; /* Virtual addr of "expansion rom" */
230 int use_dma
; /* Flag: use DMA */
231 DMACHAIN
*dmadesc_s
; /* area for DMA chains (SW addr.) */
232 DMACHAIN
*dmadesc_h
; /* area for DMA chains (Host Virtual) */
235 * Multi-NIC mode variables
237 * All entries of the devtbl[] array are valid for the 0th
238 * device (i.e. eth0, but not eth1...eth5). devtbl[0] is
239 * valid for all devices (i.e. eth0, eth1, ..., eth5).
241 int nports
; /* Number of physical ports (4 or 6) */
242 int chan
; /* Channel # (1-6) for this device */
243 struct net_device
*devtbl
[6]; /* Ptrs to N device structs */
249 * reset or un-reset the IDT processor
252 proc_reset(struct net_device
*dev0
, int reset
)
254 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
259 val
= inl(dev0
->base_addr
+ PLX_MISC_CSR
);
264 OUTL(dev0
->base_addr
+ PLX_MISC_CSR
, val
);
268 OUTB(dev0
->base_addr
+ ES4H_PC
, reset
? ES4H_PC_RESET
: 0);
273 * See if the board supports bus master DMA
276 check_board_dma(struct net_device
*dev0
)
278 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
282 * If Space.c says not to use DMA, or if its not a PLX based
283 * PCI board, or if the expansion ROM space is not PCI
284 * configured, then return false.
286 if (!dgrs_dma
|| !priv0
->plxreg
|| !priv0
->plxdma
)
290 * Set the local address remap register of the "expansion rom"
291 * area to 0x80000000 so that we can use it to access the DMA
292 * registers from the host side.
294 OUTL(dev0
->base_addr
+ PLX_ROM_BASE_ADDR
, 0x80000000);
297 * Set the PCI region descriptor to:
299 * disable read-prefetch
302 * 0 internal wait states
303 * Expansion ROM: (used for host DMA register access)
304 * disable read-prefetch
307 * 0 internal wait states
309 OUTL(dev0
->base_addr
+ PLX_BUS_REGION
, 0x49430343);
312 * Now map the DMA registers into our virtual space
314 priv0
->vplxdma
= (ulong
*) IOREMAP (priv0
->plxdma
, 256);
317 printk("%s: can't *remap() the DMA regs\n", dev0
->name
);
322 * Now test to see if we can access the DMA registers
323 * If we write -1 and get back 1FFF, then we accessed the
324 * DMA register. Otherwise, we probably have an old board
325 * and wrote into regular RAM.
327 priv0
->vplxdma
[PLX_DMA0_MODE
/4] = 0xFFFFFFFF;
328 x
= priv0
->vplxdma
[PLX_DMA0_MODE
/4];
336 * Initiate DMA using PLX part on PCI board. Spin the
337 * processor until completed. All addresses are physical!
339 * If pciaddr is NULL, then its a chaining DMA, and lcladdr is
340 * the address of the first DMA descriptor in the chain.
342 * If pciaddr is not NULL, then its a single DMA.
344 * In either case, "lcladdr" must have been fixed up to make
345 * sure the MSB isn't set using the S2DMA macro before passing
346 * the address to this routine.
350 struct net_device
*dev
,
359 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
364 * Do a single, non-chain DMA
366 priv
->vplxdma
[PLX_DMA0_PCI_ADDR
/4] = pciaddr
;
367 priv
->vplxdma
[PLX_DMA0_LCL_ADDR
/4] = lcladdr
;
368 priv
->vplxdma
[PLX_DMA0_SIZE
/4] = len
;
369 priv
->vplxdma
[PLX_DMA0_DESCRIPTOR
/4] = to_host
370 ? PLX_DMA_DESC_TO_HOST
371 : PLX_DMA_DESC_TO_BOARD
;
372 priv
->vplxdma
[PLX_DMA0_MODE
/4] =
374 | PLX_DMA_MODE_WAITSTATES(0)
376 | PLX_DMA_MODE_NOBTERM
378 | PLX_DMA_MODE_NOCHAIN
;
385 priv
->vplxdma
[PLX_DMA0_MODE
/4] =
387 | PLX_DMA_MODE_WAITSTATES(0)
389 | PLX_DMA_MODE_NOBTERM
391 | PLX_DMA_MODE_CHAIN
;
392 priv
->vplxdma
[PLX_DMA0_DESCRIPTOR
/4] = lcladdr
;
395 priv
->vplxdma
[PLX_DMA_CSR
/4] =
396 PLX_DMA_CSR_0_ENABLE
| PLX_DMA_CSR_0_START
;
399 * Wait for DMA to complete
401 for (i
= 0; i
< 1000000; ++i
)
404 * Spin the host CPU for 1 usec, so we don't thrash
405 * the PCI bus while the PLX 9060 is doing DMA.
409 csr
= (volatile unsigned long) priv
->vplxdma
[PLX_DMA_CSR
/4];
411 if (csr
& PLX_DMA_CSR_0_DONE
)
415 if ( ! (csr
& PLX_DMA_CSR_0_DONE
) )
417 printk("%s: DMA done never occurred. DMA disabled.\n",
428 * Process a received frame. This is called from the interrupt
429 * routine, and works for both switch mode and multi-NIC mode.
431 * Note that when in multi-NIC mode, we want to always access the
432 * hardware using the dev and priv structures of the first port,
433 * so that we are using only one set of variables to maintain
434 * the board interface status, but we want to use the Nth port
435 * dev and priv structures to maintain statistics and to pass
438 * Only the first device structure is attached to the interrupt.
439 * We use the special "chan" variable at the end of the first RBD
440 * to select the Nth device in multi-NIC mode.
442 * We currently do chained DMA on a per-packet basis when the
443 * packet is "long", and we spin the CPU a short time polling
444 * for DMA completion. This avoids a second interrupt overhead,
445 * and gives the best performance for light traffic to the host.
447 * However, a better scheme that could be implemented would be
448 * to see how many packets are outstanding for the host, and if
449 * the number is "large", create a long chain to DMA several
450 * packets into the host in one go. In this case, we would set
451 * up some state variables to let the host CPU continue doing
452 * other things until a DMA completion interrupt comes along.
456 struct net_device
*dev0
,
466 struct net_device
*devN
;
470 * Determine Nth priv and dev structure pointers
473 { /* Multi-NIC mode */
474 int chan
= ((I596_RBD
*) S2H(cbp
->xmit
.tbdp
))->chan
;
476 devN
= priv0
->devtbl
[chan
-1];
478 * If devN is null, we got an interrupt before the I/F
479 * has been initialized. Pitch the packet.
483 privN
= (DGRS_PRIV
*) devN
->priv
;
491 if (0) printk("%s: rcv len=%ld\n", devN
->name
, cbp
->xmit
.count
);
494 * Allocate a message block big enough to hold the whole frame
496 len
= cbp
->xmit
.count
;
497 if ((skb
= dev_alloc_skb(len
+5)) == NULL
)
499 printk("%s: dev_alloc_skb failed for rcv buffer\n", devN
->name
);
500 ++privN
->stats
.rx_dropped
;
501 /* discarding the frame */
505 skb_reserve(skb
, 2); /* Align IP header */
508 putp
= p
= skb_put(skb
, len
);
511 * There are three modes here for doing the packet copy.
512 * If we have DMA, and the packet is "long", we use the
513 * chaining mode of DMA. If it's shorter, we use single
514 * DMA's. Otherwise, we use memcpy().
516 if (priv0
->use_dma
&& priv0
->dmadesc_h
&& len
> 64)
519 * If we can use DMA and its a long frame, copy it using
522 DMACHAIN
*ddp_h
; /* Host virtual DMA desc. pointer */
523 DMACHAIN
*ddp_s
; /* Switch physical DMA desc. pointer */
527 * Get the physical address of the STREAMS buffer.
528 * NOTE: allocb() guarantees that the whole buffer
529 * is in a single page if the length < 4096.
531 phys_p
= (uchar
*) virt_to_phys(putp
);
533 ddp_h
= priv0
->dmadesc_h
;
534 ddp_s
= priv0
->dmadesc_s
;
535 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
542 amt
= count
& 0x3fff;
544 break; /* For safety */
545 if ( (p
-putp
) >= len
)
547 printk("%s: cbp = %x\n", devN
->name
, H2S(cbp
));
548 proc_reset(dev0
, 1); /* Freeze IDT */
549 break; /* For Safety */
552 ddp_h
->pciaddr
= (ulong
) phys_p
;
553 ddp_h
->lcladdr
= S2DMA(tbdp
->buf
);
559 if (count
& I596_TBD_EOF
)
561 ddp_h
->next
= PLX_DMA_DESC_TO_HOST
569 ddp_h
->next
= PLX_DMA_DESC_TO_HOST
571 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
575 if (ddp_h
- priv0
->dmadesc_h
)
579 rc
= do_plx_dma(dev0
,
580 0, (ulong
) priv0
->dmadesc_s
, len
, 0);
583 printk("%s: Chained DMA failure\n", devN
->name
);
588 else if (priv0
->use_dma
)
591 * If we can use DMA and its a shorter frame, copy it
592 * using single DMA transfers.
597 * Get the physical address of the STREAMS buffer.
598 * NOTE: allocb() guarantees that the whole buffer
599 * is in a single page if the length < 4096.
601 phys_p
= (uchar
*) virt_to_phys(putp
);
603 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
611 amt
= count
& 0x3fff;
613 break; /* For safety */
614 if ( (p
-putp
) >= len
)
616 printk("%s: cbp = %x\n", devN
->name
, H2S(cbp
));
617 proc_reset(dev0
, 1); /* Freeze IDT */
618 break; /* For Safety */
620 rc
= do_plx_dma(dev0
, (ulong
) phys_p
,
621 S2DMA(tbdp
->buf
), amt
, 1);
624 memcpy(p
, S2H(tbdp
->buf
), amt
);
625 printk("%s: Single DMA failed\n", devN
->name
);
629 if (count
& I596_TBD_EOF
)
631 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
637 * Otherwise, copy it piece by piece using memcpy()
639 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
646 amt
= count
& 0x3fff;
648 break; /* For safety */
649 if ( (p
-putp
) >= len
)
651 printk("%s: cbp = %x\n", devN
->name
, H2S(cbp
));
652 proc_reset(dev0
, 1); /* Freeze IDT */
653 break; /* For Safety */
655 memcpy(p
, S2H(tbdp
->buf
), amt
);
657 if (count
& I596_TBD_EOF
)
659 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
664 * Pass the frame to upper half
666 skb
->protocol
= eth_type_trans(skb
, devN
);
668 ++privN
->stats
.rx_packets
;
671 cbp
->xmit
.status
= I596_CB_STATUS_C
| I596_CB_STATUS_OK
;
675 * Start transmission of a frame
677 * The interface to the board is simple: we pretend that we are
678 * a fifth 82596 ethernet controller 'receiving' data, and copy the
679 * data into the same structures that a real 82596 would. This way,
680 * the board firmware handles the host 'port' the same as any other.
682 * NOTE: we do not use Bus master DMA for this routine. Turns out
683 * that it is not needed. Slave writes over the PCI bus are about
684 * as fast as DMA, due to the fact that the PLX part can do burst
685 * writes. The same is not true for data being read from the board.
687 * For multi-NIC mode, we tell the firmware the desired 82596
688 * output port by setting the special "dstchan" member at the
689 * end of the traditional 82596 RFD structure.
692 static int dgrs_start_xmit(struct sk_buff
*skb
, struct net_device
*devN
)
694 DGRS_PRIV
*privN
= (DGRS_PRIV
*) devN
->priv
;
695 struct net_device
*dev0
;
700 # define mymin(A,B) ( (A) < (B) ? (A) : (B) )
703 * Determine 0th priv and dev structure pointers
707 dev0
= privN
->devtbl
[0];
708 priv0
= (DGRS_PRIV
*) dev0
->priv
;
717 printk("%s: xmit len=%d\n", devN
->name
, (int) skb
->len
);
719 devN
->trans_start
= jiffies
;
722 if (priv0
->rfdp
->cmd
& I596_RFD_EL
)
724 if (0) printk("%s: NO RFD's\n", devN
->name
);
730 priv0
->rfdp
->rbdp
= (I596_RBD
*) H2S(rbdp
);
732 i
= 0; len
= skb
->len
;
735 if (rbdp
->size
& I596_RBD_EL
)
737 if (0) printk("%s: NO RBD's\n", devN
->name
);
741 amt
= mymin(len
, rbdp
->size
- count
);
742 memcpy( (char *) S2H(rbdp
->buf
) + count
, skb
->data
+ i
, amt
);
749 rbdp
->count
= 60 | I596_RBD_EOF
;
751 rbdp
->count
= count
| I596_RBD_EOF
;
752 rbdp
= (I596_RBD
*) S2H(rbdp
->next
);
757 /* More data to come, but we used less than 32
758 * bytes of this RBD. Keep filling this RBD.
760 {} /* Yes, we do nothing here */
765 rbdp
= (I596_RBD
*) S2H(rbdp
->next
);
773 priv0
->rfdp
->dstchan
= privN
->chan
;
774 priv0
->rfdp
->status
= I596_RFD_C
| I596_RFD_OK
;
775 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->rfdp
->next
);
777 ++privN
->stats
.tx_packets
;
783 priv0
->scbp
->status
|= I596_SCB_RNR
; /* simulate I82596 */
791 dgrs_open( struct net_device
*dev
)
805 * Close the interface
807 static int dgrs_close( struct net_device
*dev
)
822 static struct net_device_stats
*dgrs_get_stats( struct net_device
*dev
)
824 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
826 return (&priv
->stats
);
830 * Set multicast list and/or promiscuous mode
833 static void dgrs_set_multicast_list( struct net_device
*dev
)
835 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
837 priv
->port
->is_promisc
= (dev
->flags
& IFF_PROMISC
) ? 1 : 0;
843 static int dgrs_ioctl(struct net_device
*devN
, struct ifreq
*ifr
, int cmd
)
845 DGRS_PRIV
*privN
= (DGRS_PRIV
*) devN
->priv
;
849 if (cmd
!= DGRSIOCTL
)
852 if(COPY_FROM_USER(&ioc
, ifr
->ifr_data
, sizeof(DGRS_IOCTL
)))
858 if (ioc
.len
!= sizeof(ulong
))
860 if(COPY_TO_USER(ioc
.data
, &devN
->mem_start
, ioc
.len
))
864 if (ioc
.port
> privN
->bcomm
->bc_nports
)
866 if (ioc
.filter
>= NFILTERS
)
868 if (ioc
.len
> privN
->bcomm
->bc_filter_area_len
)
871 /* Wait for old command to finish */
872 for (i
= 0; i
< 1000; ++i
)
874 if ( (volatile long) privN
->bcomm
->bc_filter_cmd
<= 0 )
881 privN
->bcomm
->bc_filter_port
= ioc
.port
;
882 privN
->bcomm
->bc_filter_num
= ioc
.filter
;
883 privN
->bcomm
->bc_filter_len
= ioc
.len
;
887 if(COPY_FROM_USER(S2HN(privN
->bcomm
->bc_filter_area
),
890 privN
->bcomm
->bc_filter_cmd
= BC_FILTER_SET
;
893 privN
->bcomm
->bc_filter_cmd
= BC_FILTER_CLR
;
903 * dev, priv will always refer to the 0th device in Multi-NIC mode.
906 static void dgrs_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
908 struct net_device
*dev0
= (struct net_device
*) dev_id
;
909 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
915 if (1) ++priv0
->bcomm
->bc_cnt
[4];
918 static int cnt
= 100;
920 printk("%s: interrupt: irq %d\n", dev0
->name
, irq
);
926 cmd
= priv0
->scbp
->cmd
;
929 * See if RU has been restarted
931 if ( (cmd
& I596_SCB_RUC
) == I596_SCB_RUC_START
)
933 if (0) printk("%s: RUC start\n", dev0
->name
);
934 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->scbp
->rfdp
);
935 priv0
->rbdp
= (I596_RBD
*) S2H(priv0
->rfdp
->rbdp
);
936 priv0
->scbp
->status
&= ~(I596_SCB_RNR
|I596_SCB_RUS
);
938 * Tell upper half (halves)
942 for (i
= 0; i
< priv0
->nports
; ++i
)
943 priv0
->devtbl
[i
]->tbusy
= 0;
947 /* if (bd->flags & TX_QUEUED)
948 DL_sched(bd, bdd); */
952 * See if any CU commands to process
954 if ( (cmd
& I596_SCB_CUC
) != I596_SCB_CUC_START
)
956 priv0
->scbp
->cmd
= 0; /* Ignore all other commands */
959 priv0
->scbp
->status
&= ~(I596_SCB_CNA
|I596_SCB_CUS
);
964 cbp
= (I596_CB
*) S2H(priv0
->scbp
->cbp
);
965 priv0
->scbp
->cmd
= 0; /* Safe to clear the command */
968 switch (cbp
->nop
.cmd
& I596_CB_CMD
)
970 case I596_CB_CMD_XMIT
:
971 dgrs_rcv_frame(dev0
, priv0
, cbp
);
974 cbp
->nop
.status
= I596_CB_STATUS_C
| I596_CB_STATUS_OK
;
977 if (cbp
->nop
.cmd
& I596_CB_CMD_EL
)
979 cbp
= (I596_CB
*) S2H(cbp
->nop
.next
);
981 priv0
->scbp
->status
|= I596_SCB_CNA
;
988 OUTL(dev0
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
992 * Download the board firmware
995 dgrs_download(struct net_device
*dev0
)
997 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
1001 static int iv2is
[16] = {
1002 0, 0, 0, ES4H_IS_INT3
,
1003 0, ES4H_IS_INT5
, 0, ES4H_IS_INT7
,
1004 0, 0, ES4H_IS_INT10
, ES4H_IS_INT11
,
1005 ES4H_IS_INT12
, 0, 0, ES4H_IS_INT15
};
1008 * Map in the dual port memory
1010 priv0
->vmem
= IOREMAP(dev0
->mem_start
, 2048*1024);
1013 printk("%s: cannot map in board memory\n", dev0
->name
);
1018 * Hold the processor and configure the board addresses
1022 proc_reset(dev0
, 1);
1026 is
= iv2is
[dev0
->irq
& 0x0f];
1029 printk("%s: Illegal IRQ %d\n", dev0
->name
, dev0
->irq
);
1032 OUTB(dev0
->base_addr
+ ES4H_AS_31_24
,
1033 (uchar
) (dev0
->mem_start
>> 24) );
1034 OUTB(dev0
->base_addr
+ ES4H_AS_23_16
,
1035 (uchar
) (dev0
->mem_start
>> 16) );
1036 priv0
->is_reg
= ES4H_IS_LINEAR
| is
|
1037 ((uchar
) (dev0
->mem_start
>> 8) & ES4H_IS_AS15
);
1038 OUTB(dev0
->base_addr
+ ES4H_IS
, priv0
->is_reg
);
1039 OUTB(dev0
->base_addr
+ ES4H_EC
, ES4H_EC_ENABLE
);
1040 OUTB(dev0
->base_addr
+ ES4H_PC
, ES4H_PC_RESET
);
1041 OUTB(dev0
->base_addr
+ ES4H_MW
, ES4H_MW_ENABLE
| 0x00);
1045 * See if we can do DMA on the SE-6
1047 priv0
->use_dma
= check_board_dma(dev0
);
1049 printk("%s: Bus Master DMA is enabled.\n", dev0
->name
);
1052 * Load and verify the code at the desired address
1054 memcpy(priv0
->vmem
, dgrs_code
, dgrs_ncode
); /* Load code */
1055 if (memcmp(priv0
->vmem
, dgrs_code
, dgrs_ncode
))
1057 IOUNMAP(priv0
->vmem
);
1059 printk("%s: download compare failed\n", dev0
->name
);
1066 priv0
->bcomm
= (struct bios_comm
*) (priv0
->vmem
+ 0x0100);
1067 priv0
->bcomm
->bc_nowait
= 1; /* Tell board to make printf not wait */
1068 priv0
->bcomm
->bc_squelch
= 0; /* Flag from Space.c */
1069 priv0
->bcomm
->bc_150ohm
= 0; /* Flag from Space.c */
1071 priv0
->bcomm
->bc_spew
= 0; /* Debug flag from Space.c */
1072 priv0
->bcomm
->bc_maxrfd
= 0; /* Debug flag from Space.c */
1073 priv0
->bcomm
->bc_maxrbd
= 0; /* Debug flag from Space.c */
1076 * Tell board we are operating in switch mode (1) or in
1077 * multi-NIC mode (2).
1079 priv0
->bcomm
->bc_host
= dgrs_nicmode
? BC_MULTINIC
: BC_SWITCH
;
1082 * Request memory space on board for DMA chains
1085 priv0
->bcomm
->bc_hostarea_len
= (2048/64) * 16;
1088 * NVRAM configurables from Space.c
1090 priv0
->bcomm
->bc_spantree
= dgrs_spantree
;
1091 priv0
->bcomm
->bc_hashexpire
= dgrs_hashexpire
;
1092 memcpy(priv0
->bcomm
->bc_ipaddr
, dgrs_ipaddr
, 4);
1093 memcpy(priv0
->bcomm
->bc_iptrap
, dgrs_iptrap
, 4);
1094 memcpy(priv0
->bcomm
->bc_ipxnet
, &dgrs_ipxnet
, 4);
1097 * Release processor, wait 8 seconds for board to initialize
1099 proc_reset(dev0
, 0);
1101 for (i
= jiffies
+ 8 * HZ
; time_after(i
, jiffies
); )
1103 if (priv0
->bcomm
->bc_status
>= BC_RUN
)
1107 if (priv0
->bcomm
->bc_status
< BC_RUN
)
1109 printk("%s: board not operating\n", dev0
->name
);
1113 priv0
->port
= (PORT
*) S2H(priv0
->bcomm
->bc_port
);
1114 priv0
->scbp
= (I596_SCB
*) S2H(priv0
->port
->scbp
);
1115 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->scbp
->rfdp
);
1116 priv0
->rbdp
= (I596_RBD
*) S2H(priv0
->rfdp
->rbdp
);
1118 priv0
->scbp
->status
= I596_SCB_CNA
; /* CU is idle */
1121 * Get switch physical and host virtual pointers to DMA
1122 * chaining area. NOTE: the MSB of the switch physical
1123 * address *must* be turned off. Otherwise, the HW kludge
1124 * that allows host access of the PLX DMA registers will
1125 * erroneously select the PLX registers.
1127 priv0
->dmadesc_s
= (DMACHAIN
*) S2DMA(priv0
->bcomm
->bc_hostarea
);
1128 if (priv0
->dmadesc_s
)
1129 priv0
->dmadesc_h
= (DMACHAIN
*) S2H(priv0
->dmadesc_s
);
1131 priv0
->dmadesc_h
= NULL
;
1134 * Enable board interrupts
1138 OUTL(dev0
->base_addr
+ PLX_INT_CSR
,
1139 inl(dev0
->base_addr
+ PLX_INT_CSR
)
1140 | PLX_PCI_DOORBELL_IE
); /* Enable intr to host */
1141 OUTL(dev0
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
1151 * Probe (init) a board
1154 dgrs_probe1(struct net_device
*dev
)
1156 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
1160 printk("%s: Digi RightSwitch io=%lx mem=%lx irq=%d plx=%lx dma=%lx\n",
1161 dev
->name
, dev
->base_addr
, dev
->mem_start
, dev
->irq
,
1162 priv
->plxreg
, priv
->plxdma
);
1165 * Download the firmware and light the processor
1167 rc
= dgrs_download(dev
);
1174 * Get ether address of board
1176 printk("%s: Ethernet address", dev
->name
);
1177 memcpy(dev
->dev_addr
, priv
->port
->ethaddr
, 6);
1178 for (i
= 0; i
< 6; ++i
)
1179 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
1182 if (dev
->dev_addr
[0] & 1)
1184 printk("%s: Illegal Ethernet Address\n", dev
->name
);
1189 * ACK outstanding interrupts, hook the interrupt,
1190 * and verify that we are getting interrupts from the board.
1193 OUTL(dev
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
1194 rc
= request_irq(dev
->irq
, &dgrs_intr
, 0, "RightSwitch", dev
);
1199 for (i
= jiffies
+ 2*HZ
+ HZ
/2; time_after(i
, jiffies
); )
1200 if (priv
->intrcnt
>= 2)
1202 if (priv
->intrcnt
< 2)
1204 printk("%s: Not interrupting on IRQ %d (%d)\n",
1205 dev
->name
, dev
->irq
, priv
->intrcnt
);
1210 * Register the /proc/ioports information...
1212 request_region(dev
->base_addr
, 256, "RightSwitch");
1217 dev
->open
= &dgrs_open
;
1218 dev
->stop
= &dgrs_close
;
1219 dev
->get_stats
= &dgrs_get_stats
;
1220 dev
->hard_start_xmit
= &dgrs_start_xmit
;
1221 dev
->set_multicast_list
= &dgrs_set_multicast_list
;
1222 dev
->do_ioctl
= &dgrs_ioctl
;
1228 dgrs_initclone(struct net_device
*dev
)
1230 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
1233 printk("%s: Digi RightSwitch port %d ",
1234 dev
->name
, priv
->chan
);
1235 for (i
= 0; i
< 6; ++i
)
1236 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
1244 struct net_device
*dev
,
1256 /* Allocate and fill new device structure. */
1257 int dev_size
= sizeof(struct net_device
) + sizeof(DGRS_PRIV
);
1260 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
1261 memset(dev
, 0, dev_size
);
1262 dev
->priv
= ((void *)dev
) + sizeof(struct net_device
);
1263 priv
= (DGRS_PRIV
*)dev
->priv
;
1265 dev
->name
= priv
->devname
; /* An empty string. */
1266 dev
->base_addr
= io
;
1267 dev
->mem_start
= mem
;
1268 dev
->mem_end
= mem
+ 2048 * 1024 - 1;
1270 priv
->plxreg
= plxreg
;
1271 priv
->plxdma
= plxdma
;
1272 priv
->vplxdma
= NULL
;
1275 priv
->devtbl
[0] = dev
;
1277 dev
->init
= dgrs_probe1
;
1280 priv
->next_dev
= dgrs_root_dev
;
1281 dgrs_root_dev
= dev
;
1282 if (register_netdev(dev
) != 0)
1285 if ( !dgrs_nicmode
)
1286 return (0); /* Switch mode, we are done */
1289 * Operating card as N separate NICs
1291 priv
->nports
= priv
->bcomm
->bc_nports
;
1292 for (i
= 1; i
< priv
->nports
; ++i
)
1294 struct net_device
*devN
;
1297 /* Allocate new dev and priv structures */
1298 devN
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
1300 /* Make it an exact copy of dev[0]... */
1301 memcpy(devN
, dev
, dev_size
);
1302 devN
->priv
= ((void *)devN
) + sizeof(struct net_device
);
1303 privN
= (DGRS_PRIV
*)devN
->priv
;
1305 /* ... but seset devname to a NULL string */
1306 privN
->devname
[0] = 0;
1307 devN
->name
= privN
->devname
;
1309 /* ... and zero out VM areas */
1313 /* ... and zero out IRQ */
1316 /* ... and base MAC address off address of 1st port */
1317 devN
->dev_addr
[5] += i
;
1320 priv
->devtbl
[i
] = devN
;
1322 devN
->init
= dgrs_initclone
;
1324 privN
->next_dev
= dgrs_root_dev
;
1325 dgrs_root_dev
= devN
;
1326 if (register_netdev(devN
) != 0)
1334 dev
->priv
= kmalloc(sizeof (DGRS_PRIV
), GFP_KERNEL
);
1335 memset(dev
->priv
, 0, sizeof (DGRS_PRIV
));
1337 dev
= init_etherdev(dev
, sizeof(DGRS_PRIV
));
1338 priv
= (DGRS_PRIV
*)dev
->priv
;
1340 dev
->base_addr
= io
;
1341 dev
->mem_start
= mem
;
1342 dev
->mem_end
= mem
+ 2048 * 1024;
1344 priv
->plxreg
= plxreg
;
1345 priv
->plxdma
= plxdma
;
1346 priv
->vplxdma
= NULL
;
1349 priv
->devtbl
[0] = dev
;
1359 * Scan for all boards
1361 static int is2iv
[8] __initdata
= { 0, 3, 5, 7, 10, 11, 12, 15 };
1364 dgrs_scan(struct net_device
*dev
)
1366 int cards_found
= 0;
1374 * First, check for PCI boards
1380 for (; pci_index
< 8; pci_index
++)
1382 uchar pci_bus
, pci_device_fn
;
1383 #if LINUX_VERSION_CODE < 0x20100
1387 struct pci_dev
*pdev
;
1392 if (pcibios_find_device(SE6_PCI_VENDOR_ID
,
1394 pci_index
, &pci_bus
,
1398 pdev
= pci_find_slot(pci_bus
, pci_device_fn
);
1399 pci_irq
= pdev
->irq
;
1400 plxreg
= pdev
->resource
[0].start
;
1401 io
= pdev
->resource
[1].start
;
1402 mem
= pdev
->resource
[2].start
;
1403 pcibios_read_config_dword(pci_bus
, pci_device_fn
,
1409 * On some BIOSES, the PLX "expansion rom" (used for DMA)
1410 * address comes up as "0". This is probably because
1411 * the BIOS doesn't see a valid 55 AA ROM signature at
1412 * the "ROM" start and zeroes the address. To get
1413 * around this problem the SE-6 is configured to ask
1414 * for 4 MB of space for the dual port memory. We then
1415 * must set its range back to 2 MB, and use the upper
1416 * half for DMA register access
1418 OUTL(io
+ PLX_SPACE0_RANGE
, 0xFFE00000L
);
1420 plxdma
= mem
+ (2048L * 1024L);
1421 pcibios_write_config_dword(pci_bus
, pci_device_fn
,
1423 pcibios_read_config_dword(pci_bus
, pci_device_fn
,
1428 * Get and check the bus-master and latency values.
1429 * Some PCI BIOSes fail to set the master-enable bit,
1430 * and the latency timer must be set to the maximum
1431 * value to avoid data corruption that occurs when the
1432 * timer expires during a transfer. Yes, it's a bug.
1434 pcibios_read_config_word(pci_bus
, pci_device_fn
,
1435 PCI_COMMAND
, &pci_command
);
1436 if ( ! (pci_command
& PCI_COMMAND_MASTER
))
1438 printk(" Setting the PCI Master Bit!\n");
1439 pci_command
|= PCI_COMMAND_MASTER
;
1440 pcibios_write_config_word(pci_bus
,
1442 PCI_COMMAND
, pci_command
);
1444 pcibios_read_config_byte(pci_bus
, pci_device_fn
,
1445 PCI_LATENCY_TIMER
, &pci_latency
);
1446 if (pci_latency
!= 255)
1448 printk(" Overriding PCI latency timer: "
1449 "was %d, now is 255.\n", pci_latency
);
1450 pcibios_write_config_byte(pci_bus
,
1452 PCI_LATENCY_TIMER
, 255);
1455 dgrs_found_device(dev
, io
, mem
, irq
, plxreg
, plxdma
);
1463 * Second, check for EISA boards
1467 for (io
= 0x1000; io
< 0x9000; io
+= 0x1000)
1469 if (inb(io
+ES4H_MANUFmsb
) != 0x10
1470 || inb(io
+ES4H_MANUFlsb
) != 0x49
1471 || inb(io
+ES4H_PRODUCT
) != ES4H_PRODUCT_CODE
)
1474 if ( ! (inb(io
+ES4H_EC
) & ES4H_EC_ENABLE
) )
1475 continue; /* Not EISA configured */
1477 mem
= (inb(io
+ES4H_AS_31_24
) << 24)
1478 + (inb(io
+ES4H_AS_23_16
) << 16);
1480 irq
= is2iv
[ inb(io
+ES4H_IS
) & ES4H_IS_INTMASK
];
1482 dgrs_found_device(dev
, io
, mem
, irq
, 0L, 0L);
1493 * Module/driver initialization points. Two ways, depending on
1494 * whether we are a module or statically linked, ala Don Becker's
1501 * Variables that can be overriden from command line
1503 static int debug
= -1;
1504 static int dma
= -1;
1505 static int hashexpire
= -1;
1506 static int spantree
= -1;
1507 static int ipaddr
[4] = { -1 };
1508 static int iptrap
[4] = { -1 };
1509 static __u32 ipxnet
= -1;
1510 static int nicmode
= -1;
1512 MODULE_PARM(debug
, "i");
1513 MODULE_PARM(dma
, "i");
1514 MODULE_PARM(hashexpire
, "i");
1515 MODULE_PARM(spantree
, "i");
1516 MODULE_PARM(ipaddr
, "1-4i");
1517 MODULE_PARM(iptrap
, "1-4i");
1518 MODULE_PARM(ipxnet
, "i");
1519 MODULE_PARM(nicmode
, "i");
1528 * Command line variable overrides
1543 dgrs_nicmode
= nicmode
;
1544 if (hashexpire
>= 0)
1545 dgrs_hashexpire
= hashexpire
;
1547 dgrs_spantree
= spantree
;
1548 if (ipaddr
[0] != -1)
1549 for (i
= 0; i
< 4; ++i
)
1550 dgrs_ipaddr
[i
] = ipaddr
[i
];
1551 if (iptrap
[0] != -1)
1552 for (i
= 0; i
< 4; ++i
)
1553 dgrs_iptrap
[i
] = iptrap
[i
];
1555 dgrs_ipxnet
= htonl( ipxnet
);
1559 printk("dgrs: SW=%s FW=Build %d %s\n",
1560 version
, dgrs_firmnum
, dgrs_firmdate
);
1564 * Find and configure all the cards
1566 dgrs_root_dev
= NULL
;
1567 cards_found
= dgrs_scan(0);
1569 return cards_found
? 0 : -ENODEV
;
1573 cleanup_module(void)
1575 while (dgrs_root_dev
)
1577 struct net_device
*next_dev
;
1580 priv
= (DGRS_PRIV
*) dgrs_root_dev
->priv
;
1581 next_dev
= priv
->next_dev
;
1582 unregister_netdev(dgrs_root_dev
);
1584 proc_reset(priv
->devtbl
[0], 1);
1587 IOUNMAP(priv
->vmem
);
1589 IOUNMAP((uchar
*) priv
->vplxdma
);
1591 release_region(dgrs_root_dev
->base_addr
, 256);
1593 if (dgrs_root_dev
->irq
)
1594 free_irq(dgrs_root_dev
->irq
, dgrs_root_dev
);
1596 kfree(dgrs_root_dev
);
1597 dgrs_root_dev
= next_dev
;
1604 dgrs_probe(struct net_device
*dev
)
1608 cards_found
= dgrs_scan(dev
);
1609 if (dgrs_debug
&& cards_found
)
1610 printk("dgrs: SW=%s FW=Build %d %s\n",
1611 version
, dgrs_firmnum
, dgrs_firmdate
);
1612 return cards_found
? 0 : -ENODEV
;