setup enviroment for compilation
[linux-2.4.21-pre4.git] / 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.1.1 $
10  *
11  * Author         : Patrick J.D. Weichmann
12  *
13  * Date Created   : 94/05/26
14  * Last Updated   : $Date: 2005/04/11 02:50:28 $
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.1.1 2005/04/11 02:50:28 jack 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 \f
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 \f
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_LICENSE("GPL");
620 MODULE_PARM(io, "i");
621 MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
622
623
624 #ifdef MODULE
625 static int io;  /* 0 == probe */
626
627 static int __init SK_init_module (void)
628 {
629         int rc;
630         
631         SK_dev = init_etherdev (NULL, 0);
632         if (!SK_dev)
633                 return -ENOMEM;
634         
635         SK_dev->base_addr = io;
636
637         rc = SK_init (SK_dev);
638         if (rc) {
639                 unregister_netdev (SK_dev);
640                 kfree (SK_dev);
641                 SK_dev = NULL;
642         }
643         
644         return rc;
645 }
646 #endif /* MODULE */
647
648
649 static void __exit SK_cleanup_module (void)
650 {
651         if (SK_dev) {
652                 if (SK_dev->priv) {
653                         kfree(SK_dev->priv);
654                         SK_dev->priv = NULL;
655                 }
656                 unregister_netdev(SK_dev);
657                 kfree(SK_dev);
658                 SK_dev = NULL;
659         }
660         if (SK_ioaddr) {
661                 release_region(SK_ioaddr, ETHERCARD_TOTAL_SIZE);
662                 SK_ioaddr = 0;
663         }
664                 
665 }
666
667
668 #ifdef MODULE
669 module_init(SK_init_module);
670 #endif
671 module_exit(SK_cleanup_module);
672
673
674 \f
675 /*-
676  * Function       : SK_probe
677  * Author         : Patrick J.D. Weichmann
678  * Date Created   : 94/05/26
679  *
680  * Description    : This function is called by SK_init and 
681  *                  does the main part of initialization.
682  *                  
683  * Parameters     : I : struct net_device *dev - SK_G16 device structure
684  *                  I : short ioaddr       - I/O Port address where POS is.
685  * Return Value   : 0 = Initialization done             
686  * Errors         : ENODEV - No SK_G16 found
687  *                  -1     - Configuration problem
688  * Globals        : board       - pointer to SK_RAM
689  * Update History :
690  *     YY/MM/DD  uid  Description
691  *     94/06/30  pwe  SK_ADDR now checked and at the correct place
692 -*/
693
694 int __init SK_probe(struct net_device *dev, short ioaddr)
695 {
696     int i,j;                /* Counters */
697     int sk_addr_flag = 0;   /* SK ADDR correct? 1 - no, 0 - yes */
698     unsigned int rom_addr;  /* used to store RAM address used for POS_ADDR */
699
700     struct priv *p;         /* SK_G16 private structure */
701
702     if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
703     {
704       
705        sk_addr_flag = 1;
706
707        /* 
708         * Now here we could use a routine which searches for a free
709         * place in the ram and set SK_ADDR if found. TODO. 
710         */
711     }
712
713     if (SK_BOOT_ROM)            /* Shall we keep Boot_ROM on ? */
714     {
715         PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
716
717         rom_addr = SK_rom_addr();
718
719         if (rom_addr == 0)      /* No Boot_ROM found */
720         {
721             if (sk_addr_flag)   /* No or Invalid SK_ADDR is defined */ 
722             {
723                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
724                        dev->name, SK_ADDR);
725                 return -1;
726             }
727
728             rom_addr = SK_ADDR; /* assign predefined address */
729
730             PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
731
732             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
733             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
734             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
735         }
736         else if (rom_addr == SK_ADDR) 
737         {
738             printk("%s: RAM + ROM are set to the same address %#08x\n"
739                    "   Check configuration. Now switching off Boot_ROM\n",
740                    SK_NAME, rom_addr);
741
742             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
743             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
744             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
745         }
746         else
747         {
748             PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
749             PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
750
751             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
752             {
753                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
754                        dev->name, SK_ADDR);
755                 return -1;
756             }
757
758             rom_addr = SK_ADDR;
759
760             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 
761             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
762             outb(SK_ROM_RAM_ON, SK_POS2);  /* RAM on, BOOT_ROM on */
763         }
764     }
765     else /* Don't keep Boot_ROM */
766     {
767         PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
768
769         if (sk_addr_flag)           /* No or Invalid SK_ADDR is defined */ 
770         {
771             printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
772                    dev->name, SK_ADDR);
773             return -1;
774         }
775
776         rom_addr = SK_rom_addr();          /* Try to find a Boot_ROM */
777
778         /* IF we find a Boot_ROM disable it */
779
780         outb(SK_ROM_RAM_OFF, SK_POS2);     /* Boot_ROM + RAM off */  
781
782         /* We found a Boot_ROM and it's gone. Set RAM address on
783          * Boot_ROM address. 
784          */ 
785
786         if (rom_addr) 
787         {
788             printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
789                    "that address\n", SK_NAME, rom_addr);
790
791             outb(POS_ADDR, SK_POS3);       /* Set RAM on Boot_ROM address */
792         }
793         else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
794         {
795             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
796             {
797                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
798                        dev->name, SK_ADDR);
799                 return -1;
800             }
801
802             rom_addr = SK_ADDR;
803
804             outb(POS_ADDR, SK_POS3);       /* Set RAM address */ 
805         }
806         outb(SK_RAM_ON, SK_POS2);          /* enable RAM */
807     }
808
809 #ifdef SK_DEBUG
810     SK_print_pos(dev, "POS registers after ROM, RAM config");
811 #endif
812
813     board = (SK_RAM *) bus_to_virt(rom_addr);
814
815     /* Read in station address */
816     for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
817     {
818         dev->dev_addr[i] = readb(board->rom+j);          
819     }
820
821     /* Check for manufacturer code */
822     if (!(dev->dev_addr[0] == SK_MAC0 &&
823           dev->dev_addr[1] == SK_MAC1 &&
824           dev->dev_addr[2] == SK_MAC2) )
825     {
826         PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
827                 SK_NAME)); 
828         return -ENODEV;                     /* NO SK_G16 found */
829     }
830
831     printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
832             dev->name,
833             "Schneider & Koch Netcard",
834             (unsigned int) dev->base_addr,
835             dev->dev_addr[0],
836             dev->dev_addr[1],
837             dev->dev_addr[2],
838             dev->dev_addr[3],
839             dev->dev_addr[4],
840             dev->dev_addr[5]);
841
842     /* Allocate memory for private structure */
843     p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
844     if (p == NULL) {
845            printk("%s: ERROR - no memory for driver data!\n", dev->name);
846            return -ENOMEM;
847     }
848     memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
849
850     /* Assign our Device Driver functions */
851
852     dev->open                   = SK_open;
853     dev->stop                   = SK_close;
854     dev->hard_start_xmit        = SK_send_packet;
855     dev->get_stats              = SK_get_stats;
856     dev->set_multicast_list     = set_multicast_list;
857     dev->tx_timeout             = SK_timeout;
858     dev->watchdog_timeo         = HZ/7;
859
860
861     /* Set the generic fields of the device structure */
862
863     ether_setup(dev);
864     
865     dev->flags &= ~IFF_MULTICAST;
866
867     /* Initialize private structure */
868
869     p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
870     p->tmdhead = &(p->ram)->tmde[0];     /* Set TMD head */
871     p->rmdhead = &(p->ram)->rmde[0];     /* Set RMD head */
872
873     /* Initialize buffer pointers */
874
875     for (i = 0; i < TMDNUM; i++)
876     {
877         p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
878     }
879
880     for (i = 0; i < RMDNUM; i++)
881     {
882         p->rmdbufs[i] = &(p->ram)->rmdbuf[i]; 
883     }
884
885 #ifdef SK_DEBUG
886     SK_print_pos(dev, "End of SK_probe");
887     SK_print_ram(dev);
888 #endif 
889
890     SK_dev = dev;
891     SK_ioaddr = ioaddr;
892
893     return 0;                            /* Initialization done */
894
895 } /* End of SK_probe() */
896
897 \f
898 /*- 
899  * Function       : SK_open
900  * Author         : Patrick J.D. Weichmann
901  * Date Created   : 94/05/26
902  *
903  * Description    : This function is called sometimes after booting 
904  *                  when ifconfig program is run.
905  *
906  *                  This function requests an IRQ, sets the correct
907  *                  IRQ in the card. Then calls SK_lance_init() to 
908  *                  init and start the LANCE chip. Then if everything is 
909  *                  ok returns with 0 (OK), which means SK_G16 is now
910  *                  opened and operational.
911  *
912  *                  (Called by dev_open() /net/inet/dev.c)
913  *
914  * Parameters     : I : struct net_device *dev - SK_G16 device structure
915  * Return Value   : 0 - Device opened
916  * Errors         : -EAGAIN - Open failed
917  * Side Effects   : None
918  * Update History :
919  *     YY/MM/DD  uid  Description
920 -*/
921
922 static int SK_open(struct net_device *dev)
923 {
924     int i = 0;
925     int irqval = 0;
926     int ioaddr = dev->base_addr;
927
928     int irqtab[] = SK_IRQS; 
929
930     struct priv *p = (struct priv *)dev->priv;
931
932     PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n", 
933            SK_NAME, SK_read_reg(CSR0)));
934
935     if (dev->irq == 0) /* Autoirq */
936     {
937         i = 0;
938
939         /* 
940          * Check if one IRQ out of SK_IRQS is free and install 
941          * interrupt handler.
942          * Most done by request_irq(). 
943          * irqval: 0       - interrupt handler installed for IRQ irqtab[i]
944          *         -EBUSY  - interrupt busy 
945          *         -EINVAL - irq > 15 or handler = NULL
946          */
947
948         do
949         {
950           irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
951           i++;
952         } while (irqval && irqtab[i]);
953
954         if (irqval) /* We tried every possible IRQ but no success */
955         {
956             printk("%s: unable to get an IRQ\n", dev->name);
957             return -EAGAIN;
958         }
959
960         dev->irq = irqtab[--i]; 
961         
962         outb(i<<2, SK_POS4);           /* Set Card on probed IRQ */
963
964     }
965     else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
966     {
967         if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
968         {
969             printk("%s: unable to get IRQ 9\n", dev->name);
970             return -EAGAIN;
971         } 
972         dev->irq = 9;
973         
974         /* 
975          * Now we set card on IRQ2.
976          * This can be confusing, but remember that IRQ2 on the network
977          * card is in reality IRQ9
978          */
979         outb(0x08, SK_POS4);           /* set card to IRQ2 */
980
981     }
982     else  /* Check IRQ as defined in Space.c */
983     {
984         int i = 0;
985
986         /* check if IRQ free and valid. Then install Interrupt handler */
987
988         if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
989         {
990             printk("%s: unable to get selected IRQ\n", dev->name);
991             return -EAGAIN;
992         }
993
994         switch(dev->irq)
995         {
996             case 3: i = 0;
997                     break;
998             case 5: i = 1;
999                     break;
1000             case 2: i = 2;
1001                     break;
1002             case 11:i = 3;
1003                     break;
1004             default: 
1005                 printk("%s: Preselected IRQ %d is invalid for %s boards",
1006                        dev->name,
1007                        dev->irq,
1008                        SK_NAME);
1009                 return -EAGAIN;
1010         }      
1011   
1012         outb(i<<2, SK_POS4);           /* Set IRQ on card */
1013     }
1014
1015     printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
1016             dev->name, (unsigned int)dev->base_addr, 
1017             (int) dev->irq, (unsigned int) p->ram);
1018
1019     if (!(i = SK_lance_init(dev, 0)))  /* LANCE init OK? */
1020     {
1021         netif_start_queue(dev);
1022
1023 #ifdef SK_DEBUG
1024
1025         /* 
1026          * This debug block tries to stop LANCE,
1027          * reinit LANCE with transmitter and receiver disabled,
1028          * then stop again and reinit with NORMAL_MODE
1029          */
1030
1031         printk("## %s: After lance init. CSR0: %#06x\n", 
1032                SK_NAME, SK_read_reg(CSR0));
1033         SK_write_reg(CSR0, CSR0_STOP);
1034         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
1035                SK_NAME, SK_read_reg(CSR0));
1036         SK_lance_init(dev, MODE_DTX | MODE_DRX);
1037         printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n", 
1038                SK_NAME, SK_read_reg(CSR0));
1039         SK_write_reg(CSR0, CSR0_STOP);
1040         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
1041                SK_NAME, SK_read_reg(CSR0));
1042         SK_lance_init(dev, MODE_NORMAL);
1043         printk("## %s: LANCE back to normal mode. CSR0: %#06x\n", 
1044                SK_NAME, SK_read_reg(CSR0));
1045         SK_print_pos(dev, "POS regs before returning OK");
1046
1047 #endif /* SK_DEBUG */
1048        
1049         return 0;              /* SK_open() is successful */
1050     }
1051     else /* LANCE init failed */
1052     {
1053
1054         PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n", 
1055                SK_NAME, SK_read_reg(CSR0)));
1056
1057         return -EAGAIN;
1058     }
1059
1060 } /* End of SK_open() */
1061
1062 \f
1063 /*-
1064  * Function       : SK_lance_init
1065  * Author         : Patrick J.D. Weichmann
1066  * Date Created   : 94/05/26
1067  *
1068  * Description    : Reset LANCE chip, fill RMD, TMD structures with
1069  *                  start values and Start LANCE.
1070  *
1071  * Parameters     : I : struct net_device *dev - SK_G16 device structure
1072  *                  I : int mode - put LANCE into "mode" see data-sheet for
1073  *                                 more info.
1074  * Return Value   : 0  - Init done
1075  * Errors         : -1 - Init failed
1076  * Update History :
1077  *     YY/MM/DD  uid  Description
1078 -*/
1079
1080 static int SK_lance_init(struct net_device *dev, unsigned short mode)
1081 {
1082     int i;
1083     unsigned long flags;
1084     struct priv *p = (struct priv *) dev->priv; 
1085     struct tmd  *tmdp;
1086     struct rmd  *rmdp;
1087
1088     PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n", 
1089            SK_NAME, SK_read_reg(CSR0)));
1090
1091     /* Reset LANCE */
1092     SK_reset_board();
1093
1094     /* Initialize TMD's with start values */
1095     p->tmdnum = 0;                   /* First descriptor for transmitting */ 
1096     p->tmdlast = 0;                  /* First descriptor for reading stats */
1097
1098     for (i = 0; i < TMDNUM; i++)     /* Init all TMD's */
1099     {
1100         tmdp = p->tmdhead + i; 
1101    
1102         writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
1103         
1104         /* Mark TMD as start and end of packet */
1105         writeb(TX_STP | TX_ENP, &tmdp->u.s.status);
1106     }
1107
1108
1109     /* Initialize RMD's with start values */
1110
1111     p->rmdnum = 0;                   /* First RMD which will be used */
1112  
1113     for (i = 0; i < RMDNUM; i++)     /* Init all RMD's */
1114     {
1115         rmdp = p->rmdhead + i;
1116
1117         
1118         writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
1119         
1120         /* 
1121          * LANCE must be owner at beginning so that he can fill in 
1122          * receiving packets, set status and release RMD 
1123          */
1124
1125         writeb(RX_OWN, &rmdp->u.s.status);
1126
1127         writew(-PKT_BUF_SZ, &rmdp->blen); /* Buffer Size (two's complement) */
1128
1129         writeb(0, &rmdp->mlen);           /* init message length */       
1130         
1131     }
1132
1133     /* Fill LANCE Initialize Block */
1134
1135     writew(mode, (&((p->ram)->ib.mode))); /* Set operation mode */
1136
1137     for (i = 0; i < ETH_ALEN; i++)   /* Set physical address */
1138     {
1139         writeb(dev->dev_addr[i], (&((p->ram)->ib.paddr[i]))); 
1140     }
1141
1142     for (i = 0; i < 8; i++)          /* Set multicast, logical address */
1143     {
1144         writeb(0, (&((p->ram)->ib.laddr[i]))); /* We do not use logical addressing */
1145     } 
1146
1147     /* Set ring descriptor pointers and set number of descriptors */
1148
1149     writel((int)p->rmdhead | RMDNUMMASK, (&((p->ram)->ib.rdrp)));
1150     writel((int)p->tmdhead | TMDNUMMASK, (&((p->ram)->ib.tdrp)));
1151
1152     /* Prepare LANCE Control and Status Registers */
1153
1154     spin_lock_irqsave(&SK_lock, flags);
1155
1156     SK_write_reg(CSR3, CSR3_ACON);   /* Ale Control !!!THIS MUST BE SET!!!! */
1157  
1158     /* 
1159      * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1160      * PC Memory locations.
1161      *
1162      * In structure SK_ram is defined that the first thing in ram
1163      * is the initialization block. So his address is for LANCE always
1164      * 0x0000
1165      *
1166      * CSR1 contains low order bits 15:0 of initialization block address
1167      * CSR2 is built of: 
1168      *    7:0  High order bits 23:16 of initialization block address
1169      *   15:8  reserved, must be 0
1170      */
1171     
1172     /* Set initialization block address (must be on word boundary) */
1173     SK_write_reg(CSR1, 0);          /* Set low order bits 15:0 */
1174     SK_write_reg(CSR2, 0);          /* Set high order bits 23:16 */ 
1175     
1176
1177     PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n", 
1178            SK_NAME, SK_read_reg(CSR0)));
1179
1180     /* Initialize LANCE */
1181
1182     /* 
1183      * INIT = Initialize, when set, causes the LANCE to begin the
1184      * initialization procedure and access the Init Block.
1185      */
1186
1187     SK_write_reg(CSR0, CSR0_INIT); 
1188
1189     spin_unlock_irqrestore(&SK_lock, flags);
1190
1191     /* Wait until LANCE finished initialization */
1192     
1193     SK_set_RAP(CSR0);              /* Register Address Pointer to CSR0 */
1194
1195     for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++) 
1196         ; /* Wait until init done or go ahead if problems (i>=100) */
1197
1198     if (i >= 100) /* Something is wrong ! */
1199     {
1200         printk("%s: can't init am7990, status: %04x "
1201                "init_block: %#08x\n", 
1202                 dev->name, (int) SK_read_reg(CSR0), 
1203                 (unsigned int) &(p->ram)->ib);
1204
1205 #ifdef SK_DEBUG
1206         SK_print_pos(dev, "LANCE INIT failed");
1207         SK_print_dev(dev,"Device Structure:");
1208 #endif
1209
1210         return -1;                 /* LANCE init failed */
1211     }
1212
1213     PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
1214
1215     /* Clear Initialize done, enable Interrupts, start LANCE */
1216
1217     SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
1218
1219     PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME, 
1220             SK_read_reg(CSR0)));
1221
1222     return 0;                      /* LANCE is up and running */
1223
1224 } /* End of SK_lance_init() */
1225
1226
1227 \f
1228 /*-
1229  * Function       : SK_send_packet
1230  * Author         : Patrick J.D. Weichmann
1231  * Date Created   : 94/05/27
1232  *
1233  * Description    : Writes an socket buffer into a transmit descriptor
1234  *                  and starts transmission.
1235  *
1236  * Parameters     : I : struct sk_buff *skb - packet to transfer
1237  *                  I : struct net_device *dev  - SK_G16 device structure
1238  * Return Value   : 0 - OK
1239  *                  1 - Could not transmit (dev_queue_xmit will queue it)
1240  *                      and try to sent it later
1241  * Globals        : None
1242  * Side Effects   : None
1243  * Update History :
1244  *     YY/MM/DD  uid  Description
1245 -*/
1246
1247 static void SK_timeout(struct net_device *dev)
1248 {
1249         printk(KERN_WARNING "%s: xmitter timed out, try to restart!\n", dev->name);
1250         SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
1251         netif_wake_queue(dev);           /* Clear Transmitter flag */
1252         dev->trans_start = jiffies;      /* Mark Start of transmission */
1253 }
1254
1255 static int SK_send_packet(struct sk_buff *skb, struct net_device *dev)
1256 {
1257     struct priv *p = (struct priv *) dev->priv;
1258     struct tmd *tmdp;
1259     static char pad[64];
1260
1261     PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n", 
1262             SK_NAME, SK_read_reg(CSR0)));
1263
1264
1265     /* 
1266      * Block a timer-based transmit from overlapping. 
1267      * This means check if we are already in. 
1268      */
1269
1270     netif_stop_queue (dev);
1271
1272     {
1273
1274         /* Evaluate Packet length */
1275         short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 
1276        
1277         tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1278
1279         /* Fill in Transmit Message Descriptor */
1280
1281         /* Copy data into dual ported ram */
1282
1283         memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
1284         if(len != skb->len)
1285                 memcpy_toio((tmdp->u.buffer & 0x00ffffff) + sb->len, pad, len-skb->len);
1286
1287         writew(-len, &tmdp->blen);            /* set length to transmit */
1288
1289         /* 
1290          * Packet start and end is always set because we use the maximum
1291          * packet length as buffer length.
1292          * Relinquish ownership to LANCE
1293          */
1294
1295         writeb(TX_OWN | TX_STP | TX_ENP, &tmdp->u.s.status);
1296         
1297         /* Start Demand Transmission */
1298         SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1299
1300         dev->trans_start = jiffies;   /* Mark start of transmission */
1301
1302         /* Set pointer to next transmit buffer */
1303         p->tmdnum++; 
1304         p->tmdnum &= TMDNUM-1; 
1305
1306         /* Do we own the next transmit buffer ? */
1307         if (! (readb(&((p->tmdhead + p->tmdnum)->u.s.status)) & TX_OWN) )
1308         {
1309            /* 
1310             * We own next buffer and are ready to transmit, so
1311             * clear busy flag
1312             */
1313            netif_start_queue(dev);
1314         }
1315
1316         p->stats.tx_bytes += skb->len;
1317
1318     }
1319
1320     dev_kfree_skb(skb);
1321     return 0;  
1322 } /* End of SK_send_packet */
1323
1324 \f
1325 /*-
1326  * Function       : SK_interrupt
1327  * Author         : Patrick J.D. Weichmann
1328  * Date Created   : 94/05/27
1329  *
1330  * Description    : SK_G16 interrupt handler which checks for LANCE
1331  *                  Errors, handles transmit and receive interrupts
1332  *
1333  * Parameters     : I : int irq, void *dev_id, struct pt_regs * regs -
1334  * Return Value   : None
1335  * Errors         : None
1336  * Globals        : None
1337  * Side Effects   : None
1338  * Update History :
1339  *     YY/MM/DD  uid  Description
1340 -*/
1341
1342 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1343 {
1344     int csr0;
1345     struct net_device *dev = dev_id;
1346     struct priv *p = (struct priv *) dev->priv;
1347
1348
1349     PRINTK2(("## %s: SK_interrupt(). status: %#06x\n", 
1350             SK_NAME, SK_read_reg(CSR0)));
1351
1352     if (dev == NULL)
1353     {
1354         printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1355     }
1356     
1357     spin_lock (&SK_lock);
1358
1359     csr0 = SK_read_reg(CSR0);      /* store register for checking */
1360
1361     /* 
1362      * Acknowledge all of the current interrupt sources, disable      
1363      * Interrupts (INEA = 0) 
1364      */
1365
1366     SK_write_reg(CSR0, csr0 & CSR0_CLRALL); 
1367
1368     if (csr0 & CSR0_ERR) /* LANCE Error */
1369     {
1370         printk("%s: error: %04x\n", dev->name, csr0);
1371       
1372         if (csr0 & CSR0_MISS)      /* No place to store packet ? */
1373         { 
1374             p->stats.rx_dropped++;
1375         }
1376     }
1377
1378     if (csr0 & CSR0_RINT)          /* Receive Interrupt (packet arrived) */ 
1379     {
1380         SK_rxintr(dev); 
1381     }
1382
1383     if (csr0 & CSR0_TINT)          /* Transmit interrupt (packet sent) */
1384     {
1385         SK_txintr(dev);
1386     }
1387
1388     SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1389
1390     spin_unlock (&SK_lock);
1391 } /* End of SK_interrupt() */ 
1392
1393 \f
1394 /*-
1395  * Function       : SK_txintr
1396  * Author         : Patrick J.D. Weichmann
1397  * Date Created   : 94/05/27
1398  *
1399  * Description    : After sending a packet we check status, update
1400  *                  statistics and relinquish ownership of transmit 
1401  *                  descriptor ring.
1402  *
1403  * Parameters     : I : struct net_device *dev - SK_G16 device structure
1404  * Return Value   : None
1405  * Errors         : None
1406  * Globals        : None
1407  * Update History :
1408  *     YY/MM/DD  uid  Description
1409 -*/
1410
1411 static void SK_txintr(struct net_device *dev)
1412 {
1413     int tmdstat;
1414     struct tmd *tmdp;
1415     struct priv *p = (struct priv *) dev->priv;
1416
1417
1418     PRINTK2(("## %s: SK_txintr() status: %#06x\n", 
1419             SK_NAME, SK_read_reg(CSR0)));
1420
1421     tmdp = p->tmdhead + p->tmdlast;     /* Which buffer we sent at last ? */
1422
1423     /* Set next buffer */
1424     p->tmdlast++;
1425     p->tmdlast &= TMDNUM-1;
1426
1427     tmdstat = readb(&tmdp->u.s.status);
1428
1429     /* 
1430      * We check status of transmitted packet.
1431      * see LANCE data-sheet for error explanation
1432      */
1433     if (tmdstat & TX_ERR) /* Error occurred */
1434     {
1435         int stat2 = readw(&tmdp->status2);
1436
1437         printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
1438
1439         if (stat2 & TX_TDR)    /* TDR problems? */
1440         {
1441             printk("%s: tdr-problems \n", dev->name);
1442         }
1443
1444         if (stat2 & TX_RTRY)   /* Failed in 16 attempts to transmit ? */
1445             p->stats.tx_aborted_errors++;   
1446         if (stat2 & TX_LCOL)   /* Late collision ? */
1447             p->stats.tx_window_errors++; 
1448         if (stat2 & TX_LCAR)   /* Loss of Carrier ? */  
1449             p->stats.tx_carrier_errors++;
1450         if (stat2 & TX_UFLO)   /* Underflow error ? */
1451         {
1452             p->stats.tx_fifo_errors++;
1453
1454             /* 
1455              * If UFLO error occurs it will turn transmitter of.
1456              * So we must reinit LANCE
1457              */
1458
1459             SK_lance_init(dev, MODE_NORMAL);
1460         }
1461         
1462         p->stats.tx_errors++;
1463
1464         writew(0, &tmdp->status2);             /* Clear error flags */
1465     }
1466     else if (tmdstat & TX_MORE)        /* Collisions occurred ? */
1467     {
1468         /* 
1469          * Here I have a problem.
1470          * I only know that there must be one or up to 15 collisions.
1471          * That's why TX_MORE is set, because after 16 attempts TX_RTRY
1472          * will be set which means couldn't send packet aborted transfer.
1473          *
1474          * First I did not have this in but then I thought at minimum
1475          * we see that something was not ok.
1476          * If anyone knows something better than this to handle this
1477          * please report it.
1478          */ 
1479
1480         p->stats.collisions++; 
1481     }
1482     else   /* Packet sent without any problems */
1483     {
1484         p->stats.tx_packets++; 
1485     }
1486
1487     /* 
1488      * We mark transmitter not busy anymore, because now we have a free
1489      * transmit descriptor which can be filled by SK_send_packet and
1490      * afterwards sent by the LANCE
1491      * 
1492      * The function which do handle slow IRQ parts is do_bottom_half()
1493      * which runs at normal kernel priority, that means all interrupt are
1494      * enabled. (see kernel/irq.c)
1495      *  
1496      * net_bh does something like this:
1497      *  - check if already in net_bh
1498      *  - try to transmit something from the send queue
1499      *  - if something is in the receive queue send it up to higher 
1500      *    levels if it is a known protocol
1501      *  - try to transmit something from the send queue
1502      */
1503
1504     netif_wake_queue(dev);
1505
1506 } /* End of SK_txintr() */
1507
1508 \f
1509 /*-
1510  * Function       : SK_rxintr
1511  * Author         : Patrick J.D. Weichmann
1512  * Date Created   : 94/05/27
1513  *
1514  * Description    : Buffer sent, check for errors, relinquish ownership
1515  *                  of the receive message descriptor. 
1516  *
1517  * Parameters     : I : SK_G16 device structure
1518  * Return Value   : None
1519  * Globals        : None
1520  * Update History :
1521  *     YY/MM/DD  uid  Description
1522 -*/
1523
1524 static void SK_rxintr(struct net_device *dev)
1525 {
1526
1527     struct rmd *rmdp;
1528     int rmdstat;
1529     struct priv *p = (struct priv *) dev->priv;
1530
1531     PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n", 
1532             SK_NAME, SK_read_reg(CSR0)));
1533
1534     rmdp = p->rmdhead + p->rmdnum;
1535
1536     /* As long as we own the next entry, check status and send
1537      * it up to higher layer 
1538      */
1539
1540     while (!( (rmdstat = readb(&rmdp->u.s.status)) & RX_OWN))
1541     {
1542         /* 
1543          * Start and end of packet must be set, because we use 
1544          * the ethernet maximum packet length (1518) as buffer size.
1545          * 
1546          * Because our buffers are at maximum OFLO and BUFF errors are
1547          * not to be concerned (see Data sheet)
1548          */
1549
1550         if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
1551         {
1552             /* Start of a frame > 1518 Bytes ? */
1553
1554             if (rmdstat & RX_STP) 
1555             {
1556                 p->stats.rx_errors++;        /* bad packet received */
1557                 p->stats.rx_length_errors++; /* packet too long */
1558
1559                 printk("%s: packet too long\n", dev->name);
1560             }
1561             
1562             /* 
1563              * All other packets will be ignored until a new frame with
1564              * start (RX_STP) set follows.
1565              * 
1566              * What we do is just give descriptor free for new incoming
1567              * packets. 
1568              */
1569
1570             writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */ 
1571
1572         }
1573         else if (rmdstat & RX_ERR)          /* Receive Error ? */
1574         {
1575             printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1576             
1577             p->stats.rx_errors++;
1578
1579             if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1580             if (rmdstat & RX_CRC)  p->stats.rx_crc_errors++;
1581
1582             writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1583
1584         }
1585         else /* We have a packet which can be queued for the upper layers */
1586         {
1587
1588             int len = readw(&rmdp->mlen) & 0x0fff;  /* extract message length from receive buffer */
1589             struct sk_buff *skb;
1590
1591             skb = dev_alloc_skb(len+2); /* allocate socket buffer */ 
1592
1593             if (skb == NULL)                /* Could not get mem ? */
1594             {
1595     
1596                 /* 
1597                  * Couldn't allocate sk_buffer so we give descriptor back
1598                  * to Lance, update statistics and go ahead.
1599                  */
1600
1601                 writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
1602                 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1603                        dev->name);
1604                 p->stats.rx_dropped++;
1605
1606                 break;                      /* Jump out */
1607             }
1608             
1609             /* Prepare sk_buff to queue for upper layers */
1610
1611             skb->dev = dev;
1612             skb_reserve(skb,2);         /* Align IP header on 16 byte boundary */
1613             
1614             /* 
1615              * Copy data out of our receive descriptor into sk_buff.
1616              *
1617              * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and 
1618              * ignore status fields) 
1619              */
1620
1621             memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
1622
1623
1624             /* 
1625              * Notify the upper protocol layers that there is another packet
1626              * to handle
1627              *
1628              * netif_rx() always succeeds. see /net/inet/dev.c for more.
1629              */
1630
1631             skb->protocol=eth_type_trans(skb,dev);
1632             netif_rx(skb);                 /* queue packet and mark it for processing */
1633            
1634             /* 
1635              * Packet is queued and marked for processing so we
1636              * free our descriptor and update statistics 
1637              */
1638
1639             writeb(RX_OWN, &rmdp->u.s.status);
1640             dev->last_rx = jiffies;
1641             p->stats.rx_packets++;
1642             p->stats.rx_bytes += len;
1643
1644
1645             p->rmdnum++;
1646             p->rmdnum %= RMDNUM;
1647
1648             rmdp = p->rmdhead + p->rmdnum;
1649         }
1650     }
1651 } /* End of SK_rxintr() */
1652
1653 \f
1654 /*-
1655  * Function       : SK_close
1656  * Author         : Patrick J.D. Weichmann
1657  * Date Created   : 94/05/26
1658  *
1659  * Description    : close gets called from dev_close() and should
1660  *                  deinstall the card (free_irq, mem etc).
1661  *
1662  * Parameters     : I : struct net_device *dev - our device structure
1663  * Return Value   : 0 - closed device driver
1664  * Errors         : None
1665  * Globals        : None
1666  * Update History :
1667  *     YY/MM/DD  uid  Description
1668 -*/
1669
1670 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1671  * down' the system stops. So I don't shut set card to init state.
1672  */
1673
1674 static int SK_close(struct net_device *dev)
1675 {
1676
1677     PRINTK(("## %s: SK_close(). CSR0: %#06x\n", 
1678            SK_NAME, SK_read_reg(CSR0)));
1679
1680     netif_stop_queue(dev);         /* Transmitter busy */
1681
1682     printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME, 
1683            (int) SK_read_reg(CSR0));
1684
1685     SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1686
1687     free_irq(dev->irq, dev);      /* Free IRQ */
1688
1689     return 0; /* always succeed */
1690     
1691 } /* End of SK_close() */
1692
1693 \f
1694 /*-
1695  * Function       : SK_get_stats
1696  * Author         : Patrick J.D. Weichmann
1697  * Date Created   : 94/05/26
1698  *
1699  * Description    : Return current status structure to upper layers.
1700  *                  It is called by sprintf_stats (dev.c).
1701  *
1702  * Parameters     : I : struct net_device *dev   - our device structure
1703  * Return Value   : struct net_device_stats * - our current statistics
1704  * Errors         : None
1705  * Side Effects   : None
1706  * Update History :
1707  *     YY/MM/DD  uid  Description
1708 -*/
1709
1710 static struct net_device_stats *SK_get_stats(struct net_device *dev)
1711 {
1712
1713     struct priv *p = (struct priv *) dev->priv;
1714
1715     PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n", 
1716            SK_NAME, SK_read_reg(CSR0)));
1717
1718     return &p->stats;             /* Return Device status */
1719
1720 } /* End of SK_get_stats() */
1721
1722 \f
1723 /*-
1724  * Function       : set_multicast_list
1725  * Author         : Patrick J.D. Weichmann
1726  * Date Created   : 94/05/26
1727  *
1728  * Description    : This function gets called when a program performs
1729  *                  a SIOCSIFFLAGS call. Ifconfig does this if you call
1730  *                  'ifconfig [-]allmulti' which enables or disables the
1731  *                  Promiscuous mode.
1732  *                  Promiscuous mode is when the Network card accepts all
1733  *                  packets, not only the packets which match our MAC 
1734  *                  Address. It is useful for writing a network monitor,
1735  *                  but it is also a security problem. You have to remember
1736  *                  that all information on the net is not encrypted.
1737  *
1738  * Parameters     : I : struct net_device *dev - SK_G16 device Structure
1739  * Return Value   : None
1740  * Errors         : None
1741  * Globals        : None
1742  * Update History :
1743  *     YY/MM/DD  uid  Description
1744  *     95/10/18  ACox  New multicast calling scheme
1745 -*/
1746
1747
1748 /* Set or clear the multicast filter for SK_G16.
1749  */
1750
1751 static void set_multicast_list(struct net_device *dev)
1752 {
1753
1754     if (dev->flags&IFF_PROMISC)
1755     {
1756         /* Reinitialize LANCE with MODE_PROM set */
1757         SK_lance_init(dev, MODE_PROM);
1758     }
1759     else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
1760     {
1761         /* Reinitialize LANCE without MODE_PROM */
1762         SK_lance_init(dev, MODE_NORMAL);
1763     }
1764     else
1765     {
1766         /* Multicast with logical address filter on */
1767         /* Reinitialize LANCE without MODE_PROM */
1768         SK_lance_init(dev, MODE_NORMAL);
1769         
1770         /* Not implemented yet. */
1771     }
1772 } /* End of set_multicast_list() */
1773
1774
1775 \f
1776 /*-
1777  * Function       : SK_rom_addr
1778  * Author         : Patrick J.D. Weichmann
1779  * Date Created   : 94/06/01
1780  *
1781  * Description    : Try to find a Boot_ROM at all possible locations
1782  *
1783  * Parameters     : None
1784  * Return Value   : Address where Boot_ROM is
1785  * Errors         : 0 - Did not find Boot_ROM
1786  * Globals        : None
1787  * Update History :
1788  *     YY/MM/DD  uid  Description
1789 -*/
1790
1791 unsigned int __init SK_rom_addr(void)
1792 {
1793     int i,j;
1794     int rom_found = 0;
1795     unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1796     unsigned char rom_id[] = SK_BOOT_ROM_ID;
1797     unsigned char test_byte;
1798
1799     /* Autodetect Boot_ROM */
1800     PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1801
1802     for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1803     {
1804         
1805         PRINTK(("##   Trying ROM location %#08x", rom_location[i]));
1806         
1807         rom_found = 1; 
1808         for (j = 0; j < 6; j++)
1809         {
1810             test_byte = readb(rom_location[i]+j);
1811             PRINTK((" %02x ", *test_byte));
1812
1813             if(test_byte != rom_id[j])
1814             {
1815                 rom_found = 0;
1816             } 
1817         }
1818         PRINTK(("\n"));
1819     }
1820
1821     if (rom_found == 1)
1822     {
1823         PRINTK(("## %s: Boot_ROM found at %#08x\n", 
1824                SK_NAME, rom_location[(i-1)]));
1825
1826         return (rom_location[--i]);
1827     }
1828     else
1829     {
1830         PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1831         return 0;
1832     }
1833 } /* End of SK_rom_addr() */
1834
1835
1836 \f
1837 /* LANCE access functions 
1838  *
1839  * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1840  */
1841
1842
1843 /*-
1844  * Function       : SK_reset_board
1845  *
1846  * Author         : Patrick J.D. Weichmann
1847  *
1848  * Date Created   : 94/05/25
1849  *
1850  * Description    : This function resets SK_G16 and all components, but
1851  *                  POS registers are not changed
1852  *
1853  * Parameters     : None
1854  * Return Value   : None
1855  * Errors         : None
1856  * Globals        : SK_RAM *board - SK_RAM structure pointer
1857  *
1858  * Update History :
1859  *     YY/MM/DD  uid  Description
1860 -*/
1861
1862 void SK_reset_board(void)
1863 {
1864     writeb(0x00, SK_PORT);       /* Reset active */
1865     mdelay(5);                /* Delay min 5ms */
1866     writeb(SK_RESET, SK_PORT);   /* Set back to normal operation */
1867
1868 } /* End of SK_reset_board() */
1869
1870 \f
1871 /*-
1872  * Function       : SK_set_RAP
1873  * Author         : Patrick J.D. Weichmann
1874  * Date Created   : 94/05/25
1875  *
1876  * Description    : Set LANCE Register Address Port to register
1877  *                  for later data transfer.
1878  *
1879  * Parameters     : I : reg_number - which CSR to read/write from/to
1880  * Return Value   : None
1881  * Errors         : None
1882  * Globals        : SK_RAM *board - SK_RAM structure pointer
1883  * Update History :
1884  *     YY/MM/DD  uid  Description
1885 -*/
1886
1887 void SK_set_RAP(int reg_number)
1888 {
1889     writew(reg_number, SK_IOREG);
1890     writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
1891     writeb(SK_DOIO, SK_IOCOM);
1892
1893     while (readb(SK_PORT) & SK_IORUN) 
1894         barrier();
1895 } /* End of SK_set_RAP() */
1896
1897 \f
1898 /*-
1899  * Function       : SK_read_reg
1900  * Author         : Patrick J.D. Weichmann
1901  * Date Created   : 94/05/25
1902  *
1903  * Description    : Set RAP and read data from a LANCE CSR register
1904  *
1905  * Parameters     : I : reg_number - which CSR to read from
1906  * Return Value   : Register contents
1907  * Errors         : None
1908  * Globals        : SK_RAM *board - SK_RAM structure pointer
1909  * Update History :
1910  *     YY/MM/DD  uid  Description
1911 -*/
1912
1913 int SK_read_reg(int reg_number)
1914 {
1915     SK_set_RAP(reg_number);
1916
1917     writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1918     writeb(SK_DOIO, SK_IOCOM);
1919
1920     while (readb(SK_PORT) & SK_IORUN)
1921         barrier();
1922     return (readw(SK_IOREG));
1923
1924 } /* End of SK_read_reg() */
1925
1926 \f
1927 /*-
1928  * Function       : SK_rread_reg
1929  * Author         : Patrick J.D. Weichmann
1930  * Date Created   : 94/05/28
1931  *
1932  * Description    : Read data from preseted register.
1933  *                  This function requires that you know which
1934  *                  Register is actually set. Be aware that CSR1-3
1935  *                  can only be accessed when in CSR0 STOP is set.
1936  *
1937  * Return Value   : Register contents
1938  * Errors         : None
1939  * Globals        : SK_RAM *board - SK_RAM structure pointer
1940  * Update History :
1941  *     YY/MM/DD  uid  Description
1942 -*/
1943
1944 int SK_rread_reg(void)
1945 {
1946     writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
1947
1948     writeb(SK_DOIO, SK_IOCOM);
1949
1950     while (readb(SK_PORT) & SK_IORUN)
1951         barrier();
1952     return (readw(SK_IOREG));
1953
1954 } /* End of SK_rread_reg() */
1955
1956 \f
1957 /*-
1958  * Function       : SK_write_reg
1959  * Author         : Patrick J.D. Weichmann
1960  * Date Created   : 94/05/25
1961  *
1962  * Description    : This function sets the RAP then fills in the
1963  *                  LANCE I/O Reg and starts Transfer to LANCE.
1964  *                  It waits until transfer has ended which is max. 7 ms
1965  *                  and then it returns.
1966  *
1967  * Parameters     : I : reg_number - which CSR to write to
1968  *                  I : value      - what value to fill into register 
1969  * Return Value   : None
1970  * Errors         : None
1971  * Globals        : SK_RAM *board - SK_RAM structure pointer
1972  * Update History :
1973  *     YY/MM/DD  uid  Description
1974 -*/
1975
1976 void SK_write_reg(int reg_number, int value)
1977 {
1978     SK_set_RAP(reg_number);
1979
1980     writew(value, SK_IOREG);
1981     writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
1982     writeb(SK_DOIO, SK_IOCOM);
1983
1984     while (readb(SK_PORT) & SK_IORUN)
1985         barrier();
1986 } /* End of SK_write_reg */
1987
1988 \f
1989
1990 /* 
1991  * Debugging functions
1992  * -------------------
1993  */
1994
1995 /*-
1996  * Function       : SK_print_pos
1997  * Author         : Patrick J.D. Weichmann
1998  * Date Created   : 94/05/25
1999  *
2000  * Description    : This function prints out the 4 POS (Programmable
2001  *                  Option Select) Registers. Used mainly to debug operation.
2002  *
2003  * Parameters     : I : struct net_device *dev - SK_G16 device structure
2004  *                  I : char * - Text which will be printed as title
2005  * Return Value   : None
2006  * Errors         : None
2007  * Update History :
2008  *     YY/MM/DD  uid  Description
2009 -*/
2010
2011 void SK_print_pos(struct net_device *dev, char *text)
2012 {
2013     int ioaddr = dev->base_addr;
2014
2015     unsigned char pos0 = inb(SK_POS0),
2016                   pos1 = inb(SK_POS1),
2017                   pos2 = inb(SK_POS2),
2018                   pos3 = inb(SK_POS3),
2019                   pos4 = inb(SK_POS4);
2020
2021
2022     printk("## %s: %s.\n"
2023            "##   pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
2024            SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
2025
2026 } /* End of SK_print_pos() */
2027
2028
2029 \f
2030 /*-
2031  * Function       : SK_print_dev
2032  * Author         : Patrick J.D. Weichmann
2033  * Date Created   : 94/05/25
2034  *
2035  * Description    : This function simply prints out the important fields
2036  *                  of the device structure.
2037  *
2038  * Parameters     : I : struct net_device *dev  - SK_G16 device structure
2039  *                  I : char *text - Title for printing
2040  * Return Value   : None
2041  * Errors         : None
2042  * Update History :
2043  *     YY/MM/DD  uid  Description
2044 -*/
2045
2046 void SK_print_dev(struct net_device *dev, char *text)
2047 {
2048     if (dev == NULL)
2049     {
2050         printk("## %s: Device Structure. %s\n", SK_NAME, text);
2051         printk("## DEVICE == NULL\n");
2052     }
2053     else
2054     {
2055         printk("## %s: Device Structure. %s\n", SK_NAME, text);
2056         printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n", 
2057                dev->name, dev->base_addr, dev->irq);
2058                
2059         printk("## next device: %#08x init function: %#08x\n", 
2060               (int) dev->next, (int) dev->init);
2061     }
2062
2063 } /* End of SK_print_dev() */
2064
2065
2066 \f
2067 /*-
2068  * Function       : SK_print_ram
2069  * Author         : Patrick J.D. Weichmann
2070  * Date Created   : 94/06/02
2071  *
2072  * Description    : This function is used to check how are things set up
2073  *                  in the 16KB RAM. Also the pointers to the receive and 
2074  *                  transmit descriptor rings and rx and tx buffers locations.
2075  *                  It contains a minor bug in printing, but has no effect to the values
2076  *                  only newlines are not correct.
2077  *
2078  * Parameters     : I : struct net_device *dev - SK_G16 device structure
2079  * Return Value   : None
2080  * Errors         : None
2081  * Globals        : None
2082  * Update History :
2083  *     YY/MM/DD  uid  Description
2084 -*/
2085
2086 void __init SK_print_ram(struct net_device *dev)
2087 {
2088
2089     int i;    
2090     struct priv *p = (struct priv *) dev->priv;
2091
2092     printk("## %s: RAM Details.\n"
2093            "##   RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2094            SK_NAME, 
2095            (unsigned int) p->ram,
2096            (unsigned int) p->tmdhead, 
2097            (unsigned int) p->rmdhead, 
2098            (unsigned int) &(p->ram)->ib);
2099            
2100     printk("##   ");
2101
2102     for(i = 0; i < TMDNUM; i++)
2103     {
2104            if (!(i % 3)) /* Every third line do a newline */
2105            {
2106                printk("\n##   ");
2107            }
2108         printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2109     }
2110     printk("##   ");
2111
2112     for(i = 0; i < RMDNUM; i++)
2113     {
2114          if (!(i % 3)) /* Every third line do a newline */
2115            {
2116                printk("\n##   ");
2117            }
2118         printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2119     } 
2120     printk("\n");
2121
2122 } /* End of SK_print_ram() */
2123