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