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