at v2.6.17-rc2 2118 lines 62 kB view raw
1/* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux. 2 3 Written 1994, 1995 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 Copyright 1995 Digital Equipment Corporation. 12 13 14 This software may be used and distributed according to the terms of 15 the GNU General Public License, incorporated herein by reference. 16 17 This driver is written for the Digital Equipment Corporation series 18 of DEPCA and EtherWORKS ethernet cards: 19 20 DEPCA (the original) 21 DE100 22 DE101 23 DE200 Turbo 24 DE201 Turbo 25 DE202 Turbo (TP BNC) 26 DE210 27 DE422 (EISA) 28 29 The driver has been tested on DE100, DE200 and DE202 cards in a 30 relatively busy network. The DE422 has been tested a little. 31 32 This driver will NOT work for the DE203, DE204 and DE205 series of 33 cards, since they have a new custom ASIC in place of the AMD LANCE 34 chip. See the 'ewrk3.c' driver in the Linux source tree for running 35 those cards. 36 37 I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from) 38 a DECstation 5000/200. 39 40 The author may be reached at davies@maniac.ultranet.com 41 42 ========================================================================= 43 44 The driver was originally based on the 'lance.c' driver from Donald 45 Becker which is included with the standard driver distribution for 46 linux. V0.4 is a complete re-write with only the kernel interface 47 remaining from the original code. 48 49 1) Lance.c code in /linux/drivers/net/ 50 2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook", 51 AMD, 1992 [(800) 222-9323]. 52 3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)", 53 AMD, Pub. #17881, May 1993. 54 4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA", 55 AMD, Pub. #16907, May 1992 56 5) "DEC EtherWORKS LC Ethernet Controller Owners Manual", 57 Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003 58 6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual", 59 Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003 60 7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR 61 Digital Equipment Corporation, 1989 62 8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual", 63 Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001 64 65 66 Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this 67 driver. 68 69 The original DEPCA card requires that the ethernet ROM address counter 70 be enabled to count and has an 8 bit NICSR. The ROM counter enabling is 71 only done when a 0x08 is read as the first address octet (to minimise 72 the chances of writing over some other hardware's I/O register). The 73 NICSR accesses have been changed to byte accesses for all the cards 74 supported by this driver, since there is only one useful bit in the MSB 75 (remote boot timeout) and it is not used. Also, there is a maximum of 76 only 48kB network RAM for this card. My thanks to Torbjorn Lindh for 77 help debugging all this (and holding my feet to the fire until I got it 78 right). 79 80 The DE200 series boards have on-board 64kB RAM for use as a shared 81 memory network buffer. Only the DE100 cards make use of a 2kB buffer 82 mode which has not been implemented in this driver (only the 32kB and 83 64kB modes are supported [16kB/48kB for the original DEPCA]). 84 85 At the most only 2 DEPCA cards can be supported on the ISA bus because 86 there is only provision for two I/O base addresses on each card (0x300 87 and 0x200). The I/O address is detected by searching for a byte sequence 88 in the Ethernet station address PROM at the expected I/O address for the 89 Ethernet PROM. The shared memory base address is 'autoprobed' by 90 looking for the self test PROM and detecting the card name. When a 91 second DEPCA is detected, information is placed in the base_addr 92 variable of the next device structure (which is created if necessary), 93 thus enabling ethif_probe initialization for the device. More than 2 94 EISA cards can be supported, but care will be needed assigning the 95 shared memory to ensure that each slot has the correct IRQ, I/O address 96 and shared memory address assigned. 97 98 ************************************************************************ 99 100 NOTE: If you are using two ISA DEPCAs, it is important that you assign 101 the base memory addresses correctly. The driver autoprobes I/O 0x300 102 then 0x200. The base memory address for the first device must be less 103 than that of the second so that the auto probe will correctly assign the 104 I/O and memory addresses on the same card. I can't think of a way to do 105 this unambiguously at the moment, since there is nothing on the cards to 106 tie I/O and memory information together. 107 108 I am unable to test 2 cards together for now, so this code is 109 unchecked. All reports, good or bad, are welcome. 110 111 ************************************************************************ 112 113 The board IRQ setting must be at an unused IRQ which is auto-probed 114 using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are 115 {2,3,4,5,7}, whereas the DE200 is at {5,9,10,11,15}. Note that IRQ2 is 116 really IRQ9 in machines with 16 IRQ lines. 117 118 No 16MB memory limitation should exist with this driver as DMA is not 119 used and the common memory area is in low memory on the network card (my 120 current system has 20MB and I've not had problems yet). 121 122 The ability to load this driver as a loadable module has been added. To 123 utilise this ability, you have to do <8 things: 124 125 0) have a copy of the loadable modules code installed on your system. 126 1) copy depca.c from the /linux/drivers/net directory to your favourite 127 temporary directory. 128 2) if you wish, edit the source code near line 1530 to reflect the I/O 129 address and IRQ you're using (see also 5). 130 3) compile depca.c, but include -DMODULE in the command line to ensure 131 that the correct bits are compiled (see end of source code). 132 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a 133 kernel with the depca configuration turned off and reboot. 134 5) insmod depca.o [irq=7] [io=0x200] [mem=0xd0000] [adapter_name=DE100] 135 [Alan Cox: Changed the code to allow command line irq/io assignments] 136 [Dave Davies: Changed the code to allow command line mem/name 137 assignments] 138 6) run the net startup bits for your eth?? interface manually 139 (usually /etc/rc.inet[12] at boot time). 140 7) enjoy! 141 142 Note that autoprobing is not allowed in loadable modules - the system is 143 already up and running and you're messing with interrupts. 144 145 To unload a module, turn off the associated interface 146 'ifconfig eth?? down' then 'rmmod depca'. 147 148 To assign a base memory address for the shared memory when running as a 149 loadable module, see 5 above. To include the adapter name (if you have 150 no PROM but know the card name) also see 5 above. Note that this last 151 option will not work with kernel built-in depca's. 152 153 The shared memory assignment for a loadable module makes sense to avoid 154 the 'memory autoprobe' picking the wrong shared memory (for the case of 155 2 depca's in a PC). 156 157 ************************************************************************ 158 Support for MCA EtherWORKS cards added 11-3-98. 159 Verified to work with up to 2 DE212 cards in a system (although not 160 fully stress-tested). 161 162 Currently known bugs/limitations: 163 164 Note: with the MCA stuff as a module, it trusts the MCA configuration, 165 not the command line for IRQ and memory address. You can 166 specify them if you want, but it will throw your values out. 167 You still have to pass the IO address it was configured as 168 though. 169 170 ************************************************************************ 171 TO DO: 172 ------ 173 174 175 Revision History 176 ---------------- 177 178 Version Date Description 179 180 0.1 25-jan-94 Initial writing. 181 0.2 27-jan-94 Added LANCE TX hardware buffer chaining. 182 0.3 1-feb-94 Added multiple DEPCA support. 183 0.31 4-feb-94 Added DE202 recognition. 184 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support. 185 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable. 186 Add jabber packet fix from murf@perftech.com 187 and becker@super.org 188 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access. 189 0.35 8-mar-94 Added DE201 recognition. Tidied up. 190 0.351 30-apr-94 Added EISA support. Added DE422 recognition. 191 0.36 16-may-94 DE422 fix released. 192 0.37 22-jul-94 Added MODULE support 193 0.38 15-aug-94 Added DBR ROM switch in depca_close(). 194 Multi DEPCA bug fix. 195 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0. 196 0.381 12-dec-94 Added DE101 recognition, fix multicast bug. 197 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>. 198 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by 199 <stromain@alf.dec.com> 200 0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk> 201 0.385 3-apr-95 Fix a recognition bug reported by 202 <ryan.niemi@lastfrontier.com> 203 0.386 21-apr-95 Fix the last fix...sorry, must be galloping senility 204 0.40 25-May-95 Rewrite for portability & updated. 205 ALPHA support from <jestabro@amt.tay1.dec.com> 206 0.41 26-Jun-95 Added verify_area() calls in depca_ioctl() from 207 suggestion by <heiko@colossus.escape.de> 208 0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable 209 modules. 210 Add 'adapter_name' for loadable modules when no PROM. 211 Both above from a suggestion by 212 <pchen@woodruffs121.residence.gatech.edu>. 213 Add new multicasting code. 214 0.421 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi> 215 0.422 29-Apr-96 Fix depca_hw_init() bug <jari@markkus2.fimr.fi> 216 0.423 7-Jun-96 Fix module load bug <kmg@barco.be> 217 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c 218 0.44 1-Sep-97 Fix *_probe() to test check_region() first - bug 219 reported by <mmogilvi@elbert.uccs.edu> 220 0.45 3-Nov-98 Added support for MCA EtherWORKS (DE210/DE212) cards 221 by <tymm@computer.org> 222 0.451 5-Nov-98 Fixed mca stuff cuz I'm a dummy. <tymm@computer.org> 223 0.5 14-Nov-98 Re-spin for 2.1.x kernels. 224 0.51 27-Jun-99 Correct received packet length for CRC from 225 report by <worm@dkik.dk> 226 0.52 16-Oct-00 Fixes for 2.3 io memory accesses 227 Fix show-stopper (ints left masked) in depca_interrupt 228 by <peterd@pnd-pc.demon.co.uk> 229 0.53 12-Jan-01 Release resources on failure, bss tidbits 230 by acme@conectiva.com.br 231 0.54 08-Nov-01 use library crc32 functions 232 by Matt_Domsch@dell.com 233 0.55 01-Mar-03 Use EISA/sysfs framework <maz@wild-wind.fr.eu.org> 234 235 ========================================================================= 236*/ 237 238#include <linux/config.h> 239#include <linux/module.h> 240#include <linux/kernel.h> 241#include <linux/string.h> 242#include <linux/errno.h> 243#include <linux/ioport.h> 244#include <linux/slab.h> 245#include <linux/interrupt.h> 246#include <linux/delay.h> 247#include <linux/init.h> 248#include <linux/crc32.h> 249#include <linux/netdevice.h> 250#include <linux/etherdevice.h> 251#include <linux/skbuff.h> 252#include <linux/time.h> 253#include <linux/types.h> 254#include <linux/unistd.h> 255#include <linux/ctype.h> 256#include <linux/moduleparam.h> 257#include <linux/platform_device.h> 258#include <linux/bitops.h> 259 260#include <asm/uaccess.h> 261#include <asm/io.h> 262#include <asm/dma.h> 263 264#ifdef CONFIG_MCA 265#include <linux/mca.h> 266#endif 267 268#ifdef CONFIG_EISA 269#include <linux/eisa.h> 270#endif 271 272#include "depca.h" 273 274static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n"; 275 276#ifdef DEPCA_DEBUG 277static int depca_debug = DEPCA_DEBUG; 278#else 279static int depca_debug = 1; 280#endif 281 282#define DEPCA_NDA 0xffe0 /* No Device Address */ 283 284#define TX_TIMEOUT (1*HZ) 285 286/* 287** Ethernet PROM defines 288*/ 289#define PROBE_LENGTH 32 290#define ETH_PROM_SIG 0xAA5500FFUL 291 292/* 293** Set the number of Tx and Rx buffers. Ensure that the memory requested 294** here is <= to the amount of shared memory set up by the board switches. 295** The number of descriptors MUST BE A POWER OF 2. 296** 297** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ) 298*/ 299#define NUM_RX_DESC 8 /* Number of RX descriptors */ 300#define NUM_TX_DESC 8 /* Number of TX descriptors */ 301#define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */ 302#define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */ 303 304/* 305** EISA bus defines 306*/ 307#define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */ 308 309/* 310** ISA Bus defines 311*/ 312#define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000} 313#define DEPCA_TOTAL_SIZE 0x10 314 315static struct { 316 u_long iobase; 317 struct platform_device *device; 318} depca_io_ports[] = { 319 { 0x300, NULL }, 320 { 0x200, NULL }, 321 { 0 , NULL }, 322}; 323 324/* 325** Name <-> Adapter mapping 326*/ 327#define DEPCA_SIGNATURE {"DEPCA",\ 328 "DE100","DE101",\ 329 "DE200","DE201","DE202",\ 330 "DE210","DE212",\ 331 "DE422",\ 332 ""} 333 334static char* __initdata depca_signature[] = DEPCA_SIGNATURE; 335 336enum depca_type { 337 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown 338}; 339 340static char depca_string[] = "depca"; 341 342static int depca_device_remove (struct device *device); 343 344#ifdef CONFIG_EISA 345static struct eisa_device_id depca_eisa_ids[] = { 346 { "DEC4220", de422 }, 347 { "" } 348}; 349MODULE_DEVICE_TABLE(eisa, depca_eisa_ids); 350 351static int depca_eisa_probe (struct device *device); 352 353static struct eisa_driver depca_eisa_driver = { 354 .id_table = depca_eisa_ids, 355 .driver = { 356 .name = depca_string, 357 .probe = depca_eisa_probe, 358 .remove = __devexit_p (depca_device_remove) 359 } 360}; 361#endif 362 363#ifdef CONFIG_MCA 364/* 365** Adapter ID for the MCA EtherWORKS DE210/212 adapter 366*/ 367#define DE210_ID 0x628d 368#define DE212_ID 0x6def 369 370static short depca_mca_adapter_ids[] = { 371 DE210_ID, 372 DE212_ID, 373 0x0000 374}; 375 376static char *depca_mca_adapter_name[] = { 377 "DEC EtherWORKS MC Adapter (DE210)", 378 "DEC EtherWORKS MC Adapter (DE212)", 379 NULL 380}; 381 382static enum depca_type depca_mca_adapter_type[] = { 383 de210, 384 de212, 385 0 386}; 387 388static int depca_mca_probe (struct device *); 389 390static struct mca_driver depca_mca_driver = { 391 .id_table = depca_mca_adapter_ids, 392 .driver = { 393 .name = depca_string, 394 .bus = &mca_bus_type, 395 .probe = depca_mca_probe, 396 .remove = __devexit_p(depca_device_remove), 397 }, 398}; 399#endif 400 401static int depca_isa_probe (struct platform_device *); 402 403static int __devexit depca_isa_remove(struct platform_device *pdev) 404{ 405 return depca_device_remove(&pdev->dev); 406} 407 408static struct platform_driver depca_isa_driver = { 409 .probe = depca_isa_probe, 410 .remove = __devexit_p(depca_isa_remove), 411 .driver = { 412 .name = depca_string, 413 }, 414}; 415 416/* 417** Miscellaneous info... 418*/ 419#define DEPCA_STRLEN 16 420 421/* 422** Memory Alignment. Each descriptor is 4 longwords long. To force a 423** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and 424** DESC_ALIGN. DEPCA_ALIGN aligns the start address of the private memory area 425** and hence the RX descriptor ring's first entry. 426*/ 427#define DEPCA_ALIGN4 ((u_long)4 - 1) /* 1 longword align */ 428#define DEPCA_ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */ 429#define DEPCA_ALIGN DEPCA_ALIGN8 /* Keep the LANCE happy... */ 430 431/* 432** The DEPCA Rx and Tx ring descriptors. 433*/ 434struct depca_rx_desc { 435 volatile s32 base; 436 s16 buf_length; /* This length is negative 2's complement! */ 437 s16 msg_length; /* This length is "normal". */ 438}; 439 440struct depca_tx_desc { 441 volatile s32 base; 442 s16 length; /* This length is negative 2's complement! */ 443 s16 misc; /* Errors and TDR info */ 444}; 445 446#define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM 447 to LANCE memory address space */ 448 449/* 450** The Lance initialization block, described in databook, in common memory. 451*/ 452struct depca_init { 453 u16 mode; /* Mode register */ 454 u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */ 455 u8 mcast_table[8]; /* Multicast Hash Table. */ 456 u32 rx_ring; /* Rx ring base pointer & ring length */ 457 u32 tx_ring; /* Tx ring base pointer & ring length */ 458}; 459 460#define DEPCA_PKT_STAT_SZ 16 461#define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you 462 increase DEPCA_PKT_STAT_SZ */ 463struct depca_private { 464 char adapter_name[DEPCA_STRLEN]; /* /proc/ioports string */ 465 enum depca_type adapter; /* Adapter type */ 466 enum { 467 DEPCA_BUS_MCA = 1, 468 DEPCA_BUS_ISA, 469 DEPCA_BUS_EISA, 470 } depca_bus; /* type of bus */ 471 struct depca_init init_block; /* Shadow Initialization block */ 472/* CPU address space fields */ 473 struct depca_rx_desc __iomem *rx_ring; /* Pointer to start of RX descriptor ring */ 474 struct depca_tx_desc __iomem *tx_ring; /* Pointer to start of TX descriptor ring */ 475 void __iomem *rx_buff[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */ 476 void __iomem *tx_buff[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */ 477 void __iomem *sh_mem; /* CPU mapped virt address of device RAM */ 478 u_long mem_start; /* Bus address of device RAM (before remap) */ 479 u_long mem_len; /* device memory size */ 480/* Device address space fields */ 481 u_long device_ram_start; /* Start of RAM in device addr space */ 482/* Offsets used in both address spaces */ 483 u_long rx_ring_offset; /* Offset from start of RAM to rx_ring */ 484 u_long tx_ring_offset; /* Offset from start of RAM to tx_ring */ 485 u_long buffs_offset; /* LANCE Rx and Tx buffers start address. */ 486/* Kernel-only (not device) fields */ 487 int rx_new, tx_new; /* The next free ring entry */ 488 int rx_old, tx_old; /* The ring entries to be free()ed. */ 489 struct net_device_stats stats; 490 spinlock_t lock; 491 struct { /* Private stats counters */ 492 u32 bins[DEPCA_PKT_STAT_SZ]; 493 u32 unicast; 494 u32 multicast; 495 u32 broadcast; 496 u32 excessive_collisions; 497 u32 tx_underruns; 498 u32 excessive_underruns; 499 } pktStats; 500 int txRingMask; /* TX ring mask */ 501 int rxRingMask; /* RX ring mask */ 502 s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */ 503 s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */ 504}; 505 506/* 507** The transmit ring full condition is described by the tx_old and tx_new 508** pointers by: 509** tx_old = tx_new Empty ring 510** tx_old = tx_new+1 Full ring 511** tx_old+txRingMask = tx_new Full ring (wrapped condition) 512*/ 513#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\ 514 lp->tx_old+lp->txRingMask-lp->tx_new:\ 515 lp->tx_old -lp->tx_new-1) 516 517/* 518** Public Functions 519*/ 520static int depca_open(struct net_device *dev); 521static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev); 522static irqreturn_t depca_interrupt(int irq, void *dev_id, struct pt_regs *regs); 523static int depca_close(struct net_device *dev); 524static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 525static void depca_tx_timeout(struct net_device *dev); 526static struct net_device_stats *depca_get_stats(struct net_device *dev); 527static void set_multicast_list(struct net_device *dev); 528 529/* 530** Private functions 531*/ 532static void depca_init_ring(struct net_device *dev); 533static int depca_rx(struct net_device *dev); 534static int depca_tx(struct net_device *dev); 535 536static void LoadCSRs(struct net_device *dev); 537static int InitRestartDepca(struct net_device *dev); 538static int DepcaSignature(char *name, u_long paddr); 539static int DevicePresent(u_long ioaddr); 540static int get_hw_addr(struct net_device *dev); 541static void SetMulticastFilter(struct net_device *dev); 542static int load_packet(struct net_device *dev, struct sk_buff *skb); 543static void depca_dbg_open(struct net_device *dev); 544 545static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 }; 546static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 }; 547static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 }; 548static u_char *depca_irq; 549 550static int irq; 551static int io; 552static char *adapter_name; 553static int mem; /* For loadable module assignment 554 use insmod mem=0x????? .... */ 555module_param (irq, int, 0); 556module_param (io, int, 0); 557module_param (adapter_name, charp, 0); 558module_param (mem, int, 0); 559MODULE_PARM_DESC(irq, "DEPCA IRQ number"); 560MODULE_PARM_DESC(io, "DEPCA I/O base address"); 561MODULE_PARM_DESC(adapter_name, "DEPCA adapter name"); 562MODULE_PARM_DESC(mem, "DEPCA shared memory address"); 563MODULE_LICENSE("GPL"); 564 565/* 566** Miscellaneous defines... 567*/ 568#define STOP_DEPCA \ 569 outw(CSR0, DEPCA_ADDR);\ 570 outw(STOP, DEPCA_DATA) 571 572static int __init depca_hw_init (struct net_device *dev, struct device *device) 573{ 574 struct depca_private *lp; 575 int i, j, offset, netRAM, mem_len, status = 0; 576 s16 nicsr; 577 u_long ioaddr; 578 u_long mem_start; 579 580 /* 581 * We are now supposed to enter this function with the 582 * following fields filled with proper values : 583 * 584 * dev->base_addr 585 * lp->mem_start 586 * lp->depca_bus 587 * lp->adapter 588 * 589 * dev->irq can be set if known from device configuration (on 590 * MCA or EISA) or module option. Otherwise, it will be auto 591 * detected. 592 */ 593 594 ioaddr = dev->base_addr; 595 596 STOP_DEPCA; 597 598 nicsr = inb(DEPCA_NICSR); 599 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM); 600 outb(nicsr, DEPCA_NICSR); 601 602 if (inw(DEPCA_DATA) != STOP) { 603 return -ENXIO; 604 } 605 606 lp = (struct depca_private *) dev->priv; 607 mem_start = lp->mem_start; 608 609 if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown) 610 return -ENXIO; 611 612 printk ("%s: %s at 0x%04lx", 613 device->bus_id, depca_signature[lp->adapter], ioaddr); 614 615 switch (lp->depca_bus) { 616#ifdef CONFIG_MCA 617 case DEPCA_BUS_MCA: 618 printk(" (MCA slot %d)", to_mca_device(device)->slot + 1); 619 break; 620#endif 621 622#ifdef CONFIG_EISA 623 case DEPCA_BUS_EISA: 624 printk(" (EISA slot %d)", to_eisa_device(device)->slot); 625 break; 626#endif 627 628 case DEPCA_BUS_ISA: 629 break; 630 631 default: 632 printk("Unknown DEPCA bus %d\n", lp->depca_bus); 633 return -ENXIO; 634 } 635 636 printk(", h/w address "); 637 status = get_hw_addr(dev); 638 if (status != 0) { 639 printk(" which has an Ethernet PROM CRC error.\n"); 640 return -ENXIO; 641 } 642 for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet address */ 643 printk("%2.2x:", dev->dev_addr[i]); 644 } 645 printk("%2.2x", dev->dev_addr[i]); 646 647 /* Set up the maximum amount of network RAM(kB) */ 648 netRAM = ((lp->adapter != DEPCA) ? 64 : 48); 649 if ((nicsr & _128KB) && (lp->adapter == de422)) 650 netRAM = 128; 651 652 /* Shared Memory Base Address */ 653 if (nicsr & BUF) { 654 nicsr &= ~BS; /* DEPCA RAM in top 32k */ 655 netRAM -= 32; 656 657 /* Only EISA/ISA needs start address to be re-computed */ 658 if (lp->depca_bus != DEPCA_BUS_MCA) 659 mem_start += 0x8000; 660 } 661 662 if ((mem_len = (NUM_RX_DESC * (sizeof(struct depca_rx_desc) + RX_BUFF_SZ) + NUM_TX_DESC * (sizeof(struct depca_tx_desc) + TX_BUFF_SZ) + sizeof(struct depca_init))) 663 > (netRAM << 10)) { 664 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM); 665 return -ENXIO; 666 } 667 668 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start); 669 670 /* Enable the shadow RAM. */ 671 if (lp->adapter != DEPCA) { 672 nicsr |= SHE; 673 outb(nicsr, DEPCA_NICSR); 674 } 675 676 spin_lock_init(&lp->lock); 677 sprintf(lp->adapter_name, "%s (%s)", 678 depca_signature[lp->adapter], device->bus_id); 679 status = -EBUSY; 680 681 /* Initialisation Block */ 682 if (!request_mem_region (mem_start, mem_len, lp->adapter_name)) { 683 printk(KERN_ERR "depca: cannot request ISA memory, aborting\n"); 684 goto out_priv; 685 } 686 687 status = -EIO; 688 lp->sh_mem = ioremap(mem_start, mem_len); 689 if (lp->sh_mem == NULL) { 690 printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n"); 691 goto out1; 692 } 693 694 lp->mem_start = mem_start; 695 lp->mem_len = mem_len; 696 lp->device_ram_start = mem_start & LA_MASK; 697 698 offset = 0; 699 offset += sizeof(struct depca_init); 700 701 /* Tx & Rx descriptors (aligned to a quadword boundary) */ 702 offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN; 703 lp->rx_ring = (struct depca_rx_desc __iomem *) (lp->sh_mem + offset); 704 lp->rx_ring_offset = offset; 705 706 offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC); 707 lp->tx_ring = (struct depca_tx_desc __iomem *) (lp->sh_mem + offset); 708 lp->tx_ring_offset = offset; 709 710 offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC); 711 712 lp->buffs_offset = offset; 713 714 /* Finish initialising the ring information. */ 715 lp->rxRingMask = NUM_RX_DESC - 1; 716 lp->txRingMask = NUM_TX_DESC - 1; 717 718 /* Calculate Tx/Rx RLEN size for the descriptors. */ 719 for (i = 0, j = lp->rxRingMask; j > 0; i++) { 720 j >>= 1; 721 } 722 lp->rx_rlen = (s32) (i << 29); 723 for (i = 0, j = lp->txRingMask; j > 0; i++) { 724 j >>= 1; 725 } 726 lp->tx_rlen = (s32) (i << 29); 727 728 /* Load the initialisation block */ 729 depca_init_ring(dev); 730 731 /* Initialise the control and status registers */ 732 LoadCSRs(dev); 733 734 /* Enable DEPCA board interrupts for autoprobing */ 735 nicsr = ((nicsr & ~IM) | IEN); 736 outb(nicsr, DEPCA_NICSR); 737 738 /* To auto-IRQ we enable the initialization-done and DMA err, 739 interrupts. For now we will always get a DMA error. */ 740 if (dev->irq < 2) { 741 unsigned char irqnum; 742 unsigned long irq_mask, delay; 743 744 irq_mask = probe_irq_on(); 745 746 /* Assign the correct irq list */ 747 switch (lp->adapter) { 748 case DEPCA: 749 case de100: 750 case de101: 751 depca_irq = de1xx_irq; 752 break; 753 case de200: 754 case de201: 755 case de202: 756 case de210: 757 case de212: 758 depca_irq = de2xx_irq; 759 break; 760 case de422: 761 depca_irq = de422_irq; 762 break; 763 764 default: 765 break; /* Not reached */ 766 } 767 768 /* Trigger an initialization just for the interrupt. */ 769 outw(INEA | INIT, DEPCA_DATA); 770 771 delay = jiffies + HZ/50; 772 while (time_before(jiffies, delay)) 773 yield(); 774 775 irqnum = probe_irq_off(irq_mask); 776 777 status = -ENXIO; 778 if (!irqnum) { 779 printk(" and failed to detect IRQ line.\n"); 780 goto out2; 781 } else { 782 for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++) 783 if (irqnum == depca_irq[i]) { 784 dev->irq = irqnum; 785 printk(" and uses IRQ%d.\n", dev->irq); 786 } 787 788 if (!dev->irq) { 789 printk(" but incorrect IRQ line detected.\n"); 790 goto out2; 791 } 792 } 793 } else { 794 printk(" and assigned IRQ%d.\n", dev->irq); 795 } 796 797 if (depca_debug > 1) { 798 printk(version); 799 } 800 801 /* The DEPCA-specific entries in the device structure. */ 802 dev->open = &depca_open; 803 dev->hard_start_xmit = &depca_start_xmit; 804 dev->stop = &depca_close; 805 dev->get_stats = &depca_get_stats; 806 dev->set_multicast_list = &set_multicast_list; 807 dev->do_ioctl = &depca_ioctl; 808 dev->tx_timeout = depca_tx_timeout; 809 dev->watchdog_timeo = TX_TIMEOUT; 810 811 dev->mem_start = 0; 812 813 device->driver_data = dev; 814 SET_NETDEV_DEV (dev, device); 815 816 status = register_netdev(dev); 817 if (status == 0) 818 return 0; 819out2: 820 iounmap(lp->sh_mem); 821out1: 822 release_mem_region (mem_start, mem_len); 823out_priv: 824 return status; 825} 826 827 828static int depca_open(struct net_device *dev) 829{ 830 struct depca_private *lp = (struct depca_private *) dev->priv; 831 u_long ioaddr = dev->base_addr; 832 s16 nicsr; 833 int status = 0; 834 835 STOP_DEPCA; 836 nicsr = inb(DEPCA_NICSR); 837 838 /* Make sure the shadow RAM is enabled */ 839 if (lp->adapter != DEPCA) { 840 nicsr |= SHE; 841 outb(nicsr, DEPCA_NICSR); 842 } 843 844 /* Re-initialize the DEPCA... */ 845 depca_init_ring(dev); 846 LoadCSRs(dev); 847 848 depca_dbg_open(dev); 849 850 if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) { 851 printk("depca_open(): Requested IRQ%d is busy\n", dev->irq); 852 status = -EAGAIN; 853 } else { 854 855 /* Enable DEPCA board interrupts and turn off LED */ 856 nicsr = ((nicsr & ~IM & ~LED) | IEN); 857 outb(nicsr, DEPCA_NICSR); 858 outw(CSR0, DEPCA_ADDR); 859 860 netif_start_queue(dev); 861 862 status = InitRestartDepca(dev); 863 864 if (depca_debug > 1) { 865 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA)); 866 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR)); 867 } 868 } 869 return status; 870} 871 872/* Initialize the lance Rx and Tx descriptor rings. */ 873static void depca_init_ring(struct net_device *dev) 874{ 875 struct depca_private *lp = (struct depca_private *) dev->priv; 876 u_int i; 877 u_long offset; 878 879 /* Lock out other processes whilst setting up the hardware */ 880 netif_stop_queue(dev); 881 882 lp->rx_new = lp->tx_new = 0; 883 lp->rx_old = lp->tx_old = 0; 884 885 /* Initialize the base address and length of each buffer in the ring */ 886 for (i = 0; i <= lp->rxRingMask; i++) { 887 offset = lp->buffs_offset + i * RX_BUFF_SZ; 888 writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base); 889 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length); 890 lp->rx_buff[i] = lp->sh_mem + offset; 891 } 892 893 for (i = 0; i <= lp->txRingMask; i++) { 894 offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ; 895 writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base); 896 lp->tx_buff[i] = lp->sh_mem + offset; 897 } 898 899 /* Set up the initialization block */ 900 lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen; 901 lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen; 902 903 SetMulticastFilter(dev); 904 905 for (i = 0; i < ETH_ALEN; i++) { 906 lp->init_block.phys_addr[i] = dev->dev_addr[i]; 907 } 908 909 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */ 910} 911 912 913static void depca_tx_timeout(struct net_device *dev) 914{ 915 u_long ioaddr = dev->base_addr; 916 917 printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA)); 918 919 STOP_DEPCA; 920 depca_init_ring(dev); 921 LoadCSRs(dev); 922 dev->trans_start = jiffies; 923 netif_wake_queue(dev); 924 InitRestartDepca(dev); 925} 926 927 928/* 929** Writes a socket buffer to TX descriptor ring and starts transmission 930*/ 931static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev) 932{ 933 struct depca_private *lp = (struct depca_private *) dev->priv; 934 u_long ioaddr = dev->base_addr; 935 int status = 0; 936 937 /* Transmitter timeout, serious problems. */ 938 if (skb->len < 1) 939 goto out; 940 941 if (skb->len < ETH_ZLEN) { 942 skb = skb_padto(skb, ETH_ZLEN); 943 if (skb == NULL) 944 goto out; 945 } 946 947 netif_stop_queue(dev); 948 949 if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */ 950 status = load_packet(dev, skb); 951 952 if (!status) { 953 /* Trigger an immediate send demand. */ 954 outw(CSR0, DEPCA_ADDR); 955 outw(INEA | TDMD, DEPCA_DATA); 956 957 dev->trans_start = jiffies; 958 dev_kfree_skb(skb); 959 } 960 if (TX_BUFFS_AVAIL) 961 netif_start_queue(dev); 962 } else 963 status = -1; 964 965 out: 966 return status; 967} 968 969/* 970** The DEPCA interrupt handler. 971*/ 972static irqreturn_t depca_interrupt(int irq, void *dev_id, struct pt_regs *regs) 973{ 974 struct net_device *dev = dev_id; 975 struct depca_private *lp; 976 s16 csr0, nicsr; 977 u_long ioaddr; 978 979 if (dev == NULL) { 980 printk("depca_interrupt(): irq %d for unknown device.\n", irq); 981 return IRQ_NONE; 982 } 983 984 lp = (struct depca_private *) dev->priv; 985 ioaddr = dev->base_addr; 986 987 spin_lock(&lp->lock); 988 989 /* mask the DEPCA board interrupts and turn on the LED */ 990 nicsr = inb(DEPCA_NICSR); 991 nicsr |= (IM | LED); 992 outb(nicsr, DEPCA_NICSR); 993 994 outw(CSR0, DEPCA_ADDR); 995 csr0 = inw(DEPCA_DATA); 996 997 /* Acknowledge all of the current interrupt sources ASAP. */ 998 outw(csr0 & INTE, DEPCA_DATA); 999 1000 if (csr0 & RINT) /* Rx interrupt (packet arrived) */ 1001 depca_rx(dev); 1002 1003 if (csr0 & TINT) /* Tx interrupt (packet sent) */ 1004 depca_tx(dev); 1005 1006 /* Any resources available? */ 1007 if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) { 1008 netif_wake_queue(dev); 1009 } 1010 1011 /* Unmask the DEPCA board interrupts and turn off the LED */ 1012 nicsr = (nicsr & ~IM & ~LED); 1013 outb(nicsr, DEPCA_NICSR); 1014 1015 spin_unlock(&lp->lock); 1016 return IRQ_HANDLED; 1017} 1018 1019/* Called with lp->lock held */ 1020static int depca_rx(struct net_device *dev) 1021{ 1022 struct depca_private *lp = (struct depca_private *) dev->priv; 1023 int i, entry; 1024 s32 status; 1025 1026 for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) { 1027 status = readl(&lp->rx_ring[entry].base) >> 16; 1028 if (status & R_STP) { /* Remember start of frame */ 1029 lp->rx_old = entry; 1030 } 1031 if (status & R_ENP) { /* Valid frame status */ 1032 if (status & R_ERR) { /* There was an error. */ 1033 lp->stats.rx_errors++; /* Update the error stats. */ 1034 if (status & R_FRAM) 1035 lp->stats.rx_frame_errors++; 1036 if (status & R_OFLO) 1037 lp->stats.rx_over_errors++; 1038 if (status & R_CRC) 1039 lp->stats.rx_crc_errors++; 1040 if (status & R_BUFF) 1041 lp->stats.rx_fifo_errors++; 1042 } else { 1043 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4; 1044 struct sk_buff *skb; 1045 1046 skb = dev_alloc_skb(pkt_len + 2); 1047 if (skb != NULL) { 1048 unsigned char *buf; 1049 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1050 buf = skb_put(skb, pkt_len); 1051 skb->dev = dev; 1052 if (entry < lp->rx_old) { /* Wrapped buffer */ 1053 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ; 1054 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len); 1055 memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len); 1056 } else { /* Linear buffer */ 1057 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len); 1058 } 1059 1060 /* 1061 ** Notify the upper protocol layers that there is another 1062 ** packet to handle 1063 */ 1064 skb->protocol = eth_type_trans(skb, dev); 1065 netif_rx(skb); 1066 1067 /* 1068 ** Update stats 1069 */ 1070 dev->last_rx = jiffies; 1071 lp->stats.rx_packets++; 1072 lp->stats.rx_bytes += pkt_len; 1073 for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) { 1074 if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) { 1075 lp->pktStats.bins[i]++; 1076 i = DEPCA_PKT_STAT_SZ; 1077 } 1078 } 1079 if (buf[0] & 0x01) { /* Multicast/Broadcast */ 1080 if ((*(s16 *) & buf[0] == -1) && (*(s16 *) & buf[2] == -1) && (*(s16 *) & buf[4] == -1)) { 1081 lp->pktStats.broadcast++; 1082 } else { 1083 lp->pktStats.multicast++; 1084 } 1085 } else if ((*(s16 *) & buf[0] == *(s16 *) & dev->dev_addr[0]) && (*(s16 *) & buf[2] == *(s16 *) & dev->dev_addr[2]) && (*(s16 *) & buf[4] == *(s16 *) & dev->dev_addr[4])) { 1086 lp->pktStats.unicast++; 1087 } 1088 1089 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */ 1090 if (lp->pktStats.bins[0] == 0) { /* Reset counters */ 1091 memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats)); 1092 } 1093 } else { 1094 printk("%s: Memory squeeze, deferring packet.\n", dev->name); 1095 lp->stats.rx_dropped++; /* Really, deferred. */ 1096 break; 1097 } 1098 } 1099 /* Change buffer ownership for this last frame, back to the adapter */ 1100 for (; lp->rx_old != entry; lp->rx_old = (++lp->rx_old) & lp->rxRingMask) { 1101 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base); 1102 } 1103 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base); 1104 } 1105 1106 /* 1107 ** Update entry information 1108 */ 1109 lp->rx_new = (++lp->rx_new) & lp->rxRingMask; 1110 } 1111 1112 return 0; 1113} 1114 1115/* 1116** Buffer sent - check for buffer errors. 1117** Called with lp->lock held 1118*/ 1119static int depca_tx(struct net_device *dev) 1120{ 1121 struct depca_private *lp = (struct depca_private *) dev->priv; 1122 int entry; 1123 s32 status; 1124 u_long ioaddr = dev->base_addr; 1125 1126 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) { 1127 status = readl(&lp->tx_ring[entry].base) >> 16; 1128 1129 if (status < 0) { /* Packet not yet sent! */ 1130 break; 1131 } else if (status & T_ERR) { /* An error occurred. */ 1132 status = readl(&lp->tx_ring[entry].misc); 1133 lp->stats.tx_errors++; 1134 if (status & TMD3_RTRY) 1135 lp->stats.tx_aborted_errors++; 1136 if (status & TMD3_LCAR) 1137 lp->stats.tx_carrier_errors++; 1138 if (status & TMD3_LCOL) 1139 lp->stats.tx_window_errors++; 1140 if (status & TMD3_UFLO) 1141 lp->stats.tx_fifo_errors++; 1142 if (status & (TMD3_BUFF | TMD3_UFLO)) { 1143 /* Trigger an immediate send demand. */ 1144 outw(CSR0, DEPCA_ADDR); 1145 outw(INEA | TDMD, DEPCA_DATA); 1146 } 1147 } else if (status & (T_MORE | T_ONE)) { 1148 lp->stats.collisions++; 1149 } else { 1150 lp->stats.tx_packets++; 1151 } 1152 1153 /* Update all the pointers */ 1154 lp->tx_old = (++lp->tx_old) & lp->txRingMask; 1155 } 1156 1157 return 0; 1158} 1159 1160static int depca_close(struct net_device *dev) 1161{ 1162 struct depca_private *lp = (struct depca_private *) dev->priv; 1163 s16 nicsr; 1164 u_long ioaddr = dev->base_addr; 1165 1166 netif_stop_queue(dev); 1167 1168 outw(CSR0, DEPCA_ADDR); 1169 1170 if (depca_debug > 1) { 1171 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA)); 1172 } 1173 1174 /* 1175 ** We stop the DEPCA here -- it occasionally polls 1176 ** memory if we don't. 1177 */ 1178 outw(STOP, DEPCA_DATA); 1179 1180 /* 1181 ** Give back the ROM in case the user wants to go to DOS 1182 */ 1183 if (lp->adapter != DEPCA) { 1184 nicsr = inb(DEPCA_NICSR); 1185 nicsr &= ~SHE; 1186 outb(nicsr, DEPCA_NICSR); 1187 } 1188 1189 /* 1190 ** Free the associated irq 1191 */ 1192 free_irq(dev->irq, dev); 1193 return 0; 1194} 1195 1196static void LoadCSRs(struct net_device *dev) 1197{ 1198 struct depca_private *lp = (struct depca_private *) dev->priv; 1199 u_long ioaddr = dev->base_addr; 1200 1201 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */ 1202 outw((u16) lp->device_ram_start, DEPCA_DATA); 1203 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */ 1204 outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA); 1205 outw(CSR3, DEPCA_ADDR); /* ALE control */ 1206 outw(ACON, DEPCA_DATA); 1207 1208 outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */ 1209 1210 return; 1211} 1212 1213static int InitRestartDepca(struct net_device *dev) 1214{ 1215 struct depca_private *lp = (struct depca_private *) dev->priv; 1216 u_long ioaddr = dev->base_addr; 1217 int i, status = 0; 1218 1219 /* Copy the shadow init_block to shared memory */ 1220 memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init)); 1221 1222 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */ 1223 outw(INIT, DEPCA_DATA); /* initialize DEPCA */ 1224 1225 /* wait for lance to complete initialisation */ 1226 for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++); 1227 1228 if (i != 100) { 1229 /* clear IDON by writing a "1", enable interrupts and start lance */ 1230 outw(IDON | INEA | STRT, DEPCA_DATA); 1231 if (depca_debug > 2) { 1232 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA)); 1233 } 1234 } else { 1235 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA)); 1236 status = -1; 1237 } 1238 1239 return status; 1240} 1241 1242static struct net_device_stats *depca_get_stats(struct net_device *dev) 1243{ 1244 struct depca_private *lp = (struct depca_private *) dev->priv; 1245 1246 /* Null body since there is no framing error counter */ 1247 1248 return &lp->stats; 1249} 1250 1251/* 1252** Set or clear the multicast filter for this adaptor. 1253*/ 1254static void set_multicast_list(struct net_device *dev) 1255{ 1256 struct depca_private *lp = (struct depca_private *) dev->priv; 1257 u_long ioaddr = dev->base_addr; 1258 1259 if (dev) { 1260 netif_stop_queue(dev); 1261 while (lp->tx_old != lp->tx_new); /* Wait for the ring to empty */ 1262 1263 STOP_DEPCA; /* Temporarily stop the depca. */ 1264 depca_init_ring(dev); /* Initialize the descriptor rings */ 1265 1266 if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */ 1267 lp->init_block.mode |= PROM; 1268 } else { 1269 SetMulticastFilter(dev); 1270 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */ 1271 } 1272 1273 LoadCSRs(dev); /* Reload CSR3 */ 1274 InitRestartDepca(dev); /* Resume normal operation. */ 1275 netif_start_queue(dev); /* Unlock the TX ring */ 1276 } 1277} 1278 1279/* 1280** Calculate the hash code and update the logical address filter 1281** from a list of ethernet multicast addresses. 1282** Big endian crc one liner is mine, all mine, ha ha ha ha! 1283** LANCE calculates its hash codes big endian. 1284*/ 1285static void SetMulticastFilter(struct net_device *dev) 1286{ 1287 struct depca_private *lp = (struct depca_private *) dev->priv; 1288 struct dev_mc_list *dmi = dev->mc_list; 1289 char *addrs; 1290 int i, j, bit, byte; 1291 u16 hashcode; 1292 u32 crc; 1293 1294 if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */ 1295 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { 1296 lp->init_block.mcast_table[i] = (char) 0xff; 1297 } 1298 } else { 1299 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { /* Clear the multicast table */ 1300 lp->init_block.mcast_table[i] = 0; 1301 } 1302 /* Add multicast addresses */ 1303 for (i = 0; i < dev->mc_count; i++) { /* for each address in the list */ 1304 addrs = dmi->dmi_addr; 1305 dmi = dmi->next; 1306 if ((*addrs & 0x01) == 1) { /* multicast address? */ 1307 crc = ether_crc(ETH_ALEN, addrs); 1308 hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */ 1309 for (j = 0; j < 5; j++) { /* ... in reverse order. */ 1310 hashcode = (hashcode << 1) | ((crc >>= 1) & 1); 1311 } 1312 1313 1314 byte = hashcode >> 3; /* bit[3-5] -> byte in filter */ 1315 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */ 1316 lp->init_block.mcast_table[byte] |= bit; 1317 } 1318 } 1319 } 1320 1321 return; 1322} 1323 1324static int __init depca_common_init (u_long ioaddr, struct net_device **devp) 1325{ 1326 int status = 0; 1327 1328 if (!request_region (ioaddr, DEPCA_TOTAL_SIZE, depca_string)) { 1329 status = -EBUSY; 1330 goto out; 1331 } 1332 1333 if (DevicePresent(ioaddr)) { 1334 status = -ENODEV; 1335 goto out_release; 1336 } 1337 1338 if (!(*devp = alloc_etherdev (sizeof (struct depca_private)))) { 1339 status = -ENOMEM; 1340 goto out_release; 1341 } 1342 1343 return 0; 1344 1345 out_release: 1346 release_region (ioaddr, DEPCA_TOTAL_SIZE); 1347 out: 1348 return status; 1349} 1350 1351#ifdef CONFIG_MCA 1352/* 1353** Microchannel bus I/O device probe 1354*/ 1355static int __init depca_mca_probe(struct device *device) 1356{ 1357 unsigned char pos[2]; 1358 unsigned char where; 1359 unsigned long iobase, mem_start; 1360 int irq, err; 1361 struct mca_device *mdev = to_mca_device (device); 1362 struct net_device *dev; 1363 struct depca_private *lp; 1364 1365 /* 1366 ** Search for the adapter. If an address has been given, search 1367 ** specifically for the card at that address. Otherwise find the 1368 ** first card in the system. 1369 */ 1370 1371 pos[0] = mca_device_read_stored_pos(mdev, 2); 1372 pos[1] = mca_device_read_stored_pos(mdev, 3); 1373 1374 /* 1375 ** IO of card is handled by bits 1 and 2 of pos0. 1376 ** 1377 ** bit2 bit1 IO 1378 ** 0 0 0x2c00 1379 ** 0 1 0x2c10 1380 ** 1 0 0x2c20 1381 ** 1 1 0x2c30 1382 */ 1383 where = (pos[0] & 6) >> 1; 1384 iobase = 0x2c00 + (0x10 * where); 1385 1386 /* 1387 ** Found the adapter we were looking for. Now start setting it up. 1388 ** 1389 ** First work on decoding the IRQ. It's stored in the lower 4 bits 1390 ** of pos1. Bits are as follows (from the ADF file): 1391 ** 1392 ** Bits 1393 ** 3 2 1 0 IRQ 1394 ** -------------------- 1395 ** 0 0 1 0 5 1396 ** 0 0 0 1 9 1397 ** 0 1 0 0 10 1398 ** 1 0 0 0 11 1399 */ 1400 where = pos[1] & 0x0f; 1401 switch (where) { 1402 case 1: 1403 irq = 9; 1404 break; 1405 case 2: 1406 irq = 5; 1407 break; 1408 case 4: 1409 irq = 10; 1410 break; 1411 case 8: 1412 irq = 11; 1413 break; 1414 default: 1415 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", mdev->name, where); 1416 return -EINVAL; 1417 } 1418 1419 /* 1420 ** Shared memory address of adapter is stored in bits 3-5 of pos0. 1421 ** They are mapped as follows: 1422 ** 1423 ** Bit 1424 ** 5 4 3 Memory Addresses 1425 ** 0 0 0 C0000-CFFFF (64K) 1426 ** 1 0 0 C8000-CFFFF (32K) 1427 ** 0 0 1 D0000-DFFFF (64K) 1428 ** 1 0 1 D8000-DFFFF (32K) 1429 ** 0 1 0 E0000-EFFFF (64K) 1430 ** 1 1 0 E8000-EFFFF (32K) 1431 */ 1432 where = (pos[0] & 0x18) >> 3; 1433 mem_start = 0xc0000 + (where * 0x10000); 1434 if (pos[0] & 0x20) { 1435 mem_start += 0x8000; 1436 } 1437 1438 /* claim the slot */ 1439 strncpy(mdev->name, depca_mca_adapter_name[mdev->index], 1440 sizeof(mdev->name)); 1441 mca_device_set_claim(mdev, 1); 1442 1443 /* 1444 ** Get everything allocated and initialized... (almost just 1445 ** like the ISA and EISA probes) 1446 */ 1447 irq = mca_device_transform_irq(mdev, irq); 1448 iobase = mca_device_transform_ioport(mdev, iobase); 1449 1450 if ((err = depca_common_init (iobase, &dev))) 1451 goto out_unclaim; 1452 1453 dev->irq = irq; 1454 dev->base_addr = iobase; 1455 lp = dev->priv; 1456 lp->depca_bus = DEPCA_BUS_MCA; 1457 lp->adapter = depca_mca_adapter_type[mdev->index]; 1458 lp->mem_start = mem_start; 1459 1460 if ((err = depca_hw_init(dev, device))) 1461 goto out_free; 1462 1463 return 0; 1464 1465 out_free: 1466 free_netdev (dev); 1467 release_region (iobase, DEPCA_TOTAL_SIZE); 1468 out_unclaim: 1469 mca_device_set_claim(mdev, 0); 1470 1471 return err; 1472} 1473#endif 1474 1475/* 1476** ISA bus I/O device probe 1477*/ 1478 1479static void __init depca_platform_probe (void) 1480{ 1481 int i; 1482 struct platform_device *pldev; 1483 1484 for (i = 0; depca_io_ports[i].iobase; i++) { 1485 depca_io_ports[i].device = NULL; 1486 1487 /* if an address has been specified on the command 1488 * line, use it (if valid) */ 1489 if (io && io != depca_io_ports[i].iobase) 1490 continue; 1491 1492 pldev = platform_device_alloc(depca_string, i); 1493 if (!pldev) 1494 continue; 1495 1496 pldev->dev.platform_data = (void *) depca_io_ports[i].iobase; 1497 depca_io_ports[i].device = pldev; 1498 1499 if (platform_device_add(pldev)) { 1500 platform_device_put(pldev); 1501 depca_io_ports[i].device = NULL; 1502 continue; 1503 } 1504 1505 if (!pldev->dev.driver) { 1506 /* The driver was not bound to this device, there was 1507 * no hardware at this address. Unregister it, as the 1508 * release fuction will take care of freeing the 1509 * allocated structure */ 1510 1511 depca_io_ports[i].device = NULL; 1512 pldev->dev.platform_data = NULL; 1513 platform_device_unregister (pldev); 1514 } 1515 } 1516} 1517 1518static enum depca_type __init depca_shmem_probe (ulong *mem_start) 1519{ 1520 u_long mem_base[] = DEPCA_RAM_BASE_ADDRESSES; 1521 enum depca_type adapter = unknown; 1522 int i; 1523 1524 for (i = 0; mem_base[i]; i++) { 1525 *mem_start = mem ? mem : mem_base[i]; 1526 adapter = DepcaSignature (adapter_name, *mem_start); 1527 if (adapter != unknown) 1528 break; 1529 } 1530 1531 return adapter; 1532} 1533 1534static int __init depca_isa_probe (struct platform_device *device) 1535{ 1536 struct net_device *dev; 1537 struct depca_private *lp; 1538 u_long ioaddr, mem_start = 0; 1539 enum depca_type adapter = unknown; 1540 int status = 0; 1541 1542 ioaddr = (u_long) device->dev.platform_data; 1543 1544 if ((status = depca_common_init (ioaddr, &dev))) 1545 goto out; 1546 1547 adapter = depca_shmem_probe (&mem_start); 1548 1549 if (adapter == unknown) { 1550 status = -ENODEV; 1551 goto out_free; 1552 } 1553 1554 dev->base_addr = ioaddr; 1555 dev->irq = irq; /* Use whatever value the user gave 1556 * us, and 0 if he didn't. */ 1557 lp = dev->priv; 1558 lp->depca_bus = DEPCA_BUS_ISA; 1559 lp->adapter = adapter; 1560 lp->mem_start = mem_start; 1561 1562 if ((status = depca_hw_init(dev, &device->dev))) 1563 goto out_free; 1564 1565 return 0; 1566 1567 out_free: 1568 free_netdev (dev); 1569 release_region (ioaddr, DEPCA_TOTAL_SIZE); 1570 out: 1571 return status; 1572} 1573 1574/* 1575** EISA callbacks from sysfs. 1576*/ 1577 1578#ifdef CONFIG_EISA 1579static int __init depca_eisa_probe (struct device *device) 1580{ 1581 struct eisa_device *edev; 1582 struct net_device *dev; 1583 struct depca_private *lp; 1584 u_long ioaddr, mem_start; 1585 int status = 0; 1586 1587 edev = to_eisa_device (device); 1588 ioaddr = edev->base_addr + DEPCA_EISA_IO_PORTS; 1589 1590 if ((status = depca_common_init (ioaddr, &dev))) 1591 goto out; 1592 1593 /* It would have been nice to get card configuration from the 1594 * card. Unfortunately, this register is write-only (shares 1595 * it's address with the ethernet prom)... As we don't parse 1596 * the EISA configuration structures (yet... :-), just rely on 1597 * the ISA probing to sort it out... */ 1598 1599 depca_shmem_probe (&mem_start); 1600 1601 dev->base_addr = ioaddr; 1602 dev->irq = irq; 1603 lp = dev->priv; 1604 lp->depca_bus = DEPCA_BUS_EISA; 1605 lp->adapter = edev->id.driver_data; 1606 lp->mem_start = mem_start; 1607 1608 if ((status = depca_hw_init(dev, device))) 1609 goto out_free; 1610 1611 return 0; 1612 1613 out_free: 1614 free_netdev (dev); 1615 release_region (ioaddr, DEPCA_TOTAL_SIZE); 1616 out: 1617 return status; 1618} 1619#endif 1620 1621static int __devexit depca_device_remove (struct device *device) 1622{ 1623 struct net_device *dev; 1624 struct depca_private *lp; 1625 int bus; 1626 1627 dev = device->driver_data; 1628 lp = dev->priv; 1629 1630 unregister_netdev (dev); 1631 iounmap (lp->sh_mem); 1632 release_mem_region (lp->mem_start, lp->mem_len); 1633 release_region (dev->base_addr, DEPCA_TOTAL_SIZE); 1634 bus = lp->depca_bus; 1635 free_netdev (dev); 1636 1637 return 0; 1638} 1639 1640/* 1641** Look for a particular board name in the on-board Remote Diagnostics 1642** and Boot (readb) ROM. This will also give us a clue to the network RAM 1643** base address. 1644*/ 1645static int __init DepcaSignature(char *name, u_long base_addr) 1646{ 1647 u_int i, j, k; 1648 void __iomem *ptr; 1649 char tmpstr[16]; 1650 u_long prom_addr = base_addr + 0xc000; 1651 u_long mem_addr = base_addr + 0x8000; /* 32KB */ 1652 1653 /* Can't reserve the prom region, it is already marked as 1654 * used, at least on x86. Instead, reserve a memory region a 1655 * board would certainly use. If it works, go ahead. If not, 1656 * run like hell... */ 1657 1658 if (!request_mem_region (mem_addr, 16, depca_string)) 1659 return unknown; 1660 1661 /* Copy the first 16 bytes of ROM */ 1662 1663 ptr = ioremap(prom_addr, 16); 1664 if (ptr == NULL) { 1665 printk(KERN_ERR "depca: I/O remap failed at %lx\n", prom_addr); 1666 return unknown; 1667 } 1668 for (i = 0; i < 16; i++) { 1669 tmpstr[i] = readb(ptr + i); 1670 } 1671 iounmap(ptr); 1672 1673 release_mem_region (mem_addr, 16); 1674 1675 /* Check if PROM contains a valid string */ 1676 for (i = 0; *depca_signature[i] != '\0'; i++) { 1677 for (j = 0, k = 0; j < 16 && k < strlen(depca_signature[i]); j++) { 1678 if (depca_signature[i][k] == tmpstr[j]) { /* track signature */ 1679 k++; 1680 } else { /* lost signature; begin search again */ 1681 k = 0; 1682 } 1683 } 1684 if (k == strlen(depca_signature[i])) 1685 break; 1686 } 1687 1688 /* Check if name string is valid, provided there's no PROM */ 1689 if (name && *name && (i == unknown)) { 1690 for (i = 0; *depca_signature[i] != '\0'; i++) { 1691 if (strcmp(name, depca_signature[i]) == 0) 1692 break; 1693 } 1694 } 1695 1696 return i; 1697} 1698 1699/* 1700** Look for a special sequence in the Ethernet station address PROM that 1701** is common across all DEPCA products. Note that the original DEPCA needs 1702** its ROM address counter to be initialized and enabled. Only enable 1703** if the first address octet is a 0x08 - this minimises the chances of 1704** messing around with some other hardware, but it assumes that this DEPCA 1705** card initialized itself correctly. 1706** 1707** Search the Ethernet address ROM for the signature. Since the ROM address 1708** counter can start at an arbitrary point, the search must include the entire 1709** probe sequence length plus the (length_of_the_signature - 1). 1710** Stop the search IMMEDIATELY after the signature is found so that the 1711** PROM address counter is correctly positioned at the start of the 1712** ethernet address for later read out. 1713*/ 1714static int __init DevicePresent(u_long ioaddr) 1715{ 1716 union { 1717 struct { 1718 u32 a; 1719 u32 b; 1720 } llsig; 1721 char Sig[sizeof(u32) << 1]; 1722 } 1723 dev; 1724 short sigLength = 0; 1725 s8 data; 1726 s16 nicsr; 1727 int i, j, status = 0; 1728 1729 data = inb(DEPCA_PROM); /* clear counter on DEPCA */ 1730 data = inb(DEPCA_PROM); /* read data */ 1731 1732 if (data == 0x08) { /* Enable counter on DEPCA */ 1733 nicsr = inb(DEPCA_NICSR); 1734 nicsr |= AAC; 1735 outb(nicsr, DEPCA_NICSR); 1736 } 1737 1738 dev.llsig.a = ETH_PROM_SIG; 1739 dev.llsig.b = ETH_PROM_SIG; 1740 sigLength = sizeof(u32) << 1; 1741 1742 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) { 1743 data = inb(DEPCA_PROM); 1744 if (dev.Sig[j] == data) { /* track signature */ 1745 j++; 1746 } else { /* lost signature; begin search again */ 1747 if (data == dev.Sig[0]) { /* rare case.... */ 1748 j = 1; 1749 } else { 1750 j = 0; 1751 } 1752 } 1753 } 1754 1755 if (j != sigLength) { 1756 status = -ENODEV; /* search failed */ 1757 } 1758 1759 return status; 1760} 1761 1762/* 1763** The DE100 and DE101 PROM accesses were made non-standard for some bizarre 1764** reason: access the upper half of the PROM with x=0; access the lower half 1765** with x=1. 1766*/ 1767static int __init get_hw_addr(struct net_device *dev) 1768{ 1769 u_long ioaddr = dev->base_addr; 1770 struct depca_private *lp = dev->priv; 1771 int i, k, tmp, status = 0; 1772 u_short j, x, chksum; 1773 1774 x = (((lp->adapter == de100) || (lp->adapter == de101)) ? 1 : 0); 1775 1776 for (i = 0, k = 0, j = 0; j < 3; j++) { 1777 k <<= 1; 1778 if (k > 0xffff) 1779 k -= 0xffff; 1780 1781 k += (u_char) (tmp = inb(DEPCA_PROM + x)); 1782 dev->dev_addr[i++] = (u_char) tmp; 1783 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8); 1784 dev->dev_addr[i++] = (u_char) tmp; 1785 1786 if (k > 0xffff) 1787 k -= 0xffff; 1788 } 1789 if (k == 0xffff) 1790 k = 0; 1791 1792 chksum = (u_char) inb(DEPCA_PROM + x); 1793 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8); 1794 if (k != chksum) 1795 status = -1; 1796 1797 return status; 1798} 1799 1800/* 1801** Load a packet into the shared memory 1802*/ 1803static int load_packet(struct net_device *dev, struct sk_buff *skb) 1804{ 1805 struct depca_private *lp = (struct depca_private *) dev->priv; 1806 int i, entry, end, len, status = 0; 1807 1808 entry = lp->tx_new; /* Ring around buffer number. */ 1809 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask; 1810 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) { /* Enough room? */ 1811 /* 1812 ** Caution: the write order is important here... don't set up the 1813 ** ownership rights until all the other information is in place. 1814 */ 1815 if (end < entry) { /* wrapped buffer */ 1816 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ; 1817 memcpy_toio(lp->tx_buff[entry], skb->data, len); 1818 memcpy_toio(lp->tx_buff[0], skb->data + len, skb->len - len); 1819 } else { /* linear buffer */ 1820 memcpy_toio(lp->tx_buff[entry], skb->data, skb->len); 1821 } 1822 1823 /* set up the buffer descriptors */ 1824 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len; 1825 for (i = entry; i != end; i = (i+1) & lp->txRingMask) { 1826 /* clean out flags */ 1827 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base); 1828 writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */ 1829 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length); /* packet length in buffer */ 1830 len -= TX_BUFF_SZ; 1831 } 1832 /* clean out flags */ 1833 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base); 1834 writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */ 1835 writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */ 1836 1837 /* start of packet */ 1838 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base); 1839 /* end of packet */ 1840 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base); 1841 1842 for (i = end; i != entry; --i) { 1843 /* ownership of packet */ 1844 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base); 1845 if (i == 0) 1846 i = lp->txRingMask + 1; 1847 } 1848 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base); 1849 1850 lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */ 1851 } else { 1852 status = -1; 1853 } 1854 1855 return status; 1856} 1857 1858static void depca_dbg_open(struct net_device *dev) 1859{ 1860 struct depca_private *lp = (struct depca_private *) dev->priv; 1861 u_long ioaddr = dev->base_addr; 1862 struct depca_init *p = &lp->init_block; 1863 int i; 1864 1865 if (depca_debug > 1) { 1866 /* Do not copy the shadow init block into shared memory */ 1867 /* Debugging should not affect normal operation! */ 1868 /* The shadow init block will get copied across during InitRestartDepca */ 1869 printk("%s: depca open with irq %d\n", dev->name, dev->irq); 1870 printk("Descriptor head addresses (CPU):\n"); 1871 printk(" 0x%lx 0x%lx\n", (u_long) lp->rx_ring, (u_long) lp->tx_ring); 1872 printk("Descriptor addresses (CPU):\nRX: "); 1873 for (i = 0; i < lp->rxRingMask; i++) { 1874 if (i < 3) { 1875 printk("%p ", &lp->rx_ring[i].base); 1876 } 1877 } 1878 printk("...%p\n", &lp->rx_ring[i].base); 1879 printk("TX: "); 1880 for (i = 0; i < lp->txRingMask; i++) { 1881 if (i < 3) { 1882 printk("%p ", &lp->tx_ring[i].base); 1883 } 1884 } 1885 printk("...%p\n", &lp->tx_ring[i].base); 1886 printk("\nDescriptor buffers (Device):\nRX: "); 1887 for (i = 0; i < lp->rxRingMask; i++) { 1888 if (i < 3) { 1889 printk("0x%8.8x ", readl(&lp->rx_ring[i].base)); 1890 } 1891 } 1892 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base)); 1893 printk("TX: "); 1894 for (i = 0; i < lp->txRingMask; i++) { 1895 if (i < 3) { 1896 printk("0x%8.8x ", readl(&lp->tx_ring[i].base)); 1897 } 1898 } 1899 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base)); 1900 printk("Initialisation block at 0x%8.8lx(Phys)\n", lp->mem_start); 1901 printk(" mode: 0x%4.4x\n", p->mode); 1902 printk(" physical address: "); 1903 for (i = 0; i < ETH_ALEN - 1; i++) { 1904 printk("%2.2x:", p->phys_addr[i]); 1905 } 1906 printk("%2.2x\n", p->phys_addr[i]); 1907 printk(" multicast hash table: "); 1908 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) { 1909 printk("%2.2x:", p->mcast_table[i]); 1910 } 1911 printk("%2.2x\n", p->mcast_table[i]); 1912 printk(" rx_ring at: 0x%8.8x\n", p->rx_ring); 1913 printk(" tx_ring at: 0x%8.8x\n", p->tx_ring); 1914 printk("buffers (Phys): 0x%8.8lx\n", lp->mem_start + lp->buffs_offset); 1915 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen); 1916 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen); 1917 outw(CSR2, DEPCA_ADDR); 1918 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA)); 1919 outw(CSR1, DEPCA_ADDR); 1920 printk("%4.4x\n", inw(DEPCA_DATA)); 1921 outw(CSR3, DEPCA_ADDR); 1922 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA)); 1923 } 1924 1925 return; 1926} 1927 1928/* 1929** Perform IOCTL call functions here. Some are privileged operations and the 1930** effective uid is checked in those cases. 1931** All multicast IOCTLs will not work here and are for testing purposes only. 1932*/ 1933static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1934{ 1935 struct depca_private *lp = (struct depca_private *) dev->priv; 1936 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_ifru; 1937 int i, status = 0; 1938 u_long ioaddr = dev->base_addr; 1939 union { 1940 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)]; 1941 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1]; 1942 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2]; 1943 } tmp; 1944 unsigned long flags; 1945 void *buf; 1946 1947 switch (ioc->cmd) { 1948 case DEPCA_GET_HWADDR: /* Get the hardware address */ 1949 for (i = 0; i < ETH_ALEN; i++) { 1950 tmp.addr[i] = dev->dev_addr[i]; 1951 } 1952 ioc->len = ETH_ALEN; 1953 if (copy_to_user(ioc->data, tmp.addr, ioc->len)) 1954 return -EFAULT; 1955 break; 1956 1957 case DEPCA_SET_HWADDR: /* Set the hardware address */ 1958 if (!capable(CAP_NET_ADMIN)) 1959 return -EPERM; 1960 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN)) 1961 return -EFAULT; 1962 for (i = 0; i < ETH_ALEN; i++) { 1963 dev->dev_addr[i] = tmp.addr[i]; 1964 } 1965 netif_stop_queue(dev); 1966 while (lp->tx_old != lp->tx_new) 1967 cpu_relax(); /* Wait for the ring to empty */ 1968 1969 STOP_DEPCA; /* Temporarily stop the depca. */ 1970 depca_init_ring(dev); /* Initialize the descriptor rings */ 1971 LoadCSRs(dev); /* Reload CSR3 */ 1972 InitRestartDepca(dev); /* Resume normal operation. */ 1973 netif_start_queue(dev); /* Unlock the TX ring */ 1974 break; 1975 1976 case DEPCA_SET_PROM: /* Set Promiscuous Mode */ 1977 if (!capable(CAP_NET_ADMIN)) 1978 return -EPERM; 1979 netif_stop_queue(dev); 1980 while (lp->tx_old != lp->tx_new) 1981 cpu_relax(); /* Wait for the ring to empty */ 1982 1983 STOP_DEPCA; /* Temporarily stop the depca. */ 1984 depca_init_ring(dev); /* Initialize the descriptor rings */ 1985 lp->init_block.mode |= PROM; /* Set promiscuous mode */ 1986 1987 LoadCSRs(dev); /* Reload CSR3 */ 1988 InitRestartDepca(dev); /* Resume normal operation. */ 1989 netif_start_queue(dev); /* Unlock the TX ring */ 1990 break; 1991 1992 case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */ 1993 if (!capable(CAP_NET_ADMIN)) 1994 return -EPERM; 1995 netif_stop_queue(dev); 1996 while (lp->tx_old != lp->tx_new) 1997 cpu_relax(); /* Wait for the ring to empty */ 1998 1999 STOP_DEPCA; /* Temporarily stop the depca. */ 2000 depca_init_ring(dev); /* Initialize the descriptor rings */ 2001 lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */ 2002 2003 LoadCSRs(dev); /* Reload CSR3 */ 2004 InitRestartDepca(dev); /* Resume normal operation. */ 2005 netif_start_queue(dev); /* Unlock the TX ring */ 2006 break; 2007 2008 case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */ 2009 if(!capable(CAP_NET_ADMIN)) 2010 return -EPERM; 2011 printk("%s: Boo!\n", dev->name); 2012 break; 2013 2014 case DEPCA_GET_MCA: /* Get the multicast address table */ 2015 ioc->len = (HASH_TABLE_LEN >> 3); 2016 if (copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len)) 2017 return -EFAULT; 2018 break; 2019 2020 case DEPCA_SET_MCA: /* Set a multicast address */ 2021 if (!capable(CAP_NET_ADMIN)) 2022 return -EPERM; 2023 if (ioc->len >= HASH_TABLE_LEN) 2024 return -EINVAL; 2025 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len)) 2026 return -EFAULT; 2027 set_multicast_list(dev); 2028 break; 2029 2030 case DEPCA_CLR_MCA: /* Clear all multicast addresses */ 2031 if (!capable(CAP_NET_ADMIN)) 2032 return -EPERM; 2033 set_multicast_list(dev); 2034 break; 2035 2036 case DEPCA_MCA_EN: /* Enable pass all multicast addressing */ 2037 if (!capable(CAP_NET_ADMIN)) 2038 return -EPERM; 2039 set_multicast_list(dev); 2040 break; 2041 2042 case DEPCA_GET_STATS: /* Get the driver statistics */ 2043 ioc->len = sizeof(lp->pktStats); 2044 buf = kmalloc(ioc->len, GFP_KERNEL); 2045 if(!buf) 2046 return -ENOMEM; 2047 spin_lock_irqsave(&lp->lock, flags); 2048 memcpy(buf, &lp->pktStats, ioc->len); 2049 spin_unlock_irqrestore(&lp->lock, flags); 2050 if (copy_to_user(ioc->data, buf, ioc->len)) 2051 status = -EFAULT; 2052 kfree(buf); 2053 break; 2054 2055 case DEPCA_CLR_STATS: /* Zero out the driver statistics */ 2056 if (!capable(CAP_NET_ADMIN)) 2057 return -EPERM; 2058 spin_lock_irqsave(&lp->lock, flags); 2059 memset(&lp->pktStats, 0, sizeof(lp->pktStats)); 2060 spin_unlock_irqrestore(&lp->lock, flags); 2061 break; 2062 2063 case DEPCA_GET_REG: /* Get the DEPCA Registers */ 2064 i = 0; 2065 tmp.sval[i++] = inw(DEPCA_NICSR); 2066 outw(CSR0, DEPCA_ADDR); /* status register */ 2067 tmp.sval[i++] = inw(DEPCA_DATA); 2068 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init)); 2069 ioc->len = i + sizeof(struct depca_init); 2070 if (copy_to_user(ioc->data, tmp.addr, ioc->len)) 2071 return -EFAULT; 2072 break; 2073 2074 default: 2075 return -EOPNOTSUPP; 2076 } 2077 2078 return status; 2079} 2080 2081static int __init depca_module_init (void) 2082{ 2083 int err = 0; 2084 2085#ifdef CONFIG_MCA 2086 err = mca_register_driver (&depca_mca_driver); 2087#endif 2088#ifdef CONFIG_EISA 2089 err |= eisa_driver_register (&depca_eisa_driver); 2090#endif 2091 err |= platform_driver_register (&depca_isa_driver); 2092 depca_platform_probe (); 2093 2094 return err; 2095} 2096 2097static void __exit depca_module_exit (void) 2098{ 2099 int i; 2100#ifdef CONFIG_MCA 2101 mca_unregister_driver (&depca_mca_driver); 2102#endif 2103#ifdef CONFIG_EISA 2104 eisa_driver_unregister (&depca_eisa_driver); 2105#endif 2106 platform_driver_unregister (&depca_isa_driver); 2107 2108 for (i = 0; depca_io_ports[i].iobase; i++) { 2109 if (depca_io_ports[i].device) { 2110 depca_io_ports[i].device->dev.platform_data = NULL; 2111 platform_device_unregister (depca_io_ports[i].device); 2112 depca_io_ports[i].device = NULL; 2113 } 2114 } 2115} 2116 2117module_init (depca_module_init); 2118module_exit (depca_module_exit);