File: /usr/src/linux/drivers/net/sk_g16.c
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
26 static 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/sched.h>
64 #include <linux/ptrace.h>
65 #include <linux/fcntl.h>
66 #include <linux/ioport.h>
67 #include <linux/interrupt.h>
68 #include <linux/slab.h>
69 #include <linux/string.h>
70 #include <linux/delay.h>
71 #include <asm/system.h>
72 #include <asm/io.h>
73 #include <asm/bitops.h>
74 #include <linux/errno.h>
75 #include <linux/init.h>
76 #include <linux/spinlock.h>
77
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/skbuff.h>
81
82 #include "sk_g16.h"
83
84 /*
85 * Schneider & Koch Card Definitions
86 * =================================
87 */
88
89 #define SK_NAME "SK_G16"
90
91 /*
92 * SK_G16 Configuration
93 * --------------------
94 */
95
96 /*
97 * Abbreviations
98 * -------------
99 *
100 * RAM - used for the 16KB shared memory
101 * Boot_ROM, ROM - are used for referencing the BootEPROM
102 *
103 * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
104 * the behaviour of the driver and the SK_G16.
105 *
106 * ! See sk_g16.install on how to install and configure the driver !
107 *
108 * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
109 *
110 * SK_ADDR defines the address where the RAM will be mapped into the real
111 * host memory.
112 * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
113 */
114
115 #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
116
117 #define SK_ADDR 0xcc000
118
119 /*
120 * In POS3 are bits A14-A19 of the address bus. These bits can be set
121 * to choose the RAM address. That's why we only can choose the RAM address
122 * in 16KB steps.
123 */
124
125 #define POS_ADDR (rom_addr>>14) /* Do not change this line */
126
127 /*
128 * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
129 * ----------------------------------------------
130 */
131
132 /*
133 * As nearly every card has also SK_G16 a specified I/O Port region and
134 * only a few possible IRQ's.
135 * In the Installation Guide from Schneider & Koch is listed a possible
136 * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
137 * controllers. So we use in SK_IRQS IRQ9.
138 */
139
140 /* Don't touch any of the following #defines. */
141
142 #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
143
144 #define SK_IRQS { 3, 5, 9, 11, 0 }
145
146 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
147
148 #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
149
150 /*
151 * SK_G16 POS REGISTERS
152 * --------------------
153 */
154
155 /*
156 * SK_G16 has a Programmable Option Select (POS) Register.
157 * The POS is composed of 8 separate registers (POS0-7) which
158 * are I/O mapped on an address set by the W1 switch.
159 *
160 */
161
162 #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
163
164 #define SK_POS0 ioaddr /* Card-ID Low (R) */
165 #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
166 #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
167 #define SK_POS3 ioaddr+3 /* Base address of RAM */
168 #define SK_POS4 ioaddr+4 /* IRQ */
169
170 /* POS5 - POS7 are unused */
171
172 /*
173 * SK_G16 MAC PREFIX
174 * -----------------
175 */
176
177 /*
178 * Scheider & Koch manufacturer code (00:00:a5).
179 * This must be checked, that we are sure it is a SK card.
180 */
181
182 #define SK_MAC0 0x00
183 #define SK_MAC1 0x00
184 #define SK_MAC2 0x5a
185
186 /*
187 * SK_G16 ID
188 * ---------
189 */
190
191 /*
192 * If POS0,POS1 contain the following ID, then we know
193 * at which I/O Port Address we are.
194 */
195
196 #define SK_IDLOW 0xfd
197 #define SK_IDHIGH 0x6a
198
199
200 /*
201 * LANCE POS Bit definitions
202 * -------------------------
203 */
204
205 #define SK_ROM_RAM_ON (POS2_CARD)
206 #define SK_ROM_RAM_OFF (POS2_EPROM)
207 #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
208 #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
209 #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
210 #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
211
212 #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
213 #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
214
215 /*
216 * SK_G16 Memory mapped Registers
217 * ------------------------------
218 *
219 */
220
221 #define SK_IOREG (&board->ioreg) /* LANCE data registers. */
222 #define SK_PORT (&board->port) /* Control, Status register */
223 #define SK_IOCOM (&board->iocom) /* I/O Command */
224
225 /*
226 * SK_G16 Status/Control Register bits
227 * -----------------------------------
228 *
229 * (C) Controlreg (S) Statusreg
230 */
231
232 /*
233 * Register transfer: 0 = no transfer
234 * 1 = transferring data between LANCE and I/O reg
235 */
236 #define SK_IORUN 0x20
237
238 /*
239 * LANCE interrupt: 0 = LANCE interrupt occurred
240 * 1 = no LANCE interrupt occurred
241 */
242 #define SK_IRQ 0x10
243
244 #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
245 #define SK_RW 0x02 /* 0 = write to 1 = read from */
246 #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
247
248
249 #define SK_RREG SK_RW /* Transferdirection to read from lance */
250 #define SK_WREG 0 /* Transferdirection to write to lance */
251 #define SK_RAP SK_ADR /* Destination Register RAP */
252 #define SK_RDATA 0 /* Destination Register REG DataPort */
253
254 /*
255 * SK_G16 I/O Command
256 * ------------------
257 */
258
259 /*
260 * Any bitcombination sets the internal I/O bit (transfer will start)
261 * when written to I/O Command
262 */
263
264 #define SK_DOIO 0x80 /* Do Transfer */
265
266 /*
267 * LANCE RAP (Register Address Port).
268 * ---------------------------------
269 */
270
271 /*
272 * The LANCE internal registers are selected through the RAP.
273 * The Registers are:
274 *
275 * CSR0 - Status and Control flags
276 * CSR1 - Low order bits of initialize block (bits 15:00)
277 * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
278 * CSR3 - Allows redefinition of the Bus Master Interface.
279 * This register must be set to 0x0002, which means BSWAP = 0,
280 * ACON = 1, BCON = 0;
281 *
282 */
283
284 #define CSR0 0x00
285 #define CSR1 0x01
286 #define CSR2 0x02
287 #define CSR3 0x03
288
289 /*
290 * General Definitions
291 * ===================
292 */
293
294 /*
295 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
296 * We have 16KB RAM which can be accessed by the LANCE. In the
297 * memory are not only the buffers but also the ring descriptors and
298 * the initialize block.
299 * Don't change anything unless you really know what you do.
300 */
301
302 #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
303 #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */
304
305 /* Descriptor ring sizes */
306
307 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
308 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
309
310 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
311
312 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
313 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
314
315 /*
316 * Data Buffer size is set to maximum packet length.
317 */
318
319 #define PKT_BUF_SZ 1518
320
321 /*
322 * The number of low I/O ports used by the ethercard.
323 */
324
325 #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
326
327 /*
328 * SK_DEBUG
329 *
330 * Here you can choose what level of debugging wanted.
331 *
332 * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
333 * necessary messages will be printed.
334 *
335 * If SK_DEBUG is defined, there will be many debugging prints
336 * which can help to find some mistakes in configuration or even
337 * in the driver code.
338 *
339 * If SK_DEBUG2 is defined, many many messages will be printed
340 * which normally you don't need. I used this to check the interrupt
341 * routine.
342 *
343 * (If you define only SK_DEBUG2 then only the messages for
344 * checking interrupts will be printed!)
345 *
346 * Normal way of live is:
347 *
348 * For the whole thing get going let both symbolic constants
349 * undefined. If you face any problems and you know what's going
350 * on (you know something about the card and you can interpret some
351 * hex LANCE register output) then define SK_DEBUG
352 *
353 */
354
355 #undef SK_DEBUG /* debugging */
356 #undef SK_DEBUG2 /* debugging with more verbose report */
357
358 #ifdef SK_DEBUG
359 #define PRINTK(x) printk x
360 #else
361 #define PRINTK(x) /**/
362 #endif
363
364 #ifdef SK_DEBUG2
365 #define PRINTK2(x) printk x
366 #else
367 #define PRINTK2(x) /**/
368 #endif
369
370 /*
371 * SK_G16 RAM
372 *
373 * The components are memory mapped and can be set in a region from
374 * 0x00000 through 0xfc000 in 16KB steps.
375 *
376 * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
377 * Controlregister and I/O Command.
378 *
379 * dual ported RAM: This is the only memory region which the LANCE chip
380 * has access to. From the Lance it is addressed from 0x0000 to
381 * 0x3fbf. The host accesses it normally.
382 *
383 * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
384 * 8-Bit PROM, this means only the 16 even addresses are used of the
385 * 32 Byte Address region. Access to an odd address results in invalid
386 * data.
387 *
388 * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
389 * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
390 * Transfer from or to the LANCE is always in 16Bit so Low and High
391 * registers are always relevant.
392 *
393 * The Data from the Readregister is not the data in the Writeregister!!
394 *
395 * Port: Status- and Controlregister.
396 * Two different registers which share the same address, Status is
397 * read-only, Control is write-only.
398 *
399 * I/O Command:
400 * Any bitcombination written in here starts the transmission between
401 * Host and LANCE.
402 */
403
404 typedef struct
405 {
406 unsigned char ram[0x3fc0]; /* 16KB dual ported ram */
407 unsigned char rom[0x0020]; /* 32Byte PROM containing 6Byte MAC */
408 unsigned char res1[0x0010]; /* reserved */
409 unsigned volatile short ioreg;/* LANCE I/O Register */
410 unsigned volatile char port; /* Statusregister and Controlregister */
411 unsigned char iocom; /* I/O Command Register */
412 } SK_RAM;
413
414 /* struct */
415
416 /*
417 * This is the structure for the dual ported ram. We
418 * have exactly 16 320 Bytes. In here there must be:
419 *
420 * - Initialize Block (starting at a word boundary)
421 * - Receive and Transmit Descriptor Rings (quadword boundary)
422 * - Data Buffers (arbitrary boundary)
423 *
424 * This is because LANCE has on SK_G16 only access to the dual ported
425 * RAM and nowhere else.
426 */
427
428 struct SK_ram
429 {
430 struct init_block ib;
431 struct tmd tmde[TMDNUM];
432 struct rmd rmde[RMDNUM];
433 char tmdbuf[TMDNUM][PKT_BUF_SZ];
434 char rmdbuf[RMDNUM][PKT_BUF_SZ];
435 };
436
437 /*
438 * Structure where all necessary information is for ring buffer
439 * management and statistics.
440 */
441
442 struct priv
443 {
444 struct SK_ram *ram; /* dual ported ram structure */
445 struct rmd *rmdhead; /* start of receive ring descriptors */
446 struct tmd *tmdhead; /* start of transmit ring descriptors */
447 int rmdnum; /* actual used ring descriptor */
448 int tmdnum; /* actual transmit descriptor for transmitting data */
449 int tmdlast; /* last sent descriptor used for error handling, etc */
450 void *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
451 void *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
452 struct net_device_stats stats; /* Device driver statistics */
453 };
454
455 /* global variable declaration */
456
457 /* IRQ map used to reserve a IRQ (see SK_open()) */
458
459 /* static variables */
460
461 static SK_RAM *board; /* pointer to our memory mapped board components */
462 static struct net_device *SK_dev;
463 unsigned long SK_ioaddr;
464 static spinlock_t SK_lock = SPIN_LOCK_UNLOCKED;
465
466 /* Macros */
467
468
469 /* Function Prototypes */
470
471 /*
472 * Device Driver functions
473 * -----------------------
474 * See for short explanation of each function its definitions header.
475 */
476
477 int SK_init(struct net_device *dev);
478 static int SK_probe(struct net_device *dev, short ioaddr);
479
480 static void SK_timeout(struct net_device *dev);
481 static int SK_open(struct net_device *dev);
482 static int SK_send_packet(struct sk_buff *skb, struct net_device *dev);
483 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs);
484 static void SK_rxintr(struct net_device *dev);
485 static void SK_txintr(struct net_device *dev);
486 static int SK_close(struct net_device *dev);
487
488 static struct net_device_stats *SK_get_stats(struct net_device *dev);
489
490 unsigned int SK_rom_addr(void);
491
492 static void set_multicast_list(struct net_device *dev);
493
494 /*
495 * LANCE Functions
496 * ---------------
497 */
498
499 static int SK_lance_init(struct net_device *dev, unsigned short mode);
500 void SK_reset_board(void);
501 void SK_set_RAP(int reg_number);
502 int SK_read_reg(int reg_number);
503 int SK_rread_reg(void);
504 void SK_write_reg(int reg_number, int value);
505
506 /*
507 * Debugging functions
508 * -------------------
509 */
510
511 void SK_print_pos(struct net_device *dev, char *text);
512 void SK_print_dev(struct net_device *dev, char *text);
513 void SK_print_ram(struct net_device *dev);
514
515
516 /*-
517 * Function : SK_init
518 * Author : Patrick J.D. Weichmann
519 * Date Created : 94/05/26
520 *
521 * Description : Check for a SK_G16 network adaptor and initialize it.
522 * This function gets called by dev_init which initializes
523 * all Network devices.
524 *
525 * Parameters : I : struct net_device *dev - structure preconfigured
526 * from Space.c
527 * Return Value : 0 = Driver Found and initialized
528 * Errors : ENODEV - no device found
529 * ENXIO - not probed
530 * Globals : None
531 * Update History :
532 * YY/MM/DD uid Description
533 -*/
534
535 /*
536 * Check for a network adaptor of this type, and return '0' if one exists.
537 * If dev->base_addr == 0, probe all likely locations.
538 * If dev->base_addr == 1, always return failure.
539 */
540
541 int __init SK_init(struct net_device *dev)
542 {
543 int ioaddr; /* I/O port address used for POS regs */
544 int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */
545 static unsigned version_printed;
546
547 /* get preconfigured base_addr from dev which is done in Space.c */
548 int base_addr = dev->base_addr;
549
550 if (version_printed++ == 0)
551 PRINTK(("%s: %s", SK_NAME, rcsid));
552
553 if (base_addr > 0x0ff) /* Check a single specified address */
554 {
555 int rc = -ENODEV;
556
557 ioaddr = base_addr;
558
559 /* Check if on specified address is a SK_G16 */
560 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
561 return -EBUSY;
562
563 if ( (inb(SK_POS0) == SK_IDLOW) ||
564 (inb(SK_POS1) == SK_IDHIGH) )
565 {
566 rc = SK_probe(dev, ioaddr);
567 }
568
569 if (rc)
570 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
571 return rc;
572 }
573 else if (base_addr > 0) /* Don't probe at all */
574 {
575 return -ENXIO;
576 }
577
578 /* Autoprobe base_addr */
579
580 for (port = &ports[0]; *port; port++)
581 {
582 ioaddr = *port; /* we need ioaddr for accessing POS regs */
583
584 /* Check if I/O Port region is used by another board */
585
586 if (!request_region(ioaddr, ETHERCARD_TOTAL_SIZE, "sk_g16"))
587 {
588 continue; /* Try next Port address */
589 }
590
591 /* Check if at ioaddr is a SK_G16 */
592
593 if ( !(inb(SK_POS0) == SK_IDLOW) ||
594 !(inb(SK_POS1) == SK_IDHIGH) )
595 {
596 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
597 continue; /* Try next Port address */
598 }
599
600 dev->base_addr = ioaddr; /* Set I/O Port Address */
601
602 if (SK_probe(dev, ioaddr) == 0)
603 {
604 return 0; /* Card found and initialized */
605 }
606
607 release_region(ioaddr, ETHERCARD_TOTAL_SIZE);
608 }
609
610 dev->base_addr = base_addr; /* Write back original base_addr */
611
612 return -ENODEV; /* Failed to find or init driver */
613
614 } /* End of SK_init */
615
616
617 MODULE_AUTHOR("Patrick J.D. Weichmann");
618 MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
619 MODULE_PARM(io, "i");
620 MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
621
622
623 #ifdef MODULE
624 static int io; /* 0 == probe */
625
626 static int __init SK_init_module (void)
627 {
628 int rc;
629
630 SK_dev = init_etherdev (NULL, 0);
631 if (!SK_dev)
632 return -ENOMEM;
633
634 SK_dev->base_addr = io;
635
636 rc = SK_init (SK_dev);
637 if (rc) {
638 unregister_netdev (SK_dev);
639 kfree (SK_dev);
640 SK_dev = NULL;
641 }
642
643 return rc;
644 }
645 #endif /* MODULE */
646
647
648 static void __exit SK_cleanup_module (void)
649 {
650 if (SK_dev) {
651 if (SK_dev->priv) {
652 kfree(SK_dev->priv);
653 SK_dev->priv = NULL;
654 }
655 unregister_netdev(SK_dev);
656 kfree(SK_dev);
657 SK_dev = NULL;
658 }
659 if (SK_ioaddr) {
660 release_region(SK_ioaddr, ETHERCARD_TOTAL_SIZE);
661 SK_ioaddr = 0;
662 }
663
664 }
665
666
667 #ifdef MODULE
668 module_init(SK_init_module);
669 #endif
670 module_exit(SK_cleanup_module);
671
672
673
674 /*-
675 * Function : SK_probe
676 * Author : Patrick J.D. Weichmann
677 * Date Created : 94/05/26
678 *
679 * Description : This function is called by SK_init and
680 * does the main part of initialization.
681 *
682 * Parameters : I : struct net_device *dev - SK_G16 device structure
683 * I : short ioaddr - I/O Port address where POS is.
684 * Return Value : 0 = Initialization done
685 * Errors : ENODEV - No SK_G16 found
686 * -1 - Configuration problem
687 * Globals : board - pointer to SK_RAM
688 * Update History :
689 * YY/MM/DD uid Description
690 * 94/06/30 pwe SK_ADDR now checked and at the correct place
691 -*/
692
693 int __init SK_probe(struct net_device *dev, short ioaddr)
694 {
695 int i,j; /* Counters */
696 int sk_addr_flag = 0; /* SK ADDR correct? 1 - no, 0 - yes */
697 unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */
698
699 struct priv *p; /* SK_G16 private structure */
700
701 if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
702 {
703
704 sk_addr_flag = 1;
705
706 /*
707 * Now here we could use a routine which searches for a free
708 * place in the ram and set SK_ADDR if found. TODO.
709 */
710 }
711
712 if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */
713 {
714 PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
715
716 rom_addr = SK_rom_addr();
717
718 if (rom_addr == 0) /* No Boot_ROM found */
719 {
720 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
721 {
722 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
723 dev->name, SK_ADDR);
724 return -1;
725 }
726
727 rom_addr = SK_ADDR; /* assign predefined address */
728
729 PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
730
731 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
732 outb(POS_ADDR, SK_POS3); /* Set RAM address */
733 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
734 }
735 else if (rom_addr == SK_ADDR)
736 {
737 printk("%s: RAM + ROM are set to the same address %#08x\n"
738 " Check configuration. Now switching off Boot_ROM\n",
739 SK_NAME, rom_addr);
740
741 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
742 outb(POS_ADDR, SK_POS3); /* Set RAM address */
743 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
744 }
745 else
746 {
747 PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
748 PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
749
750 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
751 {
752 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
753 dev->name, SK_ADDR);
754 return -1;
755 }
756
757 rom_addr = SK_ADDR;
758
759 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
760 outb(POS_ADDR, SK_POS3); /* Set RAM address */
761 outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */
762 }
763 }
764 else /* Don't keep Boot_ROM */
765 {
766 PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
767
768 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
769 {
770 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
771 dev->name, SK_ADDR);
772 return -1;
773 }
774
775 rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */
776
777 /* IF we find a Boot_ROM disable it */
778
779 outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
780
781 /* We found a Boot_ROM and it's gone. Set RAM address on
782 * Boot_ROM address.
783 */
784
785 if (rom_addr)
786 {
787 printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
788 "that address\n", SK_NAME, rom_addr);
789
790 outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */
791 }
792 else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
793 {
794 if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
795 {
796 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
797 dev->name, SK_ADDR);
798 return -1;
799 }
800
801 rom_addr = SK_ADDR;
802
803 outb(POS_ADDR, SK_POS3); /* Set RAM address */
804 }
805 outb(SK_RAM_ON, SK_POS2); /* enable RAM */
806 }
807
808 #ifdef SK_DEBUG
809 SK_print_pos(dev, "POS registers after ROM, RAM config");
810 #endif
811
812 board = (SK_RAM *) bus_to_virt(rom_addr);
813
814 /* Read in station address */
815 for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
816 {
817 dev->dev_addr[i] = readb(board->rom+j);
818 }
819
820 /* Check for manufacturer code */
821 if (!(dev->dev_addr[0] == SK_MAC0 &&
822 dev->dev_addr[1] == SK_MAC1 &&
823 dev->dev_addr[2] == SK_MAC2) )
824 {
825 PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
826 SK_NAME));
827 return -ENODEV; /* NO SK_G16 found */
828 }
829
830 printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
831 dev->name,
832 "Schneider & Koch Netcard",
833 (unsigned int) dev->base_addr,
834 dev->dev_addr[0],
835 dev->dev_addr[1],
836 dev->dev_addr[2],
837 dev->dev_addr[3],
838 dev->dev_addr[4],
839 dev->dev_addr[5]);
840
841 /* Allocate memory for private structure */
842 p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
843 if (p == NULL) {
844 printk("%s: ERROR - no memory for driver data!\n", dev->name);
845 return -ENOMEM;
846 }
847 memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
848
849 /* Assign our Device Driver functions */
850
851 dev->open = SK_open;
852 dev->stop = SK_close;
853 dev->hard_start_xmit = SK_send_packet;
854 dev->get_stats = SK_get_stats;
855 dev->set_multicast_list = set_multicast_list;
856 dev->tx_timeout = SK_timeout;
857 dev->watchdog_timeo = HZ/7;
858
859
860 /* Set the generic fields of the device structure */
861
862 ether_setup(dev);
863
864 dev->flags &= ~IFF_MULTICAST;
865
866 /* Initialize private structure */
867
868 p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
869 p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */
870 p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */
871
872 /* Initialize buffer pointers */
873
874 for (i = 0; i < TMDNUM; i++)
875 {
876 p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
877 }
878
879 for (i = 0; i < RMDNUM; i++)
880 {
881 p->rmdbufs[i] = &(p->ram)->rmdbuf[i];
882 }
883
884 #ifdef SK_DEBUG
885 SK_print_pos(dev, "End of SK_probe");
886 SK_print_ram(dev);
887 #endif
888
889 SK_dev = dev;
890 SK_ioaddr = ioaddr;
891
892 return 0; /* Initialization done */
893
894 } /* End of SK_probe() */
895
896
897 /*-
898 * Function : SK_open
899 * Author : Patrick J.D. Weichmann
900 * Date Created : 94/05/26
901 *
902 * Description : This function is called sometimes after booting
903 * when ifconfig program is run.
904 *
905 * This function requests an IRQ, sets the correct
906 * IRQ in the card. Then calls SK_lance_init() to
907 * init and start the LANCE chip. Then if everything is
908 * ok returns with 0 (OK), which means SK_G16 is now
909 * opened and operational.
910 *
911 * (Called by dev_open() /net/inet/dev.c)
912 *
913 * Parameters : I : struct net_device *dev - SK_G16 device structure
914 * Return Value : 0 - Device opened
915 * Errors : -EAGAIN - Open failed
916 * Side Effects : None
917 * Update History :
918 * YY/MM/DD uid Description
919 -*/
920
921 static int SK_open(struct net_device *dev)
922 {
923 int i = 0;
924 int irqval = 0;
925 int ioaddr = dev->base_addr;
926
927 int irqtab[] = SK_IRQS;
928
929 struct priv *p = (struct priv *)dev->priv;
930
931 PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
932 SK_NAME, SK_read_reg(CSR0)));
933
934 if (dev->irq == 0) /* Autoirq */
935 {
936 i = 0;
937
938 /*
939 * Check if one IRQ out of SK_IRQS is free and install
940 * interrupt handler.
941 * Most done by request_irq().
942 * irqval: 0 - interrupt handler installed for IRQ irqtab[i]
943 * -EBUSY - interrupt busy
944 * -EINVAL - irq > 15 or handler = NULL
945 */
946
947 do
948 {
949 irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
950 i++;
951 } while (irqval && irqtab[i]);
952
953 if (irqval) /* We tried every possible IRQ but no success */
954 {
955 printk("%s: unable to get an IRQ\n", dev->name);
956 return -EAGAIN;
957 }
958
959 dev->irq = irqtab[--i];
960
961 outb(i<<2, SK_POS4); /* Set Card on probed IRQ */
962
963 }
964 else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
965 {
966 if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
967 {
968 printk("%s: unable to get IRQ 9\n", dev->name);
969 return -EAGAIN;
970 }
971 dev->irq = 9;
972
973 /*
974 * Now we set card on IRQ2.
975 * This can be confusing, but remember that IRQ2 on the network
976 * card is in reality IRQ9
977 */
978 outb(0x08, SK_POS4); /* set card to IRQ2 */
979
980 }
981 else /* Check IRQ as defined in Space.c */
982 {
983 int i = 0;
984
985 /* check if IRQ free and valid. Then install Interrupt handler */
986
987 if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
988 {
989 printk("%s: unable to get selected IRQ\n", dev->name);
990 return -EAGAIN;
991 }
992
993 switch(dev->irq)
994 {
995 case 3: i = 0;
996 break;
997 case 5: i = 1;
998 break;
999 case 2: i = 2;
1000 break;
1001 case 11:i = 3;
1002 break;
1003 default:
1004 printk("%s: Preselected IRQ %d is invalid for %s boards",
1005 dev->name,
1006 dev->irq,
1007 SK_NAME);
1008 return -EAGAIN;
1009 }
1010
1011 outb(i<<2, SK_POS4); /* Set IRQ on card */
1012 }
1013
1014 printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
1015 dev->name, (unsigned int)dev->base_addr,
1016 (int) dev->irq, (unsigned int) p->ram);
1017
1018 if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */
1019 {
1020 netif_start_queue(dev);
1021
1022 #ifdef SK_DEBUG
1023
1024 /*
1025 * This debug block tries to stop LANCE,
1026 * reinit LANCE with transmitter and receiver disabled,
1027 * then stop again and reinit with NORMAL_MODE
1028 */
1029
1030 printk("## %s: After lance init. CSR0: %#06x\n",
1031 SK_NAME, SK_read_reg(CSR0));
1032 SK_write_reg(CSR0, CSR0_STOP);
1033 printk("## %s: LANCE stopped. CSR0: %#06x\n",
1034 SK_NAME, SK_read_reg(CSR0));
1035 SK_lance_init(dev, MODE_DTX | MODE_DRX);
1036 printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n",
1037 SK_NAME, SK_read_reg(CSR0));
1038 SK_write_reg(CSR0, CSR0_STOP);
1039 printk("## %s: LANCE stopped. CSR0: %#06x\n",
1040 SK_NAME, SK_read_reg(CSR0));
1041 SK_lance_init(dev, MODE_NORMAL);
1042 printk("## %s: LANCE back to normal mode. CSR0: %#06x\n",
1043 SK_NAME, SK_read_reg(CSR0));
1044 SK_print_pos(dev, "POS regs before returning OK");
1045
1046 #endif /* SK_DEBUG */
1047
1048 return 0; /* SK_open() is successful */
1049 }
1050 else /* LANCE init failed */
1051 {
1052
1053 PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
1054 SK_NAME, SK_read_reg(CSR0)));
1055
1056 return -EAGAIN;
1057 }
1058
1059 } /* End of SK_open() */
1060
1061
1062 /*-
1063 * Function : SK_lance_init
1064 * Author : Patrick J.D. Weichmann
1065 * Date Created : 94/05/26
1066 *
1067 * Description : Reset LANCE chip, fill RMD, TMD structures with
1068 * start values and Start LANCE.
1069 *
1070 * Parameters : I : struct net_device *dev - SK_G16 device structure
1071 * I : int mode - put LANCE into "mode" see data-sheet for
1072 * more info.
1073 * Return Value : 0 - Init done
1074 * Errors : -1 - Init failed
1075 * Update History :
1076 * YY/MM/DD uid Description
1077 -*/
1078
1079 static int SK_lance_init(struct net_device *dev, unsigned short mode)
1080 {
1081 int i;
1082 unsigned long flags;
1083 struct priv *p = (struct priv *) dev->priv;
1084 struct tmd *tmdp;
1085 struct rmd *rmdp;
1086
1087 PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
1088 SK_NAME, SK_read_reg(CSR0)));
1089
1090 /* Reset LANCE */
1091 SK_reset_board();
1092
1093 /* Initialize TMD's with start values */
1094 p->tmdnum = 0; /* First descriptor for transmitting */
1095 p->tmdlast = 0; /* First descriptor for reading stats */
1096
1097 for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
1098 {
1099 tmdp = p->tmdhead + i;
1100
1101 writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
1102
1103 /* Mark TMD as start and end of packet */
1104 writeb(TX_STP | TX_ENP, &tmdp->u.s.status);
1105 }
1106
1107
1108 /* Initialize RMD's with start values */
1109
1110 p->rmdnum = 0; /* First RMD which will be used */
1111
1112 for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
1113 {
1114 rmdp = p->rmdhead + i;
1115
1116
1117 writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
1118
1119 /*
1120 * LANCE must be owner at beginning so that he can fill in
1121 * receiving packets, set status and release RMD
1122 */
1123
1124 writeb(RX_OWN, &rmdp->u.s.status);
1125
1126 writew(-PKT_BUF_SZ, &rmdp->blen); /* Buffer Size (two's complement) */
1127
1128 writeb(0, &rmdp->mlen); /* init message length */
1129
1130 }
1131
1132 /* Fill LANCE Initialize Block */
1133
1134 writew(mode, (&((p->ram)->ib.mode))); /* Set operation mode */
1135
1136 for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
1137 {
1138 writeb(dev->dev_addr[i], (&((p->ram)->ib.paddr[i])));
1139 }
1140
1141 for (i = 0; i < 8; i++) /* Set multicast, logical address */
1142 {
1143 writeb(0, (&((p->ram)->ib.laddr[i]))); /* We do not use logical addressing */
1144 }
1145
1146 /* Set ring descriptor pointers and set number of descriptors */
1147
1148 writel((int)p->rmdhead | RMDNUMMASK, (&((p->ram)->ib.rdrp)));
1149 writel((int)p->tmdhead | TMDNUMMASK, (&((p->ram)->ib.tdrp)));
1150
1151 /* Prepare LANCE Control and Status Registers */
1152
1153 spin_lock_irqsave(&SK_lock, flags);
1154
1155 SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
1156
1157 /*
1158 * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1159 * PC Memory locations.
1160 *
1161 * In structure SK_ram is defined that the first thing in ram
1162 * is the initialization block. So his address is for LANCE always
1163 * 0x0000
1164 *
1165 * CSR1 contains low order bits 15:0 of initialization block address
1166 * CSR2 is built of:
1167 * 7:0 High order bits 23:16 of initialization block address
1168 * 15:8 reserved, must be 0
1169 */
1170
1171 /* Set initialization block address (must be on word boundary) */
1172 SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */
1173 SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */
1174
1175
1176 PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
1177 SK_NAME, SK_read_reg(CSR0)));
1178
1179 /* Initialize LANCE */
1180
1181 /*
1182 * INIT = Initialize, when set, causes the LANCE to begin the
1183 * initialization procedure and access the Init Block.
1184 */
1185
1186 SK_write_reg(CSR0, CSR0_INIT);
1187
1188 spin_unlock_irqrestore(&SK_lock, flags);
1189
1190 /* Wait until LANCE finished initialization */
1191
1192 SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
1193
1194 for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
1195 ; /* Wait until init done or go ahead if problems (i>=100) */
1196
1197 if (i >= 100) /* Something is wrong ! */
1198 {
1199 printk("%s: can't init am7990, status: %04x "
1200 "init_block: %#08x\n",
1201 dev->name, (int) SK_read_reg(CSR0),
1202 (unsigned int) &(p->ram)->ib);
1203
1204 #ifdef SK_DEBUG
1205 SK_print_pos(dev, "LANCE INIT failed");
1206 SK_print_dev(dev,"Device Structure:");
1207 #endif
1208
1209 return -1; /* LANCE init failed */
1210 }
1211
1212 PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
1213
1214 /* Clear Initialize done, enable Interrupts, start LANCE */
1215
1216 SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
1217
1218 PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME,
1219 SK_read_reg(CSR0)));
1220
1221 return 0; /* LANCE is up and running */
1222
1223 } /* End of SK_lance_init() */
1224
1225
1226
1227 /*-
1228 * Function : SK_send_packet
1229 * Author : Patrick J.D. Weichmann
1230 * Date Created : 94/05/27
1231 *
1232 * Description : Writes an socket buffer into a transmit descriptor
1233 * and starts transmission.
1234 *
1235 * Parameters : I : struct sk_buff *skb - packet to transfer
1236 * I : struct net_device *dev - SK_G16 device structure
1237 * Return Value : 0 - OK
1238 * 1 - Could not transmit (dev_queue_xmit will queue it)
1239 * and try to sent it later
1240 * Globals : None
1241 * Side Effects : None
1242 * Update History :
1243 * YY/MM/DD uid Description
1244 -*/
1245
1246 static void SK_timeout(struct net_device *dev)
1247 {
1248 printk(KERN_WARNING "%s: xmitter timed out, try to restart!\n", dev->name);
1249 SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
1250 netif_wake_queue(dev); /* Clear Transmitter flag */
1251 dev->trans_start = jiffies; /* Mark Start of transmission */
1252 }
1253
1254 static int SK_send_packet(struct sk_buff *skb, struct net_device *dev)
1255 {
1256 struct priv *p = (struct priv *) dev->priv;
1257 struct tmd *tmdp;
1258
1259 PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
1260 SK_NAME, SK_read_reg(CSR0)));
1261
1262
1263 /*
1264 * Block a timer-based transmit from overlapping.
1265 * This means check if we are already in.
1266 */
1267
1268 netif_stop_queue (dev);
1269
1270 {
1271
1272 /* Evaluate Packet length */
1273 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1274
1275 tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1276
1277 /* Fill in Transmit Message Descriptor */
1278
1279 /* Copy data into dual ported ram */
1280
1281 memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
1282
1283 writew(-len, &tmdp->blen); /* set length to transmit */
1284
1285 /*
1286 * Packet start and end is always set because we use the maximum
1287 * packet length as buffer length.
1288 * Relinquish ownership to LANCE
1289 */
1290
1291 writeb(TX_OWN | TX_STP | TX_ENP, &tmdp->u.s.status);
1292
1293 /* Start Demand Transmission */
1294 SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1295
1296 dev->trans_start = jiffies; /* Mark start of transmission */
1297
1298 /* Set pointer to next transmit buffer */
1299 p->tmdnum++;
1300 p->tmdnum &= TMDNUM-1;
1301
1302 /* Do we own the next transmit buffer ? */
1303 if (! (readb(&((p->tmdhead + p->tmdnum)->u.s.status)) & TX_OWN) )
1304 {
1305 /*
1306 * We own next buffer and are ready to transmit, so
1307 * clear busy flag
1308 */
1309 netif_start_queue(dev);
1310 }
1311
1312 p->stats.tx_bytes += skb->len;
1313
1314 }
1315
1316 dev_kfree_skb(skb);
1317 return 0;
1318 } /* End of SK_send_packet */
1319
1320
1321 /*-
1322 * Function : SK_interrupt
1323 * Author : Patrick J.D. Weichmann
1324 * Date Created : 94/05/27
1325 *
1326 * Description : SK_G16 interrupt handler which checks for LANCE
1327 * Errors, handles transmit and receive interrupts
1328 *
1329 * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
1330 * Return Value : None
1331 * Errors : None
1332 * Globals : None
1333 * Side Effects : None
1334 * Update History :
1335 * YY/MM/DD uid Description
1336 -*/
1337
1338 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1339 {
1340 int csr0;
1341 struct net_device *dev = dev_id;
1342 struct priv *p = (struct priv *) dev->priv;
1343
1344
1345 PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
1346 SK_NAME, SK_read_reg(CSR0)));
1347
1348 if (dev == NULL)
1349 {
1350 printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1351 }
1352
1353 spin_lock (&SK_lock);
1354
1355 csr0 = SK_read_reg(CSR0); /* store register for checking */
1356
1357 /*
1358 * Acknowledge all of the current interrupt sources, disable
1359 * Interrupts (INEA = 0)
1360 */
1361
1362 SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
1363
1364 if (csr0 & CSR0_ERR) /* LANCE Error */
1365 {
1366 printk("%s: error: %04x\n", dev->name, csr0);
1367
1368 if (csr0 & CSR0_MISS) /* No place to store packet ? */
1369 {
1370 p->stats.rx_dropped++;
1371 }
1372 }
1373
1374 if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */
1375 {
1376 SK_rxintr(dev);
1377 }
1378
1379 if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */
1380 {
1381 SK_txintr(dev);
1382 }
1383
1384 SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1385
1386 spin_unlock (&SK_lock);
1387 } /* End of SK_interrupt() */
1388
1389
1390 /*-
1391 * Function : SK_txintr
1392 * Author : Patrick J.D. Weichmann
1393 * Date Created : 94/05/27
1394 *
1395 * Description : After sending a packet we check status, update
1396 * statistics and relinquish ownership of transmit
1397 * descriptor ring.
1398 *
1399 * Parameters : I : struct net_device *dev - SK_G16 device structure
1400 * Return Value : None
1401 * Errors : None
1402 * Globals : None
1403 * Update History :
1404 * YY/MM/DD uid Description
1405 -*/
1406
1407 static void SK_txintr(struct net_device *dev)
1408 {
1409 int tmdstat;
1410 struct tmd *tmdp;
1411 struct priv *p = (struct priv *) dev->priv;
1412
1413
1414 PRINTK2(("## %s: SK_txintr() status: %#06x\n",
1415 SK_NAME, SK_read_reg(CSR0)));
1416
1417 tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */
1418
1419 /* Set next buffer */
1420 p->tmdlast++;
1421 p->tmdlast &= TMDNUM-1;
1422
1423 tmdstat = readb(&tmdp->u.s.status);
1424
1425 /*
1426 * We check status of transmitted packet.
1427 * see LANCE data-sheet for error explanation
1428 */
1429 if (tmdstat & TX_ERR) /* Error occurred */
1430 {
1431 int stat2 = readw(&tmdp->status2);
1432
1433 printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
1434
1435 if (stat2 & TX_TDR) /* TDR problems? */
1436 {
1437 printk("%s: tdr-problems \n", dev->name);
1438 }
1439
1440 if (stat2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */
1441 p->stats.tx_aborted_errors++;
1442 if (stat2 & TX_LCOL) /* Late collision ? */
1443 p->stats.tx_window_errors++;
1444 if (stat2 & TX_LCAR) /* Loss of Carrier ? */
1445 p->stats.tx_carrier_errors++;
1446 if (stat2 & TX_UFLO) /* Underflow error ? */
1447 {
1448 p->stats.tx_fifo_errors++;
1449
1450 /*
1451 * If UFLO error occurs it will turn transmitter of.
1452 * So we must reinit LANCE
1453 */
1454
1455 SK_lance_init(dev, MODE_NORMAL);
1456 }
1457
1458 p->stats.tx_errors++;
1459
1460 writew(0, &tmdp->status2); /* Clear error flags */
1461 }
1462 else if (tmdstat & TX_MORE) /* Collisions occurred ? */
1463 {
1464 /*
1465 * Here I have a problem.
1466 * I only know that there must be one or up to 15 collisions.
1467 * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1468 * will be set which means couldn't send packet aborted transfer.
1469 *
1470 * First I did not have this in but then I thought at minimum
1471 * we see that something was not ok.
1472 * If anyone knows something better than this to handle this
1473 * please report it.
1474 */
1475
1476 p->stats.collisions++;
1477 }
1478 else /* Packet sent without any problems */
1479 {
1480 p->stats.tx_packets++;
1481 }
1482
1483 /*
1484 * We mark transmitter not busy anymore, because now we have a free
1485 * transmit descriptor which can be filled by SK_send_packet and
1486 * afterwards sent by the LANCE
1487 *
1488 * The function which do handle slow IRQ parts is do_bottom_half()
1489 * which runs at normal kernel priority, that means all interrupt are
1490 * enabled. (see kernel/irq.c)
1491 *
1492 * net_bh does something like this:
1493 * - check if already in net_bh
1494 * - try to transmit something from the send queue
1495 * - if something is in the receive queue send it up to higher
1496 * levels if it is a known protocol
1497 * - try to transmit something from the send queue
1498 */
1499
1500 netif_wake_queue(dev);
1501
1502 } /* End of SK_txintr() */
1503
1504
1505 /*-
1506 * Function : SK_rxintr
1507 * Author : Patrick J.D. Weichmann
1508 * Date Created : 94/05/27
1509 *
1510 * Description : Buffer sent, check for errors, relinquish ownership
1511 * of the receive message descriptor.
1512 *
1513 * Parameters : I : SK_G16 device structure
1514 * Return Value : None
1515 * Globals : None
1516 * Update History :
1517 * YY/MM/DD uid Description
1518 -*/
1519
1520 static void SK_rxintr(struct net_device *dev)
1521 {
1522
1523 struct rmd *rmdp;
1524 int rmdstat;
1525 struct priv *p = (struct priv *) dev->priv;
1526
1527 PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
1528 SK_NAME, SK_read_reg(CSR0)));
1529
1530 rmdp = p->rmdhead + p->rmdnum;
1531
1532 /* As long as we own the next entry, check status and send
1533 * it up to higher layer
1534 */
1535
1536 while (!( (rmdstat = readb(&rmdp->u.s.status)) & RX_OWN))
1537 {
1538 /*
1539 * Start and end of packet must be set, because we use
1540 * the ethernet maximum packet length (1518) as buffer size.
1541 *
1542 * Because our buffers are at maximum OFLO and BUFF errors are
1543 * not to be concerned (see Data sheet)
1544 */
1545
1546 if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
1547 {
1548 /* Start of a frame > 1518 Bytes ? */
1549
1550 if (rmdstat & RX_STP)
1551 {
1552 p->stats.rx_errors++; /* bad packet received */
1553 p->stats.rx_length_errors++; /* packet too long */
1554
1555 printk("%s: packet too long\n", dev->name);
1556 }
1557
1558 /*
1559 * All other packets will be ignored until a new frame with
1560 * start (RX_STP) set follows.
1561 *
1562 * What we do is just give descriptor free for new incoming
1563 * packets.
1564 */
1565
1566 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1567
1568 }
1569 else if (rmdstat & RX_ERR) /* Receive Error ? */
1570 {
1571 printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1572
1573 p->stats.rx_errors++;
1574
1575 if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1576 if (rmdstat & RX_CRC) p->stats.rx_crc_errors++;
1577
1578 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1579
1580 }
1581 else /* We have a packet which can be queued for the upper layers */
1582 {
1583
1584 int len = readw(&rmdp->mlen) & 0x0fff; /* extract message length from receive buffer */
1585 struct sk_buff *skb;
1586
1587 skb = dev_alloc_skb(len+2); /* allocate socket buffer */
1588
1589 if (skb == NULL) /* Could not get mem ? */
1590 {
1591
1592 /*
1593 * Couldn't allocate sk_buffer so we give descriptor back
1594 * to Lance, update statistics and go ahead.
1595 */
1596
1597 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1598 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1599 dev->name);
1600 p->stats.rx_dropped++;
1601
1602 break; /* Jump out */
1603 }
1604
1605 /* Prepare sk_buff to queue for upper layers */
1606
1607 skb->dev = dev;
1608 skb_reserve(skb,2); /* Align IP header on 16 byte boundary */
1609
1610 /*
1611 * Copy data out of our receive descriptor into sk_buff.
1612 *
1613 * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
1614 * ignore status fields)
1615 */
1616
1617 memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
1618
1619
1620 /*
1621 * Notify the upper protocol layers that there is another packet
1622 * to handle
1623 *
1624 * netif_rx() always succeeds. see /net/inet/dev.c for more.
1625 */
1626
1627 skb->protocol=eth_type_trans(skb,dev);
1628 netif_rx(skb); /* queue packet and mark it for processing */
1629
1630 /*
1631 * Packet is queued and marked for processing so we
1632 * free our descriptor and update statistics
1633 */
1634
1635 writeb(RX_OWN, &rmdp->u.s.status);
1636 dev->last_rx = jiffies;
1637 p->stats.rx_packets++;
1638 p->stats.rx_bytes += len;
1639
1640
1641 p->rmdnum++;
1642 p->rmdnum %= RMDNUM;
1643
1644 rmdp = p->rmdhead + p->rmdnum;
1645 }
1646 }
1647 } /* End of SK_rxintr() */
1648
1649
1650 /*-
1651 * Function : SK_close
1652 * Author : Patrick J.D. Weichmann
1653 * Date Created : 94/05/26
1654 *
1655 * Description : close gets called from dev_close() and should
1656 * deinstall the card (free_irq, mem etc).
1657 *
1658 * Parameters : I : struct net_device *dev - our device structure
1659 * Return Value : 0 - closed device driver
1660 * Errors : None
1661 * Globals : None
1662 * Update History :
1663 * YY/MM/DD uid Description
1664 -*/
1665
1666 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1667 * down' the system stops. So I don't shut set card to init state.
1668 */
1669
1670 static int SK_close(struct net_device *dev)
1671 {
1672
1673 PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
1674 SK_NAME, SK_read_reg(CSR0)));
1675
1676 netif_stop_queue(dev); /* Transmitter busy */
1677
1678 printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,
1679 (int) SK_read_reg(CSR0));
1680
1681 SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1682
1683 free_irq(dev->irq, dev); /* Free IRQ */
1684
1685 return 0; /* always succeed */
1686
1687 } /* End of SK_close() */
1688
1689
1690 /*-
1691 * Function : SK_get_stats
1692 * Author : Patrick J.D. Weichmann
1693 * Date Created : 94/05/26
1694 *
1695 * Description : Return current status structure to upper layers.
1696 * It is called by sprintf_stats (dev.c).
1697 *
1698 * Parameters : I : struct net_device *dev - our device structure
1699 * Return Value : struct net_device_stats * - our current statistics
1700 * Errors : None
1701 * Side Effects : None
1702 * Update History :
1703 * YY/MM/DD uid Description
1704 -*/
1705
1706 static struct net_device_stats *SK_get_stats(struct net_device *dev)
1707 {
1708
1709 struct priv *p = (struct priv *) dev->priv;
1710
1711 PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
1712 SK_NAME, SK_read_reg(CSR0)));
1713
1714 return &p->stats; /* Return Device status */
1715
1716 } /* End of SK_get_stats() */
1717
1718
1719 /*-
1720 * Function : set_multicast_list
1721 * Author : Patrick J.D. Weichmann
1722 * Date Created : 94/05/26
1723 *
1724 * Description : This function gets called when a program performs
1725 * a SIOCSIFFLAGS call. Ifconfig does this if you call
1726 * 'ifconfig [-]allmulti' which enables or disables the
1727 * Promiscuous mode.
1728 * Promiscuous mode is when the Network card accepts all
1729 * packets, not only the packets which match our MAC
1730 * Address. It is useful for writing a network monitor,
1731 * but it is also a security problem. You have to remember
1732 * that all information on the net is not encrypted.
1733 *
1734 * Parameters : I : struct net_device *dev - SK_G16 device Structure
1735 * Return Value : None
1736 * Errors : None
1737 * Globals : None
1738 * Update History :
1739 * YY/MM/DD uid Description
1740 * 95/10/18 ACox New multicast calling scheme
1741 -*/
1742
1743
1744 /* Set or clear the multicast filter for SK_G16.
1745 */
1746
1747 static void set_multicast_list(struct net_device *dev)
1748 {
1749
1750 if (dev->flags&IFF_PROMISC)
1751 {
1752 /* Reinitialize LANCE with MODE_PROM set */
1753 SK_lance_init(dev, MODE_PROM);
1754 }
1755 else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
1756 {
1757 /* Reinitialize LANCE without MODE_PROM */
1758 SK_lance_init(dev, MODE_NORMAL);
1759 }
1760 else
1761 {
1762 /* Multicast with logical address filter on */
1763 /* Reinitialize LANCE without MODE_PROM */
1764 SK_lance_init(dev, MODE_NORMAL);
1765
1766 /* Not implemented yet. */
1767 }
1768 } /* End of set_multicast_list() */
1769
1770
1771
1772 /*-
1773 * Function : SK_rom_addr
1774 * Author : Patrick J.D. Weichmann
1775 * Date Created : 94/06/01
1776 *
1777 * Description : Try to find a Boot_ROM at all possible locations
1778 *
1779 * Parameters : None
1780 * Return Value : Address where Boot_ROM is
1781 * Errors : 0 - Did not find Boot_ROM
1782 * Globals : None
1783 * Update History :
1784 * YY/MM/DD uid Description
1785 -*/
1786
1787 unsigned int __init SK_rom_addr(void)
1788 {
1789 int i,j;
1790 int rom_found = 0;
1791 unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1792 unsigned char rom_id[] = SK_BOOT_ROM_ID;
1793 unsigned char test_byte;
1794
1795 /* Autodetect Boot_ROM */
1796 PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1797
1798 for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1799 {
1800
1801 PRINTK(("## Trying ROM location %#08x", rom_location[i]));
1802
1803 rom_found = 1;
1804 for (j = 0; j < 6; j++)
1805 {
1806 test_byte = readb(rom_location[i]+j);
1807 PRINTK((" %02x ", *test_byte));
1808
1809 if(test_byte != rom_id[j])
1810 {
1811 rom_found = 0;
1812 }
1813 }
1814 PRINTK(("\n"));
1815 }
1816
1817 if (rom_found == 1)
1818 {
1819 PRINTK(("## %s: Boot_ROM found at %#08x\n",
1820 SK_NAME, rom_location[(i-1)]));
1821
1822 return (rom_location[--i]);
1823 }
1824 else
1825 {
1826 PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1827 return 0;
1828 }
1829 } /* End of SK_rom_addr() */
1830
1831
1832
1833 /* LANCE access functions
1834 *
1835 * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1836 */
1837
1838
1839 /*-
1840 * Function : SK_reset_board
1841 *
1842 * Author : Patrick J.D. Weichmann
1843 *
1844 * Date Created : 94/05/25
1845 *
1846 * Description : This function resets SK_G16 and all components, but
1847 * POS registers are not changed
1848 *
1849 * Parameters : None
1850 * Return Value : None
1851 * Errors : None
1852 * Globals : SK_RAM *board - SK_RAM structure pointer
1853 *
1854 * Update History :
1855 * YY/MM/DD uid Description
1856 -*/
1857
1858 void SK_reset_board(void)
1859 {
1860 writeb(0x00, SK_PORT); /* Reset active */
1861 mdelay(5); /* Delay min 5ms */
1862 writeb(SK_RESET, SK_PORT); /* Set back to normal operation */
1863
1864 } /* End of SK_reset_board() */
1865
1866
1867 /*-
1868 * Function : SK_set_RAP
1869 * Author : Patrick J.D. Weichmann
1870 * Date Created : 94/05/25
1871 *
1872 * Description : Set LANCE Register Address Port to register
1873 * for later data transfer.
1874 *
1875 * Parameters : I : reg_number - which CSR to read/write from/to
1876 * Return Value : None
1877 * Errors : None
1878 * Globals : SK_RAM *board - SK_RAM structure pointer
1879 * Update History :
1880 * YY/MM/DD uid Description
1881 -*/
1882
1883 void SK_set_RAP(int reg_number)
1884 {
1885 writew(reg_number, SK_IOREG);
1886 writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
1887 writeb(SK_DOIO, SK_IOCOM);
1888
1889 while (readb(SK_PORT) & SK_IORUN)
1890 barrier();
1891 } /* End of SK_set_RAP() */
1892
1893
1894 /*-
1895 * Function : SK_read_reg
1896 * Author : Patrick J.D. Weichmann
1897 * Date Created : 94/05/25
1898 *
1899 * Description : Set RAP and read data from a LANCE CSR register
1900 *
1901 * Parameters : I : reg_number - which CSR to read from
1902 * Return Value : Register contents
1903 * Errors : None
1904 * Globals : SK_RAM *board - SK_RAM structure pointer
1905 * Update History :
1906 * YY/MM/DD uid Description
1907 -*/
1908
1909 int SK_read_reg(int reg_number)
1910 {
1911 SK_set_RAP(reg_number);
1912
1913 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1914 writeb(SK_DOIO, SK_IOCOM);
1915
1916 while (readb(SK_PORT) & SK_IORUN)
1917 barrier();
1918 return (readw(SK_IOREG));
1919
1920 } /* End of SK_read_reg() */
1921
1922
1923 /*-
1924 * Function : SK_rread_reg
1925 * Author : Patrick J.D. Weichmann
1926 * Date Created : 94/05/28
1927 *
1928 * Description : Read data from preseted register.
1929 * This function requires that you know which
1930 * Register is actually set. Be aware that CSR1-3
1931 * can only be accessed when in CSR0 STOP is set.
1932 *
1933 * Return Value : Register contents
1934 * Errors : None
1935 * Globals : SK_RAM *board - SK_RAM structure pointer
1936 * Update History :
1937 * YY/MM/DD uid Description
1938 -*/
1939
1940 int SK_rread_reg(void)
1941 {
1942 writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1943
1944 writeb(SK_DOIO, SK_IOCOM);
1945
1946 while (readb(SK_PORT) & SK_IORUN)
1947 barrier();
1948 return (readw(SK_IOREG));
1949
1950 } /* End of SK_rread_reg() */
1951
1952
1953 /*-
1954 * Function : SK_write_reg
1955 * Author : Patrick J.D. Weichmann
1956 * Date Created : 94/05/25
1957 *
1958 * Description : This function sets the RAP then fills in the
1959 * LANCE I/O Reg and starts Transfer to LANCE.
1960 * It waits until transfer has ended which is max. 7 ms
1961 * and then it returns.
1962 *
1963 * Parameters : I : reg_number - which CSR to write to
1964 * I : value - what value to fill into register
1965 * Return Value : None
1966 * Errors : None
1967 * Globals : SK_RAM *board - SK_RAM structure pointer
1968 * Update History :
1969 * YY/MM/DD uid Description
1970 -*/
1971
1972 void SK_write_reg(int reg_number, int value)
1973 {
1974 SK_set_RAP(reg_number);
1975
1976 writew(value, SK_IOREG);
1977 writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
1978 writeb(SK_DOIO, SK_IOCOM);
1979
1980 while (readb(SK_PORT) & SK_IORUN)
1981 barrier();
1982 } /* End of SK_write_reg */
1983
1984
1985
1986 /*
1987 * Debugging functions
1988 * -------------------
1989 */
1990
1991 /*-
1992 * Function : SK_print_pos
1993 * Author : Patrick J.D. Weichmann
1994 * Date Created : 94/05/25
1995 *
1996 * Description : This function prints out the 4 POS (Programmable
1997 * Option Select) Registers. Used mainly to debug operation.
1998 *
1999 * Parameters : I : struct net_device *dev - SK_G16 device structure
2000 * I : char * - Text which will be printed as title
2001 * Return Value : None
2002 * Errors : None
2003 * Update History :
2004 * YY/MM/DD uid Description
2005 -*/
2006
2007 void SK_print_pos(struct net_device *dev, char *text)
2008 {
2009 int ioaddr = dev->base_addr;
2010
2011 unsigned char pos0 = inb(SK_POS0),
2012 pos1 = inb(SK_POS1),
2013 pos2 = inb(SK_POS2),
2014 pos3 = inb(SK_POS3),
2015 pos4 = inb(SK_POS4);
2016
2017
2018 printk("## %s: %s.\n"
2019 "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
2020 SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
2021
2022 } /* End of SK_print_pos() */
2023
2024
2025
2026 /*-
2027 * Function : SK_print_dev
2028 * Author : Patrick J.D. Weichmann
2029 * Date Created : 94/05/25
2030 *
2031 * Description : This function simply prints out the important fields
2032 * of the device structure.
2033 *
2034 * Parameters : I : struct net_device *dev - SK_G16 device structure
2035 * I : char *text - Title for printing
2036 * Return Value : None
2037 * Errors : None
2038 * Update History :
2039 * YY/MM/DD uid Description
2040 -*/
2041
2042 void SK_print_dev(struct net_device *dev, char *text)
2043 {
2044 if (dev == NULL)
2045 {
2046 printk("## %s: Device Structure. %s\n", SK_NAME, text);
2047 printk("## DEVICE == NULL\n");
2048 }
2049 else
2050 {
2051 printk("## %s: Device Structure. %s\n", SK_NAME, text);
2052 printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",
2053 dev->name, dev->base_addr, dev->irq);
2054
2055 printk("## next device: %#08x init function: %#08x\n",
2056 (int) dev->next, (int) dev->init);
2057 }
2058
2059 } /* End of SK_print_dev() */
2060
2061
2062
2063 /*-
2064 * Function : SK_print_ram
2065 * Author : Patrick J.D. Weichmann
2066 * Date Created : 94/06/02
2067 *
2068 * Description : This function is used to check how are things set up
2069 * in the 16KB RAM. Also the pointers to the receive and
2070 * transmit descriptor rings and rx and tx buffers locations.
2071 * It contains a minor bug in printing, but has no effect to the values
2072 * only newlines are not correct.
2073 *
2074 * Parameters : I : struct net_device *dev - SK_G16 device structure
2075 * Return Value : None
2076 * Errors : None
2077 * Globals : None
2078 * Update History :
2079 * YY/MM/DD uid Description
2080 -*/
2081
2082 void __init SK_print_ram(struct net_device *dev)
2083 {
2084
2085 int i;
2086 struct priv *p = (struct priv *) dev->priv;
2087
2088 printk("## %s: RAM Details.\n"
2089 "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2090 SK_NAME,
2091 (unsigned int) p->ram,
2092 (unsigned int) p->tmdhead,
2093 (unsigned int) p->rmdhead,
2094 (unsigned int) &(p->ram)->ib);
2095
2096 printk("## ");
2097
2098 for(i = 0; i < TMDNUM; i++)
2099 {
2100 if (!(i % 3)) /* Every third line do a newline */
2101 {
2102 printk("\n## ");
2103 }
2104 printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2105 }
2106 printk("## ");
2107
2108 for(i = 0; i < RMDNUM; i++)
2109 {
2110 if (!(i % 3)) /* Every third line do a newline */
2111 {
2112 printk("\n## ");
2113 }
2114 printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2115 }
2116 printk("\n");
2117
2118 } /* End of SK_print_ram() */
2119
2120