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