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 General Public License, incorporated herein by reference.
9 * Version : $Revision: 1.1.1.1 $
11 * Author : Patrick J.D. Weichmann
13 * Date Created : 94/05/26
14 * Last Updated : $Date: 2005/04/11 02:50:28 $
16 * Description : Schneider & Koch G16 Ethernet Device Driver for
17 * Linux Kernel >= 1.1.22
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
26 static const char rcsid[] = "$Id: sk_g16.c,v 1.1.1.1 2005/04/11 02:50:28 jack 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)
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
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/slab.h>
69 #include <linux/string.h>
70 #include <linux/delay.h>
71 #include <asm/system.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>
85 * Schneider & Koch Card Definitions
86 * =================================
89 #define SK_NAME "SK_G16"
92 * SK_G16 Configuration
93 * --------------------
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
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
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 */
178 * Scheider & Koch manufacturer code (00:00:a5).
179 * This must be checked, that we are sure it is a SK card.
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
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 */
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.
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;
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
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
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 */
359 #define PRINTK(x) printk x
361 #define PRINTK(x) /**/
365 #define PRINTK2(x) printk x
367 #define PRINTK2(x) /**/
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
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.
400 * Any bitcombination written in here starts the transmission between
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 */
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.
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.
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;
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);
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);
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
527 * Return Value : 0 = Driver Found and initialized
528 * Errors : ENODEV - no device found
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.
541 int __init SK_init(struct net_device *dev)
543 int ioaddr; /* I/O port address used for POS regs */
544 int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */
545 static unsigned version_printed;
547 /* get preconfigured base_addr from dev which is done in Space.c */
548 int base_addr = dev->base_addr;
550 if (version_printed++ == 0)
551 PRINTK(("%s: %s", SK_NAME, rcsid));
553 if (base_addr > 0x0ff) /* Check a single specified address */
559 /* Check if on specified address is a SK_G16 */
560 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
563 if ( (inb(SK_POS0) == SK_IDLOW) ||
564 (inb(SK_POS1) == SK_IDHIGH) )
566 rc = SK_probe(dev, ioaddr);
570 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
573 else if (base_addr > 0) /* Don't probe at all */
578 /* Autoprobe base_addr */
580 for (port = &ports[0]; *port; port++)
582 ioaddr = *port; /* we need ioaddr for accessing POS regs */
584 /* Check if I/O Port region is used by another board */
586 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
588 continue; /* Try next Port address */
591 /* Check if at ioaddr is a SK_G16 */
593 if ( !(inb(SK_POS0) == SK_IDLOW) ||
594 !(inb(SK_POS1) == SK_IDHIGH) )
596 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
597 continue; /* Try next Port address */
600 dev->base_addr = ioaddr; /* Set I/O Port Address */
602 if (SK_probe(dev, ioaddr) == 0)
604 return 0; /* Card found and initialized */
607 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
610 dev->base_addr = base_addr; /* Write back original base_addr */
612 return -ENODEV; /* Failed to find or init driver */
614 } /* End of SK_init */
617 MODULE_AUTHOR("Patrick J.D. Weichmann");
618 MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
619 MODULE_LICENSE("GPL");
620 MODULE_PARM(io, "i");
621 MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
625 static int io; /* 0 == probe */
627 static int __init SK_init_module (void)
631 SK_dev = init_etherdev (NULL, 0);
635 SK_dev->base_addr = io;
637 rc = SK_init (SK_dev);
639 unregister_netdev (SK_dev);
649 static void __exit SK_cleanup_module (void)
656 unregister_netdev(SK_dev);
661 release_region(SK_ioaddr, ETHERCARD_TOTAL_SIZE);
669 module_init(SK_init_module);
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
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)
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",
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",
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 */
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",
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",
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
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",
804 outb(POS_ADDR, SK_POS3); /* Set RAM address */
806 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
810 SK_print_pos(dev, "POS registers after ROM, RAM config");
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",
828 return -ENODEV; /* NO SK_G16 found */
831 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
833 "Schneider & Koch Netcard",
834 (unsigned int) dev->base_addr,
842 /* Allocate memory for private structure */
843 p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
845 printk("%s: ERROR - no memory for driver data!\n", dev->name);
848 memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
850 /* Assign our Device Driver functions */
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 */
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];
886 SK_print_pos(dev, "End of SK_probe");
893 return 0; /* Initialization done */
895 } /* End of SK_probe() */
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
919 * YY/MM/DD uid Description
922 static int SK_open(struct net_device *dev)
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 */
940 * Check if one IRQ out of SK_IRQS is free and install
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);
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);
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);
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 */
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);
1005 printk("%s: Preselected IRQ %d is invalid for %s boards",
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);
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)));
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
1074 * Return Value : 0 - Init done
1075 * Errors : -1 - Init failed
1077 * YY/MM/DD uid Description
1080 static int SK_lance_init(struct net_device *dev, unsigned short mode)
1083 unsigned long flags;
1084 struct priv *p = (struct priv *) dev->priv;
1088 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1089 SK_NAME, SK_read_reg(CSR0)));
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
1166 * CSR1 contains low order bits 15:0 of initialization block address
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);
1206 SK_print_pos(dev, "LANCE INIT failed");
1207 SK_print_dev(dev,"Device Structure:");
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
1242 * Side Effects : None
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_wake_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;
1259 static char pad[64];
1261 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1262 SK_NAME, SK_read_reg(CSR0)));
1266 * Block a timer-based transmit from overlapping.
1267 * This means check if we are already in.
1270 netif_stop_queue (dev);
1274 /* Evaluate Packet length */
1275 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1277 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1279 /* Fill in Transmit Message Descriptor */
1281 /* Copy data into dual ported ram */
1283 memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
1285 memcpy_toio((tmdp->u.buffer & 0x00ffffff) + sb->len, pad, len-skb->len);
1287 writew(-len, &tmdp->blen); /* set length to transmit */
1290 * Packet start and end is always set because we use the maximum
1291 * packet length as buffer length.
1292 * Relinquish ownership to LANCE
1295 writeb(TX_OWN | TX_STP | TX_ENP, &tmdp->u.s.status);
1297 /* Start Demand Transmission */
1298 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1300 dev->trans_start = jiffies; /* Mark start of transmission */
1302 /* Set pointer to next transmit buffer */
1304 p->tmdnum &= TMDNUM-1;
1306 /* Do we own the next transmit buffer ? */
1307 if (! (readb(&((p->tmdhead + p->tmdnum)->u.s.status)) & TX_OWN) )
1310 * We own next buffer and are ready to transmit, so
1313 netif_start_queue(dev);
1316 p->stats.tx_bytes += skb->len;
1322 } /* End of SK_send_packet */
1326 * Function : SK_interrupt
1327 * Author : Patrick J.D. Weichmann
1328 * Date Created : 94/05/27
1330 * Description : SK_G16 interrupt handler which checks for LANCE
1331 * Errors, handles transmit and receive interrupts
1333 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1334 * Return Value : None
1337 * Side Effects : None
1339 * YY/MM/DD uid Description
1342 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1345 struct net_device *dev = dev_id;
1346 struct priv *p = (struct priv *) dev->priv;
1349 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1350 SK_NAME, SK_read_reg(CSR0)));
1354 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1357 spin_lock (&SK_lock);
1359 csr0 = SK_read_reg(CSR0); /* store register for checking */
1362 * Acknowledge all of the current interrupt sources, disable
1363 * Interrupts (INEA = 0)
1366 SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
1368 if (csr0 & CSR0_ERR) /* LANCE Error */
1370 printk("%s: error: %04x\n", dev->name, csr0);
1372 if (csr0 & CSR0_MISS) /* No place to store packet ? */
1374 p->stats.rx_dropped++;
1378 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */
1383 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */
1388 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1390 spin_unlock (&SK_lock);
1391 } /* End of SK_interrupt() */
1395 * Function : SK_txintr
1396 * Author : Patrick J.D. Weichmann
1397 * Date Created : 94/05/27
1399 * Description : After sending a packet we check status, update
1400 * statistics and relinquish ownership of transmit
1403 * Parameters : I : struct net_device *dev - SK_G16 device structure
1404 * Return Value : None
1408 * YY/MM/DD uid Description
1411 static void SK_txintr(struct net_device *dev)
1415 struct priv *p = (struct priv *) dev->priv;
1418 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1419 SK_NAME, SK_read_reg(CSR0)));
1421 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */
1423 /* Set next buffer */
1425 p->tmdlast &= TMDNUM-1;
1427 tmdstat = readb(&tmdp->u.s.status);
1430 * We check status of transmitted packet.
1431 * see LANCE data-sheet for error explanation
1433 if (tmdstat & TX_ERR) /* Error occurred */
1435 int stat2 = readw(&tmdp->status2);
1437 printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
1439 if (stat2 & TX_TDR) /* TDR problems? */
1441 printk("%s: tdr-problems \n", dev->name);
1444 if (stat2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */
1445 p->stats.tx_aborted_errors++;
1446 if (stat2 & TX_LCOL) /* Late collision ? */
1447 p->stats.tx_window_errors++;
1448 if (stat2 & TX_LCAR) /* Loss of Carrier ? */
1449 p->stats.tx_carrier_errors++;
1450 if (stat2 & TX_UFLO) /* Underflow error ? */
1452 p->stats.tx_fifo_errors++;
1455 * If UFLO error occurs it will turn transmitter of.
1456 * So we must reinit LANCE
1459 SK_lance_init(dev, MODE_NORMAL);
1462 p->stats.tx_errors++;
1464 writew(0, &tmdp->status2); /* Clear error flags */
1466 else if (tmdstat & TX_MORE) /* Collisions occurred ? */
1469 * Here I have a problem.
1470 * I only know that there must be one or up to 15 collisions.
1471 * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1472 * will be set which means couldn't send packet aborted transfer.
1474 * First I did not have this in but then I thought at minimum
1475 * we see that something was not ok.
1476 * If anyone knows something better than this to handle this
1480 p->stats.collisions++;
1482 else /* Packet sent without any problems */
1484 p->stats.tx_packets++;
1488 * We mark transmitter not busy anymore, because now we have a free
1489 * transmit descriptor which can be filled by SK_send_packet and
1490 * afterwards sent by the LANCE
1492 * The function which do handle slow IRQ parts is do_bottom_half()
1493 * which runs at normal kernel priority, that means all interrupt are
1494 * enabled. (see kernel/irq.c)
1496 * net_bh does something like this:
1497 * - check if already in net_bh
1498 * - try to transmit something from the send queue
1499 * - if something is in the receive queue send it up to higher
1500 * levels if it is a known protocol
1501 * - try to transmit something from the send queue
1504 netif_wake_queue(dev);
1506 } /* End of SK_txintr() */
1510 * Function : SK_rxintr
1511 * Author : Patrick J.D. Weichmann
1512 * Date Created : 94/05/27
1514 * Description : Buffer sent, check for errors, relinquish ownership
1515 * of the receive message descriptor.
1517 * Parameters : I : SK_G16 device structure
1518 * Return Value : None
1521 * YY/MM/DD uid Description
1524 static void SK_rxintr(struct net_device *dev)
1529 struct priv *p = (struct priv *) dev->priv;
1531 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1532 SK_NAME, SK_read_reg(CSR0)));
1534 rmdp = p->rmdhead + p->rmdnum;
1536 /* As long as we own the next entry, check status and send
1537 * it up to higher layer
1540 while (!( (rmdstat = readb(&rmdp->u.s.status)) & RX_OWN))
1543 * Start and end of packet must be set, because we use
1544 * the ethernet maximum packet length (1518) as buffer size.
1546 * Because our buffers are at maximum OFLO and BUFF errors are
1547 * not to be concerned (see Data sheet)
1550 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
1552 /* Start of a frame > 1518 Bytes ? */
1554 if (rmdstat & RX_STP)
1556 p->stats.rx_errors++; /* bad packet received */
1557 p->stats.rx_length_errors++; /* packet too long */
1559 printk("%s: packet too long\n", dev->name);
1563 * All other packets will be ignored until a new frame with
1564 * start (RX_STP) set follows.
1566 * What we do is just give descriptor free for new incoming
1570 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1573 else if (rmdstat & RX_ERR) /* Receive Error ? */
1575 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1577 p->stats.rx_errors++;
1579 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1580 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++;
1582 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1585 else /* We have a packet which can be queued for the upper layers */
1588 int len = readw(&rmdp->mlen) & 0x0fff; /* extract message length from receive buffer */
1589 struct sk_buff *skb;
1591 skb = dev_alloc_skb(len+2); /* allocate socket buffer */
1593 if (skb == NULL) /* Could not get mem ? */
1597 * Couldn't allocate sk_buffer so we give descriptor back
1598 * to Lance, update statistics and go ahead.
1601 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1602 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1604 p->stats.rx_dropped++;
1606 break; /* Jump out */
1609 /* Prepare sk_buff to queue for upper layers */
1612 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */
1615 * Copy data out of our receive descriptor into sk_buff.
1617 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1618 * ignore status fields)
1621 memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
1625 * Notify the upper protocol layers that there is another packet
1628 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1631 skb->protocol=eth_type_trans(skb,dev);
1632 netif_rx(skb); /* queue packet and mark it for processing */
1635 * Packet is queued and marked for processing so we
1636 * free our descriptor and update statistics
1639 writeb(RX_OWN, &rmdp->u.s.status);
1640 dev->last_rx = jiffies;
1641 p->stats.rx_packets++;
1642 p->stats.rx_bytes += len;
1646 p->rmdnum %= RMDNUM;
1648 rmdp = p->rmdhead + p->rmdnum;
1651 } /* End of SK_rxintr() */
1655 * Function : SK_close
1656 * Author : Patrick J.D. Weichmann
1657 * Date Created : 94/05/26
1659 * Description : close gets called from dev_close() and should
1660 * deinstall the card (free_irq, mem etc).
1662 * Parameters : I : struct net_device *dev - our device structure
1663 * Return Value : 0 - closed device driver
1667 * YY/MM/DD uid Description
1670 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1671 * down' the system stops. So I don't shut set card to init state.
1674 static int SK_close(struct net_device *dev)
1677 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1678 SK_NAME, SK_read_reg(CSR0)));
1680 netif_stop_queue(dev); /* Transmitter busy */
1682 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,
1683 (int) SK_read_reg(CSR0));
1685 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1687 free_irq(dev->irq, dev); /* Free IRQ */
1689 return 0; /* always succeed */
1691 } /* End of SK_close() */
1695 * Function : SK_get_stats
1696 * Author : Patrick J.D. Weichmann
1697 * Date Created : 94/05/26
1699 * Description : Return current status structure to upper layers.
1700 * It is called by sprintf_stats (dev.c).
1702 * Parameters : I : struct net_device *dev - our device structure
1703 * Return Value : struct net_device_stats * - our current statistics
1705 * Side Effects : None
1707 * YY/MM/DD uid Description
1710 static struct net_device_stats *SK_get_stats(struct net_device *dev)
1713 struct priv *p = (struct priv *) dev->priv;
1715 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1716 SK_NAME, SK_read_reg(CSR0)));
1718 return &p->stats; /* Return Device status */
1720 } /* End of SK_get_stats() */
1724 * Function : set_multicast_list
1725 * Author : Patrick J.D. Weichmann
1726 * Date Created : 94/05/26
1728 * Description : This function gets called when a program performs
1729 * a SIOCSIFFLAGS call. Ifconfig does this if you call
1730 * 'ifconfig [-]allmulti' which enables or disables the
1732 * Promiscuous mode is when the Network card accepts all
1733 * packets, not only the packets which match our MAC
1734 * Address. It is useful for writing a network monitor,
1735 * but it is also a security problem. You have to remember
1736 * that all information on the net is not encrypted.
1738 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1739 * Return Value : None
1743 * YY/MM/DD uid Description
1744 * 95/10/18 ACox New multicast calling scheme
1748 /* Set or clear the multicast filter for SK_G16.
1751 static void set_multicast_list(struct net_device *dev)
1754 if (dev->flags&IFF_PROMISC)
1756 /* Reinitialize LANCE with MODE_PROM set */
1757 SK_lance_init(dev, MODE_PROM);
1759 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
1761 /* Reinitialize LANCE without MODE_PROM */
1762 SK_lance_init(dev, MODE_NORMAL);
1766 /* Multicast with logical address filter on */
1767 /* Reinitialize LANCE without MODE_PROM */
1768 SK_lance_init(dev, MODE_NORMAL);
1770 /* Not implemented yet. */
1772 } /* End of set_multicast_list() */
1777 * Function : SK_rom_addr
1778 * Author : Patrick J.D. Weichmann
1779 * Date Created : 94/06/01
1781 * Description : Try to find a Boot_ROM at all possible locations
1784 * Return Value : Address where Boot_ROM is
1785 * Errors : 0 - Did not find Boot_ROM
1788 * YY/MM/DD uid Description
1791 unsigned int __init SK_rom_addr(void)
1795 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1796 unsigned char rom_id[] = SK_BOOT_ROM_ID;
1797 unsigned char test_byte;
1799 /* Autodetect Boot_ROM */
1800 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1802 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1805 PRINTK(("## Trying ROM location %#08x", rom_location[i]));
1808 for (j = 0; j < 6; j++)
1810 test_byte = readb(rom_location[i]+j);
1811 PRINTK((" %02x ", *test_byte));
1813 if(test_byte != rom_id[j])
1823 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1824 SK_NAME, rom_location[(i-1)]));
1826 return (rom_location[--i]);
1830 PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1833 } /* End of SK_rom_addr() */
1837 /* LANCE access functions
1839 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1844 * Function : SK_reset_board
1846 * Author : Patrick J.D. Weichmann
1848 * Date Created : 94/05/25
1850 * Description : This function resets SK_G16 and all components, but
1851 * POS registers are not changed
1854 * Return Value : None
1856 * Globals : SK_RAM *board - SK_RAM structure pointer
1859 * YY/MM/DD uid Description
1862 void SK_reset_board(void)
1864 writeb(0x00, SK_PORT); /* Reset active */
1865 mdelay(5); /* Delay min 5ms */
1866 writeb(SK_RESET, SK_PORT); /* Set back to normal operation */
1868 } /* End of SK_reset_board() */
1872 * Function : SK_set_RAP
1873 * Author : Patrick J.D. Weichmann
1874 * Date Created : 94/05/25
1876 * Description : Set LANCE Register Address Port to register
1877 * for later data transfer.
1879 * Parameters : I : reg_number - which CSR to read/write from/to
1880 * Return Value : None
1882 * Globals : SK_RAM *board - SK_RAM structure pointer
1884 * YY/MM/DD uid Description
1887 void SK_set_RAP(int reg_number)
1889 writew(reg_number, SK_IOREG);
1890 writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
1891 writeb(SK_DOIO, SK_IOCOM);
1893 while (readb(SK_PORT) & SK_IORUN)
1895 } /* End of SK_set_RAP() */
1899 * Function : SK_read_reg
1900 * Author : Patrick J.D. Weichmann
1901 * Date Created : 94/05/25
1903 * Description : Set RAP and read data from a LANCE CSR register
1905 * Parameters : I : reg_number - which CSR to read from
1906 * Return Value : Register contents
1908 * Globals : SK_RAM *board - SK_RAM structure pointer
1910 * YY/MM/DD uid Description
1913 int SK_read_reg(int reg_number)
1915 SK_set_RAP(reg_number);
1917 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1918 writeb(SK_DOIO, SK_IOCOM);
1920 while (readb(SK_PORT) & SK_IORUN)
1922 return (readw(SK_IOREG));
1924 } /* End of SK_read_reg() */
1928 * Function : SK_rread_reg
1929 * Author : Patrick J.D. Weichmann
1930 * Date Created : 94/05/28
1932 * Description : Read data from preseted register.
1933 * This function requires that you know which
1934 * Register is actually set. Be aware that CSR1-3
1935 * can only be accessed when in CSR0 STOP is set.
1937 * Return Value : Register contents
1939 * Globals : SK_RAM *board - SK_RAM structure pointer
1941 * YY/MM/DD uid Description
1944 int SK_rread_reg(void)
1946 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1948 writeb(SK_DOIO, SK_IOCOM);
1950 while (readb(SK_PORT) & SK_IORUN)
1952 return (readw(SK_IOREG));
1954 } /* End of SK_rread_reg() */
1958 * Function : SK_write_reg
1959 * Author : Patrick J.D. Weichmann
1960 * Date Created : 94/05/25
1962 * Description : This function sets the RAP then fills in the
1963 * LANCE I/O Reg and starts Transfer to LANCE.
1964 * It waits until transfer has ended which is max. 7 ms
1965 * and then it returns.
1967 * Parameters : I : reg_number - which CSR to write to
1968 * I : value - what value to fill into register
1969 * Return Value : None
1971 * Globals : SK_RAM *board - SK_RAM structure pointer
1973 * YY/MM/DD uid Description
1976 void SK_write_reg(int reg_number, int value)
1978 SK_set_RAP(reg_number);
1980 writew(value, SK_IOREG);
1981 writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
1982 writeb(SK_DOIO, SK_IOCOM);
1984 while (readb(SK_PORT) & SK_IORUN)
1986 } /* End of SK_write_reg */
1991 * Debugging functions
1992 * -------------------
1996 * Function : SK_print_pos
1997 * Author : Patrick J.D. Weichmann
1998 * Date Created : 94/05/25
2000 * Description : This function prints out the 4 POS (Programmable
2001 * Option Select) Registers. Used mainly to debug operation.
2003 * Parameters : I : struct net_device *dev - SK_G16 device structure
2004 * I : char * - Text which will be printed as title
2005 * Return Value : None
2008 * YY/MM/DD uid Description
2011 void SK_print_pos(struct net_device *dev, char *text)
2013 int ioaddr = dev->base_addr;
2015 unsigned char pos0 = inb(SK_POS0),
2016 pos1 = inb(SK_POS1),
2017 pos2 = inb(SK_POS2),
2018 pos3 = inb(SK_POS3),
2019 pos4 = inb(SK_POS4);
2022 printk("## %s: %s.\n"
2023 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
2024 SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
2026 } /* End of SK_print_pos() */
2031 * Function : SK_print_dev
2032 * Author : Patrick J.D. Weichmann
2033 * Date Created : 94/05/25
2035 * Description : This function simply prints out the important fields
2036 * of the device structure.
2038 * Parameters : I : struct net_device *dev - SK_G16 device structure
2039 * I : char *text - Title for printing
2040 * Return Value : None
2043 * YY/MM/DD uid Description
2046 void SK_print_dev(struct net_device *dev, char *text)
2050 printk("## %s: Device Structure. %s\n", SK_NAME, text);
2051 printk("## DEVICE == NULL\n");
2055 printk("## %s: Device Structure. %s\n", SK_NAME, text);
2056 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",
2057 dev->name, dev->base_addr, dev->irq);
2059 printk("## next device: %#08x init function: %#08x\n",
2060 (int) dev->next, (int) dev->init);
2063 } /* End of SK_print_dev() */
2068 * Function : SK_print_ram
2069 * Author : Patrick J.D. Weichmann
2070 * Date Created : 94/06/02
2072 * Description : This function is used to check how are things set up
2073 * in the 16KB RAM. Also the pointers to the receive and
2074 * transmit descriptor rings and rx and tx buffers locations.
2075 * It contains a minor bug in printing, but has no effect to the values
2076 * only newlines are not correct.
2078 * Parameters : I : struct net_device *dev - SK_G16 device structure
2079 * Return Value : None
2083 * YY/MM/DD uid Description
2086 void __init SK_print_ram(struct net_device *dev)
2090 struct priv *p = (struct priv *) dev->priv;
2092 printk("## %s: RAM Details.\n"
2093 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2095 (unsigned int) p->ram,
2096 (unsigned int) p->tmdhead,
2097 (unsigned int) p->rmdhead,
2098 (unsigned int) &(p->ram)->ib);
2102 for(i = 0; i < TMDNUM; i++)
2104 if (!(i % 3)) /* Every third line do a newline */
2108 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2112 for(i = 0; i < RMDNUM; i++)
2114 if (!(i % 3)) /* Every third line do a newline */
2118 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2122 } /* End of SK_print_ram() */