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.
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
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
24 static const char *rcsid
= "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
27 * The Schneider & Koch (SK) G16 Network device driver is based
28 * on the 'ni6510' driver from Michael Hipp which can be found at
29 * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
31 * Sources: 1) ni6510.c by M. Hipp
32 * 2) depca.c by D.C. Davies
33 * 3) skeleton.c by D. Becker
34 * 4) Am7990 Local Area Network Controller for Ethernet (LANCE),
35 * AMD, Pub. #05698, June 1989
37 * Many Thanks for helping me to get things working to:
39 * A. Cox (A.Cox@swansea.ac.uk)
40 * M. Hipp (mhipp@student.uni-tuebingen.de)
41 * R. Bolz (Schneider & Koch, Germany)
44 * - Support of SK_G8 and other SK Network Cards.
45 * - Autoset memory mapped RAM. Check for free memory and then
46 * configure RAM correctly.
47 * - SK_close should really set card in to initial state.
48 * - Test if IRQ 3 is not switched off. Use autoirq() functionality.
49 * (as in /drivers/net/skeleton.c)
50 * - Implement Multicast addressing. At minimum something like
52 * - Redo the statistics part.
53 * - Try to find out if the board is in 8 Bit or 16 Bit slot.
54 * If in 8 Bit mode don't use IRQ 11.
55 * - (Try to make it slightly faster.)
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/ptrace.h>
61 #include <linux/fcntl.h>
62 #include <linux/ioport.h>
63 #include <linux/interrupt.h>
64 #include <linux/malloc.h>
65 #include <linux/string.h>
66 #include <linux/delay.h>
67 #include <asm/system.h>
69 #include <asm/bitops.h>
70 #include <linux/errno.h>
71 #include <linux/init.h>
73 #include <linux/netdevice.h>
74 #include <linux/etherdevice.h>
75 #include <linux/skbuff.h>
80 * Schneider & Koch Card Definitions
81 * =================================
84 #define SK_NAME "SK_G16"
87 * SK_G16 Configuration
88 * --------------------
95 * RAM - used for the 16KB shared memory
96 * Boot_ROM, ROM - are used for referencing the BootEPROM
98 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
99 * the behaviour of the driver and the SK_G16.
101 * ! See sk_g16.install on how to install and configure the driver !
103 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
105 * SK_ADDR defines the address where the RAM will be mapped into the real
107 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
110 #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
112 #define SK_ADDR 0xcc000
115 * In POS3 are bits A14-A19 of the address bus. These bits can be set
116 * to choose the RAM address. That's why we only can choose the RAM address
120 #define POS_ADDR (rom_addr>>14) /* Do not change this line */
123 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
124 * ----------------------------------------------
128 * As nearly every card has also SK_G16 a specified I/O Port region and
129 * only a few possible IRQ's.
130 * In the Installation Guide from Schneider & Koch is listed a possible
131 * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
132 * controllers. So we use in SK_IRQS IRQ9.
135 /* Don't touch any of the following #defines. */
137 #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
139 #define SK_IRQS { 3, 5, 9, 11, 0 }
141 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
143 #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
146 * SK_G16 POS REGISTERS
147 * --------------------
151 * SK_G16 has a Programmable Option Select (POS) Register.
152 * The POS is composed of 8 separate registers (POS0-7) which
153 * are I/O mapped on an address set by the W1 switch.
157 #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
159 #define SK_POS0 ioaddr /* Card-ID Low (R) */
160 #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
161 #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
162 #define SK_POS3 ioaddr+3 /* Base address of RAM */
163 #define SK_POS4 ioaddr+4 /* IRQ */
165 /* POS5 - POS7 are unused */
173 * Scheider & Koch manufacturer code (00:00:a5).
174 * This must be checked, that we are sure it is a SK card.
187 * If POS0,POS1 contain the following ID, then we know
188 * at which I/O Port Address we are.
191 #define SK_IDLOW 0xfd
192 #define SK_IDHIGH 0x6a
196 * LANCE POS Bit definitions
197 * -------------------------
200 #define SK_ROM_RAM_ON (POS2_CARD)
201 #define SK_ROM_RAM_OFF (POS2_EPROM)
202 #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
203 #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
204 #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
205 #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
207 #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
208 #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
211 * SK_G16 Memory mapped Registers
212 * ------------------------------
216 #define SK_IOREG (board->ioreg) /* LANCE data registers. */
217 #define SK_PORT (board->port) /* Control, Status register */
218 #define SK_IOCOM (board->iocom) /* I/O Command */
221 * SK_G16 Status/Control Register bits
222 * -----------------------------------
224 * (C) Controlreg (S) Statusreg
228 * Register transfer: 0 = no transfer
229 * 1 = transferring data between LANCE and I/O reg
231 #define SK_IORUN 0x20
234 * LANCE interrupt: 0 = LANCE interrupt occurred
235 * 1 = no LANCE interrupt occurred
239 #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
240 #define SK_RW 0x02 /* 0 = write to 1 = read from */
241 #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
244 #define SK_RREG SK_RW /* Transferdirection to read from lance */
245 #define SK_WREG 0 /* Transferdirection to write to lance */
246 #define SK_RAP SK_ADR /* Destination Register RAP */
247 #define SK_RDATA 0 /* Destination Register REG DataPort */
255 * Any bitcombination sets the internal I/O bit (transfer will start)
256 * when written to I/O Command
259 #define SK_DOIO 0x80 /* Do Transfer */
262 * LANCE RAP (Register Address Port).
263 * ---------------------------------
267 * The LANCE internal registers are selected through the RAP.
270 * CSR0 - Status and Control flags
271 * CSR1 - Low order bits of initialize block (bits 15:00)
272 * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
273 * CSR3 - Allows redefinition of the Bus Master Interface.
274 * This register must be set to 0x0002, which means BSWAP = 0,
275 * ACON = 1, BCON = 0;
285 * General Definitions
286 * ===================
290 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
291 * We have 16KB RAM which can be accessed by the LANCE. In the
292 * memory are not only the buffers but also the ring descriptors and
293 * the initialize block.
294 * Don't change anything unless you really know what you do.
297 #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
298 #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */
300 /* Descriptor ring sizes */
302 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
303 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
305 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
307 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
308 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
311 * Data Buffer size is set to maximum packet length.
314 #define PKT_BUF_SZ 1518
317 * The number of low I/O ports used by the ethercard.
320 #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
325 * Here you can choose what level of debugging wanted.
327 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
328 * necessary messages will be printed.
330 * If SK_DEBUG is defined, there will be many debugging prints
331 * which can help to find some mistakes in configuration or even
332 * in the driver code.
334 * If SK_DEBUG2 is defined, many many messages will be printed
335 * which normally you don't need. I used this to check the interrupt
338 * (If you define only SK_DEBUG2 then only the messages for
339 * checking interrupts will be printed!)
341 * Normal way of live is:
343 * For the whole thing get going let both symbolic constants
344 * undefined. If you face any problems and you know what's going
345 * on (you know something about the card and you can interpret some
346 * hex LANCE register output) then define SK_DEBUG
350 #undef SK_DEBUG /* debugging */
351 #undef SK_DEBUG2 /* debugging with more verbose report */
354 #define PRINTK(x) printk x
356 #define PRINTK(x) /**/
360 #define PRINTK2(x) printk x
362 #define PRINTK2(x) /**/
368 * The components are memory mapped and can be set in a region from
369 * 0x00000 through 0xfc000 in 16KB steps.
371 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
372 * Controlregister and I/O Command.
374 * dual ported RAM: This is the only memory region which the LANCE chip
375 * has access to. From the Lance it is addressed from 0x0000 to
376 * 0x3fbf. The host accesses it normally.
378 * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
379 * 8-Bit PROM, this means only the 16 even addresses are used of the
380 * 32 Byte Address region. Access to an odd address results in invalid
383 * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
384 * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
385 * Transfer from or to the LANCE is always in 16Bit so Low and High
386 * registers are always relevant.
388 * The Data from the Readregister is not the data in the Writeregister!!
390 * Port: Status- and Controlregister.
391 * Two different registers which share the same address, Status is
392 * read-only, Control is write-only.
395 * Any bitcombination written in here starts the transmission between
401 unsigned char ram
[0x3fc0]; /* 16KB dual ported ram */
402 unsigned char rom
[0x0020]; /* 32Byte PROM containing 6Byte MAC */
403 unsigned char res1
[0x0010]; /* reserved */
404 unsigned volatile short ioreg
;/* LANCE I/O Register */
405 unsigned volatile char port
; /* Statusregister and Controlregister */
406 unsigned char iocom
; /* I/O Command Register */
412 * This is the structure for the dual ported ram. We
413 * have exactly 16 320 Bytes. In here there must be:
415 * - Initialize Block (starting at a word boundary)
416 * - Receive and Transmit Descriptor Rings (quadword boundary)
417 * - Data Buffers (arbitrary boundary)
419 * This is because LANCE has on SK_G16 only access to the dual ported
420 * RAM and nowhere else.
425 struct init_block ib
;
426 struct tmd tmde
[TMDNUM
];
427 struct rmd rmde
[RMDNUM
];
428 char tmdbuf
[TMDNUM
][PKT_BUF_SZ
];
429 char rmdbuf
[RMDNUM
][PKT_BUF_SZ
];
433 * Structure where all necessary information is for ring buffer
434 * management and statistics.
439 struct SK_ram
*ram
; /* dual ported ram structure */
440 struct rmd
*rmdhead
; /* start of receive ring descriptors */
441 struct tmd
*tmdhead
; /* start of transmit ring descriptors */
442 int rmdnum
; /* actual used ring descriptor */
443 int tmdnum
; /* actual transmit descriptor for transmitting data */
444 int tmdlast
; /* last sent descriptor used for error handling, etc */
445 void *rmdbufs
[RMDNUM
]; /* pointer to the receive buffers */
446 void *tmdbufs
[TMDNUM
]; /* pointer to the transmit buffers */
447 struct net_device_stats stats
; /* Device driver statistics */
450 /* global variable declaration */
452 /* IRQ map used to reserve a IRQ (see SK_open()) */
454 /* static variables */
456 static SK_RAM
*board
; /* pointer to our memory mapped board components */
461 /* Function Prototypes */
464 * Device Driver functions
465 * -----------------------
466 * See for short explanation of each function its definitions header.
469 int SK_init(struct net_device
*dev
);
470 static int SK_probe(struct net_device
*dev
, short ioaddr
);
472 static int SK_open(struct net_device
*dev
);
473 static int SK_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
474 static void SK_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
);
475 static void SK_rxintr(struct net_device
*dev
);
476 static void SK_txintr(struct net_device
*dev
);
477 static int SK_close(struct net_device
*dev
);
479 static struct net_device_stats
*SK_get_stats(struct net_device
*dev
);
481 unsigned int SK_rom_addr(void);
483 static void set_multicast_list(struct net_device
*dev
);
490 static int SK_lance_init(struct net_device
*dev
, unsigned short mode
);
491 void SK_reset_board(void);
492 void SK_set_RAP(int reg_number
);
493 int SK_read_reg(int reg_number
);
494 int SK_rread_reg(void);
495 void SK_write_reg(int reg_number
, int value
);
498 * Debugging functions
499 * -------------------
502 void SK_print_pos(struct net_device
*dev
, char *text
);
503 void SK_print_dev(struct net_device
*dev
, char *text
);
504 void SK_print_ram(struct net_device
*dev
);
509 * Author : Patrick J.D. Weichmann
510 * Date Created : 94/05/26
512 * Description : Check for a SK_G16 network adaptor and initialize it.
513 * This function gets called by dev_init which initializes
514 * all Network devices.
516 * Parameters : I : struct net_device *dev - structure preconfigured
518 * Return Value : 0 = Driver Found and initialized
519 * Errors : ENODEV - no device found
523 * YY/MM/DD uid Description
527 * Check for a network adaptor of this type, and return '0' if one exists.
528 * If dev->base_addr == 0, probe all likely locations.
529 * If dev->base_addr == 1, always return failure.
530 * If dev->base_addr == 2, allocate space for the device and return success
531 * (detachable devices only).
534 int __init
SK_init(struct net_device
*dev
)
536 int ioaddr
= 0; /* I/O port address used for POS regs */
537 int *port
, ports
[] = SK_IO_PORTS
; /* SK_G16 supported ports */
539 /* get preconfigured base_addr from dev which is done in Space.c */
540 int base_addr
= dev
->base_addr
;
542 PRINTK(("%s: %s", SK_NAME
, rcsid
));
543 rcsid
= NULL
; /* We do not want to use this further */
545 if (base_addr
> 0x0ff) /* Check a single specified address */
547 /* Check if on specified address is a SK_G16 */
549 if ( (inb(SK_POS0
) == SK_IDLOW
) ||
550 (inb(SK_POS1
) == SK_IDHIGH
) )
552 return SK_probe(dev
, base_addr
);
555 return ENODEV
; /* Sorry, but on specified address NO SK_G16 */
557 else if (base_addr
> 0) /* Don't probe at all */
562 /* Autoprobe base_addr */
564 for (port
= &ports
[0]; *port
; port
++)
566 ioaddr
= *port
; /* we need ioaddr for accessing POS regs */
568 /* Check if I/O Port region is used by another board */
570 if (check_region(ioaddr
, ETHERCARD_TOTAL_SIZE
))
572 continue; /* Try next Port address */
575 /* Check if at ioaddr is a SK_G16 */
577 if ( !(inb(SK_POS0
) == SK_IDLOW
) ||
578 !(inb(SK_POS1
) == SK_IDHIGH
) )
580 continue; /* Try next Port address */
583 dev
->base_addr
= ioaddr
; /* Set I/O Port Address */
585 if (SK_probe(dev
, ioaddr
) == 0)
587 return 0; /* Card found and initialized */
591 dev
->base_addr
= base_addr
; /* Write back original base_addr */
593 return ENODEV
; /* Failed to find or init driver */
595 } /* End of SK_init */
599 * Function : SK_probe
600 * Author : Patrick J.D. Weichmann
601 * Date Created : 94/05/26
603 * Description : This function is called by SK_init and
604 * does the main part of initialization.
606 * Parameters : I : struct net_device *dev - SK_G16 device structure
607 * I : short ioaddr - I/O Port address where POS is.
608 * Return Value : 0 = Initialization done
609 * Errors : ENODEV - No SK_G16 found
610 * -1 - Configuration problem
611 * Globals : board - pointer to SK_RAM
613 * YY/MM/DD uid Description
614 * 94/06/30 pwe SK_ADDR now checked and at the correct place
617 int __init
SK_probe(struct net_device
*dev
, short ioaddr
)
619 int i
,j
; /* Counters */
620 int sk_addr_flag
= 0; /* SK ADDR correct? 1 - no, 0 - yes */
621 unsigned int rom_addr
; /* used to store RAM address used for POS_ADDR */
623 struct priv
*p
; /* SK_G16 private structure */
625 if (SK_ADDR
& 0x3fff || SK_ADDR
< 0xa0000)
631 * Now here we could use a routine which searches for a free
632 * place in the ram and set SK_ADDR if found. TODO.
636 if (SK_BOOT_ROM
) /* Shall we keep Boot_ROM on ? */
638 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME
));
640 rom_addr
= SK_rom_addr();
642 if (rom_addr
== 0) /* No Boot_ROM found */
644 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
646 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
651 rom_addr
= SK_ADDR
; /* assign predefined address */
653 PRINTK(("## %s: NO Bootrom found \n", SK_NAME
));
655 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
656 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
657 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
659 else if (rom_addr
== SK_ADDR
)
661 printk("%s: RAM + ROM are set to the same address %#08x\n"
662 " Check configuration. Now switching off Boot_ROM\n",
665 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off*/
666 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
667 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
671 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME
, rom_addr
));
672 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME
));
674 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
676 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
683 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
684 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
685 outb(SK_ROM_RAM_ON
, SK_POS2
); /* RAM on, BOOT_ROM on */
688 else /* Don't keep Boot_ROM */
690 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME
));
692 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
694 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
699 rom_addr
= SK_rom_addr(); /* Try to find a Boot_ROM */
701 /* IF we find a Boot_ROM disable it */
703 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
705 /* We found a Boot_ROM and it's gone. Set RAM address on
711 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
712 "that address\n", SK_NAME
, rom_addr
);
714 outb(POS_ADDR
, SK_POS3
); /* Set RAM on Boot_ROM address */
716 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
718 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
720 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
727 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
729 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
733 SK_print_pos(dev
, "POS registers after ROM, RAM config");
736 board
= (SK_RAM
*) bus_to_virt(rom_addr
);
738 /* Read in station address */
739 for (i
= 0, j
= 0; i
< ETH_ALEN
; i
++, j
+=2)
741 dev
->dev_addr
[i
] = readb(board
->rom
+j
);
744 /* Check for manufacturer code */
745 if (!(dev
->dev_addr
[0] == SK_MAC0
&&
746 dev
->dev_addr
[1] == SK_MAC1
&&
747 dev
->dev_addr
[2] == SK_MAC2
) )
749 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
751 return ENODEV
; /* NO SK_G16 found */
754 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
756 "Schneider & Koch Netcard",
757 (unsigned int) dev
->base_addr
,
765 /* Allocate memory for private structure */
766 p
= dev
->priv
= (void *) kmalloc(sizeof(struct priv
), GFP_KERNEL
);
768 printk("%s: ERROR - no memory for driver data!\n", dev
->name
);
771 memset((char *) dev
->priv
, 0, sizeof(struct priv
)); /* clear memory */
773 /* Grab the I/O Port region */
774 request_region(ioaddr
, ETHERCARD_TOTAL_SIZE
,"sk_g16");
776 /* Assign our Device Driver functions */
778 dev
->open
= &SK_open
;
779 dev
->stop
= &SK_close
;
780 dev
->hard_start_xmit
= &SK_send_packet
;
781 dev
->get_stats
= &SK_get_stats
;
782 dev
->set_multicast_list
= &set_multicast_list
;
785 /* Set the generic fields of the device structure */
789 dev
->flags
&= ~IFF_MULTICAST
;
791 /* Initialize private structure */
793 p
->ram
= (struct SK_ram
*) rom_addr
; /* Set dual ported RAM addr */
794 p
->tmdhead
= &(p
->ram
)->tmde
[0]; /* Set TMD head */
795 p
->rmdhead
= &(p
->ram
)->rmde
[0]; /* Set RMD head */
797 /* Initialize buffer pointers */
799 for (i
= 0; i
< TMDNUM
; i
++)
801 p
->tmdbufs
[i
] = &(p
->ram
)->tmdbuf
[i
];
804 for (i
= 0; i
< RMDNUM
; i
++)
806 p
->rmdbufs
[i
] = &(p
->ram
)->rmdbuf
[i
];
810 SK_print_pos(dev
, "End of SK_probe");
814 return 0; /* Initialization done */
816 } /* End of SK_probe() */
821 * Author : Patrick J.D. Weichmann
822 * Date Created : 94/05/26
824 * Description : This function is called sometimes after booting
825 * when ifconfig program is run.
827 * This function requests an IRQ, sets the correct
828 * IRQ in the card. Then calls SK_lance_init() to
829 * init and start the LANCE chip. Then if everything is
830 * ok returns with 0 (OK), which means SK_G16 is now
831 * opened and operational.
833 * (Called by dev_open() /net/inet/dev.c)
835 * Parameters : I : struct net_device *dev - SK_G16 device structure
836 * Return Value : 0 - Device opened
837 * Errors : -EAGAIN - Open failed
838 * Side Effects : None
840 * YY/MM/DD uid Description
843 static int SK_open(struct net_device
*dev
)
847 int ioaddr
= dev
->base_addr
;
849 int irqtab
[] = SK_IRQS
;
851 struct priv
*p
= (struct priv
*)dev
->priv
;
853 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
854 SK_NAME
, SK_read_reg(CSR0
)));
856 if (dev
->irq
== 0) /* Autoirq */
861 * Check if one IRQ out of SK_IRQS is free and install
863 * Most done by request_irq().
864 * irqval: 0 - interrupt handler installed for IRQ irqtab[i]
865 * -EBUSY - interrupt busy
866 * -EINVAL - irq > 15 or handler = NULL
871 irqval
= request_irq(irqtab
[i
], &SK_interrupt
, 0, "sk_g16", dev
);
873 } while (irqval
&& irqtab
[i
]);
875 if (irqval
) /* We tried every possible IRQ but no success */
877 printk("%s: unable to get an IRQ\n", dev
->name
);
881 dev
->irq
= irqtab
[--i
];
883 outb(i
<<2, SK_POS4
); /* Set Card on probed IRQ */
886 else if (dev
->irq
== 2) /* IRQ2 is always IRQ9 */
888 if (request_irq(9, &SK_interrupt
, 0, "sk_g16", dev
))
890 printk("%s: unable to get IRQ 9\n", dev
->name
);
896 * Now we set card on IRQ2.
897 * This can be confusing, but remember that IRQ2 on the network
898 * card is in reality IRQ9
900 outb(0x08, SK_POS4
); /* set card to IRQ2 */
903 else /* Check IRQ as defined in Space.c */
907 /* check if IRQ free and valid. Then install Interrupt handler */
909 if (request_irq(dev
->irq
, &SK_interrupt
, 0, "sk_g16", dev
))
911 printk("%s: unable to get selected IRQ\n", dev
->name
);
926 printk("%s: Preselected IRQ %d is invalid for %s boards",
933 outb(i
<<2, SK_POS4
); /* Set IRQ on card */
936 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
937 dev
->name
, (unsigned int)dev
->base_addr
,
938 (int) dev
->irq
, (unsigned int) p
->ram
);
940 if (!(i
= SK_lance_init(dev
, 0))) /* LANCE init OK? */
951 * This debug block tries to stop LANCE,
952 * reinit LANCE with transmitter and receiver disabled,
953 * then stop again and reinit with NORMAL_MODE
956 printk("## %s: After lance init. CSR0: %#06x\n",
957 SK_NAME
, SK_read_reg(CSR0
));
958 SK_write_reg(CSR0
, CSR0_STOP
);
959 printk("## %s: LANCE stopped. CSR0: %#06x\n",
960 SK_NAME
, SK_read_reg(CSR0
));
961 SK_lance_init(dev
, MODE_DTX
| MODE_DRX
);
962 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n",
963 SK_NAME
, SK_read_reg(CSR0
));
964 SK_write_reg(CSR0
, CSR0_STOP
);
965 printk("## %s: LANCE stopped. CSR0: %#06x\n",
966 SK_NAME
, SK_read_reg(CSR0
));
967 SK_lance_init(dev
, MODE_NORMAL
);
968 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n",
969 SK_NAME
, SK_read_reg(CSR0
));
970 SK_print_pos(dev
, "POS regs before returning OK");
972 #endif /* SK_DEBUG */
974 return 0; /* SK_open() is successful */
976 else /* LANCE init failed */
979 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
980 SK_NAME
, SK_read_reg(CSR0
)));
982 dev
->start
= 0; /* Device not ready */
986 } /* End of SK_open() */
990 * Function : SK_lance_init
991 * Author : Patrick J.D. Weichmann
992 * Date Created : 94/05/26
994 * Description : Reset LANCE chip, fill RMD, TMD structures with
995 * start values and Start LANCE.
997 * Parameters : I : struct net_device *dev - SK_G16 device structure
998 * I : int mode - put LANCE into "mode" see data-sheet for
1000 * Return Value : 0 - Init done
1001 * Errors : -1 - Init failed
1003 * YY/MM/DD uid Description
1006 static int SK_lance_init(struct net_device
*dev
, unsigned short mode
)
1009 unsigned long flags
;
1010 struct priv
*p
= (struct priv
*) dev
->priv
;
1014 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1015 SK_NAME
, SK_read_reg(CSR0
)));
1020 /* Initialize TMD's with start values */
1021 p
->tmdnum
= 0; /* First descriptor for transmitting */
1022 p
->tmdlast
= 0; /* First descriptor for reading stats */
1024 for (i
= 0; i
< TMDNUM
; i
++) /* Init all TMD's */
1026 tmdp
= p
->tmdhead
+ i
;
1028 writel((unsigned long) p
->tmdbufs
[i
], tmdp
->u
.buffer
); /* assign buffer */
1030 /* Mark TMD as start and end of packet */
1031 writeb(TX_STP
| TX_ENP
, tmdp
->u
.s
.status
);
1035 /* Initialize RMD's with start values */
1037 p
->rmdnum
= 0; /* First RMD which will be used */
1039 for (i
= 0; i
< RMDNUM
; i
++) /* Init all RMD's */
1041 rmdp
= p
->rmdhead
+ i
;
1044 writel((unsigned long) p
->rmdbufs
[i
], rmdp
->u
.buffer
); /* assign buffer */
1047 * LANCE must be owner at beginning so that he can fill in
1048 * receiving packets, set status and release RMD
1051 writeb(RX_OWN
, rmdp
->u
.s
.status
);
1053 writew(-PKT_BUF_SZ
, rmdp
->blen
); /* Buffer Size (two's complement) */
1055 writeb(0, rmdp
->mlen
); /* init message length */
1059 /* Fill LANCE Initialize Block */
1061 writew(mode
, (p
->ram
)->ib
.mode
); /* Set operation mode */
1063 for (i
= 0; i
< ETH_ALEN
; i
++) /* Set physical address */
1065 writeb(dev
->dev_addr
[i
], (p
->ram
)->ib
.paddr
[i
]);
1068 for (i
= 0; i
< 8; i
++) /* Set multicast, logical address */
1070 writeb(0, (p
->ram
)->ib
.laddr
[i
]); /* We do not use logical addressing */
1073 /* Set ring descriptor pointers and set number of descriptors */
1075 writel((int)p
->rmdhead
| RMDNUMMASK
, (p
->ram
)->ib
.rdrp
);
1076 writel((int)p
->tmdhead
| TMDNUMMASK
, (p
->ram
)->ib
.tdrp
);
1078 /* Prepare LANCE Control and Status Registers */
1083 SK_write_reg(CSR3
, CSR3_ACON
); /* Ale Control !!!THIS MUST BE SET!!!! */
1086 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1087 * PC Memory locations.
1089 * In structure SK_ram is defined that the first thing in ram
1090 * is the initialization block. So his address is for LANCE always
1093 * CSR1 contains low order bits 15:0 of initialization block address
1095 * 7:0 High order bits 23:16 of initialization block address
1096 * 15:8 reserved, must be 0
1099 /* Set initialization block address (must be on word boundary) */
1100 SK_write_reg(CSR1
, 0); /* Set low order bits 15:0 */
1101 SK_write_reg(CSR2
, 0); /* Set high order bits 23:16 */
1104 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
1105 SK_NAME
, SK_read_reg(CSR0
)));
1107 /* Initialize LANCE */
1110 * INIT = Initialize, when set, causes the LANCE to begin the
1111 * initialization procedure and access the Init Block.
1114 SK_write_reg(CSR0
, CSR0_INIT
);
1116 restore_flags(flags
);
1118 /* Wait until LANCE finished initialization */
1120 SK_set_RAP(CSR0
); /* Register Address Pointer to CSR0 */
1122 for (i
= 0; (i
< 100) && !(SK_rread_reg() & CSR0_IDON
); i
++)
1123 ; /* Wait until init done or go ahead if problems (i>=100) */
1125 if (i
>= 100) /* Something is wrong ! */
1127 printk("%s: can't init am7990, status: %04x "
1128 "init_block: %#08x\n",
1129 dev
->name
, (int) SK_read_reg(CSR0
),
1130 (unsigned int) &(p
->ram
)->ib
);
1133 SK_print_pos(dev
, "LANCE INIT failed");
1134 SK_print_dev(dev
,"Device Structure:");
1137 return -1; /* LANCE init failed */
1140 PRINTK(("## %s: init done after %d ticks\n", SK_NAME
, i
));
1142 /* Clear Initialize done, enable Interrupts, start LANCE */
1144 SK_write_reg(CSR0
, CSR0_IDON
| CSR0_INEA
| CSR0_STRT
);
1146 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME
,
1147 SK_read_reg(CSR0
)));
1149 return 0; /* LANCE is up and running */
1151 } /* End of SK_lance_init() */
1156 * Function : SK_send_packet
1157 * Author : Patrick J.D. Weichmann
1158 * Date Created : 94/05/27
1160 * Description : Writes an socket buffer into a transmit descriptor
1161 * and starts transmission.
1163 * Parameters : I : struct sk_buff *skb - packet to transfer
1164 * I : struct net_device *dev - SK_G16 device structure
1165 * Return Value : 0 - OK
1166 * 1 - Could not transmit (dev_queue_xmit will queue it)
1167 * and try to sent it later
1169 * Side Effects : None
1171 * YY/MM/DD uid Description
1174 static int SK_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1176 struct priv
*p
= (struct priv
*) dev
->priv
;
1181 /* if Transmitter more than 150ms busy -> time_out */
1183 int tickssofar
= jiffies
- dev
->trans_start
;
1184 if (tickssofar
< 15)
1186 return 1; /* We have to try transmit later */
1189 printk("%s: xmitter timed out, try to restart!\n", dev
->name
);
1191 SK_lance_init(dev
, MODE_NORMAL
); /* Reinit LANCE */
1193 dev
->tbusy
= 0; /* Clear Transmitter flag */
1195 dev
->trans_start
= jiffies
; /* Mark Start of transmission */
1199 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1200 SK_NAME
, SK_read_reg(CSR0
)));
1204 * Block a timer-based transmit from overlapping.
1205 * This means check if we are already in.
1208 if (test_and_set_bit(0, (void *) &dev
->tbusy
) != 0) /* dev->tbusy already set ? */
1210 printk("%s: Transmitter access conflict.\n", dev
->name
);
1214 /* Evaluate Packet length */
1215 short len
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1217 tmdp
= p
->tmdhead
+ p
->tmdnum
; /* Which descriptor for transmitting */
1219 /* Fill in Transmit Message Descriptor */
1221 /* Copy data into dual ported ram */
1223 memcpy_toio((tmdp
->u
.buffer
& 0x00ffffff), skb
->data
, skb
->len
);
1225 writew(-len
, tmdp
->blen
); /* set length to transmit */
1228 * Packet start and end is always set because we use the maximum
1229 * packet length as buffer length.
1230 * Relinquish ownership to LANCE
1233 writeb(TX_OWN
| TX_STP
| TX_ENP
, tmdp
->u
.s
.status
);
1235 /* Start Demand Transmission */
1236 SK_write_reg(CSR0
, CSR0_TDMD
| CSR0_INEA
);
1238 dev
->trans_start
= jiffies
; /* Mark start of transmission */
1240 /* Set pointer to next transmit buffer */
1242 p
->tmdnum
&= TMDNUM
-1;
1244 /* Do we own the next transmit buffer ? */
1245 if (! (readb((p
->tmdhead
+ p
->tmdnum
)->u
.s
.status
) & TX_OWN
) )
1248 * We own next buffer and are ready to transmit, so
1254 p
->stats
.tx_bytes
+= skb
->len
;
1258 } /* End of SK_send_packet */
1262 * Function : SK_interrupt
1263 * Author : Patrick J.D. Weichmann
1264 * Date Created : 94/05/27
1266 * Description : SK_G16 interrupt handler which checks for LANCE
1267 * Errors, handles transmit and receive interrupts
1269 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1270 * Return Value : None
1273 * Side Effects : None
1275 * YY/MM/DD uid Description
1278 static void SK_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
1281 struct net_device
*dev
= dev_id
;
1282 struct priv
*p
= (struct priv
*) dev
->priv
;
1285 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1286 SK_NAME
, SK_read_reg(CSR0
)));
1290 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq
);
1296 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
1299 csr0
= SK_read_reg(CSR0
); /* store register for checking */
1301 dev
->interrupt
= 1; /* We are handling an interrupt */
1304 * Acknowledge all of the current interrupt sources, disable
1305 * Interrupts (INEA = 0)
1308 SK_write_reg(CSR0
, csr0
& CSR0_CLRALL
);
1310 if (csr0
& CSR0_ERR
) /* LANCE Error */
1312 printk("%s: error: %04x\n", dev
->name
, csr0
);
1314 if (csr0
& CSR0_MISS
) /* No place to store packet ? */
1316 p
->stats
.rx_dropped
++;
1320 if (csr0
& CSR0_RINT
) /* Receive Interrupt (packet arrived) */
1325 if (csr0
& CSR0_TINT
) /* Transmit interrupt (packet sent) */
1330 SK_write_reg(CSR0
, CSR0_INEA
); /* Enable Interrupts */
1332 dev
->interrupt
= 0; /* We are out */
1333 } /* End of SK_interrupt() */
1337 * Function : SK_txintr
1338 * Author : Patrick J.D. Weichmann
1339 * Date Created : 94/05/27
1341 * Description : After sending a packet we check status, update
1342 * statistics and relinquish ownership of transmit
1345 * Parameters : I : struct net_device *dev - SK_G16 device structure
1346 * Return Value : None
1350 * YY/MM/DD uid Description
1353 static void SK_txintr(struct net_device
*dev
)
1357 struct priv
*p
= (struct priv
*) dev
->priv
;
1360 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1361 SK_NAME
, SK_read_reg(CSR0
)));
1363 tmdp
= p
->tmdhead
+ p
->tmdlast
; /* Which buffer we sent at last ? */
1365 /* Set next buffer */
1367 p
->tmdlast
&= TMDNUM
-1;
1369 tmdstat
= readb(tmdp
->u
.s
.status
);
1372 * We check status of transmitted packet.
1373 * see LANCE data-sheet for error explanation
1375 if (tmdstat
& TX_ERR
) /* Error occurred */
1377 int stat2
= readw(tmdp
->status2
);
1379 printk("%s: TX error: %04x %04x\n", dev
->name
, tmdstat
, stat2
);
1381 if (stat2
& TX_TDR
) /* TDR problems? */
1383 printk("%s: tdr-problems \n", dev
->name
);
1386 if (stat2
& TX_RTRY
) /* Failed in 16 attempts to transmit ? */
1387 p
->stats
.tx_aborted_errors
++;
1388 if (stat2
& TX_LCOL
) /* Late collision ? */
1389 p
->stats
.tx_window_errors
++;
1390 if (stat2
& TX_LCAR
) /* Loss of Carrier ? */
1391 p
->stats
.tx_carrier_errors
++;
1392 if (stat2
& TX_UFLO
) /* Underflow error ? */
1394 p
->stats
.tx_fifo_errors
++;
1397 * If UFLO error occurs it will turn transmitter of.
1398 * So we must reinit LANCE
1401 SK_lance_init(dev
, MODE_NORMAL
);
1404 p
->stats
.tx_errors
++;
1406 writew(0, tmdp
->status2
); /* Clear error flags */
1408 else if (tmdstat
& TX_MORE
) /* Collisions occurred ? */
1411 * Here I have a problem.
1412 * I only know that there must be one or up to 15 collisions.
1413 * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1414 * will be set which means couldn't send packet aborted transfer.
1416 * First I did not have this in but then I thought at minimum
1417 * we see that something was not ok.
1418 * If anyone knows something better than this to handle this
1422 p
->stats
.collisions
++;
1424 else /* Packet sent without any problems */
1426 p
->stats
.tx_packets
++;
1430 * We mark transmitter not busy anymore, because now we have a free
1431 * transmit descriptor which can be filled by SK_send_packet and
1432 * afterwards sent by the LANCE
1439 * This will cause net_bh() to run after this interrupt handler.
1441 * The function which do handle slow IRQ parts is do_bottom_half()
1442 * which runs at normal kernel priority, that means all interrupt are
1443 * enabled. (see kernel/irq.c)
1445 * net_bh does something like this:
1446 * - check if already in net_bh
1447 * - try to transmit something from the send queue
1448 * - if something is in the receive queue send it up to higher
1449 * levels if it is a known protocol
1450 * - try to transmit something from the send queue
1455 } /* End of SK_txintr() */
1459 * Function : SK_rxintr
1460 * Author : Patrick J.D. Weichmann
1461 * Date Created : 94/05/27
1463 * Description : Buffer sent, check for errors, relinquish ownership
1464 * of the receive message descriptor.
1466 * Parameters : I : SK_G16 device structure
1467 * Return Value : None
1470 * YY/MM/DD uid Description
1473 static void SK_rxintr(struct net_device
*dev
)
1478 struct priv
*p
= (struct priv
*) dev
->priv
;
1480 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1481 SK_NAME
, SK_read_reg(CSR0
)));
1483 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1485 /* As long as we own the next entry, check status and send
1486 * it up to higher layer
1489 while (!( (rmdstat
= readb(rmdp
->u
.s
.status
)) & RX_OWN
))
1492 * Start and end of packet must be set, because we use
1493 * the ethernet maximum packet length (1518) as buffer size.
1495 * Because our buffers are at maximum OFLO and BUFF errors are
1496 * not to be concerned (see Data sheet)
1499 if ((rmdstat
& (RX_STP
| RX_ENP
)) != (RX_STP
| RX_ENP
))
1501 /* Start of a frame > 1518 Bytes ? */
1503 if (rmdstat
& RX_STP
)
1505 p
->stats
.rx_errors
++; /* bad packet received */
1506 p
->stats
.rx_length_errors
++; /* packet too long */
1508 printk("%s: packet too long\n", dev
->name
);
1512 * All other packets will be ignored until a new frame with
1513 * start (RX_STP) set follows.
1515 * What we do is just give descriptor free for new incoming
1519 writeb(RX_OWN
, rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1522 else if (rmdstat
& RX_ERR
) /* Receive Error ? */
1524 printk("%s: RX error: %04x\n", dev
->name
, (int) rmdstat
);
1526 p
->stats
.rx_errors
++;
1528 if (rmdstat
& RX_FRAM
) p
->stats
.rx_frame_errors
++;
1529 if (rmdstat
& RX_CRC
) p
->stats
.rx_crc_errors
++;
1531 writeb(RX_OWN
, rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1534 else /* We have a packet which can be queued for the upper layers */
1537 int len
= readw(rmdp
->mlen
) & 0x0fff; /* extract message length from receive buffer */
1538 struct sk_buff
*skb
;
1540 skb
= dev_alloc_skb(len
+2); /* allocate socket buffer */
1542 if (skb
== NULL
) /* Could not get mem ? */
1546 * Couldn't allocate sk_buffer so we give descriptor back
1547 * to Lance, update statistics and go ahead.
1550 writeb(RX_OWN
, rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1551 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1553 p
->stats
.rx_dropped
++;
1555 break; /* Jump out */
1558 /* Prepare sk_buff to queue for upper layers */
1561 skb_reserve(skb
,2); /* Align IP header on 16 byte boundary */
1564 * Copy data out of our receive descriptor into sk_buff.
1566 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1567 * ignore status fields)
1570 memcpy_fromio(skb_put(skb
,len
), (rmdp
->u
.buffer
& 0x00ffffff), len
);
1574 * Notify the upper protocol layers that there is another packet
1577 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1580 skb
->protocol
=eth_type_trans(skb
,dev
);
1581 netif_rx(skb
); /* queue packet and mark it for processing */
1584 * Packet is queued and marked for processing so we
1585 * free our descriptor and update statistics
1588 writeb(RX_OWN
, rmdp
->u
.s
.status
);
1589 p
->stats
.rx_packets
++;
1590 p
->stats
.rx_bytes
+= len
;
1594 p
->rmdnum
%= RMDNUM
;
1596 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1599 } /* End of SK_rxintr() */
1603 * Function : SK_close
1604 * Author : Patrick J.D. Weichmann
1605 * Date Created : 94/05/26
1607 * Description : close gets called from dev_close() and should
1608 * deinstall the card (free_irq, mem etc).
1610 * Parameters : I : struct net_device *dev - our device structure
1611 * Return Value : 0 - closed device driver
1615 * YY/MM/DD uid Description
1618 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1619 * down' the system stops. So I don't shut set card to init state.
1622 static int SK_close(struct net_device
*dev
)
1625 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1626 SK_NAME
, SK_read_reg(CSR0
)));
1628 dev
->tbusy
= 1; /* Transmitter busy */
1629 dev
->start
= 0; /* Card down */
1631 printk("%s: Shutting %s down CSR0 %#06x\n", dev
->name
, SK_NAME
,
1632 (int) SK_read_reg(CSR0
));
1634 SK_write_reg(CSR0
, CSR0_STOP
); /* STOP the LANCE */
1636 free_irq(dev
->irq
, dev
); /* Free IRQ */
1638 return 0; /* always succeed */
1640 } /* End of SK_close() */
1644 * Function : SK_get_stats
1645 * Author : Patrick J.D. Weichmann
1646 * Date Created : 94/05/26
1648 * Description : Return current status structure to upper layers.
1649 * It is called by sprintf_stats (dev.c).
1651 * Parameters : I : struct net_device *dev - our device structure
1652 * Return Value : struct net_device_stats * - our current statistics
1654 * Side Effects : None
1656 * YY/MM/DD uid Description
1659 static struct net_device_stats
*SK_get_stats(struct net_device
*dev
)
1662 struct priv
*p
= (struct priv
*) dev
->priv
;
1664 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1665 SK_NAME
, SK_read_reg(CSR0
)));
1667 return &p
->stats
; /* Return Device status */
1669 } /* End of SK_get_stats() */
1673 * Function : set_multicast_list
1674 * Author : Patrick J.D. Weichmann
1675 * Date Created : 94/05/26
1677 * Description : This function gets called when a program performs
1678 * a SIOCSIFFLAGS call. Ifconfig does this if you call
1679 * 'ifconfig [-]allmulti' which enables or disables the
1681 * Promiscuous mode is when the Network card accepts all
1682 * packets, not only the packets which match our MAC
1683 * Address. It is useful for writing a network monitor,
1684 * but it is also a security problem. You have to remember
1685 * that all information on the net is not encrypted.
1687 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1688 * Return Value : None
1692 * YY/MM/DD uid Description
1693 * 95/10/18 ACox New multicast calling scheme
1697 /* Set or clear the multicast filter for SK_G16.
1700 static void set_multicast_list(struct net_device
*dev
)
1703 if (dev
->flags
&IFF_PROMISC
)
1705 /* Reinitialize LANCE with MODE_PROM set */
1706 SK_lance_init(dev
, MODE_PROM
);
1708 else if (dev
->mc_count
==0 && !(dev
->flags
&IFF_ALLMULTI
))
1710 /* Reinitialize LANCE without MODE_PROM */
1711 SK_lance_init(dev
, MODE_NORMAL
);
1715 /* Multicast with logical address filter on */
1716 /* Reinitialize LANCE without MODE_PROM */
1717 SK_lance_init(dev
, MODE_NORMAL
);
1719 /* Not implemented yet. */
1721 } /* End of set_multicast_list() */
1726 * Function : SK_rom_addr
1727 * Author : Patrick J.D. Weichmann
1728 * Date Created : 94/06/01
1730 * Description : Try to find a Boot_ROM at all possible locations
1733 * Return Value : Address where Boot_ROM is
1734 * Errors : 0 - Did not find Boot_ROM
1737 * YY/MM/DD uid Description
1740 unsigned int __init
SK_rom_addr(void)
1744 unsigned int rom_location
[] = SK_BOOT_ROM_LOCATIONS
;
1745 unsigned char rom_id
[] = SK_BOOT_ROM_ID
;
1746 unsigned char test_byte
;
1748 /* Autodetect Boot_ROM */
1749 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME
));
1751 for (i
= 0; (rom_location
[i
] != 0) && (rom_found
== 0); i
++)
1754 PRINTK(("## Trying ROM location %#08x", rom_location
[i
]));
1757 for (j
= 0; j
< 6; j
++)
1759 test_byte
= readb(rom_location
[i
]+j
);
1760 PRINTK((" %02x ", *test_byte
));
1762 if(test_byte
!= rom_id
[j
])
1772 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1773 SK_NAME
, rom_location
[(i
-1)]));
1775 return (rom_location
[--i
]);
1779 PRINTK(("%s: No Boot_ROM found\n", SK_NAME
));
1782 } /* End of SK_rom_addr() */
1786 /* LANCE access functions
1788 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1793 * Function : SK_reset_board
1795 * Author : Patrick J.D. Weichmann
1797 * Date Created : 94/05/25
1799 * Description : This function resets SK_G16 and all components, but
1800 * POS registers are not changed
1803 * Return Value : None
1805 * Globals : SK_RAM *board - SK_RAM structure pointer
1808 * YY/MM/DD uid Description
1811 void SK_reset_board(void)
1813 writeb(0x00, SK_PORT
); /* Reset active */
1814 mdelay(5); /* Delay min 5ms */
1815 writeb(SK_RESET
, SK_PORT
); /* Set back to normal operation */
1817 } /* End of SK_reset_board() */
1821 * Function : SK_set_RAP
1822 * Author : Patrick J.D. Weichmann
1823 * Date Created : 94/05/25
1825 * Description : Set LANCE Register Address Port to register
1826 * for later data transfer.
1828 * Parameters : I : reg_number - which CSR to read/write from/to
1829 * Return Value : None
1831 * Globals : SK_RAM *board - SK_RAM structure pointer
1833 * YY/MM/DD uid Description
1836 void SK_set_RAP(int reg_number
)
1838 writew(reg_number
, SK_IOREG
);
1839 writeb(SK_RESET
| SK_RAP
| SK_WREG
, SK_PORT
);
1840 writeb(SK_DOIO
, SK_IOCOM
);
1842 while (readb(SK_PORT
) & SK_IORUN
)
1844 } /* End of SK_set_RAP() */
1848 * Function : SK_read_reg
1849 * Author : Patrick J.D. Weichmann
1850 * Date Created : 94/05/25
1852 * Description : Set RAP and read data from a LANCE CSR register
1854 * Parameters : I : reg_number - which CSR to read from
1855 * Return Value : Register contents
1857 * Globals : SK_RAM *board - SK_RAM structure pointer
1859 * YY/MM/DD uid Description
1862 int SK_read_reg(int reg_number
)
1864 SK_set_RAP(reg_number
);
1866 writeb(SK_RESET
| SK_RDATA
| SK_RREG
, SK_PORT
);
1867 writeb(SK_DOIO
, SK_IOCOM
);
1869 while (readb(SK_PORT
) & SK_IORUN
)
1871 return (readw(SK_IOREG
));
1873 } /* End of SK_read_reg() */
1877 * Function : SK_rread_reg
1878 * Author : Patrick J.D. Weichmann
1879 * Date Created : 94/05/28
1881 * Description : Read data from preseted register.
1882 * This function requires that you know which
1883 * Register is actually set. Be aware that CSR1-3
1884 * can only be accessed when in CSR0 STOP is set.
1886 * Return Value : Register contents
1888 * Globals : SK_RAM *board - SK_RAM structure pointer
1890 * YY/MM/DD uid Description
1893 int SK_rread_reg(void)
1895 writeb(SK_RESET
| SK_RDATA
| SK_RREG
, SK_PORT
);
1897 writeb(SK_DOIO
, SK_IOCOM
);
1899 while (readb(SK_PORT
) & SK_IORUN
)
1901 return (readw(SK_IOREG
));
1903 } /* End of SK_rread_reg() */
1907 * Function : SK_write_reg
1908 * Author : Patrick J.D. Weichmann
1909 * Date Created : 94/05/25
1911 * Description : This function sets the RAP then fills in the
1912 * LANCE I/O Reg and starts Transfer to LANCE.
1913 * It waits until transfer has ended which is max. 7 ms
1914 * and then it returns.
1916 * Parameters : I : reg_number - which CSR to write to
1917 * I : value - what value to fill into register
1918 * Return Value : None
1920 * Globals : SK_RAM *board - SK_RAM structure pointer
1922 * YY/MM/DD uid Description
1925 void SK_write_reg(int reg_number
, int value
)
1927 SK_set_RAP(reg_number
);
1929 writew(value
, SK_IOREG
);
1930 writeb(SK_RESET
| SK_RDATA
| SK_WREG
, SK_PORT
);
1931 writeb(SK_DOIO
, SK_IOCOM
);
1933 while (readb(SK_PORT
) & SK_IORUN
)
1935 } /* End of SK_write_reg */
1940 * Debugging functions
1941 * -------------------
1945 * Function : SK_print_pos
1946 * Author : Patrick J.D. Weichmann
1947 * Date Created : 94/05/25
1949 * Description : This function prints out the 4 POS (Programmable
1950 * Option Select) Registers. Used mainly to debug operation.
1952 * Parameters : I : struct net_device *dev - SK_G16 device structure
1953 * I : char * - Text which will be printed as title
1954 * Return Value : None
1957 * YY/MM/DD uid Description
1960 void SK_print_pos(struct net_device
*dev
, char *text
)
1962 int ioaddr
= dev
->base_addr
;
1964 unsigned char pos0
= inb(SK_POS0
),
1965 pos1
= inb(SK_POS1
),
1966 pos2
= inb(SK_POS2
),
1967 pos3
= inb(SK_POS3
),
1968 pos4
= inb(SK_POS4
);
1971 printk("## %s: %s.\n"
1972 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
1973 SK_NAME
, text
, pos0
, pos1
, pos2
, (pos3
<<14), pos4
);
1975 } /* End of SK_print_pos() */
1980 * Function : SK_print_dev
1981 * Author : Patrick J.D. Weichmann
1982 * Date Created : 94/05/25
1984 * Description : This function simply prints out the important fields
1985 * of the device structure.
1987 * Parameters : I : struct net_device *dev - SK_G16 device structure
1988 * I : char *text - Title for printing
1989 * Return Value : None
1992 * YY/MM/DD uid Description
1995 void SK_print_dev(struct net_device
*dev
, char *text
)
1999 printk("## %s: Device Structure. %s\n", SK_NAME
, text
);
2000 printk("## DEVICE == NULL\n");
2004 printk("## %s: Device Structure. %s\n", SK_NAME
, text
);
2005 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",
2006 dev
->name
, dev
->base_addr
, dev
->irq
);
2008 printk("## FLAGS: start: %d tbusy: %ld int: %ld\n",
2009 dev
->start
, dev
->tbusy
, dev
->interrupt
);
2011 printk("## next device: %#08x init function: %#08x\n",
2012 (int) dev
->next
, (int) dev
->init
);
2015 } /* End of SK_print_dev() */
2020 * Function : SK_print_ram
2021 * Author : Patrick J.D. Weichmann
2022 * Date Created : 94/06/02
2024 * Description : This function is used to check how are things set up
2025 * in the 16KB RAM. Also the pointers to the receive and
2026 * transmit descriptor rings and rx and tx buffers locations.
2027 * It contains a minor bug in printing, but has no effect to the values
2028 * only newlines are not correct.
2030 * Parameters : I : struct net_device *dev - SK_G16 device structure
2031 * Return Value : None
2035 * YY/MM/DD uid Description
2038 void SK_print_ram(struct net_device
*dev
)
2042 struct priv
*p
= (struct priv
*) dev
->priv
;
2044 printk("## %s: RAM Details.\n"
2045 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2047 (unsigned int) p
->ram
,
2048 (unsigned int) p
->tmdhead
,
2049 (unsigned int) p
->rmdhead
,
2050 (unsigned int) &(p
->ram
)->ib
);
2054 for(i
= 0; i
< TMDNUM
; i
++)
2056 if (!(i
% 3)) /* Every third line do a newline */
2060 printk("tmdbufs%d: %#08x ", (i
+1), (int) p
->tmdbufs
[i
]);
2064 for(i
= 0; i
< RMDNUM
; i
++)
2066 if (!(i
% 3)) /* Every third line do a newline */
2070 printk("rmdbufs%d: %#08x ", (i
+1), (int) p
->rmdbufs
[i
]);
2074 } /* End of SK_print_ram() */