- pre3:
[davej-history.git] / drivers / net / sk_g16.c
blob8ecc46db2dd104af9c666237753ae5feaba29859
1 /*-
2 * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
4 * This software may be used and distributed according to the terms
5 * of the GNU Public License, incorporated herein by reference.
7 * Module : sk_g16.c
9 * Version : $Revision: 1.1 $
11 * Author : Patrick J.D. Weichmann
13 * Date Created : 94/05/26
14 * Last Updated : $Date: 1994/06/30 16:25:15 $
16 * Description : Schneider & Koch G16 Ethernet Device Driver for
17 * Linux Kernel >= 1.1.22
18 * Update History :
19 * Paul Gortmaker, 03/97: Fix for v2.1.x to use read{b,w}
20 * write{b,w} and memcpy -> memcpy_{to,from}io
22 * Jeff Garzik, 06/2000, Modularize
24 -*/
26 static const char *rcsid = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
29 * The Schneider & Koch (SK) G16 Network device driver is based
30 * on the 'ni6510' driver from Michael Hipp which can be found at
31 * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
33 * Sources: 1) ni6510.c by M. Hipp
34 * 2) depca.c by D.C. Davies
35 * 3) skeleton.c by D. Becker
36 * 4) Am7990 Local Area Network Controller for Ethernet (LANCE),
37 * AMD, Pub. #05698, June 1989
39 * Many Thanks for helping me to get things working to:
41 * A. Cox (A.Cox@swansea.ac.uk)
42 * M. Hipp (mhipp@student.uni-tuebingen.de)
43 * R. Bolz (Schneider & Koch, Germany)
45 * To Do:
46 * - Support of SK_G8 and other SK Network Cards.
47 * - Autoset memory mapped RAM. Check for free memory and then
48 * configure RAM correctly.
49 * - SK_close should really set card in to initial state.
50 * - Test if IRQ 3 is not switched off. Use autoirq() functionality.
51 * (as in /drivers/net/skeleton.c)
52 * - Implement Multicast addressing. At minimum something like
53 * in depca.c.
54 * - Redo the statistics part.
55 * - Try to find out if the board is in 8 Bit or 16 Bit slot.
56 * If in 8 Bit mode don't use IRQ 11.
57 * - (Try to make it slightly faster.)
58 * - Power management support
61 #include <linux/module.h>
62 #include <linux/kernel.h>
63 #include <linux/sched.h>
64 #include <linux/ptrace.h>
65 #include <linux/fcntl.h>
66 #include <linux/ioport.h>
67 #include <linux/interrupt.h>
68 #include <linux/malloc.h>
69 #include <linux/string.h>
70 #include <linux/delay.h>
71 #include <asm/system.h>
72 #include <asm/io.h>
73 #include <asm/bitops.h>
74 #include <linux/errno.h>
75 #include <linux/init.h>
76 #include <linux/spinlock.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/skbuff.h>
82 #include "sk_g16.h"
84 /*
85 * Schneider & Koch Card Definitions
86 * =================================
87 */
89 #define SK_NAME "SK_G16"
92 * SK_G16 Configuration
93 * --------------------
94 */
96 /*
97 * Abbreviations
98 * -------------
100 * RAM - used for the 16KB shared memory
101 * Boot_ROM, ROM - are used for referencing the BootEPROM
103 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
104 * the behaviour of the driver and the SK_G16.
106 * ! See sk_g16.install on how to install and configure the driver !
108 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
110 * SK_ADDR defines the address where the RAM will be mapped into the real
111 * host memory.
112 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
115 #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
117 #define SK_ADDR 0xcc000
120 * In POS3 are bits A14-A19 of the address bus. These bits can be set
121 * to choose the RAM address. That's why we only can choose the RAM address
122 * in 16KB steps.
125 #define POS_ADDR (rom_addr>>14) /* Do not change this line */
128 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
129 * ----------------------------------------------
133 * As nearly every card has also SK_G16 a specified I/O Port region and
134 * only a few possible IRQ's.
135 * In the Installation Guide from Schneider & Koch is listed a possible
136 * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
137 * controllers. So we use in SK_IRQS IRQ9.
140 /* Don't touch any of the following #defines. */
142 #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
144 #define SK_IRQS { 3, 5, 9, 11, 0 }
146 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
148 #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
151 * SK_G16 POS REGISTERS
152 * --------------------
156 * SK_G16 has a Programmable Option Select (POS) Register.
157 * The POS is composed of 8 separate registers (POS0-7) which
158 * are I/O mapped on an address set by the W1 switch.
162 #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
164 #define SK_POS0 ioaddr /* Card-ID Low (R) */
165 #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
166 #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
167 #define SK_POS3 ioaddr+3 /* Base address of RAM */
168 #define SK_POS4 ioaddr+4 /* IRQ */
170 /* POS5 - POS7 are unused */
173 * SK_G16 MAC PREFIX
174 * -----------------
178 * Scheider & Koch manufacturer code (00:00:a5).
179 * This must be checked, that we are sure it is a SK card.
182 #define SK_MAC0 0x00
183 #define SK_MAC1 0x00
184 #define SK_MAC2 0x5a
187 * SK_G16 ID
188 * ---------
192 * If POS0,POS1 contain the following ID, then we know
193 * at which I/O Port Address we are.
196 #define SK_IDLOW 0xfd
197 #define SK_IDHIGH 0x6a
201 * LANCE POS Bit definitions
202 * -------------------------
205 #define SK_ROM_RAM_ON (POS2_CARD)
206 #define SK_ROM_RAM_OFF (POS2_EPROM)
207 #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
208 #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
209 #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
210 #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
212 #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
213 #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
216 * SK_G16 Memory mapped Registers
217 * ------------------------------
221 #define SK_IOREG (board->ioreg) /* LANCE data registers. */
222 #define SK_PORT (board->port) /* Control, Status register */
223 #define SK_IOCOM (board->iocom) /* I/O Command */
226 * SK_G16 Status/Control Register bits
227 * -----------------------------------
229 * (C) Controlreg (S) Statusreg
233 * Register transfer: 0 = no transfer
234 * 1 = transferring data between LANCE and I/O reg
236 #define SK_IORUN 0x20
239 * LANCE interrupt: 0 = LANCE interrupt occurred
240 * 1 = no LANCE interrupt occurred
242 #define SK_IRQ 0x10
244 #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
245 #define SK_RW 0x02 /* 0 = write to 1 = read from */
246 #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
249 #define SK_RREG SK_RW /* Transferdirection to read from lance */
250 #define SK_WREG 0 /* Transferdirection to write to lance */
251 #define SK_RAP SK_ADR /* Destination Register RAP */
252 #define SK_RDATA 0 /* Destination Register REG DataPort */
255 * SK_G16 I/O Command
256 * ------------------
260 * Any bitcombination sets the internal I/O bit (transfer will start)
261 * when written to I/O Command
264 #define SK_DOIO 0x80 /* Do Transfer */
267 * LANCE RAP (Register Address Port).
268 * ---------------------------------
272 * The LANCE internal registers are selected through the RAP.
273 * The Registers are:
275 * CSR0 - Status and Control flags
276 * CSR1 - Low order bits of initialize block (bits 15:00)
277 * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
278 * CSR3 - Allows redefinition of the Bus Master Interface.
279 * This register must be set to 0x0002, which means BSWAP = 0,
280 * ACON = 1, BCON = 0;
284 #define CSR0 0x00
285 #define CSR1 0x01
286 #define CSR2 0x02
287 #define CSR3 0x03
290 * General Definitions
291 * ===================
295 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
296 * We have 16KB RAM which can be accessed by the LANCE. In the
297 * memory are not only the buffers but also the ring descriptors and
298 * the initialize block.
299 * Don't change anything unless you really know what you do.
302 #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
303 #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */
305 /* Descriptor ring sizes */
307 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
308 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
310 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
312 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
313 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
316 * Data Buffer size is set to maximum packet length.
319 #define PKT_BUF_SZ 1518
322 * The number of low I/O ports used by the ethercard.
325 #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
328 * SK_DEBUG
330 * Here you can choose what level of debugging wanted.
332 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
333 * necessary messages will be printed.
335 * If SK_DEBUG is defined, there will be many debugging prints
336 * which can help to find some mistakes in configuration or even
337 * in the driver code.
339 * If SK_DEBUG2 is defined, many many messages will be printed
340 * which normally you don't need. I used this to check the interrupt
341 * routine.
343 * (If you define only SK_DEBUG2 then only the messages for
344 * checking interrupts will be printed!)
346 * Normal way of live is:
348 * For the whole thing get going let both symbolic constants
349 * undefined. If you face any problems and you know what's going
350 * on (you know something about the card and you can interpret some
351 * hex LANCE register output) then define SK_DEBUG
355 #undef SK_DEBUG /* debugging */
356 #undef SK_DEBUG2 /* debugging with more verbose report */
358 #ifdef SK_DEBUG
359 #define PRINTK(x) printk x
360 #else
361 #define PRINTK(x) /**/
362 #endif
364 #ifdef SK_DEBUG2
365 #define PRINTK2(x) printk x
366 #else
367 #define PRINTK2(x) /**/
368 #endif
371 * SK_G16 RAM
373 * The components are memory mapped and can be set in a region from
374 * 0x00000 through 0xfc000 in 16KB steps.
376 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
377 * Controlregister and I/O Command.
379 * dual ported RAM: This is the only memory region which the LANCE chip
380 * has access to. From the Lance it is addressed from 0x0000 to
381 * 0x3fbf. The host accesses it normally.
383 * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
384 * 8-Bit PROM, this means only the 16 even addresses are used of the
385 * 32 Byte Address region. Access to an odd address results in invalid
386 * data.
388 * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
389 * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
390 * Transfer from or to the LANCE is always in 16Bit so Low and High
391 * registers are always relevant.
393 * The Data from the Readregister is not the data in the Writeregister!!
395 * Port: Status- and Controlregister.
396 * Two different registers which share the same address, Status is
397 * read-only, Control is write-only.
399 * I/O Command:
400 * Any bitcombination written in here starts the transmission between
401 * Host and LANCE.
404 typedef struct
406 unsigned char ram[0x3fc0]; /* 16KB dual ported ram */
407 unsigned char rom[0x0020]; /* 32Byte PROM containing 6Byte MAC */
408 unsigned char res1[0x0010]; /* reserved */
409 unsigned volatile short ioreg;/* LANCE I/O Register */
410 unsigned volatile char port; /* Statusregister and Controlregister */
411 unsigned char iocom; /* I/O Command Register */
412 } SK_RAM;
414 /* struct */
417 * This is the structure for the dual ported ram. We
418 * have exactly 16 320 Bytes. In here there must be:
420 * - Initialize Block (starting at a word boundary)
421 * - Receive and Transmit Descriptor Rings (quadword boundary)
422 * - Data Buffers (arbitrary boundary)
424 * This is because LANCE has on SK_G16 only access to the dual ported
425 * RAM and nowhere else.
428 struct SK_ram
430 struct init_block ib;
431 struct tmd tmde[TMDNUM];
432 struct rmd rmde[RMDNUM];
433 char tmdbuf[TMDNUM][PKT_BUF_SZ];
434 char rmdbuf[RMDNUM][PKT_BUF_SZ];
438 * Structure where all necessary information is for ring buffer
439 * management and statistics.
442 struct priv
444 struct SK_ram *ram; /* dual ported ram structure */
445 struct rmd *rmdhead; /* start of receive ring descriptors */
446 struct tmd *tmdhead; /* start of transmit ring descriptors */
447 int rmdnum; /* actual used ring descriptor */
448 int tmdnum; /* actual transmit descriptor for transmitting data */
449 int tmdlast; /* last sent descriptor used for error handling, etc */
450 void *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
451 void *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
452 struct net_device_stats stats; /* Device driver statistics */
455 /* global variable declaration */
457 /* IRQ map used to reserve a IRQ (see SK_open()) */
459 /* static variables */
461 static SK_RAM *board; /* pointer to our memory mapped board components */
462 static struct net_device *SK_dev;
463 unsigned long SK_ioaddr;
464 static spinlock_t SK_lock = SPIN_LOCK_UNLOCKED;
466 /* Macros */
469 /* Function Prototypes */
472 * Device Driver functions
473 * -----------------------
474 * See for short explanation of each function its definitions header.
477 int SK_init(struct net_device *dev);
478 static int SK_probe(struct net_device *dev, short ioaddr);
480 static void SK_timeout(struct net_device *dev);
481 static int SK_open(struct net_device *dev);
482 static int SK_send_packet(struct sk_buff *skb, struct net_device *dev);
483 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs);
484 static void SK_rxintr(struct net_device *dev);
485 static void SK_txintr(struct net_device *dev);
486 static int SK_close(struct net_device *dev);
488 static struct net_device_stats *SK_get_stats(struct net_device *dev);
490 unsigned int SK_rom_addr(void);
492 static void set_multicast_list(struct net_device *dev);
495 * LANCE Functions
496 * ---------------
499 static int SK_lance_init(struct net_device *dev, unsigned short mode);
500 void SK_reset_board(void);
501 void SK_set_RAP(int reg_number);
502 int SK_read_reg(int reg_number);
503 int SK_rread_reg(void);
504 void SK_write_reg(int reg_number, int value);
507 * Debugging functions
508 * -------------------
511 void SK_print_pos(struct net_device *dev, char *text);
512 void SK_print_dev(struct net_device *dev, char *text);
513 void SK_print_ram(struct net_device *dev);
517 * Function : SK_init
518 * Author : Patrick J.D. Weichmann
519 * Date Created : 94/05/26
521 * Description : Check for a SK_G16 network adaptor and initialize it.
522 * This function gets called by dev_init which initializes
523 * all Network devices.
525 * Parameters : I : struct net_device *dev - structure preconfigured
526 * from Space.c
527 * Return Value : 0 = Driver Found and initialized
528 * Errors : ENODEV - no device found
529 * ENXIO - not probed
530 * Globals : None
531 * Update History :
532 * YY/MM/DD uid Description
536 * Check for a network adaptor of this type, and return '0' if one exists.
537 * If dev->base_addr == 0, probe all likely locations.
538 * If dev->base_addr == 1, always return failure.
539 * If dev->base_addr == 2, allocate space for the device and return success
540 * (detachable devices only).
543 int __init SK_init(struct net_device *dev)
545 int ioaddr; /* I/O port address used for POS regs */
546 int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */
548 /* get preconfigured base_addr from dev which is done in Space.c */
549 int base_addr = dev->base_addr;
551 PRINTK(("%s: %s", SK_NAME, rcsid));
552 rcsid = NULL; /* We do not want to use this further */
554 if (base_addr > 0x0ff) /* Check a single specified address */
556 int rc = -ENODEV;
558 ioaddr = base_addr;
560 /* Check if on specified address is a SK_G16 */
561 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
562 return -EBUSY;
564 if ( (inb(SK_POS0) == SK_IDLOW) ||
565 (inb(SK_POS1) == SK_IDHIGH) )
567 rc = SK_probe(dev, ioaddr);
570 if (rc)
571 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
572 return rc;
574 else if (base_addr > 0) /* Don't probe at all */
576 return -ENXIO;
579 /* Autoprobe base_addr */
581 for (port = &ports[0]; *port; port++)
583 ioaddr = *port; /* we need ioaddr for accessing POS regs */
585 /* Check if I/O Port region is used by another board */
587 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
589 continue; /* Try next Port address */
592 /* Check if at ioaddr is a SK_G16 */
594 if ( !(inb(SK_POS0) == SK_IDLOW) ||
595 !(inb(SK_POS1) == SK_IDHIGH) )
597 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
598 continue; /* Try next Port address */
601 dev->base_addr = ioaddr; /* Set I/O Port Address */
603 if (SK_probe(dev, ioaddr) == 0)
605 return 0; /* Card found and initialized */
608 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
611 dev->base_addr = base_addr; /* Write back original base_addr */
613 return -ENODEV; /* Failed to find or init driver */
615 } /* End of SK_init */
618 MODULE_AUTHOR("Patrick J.D. Weichmann");
619 MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
620 MODULE_PARM(io, "i");
621 MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
624 #ifdef MODULE
625 static int io = 0; /* 0 == probe */
627 static int __init SK_init_module (void)
629 int rc;
631 SK_dev = init_etherdev (NULL, 0);
632 if (!SK_dev)
633 return -ENOMEM;
635 SK_dev->base_addr = io;
637 rc = SK_init (SK_dev);
638 if (rc) {
639 unregister_netdev (SK_dev);
640 kfree (SK_dev);
641 SK_dev = NULL;
644 return rc;
646 #endif /* MODULE */
649 static void __exit SK_cleanup_module (void)
651 if (SK_dev) {
652 if (SK_dev->priv) {
653 kfree(SK_dev->priv);
654 SK_dev->priv = NULL;
656 unregister_netdev(SK_dev);
657 kfree(SK_dev);
658 SK_dev = NULL;
660 if (SK_ioaddr) {
661 release_region(SK_ioaddr, ETHERCARD_TOTAL_SIZE);
662 SK_ioaddr = 0;
668 #ifdef MODULE
669 module_init(SK_init_module);
670 #endif
671 module_exit(SK_cleanup_module);
676 * Function : SK_probe
677 * Author : Patrick J.D. Weichmann
678 * Date Created : 94/05/26
680 * Description : This function is called by SK_init and
681 * does the main part of initialization.
683 * Parameters : I : struct net_device *dev - SK_G16 device structure
684 * I : short ioaddr - I/O Port address where POS is.
685 * Return Value : 0 = Initialization done
686 * Errors : ENODEV - No SK_G16 found
687 * -1 - Configuration problem
688 * Globals : board - pointer to SK_RAM
689 * Update History :
690 * YY/MM/DD uid Description
691 * 94/06/30 pwe SK_ADDR now checked and at the correct place
694 int __init SK_probe(struct net_device *dev, short ioaddr)
696 int i,j; /* Counters */
697 int sk_addr_flag = 0; /* SK ADDR correct? 1 - no, 0 - yes */
698 unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */
700 struct priv *p; /* SK_G16 private structure */
702 if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
705 sk_addr_flag = 1;
708 * Now here we could use a routine which searches for a free
709 * place in the ram and set SK_ADDR if found. TODO.
713 if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */
715 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
717 rom_addr = SK_rom_addr();
719 if (rom_addr == 0) /* No Boot_ROM found */
721 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
723 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
724 dev->name, SK_ADDR);
725 return -1;
728 rom_addr = SK_ADDR; /* assign predefined address */
730 PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
732 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
733 outb(POS_ADDR, SK_POS3); /* Set RAM address */
734 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
736 else if (rom_addr == SK_ADDR)
738 printk("%s: RAM + ROM are set to the same address %#08x\n"
739 " Check configuration. Now switching off Boot_ROM\n",
740 SK_NAME, rom_addr);
742 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
743 outb(POS_ADDR, SK_POS3); /* Set RAM address */
744 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
746 else
748 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
749 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
751 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
753 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
754 dev->name, SK_ADDR);
755 return -1;
758 rom_addr = SK_ADDR;
760 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
761 outb(POS_ADDR, SK_POS3); /* Set RAM address */
762 outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */
765 else /* Don't keep Boot_ROM */
767 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
769 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
771 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
772 dev->name, SK_ADDR);
773 return -1;
776 rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */
778 /* IF we find a Boot_ROM disable it */
780 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
782 /* We found a Boot_ROM and it's gone. Set RAM address on
783 * Boot_ROM address.
786 if (rom_addr)
788 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
789 "that address\n", SK_NAME, rom_addr);
791 outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */
793 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
795 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
797 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
798 dev->name, SK_ADDR);
799 return -1;
802 rom_addr = SK_ADDR;
804 outb(POS_ADDR, SK_POS3); /* Set RAM address */
806 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
809 #ifdef SK_DEBUG
810 SK_print_pos(dev, "POS registers after ROM, RAM config");
811 #endif
813 board = (SK_RAM *) bus_to_virt(rom_addr);
815 /* Read in station address */
816 for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
818 dev->dev_addr[i] = readb(board->rom+j);
821 /* Check for manufacturer code */
822 if (!(dev->dev_addr[0] == SK_MAC0 &&
823 dev->dev_addr[1] == SK_MAC1 &&
824 dev->dev_addr[2] == SK_MAC2) )
826 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
827 SK_NAME));
828 return -ENODEV; /* NO SK_G16 found */
831 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
832 dev->name,
833 "Schneider & Koch Netcard",
834 (unsigned int) dev->base_addr,
835 dev->dev_addr[0],
836 dev->dev_addr[1],
837 dev->dev_addr[2],
838 dev->dev_addr[3],
839 dev->dev_addr[4],
840 dev->dev_addr[5]);
842 /* Allocate memory for private structure */
843 p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
844 if (p == NULL) {
845 printk("%s: ERROR - no memory for driver data!\n", dev->name);
846 return -ENOMEM;
848 memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
850 /* Assign our Device Driver functions */
852 dev->open = SK_open;
853 dev->stop = SK_close;
854 dev->hard_start_xmit = SK_send_packet;
855 dev->get_stats = SK_get_stats;
856 dev->set_multicast_list = set_multicast_list;
857 dev->tx_timeout = SK_timeout;
858 dev->watchdog_timeo = HZ/7;
861 /* Set the generic fields of the device structure */
863 ether_setup(dev);
865 dev->flags &= ~IFF_MULTICAST;
867 /* Initialize private structure */
869 p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
870 p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */
871 p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */
873 /* Initialize buffer pointers */
875 for (i = 0; i < TMDNUM; i++)
877 p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
880 for (i = 0; i < RMDNUM; i++)
882 p->rmdbufs[i] = &(p->ram)->rmdbuf[i];
885 #ifdef SK_DEBUG
886 SK_print_pos(dev, "End of SK_probe");
887 SK_print_ram(dev);
888 #endif
890 SK_dev = dev;
891 SK_ioaddr = ioaddr;
893 return 0; /* Initialization done */
895 } /* End of SK_probe() */
898 /*-
899 * Function : SK_open
900 * Author : Patrick J.D. Weichmann
901 * Date Created : 94/05/26
903 * Description : This function is called sometimes after booting
904 * when ifconfig program is run.
906 * This function requests an IRQ, sets the correct
907 * IRQ in the card. Then calls SK_lance_init() to
908 * init and start the LANCE chip. Then if everything is
909 * ok returns with 0 (OK), which means SK_G16 is now
910 * opened and operational.
912 * (Called by dev_open() /net/inet/dev.c)
914 * Parameters : I : struct net_device *dev - SK_G16 device structure
915 * Return Value : 0 - Device opened
916 * Errors : -EAGAIN - Open failed
917 * Side Effects : None
918 * Update History :
919 * YY/MM/DD uid Description
922 static int SK_open(struct net_device *dev)
924 int i = 0;
925 int irqval = 0;
926 int ioaddr = dev->base_addr;
928 int irqtab[] = SK_IRQS;
930 struct priv *p = (struct priv *)dev->priv;
932 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
933 SK_NAME, SK_read_reg(CSR0)));
935 if (dev->irq == 0) /* Autoirq */
937 i = 0;
940 * Check if one IRQ out of SK_IRQS is free and install
941 * interrupt handler.
942 * Most done by request_irq().
943 * irqval: 0 - interrupt handler installed for IRQ irqtab[i]
944 * -EBUSY - interrupt busy
945 * -EINVAL - irq > 15 or handler = NULL
950 irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
951 i++;
952 } while (irqval && irqtab[i]);
954 if (irqval) /* We tried every possible IRQ but no success */
956 printk("%s: unable to get an IRQ\n", dev->name);
957 return -EAGAIN;
960 dev->irq = irqtab[--i];
962 outb(i<<2, SK_POS4); /* Set Card on probed IRQ */
965 else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
967 if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
969 printk("%s: unable to get IRQ 9\n", dev->name);
970 return -EAGAIN;
972 dev->irq = 9;
975 * Now we set card on IRQ2.
976 * This can be confusing, but remember that IRQ2 on the network
977 * card is in reality IRQ9
979 outb(0x08, SK_POS4); /* set card to IRQ2 */
982 else /* Check IRQ as defined in Space.c */
984 int i = 0;
986 /* check if IRQ free and valid. Then install Interrupt handler */
988 if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
990 printk("%s: unable to get selected IRQ\n", dev->name);
991 return -EAGAIN;
994 switch(dev->irq)
996 case 3: i = 0;
997 break;
998 case 5: i = 1;
999 break;
1000 case 2: i = 2;
1001 break;
1002 case 11:i = 3;
1003 break;
1004 default:
1005 printk("%s: Preselected IRQ %d is invalid for %s boards",
1006 dev->name,
1007 dev->irq,
1008 SK_NAME);
1009 return -EAGAIN;
1012 outb(i<<2, SK_POS4); /* Set IRQ on card */
1015 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
1016 dev->name, (unsigned int)dev->base_addr,
1017 (int) dev->irq, (unsigned int) p->ram);
1019 if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */
1021 netif_start_queue(dev);
1023 #ifdef SK_DEBUG
1026 * This debug block tries to stop LANCE,
1027 * reinit LANCE with transmitter and receiver disabled,
1028 * then stop again and reinit with NORMAL_MODE
1031 printk("## %s: After lance init. CSR0: %#06x\n",
1032 SK_NAME, SK_read_reg(CSR0));
1033 SK_write_reg(CSR0, CSR0_STOP);
1034 printk("## %s: LANCE stopped. CSR0: %#06x\n",
1035 SK_NAME, SK_read_reg(CSR0));
1036 SK_lance_init(dev, MODE_DTX | MODE_DRX);
1037 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n",
1038 SK_NAME, SK_read_reg(CSR0));
1039 SK_write_reg(CSR0, CSR0_STOP);
1040 printk("## %s: LANCE stopped. CSR0: %#06x\n",
1041 SK_NAME, SK_read_reg(CSR0));
1042 SK_lance_init(dev, MODE_NORMAL);
1043 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n",
1044 SK_NAME, SK_read_reg(CSR0));
1045 SK_print_pos(dev, "POS regs before returning OK");
1047 #endif /* SK_DEBUG */
1049 return 0; /* SK_open() is successful */
1051 else /* LANCE init failed */
1054 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
1055 SK_NAME, SK_read_reg(CSR0)));
1057 return -EAGAIN;
1060 } /* End of SK_open() */
1064 * Function : SK_lance_init
1065 * Author : Patrick J.D. Weichmann
1066 * Date Created : 94/05/26
1068 * Description : Reset LANCE chip, fill RMD, TMD structures with
1069 * start values and Start LANCE.
1071 * Parameters : I : struct net_device *dev - SK_G16 device structure
1072 * I : int mode - put LANCE into "mode" see data-sheet for
1073 * more info.
1074 * Return Value : 0 - Init done
1075 * Errors : -1 - Init failed
1076 * Update History :
1077 * YY/MM/DD uid Description
1080 static int SK_lance_init(struct net_device *dev, unsigned short mode)
1082 int i;
1083 unsigned long flags;
1084 struct priv *p = (struct priv *) dev->priv;
1085 struct tmd *tmdp;
1086 struct rmd *rmdp;
1088 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1089 SK_NAME, SK_read_reg(CSR0)));
1091 /* Reset LANCE */
1092 SK_reset_board();
1094 /* Initialize TMD's with start values */
1095 p->tmdnum = 0; /* First descriptor for transmitting */
1096 p->tmdlast = 0; /* First descriptor for reading stats */
1098 for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
1100 tmdp = p->tmdhead + i;
1102 writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
1104 /* Mark TMD as start and end of packet */
1105 writeb(TX_STP | TX_ENP, tmdp->u.s.status);
1109 /* Initialize RMD's with start values */
1111 p->rmdnum = 0; /* First RMD which will be used */
1113 for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
1115 rmdp = p->rmdhead + i;
1118 writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
1121 * LANCE must be owner at beginning so that he can fill in
1122 * receiving packets, set status and release RMD
1125 writeb(RX_OWN, rmdp->u.s.status);
1127 writew(-PKT_BUF_SZ, rmdp->blen); /* Buffer Size (two's complement) */
1129 writeb(0, rmdp->mlen); /* init message length */
1133 /* Fill LANCE Initialize Block */
1135 writew(mode, (p->ram)->ib.mode); /* Set operation mode */
1137 for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
1139 writeb(dev->dev_addr[i], (p->ram)->ib.paddr[i]);
1142 for (i = 0; i < 8; i++) /* Set multicast, logical address */
1144 writeb(0, (p->ram)->ib.laddr[i]); /* We do not use logical addressing */
1147 /* Set ring descriptor pointers and set number of descriptors */
1149 writel((int)p->rmdhead | RMDNUMMASK, (p->ram)->ib.rdrp);
1150 writel((int)p->tmdhead | TMDNUMMASK, (p->ram)->ib.tdrp);
1152 /* Prepare LANCE Control and Status Registers */
1154 spin_lock_irqsave(&SK_lock, flags);
1156 SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
1159 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1160 * PC Memory locations.
1162 * In structure SK_ram is defined that the first thing in ram
1163 * is the initialization block. So his address is for LANCE always
1164 * 0x0000
1166 * CSR1 contains low order bits 15:0 of initialization block address
1167 * CSR2 is built of:
1168 * 7:0 High order bits 23:16 of initialization block address
1169 * 15:8 reserved, must be 0
1172 /* Set initialization block address (must be on word boundary) */
1173 SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */
1174 SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */
1177 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
1178 SK_NAME, SK_read_reg(CSR0)));
1180 /* Initialize LANCE */
1183 * INIT = Initialize, when set, causes the LANCE to begin the
1184 * initialization procedure and access the Init Block.
1187 SK_write_reg(CSR0, CSR0_INIT);
1189 spin_unlock_irqrestore(&SK_lock, flags);
1191 /* Wait until LANCE finished initialization */
1193 SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
1195 for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
1196 ; /* Wait until init done or go ahead if problems (i>=100) */
1198 if (i >= 100) /* Something is wrong ! */
1200 printk("%s: can't init am7990, status: %04x "
1201 "init_block: %#08x\n",
1202 dev->name, (int) SK_read_reg(CSR0),
1203 (unsigned int) &(p->ram)->ib);
1205 #ifdef SK_DEBUG
1206 SK_print_pos(dev, "LANCE INIT failed");
1207 SK_print_dev(dev,"Device Structure:");
1208 #endif
1210 return -1; /* LANCE init failed */
1213 PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
1215 /* Clear Initialize done, enable Interrupts, start LANCE */
1217 SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
1219 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME,
1220 SK_read_reg(CSR0)));
1222 return 0; /* LANCE is up and running */
1224 } /* End of SK_lance_init() */
1229 * Function : SK_send_packet
1230 * Author : Patrick J.D. Weichmann
1231 * Date Created : 94/05/27
1233 * Description : Writes an socket buffer into a transmit descriptor
1234 * and starts transmission.
1236 * Parameters : I : struct sk_buff *skb - packet to transfer
1237 * I : struct net_device *dev - SK_G16 device structure
1238 * Return Value : 0 - OK
1239 * 1 - Could not transmit (dev_queue_xmit will queue it)
1240 * and try to sent it later
1241 * Globals : None
1242 * Side Effects : None
1243 * Update History :
1244 * YY/MM/DD uid Description
1247 static void SK_timeout(struct net_device *dev)
1249 printk(KERN_WARNING "%s: xmitter timed out, try to restart!\n", dev->name);
1250 SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
1251 netif_start_queue(dev); /* Clear Transmitter flag */
1252 dev->trans_start = jiffies; /* Mark Start of transmission */
1255 static int SK_send_packet(struct sk_buff *skb, struct net_device *dev)
1257 struct priv *p = (struct priv *) dev->priv;
1258 struct tmd *tmdp;
1260 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1261 SK_NAME, SK_read_reg(CSR0)));
1265 * Block a timer-based transmit from overlapping.
1266 * This means check if we are already in.
1269 netif_stop_queue (dev);
1273 /* Evaluate Packet length */
1274 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1276 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1278 /* Fill in Transmit Message Descriptor */
1280 /* Copy data into dual ported ram */
1282 memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
1284 writew(-len, tmdp->blen); /* set length to transmit */
1287 * Packet start and end is always set because we use the maximum
1288 * packet length as buffer length.
1289 * Relinquish ownership to LANCE
1292 writeb(TX_OWN | TX_STP | TX_ENP, tmdp->u.s.status);
1294 /* Start Demand Transmission */
1295 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1297 dev->trans_start = jiffies; /* Mark start of transmission */
1299 /* Set pointer to next transmit buffer */
1300 p->tmdnum++;
1301 p->tmdnum &= TMDNUM-1;
1303 /* Do we own the next transmit buffer ? */
1304 if (! (readb((p->tmdhead + p->tmdnum)->u.s.status) & TX_OWN) )
1307 * We own next buffer and are ready to transmit, so
1308 * clear busy flag
1310 netif_start_queue(dev);
1313 p->stats.tx_bytes += skb->len;
1317 dev_kfree_skb(skb);
1318 return 0;
1319 } /* End of SK_send_packet */
1323 * Function : SK_interrupt
1324 * Author : Patrick J.D. Weichmann
1325 * Date Created : 94/05/27
1327 * Description : SK_G16 interrupt handler which checks for LANCE
1328 * Errors, handles transmit and receive interrupts
1330 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1331 * Return Value : None
1332 * Errors : None
1333 * Globals : None
1334 * Side Effects : None
1335 * Update History :
1336 * YY/MM/DD uid Description
1339 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1341 int csr0;
1342 struct net_device *dev = dev_id;
1343 struct priv *p = (struct priv *) dev->priv;
1346 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1347 SK_NAME, SK_read_reg(CSR0)));
1349 if (dev == NULL)
1351 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1354 spin_lock (&SK_lock);
1356 csr0 = SK_read_reg(CSR0); /* store register for checking */
1359 * Acknowledge all of the current interrupt sources, disable
1360 * Interrupts (INEA = 0)
1363 SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
1365 if (csr0 & CSR0_ERR) /* LANCE Error */
1367 printk("%s: error: %04x\n", dev->name, csr0);
1369 if (csr0 & CSR0_MISS) /* No place to store packet ? */
1371 p->stats.rx_dropped++;
1375 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */
1377 SK_rxintr(dev);
1380 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */
1382 SK_txintr(dev);
1385 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1387 spin_unlock (&SK_lock);
1388 } /* End of SK_interrupt() */
1392 * Function : SK_txintr
1393 * Author : Patrick J.D. Weichmann
1394 * Date Created : 94/05/27
1396 * Description : After sending a packet we check status, update
1397 * statistics and relinquish ownership of transmit
1398 * descriptor ring.
1400 * Parameters : I : struct net_device *dev - SK_G16 device structure
1401 * Return Value : None
1402 * Errors : None
1403 * Globals : None
1404 * Update History :
1405 * YY/MM/DD uid Description
1408 static void SK_txintr(struct net_device *dev)
1410 int tmdstat;
1411 struct tmd *tmdp;
1412 struct priv *p = (struct priv *) dev->priv;
1415 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1416 SK_NAME, SK_read_reg(CSR0)));
1418 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */
1420 /* Set next buffer */
1421 p->tmdlast++;
1422 p->tmdlast &= TMDNUM-1;
1424 tmdstat = readb(tmdp->u.s.status);
1427 * We check status of transmitted packet.
1428 * see LANCE data-sheet for error explanation
1430 if (tmdstat & TX_ERR) /* Error occurred */
1432 int stat2 = readw(tmdp->status2);
1434 printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
1436 if (stat2 & TX_TDR) /* TDR problems? */
1438 printk("%s: tdr-problems \n", dev->name);
1441 if (stat2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */
1442 p->stats.tx_aborted_errors++;
1443 if (stat2 & TX_LCOL) /* Late collision ? */
1444 p->stats.tx_window_errors++;
1445 if (stat2 & TX_LCAR) /* Loss of Carrier ? */
1446 p->stats.tx_carrier_errors++;
1447 if (stat2 & TX_UFLO) /* Underflow error ? */
1449 p->stats.tx_fifo_errors++;
1452 * If UFLO error occurs it will turn transmitter of.
1453 * So we must reinit LANCE
1456 SK_lance_init(dev, MODE_NORMAL);
1459 p->stats.tx_errors++;
1461 writew(0, tmdp->status2); /* Clear error flags */
1463 else if (tmdstat & TX_MORE) /* Collisions occurred ? */
1466 * Here I have a problem.
1467 * I only know that there must be one or up to 15 collisions.
1468 * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1469 * will be set which means couldn't send packet aborted transfer.
1471 * First I did not have this in but then I thought at minimum
1472 * we see that something was not ok.
1473 * If anyone knows something better than this to handle this
1474 * please report it.
1477 p->stats.collisions++;
1479 else /* Packet sent without any problems */
1481 p->stats.tx_packets++;
1485 * We mark transmitter not busy anymore, because now we have a free
1486 * transmit descriptor which can be filled by SK_send_packet and
1487 * afterwards sent by the LANCE
1489 * The function which do handle slow IRQ parts is do_bottom_half()
1490 * which runs at normal kernel priority, that means all interrupt are
1491 * enabled. (see kernel/irq.c)
1493 * net_bh does something like this:
1494 * - check if already in net_bh
1495 * - try to transmit something from the send queue
1496 * - if something is in the receive queue send it up to higher
1497 * levels if it is a known protocol
1498 * - try to transmit something from the send queue
1501 netif_wake_queue(dev);
1503 } /* End of SK_txintr() */
1507 * Function : SK_rxintr
1508 * Author : Patrick J.D. Weichmann
1509 * Date Created : 94/05/27
1511 * Description : Buffer sent, check for errors, relinquish ownership
1512 * of the receive message descriptor.
1514 * Parameters : I : SK_G16 device structure
1515 * Return Value : None
1516 * Globals : None
1517 * Update History :
1518 * YY/MM/DD uid Description
1521 static void SK_rxintr(struct net_device *dev)
1524 struct rmd *rmdp;
1525 int rmdstat;
1526 struct priv *p = (struct priv *) dev->priv;
1528 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1529 SK_NAME, SK_read_reg(CSR0)));
1531 rmdp = p->rmdhead + p->rmdnum;
1533 /* As long as we own the next entry, check status and send
1534 * it up to higher layer
1537 while (!( (rmdstat = readb(rmdp->u.s.status)) & RX_OWN))
1540 * Start and end of packet must be set, because we use
1541 * the ethernet maximum packet length (1518) as buffer size.
1543 * Because our buffers are at maximum OFLO and BUFF errors are
1544 * not to be concerned (see Data sheet)
1547 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
1549 /* Start of a frame > 1518 Bytes ? */
1551 if (rmdstat & RX_STP)
1553 p->stats.rx_errors++; /* bad packet received */
1554 p->stats.rx_length_errors++; /* packet too long */
1556 printk("%s: packet too long\n", dev->name);
1560 * All other packets will be ignored until a new frame with
1561 * start (RX_STP) set follows.
1563 * What we do is just give descriptor free for new incoming
1564 * packets.
1567 writeb(RX_OWN, rmdp->u.s.status); /* Relinquish ownership to LANCE */
1570 else if (rmdstat & RX_ERR) /* Receive Error ? */
1572 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1574 p->stats.rx_errors++;
1576 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1577 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++;
1579 writeb(RX_OWN, rmdp->u.s.status); /* Relinquish ownership to LANCE */
1582 else /* We have a packet which can be queued for the upper layers */
1585 int len = readw(rmdp->mlen) & 0x0fff; /* extract message length from receive buffer */
1586 struct sk_buff *skb;
1588 skb = dev_alloc_skb(len+2); /* allocate socket buffer */
1590 if (skb == NULL) /* Could not get mem ? */
1594 * Couldn't allocate sk_buffer so we give descriptor back
1595 * to Lance, update statistics and go ahead.
1598 writeb(RX_OWN, rmdp->u.s.status); /* Relinquish ownership to LANCE */
1599 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1600 dev->name);
1601 p->stats.rx_dropped++;
1603 break; /* Jump out */
1606 /* Prepare sk_buff to queue for upper layers */
1608 skb->dev = dev;
1609 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */
1612 * Copy data out of our receive descriptor into sk_buff.
1614 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1615 * ignore status fields)
1618 memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
1622 * Notify the upper protocol layers that there is another packet
1623 * to handle
1625 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1628 skb->protocol=eth_type_trans(skb,dev);
1629 netif_rx(skb); /* queue packet and mark it for processing */
1632 * Packet is queued and marked for processing so we
1633 * free our descriptor and update statistics
1636 writeb(RX_OWN, rmdp->u.s.status);
1637 p->stats.rx_packets++;
1638 p->stats.rx_bytes += len;
1641 p->rmdnum++;
1642 p->rmdnum %= RMDNUM;
1644 rmdp = p->rmdhead + p->rmdnum;
1647 } /* End of SK_rxintr() */
1651 * Function : SK_close
1652 * Author : Patrick J.D. Weichmann
1653 * Date Created : 94/05/26
1655 * Description : close gets called from dev_close() and should
1656 * deinstall the card (free_irq, mem etc).
1658 * Parameters : I : struct net_device *dev - our device structure
1659 * Return Value : 0 - closed device driver
1660 * Errors : None
1661 * Globals : None
1662 * Update History :
1663 * YY/MM/DD uid Description
1666 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1667 * down' the system stops. So I don't shut set card to init state.
1670 static int SK_close(struct net_device *dev)
1673 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1674 SK_NAME, SK_read_reg(CSR0)));
1676 netif_stop_queue(dev); /* Transmitter busy */
1678 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,
1679 (int) SK_read_reg(CSR0));
1681 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1683 free_irq(dev->irq, dev); /* Free IRQ */
1685 return 0; /* always succeed */
1687 } /* End of SK_close() */
1691 * Function : SK_get_stats
1692 * Author : Patrick J.D. Weichmann
1693 * Date Created : 94/05/26
1695 * Description : Return current status structure to upper layers.
1696 * It is called by sprintf_stats (dev.c).
1698 * Parameters : I : struct net_device *dev - our device structure
1699 * Return Value : struct net_device_stats * - our current statistics
1700 * Errors : None
1701 * Side Effects : None
1702 * Update History :
1703 * YY/MM/DD uid Description
1706 static struct net_device_stats *SK_get_stats(struct net_device *dev)
1709 struct priv *p = (struct priv *) dev->priv;
1711 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1712 SK_NAME, SK_read_reg(CSR0)));
1714 return &p->stats; /* Return Device status */
1716 } /* End of SK_get_stats() */
1720 * Function : set_multicast_list
1721 * Author : Patrick J.D. Weichmann
1722 * Date Created : 94/05/26
1724 * Description : This function gets called when a program performs
1725 * a SIOCSIFFLAGS call. Ifconfig does this if you call
1726 * 'ifconfig [-]allmulti' which enables or disables the
1727 * Promiscuous mode.
1728 * Promiscuous mode is when the Network card accepts all
1729 * packets, not only the packets which match our MAC
1730 * Address. It is useful for writing a network monitor,
1731 * but it is also a security problem. You have to remember
1732 * that all information on the net is not encrypted.
1734 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1735 * Return Value : None
1736 * Errors : None
1737 * Globals : None
1738 * Update History :
1739 * YY/MM/DD uid Description
1740 * 95/10/18 ACox New multicast calling scheme
1744 /* Set or clear the multicast filter for SK_G16.
1747 static void set_multicast_list(struct net_device *dev)
1750 if (dev->flags&IFF_PROMISC)
1752 /* Reinitialize LANCE with MODE_PROM set */
1753 SK_lance_init(dev, MODE_PROM);
1755 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
1757 /* Reinitialize LANCE without MODE_PROM */
1758 SK_lance_init(dev, MODE_NORMAL);
1760 else
1762 /* Multicast with logical address filter on */
1763 /* Reinitialize LANCE without MODE_PROM */
1764 SK_lance_init(dev, MODE_NORMAL);
1766 /* Not implemented yet. */
1768 } /* End of set_multicast_list() */
1773 * Function : SK_rom_addr
1774 * Author : Patrick J.D. Weichmann
1775 * Date Created : 94/06/01
1777 * Description : Try to find a Boot_ROM at all possible locations
1779 * Parameters : None
1780 * Return Value : Address where Boot_ROM is
1781 * Errors : 0 - Did not find Boot_ROM
1782 * Globals : None
1783 * Update History :
1784 * YY/MM/DD uid Description
1787 unsigned int __init SK_rom_addr(void)
1789 int i,j;
1790 int rom_found = 0;
1791 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1792 unsigned char rom_id[] = SK_BOOT_ROM_ID;
1793 unsigned char test_byte;
1795 /* Autodetect Boot_ROM */
1796 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1798 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1801 PRINTK(("## Trying ROM location %#08x", rom_location[i]));
1803 rom_found = 1;
1804 for (j = 0; j < 6; j++)
1806 test_byte = readb(rom_location[i]+j);
1807 PRINTK((" %02x ", *test_byte));
1809 if(test_byte != rom_id[j])
1811 rom_found = 0;
1814 PRINTK(("\n"));
1817 if (rom_found == 1)
1819 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1820 SK_NAME, rom_location[(i-1)]));
1822 return (rom_location[--i]);
1824 else
1826 PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1827 return 0;
1829 } /* End of SK_rom_addr() */
1833 /* LANCE access functions
1835 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1840 * Function : SK_reset_board
1842 * Author : Patrick J.D. Weichmann
1844 * Date Created : 94/05/25
1846 * Description : This function resets SK_G16 and all components, but
1847 * POS registers are not changed
1849 * Parameters : None
1850 * Return Value : None
1851 * Errors : None
1852 * Globals : SK_RAM *board - SK_RAM structure pointer
1854 * Update History :
1855 * YY/MM/DD uid Description
1858 void SK_reset_board(void)
1860 writeb(0x00, SK_PORT); /* Reset active */
1861 mdelay(5); /* Delay min 5ms */
1862 writeb(SK_RESET, SK_PORT); /* Set back to normal operation */
1864 } /* End of SK_reset_board() */
1868 * Function : SK_set_RAP
1869 * Author : Patrick J.D. Weichmann
1870 * Date Created : 94/05/25
1872 * Description : Set LANCE Register Address Port to register
1873 * for later data transfer.
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
1883 void SK_set_RAP(int reg_number)
1885 writew(reg_number, SK_IOREG);
1886 writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
1887 writeb(SK_DOIO, SK_IOCOM);
1889 while (readb(SK_PORT) & SK_IORUN)
1890 barrier();
1891 } /* End of SK_set_RAP() */
1895 * Function : SK_read_reg
1896 * Author : Patrick J.D. Weichmann
1897 * Date Created : 94/05/25
1899 * Description : Set RAP and read data from a LANCE CSR register
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
1909 int SK_read_reg(int reg_number)
1911 SK_set_RAP(reg_number);
1913 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1914 writeb(SK_DOIO, SK_IOCOM);
1916 while (readb(SK_PORT) & SK_IORUN)
1917 barrier();
1918 return (readw(SK_IOREG));
1920 } /* End of SK_read_reg() */
1924 * Function : SK_rread_reg
1925 * Author : Patrick J.D. Weichmann
1926 * Date Created : 94/05/28
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.
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
1940 int SK_rread_reg(void)
1942 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1944 writeb(SK_DOIO, SK_IOCOM);
1946 while (readb(SK_PORT) & SK_IORUN)
1947 barrier();
1948 return (readw(SK_IOREG));
1950 } /* End of SK_rread_reg() */
1954 * Function : SK_write_reg
1955 * Author : Patrick J.D. Weichmann
1956 * Date Created : 94/05/25
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.
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
1972 void SK_write_reg(int reg_number, int value)
1974 SK_set_RAP(reg_number);
1976 writew(value, SK_IOREG);
1977 writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
1978 writeb(SK_DOIO, SK_IOCOM);
1980 while (readb(SK_PORT) & SK_IORUN)
1981 barrier();
1982 } /* End of SK_write_reg */
1987 * Debugging functions
1988 * -------------------
1992 * Function : SK_print_pos
1993 * Author : Patrick J.D. Weichmann
1994 * Date Created : 94/05/25
1996 * Description : This function prints out the 4 POS (Programmable
1997 * Option Select) Registers. Used mainly to debug operation.
1999 * Parameters : I : struct net_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
2007 void SK_print_pos(struct net_device *dev, char *text)
2009 int ioaddr = dev->base_addr;
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);
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);
2022 } /* End of SK_print_pos() */
2027 * Function : SK_print_dev
2028 * Author : Patrick J.D. Weichmann
2029 * Date Created : 94/05/25
2031 * Description : This function simply prints out the important fields
2032 * of the device structure.
2034 * Parameters : I : struct net_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
2042 void SK_print_dev(struct net_device *dev, char *text)
2044 if (dev == NULL)
2046 printk("## %s: Device Structure. %s\n", SK_NAME, text);
2047 printk("## DEVICE == NULL\n");
2049 else
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);
2055 printk("## next device: %#08x init function: %#08x\n",
2056 (int) dev->next, (int) dev->init);
2059 } /* End of SK_print_dev() */
2064 * Function : SK_print_ram
2065 * Author : Patrick J.D. Weichmann
2066 * Date Created : 94/06/02
2068 * Description : This function is used to check how are things set up
2069 * in the 16KB RAM. Also the pointers to the receive and
2070 * transmit descriptor rings and rx and tx buffers locations.
2071 * It contains a minor bug in printing, but has no effect to the values
2072 * only newlines are not correct.
2074 * Parameters : I : struct net_device *dev - SK_G16 device structure
2075 * Return Value : None
2076 * Errors : None
2077 * Globals : None
2078 * Update History :
2079 * YY/MM/DD uid Description
2082 void SK_print_ram(struct net_device *dev)
2085 int i;
2086 struct priv *p = (struct priv *) dev->priv;
2088 printk("## %s: RAM Details.\n"
2089 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2090 SK_NAME,
2091 (unsigned int) p->ram,
2092 (unsigned int) p->tmdhead,
2093 (unsigned int) p->rmdhead,
2094 (unsigned int) &(p->ram)->ib);
2096 printk("## ");
2098 for(i = 0; i < TMDNUM; i++)
2100 if (!(i % 3)) /* Every third line do a newline */
2102 printk("\n## ");
2104 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2106 printk("## ");
2108 for(i = 0; i < RMDNUM; i++)
2110 if (!(i % 3)) /* Every third line do a newline */
2112 printk("\n## ");
2114 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2116 printk("\n");
2118 } /* End of SK_print_ram() */