]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/sk98lin/skge.c
[PATCH] sk98lin: allow ethtool checksum on/off per port
[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                 if (pRxPort->RxCsum) {
2193                         pMsg->csum = pRxd->TcpSums;
2194                         pMsg->ip_summed = CHECKSUM_HW;
2195                 }
2196
2197                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2198                 ForRlmt = SK_RLMT_RX_PROTOCOL;
2199 #if 0
2200                 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2201 #endif
2202                 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2203                         IsBc, &Offset, &NumBytes);
2204                 if (NumBytes != 0) {
2205 #if 0
2206                         IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2207 #endif
2208                         SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2209                                 &pMsg->data[Offset],
2210                                 IsBc, IsMc, &ForRlmt);
2211                 }
2212                 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2213                                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2214                         /* send up only frames from active port */
2215                         if ((PortIndex == pAC->ActivePort) ||
2216                                 (pAC->RlmtNets == 2)) {
2217                                 /* frame for upper layer */
2218                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2219 #ifdef xDEBUG
2220                                 DumpMsg(pMsg, "Rx");
2221 #endif
2222                                 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2223                                         FrameLength, pRxPort->PortIndex);
2224
2225                                 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2226                                 pMsg->protocol = eth_type_trans(pMsg,
2227                                         pAC->dev[pRxPort->PortIndex]);
2228                                 netif_rx(pMsg);
2229                                 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2230                         }
2231                         else {
2232                                 /* drop frame */
2233                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2234                                         SK_DBGCAT_DRV_RX_PROGRESS,
2235                                         ("D"));
2236                                 DEV_KFREE_SKB(pMsg);
2237                         }
2238                         
2239                 } /* if not for rlmt */
2240                 else {
2241                         /* packet for rlmt */
2242                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2243                                 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2244                         pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2245                                 pAC->IoBase, FrameLength);
2246                         if (pRlmtMbuf != NULL) {
2247                                 pRlmtMbuf->pNext = NULL;
2248                                 pRlmtMbuf->Length = FrameLength;
2249                                 pRlmtMbuf->PortIdx = PortIndex;
2250                                 EvPara.pParaPtr = pRlmtMbuf;
2251                                 memcpy((char*)(pRlmtMbuf->pData),
2252                                            (char*)(pMsg->data),
2253                                            FrameLength);
2254
2255                                 /* SlowPathLock needed? */
2256                                 if (SlowPathLock == SK_TRUE) {
2257                                         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2258                                         SkEventQueue(pAC, SKGE_RLMT,
2259                                                 SK_RLMT_PACKET_RECEIVED,
2260                                                 EvPara);
2261                                         pAC->CheckQueue = SK_TRUE;
2262                                         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2263                                 } else {
2264                                         SkEventQueue(pAC, SKGE_RLMT,
2265                                                 SK_RLMT_PACKET_RECEIVED,
2266                                                 EvPara);
2267                                         pAC->CheckQueue = SK_TRUE;
2268                                 }
2269
2270                                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2271                                         SK_DBGCAT_DRV_RX_PROGRESS,
2272                                         ("Q"));
2273                         }
2274                         if ((pAC->dev[pRxPort->PortIndex]->flags &
2275                                 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2276                                 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2277                                 SK_RLMT_RX_PROTOCOL) {
2278                                 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2279                                 pMsg->protocol = eth_type_trans(pMsg,
2280                                         pAC->dev[pRxPort->PortIndex]);
2281                                 netif_rx(pMsg);
2282                                 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2283                         }
2284                         else {
2285                                 DEV_KFREE_SKB(pMsg);
2286                         }
2287
2288                 } /* if packet for rlmt */
2289         } /* for ... scanning the RXD ring */
2290
2291         /* RXD ring is empty -> fill and restart */
2292         FillRxRing(pAC, pRxPort);
2293         /* do not start if called from Close */
2294         if (pAC->BoardLevel > SK_INIT_DATA) {
2295                 ClearAndStartRx(pAC, PortIndex);
2296         }
2297         return;
2298
2299 rx_failed:
2300         /* remove error frame */
2301         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2302                 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2303
2304         /* release the DMA mapping */
2305
2306         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2307         PhysAddr |= (SK_U64) pRxd->VDataLow;
2308         pci_unmap_page(pAC->PciDev,
2309                          PhysAddr,
2310                          pAC->RxBufSize - 2,
2311                          PCI_DMA_FROMDEVICE);
2312         DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2313         pRxd->pMBuf = NULL;
2314         pRxPort->RxdRingFree++;
2315         pRxPort->pRxdRingHead = pRxd->pNextRxd;
2316         goto rx_start;
2317
2318 } /* ReceiveIrq */
2319
2320
2321 /*****************************************************************************
2322  *
2323  *      ClearAndStartRx - give a start receive command to BMU, clear IRQ
2324  *
2325  * Description:
2326  *      This function sends a start command and a clear interrupt
2327  *      command for one receive queue to the BMU.
2328  *
2329  * Returns: N/A
2330  *      none
2331  */
2332 static void ClearAndStartRx(
2333 SK_AC   *pAC,           /* pointer to the adapter context */
2334 int     PortIndex)      /* index of the receive port (XMAC) */
2335 {
2336         SK_OUT8(pAC->IoBase,
2337                 RxQueueAddr[PortIndex]+Q_CSR,
2338                 CSR_START | CSR_IRQ_CL_F);
2339 } /* ClearAndStartRx */
2340
2341
2342 /*****************************************************************************
2343  *
2344  *      ClearTxIrq - give a clear transmit IRQ command to BMU
2345  *
2346  * Description:
2347  *      This function sends a clear tx IRQ command for one
2348  *      transmit queue to the BMU.
2349  *
2350  * Returns: N/A
2351  */
2352 static void ClearTxIrq(
2353 SK_AC   *pAC,           /* pointer to the adapter context */
2354 int     PortIndex,      /* index of the transmit port (XMAC) */
2355 int     Prio)           /* priority or normal queue */
2356 {
2357         SK_OUT8(pAC->IoBase, 
2358                 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2359                 CSR_IRQ_CL_F);
2360 } /* ClearTxIrq */
2361
2362
2363 /*****************************************************************************
2364  *
2365  *      ClearRxRing - remove all buffers from the receive ring
2366  *
2367  * Description:
2368  *      This function removes all receive buffers from the ring.
2369  *      The receive BMU must be stopped before calling this function.
2370  *
2371  * Returns: N/A
2372  */
2373 static void ClearRxRing(
2374 SK_AC   *pAC,           /* pointer to adapter context */
2375 RX_PORT *pRxPort)       /* pointer to rx port struct */
2376 {
2377 RXD             *pRxd;  /* pointer to the current descriptor */
2378 unsigned long   Flags;
2379 SK_U64          PhysAddr;
2380
2381         if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2382                 return;
2383         }
2384         spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2385         pRxd = pRxPort->pRxdRingHead;
2386         do {
2387                 if (pRxd->pMBuf != NULL) {
2388
2389                         PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2390                         PhysAddr |= (SK_U64) pRxd->VDataLow;
2391                         pci_unmap_page(pAC->PciDev,
2392                                          PhysAddr,
2393                                          pAC->RxBufSize - 2,
2394                                          PCI_DMA_FROMDEVICE);
2395                         DEV_KFREE_SKB(pRxd->pMBuf);
2396                         pRxd->pMBuf = NULL;
2397                 }
2398                 pRxd->RBControl &= BMU_OWN;
2399                 pRxd = pRxd->pNextRxd;
2400                 pRxPort->RxdRingFree++;
2401         } while (pRxd != pRxPort->pRxdRingTail);
2402         pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2403         spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2404 } /* ClearRxRing */
2405
2406 /*****************************************************************************
2407  *
2408  *      ClearTxRing - remove all buffers from the transmit ring
2409  *
2410  * Description:
2411  *      This function removes all transmit buffers from the ring.
2412  *      The transmit BMU must be stopped before calling this function
2413  *      and transmitting at the upper level must be disabled.
2414  *      The BMU own bit of all descriptors is cleared, the rest is
2415  *      done by calling FreeTxDescriptors.
2416  *
2417  * Returns: N/A
2418  */
2419 static void ClearTxRing(
2420 SK_AC   *pAC,           /* pointer to adapter context */
2421 TX_PORT *pTxPort)       /* pointer to tx prt struct */
2422 {
2423 TXD             *pTxd;          /* pointer to the current descriptor */
2424 int             i;
2425 unsigned long   Flags;
2426
2427         spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2428         pTxd = pTxPort->pTxdRingHead;
2429         for (i=0; i<pAC->TxDescrPerRing; i++) {
2430                 pTxd->TBControl &= ~BMU_OWN;
2431                 pTxd = pTxd->pNextTxd;
2432         }
2433         FreeTxDescriptors(pAC, pTxPort);
2434         spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2435 } /* ClearTxRing */
2436
2437 /*****************************************************************************
2438  *
2439  *      SkGeSetMacAddr - Set the hardware MAC address
2440  *
2441  * Description:
2442  *      This function sets the MAC address used by the adapter.
2443  *
2444  * Returns:
2445  *      0, if everything is ok
2446  *      !=0, on error
2447  */
2448 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2449 {
2450
2451 DEV_NET *pNet = netdev_priv(dev);
2452 SK_AC   *pAC = pNet->pAC;
2453
2454 struct sockaddr *addr = p;
2455 unsigned long   Flags;
2456         
2457         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2458                 ("SkGeSetMacAddr starts now...\n"));
2459         if(netif_running(dev))
2460                 return -EBUSY;
2461
2462         memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2463         
2464         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2465
2466         if (pAC->RlmtNets == 2)
2467                 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2468                         (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2469         else
2470                 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2471                         (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2472
2473         
2474         
2475         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2476         return 0;
2477 } /* SkGeSetMacAddr */
2478
2479
2480 /*****************************************************************************
2481  *
2482  *      SkGeSetRxMode - set receive mode
2483  *
2484  * Description:
2485  *      This function sets the receive mode of an adapter. The adapter
2486  *      supports promiscuous mode, allmulticast mode and a number of
2487  *      multicast addresses. If more multicast addresses the available
2488  *      are selected, a hash function in the hardware is used.
2489  *
2490  * Returns:
2491  *      0, if everything is ok
2492  *      !=0, on error
2493  */
2494 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2495 {
2496
2497 DEV_NET         *pNet;
2498 SK_AC           *pAC;
2499
2500 struct dev_mc_list      *pMcList;
2501 int                     i;
2502 int                     PortIdx;
2503 unsigned long           Flags;
2504
2505         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2506                 ("SkGeSetRxMode starts now... "));
2507
2508         pNet = netdev_priv(dev);
2509         pAC = pNet->pAC;
2510         if (pAC->RlmtNets == 1)
2511                 PortIdx = pAC->ActivePort;
2512         else
2513                 PortIdx = pNet->NetNr;
2514
2515         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2516         if (dev->flags & IFF_PROMISC) {
2517                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2518                         ("PROMISCUOUS mode\n"));
2519                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2520                         SK_PROM_MODE_LLC);
2521         } else if (dev->flags & IFF_ALLMULTI) {
2522                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2523                         ("ALLMULTI mode\n"));
2524                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2525                         SK_PROM_MODE_ALL_MC);
2526         } else {
2527                 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2528                         SK_PROM_MODE_NONE);
2529                 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2530
2531                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2532                         ("Number of MC entries: %d ", dev->mc_count));
2533                 
2534                 pMcList = dev->mc_list;
2535                 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2536                         SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2537                                 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2538                         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2539                                 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2540                                 pMcList->dmi_addr[0],
2541                                 pMcList->dmi_addr[1],
2542                                 pMcList->dmi_addr[2],
2543                                 pMcList->dmi_addr[3],
2544                                 pMcList->dmi_addr[4],
2545                                 pMcList->dmi_addr[5]));
2546                 }
2547                 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2548         }
2549         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2550         
2551         return;
2552 } /* SkGeSetRxMode */
2553
2554
2555 /*****************************************************************************
2556  *
2557  *      SkGeChangeMtu - set the MTU to another value
2558  *
2559  * Description:
2560  *      This function sets is called whenever the MTU size is changed
2561  *      (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2562  *      ethernet MTU size, long frame support is activated.
2563  *
2564  * Returns:
2565  *      0, if everything is ok
2566  *      !=0, on error
2567  */
2568 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2569 {
2570 DEV_NET         *pNet;
2571 DEV_NET         *pOtherNet;
2572 SK_AC           *pAC;
2573 unsigned long   Flags;
2574 int             i;
2575 SK_EVPARA       EvPara;
2576
2577         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2578                 ("SkGeChangeMtu starts now...\n"));
2579
2580         pNet = netdev_priv(dev);
2581         pAC  = pNet->pAC;
2582
2583         if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2584                 return -EINVAL;
2585         }
2586
2587         if(pAC->BoardLevel != SK_INIT_RUN) {
2588                 return -EINVAL;
2589         }
2590
2591 #ifdef SK_DIAG_SUPPORT
2592         if (pAC->DiagModeActive == DIAG_ACTIVE) {
2593                 if (pAC->DiagFlowCtrl == SK_FALSE) {
2594                         return -1; /* still in use, deny any actions of MTU */
2595                 } else {
2596                         pAC->DiagFlowCtrl = SK_FALSE;
2597                 }
2598         }
2599 #endif
2600
2601         pNet->Mtu = NewMtu;
2602         pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2603         if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2604                 return(0);
2605         }
2606
2607         pAC->RxBufSize = NewMtu + 32;
2608         dev->mtu = NewMtu;
2609
2610         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2611                 ("New MTU: %d\n", NewMtu));
2612
2613         /* 
2614         ** Prevent any reconfiguration while changing the MTU 
2615         ** by disabling any interrupts 
2616         */
2617         SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2618         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2619
2620         /* 
2621         ** Notify RLMT that any ports are to be stopped
2622         */
2623         EvPara.Para32[0] =  0;
2624         EvPara.Para32[1] = -1;
2625         if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2626                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2627                 EvPara.Para32[0] =  1;
2628                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2629         } else {
2630                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2631         }
2632
2633         /*
2634         ** After calling the SkEventDispatcher(), RLMT is aware about
2635         ** the stopped ports -> configuration can take place!
2636         */
2637         SkEventDispatcher(pAC, pAC->IoBase);
2638
2639         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2640                 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2641                 netif_stop_queue(pAC->dev[i]);
2642
2643         }
2644
2645         /*
2646         ** Depending on the desired MTU size change, a different number of 
2647         ** RX buffers need to be allocated
2648         */
2649         if (NewMtu > 1500) {
2650             /* 
2651             ** Use less rx buffers 
2652             */
2653             for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2654                 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2655                     pAC->RxPort[i].RxFillLimit =  pAC->RxDescrPerRing -
2656                                                  (pAC->RxDescrPerRing / 4);
2657                 } else {
2658                     if (i == pAC->ActivePort) {
2659                         pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 
2660                                                     (pAC->RxDescrPerRing / 4);
2661                     } else {
2662                         pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 
2663                                                     (pAC->RxDescrPerRing / 10);
2664                     }
2665                 }
2666             }
2667         } else {
2668             /* 
2669             ** Use the normal amount of rx buffers 
2670             */
2671             for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2672                 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2673                     pAC->RxPort[i].RxFillLimit = 1;
2674                 } else {
2675                     if (i == pAC->ActivePort) {
2676                         pAC->RxPort[i].RxFillLimit = 1;
2677                     } else {
2678                         pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2679                                                     (pAC->RxDescrPerRing / 4);
2680                     }
2681                 }
2682             }
2683         }
2684         
2685         SkGeDeInit(pAC, pAC->IoBase);
2686
2687         /*
2688         ** enable/disable hardware support for long frames
2689         */
2690         if (NewMtu > 1500) {
2691 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2692                 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2693         } else {
2694             if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2695                 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2696             } else {
2697                 pAC->GIni.GIPortUsage = SK_RED_LINK;
2698             }
2699         }
2700
2701         SkGeInit(   pAC, pAC->IoBase, SK_INIT_IO);
2702         SkI2cInit(  pAC, pAC->IoBase, SK_INIT_IO);
2703         SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2704         SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2705         SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2706         SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2707         SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2708         
2709         /*
2710         ** tschilling:
2711         ** Speed and others are set back to default in level 1 init!
2712         */
2713         GetConfiguration(pAC);
2714         
2715         SkGeInit(   pAC, pAC->IoBase, SK_INIT_RUN);
2716         SkI2cInit(  pAC, pAC->IoBase, SK_INIT_RUN);
2717         SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2718         SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2719         SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2720         SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2721         SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2722
2723         /*
2724         ** clear and reinit the rx rings here
2725         */
2726         for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2727                 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2728                 ClearRxRing(pAC, &pAC->RxPort[i]);
2729                 FillRxRing(pAC, &pAC->RxPort[i]);
2730
2731                 /* 
2732                 ** Enable transmit descriptor polling
2733                 */
2734                 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2735                 FillRxRing(pAC, &pAC->RxPort[i]);
2736         };
2737
2738         SkGeYellowLED(pAC, pAC->IoBase, 1);
2739         SkDimEnableModerationIfNeeded(pAC);     
2740         SkDimDisplayModerationSettings(pAC);
2741
2742         netif_start_queue(pAC->dev[pNet->PortNr]);
2743         for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2744                 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2745         }
2746
2747         /* 
2748         ** Enable Interrupts again 
2749         */
2750         SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2751         SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2752
2753         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2754         SkEventDispatcher(pAC, pAC->IoBase);
2755
2756         /* 
2757         ** Notify RLMT about the changing and restarting one (or more) ports
2758         */
2759         if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2760                 EvPara.Para32[0] = pAC->RlmtNets;
2761                 EvPara.Para32[1] = -1;
2762                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2763                 EvPara.Para32[0] = pNet->PortNr;
2764                 EvPara.Para32[1] = -1;
2765                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2766                         
2767                 if (pOtherNet->Up) {
2768                         EvPara.Para32[0] = pOtherNet->PortNr;
2769                         SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2770                 }
2771         } else {
2772                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2773         }
2774
2775         SkEventDispatcher(pAC, pAC->IoBase);
2776         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2777         
2778         /*
2779         ** While testing this driver with latest kernel 2.5 (2.5.70), it 
2780         ** seems as if upper layers have a problem to handle a successful
2781         ** return value of '0'. If such a zero is returned, the complete 
2782         ** system hangs for several minutes (!), which is in acceptable.
2783         **
2784         ** Currently it is not clear, what the exact reason for this problem
2785         ** is. The implemented workaround for 2.5 is to return the desired 
2786         ** new MTU size if all needed changes for the new MTU size where 
2787         ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2788         ** which indicates the successful change of the mtu-size.
2789         */
2790         return NewMtu;
2791
2792 } /* SkGeChangeMtu */
2793
2794
2795 /*****************************************************************************
2796  *
2797  *      SkGeStats - return ethernet device statistics
2798  *
2799  * Description:
2800  *      This function return statistic data about the ethernet device
2801  *      to the operating system.
2802  *
2803  * Returns:
2804  *      pointer to the statistic structure.
2805  */
2806 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2807 {
2808 DEV_NET *pNet = netdev_priv(dev);
2809 SK_AC   *pAC = pNet->pAC;
2810 SK_PNMI_STRUCT_DATA *pPnmiStruct;       /* structure for all Pnmi-Data */
2811 SK_PNMI_STAT    *pPnmiStat;             /* pointer to virtual XMAC stat. data */
2812 SK_PNMI_CONF    *pPnmiConf;             /* pointer to virtual link config. */
2813 unsigned int    Size;                   /* size of pnmi struct */
2814 unsigned long   Flags;                  /* for spin lock */
2815
2816         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2817                 ("SkGeStats starts now...\n"));
2818         pPnmiStruct = &pAC->PnmiStruct;
2819
2820 #ifdef SK_DIAG_SUPPORT
2821         if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2822                 (pAC->BoardLevel == SK_INIT_RUN)) {
2823 #endif
2824         SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2825         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2826         Size = SK_PNMI_STRUCT_SIZE;
2827                 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2828         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2829 #ifdef SK_DIAG_SUPPORT
2830         }
2831 #endif
2832
2833         pPnmiStat = &pPnmiStruct->Stat[0];
2834         pPnmiConf = &pPnmiStruct->Conf[0];
2835
2836         pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2837         pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2838         pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2839         pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2840         
2841         if (pNet->Mtu <= 1500) {
2842                 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2843         } else {
2844                 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2845                         pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2846         }
2847
2848
2849         if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2850                 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2851
2852         pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2853         pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2854         pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2855         pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2856         pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2857
2858         /* detailed rx_errors: */
2859         pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2860         pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2861         pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2862         pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2863         pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2864         pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2865
2866         /* detailed tx_errors */
2867         pAC->stats.tx_aborted_errors = (SK_U32) 0;
2868         pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2869         pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2870         pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2871         pAC->stats.tx_window_errors = (SK_U32) 0;
2872
2873         return(&pAC->stats);
2874 } /* SkGeStats */
2875
2876
2877 /*****************************************************************************
2878  *
2879  *      SkGeIoctl - IO-control function
2880  *
2881  * Description:
2882  *      This function is called if an ioctl is issued on the device.
2883  *      There are three subfunction for reading, writing and test-writing
2884  *      the private MIB data structure (usefull for SysKonnect-internal tools).
2885  *
2886  * Returns:
2887  *      0, if everything is ok
2888  *      !=0, on error
2889  */
2890 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2891 {
2892 DEV_NET         *pNet;
2893 SK_AC           *pAC;
2894 void            *pMemBuf;
2895 struct pci_dev  *pdev = NULL;
2896 SK_GE_IOCTL     Ioctl;
2897 unsigned int    Err = 0;
2898 int             Size = 0;
2899 int             Ret = 0;
2900 unsigned int    Length = 0;
2901 int             HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2902
2903         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2904                 ("SkGeIoctl starts now...\n"));
2905
2906         pNet = netdev_priv(dev);
2907         pAC = pNet->pAC;
2908         
2909         if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2910                 return -EFAULT;
2911         }
2912
2913         switch(cmd) {
2914         case SK_IOCTL_SETMIB:
2915         case SK_IOCTL_PRESETMIB:
2916                 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2917         case SK_IOCTL_GETMIB:
2918                 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2919                         Ioctl.Len<sizeof(pAC->PnmiStruct)?
2920                         Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2921                         return -EFAULT;
2922                 }
2923                 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2924                 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2925                         Ioctl.Len<Size? Ioctl.Len : Size)) {
2926                         return -EFAULT;
2927                 }
2928                 Ioctl.Len = Size;
2929                 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2930                         return -EFAULT;
2931                 }
2932                 break;
2933         case SK_IOCTL_GEN:
2934                 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2935                         Length = Ioctl.Len;
2936                 } else {
2937                         Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2938                 }
2939                 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2940                         return -ENOMEM;
2941                 }
2942                 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2943                         Err = -EFAULT;
2944                         goto fault_gen;
2945                 }
2946                 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2947                         Err = -EFAULT;
2948                         goto fault_gen;
2949                 }
2950                 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2951                         Err = -EFAULT;
2952                         goto fault_gen;
2953                 }
2954                 Ioctl.Len = Length;
2955                 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2956                         Err = -EFAULT;
2957                         goto fault_gen;
2958                 }
2959 fault_gen:
2960                 kfree(pMemBuf); /* cleanup everything */
2961                 break;
2962 #ifdef SK_DIAG_SUPPORT
2963        case SK_IOCTL_DIAG:
2964                 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2965                 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2966                         Length = Ioctl.Len;
2967                 } else {
2968                         Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2969                 }
2970                 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2971                         return -ENOMEM;
2972                 }
2973                 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2974                         Err = -EFAULT;
2975                         goto fault_diag;
2976                 }
2977                 pdev = pAC->PciDev;
2978                 Length = 3 * sizeof(SK_U32);  /* Error, Bus and Device */
2979                 /* 
2980                 ** While coding this new IOCTL interface, only a few lines of code
2981                 ** are to to be added. Therefore no dedicated function has been 
2982                 ** added. If more functionality is added, a separate function 
2983                 ** should be used...
2984                 */
2985                 * ((SK_U32 *)pMemBuf) = 0;
2986                 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2987                 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2988                 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2989                         Err = -EFAULT;
2990                         goto fault_diag;
2991                 }
2992                 Ioctl.Len = Length;
2993                 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2994                         Err = -EFAULT;
2995                         goto fault_diag;
2996                 }
2997 fault_diag:
2998                 kfree(pMemBuf); /* cleanup everything */
2999                 break;
3000 #endif
3001         default:
3002                 Err = -EOPNOTSUPP;
3003         }
3004
3005         return(Err);
3006
3007 } /* SkGeIoctl */
3008
3009
3010 /*****************************************************************************
3011  *
3012  *      SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3013  *
3014  * Description:
3015  *      This function reads/writes the MIB data using PNMI (Private Network
3016  *      Management Interface).
3017  *      The destination for the data must be provided with the
3018  *      ioctl call and is given to the driver in the form of
3019  *      a user space address.
3020  *      Copying from the user-provided data area into kernel messages
3021  *      and back is done by copy_from_user and copy_to_user calls in
3022  *      SkGeIoctl.
3023  *
3024  * Returns:
3025  *      returned size from PNMI call
3026  */
3027 static int SkGeIocMib(
3028 DEV_NET         *pNet,  /* pointer to the adapter context */
3029 unsigned int    Size,   /* length of ioctl data */
3030 int             mode)   /* flag for set/preset */
3031 {
3032 unsigned long   Flags;  /* for spin lock */
3033 SK_AC           *pAC;
3034
3035         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3036                 ("SkGeIocMib starts now...\n"));
3037         pAC = pNet->pAC;
3038         /* access MIB */
3039         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3040         switch(mode) {
3041         case SK_IOCTL_GETMIB:
3042                 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3043                         pNet->NetNr);
3044                 break;
3045         case SK_IOCTL_PRESETMIB:
3046                 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3047                         pNet->NetNr);
3048                 break;
3049         case SK_IOCTL_SETMIB:
3050                 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3051                         pNet->NetNr);
3052                 break;
3053         default:
3054                 break;
3055         }
3056         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3057         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3058                 ("MIB data access succeeded\n"));
3059         return (Size);
3060 } /* SkGeIocMib */
3061
3062
3063 /*****************************************************************************
3064  *
3065  *      GetConfiguration - read configuration information
3066  *
3067  * Description:
3068  *      This function reads per-adapter configuration information from
3069  *      the options provided on the command line.
3070  *
3071  * Returns:
3072  *      none
3073  */
3074 static void GetConfiguration(
3075 SK_AC   *pAC)   /* pointer to the adapter context structure */
3076 {
3077 SK_I32  Port;           /* preferred port */
3078 SK_BOOL AutoSet;
3079 SK_BOOL DupSet;
3080 int     LinkSpeed          = SK_LSPEED_AUTO;    /* Link speed */
3081 int     AutoNeg            = 1;                 /* autoneg off (0) or on (1) */
3082 int     DuplexCap          = 0;                 /* 0=both,1=full,2=half */
3083 int     FlowCtrl           = SK_FLOW_MODE_SYM_OR_REM;   /* FlowControl  */
3084 int     MSMode             = SK_MS_MODE_AUTO;   /* master/slave mode    */
3085
3086 SK_BOOL IsConTypeDefined   = SK_TRUE;
3087 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3088 SK_BOOL IsFlowCtrlDefined  = SK_TRUE;
3089 SK_BOOL IsRoleDefined      = SK_TRUE;
3090 SK_BOOL IsModeDefined      = SK_TRUE;
3091 /*
3092  *      The two parameters AutoNeg. and DuplexCap. map to one configuration
3093  *      parameter. The mapping is described by this table:
3094  *      DuplexCap ->    |       both    |       full    |       half    |
3095  *      AutoNeg         |               |               |               |
3096  *      -----------------------------------------------------------------
3097  *      Off             |    illegal    |       Full    |       Half    |
3098  *      -----------------------------------------------------------------
3099  *      On              |   AutoBoth    |   AutoFull    |   AutoHalf    |
3100  *      -----------------------------------------------------------------
3101  *      Sense           |   AutoSense   |   AutoSense   |   AutoSense   |
3102  */
3103 int     Capabilities[3][3] =
3104                 { {                -1, SK_LMODE_FULL     , SK_LMODE_HALF     },
3105                   {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3106                   {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3107
3108 #define DC_BOTH 0
3109 #define DC_FULL 1
3110 #define DC_HALF 2
3111 #define AN_OFF  0
3112 #define AN_ON   1
3113 #define AN_SENS 2
3114 #define M_CurrPort pAC->GIni.GP[Port]
3115
3116
3117         /*
3118         ** Set the default values first for both ports!
3119         */
3120         for (Port = 0; Port < SK_MAX_MACS; Port++) {
3121                 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3122                 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3123                 M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3124                 M_CurrPort.PLinkSpeed    = SK_LSPEED_AUTO;
3125         }
3126
3127         /*
3128         ** Check merged parameter ConType. If it has not been used,
3129         ** verify any other parameter (e.g. AutoNeg) and use default values. 
3130         **
3131         ** Stating both ConType and other lowlevel link parameters is also
3132         ** possible. If this is the case, the passed ConType-parameter is 
3133         ** overwritten by the lowlevel link parameter.
3134         **
3135         ** The following settings are used for a merged ConType-parameter:
3136         **
3137         ** ConType   DupCap   AutoNeg   FlowCtrl      Role      Speed
3138         ** -------   ------   -------   --------   ----------   -----
3139         **  Auto      Both      On      SymOrRem      Auto       Auto
3140         **  100FD     Full      Off       None      <ignored>    100
3141         **  100HD     Half      Off       None      <ignored>    100
3142         **  10FD      Full      Off       None      <ignored>    10
3143         **  10HD      Half      Off       None      <ignored>    10
3144         ** 
3145         ** This ConType parameter is used for all ports of the adapter!
3146         */
3147         if ( (ConType != NULL)                && 
3148              (pAC->Index < SK_MAX_CARD_PARAM) &&
3149              (ConType[pAC->Index] != NULL) ) {
3150
3151                         /* Check chipset family */
3152                         if ((!pAC->ChipsetType) && 
3153                                 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3154                                 (strcmp(ConType[pAC->Index],"")!=0)) {
3155                                 /* Set the speed parameter back */
3156                                         printk("sk98lin: Illegal value \"%s\" " 
3157                                                         "for ConType."
3158                                                         " Using Auto.\n", 
3159                                                         ConType[pAC->Index]);
3160
3161                                         sprintf(ConType[pAC->Index], "Auto");   
3162                         }
3163
3164                                 if (strcmp(ConType[pAC->Index],"")==0) {
3165                         IsConTypeDefined = SK_FALSE; /* No ConType defined */
3166                                 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3167                     for (Port = 0; Port < SK_MAX_MACS; Port++) {
3168                         M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3169                         M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3170                         M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3171                         M_CurrPort.PLinkSpeed    = SK_LSPEED_AUTO;
3172                     }
3173                 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3174                     for (Port = 0; Port < SK_MAX_MACS; Port++) {
3175                         M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3176                         M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3177                         M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3178                         M_CurrPort.PLinkSpeed    = SK_LSPEED_100MBPS;
3179                     }
3180                 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3181                     for (Port = 0; Port < SK_MAX_MACS; Port++) {
3182                         M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3183                         M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3184                         M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3185                         M_CurrPort.PLinkSpeed    = SK_LSPEED_100MBPS;
3186                     }
3187                 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3188                     for (Port = 0; Port < SK_MAX_MACS; Port++) {
3189                         M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3190                         M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3191                         M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3192                         M_CurrPort.PLinkSpeed    = SK_LSPEED_10MBPS;
3193                     }
3194                 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3195                     for (Port = 0; Port < SK_MAX_MACS; Port++) {
3196                         M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3197                         M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3198                         M_CurrPort.PMSMode       = SK_MS_MODE_AUTO;
3199                         M_CurrPort.PLinkSpeed    = SK_LSPEED_10MBPS;
3200                     }
3201                 } else { 
3202                     printk("sk98lin: Illegal value \"%s\" for ConType\n", 
3203                         ConType[pAC->Index]);
3204                     IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3205                 }
3206         } else {
3207             IsConTypeDefined = SK_FALSE; /* No ConType defined */
3208         }
3209
3210         /*
3211         ** Parse any parameter settings for port A:
3212         ** a) any LinkSpeed stated?
3213         */
3214         if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3215                 Speed_A[pAC->Index] != NULL) {
3216                 if (strcmp(Speed_A[pAC->Index],"")==0) {
3217                     IsLinkSpeedDefined = SK_FALSE;
3218                 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3219                     LinkSpeed = SK_LSPEED_AUTO;
3220                 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3221                     LinkSpeed = SK_LSPEED_10MBPS;
3222                 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3223                     LinkSpeed = SK_LSPEED_100MBPS;
3224                 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3225                     LinkSpeed = SK_LSPEED_1000MBPS;
3226                 } else {
3227                     printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3228                         Speed_A[pAC->Index]);
3229                     IsLinkSpeedDefined = SK_FALSE;
3230                 }
3231         } else {
3232             IsLinkSpeedDefined = SK_FALSE;
3233         }
3234
3235         /* 
3236         ** Check speed parameter: 
3237         **    Only copper type adapter and GE V2 cards 
3238         */
3239         if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3240                 ((LinkSpeed != SK_LSPEED_AUTO) &&
3241                 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3242                 printk("sk98lin: Illegal value for Speed_A. "
3243                         "Not a copper card or GE V2 card\n    Using "
3244                         "speed 1000\n");
3245                 LinkSpeed = SK_LSPEED_1000MBPS;
3246         }
3247         
3248         /*      
3249         ** Decide whether to set new config value if somethig valid has
3250         ** been received.
3251         */
3252         if (IsLinkSpeedDefined) {
3253                 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3254         } 
3255
3256         /* 
3257         ** b) Any Autonegotiation and DuplexCapabilities set?
3258         **    Please note that both belong together...
3259         */
3260         AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3261         AutoSet = SK_FALSE;
3262         if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3263                 AutoNeg_A[pAC->Index] != NULL) {
3264                 AutoSet = SK_TRUE;
3265                 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3266                     AutoSet = SK_FALSE;
3267                 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3268                     AutoNeg = AN_ON;
3269                 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3270                     AutoNeg = AN_OFF;
3271                 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3272                     AutoNeg = AN_SENS;
3273                 } else {
3274                     printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3275                         AutoNeg_A[pAC->Index]);
3276                 }
3277         }
3278
3279         DuplexCap = DC_BOTH;
3280         DupSet    = SK_FALSE;
3281         if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3282                 DupCap_A[pAC->Index] != NULL) {
3283                 DupSet = SK_TRUE;
3284                 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3285                     DupSet = SK_FALSE;
3286                 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3287                     DuplexCap = DC_BOTH;
3288                 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3289                     DuplexCap = DC_FULL;
3290                 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3291                     DuplexCap = DC_HALF;
3292                 } else {
3293                     printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3294                         DupCap_A[pAC->Index]);
3295                 }
3296         }
3297
3298         /* 
3299         ** Check for illegal combinations 
3300         */
3301         if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3302                 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3303                 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3304                 (pAC->ChipsetType)) {
3305                     printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3306                                         "    Using Full Duplex.\n");
3307                                 DuplexCap = DC_FULL;
3308         }
3309
3310         if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3311                 printk("sk98lin, Port A: DuplexCapabilities"
3312                         " ignored using Sense mode\n");
3313         }
3314
3315         if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3316                 printk("sk98lin: Port A: Illegal combination"
3317                         " of values AutoNeg. and DuplexCap.\n    Using "
3318                         "Full Duplex\n");
3319                 DuplexCap = DC_FULL;
3320         }
3321
3322         if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3323                 DuplexCap = DC_FULL;
3324         }
3325         
3326         if (!AutoSet && DupSet) {
3327                 printk("sk98lin: Port A: Duplex setting not"
3328                         " possible in\n    default AutoNegotiation mode"
3329                         " (Sense).\n    Using AutoNegotiation On\n");
3330                 AutoNeg = AN_ON;
3331         }
3332         
3333         /* 
3334         ** set the desired mode 
3335         */
3336         if (AutoSet || DupSet) {
3337             pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3338         }
3339         
3340         /* 
3341         ** c) Any Flowcontrol-parameter set?
3342         */
3343         if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3344                 FlowCtrl_A[pAC->Index] != NULL) {
3345                 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3346                     IsFlowCtrlDefined = SK_FALSE;
3347                 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3348                     FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3349                 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3350                     FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3351                 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3352                     FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3353                 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3354                     FlowCtrl = SK_FLOW_MODE_NONE;
3355                 } else {
3356                     printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3357                         FlowCtrl_A[pAC->Index]);
3358                     IsFlowCtrlDefined = SK_FALSE;
3359                 }
3360         } else {
3361            IsFlowCtrlDefined = SK_FALSE;
3362         }
3363
3364         if (IsFlowCtrlDefined) {
3365             if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3366                 printk("sk98lin: Port A: FlowControl"
3367                         " impossible without AutoNegotiation,"
3368                         " disabled\n");
3369                 FlowCtrl = SK_FLOW_MODE_NONE;
3370             }
3371             pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3372         }
3373
3374         /*
3375         ** d) What is with the RoleParameter?
3376         */
3377         if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3378                 Role_A[pAC->Index] != NULL) {
3379                 if (strcmp(Role_A[pAC->Index],"")==0) {
3380                    IsRoleDefined = SK_FALSE;
3381                 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3382                     MSMode = SK_MS_MODE_AUTO;
3383                 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3384                     MSMode = SK_MS_MODE_MASTER;
3385                 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3386                     MSMode = SK_MS_MODE_SLAVE;
3387                 } else {
3388                     printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3389                         Role_A[pAC->Index]);
3390                     IsRoleDefined = SK_FALSE;
3391                 }
3392         } else {
3393            IsRoleDefined = SK_FALSE;
3394         }
3395
3396         if (IsRoleDefined == SK_TRUE) {
3397             pAC->GIni.GP[0].PMSMode = MSMode;
3398         }
3399         
3400
3401         
3402         /* 
3403         ** Parse any parameter settings for port B:
3404         ** a) any LinkSpeed stated?
3405         */
3406         IsConTypeDefined   = SK_TRUE;
3407         IsLinkSpeedDefined = SK_TRUE;
3408         IsFlowCtrlDefined  = SK_TRUE;
3409         IsModeDefined      = SK_TRUE;
3410
3411         if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3412                 Speed_B[pAC->Index] != NULL) {
3413                 if (strcmp(Speed_B[pAC->Index],"")==0) {
3414                     IsLinkSpeedDefined = SK_FALSE;
3415                 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3416                     LinkSpeed = SK_LSPEED_AUTO;
3417                 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3418                     LinkSpeed = SK_LSPEED_10MBPS;
3419                 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3420                     LinkSpeed = SK_LSPEED_100MBPS;
3421                 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3422                     LinkSpeed = SK_LSPEED_1000MBPS;
3423                 } else {
3424                     printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3425                         Speed_B[pAC->Index]);
3426                     IsLinkSpeedDefined = SK_FALSE;
3427                 }
3428         } else {
3429             IsLinkSpeedDefined = SK_FALSE;
3430         }
3431
3432         /* 
3433         ** Check speed parameter:
3434         **    Only copper type adapter and GE V2 cards 
3435         */
3436         if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3437                 ((LinkSpeed != SK_LSPEED_AUTO) &&
3438                 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3439                 printk("sk98lin: Illegal value for Speed_B. "
3440                         "Not a copper card or GE V2 card\n    Using "
3441                         "speed 1000\n");
3442                 LinkSpeed = SK_LSPEED_1000MBPS;
3443         }
3444
3445         /*      
3446         ** Decide whether to set new config value if somethig valid has
3447         ** been received.
3448         */
3449         if (IsLinkSpeedDefined) {
3450             pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3451         }
3452
3453         /* 
3454         ** b) Any Autonegotiation and DuplexCapabilities set?
3455         **    Please note that both belong together...
3456         */
3457         AutoNeg = AN_SENS; /* default: do auto Sense */
3458         AutoSet = SK_FALSE;
3459         if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3460                 AutoNeg_B[pAC->Index] != NULL) {
3461                 AutoSet = SK_TRUE;
3462                 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3463                     AutoSet = SK_FALSE;
3464                 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3465                     AutoNeg = AN_ON;
3466                 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3467                     AutoNeg = AN_OFF;
3468                 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3469                     AutoNeg = AN_SENS;
3470                 } else {
3471                     printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3472                         AutoNeg_B[pAC->Index]);
3473                 }
3474         }
3475
3476         DuplexCap = DC_BOTH;
3477         DupSet    = SK_FALSE;
3478         if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3479                 DupCap_B[pAC->Index] != NULL) {
3480                 DupSet = SK_TRUE;
3481                 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3482                     DupSet = SK_FALSE;
3483                 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3484                     DuplexCap = DC_BOTH;
3485                 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3486                     DuplexCap = DC_FULL;
3487                 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3488                     DuplexCap = DC_HALF;
3489                 } else {
3490                     printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3491                         DupCap_B[pAC->Index]);
3492                 }
3493         }
3494
3495         
3496         /* 
3497         ** Check for illegal combinations 
3498         */
3499         if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3500                 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3501                 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3502                 (pAC->ChipsetType)) {
3503                     printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3504                                         "    Using Full Duplex.\n");
3505                                 DuplexCap = DC_FULL;
3506         }
3507
3508         if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3509                 printk("sk98lin, Port B: DuplexCapabilities"
3510                         " ignored using Sense mode\n");
3511         }
3512
3513         if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3514                 printk("sk98lin: Port B: Illegal combination"
3515                         " of values AutoNeg. and DuplexCap.\n    Using "
3516                         "Full Duplex\n");
3517                 DuplexCap = DC_FULL;
3518         }
3519
3520         if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3521                 DuplexCap = DC_FULL;
3522         }
3523         
3524         if (!AutoSet && DupSet) {
3525                 printk("sk98lin: Port B: Duplex setting not"
3526                         " possible in\n    default AutoNegotiation mode"
3527                         " (Sense).\n    Using AutoNegotiation On\n");
3528                 AutoNeg = AN_ON;
3529         }
3530
3531         /* 
3532         ** set the desired mode 
3533         */
3534         if (AutoSet || DupSet) {
3535             pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3536         }
3537
3538         /*
3539         ** c) Any FlowCtrl parameter set?
3540         */
3541         if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3542                 FlowCtrl_B[pAC->Index] != NULL) {
3543                 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3544                     IsFlowCtrlDefined = SK_FALSE;
3545                 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3546                     FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3547                 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3548                     FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3549                 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3550                     FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3551                 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3552                     FlowCtrl = SK_FLOW_MODE_NONE;
3553                 } else {
3554                     printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3555                         FlowCtrl_B[pAC->Index]);
3556                     IsFlowCtrlDefined = SK_FALSE;
3557                 }
3558         } else {
3559                 IsFlowCtrlDefined = SK_FALSE;
3560         }
3561
3562         if (IsFlowCtrlDefined) {
3563             if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3564                 printk("sk98lin: Port B: FlowControl"
3565                         " impossible without AutoNegotiation,"
3566                         " disabled\n");
3567                 FlowCtrl = SK_FLOW_MODE_NONE;
3568             }
3569             pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3570         }
3571
3572         /*
3573         ** d) What is the RoleParameter?
3574         */
3575         if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3576                 Role_B[pAC->Index] != NULL) {
3577                 if (strcmp(Role_B[pAC->Index],"")==0) {
3578                     IsRoleDefined = SK_FALSE;
3579                 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3580                     MSMode = SK_MS_MODE_AUTO;
3581                 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3582                     MSMode = SK_MS_MODE_MASTER;
3583                 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3584                     MSMode = SK_MS_MODE_SLAVE;
3585                 } else {
3586                     printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3587                         Role_B[pAC->Index]);
3588                     IsRoleDefined = SK_FALSE;
3589                 }
3590         } else {
3591             IsRoleDefined = SK_FALSE;
3592         }
3593
3594         if (IsRoleDefined) {
3595             pAC->GIni.GP[1].PMSMode = MSMode;
3596         }
3597         
3598         /*
3599         ** Evaluate settings for both ports
3600         */
3601         pAC->ActivePort = 0;
3602         if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3603                 PrefPort[pAC->Index] != NULL) {
3604                 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3605                         pAC->ActivePort             =  0;
3606                         pAC->Rlmt.Net[0].Preference = -1; /* auto */
3607                         pAC->Rlmt.Net[0].PrefPort   =  0;
3608                 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3609                         /*
3610                         ** do not set ActivePort here, thus a port
3611                         ** switch is issued after net up.
3612                         */
3613                         Port                        = 0;
3614                         pAC->Rlmt.Net[0].Preference = Port;
3615                         pAC->Rlmt.Net[0].PrefPort   = Port;
3616                 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3617                         /*
3618                         ** do not set ActivePort here, thus a port
3619                         ** switch is issued after net up.
3620                         */
3621                         if (pAC->GIni.GIMacsFound == 1) {
3622                                 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3623                                         "      Port B not available on single port adapters.\n");
3624
3625                                 pAC->ActivePort             =  0;
3626                                 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3627                                 pAC->Rlmt.Net[0].PrefPort   =  0;
3628                         } else {
3629                                 Port                        = 1;
3630                                 pAC->Rlmt.Net[0].Preference = Port;
3631                                 pAC->Rlmt.Net[0].PrefPort   = Port;
3632                         }
3633                 } else {
3634                     printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3635                         PrefPort[pAC->Index]);
3636                 }
3637         }
3638
3639         pAC->RlmtNets = 1;
3640
3641         if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3642                 RlmtMode[pAC->Index] != NULL) {
3643                 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3644                         pAC->RlmtMode = 0;
3645                 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3646                         pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3647                 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3648                         pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3649                                         SK_RLMT_CHECK_LOC_LINK;
3650                 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3651                         pAC->RlmtMode = SK_RLMT_CHECK_LINK     |
3652                                         SK_RLMT_CHECK_LOC_LINK |
3653                                         SK_RLMT_CHECK_SEG;
3654                 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3655                         (pAC->GIni.GIMacsFound == 2)) {
3656                         pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3657                         pAC->RlmtNets = 2;
3658                 } else {
3659                     printk("sk98lin: Illegal value \"%s\" for"
3660                         " RlmtMode, using default\n", 
3661                         RlmtMode[pAC->Index]);
3662                         pAC->RlmtMode = 0;
3663                 }
3664         } else {
3665                 pAC->RlmtMode = 0;
3666         }
3667         
3668         /*
3669         ** Check the interrupt moderation parameters
3670         */
3671         if (Moderation[pAC->Index] != NULL) {
3672                 if (strcmp(Moderation[pAC->Index], "") == 0) {
3673                         pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3674                 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3675                         pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3676                 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3677                         pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3678                 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3679                         pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3680                 } else {
3681                         printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3682                                 "      Disable interrupt moderation.\n",
3683                                 Moderation[pAC->Index]);
3684                         pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3685                 }
3686         } else {
3687                 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3688         }
3689
3690         if (Stats[pAC->Index] != NULL) {
3691                 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3692                         pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3693                 } else {
3694                         pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3695                 }
3696         } else {
3697                 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3698         }
3699
3700         if (ModerationMask[pAC->Index] != NULL) {
3701                 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3702                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3703                 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3704                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3705                 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3706                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3707                 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3708                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3709                 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3710                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3711                 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3712                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3713                 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3714                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3715                 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3716                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3717                 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3718                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3719                 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3720                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3721                 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3722                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3723                 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3724                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3725                 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3726                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3727                 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3728                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3729                 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3730                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3731                 } else { /* some rubbish */
3732                         pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3733                 }
3734         } else {  /* operator has stated nothing */
3735                 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3736         }
3737
3738         if (AutoSizing[pAC->Index] != NULL) {
3739                 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3740                         pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3741                 } else {
3742                         pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3743                 }
3744         } else {  /* operator has stated nothing */
3745                 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3746         }
3747
3748         if (IntsPerSec[pAC->Index] != 0) {
3749                 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) || 
3750                         (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3751                         printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3752                                 "      Using default value of %i.\n", 
3753                                 IntsPerSec[pAC->Index],
3754                                 C_INT_MOD_IPS_LOWER_RANGE,
3755                                 C_INT_MOD_IPS_UPPER_RANGE,
3756                                 C_INTS_PER_SEC_DEFAULT);
3757                         pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3758                 } else {
3759                         pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3760                 }
3761         } else {
3762                 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3763         }
3764
3765         /*
3766         ** Evaluate upper and lower moderation threshold
3767         */
3768         pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3769                 pAC->DynIrqModInfo.MaxModIntsPerSec +
3770                 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3771
3772         pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3773                 pAC->DynIrqModInfo.MaxModIntsPerSec -
3774                 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3775
3776         pAC->DynIrqModInfo.PrevTimeVal = jiffies;  /* initial value */
3777
3778
3779 } /* GetConfiguration */
3780
3781
3782 /*****************************************************************************
3783  *
3784  *      ProductStr - return a adapter identification string from vpd
3785  *
3786  * Description:
3787  *      This function reads the product name string from the vpd area
3788  *      and puts it the field pAC->DeviceString.
3789  *
3790  * Returns: N/A
3791  */
3792 static void ProductStr(
3793 SK_AC   *pAC            /* pointer to adapter context */
3794 )
3795 {
3796 int     StrLen = 80;            /* length of the string, defined in SK_AC */
3797 char    Keyword[] = VPD_NAME;   /* vpd productname identifier */
3798 int     ReturnCode;             /* return code from vpd_read */
3799 unsigned long Flags;
3800
3801         spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3802         ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3803                 &StrLen);
3804         spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3805         if (ReturnCode != 0) {
3806                 /* there was an error reading the vpd data */
3807                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3808                         ("Error reading VPD data: %d\n", ReturnCode));
3809                 pAC->DeviceStr[0] = '\0';
3810         }
3811 } /* ProductStr */
3812
3813 /*****************************************************************************
3814  *
3815  *      StartDrvCleanupTimer - Start timer to check for descriptors which
3816  *                             might be placed in descriptor ring, but
3817  *                             havent been handled up to now
3818  *
3819  * Description:
3820  *      This function requests a HW-timer fo the Yukon card. The actions to
3821  *      perform when this timer expires, are located in the SkDrvEvent().
3822  *
3823  * Returns: N/A
3824  */
3825 static void
3826 StartDrvCleanupTimer(SK_AC *pAC) {
3827     SK_EVPARA    EventParam;   /* Event struct for timer event */
3828
3829     SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3830     EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3831     SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3832                  SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3833                  SKGE_DRV, SK_DRV_TIMER, EventParam);
3834 }
3835
3836 /*****************************************************************************
3837  *
3838  *      StopDrvCleanupTimer - Stop timer to check for descriptors
3839  *
3840  * Description:
3841  *      This function requests a HW-timer fo the Yukon card. The actions to
3842  *      perform when this timer expires, are located in the SkDrvEvent().
3843  *
3844  * Returns: N/A
3845  */
3846 static void
3847 StopDrvCleanupTimer(SK_AC *pAC) {
3848     SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3849     SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3850 }
3851
3852 /****************************************************************************/
3853 /* functions for common modules *********************************************/
3854 /****************************************************************************/
3855
3856
3857 /*****************************************************************************
3858  *
3859  *      SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3860  *
3861  * Description:
3862  *      This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3863  *      is embedded into a socket buff data area.
3864  *
3865  * Context:
3866  *      runtime
3867  *
3868  * Returns:
3869  *      NULL or pointer to Mbuf.
3870  */
3871 SK_MBUF *SkDrvAllocRlmtMbuf(
3872 SK_AC           *pAC,           /* pointer to adapter context */
3873 SK_IOC          IoC,            /* the IO-context */
3874 unsigned        BufferSize)     /* size of the requested buffer */
3875 {
3876 SK_MBUF         *pRlmtMbuf;     /* pointer to a new rlmt-mbuf structure */
3877 struct sk_buff  *pMsgBlock;     /* pointer to a new message block */
3878
3879         pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3880         if (pMsgBlock == NULL) {
3881                 return (NULL);
3882         }
3883         pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3884         skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3885         pRlmtMbuf->pNext = NULL;
3886         pRlmtMbuf->pOs = pMsgBlock;
3887         pRlmtMbuf->pData = pMsgBlock->data;     /* Data buffer. */
3888         pRlmtMbuf->Size = BufferSize;           /* Data buffer size. */
3889         pRlmtMbuf->Length = 0;          /* Length of packet (<= Size). */
3890         return (pRlmtMbuf);
3891
3892 } /* SkDrvAllocRlmtMbuf */
3893
3894
3895 /*****************************************************************************
3896  *
3897  *      SkDrvFreeRlmtMbuf - free an RLMT mbuf
3898  *
3899  * Description:
3900  *      This routine frees one or more RLMT mbuf(s).
3901  *
3902  * Context:
3903  *      runtime
3904  *
3905  * Returns:
3906  *      Nothing
3907  */
3908 void  SkDrvFreeRlmtMbuf(
3909 SK_AC           *pAC,           /* pointer to adapter context */
3910 SK_IOC          IoC,            /* the IO-context */
3911 SK_MBUF         *pMbuf)         /* size of the requested buffer */
3912 {
3913 SK_MBUF         *pFreeMbuf;
3914 SK_MBUF         *pNextMbuf;
3915
3916         pFreeMbuf = pMbuf;
3917         do {
3918                 pNextMbuf = pFreeMbuf->pNext;
3919                 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3920                 pFreeMbuf = pNextMbuf;
3921         } while ( pFreeMbuf != NULL );
3922 } /* SkDrvFreeRlmtMbuf */
3923
3924
3925 /*****************************************************************************
3926  *
3927  *      SkOsGetTime - provide a time value
3928  *
3929  * Description:
3930  *      This routine provides a time value. The unit is 1/HZ (defined by Linux).
3931  *      It is not used for absolute time, but only for time differences.
3932  *
3933  *
3934  * Returns:
3935  *      Time value
3936  */
3937 SK_U64 SkOsGetTime(SK_AC *pAC)
3938 {
3939         SK_U64  PrivateJiffies;
3940         SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3941         return PrivateJiffies;
3942 } /* SkOsGetTime */
3943
3944
3945 /*****************************************************************************
3946  *
3947  *      SkPciReadCfgDWord - read a 32 bit value from pci config space
3948  *
3949  * Description:
3950  *      This routine reads a 32 bit value from the pci configuration
3951  *      space.
3952  *
3953  * Returns:
3954  *      0 - indicate everything worked ok.
3955  *      != 0 - error indication
3956  */
3957 int SkPciReadCfgDWord(
3958 SK_AC *pAC,             /* Adapter Control structure pointer */
3959 int PciAddr,            /* PCI register address */
3960 SK_U32 *pVal)           /* pointer to store the read value */
3961 {
3962         pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3963         return(0);
3964 } /* SkPciReadCfgDWord */
3965
3966
3967 /*****************************************************************************
3968  *
3969  *      SkPciReadCfgWord - read a 16 bit value from pci config space
3970  *
3971  * Description:
3972  *      This routine reads a 16 bit value from the pci configuration
3973  *      space.
3974  *
3975  * Returns:
3976  *      0 - indicate everything worked ok.
3977  *      != 0 - error indication
3978  */
3979 int SkPciReadCfgWord(
3980 SK_AC *pAC,     /* Adapter Control structure pointer */
3981 int PciAddr,            /* PCI register address */
3982 SK_U16 *pVal)           /* pointer to store the read value */
3983 {
3984         pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3985         return(0);
3986 } /* SkPciReadCfgWord */
3987
3988
3989 /*****************************************************************************
3990  *
3991  *      SkPciReadCfgByte - read a 8 bit value from pci config space
3992  *
3993  * Description:
3994  *      This routine reads a 8 bit value from the pci configuration
3995  *      space.
3996  *
3997  * Returns:
3998  *      0 - indicate everything worked ok.
3999  *      != 0 - error indication
4000  */
4001 int SkPciReadCfgByte(
4002 SK_AC *pAC,     /* Adapter Control structure pointer */
4003 int PciAddr,            /* PCI register address */
4004 SK_U8 *pVal)            /* pointer to store the read value */
4005 {
4006         pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4007         return(0);
4008 } /* SkPciReadCfgByte */
4009
4010
4011 /*****************************************************************************
4012  *
4013  *      SkPciWriteCfgWord - write a 16 bit value to pci config space
4014  *
4015  * Description:
4016  *      This routine writes a 16 bit value to the pci configuration
4017  *      space. The flag PciConfigUp indicates whether the config space
4018  *      is accesible or must be set up first.
4019  *
4020  * Returns:
4021  *      0 - indicate everything worked ok.
4022  *      != 0 - error indication
4023  */
4024 int SkPciWriteCfgWord(
4025 SK_AC *pAC,     /* Adapter Control structure pointer */
4026 int PciAddr,            /* PCI register address */
4027 SK_U16 Val)             /* pointer to store the read value */
4028 {
4029         pci_write_config_word(pAC->PciDev, PciAddr, Val);
4030         return(0);
4031 } /* SkPciWriteCfgWord */
4032
4033
4034 /*****************************************************************************
4035  *
4036  *      SkPciWriteCfgWord - write a 8 bit value to pci config space
4037  *
4038  * Description:
4039  *      This routine writes a 8 bit value to the pci configuration
4040  *      space. The flag PciConfigUp indicates whether the config space
4041  *      is accesible or must be set up first.
4042  *
4043  * Returns:
4044  *      0 - indicate everything worked ok.
4045  *      != 0 - error indication
4046  */
4047 int SkPciWriteCfgByte(
4048 SK_AC *pAC,     /* Adapter Control structure pointer */
4049 int PciAddr,            /* PCI register address */
4050 SK_U8 Val)              /* pointer to store the read value */
4051 {
4052         pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4053         return(0);
4054 } /* SkPciWriteCfgByte */
4055
4056
4057 /*****************************************************************************
4058  *
4059  *      SkDrvEvent - handle driver events
4060  *
4061  * Description:
4062  *      This function handles events from all modules directed to the driver
4063  *
4064  * Context:
4065  *      Is called under protection of slow path lock.
4066  *
4067  * Returns:
4068  *      0 if everything ok
4069  *      < 0  on error
4070  *      
4071  */
4072 int SkDrvEvent(
4073 SK_AC *pAC,             /* pointer to adapter context */
4074 SK_IOC IoC,             /* io-context */
4075 SK_U32 Event,           /* event-id */
4076 SK_EVPARA Param)        /* event-parameter */
4077 {
4078 SK_MBUF         *pRlmtMbuf;     /* pointer to a rlmt-mbuf structure */
4079 struct sk_buff  *pMsg;          /* pointer to a message block */
4080 int             FromPort;       /* the port from which we switch away */
4081 int             ToPort;         /* the port we switch to */
4082 SK_EVPARA       NewPara;        /* parameter for further events */
4083 int             Stat;
4084 unsigned long   Flags;
4085 SK_BOOL         DualNet;
4086
4087         switch (Event) {
4088         case SK_DRV_ADAP_FAIL:
4089                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4090                         ("ADAPTER FAIL EVENT\n"));
4091                 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4092                 /* disable interrupts */
4093                 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4094                 /* cgoos */
4095                 break;
4096         case SK_DRV_PORT_FAIL:
4097                 FromPort = Param.Para32[0];
4098                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4099                         ("PORT FAIL EVENT, Port: %d\n", FromPort));
4100                 if (FromPort == 0) {
4101                         printk("%s: Port A failed.\n", pAC->dev[0]->name);
4102                 } else {
4103                         printk("%s: Port B failed.\n", pAC->dev[1]->name);
4104                 }
4105                 /* cgoos */
4106                 break;
4107         case SK_DRV_PORT_RESET:  /* SK_U32 PortIdx */
4108                 /* action list 4 */
4109                 FromPort = Param.Para32[0];
4110                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4111                         ("PORT RESET EVENT, Port: %d ", FromPort));
4112                 NewPara.Para64 = FromPort;
4113                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4114                 spin_lock_irqsave(
4115                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4116                         Flags);
4117
4118                 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4119                 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4120                 spin_unlock_irqrestore(
4121                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4122                         Flags);
4123                 
4124                 /* clear rx ring from received frames */
4125                 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4126                 
4127                 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4128                 spin_lock_irqsave(
4129                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4130                         Flags);
4131                 
4132                 /* tschilling: Handling of return value inserted. */
4133                 if (SkGeInitPort(pAC, IoC, FromPort)) {
4134                         if (FromPort == 0) {
4135                                 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4136                         } else {
4137                                 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4138                         }
4139                 }
4140                 SkAddrMcUpdate(pAC,IoC, FromPort);
4141                 PortReInitBmu(pAC, FromPort);
4142                 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4143                 ClearAndStartRx(pAC, FromPort);
4144                 spin_unlock_irqrestore(
4145                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4146                         Flags);
4147                 break;
4148         case SK_DRV_NET_UP:      /* SK_U32 PortIdx */
4149         {       struct net_device *dev = pAC->dev[Param.Para32[0]];
4150                 /* action list 5 */
4151                 FromPort = Param.Para32[0];
4152                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4153                         ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4154                 /* Mac update */
4155                 SkAddrMcUpdate(pAC,IoC, FromPort);
4156
4157                 if (DoPrintInterfaceChange) {
4158                 printk("%s: network connection up using"
4159                         " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4160
4161                 /* tschilling: Values changed according to LinkSpeedUsed. */
4162                 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4163                 if (Stat == SK_LSPEED_STAT_10MBPS) {
4164                         printk("    speed:           10\n");
4165                 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4166                         printk("    speed:           100\n");
4167                 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4168                         printk("    speed:           1000\n");
4169                 } else {
4170                         printk("    speed:           unknown\n");
4171                 }
4172
4173
4174                 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4175                 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4176                         Stat == SK_LMODE_STAT_AUTOFULL) {
4177                         printk("    autonegotiation: yes\n");
4178                 }
4179                 else {
4180                         printk("    autonegotiation: no\n");
4181                 }
4182                 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4183                         Stat == SK_LMODE_STAT_HALF) {
4184                         printk("    duplex mode:     half\n");
4185                 }
4186                 else {
4187                         printk("    duplex mode:     full\n");
4188                 }
4189                 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4190                 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4191                         printk("    flowctrl:        remote send\n");
4192                 }
4193                 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4194                         printk("    flowctrl:        local send\n");
4195                 }
4196                 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4197                         printk("    flowctrl:        symmetric\n");
4198                 }
4199                 else {
4200                         printk("    flowctrl:        none\n");
4201                 }
4202                 
4203                 /* tschilling: Check against CopperType now. */
4204                 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4205                         (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4206                         SK_LSPEED_STAT_1000MBPS)) {
4207                         Stat = pAC->GIni.GP[FromPort].PMSStatus;
4208                         if (Stat == SK_MS_STAT_MASTER ) {
4209                                 printk("    role:            master\n");
4210                         }
4211                         else if (Stat == SK_MS_STAT_SLAVE ) {
4212                                 printk("    role:            slave\n");
4213                         }
4214                         else {
4215                                 printk("    role:            ???\n");
4216                         }
4217                 }
4218
4219                 /* 
4220                    Display dim (dynamic interrupt moderation) 
4221                    informations
4222                  */
4223                 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4224                         printk("    irq moderation:  static (%d ints/sec)\n",
4225                                         pAC->DynIrqModInfo.MaxModIntsPerSec);
4226                 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4227                         printk("    irq moderation:  dynamic (%d ints/sec)\n",
4228                                         pAC->DynIrqModInfo.MaxModIntsPerSec);
4229                 else
4230                         printk("    irq moderation:  disabled\n");
4231
4232
4233                 printk("    scatter-gather:  %s\n",
4234                        (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4235                 printk("    tx-checksum:     %s\n",
4236                        (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4237                 printk("    rx-checksum:     %s\n",
4238                        pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4239
4240                 } else {
4241                         DoPrintInterfaceChange = SK_TRUE;
4242                 }
4243         
4244                 if ((Param.Para32[0] != pAC->ActivePort) &&
4245                         (pAC->RlmtNets == 1)) {
4246                         NewPara.Para32[0] = pAC->ActivePort;
4247                         NewPara.Para32[1] = Param.Para32[0];
4248                         SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4249                                 NewPara);
4250                 }
4251
4252                 /* Inform the world that link protocol is up. */
4253                 netif_carrier_on(dev);
4254                 break;
4255         }
4256         case SK_DRV_NET_DOWN:    /* SK_U32 Reason */
4257                 /* action list 7 */
4258                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4259                         ("NET DOWN EVENT "));
4260                 if (DoPrintInterfaceChange) {
4261                         printk("%s: network connection down\n", 
4262                                 pAC->dev[Param.Para32[1]]->name);
4263                 } else {
4264                         DoPrintInterfaceChange = SK_TRUE;
4265                 }
4266                 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4267                 break;
4268         case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4269                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4270                         ("PORT SWITCH HARD "));
4271         case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4272         /* action list 6 */
4273                 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4274                         'A'+Param.Para32[1]);
4275         case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4276                 FromPort = Param.Para32[0];
4277                 ToPort = Param.Para32[1];
4278                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4279                         ("PORT SWITCH EVENT, From: %d  To: %d (Pref %d) ",
4280                         FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4281                 NewPara.Para64 = FromPort;
4282                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4283                 NewPara.Para64 = ToPort;
4284                 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4285                 spin_lock_irqsave(
4286                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4287                         Flags);
4288                 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4289                 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4290                 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4291                 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4292                 spin_unlock_irqrestore(
4293                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4294                         Flags);
4295
4296                 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4297                 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4298                 
4299                 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4300                 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4301                 spin_lock_irqsave(
4302                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4303                         Flags);
4304                 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4305                 pAC->ActivePort = ToPort;
4306 #if 0
4307                 SetQueueSizes(pAC);
4308 #else
4309                 /* tschilling: New common function with minimum size check. */
4310                 DualNet = SK_FALSE;
4311                 if (pAC->RlmtNets == 2) {
4312                         DualNet = SK_TRUE;
4313                 }
4314                 
4315                 if (SkGeInitAssignRamToQueues(
4316                         pAC,
4317                         pAC->ActivePort,
4318                         DualNet)) {
4319                         spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4320                         spin_unlock_irqrestore(
4321                                 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4322                                 Flags);
4323                         printk("SkGeInitAssignRamToQueues failed.\n");
4324                         break;
4325                 }
4326 #endif
4327                 /* tschilling: Handling of return values inserted. */
4328                 if (SkGeInitPort(pAC, IoC, FromPort) ||
4329                         SkGeInitPort(pAC, IoC, ToPort)) {
4330                         printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4331                 }
4332                 if (Event == SK_DRV_SWITCH_SOFT) {
4333                         SkMacRxTxEnable(pAC, IoC, FromPort);
4334                 }
4335                 SkMacRxTxEnable(pAC, IoC, ToPort);
4336                 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4337                 SkAddrMcUpdate(pAC, IoC, FromPort);
4338                 SkAddrMcUpdate(pAC, IoC, ToPort);
4339                 PortReInitBmu(pAC, FromPort);
4340                 PortReInitBmu(pAC, ToPort);
4341                 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4342                 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4343                 ClearAndStartRx(pAC, FromPort);
4344                 ClearAndStartRx(pAC, ToPort);
4345                 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4346                 spin_unlock_irqrestore(
4347                         &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4348                         Flags);
4349                 break;
4350         case SK_DRV_RLMT_SEND:   /* SK_MBUF *pMb */
4351                 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4352                         ("RLS "));
4353                 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4354                 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4355                 skb_put(pMsg, pRlmtMbuf->Length);
4356                 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4357                         pMsg) < 0)
4358
4359                         DEV_KFREE_SKB_ANY(pMsg);
4360                 break;
4361         case SK_DRV_TIMER:
4362                 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4363                         /*
4364                         ** expiration of the moderation timer implies that
4365                         ** dynamic moderation is to be applied
4366                         */
4367                         SkDimStartModerationTimer(pAC);
4368                         SkDimModerate(pAC);
4369                         if (pAC->DynIrqModInfo.DisplayStats) {
4370                             SkDimDisplayModerationSettings(pAC);
4371                         }
4372                 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4373                         /*
4374                         ** check if we need to check for descriptors which
4375                         ** haven't been handled the last millisecs
4376                         */
4377                         StartDrvCleanupTimer(pAC);
4378                         if (pAC->GIni.GIMacsFound == 2) {
4379                                 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4380                         }
4381                         ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4382                 } else {
4383                         printk("Expiration of unknown timer\n");
4384                 }
4385                 break;
4386         default:
4387                 break;
4388         }
4389         SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4390                 ("END EVENT "));
4391         
4392         return (0);
4393 } /* SkDrvEvent */
4394
4395
4396 /*****************************************************************************
4397  *
4398  *      SkErrorLog - log errors
4399  *
4400  * Description:
4401  *      This function logs errors to the system buffer and to the console
4402  *
4403  * Returns:
4404  *      0 if everything ok
4405  *      < 0  on error
4406  *      
4407  */
4408 void SkErrorLog(
4409 SK_AC   *pAC,
4410 int     ErrClass,
4411 int     ErrNum,
4412 char    *pErrorMsg)
4413 {
4414 char    ClassStr[80];
4415
4416         switch (ErrClass) {
4417         case SK_ERRCL_OTHER:
4418                 strcpy(ClassStr, "Other error");
4419                 break;
4420         case SK_ERRCL_CONFIG:
4421                 strcpy(ClassStr, "Configuration error");
4422                 break;
4423         case SK_ERRCL_INIT:
4424                 strcpy(ClassStr, "Initialization error");
4425                 break;
4426         case SK_ERRCL_NORES:
4427                 strcpy(ClassStr, "Out of resources error");
4428                 break;
4429         case SK_ERRCL_SW:
4430                 strcpy(ClassStr, "internal Software error");
4431                 break;
4432         case SK_ERRCL_HW:
4433                 strcpy(ClassStr, "Hardware failure");
4434                 break;
4435         case SK_ERRCL_COMM:
4436                 strcpy(ClassStr, "Communication error");
4437                 break;
4438         }
4439         printk(KERN_INFO "%s: -- ERROR --\n        Class:  %s\n"
4440                 "        Nr:  0x%x\n        Msg:  %s\n", pAC->dev[0]->name,
4441                 ClassStr, ErrNum, pErrorMsg);
4442
4443 } /* SkErrorLog */
4444
4445 #ifdef SK_DIAG_SUPPORT
4446
4447 /*****************************************************************************
4448  *
4449  *      SkDrvEnterDiagMode - handles DIAG attach request
4450  *
4451  * Description:
4452  *      Notify the kernel to NOT access the card any longer due to DIAG
4453  *      Deinitialize the Card
4454  *
4455  * Returns:
4456  *      int
4457  */
4458 int SkDrvEnterDiagMode(
4459 SK_AC   *pAc)   /* pointer to adapter context */
4460 {
4461         DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4462         SK_AC   *pAC  = pNet->pAC;
4463
4464         SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct), 
4465                         sizeof(SK_PNMI_STRUCT_DATA));
4466
4467         pAC->DiagModeActive = DIAG_ACTIVE;
4468         if (pAC->BoardLevel > SK_INIT_DATA) {
4469                 if (pNet->Up) {
4470                         pAC->WasIfUp[0] = SK_TRUE;
4471                         pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose      */
4472                         DoPrintInterfaceChange = SK_FALSE;
4473                         SkDrvDeInitAdapter(pAC, 0);  /* performs SkGeClose */
4474                 } else {
4475                         pAC->WasIfUp[0] = SK_FALSE;
4476                 }
4477                 if (pNet != netdev_priv(pAC->dev[1])) {
4478                         pNet = netdev_priv(pAC->dev[1]);
4479                         if (pNet->Up) {
4480                                 pAC->WasIfUp[1] = SK_TRUE;
4481                                 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4482                                 DoPrintInterfaceChange = SK_FALSE;
4483                                 SkDrvDeInitAdapter(pAC, 1);  /* do SkGeClose  */
4484                         } else {
4485                                 pAC->WasIfUp[1] = SK_FALSE;
4486                         }
4487                 }
4488                 pAC->BoardLevel = SK_INIT_DATA;
4489         }
4490         return(0);
4491 }
4492
4493 /*****************************************************************************
4494  *
4495  *      SkDrvLeaveDiagMode - handles DIAG detach request
4496  *
4497  * Description:
4498  *      Notify the kernel to may access the card again after use by DIAG
4499  *      Initialize the Card
4500  *
4501  * Returns:
4502  *      int
4503  */
4504 int SkDrvLeaveDiagMode(
4505 SK_AC   *pAc)   /* pointer to adapter control context */
4506
4507         SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup), 
4508                         sizeof(SK_PNMI_STRUCT_DATA));
4509         pAc->DiagModeActive    = DIAG_NOTACTIVE;
4510         pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4511         if (pAc->WasIfUp[0] == SK_TRUE) {
4512                 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4513                 DoPrintInterfaceChange = SK_FALSE;
4514                 SkDrvInitAdapter(pAc, 0);    /* first device  */
4515         }
4516         if (pAc->WasIfUp[1] == SK_TRUE) {
4517                 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4518                 DoPrintInterfaceChange = SK_FALSE;
4519                 SkDrvInitAdapter(pAc, 1);    /* second device */
4520         }
4521         return(0);
4522 }
4523
4524 /*****************************************************************************
4525  *
4526  *      ParseDeviceNbrFromSlotName - Evaluate PCI device number
4527  *
4528  * Description:
4529  *      This function parses the PCI slot name information string and will
4530  *      retrieve the devcie number out of it. The slot_name maintianed by
4531  *      linux is in the form of '02:0a.0', whereas the first two characters 
4532  *      represent the bus number in hex (in the sample above this is 
4533  *      pci bus 0x02) and the next two characters the device number (0x0a).
4534  *
4535  * Returns:
4536  *      SK_U32: The device number from the PCI slot name
4537  */ 
4538
4539 static SK_U32 ParseDeviceNbrFromSlotName(
4540 const char *SlotName)   /* pointer to pci slot name eg. '02:0a.0' */
4541 {
4542         char    *CurrCharPos    = (char *) SlotName;
4543         int     FirstNibble     = -1;
4544         int     SecondNibble    = -1;
4545         SK_U32  Result          =  0;
4546
4547         while (*CurrCharPos != '\0') {
4548                 if (*CurrCharPos == ':') { 
4549                         while (*CurrCharPos != '.') {
4550                                 CurrCharPos++;  
4551                                 if (    (*CurrCharPos >= '0') && 
4552                                         (*CurrCharPos <= '9')) {
4553                                         if (FirstNibble == -1) {
4554                                                 /* dec. value for '0' */
4555                                                 FirstNibble = *CurrCharPos - 48;
4556                                         } else {
4557                                                 SecondNibble = *CurrCharPos - 48;
4558                                         }  
4559                                 } else if (     (*CurrCharPos >= 'a') && 
4560                                                 (*CurrCharPos <= 'f')  ) {
4561                                         if (FirstNibble == -1) {
4562                                                 FirstNibble = *CurrCharPos - 87; 
4563                                         } else {
4564                                                 SecondNibble = *CurrCharPos - 87; 
4565                                         }
4566                                 } else {
4567                                         Result = 0;
4568                                 }
4569                         }
4570
4571                         Result = FirstNibble;
4572                         Result = Result << 4; /* first nibble is higher one */
4573                         Result = Result | SecondNibble;
4574                 }
4575                 CurrCharPos++;   /* next character */
4576         }
4577         return (Result);
4578 }
4579
4580 /****************************************************************************
4581  *
4582  *      SkDrvDeInitAdapter - deinitialize adapter (this function is only 
4583  *                              called if Diag attaches to that card)
4584  *
4585  * Description:
4586  *      Close initialized adapter.
4587  *
4588  * Returns:
4589  *      0 - on success
4590  *      error code - on error
4591  */
4592 static int SkDrvDeInitAdapter(
4593 SK_AC   *pAC,           /* pointer to adapter context   */
4594 int      devNbr)        /* what device is to be handled */
4595 {
4596         struct SK_NET_DEVICE *dev;
4597
4598         dev = pAC->dev[devNbr];
4599
4600         /* On Linux 2.6 the network driver does NOT mess with reference
4601         ** counts.  The driver MUST be able to be unloaded at any time
4602         ** due to the possibility of hotplug.
4603         */
4604         if (SkGeClose(dev) != 0) {
4605                 return (-1);
4606         }
4607         return (0);
4608
4609 } /* SkDrvDeInitAdapter() */
4610
4611 /****************************************************************************
4612  *
4613  *      SkDrvInitAdapter - Initialize adapter (this function is only 
4614  *                              called if Diag deattaches from that card)
4615  *
4616  * Description:
4617  *      Close initialized adapter.
4618  *
4619  * Returns:
4620  *      0 - on success
4621  *      error code - on error
4622  */
4623 static int SkDrvInitAdapter(
4624 SK_AC   *pAC,           /* pointer to adapter context   */
4625 int      devNbr)        /* what device is to be handled */
4626 {
4627         struct SK_NET_DEVICE *dev;
4628
4629         dev = pAC->dev[devNbr];
4630
4631         if (SkGeOpen(dev) != 0) {
4632                 return (-1);
4633         }
4634
4635         /*
4636         ** Use correct MTU size and indicate to kernel TX queue can be started
4637         */ 
4638         if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4639                 return (-1);
4640         } 
4641         return (0);
4642
4643 } /* SkDrvInitAdapter */
4644
4645 #endif
4646
4647 #ifdef DEBUG
4648 /****************************************************************************/
4649 /* "debug only" section *****************************************************/
4650 /****************************************************************************/
4651
4652
4653 /*****************************************************************************
4654  *
4655  *      DumpMsg - print a frame
4656  *
4657  * Description:
4658  *      This function prints frames to the system logfile/to the console.
4659  *
4660  * Returns: N/A
4661  *      
4662  */
4663 static void DumpMsg(struct sk_buff *skb, char *str)
4664 {
4665         int     msglen;
4666
4667         if (skb == NULL) {
4668                 printk("DumpMsg(): NULL-Message\n");
4669                 return;
4670         }
4671
4672         if (skb->data == NULL) {
4673                 printk("DumpMsg(): Message empty\n");
4674                 return;
4675         }
4676
4677         msglen = skb->len;
4678         if (msglen > 64)
4679                 msglen = 64;
4680
4681         printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4682
4683         DumpData((char *)skb->data, msglen);
4684
4685         printk("------- End of message ---------\n");
4686 } /* DumpMsg */
4687
4688
4689
4690 /*****************************************************************************
4691  *
4692  *      DumpData - print a data area
4693  *
4694  * Description:
4695  *      This function prints a area of data to the system logfile/to the
4696  *      console.
4697  *
4698  * Returns: N/A
4699  *      
4700  */
4701 static void DumpData(char *p, int size)
4702 {
4703 register int    i;
4704 int     haddr, addr;
4705 char    hex_buffer[180];
4706 char    asc_buffer[180];
4707 char    HEXCHAR[] = "0123456789ABCDEF";
4708
4709         addr = 0;
4710         haddr = 0;
4711         hex_buffer[0] = 0;
4712         asc_buffer[0] = 0;
4713         for (i=0; i < size; ) {
4714                 if (*p >= '0' && *p <='z')
4715                         asc_buffer[addr] = *p;
4716                 else
4717                         asc_buffer[addr] = '.';
4718                 addr++;
4719                 asc_buffer[addr] = 0;
4720                 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4721                 haddr++;
4722                 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4723                 haddr++;
4724                 hex_buffer[haddr] = ' ';
4725                 haddr++;
4726                 hex_buffer[haddr] = 0;
4727                 p++;
4728                 i++;
4729                 if (i%16 == 0) {
4730                         printk("%s  %s\n", hex_buffer, asc_buffer);
4731                         addr = 0;
4732                         haddr = 0;
4733                 }
4734         }
4735 } /* DumpData */
4736
4737
4738 /*****************************************************************************
4739  *
4740  *      DumpLong - print a data area as long values
4741  *
4742  * Description:
4743  *      This function prints a area of data to the system logfile/to the
4744  *      console.
4745  *
4746  * Returns: N/A
4747  *      
4748  */
4749 static void DumpLong(char *pc, int size)
4750 {
4751 register int    i;
4752 int     haddr, addr;
4753 char    hex_buffer[180];
4754 char    asc_buffer[180];
4755 char    HEXCHAR[] = "0123456789ABCDEF";
4756 long    *p;
4757 int     l;
4758
4759         addr = 0;
4760         haddr = 0;
4761         hex_buffer[0] = 0;
4762         asc_buffer[0] = 0;
4763         p = (long*) pc;
4764         for (i=0; i < size; ) {
4765                 l = (long) *p;
4766                 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4767                 haddr++;
4768                 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4769                 haddr++;
4770                 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4771                 haddr++;
4772                 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4773                 haddr++;
4774                 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4775                 haddr++;
4776                 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4777                 haddr++;
4778                 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4779                 haddr++;
4780                 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4781                 haddr++;
4782                 hex_buffer[haddr] = ' ';
4783                 haddr++;
4784                 hex_buffer[haddr] = 0;
4785                 p++;
4786                 i++;
4787                 if (i%8 == 0) {
4788                         printk("%4x %s\n", (i-8)*4, hex_buffer);
4789                         haddr = 0;
4790                 }
4791         }
4792         printk("------------------------\n");
4793 } /* DumpLong */
4794
4795 #endif
4796
4797 static int __devinit skge_probe_one(struct pci_dev *pdev,
4798                 const struct pci_device_id *ent)
4799 {
4800         SK_AC                   *pAC;
4801         DEV_NET                 *pNet = NULL;
4802         struct net_device       *dev = NULL;
4803         static int boards_found = 0;
4804         int error = -ENODEV;
4805
4806         if (pci_enable_device(pdev))
4807                 goto out;
4808  
4809         /* Configure DMA attributes. */
4810         if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4811             pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4812                 goto out_disable_device;
4813
4814
4815         if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4816                 printk(KERN_ERR "Unable to allocate etherdev "
4817                        "structure!\n");
4818                 goto out_disable_device;
4819         }
4820
4821         pNet = netdev_priv(dev);
4822         pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4823         if (!pNet->pAC) {
4824                 printk(KERN_ERR "Unable to allocate adapter "
4825                        "structure!\n");
4826                 goto out_free_netdev;
4827         }
4828
4829         memset(pNet->pAC, 0, sizeof(SK_AC));
4830         pAC = pNet->pAC;
4831         pAC->PciDev = pdev;
4832         pAC->PciDevId = pdev->device;
4833         pAC->dev[0] = dev;
4834         pAC->dev[1] = dev;
4835         sprintf(pAC->Name, "SysKonnect SK-98xx");
4836         pAC->CheckQueue = SK_FALSE;
4837
4838         pNet->Mtu = 1500;
4839         pNet->Up = 0;
4840         dev->irq = pdev->irq;
4841         error = SkGeInitPCI(pAC);
4842         if (error) {
4843                 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4844                 goto out_free_netdev;
4845         }
4846
4847         SET_MODULE_OWNER(dev);
4848         dev->open =             &SkGeOpen;
4849         dev->stop =             &SkGeClose;
4850         dev->hard_start_xmit =  &SkGeXmit;
4851         dev->get_stats =        &SkGeStats;
4852         dev->set_multicast_list = &SkGeSetRxMode;
4853         dev->set_mac_address =  &SkGeSetMacAddr;
4854         dev->do_ioctl =         &SkGeIoctl;
4855         dev->change_mtu =       &SkGeChangeMtu;
4856 #ifdef CONFIG_NET_POLL_CONTROLLER
4857         dev->poll_controller =  &SkGePollController;
4858 #endif
4859         SET_NETDEV_DEV(dev, &pdev->dev);
4860         SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4861
4862         /* Use only if yukon hardware */
4863         if (pAC->ChipsetType) {
4864 #ifdef USE_SK_TX_CHECKSUM
4865                 dev->features |= NETIF_F_IP_CSUM;
4866 #endif
4867 #ifdef SK_ZEROCOPY
4868                 dev->features |= NETIF_F_SG;
4869 #endif
4870 #ifdef USE_SK_RX_CHECKSUM
4871                 pAC->RxPort[0].RxCsum = 1;
4872 #endif
4873         }
4874
4875         pAC->Index = boards_found++;
4876
4877         if (SkGeBoardInit(dev, pAC))
4878                 goto out_free_netdev;
4879
4880         /* Register net device */
4881         if (register_netdev(dev)) {
4882                 printk(KERN_ERR "sk98lin: Could not register device.\n");
4883                 goto out_free_resources;
4884         }
4885
4886         /* Print adapter specific string from vpd */
4887         ProductStr(pAC);
4888         printk("%s: %s\n", dev->name, pAC->DeviceStr);
4889
4890         /* Print configuration settings */
4891         printk("      PrefPort:%c  RlmtMode:%s\n",
4892                 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4893                 (pAC->RlmtMode==0)  ? "Check Link State" :
4894                 ((pAC->RlmtMode==1) ? "Check Link State" :
4895                 ((pAC->RlmtMode==3) ? "Check Local Port" :
4896                 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4897                 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4898
4899         SkGeYellowLED(pAC, pAC->IoBase, 1);
4900
4901         memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4902         memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4903
4904         SkGeProcCreate(dev);
4905
4906         pNet->PortNr = 0;
4907         pNet->NetNr  = 0;
4908
4909         boards_found++;
4910
4911         /* More then one port found */
4912         if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4913                 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4914                         printk(KERN_ERR "Unable to allocate etherdev "
4915                                 "structure!\n");
4916                         goto out;
4917                 }
4918
4919                 pAC->dev[1]   = dev;
4920                 pNet          = netdev_priv(dev);
4921                 pNet->PortNr  = 1;
4922                 pNet->NetNr   = 1;
4923                 pNet->pAC     = pAC;
4924                 pNet->Mtu     = 1500;
4925                 pNet->Up      = 0;
4926
4927                 dev->open               = &SkGeOpen;
4928                 dev->stop               = &SkGeClose;
4929                 dev->hard_start_xmit    = &SkGeXmit;
4930                 dev->get_stats          = &SkGeStats;
4931                 dev->set_multicast_list = &SkGeSetRxMode;
4932                 dev->set_mac_address    = &SkGeSetMacAddr;
4933                 dev->do_ioctl           = &SkGeIoctl;
4934                 dev->change_mtu         = &SkGeChangeMtu;
4935                 SET_NETDEV_DEV(dev, &pdev->dev);
4936                 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4937
4938                 if (pAC->ChipsetType) {
4939 #ifdef USE_SK_TX_CHECKSUM
4940                         dev->features |= NETIF_F_IP_CSUM;
4941 #endif
4942 #ifdef SK_ZEROCOPY
4943                         dev->features |= NETIF_F_SG;
4944 #endif
4945 #ifdef USE_SK_RX_CHECKSUM
4946                         pAC->RxPort[1].RxCsum = 1;
4947 #endif
4948                 }
4949
4950                 if (register_netdev(dev)) {
4951                         printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4952                         free_netdev(dev);
4953                         pAC->dev[1] = pAC->dev[0];
4954                 } else {
4955                         SkGeProcCreate(dev);
4956                         memcpy(&dev->dev_addr,
4957                                         &pAC->Addr.Net[1].CurrentMacAddress, 6);
4958                         memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4959         
4960                         printk("%s: %s\n", dev->name, pAC->DeviceStr);
4961                         printk("      PrefPort:B  RlmtMode:Dual Check Link State\n");
4962                 }
4963         }
4964
4965         /* Save the hardware revision */
4966         pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4967                 (pAC->GIni.GIPciHwRev & 0x0F);
4968
4969         /* Set driver globals */
4970         pAC->Pnmi.pDriverFileName    = DRIVER_FILE_NAME;
4971         pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4972
4973         memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4974         memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4975
4976         pci_set_drvdata(pdev, dev);
4977         return 0;
4978
4979  out_free_resources:
4980         FreeResources(dev);
4981  out_free_netdev:
4982         free_netdev(dev);
4983  out_disable_device:
4984         pci_disable_device(pdev);
4985  out:
4986         return error;
4987 }
4988
4989 static void __devexit skge_remove_one(struct pci_dev *pdev)
4990 {
4991         struct net_device *dev = pci_get_drvdata(pdev);
4992         DEV_NET *pNet = netdev_priv(dev);
4993         SK_AC *pAC = pNet->pAC;
4994         struct net_device *otherdev = pAC->dev[1];
4995
4996         SkGeProcRemove(dev);
4997         unregister_netdev(dev);
4998         if (otherdev != dev)
4999                 SkGeProcRemove(otherdev);
5000
5001         SkGeYellowLED(pAC, pAC->IoBase, 0);
5002
5003         if (pAC->BoardLevel == SK_INIT_RUN) {
5004                 SK_EVPARA EvPara;
5005                 unsigned long Flags;
5006
5007                 /* board is still alive */
5008                 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5009                 EvPara.Para32[0] = 0;
5010                 EvPara.Para32[1] = -1;
5011                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5012                 EvPara.Para32[0] = 1;
5013                 EvPara.Para32[1] = -1;
5014                 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5015                 SkEventDispatcher(pAC, pAC->IoBase);
5016                 /* disable interrupts */
5017                 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5018                 SkGeDeInit(pAC, pAC->IoBase);
5019                 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5020                 pAC->BoardLevel = SK_INIT_DATA;
5021                 /* We do NOT check here, if IRQ was pending, of course*/
5022         }
5023
5024         if (pAC->BoardLevel == SK_INIT_IO) {
5025                 /* board is still alive */
5026                 SkGeDeInit(pAC, pAC->IoBase);
5027                 pAC->BoardLevel = SK_INIT_DATA;
5028         }
5029
5030         FreeResources(dev);
5031         free_netdev(dev);
5032         if (otherdev != dev)
5033                 free_netdev(otherdev);
5034         kfree(pAC);
5035 }
5036
5037 #ifdef CONFIG_PM
5038 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5039 {
5040         struct net_device *dev = pci_get_drvdata(pdev);
5041         DEV_NET *pNet = netdev_priv(dev);
5042         SK_AC *pAC = pNet->pAC;
5043         struct net_device *otherdev = pAC->dev[1];
5044
5045         if (netif_running(dev)) {
5046                 netif_carrier_off(dev);
5047                 DoPrintInterfaceChange = SK_FALSE;
5048                 SkDrvDeInitAdapter(pAC, 0);  /* performs SkGeClose */
5049                 netif_device_detach(dev);
5050         }
5051         if (otherdev != dev) {
5052                 if (netif_running(otherdev)) {
5053                         netif_carrier_off(otherdev);
5054                         DoPrintInterfaceChange = SK_FALSE;
5055                         SkDrvDeInitAdapter(pAC, 1);  /* performs SkGeClose */
5056                         netif_device_detach(otherdev);
5057                 }
5058         }
5059
5060         pci_save_state(pdev);
5061         pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5062         if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5063                 free_irq(dev->irq, dev);
5064         }
5065         pci_disable_device(pdev);
5066         pci_set_power_state(pdev, pci_choose_state(pdev, state));
5067
5068         return 0;
5069 }
5070
5071 static int skge_resume(struct pci_dev *pdev)
5072 {
5073         struct net_device *dev = pci_get_drvdata(pdev);
5074         DEV_NET *pNet = netdev_priv(dev);
5075         SK_AC *pAC = pNet->pAC;
5076         struct net_device *otherdev = pAC->dev[1];
5077         int ret;
5078
5079         pci_set_power_state(pdev, PCI_D0);
5080         pci_restore_state(pdev);
5081         pci_enable_device(pdev);
5082         pci_set_master(pdev);
5083         if (pAC->GIni.GIMacsFound == 2)
5084                 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5085         else
5086                 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5087         if (ret) {
5088                 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5089                 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5090                 dev->irq = 0;
5091                 pci_disable_device(pdev);
5092                 return -EBUSY;
5093         }
5094
5095         netif_device_attach(dev);
5096         if (netif_running(dev)) {
5097                 DoPrintInterfaceChange = SK_FALSE;
5098                 SkDrvInitAdapter(pAC, 0);    /* first device  */
5099         }
5100         if (otherdev != dev) {
5101                 netif_device_attach(otherdev);
5102                 if (netif_running(otherdev)) {
5103                         DoPrintInterfaceChange = SK_FALSE;
5104                         SkDrvInitAdapter(pAC, 1);    /* second device  */
5105                 }
5106         }
5107
5108         return 0;
5109 }
5110 #else
5111 #define skge_suspend NULL
5112 #define skge_resume NULL
5113 #endif
5114
5115 static struct pci_device_id skge_pci_tbl[] = {
5116         { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5117         { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5118         { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5119         { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5120 /* DLink card does not have valid VPD so this driver gags
5121  *      { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5122  */
5123         { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5124         { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5125         { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5126         { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5127         { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5128         { 0 }
5129 };
5130
5131 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5132
5133 static struct pci_driver skge_driver = {
5134         .name           = "sk98lin",
5135         .id_table       = skge_pci_tbl,
5136         .probe          = skge_probe_one,
5137         .remove         = __devexit_p(skge_remove_one),
5138         .suspend        = skge_suspend,
5139         .resume         = skge_resume,
5140 };
5141
5142 static int __init skge_init(void)
5143 {
5144         int error;
5145
5146         pSkRootDir = proc_mkdir(SKRootName, NULL);
5147         if (pSkRootDir) 
5148                 pSkRootDir->owner = THIS_MODULE;
5149         
5150         error = pci_register_driver(&skge_driver);
5151         if (error)
5152                 remove_proc_entry(SKRootName, NULL);
5153         return error;
5154 }
5155
5156 static void __exit skge_exit(void)
5157 {
5158         pci_unregister_driver(&skge_driver);
5159         remove_proc_entry(SKRootName, NULL);
5160
5161 }
5162
5163 module_init(skge_init);
5164 module_exit(skge_exit);