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