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