]> git.sur5r.net Git - u-boot/blob - drivers/sk98lin/skge.c
* Add support for USB Mass Storage Devices (BBB)
[u-boot] / drivers / sk98lin / skge.c
1 /******************************************************************************
2  *
3  * Name:    skge.c
4  * Project:     GEnesis, PCI Gigabit Ethernet Adapter
5  * Version:     $Revision: 1.46 $
6  * Date:        $Date: 2003/02/25 14:16:36 $
7  * Purpose:     The main driver source module
8  *
9  ******************************************************************************/
10  
11 /******************************************************************************
12  *
13  *      (C)Copyright 1998-2003 SysKonnect GmbH.
14  *
15  *      Driver for SysKonnect Gigabit Ethernet Server Adapters:
16  *
17  *      SK-9871 (single link 1000Base-ZX)
18  *      SK-9872 (dual link   1000Base-ZX)
19  *      SK-9861 (single link 1000Base-SX, VF45 Volition Plug)
20  *      SK-9862 (dual link   1000Base-SX, VF45 Volition Plug)
21  *      SK-9841 (single link 1000Base-LX)
22  *      SK-9842 (dual link   1000Base-LX)
23  *      SK-9843 (single link 1000Base-SX)
24  *      SK-9844 (dual link   1000Base-SX)
25  *      SK-9821 (single link 1000Base-T)
26  *      SK-9822 (dual link   1000Base-T)
27  *      SK-9881 (single link 1000Base-SX V2 LC)
28  *      SK-9871 (single link 1000Base-ZX V2)
29  *      SK-9861 (single link 1000Base-SX V2, VF45 Volition Plug)
30  *      SK-9841 (single link 1000Base-LX V2)
31  *      SK-9843 (single link 1000Base-SX V2)
32  *      SK-9821 (single link 1000Base-T V2)
33  *
34  *      Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and 
35  *      SysKonnects GEnesis Solaris driver
36  *      Author: Christoph Goos (cgoos@syskonnect.de)
37  *              Mirko Lindner (mlindner@syskonnect.de)
38  *
39  *      Address all question to: linux@syskonnect.de
40  *
41  *      The technical manual for the adapters is available from SysKonnect's
42  *      web pages: www.syskonnect.com
43  *      Goto "Support" and search Knowledge Base for "manual".
44  *      
45  *      This program is free software; you can redistribute it and/or modify
46  *      it under the terms of the GNU General Public License as published by
47  *      the Free Software Foundation; either version 2 of the License, or
48  *      (at your option) any later version.
49  *
50  *      The information in this file is provided "AS IS" without warranty.
51  *
52  ******************************************************************************/
53
54 /******************************************************************************
55  *
56  * History:
57  *
58  *      $Log: skge.c,v $
59  *      Revision 1.46  2003/02/25 14:16:36  mlindner
60  *      Fix: Copyright statement
61  *      
62  *      Revision 1.45  2003/02/25 13:25:55  mlindner
63  *      Add: Performance improvements
64  *      Add: Support for various vendors
65  *      Fix: Init function
66  *      
67  *      Revision 1.44  2003/01/09 09:25:26  mlindner
68  *      Fix: Remove useless init_module/cleanup_module forward declarations
69  *      
70  *      Revision 1.43  2002/11/29 08:42:41  mlindner
71  *      Fix: Boot message
72  *      
73  *      Revision 1.42  2002/11/28 13:30:23  mlindner
74  *      Add: New frame check
75  *      
76  *      Revision 1.41  2002/11/27 13:55:18  mlindner
77  *      Fix: Drop wrong csum packets
78  *      Fix: Initialize proc_entry after hw check
79  *      
80  *      Revision 1.40  2002/10/31 07:50:37  tschilli
81  *      Function SkGeInitAssignRamToQueues() from common module inserted.
82  *      Autonegotiation is set to ON for all adapters.
83  *      LinkSpeedUsed is used in link up status report.
84  *      Role parameter will show up for 1000 Mbps links only.
85  *      GetConfiguration() inserted after init level 1 in SkGeChangeMtu().
86  *      All return values of SkGeInit() and SkGeInitPort() are checked.
87  *      
88  *      Revision 1.39  2002/10/02 12:56:05  mlindner
89  *      Add: Support for Yukon
90  *      Add: Support for ZEROCOPY, scatter-gather and hw checksum
91  *      Add: New transmit ring function (use SG and TCP/UDP hardware checksumming)
92  *      Add: New init function
93  *      Add: Speed check and setup
94  *      Add: Merge source for kernel 2.2.x and 2.4.x
95  *      Add: Opcode check for tcp
96  *      Add: Frame length check
97  *      Fix: Transmit complete interrupt
98  *      Fix: Interrupt moderation
99  *      
100  *      Revision 1.29.2.13  2002/01/14 12:44:52  mlindner
101  *      Fix: Rlmt modes
102  *      
103  *      Revision 1.29.2.12  2001/12/07 12:06:18  mlindner
104  *      Fix: malloc -> slab changes
105  *      
106  *      Revision 1.29.2.11  2001/12/06 15:19:20  mlindner
107  *      Add: DMA attributes
108  *      Fix: Module initialisation
109  *      Fix: pci_map_single and pci_unmap_single replaced
110  *      
111  *      Revision 1.29.2.10  2001/12/06 09:56:50  mlindner
112  *      Corrected some printk's
113  *      
114  *      Revision 1.29.2.9  2001/09/05 12:15:34  mlindner
115  *      Add: LBFO Changes
116  *      Fix: Counter Errors (Jumbo == to long errors)
117  *      Fix: Changed pAC->PciDev declaration
118  *      Fix: too short counters
119  *      
120  *      Revision 1.29.2.8  2001/06/25 12:10:44  mlindner
121  *      fix: ReceiveIrq() changed.
122  *      
123  *      Revision 1.29.2.7  2001/06/25 08:07:05  mlindner
124  *      fix: RLMT locking in ReceiveIrq() changed.
125  *      
126  *      Revision 1.29.2.6  2001/05/21 07:59:29  mlindner
127  *      fix: MTU init problems
128  *      
129  *      Revision 1.29.2.5  2001/05/08 11:25:08  mlindner
130  *      fix: removed VLAN error message
131  *      
132  *      Revision 1.29.2.4  2001/05/04 13:31:43  gklug
133  *      fix: do not handle eth_copy on bad fragments received.
134  *      
135  *      Revision 1.29.2.3  2001/04/23 08:06:43  mlindner
136  *      Fix: error handling
137  *      
138  *      Revision 1.29.2.2  2001/03/15 12:04:54  mlindner
139  *      Fixed memory problem
140  *      
141  *      Revision 1.29.2.1  2001/03/12 16:41:44  mlindner
142  *      add: procfs function
143  *      add: dual-net function
144  *      add: RLMT networks
145  *      add: extended PNMI features
146  *      
147  *      Kernel 2.4.x specific:
148  *      Revision 1.xx  2000/09/12 13:31:56  cgoos
149  *      Fixed missign "dev=NULL in skge_probe.
150  *      Added counting for jumbo frames (corrects error statistic).
151  *      Removed VLAN tag check (enables VLAN support).
152  *      
153  *      Kernel 2.2.x specific:
154  *      Revision 1.29  2000/02/21 13:31:56  cgoos
155  *      Fixed "unused" warning for UltraSPARC change.
156  *      
157  *      Partially kernel 2.2.x specific:
158  *      Revision 1.28  2000/02/21 10:32:36  cgoos
159  *      Added fixes for UltraSPARC.
160  *      Now printing RlmtMode and PrefPort setting at startup.
161  *      Changed XmitFrame return value.
162  *      Fixed rx checksum calculation for BIG ENDIAN systems.
163  *      Fixed rx jumbo frames counted as ierrors.
164  *      
165  *      
166  *      Revision 1.27  1999/11/25 09:06:28  cgoos
167  *      Changed base_addr to unsigned long.
168  *      
169  *      Revision 1.26  1999/11/22 13:29:16  cgoos
170  *      Changed license header to GPL.
171  *      Changes for inclusion in linux kernel (2.2.13).
172  *      Removed 2.0.x defines.
173  *      Changed SkGeProbe to skge_probe.
174  *      Added checks in SkGeIoctl.
175  *      
176  *      Revision 1.25  1999/10/07 14:47:52  cgoos
177  *      Changed 984x to 98xx.
178  *      
179  *      Revision 1.24  1999/09/30 07:21:01  cgoos
180  *      Removed SK_RLMT_SLOW_LOOKAHEAD option.
181  *      Giving spanning tree packets also to OS now.
182  *      
183  *      Revision 1.23  1999/09/29 07:36:50  cgoos
184  *      Changed assignment for IsBc/IsMc.
185  *      
186  *      Revision 1.22  1999/09/28 12:57:09  cgoos
187  *      Added CheckQueue also to Single-Port-ISR.
188  *      
189  *      Revision 1.21  1999/09/28 12:42:41  cgoos
190  *      Changed parameter strings for RlmtMode.
191  *      
192  *      Revision 1.20  1999/09/28 12:37:57  cgoos
193  *      Added CheckQueue for fast delivery of RLMT frames.
194  *      
195  *      Revision 1.19  1999/09/16 07:57:25  cgoos
196  *      Copperfield changes.
197  *      
198  *      Revision 1.18  1999/09/03 13:06:30  cgoos
199  *      Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused
200  *      double allocated skb's.
201  *      FrameStat in ReceiveIrq was accessed via wrong Rxd.
202  *      Queue size for async. standby Tx queue was zero.
203  *      FillRxLimit of 0 could cause problems with ReQueue, changed to 1.
204  *      Removed debug output of checksum statistic.
205  *      
206  *      Revision 1.17  1999/08/11 13:55:27  cgoos
207  *      Transmit descriptor polling was not reenabled after SkGePortInit.
208  *      
209  *      Revision 1.16  1999/07/27 15:17:29  cgoos
210  *      Added some "\n" in output strings (removed while debuging...).
211  *      
212  *      Revision 1.15  1999/07/23 12:09:30  cgoos
213  *      Performance optimization, rx checksumming, large frame support.
214  *      
215  *      Revision 1.14  1999/07/14 11:26:27  cgoos
216  *      Removed Link LED settings (now in RLMT).
217  *      Added status output at NET UP.
218  *      Fixed SMP problems with Tx and SWITCH running in parallel.
219  *      Fixed return code problem at RLMT_SEND event.
220  *      
221  *      Revision 1.13  1999/04/07 10:11:42  cgoos
222  *      Fixed Single Port problems.
223  *      Fixed Multi-Adapter problems.
224  *      Always display startup string.
225  *      
226  *      Revision 1.12  1999/03/29 12:26:37  cgoos
227  *      Reversed locking to fine granularity.
228  *      Fixed skb double alloc problem (caused by incorrect xmit return code).
229  *      Enhanced function descriptions.
230  *      
231  *      Revision 1.11  1999/03/15 13:10:51  cgoos
232  *      Changed device identifier in output string to ethX.
233  *      
234  *      Revision 1.10  1999/03/15 12:12:34  cgoos
235  *      Changed copyright notice.
236  *      
237  *      Revision 1.9  1999/03/15 12:10:17  cgoos
238  *      Changed locking to one driver lock.
239  *      Added check of SK_AC-size (for consistency with library).
240  *      
241  *      Revision 1.8  1999/03/08 11:44:02  cgoos
242  *      Fixed missing dev->tbusy in SkGeXmit.
243  *      Changed large frame (jumbo) buffer number.
244  *      Added copying of short frames.
245  *      
246  *      Revision 1.7  1999/03/04 13:26:57  cgoos
247  *      Fixed spinlock calls for SMP.
248  *      
249  *      Revision 1.6  1999/03/02 09:53:51  cgoos
250  *      Added descriptor revertion for big endian machines.
251  *      
252  *      Revision 1.5  1999/03/01 08:50:59  cgoos
253  *      Fixed SkGeChangeMtu.
254  *      Fixed pci config space accesses.
255  *      
256  *      Revision 1.4  1999/02/18 15:48:44  cgoos
257  *      Corrected some printk's.
258  *      
259  *      Revision 1.3  1999/02/18 12:45:55  cgoos
260  *      Changed SK_MAX_CARD_PARAM to default 16
261  *      
262  *      Revision 1.2  1999/02/18 10:55:32  cgoos
263  *      Removed SkGeDrvTimeStamp function.
264  *      Printing "ethX:" before adapter type at adapter init.
265  *      
266  *
267  *      10-Feb-1999 cg  Created, based on Linux' acenic.c, 3c59x.c and 
268  *                      SysKonnects GEnesis Solaris driver
269  *
270  ******************************************************************************/
271
272 /******************************************************************************
273  *
274  * Possible compiler options (#define xxx / -Dxxx):
275  *
276  *      debugging can be enable by changing SK_DEBUG_CHKMOD and 
277  *      SK_DEBUG_CHKCAT in makefile (described there).
278  *
279  ******************************************************************************/
280  
281 /******************************************************************************
282  *
283  * Description:
284  *
285  *      This is the main module of the Linux GE driver.
286  *      
287  *      All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
288  *      are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
289  *      Those are used for drivers on multiple OS', so some thing may seem
290  *      unnecessary complicated on Linux. Please do not try to 'clean up'
291  *      them without VERY good reasons, because this will make it more
292  *      difficult to keep the Linux driver in synchronisation with the
293  *      other versions.
294  *
295  * Include file hierarchy:
296  *
297  *      <linux/module.h>
298  *
299  *      "h/skdrv1st.h"
300  *              <linux/version.h>
301  *              <linux/types.h>
302  *              <linux/kernel.h>
303  *              <linux/string.h>
304  *              <linux/errno.h>
305  *              <linux/ioport.h>
306  *              <linux/slab.h>
307  *              <linux/interrupt.h>
308  *              <linux/pci.h>
309  *              <asm/byteorder.h>
310  *              <asm/bitops.h>
311  *              <asm/io.h>
312  *              <linux/netdevice.h>
313  *              <linux/etherdevice.h>
314  *              <linux/skbuff.h>
315  *          those three depending on kernel version used:
316  *              <linux/bios32.h>
317  *              <linux/init.h>
318  *              <asm/uaccess.h>
319  *              <net/checksum.h>
320  *
321  *              "h/skerror.h"
322  *              "h/skdebug.h"
323  *              "h/sktypes.h"
324  *              "h/lm80.h"
325  *              "h/xmac_ii.h"
326  *
327  *      "h/skdrv2nd.h"
328  *              "h/skqueue.h"
329  *              "h/skgehwt.h"
330  *              "h/sktimer.h"
331  *              "h/ski2c.h"
332  *              "h/skgepnmi.h"
333  *              "h/skvpd.h"
334  *              "h/skgehw.h"
335  *              "h/skgeinit.h"
336  *              "h/skaddr.h"
337  *              "h/skgesirq.h"
338  *              "h/skcsum.h"
339  *              "h/skrlmt.h"
340  *
341  ******************************************************************************/
342
343 #include <config.h>
344
345 #ifdef CONFIG_SK98
346
347 #include        "h/skversion.h"
348 #if 0
349 #include        <linux/module.h>
350 #include        <linux/init.h>
351 #include        <linux/proc_fs.h>
352 #endif
353 #include        "h/skdrv1st.h"
354 #include        "h/skdrv2nd.h"
355
356
357 /* defines ******************************************************************/
358 /* for debuging on x86 only */
359 /* #define BREAKPOINT() asm(" int $3"); */
360
361 /* use the scatter-gather functionality with sendfile() */
362 #if 0
363 #define SK_ZEROCOPY
364 #endif
365
366 /* use of a transmit complete interrupt */
367 #define USE_TX_COMPLETE
368
369 /* use interrupt moderation (for tx complete only) */
370 #define USE_INT_MOD
371 #define INTS_PER_SEC    1000
372
373 /*
374  * threshold for copying small receive frames
375  * set to 0 to avoid copying, set to 9001 to copy all frames
376  */
377 #define SK_COPY_THRESHOLD       50
378
379 /* number of adapters that can be configured via command line params */
380 #define SK_MAX_CARD_PARAM       16
381
382
383 /*
384  * use those defines for a compile-in version of the driver instead 
385  * of command line parameters
386  */
387 // #define LINK_SPEED_A {"Auto", }
388 // #define LINK_SPEED_B {"Auto", }
389 // #define AUTO_NEG_A   {"Sense", }
390 // #define AUTO_NEG_B   {"Sense", }
391 // #define DUP_CAP_A    {"Both", }
392 // #define DUP_CAP_B    {"Both", }
393 // #define FLOW_CTRL_A  {"SymOrRem", }
394 // #define FLOW_CTRL_B  {"SymOrRem", }
395 // #define ROLE_A       {"Auto", }
396 // #define ROLE_B       {"Auto", }
397 // #define PREF_PORT    {"A", }
398 // #define RLMT_MODE    {"CheckLinkState", }
399
400 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
401 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
402 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
403
404 /* function prototypes ******************************************************/
405 static void     FreeResources(struct SK_NET_DEVICE *dev);
406 static int      SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
407 static SK_BOOL  BoardAllocMem(SK_AC *pAC);
408 static void     BoardFreeMem(SK_AC *pAC);
409 static void     BoardInitMem(SK_AC *pAC);
410 static void     SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**,
411                         int*, SK_BOOL);
412
413 #if 0
414 static void     SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
415 static void     SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
416 static int      SkGeOpen(struct SK_NET_DEVICE *dev);
417 static int      SkGeClose(struct SK_NET_DEVICE *dev);
418 static int      SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
419 static int      SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
420 static void     SkGeSetRxMode(struct SK_NET_DEVICE *dev);
421 static struct   net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
422 static int      SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
423 #else
424 void    SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
425 void    SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
426 int     SkGeOpen(struct SK_NET_DEVICE *dev);
427 int     SkGeClose(struct SK_NET_DEVICE *dev);
428 int     SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
429 #endif
430 static void     GetConfiguration(SK_AC*);
431 static void     ProductStr(SK_AC*);
432 static int      XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
433 static void     FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
434 static void     FillRxRing(SK_AC*, RX_PORT*);
435 static SK_BOOL  FillRxDescriptor(SK_AC*, RX_PORT*);
436 #if 0
437 static void     ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
438 #else
439 void    ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
440 #endif
441 static void ClearAndStartRx(SK_AC*, int);
442 static void     ClearTxIrq(SK_AC*, int, int);
443 static void     ClearRxRing(SK_AC*, RX_PORT*);
444 static void     ClearTxRing(SK_AC*, TX_PORT*);
445 #if 0
446 static void     SetQueueSizes(SK_AC     *pAC);
447
448 static int      SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
449 #endif
450 static void     PortReInitBmu(SK_AC*, int);
451 #if 0
452 static int      SkGeIocMib(DEV_NET*, unsigned int, int);
453 static int      XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
454 #endif
455
456 /*Extern */
457
458 /* external Proc function */
459 extern int proc_read(
460         char    *buffer,
461         char    **buffer_location,
462         off_t   offset,
463         int             buffer_length,
464         int             *eof,
465         void    *data);
466
467 #ifdef DEBUG
468 static void     DumpMsg(struct sk_buff*, char*);
469 static void     DumpData(char*, int);
470 static void     DumpLong(char*, int);
471 #endif
472 void dump_frag( SK_U8 *data, int length);
473
474 /* global variables *********************************************************/
475 #if 0
476 static const char *BootString = BOOT_STRING;
477 #endif
478 struct SK_NET_DEVICE *SkGeRootDev = NULL;
479 static int probed __initdata = 0;
480
481 /* local variables **********************************************************/
482 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
483 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
484
485
486 /* local variables **********************************************************/
487 const char SK_Root_Dir_entry[8];
488
489 #if 0
490 static struct proc_dir_entry    *pSkRootDir;
491 #endif
492
493
494 static struct pci_device_id supported[] = {
495         {PCI_VENDOR_ID_3COM, 0x1700},
496         {PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE},
497         {PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE_SA},
498         {}
499 };
500
501
502 /*****************************************************************************
503  *
504  *      skge_probe - find all SK-98xx adapters
505  *
506  * Description:
507  *      This function scans the PCI bus for SK-98xx adapters. Resources for
508  *      each adapter are allocated and the adapter is brought into Init 1
509  *      state.
510  *
511  * Returns:
512  *      0, if everything is ok
513  *      !=0, on error
514  */
515 #if 0
516 static int __init skge_probe (void)
517 #else
518 int skge_probe (struct eth_device ** ret_dev)
519 #endif
520 {
521 #if 0
522         int                     proc_root_initialized = 0;
523 #endif
524         int                     boards_found = 0;
525 #if 0
526         int                     vendor_flag = SK_FALSE;
527 #endif
528         SK_AC                   *pAC;
529         DEV_NET                 *pNet = NULL;
530 #if 0
531         struct proc_dir_entry   *pProcFile;
532         struct pci_dev  *pdev = NULL;
533         unsigned long           base_address;
534 #else
535         u32                     base_address;
536 #endif
537         struct SK_NET_DEVICE *dev = NULL;
538 #if 0
539         SK_BOOL DeviceFound = SK_FALSE;
540 #endif
541         SK_BOOL BootStringCount = SK_FALSE;
542 #if 1
543         pci_dev_t devno;
544 #endif
545
546         if (probed)
547                 return -ENODEV;
548         probed++;
549
550         if (!pci_present())             /* is PCI support present? */
551                 return -ENODEV;
552
553 #if 0
554                 while((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev)))
555 #else
556                 while((devno = pci_find_devices (supported, boards_found)) >= 0)
557 #endif
558                 {
559
560                 dev = NULL;
561                 pNet = NULL;
562
563
564 #if 0
565                 SK_PCI_ISCOMPLIANT(vendor_flag, pdev);
566                 if (!vendor_flag)
567                         continue;
568 #endif
569
570 /*              if ((pdev->vendor != PCI_VENDOR_ID_SYSKONNECT) && 
571                         ((pdev->device != PCI_DEVICE_ID_SYSKONNECT_GE) || 
572                         (pdev->device != PCI_DEVICE_ID_SYSKONNECT_YU))){
573                         continue;
574                 }
575 */
576 #if 0
577                 /* Configure DMA attributes. */
578                 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&
579                         pci_set_dma_mask(pdev, (u64) 0xffffffff))
580                         continue;
581 #endif
582
583
584 #if 0
585                 if ((dev = init_etherdev(dev, sizeof(DEV_NET))) == NULL) {
586                         printk(KERN_ERR "Unable to allocate etherdev "
587                                "structure!\n");
588                         break;
589                 }
590 #else
591                 dev = malloc (sizeof *dev);
592                 memset(dev, 0, sizeof(*dev));
593                 dev->priv = malloc(sizeof(DEV_NET));
594 #endif
595
596                 if (dev->priv == NULL) {
597                         printk(KERN_ERR "Unable to allocate adapter "
598                                "structure!\n");
599                         break;
600                 }
601
602                 pNet = dev->priv;
603                 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
604                 if (pNet->pAC == NULL){
605                         kfree(dev->priv);
606                         printk(KERN_ERR "Unable to allocate adapter "
607                                "structure!\n");
608                         break;
609                 }
610
611                 /* Print message */
612                 if (!BootStringCount) {
613                         /* set display flag to TRUE so that */
614                         /* we only display this string ONCE */
615                         BootStringCount = SK_TRUE;
616 #ifdef SK98_INFO
617                         printk("%s\n", BootString);
618 #endif
619                 }
620
621                 memset(pNet->pAC, 0, sizeof(SK_AC));
622                 pAC = pNet->pAC;
623 #if 0
624                 pAC->PciDev = pdev;
625                 pAC->PciDevId = pdev->device;
626                 pAC->dev[0] = dev;
627                 pAC->dev[1] = dev;
628 #else
629                 pAC->PciDev = devno;
630                 ret_dev[0] = pAC->dev[0] = dev;
631                 ret_dev[1] = pAC->dev[1] = dev;
632 #endif
633                 sprintf(pAC->Name, "SysKonnect SK-98xx");
634                 pAC->CheckQueue = SK_FALSE;
635
636                 pNet->Mtu = 1500;
637                 pNet->Up = 0;
638 #if 0
639                 dev->irq = pdev->irq;
640
641                 dev->open =             &SkGeOpen;
642                 dev->stop =             &SkGeClose;
643                 dev->hard_start_xmit =  &SkGeXmit;
644                 dev->get_stats =        &SkGeStats;
645                 dev->set_multicast_list = &SkGeSetRxMode;
646                 dev->set_mac_address =  &SkGeSetMacAddr;
647                 dev->do_ioctl =         &SkGeIoctl;
648                 dev->change_mtu =       &SkGeChangeMtu;
649                 dev->flags &=           ~IFF_RUNNING;
650 #endif
651
652 #ifdef SK_ZEROCOPY
653                 if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
654                         /* Use only if yukon hardware */
655                         /* SK and ZEROCOPY - fly baby... */
656                         dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
657                 }
658 #endif
659
660 #if 0
661                 /*
662                  * Dummy value.
663                  */
664                 dev->base_addr = 42;
665                 pci_set_master(pdev);
666
667                 pci_set_master(pdev);
668                 base_address = pci_resource_start (pdev, 0);
669 #else
670                 pci_write_config_dword(devno,
671                                        PCI_COMMAND,
672                                        PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
673                 pci_read_config_dword (devno, PCI_BASE_ADDRESS_0,
674                                        &base_address);
675 #endif
676
677 #ifdef SK_BIG_ENDIAN
678                 /*
679                  * On big endian machines, we use the adapter's aibility of
680                  * reading the descriptors as big endian.
681                  */
682                 {
683                 SK_U32          our2;
684                         SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
685                         our2 |= PCI_REV_DESC;
686                         SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
687                 }
688 #endif
689
690                 /*
691                  * Remap the regs into kernel space.
692                  */
693 #if 0
694                 pAC->IoBase = (char*)ioremap(base_address, 0x4000);
695 #else
696                 pAC->IoBase = (char*)pci_mem_to_phys(devno, base_address);
697 #endif
698
699                 if (!pAC->IoBase){
700                         printk(KERN_ERR "%s:  Unable to map I/O register, "
701                                "SK 98xx No. %i will be disabled.\n",
702                                dev->name, boards_found);
703                         kfree(dev);
704                         break;
705                 }
706
707                 pAC->Index = boards_found;
708                 if (SkGeBoardInit(dev, pAC)) {
709                         FreeResources(dev);
710                         kfree(dev);
711                         continue;
712                 }
713
714 #if 0
715                 memcpy((caddr_t) &dev->dev_addr,
716                         (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
717 #else
718                 memcpy((caddr_t) &dev->enetaddr,
719                         (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
720 #endif
721
722 #if 0
723                 /* First adapter... Create proc and print message */
724                 if (!DeviceFound) {
725                         DeviceFound = SK_TRUE;
726                         SK_MEMCPY(&SK_Root_Dir_entry, BootString,
727                                 sizeof(SK_Root_Dir_entry) - 1);
728
729                         /*Create proc (directory)*/
730                         if(!proc_root_initialized) {
731                                 pSkRootDir = create_proc_entry(SK_Root_Dir_entry,
732                                         S_IFDIR | S_IWUSR | S_IRUGO | S_IXUGO, proc_net);
733                                 proc_root_initialized = 1;
734                         }
735
736                         pSkRootDir->owner = THIS_MODULE;
737                 }
738
739
740
741                 /* Create proc file */
742                 pProcFile = create_proc_entry(dev->name,
743                         S_IFREG | S_IXUSR | S_IWGRP | S_IROTH,
744                         pSkRootDir);
745
746                 
747                 pProcFile->read_proc = proc_read;
748                 pProcFile->write_proc = NULL;
749                 pProcFile->nlink = 1;
750                 pProcFile->size = sizeof(dev->name + 1);
751                 pProcFile->data = (void *)pProcFile;
752 #endif
753
754                 pNet->PortNr = 0;
755                 pNet->NetNr = 0;
756
757 #ifdef SK_ZEROCOPY
758                         if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
759                                 /* SG and ZEROCOPY - fly baby... */
760                                 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
761                         }
762 #endif
763
764                 boards_found++;
765
766                 /* More then one port found */
767                 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
768 #if 0
769                         if ((dev = init_etherdev(NULL, sizeof(DEV_NET))) == 0) {
770                                 printk(KERN_ERR "Unable to allocate etherdev "
771                                         "structure!\n");
772                                 break;
773                         }
774 #else
775                         dev = malloc (sizeof *dev);
776                         memset(dev, 0, sizeof(*dev));
777                         dev->priv = malloc(sizeof(DEV_NET));
778 #endif
779
780                         pAC->dev[1] = dev;
781                         pNet = dev->priv;
782                         pNet->PortNr = 1;
783                         pNet->NetNr = 1;
784                         pNet->pAC = pAC;
785                         pNet->Mtu = 1500;
786                         pNet->Up = 0;
787
788 #if 0
789                         dev->open =             &SkGeOpen;
790                         dev->stop =             &SkGeClose;
791                         dev->hard_start_xmit =  &SkGeXmit;
792                         dev->get_stats =        &SkGeStats;
793                         dev->set_multicast_list = &SkGeSetRxMode;
794                         dev->set_mac_address =  &SkGeSetMacAddr;
795                         dev->do_ioctl =         &SkGeIoctl;
796                         dev->change_mtu =       &SkGeChangeMtu;
797                         dev->flags &=           ~IFF_RUNNING;
798 #endif
799
800 #ifdef SK_ZEROCOPY
801                         if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
802                                 /* SG and ZEROCOPY - fly baby... */
803                                 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
804                         }
805 #endif
806
807 #if 0
808                         pProcFile = create_proc_entry(dev->name,
809                                 S_IFREG | S_IXUSR | S_IWGRP | S_IROTH,
810                                 pSkRootDir);
811
812                 
813                         pProcFile->read_proc = proc_read;
814                         pProcFile->write_proc = NULL;
815                         pProcFile->nlink = 1;
816                         pProcFile->size = sizeof(dev->name + 1);
817                         pProcFile->data = (void *)pProcFile;
818 #endif
819
820 #if 0
821                         memcpy((caddr_t) &dev->dev_addr,
822                         (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
823 #else
824                         memcpy((caddr_t) &dev->enetaddr,
825                         (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
826 #endif
827         
828                         printk("%s: %s\n", dev->name, pAC->DeviceStr);
829                         printk("      PrefPort:B  RlmtMode:Dual Check Link State\n");
830
831                 }
832
833
834                 /* Save the hardware revision */
835                 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
836                         (pAC->GIni.GIPciHwRev & 0x0F);
837
838                 /*
839                  * This is bollocks, but we need to tell the net-init
840                  * code that it shall go for the next device.
841                  */
842 #if 0
843 #ifndef MODULE
844                 dev->base_addr = 0;
845 #endif
846 #endif
847         }
848
849         /*
850          * If we're at this point we're going through skge_probe() for
851          * the first time.  Return success (0) if we've initialized 1
852          * or more boards. Otherwise, return failure (-ENODEV).
853          */
854
855         return boards_found;
856 } /* skge_probe */
857
858
859 /*****************************************************************************
860  *
861  *      FreeResources - release resources allocated for adapter
862  *
863  * Description:
864  *      This function releases the IRQ, unmaps the IO and
865  *      frees the desriptor ring.
866  *
867  * Returns: N/A
868  *      
869  */
870 static void FreeResources(struct SK_NET_DEVICE *dev)
871 {
872 SK_U32 AllocFlag;
873 DEV_NET         *pNet;
874 SK_AC           *pAC;
875
876         if (dev->priv) {
877                 pNet = (DEV_NET*) dev->priv;
878                 pAC = pNet->pAC;
879                 AllocFlag = pAC->AllocFlag;
880 #if 0
881                 if (AllocFlag & SK_ALLOC_IRQ) {
882                         free_irq(dev->irq, dev);
883                 }
884                 if (pAC->IoBase) {
885                         iounmap(pAC->IoBase);
886                 }
887 #endif
888                 if (pAC->pDescrMem) {
889                         BoardFreeMem(pAC);
890                 }
891         }
892         
893 } /* FreeResources */
894
895 #if 0
896 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
897 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
898 MODULE_LICENSE("GPL");
899 MODULE_PARM(Speed_A,    "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
900 MODULE_PARM(Speed_B,    "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
901 MODULE_PARM(AutoNeg_A,  "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
902 MODULE_PARM(AutoNeg_B,  "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
903 MODULE_PARM(DupCap_A,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
904 MODULE_PARM(DupCap_B,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
905 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
906 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
907 MODULE_PARM(Role_A,         "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
908 MODULE_PARM(Role_B,         "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
909 MODULE_PARM(PrefPort,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
910 MODULE_PARM(RlmtMode,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
911 /* not used, just there because every driver should have them: */
912 MODULE_PARM(options,    "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
913 MODULE_PARM(debug,      "i");
914 #endif
915
916
917 #ifdef LINK_SPEED_A
918 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED_A;
919 #else
920 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
921 #endif
922
923 #ifdef LINK_SPEED_B
924 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED_B;
925 #else
926 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
927 #endif
928
929 #ifdef AUTO_NEG_A
930 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
931 #else
932 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
933 #endif
934
935 #ifdef DUP_CAP_A
936 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
937 #else
938 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
939 #endif
940
941 #ifdef FLOW_CTRL_A
942 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
943 #else
944 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
945 #endif
946
947 #ifdef ROLE_A
948 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
949 #else
950 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
951 #endif
952
953 #ifdef AUTO_NEG_B
954 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
955 #else
956 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
957 #endif
958
959 #ifdef DUP_CAP_B
960 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
961 #else
962 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
963 #endif
964
965 #ifdef FLOW_CTRL_B
966 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
967 #else
968 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
969 #endif
970
971 #ifdef ROLE_B
972 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
973 #else
974 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
975 #endif
976
977 #ifdef PREF_PORT
978 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
979 #else
980 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
981 #endif
982
983 #ifdef RLMT_MODE
984 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
985 #else
986 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
987 #endif
988
989 #if 0
990 static int debug = 0; /* not used */
991 static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
992
993
994 /*****************************************************************************
995  *
996  *      skge_init_module - module initialization function
997  *
998  * Description:
999  *      Very simple, only call skge_probe and return approriate result.
1000  *
1001  * Returns:
1002  *      0, if everything is ok
1003  *      !=0, on error
1004  */
1005 static int __init skge_init_module(void)
1006 {
1007         int cards;
1008         SkGeRootDev = NULL;
1009         
1010         /* just to avoid warnings ... */
1011         debug = 0;
1012         options[0] = 0;
1013
1014         cards = skge_probe();
1015         if (cards == 0) {
1016                 printk("sk98lin: No adapter found.\n");
1017         }
1018         return cards ? 0 : -ENODEV;
1019 } /* skge_init_module */
1020
1021
1022 /*****************************************************************************
1023  *
1024  *      skge_cleanup_module - module unload function
1025  *
1026  * Description:
1027  *      Disable adapter if it is still running, free resources,
1028  *      free device struct.
1029  *
1030  * Returns: N/A
1031  */
1032 static void __exit skge_cleanup_module(void)
1033 {
1034 DEV_NET         *pNet;
1035 SK_AC           *pAC;
1036 struct SK_NET_DEVICE *next;
1037 unsigned long Flags;
1038 SK_EVPARA EvPara;
1039
1040         while (SkGeRootDev) {
1041                 pNet = (DEV_NET*) SkGeRootDev->priv;
1042                 pAC = pNet->pAC;
1043                 next = pAC->Next;
1044
1045                 netif_stop_queue(SkGeRootDev);
1046                 SkGeYellowLED(pAC, pAC->IoBase, 0);
1047
1048                 if(pAC->BoardLevel == 2) {
1049                         /* board is still alive */
1050                         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1051                         EvPara.Para32[0] = 0;
1052                         EvPara.Para32[1] = -1;
1053                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1054                         EvPara.Para32[0] = 1;
1055                         EvPara.Para32[1] = -1;
1056                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1057                         SkEventDispatcher(pAC, pAC->IoBase);
1058                         /* disable interrupts */
1059                         SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1060                         SkGeDeInit(pAC, pAC->IoBase); 
1061                         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1062                         pAC->BoardLevel = 0;
1063                         /* We do NOT check here, if IRQ was pending, of course*/
1064                 }
1065
1066                 if(pAC->BoardLevel == 1) {
1067                         /* board is still alive */
1068                         SkGeDeInit(pAC, pAC->IoBase); 
1069                         pAC->BoardLevel = 0;
1070                 }
1071
1072                 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
1073                         unregister_netdev(pAC->dev[1]);
1074                         kfree(pAC->dev[1]);
1075                 }
1076
1077                 FreeResources(SkGeRootDev);
1078
1079                 SkGeRootDev->get_stats = NULL;
1080                 /* 
1081                  * otherwise unregister_netdev calls get_stats with
1082                  * invalid IO ...  :-(
1083                  */
1084                 unregister_netdev(SkGeRootDev);
1085                 kfree(SkGeRootDev);
1086                 kfree(pAC);
1087                 SkGeRootDev = next;
1088         }
1089
1090         /* clear proc-dir */
1091         remove_proc_entry(pSkRootDir->name, proc_net);
1092
1093 } /* skge_cleanup_module */
1094
1095 module_init(skge_init_module);
1096 module_exit(skge_cleanup_module);
1097 #endif
1098
1099
1100 /*****************************************************************************
1101  *
1102  *      SkGeBoardInit - do level 0 and 1 initialization
1103  *
1104  * Description:
1105  *      This function prepares the board hardware for running. The desriptor
1106  *      ring is set up, the IRQ is allocated and the configuration settings
1107  *      are examined.
1108  *
1109  * Returns:
1110  *      0, if everything is ok
1111  *      !=0, on error
1112  */
1113 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
1114 {
1115 short   i;
1116 unsigned long Flags;
1117 char    *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
1118 char    *VerStr = VER_STRING;
1119 #if 0
1120 int     Ret;                    /* return code of request_irq */
1121 #endif
1122 SK_BOOL DualNet;
1123
1124         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1125                 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
1126         for (i=0; i<SK_MAX_MACS; i++) {
1127                 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
1128                 pAC->TxPort[i][0].PortIndex = i;
1129                 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
1130                 pAC->RxPort[i].PortIndex = i;
1131         }
1132
1133         /* Initialize the mutexes */
1134         for (i=0; i<SK_MAX_MACS; i++) {
1135                 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
1136                 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
1137         }
1138         spin_lock_init(&pAC->SlowPathLock);
1139
1140         /* level 0 init common modules here */
1141         
1142         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1143         /* Does a RESET on board ...*/
1144         if (SkGeInit(pAC, pAC->IoBase, 0) != 0) {
1145                 printk("HWInit (0) failed.\n");
1146                 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1147                 return(-EAGAIN);
1148         }
1149         SkI2cInit(  pAC, pAC->IoBase, 0);
1150         SkEventInit(pAC, pAC->IoBase, 0);
1151         SkPnmiInit( pAC, pAC->IoBase, 0);
1152         SkAddrInit( pAC, pAC->IoBase, 0);
1153         SkRlmtInit( pAC, pAC->IoBase, 0);
1154         SkTimerInit(pAC, pAC->IoBase, 0);
1155         
1156         pAC->BoardLevel = 0;
1157         pAC->RxBufSize = ETH_BUF_SIZE;
1158
1159         SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
1160         SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
1161
1162         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1163
1164         /* level 1 init common modules here (HW init) */
1165         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1166         if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
1167                 printk("HWInit (1) failed.\n");
1168                 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1169                 return(-EAGAIN);
1170         }
1171         SkI2cInit(  pAC, pAC->IoBase, 1);
1172         SkEventInit(pAC, pAC->IoBase, 1);
1173         SkPnmiInit( pAC, pAC->IoBase, 1);
1174         SkAddrInit( pAC, pAC->IoBase, 1);
1175         SkRlmtInit( pAC, pAC->IoBase, 1);
1176         SkTimerInit(pAC, pAC->IoBase, 1);
1177
1178         GetConfiguration(pAC);
1179         if (pAC->RlmtNets == 2) {
1180                 pAC->GIni.GIPortUsage = SK_MUL_LINK;
1181         }
1182
1183         pAC->BoardLevel = 1;
1184         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1185
1186 #if 0
1187         if (pAC->GIni.GIMacsFound == 2) {
1188                  Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
1189         } else if (pAC->GIni.GIMacsFound == 1) {
1190                 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
1191                         pAC->Name, dev);
1192         } else {
1193                 printk(KERN_WARNING "%s: Illegal number of ports: %d\n",
1194                        dev->name, pAC->GIni.GIMacsFound);
1195                 return -EAGAIN;
1196         }
1197
1198         if (Ret) {
1199                 printk(KERN_WARNING "%s: Requested IRQ %d is busy.\n",
1200                        dev->name, dev->irq);
1201                 return -EAGAIN;
1202         }
1203 #endif
1204         pAC->AllocFlag |= SK_ALLOC_IRQ;
1205
1206         /* Alloc memory for this board (Mem for RxD/TxD) : */
1207         if(!BoardAllocMem(pAC)) {
1208                 printk("No memory for descriptor rings.\n");
1209                 return(-EAGAIN);
1210         }
1211
1212         SkCsSetReceiveFlags(pAC,
1213                 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
1214                 &pAC->CsOfs1, &pAC->CsOfs2, 0);
1215         pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
1216
1217         BoardInitMem(pAC);
1218 #if 0
1219         SetQueueSizes(pAC);
1220 #else
1221         /* tschilling: New common function with minimum size check. */
1222         DualNet = SK_FALSE;
1223         if (pAC->RlmtNets == 2) {
1224                 DualNet = SK_TRUE;
1225         }
1226         
1227         if (SkGeInitAssignRamToQueues(
1228                 pAC,
1229                 pAC->ActivePort,
1230                 DualNet)) {
1231                 BoardFreeMem(pAC);
1232                 printk("SkGeInitAssignRamToQueues failed.\n");
1233                 return(-EAGAIN);
1234         }
1235 #endif
1236
1237         /* Print adapter specific string from vpd */
1238         ProductStr(pAC);
1239 #ifdef SK98_INFO
1240         printk("%s: %s\n", dev->name, pAC->DeviceStr);
1241
1242         /* Print configuration settings */
1243         printk("      PrefPort:%c  RlmtMode:%s\n",
1244                 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
1245                 (pAC->RlmtMode==0)  ? "Check Link State" :
1246                 ((pAC->RlmtMode==1) ? "Check Link State" : 
1247                 ((pAC->RlmtMode==3) ? "Check Local Port" : 
1248                 ((pAC->RlmtMode==7) ? "Check Segmentation" : 
1249                 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
1250 #endif
1251
1252         SkGeYellowLED(pAC, pAC->IoBase, 1);
1253
1254         /*
1255          * Register the device here
1256          */
1257         pAC->Next = SkGeRootDev;
1258         SkGeRootDev = dev;
1259
1260         return (0);
1261 } /* SkGeBoardInit */
1262
1263
1264 /*****************************************************************************
1265  *
1266  *      BoardAllocMem - allocate the memory for the descriptor rings
1267  *
1268  * Description:
1269  *      This function allocates the memory for all descriptor rings.
1270  *      Each ring is aligned for the desriptor alignment and no ring
1271  *      has a 4 GByte boundary in it (because the upper 32 bit must
1272  *      be constant for all descriptiors in one rings).
1273  *
1274  * Returns:
1275  *      SK_TRUE, if all memory could be allocated
1276  *      SK_FALSE, if not
1277  */
1278 static SK_BOOL BoardAllocMem(
1279 SK_AC   *pAC)
1280 {
1281 caddr_t         pDescrMem;      /* pointer to descriptor memory area */
1282 size_t          AllocLength;    /* length of complete descriptor area */
1283 int             i;              /* loop counter */
1284 unsigned long   BusAddr;
1285
1286         
1287         /* rings plus one for alignment (do not cross 4 GB boundary) */
1288         /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
1289 #if (BITS_PER_LONG == 32)
1290         AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1291 #else
1292         AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1293                 + RX_RING_SIZE + 8;
1294 #endif
1295
1296         pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
1297                                          &pAC->pDescrMemDMA);
1298
1299         if (pDescrMem == NULL) {
1300                 return (SK_FALSE);
1301         }
1302         pAC->pDescrMem = pDescrMem;
1303         BusAddr = (unsigned long) pAC->pDescrMemDMA;
1304
1305         /* Descriptors need 8 byte alignment, and this is ensured
1306          * by pci_alloc_consistent.
1307          */
1308         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1309                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1310                         ("TX%d/A: pDescrMem: %lX,   PhysDescrMem: %lX\n",
1311                         i, (unsigned long) pDescrMem,
1312                         BusAddr));
1313                 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
1314                 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
1315                 pDescrMem += TX_RING_SIZE;
1316                 BusAddr += TX_RING_SIZE;
1317         
1318                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1319                         ("RX%d: pDescrMem: %lX,   PhysDescrMem: %lX\n",
1320                         i, (unsigned long) pDescrMem,
1321                         (unsigned long)BusAddr));
1322                 pAC->RxPort[i].pRxDescrRing = pDescrMem;
1323                 pAC->RxPort[i].VRxDescrRing = BusAddr;
1324                 pDescrMem += RX_RING_SIZE;
1325                 BusAddr += RX_RING_SIZE;
1326         } /* for */
1327         
1328         return (SK_TRUE);
1329 } /* BoardAllocMem */
1330
1331
1332 /****************************************************************************
1333  *
1334  *      BoardFreeMem - reverse of BoardAllocMem
1335  *
1336  * Description:
1337  *      Free all memory allocated in BoardAllocMem: adapter context,
1338  *      descriptor rings, locks.
1339  *
1340  * Returns:     N/A
1341  */
1342 static void BoardFreeMem(
1343 SK_AC           *pAC)
1344 {
1345 size_t          AllocLength;    /* length of complete descriptor area */
1346
1347         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1348                 ("BoardFreeMem\n"));
1349 #if (BITS_PER_LONG == 32)
1350         AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1351 #else
1352         AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1353                 + RX_RING_SIZE + 8;
1354 #endif
1355
1356         pci_free_consistent(pAC->PciDev, AllocLength,
1357                             pAC->pDescrMem, pAC->pDescrMemDMA);
1358         pAC->pDescrMem = NULL;
1359 } /* BoardFreeMem */
1360
1361
1362 /*****************************************************************************
1363  *
1364  *      BoardInitMem - initiate the descriptor rings
1365  *
1366  * Description:
1367  *      This function sets the descriptor rings up in memory.
1368  *      The adapter is initialized with the descriptor start addresses.
1369  *
1370  * Returns:     N/A
1371  */
1372 static void BoardInitMem(
1373 SK_AC   *pAC)   /* pointer to adapter context */
1374 {
1375 int     i;              /* loop counter */
1376 int     RxDescrSize;    /* the size of a rx descriptor rounded up to alignment*/
1377 int     TxDescrSize;    /* the size of a tx descriptor rounded up to alignment*/
1378
1379         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1380                 ("BoardInitMem\n"));
1381
1382         RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1383         pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
1384         TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1385         pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
1386         
1387         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1388                 SetupRing(
1389                         pAC,
1390                         pAC->TxPort[i][0].pTxDescrRing,
1391                         pAC->TxPort[i][0].VTxDescrRing,
1392                         (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
1393                         (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
1394                         (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
1395                         &pAC->TxPort[i][0].TxdRingFree,
1396                         SK_TRUE);
1397                 SetupRing(
1398                         pAC,
1399                         pAC->RxPort[i].pRxDescrRing,
1400                         pAC->RxPort[i].VRxDescrRing,
1401                         &pAC->RxPort[i].pRxdRingHead,
1402                         &pAC->RxPort[i].pRxdRingTail,
1403                         &pAC->RxPort[i].pRxdRingPrev,
1404                         &pAC->RxPort[i].RxdRingFree,
1405                         SK_FALSE);
1406         }
1407 } /* BoardInitMem */
1408
1409
1410 /*****************************************************************************
1411  *
1412  *      SetupRing - create one descriptor ring
1413  *
1414  * Description:
1415  *      This function creates one descriptor ring in the given memory area.
1416  *      The head, tail and number of free descriptors in the ring are set.
1417  *
1418  * Returns:
1419  *      none
1420  */
1421 static void SetupRing(
1422 SK_AC           *pAC,
1423 void            *pMemArea,      /* a pointer to the memory area for the ring */
1424 uintptr_t       VMemArea,       /* the virtual bus address of the memory area */
1425 RXD             **ppRingHead,   /* address where the head should be written */
1426 RXD             **ppRingTail,   /* address where the tail should be written */
1427 RXD             **ppRingPrev,   /* address where the tail should be written */
1428 int             *pRingFree,     /* address where the # of free descr. goes */
1429 SK_BOOL         IsTx)           /* flag: is this a tx ring */
1430 {
1431 int     i;              /* loop counter */
1432 int     DescrSize;      /* the size of a descriptor rounded up to alignment*/
1433 int     DescrNum;       /* number of descriptors per ring */
1434 RXD     *pDescr;        /* pointer to a descriptor (receive or transmit) */
1435 RXD     *pNextDescr;    /* pointer to the next descriptor */
1436 RXD     *pPrevDescr;    /* pointer to the previous descriptor */
1437 uintptr_t VNextDescr;   /* the virtual bus address of the next descriptor */
1438
1439         if (IsTx == SK_TRUE) {
1440                 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
1441                         DESCR_ALIGN;
1442                 DescrNum = TX_RING_SIZE / DescrSize;
1443         } else {
1444                 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1445                         DESCR_ALIGN;
1446                 DescrNum = RX_RING_SIZE / DescrSize;
1447         }
1448         
1449         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1450                 ("Descriptor size: %d   Descriptor Number: %d\n",
1451                 DescrSize,DescrNum));
1452         
1453         pDescr = (RXD*) pMemArea;
1454         pPrevDescr = NULL;
1455         pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1456         VNextDescr = VMemArea + DescrSize;
1457         for(i=0; i<DescrNum; i++) {
1458                 /* set the pointers right */
1459                 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1460                 pDescr->pNextRxd = pNextDescr;
1461                 pDescr->TcpSumStarts = pAC->CsOfs;
1462
1463                 /* advance one step */
1464                 pPrevDescr = pDescr;
1465                 pDescr = pNextDescr;
1466                 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1467                 VNextDescr += DescrSize;
1468         }
1469         pPrevDescr->pNextRxd = (RXD*) pMemArea;
1470         pPrevDescr->VNextRxd = VMemArea;
1471         pDescr = (RXD*) pMemArea;
1472         *ppRingHead = (RXD*) pMemArea;
1473         *ppRingTail = *ppRingHead;
1474         *ppRingPrev = pPrevDescr;
1475         *pRingFree = DescrNum;
1476 } /* SetupRing */
1477
1478
1479 /*****************************************************************************
1480  *
1481  *      PortReInitBmu - re-initiate the descriptor rings for one port
1482  *
1483  * Description:
1484  *      This function reinitializes the descriptor rings of one port
1485  *      in memory. The port must be stopped before.
1486  *      The HW is initialized with the descriptor start addresses.
1487  *
1488  * Returns:
1489  *      none
1490  */
1491 static void PortReInitBmu(
1492 SK_AC   *pAC,           /* pointer to adapter context */
1493 int     PortIndex)      /* index of the port for which to re-init */
1494 {
1495         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1496                 ("PortReInitBmu "));
1497
1498         /* set address of first descriptor of ring in BMU */
1499         SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1500                 TX_Q_CUR_DESCR_LOW,
1501                 (uint32_t)(((caddr_t)
1502                 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1503                 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1504                 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1505                 0xFFFFFFFF));
1506         SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1507                 TX_Q_DESCR_HIGH,
1508                 (uint32_t)(((caddr_t)
1509                 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1510                 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1511                 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1512         SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CUR_DESCR_LOW,
1513                 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1514                 pAC->RxPort[PortIndex].pRxDescrRing +
1515                 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1516         SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_DESCR_HIGH,
1517                 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1518                 pAC->RxPort[PortIndex].pRxDescrRing +
1519                 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1520 } /* PortReInitBmu */
1521
1522
1523 /****************************************************************************
1524  *
1525  *      SkGeIsr - handle adapter interrupts
1526  *
1527  * Description:
1528  *      The interrupt routine is called when the network adapter
1529  *      generates an interrupt. It may also be called if another device
1530  *      shares this interrupt vector with the driver.
1531  *
1532  * Returns: N/A
1533  *
1534  */
1535 #if 0
1536 static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1537 #else
1538 void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1539 #endif
1540 {
1541 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1542 DEV_NET         *pNet;
1543 SK_AC           *pAC;
1544 SK_U32          IntSrc;         /* interrupts source register contents */       
1545
1546         pNet = (DEV_NET*) dev->priv;
1547         pAC = pNet->pAC;
1548         
1549         /*
1550          * Check and process if its our interrupt
1551          */
1552         SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1553         if (IntSrc == 0) {
1554                 return;
1555         }
1556
1557         while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1558 #if 0 /* software irq currently not used */
1559                 if (IntSrc & IRQ_SW) {
1560                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1561                                 SK_DBGCAT_DRV_INT_SRC,
1562                                 ("Software IRQ\n"));
1563                 }
1564 #endif
1565                 if (IntSrc & IRQ_EOF_RX1) {
1566                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1567                                 SK_DBGCAT_DRV_INT_SRC,
1568                                 ("EOF RX1 IRQ\n"));
1569                         ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1570                         SK_PNMI_CNT_RX_INTR(pAC, 0);
1571                 }
1572                 if (IntSrc & IRQ_EOF_RX2) {
1573                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1574                                 SK_DBGCAT_DRV_INT_SRC,
1575                                 ("EOF RX2 IRQ\n"));
1576                         ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1577                         SK_PNMI_CNT_RX_INTR(pAC, 1);
1578                 }
1579 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1580                 if (IntSrc & IRQ_EOF_AS_TX1) {
1581                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1582                                 SK_DBGCAT_DRV_INT_SRC,
1583                                 ("EOF AS TX1 IRQ\n"));
1584                         SK_PNMI_CNT_TX_INTR(pAC, 0);
1585                         spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1586                         FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1587                         spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1588                 }
1589                 if (IntSrc & IRQ_EOF_AS_TX2) {
1590                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1591                                 SK_DBGCAT_DRV_INT_SRC,
1592                                 ("EOF AS TX2 IRQ\n"));
1593                         SK_PNMI_CNT_TX_INTR(pAC, 1);
1594                         spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1595                         FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1596                         spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1597                 }
1598 #if 0 /* only if sync. queues used */
1599                 if (IntSrc & IRQ_EOF_SY_TX1) {
1600                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1601                                 SK_DBGCAT_DRV_INT_SRC,
1602                                 ("EOF SY TX1 IRQ\n"));
1603                         SK_PNMI_CNT_TX_INTR(pAC, 1);
1604                         spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1605                         FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1606                         spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1607                         ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1608                 }
1609                 if (IntSrc & IRQ_EOF_SY_TX2) {
1610                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1611                                 SK_DBGCAT_DRV_INT_SRC,
1612                                 ("EOF SY TX2 IRQ\n"));
1613                         SK_PNMI_CNT_TX_INTR(pAC, 1);
1614                         spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1615                         FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1616                         spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1617                         ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1618                 }
1619 #endif
1620 #endif
1621
1622                 /* do all IO at once */
1623                 if (IntSrc & IRQ_EOF_RX1)
1624                         ClearAndStartRx(pAC, 0);
1625                 if (IntSrc & IRQ_EOF_RX2)
1626                         ClearAndStartRx(pAC, 1);
1627 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1628                 if (IntSrc & IRQ_EOF_AS_TX1)
1629                         ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1630                 if (IntSrc & IRQ_EOF_AS_TX2)
1631                         ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1632 #endif
1633                 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1634         } /* while (IntSrc & IRQ_MASK != 0) */
1635
1636         if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1637                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1638                         ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1639                 pAC->CheckQueue = SK_FALSE;
1640                 spin_lock(&pAC->SlowPathLock);
1641                 if (IntSrc & SPECIAL_IRQS)
1642                         SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1643
1644                 SkEventDispatcher(pAC, pAC->IoBase);
1645                 spin_unlock(&pAC->SlowPathLock);
1646         }
1647         /*
1648          * do it all again is case we cleared an interrupt that 
1649          * came in after handling the ring (OUTs may be delayed
1650          * in hardware buffers, but are through after IN)
1651          */
1652
1653         ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1654         ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1655
1656         if (pAC->CheckQueue) {
1657                 pAC->CheckQueue = SK_FALSE;
1658                 spin_lock(&pAC->SlowPathLock);
1659                 SkEventDispatcher(pAC, pAC->IoBase);
1660                 spin_unlock(&pAC->SlowPathLock);
1661         }
1662
1663
1664         /* IRQ is processed - Enable IRQs again*/
1665         SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1666
1667         return;
1668 } /* SkGeIsr */
1669
1670
1671 /****************************************************************************
1672  *
1673  *      SkGeIsrOnePort - handle adapter interrupts for single port adapter
1674  *
1675  * Description:
1676  *      The interrupt routine is called when the network adapter
1677  *      generates an interrupt. It may also be called if another device
1678  *      shares this interrupt vector with the driver.
1679  *      This is the same as above, but handles only one port.
1680  *
1681  * Returns: N/A
1682  *
1683  */
1684 #if 0
1685 static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1686 #else
1687 void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1688 #endif
1689 {
1690 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1691 DEV_NET         *pNet;
1692 SK_AC           *pAC;
1693 SK_U32          IntSrc;         /* interrupts source register contents */       
1694
1695         pNet = (DEV_NET*) dev->priv;
1696         pAC = pNet->pAC;
1697         
1698         /*
1699          * Check and process if its our interrupt
1700          */
1701         SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1702         if (IntSrc == 0) {
1703                 return;
1704         }
1705         
1706         while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1707 #if 0 /* software irq currently not used */
1708                 if (IntSrc & IRQ_SW) {
1709                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1710                                 SK_DBGCAT_DRV_INT_SRC,
1711                                 ("Software IRQ\n"));
1712                 }
1713 #endif
1714                 if (IntSrc & IRQ_EOF_RX1) {
1715                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1716                                 SK_DBGCAT_DRV_INT_SRC,
1717                                 ("EOF RX1 IRQ\n"));
1718                         ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1719                         SK_PNMI_CNT_RX_INTR(pAC, 0);
1720                 }
1721 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1722                 if (IntSrc & IRQ_EOF_AS_TX1) {
1723                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1724                                 SK_DBGCAT_DRV_INT_SRC,
1725                                 ("EOF AS TX1 IRQ\n"));
1726                         SK_PNMI_CNT_TX_INTR(pAC, 0);
1727                         spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1728                         FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1729                         spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1730                 }
1731 #if 0 /* only if sync. queues used */
1732                 if (IntSrc & IRQ_EOF_SY_TX1) {
1733                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1734                                 SK_DBGCAT_DRV_INT_SRC,
1735                                 ("EOF SY TX1 IRQ\n"));
1736                         SK_PNMI_CNT_TX_INTR(pAC, 0);
1737                         spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1738                         FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1739                         spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1740                         ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1741                 }
1742 #endif
1743 #endif
1744
1745                 /* do all IO at once */
1746                 if (IntSrc & IRQ_EOF_RX1)
1747                         ClearAndStartRx(pAC, 0);
1748 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1749                 if (IntSrc & IRQ_EOF_AS_TX1)
1750                         ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1751 #endif
1752                 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1753         } /* while (IntSrc & IRQ_MASK != 0) */
1754         
1755         if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1756                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1757                         ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1758                 pAC->CheckQueue = SK_FALSE;
1759                 spin_lock(&pAC->SlowPathLock);
1760                 if (IntSrc & SPECIAL_IRQS)
1761                         SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1762
1763                 SkEventDispatcher(pAC, pAC->IoBase);
1764                 spin_unlock(&pAC->SlowPathLock);
1765         }
1766         /*
1767          * do it all again is case we cleared an interrupt that 
1768          * came in after handling the ring (OUTs may be delayed
1769          * in hardware buffers, but are through after IN)
1770          */
1771         ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1772
1773         /* IRQ is processed - Enable IRQs again*/
1774         SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1775
1776         return;
1777 } /* SkGeIsrOnePort */
1778
1779
1780 /****************************************************************************
1781  *
1782  *      SkGeOpen - handle start of initialized adapter
1783  *
1784  * Description:
1785  *      This function starts the initialized adapter.
1786  *      The board level variable is set and the adapter is
1787  *      brought to full functionality.
1788  *      The device flags are set for operation.
1789  *      Do all necessary level 2 initialization, enable interrupts and
1790  *      give start command to RLMT.
1791  *
1792  * Returns:
1793  *      0 on success
1794  *      != 0 on error
1795  */
1796 #if 0
1797 static int SkGeOpen(
1798 #else
1799 int SkGeOpen(
1800 #endif
1801 struct SK_NET_DEVICE    *dev)
1802 {
1803         DEV_NET                 *pNet;
1804         SK_AC                   *pAC;
1805         unsigned long   Flags;          /* for spin lock */
1806         int                             i;
1807         SK_EVPARA               EvPara;         /* an event parameter union */
1808
1809         pNet = (DEV_NET*) dev->priv;
1810         pAC = pNet->pAC;
1811         
1812         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1813                 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1814
1815         if (pAC->BoardLevel == 0) {
1816                 /* level 1 init common modules here */
1817                 if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
1818                         printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1819                         return (-1);
1820                 }
1821                 SkI2cInit       (pAC, pAC->IoBase, 1);
1822                 SkEventInit     (pAC, pAC->IoBase, 1);
1823                 SkPnmiInit      (pAC, pAC->IoBase, 1);
1824                 SkAddrInit      (pAC, pAC->IoBase, 1);
1825                 SkRlmtInit      (pAC, pAC->IoBase, 1);
1826                 SkTimerInit     (pAC, pAC->IoBase, 1);
1827                 pAC->BoardLevel = 1;
1828         }
1829
1830         if (pAC->BoardLevel != 2) {
1831                 /* tschilling: Level 2 init modules here, check return value. */
1832                 if (SkGeInit(pAC, pAC->IoBase, 2) != 0) {
1833                         printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1834                         return (-1);
1835                 }
1836                 SkI2cInit       (pAC, pAC->IoBase, 2);
1837                 SkEventInit     (pAC, pAC->IoBase, 2);
1838                 SkPnmiInit      (pAC, pAC->IoBase, 2);
1839                 SkAddrInit      (pAC, pAC->IoBase, 2);
1840                 SkRlmtInit      (pAC, pAC->IoBase, 2);
1841                 SkTimerInit     (pAC, pAC->IoBase, 2);
1842                 pAC->BoardLevel = 2;
1843         }
1844
1845         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1846                 /* Enable transmit descriptor polling. */
1847                 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1848                 FillRxRing(pAC, &pAC->RxPort[i]);
1849         }
1850         SkGeYellowLED(pAC, pAC->IoBase, 1);
1851
1852 #ifdef USE_INT_MOD
1853 /* moderate only TX complete interrupts (these are not time critical) */
1854 #define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)
1855         {
1856                 unsigned long ModBase;
1857                 ModBase = 53125000 / INTS_PER_SEC;
1858                 SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
1859                 SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
1860                 SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
1861         }
1862 #endif
1863
1864         /* enable Interrupts */
1865         SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1866         SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1867
1868         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1869
1870         if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1871                 EvPara.Para32[0] = pAC->RlmtNets;
1872                 EvPara.Para32[1] = -1;
1873                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1874                         EvPara);
1875                 EvPara.Para32[0] = pAC->RlmtMode;
1876                 EvPara.Para32[1] = 0;
1877                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1878                         EvPara);
1879         }
1880
1881         EvPara.Para32[0] = pNet->NetNr;
1882         EvPara.Para32[1] = -1;
1883         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1884         SkEventDispatcher(pAC, pAC->IoBase);
1885         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1886
1887         pAC->MaxPorts++;
1888         pNet->Up = 1;
1889
1890         MOD_INC_USE_COUNT;
1891
1892         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1893                 ("SkGeOpen suceeded\n"));
1894
1895         return (0);
1896 } /* SkGeOpen */
1897
1898
1899 /****************************************************************************
1900  *
1901  *      SkGeClose - Stop initialized adapter
1902  *
1903  * Description:
1904  *      Close initialized adapter.
1905  *
1906  * Returns:
1907  *      0 - on success
1908  *      error code - on error
1909  */
1910 #if 0
1911 static int SkGeClose(
1912 #else
1913 int SkGeClose(
1914 #endif
1915 struct SK_NET_DEVICE    *dev)
1916 {
1917         DEV_NET                 *pNet;
1918         SK_AC                   *pAC;
1919
1920         unsigned long   Flags;          /* for spin lock */
1921         int                             i;
1922         int                             PortIdx;
1923         SK_EVPARA               EvPara;
1924
1925         netif_stop_queue(dev);
1926         pNet = (DEV_NET*) dev->priv;
1927         pAC = pNet->pAC;
1928
1929         if (pAC->RlmtNets == 1)
1930                 PortIdx = pAC->ActivePort;
1931         else
1932                 PortIdx = pNet->NetNr;
1933
1934         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1935                 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1936
1937         /* 
1938          * Clear multicast table, promiscuous mode ....
1939          */
1940         SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1941         SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1942                 SK_PROM_MODE_NONE);
1943
1944         if (pAC->MaxPorts == 1) {
1945                 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1946                 /* disable interrupts */
1947                 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1948                 EvPara.Para32[0] = pNet->NetNr;
1949                 EvPara.Para32[1] = -1;
1950                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1951                 SkEventDispatcher(pAC, pAC->IoBase);
1952                 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1953                 /* stop the hardware */
1954                 SkGeDeInit(pAC, pAC->IoBase);
1955                 pAC->BoardLevel = 0;
1956                 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1957         } else {
1958
1959                 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1960                 EvPara.Para32[0] = pNet->NetNr;
1961                 EvPara.Para32[1] = -1;
1962                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1963                 SkEventDispatcher(pAC, pAC->IoBase);
1964                 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1965                 
1966                 /* Stop port */
1967                 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1968                         [TX_PRIO_LOW].TxDesRingLock, Flags);
1969                 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr, 
1970                         SK_STOP_ALL, SK_HARD_RST);
1971                 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1972                         [TX_PRIO_LOW].TxDesRingLock, Flags);
1973         }
1974
1975         if (pAC->RlmtNets == 1) {
1976                 /* clear all descriptor rings */
1977                 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1978                         ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1979                         ClearRxRing(pAC, &pAC->RxPort[i]);
1980                         ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1981                 }
1982         } else {
1983                 /* clear port descriptor rings */
1984                 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1985                 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1986                 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1987         }
1988
1989         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1990                 ("SkGeClose: done "));
1991
1992         pAC->MaxPorts--;
1993         pNet->Up = 0;
1994         MOD_DEC_USE_COUNT;
1995         
1996         return (0);
1997 } /* SkGeClose */
1998
1999
2000 /*****************************************************************************
2001  *
2002  *      SkGeXmit - Linux frame transmit function
2003  *
2004  * Description:
2005  *      The system calls this function to send frames onto the wire.
2006  *      It puts the frame in the tx descriptor ring. If the ring is
2007  *      full then, the 'tbusy' flag is set.
2008  *
2009  * Returns:
2010  *      0, if everything is ok
2011  *      !=0, on error
2012  * WARNING: returning 1 in 'tbusy' case caused system crashes (double
2013  *      allocated skb's) !!!
2014  */
2015 #if 0
2016 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
2017 #else
2018 int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
2019 #endif
2020 {
2021 DEV_NET         *pNet;
2022 SK_AC           *pAC;
2023 int                     Rc;     /* return code of XmitFrame */
2024
2025         pNet = (DEV_NET*) dev->priv;
2026         pAC = pNet->pAC;
2027
2028 #if 0
2029         if ((!skb_shinfo(skb)->nr_frags) || 
2030 #else
2031         if (1 ||
2032 #endif
2033                 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
2034                 /* Don't activate scatter-gather and hardware checksum */
2035
2036                 if (pAC->RlmtNets == 2)
2037                         Rc = XmitFrame(
2038                                 pAC,
2039                                 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
2040                                 skb);
2041                 else
2042                         Rc = XmitFrame(
2043                                 pAC,
2044                                 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
2045                                 skb);
2046         } else {
2047 #if 0
2048                 /* scatter-gather and hardware TCP checksumming anabled*/
2049                 if (pAC->RlmtNets == 2)
2050                         Rc = XmitFrameSG(
2051                                 pAC,
2052                                 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
2053                                 skb);
2054                 else
2055                         Rc = XmitFrameSG(
2056                                 pAC,
2057                                 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
2058                                 skb);
2059 #endif
2060         }
2061
2062         /* Transmitter out of resources? */
2063         if (Rc <= 0) {
2064                 netif_stop_queue(dev);
2065         }
2066
2067         /* If not taken, give buffer ownership back to the
2068          * queueing layer.
2069          */
2070         if (Rc < 0)
2071                 return (1);
2072
2073 #if 0
2074         dev->trans_start = jiffies;
2075 #endif
2076         return (0);
2077 } /* SkGeXmit */
2078
2079
2080 /*****************************************************************************
2081  *
2082  *      XmitFrame - fill one socket buffer into the transmit ring
2083  *
2084  * Description:
2085  *      This function puts a message into the transmit descriptor ring
2086  *      if there is a descriptors left.
2087  *      Linux skb's consist of only one continuous buffer.
2088  *      The first step locks the ring. It is held locked
2089  *      all time to avoid problems with SWITCH_../PORT_RESET.
2090  *      Then the descriptoris allocated.
2091  *      The second part is linking the buffer to the descriptor.
2092  *      At the very last, the Control field of the descriptor
2093  *      is made valid for the BMU and a start TX command is given
2094  *      if necessary.
2095  *
2096  * Returns:
2097  *      > 0 - on succes: the number of bytes in the message
2098  *      = 0 - on resource shortage: this frame sent or dropped, now
2099  *              the ring is full ( -> set tbusy)
2100  *      < 0 - on failure: other problems ( -> return failure to upper layers)
2101  */
2102 static int XmitFrame(
2103 SK_AC           *pAC,           /* pointer to adapter context */
2104 TX_PORT         *pTxPort,       /* pointer to struct of port to send to */
2105 struct sk_buff  *pMessage)      /* pointer to send-message */
2106 {
2107 TXD             *pTxd;          /* the rxd to fill */
2108 unsigned long   Flags;
2109 SK_U64          PhysAddr;
2110 int             BytesSend;
2111
2112         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
2113                 ("X"));
2114
2115         spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2116 #ifndef USE_TX_COMPLETE
2117         FreeTxDescriptors(pAC, pTxPort);
2118 #endif
2119         if (pTxPort->TxdRingFree == 0) {
2120                 /* no enough free descriptors in ring at the moment */
2121                 FreeTxDescriptors(pAC, pTxPort);
2122                 if (pTxPort->TxdRingFree == 0) {
2123                         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2124                         SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
2125                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2126                                 SK_DBGCAT_DRV_TX_PROGRESS,
2127                                 ("XmitFrame failed\n"));
2128                         /* this message can not be sent now */
2129                         /* Because tbusy seems to be set, the message should not be freed here */
2130                         /* It will be used by the scheduler of the ethernet handler */
2131                         return (-1);
2132                 }
2133         }
2134         /* advance head counter behind descriptor needed for this frame */
2135         pTxd = pTxPort->pTxdRingHead;
2136         pTxPort->pTxdRingHead = pTxd->pNextTxd;
2137         pTxPort->TxdRingFree--;
2138         /* the needed descriptor is reserved now */
2139         
2140         /* 
2141          * everything allocated ok, so add buffer to descriptor
2142          */
2143
2144 #ifdef SK_DUMP_TX
2145         DumpMsg(pMessage, "XmitFrame");
2146 #endif
2147
2148         /* set up descriptor and CONTROL dword */
2149 #if 0
2150         PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2151                 virt_to_page(pMessage->data),
2152                 ((unsigned long) pMessage->data &
2153                 ~PAGE_MASK),
2154                 pMessage->len,
2155                 PCI_DMA_TODEVICE);
2156 #else
2157         PhysAddr = (SK_U64) pci_phys_to_mem(pAC->PciDev, (u32) pMessage->data);
2158 #endif
2159         pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);
2160         pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2161         pTxd->pMBuf = pMessage;
2162         pTxd->TBControl = TX_CTRL_OWN_BMU | TX_CTRL_STF |
2163                 TX_CTRL_CHECK_DEFAULT | TX_CTRL_SOFTWARE |
2164 #ifdef USE_TX_COMPLETE
2165                 TX_CTRL_EOF | TX_CTRL_EOF_IRQ | pMessage->len;
2166 #else
2167                 TX_CTRL_EOF | pMessage->len;
2168 #endif
2169         
2170         if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
2171                 /* previous descriptor already done, so give tx start cmd */
2172                 /* StartTx(pAC, pTxPort->HwAddr); */
2173                 SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
2174         }
2175         pTxPort->pTxdRingPrev = pTxd;
2176         
2177         
2178         BytesSend = pMessage->len;
2179         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2180         /* after releasing the lock, the skb may be immidiately freed */
2181         if (pTxPort->TxdRingFree != 0)
2182                 return (BytesSend);
2183         else
2184                 return (0);
2185
2186 } /* XmitFrame */
2187
2188 /*****************************************************************************
2189  *
2190  *      XmitFrameSG - fill one socket buffer into the transmit ring
2191  *                (use SG and TCP/UDP hardware checksumming)
2192  *
2193  * Description:
2194  *      This function puts a message into the transmit descriptor ring
2195  *      if there is a descriptors left.
2196  *
2197  * Returns:
2198  *      > 0 - on succes: the number of bytes in the message
2199  *      = 0 - on resource shortage: this frame sent or dropped, now
2200  *              the ring is full ( -> set tbusy)
2201  *      < 0 - on failure: other problems ( -> return failure to upper layers)
2202  */
2203 #if 0
2204 static int XmitFrameSG(
2205 SK_AC           *pAC,                   /* pointer to adapter context */
2206 TX_PORT         *pTxPort,               /* pointer to struct of port to send to */
2207 struct sk_buff  *pMessage)      /* pointer to send-message */
2208 {
2209
2210         int             i;
2211         int                     BytesSend;
2212         int                     hlength;
2213         int                     protocol;
2214         skb_frag_t              *sk_frag;
2215         TXD                     *pTxd;
2216         TXD                     *pTxdFst;
2217         TXD                     *pTxdLst;
2218         SK_U64          PhysAddr;
2219         unsigned long   Flags;
2220
2221         spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2222 #ifndef USE_TX_COMPLETE
2223         FreeTxDescriptors(pAC, pTxPort);
2224 #endif
2225         if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
2226                 FreeTxDescriptors(pAC, pTxPort);
2227                 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
2228                         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2229                         SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
2230                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2231                                 SK_DBGCAT_DRV_TX_PROGRESS,
2232                                 ("XmitFrameSG failed - Ring full\n"));
2233                                 /* this message can not be sent now */
2234                         return(-1);
2235                 }
2236         }
2237
2238
2239         pTxd = pTxPort->pTxdRingHead;
2240         pTxdFst = pTxd;
2241         pTxdLst = pTxd;
2242         BytesSend = 0;
2243         protocol = 0;
2244
2245         /* map first fragment (header) */
2246         PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2247                         virt_to_page(pMessage->data),
2248                         ((unsigned long) pMessage->data & ~PAGE_MASK),
2249                         skb_headlen(pMessage),
2250                         PCI_DMA_TODEVICE);
2251
2252         pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);
2253         pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2254
2255         /* HW checksum? */
2256         if (pMessage->ip_summed == CHECKSUM_HW) {
2257                 pTxd->TBControl = TX_CTRL_STF |
2258                                   TX_CTRL_ST_FWD |
2259                                   skb_headlen(pMessage);
2260
2261                 /* We have to use the opcode for tcp here because the opcode for
2262                 udp is not working in the hardware yet (revision 2.0)*/
2263                 protocol = ((SK_U8)pMessage->data[23] & 0xf);
2264                 if ((protocol == 17) && (pAC->GIni.GIChipRev != 0))
2265                         pTxd->TBControl |=  BMU_UDP_CHECK;
2266                 else
2267                         pTxd->TBControl |= BMU_TCP_CHECK ;
2268
2269                 hlength = ((SK_U8)pMessage->data[14] & 0xf) * 4;
2270                 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
2271                 pTxd->TcpSumSt = 14+hlength+16;
2272                 pTxd->TcpSumWr = 14+hlength;
2273         
2274         } else {
2275                 pTxd->TBControl = TX_CTRL_CHECK_DEFAULT | 
2276                                   TX_CTRL_SOFTWARE |
2277                                   TX_CTRL_STF |
2278                                   skb_headlen(pMessage);
2279         }
2280
2281         pTxd = pTxd->pNextTxd;
2282         pTxPort->TxdRingFree--;
2283         BytesSend += skb_headlen(pMessage);
2284
2285
2286         /* Map SG fragments */
2287         for (i = 0; i < skb_shinfo(pMessage)->nr_frags; i++) {
2288                 sk_frag = &skb_shinfo(pMessage)->frags[i];
2289                 
2290                 /* we already have the proper value in entry */
2291                 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2292                                                  sk_frag->page,
2293                                                  sk_frag->page_offset,
2294                                                  sk_frag->size,
2295                                                  PCI_DMA_TODEVICE);
2296
2297                 pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);
2298                 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2299                 pTxd->pMBuf = pMessage;
2300                 
2301                 /* HW checksum */
2302                 if (pMessage->ip_summed == CHECKSUM_HW) {
2303                         pTxd->TBControl = TX_CTRL_OWN_BMU | 
2304                                           TX_CTRL_SOFTWARE |
2305                                           TX_CTRL_ST_FWD;
2306
2307                         /* We have to use the opcode for tcp here because the opcode for
2308                         udp is not working in the hardware yet (revision 2.0)*/
2309                         if ((protocol == 17) && (pAC->GIni.GIChipRev != 0))
2310                                 pTxd->TBControl |= BMU_UDP_CHECK ;
2311                         else
2312                                 pTxd->TBControl |= BMU_TCP_CHECK ;
2313
2314                 } else {
2315                         pTxd->TBControl = TX_CTRL_CHECK_DEFAULT |
2316                                           TX_CTRL_SOFTWARE |
2317                                           TX_CTRL_OWN_BMU;
2318                 }
2319
2320                 /* Last fragment  */
2321                 if( (i+1) == skb_shinfo(pMessage)->nr_frags )  {
2322 #ifdef USE_TX_COMPLETE
2323                         pTxd->TBControl |= TX_CTRL_EOF |
2324                                            TX_CTRL_EOF_IRQ |
2325                                            sk_frag->size;
2326 #else
2327                         pTxd->TBControl |= TX_CTRL_EOF |
2328                                            sk_frag->size;
2329 #endif
2330                         pTxdFst->TBControl |= TX_CTRL_OWN_BMU |
2331                                               TX_CTRL_SOFTWARE; 
2332
2333                 } else {
2334                         pTxd->TBControl |= sk_frag->size;
2335                 }
2336                 pTxdLst = pTxd;
2337                 pTxd = pTxd->pNextTxd;
2338                 pTxPort->TxdRingFree--;
2339                 BytesSend += sk_frag->size;
2340         }
2341
2342         if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
2343                 /* previous descriptor already done, so give tx start cmd */
2344                 /* StartTx(pAC, pTxPort->HwAddr); */
2345                 SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
2346         }
2347
2348         pTxPort->pTxdRingPrev = pTxdLst;
2349         pTxPort->pTxdRingHead = pTxd;
2350
2351         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2352
2353         if (pTxPort->TxdRingFree > 0)
2354                 return (BytesSend);
2355         else
2356                 return (0);
2357 }
2358 #endif
2359
2360
2361 void dump_frag( SK_U8 *data, int length)
2362 {
2363         int i;
2364
2365         printk("Length: %d\n", length);                
2366         for( i=0; i < length; i++ ) {
2367                 printk(" %02x", (SK_U8)*(data + i) );
2368                 if( !((i+1) % 20) )
2369                   printk("\n");
2370         }
2371         printk("\n\n");
2372
2373 }
2374
2375
2376 /*****************************************************************************
2377  *
2378  *      FreeTxDescriptors - release descriptors from the descriptor ring
2379  *
2380  * Description:
2381  *      This function releases descriptors from a transmit ring if they
2382  *      have been sent by the BMU.
2383  *      If a descriptors is sent, it can be freed and the message can
2384  *      be freed, too.
2385  *      The SOFTWARE controllable bit is used to prevent running around a
2386  *      completely free ring for ever. If this bit is no set in the
2387  *      frame (by XmitFrame), this frame has never been sent or is
2388  *      already freed.
2389  *      The Tx descriptor ring lock must be held while calling this function !!!
2390  *
2391  * Returns:
2392  *      none
2393  */
2394 static void FreeTxDescriptors(
2395 SK_AC   *pAC,           /* pointer to the adapter context */
2396 TX_PORT *pTxPort)       /* pointer to destination port structure */
2397 {
2398 TXD     *pTxd;          /* pointer to the checked descriptor */
2399 TXD     *pNewTail;      /* pointer to 'end' of the ring */
2400 SK_U32  Control;        /* TBControl field of descriptor */
2401 SK_U64  PhysAddr;       /* address of DMA mapping */
2402
2403         pNewTail = pTxPort->pTxdRingTail;
2404         pTxd = pNewTail;
2405         /* 
2406          * loop forever; exits if TX_CTRL_SOFTWARE bit not set in start frame
2407          * or TX_CTRL_OWN_BMU bit set in any frame
2408          */
2409         while (1) {
2410                 Control = pTxd->TBControl;
2411                 if ((Control & TX_CTRL_SOFTWARE) == 0) {
2412                         /* 
2413                          * software controllable bit is set in first
2414                          * fragment when given to BMU. Not set means that
2415                          * this fragment was never sent or is already 
2416                          * freed ( -> ring completely free now).
2417                          */
2418                         pTxPort->pTxdRingTail = pTxd;
2419                         netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2420                         return;
2421                 }
2422                 if (Control & TX_CTRL_OWN_BMU) {
2423                         pTxPort->pTxdRingTail = pTxd;
2424                         if (pTxPort->TxdRingFree > 0) {
2425                                 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2426                         }
2427                         return;
2428                 }
2429                 
2430                 /* release the DMA mapping */
2431                 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
2432                 PhysAddr |= (SK_U64) pTxd->VDataLow;
2433                 pci_unmap_page(pAC->PciDev, PhysAddr,
2434                                  pTxd->pMBuf->len,
2435                                  PCI_DMA_TODEVICE);
2436
2437                 if (Control & TX_CTRL_EOF)
2438                         DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
2439
2440                 pTxPort->TxdRingFree++;
2441                 pTxd->TBControl &= ~TX_CTRL_SOFTWARE;
2442                 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
2443         } /* while(forever) */
2444 } /* FreeTxDescriptors */
2445
2446 /*****************************************************************************
2447  *
2448  *      FillRxRing - fill the receive ring with valid descriptors
2449  *
2450  * Description:
2451  *      This function fills the receive ring descriptors with data
2452  *      segments and makes them valid for the BMU.
2453  *      The active ring is filled completely, if possible.
2454  *      The non-active ring is filled only partial to save memory.
2455  *
2456  * Description of rx ring structure:
2457  *      head - points to the descriptor which will be used next by the BMU
2458  *      tail - points to the next descriptor to give to the BMU
2459  *      
2460  * Returns:     N/A
2461  */
2462 static void FillRxRing(
2463 SK_AC           *pAC,           /* pointer to the adapter context */
2464 RX_PORT         *pRxPort)       /* ptr to port struct for which the ring
2465                                    should be filled */
2466 {
2467 unsigned long   Flags;
2468
2469         spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2470         while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
2471                 if(!FillRxDescriptor(pAC, pRxPort))
2472                         break;
2473         }
2474         spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2475 } /* FillRxRing */
2476
2477
2478 /*****************************************************************************
2479  *
2480  *      FillRxDescriptor - fill one buffer into the receive ring
2481  *
2482  * Description:
2483  *      The function allocates a new receive buffer and
2484  *      puts it into the next descriptor.
2485  *
2486  * Returns:
2487  *      SK_TRUE - a buffer was added to the ring
2488  *      SK_FALSE - a buffer could not be added
2489  */
2490 static SK_BOOL FillRxDescriptor(
2491 SK_AC           *pAC,           /* pointer to the adapter context struct */
2492 RX_PORT         *pRxPort)       /* ptr to port struct of ring to fill */
2493 {
2494 struct sk_buff  *pMsgBlock;     /* pointer to a new message block */
2495 RXD             *pRxd;          /* the rxd to fill */
2496 SK_U16          Length;         /* data fragment length */
2497 SK_U64          PhysAddr;       /* physical address of a rx buffer */
2498
2499         pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
2500         if (pMsgBlock == NULL) {
2501                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2502                         SK_DBGCAT_DRV_ENTRY,
2503                         ("%s: Allocation of rx buffer failed !\n",
2504                         pAC->dev[pRxPort->PortIndex]->name));
2505                 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
2506                 return(SK_FALSE);
2507         }
2508         skb_reserve(pMsgBlock, 2); /* to align IP frames */
2509         /* skb allocated ok, so add buffer */
2510         pRxd = pRxPort->pRxdRingTail;
2511         pRxPort->pRxdRingTail = pRxd->pNextRxd;
2512         pRxPort->RxdRingFree--;
2513         Length = pAC->RxBufSize;
2514 #if 0
2515         PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2516                 virt_to_page(pMsgBlock->data),
2517                 ((unsigned long) pMsgBlock->data &
2518                 ~PAGE_MASK),
2519                 pAC->RxBufSize - 2,
2520                 PCI_DMA_FROMDEVICE);
2521 #else
2522         PhysAddr = (SK_U64) pci_phys_to_mem(pAC->PciDev, (u32)pMsgBlock->data);
2523 #endif
2524         pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2525         pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2526         pRxd->pMBuf = pMsgBlock;
2527         pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
2528                 RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
2529         return (SK_TRUE);
2530
2531 } /* FillRxDescriptor */
2532
2533
2534 /*****************************************************************************
2535  *
2536  *      ReQueueRxBuffer - fill one buffer back into the receive ring
2537  *
2538  * Description:
2539  *      Fill a given buffer back into the rx ring. The buffer
2540  *      has been previously allocated and aligned, and its phys.
2541  *      address calculated, so this is no more necessary.
2542  *
2543  * Returns: N/A
2544  */
2545 static void ReQueueRxBuffer(
2546 SK_AC           *pAC,           /* pointer to the adapter context struct */
2547 RX_PORT         *pRxPort,       /* ptr to port struct of ring to fill */
2548 struct sk_buff  *pMsg,          /* pointer to the buffer */
2549 SK_U32          PhysHigh,       /* phys address high dword */
2550 SK_U32          PhysLow)        /* phys address low dword */
2551 {
2552 RXD             *pRxd;          /* the rxd to fill */
2553 SK_U16          Length;         /* data fragment length */
2554
2555         pRxd = pRxPort->pRxdRingTail;
2556         pRxPort->pRxdRingTail = pRxd->pNextRxd;
2557         pRxPort->RxdRingFree--;
2558         Length = pAC->RxBufSize;
2559         pRxd->VDataLow = PhysLow;
2560         pRxd->VDataHigh = PhysHigh;
2561         pRxd->pMBuf = pMsg;
2562         pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
2563                 RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
2564         return;
2565 } /* ReQueueRxBuffer */
2566
2567
2568 /*****************************************************************************
2569  *
2570  *      ReceiveIrq - handle a receive IRQ
2571  *
2572  * Description:
2573  *      This function is called when a receive IRQ is set.
2574  *      It walks the receive descriptor ring and sends up all
2575  *      frames that are complete.
2576  *
2577  * Returns:     N/A
2578  */
2579 #if 0
2580 static void ReceiveIrq(
2581 #else
2582 void ReceiveIrq(
2583 #endif
2584         SK_AC           *pAC,                   /* pointer to adapter context */
2585         RX_PORT         *pRxPort,               /* pointer to receive port struct */
2586         SK_BOOL         SlowPathLock)   /* indicates if SlowPathLock is needed */
2587 {
2588 RXD                             *pRxd;                  /* pointer to receive descriptors */
2589 SK_U32                  Control;                /* control field of descriptor */
2590 struct sk_buff  *pMsg;                  /* pointer to message holding frame */
2591 struct sk_buff  *pNewMsg;               /* pointer to a new message for copying frame */
2592 int                             FrameLength;    /* total length of received frame */
2593 SK_MBUF                 *pRlmtMbuf;             /* ptr to a buffer for giving a frame to rlmt */
2594 SK_EVPARA               EvPara;                 /* an event parameter union */  
2595 unsigned long   Flags;                  /* for spin lock */
2596 int                             PortIndex = pRxPort->PortIndex;
2597 unsigned int    Offset;
2598 unsigned int    NumBytes;
2599 unsigned int    ForRlmt;
2600 SK_BOOL                 IsBc;
2601 SK_BOOL                 IsMc;
2602 SK_BOOL  IsBadFrame;                    /* Bad frame */
2603
2604 SK_U32                  FrameStat;
2605 unsigned short  Csum1;
2606 unsigned short  Csum2;
2607 unsigned short  Type;
2608 #if 0
2609 int                             Result;
2610 #endif
2611 SK_U64                  PhysAddr;
2612
2613 rx_start:       
2614         /* do forever; exit if RX_CTRL_OWN_BMU found */
2615         for ( pRxd = pRxPort->pRxdRingHead ;
2616                   pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2617                   pRxd = pRxd->pNextRxd,
2618                   pRxPort->pRxdRingHead = pRxd,
2619                   pRxPort->RxdRingFree ++) {
2620
2621                 /*
2622                  * For a better understanding of this loop 
2623                  * Go through every descriptor beginning at the head 
2624                  * Please note: the ring might be completely received so the OWN bit
2625                  * set is not a good crirteria to leave that loop.
2626                  * Therefore the RingFree counter is used.
2627                  * On entry of this loop pRxd is a pointer to the Rxd that needs
2628                  * to be checked next.
2629                  */
2630
2631                 Control = pRxd->RBControl;
2632         
2633                 /* check if this descriptor is ready */
2634                 if ((Control & RX_CTRL_OWN_BMU) != 0) {
2635                         /* this descriptor is not yet ready */
2636                         /* This is the usual end of the loop */
2637                         /* We don't need to start the ring again */
2638                         FillRxRing(pAC, pRxPort);
2639                         return;
2640                 }
2641
2642                 /* get length of frame and check it */
2643                 FrameLength = Control & RX_CTRL_LEN_MASK;
2644                 if (FrameLength > pAC->RxBufSize) {
2645                         goto rx_failed;
2646                 }
2647
2648                 /* check for STF and EOF */
2649                 if ((Control & (RX_CTRL_STF | RX_CTRL_EOF)) !=
2650                         (RX_CTRL_STF | RX_CTRL_EOF)) {
2651                         goto rx_failed;
2652                 }
2653
2654                 /* here we have a complete frame in the ring */
2655                 pMsg = pRxd->pMBuf;
2656
2657                 FrameStat = pRxd->FrameStat;
2658
2659                 /* check for frame length mismatch */
2660 #define XMR_FS_LEN_SHIFT        18
2661 #define GMR_FS_LEN_SHIFT        16
2662                 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2663                         if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2664                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2665                                         SK_DBGCAT_DRV_RX_PROGRESS,
2666                                         ("skge: Frame length mismatch (%u/%u).\n",
2667                                         FrameLength,
2668                                         (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2669                                 goto rx_failed;
2670                         }
2671                 }
2672                 else {
2673                         if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2674                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2675                                         SK_DBGCAT_DRV_RX_PROGRESS,
2676                                         ("skge: Frame length mismatch (%u/%u).\n",
2677                                         FrameLength,
2678                                         (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2679                                 goto rx_failed;
2680                         }
2681                 }
2682
2683                 /* Set Rx Status */
2684                 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2685                         IsBc = (FrameStat & XMR_FS_BC) != 0;
2686                         IsMc = (FrameStat & XMR_FS_MC) != 0;
2687                         IsBadFrame = (FrameStat & 
2688                                 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2689                 } else {
2690                         IsBc = (FrameStat & GMR_FS_BC) != 0;
2691                         IsMc = (FrameStat & GMR_FS_MC) != 0;
2692                         IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2693                                                         ((FrameStat & GMR_FS_RX_OK) == 0));
2694                 }
2695
2696                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2697                         ("Received frame of length %d on port %d\n",
2698                         FrameLength, PortIndex));
2699                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2700                         ("Number of free rx descriptors: %d\n",
2701                         pRxPort->RxdRingFree));
2702 /* DumpMsg(pMsg, "Rx"); */
2703
2704                 if ((Control & RX_CTRL_STAT_VALID) != RX_CTRL_STAT_VALID ||
2705                         (IsBadFrame)) {
2706 #if 0
2707                         (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2708 #endif
2709                         /* there is a receive error in this frame */
2710                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2711                                 SK_DBGCAT_DRV_RX_PROGRESS,
2712                                 ("skge: Error in received frame, dropped!\n"
2713                                 "Control: %x\nRxStat: %x\n",
2714                                 Control, FrameStat));
2715
2716                         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2717                         PhysAddr |= (SK_U64) pRxd->VDataLow;
2718                         pci_dma_sync_single(pAC->PciDev,
2719                                                 (dma_addr_t) PhysAddr,
2720                                                 FrameLength,
2721                                                 PCI_DMA_FROMDEVICE);
2722                         ReQueueRxBuffer(pAC, pRxPort, pMsg,
2723                                 pRxd->VDataHigh, pRxd->VDataLow);
2724
2725                         continue;
2726                 }
2727
2728                 /*
2729                  * if short frame then copy data to reduce memory waste
2730                  */
2731                 if ((FrameLength < SK_COPY_THRESHOLD) &&
2732                         ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2733                         /*
2734                          * Short frame detected and allocation successfull
2735                          */
2736                         /* use new skb and copy data */
2737                         skb_reserve(pNewMsg, 2);
2738                         skb_put(pNewMsg, FrameLength);
2739                         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2740                         PhysAddr |= (SK_U64) pRxd->VDataLow;
2741
2742                         pci_dma_sync_single(pAC->PciDev,
2743                                                 (dma_addr_t) PhysAddr,
2744                                                 FrameLength,
2745                                                 PCI_DMA_FROMDEVICE);
2746                         eth_copy_and_sum(pNewMsg, pMsg->data,
2747                                 FrameLength, 0);
2748                         ReQueueRxBuffer(pAC, pRxPort, pMsg,
2749                                 pRxd->VDataHigh, pRxd->VDataLow);
2750                         pMsg = pNewMsg;
2751
2752                 }
2753                 else {
2754                         /*
2755                          * if large frame, or SKB allocation failed, pass
2756                          * the SKB directly to the networking
2757                          */
2758
2759                         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2760                         PhysAddr |= (SK_U64) pRxd->VDataLow;
2761
2762                         /* release the DMA mapping */
2763                         pci_unmap_single(pAC->PciDev,
2764                                          PhysAddr,
2765                                          pAC->RxBufSize - 2,
2766                                          PCI_DMA_FROMDEVICE);
2767
2768                         /* set length in message */
2769                         skb_put(pMsg, FrameLength);
2770                         /* hardware checksum */
2771                         Type = ntohs(*((short*)&pMsg->data[12]));
2772                         if (Type == 0x800) {
2773                                 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2774                                 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2775 #if 0
2776                                 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2777                                         (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2778                                         (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2779                                         Result = SkCsGetReceiveInfo(pAC,
2780                                                 &pMsg->data[14], 
2781                                                 Csum1, Csum2, pRxPort->PortIndex);
2782                                         if (Result ==
2783                                                 SKCS_STATUS_IP_FRAGMENT ||
2784                                                 Result ==
2785                                                 SKCS_STATUS_IP_CSUM_OK ||
2786                                                 Result ==
2787                                                 SKCS_STATUS_TCP_CSUM_OK ||
2788                                                 Result ==
2789                                                 SKCS_STATUS_UDP_CSUM_OK) {
2790                                                         pMsg->ip_summed =
2791                                                         CHECKSUM_UNNECESSARY;
2792                                         } else {
2793                                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2794                                                 SK_DBGCAT_DRV_RX_PROGRESS,
2795                                                 ("skge: CRC error. Frame dropped!\n"));
2796                                                 goto rx_failed;
2797                                         }
2798                                 }/* checksumControl calculation valid */
2799 #endif
2800                         } /* IP frame */
2801                 } /* frame > SK_COPY_TRESHOLD */
2802                 
2803                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2804                 ForRlmt = SK_RLMT_RX_PROTOCOL;
2805 #if 0
2806                 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2807 #endif
2808                 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2809                         IsBc, &Offset, &NumBytes);
2810                 if (NumBytes != 0) {
2811 #if 0
2812                         IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2813 #endif
2814                         SK_RLMT_LOOKAHEAD(pAC, PortIndex, 
2815                                 &pMsg->data[Offset],
2816                                 IsBc, IsMc, &ForRlmt);
2817                 }
2818                 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2819                                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2820                         /* send up only frames from active port */
2821                         if ((PortIndex == pAC->ActivePort) ||
2822                                 (pAC->RlmtNets == 2)) {
2823                                 /* frame for upper layer */
2824                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2825 #ifdef xDEBUG
2826                                 DumpMsg(pMsg, "Rx");
2827 #endif
2828                                 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2829                                         FrameLength, pRxPort->PortIndex);
2830
2831 #if 0
2832                                 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2833                                 pMsg->protocol = eth_type_trans(pMsg,
2834                                         pAC->dev[pRxPort->PortIndex]);
2835                                 netif_rx(pMsg);
2836                                 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2837 #else
2838                                 NetReceive(pMsg->data, pMsg->len);
2839                                 dev_kfree_skb_any(pMsg);
2840 #endif
2841                         }
2842                         else {
2843                                 /* drop frame */
2844                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2845                                         SK_DBGCAT_DRV_RX_PROGRESS,
2846                                         ("D"));
2847                                 DEV_KFREE_SKB(pMsg);
2848                         }
2849                         
2850                 } /* if not for rlmt */
2851                 else {
2852                         /* packet for rlmt */
2853                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2854                                 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2855                         pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2856                                 pAC->IoBase, FrameLength);
2857                         if (pRlmtMbuf != NULL) {
2858                                 pRlmtMbuf->pNext = NULL;
2859                                 pRlmtMbuf->Length = FrameLength;
2860                                 pRlmtMbuf->PortIdx = PortIndex;
2861                                 EvPara.pParaPtr = pRlmtMbuf;
2862                                 memcpy((char*)(pRlmtMbuf->pData),
2863                                            (char*)(pMsg->data),
2864                                            FrameLength);
2865
2866                                 /* SlowPathLock needed? */
2867                                 if (SlowPathLock == SK_TRUE) {
2868                                         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2869                                         SkEventQueue(pAC, SKGE_RLMT,
2870                                                 SK_RLMT_PACKET_RECEIVED,
2871                                                 EvPara);
2872                                         pAC->CheckQueue = SK_TRUE;
2873                                         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2874                                 } else {
2875                                         SkEventQueue(pAC, SKGE_RLMT,
2876                                                 SK_RLMT_PACKET_RECEIVED,
2877                                                 EvPara);
2878                                         pAC->CheckQueue = SK_TRUE;
2879                                 }
2880
2881                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2882                                         SK_DBGCAT_DRV_RX_PROGRESS,
2883                                         ("Q"));
2884                         }
2885 #if 0
2886                         if ((pAC->dev[pRxPort->PortIndex]->flags & 
2887                                 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2888                                 (ForRlmt & SK_RLMT_RX_PROTOCOL) == 
2889                                 SK_RLMT_RX_PROTOCOL) { 
2890                                 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2891                                 pMsg->protocol = eth_type_trans(pMsg,
2892                                         pAC->dev[pRxPort->PortIndex]);
2893                                 netif_rx(pMsg);
2894                                 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2895                         }
2896 #else
2897                         if (0) {
2898                         }
2899 #endif
2900                         else {
2901                                 DEV_KFREE_SKB(pMsg);
2902                         }
2903
2904                 } /* if packet for rlmt */
2905         } /* for ... scanning the RXD ring */
2906
2907         /* RXD ring is empty -> fill and restart */
2908         FillRxRing(pAC, pRxPort);
2909         /* do not start if called from Close */
2910         if (pAC->BoardLevel > 0) {
2911                 ClearAndStartRx(pAC, PortIndex);
2912         }
2913         return;
2914
2915 rx_failed:
2916         /* remove error frame */
2917         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2918                 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2919
2920         /* release the DMA mapping */
2921
2922         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2923         PhysAddr |= (SK_U64) pRxd->VDataLow;
2924         pci_unmap_page(pAC->PciDev,
2925                          PhysAddr,
2926                          pAC->RxBufSize - 2,
2927                          PCI_DMA_FROMDEVICE);
2928         DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2929         pRxd->pMBuf = NULL;
2930         pRxPort->RxdRingFree++;
2931         pRxPort->pRxdRingHead = pRxd->pNextRxd;
2932         goto rx_start;
2933
2934 } /* ReceiveIrq */
2935
2936
2937 /*****************************************************************************
2938  *
2939  *      ClearAndStartRx - give a start receive command to BMU, clear IRQ
2940  *
2941  * Description:
2942  *      This function sends a start command and a clear interrupt
2943  *      command for one receive queue to the BMU.
2944  *
2945  * Returns: N/A
2946  *      none
2947  */
2948 static void ClearAndStartRx(
2949 SK_AC   *pAC,           /* pointer to the adapter context */
2950 int     PortIndex)      /* index of the receive port (XMAC) */
2951 {
2952         SK_OUT8(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CTRL,
2953                 RX_Q_CTRL_START | RX_Q_CTRL_CLR_I_EOF);
2954 } /* ClearAndStartRx */
2955
2956
2957 /*****************************************************************************
2958  *
2959  *      ClearTxIrq - give a clear transmit IRQ command to BMU
2960  *
2961  * Description:
2962  *      This function sends a clear tx IRQ command for one
2963  *      transmit queue to the BMU.
2964  *
2965  * Returns: N/A
2966  */
2967 static void ClearTxIrq(
2968 SK_AC   *pAC,           /* pointer to the adapter context */
2969 int     PortIndex,      /* index of the transmit port (XMAC) */
2970 int     Prio)           /* priority or normal queue */
2971 {
2972         SK_OUT8(pAC->IoBase, TxQueueAddr[PortIndex][Prio]+TX_Q_CTRL,
2973                 TX_Q_CTRL_CLR_I_EOF);
2974 } /* ClearTxIrq */
2975
2976
2977 /*****************************************************************************
2978  *
2979  *      ClearRxRing - remove all buffers from the receive ring
2980  *
2981  * Description:
2982  *      This function removes all receive buffers from the ring.
2983  *      The receive BMU must be stopped before calling this function.
2984  *
2985  * Returns: N/A
2986  */
2987 static void ClearRxRing(
2988 SK_AC   *pAC,           /* pointer to adapter context */
2989 RX_PORT *pRxPort)       /* pointer to rx port struct */
2990 {
2991 RXD             *pRxd;  /* pointer to the current descriptor */
2992 unsigned long   Flags;
2993 SK_U64          PhysAddr;
2994
2995         if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2996                 return;
2997         }
2998         spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2999         pRxd = pRxPort->pRxdRingHead;
3000         do {
3001                 if (pRxd->pMBuf != NULL) {
3002
3003                         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
3004                         PhysAddr |= (SK_U64) pRxd->VDataLow;
3005                         pci_unmap_page(pAC->PciDev,
3006                                          PhysAddr,
3007                                          pAC->RxBufSize - 2,
3008                                          PCI_DMA_FROMDEVICE);
3009                         DEV_KFREE_SKB(pRxd->pMBuf);
3010                         pRxd->pMBuf = NULL;
3011                 }
3012                 pRxd->RBControl &= RX_CTRL_OWN_BMU;
3013                 pRxd = pRxd->pNextRxd;
3014                 pRxPort->RxdRingFree++;
3015         } while (pRxd != pRxPort->pRxdRingTail);
3016         pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
3017         spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
3018 } /* ClearRxRing */
3019
3020
3021 /*****************************************************************************
3022  *
3023  *      ClearTxRing - remove all buffers from the transmit ring
3024  *
3025  * Description:
3026  *      This function removes all transmit buffers from the ring.
3027  *      The transmit BMU must be stopped before calling this function
3028  *      and transmitting at the upper level must be disabled.
3029  *      The BMU own bit of all descriptors is cleared, the rest is
3030  *      done by calling FreeTxDescriptors.
3031  *
3032  * Returns: N/A
3033  */
3034 static void ClearTxRing(
3035 SK_AC   *pAC,           /* pointer to adapter context */
3036 TX_PORT *pTxPort)       /* pointer to tx prt struct */
3037 {
3038 TXD             *pTxd;          /* pointer to the current descriptor */
3039 int             i;
3040 unsigned long   Flags;
3041
3042         spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
3043         pTxd = pTxPort->pTxdRingHead;
3044         for (i=0; i<pAC->TxDescrPerRing; i++) {
3045                 pTxd->TBControl &= ~TX_CTRL_OWN_BMU;
3046                 pTxd = pTxd->pNextTxd;
3047         }
3048         FreeTxDescriptors(pAC, pTxPort);
3049         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
3050 } /* ClearTxRing */
3051
3052
3053 #if 0
3054 /*****************************************************************************
3055  *
3056  *      SetQueueSizes - configure the sizes of rx and tx queues
3057  *
3058  * Description:
3059  *      This function assigns the sizes for active and passive port
3060  *      to the appropriate HWinit structure variables.
3061  *      The passive port(s) get standard values, all remaining RAM
3062  *      is given to the active port.
3063  *      The queue sizes are in kbyte and must be multiple of 8.
3064  *      The limits for the number of buffers filled into the rx rings
3065  *      is also set in this routine.
3066  *
3067  * Returns:
3068  *      none
3069  */
3070 static void SetQueueSizes(
3071 SK_AC   *pAC)   /* pointer to the adapter context */
3072 {
3073 int     StandbyRam;     /* adapter RAM used for a standby port */
3074 int     RemainingRam;   /* adapter RAM available for the active port */
3075 int     RxRam;          /* RAM used for the active port receive queue */
3076 int     i;              /* loop counter */
3077
3078 if (pAC->RlmtNets == 1) {
3079         StandbyRam = SK_RLMT_STANDBY_QRXSIZE + SK_RLMT_STANDBY_QXASIZE +
3080                 SK_RLMT_STANDBY_QXSSIZE;
3081         RemainingRam = pAC->GIni.GIRamSize - 
3082                 (pAC->GIni.GIMacsFound-1) * StandbyRam;
3083         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3084                 pAC->GIni.GP[i].PRxQSize = SK_RLMT_STANDBY_QRXSIZE;
3085                 pAC->GIni.GP[i].PXSQSize = SK_RLMT_STANDBY_QXSSIZE;
3086                 pAC->GIni.GP[i].PXAQSize = SK_RLMT_STANDBY_QXASIZE;
3087         }
3088         RxRam = (RemainingRam * 8 / 10) & ~7;
3089         pAC->GIni.GP[pAC->ActivePort].PRxQSize = RxRam;
3090         pAC->GIni.GP[pAC->ActivePort].PXSQSize = 0;
3091         pAC->GIni.GP[pAC->ActivePort].PXAQSize =
3092                 (RemainingRam - RxRam) & ~7;
3093         pAC->RxQueueSize = RxRam;
3094         pAC->TxSQueueSize = 0;
3095         pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
3096         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3097                 ("queue sizes settings - rx:%d  txA:%d txS:%d\n",
3098                 pAC->RxQueueSize,pAC->TxAQueueSize, pAC->TxSQueueSize));
3099 } else {
3100         RemainingRam = pAC->GIni.GIRamSize/pAC->GIni.GIMacsFound;
3101         RxRam = (RemainingRam * 8 / 10) & ~7;
3102         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3103                 pAC->GIni.GP[i].PRxQSize = RxRam;
3104                 pAC->GIni.GP[i].PXSQSize = 0;
3105                 pAC->GIni.GP[i].PXAQSize = (RemainingRam - RxRam) & ~7;
3106         }
3107         
3108         pAC->RxQueueSize = RxRam;
3109         pAC->TxSQueueSize = 0;
3110         pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
3111 }
3112         for (i=0; i<SK_MAX_MACS; i++) {
3113                 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing;
3114         }
3115
3116         if (pAC->RlmtNets == 2) {
3117                 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3118                         pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
3119                 }
3120         } else {
3121                 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3122                         pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
3123                 }
3124                 /*
3125                  * Do not set the Limit to 0, because this could cause
3126                  * wrap around with ReQueue'ed buffers (a buffer could
3127                  * be requeued in the same position, made accessable to
3128                  * the hardware, and the hardware could change its
3129                  * contents!
3130                  */
3131                 pAC->RxPort[pAC->ActivePort].RxFillLimit = 1;
3132         }
3133
3134 #ifdef DEBUG
3135         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3136                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
3137                         ("i: %d,  RxQSize: %d,  PXSQsize: %d, PXAQSize: %d\n",
3138                         i,
3139                         pAC->GIni.GP[i].PRxQSize,
3140                         pAC->GIni.GP[i].PXSQSize,
3141                         pAC->GIni.GP[i].PXAQSize));
3142         }
3143 #endif
3144 } /* SetQueueSizes */
3145
3146
3147 /*****************************************************************************
3148  *
3149  *      SkGeSetMacAddr - Set the hardware MAC address
3150  *
3151  * Description:
3152  *      This function sets the MAC address used by the adapter.
3153  *
3154  * Returns:
3155  *      0, if everything is ok
3156  *      !=0, on error
3157  */
3158 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
3159 {
3160
3161 DEV_NET *pNet = (DEV_NET*) dev->priv;
3162 SK_AC   *pAC = pNet->pAC;
3163
3164 struct sockaddr *addr = p;
3165 unsigned long   Flags;
3166         
3167         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3168                 ("SkGeSetMacAddr starts now...\n"));
3169         if(netif_running(dev))
3170                 return -EBUSY;
3171
3172         memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
3173         
3174         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3175
3176         if (pAC->RlmtNets == 2)
3177                 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
3178                         (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
3179         else
3180                 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
3181                         (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
3182
3183         
3184         
3185         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3186         return 0;
3187 } /* SkGeSetMacAddr */
3188 #endif
3189
3190
3191 /*****************************************************************************
3192  *
3193  *      SkGeSetRxMode - set receive mode
3194  *
3195  * Description:
3196  *      This function sets the receive mode of an adapter. The adapter
3197  *      supports promiscuous mode, allmulticast mode and a number of
3198  *      multicast addresses. If more multicast addresses the available
3199  *      are selected, a hash function in the hardware is used.
3200  *
3201  * Returns:
3202  *      0, if everything is ok
3203  *      !=0, on error
3204  */
3205 #if 0
3206 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
3207 {
3208
3209 DEV_NET         *pNet;
3210 SK_AC           *pAC;
3211
3212 struct dev_mc_list      *pMcList;
3213 int                     i;
3214 int                     PortIdx;
3215 unsigned long           Flags;
3216
3217         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3218                 ("SkGeSetRxMode starts now... "));
3219
3220         pNet = (DEV_NET*) dev->priv;
3221         pAC = pNet->pAC;
3222         if (pAC->RlmtNets == 1)
3223                 PortIdx = pAC->ActivePort;
3224         else
3225                 PortIdx = pNet->NetNr;
3226
3227         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3228         if (dev->flags & IFF_PROMISC) {
3229                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3230                         ("PROMISCUOUS mode\n"));
3231                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
3232                         SK_PROM_MODE_LLC);
3233         } else if (dev->flags & IFF_ALLMULTI) {
3234                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3235                         ("ALLMULTI mode\n"));
3236                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
3237                         SK_PROM_MODE_ALL_MC);
3238         } else {
3239                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
3240                         SK_PROM_MODE_NONE);
3241                 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
3242
3243                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3244                         ("Number of MC entries: %d ", dev->mc_count));
3245                 
3246                 pMcList = dev->mc_list;
3247                 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
3248                         SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
3249                                 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
3250                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
3251                                 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
3252                                 pMcList->dmi_addr[0],
3253                                 pMcList->dmi_addr[1],
3254                                 pMcList->dmi_addr[2],
3255                                 pMcList->dmi_addr[3],
3256                                 pMcList->dmi_addr[4],
3257                                 pMcList->dmi_addr[5]));
3258                 }
3259                 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
3260         }
3261         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3262         
3263         return;
3264 } /* SkGeSetRxMode */
3265
3266
3267 /*****************************************************************************
3268  *
3269  *      SkGeChangeMtu - set the MTU to another value
3270  *
3271  * Description:
3272  *      This function sets is called whenever the MTU size is changed
3273  *      (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
3274  *      ethernet MTU size, long frame support is activated.
3275  *
3276  * Returns:
3277  *      0, if everything is ok
3278  *      !=0, on error
3279  */
3280 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
3281 {
3282 DEV_NET         *pNet;
3283 DEV_NET         *pOtherNet;
3284 SK_AC           *pAC;
3285 unsigned long   Flags;
3286 int             i;
3287 SK_EVPARA       EvPara;
3288
3289         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3290                 ("SkGeChangeMtu starts now...\n"));
3291
3292         pNet = (DEV_NET*) dev->priv;
3293         pAC = pNet->pAC;
3294
3295         if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
3296                 return -EINVAL;
3297         }
3298
3299         if(pAC->BoardLevel != 2) {
3300                 return -EINVAL;
3301         }
3302
3303         pNet->Mtu = NewMtu;
3304         pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
3305         if ((pOtherNet->Mtu > 1500) && (NewMtu <= 1500) && (pOtherNet->Up==1)) {
3306                 return(0);
3307         }
3308
3309         EvPara.Para32[0] = pNet->NetNr;
3310         EvPara.Para32[1] = -1;
3311
3312         pAC->RxBufSize = NewMtu + 32;
3313         dev->mtu = NewMtu;
3314
3315         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3316                 ("New MTU: %d\n", NewMtu));
3317
3318         /* prevent reconfiguration while changing the MTU */
3319
3320         /* disable interrupts */
3321         SK_OUT32(pAC->IoBase, B0_IMSK, 0);
3322         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3323
3324         /* Found more than one port */
3325         if ((pAC->GIni.GIMacsFound == 2 ) && 
3326                 (pAC->RlmtNets == 2)) {
3327                         /* Stop both ports */
3328                         EvPara.Para32[0] = 0;
3329                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3330                         EvPara.Para32[0] = 1;
3331                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3332         } else {
3333                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3334         }
3335
3336         SkEventDispatcher(pAC, pAC->IoBase);
3337
3338         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3339                 spin_lock_irqsave(
3340                         &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
3341                 netif_stop_queue(pAC->dev[i]);
3342
3343         }
3344
3345         /* 
3346          * adjust number of rx buffers allocated
3347          */
3348         if (NewMtu > 1500) {
3349                 /* use less rx buffers */
3350                 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3351                         /* Found more than one port */
3352                         if ((pAC->GIni.GIMacsFound == 2 ) && 
3353                                 (pAC->RlmtNets == 2)) {
3354                                         pAC->RxPort[i].RxFillLimit = 
3355                                                 pAC->RxDescrPerRing - 100;
3356                         } else {
3357                                 if (i == pAC->ActivePort)
3358                                         pAC->RxPort[i].RxFillLimit =
3359                                                 pAC->RxDescrPerRing - 100;
3360                                 else
3361                                         pAC->RxPort[i].RxFillLimit =
3362                                                 pAC->RxDescrPerRing - 10;
3363                         }
3364                 }
3365         }
3366         else {
3367                 /* use normal amount of rx buffers */
3368                 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3369                         /* Found more than one port */
3370                         if ((pAC->GIni.GIMacsFound == 2 ) && 
3371                                 (pAC->RlmtNets == 2)) {
3372                                         pAC->RxPort[i].RxFillLimit = 1;
3373                         } else {
3374                                 if (i == pAC->ActivePort)
3375                                         pAC->RxPort[i].RxFillLimit = 1;
3376                                 else
3377                                         pAC->RxPort[i].RxFillLimit =
3378                                                 pAC->RxDescrPerRing - 100;
3379                         }
3380                 }
3381         }
3382          
3383         SkGeDeInit(pAC, pAC->IoBase); 
3384
3385         /* 
3386          * enable/disable hardware support for long frames
3387          */
3388         if (NewMtu > 1500) {
3389 //              pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
3390                 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
3391         }
3392         else {
3393                 if ((pAC->GIni.GIMacsFound == 2 ) && 
3394                         (pAC->RlmtNets == 2)) {
3395                         pAC->GIni.GIPortUsage = SK_MUL_LINK;
3396                 } else {
3397                         pAC->GIni.GIPortUsage = SK_RED_LINK;
3398                 }
3399         }
3400
3401         SkGeInit(   pAC, pAC->IoBase, 1);
3402         SkI2cInit(  pAC, pAC->IoBase, 1);
3403         SkEventInit(pAC, pAC->IoBase, 1);
3404         SkPnmiInit( pAC, pAC->IoBase, 1);
3405         SkAddrInit( pAC, pAC->IoBase, 1);
3406         SkRlmtInit( pAC, pAC->IoBase, 1);
3407         SkTimerInit(pAC, pAC->IoBase, 1);
3408         
3409         /*
3410          * tschilling:
3411          * Speed and others are set back to default in level 1 init!
3412          */
3413         GetConfiguration(pAC);
3414         
3415         SkGeInit(   pAC, pAC->IoBase, 2);
3416         SkI2cInit(  pAC, pAC->IoBase, 2);
3417         SkEventInit(pAC, pAC->IoBase, 2);
3418         SkPnmiInit( pAC, pAC->IoBase, 2);
3419         SkAddrInit( pAC, pAC->IoBase, 2);
3420         SkRlmtInit( pAC, pAC->IoBase, 2);
3421         SkTimerInit(pAC, pAC->IoBase, 2);
3422
3423         /* 
3424          * clear and reinit the rx rings here
3425          */
3426         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3427                 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
3428                 ClearRxRing(pAC, &pAC->RxPort[i]);
3429                 FillRxRing(pAC, &pAC->RxPort[i]);
3430
3431                 /* Enable transmit descriptor polling. */
3432                 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
3433                 FillRxRing(pAC, &pAC->RxPort[i]);
3434         };
3435
3436         SkGeYellowLED(pAC, pAC->IoBase, 1);
3437
3438 #ifdef USE_INT_MOD
3439         {
3440                 unsigned long ModBase;
3441                 ModBase = 53125000 / INTS_PER_SEC;
3442                 SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
3443                 SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
3444                 SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
3445         }
3446 #endif
3447
3448         netif_start_queue(pAC->dev[pNet->PortNr]);
3449         for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
3450                 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
3451         }
3452
3453         /* enable Interrupts */
3454         SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
3455         SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
3456
3457         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3458         SkEventDispatcher(pAC, pAC->IoBase);
3459
3460         /* Found more than one port */
3461         if ((pAC->GIni.GIMacsFound == 2 ) && 
3462                 (pAC->RlmtNets == 2)) {
3463                         /* Start both ports */
3464                         EvPara.Para32[0] = pAC->RlmtNets;
3465                         EvPara.Para32[1] = -1;
3466                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
3467                                 EvPara);
3468                         
3469                         
3470                         EvPara.Para32[1] = -1;
3471                         EvPara.Para32[0] = pNet->PortNr;
3472                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3473                         
3474                         if (pOtherNet->Up) {
3475                                 EvPara.Para32[0] = pOtherNet->PortNr;
3476                                 SkEventQueue(pAC, SKGE_RLMT, 
3477                                         SK_RLMT_START, EvPara);
3478                         }
3479         } else {
3480                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3481         }
3482
3483         SkEventDispatcher(pAC, pAC->IoBase);
3484         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3485         
3486         return 0;
3487 } /* SkGeChangeMtu */
3488
3489
3490 /*****************************************************************************
3491  *
3492  *      SkGeStats - return ethernet device statistics
3493  *
3494  * Description:
3495  *      This function return statistic data about the ethernet device
3496  *      to the operating system.
3497  *
3498  * Returns:
3499  *      pointer to the statistic structure.
3500  */
3501 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
3502 {
3503 DEV_NET *pNet = (DEV_NET*) dev->priv;
3504 SK_AC   *pAC = pNet->pAC;
3505 SK_PNMI_STRUCT_DATA *pPnmiStruct;       /* structure for all Pnmi-Data */
3506 SK_PNMI_STAT    *pPnmiStat;             /* pointer to virtual XMAC stat. data */
3507 SK_PNMI_CONF    *pPnmiConf;             /* pointer to virtual link config. */
3508 unsigned int    Size;                   /* size of pnmi struct */
3509 unsigned long   Flags;                  /* for spin lock */
3510
3511         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3512                 ("SkGeStats starts now...\n"));
3513         pPnmiStruct = &pAC->PnmiStruct;
3514         memset(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
3515         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3516         Size = SK_PNMI_STRUCT_SIZE;
3517                 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
3518         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3519         pPnmiStat = &pPnmiStruct->Stat[0];
3520         pPnmiConf = &pPnmiStruct->Conf[0];
3521
3522         pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
3523         pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
3524         pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
3525         pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
3526         
3527         if (pNet->Mtu <= 1500) {
3528                 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
3529         } else {
3530                 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
3531                         pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
3532         }
3533
3534
3535         if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
3536                 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
3537
3538         pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3539         pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
3540         pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
3541         pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
3542         pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3543
3544         /* detailed rx_errors: */
3545         pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
3546         pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3547         pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
3548         pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
3549         pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3550         pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
3551
3552         /* detailed tx_errors */
3553         pAC->stats.tx_aborted_errors = (SK_U32) 0;
3554         pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3555         pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
3556         pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3557         pAC->stats.tx_window_errors = (SK_U32) 0;
3558
3559         return(&pAC->stats);
3560 } /* SkGeStats */
3561
3562
3563 /*****************************************************************************
3564  *
3565  *      SkGeIoctl - IO-control function
3566  *
3567  * Description:
3568  *      This function is called if an ioctl is issued on the device.
3569  *      There are three subfunction for reading, writing and test-writing
3570  *      the private MIB data structure (usefull for SysKonnect-internal tools).
3571  *
3572  * Returns:
3573  *      0, if everything is ok
3574  *      !=0, on error
3575  */
3576 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
3577 {
3578 DEV_NET         *pNet;
3579 SK_AC           *pAC;
3580
3581 SK_GE_IOCTL     Ioctl;
3582 unsigned int    Err = 0;
3583 int             Size;
3584
3585         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3586                 ("SkGeIoctl starts now...\n"));
3587
3588         pNet = (DEV_NET*) dev->priv;
3589         pAC = pNet->pAC;
3590         
3591         if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
3592                 return -EFAULT;
3593         }
3594
3595         switch(cmd) {
3596         case SK_IOCTL_SETMIB:
3597         case SK_IOCTL_PRESETMIB:
3598                 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3599         case SK_IOCTL_GETMIB:
3600                 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData, 
3601                         Ioctl.Len<sizeof(pAC->PnmiStruct)?
3602                         Ioctl.Len : sizeof(pAC->PnmiStruct))) {
3603                         return -EFAULT;
3604                 }
3605                 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
3606                 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
3607                         Ioctl.Len<Size? Ioctl.Len : Size)) {
3608                         return -EFAULT;
3609                 }
3610                 Ioctl.Len = Size;
3611                 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3612                         return -EFAULT;
3613                 }
3614                 break;
3615         default:
3616                 Err = -EOPNOTSUPP;
3617         }
3618         return(Err);
3619 } /* SkGeIoctl */
3620
3621
3622 /*****************************************************************************
3623  *
3624  *      SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3625  *
3626  * Description:
3627  *      This function reads/writes the MIB data using PNMI (Private Network
3628  *      Management Interface).
3629  *      The destination for the data must be provided with the
3630  *      ioctl call and is given to the driver in the form of
3631  *      a user space address.
3632  *      Copying from the user-provided data area into kernel messages
3633  *      and back is done by copy_from_user and copy_to_user calls in
3634  *      SkGeIoctl.
3635  *
3636  * Returns:
3637  *      returned size from PNMI call
3638  */
3639 static int SkGeIocMib(
3640 DEV_NET         *pNet,  /* pointer to the adapter context */
3641 unsigned int    Size,   /* length of ioctl data */
3642 int             mode)   /* flag for set/preset */
3643 {
3644 unsigned long   Flags;  /* for spin lock */
3645 SK_AC           *pAC;
3646
3647         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3648                 ("SkGeIocMib starts now...\n"));
3649         pAC = pNet->pAC;
3650         /* access MIB */
3651         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3652         switch(mode) {
3653         case SK_IOCTL_GETMIB:
3654                 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3655                         pNet->NetNr);
3656                 break;
3657         case SK_IOCTL_PRESETMIB:
3658                 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3659                         pNet->NetNr);
3660                 break;
3661         case SK_IOCTL_SETMIB:
3662                 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3663                         pNet->NetNr);
3664                 break;
3665         default:
3666                 break;
3667         }
3668         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3669         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3670                 ("MIB data access succeeded\n"));
3671         return (Size);
3672 } /* SkGeIocMib */
3673 #endif
3674
3675
3676 /*****************************************************************************
3677  *
3678  *      GetConfiguration - read configuration information
3679  *
3680  * Description:
3681  *      This function reads per-adapter configuration information from
3682  *      the options provided on the command line.
3683  *
3684  * Returns:
3685  *      none
3686  */
3687 static void GetConfiguration(
3688 SK_AC   *pAC)   /* pointer to the adapter context structure */
3689 {
3690 SK_I32  Port;           /* preferred port */
3691 int     LinkSpeed;      /* Link speed */
3692 int     AutoNeg;        /* auto negotiation off (0) or on (1) */
3693 int     DuplexCap;      /* duplex capabilities (0=both, 1=full, 2=half */
3694 int     MSMode;         /* master / slave mode selection */
3695 SK_BOOL AutoSet;
3696 SK_BOOL DupSet;
3697 /*
3698  *      The two parameters AutoNeg. and DuplexCap. map to one configuration
3699  *      parameter. The mapping is described by this table:
3700  *      DuplexCap ->    |       both    |       full    |       half    |
3701  *      AutoNeg         |               |               |               |
3702  *      -----------------------------------------------------------------
3703  *      Off             |    illegal    |       Full    |       Half    |
3704  *      -----------------------------------------------------------------
3705  *      On              |   AutoBoth    |   AutoFull    |   AutoHalf    |
3706  *      -----------------------------------------------------------------
3707  *      Sense           |   AutoSense   |   AutoSense   |   AutoSense   |
3708  */
3709 int     Capabilities[3][3] = 
3710                 { {               -1, SK_LMODE_FULL,     SK_LMODE_HALF}, 
3711                   {SK_LMODE_AUTOBOTH, SK_LMODE_AUTOFULL, SK_LMODE_AUTOHALF},
3712                   {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3713 #define DC_BOTH 0
3714 #define DC_FULL 1
3715 #define DC_HALF 2
3716 #define AN_OFF  0
3717 #define AN_ON   1
3718 #define AN_SENS 2
3719
3720         /* settings for port A */
3721         /* settings link speed */
3722         LinkSpeed = SK_LSPEED_AUTO;     /* default: do auto select */
3723         if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3724                 Speed_A[pAC->Index] != NULL) {
3725                 if (strcmp(Speed_A[pAC->Index],"")==0) {
3726                         LinkSpeed = SK_LSPEED_AUTO;
3727                 }
3728                 else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3729                         LinkSpeed = SK_LSPEED_AUTO;
3730                 }
3731                 else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3732                         LinkSpeed = SK_LSPEED_10MBPS;
3733                 }
3734                 else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3735                         LinkSpeed = SK_LSPEED_100MBPS;
3736                 }
3737                 else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3738                         LinkSpeed = SK_LSPEED_1000MBPS;
3739                 }
3740                 else printk("%s: Illegal value for Speed_A\n",
3741                         pAC->dev[0]->name);
3742         }
3743
3744         /* Check speed parameter */
3745         /* Only copper type adapter and GE V2 cards */
3746         if (((pAC->GIni.GIChipId != CHIP_ID_YUKON) ||
3747                 (pAC->GIni.GICopperType != SK_TRUE)) &&
3748                 ((LinkSpeed != SK_LSPEED_AUTO) && 
3749                 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3750                 printk("%s: Illegal value for Speed_A. "
3751                         "Not a copper card or GE V2 card\n    Using "
3752                         "speed 1000\n", pAC->dev[0]->name);
3753                 LinkSpeed = SK_LSPEED_1000MBPS;
3754         }
3755         pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3756
3757         /* Autonegotiation */
3758         AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3759         AutoSet = SK_FALSE;
3760         if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3761                 AutoNeg_A[pAC->Index] != NULL) {
3762                 AutoSet = SK_TRUE;
3763                 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3764                         AutoSet = SK_FALSE;
3765                 }
3766                 else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3767                         AutoNeg = AN_ON;
3768                 }
3769                 else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3770                         AutoNeg = AN_OFF;
3771                 }
3772                 else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3773                         AutoNeg = AN_SENS;
3774                 }
3775                 else printk("%s: Illegal value for AutoNeg_A\n",
3776                         pAC->dev[0]->name);
3777         }
3778
3779         DuplexCap = DC_BOTH;
3780         DupSet = SK_FALSE;
3781         if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3782                 DupCap_A[pAC->Index] != NULL) {
3783                 DupSet = SK_TRUE;
3784                 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3785                         DupSet = SK_FALSE;
3786                 }
3787                 else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3788                         DuplexCap = DC_BOTH;
3789                 }
3790                 else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3791                         DuplexCap = DC_FULL;
3792                 }
3793                 else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3794                         DuplexCap = DC_HALF;
3795                 }
3796                 else printk("%s: Illegal value for DupCap_A\n",
3797                         pAC->dev[0]->name);
3798         }
3799         
3800         /* check for illegal combinations */
3801         if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3802                 printk("%s, Port A: DuplexCapabilities"
3803                         " ignored using Sense mode\n", pAC->dev[0]->name);
3804         }
3805         if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3806                 printk("%s, Port A: Illegal combination"
3807                         " of values AutoNeg. and DuplexCap.\n    Using "
3808                         "Full Duplex\n", pAC->dev[0]->name);
3809
3810                 DuplexCap = DC_FULL;
3811         }
3812         if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3813                 DuplexCap = DC_FULL;
3814         }
3815         
3816         if (!AutoSet && DupSet) {
3817                 printk("%s, Port A: Duplex setting not"
3818                         " possible in\n    default AutoNegotiation mode"
3819                         " (Sense).\n    Using AutoNegotiation On\n",
3820                         pAC->dev[0]->name);
3821                 AutoNeg = AN_ON;
3822         }
3823         
3824         /* set the desired mode */
3825         pAC->GIni.GP[0].PLinkModeConf =
3826                 Capabilities[AutoNeg][DuplexCap];
3827         
3828         pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3829         if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3830                 FlowCtrl_A[pAC->Index] != NULL) {
3831                 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3832                 }
3833                 else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3834                         pAC->GIni.GP[0].PFlowCtrlMode =
3835                                 SK_FLOW_MODE_SYM_OR_REM;
3836                 }
3837                 else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3838                         pAC->GIni.GP[0].PFlowCtrlMode =
3839                                 SK_FLOW_MODE_SYMMETRIC;
3840                 }
3841                 else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3842                         pAC->GIni.GP[0].PFlowCtrlMode =
3843                                 SK_FLOW_MODE_LOC_SEND;
3844                 }
3845                 else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3846                         pAC->GIni.GP[0].PFlowCtrlMode =
3847                                 SK_FLOW_MODE_NONE;
3848                 }
3849                 else printk("Illegal value for FlowCtrl_A\n");
3850         }
3851         if (AutoNeg==AN_OFF && pAC->GIni.GP[0].PFlowCtrlMode!=
3852                 SK_FLOW_MODE_NONE) {
3853                 printk("%s, Port A: FlowControl"
3854                         " impossible without AutoNegotiation,"
3855                         " disabled\n", pAC->dev[0]->name);
3856                 pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_NONE;
3857         }
3858
3859         MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
3860         if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3861                 Role_A[pAC->Index] != NULL) {
3862                 if (strcmp(Role_A[pAC->Index],"")==0) {
3863                 }
3864                 else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3865                         MSMode = SK_MS_MODE_AUTO;
3866                 }
3867                 else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3868                         MSMode = SK_MS_MODE_MASTER;
3869                 }
3870                 else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3871                         MSMode = SK_MS_MODE_SLAVE;
3872                 }
3873                 else printk("%s: Illegal value for Role_A\n",
3874                         pAC->dev[0]->name);
3875         }
3876         pAC->GIni.GP[0].PMSMode = MSMode;
3877         
3878         
3879         /* settings for port B */
3880         /* settings link speed */
3881         LinkSpeed = SK_LSPEED_AUTO;     /* default: do auto select */
3882         if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3883                 Speed_B[pAC->Index] != NULL) {
3884                 if (strcmp(Speed_B[pAC->Index],"")==0) {
3885                         LinkSpeed = SK_LSPEED_AUTO;
3886                 }
3887                 else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3888                         LinkSpeed = SK_LSPEED_AUTO;
3889                 }
3890                 else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3891                         LinkSpeed = SK_LSPEED_10MBPS;
3892                 }
3893                 else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3894                         LinkSpeed = SK_LSPEED_100MBPS;
3895                 }
3896                 else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3897                         LinkSpeed = SK_LSPEED_1000MBPS;
3898                 }
3899                 else printk("%s: Illegal value for Speed_B\n",
3900                         pAC->dev[1]->name);
3901         }
3902
3903         /* Check speed parameter */
3904         /* Only copper type adapter and GE V2 cards */
3905         if (((pAC->GIni.GIChipId != CHIP_ID_YUKON) ||
3906                 (pAC->GIni.GICopperType != SK_TRUE)) &&
3907                 ((LinkSpeed != SK_LSPEED_AUTO) && 
3908                 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3909                 printk("%s: Illegal value for Speed_B. "
3910                         "Not a copper card or GE V2 card\n    Using "
3911                         "speed 1000\n", pAC->dev[1]->name);
3912                 LinkSpeed = SK_LSPEED_1000MBPS;
3913         }
3914         pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3915
3916         /* Auto negotiation */
3917         AutoNeg = AN_SENS; /* default: do auto Sense */
3918         AutoSet = SK_FALSE;
3919         if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3920                 AutoNeg_B[pAC->Index] != NULL) {
3921                 AutoSet = SK_TRUE;
3922                 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3923                         AutoSet = SK_FALSE;
3924                 }
3925                 else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3926                         AutoNeg = AN_ON;
3927                 }
3928                 else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3929                         AutoNeg = AN_OFF;
3930                 }
3931                 else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3932                         AutoNeg = AN_SENS;
3933                 }
3934                 else printk("Illegal value for AutoNeg_B\n");
3935         }
3936
3937         DuplexCap = DC_BOTH;
3938         DupSet = SK_FALSE;
3939         if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3940                 DupCap_B[pAC->Index] != NULL) {
3941                 DupSet = SK_TRUE;
3942                 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3943                         DupSet = SK_FALSE;
3944                 }
3945                 else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3946                         DuplexCap = DC_BOTH;
3947                 }
3948                 else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3949                         DuplexCap = DC_FULL;
3950                 }
3951                 else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3952                         DuplexCap = DC_HALF;
3953                 }
3954                 else printk("Illegal value for DupCap_B\n");
3955         }
3956         
3957         /* check for illegal combinations */
3958         if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3959                 printk("%s, Port B: DuplexCapabilities"
3960                         " ignored using Sense mode\n", pAC->dev[1]->name);
3961         }
3962         if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3963                 printk("%s, Port B: Illegal combination"
3964                         " of values AutoNeg. and DuplexCap.\n    Using "
3965                         "Full Duplex\n", pAC->dev[1]->name);
3966
3967                 DuplexCap = DC_FULL;
3968         }
3969         if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3970                 DuplexCap = DC_FULL;
3971         }
3972         
3973         if (!AutoSet && DupSet) {
3974                 printk("%s, Port B: Duplex setting not"
3975                         " possible in\n    default AutoNegotiation mode"
3976                         " (Sense).\n    Using AutoNegotiation On\n",
3977                         pAC->dev[1]->name);
3978                 AutoNeg = AN_ON;
3979         }
3980
3981         /* set the desired mode */
3982         pAC->GIni.GP[1].PLinkModeConf =
3983                 Capabilities[AutoNeg][DuplexCap];
3984
3985         pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3986         if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3987                 FlowCtrl_B[pAC->Index] != NULL) {
3988                 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3989                 }
3990                 else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3991                         pAC->GIni.GP[1].PFlowCtrlMode =
3992                                 SK_FLOW_MODE_SYM_OR_REM;
3993                 }
3994                 else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3995                         pAC->GIni.GP[1].PFlowCtrlMode =
3996                                 SK_FLOW_MODE_SYMMETRIC;
3997                 }
3998                 else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3999                         pAC->GIni.GP[1].PFlowCtrlMode =
4000                                 SK_FLOW_MODE_LOC_SEND;
4001                 }
4002                 else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
4003                         pAC->GIni.GP[1].PFlowCtrlMode =
4004                                 SK_FLOW_MODE_NONE;
4005                 }
4006                 else printk("Illegal value for FlowCtrl_B\n");
4007         }
4008         if (AutoNeg==AN_OFF && pAC->GIni.GP[1].PFlowCtrlMode!=
4009                 SK_FLOW_MODE_NONE) {
4010                 printk("%s, Port B: FlowControl"
4011                         " impossible without AutoNegotiation,"
4012                         " disabled\n", pAC->dev[1]->name);
4013                 pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_NONE;
4014         }
4015
4016         MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
4017         if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4018                 Role_B[pAC->Index] != NULL) {
4019                 if (strcmp(Role_B[pAC->Index],"")==0) {
4020                 }
4021                 else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
4022                         MSMode = SK_MS_MODE_AUTO;
4023                 }
4024                 else if (strcmp(Role_B[pAC->Index],"Master")==0) {
4025                         MSMode = SK_MS_MODE_MASTER;
4026                 }
4027                 else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
4028                         MSMode = SK_MS_MODE_SLAVE;
4029                 }
4030                 else printk("%s: Illegal value for Role_B\n",
4031                         pAC->dev[1]->name);
4032         }
4033         pAC->GIni.GP[1].PMSMode = MSMode;
4034         
4035         
4036         /* settings for both ports */
4037         pAC->ActivePort = 0;
4038         if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4039                 PrefPort[pAC->Index] != NULL) {
4040                 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
4041                         pAC->ActivePort = 0;
4042                         pAC->Rlmt.Net[0].Preference = -1; /* auto */
4043                         pAC->Rlmt.Net[0].PrefPort = 0;
4044                 }
4045                 else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
4046                         /*
4047                          * do not set ActivePort here, thus a port
4048                          * switch is issued after net up.
4049                          */
4050                         Port = 0;
4051                         pAC->Rlmt.Net[0].Preference = Port;
4052                         pAC->Rlmt.Net[0].PrefPort = Port;
4053                 }
4054                 else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
4055                         /*
4056                          * do not set ActivePort here, thus a port
4057                          * switch is issued after net up.
4058                          */
4059                         Port = 1;
4060                         pAC->Rlmt.Net[0].Preference = Port;
4061                         pAC->Rlmt.Net[0].PrefPort = Port;
4062                 }
4063                 else printk("%s: Illegal value for PrefPort\n",
4064                         pAC->dev[0]->name);
4065         }
4066
4067         pAC->RlmtNets = 1;
4068
4069         if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4070                 RlmtMode[pAC->Index] != NULL) {
4071                 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
4072                         pAC->RlmtMode = 0;
4073                 }
4074                 else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
4075                         pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4076                 }
4077                 else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
4078                         pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4079                                 SK_RLMT_CHECK_LOC_LINK;
4080                 }
4081                 else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
4082                         pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4083                                 SK_RLMT_CHECK_LOC_LINK | 
4084                                 SK_RLMT_CHECK_SEG;
4085                 }
4086                 else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
4087                         (pAC->GIni.GIMacsFound == 2)) {
4088                                 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4089                                 pAC->RlmtNets = 2;
4090                 }
4091                 else {
4092                         printk("%s: Illegal value for"
4093                                 " RlmtMode, using default\n", pAC->dev[0]->name);
4094                         pAC->RlmtMode = 0;
4095                 }
4096         }
4097         else {
4098                 pAC->RlmtMode = 0;
4099         }
4100 } /* GetConfiguration */
4101
4102
4103 /*****************************************************************************
4104  *
4105  *      ProductStr - return a adapter identification string from vpd
4106  *
4107  * Description:
4108  *      This function reads the product name string from the vpd area
4109  *      and puts it the field pAC->DeviceString.
4110  *
4111  * Returns: N/A
4112  */
4113 static void ProductStr(
4114 SK_AC   *pAC            /* pointer to adapter context */
4115 )
4116 {
4117 int     StrLen = 80;            /* length of the string, defined in SK_AC */
4118 char    Keyword[] = VPD_NAME;   /* vpd productname identifier */
4119 int     ReturnCode;             /* return code from vpd_read */
4120 unsigned long Flags;
4121
4122         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
4123         ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
4124                 &StrLen);
4125         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
4126         if (ReturnCode != 0) {
4127                 /* there was an error reading the vpd data */
4128                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
4129                         ("Error reading VPD data: %d\n", ReturnCode));
4130                 pAC->DeviceStr[0] = '\0';
4131         }
4132 } /* ProductStr */
4133
4134
4135
4136
4137 /****************************************************************************/
4138 /* functions for common modules *********************************************/
4139 /****************************************************************************/
4140
4141
4142 /*****************************************************************************
4143  *
4144  *      SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
4145  *
4146  * Description:
4147  *      This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
4148  *      is embedded into a socket buff data area.
4149  *
4150  * Context:
4151  *      runtime
4152  *
4153  * Returns:
4154  *      NULL or pointer to Mbuf.
4155  */
4156 SK_MBUF *SkDrvAllocRlmtMbuf(
4157 SK_AC           *pAC,           /* pointer to adapter context */
4158 SK_IOC          IoC,            /* the IO-context */
4159 unsigned        BufferSize)     /* size of the requested buffer */
4160 {
4161 SK_MBUF         *pRlmtMbuf;     /* pointer to a new rlmt-mbuf structure */
4162 struct sk_buff  *pMsgBlock;     /* pointer to a new message block */
4163
4164         pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
4165         if (pMsgBlock == NULL) {
4166                 return (NULL);
4167         }
4168         pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
4169         skb_reserve(pMsgBlock, sizeof(SK_MBUF));
4170         pRlmtMbuf->pNext = NULL;
4171         pRlmtMbuf->pOs = pMsgBlock;
4172         pRlmtMbuf->pData = pMsgBlock->data;     /* Data buffer. */
4173         pRlmtMbuf->Size = BufferSize;           /* Data buffer size. */
4174         pRlmtMbuf->Length = 0;          /* Length of packet (<= Size). */
4175         return (pRlmtMbuf);
4176
4177 } /* SkDrvAllocRlmtMbuf */
4178
4179
4180 /*****************************************************************************
4181  *
4182  *      SkDrvFreeRlmtMbuf - free an RLMT mbuf
4183  *
4184  * Description:
4185  *      This routine frees one or more RLMT mbuf(s).
4186  *
4187  * Context:
4188  *      runtime
4189  *
4190  * Returns:
4191  *      Nothing
4192  */
4193 void  SkDrvFreeRlmtMbuf(
4194 SK_AC           *pAC,           /* pointer to adapter context */  
4195 SK_IOC          IoC,            /* the IO-context */              
4196 SK_MBUF         *pMbuf)         /* size of the requested buffer */
4197 {
4198 SK_MBUF         *pFreeMbuf;
4199 SK_MBUF         *pNextMbuf;
4200
4201         pFreeMbuf = pMbuf;
4202         do {
4203                 pNextMbuf = pFreeMbuf->pNext;
4204                 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
4205                 pFreeMbuf = pNextMbuf;
4206         } while ( pFreeMbuf != NULL );
4207 } /* SkDrvFreeRlmtMbuf */
4208
4209
4210 /*****************************************************************************
4211  *
4212  *      SkOsGetTime - provide a time value
4213  *
4214  * Description:
4215  *      This routine provides a time value. The unit is 1/HZ (defined by Linux).
4216  *      It is not used for absolute time, but only for time differences.
4217  *
4218  *
4219  * Returns:
4220  *      Time value
4221  */
4222 SK_U64 SkOsGetTime(SK_AC *pAC)
4223 {
4224 #if 0
4225         return jiffies;
4226 #else
4227         return get_timer(0);
4228 #endif
4229 } /* SkOsGetTime */
4230
4231
4232 /*****************************************************************************
4233  *
4234  *      SkPciReadCfgDWord - read a 32 bit value from pci config space
4235  *
4236  * Description:
4237  *      This routine reads a 32 bit value from the pci configuration
4238  *      space.
4239  *
4240  * Returns:
4241  *      0 - indicate everything worked ok.
4242  *      != 0 - error indication
4243  */
4244 int SkPciReadCfgDWord(
4245 SK_AC *pAC,             /* Adapter Control structure pointer */
4246 int PciAddr,            /* PCI register address */
4247 SK_U32 *pVal)           /* pointer to store the read value */
4248 {
4249         pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4250         return(0);
4251 } /* SkPciReadCfgDWord */
4252
4253
4254 /*****************************************************************************
4255  *
4256  *      SkPciReadCfgWord - read a 16 bit value from pci config space
4257  *
4258  * Description:
4259  *      This routine reads a 16 bit value from the pci configuration
4260  *      space.
4261  *
4262  * Returns:
4263  *      0 - indicate everything worked ok.
4264  *      != 0 - error indication
4265  */
4266 int SkPciReadCfgWord(
4267 SK_AC *pAC,     /* Adapter Control structure pointer */
4268 int PciAddr,            /* PCI register address */
4269 SK_U16 *pVal)           /* pointer to store the read value */
4270 {
4271         pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4272         return(0);
4273 } /* SkPciReadCfgWord */
4274
4275
4276 /*****************************************************************************
4277  *
4278  *      SkPciReadCfgByte - read a 8 bit value from pci config space
4279  *
4280  * Description:
4281  *      This routine reads a 8 bit value from the pci configuration
4282  *      space.
4283  *
4284  * Returns:
4285  *      0 - indicate everything worked ok.
4286  *      != 0 - error indication
4287  */
4288 int SkPciReadCfgByte(
4289 SK_AC *pAC,     /* Adapter Control structure pointer */
4290 int PciAddr,            /* PCI register address */
4291 SK_U8 *pVal)            /* pointer to store the read value */
4292 {
4293         pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4294         return(0);
4295 } /* SkPciReadCfgByte */
4296
4297
4298 /*****************************************************************************
4299  *
4300  *      SkPciWriteCfgDWord - write a 32 bit value to pci config space
4301  *
4302  * Description:
4303  *      This routine writes a 32 bit value to the pci configuration
4304  *      space.
4305  *
4306  * Returns:
4307  *      0 - indicate everything worked ok.
4308  *      != 0 - error indication
4309  */
4310 int SkPciWriteCfgDWord(
4311 SK_AC *pAC,     /* Adapter Control structure pointer */
4312 int PciAddr,            /* PCI register address */
4313 SK_U32 Val)             /* pointer to store the read value */
4314 {
4315         pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4316         return(0);
4317 } /* SkPciWriteCfgDWord */
4318
4319
4320 /*****************************************************************************
4321  *
4322  *      SkPciWriteCfgWord - write a 16 bit value to pci config space
4323  *
4324  * Description:
4325  *      This routine writes a 16 bit value to the pci configuration
4326  *      space. The flag PciConfigUp indicates whether the config space
4327  *      is accesible or must be set up first.
4328  *
4329  * Returns:
4330  *      0 - indicate everything worked ok.
4331  *      != 0 - error indication
4332  */
4333 int SkPciWriteCfgWord(
4334 SK_AC *pAC,     /* Adapter Control structure pointer */
4335 int PciAddr,            /* PCI register address */
4336 SK_U16 Val)             /* pointer to store the read value */
4337 {
4338         pci_write_config_word(pAC->PciDev, PciAddr, Val);
4339         return(0);
4340 } /* SkPciWriteCfgWord */
4341
4342
4343 /*****************************************************************************
4344  *
4345  *      SkPciWriteCfgWord - write a 8 bit value to pci config space
4346  *
4347  * Description:
4348  *      This routine writes a 8 bit value to the pci configuration
4349  *      space. The flag PciConfigUp indicates whether the config space
4350  *      is accesible or must be set up first.
4351  *
4352  * Returns:
4353  *      0 - indicate everything worked ok.
4354  *      != 0 - error indication
4355  */
4356 int SkPciWriteCfgByte(
4357 SK_AC *pAC,     /* Adapter Control structure pointer */
4358 int PciAddr,            /* PCI register address */
4359 SK_U8 Val)              /* pointer to store the read value */
4360 {
4361         pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4362         return(0);
4363 } /* SkPciWriteCfgByte */
4364
4365
4366 /*****************************************************************************
4367  *
4368  *      SkDrvEvent - handle driver events
4369  *
4370  * Description:
4371  *      This function handles events from all modules directed to the driver
4372  *
4373  * Context:
4374  *      Is called under protection of slow path lock.
4375  *
4376  * Returns:
4377  *      0 if everything ok
4378  *      < 0  on error
4379  *      
4380  */
4381 int SkDrvEvent(
4382 SK_AC *pAC,             /* pointer to adapter context */
4383 SK_IOC IoC,             /* io-context */
4384 SK_U32 Event,           /* event-id */
4385 SK_EVPARA Param)        /* event-parameter */
4386 {
4387 SK_MBUF         *pRlmtMbuf;     /* pointer to a rlmt-mbuf structure */
4388 struct sk_buff  *pMsg;          /* pointer to a message block */
4389 int             FromPort;       /* the port from which we switch away */
4390 int             ToPort;         /* the port we switch to */
4391 SK_EVPARA       NewPara;        /* parameter for further events */
4392 #if 0
4393 int             Stat;
4394 #endif
4395 unsigned long   Flags;
4396 SK_BOOL         DualNet;
4397
4398         switch (Event) {
4399         case SK_DRV_ADAP_FAIL:
4400                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4401                         ("ADAPTER FAIL EVENT\n"));
4402                 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4403                 /* disable interrupts */
4404                 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4405                 /* cgoos */
4406                 break;
4407         case SK_DRV_PORT_FAIL:
4408                 FromPort = Param.Para32[0];
4409                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4410                         ("PORT FAIL EVENT, Port: %d\n", FromPort));
4411                 if (FromPort == 0) {
4412                         printk("%s: Port A failed.\n", pAC->dev[0]->name);
4413                 } else {
4414                         printk("%s: Port B failed.\n", pAC->dev[1]->name);
4415                 }
4416                 /* cgoos */
4417                 break;
4418         case SK_DRV_PORT_RESET:  /* SK_U32 PortIdx */
4419                 /* action list 4 */
4420                 FromPort = Param.Para32[0];
4421                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4422                         ("PORT RESET EVENT, Port: %d ", FromPort));
4423                 NewPara.Para64 = FromPort;
4424                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4425                 spin_lock_irqsave(
4426                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4427                         Flags);
4428                 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4429 #if 0
4430                 pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
4431 #endif
4432                 spin_unlock_irqrestore(
4433                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4434                         Flags);
4435                 
4436                 /* clear rx ring from received frames */
4437                 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4438                 
4439                 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4440                 spin_lock_irqsave(
4441                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4442                         Flags);
4443                 
4444                 /* tschilling: Handling of return value inserted. */
4445                 if (SkGeInitPort(pAC, IoC, FromPort)) {
4446                         if (FromPort == 0) {
4447                                 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4448                         } else {
4449                                 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4450                         }
4451                 }
4452                 SkAddrMcUpdate(pAC,IoC, FromPort);
4453                 PortReInitBmu(pAC, FromPort);
4454                 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4455                 ClearAndStartRx(pAC, FromPort);
4456                 spin_unlock_irqrestore(
4457                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4458                         Flags);
4459                 break;
4460         case SK_DRV_NET_UP:      /* SK_U32 PortIdx */
4461                 /* action list 5 */
4462                 FromPort = Param.Para32[0];
4463                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4464                         ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4465 #ifdef SK98_INFO
4466                 printk("%s: network connection up using"
4467                         " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4468
4469                 /* tschilling: Values changed according to LinkSpeedUsed. */
4470                 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4471                 if (Stat == SK_LSPEED_STAT_10MBPS) {
4472                         printk("    speed:           10\n");
4473                 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4474                         printk("    speed:           100\n");
4475                 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4476                         printk("    speed:           1000\n");
4477                 } else {
4478                         printk("    speed:           unknown\n");
4479                 }
4480
4481                 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4482                 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4483                         Stat == SK_LMODE_STAT_AUTOFULL) {
4484                         printk("    autonegotiation: yes\n");
4485                 }
4486                 else {
4487                         printk("    autonegotiation: no\n");
4488                 }
4489                 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4490                         Stat == SK_LMODE_STAT_HALF) {
4491                         printk("    duplex mode:     half\n");
4492                 }
4493                 else {
4494                         printk("    duplex mode:     full\n");
4495                 }
4496                 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4497                 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4498                         printk("    flowctrl:        remote send\n");
4499                 }
4500                 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4501                         printk("    flowctrl:        local send\n");
4502                 }
4503                 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4504                         printk("    flowctrl:        symmetric\n");
4505                 }
4506                 else {
4507                         printk("    flowctrl:        none\n");
4508                 }
4509                 
4510                 /* tschilling: Check against CopperType now. */
4511                 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4512                         (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4513                         SK_LSPEED_STAT_1000MBPS)) {
4514                         Stat = pAC->GIni.GP[FromPort].PMSStatus;
4515                         if (Stat == SK_MS_STAT_MASTER ) {
4516                                 printk("    role:            master\n");
4517                         }
4518                         else if (Stat == SK_MS_STAT_SLAVE ) {
4519                                 printk("    role:            slave\n");
4520                         }
4521                         else {
4522                                 printk("    role:            ???\n");
4523                         }
4524                 }
4525
4526 #ifdef SK_ZEROCOPY
4527                 if (pAC->GIni.GIChipId == CHIP_ID_YUKON)
4528                         printk("    scatter-gather:  enabled\n");
4529                 else
4530                         printk("    scatter-gather:  disabled\n");
4531
4532 #else
4533                         printk("    scatter-gather:  disabled\n");
4534 #endif
4535 #endif /* SK98_INFO */
4536                 
4537                 if ((Param.Para32[0] != pAC->ActivePort) && 
4538                         (pAC->RlmtNets == 1)) {
4539                         NewPara.Para32[0] = pAC->ActivePort;
4540                         NewPara.Para32[1] = Param.Para32[0];
4541                         SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4542                                 NewPara);
4543                 }
4544
4545                 /* Inform the world that link protocol is up. */
4546 #if 0
4547                 pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
4548 #endif
4549
4550                 break;
4551         case SK_DRV_NET_DOWN:    /* SK_U32 Reason */
4552                 /* action list 7 */
4553                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4554                         ("NET DOWN EVENT "));
4555 #ifdef SK98_INFO
4556                 printk("%s: network connection down\n", pAC->dev[Param.Para32[1]]->name);
4557 #endif
4558 #if 0
4559                 pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
4560 #endif
4561                 break;
4562         case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4563                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4564                         ("PORT SWITCH HARD "));
4565         case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4566         /* action list 6 */
4567                 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4568                         'A'+Param.Para32[1]);
4569         case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4570                 FromPort = Param.Para32[0];
4571                 ToPort = Param.Para32[1];
4572                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4573                         ("PORT SWITCH EVENT, From: %d  To: %d (Pref %d) ",
4574                         FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4575                 NewPara.Para64 = FromPort;
4576                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4577                 NewPara.Para64 = ToPort;
4578                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4579                 spin_lock_irqsave(
4580                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4581                         Flags);
4582                 spin_lock_irqsave(
4583                         &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4584                 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4585                 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4586                 spin_unlock_irqrestore(
4587                         &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4588                 spin_unlock_irqrestore(
4589                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4590                         Flags);
4591
4592                 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4593                 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4594                 
4595                 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4596                 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4597                 spin_lock_irqsave(
4598                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock, 
4599                         Flags);
4600                 spin_lock_irqsave(
4601                         &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4602                 pAC->ActivePort = ToPort;
4603 #if 0
4604                 SetQueueSizes(pAC);
4605 #else
4606                 /* tschilling: New common function with minimum size check. */
4607                 DualNet = SK_FALSE;
4608                 if (pAC->RlmtNets == 2) {
4609                         DualNet = SK_TRUE;
4610                 }
4611                 
4612                 if (SkGeInitAssignRamToQueues(
4613                         pAC,
4614                         pAC->ActivePort,
4615                         DualNet)) {
4616                         spin_unlock_irqrestore(
4617                                 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4618                         spin_unlock_irqrestore(
4619                                 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4620                                 Flags);
4621                         printk("SkGeInitAssignRamToQueues failed.\n");
4622                         break;
4623                 }
4624 #endif
4625                 /* tschilling: Handling of return values inserted. */
4626                 if (SkGeInitPort(pAC, IoC, FromPort) ||
4627                         SkGeInitPort(pAC, IoC, ToPort)) {
4628                         printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4629                 }
4630                 if (Event == SK_DRV_SWITCH_SOFT) {
4631                         SkMacRxTxEnable(pAC, IoC, FromPort);
4632                 }
4633                 SkMacRxTxEnable(pAC, IoC, ToPort);
4634                 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4635                 SkAddrMcUpdate(pAC, IoC, FromPort);
4636                 SkAddrMcUpdate(pAC, IoC, ToPort);
4637                 PortReInitBmu(pAC, FromPort);
4638                 PortReInitBmu(pAC, ToPort);
4639                 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4640                 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4641                 ClearAndStartRx(pAC, FromPort);
4642                 ClearAndStartRx(pAC, ToPort);
4643                 spin_unlock_irqrestore(
4644                         &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4645                 spin_unlock_irqrestore(
4646                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4647                         Flags);
4648                 break;
4649         case SK_DRV_RLMT_SEND:   /* SK_MBUF *pMb */
4650                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4651                         ("RLS "));
4652                 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4653                 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4654                 skb_put(pMsg, pRlmtMbuf->Length);
4655                 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4656                         pMsg) < 0)
4657
4658                         DEV_KFREE_SKB_ANY(pMsg);
4659                 break;
4660         default:
4661                 break;
4662         }
4663         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4664                 ("END EVENT "));
4665         
4666         return (0);
4667 } /* SkDrvEvent */
4668
4669
4670 /*****************************************************************************
4671  *
4672  *      SkErrorLog - log errors
4673  *
4674  * Description:
4675  *      This function logs errors to the system buffer and to the console
4676  *
4677  * Returns:
4678  *      0 if everything ok
4679  *      < 0  on error
4680  *      
4681  */
4682 void SkErrorLog(
4683 SK_AC   *pAC,
4684 int     ErrClass,
4685 int     ErrNum,
4686 char    *pErrorMsg)
4687 {
4688 char    ClassStr[80];
4689
4690         switch (ErrClass) {
4691         case SK_ERRCL_OTHER:
4692                 strcpy(ClassStr, "Other error");
4693                 break;
4694         case SK_ERRCL_CONFIG:
4695                 strcpy(ClassStr, "Configuration error");
4696                 break;
4697         case SK_ERRCL_INIT:
4698                 strcpy(ClassStr, "Initialization error");
4699                 break;
4700         case SK_ERRCL_NORES:
4701                 strcpy(ClassStr, "Out of resources error");
4702                 break;
4703         case SK_ERRCL_SW:
4704                 strcpy(ClassStr, "internal Software error");
4705                 break;
4706         case SK_ERRCL_HW:
4707                 strcpy(ClassStr, "Hardware failure");
4708                 break;
4709         case SK_ERRCL_COMM:
4710                 strcpy(ClassStr, "Communication error");
4711                 break;
4712         }
4713         printk(KERN_INFO "%s: -- ERROR --\n        Class:  %s\n"
4714                 "        Nr:  0x%x\n        Msg:  %s\n", pAC->dev[0]->name,
4715                 ClassStr, ErrNum, pErrorMsg);
4716
4717 } /* SkErrorLog */
4718
4719 #ifdef DEBUG
4720 /****************************************************************************/
4721 /* "debug only" section *****************************************************/
4722 /****************************************************************************/
4723
4724
4725 /*****************************************************************************
4726  *
4727  *      DumpMsg - print a frame
4728  *
4729  * Description:
4730  *      This function prints frames to the system logfile/to the console.
4731  *
4732  * Returns: N/A
4733  *      
4734  */
4735 static void DumpMsg(struct sk_buff *skb, char *str)
4736 {
4737         int     msglen;
4738
4739         if (skb == NULL) {
4740                 printk("DumpMsg(): NULL-Message\n");
4741                 return;
4742         }
4743
4744         if (skb->data == NULL) {
4745                 printk("DumpMsg(): Message empty\n");
4746                 return;
4747         }
4748
4749         msglen = skb->len;
4750         if (msglen > 64)
4751                 msglen = 64;
4752
4753         printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4754
4755         DumpData((char *)skb->data, msglen);
4756
4757         printk("------- End of message ---------\n");
4758 } /* DumpMsg */
4759
4760
4761
4762 /*****************************************************************************
4763  *
4764  *      DumpData - print a data area
4765  *
4766  * Description:
4767  *      This function prints a area of data to the system logfile/to the 
4768  *      console.
4769  *
4770  * Returns: N/A
4771  *      
4772  */
4773 static void DumpData(char *p, int size)
4774 {
4775 register int    i;
4776 int     haddr, addr;
4777 char    hex_buffer[180];
4778 char    asc_buffer[180];
4779 char    HEXCHAR[] = "0123456789ABCDEF";
4780
4781         addr = 0;
4782         haddr = 0;
4783         hex_buffer[0] = 0;
4784         asc_buffer[0] = 0;
4785         for (i=0; i < size; ) {
4786                 if (*p >= '0' && *p <='z')
4787                         asc_buffer[addr] = *p;
4788                 else
4789                         asc_buffer[addr] = '.';
4790                 addr++;
4791                 asc_buffer[addr] = 0;
4792                 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4793                 haddr++;
4794                 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4795                 haddr++;
4796                 hex_buffer[haddr] = ' ';
4797                 haddr++;
4798                 hex_buffer[haddr] = 0;
4799                 p++;
4800                 i++;
4801                 if (i%16 == 0) {
4802                         printk("%s  %s\n", hex_buffer, asc_buffer);
4803                         addr = 0;
4804                         haddr = 0;
4805                 }
4806         }
4807 } /* DumpData */
4808
4809
4810 /*****************************************************************************
4811  *
4812  *      DumpLong - print a data area as long values
4813  *
4814  * Description:
4815  *      This function prints a area of data to the system logfile/to the 
4816  *      console.
4817  *
4818  * Returns: N/A
4819  *      
4820  */
4821 static void DumpLong(char *pc, int size)
4822 {
4823 register int    i;
4824 int     haddr, addr;
4825 char    hex_buffer[180];
4826 char    asc_buffer[180];
4827 char    HEXCHAR[] = "0123456789ABCDEF";
4828 long    *p;
4829 int     l;
4830
4831         addr = 0;
4832         haddr = 0;
4833         hex_buffer[0] = 0;
4834         asc_buffer[0] = 0;
4835         p = (long*) pc;
4836         for (i=0; i < size; ) {
4837                 l = (long) *p;
4838                 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4839                 haddr++;
4840                 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4841                 haddr++;
4842                 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4843                 haddr++;
4844                 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4845                 haddr++;
4846                 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4847                 haddr++;
4848                 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4849                 haddr++;
4850                 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4851                 haddr++;
4852                 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4853                 haddr++;
4854                 hex_buffer[haddr] = ' ';
4855                 haddr++;
4856                 hex_buffer[haddr] = 0;
4857                 p++;
4858                 i++;
4859                 if (i%8 == 0) {
4860                         printk("%4x %s\n", (i-8)*4, hex_buffer);
4861                         haddr = 0;
4862                 }
4863         }
4864         printk("------------------------\n");
4865 } /* DumpLong */
4866
4867 #endif
4868
4869 #endif /* CONFIG_SK98 */
4870
4871 /*
4872  * Local variables:
4873  * compile-command: "make"
4874  * End:
4875  */
4876