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