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