1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.29 $
6 * Date: $Date: 2000/02/21 13:31:56 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998,1999 SysKonnect,
14 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
16 * Driver for SysKonnect Gigabit Ethernet Server Adapters:
18 * SK-9841 (single link 1000Base-LX)
19 * SK-9842 (dual link 1000Base-LX)
20 * SK-9843 (single link 1000Base-SX)
21 * SK-9844 (dual link 1000Base-SX)
22 * SK-9821 (single link 1000Base-T)
23 * SK-9822 (dual link 1000Base-T)
25 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
26 * SysKonnects GEnesis Solaris driver
27 * Author: Christoph Goos (cgoos@syskonnect.de)
29 * Address all question to: linux@syskonnect.de
31 * The technical manual for the adapters is available from SysKonnect's
32 * web pages: www.syskonnect.com
33 * Goto "Support" and search Knowledge Base for "manual".
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * The information in this file is provided "AS IS" without warranty.
42 ******************************************************************************/
44 /******************************************************************************
49 * Kernel 2.4.x specific:
50 * Revision 1.xx 2000/09/12 13:31:56 cgoos
51 * Fixed missign "dev=NULL in skge_probe.
52 * Added counting for jumbo frames (corrects error statistic).
53 * Removed VLAN tag check (enables VLAN support).
55 * Kernel 2.2.x specific:
56 * Revision 1.29 2000/02/21 13:31:56 cgoos
57 * Fixed "unused" warning for UltraSPARC change.
59 * Partially kernel 2.2.x specific:
60 * Revision 1.28 2000/02/21 10:32:36 cgoos
61 * Added fixes for UltraSPARC.
62 * Now printing RlmtMode and PrefPort setting at startup.
63 * Changed XmitFrame return value.
64 * Fixed rx checksum calculation for BIG ENDIAN systems.
65 * Fixed rx jumbo frames counted as ierrors.
68 * Revision 1.27 1999/11/25 09:06:28 cgoos
69 * Changed base_addr to unsigned long.
71 * Revision 1.26 1999/11/22 13:29:16 cgoos
72 * Changed license header to GPL.
73 * Changes for inclusion in linux kernel (2.2.13).
74 * Removed 2.0.x defines.
75 * Changed SkGeProbe to skge_probe.
76 * Added checks in SkGeIoctl.
78 * Revision 1.25 1999/10/07 14:47:52 cgoos
79 * Changed 984x to 98xx.
81 * Revision 1.24 1999/09/30 07:21:01 cgoos
82 * Removed SK_RLMT_SLOW_LOOKAHEAD option.
83 * Giving spanning tree packets also to OS now.
85 * Revision 1.23 1999/09/29 07:36:50 cgoos
86 * Changed assignment for IsBc/IsMc.
88 * Revision 1.22 1999/09/28 12:57:09 cgoos
89 * Added CheckQueue also to Single-Port-ISR.
91 * Revision 1.21 1999/09/28 12:42:41 cgoos
92 * Changed parameter strings for RlmtMode.
94 * Revision 1.20 1999/09/28 12:37:57 cgoos
95 * Added CheckQueue for fast delivery of RLMT frames.
97 * Revision 1.19 1999/09/16 07:57:25 cgoos
98 * Copperfield changes.
100 * Revision 1.18 1999/09/03 13:06:30 cgoos
101 * Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused
102 * double allocated skb's.
103 * FrameStat in ReceiveIrq was accessed via wrong Rxd.
104 * Queue size for async. standby Tx queue was zero.
105 * FillRxLimit of 0 could cause problems with ReQueue, changed to 1.
106 * Removed debug output of checksum statistic.
108 * Revision 1.17 1999/08/11 13:55:27 cgoos
109 * Transmit descriptor polling was not reenabled after SkGePortInit.
111 * Revision 1.16 1999/07/27 15:17:29 cgoos
112 * Added some "\n" in output strings (removed while debuging...).
114 * Revision 1.15 1999/07/23 12:09:30 cgoos
115 * Performance optimization, rx checksumming, large frame support.
117 * Revision 1.14 1999/07/14 11:26:27 cgoos
118 * Removed Link LED settings (now in RLMT).
119 * Added status output at NET UP.
120 * Fixed SMP problems with Tx and SWITCH running in parallel.
121 * Fixed return code problem at RLMT_SEND event.
123 * Revision 1.13 1999/04/07 10:11:42 cgoos
124 * Fixed Single Port problems.
125 * Fixed Multi-Adapter problems.
126 * Always display startup string.
128 * Revision 1.12 1999/03/29 12:26:37 cgoos
129 * Reversed locking to fine granularity.
130 * Fixed skb double alloc problem (caused by incorrect xmit return code).
131 * Enhanced function descriptions.
133 * Revision 1.11 1999/03/15 13:10:51 cgoos
134 * Changed device identifier in output string to ethX.
136 * Revision 1.10 1999/03/15 12:12:34 cgoos
137 * Changed copyright notice.
139 * Revision 1.9 1999/03/15 12:10:17 cgoos
140 * Changed locking to one driver lock.
141 * Added check of SK_AC-size (for consistency with library).
143 * Revision 1.8 1999/03/08 11:44:02 cgoos
144 * Fixed missing dev->tbusy in SkGeXmit.
145 * Changed large frame (jumbo) buffer number.
146 * Added copying of short frames.
148 * Revision 1.7 1999/03/04 13:26:57 cgoos
149 * Fixed spinlock calls for SMP.
151 * Revision 1.6 1999/03/02 09:53:51 cgoos
152 * Added descriptor revertion for big endian machines.
154 * Revision 1.5 1999/03/01 08:50:59 cgoos
155 * Fixed SkGeChangeMtu.
156 * Fixed pci config space accesses.
158 * Revision 1.4 1999/02/18 15:48:44 cgoos
159 * Corrected some printk's.
161 * Revision 1.3 1999/02/18 12:45:55 cgoos
162 * Changed SK_MAX_CARD_PARAM to default 16
164 * Revision 1.2 1999/02/18 10:55:32 cgoos
165 * Removed SkGeDrvTimeStamp function.
166 * Printing "ethX:" before adapter type at adapter init.
169 * 10-Feb-1999 cg Created, based on Linux' acenic.c, 3c59x.c and
170 * SysKonnects GEnesis Solaris driver
172 ******************************************************************************/
174 /******************************************************************************
176 * Possible compiler options (#define xxx / -Dxxx):
178 * debugging can be enable by changing SK_DEBUG_CHKMOD and
179 * SK_DEBUG_CHKCAT in makefile (described there).
181 ******************************************************************************/
183 /******************************************************************************
187 * This is the main module of the Linux GE driver.
189 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
190 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
191 * Those are used for drivers on multiple OS', so some thing may seem
192 * unnecessary complicated on Linux. Please do not try to 'clean up'
193 * them without VERY good reasons, because this will make it more
194 * difficult to keep the Linux driver in synchronisation with the
197 * Include file hierarchy:
209 * <linux/interrupt.h>
214 * <linux/netdevice.h>
215 * <linux/etherdevice.h>
217 * those three depending on kernel version used:
243 ******************************************************************************/
245 static const char SysKonnectFileId
[] = "@(#)" __FILE__
" (C) SysKonnect.";
246 static const char SysKonnectBuildNumber
[] =
247 "@(#)SK-BUILD: 3.05 (20000907) PL: 01";
249 #include <linux/module.h>
250 #include <linux/init.h>
252 #include "h/skdrv1st.h"
253 #include "h/skdrv2nd.h"
255 /* defines ******************************************************************/
257 #define BOOT_STRING "sk98lin: Network Device Driver v3.05\n" \
258 "Copyright (C) 1999-2000 SysKonnect"
260 #define VER_STRING "3.05"
263 /* for debuging on x86 only */
264 /* #define BREAKPOINT() asm(" int $3"); */
266 /* use of a transmit complete interrupt */
267 #define USE_TX_COMPLETE
269 /* use interrupt moderation (for tx complete only) */
270 // #define USE_INT_MOD
271 #define INTS_PER_SEC 1000
274 * threshold for copying small receive frames
275 * set to 0 to avoid copying, set to 9001 to copy all frames
277 #define SK_COPY_THRESHOLD 200
279 /* number of adapters that can be configured via command line params */
280 #define SK_MAX_CARD_PARAM 16
283 * use those defines for a compile-in version of the driver instead
284 * of command line parameters
286 // #define AUTO_NEG_A {"Sense", }
287 // #define AUTO_NEG_B {"Sense", }
288 // #define DUP_CAP_A {"Both", }
289 // #define DUP_CAP_B {"Both", }
290 // #define FLOW_CTRL_A {"SymOrRem", }
291 // #define FLOW_CTRL_B {"SymOrRem", }
292 // #define ROLE_A {"Auto", }
293 // #define ROLE_B {"Auto", }
294 // #define PREF_PORT {"A", }
295 // #define RLMT_MODE {"CheckLink", }
298 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
299 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
300 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
302 /* function prototypes ******************************************************/
303 static void FreeResources(struct net_device
*dev
);
304 int init_module(void);
305 void cleanup_module(void);
306 static int SkGeBoardInit(struct net_device
*dev
, SK_AC
*pAC
);
307 static SK_BOOL
BoardAllocMem(SK_AC
*pAC
);
308 static void BoardFreeMem(SK_AC
*pAC
);
309 static void BoardInitMem(SK_AC
*pAC
);
310 static void SetupRing(SK_AC
*, void*, uintptr_t, RXD
**, RXD
**, RXD
**,
313 static void SkGeIsr(int irq
, void *dev_id
, struct pt_regs
*ptregs
);
314 static void SkGeIsrOnePort(int irq
, void *dev_id
, struct pt_regs
*ptregs
);
315 static int SkGeOpen(struct net_device
*dev
);
316 static int SkGeClose(struct net_device
*dev
);
317 static int SkGeXmit(struct sk_buff
*skb
, struct net_device
*dev
);
318 static int SkGeSetMacAddr(struct net_device
*dev
, void *p
);
319 static void SkGeSetRxMode(struct net_device
*dev
);
320 static struct net_device_stats
*SkGeStats(struct net_device
*dev
);
321 static int SkGeIoctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
322 static void GetConfiguration(SK_AC
*);
323 static void ProductStr(SK_AC
*);
324 static int XmitFrame(SK_AC
*, TX_PORT
*, struct sk_buff
*);
325 static void FreeTxDescriptors(SK_AC
*pAC
, TX_PORT
*);
326 static void FillRxRing(SK_AC
*, RX_PORT
*);
327 static SK_BOOL
FillRxDescriptor(SK_AC
*, RX_PORT
*);
328 static void ReceiveIrq(SK_AC
*, RX_PORT
*);
329 static void ClearAndStartRx(SK_AC
*, int);
330 static void ClearTxIrq(SK_AC
*, int, int);
331 static void ClearRxRing(SK_AC
*, RX_PORT
*);
332 static void ClearTxRing(SK_AC
*, TX_PORT
*);
333 static void SetQueueSizes(SK_AC
*pAC
);
334 static int SkGeChangeMtu(struct net_device
*dev
, int new_mtu
);
335 static void PortReInitBmu(SK_AC
*, int);
336 static int SkGeIocMib(SK_AC
*, unsigned int, int);
338 static void DumpMsg(struct sk_buff
*, char*);
339 static void DumpData(char*, int);
340 static void DumpLong(char*, int);
344 /* global variables *********************************************************/
345 static const char *BootString
= BOOT_STRING
;
346 static struct net_device
*root_dev
= NULL
;
347 static int probed __initdata
= 0;
349 /* local variables **********************************************************/
350 static uintptr_t TxQueueAddr
[SK_MAX_MACS
][2] = {{0x680, 0x600},{0x780, 0x700}};
351 static uintptr_t RxQueueAddr
[SK_MAX_MACS
] = {0x400, 0x480};
353 /*****************************************************************************
355 * skge_probe - find all SK-98xx adapters
358 * This function scans the PCI bus for SK-98xx adapters. Resources for
359 * each adapter are allocated and the adapter is brought into Init 1
363 * 0, if everything is ok
366 static int __init
skge_probe (void)
368 int boards_found
= 0;
369 int version_disp
= 0;
371 struct pci_dev
*pdev
= NULL
;
372 unsigned long base_address
;
373 struct net_device
*dev
= NULL
;
379 /* display driver info */
382 /* set display flag to TRUE so that */
383 /* we only display this string ONCE */
385 printk("%s\n", BootString
);
388 if (!pci_present()) /* is PCI support present? */
391 while((pdev
= pci_find_device(PCI_VENDOR_ID_SYSKONNECT
,
392 PCI_DEVICE_ID_SYSKONNECT_GE
, pdev
)) != NULL
) {
393 if (pci_enable_device(pdev
))
397 dev
= init_etherdev(dev
, sizeof(SK_AC
));
400 printk(KERN_ERR
"Unable to allocate etherdev "
407 pAC
->PciDevId
= pdev
->device
;
409 sprintf(pAC
->Name
, "SysKonnect SK-98xx");
410 pAC
->CheckQueue
= SK_FALSE
;
412 dev
->irq
= pdev
->irq
;
414 dev
->open
= &SkGeOpen
;
415 dev
->stop
= &SkGeClose
;
416 dev
->hard_start_xmit
= &SkGeXmit
;
417 dev
->get_stats
= &SkGeStats
;
418 dev
->set_multicast_list
= &SkGeSetRxMode
;
419 dev
->set_mac_address
= &SkGeSetMacAddr
;
420 dev
->do_ioctl
= &SkGeIoctl
;
421 dev
->change_mtu
= &SkGeChangeMtu
;
428 pci_set_master(pdev
);
430 base_address
= pci_resource_start (pdev
, 0);
434 * On big endian machines, we use the adapter's aibility of
435 * reading the descriptors as big endian.
439 SkPciReadCfgDWord(pAC
, PCI_OUR_REG_2
, &our2
);
440 our2
|= PCI_REV_DESC
;
441 SkPciWriteCfgDWord(pAC
, PCI_OUR_REG_2
, our2
);
443 #endif /* BIG ENDIAN */
446 * Remap the regs into kernel space.
450 pAC
->IoBase
= (char*)ioremap(base_address
, 0x4000);
452 printk(KERN_ERR
"%s: Unable to map I/O register, "
453 "SK 98xx No. %i will be disabled.\n",
454 dev
->name
, boards_found
);
457 pAC
->Index
= boards_found
;
459 if (SkGeBoardInit(dev
, pAC
)) {
464 memcpy((caddr_t
) &dev
->dev_addr
,
465 (caddr_t
) &pAC
->Addr
.CurrentMacAddress
, 6);
470 * This is bollocks, but we need to tell the net-init
471 * code that it shall go for the next device.
479 * If we're at this point we're going through skge_probe() for
480 * the first time. Return success (0) if we've initialized 1
481 * or more boards. Otherwise, return failure (-ENODEV).
488 /*****************************************************************************
490 * FreeResources - release resources allocated for adapter
493 * This function releases the IRQ, unmaps the IO and
494 * frees the desriptor ring.
499 static void FreeResources(struct net_device
*dev
)
505 pAC
= (SK_AC
*) dev
->priv
;
506 AllocFlag
= pAC
->AllocFlag
;
507 if (AllocFlag
& SK_ALLOC_IRQ
) {
508 free_irq(dev
->irq
, dev
);
511 iounmap(pAC
->IoBase
);
513 if (pAC
->pDescrMem
) {
518 } /* FreeResources */
521 MODULE_AUTHOR("Christoph Goos <cgoos@syskonnect.de>");
522 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
523 MODULE_PARM(AutoNeg_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
524 MODULE_PARM(AutoNeg_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
525 MODULE_PARM(DupCap_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
526 MODULE_PARM(DupCap_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
527 MODULE_PARM(FlowCtrl_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
528 MODULE_PARM(FlowCtrl_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
529 MODULE_PARM(Role_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
530 MODULE_PARM(Role_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
531 MODULE_PARM(PrefPort
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
532 MODULE_PARM(RlmtMode
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
533 /* not used, just there because every driver should have them: */
534 MODULE_PARM(options
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "i");
535 MODULE_PARM(debug
, "i");
539 static char *AutoNeg_A
[SK_MAX_CARD_PARAM
] = AUTO_NEG_A
;
541 static char *AutoNeg_A
[SK_MAX_CARD_PARAM
] = {"", };
545 static char *DupCap_A
[SK_MAX_CARD_PARAM
] = DUP_CAP_A
;
547 static char *DupCap_A
[SK_MAX_CARD_PARAM
] = {"", };
551 static char *FlowCtrl_A
[SK_MAX_CARD_PARAM
] = FLOW_CTRL_A
;
553 static char *FlowCtrl_A
[SK_MAX_CARD_PARAM
] = {"", };
557 static char *Role_A
[SK_MAX_CARD_PARAM
] = ROLE_A
;
559 static char *Role_A
[SK_MAX_CARD_PARAM
] = {"", };
563 static char *AutoNeg_B
[SK_MAX_CARD_PARAM
] = AUTO_NEG_B
;
565 static char *AutoNeg_B
[SK_MAX_CARD_PARAM
] = {"", };
569 static char *DupCap_B
[SK_MAX_CARD_PARAM
] = DUP_CAP_B
;
571 static char *DupCap_B
[SK_MAX_CARD_PARAM
] = {"", };
575 static char *FlowCtrl_B
[SK_MAX_CARD_PARAM
] = FLOW_CTRL_B
;
577 static char *FlowCtrl_B
[SK_MAX_CARD_PARAM
] = {"", };
581 static char *Role_B
[SK_MAX_CARD_PARAM
] = ROLE_B
;
583 static char *Role_B
[SK_MAX_CARD_PARAM
] = {"", };
587 static char *PrefPort
[SK_MAX_CARD_PARAM
] = PREF_PORT
;
589 static char *PrefPort
[SK_MAX_CARD_PARAM
] = {"", };
593 static char *RlmtMode
[SK_MAX_CARD_PARAM
] = RLMT_MODE
;
595 static char *RlmtMode
[SK_MAX_CARD_PARAM
] = {"", };
599 static int debug
= 0; /* not used */
600 static int options
[SK_MAX_CARD_PARAM
] = {0, }; /* not used */
603 /*****************************************************************************
605 * skge_init_module - module initialization function
608 * Very simple, only call skge_probe and return approriate result.
611 * 0, if everything is ok
614 static int __init
skge_init_module(void)
620 /* just to avoid warnings ... */
624 cards
= skge_probe();
626 printk("No adapter found\n");
628 return cards
? 0 : -ENODEV
;
629 } /* skge_init_module */
632 /*****************************************************************************
634 * skge_cleanup_module - module unload function
637 * Disable adapter if it is still running, free resources,
638 * free device struct.
642 static void __exit
skge_cleanup_module(void)
645 struct net_device
*next
;
650 pAC
= (SK_AC
*)root_dev
->priv
;
653 netif_stop_queue(root_dev
);
654 SkGeYellowLED(pAC
, pAC
->IoBase
, 0);
656 if(pAC
->BoardLevel
== 2) {
657 /* board is still alive */
658 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
659 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
660 SkEventDispatcher(pAC
, pAC
->IoBase
);
661 /* disable interrupts */
662 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
663 SkGeDeInit(pAC
, pAC
->IoBase
);
664 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
666 /* We do NOT check here, if IRQ was pending, of course*/
669 if(pAC
->BoardLevel
== 1) {
670 /* board is still alive */
671 SkGeDeInit(pAC
, pAC
->IoBase
);
675 FreeResources(root_dev
);
677 root_dev
->get_stats
= NULL
;
679 * otherwise unregister_netdev calls get_stats with
682 unregister_netdev(root_dev
);
687 } /* skge_cleanup_module */
689 module_init(skge_init_module
);
690 module_exit(skge_cleanup_module
);
692 /*****************************************************************************
694 * SkGeBoardInit - do level 0 and 1 initialization
697 * This function prepares the board hardware for running. The desriptor
698 * ring is set up, the IRQ is allocated and the configuration settings
702 * 0, if everything is ok
705 static int __init
SkGeBoardInit(struct net_device
*dev
, SK_AC
*pAC
)
709 char *DescrString
= "sk98lin: Driver for Linux"; /* this is given to PNMI */
710 char *VerStr
= VER_STRING
;
711 int Ret
; /* return code of request_irq */
713 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
714 ("IoBase: %08lX\n", (unsigned long)pAC
->IoBase
));
715 for (i
=0; i
<SK_MAX_MACS
; i
++) {
716 pAC
->TxPort
[i
][0].HwAddr
= pAC
->IoBase
+ TxQueueAddr
[i
][0];
717 pAC
->TxPort
[i
][0].PortIndex
= i
;
718 pAC
->RxPort
[i
].HwAddr
= pAC
->IoBase
+ RxQueueAddr
[i
];
719 pAC
->RxPort
[i
].PortIndex
= i
;
722 /* Initialize the mutexes */
724 for (i
=0; i
<SK_MAX_MACS
; i
++) {
725 spin_lock_init(&pAC
->TxPort
[i
][0].TxDesRingLock
);
726 spin_lock_init(&pAC
->RxPort
[i
].RxDesRingLock
);
728 spin_lock_init(&pAC
->SlowPathLock
);
730 /* level 0 init common modules here */
732 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
733 /* Does a RESET on board ...*/
734 if (SkGeInit(pAC
, pAC
->IoBase
, 0) != 0) {
735 printk("HWInit (0) failed.\n");
736 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
739 SkI2cInit( pAC
, pAC
->IoBase
, 0);
740 SkEventInit(pAC
, pAC
->IoBase
, 0);
741 SkPnmiInit( pAC
, pAC
->IoBase
, 0);
742 SkAddrInit( pAC
, pAC
->IoBase
, 0);
743 SkRlmtInit( pAC
, pAC
->IoBase
, 0);
744 SkTimerInit(pAC
, pAC
->IoBase
, 0);
747 pAC
->RxBufSize
= ETH_BUF_SIZE
;
749 SK_PNMI_SET_DRIVER_DESCR(pAC
, DescrString
);
750 SK_PNMI_SET_DRIVER_VER(pAC
, VerStr
);
752 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
754 GetConfiguration(pAC
);
756 /* level 1 init common modules here (HW init) */
757 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
758 if (SkGeInit(pAC
, pAC
->IoBase
, 1) != 0) {
759 printk("HWInit (1) failed.\n");
760 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
763 SkI2cInit( pAC
, pAC
->IoBase
, 1);
764 SkEventInit(pAC
, pAC
->IoBase
, 1);
765 SkPnmiInit( pAC
, pAC
->IoBase
, 1);
766 SkAddrInit( pAC
, pAC
->IoBase
, 1);
767 SkRlmtInit( pAC
, pAC
->IoBase
, 1);
768 SkTimerInit(pAC
, pAC
->IoBase
, 1);
771 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
773 if (pAC
->GIni
.GIMacsFound
== 2) {
774 Ret
= request_irq(dev
->irq
, SkGeIsr
, SA_SHIRQ
, pAC
->Name
, dev
);
775 } else if (pAC
->GIni
.GIMacsFound
== 1) {
776 Ret
= request_irq(dev
->irq
, SkGeIsrOnePort
, SA_SHIRQ
,
779 printk(KERN_WARNING
"%s: illegal number of ports: %d\n",
780 dev
->name
, pAC
->GIni
.GIMacsFound
);
784 printk(KERN_WARNING
"%s: Requested IRQ %d is busy\n",
785 dev
->name
, dev
->irq
);
788 pAC
->AllocFlag
|= SK_ALLOC_IRQ
;
790 /* Alloc memory for this board (Mem for RxD/TxD) : */
791 if(!BoardAllocMem(pAC
)) {
792 printk("No memory for descriptor rings\n");
796 SkCsSetReceiveFlags(pAC
,
797 SKCS_PROTO_IP
| SKCS_PROTO_TCP
| SKCS_PROTO_UDP
,
798 &pAC
->CsOfs1
, &pAC
->CsOfs2
);
799 pAC
->CsOfs
= (pAC
->CsOfs2
<< 16) | pAC
->CsOfs1
;
805 /* Print adapter specific string from vpd */
807 printk("%s: %s\n", dev
->name
, pAC
->DeviceStr
);
809 /* Print configuration settings */
810 printk(" PrefPort:%c RlmtMode:%s\n",
811 'A' + pAC
->Rlmt
.PrefPort
,
812 (pAC
->RlmtMode
==0) ? "ChkLink" :
813 ((pAC
->RlmtMode
==1) ? "ChkLink" :
814 ((pAC
->RlmtMode
==3) ? "ChkOth" :
815 ((pAC
->RlmtMode
==7) ? "ChkSeg" : "Error"))));
817 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
820 * Register the device here
822 pAC
->Next
= root_dev
;
826 } /* SkGeBoardInit */
829 /*****************************************************************************
831 * BoardAllocMem - allocate the memory for the descriptor rings
834 * This function allocates the memory for all descriptor rings.
835 * Each ring is aligned for the desriptor alignment and no ring
836 * has a 4 GByte boundary in it (because the upper 32 bit must
837 * be constant for all descriptiors in one rings).
840 * SK_TRUE, if all memory could be allocated
843 static SK_BOOL
BoardAllocMem(
846 caddr_t pDescrMem
; /* pointer to descriptor memory area */
847 size_t AllocLength
; /* length of complete descriptor area */
848 int i
; /* loop counter */
849 unsigned long BusAddr
;
852 /* rings plus one for alignment (do not cross 4 GB boundary) */
853 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
854 #if (BITS_PER_LONG == 32)
855 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
+ 8;
857 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
860 pDescrMem
= pci_alloc_consistent(&pAC
->PciDev
, AllocLength
,
862 if (pDescrMem
== NULL
) {
865 pAC
->pDescrMem
= pDescrMem
;
867 /* Descriptors need 8 byte alignment, and this is ensured
868 * by pci_alloc_consistent.
870 BusAddr
= (unsigned long) pAC
->pDescrMemDMA
;
871 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
872 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
873 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
874 i
, (unsigned long) pDescrMem
,
876 pAC
->TxPort
[i
][0].pTxDescrRing
= pDescrMem
;
877 pAC
->TxPort
[i
][0].VTxDescrRing
= BusAddr
;
878 pDescrMem
+= TX_RING_SIZE
;
879 BusAddr
+= TX_RING_SIZE
;
881 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
882 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
883 i
, (unsigned long) pDescrMem
,
884 (unsigned long)BusAddr
));
885 pAC
->RxPort
[i
].pRxDescrRing
= pDescrMem
;
886 pAC
->RxPort
[i
].VRxDescrRing
= BusAddr
;
887 pDescrMem
+= RX_RING_SIZE
;
888 BusAddr
+= RX_RING_SIZE
;
892 } /* BoardAllocMem */
895 /****************************************************************************
897 * BoardFreeMem - reverse of BoardAllocMem
900 * Free all memory allocated in BoardAllocMem: adapter context,
901 * descriptor rings, locks.
905 static void BoardFreeMem(
908 size_t AllocLength
; /* length of complete descriptor area */
910 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
912 #if (BITS_PER_LONG == 32)
913 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
+ 8;
915 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
918 pci_free_consistent(&pAC
->PciDev
, AllocLength
,
919 pAC
->pDescrMem
, pAC
->pDescrMemDMA
);
920 pAC
->pDescrMem
= NULL
;
924 /*****************************************************************************
926 * BoardInitMem - initiate the descriptor rings
929 * This function sets the descriptor rings up in memory.
930 * The adapter is initialized with the descriptor start addresses.
934 static void BoardInitMem(
935 SK_AC
*pAC
) /* pointer to adapter context */
937 int i
; /* loop counter */
938 int RxDescrSize
; /* the size of a rx descriptor rounded up to alignment*/
939 int TxDescrSize
; /* the size of a tx descriptor rounded up to alignment*/
941 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
944 RxDescrSize
= (((sizeof(RXD
) - 1) / DESCR_ALIGN
) + 1) * DESCR_ALIGN
;
945 pAC
->RxDescrPerRing
= RX_RING_SIZE
/ RxDescrSize
;
946 TxDescrSize
= (((sizeof(TXD
) - 1) / DESCR_ALIGN
) + 1) * DESCR_ALIGN
;
947 pAC
->TxDescrPerRing
= TX_RING_SIZE
/ RxDescrSize
;
949 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
952 pAC
->TxPort
[i
][0].pTxDescrRing
,
953 pAC
->TxPort
[i
][0].VTxDescrRing
,
954 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingHead
,
955 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingTail
,
956 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingPrev
,
957 &pAC
->TxPort
[i
][0].TxdRingFree
,
961 pAC
->RxPort
[i
].pRxDescrRing
,
962 pAC
->RxPort
[i
].VRxDescrRing
,
963 &pAC
->RxPort
[i
].pRxdRingHead
,
964 &pAC
->RxPort
[i
].pRxdRingTail
,
965 &pAC
->RxPort
[i
].pRxdRingPrev
,
966 &pAC
->RxPort
[i
].RxdRingFree
,
972 /*****************************************************************************
974 * SetupRing - create one descriptor ring
977 * This function creates one descriptor ring in the given memory area.
978 * The head, tail and number of free descriptors in the ring are set.
983 static void SetupRing(
985 void *pMemArea
, /* a pointer to the memory area for the ring */
986 uintptr_t VMemArea
, /* the virtual bus address of the memory area */
987 RXD
**ppRingHead
, /* address where the head should be written */
988 RXD
**ppRingTail
, /* address where the tail should be written */
989 RXD
**ppRingPrev
, /* address where the tail should be written */
990 int *pRingFree
, /* address where the # of free descr. goes */
991 SK_BOOL IsTx
) /* flag: is this a tx ring */
993 int i
; /* loop counter */
994 int DescrSize
; /* the size of a descriptor rounded up to alignment*/
995 int DescrNum
; /* number of descriptors per ring */
996 RXD
*pDescr
; /* pointer to a descriptor (receive or transmit) */
997 RXD
*pNextDescr
; /* pointer to the next descriptor */
998 RXD
*pPrevDescr
; /* pointer to the previous descriptor */
999 uintptr_t VNextDescr
; /* the virtual bus address of the next descriptor */
1001 if (IsTx
== SK_TRUE
) {
1002 DescrSize
= (((sizeof(TXD
) - 1) / DESCR_ALIGN
) + 1) *
1004 DescrNum
= TX_RING_SIZE
/ DescrSize
;
1007 DescrSize
= (((sizeof(RXD
) - 1) / DESCR_ALIGN
) + 1) *
1009 DescrNum
= RX_RING_SIZE
/ DescrSize
;
1012 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
1013 ("Descriptor size: %d Descriptor Number: %d\n",
1014 DescrSize
,DescrNum
));
1016 pDescr
= (RXD
*) pMemArea
;
1018 pNextDescr
= (RXD
*) (((char*)pDescr
) + DescrSize
);
1019 VNextDescr
= VMemArea
+ DescrSize
;
1020 for(i
=0; i
<DescrNum
; i
++) {
1021 /* set the pointers right */
1022 pDescr
->VNextRxd
= VNextDescr
& 0xffffffffULL
;
1023 pDescr
->pNextRxd
= pNextDescr
;
1024 pDescr
->TcpSumStarts
= pAC
->CsOfs
;
1025 /* advance on step */
1026 pPrevDescr
= pDescr
;
1027 pDescr
= pNextDescr
;
1028 pNextDescr
= (RXD
*) (((char*)pDescr
) + DescrSize
);
1029 VNextDescr
+= DescrSize
;
1031 pPrevDescr
->pNextRxd
= (RXD
*) pMemArea
;
1032 pPrevDescr
->VNextRxd
= VMemArea
;
1033 pDescr
= (RXD
*) pMemArea
;
1034 *ppRingHead
= (RXD
*) pMemArea
;
1035 *ppRingTail
= *ppRingHead
;
1036 *ppRingPrev
= pPrevDescr
;
1037 *pRingFree
= DescrNum
;
1041 /*****************************************************************************
1043 * PortReInitBmu - re-initiate the descriptor rings for one port
1046 * This function reinitializes the descriptor rings of one port
1047 * in memory. The port must be stopped before.
1048 * The HW is initialized with the descriptor start addresses.
1053 static void PortReInitBmu(
1054 SK_AC
*pAC
, /* pointer to adapter context */
1055 int PortIndex
) /* index of the port for which to re-init */
1057 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1058 ("PortReInitBmu "));
1060 /* set address of first descriptor of ring in BMU */
1061 SK_OUT32(pAC
->IoBase
, TxQueueAddr
[PortIndex
][TX_PRIO_LOW
]+
1063 (uint32_t)(((caddr_t
)
1064 (pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxdRingHead
) -
1065 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxDescrRing
+
1066 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].VTxDescrRing
) &
1068 SK_OUT32(pAC
->IoBase
, TxQueueAddr
[PortIndex
][TX_PRIO_LOW
]+
1070 (uint32_t)(((caddr_t
)
1071 (pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxdRingHead
) -
1072 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxDescrRing
+
1073 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].VTxDescrRing
) >> 32));
1074 SK_OUT32(pAC
->IoBase
, RxQueueAddr
[PortIndex
]+RX_Q_CUR_DESCR_LOW
,
1075 (uint32_t)(((caddr_t
)(pAC
->RxPort
[PortIndex
].pRxdRingHead
) -
1076 pAC
->RxPort
[PortIndex
].pRxDescrRing
+
1077 pAC
->RxPort
[PortIndex
].VRxDescrRing
) & 0xFFFFFFFF));
1078 SK_OUT32(pAC
->IoBase
, RxQueueAddr
[PortIndex
]+RX_Q_DESCR_HIGH
,
1079 (uint32_t)(((caddr_t
)(pAC
->RxPort
[PortIndex
].pRxdRingHead
) -
1080 pAC
->RxPort
[PortIndex
].pRxDescrRing
+
1081 pAC
->RxPort
[PortIndex
].VRxDescrRing
) >> 32));
1082 } /* PortReInitBmu */
1085 /****************************************************************************
1087 * SkGeIsr - handle adapter interrupts
1090 * The interrupt routine is called when the network adapter
1091 * generates an interrupt. It may also be called if another device
1092 * shares this interrupt vector with the driver.
1097 static void SkGeIsr(int irq
, void *dev_id
, struct pt_regs
*ptregs
)
1099 struct net_device
*dev
= (struct net_device
*)dev_id
;
1101 SK_U32 IntSrc
; /* interrupts source register contents */
1103 pAC
= (SK_AC
*) dev
->priv
;
1106 * Check and process if its our interrupt
1108 SK_IN32(pAC
->IoBase
, B0_SP_ISRC
, &IntSrc
);
1113 while (((IntSrc
& IRQ_MASK
) & ~SPECIAL_IRQS
) != 0) {
1114 #if 0 /* software irq currently not used */
1115 if (IntSrc
& IRQ_SW
) {
1116 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1117 SK_DBGCAT_DRV_INT_SRC
,
1118 ("Software IRQ\n"));
1121 if (IntSrc
& IRQ_EOF_RX1
) {
1122 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1123 SK_DBGCAT_DRV_INT_SRC
,
1125 ReceiveIrq(pAC
, &pAC
->RxPort
[0]);
1126 SK_PNMI_CNT_RX_INTR(pAC
);
1128 if (IntSrc
& IRQ_EOF_RX2
) {
1129 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1130 SK_DBGCAT_DRV_INT_SRC
,
1132 ReceiveIrq(pAC
, &pAC
->RxPort
[1]);
1133 SK_PNMI_CNT_RX_INTR(pAC
);
1135 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1136 if (IntSrc
& IRQ_EOF_AS_TX1
) {
1137 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1138 SK_DBGCAT_DRV_INT_SRC
,
1139 ("EOF AS TX1 IRQ\n"));
1140 SK_PNMI_CNT_TX_INTR(pAC
);
1141 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1142 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
1143 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1145 if (IntSrc
& IRQ_EOF_AS_TX2
) {
1146 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1147 SK_DBGCAT_DRV_INT_SRC
,
1148 ("EOF AS TX2 IRQ\n"));
1149 SK_PNMI_CNT_TX_INTR(pAC
);
1150 spin_lock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
1151 FreeTxDescriptors(pAC
, &pAC
->TxPort
[1][TX_PRIO_LOW
]);
1152 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
1154 #if 0 /* only if sync. queues used */
1155 if (IntSrc
& IRQ_EOF_SY_TX1
) {
1156 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1157 SK_DBGCAT_DRV_INT_SRC
,
1158 ("EOF SY TX1 IRQ\n"));
1159 SK_PNMI_CNT_TX_INTR(pAC
);
1160 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1161 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
1162 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1163 ClearTxIrq(pAC
, 0, TX_PRIO_HIGH
);
1165 if (IntSrc
& IRQ_EOF_SY_TX2
) {
1166 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1167 SK_DBGCAT_DRV_INT_SRC
,
1168 ("EOF SY TX2 IRQ\n"));
1169 SK_PNMI_CNT_TX_INTR(pAC
);
1170 spin_lock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
1171 FreeTxDescriptors(pAC
, 1, TX_PRIO_HIGH
);
1172 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
1173 ClearTxIrq(pAC
, 1, TX_PRIO_HIGH
);
1176 #endif /* USE_TX_COMPLETE */
1178 /* do all IO at once */
1179 if (IntSrc
& IRQ_EOF_RX1
)
1180 ClearAndStartRx(pAC
, 0);
1181 if (IntSrc
& IRQ_EOF_RX2
)
1182 ClearAndStartRx(pAC
, 1);
1183 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1184 if (IntSrc
& IRQ_EOF_AS_TX1
)
1185 ClearTxIrq(pAC
, 0, TX_PRIO_LOW
);
1186 if (IntSrc
& IRQ_EOF_AS_TX2
)
1187 ClearTxIrq(pAC
, 1, TX_PRIO_LOW
);
1189 SK_IN32(pAC
->IoBase
, B0_ISRC
, &IntSrc
);
1190 } /* while (IntSrc & IRQ_MASK != 0) */
1192 if ((IntSrc
& SPECIAL_IRQS
) || pAC
->CheckQueue
) {
1193 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_INT_SRC
,
1195 pAC
->CheckQueue
= SK_FALSE
;
1196 spin_lock(&pAC
->SlowPathLock
);
1197 if (IntSrc
& SPECIAL_IRQS
)
1198 SkGeSirqIsr(pAC
, pAC
->IoBase
, IntSrc
);
1199 SkEventDispatcher(pAC
, pAC
->IoBase
);
1200 spin_unlock(&pAC
->SlowPathLock
);
1203 * do it all again is case we cleared an interrupt that
1204 * came in after handling the ring (OUTs may be delayed
1205 * in hardware buffers, but are through after IN)
1207 ReceiveIrq(pAC
, &pAC
->RxPort
[pAC
->ActivePort
]);
1208 // ReceiveIrq(pAC, &pAC->RxPort[1]);
1211 // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1212 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1213 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
1214 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1216 spin_lock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
1217 FreeTxDescriptors(pAC
, &pAC
->TxPort
[1][TX_PRIO_LOW
]);
1218 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
1220 #if 0 /* only if sync. queues used */
1221 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1222 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
1223 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1225 spin_lock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
1226 FreeTxDescriptors(pAC
, 1, TX_PRIO_HIGH
);
1227 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
1229 #endif /* USE_TX_COMPLETE */
1231 /* IRQ is processed - Enable IRQs again*/
1232 SK_OUT32(pAC
->IoBase
, B0_IMSK
, IRQ_MASK
);
1238 /****************************************************************************
1240 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1243 * The interrupt routine is called when the network adapter
1244 * generates an interrupt. It may also be called if another device
1245 * shares this interrupt vector with the driver.
1246 * This is the same as above, but handles only one port.
1251 static void SkGeIsrOnePort(int irq
, void *dev_id
, struct pt_regs
*ptregs
)
1253 struct net_device
*dev
= (struct net_device
*)dev_id
;
1255 SK_U32 IntSrc
; /* interrupts source register contents */
1257 pAC
= (SK_AC
*) dev
->priv
;
1260 * Check and process if its our interrupt
1262 SK_IN32(pAC
->IoBase
, B0_SP_ISRC
, &IntSrc
);
1267 while (((IntSrc
& IRQ_MASK
) & ~SPECIAL_IRQS
) != 0) {
1268 #if 0 /* software irq currently not used */
1269 if (IntSrc
& IRQ_SW
) {
1270 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1271 SK_DBGCAT_DRV_INT_SRC
,
1272 ("Software IRQ\n"));
1275 if (IntSrc
& IRQ_EOF_RX1
) {
1276 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1277 SK_DBGCAT_DRV_INT_SRC
,
1279 ReceiveIrq(pAC
, &pAC
->RxPort
[0]);
1280 SK_PNMI_CNT_RX_INTR(pAC
);
1282 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1283 if (IntSrc
& IRQ_EOF_AS_TX1
) {
1284 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1285 SK_DBGCAT_DRV_INT_SRC
,
1286 ("EOF AS TX1 IRQ\n"));
1287 SK_PNMI_CNT_TX_INTR(pAC
);
1288 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1289 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
1290 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1292 #if 0 /* only if sync. queues used */
1293 if (IntSrc
& IRQ_EOF_SY_TX1
) {
1294 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1295 SK_DBGCAT_DRV_INT_SRC
,
1296 ("EOF SY TX1 IRQ\n"));
1297 SK_PNMI_CNT_TX_INTR(pAC
);
1298 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1299 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
1300 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1301 ClearTxIrq(pAC
, 0, TX_PRIO_HIGH
);
1304 #endif /* USE_TX_COMPLETE */
1306 /* do all IO at once */
1307 if (IntSrc
& IRQ_EOF_RX1
)
1308 ClearAndStartRx(pAC
, 0);
1309 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1310 if (IntSrc
& IRQ_EOF_AS_TX1
)
1311 ClearTxIrq(pAC
, 0, TX_PRIO_LOW
);
1313 SK_IN32(pAC
->IoBase
, B0_ISRC
, &IntSrc
);
1314 } /* while (IntSrc & IRQ_MASK != 0) */
1316 if ((IntSrc
& SPECIAL_IRQS
) || pAC
->CheckQueue
) {
1317 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_INT_SRC
,
1319 pAC
->CheckQueue
= SK_FALSE
;
1320 spin_lock(&pAC
->SlowPathLock
);
1321 if (IntSrc
& SPECIAL_IRQS
)
1322 SkGeSirqIsr(pAC
, pAC
->IoBase
, IntSrc
);
1323 SkEventDispatcher(pAC
, pAC
->IoBase
);
1324 spin_unlock(&pAC
->SlowPathLock
);
1327 * do it all again is case we cleared an interrupt that
1328 * came in after handling the ring (OUTs may be delayed
1329 * in hardware buffers, but are through after IN)
1331 ReceiveIrq(pAC
, &pAC
->RxPort
[0]);
1334 // #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1335 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1336 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
1337 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1339 #if 0 /* only if sync. queues used */
1340 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1341 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
1342 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1345 #endif /* USE_TX_COMPLETE */
1347 /* IRQ is processed - Enable IRQs again*/
1348 SK_OUT32(pAC
->IoBase
, B0_IMSK
, IRQ_MASK
);
1351 } /* SkGeIsrOnePort */
1354 /****************************************************************************
1356 * SkGeOpen - handle start of initialized adapter
1359 * This function starts the initialized adapter.
1360 * The board level variable is set and the adapter is
1361 * brought to full functionality.
1362 * The device flags are set for operation.
1363 * Do all necessary level 2 initialization, enable interrupts and
1364 * give start command to RLMT.
1370 static int SkGeOpen(
1371 struct net_device
*dev
)
1373 SK_AC
*pAC
; /* pointer to adapter context struct */
1374 unsigned int Flags
; /* for spin lock */
1376 SK_EVPARA EvPara
; /* an event parameter union */
1378 pAC
= (SK_AC
*) dev
->priv
;
1380 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1381 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC
));
1383 if (pAC
->BoardLevel
== 0) {
1384 /* level 1 init common modules here */
1385 if (SkGeInit(pAC
, pAC
->IoBase
, 1) != 0) {
1386 printk("%s: HWInit(1) failed\n", pAC
->dev
->name
);
1389 SkI2cInit (pAC
, pAC
->IoBase
, 1);
1390 SkEventInit (pAC
, pAC
->IoBase
, 1);
1391 SkPnmiInit (pAC
, pAC
->IoBase
, 1);
1392 SkAddrInit (pAC
, pAC
->IoBase
, 1);
1393 SkRlmtInit (pAC
, pAC
->IoBase
, 1);
1394 SkTimerInit (pAC
, pAC
->IoBase
, 1);
1395 pAC
->BoardLevel
= 1;
1398 /* level 2 init modules here */
1399 SkGeInit (pAC
, pAC
->IoBase
, 2);
1400 SkI2cInit (pAC
, pAC
->IoBase
, 2);
1401 SkEventInit (pAC
, pAC
->IoBase
, 2);
1402 SkPnmiInit (pAC
, pAC
->IoBase
, 2);
1403 SkAddrInit (pAC
, pAC
->IoBase
, 2);
1404 SkRlmtInit (pAC
, pAC
->IoBase
, 2);
1405 SkTimerInit (pAC
, pAC
->IoBase
, 2);
1406 pAC
->BoardLevel
= 2;
1408 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
1409 // Enable transmit descriptor polling.
1410 SkGePollTxD(pAC
, pAC
->IoBase
, i
, SK_TRUE
);
1411 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
1413 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
1416 // moderate only TX complete interrupts (these are not time critical)
1417 #define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)
1419 unsigned long ModBase
;
1420 ModBase
= 53125000 / INTS_PER_SEC
;
1421 SK_OUT32(pAC
->IoBase
, B2_IRQM_INI
, ModBase
);
1422 SK_OUT32(pAC
->IoBase
, B2_IRQM_MSK
, IRQ_MOD_MASK
);
1423 SK_OUT32(pAC
->IoBase
, B2_IRQM_CTRL
, TIM_START
);
1427 /* enable Interrupts */
1428 SK_OUT32(pAC
->IoBase
, B0_IMSK
, IRQ_MASK
);
1429 SK_OUT32(pAC
->IoBase
, B0_HWE_IMSK
, IRQ_HWE_MASK
);
1431 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
1432 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
1433 if (pAC
->RlmtMode
!= 0) {
1434 EvPara
.Para32
[0] = pAC
->RlmtMode
;
1435 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_MODE_CHANGE
,
1438 SkEventDispatcher(pAC
, pAC
->IoBase
);
1439 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
1443 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1444 ("SkGeOpen suceeded\n"));
1450 /****************************************************************************
1452 * SkGeClose - Stop initialized adapter
1455 * Close initialized adapter.
1459 * error code - on error
1461 static int SkGeClose(
1462 struct net_device
*dev
)
1465 unsigned int Flags
; /* for spin lock */
1469 netif_stop_queue(dev
);
1471 pAC
= (SK_AC
*) dev
->priv
;
1473 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1474 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC
));
1477 * Clear multicast table, promiscuous mode ....
1479 SkAddrMcClear(pAC
, pAC
->IoBase
, pAC
->ActivePort
, 0);
1480 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
1484 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
1485 /* disable interrupts */
1486 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
1487 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
1488 SkEventDispatcher(pAC
, pAC
->IoBase
);
1489 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
1490 /* stop the hardware */
1491 SkGeDeInit(pAC
, pAC
->IoBase
);
1492 pAC
->BoardLevel
= 0;
1494 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
1496 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
1497 /* clear all descriptor rings */
1498 ReceiveIrq(pAC
, &pAC
->RxPort
[i
]);
1499 ClearRxRing(pAC
, &pAC
->RxPort
[i
]);
1500 ClearTxRing(pAC
, &pAC
->TxPort
[i
][TX_PRIO_LOW
]);
1503 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1504 ("SkGeClose: done "));
1511 /*****************************************************************************
1513 * SkGeXmit - Linux frame transmit function
1516 * The system calls this function to send frames onto the wire.
1517 * It puts the frame in the tx descriptor ring. If the ring is
1518 * full then, the 'tbusy' flag is set.
1521 * 0, if everything is ok
1523 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1524 * allocated skb's) !!!
1526 static int SkGeXmit(struct sk_buff
*skb
, struct net_device
*dev
)
1529 int Rc
; /* return code of XmitFrame */
1531 pAC
= (SK_AC
*) dev
->priv
;
1533 Rc
= XmitFrame(pAC
, &pAC
->TxPort
[pAC
->ActivePort
][TX_PRIO_LOW
], skb
);
1535 /* Transmitter out of resources? */
1537 netif_stop_queue(dev
);
1539 /* If not taken, give buffer ownership back to the
1545 dev
->trans_start
= jiffies
;
1550 /*****************************************************************************
1552 * XmitFrame - fill one socket buffer into the transmit ring
1555 * This function puts a message into the transmit descriptor ring
1556 * if there is a descriptors left.
1557 * Linux skb's consist of only one continuous buffer.
1558 * The first step locks the ring. It is held locked
1559 * all time to avoid problems with SWITCH_../PORT_RESET.
1560 * Then the descriptoris allocated.
1561 * The second part is linking the buffer to the descriptor.
1562 * At the very last, the Control field of the descriptor
1563 * is made valid for the BMU and a start TX command is given
1567 * > 0 - on succes: the number of bytes in the message
1568 * = 0 - on resource shortage: this frame sent or dropped, now
1569 * the ring is full ( -> set tbusy)
1570 * < 0 - on failure: other problems ( -> return failure to upper layers)
1572 static int XmitFrame(
1573 SK_AC
*pAC
, /* pointer to adapter context */
1574 TX_PORT
*pTxPort
, /* pointer to struct of port to send to */
1575 struct sk_buff
*pMessage
) /* pointer to send-message */
1577 TXD
*pTxd
; /* the rxd to fill */
1582 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
1585 spin_lock_irqsave(&pTxPort
->TxDesRingLock
, Flags
);
1587 if (pTxPort
->TxdRingFree
== 0) {
1588 /* no enough free descriptors in ring at the moment */
1589 FreeTxDescriptors(pAC
, pTxPort
);
1590 if (pTxPort
->TxdRingFree
== 0) {
1591 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1592 SK_PNMI_CNT_NO_TX_BUF(pAC
);
1593 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1594 SK_DBGCAT_DRV_TX_PROGRESS
,
1595 ("XmitFrame failed\n"));
1596 /* this message can not be sent now */
1600 /* advance head counter behind descriptor needed for this frame */
1601 pTxd
= pTxPort
->pTxdRingHead
;
1602 pTxPort
->pTxdRingHead
= pTxd
->pNextTxd
;
1603 pTxPort
->TxdRingFree
--;
1604 /* the needed descriptor is reserved now */
1607 * everything allocated ok, so add buffer to descriptor
1611 DumpMsg(pMessage
, "XmitFrame");
1614 /* set up descriptor and CONTROL dword */
1615 PhysAddr
= (SK_U64
) pci_map_single(&pAC
->PciDev
,
1619 pTxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1620 pTxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1621 pTxd
->pMBuf
= pMessage
;
1622 pTxd
->TBControl
= TX_CTRL_OWN_BMU
| TX_CTRL_STF
|
1623 TX_CTRL_CHECK_DEFAULT
| TX_CTRL_SOFTWARE
|
1624 #ifdef USE_TX_COMPLETE
1625 TX_CTRL_EOF
| TX_CTRL_EOF_IRQ
| pMessage
->len
;
1627 TX_CTRL_EOF
| pMessage
->len
;
1630 if ((pTxPort
->pTxdRingPrev
->TBControl
& TX_CTRL_OWN_BMU
) == 0) {
1631 /* previous descriptor already done, so give tx start cmd */
1632 /* StartTx(pAC, pTxPort->HwAddr); */
1633 SK_OUT8(pTxPort
->HwAddr
, TX_Q_CTRL
, TX_Q_CTRL_START
);
1635 pTxPort
->pTxdRingPrev
= pTxd
;
1638 BytesSend
= pMessage
->len
;
1639 /* after releasing the lock, the skb may be immidiately freed */
1640 if (pTxPort
->TxdRingFree
!= 0) {
1641 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1645 /* ring full: set tbusy on return */
1646 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1652 /*****************************************************************************
1654 * FreeTxDescriptors - release descriptors from the descriptor ring
1657 * This function releases descriptors from a transmit ring if they
1658 * have been sent by the BMU.
1659 * If a descriptors is sent, it can be freed and the message can
1661 * The SOFTWARE controllable bit is used to prevent running around a
1662 * completely free ring for ever. If this bit is no set in the
1663 * frame (by XmitFrame), this frame has never been sent or is
1665 * The Tx descriptor ring lock must be held while calling this function !!!
1670 static void FreeTxDescriptors(
1671 SK_AC
*pAC
, /* pointer to the adapter context */
1672 TX_PORT
*pTxPort
) /* pointer to destination port structure */
1674 TXD
*pTxd
; /* pointer to the checked descriptor */
1675 TXD
*pNewTail
; /* pointer to 'end' of the ring */
1676 SK_U32 Control
; /* TBControl field of descriptor */
1677 SK_U64 PhysAddr
; /* address of DMA mapping */
1679 pNewTail
= pTxPort
->pTxdRingTail
;
1683 * loop forever; exits if TX_CTRL_SOFTWARE bit not set in start frame
1684 * or TX_CTRL_OWN_BMU bit set in any frame
1687 Control
= pTxd
->TBControl
;
1688 if ((Control
& TX_CTRL_SOFTWARE
) == 0) {
1690 * software controllable bit is set in first
1691 * fragment when given to BMU. Not set means that
1692 * this fragment was never sent or is already
1693 * freed ( -> ring completely free now).
1695 pTxPort
->pTxdRingTail
= pTxd
;
1696 netif_start_queue(pAC
->dev
);
1699 if (Control
& TX_CTRL_OWN_BMU
) {
1700 pTxPort
->pTxdRingTail
= pTxd
;
1701 if (pTxPort
->TxdRingFree
> 0) {
1702 netif_start_queue(pAC
->dev
);
1707 /* release the DMA mapping */
1708 PhysAddr
= ((SK_U64
) pTxd
->VDataHigh
) << (SK_U64
) 32;
1709 PhysAddr
|= (SK_U64
) pTxd
->VDataLow
;
1710 pci_unmap_single(&pAC
->PciDev
, PhysAddr
,
1715 DEV_KFREE_SKB_ANY(pTxd
->pMBuf
);
1716 pTxPort
->TxdRingFree
++;
1717 pTxd
->TBControl
&= ~TX_CTRL_SOFTWARE
;
1718 pTxd
= pTxd
->pNextTxd
; /* point behind fragment with EOF */
1719 } /* while(forever) */
1720 } /* FreeTxDescriptors */
1723 /*****************************************************************************
1725 * FillRxRing - fill the receive ring with valid descriptors
1728 * This function fills the receive ring descriptors with data
1729 * segments and makes them valid for the BMU.
1730 * The active ring is filled completely, if possible.
1731 * The non-active ring is filled only partial to save memory.
1733 * Description of rx ring structure:
1734 * head - points to the descriptor which will be used next by the BMU
1735 * tail - points to the next descriptor to give to the BMU
1739 static void FillRxRing(
1740 SK_AC
*pAC
, /* pointer to the adapter context */
1741 RX_PORT
*pRxPort
) /* ptr to port struct for which the ring
1746 spin_lock_irqsave(&pRxPort
->RxDesRingLock
, Flags
);
1747 while (pRxPort
->RxdRingFree
> pRxPort
->RxFillLimit
) {
1748 if(!FillRxDescriptor(pAC
, pRxPort
))
1751 spin_unlock_irqrestore(&pRxPort
->RxDesRingLock
, Flags
);
1755 /*****************************************************************************
1757 * FillRxDescriptor - fill one buffer into the receive ring
1760 * The function allocates a new receive buffer and
1761 * puts it into the next descriptor.
1764 * SK_TRUE - a buffer was added to the ring
1765 * SK_FALSE - a buffer could not be added
1767 static SK_BOOL
FillRxDescriptor(
1768 SK_AC
*pAC
, /* pointer to the adapter context struct */
1769 RX_PORT
*pRxPort
) /* ptr to port struct of ring to fill */
1771 struct sk_buff
*pMsgBlock
; /* pointer to a new message block */
1772 RXD
*pRxd
; /* the rxd to fill */
1773 SK_U16 Length
; /* data fragment length */
1774 SK_U64 PhysAddr
; /* physical address of a rx buffer */
1776 pMsgBlock
= alloc_skb(pAC
->RxBufSize
, GFP_ATOMIC
);
1777 if (pMsgBlock
== NULL
) {
1778 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1779 SK_DBGCAT_DRV_ENTRY
,
1780 ("%s: Allocation of rx buffer failed !\n",
1782 SK_PNMI_CNT_NO_RX_BUF(pAC
);
1785 skb_reserve(pMsgBlock
, 2); /* to align IP frames */
1786 /* skb allocated ok, so add buffer */
1787 pRxd
= pRxPort
->pRxdRingTail
;
1788 pRxPort
->pRxdRingTail
= pRxd
->pNextRxd
;
1789 pRxPort
->RxdRingFree
--;
1790 Length
= pAC
->RxBufSize
;
1791 PhysAddr
= (SK_U64
) pci_map_single(&pAC
->PciDev
,
1794 PCI_DMA_FROMDEVICE
);
1795 pRxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1796 pRxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1797 pRxd
->pMBuf
= pMsgBlock
;
1798 pRxd
->RBControl
= RX_CTRL_OWN_BMU
| RX_CTRL_STF
|
1799 RX_CTRL_EOF_IRQ
| RX_CTRL_CHECK_CSUM
| Length
;
1802 } /* FillRxDescriptor */
1805 /*****************************************************************************
1807 * ReQueueRxBuffer - fill one buffer back into the receive ring
1810 * Fill a given buffer back into the rx ring. The buffer
1811 * has been previously allocated and aligned, and its phys.
1812 * address calculated, so this is no more necessary.
1816 static void ReQueueRxBuffer(
1817 SK_AC
*pAC
, /* pointer to the adapter context struct */
1818 RX_PORT
*pRxPort
, /* ptr to port struct of ring to fill */
1819 struct sk_buff
*pMsg
, /* pointer to the buffer */
1820 SK_U32 PhysHigh
, /* phys address high dword */
1821 SK_U32 PhysLow
) /* phys address low dword */
1823 RXD
*pRxd
; /* the rxd to fill */
1824 SK_U16 Length
; /* data fragment length */
1826 pRxd
= pRxPort
->pRxdRingTail
;
1827 pRxPort
->pRxdRingTail
= pRxd
->pNextRxd
;
1828 pRxPort
->RxdRingFree
--;
1829 Length
= pAC
->RxBufSize
;
1830 pRxd
->VDataLow
= PhysLow
;
1831 pRxd
->VDataHigh
= PhysHigh
;
1833 pRxd
->RBControl
= RX_CTRL_OWN_BMU
| RX_CTRL_STF
|
1834 RX_CTRL_EOF_IRQ
| RX_CTRL_CHECK_CSUM
| Length
;
1836 } /* ReQueueRxBuffer */
1839 /*****************************************************************************
1841 * ReceiveIrq - handle a receive IRQ
1844 * This function is called when a receive IRQ is set.
1845 * It walks the receive descriptor ring and sends up all
1846 * frames that are complete.
1850 static void ReceiveIrq(
1851 SK_AC
*pAC
, /* pointer to adapter context */
1852 RX_PORT
*pRxPort
) /* pointer to receive port struct */
1854 RXD
*pRxd
; /* pointer to receive descriptors */
1855 SK_U32 Control
; /* control field of descriptor */
1856 struct sk_buff
*pMsg
; /* pointer to message holding frame */
1857 struct sk_buff
*pNewMsg
; /* pointer to a new message for copying frame */
1858 int FrameLength
; /* total length of received frame */
1859 SK_MBUF
*pRlmtMbuf
; /* ptr to a buffer for giving a frame to rlmt */
1860 SK_EVPARA EvPara
; /* an event parameter union */
1861 int PortIndex
= pRxPort
->PortIndex
;
1862 unsigned int Offset
;
1863 unsigned int NumBytes
;
1864 unsigned int ForRlmt
;
1868 unsigned short Csum1
;
1869 unsigned short Csum2
;
1870 unsigned short Type
;
1876 /* do forever; exit if RX_CTRL_OWN_BMU found */
1877 while (pRxPort
->RxdRingFree
< pAC
->RxDescrPerRing
) {
1878 pRxd
= pRxPort
->pRxdRingHead
;
1880 Control
= pRxd
->RBControl
;
1882 /* check if this descriptor is ready */
1883 if ((Control
& RX_CTRL_OWN_BMU
) != 0) {
1884 /* this descriptor is not yet ready */
1885 FillRxRing(pAC
, pRxPort
);
1889 /* get length of frame and check it */
1890 FrameLength
= Control
& RX_CTRL_LEN_MASK
;
1891 if (FrameLength
> pAC
->RxBufSize
)
1894 /* check for STF and EOF */
1895 if ((Control
& (RX_CTRL_STF
| RX_CTRL_EOF
)) !=
1896 (RX_CTRL_STF
| RX_CTRL_EOF
))
1899 /* here we have a complete frame in the ring */
1903 * if short frame then copy data to reduce memory waste
1906 if (FrameLength
< SK_COPY_THRESHOLD
) {
1907 pNewMsg
= alloc_skb(FrameLength
+2, GFP_ATOMIC
);
1908 if (pNewMsg
!= NULL
) {
1909 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
1910 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
1912 /* use new skb and copy data */
1913 skb_reserve(pNewMsg
, 2);
1914 skb_put(pNewMsg
, FrameLength
);
1915 pci_dma_sync_single(&pAC
->PciDev
,
1916 (dma_addr_t
) PhysAddr
,
1918 PCI_DMA_FROMDEVICE
);
1919 eth_copy_and_sum(pNewMsg
, pMsg
->data
,
1921 ReQueueRxBuffer(pAC
, pRxPort
, pMsg
,
1922 pRxd
->VDataHigh
, pRxd
->VDataLow
);
1928 * if large frame, or SKB allocation failed, pass
1929 * the SKB directly to the networking
1931 if (pNewMsg
== NULL
) {
1932 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
1933 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
1935 /* release the DMA mapping */
1936 pci_unmap_single(&pAC
->PciDev
,
1939 PCI_DMA_FROMDEVICE
);
1941 /* set length in message */
1942 skb_put(pMsg
, FrameLength
);
1943 /* hardware checksum */
1944 Type
= ntohs(*((short*)&pMsg
->data
[12]));
1945 if (Type
== 0x800) {
1946 Csum1
=le16_to_cpu(pRxd
->TcpSums
& 0xffff);
1947 Csum2
=le16_to_cpu((pRxd
->TcpSums
>> 16) & 0xffff);
1948 if ((Csum1
& 0xfffe) && (Csum2
& 0xfffe)) {
1949 Result
= SkCsGetReceiveInfo(pAC
,
1953 SKCS_STATUS_IP_FRAGMENT
||
1955 SKCS_STATUS_IP_CSUM_OK
||
1957 SKCS_STATUS_TCP_CSUM_OK
||
1959 SKCS_STATUS_UDP_CSUM_OK
) {
1961 CHECKSUM_UNNECESSARY
;
1963 } /* checksum calculation valid */
1965 } /* frame > SK_COPY_TRESHOLD */
1967 FrameStat
= pRxd
->FrameStat
;
1968 if ((FrameStat
& XMR_FS_LNG_ERR
) != 0) {
1969 /* jumbo frame, count to correct statistic */
1970 SK_PNMI_CNT_RX_LONGFRAMES(pAC
, pRxPort
->PortIndex
);
1972 pRxd
= pRxd
->pNextRxd
;
1973 pRxPort
->pRxdRingHead
= pRxd
;
1974 pRxPort
->RxdRingFree
++;
1975 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_RX_PROGRESS
,
1976 ("Received frame of length %d on port %d\n",
1977 FrameLength
, PortIndex
));
1978 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_RX_PROGRESS
,
1979 ("Number of free rx descriptors: %d\n",
1980 pRxPort
->RxdRingFree
));
1982 if ((Control
& RX_CTRL_STAT_VALID
) == RX_CTRL_STAT_VALID
&&
1983 (FrameStat
& XMR_FS_ANY_ERR
) == 0) {
1984 // was the following, changed to allow VLAN support
1985 // (XMR_FS_ANY_ERR | XMR_FS_1L_VLAN | XMR_FS_2L_VLAN)
1986 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1987 SK_DBGCAT_DRV_RX_PROGRESS
,("V"));
1988 ForRlmt
= SK_RLMT_RX_PROTOCOL
;
1989 IsBc
= (FrameStat
& XMR_FS_BC
)==XMR_FS_BC
;
1990 SK_RLMT_PRE_LOOKAHEAD(pAC
, PortIndex
, FrameLength
,
1991 IsBc
, &Offset
, &NumBytes
);
1992 if (NumBytes
!= 0) {
1993 IsMc
= (FrameStat
& XMR_FS_MC
)==XMR_FS_MC
;
1994 SK_RLMT_LOOKAHEAD(pAC
, PortIndex
,
1995 &pMsg
->data
[Offset
],
1996 IsBc
, IsMc
, &ForRlmt
);
1998 if (ForRlmt
== SK_RLMT_RX_PROTOCOL
) {
1999 /* send up only frames from active port */
2000 if (PortIndex
== pAC
->ActivePort
) {
2001 /* frame for upper layer */
2002 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2003 SK_DBGCAT_DRV_RX_PROGRESS
,
2006 DumpMsg(pMsg
, "Rx");
2008 pMsg
->dev
= pAC
->dev
;
2009 pMsg
->protocol
= eth_type_trans(pMsg
,
2011 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC
,
2014 pAC
->dev
->last_rx
= jiffies
;
2018 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2019 SK_DBGCAT_DRV_RX_PROGRESS
,
2021 DEV_KFREE_SKB_IRQ(pMsg
);
2023 } /* if not for rlmt */
2025 /* packet for rlmt */
2026 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2027 SK_DBGCAT_DRV_RX_PROGRESS
, ("R"));
2028 pRlmtMbuf
= SkDrvAllocRlmtMbuf(pAC
,
2029 pAC
->IoBase
, FrameLength
);
2030 if (pRlmtMbuf
!= NULL
) {
2031 pRlmtMbuf
->pNext
= NULL
;
2032 pRlmtMbuf
->Length
= FrameLength
;
2033 pRlmtMbuf
->PortIdx
= PortIndex
;
2034 EvPara
.pParaPtr
= pRlmtMbuf
;
2035 memcpy((char*)(pRlmtMbuf
->pData
),
2036 (char*)(pMsg
->data
),
2038 SkEventQueue(pAC
, SKGE_RLMT
,
2039 SK_RLMT_PACKET_RECEIVED
,
2041 pAC
->CheckQueue
= SK_TRUE
;
2042 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2043 SK_DBGCAT_DRV_RX_PROGRESS
,
2046 if ((pAC
->dev
->flags
&
2047 (IFF_PROMISC
| IFF_ALLMULTI
)) != 0 ||
2048 (ForRlmt
& SK_RLMT_RX_PROTOCOL
) ==
2049 SK_RLMT_RX_PROTOCOL
) {
2050 pMsg
->dev
= pAC
->dev
;
2051 pMsg
->protocol
= eth_type_trans(pMsg
,
2054 pAC
->dev
->last_rx
= jiffies
;
2057 DEV_KFREE_SKB_IRQ(pMsg
);
2060 } /* if packet for rlmt */
2061 } /* if valid frame */
2063 /* there is a receive error in this frame */
2064 if ((FrameStat
& XMR_FS_1L_VLAN
) != 0) {
2065 printk("%s: Received frame"
2066 " with VLAN Level 1 header, check"
2067 " switch configuration\n",
2070 if ((FrameStat
& XMR_FS_2L_VLAN
) != 0) {
2071 printk("%s: Received frame"
2072 " with VLAN Level 2 header, check"
2073 " switch configuration\n",
2076 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2077 SK_DBGCAT_DRV_RX_PROGRESS
,
2078 ("skge: Error in received frame, dropped!\n"
2079 "Control: %x\nRxStat: %x\n",
2080 Control
, FrameStat
));
2081 DEV_KFREE_SKB_IRQ(pMsg
);
2084 FillRxRing(pAC
, pRxPort
);
2085 /* do not start if called from Close */
2086 if (pAC
->BoardLevel
> 0) {
2087 ClearAndStartRx(pAC
, PortIndex
);
2092 /* remove error frame */
2093 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ERROR
,
2094 ("Schrottdescriptor, length: 0x%x\n", FrameLength
));
2096 /* release the DMA mapping */
2097 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2098 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2099 pci_unmap_single(&pAC
->PciDev
,
2102 PCI_DMA_FROMDEVICE
);
2103 DEV_KFREE_SKB_IRQ(pRxd
->pMBuf
);
2105 pRxPort
->RxdRingFree
++;
2106 pRxPort
->pRxdRingHead
= pRxd
->pNextRxd
;
2112 /*****************************************************************************
2114 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2117 * This function sends a start command and a clear interrupt
2118 * command for one receive queue to the BMU.
2123 static void ClearAndStartRx(
2124 SK_AC
*pAC
, /* pointer to the adapter context */
2125 int PortIndex
) /* index of the receive port (XMAC) */
2127 SK_OUT8(pAC
->IoBase
, RxQueueAddr
[PortIndex
]+RX_Q_CTRL
,
2128 RX_Q_CTRL_START
| RX_Q_CTRL_CLR_I_EOF
);
2129 } /* ClearAndStartRx */
2132 /*****************************************************************************
2134 * ClearTxIrq - give a clear transmit IRQ command to BMU
2137 * This function sends a clear tx IRQ command for one
2138 * transmit queue to the BMU.
2142 static void ClearTxIrq(
2143 SK_AC
*pAC
, /* pointer to the adapter context */
2144 int PortIndex
, /* index of the transmit port (XMAC) */
2145 int Prio
) /* priority or normal queue */
2147 SK_OUT8(pAC
->IoBase
, TxQueueAddr
[PortIndex
][Prio
]+TX_Q_CTRL
,
2148 TX_Q_CTRL_CLR_I_EOF
);
2152 /*****************************************************************************
2154 * ClearRxRing - remove all buffers from the receive ring
2157 * This function removes all receive buffers from the ring.
2158 * The receive BMU must be stopped before calling this function.
2162 static void ClearRxRing(
2163 SK_AC
*pAC
, /* pointer to adapter context */
2164 RX_PORT
*pRxPort
) /* pointer to rx port struct */
2166 RXD
*pRxd
; /* pointer to the current descriptor */
2170 if (pRxPort
->RxdRingFree
== pAC
->RxDescrPerRing
) {
2173 spin_lock_irqsave(&pRxPort
->RxDesRingLock
, Flags
);
2174 pRxd
= pRxPort
->pRxdRingHead
;
2176 if (pRxd
->pMBuf
!= NULL
) {
2177 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2178 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2179 pci_unmap_single(&pAC
->PciDev
,
2182 PCI_DMA_FROMDEVICE
);
2183 DEV_KFREE_SKB(pRxd
->pMBuf
);
2186 pRxd
->RBControl
&= RX_CTRL_OWN_BMU
;
2187 pRxd
= pRxd
->pNextRxd
;
2188 pRxPort
->RxdRingFree
++;
2189 } while (pRxd
!= pRxPort
->pRxdRingTail
);
2190 pRxPort
->pRxdRingTail
= pRxPort
->pRxdRingHead
;
2191 spin_unlock_irqrestore(&pRxPort
->RxDesRingLock
, Flags
);
2195 /*****************************************************************************
2197 * ClearTxRing - remove all buffers from the transmit ring
2200 * This function removes all transmit buffers from the ring.
2201 * The transmit BMU must be stopped before calling this function
2202 * and transmitting at the upper level must be disabled.
2203 * The BMU own bit of all descriptors is cleared, the rest is
2204 * done by calling FreeTxDescriptors.
2208 static void ClearTxRing(
2209 SK_AC
*pAC
, /* pointer to adapter context */
2210 TX_PORT
*pTxPort
) /* pointer to tx prt struct */
2212 TXD
*pTxd
; /* pointer to the current descriptor */
2216 spin_lock_irqsave(&pTxPort
->TxDesRingLock
, Flags
);
2217 pTxd
= pTxPort
->pTxdRingHead
;
2218 for (i
=0; i
<pAC
->TxDescrPerRing
; i
++) {
2219 pTxd
->TBControl
&= ~TX_CTRL_OWN_BMU
;
2220 pTxd
= pTxd
->pNextTxd
;
2222 FreeTxDescriptors(pAC
, pTxPort
);
2223 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
2227 /*****************************************************************************
2229 * SetQueueSizes - configure the sizes of rx and tx queues
2232 * This function assigns the sizes for active and passive port
2233 * to the appropriate HWinit structure variables.
2234 * The passive port(s) get standard values, all remaining RAM
2235 * is given to the active port.
2236 * The queue sizes are in kbyte and must be multiple of 8.
2237 * The limits for the number of buffers filled into the rx rings
2238 * is also set in this routine.
2243 static void SetQueueSizes(
2244 SK_AC
*pAC
) /* pointer to the adapter context */
2246 int StandbyRam
; /* adapter RAM used for a standby port */
2247 int RemainingRam
; /* adapter RAM available for the active port */
2248 int RxRam
; /* RAM used for the active port receive queue */
2249 int i
; /* loop counter */
2251 StandbyRam
= SK_RLMT_STANDBY_QRXSIZE
+ SK_RLMT_STANDBY_QXASIZE
+
2252 SK_RLMT_STANDBY_QXSSIZE
;
2253 RemainingRam
= pAC
->GIni
.GIRamSize
-
2254 (pAC
->GIni
.GIMacsFound
-1) * StandbyRam
;
2255 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2256 pAC
->GIni
.GP
[i
].PRxQSize
= SK_RLMT_STANDBY_QRXSIZE
;
2257 pAC
->GIni
.GP
[i
].PXSQSize
= SK_RLMT_STANDBY_QXSSIZE
;
2258 pAC
->GIni
.GP
[i
].PXAQSize
= SK_RLMT_STANDBY_QXASIZE
;
2260 RxRam
= (RemainingRam
* 8 / 10) & ~7;
2261 pAC
->GIni
.GP
[pAC
->ActivePort
].PRxQSize
= RxRam
;
2262 pAC
->GIni
.GP
[pAC
->ActivePort
].PXSQSize
= 0;
2263 pAC
->GIni
.GP
[pAC
->ActivePort
].PXAQSize
=
2264 (RemainingRam
- RxRam
) & ~7;
2265 pAC
->RxQueueSize
= RxRam
;
2266 pAC
->TxSQueueSize
= 0;
2267 pAC
->TxAQueueSize
= (RemainingRam
- RxRam
) & ~7;
2268 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2269 ("queue sizes settings - rx:%d txA:%d txS:%d\n",
2270 pAC
->RxQueueSize
,pAC
->TxAQueueSize
, pAC
->TxSQueueSize
));
2272 for (i
=0; i
<SK_MAX_MACS
; i
++) {
2273 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
;
2275 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2276 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
- 100;
2279 * Do not set the Limit to 0, because this could cause
2280 * wrap around with ReQueue'ed buffers (a buffer could
2281 * be requeued in the same position, made accessable to
2282 * the hardware, and the hardware could change its
2285 pAC
->RxPort
[pAC
->ActivePort
].RxFillLimit
= 1;
2288 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2289 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
2290 ("i: %d, RxQSize: %d, PXSQsize: %d, PXAQSize: %d\n",
2292 pAC
->GIni
.GP
[i
].PRxQSize
,
2293 pAC
->GIni
.GP
[i
].PXSQSize
,
2294 pAC
->GIni
.GP
[i
].PXAQSize
));
2297 } /* SetQueueSizes */
2300 /*****************************************************************************
2302 * SkGeSetMacAddr - Set the hardware MAC address
2305 * This function sets the MAC address used by the adapter.
2308 * 0, if everything is ok
2311 static int SkGeSetMacAddr(struct net_device
*dev
, void *p
)
2313 SK_AC
*pAC
= (SK_AC
*) dev
->priv
;
2314 struct sockaddr
*addr
= p
;
2317 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2318 ("SkGeSetMacAddr starts now...\n"));
2319 if(netif_running(dev
)) {
2322 memcpy(dev
->dev_addr
, addr
->sa_data
,dev
->addr_len
);
2324 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2325 SkAddrOverride(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2326 (SK_MAC_ADDR
*)dev
->dev_addr
, SK_ADDR_VIRTUAL_ADDRESS
);
2328 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2330 } /* SkGeSetMacAddr */
2333 /*****************************************************************************
2335 * SkGeSetRxMode - set receive mode
2338 * This function sets the receive mode of an adapter. The adapter
2339 * supports promiscuous mode, allmulticast mode and a number of
2340 * multicast addresses. If more multicast addresses the available
2341 * are selected, a hash function in the hardware is used.
2344 * 0, if everything is ok
2347 static void SkGeSetRxMode(struct net_device
*dev
)
2350 struct dev_mc_list
*pMcList
;
2354 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2355 ("SkGeSetRxMode starts now... "));
2356 pAC
= (SK_AC
*) dev
->priv
;
2358 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2359 if (dev
->flags
& IFF_PROMISC
) {
2360 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2361 ("PROMISCUOUS mode\n"));
2362 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2364 } else if (dev
->flags
& IFF_ALLMULTI
) {
2365 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2366 ("ALLMULTI mode\n"));
2367 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2368 SK_PROM_MODE_ALL_MC
);
2370 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2372 SkAddrMcClear(pAC
, pAC
->IoBase
, pAC
->ActivePort
, 0);
2374 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2375 ("Number of MC entries: %d ", dev
->mc_count
));
2377 pMcList
= dev
->mc_list
;
2378 for (i
=0; i
<dev
->mc_count
; i
++, pMcList
= pMcList
->next
) {
2379 SkAddrMcAdd(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2380 (SK_MAC_ADDR
*)pMcList
->dmi_addr
, 0);
2381 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_MCA
,
2382 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2383 pMcList
->dmi_addr
[0],
2384 pMcList
->dmi_addr
[1],
2385 pMcList
->dmi_addr
[2],
2386 pMcList
->dmi_addr
[3],
2387 pMcList
->dmi_addr
[4],
2388 pMcList
->dmi_addr
[5]));
2390 SkAddrMcUpdate(pAC
, pAC
->IoBase
, pAC
->ActivePort
);
2393 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2396 } /* SkGeSetRxMode */
2399 /*****************************************************************************
2401 * SkGeChangeMtu - set the MTU to another value
2404 * This function sets is called whenever the MTU size is changed
2405 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2406 * ethernet MTU size, long frame support is activated.
2409 * 0, if everything is ok
2412 static int SkGeChangeMtu(struct net_device
*dev
, int NewMtu
)
2419 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2420 ("SkGeChangeMtu starts now...\n"));
2422 pAC
= (SK_AC
*) dev
->priv
;
2423 if ((NewMtu
< 68) || (NewMtu
> SK_JUMBO_MTU
)) {
2427 pAC
->RxBufSize
= NewMtu
+ 32;
2430 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2431 ("New MTU: %d\n", NewMtu
));
2433 /* prevent reconfiguration while changing the MTU */
2435 /* disable interrupts */
2436 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
2437 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2438 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
2439 SkEventDispatcher(pAC
, pAC
->IoBase
);
2441 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2442 spin_lock(&pAC
->TxPort
[i
][TX_PRIO_LOW
].TxDesRingLock
);
2444 netif_stop_queue(pAC
->dev
);
2447 * adjust number of rx buffers allocated
2449 if (NewMtu
> 1500) {
2450 /* use less rx buffers */
2451 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2452 if (i
== pAC
->ActivePort
)
2453 pAC
->RxPort
[i
].RxFillLimit
=
2454 pAC
->RxDescrPerRing
- 100;
2456 pAC
->RxPort
[i
].RxFillLimit
=
2457 pAC
->RxDescrPerRing
- 10;
2462 /* use normal anoumt of rx buffers */
2463 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2464 if (i
== pAC
->ActivePort
)
2465 pAC
->RxPort
[i
].RxFillLimit
= 1;
2467 pAC
->RxPort
[i
].RxFillLimit
=
2468 pAC
->RxDescrPerRing
- 100;
2472 SkGeDeInit(pAC
, pAC
->IoBase
);
2475 * enable/disable hardware support for long frames
2477 if (NewMtu
> 1500) {
2478 pAC
->GIni
.GIPortUsage
= SK_JUMBO_LINK
;
2479 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2480 pAC
->GIni
.GP
[i
].PRxCmd
=
2481 XM_RX_STRIP_FCS
| XM_RX_LENERR_OK
;
2485 pAC
->GIni
.GIPortUsage
= SK_RED_LINK
;
2486 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2487 pAC
->GIni
.GP
[i
].PRxCmd
=
2488 XM_RX_STRIP_FCS
| XM_RX_LENERR_OK
;
2492 SkGeInit( pAC
, pAC
->IoBase
, 1);
2493 SkI2cInit( pAC
, pAC
->IoBase
, 1);
2494 SkEventInit(pAC
, pAC
->IoBase
, 1);
2495 SkPnmiInit( pAC
, pAC
->IoBase
, 1);
2496 SkAddrInit( pAC
, pAC
->IoBase
, 1);
2497 SkRlmtInit( pAC
, pAC
->IoBase
, 1);
2498 SkTimerInit(pAC
, pAC
->IoBase
, 1);
2500 SkGeInit( pAC
, pAC
->IoBase
, 2);
2501 SkI2cInit( pAC
, pAC
->IoBase
, 2);
2502 SkEventInit(pAC
, pAC
->IoBase
, 2);
2503 SkPnmiInit( pAC
, pAC
->IoBase
, 2);
2504 SkAddrInit( pAC
, pAC
->IoBase
, 2);
2505 SkRlmtInit( pAC
, pAC
->IoBase
, 2);
2506 SkTimerInit(pAC
, pAC
->IoBase
, 2);
2509 * clear and reinit the rx rings here
2511 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2512 ReceiveIrq(pAC
, &pAC
->RxPort
[i
]);
2513 ClearRxRing(pAC
, &pAC
->RxPort
[i
]);
2514 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
2516 // Enable transmit descriptor polling.
2517 SkGePollTxD(pAC
, pAC
->IoBase
, i
, SK_TRUE
);
2518 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
2521 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
2525 unsigned long ModBase
;
2526 ModBase
= 53125000 / INTS_PER_SEC
;
2527 SK_OUT32(pAC
->IoBase
, B2_IRQM_INI
, ModBase
);
2528 SK_OUT32(pAC
->IoBase
, B2_IRQM_MSK
, IRQ_MOD_MASK
);
2529 SK_OUT32(pAC
->IoBase
, B2_IRQM_CTRL
, TIM_START
);
2533 netif_start_queue(pAC
->dev
);
2534 for (i
=pAC
->GIni
.GIMacsFound
-1; i
>=0; i
--) {
2535 spin_unlock(&pAC
->TxPort
[i
][TX_PRIO_LOW
].TxDesRingLock
);
2538 /* enable Interrupts */
2539 SK_OUT32(pAC
->IoBase
, B0_IMSK
, IRQ_MASK
);
2540 SK_OUT32(pAC
->IoBase
, B0_HWE_IMSK
, IRQ_HWE_MASK
);
2542 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
2543 SkEventDispatcher(pAC
, pAC
->IoBase
);
2546 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2549 } /* SkGeChangeMtu */
2552 /*****************************************************************************
2554 * SkGeStats - return ethernet device statistics
2557 * This function return statistic data about the ethernet device
2558 * to the operating system.
2561 * pointer to the statistic structure.
2563 static struct net_device_stats
*SkGeStats(struct net_device
*dev
)
2565 SK_AC
*pAC
= (SK_AC
*) dev
->priv
;
2566 SK_PNMI_STRUCT_DATA
*pPnmiStruct
; /* structure for all Pnmi-Data */
2567 SK_PNMI_STAT
*pPnmiStat
; /* pointer to virtual XMAC stat. data */SK_PNMI_CONF
*pPnmiConf
; /* pointer to virtual link config. */
2568 unsigned int Size
; /* size of pnmi struct */
2569 unsigned int Flags
; /* for spin lock */
2571 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2572 ("SkGeStats starts now...\n"));
2573 pPnmiStruct
= &pAC
->PnmiStruct
;
2574 memset(pPnmiStruct
, 0, sizeof(SK_PNMI_STRUCT_DATA
));
2575 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2576 Size
= SK_PNMI_STRUCT_SIZE
;
2577 SkPnmiGetStruct(pAC
, pAC
->IoBase
, pPnmiStruct
, &Size
);
2578 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2579 pPnmiStat
= &pPnmiStruct
->Stat
[0];
2580 pPnmiConf
= &pPnmiStruct
->Conf
[0];
2582 pAC
->stats
.rx_packets
= (SK_U32
) pPnmiStruct
->RxDeliveredCts
& 0xFFFFFFFF;
2583 pAC
->stats
.tx_packets
= (SK_U32
) pPnmiStat
->StatTxOkCts
& 0xFFFFFFFF;
2584 pAC
->stats
.rx_bytes
= (SK_U32
) pPnmiStruct
->RxOctetsDeliveredCts
;
2585 pAC
->stats
.tx_bytes
= (SK_U32
) pPnmiStat
->StatTxOctetsOkCts
;
2586 pAC
->stats
.rx_errors
= (SK_U32
) pPnmiStruct
->InErrorsCts
& 0xFFFFFFFF;
2587 pAC
->stats
.tx_errors
= (SK_U32
) pPnmiStat
->StatTxSingleCollisionCts
& 0xFFFFFFFF;
2588 pAC
->stats
.rx_dropped
= (SK_U32
) pPnmiStruct
->RxNoBufCts
& 0xFFFFFFFF;
2589 pAC
->stats
.tx_dropped
= (SK_U32
) pPnmiStruct
->TxNoBufCts
& 0xFFFFFFFF;
2590 pAC
->stats
.multicast
= (SK_U32
) pPnmiStat
->StatRxMulticastOkCts
& 0xFFFFFFFF;
2591 pAC
->stats
.collisions
= (SK_U32
) pPnmiStat
->StatTxSingleCollisionCts
& 0xFFFFFFFF;
2593 /* detailed rx_errors: */
2594 pAC
->stats
.rx_length_errors
= (SK_U32
) pPnmiStat
->StatRxRuntCts
& 0xFFFFFFFF;
2595 pAC
->stats
.rx_over_errors
= (SK_U32
) pPnmiStat
->StatRxFifoOverflowCts
& 0xFFFFFFFF;
2596 pAC
->stats
.rx_crc_errors
= (SK_U32
) pPnmiStat
->StatRxFcsCts
& 0xFFFFFFFF;
2597 pAC
->stats
.rx_frame_errors
= (SK_U32
) pPnmiStat
->StatRxFramingCts
& 0xFFFFFFFF;
2598 pAC
->stats
.rx_fifo_errors
= (SK_U32
) pPnmiStat
->StatRxFifoOverflowCts
& 0xFFFFFFFF;
2599 pAC
->stats
.rx_missed_errors
= (SK_U32
) pPnmiStat
->StatRxMissedCts
& 0xFFFFFFFF;
2601 /* detailed tx_errors */
2602 pAC
->stats
.tx_aborted_errors
= (SK_U32
) 0;
2603 pAC
->stats
.tx_carrier_errors
= (SK_U32
) pPnmiStat
->StatTxCarrierCts
& 0xFFFFFFFF;
2604 pAC
->stats
.tx_fifo_errors
= (SK_U32
) pPnmiStat
->StatTxFifoUnderrunCts
& 0xFFFFFFFF;
2605 pAC
->stats
.tx_heartbeat_errors
= (SK_U32
) pPnmiStat
->StatTxCarrierCts
& 0xFFFFFFFF;
2606 pAC
->stats
.tx_window_errors
= (SK_U32
) 0;
2608 return(&pAC
->stats
);
2612 /*****************************************************************************
2614 * SkGeIoctl - IO-control function
2617 * This function is called if an ioctl is issued on the device.
2618 * There are three subfunction for reading, writing and test-writing
2619 * the private MIB data structure (usefull for SysKonnect-internal tools).
2622 * 0, if everything is ok
2625 static int SkGeIoctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2629 unsigned int Err
= 0;
2632 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2633 ("SkGeIoctl starts now...\n"));
2634 pAC
= (SK_AC
*) dev
->priv
;
2636 if(copy_from_user(&Ioctl
, rq
->ifr_data
, sizeof(SK_GE_IOCTL
))) {
2641 case SK_IOCTL_SETMIB
:
2642 case SK_IOCTL_PRESETMIB
:
2643 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
2644 case SK_IOCTL_GETMIB
:
2645 if(copy_from_user(&pAC
->PnmiStruct
, Ioctl
.pData
,
2646 Ioctl
.Len
<sizeof(pAC
->PnmiStruct
)?
2647 Ioctl
.Len
: sizeof(pAC
->PnmiStruct
))) {
2650 Size
= SkGeIocMib(pAC
, Ioctl
.Len
, cmd
);
2651 if(copy_to_user(Ioctl
.pData
, &pAC
->PnmiStruct
,
2652 Ioctl
.Len
<Size
? Ioctl
.Len
: Size
)) {
2656 if(copy_to_user(rq
->ifr_data
, &Ioctl
, sizeof(SK_GE_IOCTL
))) {
2667 /*****************************************************************************
2669 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2672 * This function reads/writes the MIB data using PNMI (Private Network
2673 * Management Interface).
2674 * The destination for the data must be provided with the
2675 * ioctl call and is given to the driver in the form of
2676 * a user space address.
2677 * Copying from the user-provided data area into kernel messages
2678 * and back is done by copy_from_user and copy_to_user calls in
2682 * returned size from PNMI call
2684 static int SkGeIocMib(
2685 SK_AC
*pAC
, /* pointer to the adapter context */
2686 unsigned int Size
, /* length of ioctl data */
2687 int mode
) /* flag for set/preset */
2689 unsigned int Flags
; /* for spin lock */
2691 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2692 ("SkGeIocMib starts now...\n"));
2694 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2696 case SK_IOCTL_GETMIB
:
2697 SkPnmiGetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
);
2699 case SK_IOCTL_PRESETMIB
:
2700 SkPnmiPreSetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
);
2702 case SK_IOCTL_SETMIB
:
2703 SkPnmiSetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
);
2708 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2709 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2710 ("MIB data access succeeded\n"));
2715 /*****************************************************************************
2717 * GetConfiguration - read configuration information
2720 * This function reads per-adapter configuration information from
2721 * the options provided on the command line.
2726 static void GetConfiguration(
2727 SK_AC
*pAC
) /* pointer to the adapter context structure */
2729 SK_I32 Port
; /* preferred port */
2730 int AutoNeg
; /* auto negotiation off (0) or on (1) */
2731 int DuplexCap
; /* duplex capabilities (0=both, 1=full, 2=half */
2732 int MSMode
; /* master / slave mode selection */
2736 * The two parameters AutoNeg. and DuplexCap. map to one configuration
2737 * parameter. The mapping is described by this table:
2738 * DuplexCap -> | both | full | half |
2740 * -----------------------------------------------------------------
2741 * Off | illegal | Full | Half |
2742 * -----------------------------------------------------------------
2743 * On | AutoBoth | AutoFull | AutoHalf |
2744 * -----------------------------------------------------------------
2745 * Sense | AutoSense | AutoSense | AutoSense |
2747 int Capabilities
[3][3] =
2748 { { -1, SK_LMODE_FULL
, SK_LMODE_HALF
},
2749 {SK_LMODE_AUTOBOTH
, SK_LMODE_AUTOFULL
, SK_LMODE_AUTOHALF
},
2750 {SK_LMODE_AUTOSENSE
, SK_LMODE_AUTOSENSE
, SK_LMODE_AUTOSENSE
} };
2758 /* settings for port A */
2759 AutoNeg
= AN_SENS
; /* default: do auto Sense */
2761 if (AutoNeg_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2762 AutoNeg_A
[pAC
->Index
] != NULL
) {
2764 if (strcmp(AutoNeg_A
[pAC
->Index
],"")==0) {
2767 else if (strcmp(AutoNeg_A
[pAC
->Index
],"On")==0) {
2770 else if (strcmp(AutoNeg_A
[pAC
->Index
],"Off")==0) {
2773 else if (strcmp(AutoNeg_A
[pAC
->Index
],"Sense")==0) {
2776 else printk("%s: Illegal value for AutoNeg_A\n",
2780 DuplexCap
= DC_BOTH
;
2782 if (DupCap_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2783 DupCap_A
[pAC
->Index
] != NULL
) {
2785 if (strcmp(DupCap_A
[pAC
->Index
],"")==0) {
2788 else if (strcmp(DupCap_A
[pAC
->Index
],"Both")==0) {
2789 DuplexCap
= DC_BOTH
;
2791 else if (strcmp(DupCap_A
[pAC
->Index
],"Full")==0) {
2792 DuplexCap
= DC_FULL
;
2794 else if (strcmp(DupCap_A
[pAC
->Index
],"Half")==0) {
2795 DuplexCap
= DC_HALF
;
2797 else printk("%s: Illegal value for DupCap_A\n",
2801 /* check for illegal combinations */
2802 if (AutoSet
&& AutoNeg
==AN_SENS
&& DupSet
) {
2803 printk("%s, Port A: DuplexCapabilities"
2804 " ignored using Sense mode\n", pAC
->dev
->name
);
2806 if (AutoSet
&& AutoNeg
==AN_OFF
&& DupSet
&& DuplexCap
==DC_BOTH
){
2807 printk("%s, Port A: Illegal combination"
2808 " of values AutoNeg. and DuplexCap.\n Using "
2809 "Full Duplex\n", pAC
->dev
->name
);
2811 DuplexCap
= DC_FULL
;
2813 if (AutoSet
&& AutoNeg
==AN_OFF
&& !DupSet
) {
2814 DuplexCap
= DC_FULL
;
2817 if (!AutoSet
&& DupSet
) {
2818 printk("%s, Port A: Duplex setting not"
2819 " possible in\n default AutoNegotiation mode"
2820 " (Sense).\n Using AutoNegotiation On\n",
2825 /* set the desired mode */
2826 pAC
->GIni
.GP
[0].PLinkModeConf
=
2827 Capabilities
[AutoNeg
][DuplexCap
];
2829 pAC
->GIni
.GP
[0].PFlowCtrlMode
= SK_FLOW_MODE_SYM_OR_REM
;
2830 if (FlowCtrl_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2831 FlowCtrl_A
[pAC
->Index
] != NULL
) {
2832 if (strcmp(FlowCtrl_A
[pAC
->Index
],"") == 0) {
2834 else if (strcmp(FlowCtrl_A
[pAC
->Index
],"SymOrRem") == 0) {
2835 pAC
->GIni
.GP
[0].PFlowCtrlMode
=
2836 SK_FLOW_MODE_SYM_OR_REM
;
2838 else if (strcmp(FlowCtrl_A
[pAC
->Index
],"Sym")==0) {
2839 pAC
->GIni
.GP
[0].PFlowCtrlMode
=
2840 SK_FLOW_MODE_SYMMETRIC
;
2842 else if (strcmp(FlowCtrl_A
[pAC
->Index
],"LocSend")==0) {
2843 pAC
->GIni
.GP
[0].PFlowCtrlMode
=
2844 SK_FLOW_MODE_LOC_SEND
;
2846 else if (strcmp(FlowCtrl_A
[pAC
->Index
],"None")==0) {
2847 pAC
->GIni
.GP
[0].PFlowCtrlMode
=
2850 else printk("Illegal value for FlowCtrl_A\n");
2852 if (AutoNeg
==AN_OFF
&& pAC
->GIni
.GP
[0].PFlowCtrlMode
!=
2853 SK_FLOW_MODE_NONE
) {
2854 printk("%s, Port A: FlowControl"
2855 " impossible without AutoNegotiation,"
2856 " disabled\n", pAC
->dev
->name
);
2857 pAC
->GIni
.GP
[0].PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
2860 MSMode
= SK_MS_MODE_AUTO
; /* default: do auto select */
2861 if (Role_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2862 Role_A
[pAC
->Index
] != NULL
) {
2863 if (strcmp(Role_A
[pAC
->Index
],"")==0) {
2865 else if (strcmp(Role_A
[pAC
->Index
],"Auto")==0) {
2866 MSMode
= SK_MS_MODE_AUTO
;
2868 else if (strcmp(Role_A
[pAC
->Index
],"Master")==0) {
2869 MSMode
= SK_MS_MODE_MASTER
;
2871 else if (strcmp(Role_A
[pAC
->Index
],"Slave")==0) {
2872 MSMode
= SK_MS_MODE_SLAVE
;
2874 else printk("%s: Illegal value for Role_A\n",
2877 pAC
->GIni
.GP
[0].PMSMode
= MSMode
;
2880 /* settings for port B */
2881 AutoNeg
= AN_SENS
; /* default: do auto Sense */
2883 if (AutoNeg_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2884 AutoNeg_B
[pAC
->Index
] != NULL
) {
2886 if (strcmp(AutoNeg_B
[pAC
->Index
],"")==0) {
2889 else if (strcmp(AutoNeg_B
[pAC
->Index
],"On")==0) {
2892 else if (strcmp(AutoNeg_B
[pAC
->Index
],"Off")==0) {
2895 else if (strcmp(AutoNeg_B
[pAC
->Index
],"Sense")==0) {
2898 else printk("Illegal value for AutoNeg_B\n");
2901 DuplexCap
= DC_BOTH
;
2903 if (DupCap_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2904 DupCap_B
[pAC
->Index
] != NULL
) {
2906 if (strcmp(DupCap_B
[pAC
->Index
],"")==0) {
2909 else if (strcmp(DupCap_B
[pAC
->Index
],"Both")==0) {
2910 DuplexCap
= DC_BOTH
;
2912 else if (strcmp(DupCap_B
[pAC
->Index
],"Full")==0) {
2913 DuplexCap
= DC_FULL
;
2915 else if (strcmp(DupCap_B
[pAC
->Index
],"Half")==0) {
2916 DuplexCap
= DC_HALF
;
2918 else printk("Illegal value for DupCap_B\n");
2921 /* check for illegal combinations */
2922 if (AutoSet
&& AutoNeg
==AN_SENS
&& DupSet
) {
2923 printk("%s, Port B: DuplexCapabilities"
2924 " ignored using Sense mode\n", pAC
->dev
->name
);
2926 if (AutoSet
&& AutoNeg
==AN_OFF
&& DupSet
&& DuplexCap
==DC_BOTH
){
2927 printk("%s, Port B: Illegal combination"
2928 " of values AutoNeg. and DuplexCap.\n Using "
2929 "Full Duplex\n", pAC
->dev
->name
);
2931 DuplexCap
= DC_FULL
;
2933 if (AutoSet
&& AutoNeg
==AN_OFF
&& !DupSet
) {
2934 DuplexCap
= DC_FULL
;
2937 if (!AutoSet
&& DupSet
) {
2938 printk("%s, Port B: Duplex setting not"
2939 " possible in\n default AutoNegotiation mode"
2940 " (Sense).\n Using AutoNegotiation On\n",
2945 /* set the desired mode */
2946 pAC
->GIni
.GP
[1].PLinkModeConf
=
2947 Capabilities
[AutoNeg
][DuplexCap
];
2949 pAC
->GIni
.GP
[1].PFlowCtrlMode
= SK_FLOW_MODE_SYM_OR_REM
;
2950 if (FlowCtrl_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2951 FlowCtrl_B
[pAC
->Index
] != NULL
) {
2952 if (strcmp(FlowCtrl_B
[pAC
->Index
],"") == 0) {
2954 else if (strcmp(FlowCtrl_B
[pAC
->Index
],"SymOrRem") == 0) {
2955 pAC
->GIni
.GP
[1].PFlowCtrlMode
=
2956 SK_FLOW_MODE_SYM_OR_REM
;
2958 else if (strcmp(FlowCtrl_B
[pAC
->Index
],"Sym")==0) {
2959 pAC
->GIni
.GP
[1].PFlowCtrlMode
=
2960 SK_FLOW_MODE_SYMMETRIC
;
2962 else if (strcmp(FlowCtrl_B
[pAC
->Index
],"LocSend")==0) {
2963 pAC
->GIni
.GP
[1].PFlowCtrlMode
=
2964 SK_FLOW_MODE_LOC_SEND
;
2966 else if (strcmp(FlowCtrl_B
[pAC
->Index
],"None")==0) {
2967 pAC
->GIni
.GP
[1].PFlowCtrlMode
=
2970 else printk("Illegal value for FlowCtrl_B\n");
2972 if (AutoNeg
==AN_OFF
&& pAC
->GIni
.GP
[1].PFlowCtrlMode
!=
2973 SK_FLOW_MODE_NONE
) {
2974 printk("%s, Port B: FlowControl"
2975 " impossible without AutoNegotiation,"
2976 " disabled\n", pAC
->dev
->name
);
2977 pAC
->GIni
.GP
[1].PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
2980 MSMode
= SK_MS_MODE_AUTO
; /* default: do auto select */
2981 if (Role_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
2982 Role_B
[pAC
->Index
] != NULL
) {
2983 if (strcmp(Role_B
[pAC
->Index
],"")==0) {
2985 else if (strcmp(Role_B
[pAC
->Index
],"Auto")==0) {
2986 MSMode
= SK_MS_MODE_AUTO
;
2988 else if (strcmp(Role_B
[pAC
->Index
],"Master")==0) {
2989 MSMode
= SK_MS_MODE_MASTER
;
2991 else if (strcmp(Role_B
[pAC
->Index
],"Slave")==0) {
2992 MSMode
= SK_MS_MODE_SLAVE
;
2994 else printk("%s: Illegal value for Role_B\n",
2997 pAC
->GIni
.GP
[1].PMSMode
= MSMode
;
3000 /* settings for both ports */
3001 pAC
->ActivePort
= 0;
3002 if (PrefPort
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3003 PrefPort
[pAC
->Index
] != NULL
) {
3004 if (strcmp(PrefPort
[pAC
->Index
],"") == 0) { /* Auto */
3005 pAC
->ActivePort
= 0;
3006 pAC
->Rlmt
.MacPreferred
= -1; /* auto */
3007 pAC
->Rlmt
.PrefPort
= 0;
3009 else if (strcmp(PrefPort
[pAC
->Index
],"A") == 0) {
3011 * do not set ActivePort here, thus a port
3012 * switch is issued after net up.
3015 pAC
->Rlmt
.MacPreferred
= Port
;
3016 pAC
->Rlmt
.PrefPort
= Port
;
3018 else if (strcmp(PrefPort
[pAC
->Index
],"B") == 0) {
3020 * do not set ActivePort here, thus a port
3021 * switch is issued after net up.
3024 pAC
->Rlmt
.MacPreferred
= Port
;
3025 pAC
->Rlmt
.PrefPort
= Port
;
3027 else printk("%s: Illegal value for PrefPort\n",
3031 if (RlmtMode
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3032 RlmtMode
[pAC
->Index
] != NULL
) {
3033 if (strcmp(RlmtMode
[pAC
->Index
], "") == 0) {
3036 else if (strcmp(RlmtMode
[pAC
->Index
], "CheckLinkState") == 0) {
3037 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
;
3039 else if (strcmp(RlmtMode
[pAC
->Index
], "CheckLocalPort") == 0) {
3040 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
|
3041 SK_RLMT_CHECK_LOC_LINK
;
3043 else if (strcmp(RlmtMode
[pAC
->Index
], "CheckSeg") == 0) {
3044 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
|
3045 SK_RLMT_CHECK_LOC_LINK
|
3049 printk("%s: Illegal value for"
3050 " RlmtMode, using default\n", pAC
->dev
->name
);
3057 } /* GetConfiguration */
3060 /*****************************************************************************
3062 * ProductStr - return a adapter identification string from vpd
3065 * This function reads the product name string from the vpd area
3066 * and puts it the field pAC->DeviceString.
3070 static void ProductStr(
3071 SK_AC
*pAC
/* pointer to adapter context */
3074 int StrLen
= 80; /* length of the string, defined in SK_AC */
3075 char Keyword
[] = VPD_NAME
; /* vpd productname identifier */
3076 int ReturnCode
; /* return code from vpd_read */
3079 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
3080 ReturnCode
= VpdRead(pAC
, pAC
->IoBase
, Keyword
, pAC
->DeviceStr
,
3082 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
3083 if (ReturnCode
!= 0) {
3084 /* there was an error reading the vpd data */
3085 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ERROR
,
3086 ("Error reading VPD data: %d\n", ReturnCode
));
3087 pAC
->DeviceStr
[0] = '\0';
3094 /****************************************************************************/
3095 /* functions for common modules *********************************************/
3096 /****************************************************************************/
3099 /*****************************************************************************
3101 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3104 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3105 * is embedded into a socket buff data area.
3111 * NULL or pointer to Mbuf.
3113 SK_MBUF
*SkDrvAllocRlmtMbuf(
3114 SK_AC
*pAC
, /* pointer to adapter context */
3115 SK_IOC IoC
, /* the IO-context */
3116 unsigned BufferSize
) /* size of the requested buffer */
3118 SK_MBUF
*pRlmtMbuf
; /* pointer to a new rlmt-mbuf structure */
3119 struct sk_buff
*pMsgBlock
; /* pointer to a new message block */
3121 pMsgBlock
= alloc_skb(BufferSize
+ sizeof(SK_MBUF
), GFP_ATOMIC
);
3122 if (pMsgBlock
== NULL
) {
3125 pRlmtMbuf
= (SK_MBUF
*) pMsgBlock
->data
;
3126 skb_reserve(pMsgBlock
, sizeof(SK_MBUF
));
3127 pRlmtMbuf
->pNext
= NULL
;
3128 pRlmtMbuf
->pOs
= pMsgBlock
;
3129 pRlmtMbuf
->pData
= pMsgBlock
->data
; /* Data buffer. */
3130 pRlmtMbuf
->Size
= BufferSize
; /* Data buffer size. */
3131 pRlmtMbuf
->Length
= 0; /* Length of packet (<= Size). */
3134 } /* SkDrvAllocRlmtMbuf */
3137 /*****************************************************************************
3139 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3142 * This routine frees one or more RLMT mbuf(s).
3150 void SkDrvFreeRlmtMbuf(
3151 SK_AC
*pAC
, /* pointer to adapter context */
3152 SK_IOC IoC
, /* the IO-context */
3153 SK_MBUF
*pMbuf
) /* size of the requested buffer */
3160 pNextMbuf
= pFreeMbuf
->pNext
;
3161 DEV_KFREE_SKB_ANY(pFreeMbuf
->pOs
);
3162 pFreeMbuf
= pNextMbuf
;
3163 } while ( pFreeMbuf
!= NULL
);
3164 } /* SkDrvFreeRlmtMbuf */
3167 /*****************************************************************************
3169 * SkOsGetTime - provide a time value
3172 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3173 * It is not used for absolute time, but only for time differences.
3179 SK_U64
SkOsGetTime(SK_AC
*pAC
)
3185 /*****************************************************************************
3187 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3190 * This routine reads a 32 bit value from the pci configuration
3194 * 0 - indicate everything worked ok.
3195 * != 0 - error indication
3197 int SkPciReadCfgDWord(
3198 SK_AC
*pAC
, /* Adapter Control structure pointer */
3199 int PciAddr
, /* PCI register address */
3200 SK_U32
*pVal
) /* pointer to store the read value */
3202 pci_read_config_dword(&pAC
->PciDev
, PciAddr
, pVal
);
3204 } /* SkPciReadCfgDWord */
3207 /*****************************************************************************
3209 * SkPciReadCfgWord - read a 16 bit value from pci config space
3212 * This routine reads a 16 bit value from the pci configuration
3216 * 0 - indicate everything worked ok.
3217 * != 0 - error indication
3219 int SkPciReadCfgWord(
3220 SK_AC
*pAC
, /* Adapter Control structure pointer */
3221 int PciAddr
, /* PCI register address */
3222 SK_U16
*pVal
) /* pointer to store the read value */
3224 pci_read_config_word(&pAC
->PciDev
, PciAddr
, pVal
);
3226 } /* SkPciReadCfgWord */
3229 /*****************************************************************************
3231 * SkPciReadCfgByte - read a 8 bit value from pci config space
3234 * This routine reads a 8 bit value from the pci configuration
3238 * 0 - indicate everything worked ok.
3239 * != 0 - error indication
3241 int SkPciReadCfgByte(
3242 SK_AC
*pAC
, /* Adapter Control structure pointer */
3243 int PciAddr
, /* PCI register address */
3244 SK_U8
*pVal
) /* pointer to store the read value */
3246 pci_read_config_byte(&pAC
->PciDev
, PciAddr
, pVal
);
3248 } /* SkPciReadCfgByte */
3251 /*****************************************************************************
3253 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
3256 * This routine writes a 32 bit value to the pci configuration
3260 * 0 - indicate everything worked ok.
3261 * != 0 - error indication
3263 int SkPciWriteCfgDWord(
3264 SK_AC
*pAC
, /* Adapter Control structure pointer */
3265 int PciAddr
, /* PCI register address */
3266 SK_U32 Val
) /* pointer to store the read value */
3268 pci_write_config_dword(&pAC
->PciDev
, PciAddr
, Val
);
3270 } /* SkPciWriteCfgDWord */
3273 /*****************************************************************************
3275 * SkPciWriteCfgWord - write a 16 bit value to pci config space
3278 * This routine writes a 16 bit value to the pci configuration
3279 * space. The flag PciConfigUp indicates whether the config space
3280 * is accesible or must be set up first.
3283 * 0 - indicate everything worked ok.
3284 * != 0 - error indication
3286 int SkPciWriteCfgWord(
3287 SK_AC
*pAC
, /* Adapter Control structure pointer */
3288 int PciAddr
, /* PCI register address */
3289 SK_U16 Val
) /* pointer to store the read value */
3291 pci_write_config_word(&pAC
->PciDev
, PciAddr
, Val
);
3293 } /* SkPciWriteCfgWord */
3296 /*****************************************************************************
3298 * SkPciWriteCfgWord - write a 8 bit value to pci config space
3301 * This routine writes a 8 bit value to the pci configuration
3302 * space. The flag PciConfigUp indicates whether the config space
3303 * is accesible or must be set up first.
3306 * 0 - indicate everything worked ok.
3307 * != 0 - error indication
3309 int SkPciWriteCfgByte(
3310 SK_AC
*pAC
, /* Adapter Control structure pointer */
3311 int PciAddr
, /* PCI register address */
3312 SK_U8 Val
) /* pointer to store the read value */
3314 pci_write_config_byte(&pAC
->PciDev
, PciAddr
, Val
);
3316 } /* SkPciWriteCfgByte */
3319 /*****************************************************************************
3321 * SkDrvEvent - handle driver events
3324 * This function handles events from all modules directed to the driver
3327 * Is called under protection of slow path lock.
3330 * 0 if everything ok
3335 SK_AC
*pAC
, /* pointer to adapter context */
3336 SK_IOC IoC
, /* io-context */
3337 SK_U32 Event
, /* event-id */
3338 SK_EVPARA Param
) /* event-parameter */
3340 SK_MBUF
*pRlmtMbuf
; /* pointer to a rlmt-mbuf structure */
3341 struct sk_buff
*pMsg
; /* pointer to a message block */
3342 int FromPort
; /* the port from which we switch away */
3343 int ToPort
; /* the port we switch to */
3344 SK_EVPARA NewPara
; /* parameter for further events */
3349 case SK_DRV_ADAP_FAIL
:
3350 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3351 ("ADAPTER FAIL EVENT\n"));
3352 printk("%s: Adapter failed.\n", pAC
->dev
->name
);
3353 /* disable interrupts */
3354 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
3357 case SK_DRV_PORT_FAIL
:
3358 FromPort
= Param
.Para32
[0];
3359 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3360 ("PORT FAIL EVENT, Port: %d\n", FromPort
));
3361 if (FromPort
== 0) {
3362 printk("%s: Port A failed.\n", pAC
->dev
->name
);
3364 printk("%s: Port B failed.\n", pAC
->dev
->name
);
3368 case SK_DRV_PORT_RESET
: /* SK_U32 PortIdx */
3370 FromPort
= Param
.Para32
[0];
3371 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3372 ("PORT RESET EVENT, Port: %d ", FromPort
));
3373 NewPara
.Para64
= FromPort
;
3374 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
3376 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3378 SkGeStopPort(pAC
, IoC
, FromPort
, SK_STOP_ALL
, SK_HARD_RST
);
3379 spin_unlock_irqrestore(
3380 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3383 /* clear rx ring from received frames */
3384 ReceiveIrq(pAC
, &pAC
->RxPort
[FromPort
]);
3386 ClearTxRing(pAC
, &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
]);
3388 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3390 SkGeInitPort(pAC
, IoC
, FromPort
);
3391 SkAddrMcUpdate(pAC
,IoC
, FromPort
);
3392 PortReInitBmu(pAC
, FromPort
);
3393 SkGePollTxD(pAC
, IoC
, FromPort
, SK_TRUE
);
3394 ClearAndStartRx(pAC
, FromPort
);
3395 spin_unlock_irqrestore(
3396 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3399 case SK_DRV_NET_UP
: /* SK_U32 PortIdx */
3401 FromPort
= Param
.Para32
[0];
3402 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3403 ("NET UP EVENT, Port: %d ", Param
.Para32
[0]));
3404 printk("%s: network connection up using"
3405 " port %c\n", pAC
->dev
->name
, 'A'+Param
.Para32
[0]);
3406 printk(" speed: 1000\n");
3407 Stat
= pAC
->GIni
.GP
[FromPort
].PLinkModeStatus
;
3408 if (Stat
== SK_LMODE_STAT_AUTOHALF
||
3409 Stat
== SK_LMODE_STAT_AUTOFULL
) {
3410 printk(" autonegotiation: yes\n");
3413 printk(" autonegotiation: no\n");
3415 if (Stat
== SK_LMODE_STAT_AUTOHALF
||
3416 Stat
== SK_LMODE_STAT_HALF
) {
3417 printk(" duplex mode: half\n");
3420 printk(" duplex mode: full\n");
3422 Stat
= pAC
->GIni
.GP
[FromPort
].PFlowCtrlStatus
;
3423 if (Stat
== SK_FLOW_STAT_REM_SEND
) {
3424 printk(" flowctrl: remote send\n");
3426 else if (Stat
== SK_FLOW_STAT_LOC_SEND
){
3427 printk(" flowctrl: local send\n");
3429 else if (Stat
== SK_FLOW_STAT_SYMMETRIC
){
3430 printk(" flowctrl: symmetric\n");
3433 printk(" flowctrl: none\n");
3435 if (pAC
->GIni
.GP
[FromPort
].PhyType
!= SK_PHY_XMAC
) {
3436 Stat
= pAC
->GIni
.GP
[FromPort
].PMSStatus
;
3437 if (Stat
== SK_MS_STAT_MASTER
) {
3438 printk(" role: master\n");
3440 else if (Stat
== SK_MS_STAT_SLAVE
) {
3441 printk(" role: slave\n");
3444 printk(" role: ???\n");
3448 if (Param
.Para32
[0] != pAC
->ActivePort
) {
3449 NewPara
.Para32
[0] = pAC
->ActivePort
;
3450 NewPara
.Para32
[1] = Param
.Para32
[0];
3451 SkEventQueue(pAC
, SKGE_DRV
, SK_DRV_SWITCH_INTERN
,
3455 case SK_DRV_NET_DOWN
: /* SK_U32 Reason */
3457 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3458 ("NET DOWN EVENT "));
3459 printk("%s: network connection down\n", pAC
->dev
->name
);
3461 case SK_DRV_SWITCH_HARD
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3462 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3463 ("PORT SWITCH HARD "));
3464 case SK_DRV_SWITCH_SOFT
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3466 printk("%s: switching to port %c\n", pAC
->dev
->name
,
3467 'A'+Param
.Para32
[1]);
3468 case SK_DRV_SWITCH_INTERN
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
3469 FromPort
= Param
.Para32
[0];
3470 ToPort
= Param
.Para32
[1];
3471 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3472 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
3473 FromPort
, ToPort
, pAC
->Rlmt
.PrefPort
));
3474 NewPara
.Para64
= FromPort
;
3475 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
3476 NewPara
.Para64
= ToPort
;
3477 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
3479 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3482 &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
, Flags
);
3483 SkGeStopPort(pAC
, IoC
, FromPort
, SK_STOP_ALL
, SK_SOFT_RST
);
3484 SkGeStopPort(pAC
, IoC
, ToPort
, SK_STOP_ALL
, SK_SOFT_RST
);
3485 spin_unlock_irqrestore(
3486 &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
, Flags
);
3487 spin_unlock_irqrestore(
3488 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3491 ReceiveIrq(pAC
, &pAC
->RxPort
[FromPort
]); /* clears rx ring */
3492 ReceiveIrq(pAC
, &pAC
->RxPort
[ToPort
]); /* clears rx ring */
3494 ClearTxRing(pAC
, &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
]);
3495 ClearTxRing(pAC
, &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
]);
3497 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3500 &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
, Flags
);
3501 pAC
->ActivePort
= ToPort
;
3503 SkGeInitPort(pAC
, IoC
, FromPort
);
3504 SkGeInitPort(pAC
, IoC
, ToPort
);
3505 if (Event
== SK_DRV_SWITCH_SOFT
) {
3506 SkXmRxTxEnable(pAC
, IoC
, FromPort
);
3508 SkXmRxTxEnable(pAC
, IoC
, ToPort
);
3509 SkAddrSwap(pAC
, IoC
, FromPort
, ToPort
);
3510 SkAddrMcUpdate(pAC
, IoC
, FromPort
);
3511 SkAddrMcUpdate(pAC
, IoC
, ToPort
);
3512 PortReInitBmu(pAC
, FromPort
);
3513 PortReInitBmu(pAC
, ToPort
);
3514 SkGePollTxD(pAC
, IoC
, FromPort
, SK_TRUE
);
3515 SkGePollTxD(pAC
, IoC
, ToPort
, SK_TRUE
);
3516 ClearAndStartRx(pAC
, FromPort
);
3517 ClearAndStartRx(pAC
, ToPort
);
3518 spin_unlock_irqrestore(
3519 &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
, Flags
);
3520 spin_unlock_irqrestore(
3521 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
3524 case SK_DRV_RLMT_SEND
: /* SK_MBUF *pMb */
3525 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3527 pRlmtMbuf
= (SK_MBUF
*) Param
.pParaPtr
;
3528 pMsg
= (struct sk_buff
*) pRlmtMbuf
->pOs
;
3529 skb_put(pMsg
, pRlmtMbuf
->Length
);
3530 if (XmitFrame(pAC
, &pAC
->TxPort
[pRlmtMbuf
->PortIdx
][TX_PRIO_LOW
],
3532 DEV_KFREE_SKB_ANY(pMsg
);
3537 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
3544 /*****************************************************************************
3546 * SkErrorLog - log errors
3549 * This function logs errors to the system buffer and to the console
3552 * 0 if everything ok
3565 case SK_ERRCL_OTHER
:
3566 strcpy(ClassStr
, "Other error");
3568 case SK_ERRCL_CONFIG
:
3569 strcpy(ClassStr
, "Configuration error");
3572 strcpy(ClassStr
, "Initialization error");
3574 case SK_ERRCL_NORES
:
3575 strcpy(ClassStr
, "Out of resources error");
3578 strcpy(ClassStr
, "internal Software error");
3581 strcpy(ClassStr
, "Hardware failure");
3584 strcpy(ClassStr
, "Communication error");
3587 printk(KERN_INFO
"%s: -- ERROR --\n Class: %s\n"
3588 " Nr: 0x%x\n Msg: %s\n", pAC
->dev
->name
,
3589 ClassStr
, ErrNum
, pErrorMsg
);
3593 #ifdef DEBUG /***************************************************************/
3594 /* "debug only" section *****************************************************/
3595 /****************************************************************************/
3598 /*****************************************************************************
3600 * DumpMsg - print a frame
3603 * This function prints frames to the system logfile/to the console.
3608 static void DumpMsg(struct sk_buff
*skb
, char *str
)
3613 printk("DumpMsg(): NULL-Message\n");
3617 if (skb
->data
== NULL
) {
3618 printk("DumpMsg(): Message empty\n");
3626 printk("--- Begin of message from %s , len %d (from %d) ----\n", str
, msglen
, skb
->len
);
3628 DumpData((char *)skb
->data
, msglen
);
3630 printk("------- End of message ---------\n");
3635 /*****************************************************************************
3637 * DumpData - print a data area
3640 * This function prints a area of data to the system logfile/to the
3646 static void DumpData(char *p
, int size
)
3650 char hex_buffer
[180];
3651 char asc_buffer
[180];
3652 char HEXCHAR
[] = "0123456789ABCDEF";
3658 for (i
=0; i
< size
; ) {
3659 if (*p
>= '0' && *p
<='z')
3660 asc_buffer
[addr
] = *p
;
3662 asc_buffer
[addr
] = '.';
3664 asc_buffer
[addr
] = 0;
3665 hex_buffer
[haddr
] = HEXCHAR
[(*p
& 0xf0) >> 4];
3667 hex_buffer
[haddr
] = HEXCHAR
[*p
& 0x0f];
3669 hex_buffer
[haddr
] = ' ';
3671 hex_buffer
[haddr
] = 0;
3675 printk("%s %s\n", hex_buffer
, asc_buffer
);
3683 /*****************************************************************************
3685 * DumpLong - print a data area as long values
3688 * This function prints a area of data to the system logfile/to the
3694 static void DumpLong(char *pc
, int size
)
3698 char hex_buffer
[180];
3699 char asc_buffer
[180];
3700 char HEXCHAR
[] = "0123456789ABCDEF";
3709 for (i
=0; i
< size
; ) {
3711 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 28) & 0xf];
3713 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 24) & 0xf];
3715 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 20) & 0xf];
3717 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 16) & 0xf];
3719 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 12) & 0xf];
3721 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 8) & 0xf];
3723 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 4) & 0xf];
3725 hex_buffer
[haddr
] = HEXCHAR
[l
& 0x0f];
3727 hex_buffer
[haddr
] = ' ';
3729 hex_buffer
[haddr
] = 0;
3733 printk("%4x %s\n", (i
-8)*4, hex_buffer
);
3737 printk("------------------------\n");
3744 * compile-command: "make"