1 /*- 2 * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland 3 * 4 * This software may be used and distributed according to the terms 5 * of the GNU Public License, incorporated herein by reference. 6 * 7 * Module : sk_g16.c 8 * 9 * Version : $Revision: 1.1 $ 10 * 11 * Author : Patrick J.D. Weichmann 12 * 13 * Date Created : 94/05/26 14 * Last Updated : $Date: 1994/06/30 16:25:15 $ 15 * 16 * Description : Schneider & Koch G16 Ethernet Device Driver for 17 * Linux Kernel >= 1.1.22 18 * Update History : 19 * 20 -*/ 21 22 static const char *rcsid = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $"; 23 24 /* 25 * The Schneider & Koch (SK) G16 Network device driver is based 26 * on the 'ni6510' driver from Michael Hipp which can be found at 27 * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz 28 * 29 * Sources: 1) ni6510.c by M. Hipp 30 * 2) depca.c by D.C. Davies 31 * 3) skeleton.c by D. Becker 32 * 4) Am7990 Local Area Network Controller for Ethernet (LANCE), 33 * AMD, Pub. #05698, June 1989 34 * 35 * Many Thanks for helping me to get things working to: 36 * 37 * A. Cox (A.Cox@swansea.ac.uk) 38 * M. Hipp (mhipp@student.uni-tuebingen.de) 39 * R. Bolz (Schneider & Koch, Germany) 40 * 41 * See README.sk_g16 for details about limitations and bugs for the 42 * current version. 43 * 44 * To Do: 45 * - Support of SK_G8 and other SK Network Cards. 46 * - Autoset memory mapped RAM. Check for free memory and then 47 * configure RAM correctly. 48 * - SK_close should really set card in to initial state. 49 * - Test if IRQ 3 is not switched off. Use autoirq() functionality. 50 * (as in /drivers/net/skeleton.c) 51 * - Implement Multicast addressing. At minimum something like 52 * in depca.c. 53 * - Redo the statistics part. 54 * - Try to find out if the board is in 8 Bit or 16 Bit slot. 55 * If in 8 Bit mode don't use IRQ 11. 56 * - (Try to make it slightly faster.) 57 */ 58 59 #include <linux/kernel.h> 60 #include <linux/sched.h> 61 #include <linux/ptrace.h> 62 #include <linux/fcntl.h> 63 #include <linux/ioport.h> 64 #include <linux/interrupt.h> 65 #include <linux/malloc.h> 66 #include <linux/string.h> 67 #include <asm/system.h> 68 #include <asm/io.h> 69 #include <asm/bitops.h> 70 #include <linux/errno.h> 71 72 #include <linux/netdevice.h> 73 #include <linux/etherdevice.h> 74 #include <linux/skbuff.h> 75 76 #include "sk_g16.h" 77 78 /* 79 * Schneider & Koch Card Definitions 80 * ================================= 81 */ 82 83 #define SK_NAME "SK_G16" 84 85 /* 86 * SK_G16 Configuration 87 * -------------------- 88 */ 89 90 /* 91 * Abbreviations 92 * ------------- 93 * 94 * RAM - used for the 16KB shared memory 95 * Boot_ROM, ROM - are used for referencing the BootEPROM 96 * 97 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure 98 * the behaviour of the driver and the SK_G16. 99 * 100 * ! See sk_g16.install on how to install and configure the driver ! 101 * 102 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not. 103 * 104 * SK_ADDR defines the address where the RAM will be mapped into the real 105 * host memory. 106 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps. 107 */ 108 109 #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */ 110 111 #define SK_ADDR 0xcc000 112 113 /* 114 * In POS3 are bits A14-A19 of the address bus. These bits can be set 115 * to choose the RAM address. Thats why we only can choose the RAM address 116 * in 16KB steps. 117 */ 118 119 #define POS_ADDR (rom_addr>>14) /* Do not change this line */ 120 121 /* 122 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations 123 * ---------------------------------------------- 124 */ 125 126 /* 127 * As nearly every card has also SK_G16 a specified I/O Port region and 128 * only a few possible IRQ's. 129 * In the Installation Guide from Schneider & Koch is listed a possible 130 * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt 131 * controllers. So we use in SK_IRQS IRQ9. 132 */ 133 134 /* Don't touch any of the following #defines. */ 135 136 #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 } 137 138 #define SK_IRQS { 3, 5, 9, 11, 0 } 139 140 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 } 141 142 #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 } 143 144 /* 145 * SK_G16 POS REGISTERS 146 * -------------------- 147 */ 148 149 /* 150 * SK_G16 has a Programmable Option Select (POS) Register. 151 * The POS is composed of 8 separate registers (POS0-7) which 152 * are I/O mapped on an address set by the W1 switch. 153 * 154 */ 155 156 #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */ 157 158 #define SK_POS0 ioaddr /* Card-ID Low (R) */ 159 #define SK_POS1 ioaddr+1 /* Card-ID High (R) */ 160 #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */ 161 #define SK_POS3 ioaddr+3 /* Base address of RAM */ 162 #define SK_POS4 ioaddr+4 /* IRQ */ 163 164 /* POS5 - POS7 are unused */ 165 166 /* 167 * SK_G16 MAC PREFIX 168 * ----------------- 169 */ 170 171 /* 172 * Scheider & Koch manufacturer code (00:00:a5). 173 * This must be checked, that we are sure it is a SK card. 174 */ 175 176 #define SK_MAC0 0x00 177 #define SK_MAC1 0x00 178 #define SK_MAC2 0x5a 179 180 /* 181 * SK_G16 ID 182 * --------- 183 */ 184 185 /* 186 * If POS0,POS1 contain the following ID, then we know 187 * at which I/O Port Address we are. 188 */ 189 190 #define SK_IDLOW 0xfd 191 #define SK_IDHIGH 0x6a 192 193 194 /* 195 * LANCE POS Bit definitions 196 * ------------------------- 197 */ 198 199 #define SK_ROM_RAM_ON (POS2_CARD) 200 #define SK_ROM_RAM_OFF (POS2_EPROM) 201 #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD) 202 #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM) 203 #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD) 204 #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM) 205 206 #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */ 207 #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */ 208 209 /* 210 * SK_G16 Memory mapped Registers 211 * ------------------------------ 212 * 213 */ 214 215 #define SK_IOREG (board->ioreg) /* LANCE data registers. */ 216 #define SK_PORT (board->port) /* Control, Status register */ 217 #define SK_IOCOM (board->iocom) /* I/O Command */ 218 219 /* 220 * SK_G16 Status/Control Register bits 221 * ----------------------------------- 222 * 223 * (C) Controlreg (S) Statusreg 224 */ 225 226 /* 227 * Register transfer: 0 = no transfer 228 * 1 = transferring data between LANCE and I/O reg 229 */ 230 #define SK_IORUN 0x20 231 232 /* 233 * LANCE interrupt: 0 = LANCE interrupt occurred 234 * 1 = no LANCE interrupt occurred 235 */ 236 #define SK_IRQ 0x10 237 238 #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */ 239 #define SK_RW 0x02 /* 0 = write to 1 = read from */ 240 #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */ 241 242 243 #define SK_RREG SK_RW /* Transferdirection to read from lance */ 244 #define SK_WREG 0 /* Transferdirection to write to lance */ 245 #define SK_RAP SK_ADR /* Destination Register RAP */ 246 #define SK_RDATA 0 /* Destination Register REG DataPort */ 247 248 /* 249 * SK_G16 I/O Command 250 * ------------------ 251 */ 252 253 /* 254 * Any bitcombination sets the internal I/O bit (transfer will start) 255 * when written to I/O Command 256 */ 257 258 #define SK_DOIO 0x80 /* Do Transfer */ 259 260 /* 261 * LANCE RAP (Register Address Port). 262 * --------------------------------- 263 */ 264 265 /* 266 * The LANCE internal registers are selected through the RAP. 267 * The Registers are: 268 * 269 * CSR0 - Status and Control flags 270 * CSR1 - Low order bits of initialize block (bits 15:00) 271 * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved) 272 * CSR3 - Allows redefinition of the Bus Master Interface. 273 * This register must be set to 0x0002, which means BSWAP = 0, 274 * ACON = 1, BCON = 0; 275 * 276 */ 277 278 #define CSR0 0x00 279 #define CSR1 0x01 280 #define CSR2 0x02 281 #define CSR3 0x03 282 283 /* 284 * General Definitions 285 * =================== 286 */ 287 288 /* 289 * Set the number of Tx and Rx buffers, using Log_2(# buffers). 290 * We have 16KB RAM which can be accessed by the LANCE. In the 291 * memory are not only the buffers but also the ring descriptors and 292 * the initialize block. 293 * Don't change anything unless you really know what you do. 294 */ 295 296 #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */ 297 #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */ 298 299 /* Descriptor ring sizes */ 300 301 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */ 302 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */ 303 304 /* Define Mask for setting RMD, TMD length in the LANCE init_block */ 305 306 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29) 307 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29) 308 309 /* 310 * Data Buffer size is set to maximum packet length. 311 */ 312 313 #define PKT_BUF_SZ 1518 314 315 /* 316 * The number of low I/O ports used by the ethercard. 317 */ 318 319 #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE 320 321 /* 322 * Portreserve is there to mark the Card I/O Port region as used. 323 * Check_region is to check if the region at ioaddr with the size "size" 324 * is free or not. 325 * Snarf_region allocates the I/O Port region. 326 */ 327 328 #ifndef HAVE_PORTRESERVE 329 330 #define check_region(ioaddr, size) 0 331 #define request_region(ioaddr, size,name) do ; while (0) 332 333 #endif 334 335 /* 336 * SK_DEBUG 337 * 338 * Here you can choose what level of debugging wanted. 339 * 340 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the 341 * necessary messages will be printed. 342 * 343 * If SK_DEBUG is defined, there will be many debugging prints 344 * which can help to find some mistakes in configuration or even 345 * in the driver code. 346 * 347 * If SK_DEBUG2 is defined, many many messages will be printed 348 * which normally you don't need. I used this to check the interrupt 349 * routine. 350 * 351 * (If you define only SK_DEBUG2 then only the messages for 352 * checking interrupts will be printed!) 353 * 354 * Normal way of live is: 355 * 356 * For the whole thing get going let both symbolic constants 357 * undefined. If you face any problems and you know what's going 358 * on (you know something about the card and you can interpret some 359 * hex LANCE register output) then define SK_DEBUG 360 * 361 */ 362 363 #undef SK_DEBUG /* debugging */ 364 #undef SK_DEBUG2 /* debugging with more verbose report */ 365 366 #ifdef SK_DEBUG 367 #define PRINTK(x) printk x 368 #else 369 #define PRINTK(x) /**/ 370 #endif 371 372 #ifdef SK_DEBUG2 373 #define PRINTK2(x) printk x 374 #else 375 #define PRINTK2(x) /**/ 376 #endif 377 378 /* 379 * SK_G16 RAM 380 * 381 * The components are memory mapped and can be set in a region from 382 * 0x00000 through 0xfc000 in 16KB steps. 383 * 384 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-, 385 * Controlregister and I/O Command. 386 * 387 * dual ported RAM: This is the only memory region which the LANCE chip 388 * has access to. From the Lance it is addressed from 0x0000 to 389 * 0x3fbf. The host accesses it normally. 390 * 391 * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a 392 * 8-Bit PROM, this means only the 16 even addresses are used of the 393 * 32 Byte Address region. Access to a odd address results in invalid 394 * data. 395 * 396 * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write, 397 * Hi-Byte Write, Low-Byte Read, Hi-Byte Read. 398 * Transfer from or to the LANCE is always in 16Bit so Low and High 399 * registers are always relevant. 400 * 401 * The Data from the Readregister is not the data in the Writeregister!! 402 * 403 * Port: Status- and Controlregister. 404 * Two different registers which share the same address, Status is 405 * read-only, Control is write-only. 406 * 407 * I/O Command: 408 * Any bitcombination written in here starts the transmission between 409 * Host and LANCE. 410 */ 411 412 typedef struct 413 { 414 unsigned char ram[0x3fc0]; /* 16KB dual ported ram */ 415 unsigned char rom[0x0020]; /* 32Byte PROM containing 6Byte MAC */ 416 unsigned char res1[0x0010]; /* reserved */ 417 unsigned volatile short ioreg;/* LANCE I/O Register */ 418 unsigned volatile char port; /* Statusregister and Controlregister */ 419 unsigned char iocom; /* I/O Command Register */ 420 } SK_RAM; 421 422 /* struct */ 423 424 /* 425 * This is the structure for the dual ported ram. We 426 * have exactly 16 320 Bytes. In here there must be: 427 * 428 * - Initialize Block (starting at a word boundary) 429 * - Receive and Transmit Descriptor Rings (quadword boundary) 430 * - Data Buffers (arbitrary boundary) 431 * 432 * This is because LANCE has on SK_G16 only access to the dual ported 433 * RAM and nowhere else. 434 */ 435 436 struct SK_ram 437 { 438 struct init_block ib; 439 struct tmd tmde[TMDNUM]; 440 struct rmd rmde[RMDNUM]; 441 char tmdbuf[TMDNUM][PKT_BUF_SZ]; 442 char rmdbuf[RMDNUM][PKT_BUF_SZ]; 443 }; 444 445 /* 446 * Structure where all necessary information is for ring buffer 447 * management and statistics. 448 */ 449 450 struct priv 451 { 452 struct SK_ram *ram; /* dual ported ram structure */ 453 struct rmd *rmdhead; /* start of receive ring descriptors */ 454 struct tmd *tmdhead; /* start of transmit ring descriptors */ 455 int rmdnum; /* actual used ring descriptor */ 456 int tmdnum; /* actual transmit descriptor for transmitting data */ 457 int tmdlast; /* last sent descriptor used for error handling, etc */ 458 void *rmdbufs[RMDNUM]; /* pointer to the receive buffers */ 459 void *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */ 460 struct enet_statistics stats; /* Device driver statistics */ 461 }; 462 463 /* global variable declaration */ 464 465 /* IRQ map used to reserve a IRQ (see SK_open()) */ 466 467 /* extern void *irq2dev_map[16]; */ /* Declared in <linux/ioport.h> */ 468 469 /* static variables */ 470 471 static SK_RAM *board; /* pointer to our memory mapped board components */ 472 473 /* Macros */ 474 475 476 /* Function Prototypes */ 477 478 /* 479 * Device Driver functions 480 * ----------------------- 481 * See for short explanation of each function its definitions header. 482 */ 483 484 int SK_init(struct device *dev); 485 static int SK_probe(struct device *dev, short ioaddr); 486 487 static int SK_open(struct device *dev); 488 static int SK_send_packet(struct sk_buff *skb, struct device *dev); 489 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs); 490 static void SK_rxintr(struct device *dev); 491 static void SK_txintr(struct device *dev); 492 static int SK_close(struct device *dev); 493 494 static struct enet_statistics *SK_get_stats(struct device *dev); 495 496 unsigned int SK_rom_addr(void); 497 498 static void set_multicast_list(struct device *dev); 499 500 /* 501 * LANCE Functions 502 * --------------- 503 */ 504 505 static int SK_lance_init(struct device *dev, unsigned short mode); 506 void SK_reset_board(void); 507 void SK_set_RAP(int reg_number); 508 int SK_read_reg(int reg_number); 509 int SK_rread_reg(void); 510 void SK_write_reg(int reg_number, int value); 511 512 /* 513 * Debugging functions 514 * ------------------- 515 */ 516 517 void SK_print_pos(struct device *dev, char *text); 518 void SK_print_dev(struct device *dev, char *text); 519 void SK_print_ram(struct device *dev); 520 521 522 /*- 523 * Function : SK_init 524 * Author : Patrick J.D. Weichmann 525 * Date Created : 94/05/26 526 * 527 * Description : Check for a SK_G16 network adaptor and initialize it. 528 * This function gets called by dev_init which initializes 529 * all Network devices. 530 * 531 * Parameters : I : struct device *dev - structure preconfigured 532 * from Space.c 533 * Return Value : 0 = Driver Found and initialized 534 * Errors : ENODEV - no device found 535 * ENXIO - not probed 536 * Globals : None 537 * Update History : 538 * YY/MM/DD uid Description 539 -*/ 540 541 /* 542 * Check for a network adaptor of this type, and return '0' if one exists. 543 * If dev->base_addr == 0, probe all likely locations. 544 * If dev->base_addr == 1, always return failure. 545 * If dev->base_addr == 2, allocate space for the device and return success 546 * (detachable devices only). 547 */ 548 549 int SK_init(struct device *dev) /* */ 550 { 551 int ioaddr = 0; /* I/O port address used for POS regs */ 552 int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */ 553 554 /* get preconfigured base_addr from dev which is done in Space.c */ 555 int base_addr = dev->base_addr; 556 557 PRINTK(("%s: %s", SK_NAME, rcsid)); 558 rcsid = NULL; /* We do not want to use this further */ 559 560 if (base_addr > 0x0ff) /* Check a single specified address */ 561 { 562 /* Check if on specified address is a SK_G16 */ 563 564 if ( (inb(SK_POS0) == SK_IDLOW) || 565 (inb(SK_POS1) == SK_IDHIGH) ) 566 { 567 return SK_probe(dev, base_addr); 568 } 569 570 return ENODEV; /* Sorry, but on specified address NO SK_G16 */ 571 } 572 else if (base_addr > 0) /* Don't probe at all */ 573 { 574 return ENXIO; 575 } 576 577 /* Autoprobe base_addr */ 578 579 for (port = &ports[0]; *port; port++) 580 { 581 ioaddr = *port; /* we need ioaddr for accessing POS regs */ 582 583 /* Check if I/O Port region is used by another board */ 584 585 if (check_region(ioaddr, ETHERCARD_TOTAL_SIZE)) 586 { 587 continue; /* Try next Port address */ 588 } 589 590 /* Check if at ioaddr is a SK_G16 */ 591 592 if ( !(inb(SK_POS0) == SK_IDLOW) || 593 !(inb(SK_POS1) == SK_IDHIGH) ) 594 { 595 continue; /* Try next Port address */ 596 } 597 598 dev->base_addr = ioaddr; /* Set I/O Port Address */ 599 600 if (SK_probe(dev, ioaddr) == 0) 601 { 602 return 0; /* Card found and initialized */ 603 } 604 } 605 606 dev->base_addr = base_addr; /* Write back original base_addr */ 607 608 return ENODEV; /* Failed to find or init driver */ 609 610 } /* End of SK_init */ 611 612 613 /*- 614 * Function : SK_probe 615 * Author : Patrick J.D. Weichmann 616 * Date Created : 94/05/26 617 * 618 * Description : This function is called by SK_init and 619 * does the main part of initialization. 620 * 621 * Parameters : I : struct device *dev - SK_G16 device structure 622 * I : short ioaddr - I/O Port address where POS is. 623 * Return Value : 0 = Initialization done 624 * Errors : ENODEV - No SK_G16 found 625 * -1 - Configuration problem 626 * Globals : irq2dev_map - Which device uses which IRQ 627 * : board - pointer to SK_RAM 628 * Update History : 629 * YY/MM/DD uid Description 630 * 94/06/30 pwe SK_ADDR now checked and at the correct place 631 -*/ 632 633 int SK_probe(struct device *dev, short ioaddr) /* */ 634 { 635 int i,j; /* Counters */ 636 int sk_addr_flag = 0; /* SK ADDR correct? 1 - no, 0 - yes */ 637 unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */ 638 639 struct priv *p; /* SK_G16 private structure */ 640 641 if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000) 642 { 643 644 sk_addr_flag = 1; 645 646 /* 647 * Now here we could use a routine which searches for a free 648 * place in the ram and set SK_ADDR if found. TODO. 649 */ 650 } 651 652 if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */ 653 { 654 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME)); 655 656 rom_addr = SK_rom_addr(); 657 658 if (rom_addr == 0) /* No Boot_ROM found */ 659 { 660 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 661 { 662 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 663 dev->name, SK_ADDR); 664 return -1; 665 } 666 667 rom_addr = SK_ADDR; /* assign predefined address */ 668 669 PRINTK(("## %s: NO Bootrom found \n", SK_NAME)); 670 671 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 672 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 673 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 674 } 675 else if (rom_addr == SK_ADDR) 676 { 677 printk("%s: RAM + ROM are set to the same address %#08x\n" 678 " Check configuration. Now switching off Boot_ROM\n", 679 SK_NAME, rom_addr); 680 681 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/ 682 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 683 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 684 } 685 else 686 { 687 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr)); 688 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME)); 689 690 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 691 { 692 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 693 dev->name, SK_ADDR); 694 return -1; 695 } 696 697 rom_addr = SK_ADDR; 698 699 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 700 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 701 outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */ 702 } 703 } 704 else /* Don't keep Boot_ROM */ 705 { 706 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME)); 707 708 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 709 { 710 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 711 dev->name, SK_ADDR); 712 return -1; 713 } 714 715 rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */ 716 717 /* IF we find a Boot_ROM disable it */ 718 719 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 720 721 /* We found a Boot_ROM and it's gone. Set RAM address on 722 * Boot_ROM address. 723 */ 724 725 if (rom_addr) 726 { 727 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on" 728 "that address\n", SK_NAME, rom_addr); 729 730 outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */ 731 } 732 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */ 733 { 734 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 735 { 736 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 737 dev->name, SK_ADDR); 738 return -1; 739 } 740 741 rom_addr = SK_ADDR; 742 743 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 744 } 745 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 746 } 747 748 #ifdef SK_DEBUG 749 SK_print_pos(dev, "POS registers after ROM, RAM config"); 750 #endif 751 752 board = (SK_RAM *) rom_addr; 753 754 /* Read in station address */ 755 for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2) 756 { 757 dev->dev_addr[i] = board->rom[j]; 758 } 759 760 /* Check for manufacturer code */ 761 if (!(dev->dev_addr[0] == SK_MAC0 && 762 dev->dev_addr[1] == SK_MAC1 && 763 dev->dev_addr[2] == SK_MAC2) ) 764 { 765 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n", 766 SK_NAME)); 767 return ENODEV; /* NO SK_G16 found */ 768 } 769 770 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n", 771 dev->name, 772 "Schneider & Koch Netcard", 773 (unsigned int) dev->base_addr, 774 dev->dev_addr[0], 775 dev->dev_addr[1], 776 dev->dev_addr[2], 777 dev->dev_addr[3], 778 dev->dev_addr[4], 779 dev->dev_addr[5]); 780 781 /* Grab the I/O Port region */ 782 request_region(ioaddr, ETHERCARD_TOTAL_SIZE,"sk_g16"); 783 784 /* Initialize device structure */ 785 786 /* Allocate memory for private structure */ 787 p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL); 788 if (p == NULL) 789 return -ENOMEM; 790 memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */ 791 792 /* Assign our Device Driver functions */ 793 794 dev->open = &SK_open; 795 dev->stop = &SK_close; 796 dev->hard_start_xmit = &SK_send_packet; 797 dev->get_stats = &SK_get_stats; 798 dev->set_multicast_list = &set_multicast_list; 799 800 801 /* Set the generic fields of the device structure */ 802 803 ether_setup(dev); 804 805 dev->flags &= ~IFF_MULTICAST; 806 807 /* Initialize private structure */ 808 809 p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */ 810 p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */ 811 p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */ 812 813 /* Initialize buffer pointers */ 814 815 for (i = 0; i < TMDNUM; i++) 816 { 817 p->tmdbufs[i] = &(p->ram)->tmdbuf[i]; 818 } 819 820 for (i = 0; i < RMDNUM; i++) 821 { 822 p->rmdbufs[i] = &(p->ram)->rmdbuf[i]; 823 } 824 825 #ifdef SK_DEBUG 826 SK_print_pos(dev, "End of SK_probe"); 827 SK_print_ram(dev); 828 #endif 829 830 return 0; /* Initialization done */ 831 832 } /* End of SK_probe() */ 833 834 835 /*- 836 * Function : SK_open 837 * Author : Patrick J.D. Weichmann 838 * Date Created : 94/05/26 839 * 840 * Description : This function is called sometimes after booting 841 * when ifconfig program is run. 842 * 843 * This function requests an IRQ, sets the correct 844 * IRQ in the card. Then calls SK_lance_init() to 845 * init and start the LANCE chip. Then if everything is 846 * ok returns with 0 (OK), which means SK_G16 is now 847 * opened and operational. 848 * 849 * (Called by dev_open() /net/inet/dev.c) 850 * 851 * Parameters : I : struct device *dev - SK_G16 device structure 852 * Return Value : 0 - Device opened 853 * Errors : -EAGAIN - Open failed 854 * Globals : irq2dev_map - which device uses which irq 855 * Side Effects : None 856 * Update History : 857 * YY/MM/DD uid Description 858 -*/ 859 860 static int SK_open(struct device *dev) /* */ 861 { 862 int i = 0; 863 int irqval = 0; 864 int ioaddr = dev->base_addr; 865 866 int irqtab[] = SK_IRQS; 867 868 struct priv *p = (struct priv *)dev->priv; 869 870 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n", 871 SK_NAME, SK_read_reg(CSR0))); 872 873 if (dev->irq == 0) /* Autoirq */ 874 { 875 i = 0; 876 877 /* 878 * Check if one IRQ out of SK_IRQS is free and install 879 * interrupt handler. 880 * Most done by request_irq(). 881 * irqval: 0 - interrupt handler installed for IRQ irqtab[i] 882 * -EBUSY - interrupt busy 883 * -EINVAL - irq > 15 or handler = NULL 884 */ 885 886 do 887 { 888 irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", NULL); 889 i++; 890 } while (irqval && irqtab[i]); 891 892 if (irqval) /* We tried every possible IRQ but no success */ 893 { 894 printk("%s: unable to get an IRQ\n", dev->name); 895 return -EAGAIN; 896 } 897 898 dev->irq = irqtab[--i]; 899 900 outb(i<<2, SK_POS4); /* Set Card on probed IRQ */ 901 902 } 903 else if (dev->irq == 2) /* IRQ2 is always IRQ9 */ 904 { 905 if (request_irq(9, &SK_interrupt, 0, "sk_g16", NULL)) 906 { 907 printk("%s: unable to get IRQ 9\n", dev->name); 908 return -EAGAIN; 909 } 910 dev->irq = 9; 911 912 /* 913 * Now we set card on IRQ2. 914 * This can be confusing, but remember that IRQ2 on the network 915 * card is in reality IRQ9 916 */ 917 outb(0x08, SK_POS4); /* set card to IRQ2 */ 918 919 } 920 else /* Check IRQ as defined in Space.c */ 921 { 922 int i = 0; 923 924 /* check if IRQ free and valid. Then install Interrupt handler */ 925 926 if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", NULL)) 927 { 928 printk("%s: unable to get selected IRQ\n", dev->name); 929 return -EAGAIN; 930 } 931 932 switch(dev->irq) 933 { 934 case 3: i = 0; 935 break; 936 case 5: i = 1; 937 break; 938 case 2: i = 2; 939 break; 940 case 11:i = 3; 941 break; 942 default: 943 printk("%s: Preselected IRQ %d is invalid for %s boards", 944 dev->name, 945 dev->irq, 946 SK_NAME); 947 return -EAGAIN; 948 } 949 950 outb(i<<2, SK_POS4); /* Set IRQ on card */ 951 } 952 953 irq2dev_map[dev->irq] = dev; /* Set IRQ as used by us */ 954 955 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n", 956 dev->name, (unsigned int)dev->base_addr, 957 (int) dev->irq, (unsigned int) p->ram); 958 959 if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */ 960 { 961 962 963 dev->tbusy = 0; 964 dev->interrupt = 0; 965 dev->start = 1; 966 967 #ifdef SK_DEBUG 968 969 /* 970 * This debug block tries to stop LANCE, 971 * reinit LANCE with transmitter and receiver disabled, 972 * then stop again and reinit with NORMAL_MODE 973 */ 974 975 printk("## %s: After lance init. CSR0: %#06x\n", 976 SK_NAME, SK_read_reg(CSR0)); 977 SK_write_reg(CSR0, CSR0_STOP); 978 printk("## %s: LANCE stopped. CSR0: %#06x\n", 979 SK_NAME, SK_read_reg(CSR0)); 980 SK_lance_init(dev, MODE_DTX | MODE_DRX); 981 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n", 982 SK_NAME, SK_read_reg(CSR0)); 983 SK_write_reg(CSR0, CSR0_STOP); 984 printk("## %s: LANCE stopped. CSR0: %#06x\n", 985 SK_NAME, SK_read_reg(CSR0)); 986 SK_lance_init(dev, MODE_NORMAL); 987 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n", 988 SK_NAME, SK_read_reg(CSR0)); 989 SK_print_pos(dev, "POS regs before returning OK"); 990 991 #endif /* SK_DEBUG */ 992 993 return 0; /* SK_open() is successful */ 994 } 995 else /* LANCE init failed */ 996 { 997 998 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n", 999 SK_NAME, SK_read_reg(CSR0))); 1000 1001 dev->start = 0; /* Device not ready */ 1002 return -EAGAIN; 1003 } 1004 1005 } /* End of SK_open() */ 1006 1007 1008 /*- 1009 * Function : SK_lance_init 1010 * Author : Patrick J.D. Weichmann 1011 * Date Created : 94/05/26 1012 * 1013 * Description : Reset LANCE chip, fill RMD, TMD structures with 1014 * start values and Start LANCE. 1015 * 1016 * Parameters : I : struct device *dev - SK_G16 device structure 1017 * I : int mode - put LANCE into "mode" see data-sheet for 1018 * more info. 1019 * Return Value : 0 - Init done 1020 * Errors : -1 - Init failed 1021 * Update History : 1022 * YY/MM/DD uid Description 1023 -*/ 1024 1025 static int SK_lance_init(struct device *dev, unsigned short mode) /* */ 1026 { 1027 int i; 1028 struct priv *p = (struct priv *) dev->priv; 1029 struct tmd *tmdp; 1030 struct rmd *rmdp; 1031 1032 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n", 1033 SK_NAME, SK_read_reg(CSR0))); 1034 1035 /* Reset LANCE */ 1036 SK_reset_board(); 1037 1038 /* Initialize TMD's with start values */ 1039 p->tmdnum = 0; /* First descriptor for transmitting */ 1040 p->tmdlast = 0; /* First descriptor for reading stats */ 1041 1042 for (i = 0; i < TMDNUM; i++) /* Init all TMD's */ 1043 { 1044 tmdp = p->tmdhead + i; 1045 1046 tmdp->u.buffer = (unsigned long) p->tmdbufs[i]; /* assign buffer */ 1047 1048 /* Mark TMD as start and end of packet */ 1049 tmdp->u.s.status = TX_STP | TX_ENP; 1050 } 1051 1052 1053 /* Initialize RMD's with start values */ 1054 1055 p->rmdnum = 0; /* First RMD which will be used */ 1056 1057 for (i = 0; i < RMDNUM; i++) /* Init all RMD's */ 1058 { 1059 rmdp = p->rmdhead + i; 1060 1061 1062 rmdp->u.buffer = (unsigned long) p->rmdbufs[i]; /* assign buffer */ 1063 1064 /* 1065 * LANCE must be owner at beginning so that he can fill in 1066 * receiving packets, set status and release RMD 1067 */ 1068 1069 rmdp->u.s.status = RX_OWN; 1070 1071 rmdp->blen = -PKT_BUF_SZ; /* Buffer Size in a two's complement */ 1072 1073 rmdp->mlen = 0; /* init message length */ 1074 1075 } 1076 1077 /* Fill LANCE Initialize Block */ 1078 1079 (p->ram)->ib.mode = mode; /* Set operation mode */ 1080 1081 for (i = 0; i < ETH_ALEN; i++) /* Set physical address */ 1082 { 1083 (p->ram)->ib.paddr[i] = dev->dev_addr[i]; 1084 } 1085 1086 for (i = 0; i < 8; i++) /* Set multicast, logical address */ 1087 { 1088 (p->ram)->ib.laddr[i] = 0; /* We do not use logical addressing */ 1089 } 1090 1091 /* Set ring descriptor pointers and set number of descriptors */ 1092 1093 (p->ram)->ib.rdrp = (int) p->rmdhead | RMDNUMMASK; 1094 (p->ram)->ib.tdrp = (int) p->tmdhead | TMDNUMMASK; 1095 1096 /* Prepare LANCE Control and Status Registers */ 1097 1098 cli(); 1099 1100 SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */ 1101 1102 /* 1103 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to 1104 * PC Memory locations. 1105 * 1106 * In structure SK_ram is defined that the first thing in ram 1107 * is the initialization block. So his address is for LANCE always 1108 * 0x0000 1109 * 1110 * CSR1 contains low order bits 15:0 of initialization block address 1111 * CSR2 is built of: 1112 * 7:0 High order bits 23:16 of initialization block address 1113 * 15:8 reserved, must be 0 1114 */ 1115 1116 /* Set initialization block address (must be on word boundary) */ 1117 SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */ 1118 SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */ 1119 1120 1121 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n", 1122 SK_NAME, SK_read_reg(CSR0))); 1123 1124 /* Initialize LANCE */ 1125 1126 /* 1127 * INIT = Initialize, when set, causes the LANCE to begin the 1128 * initialization procedure and access the Init Block. 1129 */ 1130 1131 SK_write_reg(CSR0, CSR0_INIT); 1132 1133 sti(); 1134 1135 /* Wait until LANCE finished initialization */ 1136 1137 SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */ 1138 1139 for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++) 1140 ; /* Wait until init done or go ahead if problems (i>=100) */ 1141 1142 if (i >= 100) /* Something is wrong ! */ 1143 { 1144 printk("%s: can't init am7990, status: %04x " 1145 "init_block: %#08x\n", 1146 dev->name, (int) SK_read_reg(CSR0), 1147 (unsigned int) &(p->ram)->ib); 1148 1149 #ifdef SK_DEBUG 1150 SK_print_pos(dev, "LANCE INIT failed"); 1151 SK_print_dev(dev,"Device Structure:"); 1152 #endif 1153 1154 return -1; /* LANCE init failed */ 1155 } 1156 1157 PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i)); 1158 1159 /* Clear Initialize done, enable Interrupts, start LANCE */ 1160 1161 SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT); 1162 1163 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME, 1164 SK_read_reg(CSR0))); 1165 1166 return 0; /* LANCE is up and running */ 1167 1168 } /* End of SK_lance_init() */ 1169 1170 1171 1172 /*- 1173 * Function : SK_send_packet 1174 * Author : Patrick J.D. Weichmann 1175 * Date Created : 94/05/27 1176 * 1177 * Description : Writes an socket buffer into a transmit descriptor 1178 * and starts transmission. 1179 * 1180 * Parameters : I : struct sk_buff *skb - packet to transfer 1181 * I : struct device *dev - SK_G16 device structure 1182 * Return Value : 0 - OK 1183 * 1 - Could not transmit (dev_queue_xmit will queue it) 1184 * and try to sent it later 1185 * Globals : None 1186 * Side Effects : None 1187 * Update History : 1188 * YY/MM/DD uid Description 1189 -*/ 1190 1191 static int SK_send_packet(struct sk_buff *skb, struct device *dev) /* */ 1192 { 1193 struct priv *p = (struct priv *) dev->priv; 1194 struct tmd *tmdp; 1195 1196 if (dev->tbusy) 1197 { 1198 /* if Transmitter more than 150ms busy -> time_out */ 1199 1200 int tickssofar = jiffies - dev->trans_start; 1201 if (tickssofar < 15) 1202 { 1203 return 1; /* We have to try transmit later */ 1204 } 1205 1206 printk("%s: xmitter timed out, try to restart!\n", dev->name); 1207 1208 SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */ 1209 1210 dev->tbusy = 0; /* Clear Transmitter flag */ 1211 1212 dev->trans_start = jiffies; /* Mark Start of transmission */ 1213 1214 } 1215 1216 /* 1217 * If some upper Layer thinks we missed a transmit done interrupt 1218 * we are passed NULL. 1219 * (dev_queue_xmit net/inet/dev.c 1220 */ 1221 1222 if (skb == NULL) 1223 { 1224 /* 1225 * Dequeue packets from transmit queue and send them. 1226 */ 1227 dev_tint(dev); 1228 1229 return 0; 1230 } 1231 1232 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n", 1233 SK_NAME, SK_read_reg(CSR0))); 1234 1235 1236 /* 1237 * Block a timer-based transmit from overlapping. 1238 * This means check if we are already in. 1239 */ 1240 1241 if (set_bit(0, (void *) &dev->tbusy) != 0) /* dev->tbusy already set ? */ 1242 { 1243 printk("%s: Transmitter access conflict.\n", dev->name); 1244 } 1245 else 1246 { 1247 /* Evaluate Packet length */ 1248 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 1249 1250 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */ 1251 1252 /* Fill in Transmit Message Descriptor */ 1253 1254 /* Copy data into dual ported ram */ 1255 1256 memcpy((char *) (tmdp->u.buffer & 0x00ffffff), (char *)skb->data, 1257 skb->len); 1258 1259 tmdp->blen = -len; /* set length to transmit */ 1260 1261 /* 1262 * Packet start and end is always set because we use the maximum 1263 * packet length as buffer length. 1264 * Relinquish ownership to LANCE 1265 */ 1266 1267 tmdp->u.s.status = TX_OWN | TX_STP | TX_ENP; 1268 1269 /* Start Demand Transmission */ 1270 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA); 1271 1272 dev->trans_start = jiffies; /* Mark start of transmission */ 1273 1274 /* Set pointer to next transmit buffer */ 1275 p->tmdnum++; 1276 p->tmdnum &= TMDNUM-1; 1277 1278 /* Do we own the next transmit buffer ? */ 1279 if (! ((p->tmdhead + p->tmdnum)->u.s.status & TX_OWN) ) 1280 { 1281 /* 1282 * We own next buffer and are ready to transmit, so 1283 * clear busy flag 1284 */ 1285 dev->tbusy = 0; 1286 } 1287 } 1288 dev_kfree_skb(skb, FREE_WRITE); 1289 return 0; 1290 } /* End of SK_send_packet */ 1291 1292 1293 /*- 1294 * Function : SK_interrupt 1295 * Author : Patrick J.D. Weichmann 1296 * Date Created : 94/05/27 1297 * 1298 * Description : SK_G16 interrupt handler which checks for LANCE 1299 * Errors, handles transmit and receive interrupts 1300 * 1301 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs - 1302 * Return Value : None 1303 * Errors : None 1304 * Globals : None 1305 * Side Effects : None 1306 * Update History : 1307 * YY/MM/DD uid Description 1308 -*/ 1309 1310 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs) /* */ 1311 { 1312 int csr0; 1313 struct device *dev = (struct device *) irq2dev_map[irq]; 1314 struct priv *p = (struct priv *) dev->priv; 1315 1316 1317 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n", 1318 SK_NAME, SK_read_reg(CSR0))); 1319 1320 if (dev == NULL) 1321 { 1322 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq); 1323 } 1324 1325 1326 if (dev->interrupt) 1327 { 1328 printk("%s: Re-entering the interrupt handler.\n", dev->name); 1329 } 1330 1331 csr0 = SK_read_reg(CSR0); /* store register for checking */ 1332 1333 dev->interrupt = 1; /* We are handling an interrupt */ 1334 1335 /* 1336 * Acknowledge all of the current interrupt sources, disable 1337 * Interrupts (INEA = 0) 1338 */ 1339 1340 SK_write_reg(CSR0, csr0 & CSR0_CLRALL); 1341 1342 if (csr0 & CSR0_ERR) /* LANCE Error */ 1343 { 1344 printk("%s: error: %04x\n", dev->name, csr0); 1345 1346 if (csr0 & CSR0_MISS) /* No place to store packet ? */ 1347 { 1348 p->stats.rx_dropped++; 1349 } 1350 } 1351 1352 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */ 1353 { 1354 SK_rxintr(dev); 1355 } 1356 1357 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */ 1358 { 1359 SK_txintr(dev); 1360 } 1361 1362 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */ 1363 1364 dev->interrupt = 0; /* We are out */ 1365 } /* End of SK_interrupt() */ 1366 1367 1368 /*- 1369 * Function : SK_txintr 1370 * Author : Patrick J.D. Weichmann 1371 * Date Created : 94/05/27 1372 * 1373 * Description : After sending a packet we check status, update 1374 * statistics and relinquish ownership of transmit 1375 * descriptor ring. 1376 * 1377 * Parameters : I : struct device *dev - SK_G16 device structure 1378 * Return Value : None 1379 * Errors : None 1380 * Globals : None 1381 * Update History : 1382 * YY/MM/DD uid Description 1383 -*/ 1384 1385 static void SK_txintr(struct device *dev) /* */ 1386 { 1387 int tmdstat; 1388 struct tmd *tmdp; 1389 struct priv *p = (struct priv *) dev->priv; 1390 1391 1392 PRINTK2(("## %s: SK_txintr() status: %#06x\n", 1393 SK_NAME, SK_read_reg(CSR0))); 1394 1395 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */ 1396 1397 /* Set next buffer */ 1398 p->tmdlast++; 1399 p->tmdlast &= TMDNUM-1; 1400 1401 tmdstat = tmdp->u.s.status & 0xff00; /* filter out status bits 15:08 */ 1402 1403 /* 1404 * We check status of transmitted packet. 1405 * see LANCE data-sheet for error explanation 1406 */ 1407 if (tmdstat & TX_ERR) /* Error occurred */ 1408 { 1409 printk("%s: TX error: %04x %04x\n", dev->name, (int) tmdstat, 1410 (int) tmdp->status2); 1411 1412 if (tmdp->status2 & TX_TDR) /* TDR problems? */ 1413 { 1414 printk("%s: tdr-problems \n", dev->name); 1415 } 1416 1417 if (tmdp->status2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */ 1418 p->stats.tx_aborted_errors++; 1419 if (tmdp->status2 & TX_LCOL) /* Late collision ? */ 1420 p->stats.tx_window_errors++; 1421 if (tmdp->status2 & TX_LCAR) /* Loss of Carrier ? */ 1422 p->stats.tx_carrier_errors++; 1423 if (tmdp->status2 & TX_UFLO) /* Underflow error ? */ 1424 { 1425 p->stats.tx_fifo_errors++; 1426 1427 /* 1428 * If UFLO error occurs it will turn transmitter of. 1429 * So we must reinit LANCE 1430 */ 1431 1432 SK_lance_init(dev, MODE_NORMAL); 1433 } 1434 1435 p->stats.tx_errors++; 1436 1437 tmdp->status2 = 0; /* Clear error flags */ 1438 } 1439 else if (tmdstat & TX_MORE) /* Collisions occurred ? */ 1440 { 1441 /* 1442 * Here I have a problem. 1443 * I only know that there must be one or up to 15 collisions. 1444 * Thats why TX_MORE is set, because after 16 attempts TX_RTRY 1445 * will be set which means couldn't send packet aborted transfer. 1446 * 1447 * First I did not have this in but then I thought at minimum 1448 * we see that something was not ok. 1449 * If anyone knows something better than this to handle this 1450 * please report it. (see Email addresses in the README file) 1451 */ 1452 1453 p->stats.collisions++; 1454 } 1455 else /* Packet sent without any problems */ 1456 { 1457 p->stats.tx_packets++; 1458 } 1459 1460 /* 1461 * We mark transmitter not busy anymore, because now we have a free 1462 * transmit descriptor which can be filled by SK_send_packet and 1463 * afterwards sent by the LANCE 1464 */ 1465 1466 dev->tbusy = 0; 1467 1468 /* 1469 * mark_bh(NET_BH); 1470 * This will cause net_bh() to run after this interrupt handler. 1471 * 1472 * The function which do handle slow IRQ parts is do_bottom_half() 1473 * which runs at normal kernel priority, that means all interrupt are 1474 * enabled. (see kernel/irq.c) 1475 * 1476 * net_bh does something like this: 1477 * - check if already in net_bh 1478 * - try to transmit something from the send queue 1479 * - if something is in the receive queue send it up to higher 1480 * levels if it is a known protocol 1481 * - try to transmit something from the send queue 1482 */ 1483 1484 mark_bh(NET_BH); 1485 1486 } /* End of SK_txintr() */ 1487 1488 1489 /*- 1490 * Function : SK_rxintr 1491 * Author : Patrick J.D. Weichmann 1492 * Date Created : 94/05/27 1493 * 1494 * Description : Buffer sent, check for errors, relinquish ownership 1495 * of the receive message descriptor. 1496 * 1497 * Parameters : I : SK_G16 device structure 1498 * Return Value : None 1499 * Globals : None 1500 * Update History : 1501 * YY/MM/DD uid Description 1502 -*/ 1503 1504 static void SK_rxintr(struct device *dev) /* */ 1505 { 1506 1507 struct rmd *rmdp; 1508 int rmdstat; 1509 struct priv *p = (struct priv *) dev->priv; 1510 1511 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n", 1512 SK_NAME, SK_read_reg(CSR0))); 1513 1514 rmdp = p->rmdhead + p->rmdnum; 1515 1516 /* As long as we own the next entry, check status and send 1517 * it up to higher layer 1518 */ 1519 1520 while (!( (rmdstat = rmdp->u.s.status) & RX_OWN)) 1521 { 1522 /* 1523 * Start and end of packet must be set, because we use 1524 * the ethernet maximum packet length (1518) as buffer size. 1525 * 1526 * Because our buffers are at maximum OFLO and BUFF errors are 1527 * not to be concerned (see Data sheet) 1528 */ 1529 1530 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP)) 1531 { 1532 /* Start of a frame > 1518 Bytes ? */ 1533 1534 if (rmdstat & RX_STP) 1535 { 1536 p->stats.rx_errors++; /* bad packet received */ 1537 p->stats.rx_length_errors++; /* packet to long */ 1538 1539 printk("%s: packet too long\n", dev->name); 1540 } 1541 1542 /* 1543 * All other packets will be ignored until a new frame with 1544 * start (RX_STP) set follows. 1545 * 1546 * What we do is just give descriptor free for new incoming 1547 * packets. 1548 */ 1549 1550 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1551 1552 } 1553 else if (rmdstat & RX_ERR) /* Receive Error ? */ 1554 { 1555 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat); 1556 1557 p->stats.rx_errors++; 1558 1559 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++; 1560 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++; 1561 1562 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1563 1564 } 1565 else /* We have a packet which can be queued for the upper layers */ 1566 { 1567 1568 int len = (rmdp->mlen & 0x0fff); /* extract message length from receive buffer */ 1569 struct sk_buff *skb; 1570 1571 skb = dev_alloc_skb(len+2); /* allocate socket buffer */ 1572 1573 if (skb == NULL) /* Could not get mem ? */ 1574 { 1575 1576 /* 1577 * Couldn't allocate sk_buffer so we give descriptor back 1578 * to Lance, update statistics and go ahead. 1579 */ 1580 1581 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1582 printk("%s: Couldn't allocate sk_buff, deferring packet.\n", 1583 dev->name); 1584 p->stats.rx_dropped++; 1585 1586 break; /* Jump out */ 1587 } 1588 1589 /* Prepare sk_buff to queue for upper layers */ 1590 1591 skb->dev = dev; 1592 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */ 1593 1594 /* 1595 * Copy data out of our receive descriptor into sk_buff. 1596 * 1597 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and 1598 * ignore status fields) 1599 */ 1600 1601 memcpy(skb_put(skb,len), (unsigned char *) (rmdp->u.buffer & 0x00ffffff), 1602 len); 1603 1604 1605 /* 1606 * Notify the upper protocol layers that there is another packet 1607 * to handle 1608 * 1609 * netif_rx() always succeeds. see /net/inet/dev.c for more. 1610 */ 1611 1612 skb->protocol=eth_type_trans(skb,dev); 1613 netif_rx(skb); /* queue packet and mark it for processing */ 1614 1615 /* 1616 * Packet is queued and marked for processing so we 1617 * free our descriptor and update statistics 1618 */ 1619 1620 rmdp->u.s.status = RX_OWN; 1621 p->stats.rx_packets++; 1622 1623 1624 p->rmdnum++; 1625 p->rmdnum %= RMDNUM; 1626 1627 rmdp = p->rmdhead + p->rmdnum; 1628 } 1629 } 1630 } /* End of SK_rxintr() */ 1631 1632 1633 /*- 1634 * Function : SK_close 1635 * Author : Patrick J.D. Weichmann 1636 * Date Created : 94/05/26 1637 * 1638 * Description : close gets called from dev_close() and should 1639 * deinstall the card (free_irq, mem etc). 1640 * 1641 * Parameters : I : struct device *dev - our device structure 1642 * Return Value : 0 - closed device driver 1643 * Errors : None 1644 * Globals : None 1645 * Update History : 1646 * YY/MM/DD uid Description 1647 -*/ 1648 1649 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig 1650 * down' the system stops. So I don't shut set card to init state. 1651 */ 1652 1653 static int SK_close(struct device *dev) /* */ 1654 { 1655 1656 PRINTK(("## %s: SK_close(). CSR0: %#06x\n", 1657 SK_NAME, SK_read_reg(CSR0))); 1658 1659 dev->tbusy = 1; /* Transmitter busy */ 1660 dev->start = 0; /* Card down */ 1661 1662 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME, 1663 (int) SK_read_reg(CSR0)); 1664 1665 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */ 1666 1667 free_irq(dev->irq, NULL); /* Free IRQ */ 1668 irq2dev_map[dev->irq] = 0; /* Mark IRQ as unused */ 1669 1670 return 0; /* always succeed */ 1671 1672 } /* End of SK_close() */ 1673 1674 1675 /*- 1676 * Function : SK_get_stats 1677 * Author : Patrick J.D. Weichmann 1678 * Date Created : 94/05/26 1679 * 1680 * Description : Return current status structure to upper layers. 1681 * It is called by sprintf_stats (dev.c). 1682 * 1683 * Parameters : I : struct device *dev - our device structure 1684 * Return Value : struct enet_statistics * - our current statistics 1685 * Errors : None 1686 * Side Effects : None 1687 * Update History : 1688 * YY/MM/DD uid Description 1689 -*/ 1690 1691 static struct enet_statistics *SK_get_stats(struct device *dev) /* */ 1692 { 1693 1694 struct priv *p = (struct priv *) dev->priv; 1695 1696 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n", 1697 SK_NAME, SK_read_reg(CSR0))); 1698 1699 return &p->stats; /* Return Device status */ 1700 1701 } /* End of SK_get_stats() */ 1702 1703 1704 /*- 1705 * Function : set_multicast_list 1706 * Author : Patrick J.D. Weichmann 1707 * Date Created : 94/05/26 1708 * 1709 * Description : This function gets called when a program performs 1710 * a SIOCSIFFLAGS call. Ifconfig does this if you call 1711 * 'ifconfig [-]allmulti' which enables or disables the 1712 * Promiscuous mode. 1713 * Promiscuous mode is when the Network card accepts all 1714 * packets, not only the packets which match our MAC 1715 * Address. It is useful for writing a network monitor, 1716 * but it is also a security problem. You have to remember 1717 * that all information on the net is not encrypted. 1718 * 1719 * Parameters : I : struct device *dev - SK_G16 device Structure 1720 * Return Value : None 1721 * Errors : None 1722 * Globals : None 1723 * Update History : 1724 * YY/MM/DD uid Description 1725 * 95/10/18 ACox Noew multicast calling scheme 1726 -*/ 1727 1728 1729 /* Set or clear the multicast filter for SK_G16. 1730 */ 1731 1732 static void set_multicast_list(struct device *dev) /* */ 1733 { 1734 1735 if (dev->flags&IFF_PROMISC) 1736 { 1737 /* Reinitialize LANCE with MODE_PROM set */ 1738 SK_lance_init(dev, MODE_PROM); 1739 } 1740 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI)) 1741 { 1742 /* Reinitialize LANCE without MODE_PROM */ 1743 SK_lance_init(dev, MODE_NORMAL); 1744 } 1745 else 1746 { 1747 /* Multicast with logical address filter on */ 1748 /* Reinitialize LANCE without MODE_PROM */ 1749 SK_lance_init(dev, MODE_NORMAL); 1750 1751 /* Not implemented yet. */ 1752 } 1753 } /* End of set_multicast_list() */ 1754 1755 1756 1757 /*- 1758 * Function : SK_rom_addr 1759 * Author : Patrick J.D. Weichmann 1760 * Date Created : 94/06/01 1761 * 1762 * Description : Try to find a Boot_ROM at all possible locations 1763 * 1764 * Parameters : None 1765 * Return Value : Address where Boot_ROM is 1766 * Errors : 0 - Did not find Boot_ROM 1767 * Globals : None 1768 * Update History : 1769 * YY/MM/DD uid Description 1770 -*/ 1771 1772 unsigned int SK_rom_addr(void) /* */ 1773 { 1774 int i,j; 1775 int rom_found = 0; 1776 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS; 1777 unsigned char rom_id[] = SK_BOOT_ROM_ID; 1778 unsigned char *test_byte; 1779 1780 /* Autodetect Boot_ROM */ 1781 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME)); 1782 1783 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++) 1784 { 1785 1786 PRINTK(("## Trying ROM location %#08x", rom_location[i])); 1787 1788 rom_found = 1; 1789 for (j = 0; j < 6; j++) 1790 { 1791 test_byte = (unsigned char *) (rom_location[i]+j); 1792 PRINTK((" %02x ", *test_byte)); 1793 1794 if(!(*test_byte == rom_id[j])) 1795 { 1796 rom_found = 0; 1797 } 1798 } 1799 PRINTK(("\n")); 1800 } 1801 1802 if (rom_found == 1) 1803 { 1804 PRINTK(("## %s: Boot_ROM found at %#08x\n", 1805 SK_NAME, rom_location[(i-1)])); 1806 1807 return (rom_location[--i]); 1808 } 1809 else 1810 { 1811 PRINTK(("%s: No Boot_ROM found\n", SK_NAME)); 1812 return 0; 1813 } 1814 } /* End of SK_rom_addr() */ 1815 1816 1817 1818 /* LANCE access functions 1819 * 1820 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set ! 1821 */ 1822 1823 1824 /*- 1825 * Function : SK_reset_board 1826 * 1827 * Author : Patrick J.D. Weichmann 1828 * 1829 * Date Created : 94/05/25 1830 * 1831 * Description : This function resets SK_G16 and all components, but 1832 * POS registers are not changed 1833 * 1834 * Parameters : None 1835 * Return Value : None 1836 * Errors : None 1837 * Globals : SK_RAM *board - SK_RAM structure pointer 1838 * 1839 * Update History : 1840 * YY/MM/DD uid Description 1841 -*/ 1842 1843 void SK_reset_board(void) /* */ 1844 { 1845 int i; 1846 1847 SK_PORT = 0x00; /* Reset active */ 1848 for (i = 0; i < 10 ; i++) /* Delay min 5ms */ 1849 ; 1850 SK_PORT = SK_RESET; /* Set back to normal operation */ 1851 1852 } /* End of SK_reset_board() */ 1853 1854 1855 /*- 1856 * Function : SK_set_RAP 1857 * Author : Patrick J.D. Weichmann 1858 * Date Created : 94/05/25 1859 * 1860 * Description : Set LANCE Register Address Port to register 1861 * for later data transfer. 1862 * 1863 * Parameters : I : reg_number - which CSR to read/write from/to 1864 * Return Value : None 1865 * Errors : None 1866 * Globals : SK_RAM *board - SK_RAM structure pointer 1867 * Update History : 1868 * YY/MM/DD uid Description 1869 -*/ 1870 1871 void SK_set_RAP(int reg_number) /* */ 1872 { 1873 SK_IOREG = reg_number; 1874 SK_PORT = SK_RESET | SK_RAP | SK_WREG; 1875 SK_IOCOM = SK_DOIO; 1876 1877 while (SK_PORT & SK_IORUN) 1878 ; 1879 } /* End of SK_set_RAP() */ 1880 1881 1882 /*- 1883 * Function : SK_read_reg 1884 * Author : Patrick J.D. Weichmann 1885 * Date Created : 94/05/25 1886 * 1887 * Description : Set RAP and read data from a LANCE CSR register 1888 * 1889 * Parameters : I : reg_number - which CSR to read from 1890 * Return Value : Register contents 1891 * Errors : None 1892 * Globals : SK_RAM *board - SK_RAM structure pointer 1893 * Update History : 1894 * YY/MM/DD uid Description 1895 -*/ 1896 1897 int SK_read_reg(int reg_number) /* */ 1898 { 1899 SK_set_RAP(reg_number); 1900 1901 SK_PORT = SK_RESET | SK_RDATA | SK_RREG; 1902 SK_IOCOM = SK_DOIO; 1903 1904 while (SK_PORT & SK_IORUN) 1905 ; 1906 return (SK_IOREG); 1907 1908 } /* End of SK_read_reg() */ 1909 1910 1911 /*- 1912 * Function : SK_rread_reg 1913 * Author : Patrick J.D. Weichmann 1914 * Date Created : 94/05/28 1915 * 1916 * Description : Read data from preseted register. 1917 * This function requires that you know which 1918 * Register is actually set. Be aware that CSR1-3 1919 * can only be accessed when in CSR0 STOP is set. 1920 * 1921 * Return Value : Register contents 1922 * Errors : None 1923 * Globals : SK_RAM *board - SK_RAM structure pointer 1924 * Update History : 1925 * YY/MM/DD uid Description 1926 -*/ 1927 1928 int SK_rread_reg(void) /* */ 1929 { 1930 SK_PORT = SK_RESET | SK_RDATA | SK_RREG; 1931 1932 SK_IOCOM = SK_DOIO; 1933 1934 while (SK_PORT & SK_IORUN) 1935 ; 1936 return (SK_IOREG); 1937 1938 } /* End of SK_rread_reg() */ 1939 1940 1941 /*- 1942 * Function : SK_write_reg 1943 * Author : Patrick J.D. Weichmann 1944 * Date Created : 94/05/25 1945 * 1946 * Description : This function sets the RAP then fills in the 1947 * LANCE I/O Reg and starts Transfer to LANCE. 1948 * It waits until transfer has ended which is max. 7 ms 1949 * and then it returns. 1950 * 1951 * Parameters : I : reg_number - which CSR to write to 1952 * I : value - what value to fill into register 1953 * Return Value : None 1954 * Errors : None 1955 * Globals : SK_RAM *board - SK_RAM structure pointer 1956 * Update History : 1957 * YY/MM/DD uid Description 1958 -*/ 1959 1960 void SK_write_reg(int reg_number, int value) /* */ 1961 { 1962 SK_set_RAP(reg_number); 1963 1964 SK_IOREG = value; 1965 SK_PORT = SK_RESET | SK_RDATA | SK_WREG; 1966 SK_IOCOM = SK_DOIO; 1967 1968 while (SK_PORT & SK_IORUN) 1969 ; 1970 } /* End of SK_write_reg */ 1971 1972 1973 1974 /* 1975 * Debugging functions 1976 * ------------------- 1977 */ 1978 1979 /*- 1980 * Function : SK_print_pos 1981 * Author : Patrick J.D. Weichmann 1982 * Date Created : 94/05/25 1983 * 1984 * Description : This function prints out the 4 POS (Programmable 1985 * Option Select) Registers. Used mainly to debug operation. 1986 * 1987 * Parameters : I : struct device *dev - SK_G16 device structure 1988 * I : char * - Text which will be printed as title 1989 * Return Value : None 1990 * Errors : None 1991 * Update History : 1992 * YY/MM/DD uid Description 1993 -*/ 1994 1995 void SK_print_pos(struct device *dev, char *text) /* */ 1996 { 1997 int ioaddr = dev->base_addr; 1998 1999 unsigned char pos0 = inb(SK_POS0), 2000 pos1 = inb(SK_POS1), 2001 pos2 = inb(SK_POS2), 2002 pos3 = inb(SK_POS3), 2003 pos4 = inb(SK_POS4); 2004 2005 2006 printk("## %s: %s.\n" 2007 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n", 2008 SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4); 2009 2010 } /* End of SK_print_pos() */ 2011 2012 2013 2014 /*- 2015 * Function : SK_print_dev 2016 * Author : Patrick J.D. Weichmann 2017 * Date Created : 94/05/25 2018 * 2019 * Description : This function simply prints out the important fields 2020 * of the device structure. 2021 * 2022 * Parameters : I : struct device *dev - SK_G16 device structure 2023 * I : char *text - Title for printing 2024 * Return Value : None 2025 * Errors : None 2026 * Update History : 2027 * YY/MM/DD uid Description 2028 -*/ 2029 2030 void SK_print_dev(struct device *dev, char *text) /* */ 2031 { 2032 if (dev == NULL) 2033 { 2034 printk("## %s: Device Structure. %s\n", SK_NAME, text); 2035 printk("## DEVICE == NULL\n"); 2036 } 2037 else 2038 { 2039 printk("## %s: Device Structure. %s\n", SK_NAME, text); 2040 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n", 2041 dev->name, dev->base_addr, dev->irq); 2042 2043 printk("## FLAGS: start: %d tbusy: %ld int: %d\n", 2044 dev->start, dev->tbusy, dev->interrupt); 2045 2046 printk("## next device: %#08x init function: %#08x\n", 2047 (int) dev->next, (int) dev->init); 2048 } 2049 2050 } /* End of SK_print_dev() */ 2051 2052 2053 2054 /*- 2055 * Function : SK_print_ram 2056 * Author : Patrick J.D. Weichmann 2057 * Date Created : 94/06/02 2058 * 2059 * Description : This function is used to check how are things set up 2060 * in the 16KB RAM. Also the pointers to the receive and 2061 * transmit descriptor rings and rx and tx buffers locations. 2062 * It contains a minor bug in printing, but has no effect to the values 2063 * only newlines are not correct. 2064 * 2065 * Parameters : I : struct device *dev - SK_G16 device structure 2066 * Return Value : None 2067 * Errors : None 2068 * Globals : None 2069 * Update History : 2070 * YY/MM/DD uid Description 2071 -*/ 2072 2073 void SK_print_ram(struct device *dev) /* */ 2074 { 2075 2076 int i; 2077 struct priv *p = (struct priv *) dev->priv; 2078 2079 printk("## %s: RAM Details.\n" 2080 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n", 2081 SK_NAME, 2082 (unsigned int) p->ram, 2083 (unsigned int) p->tmdhead, 2084 (unsigned int) p->rmdhead, 2085 (unsigned int) &(p->ram)->ib); 2086 2087 printk("## "); 2088 2089 for(i = 0; i < TMDNUM; i++) 2090 { 2091 if (!(i % 3)) /* Every third line do a newline */ 2092 { 2093 printk("\n## "); 2094 } 2095 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]); 2096 } 2097 printk("## "); 2098 2099 for(i = 0; i < RMDNUM; i++) 2100 { 2101 if (!(i % 3)) /* Every third line do a newline */ 2102 { 2103 printk("\n## "); 2104 } 2105 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]); 2106 } 2107 printk("\n"); 2108 2109 } /* End of SK_print_ram() */ 2110