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 $
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
22 * Jeff Garzik, 06/2000, Modularize
26 static const char rcsid
[] = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
29 * The Schneider & Koch (SK) G16 Network device driver is based
30 * on the 'ni6510' driver from Michael Hipp which can be found at
31 * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
33 * Sources: 1) ni6510.c by M. Hipp
34 * 2) depca.c by D.C. Davies
35 * 3) skeleton.c by D. Becker
36 * 4) Am7990 Local Area Network Controller for Ethernet (LANCE),
37 * AMD, Pub. #05698, June 1989
39 * Many Thanks for helping me to get things working to:
41 * A. Cox (A.Cox@swansea.ac.uk)
42 * M. Hipp (mhipp@student.uni-tuebingen.de)
43 * R. Bolz (Schneider & Koch, Germany)
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/fcntl.h>
64 #include <linux/ioport.h>
65 #include <linux/interrupt.h>
66 #include <linux/slab.h>
67 #include <linux/string.h>
68 #include <linux/delay.h>
69 #include <linux/errno.h>
70 #include <linux/init.h>
71 #include <linux/spinlock.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
74 #include <linux/skbuff.h>
75 #include <linux/bitops.h>
77 #include <asm/system.h>
83 * Schneider & Koch Card Definitions
84 * =================================
87 #define SK_NAME "SK_G16"
90 * SK_G16 Configuration
91 * --------------------
98 * RAM - used for the 16KB shared memory
99 * Boot_ROM, ROM - are used for referencing the BootEPROM
101 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
102 * the behaviour of the driver and the SK_G16.
104 * ! See sk_g16.install on how to install and configure the driver !
106 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
108 * SK_ADDR defines the address where the RAM will be mapped into the real
110 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
113 #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
115 #define SK_ADDR 0xcc000
118 * In POS3 are bits A14-A19 of the address bus. These bits can be set
119 * to choose the RAM address. That's why we only can choose the RAM address
123 #define POS_ADDR (rom_addr>>14) /* Do not change this line */
126 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
127 * ----------------------------------------------
131 * As nearly every card has also SK_G16 a specified I/O Port region and
132 * only a few possible IRQ's.
133 * In the Installation Guide from Schneider & Koch is listed a possible
134 * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
135 * controllers. So we use in SK_IRQS IRQ9.
138 /* Don't touch any of the following #defines. */
140 #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
142 #define SK_IRQS { 3, 5, 9, 11, 0 }
144 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
146 #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
149 * SK_G16 POS REGISTERS
150 * --------------------
154 * SK_G16 has a Programmable Option Select (POS) Register.
155 * The POS is composed of 8 separate registers (POS0-7) which
156 * are I/O mapped on an address set by the W1 switch.
160 #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
162 #define SK_POS0 ioaddr /* Card-ID Low (R) */
163 #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
164 #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
165 #define SK_POS3 ioaddr+3 /* Base address of RAM */
166 #define SK_POS4 ioaddr+4 /* IRQ */
168 /* POS5 - POS7 are unused */
176 * Scheider & Koch manufacturer code (00:00:a5).
177 * This must be checked, that we are sure it is a SK card.
190 * If POS0,POS1 contain the following ID, then we know
191 * at which I/O Port Address we are.
194 #define SK_IDLOW 0xfd
195 #define SK_IDHIGH 0x6a
199 * LANCE POS Bit definitions
200 * -------------------------
203 #define SK_ROM_RAM_ON (POS2_CARD)
204 #define SK_ROM_RAM_OFF (POS2_EPROM)
205 #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
206 #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
207 #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
208 #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
210 #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
211 #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
214 * SK_G16 Memory mapped Registers
215 * ------------------------------
219 #define SK_IOREG (&board->ioreg) /* LANCE data registers. */
220 #define SK_PORT (&board->port) /* Control, Status register */
221 #define SK_IOCOM (&board->iocom) /* I/O Command */
224 * SK_G16 Status/Control Register bits
225 * -----------------------------------
227 * (C) Controlreg (S) Statusreg
231 * Register transfer: 0 = no transfer
232 * 1 = transferring data between LANCE and I/O reg
234 #define SK_IORUN 0x20
237 * LANCE interrupt: 0 = LANCE interrupt occurred
238 * 1 = no LANCE interrupt occurred
242 #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
243 #define SK_RW 0x02 /* 0 = write to 1 = read from */
244 #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
247 #define SK_RREG SK_RW /* Transferdirection to read from lance */
248 #define SK_WREG 0 /* Transferdirection to write to lance */
249 #define SK_RAP SK_ADR /* Destination Register RAP */
250 #define SK_RDATA 0 /* Destination Register REG DataPort */
258 * Any bitcombination sets the internal I/O bit (transfer will start)
259 * when written to I/O Command
262 #define SK_DOIO 0x80 /* Do Transfer */
265 * LANCE RAP (Register Address Port).
266 * ---------------------------------
270 * The LANCE internal registers are selected through the RAP.
273 * CSR0 - Status and Control flags
274 * CSR1 - Low order bits of initialize block (bits 15:00)
275 * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
276 * CSR3 - Allows redefinition of the Bus Master Interface.
277 * This register must be set to 0x0002, which means BSWAP = 0,
278 * ACON = 1, BCON = 0;
288 * General Definitions
289 * ===================
293 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
294 * We have 16KB RAM which can be accessed by the LANCE. In the
295 * memory are not only the buffers but also the ring descriptors and
296 * the initialize block.
297 * Don't change anything unless you really know what you do.
300 #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
301 #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */
303 /* Descriptor ring sizes */
305 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
306 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
308 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
310 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
311 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
314 * Data Buffer size is set to maximum packet length.
317 #define PKT_BUF_SZ 1518
320 * The number of low I/O ports used by the ethercard.
323 #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
328 * Here you can choose what level of debugging wanted.
330 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
331 * necessary messages will be printed.
333 * If SK_DEBUG is defined, there will be many debugging prints
334 * which can help to find some mistakes in configuration or even
335 * in the driver code.
337 * If SK_DEBUG2 is defined, many many messages will be printed
338 * which normally you don't need. I used this to check the interrupt
341 * (If you define only SK_DEBUG2 then only the messages for
342 * checking interrupts will be printed!)
344 * Normal way of live is:
346 * For the whole thing get going let both symbolic constants
347 * undefined. If you face any problems and you know what's going
348 * on (you know something about the card and you can interpret some
349 * hex LANCE register output) then define SK_DEBUG
353 #undef SK_DEBUG /* debugging */
354 #undef SK_DEBUG2 /* debugging with more verbose report */
357 #define PRINTK(x) printk x
359 #define PRINTK(x) /**/
363 #define PRINTK2(x) printk x
365 #define PRINTK2(x) /**/
371 * The components are memory mapped and can be set in a region from
372 * 0x00000 through 0xfc000 in 16KB steps.
374 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
375 * Controlregister and I/O Command.
377 * dual ported RAM: This is the only memory region which the LANCE chip
378 * has access to. From the Lance it is addressed from 0x0000 to
379 * 0x3fbf. The host accesses it normally.
381 * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
382 * 8-Bit PROM, this means only the 16 even addresses are used of the
383 * 32 Byte Address region. Access to an odd address results in invalid
386 * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
387 * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
388 * Transfer from or to the LANCE is always in 16Bit so Low and High
389 * registers are always relevant.
391 * The Data from the Readregister is not the data in the Writeregister!!
393 * Port: Status- and Controlregister.
394 * Two different registers which share the same address, Status is
395 * read-only, Control is write-only.
398 * Any bitcombination written in here starts the transmission between
404 unsigned char ram
[0x3fc0]; /* 16KB dual ported ram */
405 unsigned char rom
[0x0020]; /* 32Byte PROM containing 6Byte MAC */
406 unsigned char res1
[0x0010]; /* reserved */
407 unsigned volatile short ioreg
;/* LANCE I/O Register */
408 unsigned volatile char port
; /* Statusregister and Controlregister */
409 unsigned char iocom
; /* I/O Command Register */
415 * This is the structure for the dual ported ram. We
416 * have exactly 16 320 Bytes. In here there must be:
418 * - Initialize Block (starting at a word boundary)
419 * - Receive and Transmit Descriptor Rings (quadword boundary)
420 * - Data Buffers (arbitrary boundary)
422 * This is because LANCE has on SK_G16 only access to the dual ported
423 * RAM and nowhere else.
428 struct init_block ib
;
429 struct tmd tmde
[TMDNUM
];
430 struct rmd rmde
[RMDNUM
];
431 char tmdbuf
[TMDNUM
][PKT_BUF_SZ
];
432 char rmdbuf
[RMDNUM
][PKT_BUF_SZ
];
436 * Structure where all necessary information is for ring buffer
437 * management and statistics.
442 struct SK_ram
*ram
; /* dual ported ram structure */
443 struct rmd
*rmdhead
; /* start of receive ring descriptors */
444 struct tmd
*tmdhead
; /* start of transmit ring descriptors */
445 int rmdnum
; /* actual used ring descriptor */
446 int tmdnum
; /* actual transmit descriptor for transmitting data */
447 int tmdlast
; /* last sent descriptor used for error handling, etc */
448 void *rmdbufs
[RMDNUM
]; /* pointer to the receive buffers */
449 void *tmdbufs
[TMDNUM
]; /* pointer to the transmit buffers */
450 struct net_device_stats stats
; /* Device driver statistics */
453 /* global variable declaration */
455 /* IRQ map used to reserve a IRQ (see SK_open()) */
457 /* static variables */
459 static SK_RAM
*board
; /* pointer to our memory mapped board components */
460 static DEFINE_SPINLOCK(SK_lock
);
465 /* Function Prototypes */
468 * Device Driver functions
469 * -----------------------
470 * See for short explanation of each function its definitions header.
473 static int SK_probe(struct net_device
*dev
, short ioaddr
);
475 static void SK_timeout(struct net_device
*dev
);
476 static int SK_open(struct net_device
*dev
);
477 static int SK_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
478 static irqreturn_t
SK_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
);
479 static void SK_rxintr(struct net_device
*dev
);
480 static void SK_txintr(struct net_device
*dev
);
481 static int SK_close(struct net_device
*dev
);
483 static struct net_device_stats
*SK_get_stats(struct net_device
*dev
);
485 unsigned int SK_rom_addr(void);
487 static void set_multicast_list(struct net_device
*dev
);
494 static int SK_lance_init(struct net_device
*dev
, unsigned short mode
);
495 void SK_reset_board(void);
496 void SK_set_RAP(int reg_number
);
497 int SK_read_reg(int reg_number
);
498 int SK_rread_reg(void);
499 void SK_write_reg(int reg_number
, int value
);
502 * Debugging functions
503 * -------------------
506 void SK_print_pos(struct net_device
*dev
, char *text
);
507 void SK_print_dev(struct net_device
*dev
, char *text
);
508 void SK_print_ram(struct net_device
*dev
);
513 * Author : Patrick J.D. Weichmann
514 * Date Created : 94/05/26
516 * Description : Check for a SK_G16 network adaptor and initialize it.
517 * This function gets called by dev_init which initializes
518 * all Network devices.
520 * Parameters : I : struct net_device *dev - structure preconfigured
522 * Return Value : 0 = Driver Found and initialized
523 * Errors : ENODEV - no device found
527 * YY/MM/DD uid Description
530 static int io
; /* 0 == probe */
533 * Check for a network adaptor of this type, and return '0' if one exists.
534 * If dev->base_addr == 0, probe all likely locations.
535 * If dev->base_addr == 1, always return failure.
538 struct net_device
* __init
SK_init(int unit
)
540 int *port
, ports
[] = SK_IO_PORTS
; /* SK_G16 supported ports */
541 static unsigned version_printed
;
542 struct net_device
*dev
= alloc_etherdev(sizeof(struct priv
));
546 return ERR_PTR(-ENOMEM
);
549 sprintf(dev
->name
, "eth%d", unit
);
550 netdev_boot_setup_check(dev
);
554 if (version_printed
++ == 0)
555 PRINTK(("%s: %s", SK_NAME
, rcsid
));
557 if (io
> 0xff) { /* Check a single specified address */
559 /* Check if on specified address is a SK_G16 */
560 if (request_region(io
, ETHERCARD_TOTAL_SIZE
, "sk_g16")) {
561 err
= SK_probe(dev
, io
);
564 release_region(io
, ETHERCARD_TOTAL_SIZE
);
566 } else if (io
> 0) { /* Don't probe at all */
569 /* Autoprobe base_addr */
570 for (port
= &ports
[0]; *port
; port
++) {
573 /* Check if I/O Port region is used by another board */
574 if (!request_region(io
, ETHERCARD_TOTAL_SIZE
, "sk_g16"))
575 continue; /* Try next Port address */
577 /* Check if at ioaddr is a SK_G16 */
578 if (SK_probe(dev
, io
) == 0)
581 release_region(io
, ETHERCARD_TOTAL_SIZE
);
589 err
= register_netdev(dev
);
591 release_region(dev
->base_addr
, ETHERCARD_TOTAL_SIZE
);
596 } /* End of SK_init */
599 MODULE_AUTHOR("Patrick J.D. Weichmann");
600 MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
601 MODULE_LICENSE("GPL");
602 MODULE_PARM(io
, "i");
603 MODULE_PARM_DESC(io
, "0 to probe common ports (unsafe), or the I/O base of the board");
608 static struct net_device
*SK_dev
;
610 static int __init
SK_init_module (void)
612 SK_dev
= SK_init(-1);
613 return IS_ERR(SK_dev
) ? PTR_ERR(SK_dev
) : 0;
616 static void __exit
SK_cleanup_module (void)
618 unregister_netdev(SK_dev
);
619 release_region(SK_dev
->base_addr
, ETHERCARD_TOTAL_SIZE
);
623 module_init(SK_init_module
);
624 module_exit(SK_cleanup_module
);
629 * Function : SK_probe
630 * Author : Patrick J.D. Weichmann
631 * Date Created : 94/05/26
633 * Description : This function is called by SK_init and
634 * does the main part of initialization.
636 * Parameters : I : struct net_device *dev - SK_G16 device structure
637 * I : short ioaddr - I/O Port address where POS is.
638 * Return Value : 0 = Initialization done
639 * Errors : ENODEV - No SK_G16 found
640 * -1 - Configuration problem
641 * Globals : board - pointer to SK_RAM
643 * YY/MM/DD uid Description
644 * 94/06/30 pwe SK_ADDR now checked and at the correct place
647 int __init
SK_probe(struct net_device
*dev
, short ioaddr
)
649 int i
,j
; /* Counters */
650 int sk_addr_flag
= 0; /* SK ADDR correct? 1 - no, 0 - yes */
651 unsigned int rom_addr
; /* used to store RAM address used for POS_ADDR */
653 struct priv
*p
= netdev_priv(dev
); /* SK_G16 private structure */
655 if (inb(SK_POS0
) != SK_IDLOW
|| inb(SK_POS1
) != SK_IDHIGH
)
657 dev
->base_addr
= ioaddr
;
659 if (SK_ADDR
& 0x3fff || SK_ADDR
< 0xa0000)
665 * Now here we could use a routine which searches for a free
666 * place in the ram and set SK_ADDR if found. TODO.
670 if (SK_BOOT_ROM
) /* Shall we keep Boot_ROM on ? */
672 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME
));
674 rom_addr
= SK_rom_addr();
676 if (rom_addr
== 0) /* No Boot_ROM found */
678 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
680 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
685 rom_addr
= SK_ADDR
; /* assign predefined address */
687 PRINTK(("## %s: NO Bootrom found \n", SK_NAME
));
689 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
690 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
691 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
693 else if (rom_addr
== SK_ADDR
)
695 printk("%s: RAM + ROM are set to the same address %#08x\n"
696 " Check configuration. Now switching off Boot_ROM\n",
699 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off*/
700 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
701 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
705 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME
, rom_addr
));
706 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME
));
708 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
710 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
717 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
718 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
719 outb(SK_ROM_RAM_ON
, SK_POS2
); /* RAM on, BOOT_ROM on */
722 else /* Don't keep Boot_ROM */
724 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME
));
726 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
728 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
733 rom_addr
= SK_rom_addr(); /* Try to find a Boot_ROM */
735 /* IF we find a Boot_ROM disable it */
737 outb(SK_ROM_RAM_OFF
, SK_POS2
); /* Boot_ROM + RAM off */
739 /* We found a Boot_ROM and it's gone. Set RAM address on
745 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
746 "that address\n", SK_NAME
, rom_addr
);
748 outb(POS_ADDR
, SK_POS3
); /* Set RAM on Boot_ROM address */
750 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
752 if (sk_addr_flag
) /* No or Invalid SK_ADDR is defined */
754 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
761 outb(POS_ADDR
, SK_POS3
); /* Set RAM address */
763 outb(SK_RAM_ON
, SK_POS2
); /* enable RAM */
767 SK_print_pos(dev
, "POS registers after ROM, RAM config");
770 board
= (SK_RAM
*) isa_bus_to_virt(rom_addr
);
772 /* Read in station address */
773 for (i
= 0, j
= 0; i
< ETH_ALEN
; i
++, j
+=2)
775 dev
->dev_addr
[i
] = readb(board
->rom
+j
);
778 /* Check for manufacturer code */
779 if (!(dev
->dev_addr
[0] == SK_MAC0
&&
780 dev
->dev_addr
[1] == SK_MAC1
&&
781 dev
->dev_addr
[2] == SK_MAC2
) )
783 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
785 return -ENODEV
; /* NO SK_G16 found */
788 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
790 "Schneider & Koch Netcard",
791 (unsigned int) dev
->base_addr
,
799 memset((char *) dev
->priv
, 0, sizeof(struct priv
)); /* clear memory */
801 /* Assign our Device Driver functions */
804 dev
->stop
= SK_close
;
805 dev
->hard_start_xmit
= SK_send_packet
;
806 dev
->get_stats
= SK_get_stats
;
807 dev
->set_multicast_list
= set_multicast_list
;
808 dev
->tx_timeout
= SK_timeout
;
809 dev
->watchdog_timeo
= HZ
/7;
812 dev
->flags
&= ~IFF_MULTICAST
;
814 /* Initialize private structure */
816 p
->ram
= (struct SK_ram
*) rom_addr
; /* Set dual ported RAM addr */
817 p
->tmdhead
= &(p
->ram
)->tmde
[0]; /* Set TMD head */
818 p
->rmdhead
= &(p
->ram
)->rmde
[0]; /* Set RMD head */
820 /* Initialize buffer pointers */
822 for (i
= 0; i
< TMDNUM
; i
++)
824 p
->tmdbufs
[i
] = &(p
->ram
)->tmdbuf
[i
];
827 for (i
= 0; i
< RMDNUM
; i
++)
829 p
->rmdbufs
[i
] = &(p
->ram
)->rmdbuf
[i
];
833 SK_print_pos(dev
, "End of SK_probe");
836 return 0; /* Initialization done */
837 } /* End of SK_probe() */
842 * Author : Patrick J.D. Weichmann
843 * Date Created : 94/05/26
845 * Description : This function is called sometimes after booting
846 * when ifconfig program is run.
848 * This function requests an IRQ, sets the correct
849 * IRQ in the card. Then calls SK_lance_init() to
850 * init and start the LANCE chip. Then if everything is
851 * ok returns with 0 (OK), which means SK_G16 is now
852 * opened and operational.
854 * (Called by dev_open() /net/inet/dev.c)
856 * Parameters : I : struct net_device *dev - SK_G16 device structure
857 * Return Value : 0 - Device opened
858 * Errors : -EAGAIN - Open failed
859 * Side Effects : None
861 * YY/MM/DD uid Description
864 static int SK_open(struct net_device
*dev
)
868 int ioaddr
= dev
->base_addr
;
870 int irqtab
[] = SK_IRQS
;
872 struct priv
*p
= netdev_priv(dev
);
874 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
875 SK_NAME
, SK_read_reg(CSR0
)));
877 if (dev
->irq
== 0) /* Autoirq */
882 * Check if one IRQ out of SK_IRQS is free and install
884 * Most done by request_irq().
885 * irqval: 0 - interrupt handler installed for IRQ irqtab[i]
886 * -EBUSY - interrupt busy
887 * -EINVAL - irq > 15 or handler = NULL
892 irqval
= request_irq(irqtab
[i
], &SK_interrupt
, 0, "sk_g16", dev
);
894 } while (irqval
&& irqtab
[i
]);
896 if (irqval
) /* We tried every possible IRQ but no success */
898 printk("%s: unable to get an IRQ\n", dev
->name
);
902 dev
->irq
= irqtab
[--i
];
904 outb(i
<<2, SK_POS4
); /* Set Card on probed IRQ */
907 else if (dev
->irq
== 2) /* IRQ2 is always IRQ9 */
909 if (request_irq(9, &SK_interrupt
, 0, "sk_g16", dev
))
911 printk("%s: unable to get IRQ 9\n", dev
->name
);
917 * Now we set card on IRQ2.
918 * This can be confusing, but remember that IRQ2 on the network
919 * card is in reality IRQ9
921 outb(0x08, SK_POS4
); /* set card to IRQ2 */
924 else /* Check IRQ as defined in Space.c */
928 /* check if IRQ free and valid. Then install Interrupt handler */
930 if (request_irq(dev
->irq
, &SK_interrupt
, 0, "sk_g16", dev
))
932 printk("%s: unable to get selected IRQ\n", dev
->name
);
947 printk("%s: Preselected IRQ %d is invalid for %s boards",
954 outb(i
<<2, SK_POS4
); /* Set IRQ on card */
957 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
958 dev
->name
, (unsigned int)dev
->base_addr
,
959 (int) dev
->irq
, (unsigned int) p
->ram
);
961 if (!(i
= SK_lance_init(dev
, 0))) /* LANCE init OK? */
963 netif_start_queue(dev
);
968 * This debug block tries to stop LANCE,
969 * reinit LANCE with transmitter and receiver disabled,
970 * then stop again and reinit with NORMAL_MODE
973 printk("## %s: After lance init. CSR0: %#06x\n",
974 SK_NAME
, SK_read_reg(CSR0
));
975 SK_write_reg(CSR0
, CSR0_STOP
);
976 printk("## %s: LANCE stopped. CSR0: %#06x\n",
977 SK_NAME
, SK_read_reg(CSR0
));
978 SK_lance_init(dev
, MODE_DTX
| MODE_DRX
);
979 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n",
980 SK_NAME
, SK_read_reg(CSR0
));
981 SK_write_reg(CSR0
, CSR0_STOP
);
982 printk("## %s: LANCE stopped. CSR0: %#06x\n",
983 SK_NAME
, SK_read_reg(CSR0
));
984 SK_lance_init(dev
, MODE_NORMAL
);
985 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n",
986 SK_NAME
, SK_read_reg(CSR0
));
987 SK_print_pos(dev
, "POS regs before returning OK");
989 #endif /* SK_DEBUG */
991 return 0; /* SK_open() is successful */
993 else /* LANCE init failed */
996 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
997 SK_NAME
, SK_read_reg(CSR0
)));
1002 } /* End of SK_open() */
1006 * Function : SK_lance_init
1007 * Author : Patrick J.D. Weichmann
1008 * Date Created : 94/05/26
1010 * Description : Reset LANCE chip, fill RMD, TMD structures with
1011 * start values and Start LANCE.
1013 * Parameters : I : struct net_device *dev - SK_G16 device structure
1014 * I : int mode - put LANCE into "mode" see data-sheet for
1016 * Return Value : 0 - Init done
1017 * Errors : -1 - Init failed
1019 * YY/MM/DD uid Description
1022 static int SK_lance_init(struct net_device
*dev
, unsigned short mode
)
1025 unsigned long flags
;
1026 struct priv
*p
= netdev_priv(dev
);
1030 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1031 SK_NAME
, SK_read_reg(CSR0
)));
1036 /* Initialize TMD's with start values */
1037 p
->tmdnum
= 0; /* First descriptor for transmitting */
1038 p
->tmdlast
= 0; /* First descriptor for reading stats */
1040 for (i
= 0; i
< TMDNUM
; i
++) /* Init all TMD's */
1042 tmdp
= p
->tmdhead
+ i
;
1044 writel((unsigned long) p
->tmdbufs
[i
], tmdp
->u
.buffer
); /* assign buffer */
1046 /* Mark TMD as start and end of packet */
1047 writeb(TX_STP
| TX_ENP
, &tmdp
->u
.s
.status
);
1051 /* Initialize RMD's with start values */
1053 p
->rmdnum
= 0; /* First RMD which will be used */
1055 for (i
= 0; i
< RMDNUM
; i
++) /* Init all RMD's */
1057 rmdp
= p
->rmdhead
+ i
;
1060 writel((unsigned long) p
->rmdbufs
[i
], rmdp
->u
.buffer
); /* assign buffer */
1063 * LANCE must be owner at beginning so that he can fill in
1064 * receiving packets, set status and release RMD
1067 writeb(RX_OWN
, &rmdp
->u
.s
.status
);
1069 writew(-PKT_BUF_SZ
, &rmdp
->blen
); /* Buffer Size (two's complement) */
1071 writeb(0, &rmdp
->mlen
); /* init message length */
1075 /* Fill LANCE Initialize Block */
1077 writew(mode
, (&((p
->ram
)->ib
.mode
))); /* Set operation mode */
1079 for (i
= 0; i
< ETH_ALEN
; i
++) /* Set physical address */
1081 writeb(dev
->dev_addr
[i
], (&((p
->ram
)->ib
.paddr
[i
])));
1084 for (i
= 0; i
< 8; i
++) /* Set multicast, logical address */
1086 writeb(0, (&((p
->ram
)->ib
.laddr
[i
]))); /* We do not use logical addressing */
1089 /* Set ring descriptor pointers and set number of descriptors */
1091 writel((int)p
->rmdhead
| RMDNUMMASK
, (&((p
->ram
)->ib
.rdrp
)));
1092 writel((int)p
->tmdhead
| TMDNUMMASK
, (&((p
->ram
)->ib
.tdrp
)));
1094 /* Prepare LANCE Control and Status Registers */
1096 spin_lock_irqsave(&SK_lock
, flags
);
1098 SK_write_reg(CSR3
, CSR3_ACON
); /* Ale Control !!!THIS MUST BE SET!!!! */
1101 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1102 * PC Memory locations.
1104 * In structure SK_ram is defined that the first thing in ram
1105 * is the initialization block. So his address is for LANCE always
1108 * CSR1 contains low order bits 15:0 of initialization block address
1110 * 7:0 High order bits 23:16 of initialization block address
1111 * 15:8 reserved, must be 0
1114 /* Set initialization block address (must be on word boundary) */
1115 SK_write_reg(CSR1
, 0); /* Set low order bits 15:0 */
1116 SK_write_reg(CSR2
, 0); /* Set high order bits 23:16 */
1119 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
1120 SK_NAME
, SK_read_reg(CSR0
)));
1122 /* Initialize LANCE */
1125 * INIT = Initialize, when set, causes the LANCE to begin the
1126 * initialization procedure and access the Init Block.
1129 SK_write_reg(CSR0
, CSR0_INIT
);
1131 spin_unlock_irqrestore(&SK_lock
, flags
);
1133 /* Wait until LANCE finished initialization */
1135 SK_set_RAP(CSR0
); /* Register Address Pointer to CSR0 */
1137 for (i
= 0; (i
< 100) && !(SK_rread_reg() & CSR0_IDON
); i
++)
1138 ; /* Wait until init done or go ahead if problems (i>=100) */
1140 if (i
>= 100) /* Something is wrong ! */
1142 printk("%s: can't init am7990, status: %04x "
1143 "init_block: %#08x\n",
1144 dev
->name
, (int) SK_read_reg(CSR0
),
1145 (unsigned int) &(p
->ram
)->ib
);
1148 SK_print_pos(dev
, "LANCE INIT failed");
1149 SK_print_dev(dev
,"Device Structure:");
1152 return -1; /* LANCE init failed */
1155 PRINTK(("## %s: init done after %d ticks\n", SK_NAME
, i
));
1157 /* Clear Initialize done, enable Interrupts, start LANCE */
1159 SK_write_reg(CSR0
, CSR0_IDON
| CSR0_INEA
| CSR0_STRT
);
1161 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME
,
1162 SK_read_reg(CSR0
)));
1164 return 0; /* LANCE is up and running */
1166 } /* End of SK_lance_init() */
1171 * Function : SK_send_packet
1172 * Author : Patrick J.D. Weichmann
1173 * Date Created : 94/05/27
1175 * Description : Writes an socket buffer into a transmit descriptor
1176 * and starts transmission.
1178 * Parameters : I : struct sk_buff *skb - packet to transfer
1179 * I : struct net_device *dev - SK_G16 device structure
1180 * Return Value : 0 - OK
1181 * 1 - Could not transmit (dev_queue_xmit will queue it)
1182 * and try to sent it later
1184 * Side Effects : None
1186 * YY/MM/DD uid Description
1189 static void SK_timeout(struct net_device
*dev
)
1191 printk(KERN_WARNING
"%s: xmitter timed out, try to restart!\n", dev
->name
);
1192 SK_lance_init(dev
, MODE_NORMAL
); /* Reinit LANCE */
1193 netif_wake_queue(dev
); /* Clear Transmitter flag */
1194 dev
->trans_start
= jiffies
; /* Mark Start of transmission */
1197 static int SK_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1199 struct priv
*p
= netdev_priv(dev
);
1201 static char pad
[64];
1203 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1204 SK_NAME
, SK_read_reg(CSR0
)));
1208 * Block a timer-based transmit from overlapping.
1209 * This means check if we are already in.
1212 netif_stop_queue (dev
);
1216 /* Evaluate Packet length */
1217 short len
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1219 tmdp
= p
->tmdhead
+ p
->tmdnum
; /* Which descriptor for transmitting */
1221 /* Fill in Transmit Message Descriptor */
1223 /* Copy data into dual ported ram */
1225 memcpy_toio((tmdp
->u
.buffer
& 0x00ffffff), skb
->data
, skb
->len
);
1226 if (len
!= skb
->len
)
1227 memcpy_toio((tmdp
->u
.buffer
& 0x00ffffff) + skb
->len
, pad
, len
-skb
->len
);
1229 writew(-len
, &tmdp
->blen
); /* set length to transmit */
1232 * Packet start and end is always set because we use the maximum
1233 * packet length as buffer length.
1234 * Relinquish ownership to LANCE
1237 writeb(TX_OWN
| TX_STP
| TX_ENP
, &tmdp
->u
.s
.status
);
1239 /* Start Demand Transmission */
1240 SK_write_reg(CSR0
, CSR0_TDMD
| CSR0_INEA
);
1242 dev
->trans_start
= jiffies
; /* Mark start of transmission */
1244 /* Set pointer to next transmit buffer */
1246 p
->tmdnum
&= TMDNUM
-1;
1248 /* Do we own the next transmit buffer ? */
1249 if (! (readb(&((p
->tmdhead
+ p
->tmdnum
)->u
.s
.status
)) & TX_OWN
) )
1252 * We own next buffer and are ready to transmit, so
1255 netif_start_queue(dev
);
1258 p
->stats
.tx_bytes
+= skb
->len
;
1264 } /* End of SK_send_packet */
1268 * Function : SK_interrupt
1269 * Author : Patrick J.D. Weichmann
1270 * Date Created : 94/05/27
1272 * Description : SK_G16 interrupt handler which checks for LANCE
1273 * Errors, handles transmit and receive interrupts
1275 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1276 * Return Value : None
1279 * Side Effects : None
1281 * YY/MM/DD uid Description
1284 static irqreturn_t
SK_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
1287 struct net_device
*dev
= dev_id
;
1288 struct priv
*p
= netdev_priv(dev
);
1291 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1292 SK_NAME
, SK_read_reg(CSR0
)));
1296 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq
);
1299 spin_lock (&SK_lock
);
1301 csr0
= SK_read_reg(CSR0
); /* store register for checking */
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 spin_unlock (&SK_lock
);
1334 } /* End of SK_interrupt() */
1338 * Function : SK_txintr
1339 * Author : Patrick J.D. Weichmann
1340 * Date Created : 94/05/27
1342 * Description : After sending a packet we check status, update
1343 * statistics and relinquish ownership of transmit
1346 * Parameters : I : struct net_device *dev - SK_G16 device structure
1347 * Return Value : None
1351 * YY/MM/DD uid Description
1354 static void SK_txintr(struct net_device
*dev
)
1358 struct priv
*p
= netdev_priv(dev
);
1361 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1362 SK_NAME
, SK_read_reg(CSR0
)));
1364 tmdp
= p
->tmdhead
+ p
->tmdlast
; /* Which buffer we sent at last ? */
1366 /* Set next buffer */
1368 p
->tmdlast
&= TMDNUM
-1;
1370 tmdstat
= readb(&tmdp
->u
.s
.status
);
1373 * We check status of transmitted packet.
1374 * see LANCE data-sheet for error explanation
1376 if (tmdstat
& TX_ERR
) /* Error occurred */
1378 int stat2
= readw(&tmdp
->status2
);
1380 printk("%s: TX error: %04x %04x\n", dev
->name
, tmdstat
, stat2
);
1382 if (stat2
& TX_TDR
) /* TDR problems? */
1384 printk("%s: tdr-problems \n", dev
->name
);
1387 if (stat2
& TX_RTRY
) /* Failed in 16 attempts to transmit ? */
1388 p
->stats
.tx_aborted_errors
++;
1389 if (stat2
& TX_LCOL
) /* Late collision ? */
1390 p
->stats
.tx_window_errors
++;
1391 if (stat2
& TX_LCAR
) /* Loss of Carrier ? */
1392 p
->stats
.tx_carrier_errors
++;
1393 if (stat2
& TX_UFLO
) /* Underflow error ? */
1395 p
->stats
.tx_fifo_errors
++;
1398 * If UFLO error occurs it will turn transmitter of.
1399 * So we must reinit LANCE
1402 SK_lance_init(dev
, MODE_NORMAL
);
1405 p
->stats
.tx_errors
++;
1407 writew(0, &tmdp
->status2
); /* Clear error flags */
1409 else if (tmdstat
& TX_MORE
) /* Collisions occurred ? */
1412 * Here I have a problem.
1413 * I only know that there must be one or up to 15 collisions.
1414 * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1415 * will be set which means couldn't send packet aborted transfer.
1417 * First I did not have this in but then I thought at minimum
1418 * we see that something was not ok.
1419 * If anyone knows something better than this to handle this
1423 p
->stats
.collisions
++;
1425 else /* Packet sent without any problems */
1427 p
->stats
.tx_packets
++;
1431 * We mark transmitter not busy anymore, because now we have a free
1432 * transmit descriptor which can be filled by SK_send_packet and
1433 * afterwards sent by the LANCE
1435 * The function which do handle slow IRQ parts is do_bottom_half()
1436 * which runs at normal kernel priority, that means all interrupt are
1437 * enabled. (see kernel/irq.c)
1439 * net_bh does something like this:
1440 * - check if already in net_bh
1441 * - try to transmit something from the send queue
1442 * - if something is in the receive queue send it up to higher
1443 * levels if it is a known protocol
1444 * - try to transmit something from the send queue
1447 netif_wake_queue(dev
);
1449 } /* End of SK_txintr() */
1453 * Function : SK_rxintr
1454 * Author : Patrick J.D. Weichmann
1455 * Date Created : 94/05/27
1457 * Description : Buffer sent, check for errors, relinquish ownership
1458 * of the receive message descriptor.
1460 * Parameters : I : SK_G16 device structure
1461 * Return Value : None
1464 * YY/MM/DD uid Description
1467 static void SK_rxintr(struct net_device
*dev
)
1472 struct priv
*p
= netdev_priv(dev
);
1474 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1475 SK_NAME
, SK_read_reg(CSR0
)));
1477 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1479 /* As long as we own the next entry, check status and send
1480 * it up to higher layer
1483 while (!( (rmdstat
= readb(&rmdp
->u
.s
.status
)) & RX_OWN
))
1486 * Start and end of packet must be set, because we use
1487 * the ethernet maximum packet length (1518) as buffer size.
1489 * Because our buffers are at maximum OFLO and BUFF errors are
1490 * not to be concerned (see Data sheet)
1493 if ((rmdstat
& (RX_STP
| RX_ENP
)) != (RX_STP
| RX_ENP
))
1495 /* Start of a frame > 1518 Bytes ? */
1497 if (rmdstat
& RX_STP
)
1499 p
->stats
.rx_errors
++; /* bad packet received */
1500 p
->stats
.rx_length_errors
++; /* packet too long */
1502 printk("%s: packet too long\n", dev
->name
);
1506 * All other packets will be ignored until a new frame with
1507 * start (RX_STP) set follows.
1509 * What we do is just give descriptor free for new incoming
1513 writeb(RX_OWN
, &rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1516 else if (rmdstat
& RX_ERR
) /* Receive Error ? */
1518 printk("%s: RX error: %04x\n", dev
->name
, (int) rmdstat
);
1520 p
->stats
.rx_errors
++;
1522 if (rmdstat
& RX_FRAM
) p
->stats
.rx_frame_errors
++;
1523 if (rmdstat
& RX_CRC
) p
->stats
.rx_crc_errors
++;
1525 writeb(RX_OWN
, &rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1528 else /* We have a packet which can be queued for the upper layers */
1531 int len
= readw(&rmdp
->mlen
) & 0x0fff; /* extract message length from receive buffer */
1532 struct sk_buff
*skb
;
1534 skb
= dev_alloc_skb(len
+2); /* allocate socket buffer */
1536 if (skb
== NULL
) /* Could not get mem ? */
1540 * Couldn't allocate sk_buffer so we give descriptor back
1541 * to Lance, update statistics and go ahead.
1544 writeb(RX_OWN
, &rmdp
->u
.s
.status
); /* Relinquish ownership to LANCE */
1545 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1547 p
->stats
.rx_dropped
++;
1549 break; /* Jump out */
1552 /* Prepare sk_buff to queue for upper layers */
1555 skb_reserve(skb
,2); /* Align IP header on 16 byte boundary */
1558 * Copy data out of our receive descriptor into sk_buff.
1560 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1561 * ignore status fields)
1564 memcpy_fromio(skb_put(skb
,len
), (rmdp
->u
.buffer
& 0x00ffffff), len
);
1568 * Notify the upper protocol layers that there is another packet
1571 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1574 skb
->protocol
=eth_type_trans(skb
,dev
);
1575 netif_rx(skb
); /* queue packet and mark it for processing */
1578 * Packet is queued and marked for processing so we
1579 * free our descriptor and update statistics
1582 writeb(RX_OWN
, &rmdp
->u
.s
.status
);
1583 dev
->last_rx
= jiffies
;
1584 p
->stats
.rx_packets
++;
1585 p
->stats
.rx_bytes
+= len
;
1589 p
->rmdnum
%= RMDNUM
;
1591 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1594 } /* End of SK_rxintr() */
1598 * Function : SK_close
1599 * Author : Patrick J.D. Weichmann
1600 * Date Created : 94/05/26
1602 * Description : close gets called from dev_close() and should
1603 * deinstall the card (free_irq, mem etc).
1605 * Parameters : I : struct net_device *dev - our device structure
1606 * Return Value : 0 - closed device driver
1610 * YY/MM/DD uid Description
1613 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1614 * down' the system stops. So I don't shut set card to init state.
1617 static int SK_close(struct net_device
*dev
)
1620 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1621 SK_NAME
, SK_read_reg(CSR0
)));
1623 netif_stop_queue(dev
); /* Transmitter busy */
1625 printk("%s: Shutting %s down CSR0 %#06x\n", dev
->name
, SK_NAME
,
1626 (int) SK_read_reg(CSR0
));
1628 SK_write_reg(CSR0
, CSR0_STOP
); /* STOP the LANCE */
1630 free_irq(dev
->irq
, dev
); /* Free IRQ */
1632 return 0; /* always succeed */
1634 } /* End of SK_close() */
1638 * Function : SK_get_stats
1639 * Author : Patrick J.D. Weichmann
1640 * Date Created : 94/05/26
1642 * Description : Return current status structure to upper layers.
1643 * It is called by sprintf_stats (dev.c).
1645 * Parameters : I : struct net_device *dev - our device structure
1646 * Return Value : struct net_device_stats * - our current statistics
1648 * Side Effects : None
1650 * YY/MM/DD uid Description
1653 static struct net_device_stats
*SK_get_stats(struct net_device
*dev
)
1656 struct priv
*p
= netdev_priv(dev
);
1658 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1659 SK_NAME
, SK_read_reg(CSR0
)));
1661 return &p
->stats
; /* Return Device status */
1663 } /* End of SK_get_stats() */
1667 * Function : set_multicast_list
1668 * Author : Patrick J.D. Weichmann
1669 * Date Created : 94/05/26
1671 * Description : This function gets called when a program performs
1672 * a SIOCSIFFLAGS call. Ifconfig does this if you call
1673 * 'ifconfig [-]allmulti' which enables or disables the
1675 * Promiscuous mode is when the Network card accepts all
1676 * packets, not only the packets which match our MAC
1677 * Address. It is useful for writing a network monitor,
1678 * but it is also a security problem. You have to remember
1679 * that all information on the net is not encrypted.
1681 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1682 * Return Value : None
1686 * YY/MM/DD uid Description
1687 * 95/10/18 ACox New multicast calling scheme
1691 /* Set or clear the multicast filter for SK_G16.
1694 static void set_multicast_list(struct net_device
*dev
)
1697 if (dev
->flags
&IFF_PROMISC
)
1699 /* Reinitialize LANCE with MODE_PROM set */
1700 SK_lance_init(dev
, MODE_PROM
);
1702 else if (dev
->mc_count
==0 && !(dev
->flags
&IFF_ALLMULTI
))
1704 /* Reinitialize LANCE without MODE_PROM */
1705 SK_lance_init(dev
, MODE_NORMAL
);
1709 /* Multicast with logical address filter on */
1710 /* Reinitialize LANCE without MODE_PROM */
1711 SK_lance_init(dev
, MODE_NORMAL
);
1713 /* Not implemented yet. */
1715 } /* End of set_multicast_list() */
1720 * Function : SK_rom_addr
1721 * Author : Patrick J.D. Weichmann
1722 * Date Created : 94/06/01
1724 * Description : Try to find a Boot_ROM at all possible locations
1727 * Return Value : Address where Boot_ROM is
1728 * Errors : 0 - Did not find Boot_ROM
1731 * YY/MM/DD uid Description
1734 unsigned int __init
SK_rom_addr(void)
1738 unsigned int rom_location
[] = SK_BOOT_ROM_LOCATIONS
;
1739 unsigned char rom_id
[] = SK_BOOT_ROM_ID
;
1740 unsigned char test_byte
;
1742 /* Autodetect Boot_ROM */
1743 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME
));
1745 for (i
= 0; (rom_location
[i
] != 0) && (rom_found
== 0); i
++)
1748 PRINTK(("## Trying ROM location %#08x", rom_location
[i
]));
1751 for (j
= 0; j
< 6; j
++)
1753 test_byte
= readb(rom_location
[i
]+j
);
1754 PRINTK((" %02x ", *test_byte
));
1756 if(test_byte
!= rom_id
[j
])
1766 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1767 SK_NAME
, rom_location
[(i
-1)]));
1769 return (rom_location
[--i
]);
1773 PRINTK(("%s: No Boot_ROM found\n", SK_NAME
));
1776 } /* End of SK_rom_addr() */
1780 /* LANCE access functions
1782 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1787 * Function : SK_reset_board
1789 * Author : Patrick J.D. Weichmann
1791 * Date Created : 94/05/25
1793 * Description : This function resets SK_G16 and all components, but
1794 * POS registers are not changed
1797 * Return Value : None
1799 * Globals : SK_RAM *board - SK_RAM structure pointer
1802 * YY/MM/DD uid Description
1805 void SK_reset_board(void)
1807 writeb(0x00, SK_PORT
); /* Reset active */
1808 mdelay(5); /* Delay min 5ms */
1809 writeb(SK_RESET
, SK_PORT
); /* Set back to normal operation */
1811 } /* End of SK_reset_board() */
1815 * Function : SK_set_RAP
1816 * Author : Patrick J.D. Weichmann
1817 * Date Created : 94/05/25
1819 * Description : Set LANCE Register Address Port to register
1820 * for later data transfer.
1822 * Parameters : I : reg_number - which CSR to read/write from/to
1823 * Return Value : None
1825 * Globals : SK_RAM *board - SK_RAM structure pointer
1827 * YY/MM/DD uid Description
1830 void SK_set_RAP(int reg_number
)
1832 writew(reg_number
, SK_IOREG
);
1833 writeb(SK_RESET
| SK_RAP
| SK_WREG
, SK_PORT
);
1834 writeb(SK_DOIO
, SK_IOCOM
);
1836 while (readb(SK_PORT
) & SK_IORUN
)
1838 } /* End of SK_set_RAP() */
1842 * Function : SK_read_reg
1843 * Author : Patrick J.D. Weichmann
1844 * Date Created : 94/05/25
1846 * Description : Set RAP and read data from a LANCE CSR register
1848 * Parameters : I : reg_number - which CSR to read from
1849 * Return Value : Register contents
1851 * Globals : SK_RAM *board - SK_RAM structure pointer
1853 * YY/MM/DD uid Description
1856 int SK_read_reg(int reg_number
)
1858 SK_set_RAP(reg_number
);
1860 writeb(SK_RESET
| SK_RDATA
| SK_RREG
, SK_PORT
);
1861 writeb(SK_DOIO
, SK_IOCOM
);
1863 while (readb(SK_PORT
) & SK_IORUN
)
1865 return (readw(SK_IOREG
));
1867 } /* End of SK_read_reg() */
1871 * Function : SK_rread_reg
1872 * Author : Patrick J.D. Weichmann
1873 * Date Created : 94/05/28
1875 * Description : Read data from preseted register.
1876 * This function requires that you know which
1877 * Register is actually set. Be aware that CSR1-3
1878 * can only be accessed when in CSR0 STOP is set.
1880 * Return Value : Register contents
1882 * Globals : SK_RAM *board - SK_RAM structure pointer
1884 * YY/MM/DD uid Description
1887 int SK_rread_reg(void)
1889 writeb(SK_RESET
| SK_RDATA
| SK_RREG
, SK_PORT
);
1891 writeb(SK_DOIO
, SK_IOCOM
);
1893 while (readb(SK_PORT
) & SK_IORUN
)
1895 return (readw(SK_IOREG
));
1897 } /* End of SK_rread_reg() */
1901 * Function : SK_write_reg
1902 * Author : Patrick J.D. Weichmann
1903 * Date Created : 94/05/25
1905 * Description : This function sets the RAP then fills in the
1906 * LANCE I/O Reg and starts Transfer to LANCE.
1907 * It waits until transfer has ended which is max. 7 ms
1908 * and then it returns.
1910 * Parameters : I : reg_number - which CSR to write to
1911 * I : value - what value to fill into register
1912 * Return Value : None
1914 * Globals : SK_RAM *board - SK_RAM structure pointer
1916 * YY/MM/DD uid Description
1919 void SK_write_reg(int reg_number
, int value
)
1921 SK_set_RAP(reg_number
);
1923 writew(value
, SK_IOREG
);
1924 writeb(SK_RESET
| SK_RDATA
| SK_WREG
, SK_PORT
);
1925 writeb(SK_DOIO
, SK_IOCOM
);
1927 while (readb(SK_PORT
) & SK_IORUN
)
1929 } /* End of SK_write_reg */
1934 * Debugging functions
1935 * -------------------
1939 * Function : SK_print_pos
1940 * Author : Patrick J.D. Weichmann
1941 * Date Created : 94/05/25
1943 * Description : This function prints out the 4 POS (Programmable
1944 * Option Select) Registers. Used mainly to debug operation.
1946 * Parameters : I : struct net_device *dev - SK_G16 device structure
1947 * I : char * - Text which will be printed as title
1948 * Return Value : None
1951 * YY/MM/DD uid Description
1954 void SK_print_pos(struct net_device
*dev
, char *text
)
1956 int ioaddr
= dev
->base_addr
;
1958 unsigned char pos0
= inb(SK_POS0
),
1959 pos1
= inb(SK_POS1
),
1960 pos2
= inb(SK_POS2
),
1961 pos3
= inb(SK_POS3
),
1962 pos4
= inb(SK_POS4
);
1965 printk("## %s: %s.\n"
1966 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
1967 SK_NAME
, text
, pos0
, pos1
, pos2
, (pos3
<<14), pos4
);
1969 } /* End of SK_print_pos() */
1974 * Function : SK_print_dev
1975 * Author : Patrick J.D. Weichmann
1976 * Date Created : 94/05/25
1978 * Description : This function simply prints out the important fields
1979 * of the device structure.
1981 * Parameters : I : struct net_device *dev - SK_G16 device structure
1982 * I : char *text - Title for printing
1983 * Return Value : None
1986 * YY/MM/DD uid Description
1989 void SK_print_dev(struct net_device
*dev
, char *text
)
1993 printk("## %s: Device Structure. %s\n", SK_NAME
, text
);
1994 printk("## DEVICE == NULL\n");
1998 printk("## %s: Device Structure. %s\n", SK_NAME
, text
);
1999 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",
2000 dev
->name
, dev
->base_addr
, dev
->irq
);
2002 printk("## next device: %#08x init function: %#08x\n",
2003 (int) dev
->next
, (int) dev
->init
);
2006 } /* End of SK_print_dev() */
2011 * Function : SK_print_ram
2012 * Author : Patrick J.D. Weichmann
2013 * Date Created : 94/06/02
2015 * Description : This function is used to check how are things set up
2016 * in the 16KB RAM. Also the pointers to the receive and
2017 * transmit descriptor rings and rx and tx buffers locations.
2018 * It contains a minor bug in printing, but has no effect to the values
2019 * only newlines are not correct.
2021 * Parameters : I : struct net_device *dev - SK_G16 device structure
2022 * Return Value : None
2026 * YY/MM/DD uid Description
2029 void __init
SK_print_ram(struct net_device
*dev
)
2033 struct priv
*p
= netdev_priv(dev
);
2035 printk("## %s: RAM Details.\n"
2036 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2038 (unsigned int) p
->ram
,
2039 (unsigned int) p
->tmdhead
,
2040 (unsigned int) p
->rmdhead
,
2041 (unsigned int) &(p
->ram
)->ib
);
2045 for(i
= 0; i
< TMDNUM
; i
++)
2047 if (!(i
% 3)) /* Every third line do a newline */
2051 printk("tmdbufs%d: %#08x ", (i
+1), (int) p
->tmdbufs
[i
]);
2055 for(i
= 0; i
< RMDNUM
; i
++)
2057 if (!(i
% 3)) /* Every third line do a newline */
2061 printk("rmdbufs%d: %#08x ", (i
+1), (int) p
->rmdbufs
[i
]);
2065 } /* End of SK_print_ram() */