File: /usr/src/linux/drivers/net/sk98lin/skge.c

1     /******************************************************************************
2      *
3      * Name:    skge.c
4      * Project:	GEnesis, PCI Gigabit Ethernet Adapter
5      * Version:	$Revision: 1.29.2.6 $
6      * Date:       	$Date: 2001/05/21 07:59:29 $
7      * Purpose:	The main driver source module
8      *
9      ******************************************************************************/
10      
11     /******************************************************************************
12      *
13      *	(C)Copyright 1998-2001 SysKonnect GmbH.
14      *
15      *	Driver for SysKonnect Gigabit Ethernet Server Adapters:
16      *
17      *	SK-9861 (single link 1000Base-SX, VF45 Volition Plug)
18      *	SK-9862 (dual link   1000Base-SX, VF45 Volition Plug)
19      *	SK-9841 (single link 1000Base-LX)
20      *	SK-9842 (dual link   1000Base-LX)
21      *	SK-9843 (single link 1000Base-SX)
22      *	SK-9844 (dual link   1000Base-SX)
23      *	SK-9821 (single link 1000Base-T)
24      *	SK-9822 (dual link   1000Base-T)
25      *
26      *	Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and 
27      *	SysKonnects GEnesis Solaris driver
28      *	Author: Christoph Goos (cgoos@syskonnect.de)
29      *	        Mirko Lindner (mlindner@syskonnect.de)
30      *
31      *	Address all question to: linux@syskonnect.de
32      *
33      *	The technical manual for the adapters is available from SysKonnect's
34      *	web pages: www.syskonnect.com
35      *	Goto "Support" and search Knowledge Base for "manual".
36      *	
37      *	This program is free software; you can redistribute it and/or modify
38      *	it under the terms of the GNU General Public License as published by
39      *	the Free Software Foundation; either version 2 of the License, or
40      *	(at your option) any later version.
41      *
42      *	The information in this file is provided "AS IS" without warranty.
43      *
44      ******************************************************************************/
45     
46     /******************************************************************************
47      *
48      * History:
49      *
50      *	$Log: skge.c,v $
51      *	Revision 1.29.2.6  2001/05/21 07:59:29  mlindner
52      *	fix: MTU init problems
53      *	
54      *	Revision 1.29.2.5  2001/05/08 11:25:08  mlindner
55      *	fix: removed VLAN error message
56      *	
57      *	Revision 1.29.2.4  2001/05/04 13:31:43  gklug
58      *	fix: do not handle eth_copy on bad fragments received.
59      *	
60      *	Revision 1.29.2.3  2001/04/23 08:06:43  mlindner
61      *	Fix: error handling
62      *	
63      *	Revision 1.29.2.2  2001/03/15 12:04:54  mlindner
64      *	Fixed memory problem
65      *	
66      *	Revision 1.29.2.1  2001/03/12 16:41:44  mlindner
67      *	add: procfs function
68      *	add: dual-net function
69      *	add: RLMT networks
70      *	add: extended PNMI features
71      *	
72      *	Kernel 2.4.x specific:
73      *	Revision 1.xx  2000/09/12 13:31:56  cgoos
74      *	Fixed missign "dev=NULL in skge_probe.
75      *	Added counting for jumbo frames (corrects error statistic).
76      *	Removed VLAN tag check (enables VLAN support).
77      *	
78      *	Kernel 2.2.x specific:
79      *	Revision 1.29  2000/02/21 13:31:56  cgoos
80      *	Fixed "unused" warning for UltraSPARC change.
81      *	
82      *	Partially kernel 2.2.x specific:
83      *	Revision 1.28  2000/02/21 10:32:36  cgoos
84      *	Added fixes for UltraSPARC.
85      *	Now printing RlmtMode and PrefPort setting at startup.
86      *	Changed XmitFrame return value.
87      *	Fixed rx checksum calculation for BIG ENDIAN systems.
88      *	Fixed rx jumbo frames counted as ierrors.
89      *	
90      *	
91      *	Revision 1.27  1999/11/25 09:06:28  cgoos
92      *	Changed base_addr to unsigned long.
93      *	
94      *	Revision 1.26  1999/11/22 13:29:16  cgoos
95      *	Changed license header to GPL.
96      *	Changes for inclusion in linux kernel (2.2.13).
97      *	Removed 2.0.x defines.
98      *	Changed SkGeProbe to skge_probe.
99      *	Added checks in SkGeIoctl.
100      *	
101      *	Revision 1.25  1999/10/07 14:47:52  cgoos
102      *	Changed 984x to 98xx.
103      *	
104      *	Revision 1.24  1999/09/30 07:21:01  cgoos
105      *	Removed SK_RLMT_SLOW_LOOKAHEAD option.
106      *	Giving spanning tree packets also to OS now.
107      *	
108      *	Revision 1.23  1999/09/29 07:36:50  cgoos
109      *	Changed assignment for IsBc/IsMc.
110      *	
111      *	Revision 1.22  1999/09/28 12:57:09  cgoos
112      *	Added CheckQueue also to Single-Port-ISR.
113      *	
114      *	Revision 1.21  1999/09/28 12:42:41  cgoos
115      *	Changed parameter strings for RlmtMode.
116      *	
117      *	Revision 1.20  1999/09/28 12:37:57  cgoos
118      *	Added CheckQueue for fast delivery of RLMT frames.
119      *	
120      *	Revision 1.19  1999/09/16 07:57:25  cgoos
121      *	Copperfield changes.
122      *	
123      *	Revision 1.18  1999/09/03 13:06:30  cgoos
124      *	Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused
125      *	double allocated skb's.
126      *	FrameStat in ReceiveIrq was accessed via wrong Rxd.
127      *	Queue size for async. standby Tx queue was zero.
128      *	FillRxLimit of 0 could cause problems with ReQueue, changed to 1.
129      *	Removed debug output of checksum statistic.
130      *	
131      *	Revision 1.17  1999/08/11 13:55:27  cgoos
132      *	Transmit descriptor polling was not reenabled after SkGePortInit.
133      *	
134      *	Revision 1.16  1999/07/27 15:17:29  cgoos
135      *	Added some "\n" in output strings (removed while debuging...).
136      *	
137      *	Revision 1.15  1999/07/23 12:09:30  cgoos
138      *	Performance optimization, rx checksumming, large frame support.
139      *	
140      *	Revision 1.14  1999/07/14 11:26:27  cgoos
141      *	Removed Link LED settings (now in RLMT).
142      *	Added status output at NET UP.
143      *	Fixed SMP problems with Tx and SWITCH running in parallel.
144      *	Fixed return code problem at RLMT_SEND event.
145      *	
146      *	Revision 1.13  1999/04/07 10:11:42  cgoos
147      *	Fixed Single Port problems.
148      *	Fixed Multi-Adapter problems.
149      *	Always display startup string.
150      *	
151      *	Revision 1.12  1999/03/29 12:26:37  cgoos
152      *	Reversed locking to fine granularity.
153      *	Fixed skb double alloc problem (caused by incorrect xmit return code).
154      *	Enhanced function descriptions.
155      *	
156      *	Revision 1.11  1999/03/15 13:10:51  cgoos
157      *	Changed device identifier in output string to ethX.
158      *	
159      *	Revision 1.10  1999/03/15 12:12:34  cgoos
160      *	Changed copyright notice.
161      *	
162      *	Revision 1.9  1999/03/15 12:10:17  cgoos
163      *	Changed locking to one driver lock.
164      *	Added check of SK_AC-size (for consistency with library).
165      *	
166      *	Revision 1.8  1999/03/08 11:44:02  cgoos
167      *	Fixed missing dev->tbusy in SkGeXmit.
168      *	Changed large frame (jumbo) buffer number.
169      *	Added copying of short frames.
170      *	
171      *	Revision 1.7  1999/03/04 13:26:57  cgoos
172      *	Fixed spinlock calls for SMP.
173      *	
174      *	Revision 1.6  1999/03/02 09:53:51  cgoos
175      *	Added descriptor revertion for big endian machines.
176      *	
177      *	Revision 1.5  1999/03/01 08:50:59  cgoos
178      *	Fixed SkGeChangeMtu.
179      *	Fixed pci config space accesses.
180      *	
181      *	Revision 1.4  1999/02/18 15:48:44  cgoos
182      *	Corrected some printk's.
183      *	
184      *	Revision 1.3  1999/02/18 12:45:55  cgoos
185      *	Changed SK_MAX_CARD_PARAM to default 16
186      *	
187      *	Revision 1.2  1999/02/18 10:55:32  cgoos
188      *	Removed SkGeDrvTimeStamp function.
189      *	Printing "ethX:" before adapter type at adapter init.
190      *	
191      *
192      *	10-Feb-1999 cg	Created, based on Linux' acenic.c, 3c59x.c and 
193      *			SysKonnects GEnesis Solaris driver
194      *
195      ******************************************************************************/
196     
197     /******************************************************************************
198      *
199      * Possible compiler options (#define xxx / -Dxxx):
200      *
201      *	debugging can be enable by changing SK_DEBUG_CHKMOD and 
202      *	SK_DEBUG_CHKCAT in makefile (described there).
203      *
204      ******************************************************************************/
205      
206     /******************************************************************************
207      *
208      * Description:
209      *
210      *	This is the main module of the Linux GE driver.
211      *	
212      *	All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
213      *	are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
214      *	Those are used for drivers on multiple OS', so some thing may seem
215      *	unnecessary complicated on Linux. Please do not try to 'clean up'
216      *	them without VERY good reasons, because this will make it more
217      *	difficult to keep the Linux driver in synchronisation with the
218      *	other versions.
219      *
220      * Include file hierarchy:
221      *
222      *	<linux/module.h>
223      *
224      *	"h/skdrv1st.h"
225      *		<linux/version.h>
226      *		<linux/types.h>
227      *		<linux/kernel.h>
228      *		<linux/string.h>
229      *		<linux/errno.h>
230      *		<linux/ioport.h>
231      *		<linux/malloc.h>
232      *		<linux/interrupt.h>
233      *		<linux/pci.h>
234      *		<asm/byteorder.h>
235      *		<asm/bitops.h>
236      *		<asm/io.h>
237      *		<linux/netdevice.h>
238      *		<linux/etherdevice.h>
239      *		<linux/skbuff.h>
240      *	    those three depending on kernel version used:
241      *		<linux/bios32.h>
242      *		<linux/init.h>
243      *		<asm/uaccess.h>
244      *		<net/checksum.h>
245      *
246      *		"h/skerror.h"
247      *		"h/skdebug.h"
248      *		"h/sktypes.h"
249      *		"h/lm80.h"
250      *		"h/xmac_ii.h"
251      *
252      *      "h/skdrv2nd.h"
253      *		"h/skqueue.h"
254      *		"h/skgehwt.h"
255      *		"h/sktimer.h"
256      *		"h/ski2c.h"
257      *		"h/skgepnmi.h"
258      *		"h/skvpd.h"
259      *		"h/skgehw.h"
260      *		"h/skgeinit.h"
261      *		"h/skaddr.h"
262      *		"h/skgesirq.h"
263      *		"h/skcsum.h"
264      *		"h/skrlmt.h"
265      *
266      ******************************************************************************/
267     
268     #include	"h/skversion.h"
269     
270     #include	<linux/module.h>
271     #include	<linux/init.h>
272     #include 	<linux/proc_fs.h>
273     
274     #include	"h/skdrv1st.h"
275     #include	"h/skdrv2nd.h"
276     
277     /* defines ******************************************************************/
278     /* for debuging on x86 only */
279     /* #define BREAKPOINT() asm(" int $3"); */
280     
281     /* use of a transmit complete interrupt */
282     #define USE_TX_COMPLETE
283     
284     /* use interrupt moderation (for tx complete only) */
285     // #define USE_INT_MOD
286     #define INTS_PER_SEC	1000
287     
288     /*
289      * threshold for copying small receive frames
290      * set to 0 to avoid copying, set to 9001 to copy all frames
291      */
292     #define SK_COPY_THRESHOLD	200
293     
294     /* number of adapters that can be configured via command line params */
295     #define SK_MAX_CARD_PARAM	16
296     
297     /*
298      * use those defines for a compile-in version of the driver instead 
299      * of command line parameters
300      */
301     // #define AUTO_NEG_A	{"Sense", }
302     // #define AUTO_NEG_B	{"Sense", }
303     // #define DUP_CAP_A	{"Both", }
304     // #define DUP_CAP_B	{"Both", }
305     // #define FLOW_CTRL_A	{"SymOrRem", }
306     // #define FLOW_CTRL_B	{"SymOrRem", }
307     // #define ROLE_A	{"Auto", }
308     // #define ROLE_B	{"Auto", }
309     // #define PREF_PORT	{"A", }
310     // #define RLMT_MODE	{"CheckLinkState", }
311     
312     #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
313     #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
314     #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
315     
316     /* function prototypes ******************************************************/
317     static void	FreeResources(struct net_device *dev);
318     int		init_module(void);
319     void		cleanup_module(void);
320     static int	SkGeBoardInit(struct net_device *dev, SK_AC *pAC);
321     static SK_BOOL	BoardAllocMem(SK_AC *pAC);
322     static void	BoardFreeMem(SK_AC *pAC);
323     static void	BoardInitMem(SK_AC *pAC);
324     static void	SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**,
325     			int*, SK_BOOL);
326     
327     static void	SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
328     static void	SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
329     static int	SkGeOpen(struct net_device *dev);
330     static int	SkGeClose(struct net_device *dev);
331     static int	SkGeXmit(struct sk_buff *skb, struct net_device *dev);
332     static int	SkGeSetMacAddr(struct net_device *dev, void *p);
333     static void	SkGeSetRxMode(struct net_device *dev);
334     static struct net_device_stats *SkGeStats(struct net_device *dev);
335     static int	SkGeIoctl(struct net_device *dev, struct ifreq *rq, int cmd);
336     static void	GetConfiguration(SK_AC*);
337     static void	ProductStr(SK_AC*);
338     static int	XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
339     static void	FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
340     static void	FillRxRing(SK_AC*, RX_PORT*);
341     static SK_BOOL	FillRxDescriptor(SK_AC*, RX_PORT*);
342     static void	ReceiveIrq(SK_AC*, RX_PORT*);
343     static void	ClearAndStartRx(SK_AC*, int);
344     static void	ClearTxIrq(SK_AC*, int, int);
345     static void	ClearRxRing(SK_AC*, RX_PORT*);
346     static void	ClearTxRing(SK_AC*, TX_PORT*);
347     static void	SetQueueSizes(SK_AC	*pAC);
348     static int	SkGeChangeMtu(struct net_device *dev, int new_mtu);
349     static void	PortReInitBmu(SK_AC*, int);
350     static int	SkGeIocMib(DEV_NET*, unsigned int, int);
351     
352     
353     /*Extern */
354     
355     extern struct proc_dir_entry *pSkRootDir;
356     
357     //extern struct proc_dir_entry Our_Proc_Dir;
358     extern int proc_read(char *buffer, char **buffer_location,
359     	off_t offset, int buffer_length, int *eof, void *data);
360     
361     
362     #ifdef DEBUG
363     static void	DumpMsg(struct sk_buff*, char*);
364     static void	DumpData(char*, int);
365     static void	DumpLong(char*, int);
366     #endif
367     
368     
369     /* global variables *********************************************************/
370     static const char *BootString = BOOT_STRING;
371     struct net_device *sk98lin_root_dev = NULL;
372     static int probed __initdata = 0;
373     struct inode_operations SkInodeOps;
374     //static struct file_operations SkFileOps;  /* with open/relase */
375     
376     /* local variables **********************************************************/
377     static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
378     static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
379     
380     
381     
382     void proc_fill_inode(struct inode *inode, int fill)
383     {
384     	if (fill)
385     		MOD_INC_USE_COUNT;
386     	else
387     		MOD_DEC_USE_COUNT;
388     }
389     
390     
391     
392     /*****************************************************************************
393      *
394      * 	skge_probe - find all SK-98xx adapters
395      *
396      * Description:
397      *	This function scans the PCI bus for SK-98xx adapters. Resources for
398      *	each adapter are allocated and the adapter is brought into Init 1
399      *	state.
400      *
401      * Returns:
402      *	0, if everything is ok
403      *	!=0, on error
404      */
405     static int __init skge_probe (void)
406     {
407     	int 		boards_found = 0;
408     	int			version_disp = 0;
409     	SK_AC		*pAC;
410     	DEV_NET		*pNet = NULL;
411     	struct 		pci_dev	*pdev = NULL;
412     	unsigned long		base_address;
413     	struct net_device *dev = NULL;
414     	struct proc_dir_entry	*pProcFile;
415     
416     	if (probed)
417     		return -ENODEV;
418     	probed++;
419     	
420     	/* display driver info */
421     	if (!version_disp)
422     	{
423     		/* set display flag to TRUE so that */
424     		/* we only display this string ONCE */
425     		version_disp = 1;
426     		printk("%s\n", BootString);
427     	}
428     
429     	if (!pci_present())		/* is PCI support present? */
430     		return -ENODEV;
431     
432             pSkRootDir = create_proc_entry("sk98lin",
433                     S_IFDIR | S_IWUSR | S_IRUGO | S_IXUGO, proc_net); 
434     
435     	pSkRootDir->owner = THIS_MODULE;
436     
437     	while((pdev = pci_find_device(PCI_VENDOR_ID_SYSKONNECT,
438     				      PCI_DEVICE_ID_SYSKONNECT_GE, pdev)) != NULL) {
439     
440     		dev = NULL;
441     		pNet = NULL;
442     
443     		if (pci_enable_device(pdev))
444     			continue;
445     
446     		if ((dev = init_etherdev(dev, sizeof(DEV_NET))) == 0) {
447     			printk(KERN_ERR "Unable to allocate etherdev "
448     			       "structure!\n");
449     			break;
450     		}
451     
452     		pNet = dev->priv;
453     		pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
454     		if (pNet->pAC == NULL){
455     			kfree(dev->priv);
456     			printk(KERN_ERR "Unable to allocate adapter "
457     			       "structure!\n");
458     			break;
459     		}
460     
461     		memset(pNet->pAC, 0, sizeof(SK_AC));
462     		pAC = pNet->pAC;
463     		pAC->PciDev = *pdev;
464     		pAC->PciDevId = pdev->device;
465     		pAC->dev[0] = dev;
466     		pAC->dev[1] = dev;
467     		sprintf(pAC->Name, "SysKonnect SK-98xx");
468     		pAC->CheckQueue = SK_FALSE;
469     		
470     		pNet->Mtu = 1500;
471     		pNet->Up = 0;
472     		dev->irq = pdev->irq;
473     
474     		dev->open =		&SkGeOpen;
475     		dev->stop =		&SkGeClose;
476     		dev->hard_start_xmit =	&SkGeXmit;
477     		dev->get_stats =	&SkGeStats;
478     		dev->set_multicast_list = &SkGeSetRxMode;
479     		dev->set_mac_address =	&SkGeSetMacAddr;
480     		dev->do_ioctl =		&SkGeIoctl;
481     		dev->change_mtu =	&SkGeChangeMtu;
482     
483     		pProcFile = create_proc_entry(dev->name, 
484     			S_IFREG | 0444, pSkRootDir);
485     		pProcFile->read_proc = proc_read;
486     		pProcFile->write_proc = NULL;
487     		pProcFile->nlink = 1;
488     		pProcFile->size = sizeof(dev->name+1);
489     		pProcFile->data = (void*)pProcFile;
490     
491     		/*
492     		 * Dummy value.
493     		 */
494     		dev->base_addr = 42;
495     		pci_set_master(pdev);
496     		base_address = pci_resource_start (pdev, 0);
497     
498     #ifdef SK_BIG_ENDIAN
499     		/*
500     		 * On big endian machines, we use the adapter's aibility of
501     		 * reading the descriptors as big endian.
502     		 */
503     		{
504     		SK_U32		our2;
505     			SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
506     			our2 |= PCI_REV_DESC;
507     			SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
508     		}
509     #endif /* BIG ENDIAN */
510     
511     		/*
512     		 * Remap the regs into kernel space.
513     		 */
514     
515     		pAC->IoBase = (char*)ioremap(base_address, 0x4000);
516     		if (!pAC->IoBase){
517     			printk(KERN_ERR "%s:  Unable to map I/O register, "
518     			       "SK 98xx No. %i will be disabled.\n",
519     			       dev->name, boards_found);
520     			kfree(dev);
521     			break;
522     		}
523     		pAC->Index = boards_found;
524     
525     		if (SkGeBoardInit(dev, pAC)) {
526     			FreeResources(dev);
527     			kfree(dev);
528     			continue;
529     		}
530     
531     		memcpy((caddr_t) &dev->dev_addr,
532     			(caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
533     
534     		pNet->PortNr = 0;
535     		pNet->NetNr = 0;
536     
537     		boards_found++;
538     
539     		/*
540     		 * This is bollocks, but we need to tell the net-init
541     		 * code that it shall go for the next device.
542     		 */
543     #ifndef MODULE
544     		dev->base_addr = 0;
545     #endif
546     	}
547     
548     	/*
549     	 * If we're at this point we're going through skge_probe() for
550     	 * the first time.  Return success (0) if we've initialized 1
551     	 * or more boards. Otherwise, return failure (-ENODEV).
552     	 */
553     
554     	return boards_found;
555     } /* skge_probe */
556     
557     
558     /*****************************************************************************
559      *
560      * 	FreeResources - release resources allocated for adapter
561      *
562      * Description:
563      *	This function releases the IRQ, unmaps the IO and
564      *	frees the desriptor ring.
565      *
566      * Returns: N/A
567      *	
568      */
569     static void FreeResources(struct net_device *dev)
570     {
571     SK_U32 AllocFlag;
572     DEV_NET		*pNet;
573     SK_AC		*pAC;
574     
575     	if (dev->priv) {
576     		pNet = (DEV_NET*) dev->priv;
577     		pAC = pNet->pAC;
578     		AllocFlag = pAC->AllocFlag;
579     		if (AllocFlag & SK_ALLOC_IRQ) {
580     			free_irq(dev->irq, dev);
581     		}
582     		if (pAC->IoBase) {
583     			iounmap(pAC->IoBase);
584     		}
585     		if (pAC->pDescrMem) {
586     			BoardFreeMem(pAC);
587     		}
588     	}
589     	
590     } /* FreeResources */
591     
592     MODULE_AUTHOR("Christoph Goos <cgoos@syskonnect.de>");
593     MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
594     MODULE_PARM(AutoNeg_A,  "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
595     MODULE_PARM(AutoNeg_B,  "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
596     MODULE_PARM(DupCap_A,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
597     MODULE_PARM(DupCap_B,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
598     MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
599     MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
600     MODULE_PARM(Role_A,	"1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
601     MODULE_PARM(Role_B,	"1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
602     MODULE_PARM(PrefPort,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
603     MODULE_PARM(RlmtMode,   "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
604     /* not used, just there because every driver should have them: */
605     MODULE_PARM(options,    "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
606     MODULE_PARM(debug,      "i");
607     
608     
609     #ifdef AUTO_NEG_A
610     static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
611     #else
612     static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
613     #endif
614     
615     #ifdef DUP_CAP_A
616     static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
617     #else
618     static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
619     #endif
620     
621     #ifdef FLOW_CTRL_A
622     static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
623     #else
624     static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
625     #endif
626     
627     #ifdef ROLE_A
628     static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
629     #else
630     static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
631     #endif
632     
633     #ifdef AUTO_NEG_B
634     static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
635     #else
636     static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
637     #endif
638     
639     #ifdef DUP_CAP_B
640     static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
641     #else
642     static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
643     #endif
644     
645     #ifdef FLOW_CTRL_B
646     static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
647     #else
648     static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
649     #endif
650     
651     #ifdef ROLE_B
652     static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
653     #else
654     static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
655     #endif
656     
657     #ifdef PREF_PORT
658     static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
659     #else
660     static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
661     #endif
662     
663     #ifdef RLMT_MODE
664     static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
665     #else
666     static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
667     #endif
668     
669     
670     static int debug = 0; /* not used */
671     static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
672     
673     
674     /*****************************************************************************
675      *
676      * 	skge_init_module - module initialization function
677      *
678      * Description:
679      *	Very simple, only call skge_probe and return approriate result.
680      *
681      * Returns:
682      *	0, if everything is ok
683      *	!=0, on error
684      */
685     static int __init skge_init_module(void)
686     {
687     	int cards;
688     	sk98lin_root_dev = NULL;
689     	
690     	/* just to avoid warnings ... */
691     	debug = 0;
692     	options[0] = 0;
693     
694     	cards = skge_probe();
695     	if (cards == 0) {
696     		printk("No adapter found\n");
697     	}
698     	return cards ? 0 : -ENODEV;
699     } /* skge_init_module */
700     
701     
702     /*****************************************************************************
703      *
704      * 	skge_cleanup_module - module unload function
705      *
706      * Description:
707      *	Disable adapter if it is still running, free resources,
708      *	free device struct.
709      *
710      * Returns: N/A
711      */
712     static void __exit skge_cleanup_module(void)
713     {
714     DEV_NET		*pNet;
715     SK_AC		*pAC;
716     struct net_device *next;
717     unsigned long Flags;
718     SK_EVPARA EvPara;
719     
720     	while (sk98lin_root_dev) {
721     		pNet = (DEV_NET*) sk98lin_root_dev->priv;
722     		pAC = pNet->pAC;
723     		next = pAC->Next;
724     
725     		netif_stop_queue(sk98lin_root_dev);
726     		SkGeYellowLED(pAC, pAC->IoBase, 0);
727     
728     		if(pAC->BoardLevel == 2) {
729     			/* board is still alive */
730     			spin_lock_irqsave(&pAC->SlowPathLock, Flags);
731     			EvPara.Para32[0] = 0;
732     			EvPara.Para32[1] = -1;
733     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
734     			EvPara.Para32[0] = 1;
735     			EvPara.Para32[1] = -1;
736     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
737     			SkEventDispatcher(pAC, pAC->IoBase);
738     			/* disable interrupts */
739     			SK_OUT32(pAC->IoBase, B0_IMSK, 0);
740     			SkGeDeInit(pAC, pAC->IoBase); 
741     			spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
742     			pAC->BoardLevel = 0;
743     			/* We do NOT check here, if IRQ was pending, of course*/
744     		}
745     
746     		if(pAC->BoardLevel == 1) {
747     			/* board is still alive */
748     			SkGeDeInit(pAC, pAC->IoBase); 
749     			pAC->BoardLevel = 0;
750     		}
751     
752     		if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
753     			unregister_netdev(pAC->dev[1]);
754     			kfree(pAC->dev[1]);
755     		}
756     
757     		FreeResources(sk98lin_root_dev);
758     
759     		sk98lin_root_dev->get_stats = NULL;
760     		/* 
761     		 * otherwise unregister_netdev calls get_stats with
762     		 * invalid IO ...  :-(
763     		 */
764     		unregister_netdev(sk98lin_root_dev);
765     		kfree(sk98lin_root_dev);
766     		kfree(pAC);
767     		sk98lin_root_dev = next;
768     	}
769     
770     	/* clear proc-dir */
771     	remove_proc_entry(pSkRootDir->name, proc_net);
772     
773     } /* skge_cleanup_module */
774     
775     module_init(skge_init_module);
776     module_exit(skge_cleanup_module);
777     
778     /*****************************************************************************
779      *
780      * 	SkGeBoardInit - do level 0 and 1 initialization
781      *
782      * Description:
783      *	This function prepares the board hardware for running. The desriptor
784      *	ring is set up, the IRQ is allocated and the configuration settings
785      *	are examined.
786      *
787      * Returns:
788      *	0, if everything is ok
789      *	!=0, on error
790      */
791     static int __init SkGeBoardInit(struct net_device *dev, SK_AC *pAC)
792     {
793     short	i;
794     unsigned long Flags;
795     char	*DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
796     char	*VerStr	= VER_STRING;
797     int	Ret;			/* return code of request_irq */
798     
799     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
800     		("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
801     	for (i=0; i<SK_MAX_MACS; i++) {
802     		pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
803     		pAC->TxPort[i][0].PortIndex = i;
804     		pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
805     		pAC->RxPort[i].PortIndex = i;
806     	}
807     
808     	/* Initialize the mutexes */
809     
810     	for (i=0; i<SK_MAX_MACS; i++) {
811     		spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
812     		spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
813     	}
814     	spin_lock_init(&pAC->SlowPathLock);
815     
816     	/* level 0 init common modules here */
817     	
818     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
819     	/* Does a RESET on board ...*/
820     	if (SkGeInit(pAC, pAC->IoBase, 0) != 0) {
821     		printk("HWInit (0) failed.\n");
822     		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
823     		return(-EAGAIN);
824     	}
825     	SkI2cInit(  pAC, pAC->IoBase, 0);
826     	SkEventInit(pAC, pAC->IoBase, 0);
827     	SkPnmiInit( pAC, pAC->IoBase, 0);
828     	SkAddrInit( pAC, pAC->IoBase, 0);
829     	SkRlmtInit( pAC, pAC->IoBase, 0);
830     	SkTimerInit(pAC, pAC->IoBase, 0);
831     	
832     	pAC->BoardLevel = 0;
833     	pAC->RxBufSize = ETH_BUF_SIZE;
834     
835     	SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
836     	SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
837     
838     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
839     
840     	/* level 1 init common modules here (HW init) */
841     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
842     	if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
843     		printk("HWInit (1) failed.\n");
844     		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
845     		return(-EAGAIN);
846     	}
847     	SkI2cInit(  pAC, pAC->IoBase, 1);
848     	SkEventInit(pAC, pAC->IoBase, 1);
849     	SkPnmiInit( pAC, pAC->IoBase, 1);
850     	SkAddrInit( pAC, pAC->IoBase, 1);
851     	SkRlmtInit( pAC, pAC->IoBase, 1);
852     	SkTimerInit(pAC, pAC->IoBase, 1);
853     
854     	GetConfiguration(pAC);
855     	if (pAC->RlmtNets == 2) {
856     		pAC->GIni.GIPortUsage = SK_MUL_LINK;
857     	}
858     
859     
860     	pAC->BoardLevel = 1;
861     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
862     
863     	if (pAC->GIni.GIMacsFound == 2) {
864     		 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
865     	} else if (pAC->GIni.GIMacsFound == 1) {
866     		Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
867     			pAC->Name, dev);
868     	} else {
869     		printk(KERN_WARNING "%s: illegal number of ports: %d\n",
870     		       dev->name, pAC->GIni.GIMacsFound);
871     		return -EAGAIN;
872     	}
873     	if (Ret) {
874     		printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
875     		       dev->name, dev->irq);
876     		return -EAGAIN;
877     	}
878     	pAC->AllocFlag |= SK_ALLOC_IRQ;
879     
880     	/* Alloc memory for this board (Mem for RxD/TxD) : */
881     	if(!BoardAllocMem(pAC)) {
882     		printk("No memory for descriptor rings\n");
883            		return(-EAGAIN);
884     	}
885     
886     	SkCsSetReceiveFlags(pAC,
887     		SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
888     		&pAC->CsOfs1, &pAC->CsOfs2, 0);
889     	pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
890     
891     	BoardInitMem(pAC);
892     
893     	SetQueueSizes(pAC);
894     
895     	/* Print adapter specific string from vpd */
896     	ProductStr(pAC);
897     	printk("%s: %s\n", dev->name, pAC->DeviceStr);
898     
899     	/* Print configuration settings */
900     	printk("      PrefPort:%c  RlmtMode:%s\n",
901     		'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
902     		(pAC->RlmtMode==0)  ? "Check Link State" :
903     		((pAC->RlmtMode==1) ? "Check Link State" : 
904     		((pAC->RlmtMode==3) ? "Check Local Port" : 
905     		((pAC->RlmtMode==7) ? "Check Segmentation" : 
906     		((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
907     
908     
909     	SkGeYellowLED(pAC, pAC->IoBase, 1);
910     
911     	/*
912     	 * Register the device here
913     	 */
914     	pAC->Next = sk98lin_root_dev;
915     	sk98lin_root_dev = dev;
916     
917     	return (0);
918     } /* SkGeBoardInit */
919     
920     
921     /*****************************************************************************
922      *
923      * 	BoardAllocMem - allocate the memory for the descriptor rings
924      *
925      * Description:
926      *	This function allocates the memory for all descriptor rings.
927      *	Each ring is aligned for the desriptor alignment and no ring
928      *	has a 4 GByte boundary in it (because the upper 32 bit must
929      *	be constant for all descriptiors in one rings).
930      *
931      * Returns:
932      *	SK_TRUE, if all memory could be allocated
933      *	SK_FALSE, if not
934      */
935     static SK_BOOL BoardAllocMem(
936     SK_AC	*pAC)
937     {
938     caddr_t		pDescrMem;	/* pointer to descriptor memory area */
939     size_t		AllocLength;	/* length of complete descriptor area */
940     int		i;		/* loop counter */
941     unsigned long	BusAddr;
942     
943     	
944     	/* rings plus one for alignment (do not cross 4 GB boundary) */
945     	/* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
946     #if (BITS_PER_LONG == 32)
947     	AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
948     #else
949     	AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
950     		+ RX_RING_SIZE + 8;
951     #endif
952     	pDescrMem = pci_alloc_consistent(&pAC->PciDev, AllocLength,
953     					 &pAC->pDescrMemDMA);
954     	if (pDescrMem == NULL) {
955     		return (SK_FALSE);
956     	}
957     	pAC->pDescrMem = pDescrMem;
958     
959     	/* Descriptors need 8 byte alignment, and this is ensured
960     	 * by pci_alloc_consistent.
961     	 */
962     	BusAddr = (unsigned long) pAC->pDescrMemDMA;
963     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
964     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
965     			("TX%d/A: pDescrMem: %lX,   PhysDescrMem: %lX\n",
966     			i, (unsigned long) pDescrMem,
967     			BusAddr));
968     		pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
969     		pAC->TxPort[i][0].VTxDescrRing = BusAddr;
970     		pDescrMem += TX_RING_SIZE;
971     		BusAddr += TX_RING_SIZE;
972     	
973     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
974     			("RX%d: pDescrMem: %lX,   PhysDescrMem: %lX\n",
975     			i, (unsigned long) pDescrMem,
976     			(unsigned long)BusAddr));
977     		pAC->RxPort[i].pRxDescrRing = pDescrMem;
978     		pAC->RxPort[i].VRxDescrRing = BusAddr;
979     		pDescrMem += RX_RING_SIZE;
980     		BusAddr += RX_RING_SIZE;
981     	} /* for */
982     	
983     	return (SK_TRUE);
984     } /* BoardAllocMem */
985     
986     
987     /****************************************************************************
988      *
989      *	BoardFreeMem - reverse of BoardAllocMem
990      *
991      * Description:
992      *	Free all memory allocated in BoardAllocMem: adapter context,
993      *	descriptor rings, locks.
994      *
995      * Returns:	N/A
996      */
997     static void BoardFreeMem(
998     SK_AC		*pAC)
999     {
1000     size_t		AllocLength;	/* length of complete descriptor area */
1001     
1002     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1003     		("BoardFreeMem\n"));
1004     #if (BITS_PER_LONG == 32)
1005     	AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1006     #else
1007     	AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1008     		+ RX_RING_SIZE + 8;
1009     #endif
1010     	pci_free_consistent(&pAC->PciDev, AllocLength,
1011     			    pAC->pDescrMem, pAC->pDescrMemDMA);
1012     	pAC->pDescrMem = NULL;
1013     } /* BoardFreeMem */
1014     
1015     
1016     /*****************************************************************************
1017      *
1018      * 	BoardInitMem - initiate the descriptor rings
1019      *
1020      * Description:
1021      *	This function sets the descriptor rings up in memory.
1022      *	The adapter is initialized with the descriptor start addresses.
1023      *
1024      * Returns:	N/A
1025      */
1026     static void BoardInitMem(
1027     SK_AC	*pAC)	/* pointer to adapter context */
1028     {
1029     int	i;		/* loop counter */
1030     int	RxDescrSize;	/* the size of a rx descriptor rounded up to alignment*/
1031     int	TxDescrSize;	/* the size of a tx descriptor rounded up to alignment*/
1032     
1033     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1034     		("BoardInitMem\n"));
1035     
1036     	RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1037     	pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
1038     	TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1039     	pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
1040     	
1041     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1042     		SetupRing(
1043     			pAC,
1044     			pAC->TxPort[i][0].pTxDescrRing,
1045     			pAC->TxPort[i][0].VTxDescrRing,
1046     			(RXD**)&pAC->TxPort[i][0].pTxdRingHead,
1047     			(RXD**)&pAC->TxPort[i][0].pTxdRingTail,
1048     			(RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
1049     			&pAC->TxPort[i][0].TxdRingFree,
1050     			SK_TRUE);
1051     		SetupRing(
1052     			pAC,
1053     			pAC->RxPort[i].pRxDescrRing,
1054     			pAC->RxPort[i].VRxDescrRing,
1055     			&pAC->RxPort[i].pRxdRingHead,
1056     			&pAC->RxPort[i].pRxdRingTail,
1057     			&pAC->RxPort[i].pRxdRingPrev,
1058     			&pAC->RxPort[i].RxdRingFree,
1059     			SK_FALSE);
1060     	}
1061     } /* BoardInitMem */
1062     
1063     
1064     /*****************************************************************************
1065      *
1066      * 	SetupRing - create one descriptor ring
1067      *
1068      * Description:
1069      *	This function creates one descriptor ring in the given memory area.
1070      *	The head, tail and number of free descriptors in the ring are set.
1071      *
1072      * Returns:
1073      *	none
1074      */
1075     static void SetupRing(
1076     SK_AC		*pAC,
1077     void		*pMemArea,	/* a pointer to the memory area for the ring */
1078     uintptr_t	VMemArea,	/* the virtual bus address of the memory area */
1079     RXD		**ppRingHead,	/* address where the head should be written */
1080     RXD		**ppRingTail,	/* address where the tail should be written */
1081     RXD		**ppRingPrev,	/* address where the tail should be written */
1082     int		*pRingFree,	/* address where the # of free descr. goes */
1083     SK_BOOL		IsTx)		/* flag: is this a tx ring */
1084     {
1085     int	i;		/* loop counter */
1086     int	DescrSize;	/* the size of a descriptor rounded up to alignment*/
1087     int	DescrNum;	/* number of descriptors per ring */
1088     RXD	*pDescr;	/* pointer to a descriptor (receive or transmit) */
1089     RXD	*pNextDescr;	/* pointer to the next descriptor */
1090     RXD	*pPrevDescr;	/* pointer to the previous descriptor */
1091     uintptr_t VNextDescr;	/* the virtual bus address of the next descriptor */
1092     
1093     	if (IsTx == SK_TRUE) {
1094     		DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
1095     			DESCR_ALIGN;
1096     		DescrNum = TX_RING_SIZE / DescrSize;
1097     	}
1098     	else {
1099     		DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1100     			DESCR_ALIGN;
1101     		DescrNum = RX_RING_SIZE / DescrSize;
1102     	}
1103     	
1104     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1105     		("Descriptor size: %d   Descriptor Number: %d\n",
1106     		DescrSize,DescrNum));
1107     	
1108     	pDescr = (RXD*) pMemArea;
1109     	pPrevDescr = NULL;
1110     	pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1111     	VNextDescr = VMemArea + DescrSize;
1112     	for(i=0; i<DescrNum; i++) {
1113     		/* set the pointers right */
1114     		pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1115     		pDescr->pNextRxd = pNextDescr;
1116     		pDescr->TcpSumStarts = pAC->CsOfs;
1117     		/* advance on step */
1118     		pPrevDescr = pDescr;
1119     		pDescr = pNextDescr;
1120     		pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1121     		VNextDescr += DescrSize;
1122     	}
1123     	pPrevDescr->pNextRxd = (RXD*) pMemArea;
1124     	pPrevDescr->VNextRxd = VMemArea;
1125     	pDescr = (RXD*) pMemArea;
1126     	*ppRingHead = (RXD*) pMemArea;
1127     	*ppRingTail = *ppRingHead;
1128     	*ppRingPrev = pPrevDescr;
1129     	*pRingFree = DescrNum;
1130     } /* SetupRing */
1131     
1132     
1133     /*****************************************************************************
1134      *
1135      * 	PortReInitBmu - re-initiate the descriptor rings for one port
1136      *
1137      * Description:
1138      *	This function reinitializes the descriptor rings of one port
1139      *	in memory. The port must be stopped before.
1140      *	The HW is initialized with the descriptor start addresses.
1141      *
1142      * Returns:
1143      *	none
1144      */
1145     static void PortReInitBmu(
1146     SK_AC	*pAC,		/* pointer to adapter context */
1147     int	PortIndex)	/* index of the port for which to re-init */
1148     {
1149     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1150     		("PortReInitBmu "));
1151     
1152     	/* set address of first descriptor of ring in BMU */
1153     	SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1154     		TX_Q_CUR_DESCR_LOW,
1155     		(uint32_t)(((caddr_t)
1156     		(pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1157     		pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1158     		pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1159     		0xFFFFFFFF));
1160     	SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
1161     		TX_Q_DESCR_HIGH,
1162     		(uint32_t)(((caddr_t)
1163     		(pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1164     		pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1165     		pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1166     	SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CUR_DESCR_LOW,
1167     		(uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1168     		pAC->RxPort[PortIndex].pRxDescrRing +
1169     		pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1170     	SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_DESCR_HIGH,
1171     		(uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1172     		pAC->RxPort[PortIndex].pRxDescrRing +
1173     		pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1174     } /* PortReInitBmu */
1175     
1176     
1177     /****************************************************************************
1178      *
1179      *	SkGeIsr - handle adapter interrupts
1180      *
1181      * Description:
1182      *	The interrupt routine is called when the network adapter
1183      *	generates an interrupt. It may also be called if another device
1184      *	shares this interrupt vector with the driver.
1185      *
1186      * Returns: N/A
1187      *
1188      */
1189     static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1190     {
1191     struct net_device *dev = (struct net_device *)dev_id;
1192     
1193     DEV_NET		*pNet;
1194     SK_AC		*pAC;
1195     SK_U32		IntSrc;		/* interrupts source register contents */	
1196     
1197     	pNet = (DEV_NET*) dev->priv;
1198     	pAC = pNet->pAC;
1199     	
1200     	/*
1201     	 * Check and process if its our interrupt
1202     	 */
1203     	SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1204     	if (IntSrc == 0) {
1205     		return;
1206     	}
1207     
1208     	while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1209     #if 0 /* software irq currently not used */
1210     		if (IntSrc & IRQ_SW) {
1211     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1212     				SK_DBGCAT_DRV_INT_SRC,
1213     				("Software IRQ\n"));
1214     		}
1215     #endif
1216     		if (IntSrc & IRQ_EOF_RX1) {
1217     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1218     				SK_DBGCAT_DRV_INT_SRC,
1219     				("EOF RX1 IRQ\n"));
1220     			ReceiveIrq(pAC, &pAC->RxPort[0]);
1221     			SK_PNMI_CNT_RX_INTR(pAC,0);
1222     		}
1223     		if (IntSrc & IRQ_EOF_RX2) {
1224     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1225     				SK_DBGCAT_DRV_INT_SRC,
1226     				("EOF RX2 IRQ\n"));
1227     			ReceiveIrq(pAC, &pAC->RxPort[1]);
1228     			SK_PNMI_CNT_RX_INTR(pAC,1);
1229     		}
1230     #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1231     		if (IntSrc & IRQ_EOF_AS_TX1) {
1232     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1233     				SK_DBGCAT_DRV_INT_SRC,
1234     				("EOF AS TX1 IRQ\n"));
1235     			SK_PNMI_CNT_TX_INTR(pAC,0);
1236     			spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1237     			FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1238     			spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1239     		}
1240     		if (IntSrc & IRQ_EOF_AS_TX2) {
1241     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1242     				SK_DBGCAT_DRV_INT_SRC,
1243     				("EOF AS TX2 IRQ\n"));
1244     			SK_PNMI_CNT_TX_INTR(pAC,1);
1245     			spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1246     			FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1247     			spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1248     		}
1249     #if 0 /* only if sync. queues used */
1250     		if (IntSrc & IRQ_EOF_SY_TX1) {
1251     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1252     				SK_DBGCAT_DRV_INT_SRC,
1253     				("EOF SY TX1 IRQ\n"));
1254     			SK_PNMI_CNT_TX_INTR(pAC,0);
1255     			spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1256     			FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1257     			spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1258     			ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1259     		}
1260     		if (IntSrc & IRQ_EOF_SY_TX2) {
1261     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1262     				SK_DBGCAT_DRV_INT_SRC,
1263     				("EOF SY TX2 IRQ\n"));
1264     			SK_PNMI_CNT_TX_INTR(pAC,1);
1265     			spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1266     			FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1267     			spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1268     			ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1269     		}
1270     #endif /* 0 */
1271     #endif /* USE_TX_COMPLETE */
1272     
1273     		/* do all IO at once */
1274     		if (IntSrc & IRQ_EOF_RX1)
1275     			ClearAndStartRx(pAC, 0);
1276     		if (IntSrc & IRQ_EOF_RX2)
1277     			ClearAndStartRx(pAC, 1);
1278     #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1279     		if (IntSrc & IRQ_EOF_AS_TX1)
1280     			ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1281     		if (IntSrc & IRQ_EOF_AS_TX2)
1282     			ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1283     #endif
1284     		SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1285     	} /* while (IntSrc & IRQ_MASK != 0) */
1286     
1287     	if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1288     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1289     			("SPECIAL IRQ\n"));
1290     		pAC->CheckQueue = SK_FALSE;
1291     		spin_lock(&pAC->SlowPathLock);
1292     		if (IntSrc & SPECIAL_IRQS)
1293     			SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1294     		SkEventDispatcher(pAC, pAC->IoBase);
1295     		spin_unlock(&pAC->SlowPathLock);
1296     	}
1297     	/*
1298     	 * do it all again is case we cleared an interrupt that 
1299     	 * came in after handling the ring (OUTs may be delayed
1300     	 * in hardware buffers, but are through after IN)
1301     	 */
1302     	// ReceiveIrq(pAC, &pAC->RxPort[pAC->ActivePort]);
1303     	ReceiveIrq(pAC, &pAC->RxPort[0]);
1304     	ReceiveIrq(pAC, &pAC->RxPort[1]);
1305     	
1306     
1307     
1308     
1309     #if 0
1310     // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1311     	spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1312     	FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1313     	spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1314     
1315     	spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1316     	FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1317     	spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1318     
1319     #if 0	/* only if sync. queues used */
1320     	spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1321     	FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1322     	spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1323     	
1324     	spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1325     	FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1326     	spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1327     #endif /* 0 */
1328     #endif /* USE_TX_COMPLETE */
1329     
1330     	/* IRQ is processed - Enable IRQs again*/
1331     	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1332     
1333     	return;
1334     } /* SkGeIsr */
1335     
1336     
1337     /****************************************************************************
1338      *
1339      *	SkGeIsrOnePort - handle adapter interrupts for single port adapter
1340      *
1341      * Description:
1342      *	The interrupt routine is called when the network adapter
1343      *	generates an interrupt. It may also be called if another device
1344      *	shares this interrupt vector with the driver.
1345      *	This is the same as above, but handles only one port.
1346      *
1347      * Returns: N/A
1348      *
1349      */
1350     static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1351     {
1352     struct net_device *dev = (struct net_device *)dev_id;
1353     DEV_NET		*pNet;
1354     SK_AC		*pAC;
1355     SK_U32		IntSrc;		/* interrupts source register contents */	
1356     
1357     	pNet = (DEV_NET*) dev->priv;
1358     	pAC = pNet->pAC;
1359     	
1360     	/*
1361     	 * Check and process if its our interrupt
1362     	 */
1363     	SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1364     	if (IntSrc == 0) {
1365     		return;
1366     	}
1367     
1368     	while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1369     #if 0 /* software irq currently not used */
1370     		if (IntSrc & IRQ_SW) {
1371     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1372     				SK_DBGCAT_DRV_INT_SRC,
1373     				("Software IRQ\n"));
1374     		}
1375     #endif
1376     		if (IntSrc & IRQ_EOF_RX1) {
1377     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1378     				SK_DBGCAT_DRV_INT_SRC,
1379     				("EOF RX1 IRQ\n"));
1380     			ReceiveIrq(pAC, &pAC->RxPort[0]);
1381     			SK_PNMI_CNT_RX_INTR(pAC,0);
1382     		}
1383     #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1384     		if (IntSrc & IRQ_EOF_AS_TX1) {
1385     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1386     				SK_DBGCAT_DRV_INT_SRC,
1387     				("EOF AS TX1 IRQ\n"));
1388     			SK_PNMI_CNT_TX_INTR(pAC,0);
1389     			spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1390     			FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1391     			spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1392     		}
1393     #if 0 /* only if sync. queues used */
1394     		if (IntSrc & IRQ_EOF_SY_TX1) {
1395     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1396     				SK_DBGCAT_DRV_INT_SRC,
1397     				("EOF SY TX1 IRQ\n"));
1398     			SK_PNMI_CNT_TX_INTR(pAC,1);
1399     			spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1400     			FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1401     			spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1402     			ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1403     		}
1404     #endif /* 0 */
1405     #endif /* USE_TX_COMPLETE */
1406     
1407     		/* do all IO at once */
1408     		if (IntSrc & IRQ_EOF_RX1)
1409     			ClearAndStartRx(pAC, 0);
1410     #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1411     		if (IntSrc & IRQ_EOF_AS_TX1)
1412     			ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1413     #endif
1414     		SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1415     	} /* while (IntSrc & IRQ_MASK != 0) */
1416     	
1417     	if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1418     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1419     			("SPECIAL IRQ\n"));
1420     		pAC->CheckQueue = SK_FALSE;
1421     		spin_lock(&pAC->SlowPathLock);
1422     		if (IntSrc & SPECIAL_IRQS)
1423     			SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1424     		SkEventDispatcher(pAC, pAC->IoBase);
1425     		spin_unlock(&pAC->SlowPathLock);
1426     	}
1427     	/*
1428     	 * do it all again is case we cleared an interrupt that 
1429     	 * came in after handling the ring (OUTs may be delayed
1430     	 * in hardware buffers, but are through after IN)
1431     	 */
1432     	ReceiveIrq(pAC, &pAC->RxPort[0]);
1433     
1434     #if 0
1435     // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1436     	spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1437     	FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1438     	spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1439     
1440     #if 0	/* only if sync. queues used */
1441     	spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1442     	FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1443     	spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1444     	
1445     #endif /* 0 */
1446     #endif /* USE_TX_COMPLETE */
1447     
1448     	/* IRQ is processed - Enable IRQs again*/
1449     	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1450     
1451     	return;
1452     } /* SkGeIsrOnePort */
1453     
1454     
1455     /****************************************************************************
1456      *
1457      *	SkGeOpen - handle start of initialized adapter
1458      *
1459      * Description:
1460      *	This function starts the initialized adapter.
1461      *	The board level variable is set and the adapter is
1462      *	brought to full functionality.
1463      *	The device flags are set for operation.
1464      *	Do all necessary level 2 initialization, enable interrupts and
1465      *	give start command to RLMT.
1466      *
1467      * Returns:
1468      *	0 on success
1469      *	!= 0 on error
1470      */
1471     static int SkGeOpen(
1472     struct net_device	*dev)
1473     {
1474     DEV_NET			*pNet;
1475     SK_AC			*pAC;
1476     unsigned long	Flags;		/* for spin lock */
1477     int		i;
1478     SK_EVPARA		EvPara;		/* an event parameter union */
1479     
1480     	pNet = (DEV_NET*) dev->priv;
1481     	pAC = pNet->pAC;
1482     	
1483     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1484     		("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1485     
1486     	if (pAC->BoardLevel == 0) {
1487     		/* level 1 init common modules here */
1488     		if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
1489     			printk("%s: HWInit(1) failed\n", pAC->dev[pNet->PortNr]->name);
1490     			return (-1);
1491     		}
1492     		SkI2cInit	(pAC, pAC->IoBase, 1);
1493     		SkEventInit	(pAC, pAC->IoBase, 1);
1494     		SkPnmiInit	(pAC, pAC->IoBase, 1);
1495     		SkAddrInit	(pAC, pAC->IoBase, 1);
1496     		SkRlmtInit	(pAC, pAC->IoBase, 1);
1497     		SkTimerInit	(pAC, pAC->IoBase, 1);
1498     		pAC->BoardLevel = 1;
1499     	}
1500     
1501     	if (pAC->BoardLevel != 2) {
1502     		/* level 2 init modules here */
1503     		SkGeInit	(pAC, pAC->IoBase, 2);
1504     		SkI2cInit	(pAC, pAC->IoBase, 2);
1505     		SkEventInit	(pAC, pAC->IoBase, 2);
1506     		SkPnmiInit	(pAC, pAC->IoBase, 2);
1507     		SkAddrInit	(pAC, pAC->IoBase, 2);
1508     		SkRlmtInit	(pAC, pAC->IoBase, 2);
1509     		SkTimerInit	(pAC, pAC->IoBase, 2);
1510     		pAC->BoardLevel = 2;
1511     	}
1512     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1513     		/* Enable transmit descriptor polling. */
1514     		SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1515     		FillRxRing(pAC, &pAC->RxPort[i]);
1516     	}
1517     	SkGeYellowLED(pAC, pAC->IoBase, 1);
1518     
1519     #ifdef USE_INT_MOD
1520     /* moderate only TX complete interrupts (these are not time critical) */
1521     #define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)
1522     	{
1523     		unsigned long ModBase;
1524     		ModBase = 53125000 / INTS_PER_SEC;
1525     		SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
1526     		SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
1527     		SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
1528     	}
1529     #endif
1530     
1531     	/* enable Interrupts */
1532     	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
1533     	SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1534     
1535     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1536     
1537     	if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1538     		EvPara.Para32[0] = pAC->RlmtNets;
1539     		EvPara.Para32[1] = -1;
1540     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1541     			EvPara);
1542     		EvPara.Para32[0] = pAC->RlmtMode;
1543     		EvPara.Para32[1] = 0;
1544     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1545     			EvPara);
1546     	}
1547     
1548     	EvPara.Para32[0] = pNet->NetNr;
1549     	EvPara.Para32[1] = -1;
1550     	SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1551     	SkEventDispatcher(pAC, pAC->IoBase);
1552     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1553     
1554     	pAC->MaxPorts++;
1555     	pNet->Up = 1;
1556     
1557     	MOD_INC_USE_COUNT;
1558     
1559     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1560     		("SkGeOpen suceeded\n"));
1561     
1562     	return (0);
1563     } /* SkGeOpen */
1564     
1565     
1566     /****************************************************************************
1567      *
1568      *	SkGeClose - Stop initialized adapter
1569      *
1570      * Description:
1571      *	Close initialized adapter.
1572      *
1573      * Returns:
1574      *	0 - on success
1575      *	error code - on error
1576      */
1577     static int SkGeClose(
1578     struct net_device	*dev)
1579     {
1580     DEV_NET		*pNet;
1581     SK_AC		*pAC;
1582     
1583     unsigned long	Flags;		/* for spin lock */
1584     int				i;
1585     int				PortIdx;
1586     SK_EVPARA		EvPara;
1587     
1588     	netif_stop_queue(dev);
1589     
1590     	pNet = (DEV_NET*) dev->priv;
1591     	pAC = pNet->pAC;
1592     
1593     	if (pAC->RlmtNets == 1)
1594     		PortIdx = pAC->ActivePort;
1595     	else
1596     		PortIdx = pNet->NetNr;
1597     
1598     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1599     		("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1600     
1601     	/* 
1602     	 * Clear multicast table, promiscuous mode ....
1603     	 */
1604     	 
1605     	SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1606     	SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1607     		SK_PROM_MODE_NONE);
1608     
1609     	if (pAC->MaxPorts == 1) {
1610     		spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1611     		/* disable interrupts */
1612     		SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1613     		EvPara.Para32[0] = pNet->NetNr;
1614     		EvPara.Para32[1] = -1;
1615     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1616     		SkEventDispatcher(pAC, pAC->IoBase);
1617     		SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1618     		/* stop the hardware */
1619     		SkGeDeInit(pAC, pAC->IoBase);
1620     		pAC->BoardLevel = 0;
1621     		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1622     	} else {
1623     
1624     		spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1625     		EvPara.Para32[0] = pNet->NetNr;
1626     		EvPara.Para32[1] = -1;
1627     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1628     		SkEventDispatcher(pAC, pAC->IoBase);
1629     		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1630     		
1631     		/* Stop port */
1632     		spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1633     			[TX_PRIO_LOW].TxDesRingLock, Flags);
1634     		SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr, 
1635     			SK_STOP_ALL, SK_HARD_RST);
1636     		spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1637     			[TX_PRIO_LOW].TxDesRingLock, Flags);
1638     	}
1639     	if (pAC->RlmtNets == 1) {
1640     		/* clear all descriptor rings */
1641     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1642     			ReceiveIrq(pAC, &pAC->RxPort[i]);
1643     			ClearRxRing(pAC, &pAC->RxPort[i]);
1644     			ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1645     		}
1646     	} else {
1647     		/* clear port descriptor rings */
1648     		ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr]);
1649     		ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1650     		ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1651     	}
1652     
1653     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1654     		("SkGeClose: done "));
1655     
1656     	pAC->MaxPorts--;
1657     	pNet->Up = 0;
1658     	MOD_DEC_USE_COUNT;
1659     	
1660     	return (0);
1661     } /* SkGeClose */
1662     
1663     /*****************************************************************************
1664      *
1665      * 	SkGeXmit - Linux frame transmit function
1666      *
1667      * Description:
1668      *	The system calls this function to send frames onto the wire.
1669      *	It puts the frame in the tx descriptor ring. If the ring is
1670      *	full then, the 'tbusy' flag is set.
1671      *
1672      * Returns:
1673      *	0, if everything is ok
1674      *	!=0, on error
1675      * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1676      *	allocated skb's) !!!
1677      */
1678     static int SkGeXmit(struct sk_buff *skb, struct net_device *dev)
1679     {
1680     DEV_NET		*pNet;
1681     SK_AC		*pAC;
1682     int			Rc;	/* return code of XmitFrame */
1683     	
1684     	pNet = (DEV_NET*) dev->priv;
1685     	pAC = pNet->pAC;
1686     
1687     	if (pAC->RlmtNets == 2)
1688     		Rc = XmitFrame(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW], skb);
1689     	else
1690     		Rc = XmitFrame(pAC, &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW], skb);
1691     
1692     	/* Transmitter out of resources? */
1693     	if (Rc <= 0)
1694     		netif_stop_queue(dev);
1695     
1696     	/* If not taken, give buffer ownership back to the
1697     	 * queueing layer.
1698     	 */
1699     	if (Rc < 0)
1700     		return (1);
1701     
1702     	dev->trans_start = jiffies;
1703     	return (0);
1704     } /* SkGeXmit */
1705     
1706     
1707     /*****************************************************************************
1708      *
1709      * 	XmitFrame - fill one socket buffer into the transmit ring
1710      *
1711      * Description:
1712      *	This function puts a message into the transmit descriptor ring
1713      *	if there is a descriptors left.
1714      *	Linux skb's consist of only one continuous buffer.
1715      *	The first step locks the ring. It is held locked
1716      *	all time to avoid problems with SWITCH_../PORT_RESET.
1717      *	Then the descriptoris allocated.
1718      *	The second part is linking the buffer to the descriptor.
1719      *	At the very last, the Control field of the descriptor
1720      *	is made valid for the BMU and a start TX command is given
1721      *	if necessary.
1722      *
1723      * Returns:
1724      *  > 0 - on succes: the number of bytes in the message
1725      *  = 0 - on resource shortage: this frame sent or dropped, now
1726      *        the ring is full ( -> set tbusy)
1727      *  < 0 - on failure: other problems ( -> return failure to upper layers)
1728      */
1729     static int XmitFrame(
1730     SK_AC 		*pAC,		/* pointer to adapter context */
1731     TX_PORT		*pTxPort,	/* pointer to struct of port to send to */
1732     struct sk_buff	*pMessage)	/* pointer to send-message */
1733     {
1734     TXD		*pTxd;		/* the rxd to fill */
1735     unsigned long	Flags;
1736     SK_U64		PhysAddr;
1737     int		BytesSend;
1738     
1739     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1740     		("X"));
1741     
1742     	spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1743     
1744     	if (pTxPort->TxdRingFree == 0) {
1745     		/* no enough free descriptors in ring at the moment */
1746     		FreeTxDescriptors(pAC, pTxPort);
1747     		if (pTxPort->TxdRingFree == 0) {
1748     			spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1749     			SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1750     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1751     				SK_DBGCAT_DRV_TX_PROGRESS,
1752     				("XmitFrame failed\n"));
1753     			/* this message can not be sent now */
1754     			return (-1);
1755     		}
1756     	}
1757     	/* advance head counter behind descriptor needed for this frame */
1758     	pTxd = pTxPort->pTxdRingHead;
1759     	pTxPort->pTxdRingHead = pTxd->pNextTxd;
1760     	pTxPort->TxdRingFree--;
1761     	/* the needed descriptor is reserved now */
1762     	
1763     	/* 
1764     	 * everything allocated ok, so add buffer to descriptor
1765     	 */
1766     
1767     #ifdef SK_DUMP_TX
1768     	DumpMsg(pMessage, "XmitFrame");
1769     #endif
1770     
1771     	/* set up descriptor and CONTROL dword */
1772     	PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
1773     					   pMessage->data,
1774     					   pMessage->len,
1775     					   PCI_DMA_TODEVICE);
1776     	pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);
1777     	pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1778     	pTxd->pMBuf = pMessage;
1779     	pTxd->TBControl = TX_CTRL_OWN_BMU | TX_CTRL_STF |
1780     		TX_CTRL_CHECK_DEFAULT | TX_CTRL_SOFTWARE |
1781     #ifdef USE_TX_COMPLETE
1782     		TX_CTRL_EOF | TX_CTRL_EOF_IRQ | pMessage->len;
1783     #else
1784     		TX_CTRL_EOF | pMessage->len;
1785     #endif
1786     	
1787     	if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
1788     		/* previous descriptor already done, so give tx start cmd */
1789     		/* StartTx(pAC, pTxPort->HwAddr); */
1790     		SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
1791     	}
1792     	pTxPort->pTxdRingPrev = pTxd;
1793     	
1794     	
1795     	BytesSend = pMessage->len;
1796     	/* after releasing the lock, the skb may be immidiately freed */
1797     	if (pTxPort->TxdRingFree != 0) {
1798     		spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1799     		return (BytesSend);
1800     	}
1801     	else {
1802     		/* ring full: set tbusy on return */
1803     		spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1804     		return (0);
1805     	}
1806     } /* XmitFrame */
1807     
1808     
1809     /*****************************************************************************
1810      *
1811      * 	FreeTxDescriptors - release descriptors from the descriptor ring
1812      *
1813      * Description:
1814      *	This function releases descriptors from a transmit ring if they
1815      *	have been sent by the BMU.
1816      *	If a descriptors is sent, it can be freed and the message can
1817      *	be freed, too.
1818      *	The SOFTWARE controllable bit is used to prevent running around a
1819      *	completely free ring for ever. If this bit is no set in the
1820      *	frame (by XmitFrame), this frame has never been sent or is
1821      *	already freed.
1822      *	The Tx descriptor ring lock must be held while calling this function !!!
1823      *
1824      * Returns:
1825      *	none
1826      */
1827     static void FreeTxDescriptors(
1828     SK_AC	*pAC,		/* pointer to the adapter context */
1829     TX_PORT	*pTxPort)	/* pointer to destination port structure */
1830     {
1831     TXD	*pTxd;		/* pointer to the checked descriptor */
1832     TXD	*pNewTail;	/* pointer to 'end' of the ring */
1833     SK_U32	Control;	/* TBControl field of descriptor */
1834     SK_U64	PhysAddr;	/* address of DMA mapping */
1835     
1836     	pNewTail = pTxPort->pTxdRingTail;
1837     	pTxd = pNewTail;
1838     	
1839     	/* 
1840     	 * loop forever; exits if TX_CTRL_SOFTWARE bit not set in start frame
1841     	 * or TX_CTRL_OWN_BMU bit set in any frame
1842     	 */
1843     	while (1) {
1844     		Control = pTxd->TBControl;
1845     		if ((Control & TX_CTRL_SOFTWARE) == 0) {
1846     			/* 
1847     			 * software controllable bit is set in first
1848     			 * fragment when given to BMU. Not set means that
1849     			 * this fragment was never sent or is already 
1850     			 * freed ( -> ring completely free now).
1851     			 */
1852     			pTxPort->pTxdRingTail = pTxd;
1853     			netif_start_queue(pAC->dev[pTxPort->PortIndex]);
1854     			return;
1855     		}
1856     		if (Control & TX_CTRL_OWN_BMU) {
1857     			pTxPort->pTxdRingTail = pTxd;
1858     			if (pTxPort->TxdRingFree > 0) {
1859     				netif_start_queue(pAC->dev[pTxPort->PortIndex]);
1860     			}
1861     			return;
1862     		}
1863     		
1864     		/* release the DMA mapping */
1865     		PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1866     		PhysAddr |= (SK_U64) pTxd->VDataLow;
1867     		pci_unmap_single(&pAC->PciDev, PhysAddr,
1868     				 pTxd->pMBuf->len,
1869     				 PCI_DMA_TODEVICE);
1870     
1871     		/* free message */
1872     		DEV_KFREE_SKB_ANY(pTxd->pMBuf);
1873     		pTxPort->TxdRingFree++;
1874     		pTxd->TBControl &= ~TX_CTRL_SOFTWARE;
1875     		pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1876     	} /* while(forever) */
1877     } /* FreeTxDescriptors */
1878     
1879     
1880     /*****************************************************************************
1881      *
1882      * 	FillRxRing - fill the receive ring with valid descriptors
1883      *
1884      * Description:
1885      *	This function fills the receive ring descriptors with data
1886      *	segments and makes them valid for the BMU.
1887      *	The active ring is filled completely, if possible.
1888      *	The non-active ring is filled only partial to save memory.
1889      *
1890      * Description of rx ring structure:
1891      *	head - points to the descriptor which will be used next by the BMU
1892      *	tail - points to the next descriptor to give to the BMU
1893      *	
1894      * Returns:	N/A
1895      */
1896     static void FillRxRing(
1897     SK_AC		*pAC,		/* pointer to the adapter context */
1898     RX_PORT		*pRxPort)	/* ptr to port struct for which the ring
1899     				   should be filled */
1900     {
1901     unsigned long	Flags;
1902     
1903     	spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1904     	while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1905     		if(!FillRxDescriptor(pAC, pRxPort))
1906     			break;
1907     	}
1908     	spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1909     } /* FillRxRing */
1910     
1911     
1912     /*****************************************************************************
1913      *
1914      * 	FillRxDescriptor - fill one buffer into the receive ring
1915      *
1916      * Description:
1917      *	The function allocates a new receive buffer and
1918      *	puts it into the next descriptor.
1919      *
1920      * Returns:
1921      *	SK_TRUE - a buffer was added to the ring
1922      *	SK_FALSE - a buffer could not be added
1923      */
1924     static SK_BOOL FillRxDescriptor(
1925     SK_AC		*pAC,		/* pointer to the adapter context struct */
1926     RX_PORT		*pRxPort)	/* ptr to port struct of ring to fill */
1927     {
1928     struct sk_buff	*pMsgBlock;	/* pointer to a new message block */
1929     RXD		*pRxd;		/* the rxd to fill */
1930     SK_U16		Length;		/* data fragment length */
1931     SK_U64		PhysAddr;	/* physical address of a rx buffer */
1932     
1933     	pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1934     	if (pMsgBlock == NULL) {
1935     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1936     			SK_DBGCAT_DRV_ENTRY,
1937     			("%s: Allocation of rx buffer failed !\n",
1938     			pAC->dev[pRxPort->PortIndex]->name));
1939     		SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1940     		return(SK_FALSE);
1941     	}
1942     	skb_reserve(pMsgBlock, 2); /* to align IP frames */
1943     	/* skb allocated ok, so add buffer */
1944     	pRxd = pRxPort->pRxdRingTail;
1945     	pRxPort->pRxdRingTail = pRxd->pNextRxd;
1946     	pRxPort->RxdRingFree--;
1947     	Length = pAC->RxBufSize;
1948     	PhysAddr = (SK_U64) pci_map_single(&pAC->PciDev,
1949     					   pMsgBlock->data,
1950     					   pAC->RxBufSize - 2,
1951     					   PCI_DMA_FROMDEVICE);
1952     	pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1953     	pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1954     	pRxd->pMBuf = pMsgBlock;
1955     	pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
1956     		RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
1957     	return (SK_TRUE);
1958     
1959     } /* FillRxDescriptor */
1960     
1961     
1962     /*****************************************************************************
1963      *
1964      * 	ReQueueRxBuffer - fill one buffer back into the receive ring
1965      *
1966      * Description:
1967      *	Fill a given buffer back into the rx ring. The buffer
1968      *	has been previously allocated and aligned, and its phys.
1969      *	address calculated, so this is no more necessary.
1970      *
1971      * Returns: N/A
1972      */
1973     static void ReQueueRxBuffer(
1974     SK_AC		*pAC,		/* pointer to the adapter context struct */
1975     RX_PORT		*pRxPort,	/* ptr to port struct of ring to fill */
1976     struct sk_buff	*pMsg,		/* pointer to the buffer */
1977     SK_U32		PhysHigh,	/* phys address high dword */
1978     SK_U32		PhysLow)	/* phys address low dword */
1979     {
1980     RXD		*pRxd;		/* the rxd to fill */
1981     SK_U16		Length;		/* data fragment length */
1982     
1983     	pRxd = pRxPort->pRxdRingTail;
1984     	pRxPort->pRxdRingTail = pRxd->pNextRxd;
1985     	pRxPort->RxdRingFree--;
1986     	Length = pAC->RxBufSize;
1987     	pRxd->VDataLow = PhysLow;
1988     	pRxd->VDataHigh = PhysHigh;
1989     	pRxd->pMBuf = pMsg;
1990     	pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
1991     		RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
1992     	return;
1993     } /* ReQueueRxBuffer */
1994     
1995     
1996     /*****************************************************************************
1997      *
1998      * 	ReceiveIrq - handle a receive IRQ
1999      *
2000      * Description:
2001      *	This function is called when a receive IRQ is set.
2002      *	It walks the receive descriptor ring and sends up all
2003      *	frames that are complete.
2004      *
2005      * Returns:	N/A
2006      */
2007     static void ReceiveIrq(
2008     SK_AC		*pAC,		/* pointer to adapter context */
2009     RX_PORT		*pRxPort)	/* pointer to receive port struct */
2010     {
2011     RXD		*pRxd;		/* pointer to receive descriptors */
2012     SK_U32		Control;	/* control field of descriptor */
2013     struct sk_buff	*pMsg;		/* pointer to message holding frame */
2014     struct sk_buff	*pNewMsg;	/* pointer to a new message for copying frame */
2015     int		FrameLength;	/* total length of received frame */
2016     SK_MBUF		*pRlmtMbuf;	/* ptr to a buffer for giving a frame to rlmt */
2017     SK_EVPARA	EvPara;		/* an event parameter union */	
2018     int		PortIndex = pRxPort->PortIndex;
2019     unsigned int	Offset;
2020     unsigned int	NumBytes;
2021     unsigned int	ForRlmt;
2022     SK_BOOL		IsBc;
2023     SK_BOOL		IsMc;
2024     SK_U32		FrameStat;
2025     unsigned short	Csum1;
2026     unsigned short	Csum2;
2027     unsigned short	Type;
2028     int		Result;
2029     SK_U64		PhysAddr;
2030     
2031     rx_start:	
2032     	/* do forever; exit if RX_CTRL_OWN_BMU found */
2033     	for ( pRxd = pRxPort->pRxdRingHead ;
2034     		  pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2035     		  pRxd = pRxd->pNextRxd,
2036     		  pRxPort->pRxdRingHead = pRxd,
2037     		  pRxPort->RxdRingFree ++) {
2038     
2039     		/*
2040     		 * For a better understanding of this loop 
2041     		 * Go through every descriptor beginning at the head 
2042     		 * Please note: the ring might be completely received so the OWN bit
2043     		 * set is not a good crirteria to leave that loop.
2044     		 * Therefore the RingFree counter is used.
2045     		 * On entry of this loop pRxd is a pointer to the Rxd that needs
2046     		 * to be checked next.
2047     		 */
2048     
2049     		Control = pRxd->RBControl;
2050     	
2051     		/* check if this descriptor is ready */
2052     		if ((Control & RX_CTRL_OWN_BMU) != 0) {
2053     			/* this descriptor is not yet ready */
2054     			/* This is the usual end of the loop */
2055     			/* We don't need to start the ring again */
2056     			FillRxRing(pAC, pRxPort);
2057     			return;
2058     		}
2059     
2060     		/* get length of frame and check it */
2061     		FrameLength = Control & RX_CTRL_LEN_MASK;
2062     		if (FrameLength > pAC->RxBufSize) {
2063     			goto rx_failed;
2064     		}
2065     
2066     		/* check for STF and EOF */
2067     		if ((Control & (RX_CTRL_STF | RX_CTRL_EOF)) !=
2068     			(RX_CTRL_STF | RX_CTRL_EOF)) {
2069     			goto rx_failed;
2070     		}
2071     		
2072     		/* here we have a complete frame in the ring */
2073     		pMsg = pRxd->pMBuf;
2074     
2075     		FrameStat = pRxd->FrameStat;
2076     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2077     			("Received frame of length %d on port %d\n",
2078     			FrameLength, PortIndex));
2079     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2080     			("Number of free rx descriptors: %d\n",
2081     			pRxPort->RxdRingFree));
2082     		/*DumpMsg(pMsg, "Rx");	*/	
2083     		
2084     		if ((Control & RX_CTRL_STAT_VALID) != RX_CTRL_STAT_VALID ||
2085     			(FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2086     			/* there is a receive error in this frame */
2087     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2088     				SK_DBGCAT_DRV_RX_PROGRESS,
2089     				("skge: Error in received frame, dropped!\n"
2090     				"Control: %x\nRxStat: %x\n",
2091     				Control, FrameStat));
2092     			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2093     			PhysAddr |= (SK_U64) pRxd->VDataLow;
2094     			pci_dma_sync_single(&pAC->PciDev,
2095     						(dma_addr_t) PhysAddr,
2096     						FrameLength,
2097     						PCI_DMA_FROMDEVICE);
2098     			ReQueueRxBuffer(pAC, pRxPort, pMsg,
2099     				pRxd->VDataHigh, pRxd->VDataLow);
2100     
2101     			continue;
2102     		}
2103     
2104     		/*
2105     		 * if short frame then copy data to reduce memory waste
2106     		 */
2107     		if ((FrameLength < SK_COPY_THRESHOLD) &&
2108     			((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2109     			/*
2110     			 * Short frame detected and allocation successfull
2111     			 */
2112     			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2113     			PhysAddr |= (SK_U64) pRxd->VDataLow;
2114     
2115     			/* use new skb and copy data */
2116     			skb_reserve(pNewMsg, 2);
2117     			skb_put(pNewMsg, FrameLength);
2118     			pci_dma_sync_single(&pAC->PciDev,
2119     						(dma_addr_t) PhysAddr,
2120     						FrameLength,
2121     						PCI_DMA_FROMDEVICE);
2122     			eth_copy_and_sum(pNewMsg, pMsg->data,
2123     				FrameLength, 0);
2124     			ReQueueRxBuffer(pAC, pRxPort, pMsg,
2125     				pRxd->VDataHigh, pRxd->VDataLow);
2126     			pMsg = pNewMsg;
2127     
2128     		}
2129     		else {
2130     			/*
2131     			 * if large frame, or SKB allocation failed, pass
2132     			 * the SKB directly to the networking
2133     			 */
2134     
2135     			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2136     			PhysAddr |= (SK_U64) pRxd->VDataLow;
2137     
2138     			/* release the DMA mapping */
2139     			pci_unmap_single(&pAC->PciDev,
2140     					 PhysAddr,
2141     					 pAC->RxBufSize - 2,
2142     					 PCI_DMA_FROMDEVICE);
2143     
2144     			/* set length in message */
2145     			skb_put(pMsg, FrameLength);
2146     			/* hardware checksum */
2147     			Type = ntohs(*((short*)&pMsg->data[12]));
2148     			if (Type == 0x800) {
2149     				Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2150     				Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2151     				if ((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) {
2152     					Result = SkCsGetReceiveInfo(pAC,
2153     						&pMsg->data[14], 
2154     						Csum1, Csum2, pRxPort->PortIndex);
2155     					if (Result == 
2156     						SKCS_STATUS_IP_FRAGMENT ||
2157     						Result ==
2158     						SKCS_STATUS_IP_CSUM_OK ||
2159     						Result ==
2160     						SKCS_STATUS_TCP_CSUM_OK ||
2161     						Result ==
2162     						SKCS_STATUS_UDP_CSUM_OK) {
2163     						pMsg->ip_summed =
2164     						CHECKSUM_UNNECESSARY;
2165     					}
2166     				} /* checksum calculation valid */
2167     			} /* IP frame */
2168     		} /* frame > SK_COPY_TRESHOLD */
2169     		
2170     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV,	1,("V"));
2171     		ForRlmt = SK_RLMT_RX_PROTOCOL;
2172     		IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2173     		SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2174     			IsBc, &Offset, &NumBytes);
2175     		if (NumBytes != 0) {
2176     			IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2177     			SK_RLMT_LOOKAHEAD(pAC, PortIndex, 
2178     				&pMsg->data[Offset],
2179     				IsBc, IsMc, &ForRlmt);
2180     		}
2181     		if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2182     					SK_DBG_MSG(NULL, SK_DBGMOD_DRV,	1,("W"));
2183     			/* send up only frames from active port */
2184     			if ((PortIndex == pAC->ActivePort) ||
2185     				(pAC->RlmtNets == 2)) {
2186     				/* frame for upper layer */
2187     				SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2188     #ifdef xDEBUG
2189     				DumpMsg(pMsg, "Rx");
2190     #endif
2191     				SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2192     					FrameLength, pRxPort->PortIndex);
2193     
2194     				pMsg->dev = pAC->dev[pRxPort->PortIndex];
2195     				pMsg->protocol = eth_type_trans(pMsg,
2196     					pAC->dev[pRxPort->PortIndex]);
2197     				netif_rx(pMsg);
2198     				pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2199     			}
2200     			else {
2201     				/* drop frame */
2202     				SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2203     					SK_DBGCAT_DRV_RX_PROGRESS,
2204     					("D"));
2205     				DEV_KFREE_SKB(pMsg);
2206     			}
2207     			
2208     		} /* if not for rlmt */
2209     		else {
2210     			/* packet for rlmt */
2211     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2212     				SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2213     			pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2214     				pAC->IoBase, FrameLength);
2215     			if (pRlmtMbuf != NULL) {
2216     				pRlmtMbuf->pNext = NULL;
2217     				pRlmtMbuf->Length = FrameLength;
2218     				pRlmtMbuf->PortIdx = PortIndex;
2219     				EvPara.pParaPtr = pRlmtMbuf;
2220     				memcpy((char*)(pRlmtMbuf->pData),
2221     					   (char*)(pMsg->data),
2222     					   FrameLength);
2223     				SkEventQueue(pAC, SKGE_RLMT,
2224     					SK_RLMT_PACKET_RECEIVED,
2225     					EvPara);
2226     				pAC->CheckQueue = SK_TRUE;
2227     				SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 
2228     					SK_DBGCAT_DRV_RX_PROGRESS,
2229     					("Q"));
2230     			}
2231     			if ((pAC->dev[pRxPort->PortIndex]->flags & 
2232     				(IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2233     				(ForRlmt & SK_RLMT_RX_PROTOCOL) == 
2234     				SK_RLMT_RX_PROTOCOL) { 
2235     				pMsg->dev = pAC->dev[pRxPort->PortIndex];
2236     				pMsg->protocol = eth_type_trans(pMsg,
2237     					pAC->dev[pRxPort->PortIndex]);
2238     				netif_rx(pMsg);
2239     				pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2240     			}
2241     			else {
2242     				DEV_KFREE_SKB(pMsg);
2243     			}
2244     
2245     		} /* if packet for rlmt */
2246     	} /* for ... scanning the RXD ring */
2247     
2248     	/* RXD ring is empty -> fill and restart */
2249     	FillRxRing(pAC, pRxPort);
2250     	/* do not start if called from Close */
2251     	if (pAC->BoardLevel > 0) {
2252     		ClearAndStartRx(pAC, PortIndex);
2253     	}
2254     	return;
2255     
2256     rx_failed:
2257     	/* remove error frame */
2258     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2259     		("Schrottdescriptor, length: 0x%x\n", FrameLength));
2260     
2261     	/* release the DMA mapping */
2262     	PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2263     	PhysAddr |= (SK_U64) pRxd->VDataLow;
2264     	pci_unmap_single(&pAC->PciDev,
2265     			 PhysAddr,
2266     			 pAC->RxBufSize - 2,
2267     			 PCI_DMA_FROMDEVICE);
2268     	DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2269     	pRxd->pMBuf = NULL;
2270     	pRxPort->RxdRingFree++;
2271     	pRxPort->pRxdRingHead = pRxd->pNextRxd;
2272     	goto rx_start;
2273     
2274     } /* ReceiveIrq */
2275     
2276     
2277     /*****************************************************************************
2278      *
2279      * 	ClearAndStartRx - give a start receive command to BMU, clear IRQ
2280      *
2281      * Description:
2282      *	This function sends a start command and a clear interrupt
2283      *	command for one receive queue to the BMU.
2284      *
2285      * Returns: N/A
2286      *	none
2287      */
2288     static void ClearAndStartRx(
2289     SK_AC	*pAC,		/* pointer to the adapter context */
2290     int	PortIndex)	/* index of the receive port (XMAC) */
2291     {
2292     	SK_OUT8(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CTRL,
2293     		RX_Q_CTRL_START | RX_Q_CTRL_CLR_I_EOF);
2294     } /* ClearAndStartRx */
2295     
2296     
2297     /*****************************************************************************
2298      *
2299      * 	ClearTxIrq - give a clear transmit IRQ command to BMU
2300      *
2301      * Description:
2302      *	This function sends a clear tx IRQ command for one
2303      *	transmit queue to the BMU.
2304      *
2305      * Returns: N/A
2306      */
2307     static void ClearTxIrq(
2308     SK_AC	*pAC,		/* pointer to the adapter context */
2309     int	PortIndex,	/* index of the transmit port (XMAC) */
2310     int	Prio)		/* priority or normal queue */
2311     {
2312     	SK_OUT8(pAC->IoBase, TxQueueAddr[PortIndex][Prio]+TX_Q_CTRL,
2313     		TX_Q_CTRL_CLR_I_EOF);
2314     } /* ClearTxIrq */
2315     
2316     
2317     /*****************************************************************************
2318      *
2319      * 	ClearRxRing - remove all buffers from the receive ring
2320      *
2321      * Description:
2322      *	This function removes all receive buffers from the ring.
2323      *	The receive BMU must be stopped before calling this function.
2324      *
2325      * Returns: N/A
2326      */
2327     static void ClearRxRing(
2328     SK_AC	*pAC,		/* pointer to adapter context */
2329     RX_PORT	*pRxPort)	/* pointer to rx port struct */
2330     {
2331     RXD		*pRxd;	/* pointer to the current descriptor */
2332     unsigned long	Flags;
2333      SK_U64		PhysAddr;
2334     
2335     	if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2336     		return;
2337     	}
2338     	spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2339     	pRxd = pRxPort->pRxdRingHead;
2340     	do {
2341     		if (pRxd->pMBuf != NULL) {
2342     			PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2343     			PhysAddr |= (SK_U64) pRxd->VDataLow;
2344     			pci_unmap_single(&pAC->PciDev,
2345     					 PhysAddr,
2346     					 pAC->RxBufSize - 2,
2347     					 PCI_DMA_FROMDEVICE);
2348     			DEV_KFREE_SKB(pRxd->pMBuf);
2349     			pRxd->pMBuf = NULL;
2350     		}
2351     		pRxd->RBControl &= RX_CTRL_OWN_BMU;
2352     		pRxd = pRxd->pNextRxd;
2353     		pRxPort->RxdRingFree++;
2354     	} while (pRxd != pRxPort->pRxdRingTail);
2355     	pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2356     	spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2357     } /* ClearRxRing */
2358     
2359     
2360     /*****************************************************************************
2361      *
2362      *	ClearTxRing - remove all buffers from the transmit ring
2363      *
2364      * Description:
2365      *	This function removes all transmit buffers from the ring.
2366      *	The transmit BMU must be stopped before calling this function
2367      *	and transmitting at the upper level must be disabled.
2368      *	The BMU own bit of all descriptors is cleared, the rest is
2369      *	done by calling FreeTxDescriptors.
2370      *
2371      * Returns: N/A
2372      */
2373     static void ClearTxRing(
2374     SK_AC	*pAC,		/* pointer to adapter context */
2375     TX_PORT	*pTxPort)	/* pointer to tx prt struct */
2376     {
2377     TXD		*pTxd;		/* pointer to the current descriptor */
2378     int		i;
2379     unsigned long	Flags;
2380     
2381     	spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2382     	pTxd = pTxPort->pTxdRingHead;
2383     	for (i=0; i<pAC->TxDescrPerRing; i++) {
2384     		pTxd->TBControl &= ~TX_CTRL_OWN_BMU;
2385     		pTxd = pTxd->pNextTxd;
2386     	}
2387     	FreeTxDescriptors(pAC, pTxPort);
2388     	spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2389     } /* ClearTxRing */
2390     
2391     
2392     /*****************************************************************************
2393      *
2394      * 	SetQueueSizes - configure the sizes of rx and tx queues
2395      *
2396      * Description:
2397      *	This function assigns the sizes for active and passive port
2398      *	to the appropriate HWinit structure variables.
2399      *	The passive port(s) get standard values, all remaining RAM
2400      *	is given to the active port.
2401      *	The queue sizes are in kbyte and must be multiple of 8.
2402      *	The limits for the number of buffers filled into the rx rings
2403      *	is also set in this routine.
2404      *
2405      * Returns:
2406      *	none
2407      */
2408     static void SetQueueSizes(
2409     SK_AC	*pAC)	/* pointer to the adapter context */
2410     {
2411     int	StandbyRam;	/* adapter RAM used for a standby port */
2412     int	RemainingRam;	/* adapter RAM available for the active port */
2413     int	RxRam;		/* RAM used for the active port receive queue */
2414     int	i;		/* loop counter */
2415     
2416     if (pAC->RlmtNets == 1) {
2417     	StandbyRam = SK_RLMT_STANDBY_QRXSIZE + SK_RLMT_STANDBY_QXASIZE +
2418     		SK_RLMT_STANDBY_QXSSIZE;
2419     	RemainingRam = pAC->GIni.GIRamSize - 
2420     		(pAC->GIni.GIMacsFound-1) * StandbyRam;
2421     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2422     		pAC->GIni.GP[i].PRxQSize = SK_RLMT_STANDBY_QRXSIZE;
2423     		pAC->GIni.GP[i].PXSQSize = SK_RLMT_STANDBY_QXSSIZE;
2424     		pAC->GIni.GP[i].PXAQSize = SK_RLMT_STANDBY_QXASIZE;
2425     	}
2426     	RxRam = (RemainingRam * 8 / 10) & ~7;
2427     	pAC->GIni.GP[pAC->ActivePort].PRxQSize = RxRam;
2428     	pAC->GIni.GP[pAC->ActivePort].PXSQSize = 0;
2429     	pAC->GIni.GP[pAC->ActivePort].PXAQSize =
2430     		(RemainingRam - RxRam) & ~7;
2431     	pAC->RxQueueSize = RxRam;
2432     	pAC->TxSQueueSize = 0;
2433     	pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
2434     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2435     		("queue sizes settings - rx:%d  txA:%d txS:%d\n",
2436     		pAC->RxQueueSize,pAC->TxAQueueSize, pAC->TxSQueueSize));
2437     } else {
2438     	RemainingRam = pAC->GIni.GIRamSize/pAC->GIni.GIMacsFound;
2439     	RxRam = (RemainingRam * 8 / 10) & ~7;
2440     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2441     		pAC->GIni.GP[i].PRxQSize = RxRam;
2442     		pAC->GIni.GP[i].PXSQSize = 0;
2443     		pAC->GIni.GP[i].PXAQSize = (RemainingRam - RxRam) & ~7;
2444     	}
2445     	
2446     	pAC->RxQueueSize = RxRam;
2447     	pAC->TxSQueueSize = 0;
2448     	pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
2449     }
2450     	for (i=0; i<SK_MAX_MACS; i++) {
2451     		pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing;
2452     	}
2453     
2454     	if (pAC->RlmtNets == 2) {
2455     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2456     			pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
2457     		}
2458     	} else {
2459     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2460     			pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
2461     		}
2462     		/*
2463     		 * Do not set the Limit to 0, because this could cause
2464     		 * wrap around with ReQueue'ed buffers (a buffer could
2465     		 * be requeued in the same position, made accessable to
2466     		 * the hardware, and the hardware could change its
2467     		 * contents!
2468     		 */
2469     		pAC->RxPort[pAC->ActivePort].RxFillLimit = 1;
2470     	}
2471     
2472     #ifdef DEBUG
2473     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2474     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
2475     			("i: %d,  RxQSize: %d,  PXSQsize: %d, PXAQSize: %d\n",
2476     			i,
2477     			pAC->GIni.GP[i].PRxQSize,
2478     			pAC->GIni.GP[i].PXSQSize,
2479     			pAC->GIni.GP[i].PXAQSize));
2480     	}
2481     #endif
2482     } /* SetQueueSizes */
2483     
2484     
2485     /*****************************************************************************
2486      *
2487      * 	SkGeSetMacAddr - Set the hardware MAC address
2488      *
2489      * Description:
2490      *	This function sets the MAC address used by the adapter.
2491      *
2492      * Returns:
2493      *	0, if everything is ok
2494      *	!=0, on error
2495      */
2496     static int SkGeSetMacAddr(struct net_device *dev, void *p)
2497     {
2498     
2499     DEV_NET *pNet = (DEV_NET*) dev->priv;
2500     SK_AC	*pAC = pNet->pAC;
2501     
2502     struct sockaddr	*addr = p;
2503     unsigned long	Flags;
2504     
2505     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2506     		("SkGeSetMacAddr starts now...\n"));
2507     	if(netif_running(dev)) {
2508     		return -EBUSY;
2509     	}
2510     	memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2511     	
2512     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2513     
2514     	if (pAC->RlmtNets == 2)
2515     		SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2516     			(SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2517     	else
2518     		SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2519     			(SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2520     
2521     	
2522     	
2523     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2524     	return 0;
2525     } /* SkGeSetMacAddr */
2526     
2527     
2528     /*****************************************************************************
2529      *
2530      * 	SkGeSetRxMode - set receive mode
2531      *
2532      * Description:
2533      *	This function sets the receive mode of an adapter. The adapter
2534      *	supports promiscuous mode, allmulticast mode and a number of
2535      *	multicast addresses. If more multicast addresses the available
2536      *	are selected, a hash function in the hardware is used.
2537      *
2538      * Returns:
2539      *	0, if everything is ok
2540      *	!=0, on error
2541      */
2542     static void SkGeSetRxMode(struct net_device *dev)
2543     {
2544     
2545     DEV_NET		*pNet;
2546     SK_AC		*pAC;
2547     
2548     struct dev_mc_list	*pMcList;
2549     int			i;
2550     int			PortIdx;
2551     unsigned long		Flags;
2552     
2553     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2554     		("SkGeSetRxMode starts now... "));
2555     
2556     	pNet = (DEV_NET*) dev->priv;
2557     	pAC = pNet->pAC;
2558     	if (pAC->RlmtNets == 1)
2559     		PortIdx = pAC->ActivePort;
2560     	else
2561     		PortIdx = pNet->NetNr;
2562     
2563     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2564     	if (dev->flags & IFF_PROMISC) {
2565     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2566     			("PROMISCUOUS mode\n"));
2567     		SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2568     			SK_PROM_MODE_LLC);
2569     	} else if (dev->flags & IFF_ALLMULTI) {
2570     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2571     			("ALLMULTI mode\n"));
2572     		SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2573     			SK_PROM_MODE_ALL_MC);
2574     	} else {
2575     		SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2576     			SK_PROM_MODE_NONE);
2577     		SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2578     
2579     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2580     			("Number of MC entries: %d ", dev->mc_count));
2581     		
2582     		pMcList = dev->mc_list;
2583     		for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2584     			SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2585     				(SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2586     			SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2587     				("%02x:%02x:%02x:%02x:%02x:%02x\n",
2588     				pMcList->dmi_addr[0],
2589     				pMcList->dmi_addr[1],
2590     				pMcList->dmi_addr[2],
2591     				pMcList->dmi_addr[3],
2592     				pMcList->dmi_addr[4],
2593     				pMcList->dmi_addr[5]));
2594     		}
2595     		SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2596     	
2597     	}
2598     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2599     	
2600     	return;
2601     } /* SkGeSetRxMode */
2602     
2603     
2604     /*****************************************************************************
2605      *
2606      * 	SkGeChangeMtu - set the MTU to another value
2607      *
2608      * Description:
2609      *	This function sets is called whenever the MTU size is changed
2610      *	(ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2611      *	ethernet MTU size, long frame support is activated.
2612      *
2613      * Returns:
2614      *	0, if everything is ok
2615      *	!=0, on error
2616      */
2617     static int SkGeChangeMtu(struct net_device *dev, int NewMtu)
2618     {
2619     DEV_NET		*pNet;
2620     DEV_NET		*pOtherNet;
2621     SK_AC		*pAC;
2622     unsigned long	Flags;
2623     int		i;
2624     SK_EVPARA 	EvPara;
2625     
2626     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2627     		("SkGeChangeMtu starts now...\n"));
2628     
2629     	pNet = (DEV_NET*) dev->priv;
2630     	pAC = pNet->pAC;
2631     
2632     	if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2633     		return -EINVAL;
2634     	}
2635     
2636     	pNet->Mtu = NewMtu;
2637     	pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
2638     	if ((pOtherNet->Mtu > 1500) && (NewMtu <= 1500) && (pOtherNet->Up==1)) {
2639     		return(0);
2640     	}
2641     
2642     	EvPara.Para32[0] = pNet->NetNr;
2643     	EvPara.Para32[1] = -1;
2644     
2645     	pAC->RxBufSize = NewMtu + 32;
2646     	dev->mtu = NewMtu;
2647     
2648     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2649     		("New MTU: %d\n", NewMtu));
2650     
2651     	if(pAC->BoardLevel != 2) {
2652     		return 0;
2653     	}
2654     
2655     	/* prevent reconfiguration while changing the MTU */
2656     
2657     	/* disable interrupts */
2658     	SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2659     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2660     
2661     	/* Found more than one port */
2662     	if ((pAC->GIni.GIMacsFound == 2 ) && 
2663     		(pAC->RlmtNets == 2)) {
2664     			/* Stop both ports */
2665     			EvPara.Para32[0] = 0;
2666     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2667     			EvPara.Para32[0] = 1;
2668     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2669     	} else {
2670     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2671     	}
2672     
2673     	SkEventDispatcher(pAC, pAC->IoBase);
2674     
2675     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2676     		spin_lock_irqsave(
2677     			&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
2678     		netif_stop_queue(pAC->dev[i]);
2679     	}
2680     
2681     	/* 
2682     	 * adjust number of rx buffers allocated
2683     	 */
2684     	if (NewMtu > 1500) {
2685     		/* use less rx buffers */
2686     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2687     			/* Found more than one port */
2688     			if ((pAC->GIni.GIMacsFound == 2 ) && 
2689     				(pAC->RlmtNets == 2)) {
2690     					pAC->RxPort[i].RxFillLimit = 
2691     						pAC->RxDescrPerRing - 100;
2692     			} else {
2693     				if (i == pAC->ActivePort)
2694     					pAC->RxPort[i].RxFillLimit =
2695     						pAC->RxDescrPerRing - 100;
2696     				else
2697     					pAC->RxPort[i].RxFillLimit =
2698     						pAC->RxDescrPerRing - 10;
2699     			}
2700     		}
2701     	}
2702     	else {
2703     		/* use normal anoumt of rx buffers */
2704     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2705     			/* Found more than one port */
2706     			if ((pAC->GIni.GIMacsFound == 2 ) && 
2707     				(pAC->RlmtNets == 2)) {
2708     					pAC->RxPort[i].RxFillLimit = 1;
2709     			} else {
2710     				if (i == pAC->ActivePort)
2711     					pAC->RxPort[i].RxFillLimit = 1;
2712     				else
2713     					pAC->RxPort[i].RxFillLimit =
2714     						pAC->RxDescrPerRing - 100;
2715     			}
2716     		}
2717     	}
2718     	 
2719     	SkGeDeInit(pAC, pAC->IoBase); 
2720     
2721     	/* 
2722     	 * enable/disable hardware support for long frames
2723     	 */
2724     	if (NewMtu > 1500) {
2725     //		pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2726     		pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2727     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2728     			pAC->GIni.GP[i].PRxCmd = 
2729     				XM_RX_STRIP_FCS | XM_RX_LENERR_OK;
2730     		}
2731     	}
2732     	else {
2733     		if ((pAC->GIni.GIMacsFound == 2 ) && 
2734     			(pAC->RlmtNets == 2)) {
2735     			pAC->GIni.GIPortUsage = SK_MUL_LINK;
2736     		} else {
2737     			pAC->GIni.GIPortUsage = SK_RED_LINK;
2738     		}
2739     		for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2740     			pAC->GIni.GP[i].PRxCmd = XM_RX_STRIP_FCS;
2741     		}
2742     	}
2743     
2744     	SkGeInit(   pAC, pAC->IoBase, 1);
2745     	SkI2cInit(  pAC, pAC->IoBase, 1);
2746     	SkEventInit(pAC, pAC->IoBase, 1);
2747     	SkPnmiInit( pAC, pAC->IoBase, 1);
2748     	SkAddrInit( pAC, pAC->IoBase, 1);
2749     	SkRlmtInit( pAC, pAC->IoBase, 1);
2750     	SkTimerInit(pAC, pAC->IoBase, 1);
2751     	
2752     	SkGeInit(   pAC, pAC->IoBase, 2);
2753     	SkI2cInit(  pAC, pAC->IoBase, 2);
2754     	SkEventInit(pAC, pAC->IoBase, 2);
2755     	SkPnmiInit( pAC, pAC->IoBase, 2);
2756     	SkAddrInit( pAC, pAC->IoBase, 2);
2757     	SkRlmtInit( pAC, pAC->IoBase, 2);
2758     	SkTimerInit(pAC, pAC->IoBase, 2);
2759     
2760     	/* 
2761     	 * clear and reinit the rx rings here
2762     	 */
2763     	for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2764     		ReceiveIrq(pAC, &pAC->RxPort[i]);
2765     		ClearRxRing(pAC, &pAC->RxPort[i]);
2766     		FillRxRing(pAC, &pAC->RxPort[i]);
2767     
2768     		/* Enable transmit descriptor polling. */
2769     		SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2770     		FillRxRing(pAC, &pAC->RxPort[i]);
2771     	};
2772     
2773     	SkGeYellowLED(pAC, pAC->IoBase, 1);
2774     
2775     #ifdef USE_INT_MOD
2776     	{
2777     		unsigned long ModBase;
2778     		ModBase = 53125000 / INTS_PER_SEC;
2779     		SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
2780     		SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
2781     		SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
2782     	}
2783     #endif
2784     
2785     	netif_start_queue(pAC->dev[pNet->PortNr]);
2786     	for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2787     		spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2788     	}
2789     
2790     	/* enable Interrupts */
2791     	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
2792     	SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2793     
2794     	SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2795     	SkEventDispatcher(pAC, pAC->IoBase);
2796     
2797     	/* Found more than one port */
2798     	if ((pAC->GIni.GIMacsFound == 2 ) && 
2799     		(pAC->RlmtNets == 2)) {
2800     			/* Start both ports */
2801     			EvPara.Para32[0] = pAC->RlmtNets;
2802     			EvPara.Para32[1] = -1;
2803     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
2804     				EvPara);
2805     			
2806     			
2807     			EvPara.Para32[1] = -1;
2808     			EvPara.Para32[0] = pNet->PortNr;
2809     			SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2810     			
2811     			if (pOtherNet->Up) {
2812     				EvPara.Para32[0] = pOtherNet->PortNr;
2813     				SkEventQueue(pAC, SKGE_RLMT, 
2814     					SK_RLMT_START, EvPara);
2815     			}
2816     	} else {
2817     		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2818     	}
2819     
2820     	SkEventDispatcher(pAC, pAC->IoBase);
2821     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2822     	
2823     	return 0;
2824     } /* SkGeChangeMtu */
2825     
2826     
2827     /*****************************************************************************
2828      *
2829      * 	SkGeStats - return ethernet device statistics
2830      *
2831      * Description:
2832      *	This function return statistic data about the ethernet device
2833      *	to the operating system.
2834      *
2835      * Returns:
2836      *	pointer to the statistic structure.
2837      */
2838     static struct net_device_stats *SkGeStats(struct net_device *dev)
2839     {
2840     DEV_NET *pNet = (DEV_NET*) dev->priv;
2841     SK_AC	*pAC = pNet->pAC;
2842     SK_PNMI_STRUCT_DATA *pPnmiStruct;       /* structure for all Pnmi-Data */
2843     SK_PNMI_STAT    *pPnmiStat;             /* pointer to virtual XMAC stat. data */SK_PNMI_CONF    *pPnmiConf;             /* pointer to virtual link config. */
2844     unsigned int    Size;                   /* size of pnmi struct */
2845     unsigned long	Flags;			/* for spin lock */
2846     
2847     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2848     		("SkGeStats starts now...\n"));
2849     	pPnmiStruct = &pAC->PnmiStruct;
2850             memset(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2851             spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2852             Size = SK_PNMI_STRUCT_SIZE;
2853     		SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2854             spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2855             pPnmiStat = &pPnmiStruct->Stat[0];
2856             pPnmiConf = &pPnmiStruct->Conf[0];
2857     
2858     	pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2859     	pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2860     	pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2861     	pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2862     	pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2863     	pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2864     	pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2865     	pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2866     	pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2867     	pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2868     
2869     	/* detailed rx_errors: */
2870     	pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2871     	pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2872     	pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2873     	pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2874     	pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2875     	pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2876     
2877     	/* detailed tx_errors */
2878     	pAC->stats.tx_aborted_errors = (SK_U32) 0;
2879     	pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2880     	pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2881     	pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2882     	pAC->stats.tx_window_errors = (SK_U32) 0;
2883     
2884     	return(&pAC->stats);
2885     } /* SkGeStats */
2886     
2887     
2888     /*****************************************************************************
2889      *
2890      * 	SkGeIoctl - IO-control function
2891      *
2892      * Description:
2893      *	This function is called if an ioctl is issued on the device.
2894      *	There are three subfunction for reading, writing and test-writing
2895      *	the private MIB data structure (usefull for SysKonnect-internal tools).
2896      *
2897      * Returns:
2898      *	0, if everything is ok
2899      *	!=0, on error
2900      */
2901     static int SkGeIoctl(struct net_device *dev, struct ifreq *rq, int cmd)
2902     {
2903     DEV_NET		*pNet;
2904     SK_AC		*pAC;
2905     
2906     SK_GE_IOCTL	Ioctl;
2907     unsigned int	Err = 0;
2908     int		Size;
2909     
2910     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2911     		("SkGeIoctl starts now...\n"));
2912     
2913     	pNet = (DEV_NET*) dev->priv;
2914     	pAC = pNet->pAC;
2915     	
2916     	if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2917     		return -EFAULT;
2918     	}
2919     
2920     	switch(cmd) {
2921     	case SK_IOCTL_SETMIB:
2922     	case SK_IOCTL_PRESETMIB:
2923     		if (!capable(CAP_NET_ADMIN)) return -EPERM;
2924      	case SK_IOCTL_GETMIB:
2925     		if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData, 
2926     			Ioctl.Len<sizeof(pAC->PnmiStruct)?
2927     			Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2928     			return -EFAULT;
2929     		}
2930     		Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2931     		if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2932     			Ioctl.Len<Size? Ioctl.Len : Size)) {
2933     			return -EFAULT;
2934     		}
2935     		Ioctl.Len = Size;
2936     		if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2937     			return -EFAULT;
2938     		}
2939     		break;
2940     	default:
2941     		Err = -EOPNOTSUPP;
2942     	}
2943     	return(Err);
2944     } /* SkGeIoctl */
2945     
2946     
2947     /*****************************************************************************
2948      *
2949      * 	SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2950      *
2951      * Description:
2952      *	This function reads/writes the MIB data using PNMI (Private Network
2953      *	Management Interface).
2954      *	The destination for the data must be provided with the
2955      *	ioctl call and is given to the driver in the form of
2956      *	a user space address.
2957      *	Copying from the user-provided data area into kernel messages
2958      *	and back is done by copy_from_user and copy_to_user calls in
2959      *	SkGeIoctl.
2960      *
2961      * Returns:
2962      *	returned size from PNMI call
2963      */
2964     static int SkGeIocMib(
2965     DEV_NET		*pNet,	/* pointer to the adapter context */
2966     unsigned int	Size,	/* length of ioctl data */
2967     int		mode)	/* flag for set/preset */
2968     {
2969     unsigned long	Flags;	/* for spin lock */
2970     SK_AC		*pAC;
2971     
2972     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2973     		("SkGeIocMib starts now...\n"));
2974     	pAC = pNet->pAC;
2975     	/* access MIB */
2976     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2977     	switch(mode) {
2978     	case SK_IOCTL_GETMIB:
2979     		SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
2980     			pNet->NetNr);
2981     		break;
2982     	case SK_IOCTL_PRESETMIB:
2983     		SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
2984     			pNet->NetNr);
2985     		break;
2986     	case SK_IOCTL_SETMIB:
2987     		SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
2988     			pNet->NetNr);
2989     		break;
2990     	default:
2991     		break;
2992     	}
2993     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2994     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2995     		("MIB data access succeeded\n"));
2996     	return (Size);
2997     } /* SkGeIocMib */
2998     
2999     
3000     /*****************************************************************************
3001      *
3002      * 	GetConfiguration - read configuration information
3003      *
3004      * Description:
3005      *	This function reads per-adapter configuration information from
3006      *	the options provided on the command line.
3007      *
3008      * Returns:
3009      *	none
3010      */
3011     static void GetConfiguration(
3012     SK_AC	*pAC)	/* pointer to the adapter context structure */
3013     {
3014     SK_I32	Port;		/* preferred port */
3015     int	AutoNeg;	/* auto negotiation off (0) or on (1) */
3016     int	DuplexCap;	/* duplex capabilities (0=both, 1=full, 2=half */
3017     int	MSMode;		/* master / slave mode selection */
3018     SK_BOOL	AutoSet;
3019     SK_BOOL DupSet;
3020     /*
3021      *	The two parameters AutoNeg. and DuplexCap. map to one configuration
3022      *	parameter. The mapping is described by this table:
3023      *	DuplexCap ->	|	both	|	full	|	half	|
3024      *	AutoNeg		|		|		|		|
3025      *	-----------------------------------------------------------------
3026      *	Off		|    illegal	|	Full	|	Half	|
3027      *	-----------------------------------------------------------------
3028      *	On		|   AutoBoth	|   AutoFull	|   AutoHalf	|
3029      *	-----------------------------------------------------------------
3030      *	Sense		|   AutoSense	|   AutoSense	|   AutoSense	|
3031      */
3032     int	Capabilities[3][3] = 
3033     		{ {		  -1, SK_LMODE_FULL,     SK_LMODE_HALF}, 
3034     		  {SK_LMODE_AUTOBOTH, SK_LMODE_AUTOFULL, SK_LMODE_AUTOHALF},
3035     		  {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3036     #define DC_BOTH	0
3037     #define DC_FULL 1
3038     #define DC_HALF 2
3039     #define AN_OFF	0
3040     #define AN_ON	1
3041     #define AN_SENS	2
3042     
3043     	/* settings for port A */
3044     	AutoNeg = AN_SENS; /* default: do auto Sense */
3045     	AutoSet = SK_FALSE;
3046     	if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3047     		AutoNeg_A[pAC->Index] != NULL) {
3048     		AutoSet = SK_TRUE;
3049     		if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3050     			AutoSet = SK_FALSE;
3051     		}
3052     		else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3053     			AutoNeg = AN_ON;
3054     		}
3055     		else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3056     			AutoNeg = AN_OFF;
3057     		}
3058     		else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3059     			AutoNeg = AN_SENS;
3060     		}
3061     		else printk("%s: Illegal value for AutoNeg_A\n",
3062     			pAC->dev[0]->name);
3063     	}
3064     
3065     	DuplexCap = DC_BOTH;
3066     	DupSet = SK_FALSE;
3067     	if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3068     		DupCap_A[pAC->Index] != NULL) {
3069     		DupSet = SK_TRUE;
3070     		if (strcmp(DupCap_A[pAC->Index],"")==0) {
3071     			DupSet = SK_FALSE;
3072     		}
3073     		else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3074     			DuplexCap = DC_BOTH;
3075     		}
3076     		else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3077     			DuplexCap = DC_FULL;
3078     		}
3079     		else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3080     			DuplexCap = DC_HALF;
3081     		}
3082     		else printk("%s: Illegal value for DupCap_A\n",
3083     			pAC->dev[0]->name);
3084     	}
3085     	
3086     	/* check for illegal combinations */
3087     	if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3088     		printk("%s, Port A: DuplexCapabilities"
3089     			" ignored using Sense mode\n", pAC->dev[0]->name);
3090     	}
3091     	if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3092     		printk("%s, Port A: Illegal combination"
3093     			" of values AutoNeg. and DuplexCap.\n    Using "
3094     			"Full Duplex\n", pAC->dev[0]->name);
3095     
3096     		DuplexCap = DC_FULL;
3097     	}
3098     	if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3099     		DuplexCap = DC_FULL;
3100     	}
3101     	
3102     	if (!AutoSet && DupSet) {
3103     		printk("%s, Port A: Duplex setting not"
3104     			" possible in\n    default AutoNegotiation mode"
3105     			" (Sense).\n    Using AutoNegotiation On\n",
3106     			pAC->dev[0]->name);
3107     		AutoNeg = AN_ON;
3108     	}
3109     	
3110     	/* set the desired mode */
3111     	pAC->GIni.GP[0].PLinkModeConf =
3112     		Capabilities[AutoNeg][DuplexCap];
3113     	
3114     	pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3115     	if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3116     		FlowCtrl_A[pAC->Index] != NULL) {
3117     		if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3118     		}
3119     		else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3120     			pAC->GIni.GP[0].PFlowCtrlMode =
3121     				SK_FLOW_MODE_SYM_OR_REM;
3122     		}
3123     		else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3124     			pAC->GIni.GP[0].PFlowCtrlMode =
3125     				SK_FLOW_MODE_SYMMETRIC;
3126     		}
3127     		else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3128     			pAC->GIni.GP[0].PFlowCtrlMode =
3129     				SK_FLOW_MODE_LOC_SEND;
3130     		}
3131     		else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3132     			pAC->GIni.GP[0].PFlowCtrlMode =
3133     				SK_FLOW_MODE_NONE;
3134     		}
3135     		else printk("Illegal value for FlowCtrl_A\n");
3136     	}
3137     	if (AutoNeg==AN_OFF && pAC->GIni.GP[0].PFlowCtrlMode!=
3138     		SK_FLOW_MODE_NONE) {
3139     		printk("%s, Port A: FlowControl"
3140     			" impossible without AutoNegotiation,"
3141     			" disabled\n", pAC->dev[0]->name);
3142     		pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_NONE;
3143     	}
3144     
3145     	MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
3146     	if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3147     		Role_A[pAC->Index] != NULL) {
3148     		if (strcmp(Role_A[pAC->Index],"")==0) {
3149     		}
3150     		else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3151     			MSMode = SK_MS_MODE_AUTO;
3152     		}
3153     		else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3154     			MSMode = SK_MS_MODE_MASTER;
3155     		}
3156     		else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3157     			MSMode = SK_MS_MODE_SLAVE;
3158     		}
3159     		else printk("%s: Illegal value for Role_A\n",
3160     			pAC->dev[0]->name);
3161     	}
3162     	pAC->GIni.GP[0].PMSMode = MSMode;
3163     	
3164     	
3165     	/* settings for port B */
3166     	AutoNeg = AN_SENS; /* default: do auto Sense */
3167     	AutoSet = SK_FALSE;
3168     	if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3169     		AutoNeg_B[pAC->Index] != NULL) {
3170     		AutoSet = SK_TRUE;
3171     		if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3172     			AutoSet = SK_FALSE;
3173     		}
3174     		else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3175     			AutoNeg = AN_ON;
3176     		}
3177     		else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3178     			AutoNeg = AN_OFF;
3179     		}
3180     		else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3181     			AutoNeg = AN_SENS;
3182     		}
3183     		else printk("Illegal value for AutoNeg_B\n");
3184     	}
3185     
3186     	DuplexCap = DC_BOTH;
3187     	DupSet = SK_FALSE;
3188     	if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3189     		DupCap_B[pAC->Index] != NULL) {
3190     		DupSet = SK_TRUE;
3191     		if (strcmp(DupCap_B[pAC->Index],"")==0) {
3192     			DupSet = SK_FALSE;
3193     		}
3194     		else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3195     			DuplexCap = DC_BOTH;
3196     		}
3197     		else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3198     			DuplexCap = DC_FULL;
3199     		}
3200     		else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3201     			DuplexCap = DC_HALF;
3202     		}
3203     		else printk("Illegal value for DupCap_B\n");
3204     	}
3205     	
3206     	/* check for illegal combinations */
3207     	if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3208     		printk("%s, Port B: DuplexCapabilities"
3209     			" ignored using Sense mode\n", pAC->dev[1]->name);
3210     	}
3211     	if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3212     		printk("%s, Port B: Illegal combination"
3213     			" of values AutoNeg. and DuplexCap.\n    Using "
3214     			"Full Duplex\n", pAC->dev[1]->name);
3215     
3216     		DuplexCap = DC_FULL;
3217     	}
3218     	if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3219     		DuplexCap = DC_FULL;
3220     	}
3221     	
3222     	if (!AutoSet && DupSet) {
3223     		printk("%s, Port B: Duplex setting not"
3224     			" possible in\n    default AutoNegotiation mode"
3225     			" (Sense).\n    Using AutoNegotiation On\n",
3226     			pAC->dev[1]->name);
3227     		AutoNeg = AN_ON;
3228     	}
3229     
3230     	/* set the desired mode */
3231     	pAC->GIni.GP[1].PLinkModeConf =
3232     		Capabilities[AutoNeg][DuplexCap];
3233     
3234     	pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3235     	if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3236     		FlowCtrl_B[pAC->Index] != NULL) {
3237     		if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3238     		}
3239     		else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3240     			pAC->GIni.GP[1].PFlowCtrlMode =
3241     				SK_FLOW_MODE_SYM_OR_REM;
3242     		}
3243     		else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3244     			pAC->GIni.GP[1].PFlowCtrlMode =
3245     				SK_FLOW_MODE_SYMMETRIC;
3246     		}
3247     		else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3248     			pAC->GIni.GP[1].PFlowCtrlMode =
3249     				SK_FLOW_MODE_LOC_SEND;
3250     		}
3251     		else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3252     			pAC->GIni.GP[1].PFlowCtrlMode =
3253     				SK_FLOW_MODE_NONE;
3254     		}
3255     		else printk("Illegal value for FlowCtrl_B\n");
3256     	}
3257     	if (AutoNeg==AN_OFF && pAC->GIni.GP[1].PFlowCtrlMode!=
3258     		SK_FLOW_MODE_NONE) {
3259     		printk("%s, Port B: FlowControl"
3260     			" impossible without AutoNegotiation,"
3261     			" disabled\n", pAC->dev[1]->name);
3262     		pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_NONE;
3263     	}
3264     
3265     	MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
3266     	if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3267     		Role_B[pAC->Index] != NULL) {
3268     		if (strcmp(Role_B[pAC->Index],"")==0) {
3269     		}
3270     		else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3271     			MSMode = SK_MS_MODE_AUTO;
3272     		}
3273     		else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3274     			MSMode = SK_MS_MODE_MASTER;
3275     		}
3276     		else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3277     			MSMode = SK_MS_MODE_SLAVE;
3278     		}
3279     		else printk("%s: Illegal value for Role_B\n",
3280     			pAC->dev[1]->name);
3281     	}
3282     	pAC->GIni.GP[1].PMSMode = MSMode;
3283     	
3284     	
3285     	/* settings for both ports */
3286     	pAC->ActivePort = 0;
3287     	if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3288     		PrefPort[pAC->Index] != NULL) {
3289     		if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3290     			pAC->ActivePort = 0;
3291     			pAC->Rlmt.Net[0].Preference = -1; /* auto */
3292     			pAC->Rlmt.Net[0].PrefPort = 0;
3293     		}
3294     		else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3295     			/*
3296     			 * do not set ActivePort here, thus a port
3297     			 * switch is issued after net up.
3298     			 */
3299     			Port = 0;
3300     			pAC->Rlmt.Net[0].Preference = Port;
3301     			pAC->Rlmt.Net[0].PrefPort = Port;
3302     		}
3303     		else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3304     			/*
3305     			 * do not set ActivePort here, thus a port
3306     			 * switch is issued after net up.
3307     			 */
3308     			Port = 1;
3309     			pAC->Rlmt.Net[0].Preference = Port;
3310     			pAC->Rlmt.Net[0].PrefPort = Port;
3311     		}
3312     		else printk("%s: Illegal value for PrefPort\n",
3313     			pAC->dev[0]->name);
3314     	}
3315     
3316     	pAC->RlmtNets = 1;
3317     	
3318     	if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3319     		RlmtMode[pAC->Index] != NULL) {
3320     		if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3321     			pAC->RlmtMode = 0;
3322     		}
3323     		else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3324     			pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3325     		}
3326     		else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3327     			pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3328     				SK_RLMT_CHECK_LOC_LINK;
3329     		}
3330     		else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3331     			pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3332     				SK_RLMT_CHECK_LOC_LINK | 
3333     				SK_RLMT_CHECK_SEG;
3334     		}
3335     		else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3336     			(pAC->GIni.GIMacsFound == 2)) {
3337     				pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3338     				pAC->RlmtNets = 2;
3339     		}
3340     		else {
3341     			printk("%s: Illegal value for"
3342     				" RlmtMode, using default\n", pAC->dev[0]->name);
3343     
3344     printk("MacFound = %d\nRlmtMode = %s", pAC->GIni.GIMacsFound, RlmtMode[pAC->Index]);
3345     	
3346     
3347     			pAC->RlmtMode = 0;
3348     		}
3349     	}
3350     	else {
3351     		pAC->RlmtMode = 0;
3352     	}
3353     } /* GetConfiguration */
3354     
3355     
3356     /*****************************************************************************
3357      *
3358      * 	ProductStr - return a adapter identification string from vpd
3359      *
3360      * Description:
3361      *	This function reads the product name string from the vpd area
3362      *	and puts it the field pAC->DeviceString.
3363      *
3364      * Returns: N/A
3365      */
3366     static void ProductStr(
3367     SK_AC	*pAC		/* pointer to adapter context */
3368     )
3369     {
3370     int	StrLen = 80;		/* length of the string, defined in SK_AC */
3371     char	Keyword[] = VPD_NAME;	/* vpd productname identifier */
3372     int	ReturnCode;		/* return code from vpd_read */
3373     unsigned long Flags;
3374     
3375     	spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3376     	ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3377     		&StrLen);
3378     	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3379     	if (ReturnCode != 0) {
3380     		/* there was an error reading the vpd data */
3381     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3382     			("Error reading VPD data: %d\n", ReturnCode));
3383     		pAC->DeviceStr[0] = '\0';
3384     	}
3385     } /* ProductStr */
3386     
3387     
3388     
3389     
3390     /****************************************************************************/
3391     /* functions for common modules *********************************************/
3392     /****************************************************************************/
3393     
3394     
3395     /*****************************************************************************
3396      *
3397      *	SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3398      *
3399      * Description:
3400      *	This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3401      *	is embedded into a socket buff data area.
3402      *
3403      * Context:
3404      *	runtime
3405      *
3406      * Returns:
3407      *	NULL or pointer to Mbuf.
3408      */
3409     SK_MBUF *SkDrvAllocRlmtMbuf(
3410     SK_AC		*pAC,		/* pointer to adapter context */
3411     SK_IOC		IoC,		/* the IO-context */
3412     unsigned	BufferSize)	/* size of the requested buffer */
3413     {
3414     SK_MBUF		*pRlmtMbuf;	/* pointer to a new rlmt-mbuf structure */
3415     struct sk_buff	*pMsgBlock;	/* pointer to a new message block */
3416     
3417     	pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3418     	if (pMsgBlock == NULL) {
3419     		return (NULL);
3420     	}
3421     	pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3422     	skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3423     	pRlmtMbuf->pNext = NULL;
3424     	pRlmtMbuf->pOs = pMsgBlock;
3425     	pRlmtMbuf->pData = pMsgBlock->data;	/* Data buffer. */
3426     	pRlmtMbuf->Size = BufferSize;		/* Data buffer size. */
3427     	pRlmtMbuf->Length = 0;		/* Length of packet (<= Size). */
3428     	return (pRlmtMbuf);
3429     
3430     } /* SkDrvAllocRlmtMbuf */
3431     
3432     
3433     /*****************************************************************************
3434      *
3435      *	SkDrvFreeRlmtMbuf - free an RLMT mbuf
3436      *
3437      * Description:
3438      *	This routine frees one or more RLMT mbuf(s).
3439      *
3440      * Context:
3441      *	runtime
3442      *
3443      * Returns:
3444      *	Nothing
3445      */
3446     void  SkDrvFreeRlmtMbuf(
3447     SK_AC		*pAC,		/* pointer to adapter context */  
3448     SK_IOC		IoC,		/* the IO-context */              
3449     SK_MBUF		*pMbuf)		/* size of the requested buffer */
3450     {
3451     SK_MBUF		*pFreeMbuf;
3452     SK_MBUF		*pNextMbuf;
3453     
3454     	pFreeMbuf = pMbuf;
3455     	do {
3456     		pNextMbuf = pFreeMbuf->pNext;
3457     		DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3458     		pFreeMbuf = pNextMbuf;
3459     	} while ( pFreeMbuf != NULL );
3460     } /* SkDrvFreeRlmtMbuf */
3461     
3462     
3463     /*****************************************************************************
3464      *
3465      *	SkOsGetTime - provide a time value
3466      *
3467      * Description:
3468      *	This routine provides a time value. The unit is 1/HZ (defined by Linux).
3469      *	It is not used for absolute time, but only for time differences.
3470      *
3471      *
3472      * Returns:
3473      *	Time value
3474      */
3475     SK_U64 SkOsGetTime(SK_AC *pAC)
3476     {
3477     	return jiffies;
3478     } /* SkOsGetTime */
3479     
3480     
3481     /*****************************************************************************
3482      *
3483      *	SkPciReadCfgDWord - read a 32 bit value from pci config space
3484      *
3485      * Description:
3486      *	This routine reads a 32 bit value from the pci configuration
3487      *	space.
3488      *
3489      * Returns:
3490      *	0 - indicate everything worked ok.
3491      *	!= 0 - error indication
3492      */
3493     int SkPciReadCfgDWord(
3494     SK_AC *pAC,		/* Adapter Control structure pointer */
3495     int PciAddr,		/* PCI register address */
3496     SK_U32 *pVal)		/* pointer to store the read value */
3497     {
3498     	pci_read_config_dword(&pAC->PciDev, PciAddr, pVal);
3499     	return(0);
3500     } /* SkPciReadCfgDWord */
3501     
3502     
3503     /*****************************************************************************
3504      *
3505      *	SkPciReadCfgWord - read a 16 bit value from pci config space
3506      *
3507      * Description:
3508      *	This routine reads a 16 bit value from the pci configuration
3509      *	space.
3510      *
3511      * Returns:
3512      *	0 - indicate everything worked ok.
3513      *	!= 0 - error indication
3514      */
3515     int SkPciReadCfgWord(
3516     SK_AC *pAC,	/* Adapter Control structure pointer */
3517     int PciAddr,		/* PCI register address */
3518     SK_U16 *pVal)		/* pointer to store the read value */
3519     {
3520     	pci_read_config_word(&pAC->PciDev, PciAddr, pVal);
3521     	return(0);
3522     } /* SkPciReadCfgWord */
3523     
3524     
3525     /*****************************************************************************
3526      *
3527      *	SkPciReadCfgByte - read a 8 bit value from pci config space
3528      *
3529      * Description:
3530      *	This routine reads a 8 bit value from the pci configuration
3531      *	space.
3532      *
3533      * Returns:
3534      *	0 - indicate everything worked ok.
3535      *	!= 0 - error indication
3536      */
3537     int SkPciReadCfgByte(
3538     SK_AC *pAC,	/* Adapter Control structure pointer */
3539     int PciAddr,		/* PCI register address */
3540     SK_U8 *pVal)		/* pointer to store the read value */
3541     {
3542     	pci_read_config_byte(&pAC->PciDev, PciAddr, pVal);
3543     	return(0);
3544     } /* SkPciReadCfgByte */
3545     
3546     
3547     /*****************************************************************************
3548      *
3549      *	SkPciWriteCfgDWord - write a 32 bit value to pci config space
3550      *
3551      * Description:
3552      *	This routine writes a 32 bit value to the pci configuration
3553      *	space.
3554      *
3555      * Returns:
3556      *	0 - indicate everything worked ok.
3557      *	!= 0 - error indication
3558      */
3559     int SkPciWriteCfgDWord(
3560     SK_AC *pAC,	/* Adapter Control structure pointer */
3561     int PciAddr,		/* PCI register address */
3562     SK_U32 Val)		/* pointer to store the read value */
3563     {
3564     	pci_write_config_dword(&pAC->PciDev, PciAddr, Val);
3565     	return(0);
3566     } /* SkPciWriteCfgDWord */
3567     
3568     
3569     /*****************************************************************************
3570      *
3571      *	SkPciWriteCfgWord - write a 16 bit value to pci config space
3572      *
3573      * Description:
3574      *	This routine writes a 16 bit value to the pci configuration
3575      *	space. The flag PciConfigUp indicates whether the config space
3576      *	is accesible or must be set up first.
3577      *
3578      * Returns:
3579      *	0 - indicate everything worked ok.
3580      *	!= 0 - error indication
3581      */
3582     int SkPciWriteCfgWord(
3583     SK_AC *pAC,	/* Adapter Control structure pointer */
3584     int PciAddr,		/* PCI register address */
3585     SK_U16 Val)		/* pointer to store the read value */
3586     {
3587     	pci_write_config_word(&pAC->PciDev, PciAddr, Val);
3588     	return(0);
3589     } /* SkPciWriteCfgWord */
3590     
3591     
3592     /*****************************************************************************
3593      *
3594      *	SkPciWriteCfgWord - write a 8 bit value to pci config space
3595      *
3596      * Description:
3597      *	This routine writes a 8 bit value to the pci configuration
3598      *	space. The flag PciConfigUp indicates whether the config space
3599      *	is accesible or must be set up first.
3600      *
3601      * Returns:
3602      *	0 - indicate everything worked ok.
3603      *	!= 0 - error indication
3604      */
3605     int SkPciWriteCfgByte(
3606     SK_AC *pAC,	/* Adapter Control structure pointer */
3607     int PciAddr,		/* PCI register address */
3608     SK_U8 Val)		/* pointer to store the read value */
3609     {
3610     	pci_write_config_byte(&pAC->PciDev, PciAddr, Val);
3611     	return(0);
3612     } /* SkPciWriteCfgByte */
3613     
3614     
3615     /*****************************************************************************
3616      *
3617      *	SkDrvEvent - handle driver events
3618      *
3619      * Description:
3620      *	This function handles events from all modules directed to the driver
3621      *
3622      * Context:
3623      *	Is called under protection of slow path lock.
3624      *
3625      * Returns:
3626      *	0 if everything ok
3627      *	< 0  on error
3628      *	
3629      */
3630     int SkDrvEvent(
3631     SK_AC *pAC,		/* pointer to adapter context */
3632     SK_IOC IoC,		/* io-context */
3633     SK_U32 Event,		/* event-id */
3634     SK_EVPARA Param)	/* event-parameter */
3635     {
3636     SK_MBUF		*pRlmtMbuf;	/* pointer to a rlmt-mbuf structure */
3637     struct sk_buff	*pMsg;		/* pointer to a message block */
3638     int		FromPort;	/* the port from which we switch away */
3639     int		ToPort;		/* the port we switch to */
3640     SK_EVPARA	NewPara;	/* parameter for further events */
3641     int		Stat;
3642     unsigned long	Flags;
3643     
3644     	switch (Event) {
3645     	case SK_DRV_ADAP_FAIL:
3646     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3647     			("ADAPTER FAIL EVENT\n"));
3648     		printk("%s: Adapter failed.\n", pAC->dev[0]->name);
3649     		/* disable interrupts */
3650     		SK_OUT32(pAC->IoBase, B0_IMSK, 0);
3651     		/* cgoos */
3652     		break;
3653     	case SK_DRV_PORT_FAIL:
3654     		FromPort = Param.Para32[0];
3655     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3656     			("PORT FAIL EVENT, Port: %d\n", FromPort));
3657     		if (FromPort == 0) {
3658     			printk("%s: Port A failed.\n", pAC->dev[0]->name);
3659     		} else {
3660     			printk("%s: Port B failed.\n", pAC->dev[1]->name);
3661     		}
3662     		/* cgoos */
3663     		break;
3664     	case SK_DRV_PORT_RESET:	 /* SK_U32 PortIdx */
3665     		/* action list 4 */
3666     		FromPort = Param.Para32[0];
3667     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3668     			("PORT RESET EVENT, Port: %d ", FromPort));
3669     		NewPara.Para64 = FromPort;
3670     		SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3671     		spin_lock_irqsave(
3672     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3673     			Flags);
3674     		SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
3675     		spin_unlock_irqrestore(
3676     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3677     			Flags);
3678     		
3679     		/* clear rx ring from received frames */
3680     		ReceiveIrq(pAC, &pAC->RxPort[FromPort]);
3681     		
3682     		ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
3683     		spin_lock_irqsave(
3684     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3685     			Flags);
3686     		SkGeInitPort(pAC, IoC, FromPort);
3687     		SkAddrMcUpdate(pAC,IoC, FromPort);
3688     		PortReInitBmu(pAC, FromPort);
3689     		SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
3690     		ClearAndStartRx(pAC, FromPort);
3691     		spin_unlock_irqrestore(
3692     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3693     			Flags);
3694     		break;
3695     	case SK_DRV_NET_UP:	 /* SK_U32 PortIdx */
3696     		/* action list 5 */
3697     		FromPort = Param.Para32[0];
3698     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3699     			("NET UP EVENT, Port: %d ", Param.Para32[0]));
3700     		printk("%s: network connection up using"
3701     			" port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
3702     		printk("    speed:           1000\n");
3703     		Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
3704     		if (Stat == SK_LMODE_STAT_AUTOHALF ||
3705     			Stat == SK_LMODE_STAT_AUTOFULL) {
3706     			printk("    autonegotiation: yes\n");
3707     		}
3708     		else {
3709     			printk("    autonegotiation: no\n");
3710     		}
3711     		if (Stat == SK_LMODE_STAT_AUTOHALF ||
3712     			Stat == SK_LMODE_STAT_HALF) {
3713     			printk("    duplex mode:     half\n");
3714     		}
3715     		else {
3716     			printk("    duplex mode:     full\n");
3717     		}
3718     		Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
3719     		if (Stat == SK_FLOW_STAT_REM_SEND ) {
3720     			printk("    flowctrl:        remote send\n");
3721     		}
3722     		else if (Stat == SK_FLOW_STAT_LOC_SEND ){
3723     			printk("    flowctrl:        local send\n");
3724     		}
3725     		else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
3726     			printk("    flowctrl:        symmetric\n");
3727     		}
3728     		else {
3729     			printk("    flowctrl:        none\n");
3730     		}
3731     		if (pAC->GIni.GP[FromPort].PhyType != SK_PHY_XMAC) {
3732     		Stat = pAC->GIni.GP[FromPort].PMSStatus;
3733     			if (Stat == SK_MS_STAT_MASTER ) {
3734     				printk("    role:            master\n");
3735     			}
3736     			else if (Stat == SK_MS_STAT_SLAVE ) {
3737     				printk("    role:            slave\n");
3738     			}
3739     			else {
3740     				printk("    role:            ???\n");
3741     			}
3742     		}
3743     		
3744     		if ((Param.Para32[0] != pAC->ActivePort) && 
3745     			(pAC->RlmtNets == 1)) {
3746     			NewPara.Para32[0] = pAC->ActivePort;
3747     			NewPara.Para32[1] = Param.Para32[0];
3748     			SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
3749     				NewPara);
3750     		}
3751     		break;
3752     	case SK_DRV_NET_DOWN:	 /* SK_U32 Reason */
3753     		/* action list 7 */
3754     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3755     			("NET DOWN EVENT "));
3756     		printk("%s: network connection down\n", pAC->dev[Param.Para32[1]]->name);
3757     		break;
3758     	case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3759     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3760     			("PORT SWITCH HARD "));
3761     	case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3762     	/* action list 6 */
3763     		printk("%s: switching to port %c\n", pAC->dev[0]->name,
3764     			'A'+Param.Para32[1]);
3765     	case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3766     		FromPort = Param.Para32[0];
3767     		ToPort = Param.Para32[1];
3768     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3769     			("PORT SWITCH EVENT, From: %d  To: %d (Pref %d) ",
3770     			FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
3771     		NewPara.Para64 = FromPort;
3772     		SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3773     		NewPara.Para64 = ToPort;
3774     		SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
3775     		spin_lock_irqsave(
3776     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3777     			Flags);
3778     		spin_lock_irqsave(
3779     			&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3780     		SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
3781     		SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
3782     		spin_unlock_irqrestore(
3783     			&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3784     		spin_unlock_irqrestore(
3785     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3786     			Flags);
3787     
3788     		ReceiveIrq(pAC, &pAC->RxPort[FromPort]); /* clears rx ring */
3789     		ReceiveIrq(pAC, &pAC->RxPort[ToPort]); /* clears rx ring */
3790     		
3791     		ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
3792     		ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
3793     		spin_lock_irqsave(
3794     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock, 
3795     			Flags);
3796     		spin_lock_irqsave(
3797     			&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3798     		pAC->ActivePort = ToPort;
3799     		SetQueueSizes(pAC);
3800     		SkGeInitPort(pAC, IoC, FromPort);
3801     		SkGeInitPort(pAC, IoC, ToPort);
3802     		if (Event == SK_DRV_SWITCH_SOFT) {
3803     			SkXmRxTxEnable(pAC, IoC, FromPort);
3804     		}
3805     		SkXmRxTxEnable(pAC, IoC, ToPort);
3806     		SkAddrSwap(pAC, IoC, FromPort, ToPort);
3807     		SkAddrMcUpdate(pAC, IoC, FromPort);
3808     		SkAddrMcUpdate(pAC, IoC, ToPort);
3809     		PortReInitBmu(pAC, FromPort);
3810     		PortReInitBmu(pAC, ToPort);
3811     		SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
3812     		SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
3813     		ClearAndStartRx(pAC, FromPort);
3814     		ClearAndStartRx(pAC, ToPort);
3815     		spin_unlock_irqrestore(
3816     			&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
3817     		spin_unlock_irqrestore(
3818     			&pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
3819     			Flags);
3820     		break;
3821     	case SK_DRV_RLMT_SEND:	 /* SK_MBUF *pMb */
3822     		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3823     			("RLS "));
3824     		pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
3825     		pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
3826     		skb_put(pMsg, pRlmtMbuf->Length);
3827     		if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
3828     			      pMsg) < 0)
3829     			DEV_KFREE_SKB_ANY(pMsg);
3830     		break;
3831     	default:
3832     		break;
3833     	}
3834     	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
3835     		("END EVENT "));
3836     	
3837     	return (0);
3838     } /* SkDrvEvent */
3839     
3840     
3841     /*****************************************************************************
3842      *
3843      *	SkErrorLog - log errors
3844      *
3845      * Description:
3846      *	This function logs errors to the system buffer and to the console
3847      *
3848      * Returns:
3849      *	0 if everything ok
3850      *	< 0  on error
3851      *	
3852      */
3853     void SkErrorLog(
3854     SK_AC	*pAC,
3855     int	ErrClass,
3856     int	ErrNum,
3857     char	*pErrorMsg)
3858     {
3859     char	ClassStr[80];
3860     
3861     	switch (ErrClass) {
3862     	case SK_ERRCL_OTHER:
3863     		strcpy(ClassStr, "Other error");
3864     		break;
3865     	case SK_ERRCL_CONFIG:
3866     		strcpy(ClassStr, "Configuration error");
3867     		break;
3868     	case SK_ERRCL_INIT:
3869     		strcpy(ClassStr, "Initialization error");
3870     		break;
3871     	case SK_ERRCL_NORES:
3872     		strcpy(ClassStr, "Out of resources error");
3873     		break;
3874     	case SK_ERRCL_SW:
3875     		strcpy(ClassStr, "internal Software error");
3876     		break;
3877     	case SK_ERRCL_HW:
3878     		strcpy(ClassStr, "Hardware failure");
3879     		break;
3880     	case SK_ERRCL_COMM:
3881     		strcpy(ClassStr, "Communication error");
3882     		break;
3883     	}
3884     	printk(KERN_INFO "%s: -- ERROR --\n        Class:  %s\n"
3885     		"        Nr:  0x%x\n        Msg:  %s\n", pAC->dev[0]->name,
3886     		ClassStr, ErrNum, pErrorMsg);
3887     
3888     } /* SkErrorLog */
3889     
3890     #ifdef DEBUG /***************************************************************/
3891     /* "debug only" section *****************************************************/
3892     /****************************************************************************/
3893     
3894     
3895     /*****************************************************************************
3896      *
3897      *	DumpMsg - print a frame
3898      *
3899      * Description:
3900      *	This function prints frames to the system logfile/to the console.
3901      *
3902      * Returns: N/A
3903      *	
3904      */
3905     static void DumpMsg(struct sk_buff *skb, char *str)
3906     {
3907     	int	msglen;
3908     
3909     	if (skb == NULL) {
3910     		printk("DumpMsg(): NULL-Message\n");
3911     		return;
3912     	}
3913     
3914     	if (skb->data == NULL) {
3915     		printk("DumpMsg(): Message empty\n");
3916     		return;
3917     	}
3918     
3919     	msglen = skb->len;
3920     	if (msglen > 64)
3921     		msglen = 64;
3922     
3923     	printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
3924     
3925     	DumpData((char *)skb->data, msglen);
3926     
3927     	printk("------- End of message ---------\n");
3928     } /* DumpMsg */
3929     
3930     
3931     
3932     /*****************************************************************************
3933      *
3934      *	DumpData - print a data area
3935      *
3936      * Description:
3937      *	This function prints a area of data to the system logfile/to the 
3938      *	console.
3939      *
3940      * Returns: N/A
3941      *	
3942      */
3943     static void DumpData(char *p, int size)
3944     {
3945     register int    i;
3946     int	haddr, addr;
3947     char	hex_buffer[180];
3948     char	asc_buffer[180];
3949     char	HEXCHAR[] = "0123456789ABCDEF";
3950     
3951     	addr = 0;
3952     	haddr = 0;
3953     	hex_buffer[0] = 0;
3954     	asc_buffer[0] = 0;
3955     	for (i=0; i < size; ) {
3956     		if (*p >= '0' && *p <='z')
3957     			asc_buffer[addr] = *p;
3958     		else
3959     			asc_buffer[addr] = '.';
3960     		addr++;
3961     		asc_buffer[addr] = 0;
3962     		hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
3963     		haddr++;
3964     		hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
3965     		haddr++;
3966     		hex_buffer[haddr] = ' ';
3967     		haddr++;
3968     		hex_buffer[haddr] = 0;
3969     		p++;
3970     		i++;
3971     		if (i%16 == 0) {
3972     			printk("%s  %s\n", hex_buffer, asc_buffer);
3973     			addr = 0;
3974     			haddr = 0;
3975     		}
3976     	}
3977     } /* DumpData */
3978     
3979     
3980     /*****************************************************************************
3981      *
3982      *	DumpLong - print a data area as long values
3983      *
3984      * Description:
3985      *	This function prints a area of data to the system logfile/to the 
3986      *	console.
3987      *
3988      * Returns: N/A
3989      *	
3990      */
3991     static void DumpLong(char *pc, int size)
3992     {
3993     register int    i;
3994     int	haddr, addr;
3995     char	hex_buffer[180];
3996     char	asc_buffer[180];
3997     char	HEXCHAR[] = "0123456789ABCDEF";
3998     long	*p;
3999     int	l;
4000     
4001     	addr = 0;
4002     	haddr = 0;
4003     	hex_buffer[0] = 0;
4004     	asc_buffer[0] = 0;
4005     	p = (long*) pc;
4006     	for (i=0; i < size; ) {
4007     		l = (long) *p;
4008     		hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4009     		haddr++;
4010     		hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4011     		haddr++;
4012     		hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4013     		haddr++;
4014     		hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4015     		haddr++;
4016     		hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4017     		haddr++;
4018     		hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4019     		haddr++;
4020     		hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4021     		haddr++;
4022     		hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4023     		haddr++;
4024     		hex_buffer[haddr] = ' ';
4025     		haddr++;
4026     		hex_buffer[haddr] = 0;
4027     		p++;
4028     		i++;
4029     		if (i%8 == 0) {
4030     			printk("%4x %s\n", (i-8)*4, hex_buffer);
4031     			haddr = 0;
4032     		}
4033     	}
4034     	printk("------------------------\n");
4035     } /* DumpLong */
4036     
4037     #endif /* DEBUG */
4038     
4039     /*
4040      * Local variables:
4041      * compile-command: "make"
4042      * End:
4043      */
4044     
4045