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