aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sk_g16.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/sk_g16.c')
-rw-r--r--drivers/net/sk_g16.c2066
1 files changed, 0 insertions, 2066 deletions
diff --git a/drivers/net/sk_g16.c b/drivers/net/sk_g16.c
deleted file mode 100644
index 134ae0e6495b..000000000000
--- a/drivers/net/sk_g16.c
+++ /dev/null
@@ -1,2066 +0,0 @@
1/*-
2 * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
3 *
4 * This software may be used and distributed according to the terms
5 * of the GNU General Public License, incorporated herein by reference.
6 *
7 * Module : sk_g16.c
8 *
9 * Version : $Revision: 1.1 $
10 *
11 * Author : Patrick J.D. Weichmann
12 *
13 * Date Created : 94/05/26
14 * Last Updated : $Date: 1994/06/30 16:25:15 $
15 *
16 * Description : Schneider & Koch G16 Ethernet Device Driver for
17 * Linux Kernel >= 1.1.22
18 * Update History :
19 * Paul Gortmaker, 03/97: Fix for v2.1.x to use read{b,w}
20 * write{b,w} and memcpy -> memcpy_{to,from}io
21 *
22 * Jeff Garzik, 06/2000, Modularize
23 *
24-*/
25
26static const char rcsid[] = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
27
28/*
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
32 *
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
38 *
39 * Many Thanks for helping me to get things working to:
40 *
41 * A. Cox (A.Cox@swansea.ac.uk)
42 * M. Hipp (mhipp@student.uni-tuebingen.de)
43 * R. Bolz (Schneider & Koch, Germany)
44 *
45 * To Do:
46 * - Support of SK_G8 and other SK Network Cards.
47 * - Autoset memory mapped RAM. Check for free memory and then
48 * configure RAM correctly.
49 * - SK_close should really set card in to initial state.
50 * - Test if IRQ 3 is not switched off. Use autoirq() functionality.
51 * (as in /drivers/net/skeleton.c)
52 * - Implement Multicast addressing. At minimum something like
53 * in depca.c.
54 * - Redo the statistics part.
55 * - Try to find out if the board is in 8 Bit or 16 Bit slot.
56 * If in 8 Bit mode don't use IRQ 11.
57 * - (Try to make it slightly faster.)
58 * - Power management support
59 */
60
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>
76
77#include <asm/system.h>
78#include <asm/io.h>
79
80#include "sk_g16.h"
81
82/*
83 * Schneider & Koch Card Definitions
84 * =================================
85 */
86
87#define SK_NAME "SK_G16"
88
89/*
90 * SK_G16 Configuration
91 * --------------------
92 */
93
94/*
95 * Abbreviations
96 * -------------
97 *
98 * RAM - used for the 16KB shared memory
99 * Boot_ROM, ROM - are used for referencing the BootEPROM
100 *
101 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
102 * the behaviour of the driver and the SK_G16.
103 *
104 * ! See sk_g16.install on how to install and configure the driver !
105 *
106 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
107 *
108 * SK_ADDR defines the address where the RAM will be mapped into the real
109 * host memory.
110 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
111 */
112
113#define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
114
115#define SK_ADDR 0xcc000
116
117/*
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
120 * in 16KB steps.
121 */
122
123#define POS_ADDR (rom_addr>>14) /* Do not change this line */
124
125/*
126 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
127 * ----------------------------------------------
128 */
129
130/*
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.
136 */
137
138/* Don't touch any of the following #defines. */
139
140#define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
141
142#define SK_IRQS { 3, 5, 9, 11, 0 }
143
144#define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
145
146#define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
147
148/*
149 * SK_G16 POS REGISTERS
150 * --------------------
151 */
152
153/*
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.
157 *
158 */
159
160#define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
161
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 */
167
168/* POS5 - POS7 are unused */
169
170/*
171 * SK_G16 MAC PREFIX
172 * -----------------
173 */
174
175/*
176 * Scheider & Koch manufacturer code (00:00:a5).
177 * This must be checked, that we are sure it is a SK card.
178 */
179
180#define SK_MAC0 0x00
181#define SK_MAC1 0x00
182#define SK_MAC2 0x5a
183
184/*
185 * SK_G16 ID
186 * ---------
187 */
188
189/*
190 * If POS0,POS1 contain the following ID, then we know
191 * at which I/O Port Address we are.
192 */
193
194#define SK_IDLOW 0xfd
195#define SK_IDHIGH 0x6a
196
197
198/*
199 * LANCE POS Bit definitions
200 * -------------------------
201 */
202
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)
209
210#define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
211#define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
212
213/*
214 * SK_G16 Memory mapped Registers
215 * ------------------------------
216 *
217 */
218
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 */
222
223/*
224 * SK_G16 Status/Control Register bits
225 * -----------------------------------
226 *
227 * (C) Controlreg (S) Statusreg
228 */
229
230/*
231 * Register transfer: 0 = no transfer
232 * 1 = transferring data between LANCE and I/O reg
233 */
234#define SK_IORUN 0x20
235
236/*
237 * LANCE interrupt: 0 = LANCE interrupt occurred
238 * 1 = no LANCE interrupt occurred
239 */
240#define SK_IRQ 0x10
241
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 */
245
246
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 */
251
252/*
253 * SK_G16 I/O Command
254 * ------------------
255 */
256
257/*
258 * Any bitcombination sets the internal I/O bit (transfer will start)
259 * when written to I/O Command
260 */
261
262#define SK_DOIO 0x80 /* Do Transfer */
263
264/*
265 * LANCE RAP (Register Address Port).
266 * ---------------------------------
267 */
268
269/*
270 * The LANCE internal registers are selected through the RAP.
271 * The Registers are:
272 *
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;
279 *
280 */
281
282#define CSR0 0x00
283#define CSR1 0x01
284#define CSR2 0x02
285#define CSR3 0x03
286
287/*
288 * General Definitions
289 * ===================
290 */
291
292/*
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.
298 */
299
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 */
302
303/* Descriptor ring sizes */
304
305#define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
306#define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
307
308/* Define Mask for setting RMD, TMD length in the LANCE init_block */
309
310#define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
311#define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
312
313/*
314 * Data Buffer size is set to maximum packet length.
315 */
316
317#define PKT_BUF_SZ 1518
318
319/*
320 * The number of low I/O ports used by the ethercard.
321 */
322
323#define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
324
325/*
326 * SK_DEBUG
327 *
328 * Here you can choose what level of debugging wanted.
329 *
330 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
331 * necessary messages will be printed.
332 *
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.
336 *
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
339 * routine.
340 *
341 * (If you define only SK_DEBUG2 then only the messages for
342 * checking interrupts will be printed!)
343 *
344 * Normal way of live is:
345 *
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
350 *
351 */
352
353#undef SK_DEBUG /* debugging */
354#undef SK_DEBUG2 /* debugging with more verbose report */
355
356#ifdef SK_DEBUG
357#define PRINTK(x) printk x
358#else
359#define PRINTK(x) /**/
360#endif
361
362#ifdef SK_DEBUG2
363#define PRINTK2(x) printk x
364#else
365#define PRINTK2(x) /**/
366#endif
367
368/*
369 * SK_G16 RAM
370 *
371 * The components are memory mapped and can be set in a region from
372 * 0x00000 through 0xfc000 in 16KB steps.
373 *
374 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
375 * Controlregister and I/O Command.
376 *
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.
380 *
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
384 * data.
385 *
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.
390 *
391 * The Data from the Readregister is not the data in the Writeregister!!
392 *
393 * Port: Status- and Controlregister.
394 * Two different registers which share the same address, Status is
395 * read-only, Control is write-only.
396 *
397 * I/O Command:
398 * Any bitcombination written in here starts the transmission between
399 * Host and LANCE.
400 */
401
402typedef struct
403{
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 */
410} SK_RAM;
411
412/* struct */
413
414/*
415 * This is the structure for the dual ported ram. We
416 * have exactly 16 320 Bytes. In here there must be:
417 *
418 * - Initialize Block (starting at a word boundary)
419 * - Receive and Transmit Descriptor Rings (quadword boundary)
420 * - Data Buffers (arbitrary boundary)
421 *
422 * This is because LANCE has on SK_G16 only access to the dual ported
423 * RAM and nowhere else.
424 */
425
426struct SK_ram
427{
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];
433};
434
435/*
436 * Structure where all necessary information is for ring buffer
437 * management and statistics.
438 */
439
440struct priv
441{
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 */
451};
452
453/* global variable declaration */
454
455/* IRQ map used to reserve a IRQ (see SK_open()) */
456
457/* static variables */
458
459static SK_RAM *board; /* pointer to our memory mapped board components */
460static DEFINE_SPINLOCK(SK_lock);
461
462/* Macros */
463
464
465/* Function Prototypes */
466
467/*
468 * Device Driver functions
469 * -----------------------
470 * See for short explanation of each function its definitions header.
471 */
472
473static int SK_probe(struct net_device *dev, short ioaddr);
474
475static void SK_timeout(struct net_device *dev);
476static int SK_open(struct net_device *dev);
477static int SK_send_packet(struct sk_buff *skb, struct net_device *dev);
478static irqreturn_t SK_interrupt(int irq, void *dev_id, struct pt_regs * regs);
479static void SK_rxintr(struct net_device *dev);
480static void SK_txintr(struct net_device *dev);
481static int SK_close(struct net_device *dev);
482
483static struct net_device_stats *SK_get_stats(struct net_device *dev);
484
485unsigned int SK_rom_addr(void);
486
487static void set_multicast_list(struct net_device *dev);
488
489/*
490 * LANCE Functions
491 * ---------------
492 */
493
494static int SK_lance_init(struct net_device *dev, unsigned short mode);
495void SK_reset_board(void);
496void SK_set_RAP(int reg_number);
497int SK_read_reg(int reg_number);
498int SK_rread_reg(void);
499void SK_write_reg(int reg_number, int value);
500
501/*
502 * Debugging functions
503 * -------------------
504 */
505
506void SK_print_pos(struct net_device *dev, char *text);
507void SK_print_dev(struct net_device *dev, char *text);
508void SK_print_ram(struct net_device *dev);
509
510
511/*-
512 * Function : SK_init
513 * Author : Patrick J.D. Weichmann
514 * Date Created : 94/05/26
515 *
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.
519 *
520 * Parameters : I : struct net_device *dev - structure preconfigured
521 * from Space.c
522 * Return Value : 0 = Driver Found and initialized
523 * Errors : ENODEV - no device found
524 * ENXIO - not probed
525 * Globals : None
526 * Update History :
527 * YY/MM/DD uid Description
528-*/
529
530static int io; /* 0 == probe */
531
532/*
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.
536 */
537
538struct net_device * __init SK_init(int unit)
539{
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));
543 int err = -ENODEV;
544
545 if (!dev)
546 return ERR_PTR(-ENOMEM);
547
548 if (unit >= 0) {
549 sprintf(dev->name, "eth%d", unit);
550 netdev_boot_setup_check(dev);
551 io = dev->base_addr;
552 }
553
554 if (version_printed++ == 0)
555 PRINTK(("%s: %s", SK_NAME, rcsid));
556
557 if (io > 0xff) { /* Check a single specified address */
558 err = -EBUSY;
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);
562 if (!err)
563 goto got_it;
564 release_region(io, ETHERCARD_TOTAL_SIZE);
565 }
566 } else if (io > 0) { /* Don't probe at all */
567 err = -ENXIO;
568 } else {
569 /* Autoprobe base_addr */
570 for (port = &ports[0]; *port; port++) {
571 io = *port;
572
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 */
576
577 /* Check if at ioaddr is a SK_G16 */
578 if (SK_probe(dev, io) == 0)
579 goto got_it;
580
581 release_region(io, ETHERCARD_TOTAL_SIZE);
582 }
583 }
584err_out:
585 free_netdev(dev);
586 return ERR_PTR(err);
587
588got_it:
589 err = register_netdev(dev);
590 if (err) {
591 release_region(dev->base_addr, ETHERCARD_TOTAL_SIZE);
592 goto err_out;
593 }
594 return dev;
595
596} /* End of SK_init */
597
598
599MODULE_AUTHOR("Patrick J.D. Weichmann");
600MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
601MODULE_LICENSE("GPL");
602MODULE_PARM(io, "i");
603MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
604
605
606#ifdef MODULE
607
608static struct net_device *SK_dev;
609
610static int __init SK_init_module (void)
611{
612 SK_dev = SK_init(-1);
613 return IS_ERR(SK_dev) ? PTR_ERR(SK_dev) : 0;
614}
615
616static void __exit SK_cleanup_module (void)
617{
618 unregister_netdev(SK_dev);
619 release_region(SK_dev->base_addr, ETHERCARD_TOTAL_SIZE);
620 free_netdev(SK_dev);
621}
622
623module_init(SK_init_module);
624module_exit(SK_cleanup_module);
625#endif
626
627
628/*-
629 * Function : SK_probe
630 * Author : Patrick J.D. Weichmann
631 * Date Created : 94/05/26
632 *
633 * Description : This function is called by SK_init and
634 * does the main part of initialization.
635 *
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
642 * Update History :
643 * YY/MM/DD uid Description
644 * 94/06/30 pwe SK_ADDR now checked and at the correct place
645-*/
646
647int __init SK_probe(struct net_device *dev, short ioaddr)
648{
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 */
652
653 struct priv *p = netdev_priv(dev); /* SK_G16 private structure */
654
655 if (inb(SK_POS0) != SK_IDLOW || inb(SK_POS1) != SK_IDHIGH)
656 return -ENODEV;
657 dev->base_addr = ioaddr;
658
659 if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
660 {
661
662 sk_addr_flag = 1;
663
664 /*
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.
667 */
668 }
669
670 if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */
671 {
672 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
673
674 rom_addr = SK_rom_addr();
675
676 if (rom_addr == 0) /* No Boot_ROM found */
677 {
678 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
679 {
680 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
681 dev->name, SK_ADDR);
682 return -1;
683 }
684
685 rom_addr = SK_ADDR; /* assign predefined address */
686
687 PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
688
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 */
692 }
693 else if (rom_addr == SK_ADDR)
694 {
695 printk("%s: RAM + ROM are set to the same address %#08x\n"
696 " Check configuration. Now switching off Boot_ROM\n",
697 SK_NAME, rom_addr);
698
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 */
702 }
703 else
704 {
705 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
706 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
707
708 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
709 {
710 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
711 dev->name, SK_ADDR);
712 return -1;
713 }
714
715 rom_addr = SK_ADDR;
716
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 */
720 }
721 }
722 else /* Don't keep Boot_ROM */
723 {
724 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
725
726 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
727 {
728 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
729 dev->name, SK_ADDR);
730 return -1;
731 }
732
733 rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */
734
735 /* IF we find a Boot_ROM disable it */
736
737 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
738
739 /* We found a Boot_ROM and it's gone. Set RAM address on
740 * Boot_ROM address.
741 */
742
743 if (rom_addr)
744 {
745 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
746 "that address\n", SK_NAME, rom_addr);
747
748 outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */
749 }
750 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
751 {
752 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
753 {
754 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
755 dev->name, SK_ADDR);
756 return -1;
757 }
758
759 rom_addr = SK_ADDR;
760
761 outb(POS_ADDR, SK_POS3); /* Set RAM address */
762 }
763 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
764 }
765
766#ifdef SK_DEBUG
767 SK_print_pos(dev, "POS registers after ROM, RAM config");
768#endif
769
770 board = (SK_RAM *) isa_bus_to_virt(rom_addr);
771
772 /* Read in station address */
773 for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
774 {
775 dev->dev_addr[i] = readb(board->rom+j);
776 }
777
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) )
782 {
783 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
784 SK_NAME));
785 return -ENODEV; /* NO SK_G16 found */
786 }
787
788 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
789 dev->name,
790 "Schneider & Koch Netcard",
791 (unsigned int) dev->base_addr,
792 dev->dev_addr[0],
793 dev->dev_addr[1],
794 dev->dev_addr[2],
795 dev->dev_addr[3],
796 dev->dev_addr[4],
797 dev->dev_addr[5]);
798
799 memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
800
801 /* Assign our Device Driver functions */
802
803 dev->open = SK_open;
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;
810
811
812 dev->flags &= ~IFF_MULTICAST;
813
814 /* Initialize private structure */
815
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 */
819
820 /* Initialize buffer pointers */
821
822 for (i = 0; i < TMDNUM; i++)
823 {
824 p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
825 }
826
827 for (i = 0; i < RMDNUM; i++)
828 {
829 p->rmdbufs[i] = &(p->ram)->rmdbuf[i];
830 }
831
832#ifdef SK_DEBUG
833 SK_print_pos(dev, "End of SK_probe");
834 SK_print_ram(dev);
835#endif
836 return 0; /* Initialization done */
837} /* End of SK_probe() */
838
839
840/*-
841 * Function : SK_open
842 * Author : Patrick J.D. Weichmann
843 * Date Created : 94/05/26
844 *
845 * Description : This function is called sometimes after booting
846 * when ifconfig program is run.
847 *
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.
853 *
854 * (Called by dev_open() /net/inet/dev.c)
855 *
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
860 * Update History :
861 * YY/MM/DD uid Description
862-*/
863
864static int SK_open(struct net_device *dev)
865{
866 int i = 0;
867 int irqval = 0;
868 int ioaddr = dev->base_addr;
869
870 int irqtab[] = SK_IRQS;
871
872 struct priv *p = netdev_priv(dev);
873
874 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
875 SK_NAME, SK_read_reg(CSR0)));
876
877 if (dev->irq == 0) /* Autoirq */
878 {
879 i = 0;
880
881 /*
882 * Check if one IRQ out of SK_IRQS is free and install
883 * interrupt handler.
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
888 */
889
890 do
891 {
892 irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
893 i++;
894 } while (irqval && irqtab[i]);
895
896 if (irqval) /* We tried every possible IRQ but no success */
897 {
898 printk("%s: unable to get an IRQ\n", dev->name);
899 return -EAGAIN;
900 }
901
902 dev->irq = irqtab[--i];
903
904 outb(i<<2, SK_POS4); /* Set Card on probed IRQ */
905
906 }
907 else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
908 {
909 if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
910 {
911 printk("%s: unable to get IRQ 9\n", dev->name);
912 return -EAGAIN;
913 }
914 dev->irq = 9;
915
916 /*
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
920 */
921 outb(0x08, SK_POS4); /* set card to IRQ2 */
922
923 }
924 else /* Check IRQ as defined in Space.c */
925 {
926 int i = 0;
927
928 /* check if IRQ free and valid. Then install Interrupt handler */
929
930 if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
931 {
932 printk("%s: unable to get selected IRQ\n", dev->name);
933 return -EAGAIN;
934 }
935
936 switch(dev->irq)
937 {
938 case 3: i = 0;
939 break;
940 case 5: i = 1;
941 break;
942 case 2: i = 2;
943 break;
944 case 11:i = 3;
945 break;
946 default:
947 printk("%s: Preselected IRQ %d is invalid for %s boards",
948 dev->name,
949 dev->irq,
950 SK_NAME);
951 return -EAGAIN;
952 }
953
954 outb(i<<2, SK_POS4); /* Set IRQ on card */
955 }
956
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);
960
961 if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */
962 {
963 netif_start_queue(dev);
964
965#ifdef SK_DEBUG
966
967 /*
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
971 */
972
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");
988
989#endif /* SK_DEBUG */
990
991 return 0; /* SK_open() is successful */
992 }
993 else /* LANCE init failed */
994 {
995
996 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
997 SK_NAME, SK_read_reg(CSR0)));
998
999 return -EAGAIN;
1000 }
1001
1002} /* End of SK_open() */
1003
1004
1005/*-
1006 * Function : SK_lance_init
1007 * Author : Patrick J.D. Weichmann
1008 * Date Created : 94/05/26
1009 *
1010 * Description : Reset LANCE chip, fill RMD, TMD structures with
1011 * start values and Start LANCE.
1012 *
1013 * Parameters : I : struct net_device *dev - SK_G16 device structure
1014 * I : int mode - put LANCE into "mode" see data-sheet for
1015 * more info.
1016 * Return Value : 0 - Init done
1017 * Errors : -1 - Init failed
1018 * Update History :
1019 * YY/MM/DD uid Description
1020-*/
1021
1022static int SK_lance_init(struct net_device *dev, unsigned short mode)
1023{
1024 int i;
1025 unsigned long flags;
1026 struct priv *p = netdev_priv(dev);
1027 struct tmd *tmdp;
1028 struct rmd *rmdp;
1029
1030 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1031 SK_NAME, SK_read_reg(CSR0)));
1032
1033 /* Reset LANCE */
1034 SK_reset_board();
1035
1036 /* Initialize TMD's with start values */
1037 p->tmdnum = 0; /* First descriptor for transmitting */
1038 p->tmdlast = 0; /* First descriptor for reading stats */
1039
1040 for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
1041 {
1042 tmdp = p->tmdhead + i;
1043
1044 writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
1045
1046 /* Mark TMD as start and end of packet */
1047 writeb(TX_STP | TX_ENP, &tmdp->u.s.status);
1048 }
1049
1050
1051 /* Initialize RMD's with start values */
1052
1053 p->rmdnum = 0; /* First RMD which will be used */
1054
1055 for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
1056 {
1057 rmdp = p->rmdhead + i;
1058
1059
1060 writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
1061
1062 /*
1063 * LANCE must be owner at beginning so that he can fill in
1064 * receiving packets, set status and release RMD
1065 */
1066
1067 writeb(RX_OWN, &rmdp->u.s.status);
1068
1069 writew(-PKT_BUF_SZ, &rmdp->blen); /* Buffer Size (two's complement) */
1070
1071 writeb(0, &rmdp->mlen); /* init message length */
1072
1073 }
1074
1075 /* Fill LANCE Initialize Block */
1076
1077 writew(mode, (&((p->ram)->ib.mode))); /* Set operation mode */
1078
1079 for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
1080 {
1081 writeb(dev->dev_addr[i], (&((p->ram)->ib.paddr[i])));
1082 }
1083
1084 for (i = 0; i < 8; i++) /* Set multicast, logical address */
1085 {
1086 writeb(0, (&((p->ram)->ib.laddr[i]))); /* We do not use logical addressing */
1087 }
1088
1089 /* Set ring descriptor pointers and set number of descriptors */
1090
1091 writel((int)p->rmdhead | RMDNUMMASK, (&((p->ram)->ib.rdrp)));
1092 writel((int)p->tmdhead | TMDNUMMASK, (&((p->ram)->ib.tdrp)));
1093
1094 /* Prepare LANCE Control and Status Registers */
1095
1096 spin_lock_irqsave(&SK_lock, flags);
1097
1098 SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
1099
1100 /*
1101 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1102 * PC Memory locations.
1103 *
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
1106 * 0x0000
1107 *
1108 * CSR1 contains low order bits 15:0 of initialization block address
1109 * CSR2 is built of:
1110 * 7:0 High order bits 23:16 of initialization block address
1111 * 15:8 reserved, must be 0
1112 */
1113
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 */
1117
1118
1119 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
1120 SK_NAME, SK_read_reg(CSR0)));
1121
1122 /* Initialize LANCE */
1123
1124 /*
1125 * INIT = Initialize, when set, causes the LANCE to begin the
1126 * initialization procedure and access the Init Block.
1127 */
1128
1129 SK_write_reg(CSR0, CSR0_INIT);
1130
1131 spin_unlock_irqrestore(&SK_lock, flags);
1132
1133 /* Wait until LANCE finished initialization */
1134
1135 SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
1136
1137 for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
1138 ; /* Wait until init done or go ahead if problems (i>=100) */
1139
1140 if (i >= 100) /* Something is wrong ! */
1141 {
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);
1146
1147#ifdef SK_DEBUG
1148 SK_print_pos(dev, "LANCE INIT failed");
1149 SK_print_dev(dev,"Device Structure:");
1150#endif
1151
1152 return -1; /* LANCE init failed */
1153 }
1154
1155 PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
1156
1157 /* Clear Initialize done, enable Interrupts, start LANCE */
1158
1159 SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
1160
1161 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME,
1162 SK_read_reg(CSR0)));
1163
1164 return 0; /* LANCE is up and running */
1165
1166} /* End of SK_lance_init() */
1167
1168
1169
1170/*-
1171 * Function : SK_send_packet
1172 * Author : Patrick J.D. Weichmann
1173 * Date Created : 94/05/27
1174 *
1175 * Description : Writes an socket buffer into a transmit descriptor
1176 * and starts transmission.
1177 *
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
1183 * Globals : None
1184 * Side Effects : None
1185 * Update History :
1186 * YY/MM/DD uid Description
1187-*/
1188
1189static void SK_timeout(struct net_device *dev)
1190{
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 */
1195}
1196
1197static int SK_send_packet(struct sk_buff *skb, struct net_device *dev)
1198{
1199 struct priv *p = netdev_priv(dev);
1200 struct tmd *tmdp;
1201 static char pad[64];
1202
1203 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1204 SK_NAME, SK_read_reg(CSR0)));
1205
1206
1207 /*
1208 * Block a timer-based transmit from overlapping.
1209 * This means check if we are already in.
1210 */
1211
1212 netif_stop_queue (dev);
1213
1214 {
1215
1216 /* Evaluate Packet length */
1217 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1218
1219 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1220
1221 /* Fill in Transmit Message Descriptor */
1222
1223 /* Copy data into dual ported ram */
1224
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);
1228
1229 writew(-len, &tmdp->blen); /* set length to transmit */
1230
1231 /*
1232 * Packet start and end is always set because we use the maximum
1233 * packet length as buffer length.
1234 * Relinquish ownership to LANCE
1235 */
1236
1237 writeb(TX_OWN | TX_STP | TX_ENP, &tmdp->u.s.status);
1238
1239 /* Start Demand Transmission */
1240 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1241
1242 dev->trans_start = jiffies; /* Mark start of transmission */
1243
1244 /* Set pointer to next transmit buffer */
1245 p->tmdnum++;
1246 p->tmdnum &= TMDNUM-1;
1247
1248 /* Do we own the next transmit buffer ? */
1249 if (! (readb(&((p->tmdhead + p->tmdnum)->u.s.status)) & TX_OWN) )
1250 {
1251 /*
1252 * We own next buffer and are ready to transmit, so
1253 * clear busy flag
1254 */
1255 netif_start_queue(dev);
1256 }
1257
1258 p->stats.tx_bytes += skb->len;
1259
1260 }
1261
1262 dev_kfree_skb(skb);
1263 return 0;
1264} /* End of SK_send_packet */
1265
1266
1267/*-
1268 * Function : SK_interrupt
1269 * Author : Patrick J.D. Weichmann
1270 * Date Created : 94/05/27
1271 *
1272 * Description : SK_G16 interrupt handler which checks for LANCE
1273 * Errors, handles transmit and receive interrupts
1274 *
1275 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1276 * Return Value : None
1277 * Errors : None
1278 * Globals : None
1279 * Side Effects : None
1280 * Update History :
1281 * YY/MM/DD uid Description
1282-*/
1283
1284static irqreturn_t SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1285{
1286 int csr0;
1287 struct net_device *dev = dev_id;
1288 struct priv *p = netdev_priv(dev);
1289
1290
1291 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1292 SK_NAME, SK_read_reg(CSR0)));
1293
1294 if (dev == NULL)
1295 {
1296 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1297 }
1298
1299 spin_lock (&SK_lock);
1300
1301 csr0 = SK_read_reg(CSR0); /* store register for checking */
1302
1303 /*
1304 * Acknowledge all of the current interrupt sources, disable
1305 * Interrupts (INEA = 0)
1306 */
1307
1308 SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
1309
1310 if (csr0 & CSR0_ERR) /* LANCE Error */
1311 {
1312 printk("%s: error: %04x\n", dev->name, csr0);
1313
1314 if (csr0 & CSR0_MISS) /* No place to store packet ? */
1315 {
1316 p->stats.rx_dropped++;
1317 }
1318 }
1319
1320 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */
1321 {
1322 SK_rxintr(dev);
1323 }
1324
1325 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */
1326 {
1327 SK_txintr(dev);
1328 }
1329
1330 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1331
1332 spin_unlock (&SK_lock);
1333 return IRQ_HANDLED;
1334} /* End of SK_interrupt() */
1335
1336
1337/*-
1338 * Function : SK_txintr
1339 * Author : Patrick J.D. Weichmann
1340 * Date Created : 94/05/27
1341 *
1342 * Description : After sending a packet we check status, update
1343 * statistics and relinquish ownership of transmit
1344 * descriptor ring.
1345 *
1346 * Parameters : I : struct net_device *dev - SK_G16 device structure
1347 * Return Value : None
1348 * Errors : None
1349 * Globals : None
1350 * Update History :
1351 * YY/MM/DD uid Description
1352-*/
1353
1354static void SK_txintr(struct net_device *dev)
1355{
1356 int tmdstat;
1357 struct tmd *tmdp;
1358 struct priv *p = netdev_priv(dev);
1359
1360
1361 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1362 SK_NAME, SK_read_reg(CSR0)));
1363
1364 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */
1365
1366 /* Set next buffer */
1367 p->tmdlast++;
1368 p->tmdlast &= TMDNUM-1;
1369
1370 tmdstat = readb(&tmdp->u.s.status);
1371
1372 /*
1373 * We check status of transmitted packet.
1374 * see LANCE data-sheet for error explanation
1375 */
1376 if (tmdstat & TX_ERR) /* Error occurred */
1377 {
1378 int stat2 = readw(&tmdp->status2);
1379
1380 printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
1381
1382 if (stat2 & TX_TDR) /* TDR problems? */
1383 {
1384 printk("%s: tdr-problems \n", dev->name);
1385 }
1386
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 ? */
1394 {
1395 p->stats.tx_fifo_errors++;
1396
1397 /*
1398 * If UFLO error occurs it will turn transmitter of.
1399 * So we must reinit LANCE
1400 */
1401
1402 SK_lance_init(dev, MODE_NORMAL);
1403 }
1404
1405 p->stats.tx_errors++;
1406
1407 writew(0, &tmdp->status2); /* Clear error flags */
1408 }
1409 else if (tmdstat & TX_MORE) /* Collisions occurred ? */
1410 {
1411 /*
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.
1416 *
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
1420 * please report it.
1421 */
1422
1423 p->stats.collisions++;
1424 }
1425 else /* Packet sent without any problems */
1426 {
1427 p->stats.tx_packets++;
1428 }
1429
1430 /*
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
1434 *
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)
1438 *
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
1445 */
1446
1447 netif_wake_queue(dev);
1448
1449} /* End of SK_txintr() */
1450
1451
1452/*-
1453 * Function : SK_rxintr
1454 * Author : Patrick J.D. Weichmann
1455 * Date Created : 94/05/27
1456 *
1457 * Description : Buffer sent, check for errors, relinquish ownership
1458 * of the receive message descriptor.
1459 *
1460 * Parameters : I : SK_G16 device structure
1461 * Return Value : None
1462 * Globals : None
1463 * Update History :
1464 * YY/MM/DD uid Description
1465-*/
1466
1467static void SK_rxintr(struct net_device *dev)
1468{
1469
1470 struct rmd *rmdp;
1471 int rmdstat;
1472 struct priv *p = netdev_priv(dev);
1473
1474 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1475 SK_NAME, SK_read_reg(CSR0)));
1476
1477 rmdp = p->rmdhead + p->rmdnum;
1478
1479 /* As long as we own the next entry, check status and send
1480 * it up to higher layer
1481 */
1482
1483 while (!( (rmdstat = readb(&rmdp->u.s.status)) & RX_OWN))
1484 {
1485 /*
1486 * Start and end of packet must be set, because we use
1487 * the ethernet maximum packet length (1518) as buffer size.
1488 *
1489 * Because our buffers are at maximum OFLO and BUFF errors are
1490 * not to be concerned (see Data sheet)
1491 */
1492
1493 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
1494 {
1495 /* Start of a frame > 1518 Bytes ? */
1496
1497 if (rmdstat & RX_STP)
1498 {
1499 p->stats.rx_errors++; /* bad packet received */
1500 p->stats.rx_length_errors++; /* packet too long */
1501
1502 printk("%s: packet too long\n", dev->name);
1503 }
1504
1505 /*
1506 * All other packets will be ignored until a new frame with
1507 * start (RX_STP) set follows.
1508 *
1509 * What we do is just give descriptor free for new incoming
1510 * packets.
1511 */
1512
1513 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1514
1515 }
1516 else if (rmdstat & RX_ERR) /* Receive Error ? */
1517 {
1518 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1519
1520 p->stats.rx_errors++;
1521
1522 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1523 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++;
1524
1525 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1526
1527 }
1528 else /* We have a packet which can be queued for the upper layers */
1529 {
1530
1531 int len = readw(&rmdp->mlen) & 0x0fff; /* extract message length from receive buffer */
1532 struct sk_buff *skb;
1533
1534 skb = dev_alloc_skb(len+2); /* allocate socket buffer */
1535
1536 if (skb == NULL) /* Could not get mem ? */
1537 {
1538
1539 /*
1540 * Couldn't allocate sk_buffer so we give descriptor back
1541 * to Lance, update statistics and go ahead.
1542 */
1543
1544 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1545 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1546 dev->name);
1547 p->stats.rx_dropped++;
1548
1549 break; /* Jump out */
1550 }
1551
1552 /* Prepare sk_buff to queue for upper layers */
1553
1554 skb->dev = dev;
1555 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */
1556
1557 /*
1558 * Copy data out of our receive descriptor into sk_buff.
1559 *
1560 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1561 * ignore status fields)
1562 */
1563
1564 memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
1565
1566
1567 /*
1568 * Notify the upper protocol layers that there is another packet
1569 * to handle
1570 *
1571 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1572 */
1573
1574 skb->protocol=eth_type_trans(skb,dev);
1575 netif_rx(skb); /* queue packet and mark it for processing */
1576
1577 /*
1578 * Packet is queued and marked for processing so we
1579 * free our descriptor and update statistics
1580 */
1581
1582 writeb(RX_OWN, &rmdp->u.s.status);
1583 dev->last_rx = jiffies;
1584 p->stats.rx_packets++;
1585 p->stats.rx_bytes += len;
1586
1587
1588 p->rmdnum++;
1589 p->rmdnum %= RMDNUM;
1590
1591 rmdp = p->rmdhead + p->rmdnum;
1592 }
1593 }
1594} /* End of SK_rxintr() */
1595
1596
1597/*-
1598 * Function : SK_close
1599 * Author : Patrick J.D. Weichmann
1600 * Date Created : 94/05/26
1601 *
1602 * Description : close gets called from dev_close() and should
1603 * deinstall the card (free_irq, mem etc).
1604 *
1605 * Parameters : I : struct net_device *dev - our device structure
1606 * Return Value : 0 - closed device driver
1607 * Errors : None
1608 * Globals : None
1609 * Update History :
1610 * YY/MM/DD uid Description
1611-*/
1612
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.
1615 */
1616
1617static int SK_close(struct net_device *dev)
1618{
1619
1620 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1621 SK_NAME, SK_read_reg(CSR0)));
1622
1623 netif_stop_queue(dev); /* Transmitter busy */
1624
1625 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,
1626 (int) SK_read_reg(CSR0));
1627
1628 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1629
1630 free_irq(dev->irq, dev); /* Free IRQ */
1631
1632 return 0; /* always succeed */
1633
1634} /* End of SK_close() */
1635
1636
1637/*-
1638 * Function : SK_get_stats
1639 * Author : Patrick J.D. Weichmann
1640 * Date Created : 94/05/26
1641 *
1642 * Description : Return current status structure to upper layers.
1643 * It is called by sprintf_stats (dev.c).
1644 *
1645 * Parameters : I : struct net_device *dev - our device structure
1646 * Return Value : struct net_device_stats * - our current statistics
1647 * Errors : None
1648 * Side Effects : None
1649 * Update History :
1650 * YY/MM/DD uid Description
1651-*/
1652
1653static struct net_device_stats *SK_get_stats(struct net_device *dev)
1654{
1655
1656 struct priv *p = netdev_priv(dev);
1657
1658 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1659 SK_NAME, SK_read_reg(CSR0)));
1660
1661 return &p->stats; /* Return Device status */
1662
1663} /* End of SK_get_stats() */
1664
1665
1666/*-
1667 * Function : set_multicast_list
1668 * Author : Patrick J.D. Weichmann
1669 * Date Created : 94/05/26
1670 *
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
1674 * Promiscuous mode.
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.
1680 *
1681 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1682 * Return Value : None
1683 * Errors : None
1684 * Globals : None
1685 * Update History :
1686 * YY/MM/DD uid Description
1687 * 95/10/18 ACox New multicast calling scheme
1688-*/
1689
1690
1691/* Set or clear the multicast filter for SK_G16.
1692 */
1693
1694static void set_multicast_list(struct net_device *dev)
1695{
1696
1697 if (dev->flags&IFF_PROMISC)
1698 {
1699 /* Reinitialize LANCE with MODE_PROM set */
1700 SK_lance_init(dev, MODE_PROM);
1701 }
1702 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
1703 {
1704 /* Reinitialize LANCE without MODE_PROM */
1705 SK_lance_init(dev, MODE_NORMAL);
1706 }
1707 else
1708 {
1709 /* Multicast with logical address filter on */
1710 /* Reinitialize LANCE without MODE_PROM */
1711 SK_lance_init(dev, MODE_NORMAL);
1712
1713 /* Not implemented yet. */
1714 }
1715} /* End of set_multicast_list() */
1716
1717
1718
1719/*-
1720 * Function : SK_rom_addr
1721 * Author : Patrick J.D. Weichmann
1722 * Date Created : 94/06/01
1723 *
1724 * Description : Try to find a Boot_ROM at all possible locations
1725 *
1726 * Parameters : None
1727 * Return Value : Address where Boot_ROM is
1728 * Errors : 0 - Did not find Boot_ROM
1729 * Globals : None
1730 * Update History :
1731 * YY/MM/DD uid Description
1732-*/
1733
1734unsigned int __init SK_rom_addr(void)
1735{
1736 int i,j;
1737 int rom_found = 0;
1738 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1739 unsigned char rom_id[] = SK_BOOT_ROM_ID;
1740 unsigned char test_byte;
1741
1742 /* Autodetect Boot_ROM */
1743 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1744
1745 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1746 {
1747
1748 PRINTK(("## Trying ROM location %#08x", rom_location[i]));
1749
1750 rom_found = 1;
1751 for (j = 0; j < 6; j++)
1752 {
1753 test_byte = readb(rom_location[i]+j);
1754 PRINTK((" %02x ", *test_byte));
1755
1756 if(test_byte != rom_id[j])
1757 {
1758 rom_found = 0;
1759 }
1760 }
1761 PRINTK(("\n"));
1762 }
1763
1764 if (rom_found == 1)
1765 {
1766 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1767 SK_NAME, rom_location[(i-1)]));
1768
1769 return (rom_location[--i]);
1770 }
1771 else
1772 {
1773 PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1774 return 0;
1775 }
1776} /* End of SK_rom_addr() */
1777
1778
1779
1780/* LANCE access functions
1781 *
1782 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1783 */
1784
1785
1786/*-
1787 * Function : SK_reset_board
1788 *
1789 * Author : Patrick J.D. Weichmann
1790 *
1791 * Date Created : 94/05/25
1792 *
1793 * Description : This function resets SK_G16 and all components, but
1794 * POS registers are not changed
1795 *
1796 * Parameters : None
1797 * Return Value : None
1798 * Errors : None
1799 * Globals : SK_RAM *board - SK_RAM structure pointer
1800 *
1801 * Update History :
1802 * YY/MM/DD uid Description
1803-*/
1804
1805void SK_reset_board(void)
1806{
1807 writeb(0x00, SK_PORT); /* Reset active */
1808 mdelay(5); /* Delay min 5ms */
1809 writeb(SK_RESET, SK_PORT); /* Set back to normal operation */
1810
1811} /* End of SK_reset_board() */
1812
1813
1814/*-
1815 * Function : SK_set_RAP
1816 * Author : Patrick J.D. Weichmann
1817 * Date Created : 94/05/25
1818 *
1819 * Description : Set LANCE Register Address Port to register
1820 * for later data transfer.
1821 *
1822 * Parameters : I : reg_number - which CSR to read/write from/to
1823 * Return Value : None
1824 * Errors : None
1825 * Globals : SK_RAM *board - SK_RAM structure pointer
1826 * Update History :
1827 * YY/MM/DD uid Description
1828-*/
1829
1830void SK_set_RAP(int reg_number)
1831{
1832 writew(reg_number, SK_IOREG);
1833 writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
1834 writeb(SK_DOIO, SK_IOCOM);
1835
1836 while (readb(SK_PORT) & SK_IORUN)
1837 barrier();
1838} /* End of SK_set_RAP() */
1839
1840
1841/*-
1842 * Function : SK_read_reg
1843 * Author : Patrick J.D. Weichmann
1844 * Date Created : 94/05/25
1845 *
1846 * Description : Set RAP and read data from a LANCE CSR register
1847 *
1848 * Parameters : I : reg_number - which CSR to read from
1849 * Return Value : Register contents
1850 * Errors : None
1851 * Globals : SK_RAM *board - SK_RAM structure pointer
1852 * Update History :
1853 * YY/MM/DD uid Description
1854-*/
1855
1856int SK_read_reg(int reg_number)
1857{
1858 SK_set_RAP(reg_number);
1859
1860 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1861 writeb(SK_DOIO, SK_IOCOM);
1862
1863 while (readb(SK_PORT) & SK_IORUN)
1864 barrier();
1865 return (readw(SK_IOREG));
1866
1867} /* End of SK_read_reg() */
1868
1869
1870/*-
1871 * Function : SK_rread_reg
1872 * Author : Patrick J.D. Weichmann
1873 * Date Created : 94/05/28
1874 *
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.
1879 *
1880 * Return Value : Register contents
1881 * Errors : None
1882 * Globals : SK_RAM *board - SK_RAM structure pointer
1883 * Update History :
1884 * YY/MM/DD uid Description
1885-*/
1886
1887int SK_rread_reg(void)
1888{
1889 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1890
1891 writeb(SK_DOIO, SK_IOCOM);
1892
1893 while (readb(SK_PORT) & SK_IORUN)
1894 barrier();
1895 return (readw(SK_IOREG));
1896
1897} /* End of SK_rread_reg() */
1898
1899
1900/*-
1901 * Function : SK_write_reg
1902 * Author : Patrick J.D. Weichmann
1903 * Date Created : 94/05/25
1904 *
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.
1909 *
1910 * Parameters : I : reg_number - which CSR to write to
1911 * I : value - what value to fill into register
1912 * Return Value : None
1913 * Errors : None
1914 * Globals : SK_RAM *board - SK_RAM structure pointer
1915 * Update History :
1916 * YY/MM/DD uid Description
1917-*/
1918
1919void SK_write_reg(int reg_number, int value)
1920{
1921 SK_set_RAP(reg_number);
1922
1923 writew(value, SK_IOREG);
1924 writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
1925 writeb(SK_DOIO, SK_IOCOM);
1926
1927 while (readb(SK_PORT) & SK_IORUN)
1928 barrier();
1929} /* End of SK_write_reg */
1930
1931
1932
1933/*
1934 * Debugging functions
1935 * -------------------
1936 */
1937
1938/*-
1939 * Function : SK_print_pos
1940 * Author : Patrick J.D. Weichmann
1941 * Date Created : 94/05/25
1942 *
1943 * Description : This function prints out the 4 POS (Programmable
1944 * Option Select) Registers. Used mainly to debug operation.
1945 *
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
1949 * Errors : None
1950 * Update History :
1951 * YY/MM/DD uid Description
1952-*/
1953
1954void SK_print_pos(struct net_device *dev, char *text)
1955{
1956 int ioaddr = dev->base_addr;
1957
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);
1963
1964
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);
1968
1969} /* End of SK_print_pos() */
1970
1971
1972
1973/*-
1974 * Function : SK_print_dev
1975 * Author : Patrick J.D. Weichmann
1976 * Date Created : 94/05/25
1977 *
1978 * Description : This function simply prints out the important fields
1979 * of the device structure.
1980 *
1981 * Parameters : I : struct net_device *dev - SK_G16 device structure
1982 * I : char *text - Title for printing
1983 * Return Value : None
1984 * Errors : None
1985 * Update History :
1986 * YY/MM/DD uid Description
1987-*/
1988
1989void SK_print_dev(struct net_device *dev, char *text)
1990{
1991 if (dev == NULL)
1992 {
1993 printk("## %s: Device Structure. %s\n", SK_NAME, text);
1994 printk("## DEVICE == NULL\n");
1995 }
1996 else
1997 {
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);
2001
2002 printk("## next device: %#08x init function: %#08x\n",
2003 (int) dev->next, (int) dev->init);
2004 }
2005
2006} /* End of SK_print_dev() */
2007
2008
2009
2010/*-
2011 * Function : SK_print_ram
2012 * Author : Patrick J.D. Weichmann
2013 * Date Created : 94/06/02
2014 *
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.
2020 *
2021 * Parameters : I : struct net_device *dev - SK_G16 device structure
2022 * Return Value : None
2023 * Errors : None
2024 * Globals : None
2025 * Update History :
2026 * YY/MM/DD uid Description
2027-*/
2028
2029void __init SK_print_ram(struct net_device *dev)
2030{
2031
2032 int i;
2033 struct priv *p = netdev_priv(dev);
2034
2035 printk("## %s: RAM Details.\n"
2036 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2037 SK_NAME,
2038 (unsigned int) p->ram,
2039 (unsigned int) p->tmdhead,
2040 (unsigned int) p->rmdhead,
2041 (unsigned int) &(p->ram)->ib);
2042
2043 printk("## ");
2044
2045 for(i = 0; i < TMDNUM; i++)
2046 {
2047 if (!(i % 3)) /* Every third line do a newline */
2048 {
2049 printk("\n## ");
2050 }
2051 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2052 }
2053 printk("## ");
2054
2055 for(i = 0; i < RMDNUM; i++)
2056 {
2057 if (!(i % 3)) /* Every third line do a newline */
2058 {
2059 printk("\n## ");
2060 }
2061 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2062 }
2063 printk("\n");
2064
2065} /* End of SK_print_ram() */
2066