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/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]; */ /* Declared in <linux/ioport.h> */ 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 static void set_multicast_list(struct device *dev); 500 501 /* 502 * LANCE Functions 503 * --------------- 504 */ 505 506 static int SK_lance_init(struct device *dev, unsigned short mode); 507 void SK_reset_board(void); 508 void SK_set_RAP(int reg_number); 509 int SK_read_reg(int reg_number); 510 int SK_rread_reg(void); 511 void SK_write_reg(int reg_number, int value); 512 513 /* 514 * Debugging functions 515 * ------------------- 516 */ 517 518 void SK_print_pos(struct device *dev, char *text); 519 void SK_print_dev(struct device *dev, char *text); 520 void SK_print_ram(struct device *dev); 521 522 523 /*- 524 * Function : SK_init 525 * Author : Patrick J.D. Weichmann 526 * Date Created : 94/05/26 527 * 528 * Description : Check for a SK_G16 network adaptor and initialize it. 529 * This function gets called by dev_init which initializes 530 * all Network devices. 531 * 532 * Parameters : I : struct device *dev - structure preconfigured 533 * from Space.c 534 * Return Value : 0 = Driver Found and initialized 535 * Errors : ENODEV - no device found 536 * ENXIO - not probed 537 * Globals : None 538 * Update History : 539 * YY/MM/DD uid Description 540 -*/ 541 542 /* 543 * Check for a network adaptor of this type, and return '0' if one exists. 544 * If dev->base_addr == 0, probe all likely locations. 545 * If dev->base_addr == 1, always return failure. 546 * If dev->base_addr == 2, allocate space for the device and return success 547 * (detachable devices only). 548 */ 549 550 int SK_init(struct device *dev) /* */ 551 { 552 int ioaddr = 0; /* I/O port address used for POS regs */ 553 int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */ 554 555 /* get preconfigured base_addr from dev which is done in Space.c */ 556 int base_addr = dev->base_addr; 557 558 PRINTK(("%s: %s", SK_NAME, rcsid)); 559 rcsid = NULL; /* We do not want to use this further */ 560 561 if (base_addr > 0x0ff) /* Check a single specified address */ 562 { 563 /* Check if on specified address is a SK_G16 */ 564 565 if ( (inb(SK_POS0) == SK_IDLOW) || 566 (inb(SK_POS1) == SK_IDHIGH) ) 567 { 568 return SK_probe(dev, base_addr); 569 } 570 571 return ENODEV; /* Sorry, but on specified address NO SK_G16 */ 572 } 573 else if (base_addr > 0) /* Don't probe at all */ 574 { 575 return ENXIO; 576 } 577 578 /* Autoprobe base_addr */ 579 580 for (port = &ports[0]; *port; port++) 581 { 582 ioaddr = *port; /* we need ioaddr for accessing POS regs */ 583 584 /* Check if I/O Port region is used by another board */ 585 586 if (check_region(ioaddr, ETHERCARD_TOTAL_SIZE)) 587 { 588 continue; /* Try next Port address */ 589 } 590 591 /* Check if at ioaddr is a SK_G16 */ 592 593 if ( !(inb(SK_POS0) == SK_IDLOW) || 594 !(inb(SK_POS1) == SK_IDHIGH) ) 595 { 596 continue; /* Try next Port address */ 597 } 598 599 dev->base_addr = ioaddr; /* Set I/O Port Address */ 600 601 if (SK_probe(dev, ioaddr) == 0) 602 { 603 return 0; /* Card found and initialized */ 604 } 605 } 606 607 dev->base_addr = base_addr; /* Write back original base_addr */ 608 609 return ENODEV; /* Failed to find or init driver */ 610 611 } /* End of SK_init */ 612 613 614 /*- 615 * Function : SK_probe 616 * Author : Patrick J.D. Weichmann 617 * Date Created : 94/05/26 618 * 619 * Description : This function is called by SK_init and 620 * does the main part of initialization. 621 * 622 * Parameters : I : struct device *dev - SK_G16 device structure 623 * I : short ioaddr - I/O Port address where POS is. 624 * Return Value : 0 = Initialization done 625 * Errors : ENODEV - No SK_G16 found 626 * -1 - Configuration problem 627 * Globals : irq2dev_map - Which device uses which IRQ 628 * : board - pointer to SK_RAM 629 * Update History : 630 * YY/MM/DD uid Description 631 * 94/06/30 pwe SK_ADDR now checked and at the correct place 632 -*/ 633 634 int SK_probe(struct device *dev, short ioaddr) /* */ 635 { 636 int i,j; /* Counters */ 637 int sk_addr_flag = 0; /* SK ADDR correct? 1 - no, 0 - yes */ 638 unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */ 639 640 struct priv *p; /* SK_G16 private structure */ 641 642 if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000) 643 { 644 645 sk_addr_flag = 1; 646 647 /* 648 * Now here we could use a routine which searches for a free 649 * place in the ram and set SK_ADDR if found. TODO. 650 */ 651 } 652 653 if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */ 654 { 655 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME)); 656 657 rom_addr = SK_rom_addr(); 658 659 if (rom_addr == 0) /* No Boot_ROM found */ 660 { 661 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 662 { 663 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 664 dev->name, SK_ADDR); 665 return -1; 666 } 667 668 rom_addr = SK_ADDR; /* assign predefined address */ 669 670 PRINTK(("## %s: NO Bootrom found \n", SK_NAME)); 671 672 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 673 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 674 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 675 } 676 else if (rom_addr == SK_ADDR) 677 { 678 printk("%s: RAM + ROM are set to the same address %#08x\n" 679 " Check configuration. Now switching off Boot_ROM\n", 680 SK_NAME, rom_addr); 681 682 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/ 683 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 684 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 685 } 686 else 687 { 688 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr)); 689 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME)); 690 691 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 692 { 693 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 694 dev->name, SK_ADDR); 695 return -1; 696 } 697 698 rom_addr = SK_ADDR; 699 700 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 701 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 702 outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */ 703 } 704 } 705 else /* Don't keep Boot_ROM */ 706 { 707 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME)); 708 709 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 710 { 711 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 712 dev->name, SK_ADDR); 713 return -1; 714 } 715 716 rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */ 717 718 /* IF we find a Boot_ROM disable it */ 719 720 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 721 722 /* We found a Boot_ROM and it's gone. Set RAM address on 723 * Boot_ROM address. 724 */ 725 726 if (rom_addr) 727 { 728 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on" 729 "that address\n", SK_NAME, rom_addr); 730 731 outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */ 732 } 733 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */ 734 { 735 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */ 736 { 737 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n", 738 dev->name, SK_ADDR); 739 return -1; 740 } 741 742 rom_addr = SK_ADDR; 743 744 outb(POS_ADDR, SK_POS3); /* Set RAM address */ 745 } 746 outb(SK_RAM_ON, SK_POS2); /* enable RAM */ 747 } 748 749 #ifdef SK_DEBUG 750 SK_print_pos(dev, "POS registers after ROM, RAM config"); 751 #endif 752 753 board = (SK_RAM *) rom_addr; 754 755 /* Read in station address */ 756 for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2) 757 { 758 dev->dev_addr[i] = board->rom[j]; 759 } 760 761 /* Check for manufacturer code */ 762 if (!(dev->dev_addr[0] == SK_MAC0 && 763 dev->dev_addr[1] == SK_MAC1 && 764 dev->dev_addr[2] == SK_MAC2) ) 765 { 766 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n", 767 SK_NAME)); 768 return ENODEV; /* NO SK_G16 found */ 769 } 770 771 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n", 772 dev->name, 773 "Schneider & Koch Netcard", 774 (unsigned int) dev->base_addr, 775 dev->dev_addr[0], 776 dev->dev_addr[1], 777 dev->dev_addr[2], 778 dev->dev_addr[3], 779 dev->dev_addr[4], 780 dev->dev_addr[5]); 781 782 /* Grab the I/O Port region */ 783 request_region(ioaddr, ETHERCARD_TOTAL_SIZE,"sk_g16"); 784 785 /* Initialize device structure */ 786 787 /* Allocate memory for private structure */ 788 p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL); 789 if (p == NULL) 790 return -ENOMEM; 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 dev->set_multicast_list = &set_multicast_list; 800 801 802 /* Set the generic fields of the device structure */ 803 804 ether_setup(dev); 805 806 dev->flags &= ~IFF_MULTICAST; 807 808 /* Initialize private structure */ 809 810 p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */ 811 p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */ 812 p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */ 813 814 /* Initialize buffer pointers */ 815 816 for (i = 0; i < TMDNUM; i++) 817 { 818 p->tmdbufs[i] = &(p->ram)->tmdbuf[i]; 819 } 820 821 for (i = 0; i < RMDNUM; i++) 822 { 823 p->rmdbufs[i] = &(p->ram)->rmdbuf[i]; 824 } 825 826 #ifdef SK_DEBUG 827 SK_print_pos(dev, "End of SK_probe"); 828 SK_print_ram(dev); 829 #endif 830 831 return 0; /* Initialization done */ 832 833 } /* End of SK_probe() */ 834 835 836 /*- 837 * Function : SK_open 838 * Author : Patrick J.D. Weichmann 839 * Date Created : 94/05/26 840 * 841 * Description : This function is called sometimes after booting 842 * when ifconfig program is run. 843 * 844 * This function requests an IRQ, sets the correct 845 * IRQ in the card. Then calls SK_lance_init() to 846 * init and start the LANCE chip. Then if everything is 847 * ok returns with 0 (OK), which means SK_G16 is now 848 * opened and operational. 849 * 850 * (Called by dev_open() /net/inet/dev.c) 851 * 852 * Parameters : I : struct device *dev - SK_G16 device structure 853 * Return Value : 0 - Device opened 854 * Errors : -EAGAIN - Open failed 855 * Globals : irq2dev_map - which device uses which irq 856 * Side Effects : None 857 * Update History : 858 * YY/MM/DD uid Description 859 -*/ 860 861 static int SK_open(struct device *dev) /* */ 862 { 863 int i = 0; 864 int irqval = 0; 865 int ioaddr = dev->base_addr; 866 867 int irqtab[] = SK_IRQS; 868 869 struct priv *p = (struct priv *)dev->priv; 870 871 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n", 872 SK_NAME, SK_read_reg(CSR0))); 873 874 if (dev->irq == 0) /* Autoirq */ 875 { 876 i = 0; 877 878 /* 879 * Check if one IRQ out of SK_IRQS is free and install 880 * interrupt handler. 881 * Most done by request_irq(). 882 * irqval: 0 - interrupt handler installed for IRQ irqtab[i] 883 * -EBUSY - interrupt busy 884 * -EINVAL - irq > 15 or handler = NULL 885 */ 886 887 do 888 { 889 irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16"); 890 i++; 891 } while (irqval && irqtab[i]); 892 893 if (irqval) /* We tried every possible IRQ but no success */ 894 { 895 printk("%s: unable to get an IRQ\n", dev->name); 896 return -EAGAIN; 897 } 898 899 dev->irq = irqtab[--i]; 900 901 outb(i<<2, SK_POS4); /* Set Card on probed IRQ */ 902 903 } 904 else if (dev->irq == 2) /* IRQ2 is always IRQ9 */ 905 { 906 if (request_irq(9, &SK_interrupt, 0, "sk_g16")) 907 { 908 printk("%s: unable to get IRQ 9\n", dev->name); 909 return -EAGAIN; 910 } 911 dev->irq = 9; 912 913 /* 914 * Now we set card on IRQ2. 915 * This can be confusing, but remember that IRQ2 on the network 916 * card is in reality IRQ9 917 */ 918 outb(0x08, SK_POS4); /* set card to IRQ2 */ 919 920 } 921 else /* Check IRQ as defined in Space.c */ 922 { 923 int i = 0; 924 925 /* check if IRQ free and valid. Then install Interrupt handler */ 926 927 if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16")) 928 { 929 printk("%s: unable to get selected IRQ\n", dev->name); 930 return -EAGAIN; 931 } 932 933 switch(dev->irq) 934 { 935 case 3: i = 0; 936 break; 937 case 5: i = 1; 938 break; 939 case 2: i = 2; 940 break; 941 case 11:i = 3; 942 break; 943 default: 944 printk("%s: Preselected IRQ %d is invalid for %s boards", 945 dev->name, 946 dev->irq, 947 SK_NAME); 948 return -EAGAIN; 949 } 950 951 outb(i<<2, SK_POS4); /* Set IRQ on card */ 952 } 953 954 irq2dev_map[dev->irq] = dev; /* Set IRQ as used by us */ 955 956 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n", 957 dev->name, (unsigned int)dev->base_addr, 958 (int) dev->irq, (unsigned int) p->ram); 959 960 if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */ 961 { 962 963 964 dev->tbusy = 0; 965 dev->interrupt = 0; 966 dev->start = 1; 967 968 #ifdef SK_DEBUG 969 970 /* 971 * This debug block tries to stop LANCE, 972 * reinit LANCE with transmitter and receiver disabled, 973 * then stop again and reinit with NORMAL_MODE 974 */ 975 976 printk("## %s: After lance init. CSR0: %#06x\n", 977 SK_NAME, SK_read_reg(CSR0)); 978 SK_write_reg(CSR0, CSR0_STOP); 979 printk("## %s: LANCE stopped. CSR0: %#06x\n", 980 SK_NAME, SK_read_reg(CSR0)); 981 SK_lance_init(dev, MODE_DTX | MODE_DRX); 982 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n", 983 SK_NAME, SK_read_reg(CSR0)); 984 SK_write_reg(CSR0, CSR0_STOP); 985 printk("## %s: LANCE stopped. CSR0: %#06x\n", 986 SK_NAME, SK_read_reg(CSR0)); 987 SK_lance_init(dev, MODE_NORMAL); 988 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n", 989 SK_NAME, SK_read_reg(CSR0)); 990 SK_print_pos(dev, "POS regs before returning OK"); 991 992 #endif /* SK_DEBUG */ 993 994 return 0; /* SK_open() is successful */ 995 } 996 else /* LANCE init failed */ 997 { 998 999 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n", 1000 SK_NAME, SK_read_reg(CSR0))); 1001 1002 dev->start = 0; /* Device not ready */ 1003 return -EAGAIN; 1004 } 1005 1006 } /* End of SK_open() */ 1007 1008 1009 /*- 1010 * Function : SK_lance_init 1011 * Author : Patrick J.D. Weichmann 1012 * Date Created : 94/05/26 1013 * 1014 * Description : Reset LANCE chip, fill RMD, TMD structures with 1015 * start values and Start LANCE. 1016 * 1017 * Parameters : I : struct device *dev - SK_G16 device structure 1018 * I : int mode - put LANCE into "mode" see data-sheet for 1019 * more info. 1020 * Return Value : 0 - Init done 1021 * Errors : -1 - Init failed 1022 * Update History : 1023 * YY/MM/DD uid Description 1024 -*/ 1025 1026 static int SK_lance_init(struct device *dev, unsigned short mode) /* */ 1027 { 1028 int i; 1029 struct priv *p = (struct priv *) dev->priv; 1030 struct tmd *tmdp; 1031 struct rmd *rmdp; 1032 1033 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n", 1034 SK_NAME, SK_read_reg(CSR0))); 1035 1036 /* Reset LANCE */ 1037 SK_reset_board(); 1038 1039 /* Initialize TMD's with start values */ 1040 p->tmdnum = 0; /* First descriptor for transmitting */ 1041 p->tmdlast = 0; /* First descriptor for reading stats */ 1042 1043 for (i = 0; i < TMDNUM; i++) /* Init all TMD's */ 1044 { 1045 tmdp = p->tmdhead + i; 1046 1047 tmdp->u.buffer = (unsigned long) p->tmdbufs[i]; /* assign buffer */ 1048 1049 /* Mark TMD as start and end of packet */ 1050 tmdp->u.s.status = TX_STP | TX_ENP; 1051 } 1052 1053 1054 /* Initialize RMD's with start values */ 1055 1056 p->rmdnum = 0; /* First RMD which will be used */ 1057 1058 for (i = 0; i < RMDNUM; i++) /* Init all RMD's */ 1059 { 1060 rmdp = p->rmdhead + i; 1061 1062 1063 rmdp->u.buffer = (unsigned long) p->rmdbufs[i]; /* assign buffer */ 1064 1065 /* 1066 * LANCE must be owner at beginning so that he can fill in 1067 * receiving packets, set status and release RMD 1068 */ 1069 1070 rmdp->u.s.status = RX_OWN; 1071 1072 rmdp->blen = -PKT_BUF_SZ; /* Buffer Size in a two's complement */ 1073 1074 rmdp->mlen = 0; /* init message length */ 1075 1076 } 1077 1078 /* Fill LANCE Initialize Block */ 1079 1080 (p->ram)->ib.mode = mode; /* Set operation mode */ 1081 1082 for (i = 0; i < ETH_ALEN; i++) /* Set physical address */ 1083 { 1084 (p->ram)->ib.paddr[i] = dev->dev_addr[i]; 1085 } 1086 1087 for (i = 0; i < 8; i++) /* Set multicast, logical address */ 1088 { 1089 (p->ram)->ib.laddr[i] = 0; /* We do not use logical addressing */ 1090 } 1091 1092 /* Set ring descriptor pointers and set number of descriptors */ 1093 1094 (p->ram)->ib.rdrp = (int) p->rmdhead | RMDNUMMASK; 1095 (p->ram)->ib.tdrp = (int) p->tmdhead | TMDNUMMASK; 1096 1097 /* Prepare LANCE Control and Status Registers */ 1098 1099 cli(); 1100 1101 SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */ 1102 1103 /* 1104 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to 1105 * PC Memory locations. 1106 * 1107 * In structure SK_ram is defined that the first thing in ram 1108 * is the initialization block. So his address is for LANCE always 1109 * 0x0000 1110 * 1111 * CSR1 contains low order bits 15:0 of initialization block address 1112 * CSR2 is built of: 1113 * 7:0 High order bits 23:16 of initialization block address 1114 * 15:8 reserved, must be 0 1115 */ 1116 1117 /* Set initialization block address (must be on word boundary) */ 1118 SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */ 1119 SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */ 1120 1121 1122 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n", 1123 SK_NAME, SK_read_reg(CSR0))); 1124 1125 /* Initialize LANCE */ 1126 1127 /* 1128 * INIT = Initialize, when set, causes the LANCE to begin the 1129 * initialization procedure and access the Init Block. 1130 */ 1131 1132 SK_write_reg(CSR0, CSR0_INIT); 1133 1134 sti(); 1135 1136 /* Wait until LANCE finished initialization */ 1137 1138 SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */ 1139 1140 for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++) 1141 ; /* Wait until init done or go ahead if problems (i>=100) */ 1142 1143 if (i >= 100) /* Something is wrong ! */ 1144 { 1145 printk("%s: can't init am7990, status: %04x " 1146 "init_block: %#08x\n", 1147 dev->name, (int) SK_read_reg(CSR0), 1148 (unsigned int) &(p->ram)->ib); 1149 1150 #ifdef SK_DEBUG 1151 SK_print_pos(dev, "LANCE INIT failed"); 1152 SK_print_dev(dev,"Device Structure:"); 1153 #endif 1154 1155 return -1; /* LANCE init failed */ 1156 } 1157 1158 PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i)); 1159 1160 /* Clear Initialize done, enable Interrupts, start LANCE */ 1161 1162 SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT); 1163 1164 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME, 1165 SK_read_reg(CSR0))); 1166 1167 return 0; /* LANCE is up and running */ 1168 1169 } /* End of SK_lance_init() */ 1170 1171 1172 1173 /*- 1174 * Function : SK_send_packet 1175 * Author : Patrick J.D. Weichmann 1176 * Date Created : 94/05/27 1177 * 1178 * Description : Writes an socket buffer into a transmit descriptor 1179 * and starts transmission. 1180 * 1181 * Parameters : I : struct sk_buff *skb - packet to transfer 1182 * I : struct device *dev - SK_G16 device structure 1183 * Return Value : 0 - OK 1184 * 1 - Could not transmit (dev_queue_xmit will queue it) 1185 * and try to sent it later 1186 * Globals : None 1187 * Side Effects : None 1188 * Update History : 1189 * YY/MM/DD uid Description 1190 -*/ 1191 1192 static int SK_send_packet(struct sk_buff *skb, struct device *dev) /* */ 1193 { 1194 struct priv *p = (struct priv *) dev->priv; 1195 struct tmd *tmdp; 1196 1197 if (dev->tbusy) 1198 { 1199 /* if Transmitter more than 150ms busy -> time_out */ 1200 1201 int tickssofar = jiffies - dev->trans_start; 1202 if (tickssofar < 15) 1203 { 1204 return 1; /* We have to try transmit later */ 1205 } 1206 1207 printk("%s: xmitter timed out, try to restart!\n", dev->name); 1208 1209 SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */ 1210 1211 dev->tbusy = 0; /* Clear Transmitter flag */ 1212 1213 dev->trans_start = jiffies; /* Mark Start of transmission */ 1214 1215 } 1216 1217 /* 1218 * If some upper Layer thinks we missed a transmit done interrupt 1219 * we are passed NULL. 1220 * (dev_queue_xmit net/inet/dev.c 1221 */ 1222 1223 if (skb == NULL) 1224 { 1225 /* 1226 * Dequeue packets from transmit queue and send them. 1227 */ 1228 dev_tint(dev); 1229 1230 return 0; 1231 } 1232 1233 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n", 1234 SK_NAME, SK_read_reg(CSR0))); 1235 1236 1237 /* 1238 * Block a timer-based transmit from overlapping. 1239 * This means check if we are already in. 1240 */ 1241 1242 if (set_bit(0, (void *) &dev->tbusy) != 0) /* dev->tbusy already set ? */ 1243 { 1244 printk("%s: Transmitter access conflict.\n", dev->name); 1245 } 1246 else 1247 { 1248 /* Evaluate Packet length */ 1249 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 1250 1251 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */ 1252 1253 /* Fill in Transmit Message Descriptor */ 1254 1255 /* Copy data into dual ported ram */ 1256 1257 memcpy((char *) (tmdp->u.buffer & 0x00ffffff), (char *)skb->data, 1258 skb->len); 1259 1260 tmdp->blen = -len; /* set length to transmit */ 1261 1262 /* 1263 * Packet start and end is always set because we use the maximum 1264 * packet length as buffer length. 1265 * Relinquish ownership to LANCE 1266 */ 1267 1268 tmdp->u.s.status = TX_OWN | TX_STP | TX_ENP; 1269 1270 /* Start Demand Transmission */ 1271 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA); 1272 1273 dev->trans_start = jiffies; /* Mark start of transmission */ 1274 1275 /* Set pointer to next transmit buffer */ 1276 p->tmdnum++; 1277 p->tmdnum &= TMDNUM-1; 1278 1279 /* Do we own the next transmit buffer ? */ 1280 if (! ((p->tmdhead + p->tmdnum)->u.s.status & TX_OWN) ) 1281 { 1282 /* 1283 * We own next buffer and are ready to transmit, so 1284 * clear busy flag 1285 */ 1286 dev->tbusy = 0; 1287 } 1288 } 1289 dev_kfree_skb(skb, FREE_WRITE); 1290 return 0; 1291 } /* End of SK_send_packet */ 1292 1293 1294 /*- 1295 * Function : SK_interrupt 1296 * Author : Patrick J.D. Weichmann 1297 * Date Created : 94/05/27 1298 * 1299 * Description : SK_G16 interrupt handler which checks for LANCE 1300 * Errors, handles transmit and receive interrupts 1301 * 1302 * Parameters : I : int irq, struct pt_regs * regs - 1303 * Return Value : None 1304 * Errors : None 1305 * Globals : None 1306 * Side Effects : None 1307 * Update History : 1308 * YY/MM/DD uid Description 1309 -*/ 1310 1311 static void SK_interrupt(int irq, struct pt_regs * regs) /* */ 1312 { 1313 int csr0; 1314 struct device *dev = (struct device *) irq2dev_map[irq]; 1315 struct priv *p = (struct priv *) dev->priv; 1316 1317 1318 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n", 1319 SK_NAME, SK_read_reg(CSR0))); 1320 1321 if (dev == NULL) 1322 { 1323 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq); 1324 } 1325 1326 1327 if (dev->interrupt) 1328 { 1329 printk("%s: Re-entering the interrupt handler.\n", dev->name); 1330 } 1331 1332 csr0 = SK_read_reg(CSR0); /* store register for checking */ 1333 1334 dev->interrupt = 1; /* We are handling an interrupt */ 1335 1336 /* 1337 * Acknowledge all of the current interrupt sources, disable 1338 * Interrupts (INEA = 0) 1339 */ 1340 1341 SK_write_reg(CSR0, csr0 & CSR0_CLRALL); 1342 1343 if (csr0 & CSR0_ERR) /* LANCE Error */ 1344 { 1345 printk("%s: error: %04x\n", dev->name, csr0); 1346 1347 if (csr0 & CSR0_MISS) /* No place to store packet ? */ 1348 { 1349 p->stats.rx_dropped++; 1350 } 1351 } 1352 1353 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */ 1354 { 1355 SK_rxintr(dev); 1356 } 1357 1358 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */ 1359 { 1360 SK_txintr(dev); 1361 } 1362 1363 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */ 1364 1365 dev->interrupt = 0; /* We are out */ 1366 } /* End of SK_interrupt() */ 1367 1368 1369 /*- 1370 * Function : SK_txintr 1371 * Author : Patrick J.D. Weichmann 1372 * Date Created : 94/05/27 1373 * 1374 * Description : After sending a packet we check status, update 1375 * statistics and relinquish ownership of transmit 1376 * descriptor ring. 1377 * 1378 * Parameters : I : struct device *dev - SK_G16 device structure 1379 * Return Value : None 1380 * Errors : None 1381 * Globals : None 1382 * Update History : 1383 * YY/MM/DD uid Description 1384 -*/ 1385 1386 static void SK_txintr(struct device *dev) /* */ 1387 { 1388 int tmdstat; 1389 struct tmd *tmdp; 1390 struct priv *p = (struct priv *) dev->priv; 1391 1392 1393 PRINTK2(("## %s: SK_txintr() status: %#06x\n", 1394 SK_NAME, SK_read_reg(CSR0))); 1395 1396 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */ 1397 1398 /* Set next buffer */ 1399 p->tmdlast++; 1400 p->tmdlast &= TMDNUM-1; 1401 1402 tmdstat = tmdp->u.s.status & 0xff00; /* filter out status bits 15:08 */ 1403 1404 /* 1405 * We check status of transmitted packet. 1406 * see LANCE data-sheet for error explanation 1407 */ 1408 if (tmdstat & TX_ERR) /* Error occurred */ 1409 { 1410 printk("%s: TX error: %04x %04x\n", dev->name, (int) tmdstat, 1411 (int) tmdp->status2); 1412 1413 if (tmdp->status2 & TX_TDR) /* TDR problems? */ 1414 { 1415 printk("%s: tdr-problems \n", dev->name); 1416 } 1417 1418 if (tmdp->status2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */ 1419 p->stats.tx_aborted_errors++; 1420 if (tmdp->status2 & TX_LCOL) /* Late collision ? */ 1421 p->stats.tx_window_errors++; 1422 if (tmdp->status2 & TX_LCAR) /* Loss of Carrier ? */ 1423 p->stats.tx_carrier_errors++; 1424 if (tmdp->status2 & TX_UFLO) /* Underflow error ? */ 1425 { 1426 p->stats.tx_fifo_errors++; 1427 1428 /* 1429 * If UFLO error occurs it will turn transmitter of. 1430 * So we must reinit LANCE 1431 */ 1432 1433 SK_lance_init(dev, MODE_NORMAL); 1434 } 1435 1436 p->stats.tx_errors++; 1437 1438 tmdp->status2 = 0; /* Clear error flags */ 1439 } 1440 else if (tmdstat & TX_MORE) /* Collisions occurred ? */ 1441 { 1442 /* 1443 * Here I have a problem. 1444 * I only know that there must be one or up to 15 collisions. 1445 * Thats why TX_MORE is set, because after 16 attempts TX_RTRY 1446 * will be set which means couldn't send packet aborted transfer. 1447 * 1448 * First I did not have this in but then I thought at minimum 1449 * we see that something was not ok. 1450 * If anyone knows something better than this to handle this 1451 * please report it. (see Email addresses in the README file) 1452 */ 1453 1454 p->stats.collisions++; 1455 } 1456 else /* Packet sent without any problems */ 1457 { 1458 p->stats.tx_packets++; 1459 } 1460 1461 /* 1462 * We mark transmitter not busy anymore, because now we have a free 1463 * transmit descriptor which can be filled by SK_send_packet and 1464 * afterwards sent by the LANCE 1465 */ 1466 1467 dev->tbusy = 0; 1468 1469 /* 1470 * mark_bh(NET_BH); 1471 * This will cause net_bh() to run after this interrupt handler. 1472 * 1473 * The function which do handle slow IRQ parts is do_bottom_half() 1474 * which runs at normal kernel priority, that means all interrupt are 1475 * enabled. (see kernel/irq.c) 1476 * 1477 * net_bh does something like this: 1478 * - check if already in net_bh 1479 * - try to transmit something from the send queue 1480 * - if something is in the receive queue send it up to higher 1481 * levels if it is a known protocol 1482 * - try to transmit something from the send queue 1483 */ 1484 1485 mark_bh(NET_BH); 1486 1487 } /* End of SK_txintr() */ 1488 1489 1490 /*- 1491 * Function : SK_rxintr 1492 * Author : Patrick J.D. Weichmann 1493 * Date Created : 94/05/27 1494 * 1495 * Description : Buffer sent, check for errors, relinquish ownership 1496 * of the receive message descriptor. 1497 * 1498 * Parameters : I : SK_G16 device structure 1499 * Return Value : None 1500 * Globals : None 1501 * Update History : 1502 * YY/MM/DD uid Description 1503 -*/ 1504 1505 static void SK_rxintr(struct device *dev) /* */ 1506 { 1507 1508 struct rmd *rmdp; 1509 int rmdstat; 1510 struct priv *p = (struct priv *) dev->priv; 1511 1512 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n", 1513 SK_NAME, SK_read_reg(CSR0))); 1514 1515 rmdp = p->rmdhead + p->rmdnum; 1516 1517 /* As long as we own the next entry, check status and send 1518 * it up to higher layer 1519 */ 1520 1521 while (!( (rmdstat = rmdp->u.s.status) & RX_OWN)) 1522 { 1523 /* 1524 * Start and end of packet must be set, because we use 1525 * the ethernet maximum packet length (1518) as buffer size. 1526 * 1527 * Because our buffers are at maximum OFLO and BUFF errors are 1528 * not to be concerned (see Data sheet) 1529 */ 1530 1531 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP)) 1532 { 1533 /* Start of a frame > 1518 Bytes ? */ 1534 1535 if (rmdstat & RX_STP) 1536 { 1537 p->stats.rx_errors++; /* bad packet received */ 1538 p->stats.rx_length_errors++; /* packet to long */ 1539 1540 printk("%s: packet too long\n", dev->name); 1541 } 1542 1543 /* 1544 * All other packets will be ignored until a new frame with 1545 * start (RX_STP) set follows. 1546 * 1547 * What we do is just give descriptor free for new incoming 1548 * packets. 1549 */ 1550 1551 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1552 1553 } 1554 else if (rmdstat & RX_ERR) /* Receive Error ? */ 1555 { 1556 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat); 1557 1558 p->stats.rx_errors++; 1559 1560 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++; 1561 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++; 1562 1563 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1564 1565 } 1566 else /* We have a packet which can be queued for the upper layers */ 1567 { 1568 1569 int len = (rmdp->mlen & 0x0fff); /* extract message length from receive buffer */ 1570 struct sk_buff *skb; 1571 1572 skb = dev_alloc_skb(len+2); /* allocate socket buffer */ 1573 1574 if (skb == NULL) /* Could not get mem ? */ 1575 { 1576 1577 /* 1578 * Couldn't allocate sk_buffer so we give descriptor back 1579 * to Lance, update statistics and go ahead. 1580 */ 1581 1582 rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */ 1583 printk("%s: Couldn't allocate sk_buff, deferring packet.\n", 1584 dev->name); 1585 p->stats.rx_dropped++; 1586 1587 break; /* Jump out */ 1588 } 1589 1590 /* Prepare sk_buff to queue for upper layers */ 1591 1592 skb->dev = dev; 1593 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */ 1594 1595 /* 1596 * Copy data out of our receive descriptor into sk_buff. 1597 * 1598 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and 1599 * ignore status fields) 1600 */ 1601 1602 memcpy(skb_put(skb,len), (unsigned char *) (rmdp->u.buffer & 0x00ffffff), 1603 len); 1604 1605 1606 /* 1607 * Notify the upper protocol layers that there is another packet 1608 * to handle 1609 * 1610 * netif_rx() always succeeds. see /net/inet/dev.c for more. 1611 */ 1612 1613 skb->protocol=eth_type_trans(skb,dev); 1614 netif_rx(skb); /* queue packet and mark it for processing */ 1615 1616 /* 1617 * Packet is queued and marked for processing so we 1618 * free our descriptor and update statistics 1619 */ 1620 1621 rmdp->u.s.status = RX_OWN; 1622 p->stats.rx_packets++; 1623 1624 1625 p->rmdnum++; 1626 p->rmdnum %= RMDNUM; 1627 1628 rmdp = p->rmdhead + p->rmdnum; 1629 } 1630 } 1631 } /* End of SK_rxintr() */ 1632 1633 1634 /*- 1635 * Function : SK_close 1636 * Author : Patrick J.D. Weichmann 1637 * Date Created : 94/05/26 1638 * 1639 * Description : close gets called from dev_close() and should 1640 * deinstall the card (free_irq, mem etc). 1641 * 1642 * Parameters : I : struct device *dev - our device structure 1643 * Return Value : 0 - closed device driver 1644 * Errors : None 1645 * Globals : None 1646 * Update History : 1647 * YY/MM/DD uid Description 1648 -*/ 1649 1650 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig 1651 * down' the system stops. So I don't shut set card to init state. 1652 */ 1653 1654 static int SK_close(struct device *dev) /* */ 1655 { 1656 1657 PRINTK(("## %s: SK_close(). CSR0: %#06x\n", 1658 SK_NAME, SK_read_reg(CSR0))); 1659 1660 dev->tbusy = 1; /* Transmitter busy */ 1661 dev->start = 0; /* Card down */ 1662 1663 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME, 1664 (int) SK_read_reg(CSR0)); 1665 1666 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */ 1667 1668 free_irq(dev->irq); /* Free IRQ */ 1669 irq2dev_map[dev->irq] = 0; /* Mark IRQ as unused */ 1670 1671 return 0; /* always succeed */ 1672 1673 } /* End of SK_close() */ 1674 1675 1676 /*- 1677 * Function : SK_get_stats 1678 * Author : Patrick J.D. Weichmann 1679 * Date Created : 94/05/26 1680 * 1681 * Description : Return current status structure to upper layers. 1682 * It is called by sprintf_stats (dev.c). 1683 * 1684 * Parameters : I : struct device *dev - our device structure 1685 * Return Value : struct enet_statistics * - our current statistics 1686 * Errors : None 1687 * Side Effects : None 1688 * Update History : 1689 * YY/MM/DD uid Description 1690 -*/ 1691 1692 static struct enet_statistics *SK_get_stats(struct device *dev) /* */ 1693 { 1694 1695 struct priv *p = (struct priv *) dev->priv; 1696 1697 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n", 1698 SK_NAME, SK_read_reg(CSR0))); 1699 1700 return &p->stats; /* Return Device status */ 1701 1702 } /* End of SK_get_stats() */ 1703 1704 1705 /*- 1706 * Function : set_multicast_list 1707 * Author : Patrick J.D. Weichmann 1708 * Date Created : 94/05/26 1709 * 1710 * Description : This function gets called when a program performs 1711 * a SIOCSIFFLAGS call. Ifconfig does this if you call 1712 * 'ifconfig [-]allmulti' which enables or disables the 1713 * Promiscuous mode. 1714 * Promiscuous mode is when the Network card accepts all 1715 * packets, not only the packets which match our MAC 1716 * Address. It is useful for writing a network monitor, 1717 * but it is also a security problem. You have to remember 1718 * that all information on the net is not encrypted. 1719 * 1720 * Parameters : I : struct device *dev - SK_G16 device Structure 1721 * Return Value : None 1722 * Errors : None 1723 * Globals : None 1724 * Update History : 1725 * YY/MM/DD uid Description 1726 * 95/10/18 ACox Noew multicast calling scheme 1727 -*/ 1728 1729 1730 /* Set or clear the multicast filter for SK_G16. 1731 */ 1732 1733 static void set_multicast_list(struct device *dev) /* */ 1734 { 1735 1736 if (dev->flags&IFF_PROMISC) 1737 { 1738 /* Reinitialize LANCE with MODE_PROM set */ 1739 SK_lance_init(dev, MODE_PROM); 1740 } 1741 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI)) 1742 { 1743 /* Reinitialize LANCE without MODE_PROM */ 1744 SK_lance_init(dev, MODE_NORMAL); 1745 } 1746 else 1747 { 1748 /* Multicast with logical address filter on */ 1749 /* Reinitialize LANCE without MODE_PROM */ 1750 SK_lance_init(dev, MODE_NORMAL); 1751 1752 /* Not implemented yet. */ 1753 } 1754 } /* End of set_multicast_list() */ 1755 1756 #endif 1757 1758 1759 1760 /*- 1761 * Function : SK_rom_addr 1762 * Author : Patrick J.D. Weichmann 1763 * Date Created : 94/06/01 1764 * 1765 * Description : Try to find a Boot_ROM at all possible locations 1766 * 1767 * Parameters : None 1768 * Return Value : Address where Boot_ROM is 1769 * Errors : 0 - Did not find Boot_ROM 1770 * Globals : None 1771 * Update History : 1772 * YY/MM/DD uid Description 1773 -*/ 1774 1775 unsigned int SK_rom_addr(void) /* */ 1776 { 1777 int i,j; 1778 int rom_found = 0; 1779 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS; 1780 unsigned char rom_id[] = SK_BOOT_ROM_ID; 1781 unsigned char *test_byte; 1782 1783 /* Autodetect Boot_ROM */ 1784 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME)); 1785 1786 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++) 1787 { 1788 1789 PRINTK(("## Trying ROM location %#08x", rom_location[i])); 1790 1791 rom_found = 1; 1792 for (j = 0; j < 6; j++) 1793 { 1794 test_byte = (unsigned char *) (rom_location[i]+j); 1795 PRINTK((" %02x ", *test_byte)); 1796 1797 if(!(*test_byte == rom_id[j])) 1798 { 1799 rom_found = 0; 1800 } 1801 } 1802 PRINTK(("\n")); 1803 } 1804 1805 if (rom_found == 1) 1806 { 1807 PRINTK(("## %s: Boot_ROM found at %#08x\n", 1808 SK_NAME, rom_location[(i-1)])); 1809 1810 return (rom_location[--i]); 1811 } 1812 else 1813 { 1814 PRINTK(("%s: No Boot_ROM found\n", SK_NAME)); 1815 return 0; 1816 } 1817 } /* End of SK_rom_addr() */ 1818 1819 1820 1821 /* LANCE access functions 1822 * 1823 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set ! 1824 */ 1825 1826 1827 /*- 1828 * Function : SK_reset_board 1829 * 1830 * Author : Patrick J.D. Weichmann 1831 * 1832 * Date Created : 94/05/25 1833 * 1834 * Description : This function resets SK_G16 and all components, but 1835 * POS registers are not changed 1836 * 1837 * Parameters : None 1838 * Return Value : None 1839 * Errors : None 1840 * Globals : SK_RAM *board - SK_RAM structure pointer 1841 * 1842 * Update History : 1843 * YY/MM/DD uid Description 1844 -*/ 1845 1846 void SK_reset_board(void) /* */ 1847 { 1848 int i; 1849 1850 SK_PORT = 0x00; /* Reset active */ 1851 for (i = 0; i < 10 ; i++) /* Delay min 5ms */ 1852 ; 1853 SK_PORT = SK_RESET; /* Set back to normal operation */ 1854 1855 } /* End of SK_reset_board() */ 1856 1857 1858 /*- 1859 * Function : SK_set_RAP 1860 * Author : Patrick J.D. Weichmann 1861 * Date Created : 94/05/25 1862 * 1863 * Description : Set LANCE Register Address Port to register 1864 * for later data transfer. 1865 * 1866 * Parameters : I : reg_number - which CSR to read/write from/to 1867 * Return Value : None 1868 * Errors : None 1869 * Globals : SK_RAM *board - SK_RAM structure pointer 1870 * Update History : 1871 * YY/MM/DD uid Description 1872 -*/ 1873 1874 void SK_set_RAP(int reg_number) /* */ 1875 { 1876 SK_IOREG = reg_number; 1877 SK_PORT = SK_RESET | SK_RAP | SK_WREG; 1878 SK_IOCOM = SK_DOIO; 1879 1880 while (SK_PORT & SK_IORUN) 1881 ; 1882 } /* End of SK_set_RAP() */ 1883 1884 1885 /*- 1886 * Function : SK_read_reg 1887 * Author : Patrick J.D. Weichmann 1888 * Date Created : 94/05/25 1889 * 1890 * Description : Set RAP and read data from a LANCE CSR register 1891 * 1892 * Parameters : I : reg_number - which CSR to read from 1893 * Return Value : Register contents 1894 * Errors : None 1895 * Globals : SK_RAM *board - SK_RAM structure pointer 1896 * Update History : 1897 * YY/MM/DD uid Description 1898 -*/ 1899 1900 int SK_read_reg(int reg_number) /* */ 1901 { 1902 SK_set_RAP(reg_number); 1903 1904 SK_PORT = SK_RESET | SK_RDATA | SK_RREG; 1905 SK_IOCOM = SK_DOIO; 1906 1907 while (SK_PORT & SK_IORUN) 1908 ; 1909 return (SK_IOREG); 1910 1911 } /* End of SK_read_reg() */ 1912 1913 1914 /*- 1915 * Function : SK_rread_reg 1916 * Author : Patrick J.D. Weichmann 1917 * Date Created : 94/05/28 1918 * 1919 * Description : Read data from preseted register. 1920 * This function requires that you know which 1921 * Register is actually set. Be aware that CSR1-3 1922 * can only be accessed when in CSR0 STOP is set. 1923 * 1924 * Return Value : Register contents 1925 * Errors : None 1926 * Globals : SK_RAM *board - SK_RAM structure pointer 1927 * Update History : 1928 * YY/MM/DD uid Description 1929 -*/ 1930 1931 int SK_rread_reg(void) /* */ 1932 { 1933 SK_PORT = SK_RESET | SK_RDATA | SK_RREG; 1934 1935 SK_IOCOM = SK_DOIO; 1936 1937 while (SK_PORT & SK_IORUN) 1938 ; 1939 return (SK_IOREG); 1940 1941 } /* End of SK_rread_reg() */ 1942 1943 1944 /*- 1945 * Function : SK_write_reg 1946 * Author : Patrick J.D. Weichmann 1947 * Date Created : 94/05/25 1948 * 1949 * Description : This function sets the RAP then fills in the 1950 * LANCE I/O Reg and starts Transfer to LANCE. 1951 * It waits until transfer has ended which is max. 7 ms 1952 * and then it returns. 1953 * 1954 * Parameters : I : reg_number - which CSR to write to 1955 * I : value - what value to fill into register 1956 * Return Value : None 1957 * Errors : None 1958 * Globals : SK_RAM *board - SK_RAM structure pointer 1959 * Update History : 1960 * YY/MM/DD uid Description 1961 -*/ 1962 1963 void SK_write_reg(int reg_number, int value) /* */ 1964 { 1965 SK_set_RAP(reg_number); 1966 1967 SK_IOREG = value; 1968 SK_PORT = SK_RESET | SK_RDATA | SK_WREG; 1969 SK_IOCOM = SK_DOIO; 1970 1971 while (SK_PORT & SK_IORUN) 1972 ; 1973 } /* End of SK_write_reg */ 1974 1975 1976 1977 /* 1978 * Debugging functions 1979 * ------------------- 1980 */ 1981 1982 /*- 1983 * Function : SK_print_pos 1984 * Author : Patrick J.D. Weichmann 1985 * Date Created : 94/05/25 1986 * 1987 * Description : This function prints out the 4 POS (Programmable 1988 * Option Select) Registers. Used mainly to debug operation. 1989 * 1990 * Parameters : I : struct device *dev - SK_G16 device structure 1991 * I : char * - Text which will be printed as title 1992 * Return Value : None 1993 * Errors : None 1994 * Update History : 1995 * YY/MM/DD uid Description 1996 -*/ 1997 1998 void SK_print_pos(struct device *dev, char *text) /* */ 1999 { 2000 int ioaddr = dev->base_addr; 2001 2002 unsigned char pos0 = inb(SK_POS0), 2003 pos1 = inb(SK_POS1), 2004 pos2 = inb(SK_POS2), 2005 pos3 = inb(SK_POS3), 2006 pos4 = inb(SK_POS4); 2007 2008 2009 printk("## %s: %s.\n" 2010 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n", 2011 SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4); 2012 2013 } /* End of SK_print_pos() */ 2014 2015 2016 2017 /*- 2018 * Function : SK_print_dev 2019 * Author : Patrick J.D. Weichmann 2020 * Date Created : 94/05/25 2021 * 2022 * Description : This function simply prints out the important fields 2023 * of the device structure. 2024 * 2025 * Parameters : I : struct device *dev - SK_G16 device structure 2026 * I : char *text - Title for printing 2027 * Return Value : None 2028 * Errors : None 2029 * Update History : 2030 * YY/MM/DD uid Description 2031 -*/ 2032 2033 void SK_print_dev(struct device *dev, char *text) /* */ 2034 { 2035 if (dev == NULL) 2036 { 2037 printk("## %s: Device Structure. %s\n", SK_NAME, text); 2038 printk("## DEVICE == NULL\n"); 2039 } 2040 else 2041 { 2042 printk("## %s: Device Structure. %s\n", SK_NAME, text); 2043 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n", 2044 dev->name, dev->base_addr, dev->irq); 2045 2046 printk("## FLAGS: start: %d tbusy: %ld int: %d\n", 2047 dev->start, dev->tbusy, dev->interrupt); 2048 2049 printk("## next device: %#08x init function: %#08x\n", 2050 (int) dev->next, (int) dev->init); 2051 } 2052 2053 } /* End of SK_print_dev() */ 2054 2055 2056 2057 /*- 2058 * Function : SK_print_ram 2059 * Author : Patrick J.D. Weichmann 2060 * Date Created : 94/06/02 2061 * 2062 * Description : This function is used to check how are things set up 2063 * in the 16KB RAM. Also the pointers to the receive and 2064 * transmit descriptor rings and rx and tx buffers locations. 2065 * It contains a minor bug in printing, but has no effect to the values 2066 * only newlines are not correct. 2067 * 2068 * Parameters : I : struct device *dev - SK_G16 device structure 2069 * Return Value : None 2070 * Errors : None 2071 * Globals : None 2072 * Update History : 2073 * YY/MM/DD uid Description 2074 -*/ 2075 2076 void SK_print_ram(struct device *dev) /* */ 2077 { 2078 2079 int i; 2080 struct priv *p = (struct priv *) dev->priv; 2081 2082 printk("## %s: RAM Details.\n" 2083 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n", 2084 SK_NAME, 2085 (unsigned int) p->ram, 2086 (unsigned int) p->tmdhead, 2087 (unsigned int) p->rmdhead, 2088 (unsigned int) &(p->ram)->ib); 2089 2090 printk("## "); 2091 2092 for(i = 0; i < TMDNUM; i++) 2093 { 2094 if (!(i % 3)) /* Every third line do a newline */ 2095 { 2096 printk("\n## "); 2097 } 2098 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]); 2099 } 2100 printk("## "); 2101 2102 for(i = 0; i < RMDNUM; i++) 2103 { 2104 if (!(i % 3)) /* Every third line do a newline */ 2105 { 2106 printk("\n## "); 2107 } 2108 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]); 2109 } 2110 printk("\n"); 2111 2112 } /* End of SK_print_ram() */ 2113