1 /* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux. 2
3 Written 1994 by David C. Davies. 4
5
6 Copyright 1994 David C. Davies 7 and 8 United States Government 9 (as represented by the Director, National Security Agency). 10
11
12 This software may be used and distributed according to the terms of 13 the GNU Public License, incorporated herein by reference. 14
15 This driver is written for the Digital Equipment Corporation series 16 of DEPCA and EtherWORKS ethernet cards: 17
18 DEPCA (the original) 19 DE100 20 DE101 21 DE200 Turbo 22 DE201 Turbo 23 DE202 Turbo (TP BNC) 24 DE210 25 DE422 (EISA) 26
27 The driver has been tested on DE100, DE200 and DE202 cards in a 28 relatively busy network. The DE422 has been tested a little. 29
30 This driver will NOT work for the DE203, DE204 and DE205 series of 31 cards, since they have a new custom ASIC in place of the AMD LANCE 32 chip. 33
34 The author may be reached as davies@wanton.lkg.dec.com or 35 Digital Equipment Corporation, 550 King Street, Littleton MA 01460. 36
37 ========================================================================= 38 The driver was based on the 'lance.c' driver from Donald Becker which is 39 included with the standard driver distribution for linux. Modifications 40 were made to most routines and the hardware recognition routines were 41 written from scratch. Primary references used were: 42
43 1) Lance.c code in /linux/drivers/net/ 44 2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook", 45 AMD, 1992 [(800) 222-9323]. 46 3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)", 47 AMD, Pub. #17881, May 1993. 48 4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA", 49 AMD, Pub. #16907, May 1992 50 5) "DEC EtherWORKS LC Ethernet Controller Owners Manual", 51 Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003 52 6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual", 53 Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003 54 7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR 55 Digital Equipment Corporation, 1989 56 8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual", 57 Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001 58 59 Peter Bauer's depca.c (V0.5) was referred to when debugging this driver. 60 The hash filter code was derived from Reference 3 and has been tested 61 only to the extent that the Table A-1, page A-7, was confirmed to fill 62 the filter bit positions correctly. Hash filtering is not yet 63 implemented in the current driver set. 64
65 The original DEPCA card requires that the ethernet ROM address counter 66 be enabled to count and has an 8 bit NICSR. The ROM counter enabling is 67 only done when a 0x08 is read as the first address octet (to minimise 68 the chances of writing over some other hardware's I/O register). The 69 NICSR accesses have been changed to byte accesses for all the cards 70 supported by this driver, since there is only one useful bit in the MSB 71 (remote boot timeout) and it is not used. Also, there is a maximum of 72 only 48kB network RAM for this card. My thanks to Torbjorn Lindh for 73 help debugging all this (and holding my feet to the fire until I got it 74 right). 75
76 The DE200 series boards have on-board 64kB RAM for use as a shared 77 memory network buffer. Only the DE100 cards make use of a 2kB buffer 78 mode which has not been implemented in this driver (only the 32kB and 79 64kB modes are supported [16kB/48kB for the original DEPCA]). 80
81 At the most only 2 DEPCA cards can be supported on the ISA bus because 82 there is only provision for two I/O base addresses on each card (0x300 83 and 0x200). The I/O address is detected by searching for a byte sequence 84 in the Ethernet station address PROM at the expected I/O address for the 85 Ethernet PROM. The shared memory base address is 'autoprobed' by 86 looking for the self test PROM and detecting the card name. When a 87 second DEPCA is detected, information is placed in the base_addr 88 variable of the next device structure (which is created if necessary), 89 thus enabling ethif_probe initialization for the device. More than 2 90 EISA cards can be supported, but care will be needed assigning the 91 shared memory to ensure that each slot has the correct IRQ, I/O address 92 and shared memory address assigned. 93
94 ************************************************************************ 95
96 NOTE: If you are using two ISA DEPCAs, it is important that you assign 97 the base memory addresses correctly. The driver autoprobes I/O 0x300 98 then 0x200. The base memory address for the first device must be less 99 than that of the second so that the auto probe will correctly assign the 100 I/O and memory addresses on the same card. I can't think of a way to do 101 this unambiguously at the moment, since there is nothing on the cards to 102 tie I/O and memory information together. 103
104 I am unable to test 2 cards together for now, so this code is 105 unchecked. All reports, good or bad, are welcome. 106
107 ************************************************************************ 108
109 The board IRQ setting must be at an unused IRQ which is auto-probed 110 using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are 111 {2,3,4,5,7}, whereas the DE200 is at {5,9,10,11,15}. Note that IRQ2 is 112 really IRQ9 in machines with 16 IRQ lines. 113
114 No 16MB memory limitation should exist with this driver as DMA is not 115 used and the common memory area is in low memory on the network card (my 116 current system has 20MB and I've not had problems yet). 117
118 The ability to load this driver as a loadable module has been added. To 119 utilise this ability, you have to do <8 things: 120
121 1) copy depca.c from the /linux/drivers/net directory to your favourite 122 temporary directory. 123 2) edit the source code near line 1530 to reflect the I/O address and 124 IRQ you're using. 125 3) compile depca.c, but include -DMODULE in the command line to ensure 126 that the correct bits are compiled (see end of source code). 127 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a 128 kernel with the depca configuration turned off and reboot. 129 5) insmod depca.o 130 6) run the net startup bits for your eth?? interface manually 131 (usually /etc/rc.inet[12] at boot time). 132 7) enjoy! 133
134 Note that autoprobing is not allowed in loadable modules - the system is 135 already up and running and you're messing with interrupts. Also, there 136 is no way to check on the number of depcas installed at the moment. 137
138 To unload a module, turn off the associated interface 139 'ifconfig eth?? down' then 'rmmod depca'. 140
141 [Alan Cox: Changed to split off the module values as ints for insmod 142 143 you can now do insmod depca.c irq=7 io=0x200 ] 144 145
146 TO DO: 147 ------ 148
149 1. Implement the 2k buffer mode - does anyone need it?? 150
151 Revision History 152 ---------------- 153
154 Version Date Description 155 156 0.1 25-jan-94 Initial writing. 157 0.2 27-jan-94 Added LANCE TX hardware buffer chaining. 158 0.3 1-feb-94 Added multiple DEPCA support. 159 0.31 4-feb-94 Added DE202 recognition. 160 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support. 161 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable. 162 Add jabber packet fix from murf@perftech.com 163 and becker@super.org 164 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access. 165 0.35 8-mar-94 Added DE201 recognition. Tidied up. 166 0.351 30-apr-94 Added EISA support. Added DE422 recognition. 167 0.36 16-may-94 DE422 fix released. 168 0.37 22-jul-94 Added MODULE support 169 0.38 15-aug-94 Added DBR ROM switch in depca_close(). 170 Multi DEPCA bug fix. 171 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0. 172 0.381 12-dec-94 Added DE101 recognition, fix multicast bug. 173 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>. 174 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by 175 <stromain@alf.dec.com> 176
177 ========================================================================= 178 */ 179
180 staticchar *version = "depca.c:v0.383 2/22/94 davies@wanton.lkg.dec.com\n";
181
182 #include <linux/config.h>
183 #ifdefMODULE 184 #include <linux/module.h>
185 #include <linux/version.h>
186 #else 187 #defineMOD_INC_USE_COUNT 188 #defineMOD_DEC_USE_COUNT 189 #endif/* MODULE */ 190
191 #include <linux/kernel.h>
192 #include <linux/sched.h>
193 #include <linux/string.h>
194 #include <linux/ptrace.h>
195 #include <linux/errno.h>
196 #include <linux/ioport.h>
197 #include <linux/malloc.h>
198 #include <linux/interrupt.h>
199 #include <asm/bitops.h>
200 #include <asm/io.h>
201 #include <asm/dma.h>
202
203 #include <linux/netdevice.h>
204 #include <linux/etherdevice.h>
205 #include <linux/skbuff.h>
206
207 #include "depca.h"
208
209 #ifdefDEPCA_DEBUG 210 staticintdepca_debug = DEPCA_DEBUG;
211 #else 212 staticintdepca_debug = 1;
213 #endif 214
215 #ifndefPROBE_LENGTH 216 #definePROBE_LENGTH 32
217 #endif 218
219 #defineETH_PROM_SIG 0xAA5500FFUL
220
221 #ifndefDEPCA_SIGNATURE 222 #defineDEPCA_SIGNATURE{"DEPCA",\
223 "DE100","DE101",\
224 "DE200","DE201","DE202",\
225 "DE210",\
226 "DE422",\
227 ""} 228 #defineDEPCA_NAME_LENGTH 8
229 #endif 230
231 #ifndefDEPCA_RAM_BASE_ADDRESSES 232 #defineDEPCA_RAM_BASE_ADDRESSES{0xc0000,0xd0000,0xe0000,0x00000} 233 #endif 234 staticshortmem_chkd = 0; /* holds which base addrs have been */ 235 /* checked, for multi-DEPCA case */ 236
237 #ifndefDEPCA_IO_PORTS 238 #defineDEPCA_IO_PORTS{0x300, 0x200, 0} 239 #endif 240
241 #ifndefDEPCA_TOTAL_SIZE 242 #defineDEPCA_TOTAL_SIZE 0x10
243 #endif 244
245 #ifndefMAX_NUM_DEPCAS 246 #defineMAX_NUM_DEPCAS 2
247 #endif 248
249 #ifndefDEPCA_EISA_IO_PORTS 250 #defineDEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */ 251 #endif 252
253 #ifndefMAX_EISA_SLOTS 254 #defineMAX_EISA_SLOTS 8
255 #endif 256
257 /* 258 ** Set the number of Tx and Rx buffers. 259 */ 260 #ifndef DEPCA_BUFFER_LOG_SZ
261 #defineRING_SIZE 16 /* 16 buffers */ 262 #else 263 #defineRING_SIZE (1 << (DEPCA_BUFFERS_LOG_SZ))
264 #endif/* DEPCA_BUFFER_LOG_SZ */ 265
266 #definePKT_BUF_SZ 1544 /* Buffer size for each Tx/Rx buffer */ 267 #definePKT_SZ 1514 /* Maximum ethernet packet length */ 268 #defineDAT_SZ 1500 /* Maximum ethernet data length */ 269 #definePKT_HDR_LEN 14 /* Addresses and data length info */ 270
271 #ifdefHAVE_MULTICAST 272 #ifndefCRC_POLYNOMIAL 273 #defineCRC_POLYNOMIAL 0x04c11db7 /* Ethernet CRC polynomial */ 274 #endif/* CRC_POLYNOMIAL */ 275 #endif/* HAVE_MULTICAST */ 276
277 /* 278 ** The DEPCA Rx and Tx ring descriptors. 279 */ 280 structdepca_rx_head{ 281 volatilelongbase;
282 shortbuf_length; /* This length is negative 2's complement! */ 283 shortmsg_length; /* This length is "normal". */ 284 };
285
286 structdepca_tx_head{ 287 volatilelongbase;
288 shortlength; /* This length is negative 2's complement! */ 289 shortmisc; /* Errors and TDR info */ 290 };
291
292 #defineLA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM 293 to LANCE memory address space */ 294
295 /* 296 ** The Lance initialization block, described in databook, in common memory. 297 */ 298 structdepca_init{ 299 unsignedshortmode; /* Mode register */ 300 unsignedcharphys_addr[ETH_ALEN]; /* Physical ethernet address */ 301 unsignedshortfilter[4]; /* Multicast filter. */ 302 unsignedlongrx_ring; /* Rx ring base pointer & ring length */ 303 unsignedlongtx_ring; /* Tx ring base pointer & ring length */ 304 };
305
306 structdepca_private{ 307 chardevname[8]; /* Device Product String */ 308 structdepca_rx_head *rx_ring; /* Pointer to start of RX descriptor ring */ 309 structdepca_tx_head *tx_ring; /* Pointer to start of TX descriptor ring */ 310 structdepca_initinit_block;/* Initialization block */ 311 longbus_offset; /* (E)ISA bus address offset vs LANCE */ 312 longdma_buffs; /* Start address of Rx and Tx buffers. */ 313 intcur_rx, cur_tx; /* The next free ring entry */ 314 intdirty_rx, dirty_tx; /* The ring entries to be free()ed. */ 315 intdma;
316 structenet_statisticsstats;
317 char depca_na; /* NICSR access width: 0=>byte, 1=>word */ 318 shortringSize; /* ring size based on available memory */ 319 shortrmask; /* modulus mask based on ring size */ 320 longrlen; /* log2(ringSize) for the descriptors */ 321 };
322
323 /* 324 ** Public Functions 325 */ 326 staticintdepca_open(structdevice *dev);
327 staticintdepca_start_xmit(structsk_buff *skb, structdevice *dev);
328 staticvoiddepca_interrupt(intirq, structpt_regs * regs);
329 staticintdepca_close(structdevice *dev);
330 staticstructenet_statistics *depca_get_stats(structdevice *dev);
331 #ifdefHAVE_MULTICAST 332 staticvoidset_multicast_list(structdevice *dev, intnum_addrs, void *addrs);
333 #endif 334
335 /* 336 ** Private functions 337 */ 338 staticintdepca_probe1(structdevice *dev, shortioaddr);
339 staticvoiddepca_init_ring(structdevice *dev);
340 staticintdepca_rx(structdevice *dev);
341 staticintdepca_tx(structdevice *dev);
342
343 staticvoidLoadCSRs(structdevice *dev);
344 staticintInitRestartDepca(structdevice *dev);
345 staticchar *DepcaSignature(unsignedlongmem_addr);
346 staticintDevicePresent(shortioaddr);
347 staticintEISA_signature(shortiobase);
348 #ifdefHAVE_MULTICAST 349 staticvoidSetMulticastFilter(intnum_addrs, char *addrs, char *multicast_table);
350 #endif 351
352 #ifndefMODULE 353 staticstructdevice *isa_probe(structdevice *dev);
354 staticstructdevice *eisa_probe(structdevice *dev);
355 staticstructdevice *alloc_device(structdevice *dev, intioaddr);
356
357 staticintnum_depcas = 0, num_eth = 0, autoprobed = 0;
358
359 #else 360 intinit_module(void);
361 voidcleanup_module(void);
362
363 #endif/* MODULE */ 364
365 /* 366 ** Miscellaneous defines... 367 */ 368 #defineSTOP_DEPCA \
369 outw(CSR0, DEPCA_ADDR);\
370 outw(STOP, DEPCA_DATA)
371
372
373
374
375 intdepca_probe(structdevice *dev)
/* */ 376 { 377 shortbase_addr = dev->base_addr;
378 intstatus = -ENODEV;
379 #ifndefMODULE 380 structdevice *eth0;
381 #endif 382
383 if (base_addr > 0x1ff) {/* Check a single specified location. */ 384 if (DevicePresent(base_addr) == 0) {/* Is DEPCA really here? */ 385 status = depca_probe1(dev, base_addr);
386 } 387 }elseif (base_addr > 0) {/* Don't probe at all. */ 388 status = -ENXIO;
389
390 #ifdefMODULE 391 }else{ 392 printk("Autoprobing is not supported when loading a module based driver.\n");
393 status = -EIO;
394 #else 395 }elseif (!autoprobed) {/* First probe for the DEPCA test */ 396 /* pattern in ROM */ 397 eth0=isa_probe(dev);
398 eth0=eisa_probe(eth0);
399 if (dev->priv) status=0;
400 autoprobed = 1;
401 }else{ 402 status = -ENXIO;
403 #endif/* MODULE */ 404
405 } 406
407 if (status) dev->base_addr = base_addr;
408
409 returnstatus; /* ENODEV would be more accurate. */ 410 } 411
412 staticint 413 depca_probe1(structdevice *dev, shortioaddr)
/* */ 414 { 415 structdepca_private *lp;
416 inti,j, status=0;
417 unsignedlongmem_start, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
418 char *name = NULL;
419 unsignedintnicsr, offset, netRAM;
420
421
422 /* 423 ** Stop the DEPCA. Enable the DBR ROM. Disable interrupts and remote boot. 424 */ 425 STOP_DEPCA;
426
427 nicsr = inb(DEPCA_NICSR);
428 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
429 outb(nicsr, DEPCA_NICSR);
430
431 if (inw(DEPCA_DATA) == STOP) { 432
433 /* Now find out what kind of DEPCA we have. The DE100 uses a different 434 ** addressing scheme for some registers compared to the DE2xx series. 435 ** Note that a base address location is marked as checked if no DEPCA is 436 ** there or one is found (when the search is immediately terminated). This 437 ** shortens the search time a little for multiple DEPCAs. 438 */ 439
440 for (j = 0, i = 0; mem_base[i] && (j == 0);i++) { 441 if (((mem_chkd >> i) & 0x01) == 0) {/* has the memory been checked? */ 442 name = DepcaSignature(mem_base[i]);/* check for a DEPCA here */ 443 mem_chkd |= (0x01 << i); /* mark location checked */ 444 if (*name != '\0') {/* one found? */ 445 j = 1; /* set exit flag */ 446 --i;
447 } 448 } 449 } 450
451 if (*name != '\0') {/* found a DEPCA device */ 452 mem_start = mem_base[i];
453 dev->base_addr = ioaddr;
454
455 if ((ioaddr&0x0fff)==DEPCA_EISA_IO_PORTS) {/* EISA slot address */ 456 printk("%s: %s at %#3x (EISA slot %d)",
457 dev->name, name, ioaddr, ((ioaddr>>12)&0x0f));
458 }else{/* ISA port address */ 459 printk("%s: %s at %#3x", dev->name, name, ioaddr);
460 } 461
462 /* There is a 32 byte station address PROM at DEPCA_PROM address. 463 The first six bytes are the station address. They can be read 464 directly since the signature search set up the ROM address 465 counter correctly just before this function. 466
467 For the DE100 we have to be careful about which port is used to 468 read the ROM info. 469 */ 470
471 if (strstr(name,"DE100")!= NULL) { 472 j = 1;
473 }else{ 474 j = 0;
475 } 476
477 printk(", h/w address ");
478 for (i = 0; i < ETH_ALEN - 1; i++) {/* get the ethernet address */ 479 printk("%2.2x:", dev->dev_addr[i] = inb(DEPCA_PROM + j));
480 } 481 printk("%2.2x", dev->dev_addr[i] = inb(DEPCA_PROM + j));
482
483 for (;i<32;i++) {/* leave ROM counter in known state */ 484 j=inb(DEPCA_PROM);
485 } 486
487 request_region(ioaddr, DEPCA_TOTAL_SIZE, dev->name);
488
489 /* 490 ** Set up the maximum amount of network RAM(kB) 491 */ 492 if (strstr(name,"DEPCA")== NULL) { 493 netRAM=64;
494 }else{ 495 netRAM=48;
496 } 497
498 /* 499 ** Determine the base address for the DEPCA RAM from the NI-CSR 500 ** and make up a DEPCA-specific-data structure. 501 */ 502
503 if (nicsr & BUF) { 504 offset = 0x8000; /* 32kbyte RAM offset*/ 505 nicsr &= ~BS; /* DEPCA RAM in top 32k */ 506 printk(",\n has %dkB RAM", netRAM - 32);
507 }elseif ((nicsr & _128KB) && (netRAM!=48)) { 508 offset = 0x0000;
509 printk(",\n has 128kB RAM");
510 }else{ 511 offset = 0x0000; /* 64k/48k bytes RAM */ 512 printk(",\n has %dkB RAM", netRAM);
513 } 514
515 mem_start += offset; /* (E)ISA start address */ 516 printk(" at 0x%.5lx", mem_start);
517
518 /* 519 ** Enable the shadow RAM. 520 */ 521 if (strstr(name,"DEPCA") == NULL) { 522 nicsr |= SHE;
523 outb(nicsr, DEPCA_NICSR);
524 } 525
526 /* 527 ** Calculate the ring size based on the available RAM 528 ** found above. Allocate an equal number of buffers, each 529 ** of size PKT_BUF_SZ (1544 bytes) to the Tx and Rx, allowing one 530 ** descriptor entry (8 bytes) for each buffer. Make sure 531 ** that this ring size is <= RING_SIZE. The ring size must be 532 ** a power of 2. 533 */ 534
535 j = (((netRAM << 10) - offset - sizeof(structdepca_private)) /
536 (PKT_BUF_SZ + 8)) >> 1;
537 for (i=0;j>1;i++) { 538 j >>= 1;
539 } 540
541 /* Hold the ring size information here before the depca 542 ** private structure is allocated. Need this for the memory 543 ** space calculations. 544 */ 545 j = 1 << i;
546
547 /* 548 ** Set up memory information in the device structure. 549 ** Align the descriptor rings on an 8 byte (quadword) boundary. 550 ** 551 ** depca_private area 552 ** rx ring descriptors 553 ** tx ring descriptors 554 ** rx buffers 555 ** tx buffers 556 ** 557 */ 558
559 /* private area & initialise */ 560 dev->priv = (void *)((mem_start + 0x07) & ~0x07);
561 lp = (structdepca_private *)dev->priv;
562 memset(dev->priv, 0, sizeof(structdepca_private));
563 strcpy(lp->devname,name);
564
565 /* Tx & Rx descriptors (aligned to a quadword boundary) */ 566 mem_start = ((((unsignedlong)dev->priv +
567 sizeof(structdepca_private)) +
568 (unsignedlong)0x07) & (unsignedlong)~0x07);
569 lp->rx_ring = (structdepca_rx_head *)mem_start;
570
571 mem_start += (sizeof(structdepca_rx_head) * j);
572 lp->tx_ring = (structdepca_tx_head *)mem_start;
573
574 mem_start += (sizeof(structdepca_tx_head) * j);
575 lp->bus_offset = mem_start & 0x00ff0000;
576 mem_start &= LA_MASK; /* LANCE re-mapped start address */ 577
578 lp->dma_buffs = mem_start;
579
580 mem_start += (PKT_BUF_SZ * j);
581 /* (mem_start now points to the start of the Tx buffers) */ 582
583 /* Initialise the data structures wrt CPU */ 584 memset(lp->rx_ring, 0, sizeof(structdepca_rx_head)*j);
585 memset(lp->tx_ring, 0, sizeof(structdepca_tx_head)*j);
586
587 /* This should never happen. */ 588 if ((long)(lp->rx_ring) & 0x07) { 589 printk("\n **ERROR** DEPCA Rx and Tx descriptor rings not on a quadword boundary.\n");
590 return -ENXIO;
591 } 592
593 /* 594 ** Finish initialising the ring information. 595 */ 596 lp->ringSize = j;
597 if (lp->ringSize > RING_SIZE) lp->ringSize = RING_SIZE;
598 lp->rmask = lp->ringSize - 1;
599
600 /* 601 ** calculate the real RLEN size for the descriptors. It is 602 ** log2(ringSize). 603 */ 604 for (i=0, j = lp->ringSize; j>1; i++) { 605 j >>= 1;
606 } 607 lp->rlen = (unsignedlong)(i << 29);
608
609 /* 610 ** load the initialisation block 611 */ 612 depca_init_ring(dev);
613
614 /* 615 ** Initialise the control and status registers 616 */ 617 LoadCSRs(dev);
618
619 /* 620 ** Enable DEPCA board interrupts for autoprobing 621 */ 622 nicsr = ((nicsr & ~IM)|IEN);
623 outb(nicsr, DEPCA_NICSR);
624
625 /* The DMA channel may be passed in on this parameter. */ 626 dev->dma = 0;
627
628 /* To auto-IRQ we enable the initialization-done and DMA err, 629 interrupts. For now we will always get a DMA error. */ 630 if (dev->irq < 2) { 631 #ifndefMODULE 632 autoirq_setup(0);
633
634 /* Trigger an initialization just for the interrupt. */ 635 outw(INEA | INIT, DEPCA_DATA);
636
637 dev->irq = autoirq_report(1);
638 if (dev->irq) { 639 printk(" and uses IRQ%d.\n", dev->irq);
640 }else{ 641 printk(" and failed to detect IRQ line.\n");
642 status = -EAGAIN;
643 } 644 #endif/* MODULE */ 645 }else{ 646 printk(" and assigned IRQ%d.\n", dev->irq);
647 } 648 }else{ 649 status = -ENXIO;
650 } 651 if (!status) { 652 if (depca_debug > 0) { 653 printk(version);
654 } 655
656 /* The DEPCA-specific entries in the device structure. */ 657 dev->open = &depca_open;
658 dev->hard_start_xmit = &depca_start_xmit;
659 dev->stop = &depca_close;
660 dev->get_stats = &depca_get_stats;
661 #ifdefHAVE_MULTICAST 662 dev->set_multicast_list = &set_multicast_list;
663 #endif 664
665 dev->mem_start = 0;
666
667 /* Fill in the generic field of the device structure. */ 668 ether_setup(dev);
669 } 670 }else{ 671 status = -ENXIO;
672 } 673
674 returnstatus;
675 } 676
677
678 staticint 679 depca_open(structdevice *dev)
/* */ 680 { 681 structdepca_private *lp = (structdepca_private *)dev->priv;
682 inti,nicsr,ioaddr = dev->base_addr;
683
684 if (request_irq(dev->irq, &depca_interrupt, 0, "depca")) { 685 printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
686 return -EAGAIN;
687 } 688
689 irq2dev_map[dev->irq] = dev;
690
691 /* 692 ** Stop the DEPCA & get the board status information. 693 */ 694 STOP_DEPCA;
695 nicsr = inb(DEPCA_NICSR);
696
697 /* 698 ** Make sure the shadow RAM is enabled 699 */ 700 if (strstr(lp->devname,"DEPCA") == NULL) { 701 nicsr |= SHE;
702 outb(nicsr, DEPCA_NICSR);
703 } 704
705 /* 706 ** Re-initialize the DEPCA... 707 */ 708 depca_init_ring(dev); /* initialize the descriptor rings */ 709 LoadCSRs(dev);
710
711 if (depca_debug > 1){ 712 printk("%s: depca open with irq %d\n",dev->name,dev->irq);
713 printk("Descriptor head addresses:\n");
714 printk("\t0x%8.8lx 0x%8.8lx\n",(long)lp->rx_ring,(long)lp->tx_ring);
715 printk("Descriptor addresses:\n");
716 for (i=0;i<lp->ringSize;i++){ 717 printk("\t0x%8.8lx 0x%8.8lx\n",(long)&lp->rx_ring[i].base,
718 (long)&lp->tx_ring[i].base);
719 } 720 printk("Buffer addresses:\n");
721 for (i=0;i<lp->ringSize;i++){ 722 printk("\t0x%8.8lx 0x%8.8lx\n",(long)lp->rx_ring[i].base,
723 (long)lp->tx_ring[i].base);
724 } 725 printk("Initialisation block at 0x%8.8lx\n",(long)&lp->init_block);
726 printk("\tmode: 0x%4.4x\n",lp->init_block.mode);
727 printk("\tphysical address: ");
728 for (i=0;i<6;i++){ 729 printk("%2.2x:",(short)lp->init_block.phys_addr[i]);
730 } 731 printk("\n\tlogical address filter: 0x");
732 for (i=0;i<4;i++){ 733 printk("%2.2x",(short)lp->init_block.filter[i]);
734 } 735 printk("\n\trx_ring at: 0x%8.8lx\n",(long)lp->init_block.rx_ring);
736 printk("\ttx_ring at: 0x%8.8lx\n",(long)lp->init_block.tx_ring);
737 printk("dma_buffs: 0x%8.8lx\n",(long)lp->dma_buffs);
738 printk("Ring size: %d\nMask: 0x%2.2x\nLog2(ringSize): 0x%8.8lx\n",
739 (short)lp->ringSize,
740 (char)lp->rmask,
741 (long)lp->rlen);
742 outw(CSR2,DEPCA_ADDR);
743 printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
744 outw(CSR1,DEPCA_ADDR);
745 printk("%4.4x\n",inw(DEPCA_DATA));
746 outw(CSR3,DEPCA_ADDR);
747 printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
748 } 749
750 /* 751 ** Enable DEPCA board interrupts and turn off LED 752 */ 753 nicsr = ((nicsr & ~IM & ~LED)|IEN);
754 outb(nicsr, DEPCA_NICSR);
755 outw(CSR0,DEPCA_ADDR);
756
757 dev->tbusy = 0;
758 dev->interrupt = 0;
759 dev->start = 1;
760
761 InitRestartDepca(dev); /* ignore the return status */ 762
763 if (depca_debug > 1){ 764 printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
765 printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
766 } 767
768 MOD_INC_USE_COUNT;
769
770 return 0; /* Always succeed */ 771 } 772
773 /* Initialize the lance Rx and Tx descriptor rings. */ 774 staticvoid 775 depca_init_ring(structdevice *dev)
/* */ 776 { 777 structdepca_private *lp = (structdepca_private *)dev->priv;
778 unsignedlongi;
779
780 lp->init_block.mode = DTX | DRX; /* Disable Rx and Tx. */ 781 lp->cur_rx = lp->cur_tx = 0;
782 lp->dirty_rx = lp->dirty_tx = 0;
783
784 /* Initialize the base addresses and length of each buffer in the ring */ 785 for (i = 0; i < lp->ringSize; i++) { 786 lp->rx_ring[i].base = (lp->dma_buffs + i*PKT_BUF_SZ) | R_OWN;
787 lp->rx_ring[i].buf_length = -PKT_BUF_SZ;
788 lp->tx_ring[i].base = (lp->dma_buffs + (i+lp->ringSize) * PKT_BUF_SZ) &
789 (unsignedlong)(0x00ffffff);
790 } 791
792 /* Set up the initialization block */ 793 for (i = 0; i < ETH_ALEN; i++) { 794 lp->init_block.phys_addr[i] = dev->dev_addr[i];
795 } 796 for (i = 0; i < 4; i++) { 797 lp->init_block.filter[i] = 0x0000;
798 } 799 lp->init_block.rx_ring = ((unsignedlong)lp->rx_ring & LA_MASK) | lp->rlen;
800 lp->init_block.tx_ring = ((unsignedlong)lp->tx_ring & LA_MASK) | lp->rlen;
801
802 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */ 803 } 804
805 /* 806 ** Writes a socket buffer to TX descriptor ring and starts transmission 807 */ 808 staticint 809 depca_start_xmit(structsk_buff *skb, structdevice *dev)
/* */ 810 { 811 structdepca_private *lp = (structdepca_private *)dev->priv;
812 intioaddr = dev->base_addr;
813 intstatus = 0;
814
815 /* Transmitter timeout, serious problems. */ 816 if (dev->tbusy) { 817 inttickssofar = jiffies - dev->trans_start;
818 if (tickssofar < 10) { 819 status = -1;
820 }else{ 821 printk("%s: transmit timed out, status %04x, resetting.\n",
822 dev->name, inw(DEPCA_DATA));
823
824 STOP_DEPCA;
825 depca_init_ring(dev);
826 LoadCSRs(dev);
827 InitRestartDepca(dev);
828 dev->tbusy=0;
829 dev->trans_start = jiffies;
830 } 831 returnstatus;
832 } 833
834 if (skb == NULL) { 835 dev_tint(dev);
836 return 0;
837 } 838
839 if (skb->len <= 0) { 840 return 0;
841 } 842
843 if (depca_debug > 3) { 844 outw(CSR0, DEPCA_ADDR);
845 printk("%s: depca_start_xmit() called, csr0 %4.4x.\n", dev->name,
846 inw(DEPCA_DATA));
847 } 848
849 /* Block a timer-based transmit from overlapping. This could better be 850 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */ 851 if (set_bit(0, (void*)&dev->tbusy) != 0)
852 printk("%s: Transmitter access conflict.\n", dev->name);
853
854 /* 855 ** The TX buffer, skb, has to be copied into the local network RAM 856 ** for the LANCE to access it. The skb may be at > 16MB for large 857 ** (memory) systems. 858 */ 859 {/* Fill in a Tx ring entry */ 860 unsignedchar *buf;
861 intentry = lp->cur_tx++;
862 intlen;
863 longskbL = skb->len;
864 char *p = (char *) skb->data;
865
866 entry &= lp->rmask; /* Ring around buffer number. */ 867 buf = (unsignedchar *)((lp->tx_ring[entry].base+lp->bus_offset) &
868 0x00ffffff);
869
870 /* Wait for a full ring to free up */ 871 while (lp->tx_ring[entry].base < 0);
872
873 /* 874 ** Caution: the write order is important here... don't set up the 875 ** ownership rights until all the other information is in place. 876 */ 877 len = ((skbL > PKT_SZ) ? PKT_SZ : skbL); /* skb too long */ 878 if (len < ETH_ZLEN) len = ETH_ZLEN; /* len too short */ 879 skbL -= len;
880 lp->tx_ring[entry].length = -len;
881
882 /* Clears various error flags */ 883 lp->tx_ring[entry].misc = 0x0000;
884
885 /* copy the data from the socket buffer to the net memory */ 886 memcpy((unsignedchar *)(buf), skb->data, len);
887
888 /* Hand over buffer ownership to the LANCE */ 889 if (skbL <= 0) lp->tx_ring[entry].base |= (T_ENP);
890 lp->tx_ring[entry].base |= (T_OWN|T_STP);
891
892 /* Trigger an immediate send demand. */ 893 outw(CSR0, DEPCA_ADDR);
894 outw(INEA | TDMD, DEPCA_DATA);
895
896 dev->trans_start = jiffies;
897
898 for (p += len; skbL > 0; p += len) { 899
900 /* Get new buffer pointer */ 901 entry = lp->cur_tx++;
902 entry &= lp->rmask; /* Ring around buffer number. */ 903 buf = (unsignedchar *)((lp->tx_ring[entry].base+lp->bus_offset) &
904 0x00ffffff);
905
906 /* Wait for a full ring to free up */ 907 while (lp->tx_ring[entry].base < 0);
908 dev->tbusy=0;
909
910 /* Copy ethernet header to the new buffer */ 911 memcpy((unsignedchar *)buf, skb->data, PKT_HDR_LEN);
912
913 /* Determine length of data buffer */ 914 len = ((skbL > DAT_SZ) ? DAT_SZ : skbL); /* skbL too long */ 915 if (len < ETH_ZLEN) len = ETH_ZLEN; /* len too short */ 916 skbL -= len;
917 lp->tx_ring[entry].length = -len;
918
919 /* Clears various error flags */ 920 lp->tx_ring[entry].misc = 0x0000;
921
922 /* copy the data from the socket buffer to the net memory */ 923 memcpy((unsignedchar *)(buf + PKT_HDR_LEN), (unsignedchar *)p, len);
924
925 /* Hand over buffer ownership to the LANCE */ 926 if (skbL <= 0) lp->tx_ring[entry].base |= T_ENP;
927 lp->tx_ring[entry].base |= T_OWN;
928 } 929
930 if (depca_debug > 4) { 931 unsignedchar *pkt =
932 (unsignedchar *)((lp->tx_ring[entry].base+lp->bus_offset) &
933 0x00ffffff);
934
935 printk("%s: tx ring[%d], %#lx, sk_buf %#lx len %d.\n",
936 dev->name, entry, (unsignedlong) &lp->tx_ring[entry],
937 lp->tx_ring[entry].base, -lp->tx_ring[entry].length);
938 printk("%s: Tx %2.2x %2.2x %2.2x ... %2.2x %2.2x %2.2x %2.2x...%2.2x len %2.2x %2.2x %2.2x %2.2x.\n",
939 dev->name, pkt[0], pkt[1], pkt[2], pkt[5], pkt[6],
940 pkt[7], pkt[8], pkt[11], pkt[12], pkt[13],
941 pkt[14], pkt[15]);
942 } 943
944 /* Check if the TX ring is full or not - 'tbusy' cleared if not full. */ 945 if (lp->tx_ring[(entry+1) & lp->rmask].base >= 0) { 946 dev->tbusy=0;
947 } 948
949 dev_kfree_skb (skb, FREE_WRITE);
950 } 951
952 return 0;
953 } 954
955 /* 956 ** The DEPCA interrupt handler. 957 */ 958 staticvoid 959 depca_interrupt(intirq, structpt_regs * regs)
/* */ 960 { 961 structdevice *dev = (structdevice *)(irq2dev_map[irq]);
962 structdepca_private *lp;
963 intcsr0, ioaddr, nicsr;
964
965 if (dev == NULL) { 966 printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
967 }else{ 968 lp = (structdepca_private *)dev->priv;
969 ioaddr = dev->base_addr;
970
971 if (dev->interrupt)
972 printk("%s: Re-entering the interrupt handler.\n", dev->name);
973
974 dev->interrupt = MASK_INTERRUPTS;
975
976 /* mask the DEPCA board interrupts and turn on the LED */ 977 nicsr = inb(DEPCA_NICSR);
978 nicsr |= (IM|LED);
979 outb(nicsr, DEPCA_NICSR);
980
981 outw(CSR0, DEPCA_ADDR);
982 csr0 = inw(DEPCA_DATA);
983
984 /* Acknowledge all of the current interrupt sources ASAP. */ 985 outw(csr0 & ~(INEA|TDMD|STOP|STRT|INIT), DEPCA_DATA);
986
987 if (depca_debug > 5)
988 printk("%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
989 dev->name, csr0, inw(DEPCA_DATA));
990
991 if (csr0 & RINT) /* Rx interrupt (packet arrived) */ 992 depca_rx(dev);
993
994 if (csr0 & TINT) /* Tx interrupt (packet sent) */ 995 depca_tx(dev);
996
997 /* Clear the interrupts we've handled. */ 998 outw(CSR0, DEPCA_ADDR);
999 outw(BABL|CERR|MISS|MERR|RINT|TINT|IDON|INEA, DEPCA_DATA);
1000
1001 if (depca_debug > 4) {1002 printk("%s: exiting interrupt, csr%d=%#4.4x.\n",
1003 dev->name, inw(DEPCA_ADDR),
1004 inw(DEPCA_DATA));
1005 }1006
1007 /* Unmask the DEPCA board interrupts and turn off the LED */1008 nicsr = (nicsr & ~IM & ~LED);
1009 outb(nicsr, DEPCA_NICSR);
1010 dev->interrupt = UNMASK_INTERRUPTS;
1011 }1012
1013 return;
1014 }1015
1016 staticint1017 depca_rx(structdevice *dev)
/* */1018 {1019 structdepca_private *lp = (structdepca_private *)dev->priv;
1020 intentry = lp->cur_rx & lp->rmask;
1021
1022 /* If we own the next entry, it's a new packet. Send it up. */1023 for (; lp->rx_ring[entry].base >= 0; entry = (++lp->cur_rx) & lp->rmask) {1024 intstatus = lp->rx_ring[entry].base >> 16 ;
1025 intchained;
1026
1027 /*1028 ** There is a tricky error noted by John Murphy, <murf@perftech.com>1029 ** to Russ Nelson: even with full-sized buffers, it's possible for a1030 ** jabber packet to use two buffers, with only the last one correctly1031 ** noting the error.1032 */1033
1034 /* Check for a chaining buffer */1035 chained = 0;
1036 if (status == R_STP) {1037 chained = 1;
1038
1039 /* 1040 ** Wait for next buffer to complete to check for errors. This1041 ** is slow but infrequent and allows for correct hardware buffer1042 ** chaining (whilst defeating the chaining's purpose).1043 */1044 while ((status=(lp->rx_ring[(entry+1)&lp->rmask].base >> 16)) < 0);
1045
1046 /* NB: 'status' now comes from the buffer following 'entry'. */1047 }1048
1049 if (status & R_ERR) {/* There was an error. */1050 lp->stats.rx_errors++; /* Update the error stats. */1051 if (status & R_FRAM) lp->stats.rx_frame_errors++;
1052 if (status & R_OFLO) lp->stats.rx_over_errors++;
1053 if (status & R_CRC) lp->stats.rx_crc_errors++;
1054 if (status & R_BUFF) lp->stats.rx_fifo_errors++;
1055 }else{/* Malloc up new buffer, compatible with net-2e. */1056 shortpkt_len = lp->rx_ring[entry].msg_length;
1057 structsk_buff *skb;
1058
1059 skb = alloc_skb(pkt_len, GFP_ATOMIC);
1060 if (skb == NULL) {1061 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
1062 lp->stats.rx_dropped++; /* Really, deferred. */1063 break;
1064 }1065 skb->len = pkt_len;
1066 skb->dev = dev;
1067 memcpy(skb->data,
1068 (unsignedchar *)((lp->rx_ring[entry].base+lp->bus_offset) &
1069 0x00ffffff),
1070 pkt_len);
1071 /* 1072 ** Notify the upper protocol layers that there is another 1073 ** packet to handle1074 */1075 skb->protocol=eth_type_trans(skb,dev);
1076 netif_rx(skb);
1077 lp->stats.rx_packets++;
1078 }1079
1080 /* turn over ownership of the current entry back to the LANCE */1081 lp->rx_ring[entry].base |= R_OWN;
1082 if (chained && (status & R_ERR)) {/* next entry also bad */1083 entry = (++lp->cur_rx) & lp->rmask;
1084 lp->rx_ring[entry].base |= R_OWN;
1085 }1086 }1087
1088 /* 1089 ** We should check that at least two ring entries are free. If not,1090 ** we should free one and mark stats->rx_dropped++. 1091 */1092
1093 return 0;
1094 }1095
1096 /*1097 ** Buffer sent - check for buffer errors.1098 */1099 staticint1100 depca_tx(structdevice *dev)
/* */1101 {1102 structdepca_private *lp = (structdepca_private *)dev->priv;
1103 intdirty_tx = lp->dirty_tx & lp->rmask;
1104
1105 if (depca_debug > 5)
1106 printk("%s: Cleaning tx ring, dirty %d clean %d.\n",
1107 dev->name, dirty_tx, (lp->cur_tx & lp->rmask));
1108
1109 /* 1110 ** While the dirty entry is not the current one AND 1111 ** the LANCE doesn't own it... 1112 */1113 for (; dirty_tx!=(lp->cur_tx & lp->rmask) && lp->tx_ring[dirty_tx].base>0;
1114 dirty_tx = ++lp->dirty_tx & lp->rmask) {1115 unsignedlong *tmdp = (unsignedlong *)(&lp->tx_ring[dirty_tx]);
1116 intstatus = lp->tx_ring[dirty_tx].base >> 16;
1117
1118 if (status < 0) {/* Packet not yet sent! */1119 printk("interrupt for packet not yet sent!\n");
1120 break;
1121 }1122 if (status & T_ERR) {/* There was an major error, log it. */1123 interr_status = lp->tx_ring[dirty_tx].misc;
1124
1125 lp->stats.tx_errors++;
1126 if (err_status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
1127 if (err_status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
1128 if (err_status & TMD3_LCOL) lp->stats.tx_window_errors++;
1129 if (err_status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
1130 /* We should re-init() after the FIFO error. */1131 }elseif (status & (T_MORE | T_ONE)) {1132 lp->stats.collisions++;
1133 }else{1134 lp->stats.tx_packets++;
1135 }1136
1137 if (depca_debug > 5)
1138 printk("%s: Tx done entry %d, %4.4lx %4.4lx %4.4lx %4.4lx.\n",
1139 dev->name, dirty_tx,
1140 tmdp[0], tmdp[1], tmdp[2], tmdp[3]);
1141 }1142 /*mark_bh(INET_BH);*/1143 return 0;
1144 }1145
1146 staticint1147 depca_close(structdevice *dev)
/* */1148 {1149 structdepca_private *lp = (structdepca_private *)dev->priv;
1150 intnicsr, ioaddr = dev->base_addr;
1151
1152 dev->start = 0;
1153 dev->tbusy = 1;
1154
1155 outw(CSR0, DEPCA_ADDR);
1156
1157 if (depca_debug > 1) {1158 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1159 dev->name, inw(DEPCA_DATA));
1160 }1161
1162 /* 1163 ** We stop the DEPCA here -- it occasionally polls1164 ** memory if we don't. 1165 */1166 outw(STOP, DEPCA_DATA);
1167
1168 /*1169 ** Give back the ROM in case the user wants to go to DOS1170 */1171 if (strstr(lp->devname,"DEPCA") == NULL) {1172 nicsr = inb(DEPCA_NICSR);
1173 nicsr &= ~SHE;
1174 outb(nicsr, DEPCA_NICSR);
1175 }1176
1177 free_irq(dev->irq);
1178
1179 irq2dev_map[dev->irq] = 0;
1180
1181 MOD_DEC_USE_COUNT;
1182
1183 return 0;
1184 }1185
1186 staticvoidLoadCSRs(structdevice *dev)
/* */1187 {1188 structdepca_private *lp = (structdepca_private *)dev->priv;
1189 intioaddr = dev->base_addr;
1190
1191 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */1192 outw((unsignedshort)((unsignedlong)(&lp->init_block) & LA_MASK),
1193 DEPCA_DATA);
1194 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */1195 outw((unsignedshort)(((unsignedlong)(&lp->init_block) & LA_MASK) >> 16),
1196 DEPCA_DATA);
1197 outw(CSR3, DEPCA_ADDR); /* ALE control */1198 outw(ACON, DEPCA_DATA);
1199 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */1200 }1201
1202 staticintInitRestartDepca(structdevice *dev)
/* */1203 {1204 structdepca_private *lp = (structdepca_private *)dev->priv;
1205 intioaddr = dev->base_addr;
1206 inti, status=0;
1207
1208 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */1209 outw(INIT, DEPCA_DATA); /* initialize DEPCA */1210
1211 /* wait for lance to complete initialisation */1212 for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
1213
1214 if (i!=100) {1215 /* clear IDON by writing a "1", enable interrupts and start lance */1216 outw(IDON | INEA | STRT, DEPCA_DATA);
1217 if (depca_debug > 2) {1218 printk("%s: DEPCA open after %d ticks, init block %#lx csr0 %4.4x.\n",
1219 dev->name, i, (long) &lp->init_block, inw(DEPCA_DATA));
1220 }1221 }else{1222 status = -1;
1223 printk("%s: DEPCA unopened after %d ticks, init block %#lx csr0 %4.4x.\n",
1224 dev->name, i, (long) &lp->init_block, inw(DEPCA_DATA));
1225 }1226
1227 returnstatus;
1228 }1229
1230 staticstructenet_statistics *
1231 depca_get_stats(structdevice *dev)
/* */1232 {1233 structdepca_private *lp = (structdepca_private *)dev->priv;
1234
1235 /* Null body since there is no framing error counter */1236
1237 return &lp->stats;
1238 }1239
1240 #ifdefHAVE_MULTICAST1241 /*1242 ** Set or clear the multicast filter for this adaptor.1243 ** num_addrs == -1 Promiscuous mode, receive all packets1244 ** num_addrs == 0 Normal mode, clear multicast list1245 ** num_addrs > 0 Multicast mode, receive normal and MC packets, and do1246 ** best-effort filtering.1247 */1248 #definehash_filterlp->init_block.filter1249
1250 staticvoid1251 set_multicast_list(structdevice *dev, intnum_addrs, void *addrs)
/* */1252 {1253 shortioaddr = dev->base_addr;
1254 structdepca_private *lp = (structdepca_private *)dev->priv;
1255
1256 if (irq2dev_map[dev->irq] != NULL) {1257 STOP_DEPCA; /* Temporarily stop the depca. */1258 depca_init_ring(dev); /* Initialize the descriptor rings */1259
1260 if (num_addrs >= 0) {1261 SetMulticastFilter(num_addrs, (char *)addrs, (char *)hash_filter);
1262 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */1263 }else{1264 lp->init_block.mode |= PROM; /* Set promiscuous mode */1265 }1266
1267 LoadCSRs(dev); /* Reload CSR3 */1268 InitRestartDepca(dev); /* Resume normal operation. */1269 }1270 }1271
1272 /*1273 ** Calculate the hash code and update the logical address filter1274 ** from a list of ethernet multicast addresses.1275 ** Derived from a 'C' program in the AMD data book:1276 ** "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)", 1277 ** Pub #17781, Rev. A, May 19931278 */1279 staticvoidSetMulticastFilter(intnum_addrs, char *addrs, char *multicast_table)
/* */1280 {1281 charj, ctrl, bit, octet, hashcode;
1282 shortinti;
1283 longintCRC, poly = (longint) CRC_POLYNOMIAL;
1284
1285 for (i=0;i<num_addrs;i++) {/* for each address in the list */1286 if (((char) *(addrs+ETH_ALEN*i) & 0x01) == 1) {/* is multicast address? */1287 CRC = (longint) 0xffffffff; /* init CRC for each address */1288 for (octet=0;octet<ETH_ALEN;octet++) {/* for each address octet */1289 for(j=0;j<8;j++) {/* process each address bit */1290 bit = (((char)* (addrs+ETH_ALEN*i+octet)) >> j) & 0x01;
1291 ctrl = ((CRC < 0) ? 1 : 0); /* shift the control bit */1292 CRC <<= 1; /* shift the CRC */1293 if (bit ^ ctrl) {/* (bit) XOR (control bit) */1294 CRC ^= poly; /* (CRC) XOR (polynomial) */1295 }1296 }1297 }1298 hashcode = (CRC & 0x00000001); /* hashcode is 6 LSb of CRC ... */1299 for (j=0;j<5;j++) {/* ... in reverse order. */1300 hashcode <<= 1;
1301 CRC >>= 1;
1302 hashcode |= (CRC & 0x00000001);
1303 }1304 octet = hashcode >> 3; /* bit[3-5] -> octet in filter */1305 /* bit[0-2] -> bit in octet */1306 multicast_table[octet] |= (1 << (hashcode & 0x07));
1307 }1308 }1309 return;
1310 }1311
1312 #endif/* HAVE_MULTICAST */1313
1314 #ifndefMODULE1315 /*1316 ** ISA bus I/O device probe1317 */1318 staticstructdevice *isa_probe(structdevice *dev)
/* */1319 {1320 int *port, ports[] = DEPCA_IO_PORTS;
1321 intstatus;
1322
1323 for (status = -ENODEV, port = &ports[0];
1324 *port && (num_depcas < MAX_NUM_DEPCAS); port++) {1325 intioaddr = *port;
1326
1327 if (DevicePresent(ioaddr) == 0) {1328 if (num_depcas > 0) {/* only gets here in autoprobe */1329 dev = alloc_device(dev, ioaddr);
1330 }else{1331 if ((status = depca_probe1(dev, ioaddr)) == 0) {1332 num_depcas++;
1333 }1334 }1335 num_eth++;
1336 }1337 }1338 returndev;
1339 }1340
1341 /*1342 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually1343 ** the motherboard.1344 */1345 staticstructdevice *eisa_probe(structdevice *dev)
/* */1346 {1347 inti, ioaddr = DEPCA_EISA_IO_PORTS;
1348 intstatus;
1349
1350 ioaddr+=0x1000; /* get the first slot address */1351 for (status = -ENODEV, i=1; i<MAX_EISA_SLOTS; i++, ioaddr+=0x1000) {1352
1353 if (EISA_signature(DEPCA_EISA_ID) == 0) {1354 if (num_depcas > 0) {/* only gets here in autoprobe */1355 dev = alloc_device(dev, ioaddr);
1356 }else{1357 if ((status = depca_probe1(dev, ioaddr)) == 0) {1358 num_depcas++;
1359 }1360 }1361 num_eth++;
1362 }1363 }1364 returndev;
1365 }1366
1367 /*1368 ** Allocate the device by pointing to the next available space in the1369 ** device structure. Should one not be available, it is created.1370 */1371 staticstructdevice *alloc_device(structdevice *dev, intioaddr)
/* */1372 {1373 /*1374 ** Check the device structures for an end of list or unused device1375 */1376 while (dev->next != NULL) {1377 if (dev->next->base_addr == 0xffe0) break;
1378 dev = dev->next; /* walk through eth device list */1379 num_eth++; /* increment eth device number */1380 }1381
1382 /*1383 ** If no more device structures, malloc one up. If memory could1384 ** not be allocated, print an error message.1385 */1386 if (dev->next == NULL) {1387 dev->next = (structdevice *)kmalloc(sizeof(structdevice) + 8,
1388 GFP_KERNEL);
1389 if (dev->next == NULL) {1390 printk("eth%d: Device not initialised, insufficient memory\n",
1391 num_eth);
1392 }1393 }1394
1395 /*1396 ** If the memory was allocated, point to the new memory area1397 ** and initialize it (name, I/O address, next device (NULL) and1398 ** initialisation probe routine).1399 */1400 if ((dev->next != NULL) &&
1401 (num_eth > 0) && (num_eth < 9999)) {1402 dev = dev->next; /* point to the new device */1403 dev->name = (char *)(dev + 1);
1404 sprintf(dev->name,"eth%d", num_eth);/* New device name */1405 dev->base_addr = ioaddr; /* assign the io address */1406 dev->next = NULL; /* mark the end of list */1407 dev->init = &depca_probe; /* initialisation routine */1408 num_depcas++;
1409 }1410
1411 returndev;
1412 }1413 #endif/* MODULE */1414
1415 /*1416 ** Look for a particular board name in the on-board Remote Diagnostics1417 ** and Boot (RDB) ROM. This will also give us a clue to the network RAM1418 ** base address.1419 */1420 staticchar *DepcaSignature(unsignedlongmem_addr)
/* */1421 {1422 unsignedlongi,j,k;
1423 staticcharsignatures[][DEPCA_NAME_LENGTH] = DEPCA_SIGNATURE;
1424 staticcharthisName[DEPCA_NAME_LENGTH];
1425 chartmpstr[17];
1426
1427 for (i=0;i<16;i++) {/* copy the first 16 bytes of ROM to */1428 tmpstr[i] = *(unsignedchar *)(mem_addr+0xc000+i); /* a temporary string */1429 }1430 tmpstr[i]='\0';
1431
1432 strcpy(thisName,"");
1433 for (i=0;*signatures[i]!='\0' && *thisName=='\0';i++) {1434 for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {1435 if (signatures[i][k] == tmpstr[j]) {/* track signature */1436 k++;
1437 }else{/* lost signature; begin search again */1438 k=0;
1439 }1440 }1441 if (k == strlen(signatures[i])) {1442 strcpy(thisName,signatures[i]);
1443 }1444 }1445
1446 returnthisName; /* return the device name string */1447 }1448
1449 /*1450 ** Look for a special sequence in the Ethernet station address PROM that1451 ** is common across all DEPCA products. Note that the original DEPCA needs1452 ** its ROM address counter to be initialized and enabled. Only enable1453 ** if the first address octet is a 0x08 - this minimises the chances of1454 ** messing around with some other hardware, but it assumes that this DEPCA1455 ** card initialized itself correctly.1456 ** 1457 ** Search the Ethernet address ROM for the signature. Since the ROM address1458 ** counter can start at an arbitrary point, the search must include the entire1459 ** probe sequence length plus the (length_of_the_signature - 1).1460 ** Stop the search IMMEDIATELY after the signature is found so that the1461 ** PROM address counter is correctly positioned at the start of the1462 ** ethernet address for later read out.1463 */1464 staticintDevicePresent(shortioaddr)
/* */1465 {1466 union{1467 struct{1468 u_longa;
1469 u_longb;
1470 }llsig;
1471 charSig[sizeof(long) << 1];
1472 }dev;
1473 shortsigLength=0;
1474 chardata;
1475 inti, j, nicsr, status = 0;
1476
1477 data = inb(DEPCA_PROM); /* clear counter on DEPCA */1478 data = inb(DEPCA_PROM); /* read data */1479
1480 if (data == 0x08) {/* Enable counter on DEPCA */1481 nicsr = inb(DEPCA_NICSR);
1482 nicsr |= AAC;
1483 outb(nicsr, DEPCA_NICSR);
1484 }1485
1486 dev.llsig.a = ETH_PROM_SIG;
1487 dev.llsig.b = ETH_PROM_SIG;
1488 sigLength = sizeof(long) << 1;
1489
1490 for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {1491 data = inb(DEPCA_PROM);
1492 if (dev.Sig[j] == data) {/* track signature */1493 j++;
1494 }else{/* lost signature; begin search again */1495 if (data == dev.Sig[0]) {/* rare case.... */1496 j=1;
1497 }else{1498 j=0;
1499 }1500 }1501 }1502
1503 if (j!=sigLength) {1504 status = -ENODEV; /* search failed */1505 }1506
1507 returnstatus;
1508 }1509
1510 /*1511 ** Look for a particular board name in the EISA configuration space1512 */1513 staticintEISA_signature(shortiobase)
/* */1514 {1515 unsignedlongi;
1516 intstatus;
1517 char *signatures[] = DEPCA_SIGNATURE;
1518 charManCode[8];
1519 union{1520 u_longID;
1521 u_charId[4];
1522 }Eisa;
1523
1524 for (i=0; i<4; i++) {1525 Eisa.Id[i] = inb(iobase + i);
1526 }1527
1528 ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1529 ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1530 ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1531 ManCode[3]=((Eisa.Id[2]&0x0f)+0x30);
1532 ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1533 ManCode[5]='\0';
1534
1535 for (status = -ENXIO, i=0;*signatures[i] != '\0' && status;i++) {1536 if (strstr(ManCode, signatures[i]) != NULL) {1537 status = 0;
1538 }1539 }1540
1541 returnstatus; /* return the device name string */1542 }1543
1544 #ifdefMODULE1545 charkernel_version[] = UTS_RELEASE;
1546 staticstructdevicethisDepca = {1547 " ", /* device name inserted by /linux/drivers/net/net_init.c */1548 0, 0, 0, 0,
1549 0x200, 7, /* I/O address, IRQ */1550 0, 0, 0, NULL, depca_probe};
1551
1552 /*1553 * This is a tweak to keep the insmod program happy. It can only1554 * set int values with var=value so we split these out.1555 */1556
1557 intirq=7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */1558 intio=0x200; /* Or use the irq= io= options to insmod */1559
1560 int1561 init_module(void)
/* */1562 {1563 thisDepca.irq=irq;
1564 thisDepca.base_addr=io;
1565 if (register_netdev(&thisDepca) != 0)
1566 return -EIO;
1567 return 0;
1568 }1569
1570 void1571 cleanup_module(void)
/* */1572 {1573 if (MOD_IN_USE) {1574 printk("%s: device busy, remove delayed\n",thisDepca.name);
1575 }else{1576 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
1577 unregister_netdev(&thisDepca);
1578 }1579 }1580 #endif/* MODULE */1581
1582
1583 /*1584 * Local variables:1585 * kernel-compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"1586 *1587 * module-compile-command: "gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"1588 * End:1589 */