Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / drivers / net / dgrs.c
blob2de40294430f0ab4db039e55a3b458fa278f8692
1 /*
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.
20 * OPERATION:
21 * When compiled as a loadable module, this driver can operate
22 * the board as either a 4/6 port switch with a 5th or 7th port
23 * that is a conventional NIC interface as far as the host is
24 * concerned, OR as 4/6 independent NICs. To select multi-NIC
25 * mode, add "nicmode=1" on the insmod load line for the driver.
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
42 * NIC mode.
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;
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.
76 static char*version ="$Id: dgrs.c,v 1.13 2000/06/06 04:07:00 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>
92 #include <asm/io.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)
110 #else
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)
116 #endif
119 * DGRS include files
121 typedefunsigned char uchar;
122 typedefunsigned int bool;
123 #define vol volatile
125 #include"dgrs.h"
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"
133 #if LINUX_VERSION_CODE >= 0x20400
134 static struct pci_device_id dgrs_pci_tbl[] __initdata = {
135 { SE6_PCI_VENDOR_ID, SE6_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, },
136 { }/* Terminating entry */
138 MODULE_DEVICE_TABLE(pci, dgrs_pci_tbl);
139 #endif/* LINUX_VERSION_CODE >= 0x20400 */
142 * Firmware. Compiled separately for local compilation,
143 * but #included for Linux distribution.
145 #ifndef NOFW
146 #include"dgrs_firmware.c"
147 #else
148 externint dgrs_firmnum;
149 externchar dgrs_firmver[];
150 externchar dgrs_firmdate[];
151 extern uchar dgrs_code[];
152 externint dgrs_ncode;
153 #endif
156 * Linux out*() is backwards from all other operating systems
158 #define OUTB(ADDR, VAL) outb(VAL, ADDR)
159 #define OUTW(ADDR, VAL) outw(VAL, ADDR)
160 #define OUTL(ADDR, VAL) outl(VAL, ADDR)
163 * Macros to convert switch to host and host to switch addresses
164 * (assumes a local variable priv points to board dependent struct)
166 #define S2H(A) ( ((unsigned long)(A)&0x00ffffff) + priv0->vmem )
167 #define S2HN(A) ( ((unsigned long)(A)&0x00ffffff) + privN->vmem )
168 #define H2S(A) ( ((char *) (A) - priv0->vmem) + 0xA3000000 )
171 * Convert a switch address to a "safe" address for use with the
172 * PLX 9060 DMA registers and the associated HW kludge that allows
173 * for host access of the DMA registers.
175 #define S2DMA(A) ( (unsigned long)(A) & 0x00ffffff)
178 * "Space.c" variables, now settable from module interface
179 * Use the name below, minus the "dgrs_" prefix. See init_module().
181 int dgrs_debug =1;
182 int dgrs_dma =1;
183 int dgrs_spantree = -1;
184 int dgrs_hashexpire = -1;
185 uchar dgrs_ipaddr[4] = {0xff,0xff,0xff,0xff};
186 uchar dgrs_iptrap[4] = {0xff,0xff,0xff,0xff};
187 __u32 dgrs_ipxnet = -1;
188 int dgrs_nicmode =0;
191 * Chain of device structures
193 static struct net_device *dgrs_root_dev = NULL;
196 * Private per-board data structure (dev->priv)
198 typedefstruct
201 * Stuff for generic ethercard I/F
203 struct net_device *next_dev;
204 struct net_device_stats stats;
207 * DGRS specific data
209 char*vmem;
211 struct bios_comm *bcomm;/* Firmware BIOS comm structure */
212 PORT *port;/* Ptr to PORT[0] struct in VM */
213 I596_SCB *scbp;/* Ptr to SCB struct in VM */
214 I596_RFD *rfdp;/* Current RFD list */
215 I596_RBD *rbdp;/* Current RBD list */
217 volatileint intrcnt;/* Count of interrupts */
220 * SE-4 (EISA) board variables
222 uchar is_reg;/* EISA: Value for ES4H_IS reg */
225 * SE-6 (PCI) board variables
227 * The PLX "expansion rom" space is used for DMA register
228 * access from the host on the SE-6. These are the physical
229 * and virtual addresses of that space.
231 ulong plxreg;/* Phys address of PLX chip */
232 char*vplxreg;/* Virtual address of PLX chip */
233 ulong plxdma;/* Phys addr of PLX "expansion rom" */
234 ulong volatile*vplxdma;/* Virtual addr of "expansion rom" */
235 int use_dma;/* Flag: use DMA */
236 DMACHAIN *dmadesc_s;/* area for DMA chains (SW addr.) */
237 DMACHAIN *dmadesc_h;/* area for DMA chains (Host Virtual) */
240 * Multi-NIC mode variables
242 * All entries of the devtbl[] array are valid for the 0th
243 * device (i.e. eth0, but not eth1...eth5). devtbl[0] is
244 * valid for all devices (i.e. eth0, eth1, ..., eth5).
246 int nports;/* Number of physical ports (4 or 6) */
247 int chan;/* Channel # (1-6) for this device */
248 struct net_device *devtbl[6];/* Ptrs to N device structs */
250 } DGRS_PRIV;
254 * reset or un-reset the IDT processor
256 static void
257 proc_reset(struct net_device *dev0,int reset)
259 DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
261 if(priv0->plxreg)
263 ulong val;
264 val =inl(dev0->base_addr + PLX_MISC_CSR);
265 if(reset)
266 val |= SE6_RESET;
267 else
268 val &= ~SE6_RESET;
269 OUTL(dev0->base_addr + PLX_MISC_CSR, val);
271 else
273 OUTB(dev0->base_addr + ES4H_PC, reset ? ES4H_PC_RESET :0);
278 * See if the board supports bus master DMA
280 static int
281 check_board_dma(struct net_device *dev0)
283 DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
284 ulong x;
287 * If Space.c says not to use DMA, or if its not a PLX based
288 * PCI board, or if the expansion ROM space is not PCI
289 * configured, then return false.
291 if(!dgrs_dma || !priv0->plxreg || !priv0->plxdma)
292 return(0);
295 * Set the local address remap register of the "expansion rom"
296 * area to 0x80000000 so that we can use it to access the DMA
297 * registers from the host side.
299 OUTL(dev0->base_addr + PLX_ROM_BASE_ADDR,0x80000000);
302 * Set the PCI region descriptor to:
303 * Space 0:
304 * disable read-prefetch
305 * enable READY
306 * enable BURST
307 * 0 internal wait states
308 * Expansion ROM: (used for host DMA register access)
309 * disable read-prefetch
310 * enable READY
311 * disable BURST
312 * 0 internal wait states
314 OUTL(dev0->base_addr + PLX_BUS_REGION,0x49430343);
317 * Now map the DMA registers into our virtual space
319 priv0->vplxdma = (ulong *)IOREMAP(priv0->plxdma,256);
320 if(!priv0->vplxdma)
322 printk("%s: can't *remap() the DMA regs\n", dev0->name);
323 return(0);
327 * Now test to see if we can access the DMA registers
328 * If we write -1 and get back 1FFF, then we accessed the
329 * DMA register. Otherwise, we probably have an old board
330 * and wrote into regular RAM.
332 priv0->vplxdma[PLX_DMA0_MODE/4] =0xFFFFFFFF;
333 x = priv0->vplxdma[PLX_DMA0_MODE/4];
334 if(x !=0x00001FFF)
335 return(0);
337 return(1);
341 * Initiate DMA using PLX part on PCI board. Spin the
342 * processor until completed. All addresses are physical!
344 * If pciaddr is NULL, then its a chaining DMA, and lcladdr is
345 * the address of the first DMA descriptor in the chain.
347 * If pciaddr is not NULL, then its a single DMA.
349 * In either case, "lcladdr" must have been fixed up to make
350 * sure the MSB isn't set using the S2DMA macro before passing
351 * the address to this routine.
353 static int
354 do_plx_dma(
355 struct net_device *dev,
356 ulong pciaddr,
357 ulong lcladdr,
358 int len,
359 int to_host
362 int i;
363 ulong csr =0;
364 DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
366 if(pciaddr)
369 * Do a single, non-chain DMA
371 priv->vplxdma[PLX_DMA0_PCI_ADDR/4] = pciaddr;
372 priv->vplxdma[PLX_DMA0_LCL_ADDR/4] = lcladdr;
373 priv->vplxdma[PLX_DMA0_SIZE/4] = len;
374 priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = to_host
375 ? PLX_DMA_DESC_TO_HOST
376 : PLX_DMA_DESC_TO_BOARD;
377 priv->vplxdma[PLX_DMA0_MODE/4] =
378 PLX_DMA_MODE_WIDTH32
379 |PLX_DMA_MODE_WAITSTATES(0)
380 | PLX_DMA_MODE_READY
381 | PLX_DMA_MODE_NOBTERM
382 | PLX_DMA_MODE_BURST
383 | PLX_DMA_MODE_NOCHAIN;
385 else
388 * Do a chaining DMA
390 priv->vplxdma[PLX_DMA0_MODE/4] =
391 PLX_DMA_MODE_WIDTH32
392 |PLX_DMA_MODE_WAITSTATES(0)
393 | PLX_DMA_MODE_READY
394 | PLX_DMA_MODE_NOBTERM
395 | PLX_DMA_MODE_BURST
396 | PLX_DMA_MODE_CHAIN;
397 priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = lcladdr;
400 priv->vplxdma[PLX_DMA_CSR/4] =
401 PLX_DMA_CSR_0_ENABLE | PLX_DMA_CSR_0_START;
404 * Wait for DMA to complete
406 for(i =0; i <1000000; ++i)
409 * Spin the host CPU for 1 usec, so we don't thrash
410 * the PCI bus while the PLX 9060 is doing DMA.
412 udelay(1);
414 csr = (volatileunsigned long) priv->vplxdma[PLX_DMA_CSR/4];
416 if(csr & PLX_DMA_CSR_0_DONE)
417 break;
420 if( ! (csr & PLX_DMA_CSR_0_DONE) )
422 printk("%s: DMA done never occurred. DMA disabled.\n",
423 dev->name);
424 priv->use_dma =0;
425 return1;
427 return0;
431 * dgrs_rcv_frame()
433 * Process a received frame. This is called from the interrupt
434 * routine, and works for both switch mode and multi-NIC mode.
436 * Note that when in multi-NIC mode, we want to always access the
437 * hardware using the dev and priv structures of the first port,
438 * so that we are using only one set of variables to maintain
439 * the board interface status, but we want to use the Nth port
440 * dev and priv structures to maintain statistics and to pass
441 * the packet up.
443 * Only the first device structure is attached to the interrupt.
444 * We use the special "chan" variable at the end of the first RBD
445 * to select the Nth device in multi-NIC mode.
447 * We currently do chained DMA on a per-packet basis when the
448 * packet is "long", and we spin the CPU a short time polling
449 * for DMA completion. This avoids a second interrupt overhead,
450 * and gives the best performance for light traffic to the host.
452 * However, a better scheme that could be implemented would be
453 * to see how many packets are outstanding for the host, and if
454 * the number is "large", create a long chain to DMA several
455 * packets into the host in one go. In this case, we would set
456 * up some state variables to let the host CPU continue doing
457 * other things until a DMA completion interrupt comes along.
459 void
460 dgrs_rcv_frame(
461 struct net_device *dev0,
462 DGRS_PRIV *priv0,
463 I596_CB *cbp
466 int len;
467 I596_TBD *tbdp;
468 struct sk_buff *skb;
469 uchar *putp;
470 uchar *p;
471 struct net_device *devN;
472 DGRS_PRIV *privN;
475 * Determine Nth priv and dev structure pointers
477 if(dgrs_nicmode)
478 {/* Multi-NIC mode */
479 int chan = ((I596_RBD *)S2H(cbp->xmit.tbdp))->chan;
481 devN = priv0->devtbl[chan-1];
483 * If devN is null, we got an interrupt before the I/F
484 * has been initialized. Pitch the packet.
486 if(devN == NULL)
487 goto out;
488 privN = (DGRS_PRIV *) devN->priv;
490 else
491 {/* Switch mode */
492 devN = dev0;
493 privN = priv0;
496 if(0)printk("%s: rcv len=%ld\n", devN->name, cbp->xmit.count);
499 * Allocate a message block big enough to hold the whole frame
501 len = cbp->xmit.count;
502 if((skb =dev_alloc_skb(len+5)) == NULL)
504 printk("%s: dev_alloc_skb failed for rcv buffer\n", devN->name);
505 ++privN->stats.rx_dropped;
506 /* discarding the frame */
507 goto out;
509 skb->dev = devN;
510 skb_reserve(skb,2);/* Align IP header */
512 again:
513 putp = p =skb_put(skb, len);
516 * There are three modes here for doing the packet copy.
517 * If we have DMA, and the packet is "long", we use the
518 * chaining mode of DMA. If it's shorter, we use single
519 * DMA's. Otherwise, we use memcpy().
521 if(priv0->use_dma && priv0->dmadesc_h && len >64)
524 * If we can use DMA and its a long frame, copy it using
525 * DMA chaining.
527 DMACHAIN *ddp_h;/* Host virtual DMA desc. pointer */
528 DMACHAIN *ddp_s;/* Switch physical DMA desc. pointer */
529 uchar *phys_p;
532 * Get the physical address of the STREAMS buffer.
533 * NOTE: allocb() guarantees that the whole buffer
534 * is in a single page if the length < 4096.
536 phys_p = (uchar *)virt_to_phys(putp);
538 ddp_h = priv0->dmadesc_h;
539 ddp_s = priv0->dmadesc_s;
540 tbdp = (I596_TBD *)S2H(cbp->xmit.tbdp);
541 for(;;)
543 int count;
544 int amt;
546 count = tbdp->count;
547 amt = count &0x3fff;
548 if(amt ==0)
549 break;/* For safety */
550 if( (p-putp) >= len)
552 printk("%s: cbp = %x\n", devN->name,H2S(cbp));
553 proc_reset(dev0,1);/* Freeze IDT */
554 break;/* For Safety */
557 ddp_h->pciaddr = (ulong) phys_p;
558 ddp_h->lcladdr =S2DMA(tbdp->buf);
559 ddp_h->len = amt;
561 phys_p += amt;
562 p += amt;
564 if(count & I596_TBD_EOF)
566 ddp_h->next = PLX_DMA_DESC_TO_HOST
567 | PLX_DMA_DESC_EOC;
568 ++ddp_h;
569 break;
571 else
573 ++ddp_s;
574 ddp_h->next = PLX_DMA_DESC_TO_HOST
575 | (ulong) ddp_s;
576 tbdp = (I596_TBD *)S2H(tbdp->next);
577 ++ddp_h;
580 if(ddp_h - priv0->dmadesc_h)
582 int rc;
584 rc =do_plx_dma(dev0,
585 0, (ulong) priv0->dmadesc_s, len,0);
586 if(rc)
588 printk("%s: Chained DMA failure\n", devN->name);
589 goto again;
593 else if(priv0->use_dma)
596 * If we can use DMA and its a shorter frame, copy it
597 * using single DMA transfers.
599 uchar *phys_p;
602 * Get the physical address of the STREAMS buffer.
603 * NOTE: allocb() guarantees that the whole buffer
604 * is in a single page if the length < 4096.
606 phys_p = (uchar *)virt_to_phys(putp);
608 tbdp = (I596_TBD *)S2H(cbp->xmit.tbdp);
609 for(;;)
611 int count;
612 int amt;
613 int rc;
615 count = tbdp->count;
616 amt = count &0x3fff;
617 if(amt ==0)
618 break;/* For safety */
619 if( (p-putp) >= len)
621 printk("%s: cbp = %x\n", devN->name,H2S(cbp));
622 proc_reset(dev0,1);/* Freeze IDT */
623 break;/* For Safety */
625 rc =do_plx_dma(dev0, (ulong) phys_p,
626 S2DMA(tbdp->buf), amt,1);
627 if(rc)
629 memcpy(p,S2H(tbdp->buf), amt);
630 printk("%s: Single DMA failed\n", devN->name);
632 phys_p += amt;
633 p += amt;
634 if(count & I596_TBD_EOF)
635 break;
636 tbdp = (I596_TBD *)S2H(tbdp->next);
639 else
642 * Otherwise, copy it piece by piece using memcpy()
644 tbdp = (I596_TBD *)S2H(cbp->xmit.tbdp);
645 for(;;)
647 int count;
648 int amt;
650 count = tbdp->count;
651 amt = count &0x3fff;
652 if(amt ==0)
653 break;/* For safety */
654 if( (p-putp) >= len)
656 printk("%s: cbp = %x\n", devN->name,H2S(cbp));
657 proc_reset(dev0,1);/* Freeze IDT */
658 break;/* For Safety */
660 memcpy(p,S2H(tbdp->buf), amt);
661 p += amt;
662 if(count & I596_TBD_EOF)
663 break;
664 tbdp = (I596_TBD *)S2H(tbdp->next);
669 * Pass the frame to upper half
671 skb->protocol =eth_type_trans(skb, devN);
672 netif_rx(skb);
673 ++privN->stats.rx_packets;
675 out:
676 cbp->xmit.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
680 * Start transmission of a frame
682 * The interface to the board is simple: we pretend that we are
683 * a fifth 82596 ethernet controller 'receiving' data, and copy the
684 * data into the same structures that a real 82596 would. This way,
685 * the board firmware handles the host 'port' the same as any other.
687 * NOTE: we do not use Bus master DMA for this routine. Turns out
688 * that it is not needed. Slave writes over the PCI bus are about
689 * as fast as DMA, due to the fact that the PLX part can do burst
690 * writes. The same is not true for data being read from the board.
692 * For multi-NIC mode, we tell the firmware the desired 82596
693 * output port by setting the special "dstchan" member at the
694 * end of the traditional 82596 RFD structure.
697 static intdgrs_start_xmit(struct sk_buff *skb,struct net_device *devN)
699 DGRS_PRIV *privN = (DGRS_PRIV *) devN->priv;
700 struct net_device *dev0;
701 DGRS_PRIV *priv0;
702 I596_RBD *rbdp;
703 int count;
704 int i, len, amt;
705 # define mymin(A,B) ( (A) < (B) ? (A) : (B) )
708 * Determine 0th priv and dev structure pointers
710 if(dgrs_nicmode)
712 dev0 = privN->devtbl[0];
713 priv0 = (DGRS_PRIV *) dev0->priv;
715 else
717 dev0 = devN;
718 priv0 = privN;
721 if(dgrs_debug >1)
722 printk("%s: xmit len=%d\n", devN->name, (int) skb->len);
724 devN->trans_start = jiffies;
725 netif_start_queue(devN);
727 if(priv0->rfdp->cmd & I596_RFD_EL)
728 {/* Out of RFD's */
729 if(0)printk("%s: NO RFD's\n", devN->name);
730 goto no_resources;
733 rbdp = priv0->rbdp;
734 count =0;
735 priv0->rfdp->rbdp = (I596_RBD *)H2S(rbdp);
737 i =0; len = skb->len;
738 for(;;)
740 if(rbdp->size & I596_RBD_EL)
741 {/* Out of RBD's */
742 if(0)printk("%s: NO RBD's\n", devN->name);
743 goto no_resources;
746 amt =mymin(len, rbdp->size - count);
747 memcpy( (char*)S2H(rbdp->buf) + count, skb->data + i, amt);
748 i += amt;
749 count += amt;
750 len -= amt;
751 if(len ==0)
753 if(skb->len <60)
754 rbdp->count =60| I596_RBD_EOF;
755 else
756 rbdp->count = count | I596_RBD_EOF;
757 rbdp = (I596_RBD *)S2H(rbdp->next);
758 goto frame_done;
760 else if(count <32)
762 /* More data to come, but we used less than 32
763 * bytes of this RBD. Keep filling this RBD.
765 {}/* Yes, we do nothing here */
767 else
769 rbdp->count = count;
770 rbdp = (I596_RBD *)S2H(rbdp->next);
771 count =0;
775 frame_done:
776 priv0->rbdp = rbdp;
777 if(dgrs_nicmode)
778 priv0->rfdp->dstchan = privN->chan;
779 priv0->rfdp->status = I596_RFD_C | I596_RFD_OK;
780 priv0->rfdp = (I596_RFD *)S2H(priv0->rfdp->next);
782 ++privN->stats.tx_packets;
784 dev_kfree_skb(skb);
785 return(0);
787 no_resources:
788 priv0->scbp->status |= I596_SCB_RNR;/* simulate I82596 */
789 return(-EAGAIN);
793 * Open the interface
795 static int
796 dgrs_open(struct net_device *dev )
798 netif_start_queue(dev);
799 return(0);
803 * Close the interface
805 static intdgrs_close(struct net_device *dev )
807 netif_stop_queue(dev);
808 return(0);
812 * Get statistics
814 static struct net_device_stats *dgrs_get_stats(struct net_device *dev )
816 DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
818 return(&priv->stats);
822 * Set multicast list and/or promiscuous mode
825 static voiddgrs_set_multicast_list(struct net_device *dev)
827 DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
829 priv->port->is_promisc = (dev->flags & IFF_PROMISC) ?1:0;
833 * Unique ioctl's
835 static intdgrs_ioctl(struct net_device *devN,struct ifreq *ifr,int cmd)
837 DGRS_PRIV *privN = (DGRS_PRIV *) devN->priv;
838 DGRS_IOCTL ioc;
839 int i;
841 if(cmd != DGRSIOCTL)
842 return-EINVAL;
844 if(COPY_FROM_USER(&ioc, ifr->ifr_data,sizeof(DGRS_IOCTL)))
845 return-EFAULT;
847 switch(ioc.cmd)
849 case DGRS_GETMEM:
850 if(ioc.len !=sizeof(ulong))
851 return-EINVAL;
852 if(COPY_TO_USER(ioc.data, &devN->mem_start, ioc.len))
853 return-EFAULT;
854 return(0);
855 case DGRS_SETFILTER:
856 if(!capable(CAP_NET_ADMIN))
857 return-EPERM;
858 if(ioc.port > privN->bcomm->bc_nports)
859 return-EINVAL;
860 if(ioc.filter >= NFILTERS)
861 return-EINVAL;
862 if(ioc.len > privN->bcomm->bc_filter_area_len)
863 return-EINVAL;
865 /* Wait for old command to finish */
866 for(i =0; i <1000; ++i)
868 if( (volatilelong) privN->bcomm->bc_filter_cmd <=0)
869 break;
870 udelay(1);
872 if(i >=1000)
873 return-EIO;
875 privN->bcomm->bc_filter_port = ioc.port;
876 privN->bcomm->bc_filter_num = ioc.filter;
877 privN->bcomm->bc_filter_len = ioc.len;
879 if(ioc.len)
881 if(COPY_FROM_USER(S2HN(privN->bcomm->bc_filter_area),
882 ioc.data, ioc.len))
883 return-EFAULT;
884 privN->bcomm->bc_filter_cmd = BC_FILTER_SET;
886 else
887 privN->bcomm->bc_filter_cmd = BC_FILTER_CLR;
888 return(0);
889 default:
890 return-EOPNOTSUPP;
895 * Process interrupts
897 * dev, priv will always refer to the 0th device in Multi-NIC mode.
900 static voiddgrs_intr(int irq,void*dev_id,struct pt_regs *regs)
902 struct net_device *dev0 = (struct net_device *) dev_id;
903 DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
904 I596_CB *cbp;
905 int cmd;
906 int i;
908 ++priv0->intrcnt;
909 if(1) ++priv0->bcomm->bc_cnt[4];
910 if(0)
912 static int cnt =100;
913 if(--cnt >0)
914 printk("%s: interrupt: irq %d\n", dev0->name, irq);
918 * Get 596 command
920 cmd = priv0->scbp->cmd;
923 * See if RU has been restarted
925 if( (cmd & I596_SCB_RUC) == I596_SCB_RUC_START)
927 if(0)printk("%s: RUC start\n", dev0->name);
928 priv0->rfdp = (I596_RFD *)S2H(priv0->scbp->rfdp);
929 priv0->rbdp = (I596_RBD *)S2H(priv0->rfdp->rbdp);
930 priv0->scbp->status &= ~(I596_SCB_RNR|I596_SCB_RUS);
932 * Tell upper half (halves)
934 if(dgrs_nicmode)
936 for(i =0; i < priv0->nports; ++i)
937 netif_wake_queue(priv0->devtbl[i]);
939 else
940 netif_wake_queue(dev0);
941 /* if (bd->flags & TX_QUEUED)
942 DL_sched(bd, bdd); */
946 * See if any CU commands to process
948 if( (cmd & I596_SCB_CUC) != I596_SCB_CUC_START)
950 priv0->scbp->cmd =0;/* Ignore all other commands */
951 goto ack_intr;
953 priv0->scbp->status &= ~(I596_SCB_CNA|I596_SCB_CUS);
956 * Process a command
958 cbp = (I596_CB *)S2H(priv0->scbp->cbp);
959 priv0->scbp->cmd =0;/* Safe to clear the command */
960 for(;;)
962 switch(cbp->nop.cmd & I596_CB_CMD)
964 case I596_CB_CMD_XMIT:
965 dgrs_rcv_frame(dev0, priv0, cbp);
966 break;
967 default:
968 cbp->nop.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
969 break;
971 if(cbp->nop.cmd & I596_CB_CMD_EL)
972 break;
973 cbp = (I596_CB *)S2H(cbp->nop.next);
975 priv0->scbp->status |= I596_SCB_CNA;
978 * Ack the interrupt
980 ack_intr:
981 if(priv0->plxreg)
982 OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL,1);
986 * Download the board firmware
988 static int __init
989 dgrs_download(struct net_device *dev0)
991 DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
992 int is;
993 int i;
995 static int iv2is[16] = {
996 0,0,0, ES4H_IS_INT3,
997 0, ES4H_IS_INT5,0, ES4H_IS_INT7,
998 0,0, ES4H_IS_INT10, ES4H_IS_INT11,
999 ES4H_IS_INT12,0,0, ES4H_IS_INT15 };
1002 * Map in the dual port memory
1004 priv0->vmem =IOREMAP(dev0->mem_start,2048*1024);
1005 if(!priv0->vmem)
1007 printk("%s: cannot map in board memory\n", dev0->name);
1008 return-ENXIO;
1012 * Hold the processor and configure the board addresses
1014 if(priv0->plxreg)
1015 {/* PCI bus */
1016 proc_reset(dev0,1);
1018 else
1019 {/* EISA bus */
1020 is = iv2is[dev0->irq &0x0f];
1021 if(!is)
1023 printk("%s: Illegal IRQ %d\n", dev0->name, dev0->irq);
1024 return-ENXIO;
1026 OUTB(dev0->base_addr + ES4H_AS_31_24,
1027 (uchar) (dev0->mem_start >>24) );
1028 OUTB(dev0->base_addr + ES4H_AS_23_16,
1029 (uchar) (dev0->mem_start >>16) );
1030 priv0->is_reg = ES4H_IS_LINEAR | is |
1031 ((uchar) (dev0->mem_start >>8) & ES4H_IS_AS15);
1032 OUTB(dev0->base_addr + ES4H_IS, priv0->is_reg);
1033 OUTB(dev0->base_addr + ES4H_EC, ES4H_EC_ENABLE);
1034 OUTB(dev0->base_addr + ES4H_PC, ES4H_PC_RESET);
1035 OUTB(dev0->base_addr + ES4H_MW, ES4H_MW_ENABLE |0x00);
1039 * See if we can do DMA on the SE-6
1041 priv0->use_dma =check_board_dma(dev0);
1042 if(priv0->use_dma)
1043 printk("%s: Bus Master DMA is enabled.\n", dev0->name);
1046 * Load and verify the code at the desired address
1048 memcpy(priv0->vmem, dgrs_code, dgrs_ncode);/* Load code */
1049 if(memcmp(priv0->vmem, dgrs_code, dgrs_ncode))
1051 IOUNMAP(priv0->vmem);
1052 priv0->vmem = NULL;
1053 printk("%s: download compare failed\n", dev0->name);
1054 return-ENXIO;
1058 * Configurables
1060 priv0->bcomm = (struct bios_comm *) (priv0->vmem +0x0100);
1061 priv0->bcomm->bc_nowait =1;/* Tell board to make printf not wait */
1062 priv0->bcomm->bc_squelch =0;/* Flag from Space.c */
1063 priv0->bcomm->bc_150ohm =0;/* Flag from Space.c */
1065 priv0->bcomm->bc_spew =0;/* Debug flag from Space.c */
1066 priv0->bcomm->bc_maxrfd =0;/* Debug flag from Space.c */
1067 priv0->bcomm->bc_maxrbd =0;/* Debug flag from Space.c */
1070 * Tell board we are operating in switch mode (1) or in
1071 * multi-NIC mode (2).
1073 priv0->bcomm->bc_host = dgrs_nicmode ? BC_MULTINIC : BC_SWITCH;
1076 * Request memory space on board for DMA chains
1078 if(priv0->use_dma)
1079 priv0->bcomm->bc_hostarea_len = (2048/64) *16;
1082 * NVRAM configurables from Space.c
1084 priv0->bcomm->bc_spantree = dgrs_spantree;
1085 priv0->bcomm->bc_hashexpire = dgrs_hashexpire;
1086 memcpy(priv0->bcomm->bc_ipaddr, dgrs_ipaddr,4);
1087 memcpy(priv0->bcomm->bc_iptrap, dgrs_iptrap,4);
1088 memcpy(priv0->bcomm->bc_ipxnet, &dgrs_ipxnet,4);
1091 * Release processor, wait 8 seconds for board to initialize
1093 proc_reset(dev0,0);
1095 for(i = jiffies +8* HZ;time_after(i, jiffies); )
1097 barrier();/* Gcc 2.95 needs this */
1098 if(priv0->bcomm->bc_status >= BC_RUN)
1099 break;
1102 if(priv0->bcomm->bc_status < BC_RUN)
1104 printk("%s: board not operating\n", dev0->name);
1105 return-ENXIO;
1108 priv0->port = (PORT *)S2H(priv0->bcomm->bc_port);
1109 priv0->scbp = (I596_SCB *)S2H(priv0->port->scbp);
1110 priv0->rfdp = (I596_RFD *)S2H(priv0->scbp->rfdp);
1111 priv0->rbdp = (I596_RBD *)S2H(priv0->rfdp->rbdp);
1113 priv0->scbp->status = I596_SCB_CNA;/* CU is idle */
1116 * Get switch physical and host virtual pointers to DMA
1117 * chaining area. NOTE: the MSB of the switch physical
1118 * address *must* be turned off. Otherwise, the HW kludge
1119 * that allows host access of the PLX DMA registers will
1120 * erroneously select the PLX registers.
1122 priv0->dmadesc_s = (DMACHAIN *)S2DMA(priv0->bcomm->bc_hostarea);
1123 if(priv0->dmadesc_s)
1124 priv0->dmadesc_h = (DMACHAIN *)S2H(priv0->dmadesc_s);
1125 else
1126 priv0->dmadesc_h = NULL;
1129 * Enable board interrupts
1131 if(priv0->plxreg)
1132 {/* PCI bus */
1133 OUTL(dev0->base_addr + PLX_INT_CSR,
1134 inl(dev0->base_addr + PLX_INT_CSR)
1135 | PLX_PCI_DOORBELL_IE);/* Enable intr to host */
1136 OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL,1);
1138 else
1139 {/* EISA bus */
1142 return(0);
1146 * Probe (init) a board
1148 int __init
1149 dgrs_probe1(struct net_device *dev)
1151 DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
1152 int i;
1153 int rc;
1155 printk("%s: Digi RightSwitch io=%lx mem=%lx irq=%d plx=%lx dma=%lx\n",
1156 dev->name, dev->base_addr, dev->mem_start, dev->irq,
1157 priv->plxreg, priv->plxdma);
1160 * Download the firmware and light the processor
1162 rc =dgrs_download(dev);
1163 if(rc)
1165 return rc;
1169 * Get ether address of board
1171 printk("%s: Ethernet address", dev->name);
1172 memcpy(dev->dev_addr, priv->port->ethaddr,6);
1173 for(i =0; i <6; ++i)
1174 printk("%c%2.2x", i ?':':' ', dev->dev_addr[i]);
1175 printk("\n");
1177 if(dev->dev_addr[0] &1)
1179 printk("%s: Illegal Ethernet Address\n", dev->name);
1180 return(-ENXIO);
1184 * ACK outstanding interrupts, hook the interrupt,
1185 * and verify that we are getting interrupts from the board.
1187 if(priv->plxreg)
1188 OUTL(dev->base_addr + PLX_LCL2PCI_DOORBELL,1);
1189 rc =request_irq(dev->irq, &dgrs_intr, SA_SHIRQ,"RightSwitch", dev);
1190 if(rc)
1191 return(rc);
1193 priv->intrcnt =0;
1194 for(i = jiffies +2*HZ + HZ/2;time_after(i, jiffies); )
1196 barrier();/* gcc 2.95 needs this */
1197 if(priv->intrcnt >=2)
1198 break;
1200 if(priv->intrcnt <2)
1202 printk("%s: Not interrupting on IRQ %d (%d)\n",
1203 dev->name, dev->irq, priv->intrcnt);
1204 return(-ENXIO);
1208 * Register the /proc/ioports information...
1210 request_region(dev->base_addr,256,"RightSwitch");
1213 * Entry points...
1215 dev->open = &dgrs_open;
1216 dev->stop = &dgrs_close;
1217 dev->get_stats = &dgrs_get_stats;
1218 dev->hard_start_xmit = &dgrs_start_xmit;
1219 dev->set_multicast_list = &dgrs_set_multicast_list;
1220 dev->do_ioctl = &dgrs_ioctl;
1222 return(0);
1225 int __init
1226 dgrs_initclone(struct net_device *dev)
1228 DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
1229 int i;
1231 printk("%s: Digi RightSwitch port %d ",
1232 dev->name, priv->chan);
1233 for(i =0; i <6; ++i)
1234 printk("%c%2.2x", i ?':':' ', dev->dev_addr[i]);
1235 printk("\n");
1237 return(0);
1240 static int __init
1241 dgrs_found_device(
1242 int io,
1243 ulong mem,
1244 int irq,
1245 ulong plxreg,
1246 ulong plxdma
1249 DGRS_PRIV *priv;
1250 struct net_device *dev;
1252 /* Allocate and fill new device structure. */
1253 int dev_size =sizeof(struct net_device) +sizeof(DGRS_PRIV);
1254 int i;
1256 dev = (struct net_device *)kmalloc(dev_size, GFP_KERNEL);
1257 memset(dev,0, dev_size);
1258 dev->priv = ((void*)dev) +sizeof(struct net_device);
1259 priv = (DGRS_PRIV *)dev->priv;
1261 dev->base_addr = io;
1262 dev->mem_start = mem;
1263 dev->mem_end = mem +2048*1024-1;
1264 dev->irq = irq;
1265 priv->plxreg = plxreg;
1266 priv->plxdma = plxdma;
1267 priv->vplxdma = NULL;
1269 priv->chan =1;
1270 priv->devtbl[0] = dev;
1272 dev->init = dgrs_probe1;
1273 SET_MODULE_OWNER(dev);
1274 ether_setup(dev);
1275 priv->next_dev = dgrs_root_dev;
1276 dgrs_root_dev = dev;
1277 if(register_netdev(dev) !=0)
1278 return-EIO;
1280 if( !dgrs_nicmode )
1281 return(0);/* Switch mode, we are done */
1284 * Operating card as N separate NICs
1287 priv->nports = priv->bcomm->bc_nports;
1289 for(i =1; i < priv->nports; ++i)
1291 struct net_device *devN;
1292 DGRS_PRIV *privN;
1293 /* Allocate new dev and priv structures */
1294 devN = (struct net_device *)kmalloc(dev_size, GFP_KERNEL);
1295 /* Make it an exact copy of dev[0]... */
1296 memcpy(devN, dev, dev_size);
1297 devN->priv = ((void*)devN) +sizeof(struct net_device);
1298 privN = (DGRS_PRIV *)devN->priv;
1299 /* ... and zero out VM areas */
1300 privN->vmem =0;
1301 privN->vplxdma =0;
1302 /* ... and zero out IRQ */
1303 devN->irq =0;
1304 /* ... and base MAC address off address of 1st port */
1305 devN->dev_addr[5] += i;
1306 privN->chan = i+1;
1307 priv->devtbl[i] = devN;
1308 devN->init = dgrs_initclone;
1309 SET_MODULE_OWNER(dev);
1310 ether_setup(devN);
1311 privN->next_dev = dgrs_root_dev;
1312 dgrs_root_dev = devN;
1313 if(register_netdev(devN) !=0)
1314 return-EIO;
1316 return(0);
1320 * Scan for all boards
1322 static int is2iv[8] __initdata = {0,3,5,7,10,11,12,15};
1324 static int __init dgrs_scan(void)
1326 int cards_found =0;
1327 uint io;
1328 uint mem;
1329 uint irq;
1330 uint plxreg;
1331 uint plxdma;
1334 * First, check for PCI boards
1336 if(pci_present())
1338 struct pci_dev *pdev = NULL;
1340 while((pdev =pci_find_device(SE6_PCI_VENDOR_ID, SE6_PCI_DEVICE_ID, pdev)) != NULL)
1342 plxreg =pci_resource_start(pdev,0);
1343 io =pci_resource_start(pdev,1);
1344 mem =pci_resource_start(pdev,2);
1345 pci_read_config_dword(pdev,0x30, &plxdma);
1346 irq = pdev->irq;
1347 plxdma &= ~15;
1350 * On some BIOSES, the PLX "expansion rom" (used for DMA)
1351 * address comes up as "0". This is probably because
1352 * the BIOS doesn't see a valid 55 AA ROM signature at
1353 * the "ROM" start and zeroes the address. To get
1354 * around this problem the SE-6 is configured to ask
1355 * for 4 MB of space for the dual port memory. We then
1356 * must set its range back to 2 MB, and use the upper
1357 * half for DMA register access
1359 OUTL(io + PLX_SPACE0_RANGE,0xFFE00000L);
1360 if(plxdma ==0)
1361 plxdma = mem + (2048L*1024L);
1362 pci_write_config_dword(pdev,0x30, plxdma +1);
1363 pci_read_config_dword(pdev,0x30, &plxdma);
1364 plxdma &= ~15;
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))
1374 continue;
1375 pci_set_master(pdev);
1377 dgrs_found_device(io, mem, irq, plxreg, plxdma);
1379 cards_found++;
1384 * Second, check for EISA boards
1386 if(EISA_bus)
1388 for(io =0x1000; io <0x9000; io +=0x1000)
1390 if(inb(io+ES4H_MANUFmsb) !=0x10
1391 ||inb(io+ES4H_MANUFlsb) !=0x49
1392 ||inb(io+ES4H_PRODUCT) != ES4H_PRODUCT_CODE)
1393 continue;
1395 if( ! (inb(io+ES4H_EC) & ES4H_EC_ENABLE) )
1396 continue;/* Not EISA configured */
1398 mem = (inb(io+ES4H_AS_31_24) <<24)
1399 + (inb(io+ES4H_AS_23_16) <<16);
1401 irq = is2iv[inb(io+ES4H_IS) & ES4H_IS_INTMASK ];
1403 dgrs_found_device(io, mem, irq,0L,0L);
1405 ++cards_found;
1409 return cards_found;
1414 * Variables that can be overriden from module command line
1416 static int debug = -1;
1417 static int dma = -1;
1418 static int hashexpire = -1;
1419 static int spantree = -1;
1420 static int ipaddr[4] = { -1};
1421 static int iptrap[4] = { -1};
1422 static __u32 ipxnet = -1;
1423 static int nicmode = -1;
1425 MODULE_PARM(debug,"i");
1426 MODULE_PARM(dma,"i");
1427 MODULE_PARM(hashexpire,"i");
1428 MODULE_PARM(spantree,"i");
1429 MODULE_PARM(ipaddr,"1-4i");
1430 MODULE_PARM(iptrap,"1-4i");
1431 MODULE_PARM(ipxnet,"i");
1432 MODULE_PARM(nicmode,"i");
1434 static int __init dgrs_init_module(void)
1436 int cards_found;
1437 int i;
1440 * Command line variable overrides
1441 * debug=NNN
1442 * dma=0/1
1443 * spantree=0/1
1444 * hashexpire=NNN
1445 * ipaddr=A,B,C,D
1446 * iptrap=A,B,C,D
1447 * ipxnet=NNN
1448 * nicmode=NNN
1450 if(debug >=0)
1451 dgrs_debug = debug;
1452 if(dma >=0)
1453 dgrs_dma = dma;
1454 if(nicmode >=0)
1455 dgrs_nicmode = nicmode;
1456 if(hashexpire >=0)
1457 dgrs_hashexpire = hashexpire;
1458 if(spantree >=0)
1459 dgrs_spantree = spantree;
1460 if(ipaddr[0] != -1)
1461 for(i =0; i <4; ++i)
1462 dgrs_ipaddr[i] = ipaddr[i];
1463 if(iptrap[0] != -1)
1464 for(i =0; i <4; ++i)
1465 dgrs_iptrap[i] = iptrap[i];
1466 if(ipxnet != -1)
1467 dgrs_ipxnet =htonl( ipxnet );
1469 if(dgrs_debug)
1471 printk("dgrs: SW=%s FW=Build %d %s\n",
1472 version, dgrs_firmnum, dgrs_firmdate);
1476 * Find and configure all the cards
1478 dgrs_root_dev = NULL;
1479 cards_found =dgrs_scan();
1481 return cards_found ?0: -ENODEV;
1484 static void __exit dgrs_cleanup_module(void)
1486 while(dgrs_root_dev)
1488 struct net_device *next_dev;
1489 DGRS_PRIV *priv;
1491 priv = (DGRS_PRIV *) dgrs_root_dev->priv;
1492 next_dev = priv->next_dev;
1493 unregister_netdev(dgrs_root_dev);
1495 proc_reset(priv->devtbl[0],1);
1497 if(priv->vmem)
1498 IOUNMAP(priv->vmem);
1499 if(priv->vplxdma)
1500 IOUNMAP((uchar *) priv->vplxdma);
1502 release_region(dgrs_root_dev->base_addr,256);
1504 if(dgrs_root_dev->irq)
1505 free_irq(dgrs_root_dev->irq, dgrs_root_dev);
1507 kfree(dgrs_root_dev);
1508 dgrs_root_dev = next_dev;
1512 module_init(dgrs_init_module);
1513 module_exit(dgrs_cleanup_module);
close