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