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@remotepoint.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.
75 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 11/01/2001
76 * - fix dgrs_found_device wrt checking kmalloc return and
77 * rollbacking the partial steps of the whole process when
78 * one of the devices can't be allocated. Fix SET_MODULE_OWNER
79 * on the loop to use devN instead of repeated calls to dev.
81 * davej <davej@suse.de> - 9/2/2001
82 * - Enable PCI device before reading ioaddr/irq
86 #include <linux/module.h>
87 #include <linux/kernel.h>
88 #include <linux/string.h>
89 #include <linux/delay.h>
90 #include <linux/errno.h>
91 #include <linux/ioport.h>
92 #include <linux/slab.h>
93 #include <linux/interrupt.h>
94 #include <linux/pci.h>
95 #include <linux/init.h>
96 #include <linux/netdevice.h>
97 #include <linux/etherdevice.h>
98 #include <linux/skbuff.h>
100 #include <asm/bitops.h>
102 #include <asm/byteorder.h>
103 #include <asm/uaccess.h>
105 static char version
[] __initdata
=
106 "$Id: dgrs.c,v 1.13 2000/06/06 04:07:00 rick Exp $";
111 typedef unsigned char uchar
;
112 typedef unsigned int bool;
116 #include "dgrs_es4h.h"
117 #include "dgrs_plx9060.h"
118 #include "dgrs_i82596.h"
119 #include "dgrs_ether.h"
120 #include "dgrs_asstruct.h"
121 #include "dgrs_bcomm.h"
123 static struct pci_device_id dgrs_pci_tbl
[] __initdata
= {
124 { SE6_PCI_VENDOR_ID
, SE6_PCI_DEVICE_ID
, PCI_ANY_ID
, PCI_ANY_ID
, },
125 { } /* Terminating entry */
127 MODULE_DEVICE_TABLE(pci
, dgrs_pci_tbl
);
128 MODULE_LICENSE("GPL");
132 * Firmware. Compiled separately for local compilation,
133 * but #included for Linux distribution.
136 #include "dgrs_firmware.c"
138 extern int dgrs_firmnum
;
139 extern char dgrs_firmver
[];
140 extern char dgrs_firmdate
[];
141 extern uchar dgrs_code
[];
142 extern int dgrs_ncode
;
146 * Linux out*() is backwards from all other operating systems
148 #define OUTB(ADDR, VAL) outb(VAL, ADDR)
149 #define OUTW(ADDR, VAL) outw(VAL, ADDR)
150 #define OUTL(ADDR, VAL) outl(VAL, ADDR)
153 * Macros to convert switch to host and host to switch addresses
154 * (assumes a local variable priv points to board dependent struct)
156 #define S2H(A) ( ((unsigned long)(A)&0x00ffffff) + priv0->vmem )
157 #define S2HN(A) ( ((unsigned long)(A)&0x00ffffff) + privN->vmem )
158 #define H2S(A) ( ((char *) (A) - priv0->vmem) + 0xA3000000 )
161 * Convert a switch address to a "safe" address for use with the
162 * PLX 9060 DMA registers and the associated HW kludge that allows
163 * for host access of the DMA registers.
165 #define S2DMA(A) ( (unsigned long)(A) & 0x00ffffff)
168 * "Space.c" variables, now settable from module interface
169 * Use the name below, minus the "dgrs_" prefix. See init_module().
171 static int dgrs_debug
= 1;
172 static int dgrs_dma
= 1;
173 static int dgrs_spantree
= -1;
174 static int dgrs_hashexpire
= -1;
175 static uchar dgrs_ipaddr
[4] = { 0xff, 0xff, 0xff, 0xff};
176 static uchar dgrs_iptrap
[4] = { 0xff, 0xff, 0xff, 0xff};
177 static __u32 dgrs_ipxnet
= -1;
178 static int dgrs_nicmode
;
181 * Chain of device structures
183 static struct net_device
*dgrs_root_dev
;
186 * Private per-board data structure (dev->priv)
191 * Stuff for generic ethercard I/F
193 struct net_device
*next_dev
;
194 struct net_device_stats stats
;
201 struct bios_comm
*bcomm
; /* Firmware BIOS comm structure */
202 PORT
*port
; /* Ptr to PORT[0] struct in VM */
203 I596_SCB
*scbp
; /* Ptr to SCB struct in VM */
204 I596_RFD
*rfdp
; /* Current RFD list */
205 I596_RBD
*rbdp
; /* Current RBD list */
207 volatile int intrcnt
; /* Count of interrupts */
210 * SE-4 (EISA) board variables
212 uchar is_reg
; /* EISA: Value for ES4H_IS reg */
215 * SE-6 (PCI) board variables
217 * The PLX "expansion rom" space is used for DMA register
218 * access from the host on the SE-6. These are the physical
219 * and virtual addresses of that space.
221 ulong plxreg
; /* Phys address of PLX chip */
222 char *vplxreg
; /* Virtual address of PLX chip */
223 ulong plxdma
; /* Phys addr of PLX "expansion rom" */
224 ulong
volatile *vplxdma
; /* Virtual addr of "expansion rom" */
225 int use_dma
; /* Flag: use DMA */
226 DMACHAIN
*dmadesc_s
; /* area for DMA chains (SW addr.) */
227 DMACHAIN
*dmadesc_h
; /* area for DMA chains (Host Virtual) */
230 * Multi-NIC mode variables
232 * All entries of the devtbl[] array are valid for the 0th
233 * device (i.e. eth0, but not eth1...eth5). devtbl[0] is
234 * valid for all devices (i.e. eth0, eth1, ..., eth5).
236 int nports
; /* Number of physical ports (4 or 6) */
237 int chan
; /* Channel # (1-6) for this device */
238 struct net_device
*devtbl
[6]; /* Ptrs to N device structs */
244 * reset or un-reset the IDT processor
247 proc_reset(struct net_device
*dev0
, int reset
)
249 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
254 val
= inl(dev0
->base_addr
+ PLX_MISC_CSR
);
259 OUTL(dev0
->base_addr
+ PLX_MISC_CSR
, val
);
263 OUTB(dev0
->base_addr
+ ES4H_PC
, reset
? ES4H_PC_RESET
: 0);
268 * See if the board supports bus master DMA
271 check_board_dma(struct net_device
*dev0
)
273 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
277 * If Space.c says not to use DMA, or if it's not a PLX based
278 * PCI board, or if the expansion ROM space is not PCI
279 * configured, then return false.
281 if (!dgrs_dma
|| !priv0
->plxreg
|| !priv0
->plxdma
)
285 * Set the local address remap register of the "expansion rom"
286 * area to 0x80000000 so that we can use it to access the DMA
287 * registers from the host side.
289 OUTL(dev0
->base_addr
+ PLX_ROM_BASE_ADDR
, 0x80000000);
292 * Set the PCI region descriptor to:
294 * disable read-prefetch
297 * 0 internal wait states
298 * Expansion ROM: (used for host DMA register access)
299 * disable read-prefetch
302 * 0 internal wait states
304 OUTL(dev0
->base_addr
+ PLX_BUS_REGION
, 0x49430343);
307 * Now map the DMA registers into our virtual space
309 priv0
->vplxdma
= (ulong
*) ioremap (priv0
->plxdma
, 256);
312 printk("%s: can't *remap() the DMA regs\n", dev0
->name
);
317 * Now test to see if we can access the DMA registers
318 * If we write -1 and get back 1FFF, then we accessed the
319 * DMA register. Otherwise, we probably have an old board
320 * and wrote into regular RAM.
322 priv0
->vplxdma
[PLX_DMA0_MODE
/4] = 0xFFFFFFFF;
323 x
= priv0
->vplxdma
[PLX_DMA0_MODE
/4];
331 * Initiate DMA using PLX part on PCI board. Spin the
332 * processor until completed. All addresses are physical!
334 * If pciaddr is NULL, then it's a chaining DMA, and lcladdr is
335 * the address of the first DMA descriptor in the chain.
337 * If pciaddr is not NULL, then it's a single DMA.
339 * In either case, "lcladdr" must have been fixed up to make
340 * sure the MSB isn't set using the S2DMA macro before passing
341 * the address to this routine.
345 struct net_device
*dev
,
354 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
359 * Do a single, non-chain DMA
361 priv
->vplxdma
[PLX_DMA0_PCI_ADDR
/4] = pciaddr
;
362 priv
->vplxdma
[PLX_DMA0_LCL_ADDR
/4] = lcladdr
;
363 priv
->vplxdma
[PLX_DMA0_SIZE
/4] = len
;
364 priv
->vplxdma
[PLX_DMA0_DESCRIPTOR
/4] = to_host
365 ? PLX_DMA_DESC_TO_HOST
366 : PLX_DMA_DESC_TO_BOARD
;
367 priv
->vplxdma
[PLX_DMA0_MODE
/4] =
369 | PLX_DMA_MODE_WAITSTATES(0)
371 | PLX_DMA_MODE_NOBTERM
373 | PLX_DMA_MODE_NOCHAIN
;
380 priv
->vplxdma
[PLX_DMA0_MODE
/4] =
382 | PLX_DMA_MODE_WAITSTATES(0)
384 | PLX_DMA_MODE_NOBTERM
386 | PLX_DMA_MODE_CHAIN
;
387 priv
->vplxdma
[PLX_DMA0_DESCRIPTOR
/4] = lcladdr
;
390 priv
->vplxdma
[PLX_DMA_CSR
/4] =
391 PLX_DMA_CSR_0_ENABLE
| PLX_DMA_CSR_0_START
;
394 * Wait for DMA to complete
396 for (i
= 0; i
< 1000000; ++i
)
399 * Spin the host CPU for 1 usec, so we don't thrash
400 * the PCI bus while the PLX 9060 is doing DMA.
404 csr
= (volatile unsigned long) priv
->vplxdma
[PLX_DMA_CSR
/4];
406 if (csr
& PLX_DMA_CSR_0_DONE
)
410 if ( ! (csr
& PLX_DMA_CSR_0_DONE
) )
412 printk("%s: DMA done never occurred. DMA disabled.\n",
423 * Process a received frame. This is called from the interrupt
424 * routine, and works for both switch mode and multi-NIC mode.
426 * Note that when in multi-NIC mode, we want to always access the
427 * hardware using the dev and priv structures of the first port,
428 * so that we are using only one set of variables to maintain
429 * the board interface status, but we want to use the Nth port
430 * dev and priv structures to maintain statistics and to pass
433 * Only the first device structure is attached to the interrupt.
434 * We use the special "chan" variable at the end of the first RBD
435 * to select the Nth device in multi-NIC mode.
437 * We currently do chained DMA on a per-packet basis when the
438 * packet is "long", and we spin the CPU a short time polling
439 * for DMA completion. This avoids a second interrupt overhead,
440 * and gives the best performance for light traffic to the host.
442 * However, a better scheme that could be implemented would be
443 * to see how many packets are outstanding for the host, and if
444 * the number is "large", create a long chain to DMA several
445 * packets into the host in one go. In this case, we would set
446 * up some state variables to let the host CPU continue doing
447 * other things until a DMA completion interrupt comes along.
451 struct net_device
*dev0
,
461 struct net_device
*devN
;
465 * Determine Nth priv and dev structure pointers
468 { /* Multi-NIC mode */
469 int chan
= ((I596_RBD
*) S2H(cbp
->xmit
.tbdp
))->chan
;
471 devN
= priv0
->devtbl
[chan
-1];
473 * If devN is null, we got an interrupt before the I/F
474 * has been initialized. Pitch the packet.
478 privN
= (DGRS_PRIV
*) devN
->priv
;
486 if (0) printk("%s: rcv len=%ld\n", devN
->name
, cbp
->xmit
.count
);
489 * Allocate a message block big enough to hold the whole frame
491 len
= cbp
->xmit
.count
;
492 if ((skb
= dev_alloc_skb(len
+5)) == NULL
)
494 printk("%s: dev_alloc_skb failed for rcv buffer\n", devN
->name
);
495 ++privN
->stats
.rx_dropped
;
496 /* discarding the frame */
500 skb_reserve(skb
, 2); /* Align IP header */
503 putp
= p
= skb_put(skb
, len
);
506 * There are three modes here for doing the packet copy.
507 * If we have DMA, and the packet is "long", we use the
508 * chaining mode of DMA. If it's shorter, we use single
509 * DMA's. Otherwise, we use memcpy().
511 if (priv0
->use_dma
&& priv0
->dmadesc_h
&& len
> 64)
514 * If we can use DMA and it's a long frame, copy it using
517 DMACHAIN
*ddp_h
; /* Host virtual DMA desc. pointer */
518 DMACHAIN
*ddp_s
; /* Switch physical DMA desc. pointer */
522 * Get the physical address of the STREAMS buffer.
523 * NOTE: allocb() guarantees that the whole buffer
524 * is in a single page if the length < 4096.
526 phys_p
= (uchar
*) virt_to_phys(putp
);
528 ddp_h
= priv0
->dmadesc_h
;
529 ddp_s
= priv0
->dmadesc_s
;
530 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
537 amt
= count
& 0x3fff;
539 break; /* For safety */
540 if ( (p
-putp
) >= len
)
542 printk("%s: cbp = %lx\n", devN
->name
, (long) H2S(cbp
));
543 proc_reset(dev0
, 1); /* Freeze IDT */
544 break; /* For Safety */
547 ddp_h
->pciaddr
= (ulong
) phys_p
;
548 ddp_h
->lcladdr
= S2DMA(tbdp
->buf
);
554 if (count
& I596_TBD_EOF
)
556 ddp_h
->next
= PLX_DMA_DESC_TO_HOST
564 ddp_h
->next
= PLX_DMA_DESC_TO_HOST
566 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
570 if (ddp_h
- priv0
->dmadesc_h
)
574 rc
= do_plx_dma(dev0
,
575 0, (ulong
) priv0
->dmadesc_s
, len
, 0);
578 printk("%s: Chained DMA failure\n", devN
->name
);
583 else if (priv0
->use_dma
)
586 * If we can use DMA and it's a shorter frame, copy it
587 * using single DMA transfers.
592 * Get the physical address of the STREAMS buffer.
593 * NOTE: allocb() guarantees that the whole buffer
594 * is in a single page if the length < 4096.
596 phys_p
= (uchar
*) virt_to_phys(putp
);
598 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
606 amt
= count
& 0x3fff;
608 break; /* For safety */
609 if ( (p
-putp
) >= len
)
611 printk("%s: cbp = %lx\n", devN
->name
, (long) H2S(cbp
));
612 proc_reset(dev0
, 1); /* Freeze IDT */
613 break; /* For Safety */
615 rc
= do_plx_dma(dev0
, (ulong
) phys_p
,
616 S2DMA(tbdp
->buf
), amt
, 1);
619 memcpy(p
, S2H(tbdp
->buf
), amt
);
620 printk("%s: Single DMA failed\n", devN
->name
);
624 if (count
& I596_TBD_EOF
)
626 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
632 * Otherwise, copy it piece by piece using memcpy()
634 tbdp
= (I596_TBD
*) S2H(cbp
->xmit
.tbdp
);
641 amt
= count
& 0x3fff;
643 break; /* For safety */
644 if ( (p
-putp
) >= len
)
646 printk("%s: cbp = %lx\n", devN
->name
, (long) H2S(cbp
));
647 proc_reset(dev0
, 1); /* Freeze IDT */
648 break; /* For Safety */
650 memcpy(p
, S2H(tbdp
->buf
), amt
);
652 if (count
& I596_TBD_EOF
)
654 tbdp
= (I596_TBD
*) S2H(tbdp
->next
);
659 * Pass the frame to upper half
661 skb
->protocol
= eth_type_trans(skb
, devN
);
663 devN
->last_rx
= jiffies
;
664 ++privN
->stats
.rx_packets
;
665 privN
->stats
.rx_bytes
+= len
;
668 cbp
->xmit
.status
= I596_CB_STATUS_C
| I596_CB_STATUS_OK
;
672 * Start transmission of a frame
674 * The interface to the board is simple: we pretend that we are
675 * a fifth 82596 ethernet controller 'receiving' data, and copy the
676 * data into the same structures that a real 82596 would. This way,
677 * the board firmware handles the host 'port' the same as any other.
679 * NOTE: we do not use Bus master DMA for this routine. Turns out
680 * that it is not needed. Slave writes over the PCI bus are about
681 * as fast as DMA, due to the fact that the PLX part can do burst
682 * writes. The same is not true for data being read from the board.
684 * For multi-NIC mode, we tell the firmware the desired 82596
685 * output port by setting the special "dstchan" member at the
686 * end of the traditional 82596 RFD structure.
689 static int dgrs_start_xmit(struct sk_buff
*skb
, struct net_device
*devN
)
691 DGRS_PRIV
*privN
= (DGRS_PRIV
*) devN
->priv
;
692 struct net_device
*dev0
;
699 * Determine 0th priv and dev structure pointers
703 dev0
= privN
->devtbl
[0];
704 priv0
= (DGRS_PRIV
*) dev0
->priv
;
713 printk("%s: xmit len=%d\n", devN
->name
, (int) skb
->len
);
715 devN
->trans_start
= jiffies
;
716 netif_start_queue(devN
);
718 if (priv0
->rfdp
->cmd
& I596_RFD_EL
)
720 if (0) printk("%s: NO RFD's\n", devN
->name
);
726 priv0
->rfdp
->rbdp
= (I596_RBD
*) H2S(rbdp
);
728 i
= 0; len
= skb
->len
;
731 if (rbdp
->size
& I596_RBD_EL
)
733 if (0) printk("%s: NO RBD's\n", devN
->name
);
737 amt
= min_t(unsigned int, len
, rbdp
->size
- count
);
738 memcpy( (char *) S2H(rbdp
->buf
) + count
, skb
->data
+ i
, amt
);
745 rbdp
->count
= 60 | I596_RBD_EOF
;
747 rbdp
->count
= count
| I596_RBD_EOF
;
748 rbdp
= (I596_RBD
*) S2H(rbdp
->next
);
753 /* More data to come, but we used less than 32
754 * bytes of this RBD. Keep filling this RBD.
756 {} /* Yes, we do nothing here */
761 rbdp
= (I596_RBD
*) S2H(rbdp
->next
);
769 priv0
->rfdp
->dstchan
= privN
->chan
;
770 priv0
->rfdp
->status
= I596_RFD_C
| I596_RFD_OK
;
771 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->rfdp
->next
);
773 ++privN
->stats
.tx_packets
;
779 priv0
->scbp
->status
|= I596_SCB_RNR
; /* simulate I82596 */
787 dgrs_open( struct net_device
*dev
)
789 netif_start_queue(dev
);
794 * Close the interface
796 static int dgrs_close( struct net_device
*dev
)
798 netif_stop_queue(dev
);
805 static struct net_device_stats
*dgrs_get_stats( struct net_device
*dev
)
807 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
809 return (&priv
->stats
);
813 * Set multicast list and/or promiscuous mode
816 static void dgrs_set_multicast_list( struct net_device
*dev
)
818 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
820 priv
->port
->is_promisc
= (dev
->flags
& IFF_PROMISC
) ? 1 : 0;
826 static int dgrs_ioctl(struct net_device
*devN
, struct ifreq
*ifr
, int cmd
)
828 DGRS_PRIV
*privN
= (DGRS_PRIV
*) devN
->priv
;
832 if (cmd
!= DGRSIOCTL
)
835 if(copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(DGRS_IOCTL
)))
841 if (ioc
.len
!= sizeof(ulong
))
843 if(copy_to_user(ioc
.data
, &devN
->mem_start
, ioc
.len
))
847 if (!capable(CAP_NET_ADMIN
))
849 if (ioc
.port
> privN
->bcomm
->bc_nports
)
851 if (ioc
.filter
>= NFILTERS
)
853 if (ioc
.len
> privN
->bcomm
->bc_filter_area_len
)
856 /* Wait for old command to finish */
857 for (i
= 0; i
< 1000; ++i
)
859 if ( (volatile long) privN
->bcomm
->bc_filter_cmd
<= 0 )
866 privN
->bcomm
->bc_filter_port
= ioc
.port
;
867 privN
->bcomm
->bc_filter_num
= ioc
.filter
;
868 privN
->bcomm
->bc_filter_len
= ioc
.len
;
872 if(copy_from_user(S2HN(privN
->bcomm
->bc_filter_area
),
875 privN
->bcomm
->bc_filter_cmd
= BC_FILTER_SET
;
878 privN
->bcomm
->bc_filter_cmd
= BC_FILTER_CLR
;
888 * dev, priv will always refer to the 0th device in Multi-NIC mode.
891 static irqreturn_t
dgrs_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
893 struct net_device
*dev0
= (struct net_device
*) dev_id
;
894 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
900 if (1) ++priv0
->bcomm
->bc_cnt
[4];
903 static int cnt
= 100;
905 printk("%s: interrupt: irq %d\n", dev0
->name
, irq
);
911 cmd
= priv0
->scbp
->cmd
;
914 * See if RU has been restarted
916 if ( (cmd
& I596_SCB_RUC
) == I596_SCB_RUC_START
)
918 if (0) printk("%s: RUC start\n", dev0
->name
);
919 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->scbp
->rfdp
);
920 priv0
->rbdp
= (I596_RBD
*) S2H(priv0
->rfdp
->rbdp
);
921 priv0
->scbp
->status
&= ~(I596_SCB_RNR
|I596_SCB_RUS
);
923 * Tell upper half (halves)
927 for (i
= 0; i
< priv0
->nports
; ++i
)
928 netif_wake_queue (priv0
->devtbl
[i
]);
931 netif_wake_queue (dev0
);
932 /* if (bd->flags & TX_QUEUED)
933 DL_sched(bd, bdd); */
937 * See if any CU commands to process
939 if ( (cmd
& I596_SCB_CUC
) != I596_SCB_CUC_START
)
941 priv0
->scbp
->cmd
= 0; /* Ignore all other commands */
944 priv0
->scbp
->status
&= ~(I596_SCB_CNA
|I596_SCB_CUS
);
949 cbp
= (I596_CB
*) S2H(priv0
->scbp
->cbp
);
950 priv0
->scbp
->cmd
= 0; /* Safe to clear the command */
953 switch (cbp
->nop
.cmd
& I596_CB_CMD
)
955 case I596_CB_CMD_XMIT
:
956 dgrs_rcv_frame(dev0
, priv0
, cbp
);
959 cbp
->nop
.status
= I596_CB_STATUS_C
| I596_CB_STATUS_OK
;
962 if (cbp
->nop
.cmd
& I596_CB_CMD_EL
)
964 cbp
= (I596_CB
*) S2H(cbp
->nop
.next
);
966 priv0
->scbp
->status
|= I596_SCB_CNA
;
973 OUTL(dev0
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
979 * Download the board firmware
982 dgrs_download(struct net_device
*dev0
)
984 DGRS_PRIV
*priv0
= (DGRS_PRIV
*) dev0
->priv
;
988 static int iv2is
[16] = {
989 0, 0, 0, ES4H_IS_INT3
,
990 0, ES4H_IS_INT5
, 0, ES4H_IS_INT7
,
991 0, 0, ES4H_IS_INT10
, ES4H_IS_INT11
,
992 ES4H_IS_INT12
, 0, 0, ES4H_IS_INT15
};
995 * Map in the dual port memory
997 priv0
->vmem
= ioremap(dev0
->mem_start
, 2048*1024);
1000 printk("%s: cannot map in board memory\n", dev0
->name
);
1005 * Hold the processor and configure the board addresses
1009 proc_reset(dev0
, 1);
1013 is
= iv2is
[dev0
->irq
& 0x0f];
1016 printk("%s: Illegal IRQ %d\n", dev0
->name
, dev0
->irq
);
1019 OUTB(dev0
->base_addr
+ ES4H_AS_31_24
,
1020 (uchar
) (dev0
->mem_start
>> 24) );
1021 OUTB(dev0
->base_addr
+ ES4H_AS_23_16
,
1022 (uchar
) (dev0
->mem_start
>> 16) );
1023 priv0
->is_reg
= ES4H_IS_LINEAR
| is
|
1024 ((uchar
) (dev0
->mem_start
>> 8) & ES4H_IS_AS15
);
1025 OUTB(dev0
->base_addr
+ ES4H_IS
, priv0
->is_reg
);
1026 OUTB(dev0
->base_addr
+ ES4H_EC
, ES4H_EC_ENABLE
);
1027 OUTB(dev0
->base_addr
+ ES4H_PC
, ES4H_PC_RESET
);
1028 OUTB(dev0
->base_addr
+ ES4H_MW
, ES4H_MW_ENABLE
| 0x00);
1032 * See if we can do DMA on the SE-6
1034 priv0
->use_dma
= check_board_dma(dev0
);
1036 printk("%s: Bus Master DMA is enabled.\n", dev0
->name
);
1039 * Load and verify the code at the desired address
1041 memcpy(priv0
->vmem
, dgrs_code
, dgrs_ncode
); /* Load code */
1042 if (memcmp(priv0
->vmem
, dgrs_code
, dgrs_ncode
))
1044 iounmap(priv0
->vmem
);
1046 printk("%s: download compare failed\n", dev0
->name
);
1053 priv0
->bcomm
= (struct bios_comm
*) (priv0
->vmem
+ 0x0100);
1054 priv0
->bcomm
->bc_nowait
= 1; /* Tell board to make printf not wait */
1055 priv0
->bcomm
->bc_squelch
= 0; /* Flag from Space.c */
1056 priv0
->bcomm
->bc_150ohm
= 0; /* Flag from Space.c */
1058 priv0
->bcomm
->bc_spew
= 0; /* Debug flag from Space.c */
1059 priv0
->bcomm
->bc_maxrfd
= 0; /* Debug flag from Space.c */
1060 priv0
->bcomm
->bc_maxrbd
= 0; /* Debug flag from Space.c */
1063 * Tell board we are operating in switch mode (1) or in
1064 * multi-NIC mode (2).
1066 priv0
->bcomm
->bc_host
= dgrs_nicmode
? BC_MULTINIC
: BC_SWITCH
;
1069 * Request memory space on board for DMA chains
1072 priv0
->bcomm
->bc_hostarea_len
= (2048/64) * 16;
1075 * NVRAM configurables from Space.c
1077 priv0
->bcomm
->bc_spantree
= dgrs_spantree
;
1078 priv0
->bcomm
->bc_hashexpire
= dgrs_hashexpire
;
1079 memcpy(priv0
->bcomm
->bc_ipaddr
, dgrs_ipaddr
, 4);
1080 memcpy(priv0
->bcomm
->bc_iptrap
, dgrs_iptrap
, 4);
1081 memcpy(priv0
->bcomm
->bc_ipxnet
, &dgrs_ipxnet
, 4);
1084 * Release processor, wait 8 seconds for board to initialize
1086 proc_reset(dev0
, 0);
1088 for (i
= jiffies
+ 8 * HZ
; time_after(i
, jiffies
); )
1090 barrier(); /* Gcc 2.95 needs this */
1091 if (priv0
->bcomm
->bc_status
>= BC_RUN
)
1095 if (priv0
->bcomm
->bc_status
< BC_RUN
)
1097 printk("%s: board not operating\n", dev0
->name
);
1101 priv0
->port
= (PORT
*) S2H(priv0
->bcomm
->bc_port
);
1102 priv0
->scbp
= (I596_SCB
*) S2H(priv0
->port
->scbp
);
1103 priv0
->rfdp
= (I596_RFD
*) S2H(priv0
->scbp
->rfdp
);
1104 priv0
->rbdp
= (I596_RBD
*) S2H(priv0
->rfdp
->rbdp
);
1106 priv0
->scbp
->status
= I596_SCB_CNA
; /* CU is idle */
1109 * Get switch physical and host virtual pointers to DMA
1110 * chaining area. NOTE: the MSB of the switch physical
1111 * address *must* be turned off. Otherwise, the HW kludge
1112 * that allows host access of the PLX DMA registers will
1113 * erroneously select the PLX registers.
1115 priv0
->dmadesc_s
= (DMACHAIN
*) S2DMA(priv0
->bcomm
->bc_hostarea
);
1116 if (priv0
->dmadesc_s
)
1117 priv0
->dmadesc_h
= (DMACHAIN
*) S2H(priv0
->dmadesc_s
);
1119 priv0
->dmadesc_h
= NULL
;
1122 * Enable board interrupts
1126 OUTL(dev0
->base_addr
+ PLX_INT_CSR
,
1127 inl(dev0
->base_addr
+ PLX_INT_CSR
)
1128 | PLX_PCI_DOORBELL_IE
); /* Enable intr to host */
1129 OUTL(dev0
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
1139 * Probe (init) a board
1142 dgrs_probe1(struct net_device
*dev
)
1144 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
1148 printk("%s: Digi RightSwitch io=%lx mem=%lx irq=%d plx=%lx dma=%lx\n",
1149 dev
->name
, dev
->base_addr
, dev
->mem_start
, dev
->irq
,
1150 priv
->plxreg
, priv
->plxdma
);
1153 * Download the firmware and light the processor
1155 rc
= dgrs_download(dev
);
1160 * Get ether address of board
1162 printk("%s: Ethernet address", dev
->name
);
1163 memcpy(dev
->dev_addr
, priv
->port
->ethaddr
, 6);
1164 for (i
= 0; i
< 6; ++i
)
1165 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
1168 if (dev
->dev_addr
[0] & 1)
1170 printk("%s: Illegal Ethernet Address\n", dev
->name
);
1176 * ACK outstanding interrupts, hook the interrupt,
1177 * and verify that we are getting interrupts from the board.
1180 OUTL(dev
->base_addr
+ PLX_LCL2PCI_DOORBELL
, 1);
1182 rc
= request_irq(dev
->irq
, &dgrs_intr
, SA_SHIRQ
, "RightSwitch", dev
);
1187 for (i
= jiffies
+ 2*HZ
+ HZ
/2; time_after(i
, jiffies
); )
1189 barrier(); /* gcc 2.95 needs this */
1190 if (priv
->intrcnt
>= 2)
1193 if (priv
->intrcnt
< 2)
1195 printk(KERN_ERR
"%s: Not interrupting on IRQ %d (%d)\n",
1196 dev
->name
, dev
->irq
, priv
->intrcnt
);
1202 * Register the /proc/ioports information...
1204 if (!request_region(dev
->base_addr
, 256, "RightSwitch")) {
1205 printk(KERN_ERR
"%s: io 0x%3lX, which is busy.\n", dev
->name
,
1214 dev
->open
= &dgrs_open
;
1215 dev
->stop
= &dgrs_close
;
1216 dev
->get_stats
= &dgrs_get_stats
;
1217 dev
->hard_start_xmit
= &dgrs_start_xmit
;
1218 dev
->set_multicast_list
= &dgrs_set_multicast_list
;
1219 dev
->do_ioctl
= &dgrs_ioctl
;
1224 free_irq(dev
->irq
, dev
);
1230 dgrs_initclone(struct net_device
*dev
)
1232 DGRS_PRIV
*priv
= (DGRS_PRIV
*) dev
->priv
;
1235 printk("%s: Digi RightSwitch port %d ",
1236 dev
->name
, priv
->chan
);
1237 for (i
= 0; i
< 6; ++i
)
1238 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
1254 struct net_device
*dev
, *aux
;
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
);
1265 memset(dev
, 0, dev_size
);
1266 dev
->priv
= ((void *)dev
) + sizeof(struct net_device
);
1267 priv
= (DGRS_PRIV
*)dev
->priv
;
1269 dev
->base_addr
= io
;
1270 dev
->mem_start
= mem
;
1271 dev
->mem_end
= mem
+ 2048 * 1024 - 1;
1273 priv
->plxreg
= plxreg
;
1274 priv
->plxdma
= plxdma
;
1275 priv
->vplxdma
= NULL
;
1278 priv
->devtbl
[0] = dev
;
1280 dev
->init
= dgrs_probe1
;
1281 SET_MODULE_OWNER(dev
);
1283 if (register_netdev(dev
) != 0) {
1288 priv
->next_dev
= dgrs_root_dev
;
1289 dgrs_root_dev
= dev
;
1291 if ( !dgrs_nicmode
)
1292 return (0); /* Switch mode, we are done */
1295 * Operating card as N separate NICs
1298 priv
->nports
= priv
->bcomm
->bc_nports
;
1300 for (i
= 1; i
< priv
->nports
; ++i
)
1302 struct net_device
*devN
;
1304 /* Allocate new dev and priv structures */
1305 devN
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
1306 /* Make it an exact copy of dev[0]... */
1310 memcpy(devN
, dev
, dev_size
);
1311 memset(devN
->name
, 0, sizeof(devN
->name
));
1312 devN
->priv
= ((void *)devN
) + sizeof(struct net_device
);
1313 privN
= (DGRS_PRIV
*)devN
->priv
;
1314 /* ... and zero out VM areas */
1317 /* ... and zero out IRQ */
1319 /* ... and base MAC address off address of 1st port */
1320 devN
->dev_addr
[5] += i
;
1321 devN
->init
= dgrs_initclone
;
1322 SET_MODULE_OWNER(devN
);
1325 if (register_netdev(devN
)) {
1330 priv
->devtbl
[i
] = devN
;
1331 privN
->next_dev
= dgrs_root_dev
;
1332 dgrs_root_dev
= devN
;
1335 fail
: aux
= priv
->next_dev
;
1336 while (dgrs_root_dev
!= aux
) {
1337 struct net_device
*d
= dgrs_root_dev
;
1339 dgrs_root_dev
= ((DGRS_PRIV
*)d
->priv
)->next_dev
;
1340 unregister_netdev(d
);
1347 * Scan for all boards
1349 static int is2iv
[8] __initdata
= { 0, 3, 5, 7, 10, 11, 12, 15 };
1351 static int __init
dgrs_scan(void)
1353 int cards_found
= 0;
1359 struct pci_dev
*pdev
= NULL
;
1362 * First, check for PCI boards
1364 while ((pdev
= pci_find_device(SE6_PCI_VENDOR_ID
, SE6_PCI_DEVICE_ID
, pdev
)) != NULL
)
1367 * Get and check the bus-master and latency values.
1368 * Some PCI BIOSes fail to set the master-enable bit,
1369 * and the latency timer must be set to the maximum
1370 * value to avoid data corruption that occurs when the
1371 * timer expires during a transfer. Yes, it's a bug.
1373 if (pci_enable_device(pdev
))
1375 pci_set_master(pdev
);
1377 plxreg
= pci_resource_start (pdev
, 0);
1378 io
= pci_resource_start (pdev
, 1);
1379 mem
= pci_resource_start (pdev
, 2);
1380 pci_read_config_dword(pdev
, 0x30, &plxdma
);
1385 * On some BIOSES, the PLX "expansion rom" (used for DMA)
1386 * address comes up as "0". This is probably because
1387 * the BIOS doesn't see a valid 55 AA ROM signature at
1388 * the "ROM" start and zeroes the address. To get
1389 * around this problem the SE-6 is configured to ask
1390 * for 4 MB of space for the dual port memory. We then
1391 * must set its range back to 2 MB, and use the upper
1392 * half for DMA register access
1394 OUTL(io
+ PLX_SPACE0_RANGE
, 0xFFE00000L
);
1396 plxdma
= mem
+ (2048L * 1024L);
1397 pci_write_config_dword(pdev
, 0x30, plxdma
+ 1);
1398 pci_read_config_dword(pdev
, 0x30, &plxdma
);
1401 dgrs_found_device(io
, mem
, irq
, plxreg
, plxdma
);
1407 * Second, check for EISA boards
1411 for (io
= 0x1000; io
< 0x9000; io
+= 0x1000)
1413 if (inb(io
+ES4H_MANUFmsb
) != 0x10
1414 || inb(io
+ES4H_MANUFlsb
) != 0x49
1415 || inb(io
+ES4H_PRODUCT
) != ES4H_PRODUCT_CODE
)
1418 if ( ! (inb(io
+ES4H_EC
) & ES4H_EC_ENABLE
) )
1419 continue; /* Not EISA configured */
1421 mem
= (inb(io
+ES4H_AS_31_24
) << 24)
1422 + (inb(io
+ES4H_AS_23_16
) << 16);
1424 irq
= is2iv
[ inb(io
+ES4H_IS
) & ES4H_IS_INTMASK
];
1426 dgrs_found_device(io
, mem
, irq
, 0L, 0L);
1437 * Variables that can be overriden from module command line
1439 static int debug
= -1;
1440 static int dma
= -1;
1441 static int hashexpire
= -1;
1442 static int spantree
= -1;
1443 static int ipaddr
[4] = { -1 };
1444 static int iptrap
[4] = { -1 };
1445 static __u32 ipxnet
= -1;
1446 static int nicmode
= -1;
1448 MODULE_PARM(debug
, "i");
1449 MODULE_PARM(dma
, "i");
1450 MODULE_PARM(hashexpire
, "i");
1451 MODULE_PARM(spantree
, "i");
1452 MODULE_PARM(ipaddr
, "1-4i");
1453 MODULE_PARM(iptrap
, "1-4i");
1454 MODULE_PARM(ipxnet
, "i");
1455 MODULE_PARM(nicmode
, "i");
1456 MODULE_PARM_DESC(debug
, "Digi RightSwitch enable debugging (0-1)");
1457 MODULE_PARM_DESC(dma
, "Digi RightSwitch enable BM DMA (0-1)");
1458 MODULE_PARM_DESC(nicmode
, "Digi RightSwitch operating mode (1: switch, 2: multi-NIC)");
1460 static int __init
dgrs_init_module (void)
1466 * Command line variable overrides
1481 dgrs_nicmode
= nicmode
;
1482 if (hashexpire
>= 0)
1483 dgrs_hashexpire
= hashexpire
;
1485 dgrs_spantree
= spantree
;
1486 if (ipaddr
[0] != -1)
1487 for (i
= 0; i
< 4; ++i
)
1488 dgrs_ipaddr
[i
] = ipaddr
[i
];
1489 if (iptrap
[0] != -1)
1490 for (i
= 0; i
< 4; ++i
)
1491 dgrs_iptrap
[i
] = iptrap
[i
];
1493 dgrs_ipxnet
= htonl( ipxnet
);
1497 printk(KERN_INFO
"dgrs: SW=%s FW=Build %d %s\nFW Version=%s\n",
1498 version
, dgrs_firmnum
, dgrs_firmdate
, dgrs_firmver
);
1502 * Find and configure all the cards
1504 dgrs_root_dev
= NULL
;
1505 cards_found
= dgrs_scan();
1507 return cards_found
? 0 : -ENODEV
;
1510 static void __exit
dgrs_cleanup_module (void)
1512 while (dgrs_root_dev
)
1514 struct net_device
*next_dev
;
1517 priv
= (DGRS_PRIV
*) dgrs_root_dev
->priv
;
1518 next_dev
= priv
->next_dev
;
1519 unregister_netdev(dgrs_root_dev
);
1521 proc_reset(priv
->devtbl
[0], 1);
1524 iounmap(priv
->vmem
);
1526 iounmap((uchar
*) priv
->vplxdma
);
1528 release_region(dgrs_root_dev
->base_addr
, 256);
1530 if (dgrs_root_dev
->irq
)
1531 free_irq(dgrs_root_dev
->irq
, dgrs_root_dev
);
1533 kfree(dgrs_root_dev
);
1534 dgrs_root_dev
= next_dev
;
1538 module_init(dgrs_init_module
);
1539 module_exit(dgrs_cleanup_module
);