1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.45 $
6 * Date: $Date: 2004/02/12 14:41:02 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
19 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
20 * SysKonnects GEnesis Solaris driver
21 * Author: Christoph Goos (cgoos@syskonnect.de)
22 * Mirko Lindner (mlindner@syskonnect.de)
24 * Address all question to: linux@syskonnect.de
26 * The technical manual for the adapters is available from SysKonnect's
27 * web pages: www.syskonnect.com
28 * Goto "Support" and search Knowledge Base for "manual".
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * The information in this file is provided "AS IS" without warranty.
37 ******************************************************************************/
39 /******************************************************************************
41 * Possible compiler options (#define xxx / -Dxxx):
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
46 ******************************************************************************/
48 /******************************************************************************
52 * This is the main module of the Linux GE driver.
54 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
55 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
56 * Those are used for drivers on multiple OS', so some thing may seem
57 * unnecessary complicated on Linux. Please do not try to 'clean up'
58 * them without VERY good reasons, because this will make it more
59 * difficult to keep the Linux driver in synchronisation with the
62 * Include file hierarchy:
79 * <linux/etherdevice.h>
81 * those three depending on kernel version used:
107 ******************************************************************************/
109 #include "h/skversion.h"
111 #include <linux/module.h>
112 #include <linux/init.h>
113 #include <linux/proc_fs.h>
115 #include "h/skdrv1st.h"
116 #include "h/skdrv2nd.h"
118 /*******************************************************************************
122 ******************************************************************************/
124 /* for debuging on x86 only */
125 /* #define BREAKPOINT() asm(" int $3"); */
127 /* use the transmit hw checksum driver functionality */
128 #define USE_SK_TX_CHECKSUM
130 /* use the receive hw checksum driver functionality */
131 #define USE_SK_RX_CHECKSUM
133 /* use the scatter-gather functionality with sendfile() */
136 /* use of a transmit complete interrupt */
137 #define USE_TX_COMPLETE
140 * threshold for copying small receive frames
141 * set to 0 to avoid copying, set to 9001 to copy all frames
143 #define SK_COPY_THRESHOLD 50
145 /* number of adapters that can be configured via command line params */
146 #define SK_MAX_CARD_PARAM 16
151 * use those defines for a compile-in version of the driver instead
152 * of command line parameters
154 // #define LINK_SPEED_A {"Auto", }
155 // #define LINK_SPEED_B {"Auto", }
156 // #define AUTO_NEG_A {"Sense", }
157 // #define AUTO_NEG_B {"Sense", }
158 // #define DUP_CAP_A {"Both", }
159 // #define DUP_CAP_B {"Both", }
160 // #define FLOW_CTRL_A {"SymOrRem", }
161 // #define FLOW_CTRL_B {"SymOrRem", }
162 // #define ROLE_A {"Auto", }
163 // #define ROLE_B {"Auto", }
164 // #define PREF_PORT {"A", }
165 // #define CON_TYPE {"Auto", }
166 // #define RLMT_MODE {"CheckLinkState", }
168 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
169 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
170 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
174 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
175 SK_DUP_LED_NORMAL | \
179 /* Isr return value */
180 #define SkIsrRetVar irqreturn_t
181 #define SkIsrRetNone IRQ_NONE
182 #define SkIsrRetHandled IRQ_HANDLED
185 /*******************************************************************************
187 * Local Function Prototypes
189 ******************************************************************************/
191 static void FreeResources(struct SK_NET_DEVICE
*dev
);
192 static int SkGeBoardInit(struct SK_NET_DEVICE
*dev
, SK_AC
*pAC
);
193 static SK_BOOL
BoardAllocMem(SK_AC
*pAC
);
194 static void BoardFreeMem(SK_AC
*pAC
);
195 static void BoardInitMem(SK_AC
*pAC
);
196 static void SetupRing(SK_AC
*, void*, uintptr_t, RXD
**, RXD
**, RXD
**, int*, SK_BOOL
);
197 static SkIsrRetVar
SkGeIsr(int irq
, void *dev_id
, struct pt_regs
*ptregs
);
198 static SkIsrRetVar
SkGeIsrOnePort(int irq
, void *dev_id
, struct pt_regs
*ptregs
);
199 static int SkGeOpen(struct SK_NET_DEVICE
*dev
);
200 static int SkGeClose(struct SK_NET_DEVICE
*dev
);
201 static int SkGeXmit(struct sk_buff
*skb
, struct SK_NET_DEVICE
*dev
);
202 static int SkGeSetMacAddr(struct SK_NET_DEVICE
*dev
, void *p
);
203 static void SkGeSetRxMode(struct SK_NET_DEVICE
*dev
);
204 static struct net_device_stats
*SkGeStats(struct SK_NET_DEVICE
*dev
);
205 static int SkGeIoctl(struct SK_NET_DEVICE
*dev
, struct ifreq
*rq
, int cmd
);
206 static void GetConfiguration(SK_AC
*);
207 static void ProductStr(SK_AC
*);
208 static int XmitFrame(SK_AC
*, TX_PORT
*, struct sk_buff
*);
209 static void FreeTxDescriptors(SK_AC
*pAC
, TX_PORT
*);
210 static void FillRxRing(SK_AC
*, RX_PORT
*);
211 static SK_BOOL
FillRxDescriptor(SK_AC
*, RX_PORT
*);
212 static void ReceiveIrq(SK_AC
*, RX_PORT
*, SK_BOOL
);
213 static void ClearAndStartRx(SK_AC
*, int);
214 static void ClearTxIrq(SK_AC
*, int, int);
215 static void ClearRxRing(SK_AC
*, RX_PORT
*);
216 static void ClearTxRing(SK_AC
*, TX_PORT
*);
217 static int SkGeChangeMtu(struct SK_NET_DEVICE
*dev
, int new_mtu
);
218 static void PortReInitBmu(SK_AC
*, int);
219 static int SkGeIocMib(DEV_NET
*, unsigned int, int);
220 static int SkGeInitPCI(SK_AC
*pAC
);
221 static void StartDrvCleanupTimer(SK_AC
*pAC
);
222 static void StopDrvCleanupTimer(SK_AC
*pAC
);
223 static int XmitFrameSG(SK_AC
*, TX_PORT
*, struct sk_buff
*);
225 #ifdef SK_DIAG_SUPPORT
226 static SK_U32
ParseDeviceNbrFromSlotName(const char *SlotName
);
227 static int SkDrvInitAdapter(SK_AC
*pAC
, int devNbr
);
228 static int SkDrvDeInitAdapter(SK_AC
*pAC
, int devNbr
);
231 /*******************************************************************************
233 * Extern Function Prototypes
235 ******************************************************************************/
237 #ifdef CONFIG_PROC_FS
238 static const char SK_Root_Dir_entry
[] = "sk98lin";
239 static struct proc_dir_entry
*pSkRootDir
;
240 extern struct file_operations sk_proc_fops
;
243 extern void SkDimEnableModerationIfNeeded(SK_AC
*pAC
);
244 extern void SkDimDisplayModerationSettings(SK_AC
*pAC
);
245 extern void SkDimStartModerationTimer(SK_AC
*pAC
);
246 extern void SkDimModerate(SK_AC
*pAC
);
249 static void DumpMsg(struct sk_buff
*, char*);
250 static void DumpData(char*, int);
251 static void DumpLong(char*, int);
254 /* global variables *********************************************************/
255 struct SK_NET_DEVICE
*SkGeRootDev
= NULL
;
256 static SK_BOOL DoPrintInterfaceChange
= SK_TRUE
;
258 /* local variables **********************************************************/
259 static uintptr_t TxQueueAddr
[SK_MAX_MACS
][2] = {{0x680, 0x600},{0x780, 0x700}};
260 static uintptr_t RxQueueAddr
[SK_MAX_MACS
] = {0x400, 0x480};
262 /*****************************************************************************
264 * SkGeInitPCI - Init the PCI resources
267 * This function initialize the PCI resources and IO
272 int SkGeInitPCI(SK_AC
*pAC
)
274 struct SK_NET_DEVICE
*dev
= pAC
->dev
[0];
275 struct pci_dev
*pdev
= pAC
->PciDev
;
278 if (pci_enable_device(pdev
) != 0) {
282 dev
->mem_start
= pci_resource_start (pdev
, 0);
283 pci_set_master(pdev
);
285 if (pci_request_regions(pdev
, pAC
->Name
) != 0) {
292 * On big endian machines, we use the adapter's aibility of
293 * reading the descriptors as big endian.
297 SkPciReadCfgDWord(pAC
, PCI_OUR_REG_2
, &our2
);
298 our2
|= PCI_REV_DESC
;
299 SkPciWriteCfgDWord(pAC
, PCI_OUR_REG_2
, our2
);
304 * Remap the regs into kernel space.
306 pAC
->IoBase
= (char*)ioremap_nocache(dev
->mem_start
, 0x4000);
316 pci_release_regions(pdev
);
318 pci_disable_device(pdev
);
323 /*****************************************************************************
325 * FreeResources - release resources allocated for adapter
328 * This function releases the IRQ, unmaps the IO and
329 * frees the desriptor ring.
334 static void FreeResources(struct SK_NET_DEVICE
*dev
)
341 pNet
= (DEV_NET
*) dev
->priv
;
343 AllocFlag
= pAC
->AllocFlag
;
345 pci_release_regions(pAC
->PciDev
);
347 if (AllocFlag
& SK_ALLOC_IRQ
) {
348 free_irq(dev
->irq
, dev
);
351 iounmap(pAC
->IoBase
);
353 if (pAC
->pDescrMem
) {
358 } /* FreeResources */
360 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
361 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
362 MODULE_LICENSE("GPL");
363 MODULE_PARM(Speed_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
364 MODULE_PARM(Speed_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
365 MODULE_PARM(AutoNeg_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
366 MODULE_PARM(AutoNeg_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
367 MODULE_PARM(DupCap_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
368 MODULE_PARM(DupCap_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
369 MODULE_PARM(FlowCtrl_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
370 MODULE_PARM(FlowCtrl_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
371 MODULE_PARM(Role_A
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
372 MODULE_PARM(Role_B
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
373 MODULE_PARM(ConType
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
374 MODULE_PARM(PrefPort
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
375 MODULE_PARM(RlmtMode
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
376 /* used for interrupt moderation */
377 MODULE_PARM(IntsPerSec
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "i");
378 MODULE_PARM(Moderation
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
379 MODULE_PARM(Stats
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
380 MODULE_PARM(ModerationMask
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
381 MODULE_PARM(AutoSizing
, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM
) "s");
385 static char *Speed_A
[SK_MAX_CARD_PARAM
] = LINK_SPEED
;
387 static char *Speed_A
[SK_MAX_CARD_PARAM
] = {"", };
391 static char *Speed_B
[SK_MAX_CARD_PARAM
] = LINK_SPEED
;
393 static char *Speed_B
[SK_MAX_CARD_PARAM
] = {"", };
397 static char *AutoNeg_A
[SK_MAX_CARD_PARAM
] = AUTO_NEG_A
;
399 static char *AutoNeg_A
[SK_MAX_CARD_PARAM
] = {"", };
403 static char *DupCap_A
[SK_MAX_CARD_PARAM
] = DUP_CAP_A
;
405 static char *DupCap_A
[SK_MAX_CARD_PARAM
] = {"", };
409 static char *FlowCtrl_A
[SK_MAX_CARD_PARAM
] = FLOW_CTRL_A
;
411 static char *FlowCtrl_A
[SK_MAX_CARD_PARAM
] = {"", };
415 static char *Role_A
[SK_MAX_CARD_PARAM
] = ROLE_A
;
417 static char *Role_A
[SK_MAX_CARD_PARAM
] = {"", };
421 static char *AutoNeg_B
[SK_MAX_CARD_PARAM
] = AUTO_NEG_B
;
423 static char *AutoNeg_B
[SK_MAX_CARD_PARAM
] = {"", };
427 static char *DupCap_B
[SK_MAX_CARD_PARAM
] = DUP_CAP_B
;
429 static char *DupCap_B
[SK_MAX_CARD_PARAM
] = {"", };
433 static char *FlowCtrl_B
[SK_MAX_CARD_PARAM
] = FLOW_CTRL_B
;
435 static char *FlowCtrl_B
[SK_MAX_CARD_PARAM
] = {"", };
439 static char *Role_B
[SK_MAX_CARD_PARAM
] = ROLE_B
;
441 static char *Role_B
[SK_MAX_CARD_PARAM
] = {"", };
445 static char *ConType
[SK_MAX_CARD_PARAM
] = CON_TYPE
;
447 static char *ConType
[SK_MAX_CARD_PARAM
] = {"", };
451 static char *PrefPort
[SK_MAX_CARD_PARAM
] = PREF_PORT
;
453 static char *PrefPort
[SK_MAX_CARD_PARAM
] = {"", };
457 static char *RlmtMode
[SK_MAX_CARD_PARAM
] = RLMT_MODE
;
459 static char *RlmtMode
[SK_MAX_CARD_PARAM
] = {"", };
462 static int IntsPerSec
[SK_MAX_CARD_PARAM
];
463 static char *Moderation
[SK_MAX_CARD_PARAM
];
464 static char *ModerationMask
[SK_MAX_CARD_PARAM
];
465 static char *AutoSizing
[SK_MAX_CARD_PARAM
];
466 static char *Stats
[SK_MAX_CARD_PARAM
];
468 /*****************************************************************************
470 * SkGeBoardInit - do level 0 and 1 initialization
473 * This function prepares the board hardware for running. The desriptor
474 * ring is set up, the IRQ is allocated and the configuration settings
478 * 0, if everything is ok
481 static int __init
SkGeBoardInit(struct SK_NET_DEVICE
*dev
, SK_AC
*pAC
)
485 char *DescrString
= "sk98lin: Driver for Linux"; /* this is given to PNMI */
486 char *VerStr
= VER_STRING
;
487 int Ret
; /* return code of request_irq */
490 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
491 ("IoBase: %08lX\n", (unsigned long)pAC
->IoBase
));
492 for (i
=0; i
<SK_MAX_MACS
; i
++) {
493 pAC
->TxPort
[i
][0].HwAddr
= pAC
->IoBase
+ TxQueueAddr
[i
][0];
494 pAC
->TxPort
[i
][0].PortIndex
= i
;
495 pAC
->RxPort
[i
].HwAddr
= pAC
->IoBase
+ RxQueueAddr
[i
];
496 pAC
->RxPort
[i
].PortIndex
= i
;
499 /* Initialize the mutexes */
500 for (i
=0; i
<SK_MAX_MACS
; i
++) {
501 spin_lock_init(&pAC
->TxPort
[i
][0].TxDesRingLock
);
502 spin_lock_init(&pAC
->RxPort
[i
].RxDesRingLock
);
504 spin_lock_init(&pAC
->SlowPathLock
);
506 /* level 0 init common modules here */
508 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
509 /* Does a RESET on board ...*/
510 if (SkGeInit(pAC
, pAC
->IoBase
, SK_INIT_DATA
) != 0) {
511 printk("HWInit (0) failed.\n");
512 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
515 SkI2cInit( pAC
, pAC
->IoBase
, SK_INIT_DATA
);
516 SkEventInit(pAC
, pAC
->IoBase
, SK_INIT_DATA
);
517 SkPnmiInit( pAC
, pAC
->IoBase
, SK_INIT_DATA
);
518 SkAddrInit( pAC
, pAC
->IoBase
, SK_INIT_DATA
);
519 SkRlmtInit( pAC
, pAC
->IoBase
, SK_INIT_DATA
);
520 SkTimerInit(pAC
, pAC
->IoBase
, SK_INIT_DATA
);
522 pAC
->BoardLevel
= SK_INIT_DATA
;
523 pAC
->RxBufSize
= ETH_BUF_SIZE
;
525 SK_PNMI_SET_DRIVER_DESCR(pAC
, DescrString
);
526 SK_PNMI_SET_DRIVER_VER(pAC
, VerStr
);
528 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
530 /* level 1 init common modules here (HW init) */
531 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
532 if (SkGeInit(pAC
, pAC
->IoBase
, SK_INIT_IO
) != 0) {
533 printk("sk98lin: HWInit (1) failed.\n");
534 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
537 SkI2cInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
538 SkEventInit(pAC
, pAC
->IoBase
, SK_INIT_IO
);
539 SkPnmiInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
540 SkAddrInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
541 SkRlmtInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
542 SkTimerInit(pAC
, pAC
->IoBase
, SK_INIT_IO
);
544 /* Set chipset type support */
545 pAC
->ChipsetType
= 0;
546 if ((pAC
->GIni
.GIChipId
== CHIP_ID_YUKON
) ||
547 (pAC
->GIni
.GIChipId
== CHIP_ID_YUKON_LITE
)) {
548 pAC
->ChipsetType
= 1;
551 GetConfiguration(pAC
);
552 if (pAC
->RlmtNets
== 2) {
553 pAC
->GIni
.GIPortUsage
= SK_MUL_LINK
;
556 pAC
->BoardLevel
= SK_INIT_IO
;
557 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
559 if (pAC
->GIni
.GIMacsFound
== 2) {
560 Ret
= request_irq(dev
->irq
, SkGeIsr
, SA_SHIRQ
, pAC
->Name
, dev
);
561 } else if (pAC
->GIni
.GIMacsFound
== 1) {
562 Ret
= request_irq(dev
->irq
, SkGeIsrOnePort
, SA_SHIRQ
,
565 printk(KERN_WARNING
"sk98lin: Illegal number of ports: %d\n",
566 pAC
->GIni
.GIMacsFound
);
571 printk(KERN_WARNING
"sk98lin: Requested IRQ %d is busy.\n",
575 pAC
->AllocFlag
|= SK_ALLOC_IRQ
;
577 /* Alloc memory for this board (Mem for RxD/TxD) : */
578 if(!BoardAllocMem(pAC
)) {
579 printk("No memory for descriptor rings.\n");
583 SkCsSetReceiveFlags(pAC
,
584 SKCS_PROTO_IP
| SKCS_PROTO_TCP
| SKCS_PROTO_UDP
,
585 &pAC
->CsOfs1
, &pAC
->CsOfs2
, 0);
586 pAC
->CsOfs
= (pAC
->CsOfs2
<< 16) | pAC
->CsOfs1
;
589 /* tschilling: New common function with minimum size check. */
591 if (pAC
->RlmtNets
== 2) {
595 if (SkGeInitAssignRamToQueues(
600 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
605 * Register the device here
607 pAC
->Next
= SkGeRootDev
;
611 } /* SkGeBoardInit */
614 /*****************************************************************************
616 * BoardAllocMem - allocate the memory for the descriptor rings
619 * This function allocates the memory for all descriptor rings.
620 * Each ring is aligned for the desriptor alignment and no ring
621 * has a 4 GByte boundary in it (because the upper 32 bit must
622 * be constant for all descriptiors in one rings).
625 * SK_TRUE, if all memory could be allocated
628 static SK_BOOL
BoardAllocMem(
631 caddr_t pDescrMem
; /* pointer to descriptor memory area */
632 size_t AllocLength
; /* length of complete descriptor area */
633 int i
; /* loop counter */
634 unsigned long BusAddr
;
637 /* rings plus one for alignment (do not cross 4 GB boundary) */
638 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
639 #if (BITS_PER_LONG == 32)
640 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
+ 8;
642 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
646 pDescrMem
= pci_alloc_consistent(pAC
->PciDev
, AllocLength
,
649 if (pDescrMem
== NULL
) {
652 pAC
->pDescrMem
= pDescrMem
;
653 BusAddr
= (unsigned long) pAC
->pDescrMemDMA
;
655 /* Descriptors need 8 byte alignment, and this is ensured
656 * by pci_alloc_consistent.
658 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
659 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
660 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
661 i
, (unsigned long) pDescrMem
,
663 pAC
->TxPort
[i
][0].pTxDescrRing
= pDescrMem
;
664 pAC
->TxPort
[i
][0].VTxDescrRing
= BusAddr
;
665 pDescrMem
+= TX_RING_SIZE
;
666 BusAddr
+= TX_RING_SIZE
;
668 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
669 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
670 i
, (unsigned long) pDescrMem
,
671 (unsigned long)BusAddr
));
672 pAC
->RxPort
[i
].pRxDescrRing
= pDescrMem
;
673 pAC
->RxPort
[i
].VRxDescrRing
= BusAddr
;
674 pDescrMem
+= RX_RING_SIZE
;
675 BusAddr
+= RX_RING_SIZE
;
679 } /* BoardAllocMem */
682 /****************************************************************************
684 * BoardFreeMem - reverse of BoardAllocMem
687 * Free all memory allocated in BoardAllocMem: adapter context,
688 * descriptor rings, locks.
692 static void BoardFreeMem(
695 size_t AllocLength
; /* length of complete descriptor area */
697 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
699 #if (BITS_PER_LONG == 32)
700 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
+ 8;
702 AllocLength
= (RX_RING_SIZE
+ TX_RING_SIZE
) * pAC
->GIni
.GIMacsFound
706 pci_free_consistent(pAC
->PciDev
, AllocLength
,
707 pAC
->pDescrMem
, pAC
->pDescrMemDMA
);
708 pAC
->pDescrMem
= NULL
;
712 /*****************************************************************************
714 * BoardInitMem - initiate the descriptor rings
717 * This function sets the descriptor rings up in memory.
718 * The adapter is initialized with the descriptor start addresses.
722 static void BoardInitMem(
723 SK_AC
*pAC
) /* pointer to adapter context */
725 int i
; /* loop counter */
726 int RxDescrSize
; /* the size of a rx descriptor rounded up to alignment*/
727 int TxDescrSize
; /* the size of a tx descriptor rounded up to alignment*/
729 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
732 RxDescrSize
= (((sizeof(RXD
) - 1) / DESCR_ALIGN
) + 1) * DESCR_ALIGN
;
733 pAC
->RxDescrPerRing
= RX_RING_SIZE
/ RxDescrSize
;
734 TxDescrSize
= (((sizeof(TXD
) - 1) / DESCR_ALIGN
) + 1) * DESCR_ALIGN
;
735 pAC
->TxDescrPerRing
= TX_RING_SIZE
/ RxDescrSize
;
737 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
740 pAC
->TxPort
[i
][0].pTxDescrRing
,
741 pAC
->TxPort
[i
][0].VTxDescrRing
,
742 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingHead
,
743 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingTail
,
744 (RXD
**)&pAC
->TxPort
[i
][0].pTxdRingPrev
,
745 &pAC
->TxPort
[i
][0].TxdRingFree
,
749 pAC
->RxPort
[i
].pRxDescrRing
,
750 pAC
->RxPort
[i
].VRxDescrRing
,
751 &pAC
->RxPort
[i
].pRxdRingHead
,
752 &pAC
->RxPort
[i
].pRxdRingTail
,
753 &pAC
->RxPort
[i
].pRxdRingPrev
,
754 &pAC
->RxPort
[i
].RxdRingFree
,
760 /*****************************************************************************
762 * SetupRing - create one descriptor ring
765 * This function creates one descriptor ring in the given memory area.
766 * The head, tail and number of free descriptors in the ring are set.
771 static void SetupRing(
773 void *pMemArea
, /* a pointer to the memory area for the ring */
774 uintptr_t VMemArea
, /* the virtual bus address of the memory area */
775 RXD
**ppRingHead
, /* address where the head should be written */
776 RXD
**ppRingTail
, /* address where the tail should be written */
777 RXD
**ppRingPrev
, /* address where the tail should be written */
778 int *pRingFree
, /* address where the # of free descr. goes */
779 SK_BOOL IsTx
) /* flag: is this a tx ring */
781 int i
; /* loop counter */
782 int DescrSize
; /* the size of a descriptor rounded up to alignment*/
783 int DescrNum
; /* number of descriptors per ring */
784 RXD
*pDescr
; /* pointer to a descriptor (receive or transmit) */
785 RXD
*pNextDescr
; /* pointer to the next descriptor */
786 RXD
*pPrevDescr
; /* pointer to the previous descriptor */
787 uintptr_t VNextDescr
; /* the virtual bus address of the next descriptor */
789 if (IsTx
== SK_TRUE
) {
790 DescrSize
= (((sizeof(TXD
) - 1) / DESCR_ALIGN
) + 1) *
792 DescrNum
= TX_RING_SIZE
/ DescrSize
;
794 DescrSize
= (((sizeof(RXD
) - 1) / DESCR_ALIGN
) + 1) *
796 DescrNum
= RX_RING_SIZE
/ DescrSize
;
799 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
,
800 ("Descriptor size: %d Descriptor Number: %d\n",
801 DescrSize
,DescrNum
));
803 pDescr
= (RXD
*) pMemArea
;
805 pNextDescr
= (RXD
*) (((char*)pDescr
) + DescrSize
);
806 VNextDescr
= VMemArea
+ DescrSize
;
807 for(i
=0; i
<DescrNum
; i
++) {
808 /* set the pointers right */
809 pDescr
->VNextRxd
= VNextDescr
& 0xffffffffULL
;
810 pDescr
->pNextRxd
= pNextDescr
;
811 pDescr
->TcpSumStarts
= pAC
->CsOfs
;
813 /* advance one step */
816 pNextDescr
= (RXD
*) (((char*)pDescr
) + DescrSize
);
817 VNextDescr
+= DescrSize
;
819 pPrevDescr
->pNextRxd
= (RXD
*) pMemArea
;
820 pPrevDescr
->VNextRxd
= VMemArea
;
821 pDescr
= (RXD
*) pMemArea
;
822 *ppRingHead
= (RXD
*) pMemArea
;
823 *ppRingTail
= *ppRingHead
;
824 *ppRingPrev
= pPrevDescr
;
825 *pRingFree
= DescrNum
;
829 /*****************************************************************************
831 * PortReInitBmu - re-initiate the descriptor rings for one port
834 * This function reinitializes the descriptor rings of one port
835 * in memory. The port must be stopped before.
836 * The HW is initialized with the descriptor start addresses.
841 static void PortReInitBmu(
842 SK_AC
*pAC
, /* pointer to adapter context */
843 int PortIndex
) /* index of the port for which to re-init */
845 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
848 /* set address of first descriptor of ring in BMU */
849 SK_OUT32(pAC
->IoBase
, TxQueueAddr
[PortIndex
][TX_PRIO_LOW
]+ Q_DA_L
,
850 (uint32_t)(((caddr_t
)
851 (pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxdRingHead
) -
852 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxDescrRing
+
853 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].VTxDescrRing
) &
855 SK_OUT32(pAC
->IoBase
, TxQueueAddr
[PortIndex
][TX_PRIO_LOW
]+ Q_DA_H
,
856 (uint32_t)(((caddr_t
)
857 (pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxdRingHead
) -
858 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].pTxDescrRing
+
859 pAC
->TxPort
[PortIndex
][TX_PRIO_LOW
].VTxDescrRing
) >> 32));
860 SK_OUT32(pAC
->IoBase
, RxQueueAddr
[PortIndex
]+Q_DA_L
,
861 (uint32_t)(((caddr_t
)(pAC
->RxPort
[PortIndex
].pRxdRingHead
) -
862 pAC
->RxPort
[PortIndex
].pRxDescrRing
+
863 pAC
->RxPort
[PortIndex
].VRxDescrRing
) & 0xFFFFFFFF));
864 SK_OUT32(pAC
->IoBase
, RxQueueAddr
[PortIndex
]+Q_DA_H
,
865 (uint32_t)(((caddr_t
)(pAC
->RxPort
[PortIndex
].pRxdRingHead
) -
866 pAC
->RxPort
[PortIndex
].pRxDescrRing
+
867 pAC
->RxPort
[PortIndex
].VRxDescrRing
) >> 32));
868 } /* PortReInitBmu */
871 /****************************************************************************
873 * SkGeIsr - handle adapter interrupts
876 * The interrupt routine is called when the network adapter
877 * generates an interrupt. It may also be called if another device
878 * shares this interrupt vector with the driver.
883 static SkIsrRetVar
SkGeIsr(int irq
, void *dev_id
, struct pt_regs
*ptregs
)
885 struct SK_NET_DEVICE
*dev
= (struct SK_NET_DEVICE
*)dev_id
;
888 SK_U32 IntSrc
; /* interrupts source register contents */
890 pNet
= (DEV_NET
*) dev
->priv
;
894 * Check and process if its our interrupt
896 SK_IN32(pAC
->IoBase
, B0_SP_ISRC
, &IntSrc
);
901 while (((IntSrc
& IRQ_MASK
) & ~SPECIAL_IRQS
) != 0) {
902 #if 0 /* software irq currently not used */
903 if (IntSrc
& IS_IRQ_SW
) {
904 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
905 SK_DBGCAT_DRV_INT_SRC
,
909 if (IntSrc
& IS_R1_F
) {
910 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
911 SK_DBGCAT_DRV_INT_SRC
,
913 ReceiveIrq(pAC
, &pAC
->RxPort
[0], SK_TRUE
);
914 SK_PNMI_CNT_RX_INTR(pAC
, 0);
916 if (IntSrc
& IS_R2_F
) {
917 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
918 SK_DBGCAT_DRV_INT_SRC
,
920 ReceiveIrq(pAC
, &pAC
->RxPort
[1], SK_TRUE
);
921 SK_PNMI_CNT_RX_INTR(pAC
, 1);
923 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
924 if (IntSrc
& IS_XA1_F
) {
925 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
926 SK_DBGCAT_DRV_INT_SRC
,
927 ("EOF AS TX1 IRQ\n"));
928 SK_PNMI_CNT_TX_INTR(pAC
, 0);
929 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
930 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
931 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
933 if (IntSrc
& IS_XA2_F
) {
934 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
935 SK_DBGCAT_DRV_INT_SRC
,
936 ("EOF AS TX2 IRQ\n"));
937 SK_PNMI_CNT_TX_INTR(pAC
, 1);
938 spin_lock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
939 FreeTxDescriptors(pAC
, &pAC
->TxPort
[1][TX_PRIO_LOW
]);
940 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_LOW
].TxDesRingLock
);
942 #if 0 /* only if sync. queues used */
943 if (IntSrc
& IS_XS1_F
) {
944 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
945 SK_DBGCAT_DRV_INT_SRC
,
946 ("EOF SY TX1 IRQ\n"));
947 SK_PNMI_CNT_TX_INTR(pAC
, 1);
948 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
949 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
950 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
951 ClearTxIrq(pAC
, 0, TX_PRIO_HIGH
);
953 if (IntSrc
& IS_XS2_F
) {
954 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
955 SK_DBGCAT_DRV_INT_SRC
,
956 ("EOF SY TX2 IRQ\n"));
957 SK_PNMI_CNT_TX_INTR(pAC
, 1);
958 spin_lock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
959 FreeTxDescriptors(pAC
, 1, TX_PRIO_HIGH
);
960 spin_unlock(&pAC
->TxPort
[1][TX_PRIO_HIGH
].TxDesRingLock
);
961 ClearTxIrq(pAC
, 1, TX_PRIO_HIGH
);
966 /* do all IO at once */
967 if (IntSrc
& IS_R1_F
)
968 ClearAndStartRx(pAC
, 0);
969 if (IntSrc
& IS_R2_F
)
970 ClearAndStartRx(pAC
, 1);
971 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
972 if (IntSrc
& IS_XA1_F
)
973 ClearTxIrq(pAC
, 0, TX_PRIO_LOW
);
974 if (IntSrc
& IS_XA2_F
)
975 ClearTxIrq(pAC
, 1, TX_PRIO_LOW
);
977 SK_IN32(pAC
->IoBase
, B0_ISRC
, &IntSrc
);
978 } /* while (IntSrc & IRQ_MASK != 0) */
980 IntSrc
&= pAC
->GIni
.GIValIrqMask
;
981 if ((IntSrc
& SPECIAL_IRQS
) || pAC
->CheckQueue
) {
982 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_INT_SRC
,
983 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc
));
984 pAC
->CheckQueue
= SK_FALSE
;
985 spin_lock(&pAC
->SlowPathLock
);
986 if (IntSrc
& SPECIAL_IRQS
)
987 SkGeSirqIsr(pAC
, pAC
->IoBase
, IntSrc
);
989 SkEventDispatcher(pAC
, pAC
->IoBase
);
990 spin_unlock(&pAC
->SlowPathLock
);
993 * do it all again is case we cleared an interrupt that
994 * came in after handling the ring (OUTs may be delayed
995 * in hardware buffers, but are through after IN)
997 * rroesler: has been commented out and shifted to
998 * SkGeDrvEvent(), because it is timer
1001 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1002 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1005 if (pAC
->CheckQueue
) {
1006 pAC
->CheckQueue
= SK_FALSE
;
1007 spin_lock(&pAC
->SlowPathLock
);
1008 SkEventDispatcher(pAC
, pAC
->IoBase
);
1009 spin_unlock(&pAC
->SlowPathLock
);
1012 /* IRQ is processed - Enable IRQs again*/
1013 SK_OUT32(pAC
->IoBase
, B0_IMSK
, pAC
->GIni
.GIValIrqMask
);
1015 return SkIsrRetHandled
;
1019 /****************************************************************************
1021 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1024 * The interrupt routine is called when the network adapter
1025 * generates an interrupt. It may also be called if another device
1026 * shares this interrupt vector with the driver.
1027 * This is the same as above, but handles only one port.
1032 static SkIsrRetVar
SkGeIsrOnePort(int irq
, void *dev_id
, struct pt_regs
*ptregs
)
1034 struct SK_NET_DEVICE
*dev
= (struct SK_NET_DEVICE
*)dev_id
;
1037 SK_U32 IntSrc
; /* interrupts source register contents */
1039 pNet
= (DEV_NET
*) dev
->priv
;
1043 * Check and process if its our interrupt
1045 SK_IN32(pAC
->IoBase
, B0_SP_ISRC
, &IntSrc
);
1047 return SkIsrRetNone
;
1050 while (((IntSrc
& IRQ_MASK
) & ~SPECIAL_IRQS
) != 0) {
1051 #if 0 /* software irq currently not used */
1052 if (IntSrc
& IS_IRQ_SW
) {
1053 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1054 SK_DBGCAT_DRV_INT_SRC
,
1055 ("Software IRQ\n"));
1058 if (IntSrc
& IS_R1_F
) {
1059 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1060 SK_DBGCAT_DRV_INT_SRC
,
1062 ReceiveIrq(pAC
, &pAC
->RxPort
[0], SK_TRUE
);
1063 SK_PNMI_CNT_RX_INTR(pAC
, 0);
1065 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1066 if (IntSrc
& IS_XA1_F
) {
1067 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1068 SK_DBGCAT_DRV_INT_SRC
,
1069 ("EOF AS TX1 IRQ\n"));
1070 SK_PNMI_CNT_TX_INTR(pAC
, 0);
1071 spin_lock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1072 FreeTxDescriptors(pAC
, &pAC
->TxPort
[0][TX_PRIO_LOW
]);
1073 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_LOW
].TxDesRingLock
);
1075 #if 0 /* only if sync. queues used */
1076 if (IntSrc
& IS_XS1_F
) {
1077 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1078 SK_DBGCAT_DRV_INT_SRC
,
1079 ("EOF SY TX1 IRQ\n"));
1080 SK_PNMI_CNT_TX_INTR(pAC
, 0);
1081 spin_lock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1082 FreeTxDescriptors(pAC
, 0, TX_PRIO_HIGH
);
1083 spin_unlock(&pAC
->TxPort
[0][TX_PRIO_HIGH
].TxDesRingLock
);
1084 ClearTxIrq(pAC
, 0, TX_PRIO_HIGH
);
1089 /* do all IO at once */
1090 if (IntSrc
& IS_R1_F
)
1091 ClearAndStartRx(pAC
, 0);
1092 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1093 if (IntSrc
& IS_XA1_F
)
1094 ClearTxIrq(pAC
, 0, TX_PRIO_LOW
);
1096 SK_IN32(pAC
->IoBase
, B0_ISRC
, &IntSrc
);
1097 } /* while (IntSrc & IRQ_MASK != 0) */
1099 IntSrc
&= pAC
->GIni
.GIValIrqMask
;
1100 if ((IntSrc
& SPECIAL_IRQS
) || pAC
->CheckQueue
) {
1101 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_INT_SRC
,
1102 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc
));
1103 pAC
->CheckQueue
= SK_FALSE
;
1104 spin_lock(&pAC
->SlowPathLock
);
1105 if (IntSrc
& SPECIAL_IRQS
)
1106 SkGeSirqIsr(pAC
, pAC
->IoBase
, IntSrc
);
1108 SkEventDispatcher(pAC
, pAC
->IoBase
);
1109 spin_unlock(&pAC
->SlowPathLock
);
1112 * do it all again is case we cleared an interrupt that
1113 * came in after handling the ring (OUTs may be delayed
1114 * in hardware buffers, but are through after IN)
1116 * rroesler: has been commented out and shifted to
1117 * SkGeDrvEvent(), because it is timer
1120 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1123 /* IRQ is processed - Enable IRQs again*/
1124 SK_OUT32(pAC
->IoBase
, B0_IMSK
, pAC
->GIni
.GIValIrqMask
);
1126 return SkIsrRetHandled
;
1127 } /* SkGeIsrOnePort */
1130 /****************************************************************************
1132 * SkGeOpen - handle start of initialized adapter
1135 * This function starts the initialized adapter.
1136 * The board level variable is set and the adapter is
1137 * brought to full functionality.
1138 * The device flags are set for operation.
1139 * Do all necessary level 2 initialization, enable interrupts and
1140 * give start command to RLMT.
1146 static int SkGeOpen(
1147 struct SK_NET_DEVICE
*dev
)
1151 unsigned long Flags
; /* for spin lock */
1153 SK_EVPARA EvPara
; /* an event parameter union */
1155 pNet
= (DEV_NET
*) dev
->priv
;
1158 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1159 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC
));
1161 #ifdef SK_DIAG_SUPPORT
1162 if (pAC
->DiagModeActive
== DIAG_ACTIVE
) {
1163 if (pAC
->Pnmi
.DiagAttached
== SK_DIAG_RUNNING
) {
1164 return (-1); /* still in use by diag; deny actions */
1169 if (!try_module_get(THIS_MODULE
)) {
1170 return (-1); /* increase of usage count not possible */
1173 /* Set blink mode */
1174 if ((pAC
->PciDev
->vendor
== 0x1186) || (pAC
->PciDev
->vendor
== 0x11ab ))
1175 pAC
->GIni
.GILedBlinkCtrl
= OEM_CONFIG_VALUE
;
1177 if (pAC
->BoardLevel
== SK_INIT_DATA
) {
1178 /* level 1 init common modules here */
1179 if (SkGeInit(pAC
, pAC
->IoBase
, SK_INIT_IO
) != 0) {
1180 module_put(THIS_MODULE
); /* decrease usage count */
1181 printk("%s: HWInit (1) failed.\n", pAC
->dev
[pNet
->PortNr
]->name
);
1184 SkI2cInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1185 SkEventInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1186 SkPnmiInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1187 SkAddrInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1188 SkRlmtInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1189 SkTimerInit (pAC
, pAC
->IoBase
, SK_INIT_IO
);
1190 pAC
->BoardLevel
= SK_INIT_IO
;
1193 if (pAC
->BoardLevel
!= SK_INIT_RUN
) {
1194 /* tschilling: Level 2 init modules here, check return value. */
1195 if (SkGeInit(pAC
, pAC
->IoBase
, SK_INIT_RUN
) != 0) {
1196 module_put(THIS_MODULE
); /* decrease usage count */
1197 printk("%s: HWInit (2) failed.\n", pAC
->dev
[pNet
->PortNr
]->name
);
1200 SkI2cInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1201 SkEventInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1202 SkPnmiInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1203 SkAddrInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1204 SkRlmtInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1205 SkTimerInit (pAC
, pAC
->IoBase
, SK_INIT_RUN
);
1206 pAC
->BoardLevel
= SK_INIT_RUN
;
1209 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
1210 /* Enable transmit descriptor polling. */
1211 SkGePollTxD(pAC
, pAC
->IoBase
, i
, SK_TRUE
);
1212 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
1214 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
1216 StartDrvCleanupTimer(pAC
);
1217 SkDimEnableModerationIfNeeded(pAC
);
1218 SkDimDisplayModerationSettings(pAC
);
1220 pAC
->GIni
.GIValIrqMask
&= IRQ_MASK
;
1222 /* enable Interrupts */
1223 SK_OUT32(pAC
->IoBase
, B0_IMSK
, pAC
->GIni
.GIValIrqMask
);
1224 SK_OUT32(pAC
->IoBase
, B0_HWE_IMSK
, IRQ_HWE_MASK
);
1226 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
1228 if ((pAC
->RlmtMode
!= 0) && (pAC
->MaxPorts
== 0)) {
1229 EvPara
.Para32
[0] = pAC
->RlmtNets
;
1230 EvPara
.Para32
[1] = -1;
1231 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_SET_NETS
,
1233 EvPara
.Para32
[0] = pAC
->RlmtMode
;
1234 EvPara
.Para32
[1] = 0;
1235 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_MODE_CHANGE
,
1239 EvPara
.Para32
[0] = pNet
->NetNr
;
1240 EvPara
.Para32
[1] = -1;
1241 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
1242 SkEventDispatcher(pAC
, pAC
->IoBase
);
1243 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
1249 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1250 ("SkGeOpen suceeded\n"));
1256 /****************************************************************************
1258 * SkGeClose - Stop initialized adapter
1261 * Close initialized adapter.
1265 * error code - on error
1267 static int SkGeClose(
1268 struct SK_NET_DEVICE
*dev
)
1274 unsigned long Flags
; /* for spin lock */
1279 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1280 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC
));
1282 pNet
= (DEV_NET
*) dev
->priv
;
1285 #ifdef SK_DIAG_SUPPORT
1286 if (pAC
->DiagModeActive
== DIAG_ACTIVE
) {
1287 if (pAC
->DiagFlowCtrl
== SK_FALSE
) {
1288 module_put(THIS_MODULE
);
1290 ** notify that the interface which has been closed
1291 ** by operator interaction must not be started up
1292 ** again when the DIAG has finished.
1294 newPtrNet
= (DEV_NET
*) pAC
->dev
[0]->priv
;
1295 if (newPtrNet
== pNet
) {
1296 pAC
->WasIfUp
[0] = SK_FALSE
;
1298 pAC
->WasIfUp
[1] = SK_FALSE
;
1300 return 0; /* return to system everything is fine... */
1302 pAC
->DiagFlowCtrl
= SK_FALSE
;
1307 netif_stop_queue(dev
);
1309 if (pAC
->RlmtNets
== 1)
1310 PortIdx
= pAC
->ActivePort
;
1312 PortIdx
= pNet
->NetNr
;
1314 StopDrvCleanupTimer(pAC
);
1317 * Clear multicast table, promiscuous mode ....
1319 SkAddrMcClear(pAC
, pAC
->IoBase
, PortIdx
, 0);
1320 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, PortIdx
,
1323 if (pAC
->MaxPorts
== 1) {
1324 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
1325 /* disable interrupts */
1326 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
1327 EvPara
.Para32
[0] = pNet
->NetNr
;
1328 EvPara
.Para32
[1] = -1;
1329 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
1330 SkEventDispatcher(pAC
, pAC
->IoBase
);
1331 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
1332 /* stop the hardware */
1333 SkGeDeInit(pAC
, pAC
->IoBase
);
1334 pAC
->BoardLevel
= SK_INIT_DATA
;
1335 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
1338 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
1339 EvPara
.Para32
[0] = pNet
->NetNr
;
1340 EvPara
.Para32
[1] = -1;
1341 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
1342 SkPnmiEvent(pAC
, pAC
->IoBase
, SK_PNMI_EVT_XMAC_RESET
, EvPara
);
1343 SkEventDispatcher(pAC
, pAC
->IoBase
);
1344 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
1347 spin_lock_irqsave(&pAC
->TxPort
[pNet
->PortNr
]
1348 [TX_PRIO_LOW
].TxDesRingLock
, Flags
);
1349 SkGeStopPort(pAC
, pAC
->IoBase
, pNet
->PortNr
,
1350 SK_STOP_ALL
, SK_HARD_RST
);
1351 spin_unlock_irqrestore(&pAC
->TxPort
[pNet
->PortNr
]
1352 [TX_PRIO_LOW
].TxDesRingLock
, Flags
);
1355 if (pAC
->RlmtNets
== 1) {
1356 /* clear all descriptor rings */
1357 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
1358 ReceiveIrq(pAC
, &pAC
->RxPort
[i
], SK_TRUE
);
1359 ClearRxRing(pAC
, &pAC
->RxPort
[i
]);
1360 ClearTxRing(pAC
, &pAC
->TxPort
[i
][TX_PRIO_LOW
]);
1363 /* clear port descriptor rings */
1364 ReceiveIrq(pAC
, &pAC
->RxPort
[pNet
->PortNr
], SK_TRUE
);
1365 ClearRxRing(pAC
, &pAC
->RxPort
[pNet
->PortNr
]);
1366 ClearTxRing(pAC
, &pAC
->TxPort
[pNet
->PortNr
][TX_PRIO_LOW
]);
1369 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
1370 ("SkGeClose: done "));
1372 SK_MEMSET(&(pAC
->PnmiBackup
), 0, sizeof(SK_PNMI_STRUCT_DATA
));
1373 SK_MEMCPY(&(pAC
->PnmiBackup
), &(pAC
->PnmiStruct
),
1374 sizeof(SK_PNMI_STRUCT_DATA
));
1379 module_put(THIS_MODULE
);
1384 /*****************************************************************************
1386 * SkGeXmit - Linux frame transmit function
1389 * The system calls this function to send frames onto the wire.
1390 * It puts the frame in the tx descriptor ring. If the ring is
1391 * full then, the 'tbusy' flag is set.
1394 * 0, if everything is ok
1396 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1397 * allocated skb's) !!!
1399 static int SkGeXmit(struct sk_buff
*skb
, struct SK_NET_DEVICE
*dev
)
1403 int Rc
; /* return code of XmitFrame */
1405 pNet
= (DEV_NET
*) dev
->priv
;
1408 if ((!skb_shinfo(skb
)->nr_frags
) ||
1409 (pAC
->GIni
.GIChipId
== CHIP_ID_GENESIS
)) {
1410 /* Don't activate scatter-gather and hardware checksum */
1412 if (pAC
->RlmtNets
== 2)
1415 &pAC
->TxPort
[pNet
->PortNr
][TX_PRIO_LOW
],
1420 &pAC
->TxPort
[pAC
->ActivePort
][TX_PRIO_LOW
],
1423 /* scatter-gather and hardware TCP checksumming anabled*/
1424 if (pAC
->RlmtNets
== 2)
1427 &pAC
->TxPort
[pNet
->PortNr
][TX_PRIO_LOW
],
1432 &pAC
->TxPort
[pAC
->ActivePort
][TX_PRIO_LOW
],
1436 /* Transmitter out of resources? */
1438 netif_stop_queue(dev
);
1441 /* If not taken, give buffer ownership back to the
1447 dev
->trans_start
= jiffies
;
1452 /*****************************************************************************
1454 * XmitFrame - fill one socket buffer into the transmit ring
1457 * This function puts a message into the transmit descriptor ring
1458 * if there is a descriptors left.
1459 * Linux skb's consist of only one continuous buffer.
1460 * The first step locks the ring. It is held locked
1461 * all time to avoid problems with SWITCH_../PORT_RESET.
1462 * Then the descriptoris allocated.
1463 * The second part is linking the buffer to the descriptor.
1464 * At the very last, the Control field of the descriptor
1465 * is made valid for the BMU and a start TX command is given
1469 * > 0 - on succes: the number of bytes in the message
1470 * = 0 - on resource shortage: this frame sent or dropped, now
1471 * the ring is full ( -> set tbusy)
1472 * < 0 - on failure: other problems ( -> return failure to upper layers)
1474 static int XmitFrame(
1475 SK_AC
*pAC
, /* pointer to adapter context */
1476 TX_PORT
*pTxPort
, /* pointer to struct of port to send to */
1477 struct sk_buff
*pMessage
) /* pointer to send-message */
1479 TXD
*pTxd
; /* the rxd to fill */
1481 unsigned long Flags
;
1485 int BytesSend
= pMessage
->len
;
1487 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_TX_PROGRESS
, ("X"));
1489 spin_lock_irqsave(&pTxPort
->TxDesRingLock
, Flags
);
1490 #ifndef USE_TX_COMPLETE
1491 FreeTxDescriptors(pAC
, pTxPort
);
1493 if (pTxPort
->TxdRingFree
== 0) {
1495 ** no enough free descriptors in ring at the moment.
1496 ** Maybe free'ing some old one help?
1498 FreeTxDescriptors(pAC
, pTxPort
);
1499 if (pTxPort
->TxdRingFree
== 0) {
1500 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1501 SK_PNMI_CNT_NO_TX_BUF(pAC
, pTxPort
->PortIndex
);
1502 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1503 SK_DBGCAT_DRV_TX_PROGRESS
,
1504 ("XmitFrame failed\n"));
1506 ** the desired message can not be sent
1507 ** Because tbusy seems to be set, the message
1508 ** should not be freed here. It will be used
1509 ** by the scheduler of the ethernet handler
1516 ** If the passed socket buffer is of smaller MTU-size than 60,
1517 ** copy everything into new buffer and fill all bytes between
1518 ** the original packet end and the new packet end of 60 with 0x00.
1519 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1521 if (BytesSend
< C_LEN_ETHERNET_MINSIZE
) {
1522 if ((pMessage
= skb_padto(pMessage
, C_LEN_ETHERNET_MINSIZE
)) == NULL
) {
1523 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1526 pMessage
->len
= C_LEN_ETHERNET_MINSIZE
;
1530 ** advance head counter behind descriptor needed for this frame,
1531 ** so that needed descriptor is reserved from that on. The next
1532 ** action will be to add the passed buffer to the TX-descriptor
1534 pTxd
= pTxPort
->pTxdRingHead
;
1535 pTxPort
->pTxdRingHead
= pTxd
->pNextTxd
;
1536 pTxPort
->TxdRingFree
--;
1539 DumpMsg(pMessage
, "XmitFrame");
1543 ** First step is to map the data to be sent via the adapter onto
1544 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1545 ** and 2.6 need to use pci_map_page() for that mapping.
1547 PhysAddr
= (SK_U64
) pci_map_page(pAC
->PciDev
,
1548 virt_to_page(pMessage
->data
),
1549 ((unsigned long) pMessage
->data
& ~PAGE_MASK
),
1552 pTxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1553 pTxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1554 pTxd
->pMBuf
= pMessage
;
1556 if (pMessage
->ip_summed
== CHECKSUM_HW
) {
1557 Protocol
= ((SK_U8
)pMessage
->data
[C_OFFSET_IPPROTO
] & 0xff);
1558 if ((Protocol
== C_PROTO_ID_UDP
) &&
1559 (pAC
->GIni
.GIChipRev
== 0) &&
1560 (pAC
->GIni
.GIChipId
== CHIP_ID_YUKON
)) {
1561 pTxd
->TBControl
= BMU_TCP_CHECK
;
1563 pTxd
->TBControl
= BMU_UDP_CHECK
;
1566 IpHeaderLength
= (SK_U8
)pMessage
->data
[C_OFFSET_IPHEADER
];
1567 IpHeaderLength
= (IpHeaderLength
& 0xf) * 4;
1568 pTxd
->TcpSumOfs
= 0; /* PH-Checksum already calculated */
1569 pTxd
->TcpSumSt
= C_LEN_ETHERMAC_HEADER
+ IpHeaderLength
+
1570 (Protocol
== C_PROTO_ID_UDP
?
1571 C_OFFSET_UDPHEADER_UDPCS
:
1572 C_OFFSET_TCPHEADER_TCPCS
);
1573 pTxd
->TcpSumWr
= C_LEN_ETHERMAC_HEADER
+ IpHeaderLength
;
1575 pTxd
->TBControl
|= BMU_OWN
| BMU_STF
|
1577 #ifdef USE_TX_COMPLETE
1582 pTxd
->TBControl
= BMU_OWN
| BMU_STF
| BMU_CHECK
|
1584 #ifdef USE_TX_COMPLETE
1591 ** If previous descriptor already done, give TX start cmd
1593 pOldTxd
= xchg(&pTxPort
->pTxdRingPrev
, pTxd
);
1594 if ((pOldTxd
->TBControl
& BMU_OWN
) == 0) {
1595 SK_OUT8(pTxPort
->HwAddr
, Q_CSR
, CSR_START
);
1599 ** after releasing the lock, the skb may immediately be free'd
1601 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1602 if (pTxPort
->TxdRingFree
!= 0) {
1610 /*****************************************************************************
1612 * XmitFrameSG - fill one socket buffer into the transmit ring
1613 * (use SG and TCP/UDP hardware checksumming)
1616 * This function puts a message into the transmit descriptor ring
1617 * if there is a descriptors left.
1620 * > 0 - on succes: the number of bytes in the message
1621 * = 0 - on resource shortage: this frame sent or dropped, now
1622 * the ring is full ( -> set tbusy)
1623 * < 0 - on failure: other problems ( -> return failure to upper layers)
1625 static int XmitFrameSG(
1626 SK_AC
*pAC
, /* pointer to adapter context */
1627 TX_PORT
*pTxPort
, /* pointer to struct of port to send to */
1628 struct sk_buff
*pMessage
) /* pointer to send-message */
1638 skb_frag_t
*sk_frag
;
1640 unsigned long Flags
;
1642 spin_lock_irqsave(&pTxPort
->TxDesRingLock
, Flags
);
1643 #ifndef USE_TX_COMPLETE
1644 FreeTxDescriptors(pAC
, pTxPort
);
1646 if ((skb_shinfo(pMessage
)->nr_frags
+1) > pTxPort
->TxdRingFree
) {
1647 FreeTxDescriptors(pAC
, pTxPort
);
1648 if ((skb_shinfo(pMessage
)->nr_frags
+ 1) > pTxPort
->TxdRingFree
) {
1649 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1650 SK_PNMI_CNT_NO_TX_BUF(pAC
, pTxPort
->PortIndex
);
1651 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1652 SK_DBGCAT_DRV_TX_PROGRESS
,
1653 ("XmitFrameSG failed - Ring full\n"));
1654 /* this message can not be sent now */
1659 pTxd
= pTxPort
->pTxdRingHead
;
1666 ** Map the first fragment (header) into the DMA-space
1668 PhysAddr
= (SK_U64
) pci_map_page(pAC
->PciDev
,
1669 virt_to_page(pMessage
->data
),
1670 ((unsigned long) pMessage
->data
& ~PAGE_MASK
),
1671 skb_headlen(pMessage
),
1674 pTxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1675 pTxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1678 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1680 if (pMessage
->ip_summed
== CHECKSUM_HW
) {
1681 pTxd
->TBControl
= BMU_STF
| BMU_STFWD
| skb_headlen(pMessage
);
1683 ** We have to use the opcode for tcp here, because the
1684 ** opcode for udp is not working in the hardware yet
1687 Protocol
= ((SK_U8
)pMessage
->data
[C_OFFSET_IPPROTO
] & 0xff);
1688 if ((Protocol
== C_PROTO_ID_UDP
) &&
1689 (pAC
->GIni
.GIChipRev
== 0) &&
1690 (pAC
->GIni
.GIChipId
== CHIP_ID_YUKON
)) {
1691 pTxd
->TBControl
|= BMU_TCP_CHECK
;
1693 pTxd
->TBControl
|= BMU_UDP_CHECK
;
1696 IpHeaderLength
= ((SK_U8
)pMessage
->data
[C_OFFSET_IPHEADER
] & 0xf)*4;
1697 pTxd
->TcpSumOfs
= 0; /* PH-Checksum already claculated */
1698 pTxd
->TcpSumSt
= C_LEN_ETHERMAC_HEADER
+ IpHeaderLength
+
1699 (Protocol
== C_PROTO_ID_UDP
?
1700 C_OFFSET_UDPHEADER_UDPCS
:
1701 C_OFFSET_TCPHEADER_TCPCS
);
1702 pTxd
->TcpSumWr
= C_LEN_ETHERMAC_HEADER
+ IpHeaderLength
;
1704 pTxd
->TBControl
= BMU_CHECK
| BMU_SW
| BMU_STF
|
1705 skb_headlen(pMessage
);
1708 pTxd
= pTxd
->pNextTxd
;
1709 pTxPort
->TxdRingFree
--;
1710 BytesSend
+= skb_headlen(pMessage
);
1713 ** Browse over all SG fragments and map each of them into the DMA space
1715 for (CurrFrag
= 0; CurrFrag
< skb_shinfo(pMessage
)->nr_frags
; CurrFrag
++) {
1716 sk_frag
= &skb_shinfo(pMessage
)->frags
[CurrFrag
];
1718 ** we already have the proper value in entry
1720 PhysAddr
= (SK_U64
) pci_map_page(pAC
->PciDev
,
1722 sk_frag
->page_offset
,
1726 pTxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1727 pTxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1728 pTxd
->pMBuf
= pMessage
;
1731 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1733 if (pMessage
->ip_summed
== CHECKSUM_HW
) {
1734 pTxd
->TBControl
= BMU_OWN
| BMU_SW
| BMU_STFWD
;
1736 ** We have to use the opcode for tcp here because the
1737 ** opcode for udp is not working in the hardware yet
1740 if ((Protocol
== C_PROTO_ID_UDP
) &&
1741 (pAC
->GIni
.GIChipRev
== 0) &&
1742 (pAC
->GIni
.GIChipId
== CHIP_ID_YUKON
)) {
1743 pTxd
->TBControl
|= BMU_TCP_CHECK
;
1745 pTxd
->TBControl
|= BMU_UDP_CHECK
;
1748 pTxd
->TBControl
= BMU_CHECK
| BMU_SW
| BMU_OWN
;
1752 ** Do we have the last fragment?
1754 if( (CurrFrag
+1) == skb_shinfo(pMessage
)->nr_frags
) {
1755 #ifdef USE_TX_COMPLETE
1756 pTxd
->TBControl
|= BMU_EOF
| BMU_IRQ_EOF
| sk_frag
->size
;
1758 pTxd
->TBControl
|= BMU_EOF
| sk_frag
->size
;
1760 pTxdFst
->TBControl
|= BMU_OWN
| BMU_SW
;
1763 pTxd
->TBControl
|= sk_frag
->size
;
1766 pTxd
= pTxd
->pNextTxd
;
1767 pTxPort
->TxdRingFree
--;
1768 BytesSend
+= sk_frag
->size
;
1772 ** If previous descriptor already done, give TX start cmd
1774 if ((pTxPort
->pTxdRingPrev
->TBControl
& BMU_OWN
) == 0) {
1775 SK_OUT8(pTxPort
->HwAddr
, Q_CSR
, CSR_START
);
1778 pTxPort
->pTxdRingPrev
= pTxdLst
;
1779 pTxPort
->pTxdRingHead
= pTxd
;
1781 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
1783 if (pTxPort
->TxdRingFree
> 0) {
1790 /*****************************************************************************
1792 * FreeTxDescriptors - release descriptors from the descriptor ring
1795 * This function releases descriptors from a transmit ring if they
1796 * have been sent by the BMU.
1797 * If a descriptors is sent, it can be freed and the message can
1799 * The SOFTWARE controllable bit is used to prevent running around a
1800 * completely free ring for ever. If this bit is no set in the
1801 * frame (by XmitFrame), this frame has never been sent or is
1803 * The Tx descriptor ring lock must be held while calling this function !!!
1808 static void FreeTxDescriptors(
1809 SK_AC
*pAC
, /* pointer to the adapter context */
1810 TX_PORT
*pTxPort
) /* pointer to destination port structure */
1812 TXD
*pTxd
; /* pointer to the checked descriptor */
1813 TXD
*pNewTail
; /* pointer to 'end' of the ring */
1814 SK_U32 Control
; /* TBControl field of descriptor */
1815 SK_U64 PhysAddr
; /* address of DMA mapping */
1817 pNewTail
= pTxPort
->pTxdRingTail
;
1820 ** loop forever; exits if BMU_SW bit not set in start frame
1821 ** or BMU_OWN bit set in any frame
1824 Control
= pTxd
->TBControl
;
1825 if ((Control
& BMU_SW
) == 0) {
1827 ** software controllable bit is set in first
1828 ** fragment when given to BMU. Not set means that
1829 ** this fragment was never sent or is already
1830 ** freed ( -> ring completely free now).
1832 pTxPort
->pTxdRingTail
= pTxd
;
1833 netif_wake_queue(pAC
->dev
[pTxPort
->PortIndex
]);
1836 if (Control
& BMU_OWN
) {
1837 pTxPort
->pTxdRingTail
= pTxd
;
1838 if (pTxPort
->TxdRingFree
> 0) {
1839 netif_wake_queue(pAC
->dev
[pTxPort
->PortIndex
]);
1845 ** release the DMA mapping, because until not unmapped
1846 ** this buffer is considered being under control of the
1849 PhysAddr
= ((SK_U64
) pTxd
->VDataHigh
) << (SK_U64
) 32;
1850 PhysAddr
|= (SK_U64
) pTxd
->VDataLow
;
1851 pci_unmap_page(pAC
->PciDev
, PhysAddr
,
1855 if (Control
& BMU_EOF
)
1856 DEV_KFREE_SKB_ANY(pTxd
->pMBuf
); /* free message */
1858 pTxPort
->TxdRingFree
++;
1859 pTxd
->TBControl
&= ~BMU_SW
;
1860 pTxd
= pTxd
->pNextTxd
; /* point behind fragment with EOF */
1861 } /* while(forever) */
1862 } /* FreeTxDescriptors */
1864 /*****************************************************************************
1866 * FillRxRing - fill the receive ring with valid descriptors
1869 * This function fills the receive ring descriptors with data
1870 * segments and makes them valid for the BMU.
1871 * The active ring is filled completely, if possible.
1872 * The non-active ring is filled only partial to save memory.
1874 * Description of rx ring structure:
1875 * head - points to the descriptor which will be used next by the BMU
1876 * tail - points to the next descriptor to give to the BMU
1880 static void FillRxRing(
1881 SK_AC
*pAC
, /* pointer to the adapter context */
1882 RX_PORT
*pRxPort
) /* ptr to port struct for which the ring
1885 unsigned long Flags
;
1887 spin_lock_irqsave(&pRxPort
->RxDesRingLock
, Flags
);
1888 while (pRxPort
->RxdRingFree
> pRxPort
->RxFillLimit
) {
1889 if(!FillRxDescriptor(pAC
, pRxPort
))
1892 spin_unlock_irqrestore(&pRxPort
->RxDesRingLock
, Flags
);
1896 /*****************************************************************************
1898 * FillRxDescriptor - fill one buffer into the receive ring
1901 * The function allocates a new receive buffer and
1902 * puts it into the next descriptor.
1905 * SK_TRUE - a buffer was added to the ring
1906 * SK_FALSE - a buffer could not be added
1908 static SK_BOOL
FillRxDescriptor(
1909 SK_AC
*pAC
, /* pointer to the adapter context struct */
1910 RX_PORT
*pRxPort
) /* ptr to port struct of ring to fill */
1912 struct sk_buff
*pMsgBlock
; /* pointer to a new message block */
1913 RXD
*pRxd
; /* the rxd to fill */
1914 SK_U16 Length
; /* data fragment length */
1915 SK_U64 PhysAddr
; /* physical address of a rx buffer */
1917 pMsgBlock
= alloc_skb(pAC
->RxBufSize
, GFP_ATOMIC
);
1918 if (pMsgBlock
== NULL
) {
1919 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
1920 SK_DBGCAT_DRV_ENTRY
,
1921 ("%s: Allocation of rx buffer failed !\n",
1922 pAC
->dev
[pRxPort
->PortIndex
]->name
));
1923 SK_PNMI_CNT_NO_RX_BUF(pAC
, pRxPort
->PortIndex
);
1926 skb_reserve(pMsgBlock
, 2); /* to align IP frames */
1927 /* skb allocated ok, so add buffer */
1928 pRxd
= pRxPort
->pRxdRingTail
;
1929 pRxPort
->pRxdRingTail
= pRxd
->pNextRxd
;
1930 pRxPort
->RxdRingFree
--;
1931 Length
= pAC
->RxBufSize
;
1932 PhysAddr
= (SK_U64
) pci_map_page(pAC
->PciDev
,
1933 virt_to_page(pMsgBlock
->data
),
1934 ((unsigned long) pMsgBlock
->data
&
1937 PCI_DMA_FROMDEVICE
);
1939 pRxd
->VDataLow
= (SK_U32
) (PhysAddr
& 0xffffffff);
1940 pRxd
->VDataHigh
= (SK_U32
) (PhysAddr
>> 32);
1941 pRxd
->pMBuf
= pMsgBlock
;
1942 pRxd
->RBControl
= BMU_OWN
|
1949 } /* FillRxDescriptor */
1952 /*****************************************************************************
1954 * ReQueueRxBuffer - fill one buffer back into the receive ring
1957 * Fill a given buffer back into the rx ring. The buffer
1958 * has been previously allocated and aligned, and its phys.
1959 * address calculated, so this is no more necessary.
1963 static void ReQueueRxBuffer(
1964 SK_AC
*pAC
, /* pointer to the adapter context struct */
1965 RX_PORT
*pRxPort
, /* ptr to port struct of ring to fill */
1966 struct sk_buff
*pMsg
, /* pointer to the buffer */
1967 SK_U32 PhysHigh
, /* phys address high dword */
1968 SK_U32 PhysLow
) /* phys address low dword */
1970 RXD
*pRxd
; /* the rxd to fill */
1971 SK_U16 Length
; /* data fragment length */
1973 pRxd
= pRxPort
->pRxdRingTail
;
1974 pRxPort
->pRxdRingTail
= pRxd
->pNextRxd
;
1975 pRxPort
->RxdRingFree
--;
1976 Length
= pAC
->RxBufSize
;
1978 pRxd
->VDataLow
= PhysLow
;
1979 pRxd
->VDataHigh
= PhysHigh
;
1981 pRxd
->RBControl
= BMU_OWN
|
1987 } /* ReQueueRxBuffer */
1989 /*****************************************************************************
1991 * ReceiveIrq - handle a receive IRQ
1994 * This function is called when a receive IRQ is set.
1995 * It walks the receive descriptor ring and sends up all
1996 * frames that are complete.
2000 static void ReceiveIrq(
2001 SK_AC
*pAC
, /* pointer to adapter context */
2002 RX_PORT
*pRxPort
, /* pointer to receive port struct */
2003 SK_BOOL SlowPathLock
) /* indicates if SlowPathLock is needed */
2005 RXD
*pRxd
; /* pointer to receive descriptors */
2006 SK_U32 Control
; /* control field of descriptor */
2007 struct sk_buff
*pMsg
; /* pointer to message holding frame */
2008 struct sk_buff
*pNewMsg
; /* pointer to a new message for copying frame */
2009 int FrameLength
; /* total length of received frame */
2011 SK_MBUF
*pRlmtMbuf
; /* ptr to a buffer for giving a frame to rlmt */
2012 SK_EVPARA EvPara
; /* an event parameter union */
2013 unsigned long Flags
; /* for spin lock */
2014 int PortIndex
= pRxPort
->PortIndex
;
2015 unsigned int Offset
;
2016 unsigned int NumBytes
;
2017 unsigned int ForRlmt
;
2020 SK_BOOL IsBadFrame
; /* Bad frame */
2023 unsigned short Csum1
;
2024 unsigned short Csum2
;
2025 unsigned short Type
;
2030 /* do forever; exit if BMU_OWN found */
2031 for ( pRxd
= pRxPort
->pRxdRingHead
;
2032 pRxPort
->RxdRingFree
< pAC
->RxDescrPerRing
;
2033 pRxd
= pRxd
->pNextRxd
,
2034 pRxPort
->pRxdRingHead
= pRxd
,
2035 pRxPort
->RxdRingFree
++) {
2038 * For a better understanding of this loop
2039 * Go through every descriptor beginning at the head
2040 * Please note: the ring might be completely received so the OWN bit
2041 * set is not a good crirteria to leave that loop.
2042 * Therefore the RingFree counter is used.
2043 * On entry of this loop pRxd is a pointer to the Rxd that needs
2044 * to be checked next.
2047 Control
= pRxd
->RBControl
;
2049 /* check if this descriptor is ready */
2050 if ((Control
& BMU_OWN
) != 0) {
2051 /* this descriptor is not yet ready */
2052 /* This is the usual end of the loop */
2053 /* We don't need to start the ring again */
2054 FillRxRing(pAC
, pRxPort
);
2057 pAC
->DynIrqModInfo
.NbrProcessedDescr
++;
2059 /* get length of frame and check it */
2060 FrameLength
= Control
& BMU_BBC
;
2061 if (FrameLength
> pAC
->RxBufSize
) {
2065 /* check for STF and EOF */
2066 if ((Control
& (BMU_STF
| BMU_EOF
)) != (BMU_STF
| BMU_EOF
)) {
2070 /* here we have a complete frame in the ring */
2073 FrameStat
= pRxd
->FrameStat
;
2075 /* check for frame length mismatch */
2076 #define XMR_FS_LEN_SHIFT 18
2077 #define GMR_FS_LEN_SHIFT 16
2078 if (pAC
->GIni
.GIChipId
== CHIP_ID_GENESIS
) {
2079 if (FrameLength
!= (SK_U32
) (FrameStat
>> XMR_FS_LEN_SHIFT
)) {
2080 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2081 SK_DBGCAT_DRV_RX_PROGRESS
,
2082 ("skge: Frame length mismatch (%u/%u).\n",
2084 (SK_U32
) (FrameStat
>> XMR_FS_LEN_SHIFT
)));
2089 if (FrameLength
!= (SK_U32
) (FrameStat
>> GMR_FS_LEN_SHIFT
)) {
2090 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2091 SK_DBGCAT_DRV_RX_PROGRESS
,
2092 ("skge: Frame length mismatch (%u/%u).\n",
2094 (SK_U32
) (FrameStat
>> XMR_FS_LEN_SHIFT
)));
2100 if (pAC
->GIni
.GIChipId
== CHIP_ID_GENESIS
) {
2101 IsBc
= (FrameStat
& XMR_FS_BC
) != 0;
2102 IsMc
= (FrameStat
& XMR_FS_MC
) != 0;
2103 IsBadFrame
= (FrameStat
&
2104 (XMR_FS_ANY_ERR
| XMR_FS_2L_VLAN
)) != 0;
2106 IsBc
= (FrameStat
& GMR_FS_BC
) != 0;
2107 IsMc
= (FrameStat
& GMR_FS_MC
) != 0;
2108 IsBadFrame
= (((FrameStat
& GMR_FS_ANY_ERR
) != 0) ||
2109 ((FrameStat
& GMR_FS_RX_OK
) == 0));
2112 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, 0,
2113 ("Received frame of length %d on port %d\n",
2114 FrameLength
, PortIndex
));
2115 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, 0,
2116 ("Number of free rx descriptors: %d\n",
2117 pRxPort
->RxdRingFree
));
2118 /* DumpMsg(pMsg, "Rx"); */
2120 if ((Control
& BMU_STAT_VAL
) != BMU_STAT_VAL
|| (IsBadFrame
)) {
2122 (FrameStat
& (XMR_FS_ANY_ERR
| XMR_FS_2L_VLAN
)) != 0) {
2124 /* there is a receive error in this frame */
2125 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2126 SK_DBGCAT_DRV_RX_PROGRESS
,
2127 ("skge: Error in received frame, dropped!\n"
2128 "Control: %x\nRxStat: %x\n",
2129 Control
, FrameStat
));
2131 ReQueueRxBuffer(pAC
, pRxPort
, pMsg
,
2132 pRxd
->VDataHigh
, pRxd
->VDataLow
);
2138 * if short frame then copy data to reduce memory waste
2140 if ((FrameLength
< SK_COPY_THRESHOLD
) &&
2141 ((pNewMsg
= alloc_skb(FrameLength
+2, GFP_ATOMIC
)) != NULL
)) {
2143 * Short frame detected and allocation successfull
2145 /* use new skb and copy data */
2146 skb_reserve(pNewMsg
, 2);
2147 skb_put(pNewMsg
, FrameLength
);
2148 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2149 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2151 pci_dma_sync_single_for_cpu(pAC
->PciDev
,
2152 (dma_addr_t
) PhysAddr
,
2154 PCI_DMA_FROMDEVICE
);
2155 eth_copy_and_sum(pNewMsg
, pMsg
->data
,
2157 pci_dma_sync_single_for_device(pAC
->PciDev
,
2158 (dma_addr_t
) PhysAddr
,
2160 PCI_DMA_FROMDEVICE
);
2161 ReQueueRxBuffer(pAC
, pRxPort
, pMsg
,
2162 pRxd
->VDataHigh
, pRxd
->VDataLow
);
2169 * if large frame, or SKB allocation failed, pass
2170 * the SKB directly to the networking
2173 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2174 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2176 /* release the DMA mapping */
2177 pci_unmap_single(pAC
->PciDev
,
2180 PCI_DMA_FROMDEVICE
);
2182 /* set length in message */
2183 skb_put(pMsg
, FrameLength
);
2184 /* hardware checksum */
2185 Type
= ntohs(*((short*)&pMsg
->data
[12]));
2187 #ifdef USE_SK_RX_CHECKSUM
2188 if (Type
== 0x800) {
2189 Csum1
=le16_to_cpu(pRxd
->TcpSums
& 0xffff);
2190 Csum2
=le16_to_cpu((pRxd
->TcpSums
>> 16) & 0xffff);
2191 IpFrameLength
= (int) ntohs((unsigned short)
2192 ((unsigned short *) pMsg
->data
)[8]);
2195 * Test: If frame is padded, a check is not possible!
2196 * Frame not padded? Length difference must be 14 (0xe)!
2198 if ((FrameLength
- IpFrameLength
) != 0xe) {
2199 /* Frame padded => TCP offload not possible! */
2200 pMsg
->ip_summed
= CHECKSUM_NONE
;
2202 /* Frame not padded => TCP offload! */
2203 if ((((Csum1
& 0xfffe) && (Csum2
& 0xfffe)) &&
2204 (pAC
->GIni
.GIChipId
== CHIP_ID_GENESIS
)) ||
2205 (pAC
->ChipsetType
)) {
2206 Result
= SkCsGetReceiveInfo(pAC
,
2208 Csum1
, Csum2
, pRxPort
->PortIndex
);
2210 SKCS_STATUS_IP_FRAGMENT
||
2212 SKCS_STATUS_IP_CSUM_OK
||
2214 SKCS_STATUS_TCP_CSUM_OK
||
2216 SKCS_STATUS_UDP_CSUM_OK
) {
2218 CHECKSUM_UNNECESSARY
;
2221 SKCS_STATUS_TCP_CSUM_ERROR
||
2223 SKCS_STATUS_UDP_CSUM_ERROR
||
2225 SKCS_STATUS_IP_CSUM_ERROR_UDP
||
2227 SKCS_STATUS_IP_CSUM_ERROR_TCP
||
2229 SKCS_STATUS_IP_CSUM_ERROR
) {
2230 /* HW Checksum error */
2231 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2232 SK_DBGCAT_DRV_RX_PROGRESS
,
2233 ("skge: CRC error. Frame dropped!\n"));
2239 }/* checksumControl calculation valid */
2240 } /* Frame length check */
2243 pMsg
->ip_summed
= CHECKSUM_NONE
;
2245 } /* frame > SK_COPY_TRESHOLD */
2247 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, 1,("V"));
2248 ForRlmt
= SK_RLMT_RX_PROTOCOL
;
2250 IsBc
= (FrameStat
& XMR_FS_BC
)==XMR_FS_BC
;
2252 SK_RLMT_PRE_LOOKAHEAD(pAC
, PortIndex
, FrameLength
,
2253 IsBc
, &Offset
, &NumBytes
);
2254 if (NumBytes
!= 0) {
2256 IsMc
= (FrameStat
& XMR_FS_MC
)==XMR_FS_MC
;
2258 SK_RLMT_LOOKAHEAD(pAC
, PortIndex
,
2259 &pMsg
->data
[Offset
],
2260 IsBc
, IsMc
, &ForRlmt
);
2262 if (ForRlmt
== SK_RLMT_RX_PROTOCOL
) {
2263 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, 1,("W"));
2264 /* send up only frames from active port */
2265 if ((PortIndex
== pAC
->ActivePort
) ||
2266 (pAC
->RlmtNets
== 2)) {
2267 /* frame for upper layer */
2268 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, 1,("U"));
2270 DumpMsg(pMsg
, "Rx");
2272 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC
,
2273 FrameLength
, pRxPort
->PortIndex
);
2275 pMsg
->dev
= pAC
->dev
[pRxPort
->PortIndex
];
2276 pMsg
->protocol
= eth_type_trans(pMsg
,
2277 pAC
->dev
[pRxPort
->PortIndex
]);
2279 pAC
->dev
[pRxPort
->PortIndex
]->last_rx
= jiffies
;
2283 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2284 SK_DBGCAT_DRV_RX_PROGRESS
,
2286 DEV_KFREE_SKB(pMsg
);
2289 } /* if not for rlmt */
2291 /* packet for rlmt */
2292 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2293 SK_DBGCAT_DRV_RX_PROGRESS
, ("R"));
2294 pRlmtMbuf
= SkDrvAllocRlmtMbuf(pAC
,
2295 pAC
->IoBase
, FrameLength
);
2296 if (pRlmtMbuf
!= NULL
) {
2297 pRlmtMbuf
->pNext
= NULL
;
2298 pRlmtMbuf
->Length
= FrameLength
;
2299 pRlmtMbuf
->PortIdx
= PortIndex
;
2300 EvPara
.pParaPtr
= pRlmtMbuf
;
2301 memcpy((char*)(pRlmtMbuf
->pData
),
2302 (char*)(pMsg
->data
),
2305 /* SlowPathLock needed? */
2306 if (SlowPathLock
== SK_TRUE
) {
2307 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2308 SkEventQueue(pAC
, SKGE_RLMT
,
2309 SK_RLMT_PACKET_RECEIVED
,
2311 pAC
->CheckQueue
= SK_TRUE
;
2312 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2314 SkEventQueue(pAC
, SKGE_RLMT
,
2315 SK_RLMT_PACKET_RECEIVED
,
2317 pAC
->CheckQueue
= SK_TRUE
;
2320 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
,
2321 SK_DBGCAT_DRV_RX_PROGRESS
,
2324 if ((pAC
->dev
[pRxPort
->PortIndex
]->flags
&
2325 (IFF_PROMISC
| IFF_ALLMULTI
)) != 0 ||
2326 (ForRlmt
& SK_RLMT_RX_PROTOCOL
) ==
2327 SK_RLMT_RX_PROTOCOL
) {
2328 pMsg
->dev
= pAC
->dev
[pRxPort
->PortIndex
];
2329 pMsg
->protocol
= eth_type_trans(pMsg
,
2330 pAC
->dev
[pRxPort
->PortIndex
]);
2332 pAC
->dev
[pRxPort
->PortIndex
]->last_rx
= jiffies
;
2335 DEV_KFREE_SKB(pMsg
);
2338 } /* if packet for rlmt */
2339 } /* for ... scanning the RXD ring */
2341 /* RXD ring is empty -> fill and restart */
2342 FillRxRing(pAC
, pRxPort
);
2343 /* do not start if called from Close */
2344 if (pAC
->BoardLevel
> SK_INIT_DATA
) {
2345 ClearAndStartRx(pAC
, PortIndex
);
2350 /* remove error frame */
2351 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ERROR
,
2352 ("Schrottdescriptor, length: 0x%x\n", FrameLength
));
2354 /* release the DMA mapping */
2356 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2357 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2358 pci_unmap_page(pAC
->PciDev
,
2361 PCI_DMA_FROMDEVICE
);
2362 DEV_KFREE_SKB_IRQ(pRxd
->pMBuf
);
2364 pRxPort
->RxdRingFree
++;
2365 pRxPort
->pRxdRingHead
= pRxd
->pNextRxd
;
2371 /*****************************************************************************
2373 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2376 * This function sends a start command and a clear interrupt
2377 * command for one receive queue to the BMU.
2382 static void ClearAndStartRx(
2383 SK_AC
*pAC
, /* pointer to the adapter context */
2384 int PortIndex
) /* index of the receive port (XMAC) */
2386 SK_OUT8(pAC
->IoBase
,
2387 RxQueueAddr
[PortIndex
]+Q_CSR
,
2388 CSR_START
| CSR_IRQ_CL_F
);
2389 } /* ClearAndStartRx */
2392 /*****************************************************************************
2394 * ClearTxIrq - give a clear transmit IRQ command to BMU
2397 * This function sends a clear tx IRQ command for one
2398 * transmit queue to the BMU.
2402 static void ClearTxIrq(
2403 SK_AC
*pAC
, /* pointer to the adapter context */
2404 int PortIndex
, /* index of the transmit port (XMAC) */
2405 int Prio
) /* priority or normal queue */
2407 SK_OUT8(pAC
->IoBase
,
2408 TxQueueAddr
[PortIndex
][Prio
]+Q_CSR
,
2413 /*****************************************************************************
2415 * ClearRxRing - remove all buffers from the receive ring
2418 * This function removes all receive buffers from the ring.
2419 * The receive BMU must be stopped before calling this function.
2423 static void ClearRxRing(
2424 SK_AC
*pAC
, /* pointer to adapter context */
2425 RX_PORT
*pRxPort
) /* pointer to rx port struct */
2427 RXD
*pRxd
; /* pointer to the current descriptor */
2428 unsigned long Flags
;
2431 if (pRxPort
->RxdRingFree
== pAC
->RxDescrPerRing
) {
2434 spin_lock_irqsave(&pRxPort
->RxDesRingLock
, Flags
);
2435 pRxd
= pRxPort
->pRxdRingHead
;
2437 if (pRxd
->pMBuf
!= NULL
) {
2439 PhysAddr
= ((SK_U64
) pRxd
->VDataHigh
) << (SK_U64
)32;
2440 PhysAddr
|= (SK_U64
) pRxd
->VDataLow
;
2441 pci_unmap_page(pAC
->PciDev
,
2444 PCI_DMA_FROMDEVICE
);
2445 DEV_KFREE_SKB(pRxd
->pMBuf
);
2448 pRxd
->RBControl
&= BMU_OWN
;
2449 pRxd
= pRxd
->pNextRxd
;
2450 pRxPort
->RxdRingFree
++;
2451 } while (pRxd
!= pRxPort
->pRxdRingTail
);
2452 pRxPort
->pRxdRingTail
= pRxPort
->pRxdRingHead
;
2453 spin_unlock_irqrestore(&pRxPort
->RxDesRingLock
, Flags
);
2456 /*****************************************************************************
2458 * ClearTxRing - remove all buffers from the transmit ring
2461 * This function removes all transmit buffers from the ring.
2462 * The transmit BMU must be stopped before calling this function
2463 * and transmitting at the upper level must be disabled.
2464 * The BMU own bit of all descriptors is cleared, the rest is
2465 * done by calling FreeTxDescriptors.
2469 static void ClearTxRing(
2470 SK_AC
*pAC
, /* pointer to adapter context */
2471 TX_PORT
*pTxPort
) /* pointer to tx prt struct */
2473 TXD
*pTxd
; /* pointer to the current descriptor */
2475 unsigned long Flags
;
2477 spin_lock_irqsave(&pTxPort
->TxDesRingLock
, Flags
);
2478 pTxd
= pTxPort
->pTxdRingHead
;
2479 for (i
=0; i
<pAC
->TxDescrPerRing
; i
++) {
2480 pTxd
->TBControl
&= ~BMU_OWN
;
2481 pTxd
= pTxd
->pNextTxd
;
2483 FreeTxDescriptors(pAC
, pTxPort
);
2484 spin_unlock_irqrestore(&pTxPort
->TxDesRingLock
, Flags
);
2487 /*****************************************************************************
2489 * SkGeSetMacAddr - Set the hardware MAC address
2492 * This function sets the MAC address used by the adapter.
2495 * 0, if everything is ok
2498 static int SkGeSetMacAddr(struct SK_NET_DEVICE
*dev
, void *p
)
2501 DEV_NET
*pNet
= (DEV_NET
*) dev
->priv
;
2502 SK_AC
*pAC
= pNet
->pAC
;
2504 struct sockaddr
*addr
= p
;
2505 unsigned long Flags
;
2507 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2508 ("SkGeSetMacAddr starts now...\n"));
2509 if(netif_running(dev
))
2512 memcpy(dev
->dev_addr
, addr
->sa_data
,dev
->addr_len
);
2514 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2516 if (pAC
->RlmtNets
== 2)
2517 SkAddrOverride(pAC
, pAC
->IoBase
, pNet
->NetNr
,
2518 (SK_MAC_ADDR
*)dev
->dev_addr
, SK_ADDR_VIRTUAL_ADDRESS
);
2520 SkAddrOverride(pAC
, pAC
->IoBase
, pAC
->ActivePort
,
2521 (SK_MAC_ADDR
*)dev
->dev_addr
, SK_ADDR_VIRTUAL_ADDRESS
);
2525 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2527 } /* SkGeSetMacAddr */
2530 /*****************************************************************************
2532 * SkGeSetRxMode - set receive mode
2535 * This function sets the receive mode of an adapter. The adapter
2536 * supports promiscuous mode, allmulticast mode and a number of
2537 * multicast addresses. If more multicast addresses the available
2538 * are selected, a hash function in the hardware is used.
2541 * 0, if everything is ok
2544 static void SkGeSetRxMode(struct SK_NET_DEVICE
*dev
)
2550 struct dev_mc_list
*pMcList
;
2553 unsigned long Flags
;
2555 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2556 ("SkGeSetRxMode starts now... "));
2558 pNet
= (DEV_NET
*) dev
->priv
;
2560 if (pAC
->RlmtNets
== 1)
2561 PortIdx
= pAC
->ActivePort
;
2563 PortIdx
= pNet
->NetNr
;
2565 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2566 if (dev
->flags
& IFF_PROMISC
) {
2567 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2568 ("PROMISCUOUS mode\n"));
2569 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, PortIdx
,
2571 } else if (dev
->flags
& IFF_ALLMULTI
) {
2572 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2573 ("ALLMULTI mode\n"));
2574 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, PortIdx
,
2575 SK_PROM_MODE_ALL_MC
);
2577 SkAddrPromiscuousChange(pAC
, pAC
->IoBase
, PortIdx
,
2579 SkAddrMcClear(pAC
, pAC
->IoBase
, PortIdx
, 0);
2581 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2582 ("Number of MC entries: %d ", dev
->mc_count
));
2584 pMcList
= dev
->mc_list
;
2585 for (i
=0; i
<dev
->mc_count
; i
++, pMcList
= pMcList
->next
) {
2586 SkAddrMcAdd(pAC
, pAC
->IoBase
, PortIdx
,
2587 (SK_MAC_ADDR
*)pMcList
->dmi_addr
, 0);
2588 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_MCA
,
2589 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2590 pMcList
->dmi_addr
[0],
2591 pMcList
->dmi_addr
[1],
2592 pMcList
->dmi_addr
[2],
2593 pMcList
->dmi_addr
[3],
2594 pMcList
->dmi_addr
[4],
2595 pMcList
->dmi_addr
[5]));
2597 SkAddrMcUpdate(pAC
, pAC
->IoBase
, PortIdx
);
2599 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2602 } /* SkGeSetRxMode */
2605 /*****************************************************************************
2607 * SkGeChangeMtu - set the MTU to another value
2610 * This function sets is called whenever the MTU size is changed
2611 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2612 * ethernet MTU size, long frame support is activated.
2615 * 0, if everything is ok
2618 static int SkGeChangeMtu(struct SK_NET_DEVICE
*dev
, int NewMtu
)
2623 unsigned long Flags
;
2627 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2628 ("SkGeChangeMtu starts now...\n"));
2630 pNet
= (DEV_NET
*) dev
->priv
;
2633 if ((NewMtu
< 68) || (NewMtu
> SK_JUMBO_MTU
)) {
2637 if(pAC
->BoardLevel
!= SK_INIT_RUN
) {
2641 #ifdef SK_DIAG_SUPPORT
2642 if (pAC
->DiagModeActive
== DIAG_ACTIVE
) {
2643 if (pAC
->DiagFlowCtrl
== SK_FALSE
) {
2644 return -1; /* still in use, deny any actions of MTU */
2646 pAC
->DiagFlowCtrl
= SK_FALSE
;
2652 pOtherNet
= (DEV_NET
*)pAC
->dev
[1 - pNet
->NetNr
]->priv
;
2653 if ((pOtherNet
->Mtu
>1500) && (NewMtu
<=1500) && (pOtherNet
->Up
==1)) {
2657 pAC
->RxBufSize
= NewMtu
+ 32;
2660 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2661 ("New MTU: %d\n", NewMtu
));
2664 ** Prevent any reconfiguration while changing the MTU
2665 ** by disabling any interrupts
2667 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
2668 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2671 ** Notify RLMT that any ports are to be stopped
2673 EvPara
.Para32
[0] = 0;
2674 EvPara
.Para32
[1] = -1;
2675 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
2676 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
2677 EvPara
.Para32
[0] = 1;
2678 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
2680 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
2684 ** After calling the SkEventDispatcher(), RLMT is aware about
2685 ** the stopped ports -> configuration can take place!
2687 SkEventDispatcher(pAC
, pAC
->IoBase
);
2689 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2690 spin_lock(&pAC
->TxPort
[i
][TX_PRIO_LOW
].TxDesRingLock
);
2691 netif_stop_queue(pAC
->dev
[i
]);
2696 ** Depending on the desired MTU size change, a different number of
2697 ** RX buffers need to be allocated
2699 if (NewMtu
> 1500) {
2701 ** Use less rx buffers
2703 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2704 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
2705 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
-
2706 (pAC
->RxDescrPerRing
/ 4);
2708 if (i
== pAC
->ActivePort
) {
2709 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
-
2710 (pAC
->RxDescrPerRing
/ 4);
2712 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
-
2713 (pAC
->RxDescrPerRing
/ 10);
2719 ** Use the normal amount of rx buffers
2721 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2722 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
2723 pAC
->RxPort
[i
].RxFillLimit
= 1;
2725 if (i
== pAC
->ActivePort
) {
2726 pAC
->RxPort
[i
].RxFillLimit
= 1;
2728 pAC
->RxPort
[i
].RxFillLimit
= pAC
->RxDescrPerRing
-
2729 (pAC
->RxDescrPerRing
/ 4);
2735 SkGeDeInit(pAC
, pAC
->IoBase
);
2738 ** enable/disable hardware support for long frames
2740 if (NewMtu
> 1500) {
2741 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2742 pAC
->GIni
.GIPortUsage
= SK_JUMBO_LINK
;
2744 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
2745 pAC
->GIni
.GIPortUsage
= SK_MUL_LINK
;
2747 pAC
->GIni
.GIPortUsage
= SK_RED_LINK
;
2751 SkGeInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
2752 SkI2cInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
2753 SkEventInit(pAC
, pAC
->IoBase
, SK_INIT_IO
);
2754 SkPnmiInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
2755 SkAddrInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
2756 SkRlmtInit( pAC
, pAC
->IoBase
, SK_INIT_IO
);
2757 SkTimerInit(pAC
, pAC
->IoBase
, SK_INIT_IO
);
2761 ** Speed and others are set back to default in level 1 init!
2763 GetConfiguration(pAC
);
2765 SkGeInit( pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2766 SkI2cInit( pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2767 SkEventInit(pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2768 SkPnmiInit( pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2769 SkAddrInit( pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2770 SkRlmtInit( pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2771 SkTimerInit(pAC
, pAC
->IoBase
, SK_INIT_RUN
);
2774 ** clear and reinit the rx rings here
2776 for (i
=0; i
<pAC
->GIni
.GIMacsFound
; i
++) {
2777 ReceiveIrq(pAC
, &pAC
->RxPort
[i
], SK_TRUE
);
2778 ClearRxRing(pAC
, &pAC
->RxPort
[i
]);
2779 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
2782 ** Enable transmit descriptor polling
2784 SkGePollTxD(pAC
, pAC
->IoBase
, i
, SK_TRUE
);
2785 FillRxRing(pAC
, &pAC
->RxPort
[i
]);
2788 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
2789 SkDimEnableModerationIfNeeded(pAC
);
2790 SkDimDisplayModerationSettings(pAC
);
2792 netif_start_queue(pAC
->dev
[pNet
->PortNr
]);
2793 for (i
=pAC
->GIni
.GIMacsFound
-1; i
>=0; i
--) {
2794 spin_unlock(&pAC
->TxPort
[i
][TX_PRIO_LOW
].TxDesRingLock
);
2798 ** Enable Interrupts again
2800 SK_OUT32(pAC
->IoBase
, B0_IMSK
, pAC
->GIni
.GIValIrqMask
);
2801 SK_OUT32(pAC
->IoBase
, B0_HWE_IMSK
, IRQ_HWE_MASK
);
2803 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
2804 SkEventDispatcher(pAC
, pAC
->IoBase
);
2807 ** Notify RLMT about the changing and restarting one (or more) ports
2809 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
2810 EvPara
.Para32
[0] = pAC
->RlmtNets
;
2811 EvPara
.Para32
[1] = -1;
2812 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_SET_NETS
, EvPara
);
2813 EvPara
.Para32
[0] = pNet
->PortNr
;
2814 EvPara
.Para32
[1] = -1;
2815 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
2817 if (pOtherNet
->Up
) {
2818 EvPara
.Para32
[0] = pOtherNet
->PortNr
;
2819 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
2822 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_START
, EvPara
);
2825 SkEventDispatcher(pAC
, pAC
->IoBase
);
2826 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2829 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2830 ** seems as if upper layers have a problem to handle a successful
2831 ** return value of '0'. If such a zero is returned, the complete
2832 ** system hangs for several minutes (!), which is in acceptable.
2834 ** Currently it is not clear, what the exact reason for this problem
2835 ** is. The implemented workaround for 2.5 is to return the desired
2836 ** new MTU size if all needed changes for the new MTU size where
2837 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2838 ** which indicates the successful change of the mtu-size.
2842 } /* SkGeChangeMtu */
2845 /*****************************************************************************
2847 * SkGeStats - return ethernet device statistics
2850 * This function return statistic data about the ethernet device
2851 * to the operating system.
2854 * pointer to the statistic structure.
2856 static struct net_device_stats
*SkGeStats(struct SK_NET_DEVICE
*dev
)
2858 DEV_NET
*pNet
= (DEV_NET
*) dev
->priv
;
2859 SK_AC
*pAC
= pNet
->pAC
;
2860 SK_PNMI_STRUCT_DATA
*pPnmiStruct
; /* structure for all Pnmi-Data */
2861 SK_PNMI_STAT
*pPnmiStat
; /* pointer to virtual XMAC stat. data */
2862 SK_PNMI_CONF
*pPnmiConf
; /* pointer to virtual link config. */
2863 unsigned int Size
; /* size of pnmi struct */
2864 unsigned long Flags
; /* for spin lock */
2866 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2867 ("SkGeStats starts now...\n"));
2868 pPnmiStruct
= &pAC
->PnmiStruct
;
2870 #ifdef SK_DIAG_SUPPORT
2871 if ((pAC
->DiagModeActive
== DIAG_NOTACTIVE
) &&
2872 (pAC
->BoardLevel
== SK_INIT_RUN
)) {
2874 SK_MEMSET(pPnmiStruct
, 0, sizeof(SK_PNMI_STRUCT_DATA
));
2875 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
2876 Size
= SK_PNMI_STRUCT_SIZE
;
2877 SkPnmiGetStruct(pAC
, pAC
->IoBase
, pPnmiStruct
, &Size
, pNet
->NetNr
);
2878 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
2879 #ifdef SK_DIAG_SUPPORT
2883 pPnmiStat
= &pPnmiStruct
->Stat
[0];
2884 pPnmiConf
= &pPnmiStruct
->Conf
[0];
2886 pAC
->stats
.rx_packets
= (SK_U32
) pPnmiStruct
->RxDeliveredCts
& 0xFFFFFFFF;
2887 pAC
->stats
.tx_packets
= (SK_U32
) pPnmiStat
->StatTxOkCts
& 0xFFFFFFFF;
2888 pAC
->stats
.rx_bytes
= (SK_U32
) pPnmiStruct
->RxOctetsDeliveredCts
;
2889 pAC
->stats
.tx_bytes
= (SK_U32
) pPnmiStat
->StatTxOctetsOkCts
;
2891 if (pNet
->Mtu
<= 1500) {
2892 pAC
->stats
.rx_errors
= (SK_U32
) pPnmiStruct
->InErrorsCts
& 0xFFFFFFFF;
2894 pAC
->stats
.rx_errors
= (SK_U32
) ((pPnmiStruct
->InErrorsCts
-
2895 pPnmiStat
->StatRxTooLongCts
) & 0xFFFFFFFF);
2899 if (pAC
->GIni
.GP
[0].PhyType
== SK_PHY_XMAC
&& pAC
->HWRevision
< 12)
2900 pAC
->stats
.rx_errors
= pAC
->stats
.rx_errors
- pPnmiStat
->StatRxShortsCts
;
2902 pAC
->stats
.tx_errors
= (SK_U32
) pPnmiStat
->StatTxSingleCollisionCts
& 0xFFFFFFFF;
2903 pAC
->stats
.rx_dropped
= (SK_U32
) pPnmiStruct
->RxNoBufCts
& 0xFFFFFFFF;
2904 pAC
->stats
.tx_dropped
= (SK_U32
) pPnmiStruct
->TxNoBufCts
& 0xFFFFFFFF;
2905 pAC
->stats
.multicast
= (SK_U32
) pPnmiStat
->StatRxMulticastOkCts
& 0xFFFFFFFF;
2906 pAC
->stats
.collisions
= (SK_U32
) pPnmiStat
->StatTxSingleCollisionCts
& 0xFFFFFFFF;
2908 /* detailed rx_errors: */
2909 pAC
->stats
.rx_length_errors
= (SK_U32
) pPnmiStat
->StatRxRuntCts
& 0xFFFFFFFF;
2910 pAC
->stats
.rx_over_errors
= (SK_U32
) pPnmiStat
->StatRxFifoOverflowCts
& 0xFFFFFFFF;
2911 pAC
->stats
.rx_crc_errors
= (SK_U32
) pPnmiStat
->StatRxFcsCts
& 0xFFFFFFFF;
2912 pAC
->stats
.rx_frame_errors
= (SK_U32
) pPnmiStat
->StatRxFramingCts
& 0xFFFFFFFF;
2913 pAC
->stats
.rx_fifo_errors
= (SK_U32
) pPnmiStat
->StatRxFifoOverflowCts
& 0xFFFFFFFF;
2914 pAC
->stats
.rx_missed_errors
= (SK_U32
) pPnmiStat
->StatRxMissedCts
& 0xFFFFFFFF;
2916 /* detailed tx_errors */
2917 pAC
->stats
.tx_aborted_errors
= (SK_U32
) 0;
2918 pAC
->stats
.tx_carrier_errors
= (SK_U32
) pPnmiStat
->StatTxCarrierCts
& 0xFFFFFFFF;
2919 pAC
->stats
.tx_fifo_errors
= (SK_U32
) pPnmiStat
->StatTxFifoUnderrunCts
& 0xFFFFFFFF;
2920 pAC
->stats
.tx_heartbeat_errors
= (SK_U32
) pPnmiStat
->StatTxCarrierCts
& 0xFFFFFFFF;
2921 pAC
->stats
.tx_window_errors
= (SK_U32
) 0;
2923 return(&pAC
->stats
);
2927 /*****************************************************************************
2929 * SkGeIoctl - IO-control function
2932 * This function is called if an ioctl is issued on the device.
2933 * There are three subfunction for reading, writing and test-writing
2934 * the private MIB data structure (usefull for SysKonnect-internal tools).
2937 * 0, if everything is ok
2940 static int SkGeIoctl(struct SK_NET_DEVICE
*dev
, struct ifreq
*rq
, int cmd
)
2945 struct pci_dev
*pdev
= NULL
;
2947 unsigned int Err
= 0;
2950 unsigned int Length
= 0;
2951 int HeaderLength
= sizeof(SK_U32
) + sizeof(SK_U32
);
2953 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
2954 ("SkGeIoctl starts now...\n"));
2956 pNet
= (DEV_NET
*) dev
->priv
;
2959 if(copy_from_user(&Ioctl
, rq
->ifr_data
, sizeof(SK_GE_IOCTL
))) {
2964 case SK_IOCTL_SETMIB
:
2965 case SK_IOCTL_PRESETMIB
:
2966 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
2967 case SK_IOCTL_GETMIB
:
2968 if(copy_from_user(&pAC
->PnmiStruct
, Ioctl
.pData
,
2969 Ioctl
.Len
<sizeof(pAC
->PnmiStruct
)?
2970 Ioctl
.Len
: sizeof(pAC
->PnmiStruct
))) {
2973 Size
= SkGeIocMib(pNet
, Ioctl
.Len
, cmd
);
2974 if(copy_to_user(Ioctl
.pData
, &pAC
->PnmiStruct
,
2975 Ioctl
.Len
<Size
? Ioctl
.Len
: Size
)) {
2979 if(copy_to_user(rq
->ifr_data
, &Ioctl
, sizeof(SK_GE_IOCTL
))) {
2984 if (Ioctl
.Len
< (sizeof(pAC
->PnmiStruct
) + HeaderLength
)) {
2987 Length
= sizeof(pAC
->PnmiStruct
) + HeaderLength
;
2989 if (NULL
== (pMemBuf
= kmalloc(Length
, GFP_KERNEL
))) {
2992 if(copy_from_user(pMemBuf
, Ioctl
.pData
, Length
)) {
2996 if ((Ret
= SkPnmiGenIoctl(pAC
, pAC
->IoBase
, pMemBuf
, &Length
, 0)) < 0) {
3000 if(copy_to_user(Ioctl
.pData
, pMemBuf
, Length
) ) {
3005 if(copy_to_user(rq
->ifr_data
, &Ioctl
, sizeof(SK_GE_IOCTL
))) {
3010 kfree(pMemBuf
); /* cleanup everything */
3012 #ifdef SK_DIAG_SUPPORT
3014 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
3015 if (Ioctl
.Len
< (sizeof(pAC
->PnmiStruct
) + HeaderLength
)) {
3018 Length
= sizeof(pAC
->PnmiStruct
) + HeaderLength
;
3020 if (NULL
== (pMemBuf
= kmalloc(Length
, GFP_KERNEL
))) {
3023 if(copy_from_user(pMemBuf
, Ioctl
.pData
, Length
)) {
3028 Length
= 3 * sizeof(SK_U32
); /* Error, Bus and Device */
3030 ** While coding this new IOCTL interface, only a few lines of code
3031 ** are to to be added. Therefore no dedicated function has been
3032 ** added. If more functionality is added, a separate function
3033 ** should be used...
3035 * ((SK_U32
*)pMemBuf
) = 0;
3036 * ((SK_U32
*)pMemBuf
+ 1) = pdev
->bus
->number
;
3037 * ((SK_U32
*)pMemBuf
+ 2) = ParseDeviceNbrFromSlotName(pdev
->slot_name
);
3038 if(copy_to_user(Ioctl
.pData
, pMemBuf
, Length
) ) {
3043 if(copy_to_user(rq
->ifr_data
, &Ioctl
, sizeof(SK_GE_IOCTL
))) {
3048 kfree(pMemBuf
); /* cleanup everything */
3060 /*****************************************************************************
3062 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3065 * This function reads/writes the MIB data using PNMI (Private Network
3066 * Management Interface).
3067 * The destination for the data must be provided with the
3068 * ioctl call and is given to the driver in the form of
3069 * a user space address.
3070 * Copying from the user-provided data area into kernel messages
3071 * and back is done by copy_from_user and copy_to_user calls in
3075 * returned size from PNMI call
3077 static int SkGeIocMib(
3078 DEV_NET
*pNet
, /* pointer to the adapter context */
3079 unsigned int Size
, /* length of ioctl data */
3080 int mode
) /* flag for set/preset */
3082 unsigned long Flags
; /* for spin lock */
3085 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
3086 ("SkGeIocMib starts now...\n"));
3089 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
3091 case SK_IOCTL_GETMIB
:
3092 SkPnmiGetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
,
3095 case SK_IOCTL_PRESETMIB
:
3096 SkPnmiPreSetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
,
3099 case SK_IOCTL_SETMIB
:
3100 SkPnmiSetStruct(pAC
, pAC
->IoBase
, &pAC
->PnmiStruct
, &Size
,
3106 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
3107 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ENTRY
,
3108 ("MIB data access succeeded\n"));
3113 /*****************************************************************************
3115 * GetConfiguration - read configuration information
3118 * This function reads per-adapter configuration information from
3119 * the options provided on the command line.
3124 static void GetConfiguration(
3125 SK_AC
*pAC
) /* pointer to the adapter context structure */
3127 SK_I32 Port
; /* preferred port */
3130 int LinkSpeed
= SK_LSPEED_AUTO
; /* Link speed */
3131 int AutoNeg
= 1; /* autoneg off (0) or on (1) */
3132 int DuplexCap
= 0; /* 0=both,1=full,2=half */
3133 int FlowCtrl
= SK_FLOW_MODE_SYM_OR_REM
; /* FlowControl */
3134 int MSMode
= SK_MS_MODE_AUTO
; /* master/slave mode */
3136 SK_BOOL IsConTypeDefined
= SK_TRUE
;
3137 SK_BOOL IsLinkSpeedDefined
= SK_TRUE
;
3138 SK_BOOL IsFlowCtrlDefined
= SK_TRUE
;
3139 SK_BOOL IsRoleDefined
= SK_TRUE
;
3140 SK_BOOL IsModeDefined
= SK_TRUE
;
3142 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3143 * parameter. The mapping is described by this table:
3144 * DuplexCap -> | both | full | half |
3146 * -----------------------------------------------------------------
3147 * Off | illegal | Full | Half |
3148 * -----------------------------------------------------------------
3149 * On | AutoBoth | AutoFull | AutoHalf |
3150 * -----------------------------------------------------------------
3151 * Sense | AutoSense | AutoSense | AutoSense |
3153 int Capabilities
[3][3] =
3154 { { -1, SK_LMODE_FULL
, SK_LMODE_HALF
},
3155 {SK_LMODE_AUTOBOTH
, SK_LMODE_AUTOFULL
, SK_LMODE_AUTOHALF
},
3156 {SK_LMODE_AUTOSENSE
, SK_LMODE_AUTOSENSE
, SK_LMODE_AUTOSENSE
} };
3164 #define M_CurrPort pAC->GIni.GP[Port]
3168 ** Set the default values first for both ports!
3170 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3171 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_ON
][DC_BOTH
];
3172 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_SYM_OR_REM
;
3173 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3174 M_CurrPort
.PLinkSpeed
= SK_LSPEED_AUTO
;
3178 ** Check merged parameter ConType. If it has not been used,
3179 ** verify any other parameter (e.g. AutoNeg) and use default values.
3181 ** Stating both ConType and other lowlevel link parameters is also
3182 ** possible. If this is the case, the passed ConType-parameter is
3183 ** overwritten by the lowlevel link parameter.
3185 ** The following settings are used for a merged ConType-parameter:
3187 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3188 ** ------- ------ ------- -------- ---------- -----
3189 ** Auto Both On SymOrRem Auto Auto
3190 ** 100FD Full Off None <ignored> 100
3191 ** 100HD Half Off None <ignored> 100
3192 ** 10FD Full Off None <ignored> 10
3193 ** 10HD Half Off None <ignored> 10
3195 ** This ConType parameter is used for all ports of the adapter!
3197 if ( (ConType
!= NULL
) &&
3198 (pAC
->Index
< SK_MAX_CARD_PARAM
) &&
3199 (ConType
[pAC
->Index
] != NULL
) ) {
3201 /* Check chipset family */
3202 if ((!pAC
->ChipsetType
) &&
3203 (strcmp(ConType
[pAC
->Index
],"Auto")!=0) &&
3204 (strcmp(ConType
[pAC
->Index
],"")!=0)) {
3205 /* Set the speed parameter back */
3206 printk("sk98lin: Illegal value \"%s\" "
3209 ConType
[pAC
->Index
]);
3211 sprintf(ConType
[pAC
->Index
], "Auto");
3214 if (strcmp(ConType
[pAC
->Index
],"")==0) {
3215 IsConTypeDefined
= SK_FALSE
; /* No ConType defined */
3216 } else if (strcmp(ConType
[pAC
->Index
],"Auto")==0) {
3217 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3218 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_ON
][DC_BOTH
];
3219 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_SYM_OR_REM
;
3220 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3221 M_CurrPort
.PLinkSpeed
= SK_LSPEED_AUTO
;
3223 } else if (strcmp(ConType
[pAC
->Index
],"100FD")==0) {
3224 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3225 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_OFF
][DC_FULL
];
3226 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
3227 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3228 M_CurrPort
.PLinkSpeed
= SK_LSPEED_100MBPS
;
3230 } else if (strcmp(ConType
[pAC
->Index
],"100HD")==0) {
3231 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3232 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_OFF
][DC_HALF
];
3233 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
3234 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3235 M_CurrPort
.PLinkSpeed
= SK_LSPEED_100MBPS
;
3237 } else if (strcmp(ConType
[pAC
->Index
],"10FD")==0) {
3238 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3239 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_OFF
][DC_FULL
];
3240 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
3241 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3242 M_CurrPort
.PLinkSpeed
= SK_LSPEED_10MBPS
;
3244 } else if (strcmp(ConType
[pAC
->Index
],"10HD")==0) {
3245 for (Port
= 0; Port
< SK_MAX_MACS
; Port
++) {
3246 M_CurrPort
.PLinkModeConf
= Capabilities
[AN_OFF
][DC_HALF
];
3247 M_CurrPort
.PFlowCtrlMode
= SK_FLOW_MODE_NONE
;
3248 M_CurrPort
.PMSMode
= SK_MS_MODE_AUTO
;
3249 M_CurrPort
.PLinkSpeed
= SK_LSPEED_10MBPS
;
3252 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3253 ConType
[pAC
->Index
]);
3254 IsConTypeDefined
= SK_FALSE
; /* Wrong ConType defined */
3257 IsConTypeDefined
= SK_FALSE
; /* No ConType defined */
3261 ** Parse any parameter settings for port A:
3262 ** a) any LinkSpeed stated?
3264 if (Speed_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3265 Speed_A
[pAC
->Index
] != NULL
) {
3266 if (strcmp(Speed_A
[pAC
->Index
],"")==0) {
3267 IsLinkSpeedDefined
= SK_FALSE
;
3268 } else if (strcmp(Speed_A
[pAC
->Index
],"Auto")==0) {
3269 LinkSpeed
= SK_LSPEED_AUTO
;
3270 } else if (strcmp(Speed_A
[pAC
->Index
],"10")==0) {
3271 LinkSpeed
= SK_LSPEED_10MBPS
;
3272 } else if (strcmp(Speed_A
[pAC
->Index
],"100")==0) {
3273 LinkSpeed
= SK_LSPEED_100MBPS
;
3274 } else if (strcmp(Speed_A
[pAC
->Index
],"1000")==0) {
3275 LinkSpeed
= SK_LSPEED_1000MBPS
;
3277 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3278 Speed_A
[pAC
->Index
]);
3279 IsLinkSpeedDefined
= SK_FALSE
;
3282 IsLinkSpeedDefined
= SK_FALSE
;
3286 ** Check speed parameter:
3287 ** Only copper type adapter and GE V2 cards
3289 if (((!pAC
->ChipsetType
) || (pAC
->GIni
.GICopperType
!= SK_TRUE
)) &&
3290 ((LinkSpeed
!= SK_LSPEED_AUTO
) &&
3291 (LinkSpeed
!= SK_LSPEED_1000MBPS
))) {
3292 printk("sk98lin: Illegal value for Speed_A. "
3293 "Not a copper card or GE V2 card\n Using "
3295 LinkSpeed
= SK_LSPEED_1000MBPS
;
3299 ** Decide whether to set new config value if somethig valid has
3302 if (IsLinkSpeedDefined
) {
3303 pAC
->GIni
.GP
[0].PLinkSpeed
= LinkSpeed
;
3307 ** b) Any Autonegotiation and DuplexCapabilities set?
3308 ** Please note that both belong together...
3310 AutoNeg
= AN_ON
; /* tschilling: Default: Autonegotiation on! */
3312 if (AutoNeg_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3313 AutoNeg_A
[pAC
->Index
] != NULL
) {
3315 if (strcmp(AutoNeg_A
[pAC
->Index
],"")==0) {
3317 } else if (strcmp(AutoNeg_A
[pAC
->Index
],"On")==0) {
3319 } else if (strcmp(AutoNeg_A
[pAC
->Index
],"Off")==0) {
3321 } else if (strcmp(AutoNeg_A
[pAC
->Index
],"Sense")==0) {
3324 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3325 AutoNeg_A
[pAC
->Index
]);
3329 DuplexCap
= DC_BOTH
;
3331 if (DupCap_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3332 DupCap_A
[pAC
->Index
] != NULL
) {
3334 if (strcmp(DupCap_A
[pAC
->Index
],"")==0) {
3336 } else if (strcmp(DupCap_A
[pAC
->Index
],"Both")==0) {
3337 DuplexCap
= DC_BOTH
;
3338 } else if (strcmp(DupCap_A
[pAC
->Index
],"Full")==0) {
3339 DuplexCap
= DC_FULL
;
3340 } else if (strcmp(DupCap_A
[pAC
->Index
],"Half")==0) {
3341 DuplexCap
= DC_HALF
;
3343 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3344 DupCap_A
[pAC
->Index
]);
3349 ** Check for illegal combinations
3351 if ((LinkSpeed
== SK_LSPEED_1000MBPS
) &&
3352 ((DuplexCap
== SK_LMODE_STAT_AUTOHALF
) ||
3353 (DuplexCap
== SK_LMODE_STAT_HALF
)) &&
3354 (pAC
->ChipsetType
)) {
3355 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3356 " Using Full Duplex.\n");
3357 DuplexCap
= DC_FULL
;
3360 if ( AutoSet
&& AutoNeg
==AN_SENS
&& DupSet
) {
3361 printk("sk98lin, Port A: DuplexCapabilities"
3362 " ignored using Sense mode\n");
3365 if (AutoSet
&& AutoNeg
==AN_OFF
&& DupSet
&& DuplexCap
==DC_BOTH
){
3366 printk("sk98lin: Port A: Illegal combination"
3367 " of values AutoNeg. and DuplexCap.\n Using "
3369 DuplexCap
= DC_FULL
;
3372 if (AutoSet
&& AutoNeg
==AN_OFF
&& !DupSet
) {
3373 DuplexCap
= DC_FULL
;
3376 if (!AutoSet
&& DupSet
) {
3377 printk("sk98lin: Port A: Duplex setting not"
3378 " possible in\n default AutoNegotiation mode"
3379 " (Sense).\n Using AutoNegotiation On\n");
3384 ** set the desired mode
3386 if (AutoSet
|| DupSet
) {
3387 pAC
->GIni
.GP
[0].PLinkModeConf
= Capabilities
[AutoNeg
][DuplexCap
];
3391 ** c) Any Flowcontrol-parameter set?
3393 if (FlowCtrl_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3394 FlowCtrl_A
[pAC
->Index
] != NULL
) {
3395 if (strcmp(FlowCtrl_A
[pAC
->Index
],"") == 0) {
3396 IsFlowCtrlDefined
= SK_FALSE
;
3397 } else if (strcmp(FlowCtrl_A
[pAC
->Index
],"SymOrRem") == 0) {
3398 FlowCtrl
= SK_FLOW_MODE_SYM_OR_REM
;
3399 } else if (strcmp(FlowCtrl_A
[pAC
->Index
],"Sym")==0) {
3400 FlowCtrl
= SK_FLOW_MODE_SYMMETRIC
;
3401 } else if (strcmp(FlowCtrl_A
[pAC
->Index
],"LocSend")==0) {
3402 FlowCtrl
= SK_FLOW_MODE_LOC_SEND
;
3403 } else if (strcmp(FlowCtrl_A
[pAC
->Index
],"None")==0) {
3404 FlowCtrl
= SK_FLOW_MODE_NONE
;
3406 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3407 FlowCtrl_A
[pAC
->Index
]);
3408 IsFlowCtrlDefined
= SK_FALSE
;
3411 IsFlowCtrlDefined
= SK_FALSE
;
3414 if (IsFlowCtrlDefined
) {
3415 if ((AutoNeg
== AN_OFF
) && (FlowCtrl
!= SK_FLOW_MODE_NONE
)) {
3416 printk("sk98lin: Port A: FlowControl"
3417 " impossible without AutoNegotiation,"
3419 FlowCtrl
= SK_FLOW_MODE_NONE
;
3421 pAC
->GIni
.GP
[0].PFlowCtrlMode
= FlowCtrl
;
3425 ** d) What is with the RoleParameter?
3427 if (Role_A
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3428 Role_A
[pAC
->Index
] != NULL
) {
3429 if (strcmp(Role_A
[pAC
->Index
],"")==0) {
3430 IsRoleDefined
= SK_FALSE
;
3431 } else if (strcmp(Role_A
[pAC
->Index
],"Auto")==0) {
3432 MSMode
= SK_MS_MODE_AUTO
;
3433 } else if (strcmp(Role_A
[pAC
->Index
],"Master")==0) {
3434 MSMode
= SK_MS_MODE_MASTER
;
3435 } else if (strcmp(Role_A
[pAC
->Index
],"Slave")==0) {
3436 MSMode
= SK_MS_MODE_SLAVE
;
3438 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3439 Role_A
[pAC
->Index
]);
3440 IsRoleDefined
= SK_FALSE
;
3443 IsRoleDefined
= SK_FALSE
;
3446 if (IsRoleDefined
== SK_TRUE
) {
3447 pAC
->GIni
.GP
[0].PMSMode
= MSMode
;
3453 ** Parse any parameter settings for port B:
3454 ** a) any LinkSpeed stated?
3456 IsConTypeDefined
= SK_TRUE
;
3457 IsLinkSpeedDefined
= SK_TRUE
;
3458 IsFlowCtrlDefined
= SK_TRUE
;
3459 IsModeDefined
= SK_TRUE
;
3461 if (Speed_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3462 Speed_B
[pAC
->Index
] != NULL
) {
3463 if (strcmp(Speed_B
[pAC
->Index
],"")==0) {
3464 IsLinkSpeedDefined
= SK_FALSE
;
3465 } else if (strcmp(Speed_B
[pAC
->Index
],"Auto")==0) {
3466 LinkSpeed
= SK_LSPEED_AUTO
;
3467 } else if (strcmp(Speed_B
[pAC
->Index
],"10")==0) {
3468 LinkSpeed
= SK_LSPEED_10MBPS
;
3469 } else if (strcmp(Speed_B
[pAC
->Index
],"100")==0) {
3470 LinkSpeed
= SK_LSPEED_100MBPS
;
3471 } else if (strcmp(Speed_B
[pAC
->Index
],"1000")==0) {
3472 LinkSpeed
= SK_LSPEED_1000MBPS
;
3474 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3475 Speed_B
[pAC
->Index
]);
3476 IsLinkSpeedDefined
= SK_FALSE
;
3479 IsLinkSpeedDefined
= SK_FALSE
;
3483 ** Check speed parameter:
3484 ** Only copper type adapter and GE V2 cards
3486 if (((!pAC
->ChipsetType
) || (pAC
->GIni
.GICopperType
!= SK_TRUE
)) &&
3487 ((LinkSpeed
!= SK_LSPEED_AUTO
) &&
3488 (LinkSpeed
!= SK_LSPEED_1000MBPS
))) {
3489 printk("sk98lin: Illegal value for Speed_B. "
3490 "Not a copper card or GE V2 card\n Using "
3492 LinkSpeed
= SK_LSPEED_1000MBPS
;
3496 ** Decide whether to set new config value if somethig valid has
3499 if (IsLinkSpeedDefined
) {
3500 pAC
->GIni
.GP
[1].PLinkSpeed
= LinkSpeed
;
3504 ** b) Any Autonegotiation and DuplexCapabilities set?
3505 ** Please note that both belong together...
3507 AutoNeg
= AN_SENS
; /* default: do auto Sense */
3509 if (AutoNeg_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3510 AutoNeg_B
[pAC
->Index
] != NULL
) {
3512 if (strcmp(AutoNeg_B
[pAC
->Index
],"")==0) {
3514 } else if (strcmp(AutoNeg_B
[pAC
->Index
],"On")==0) {
3516 } else if (strcmp(AutoNeg_B
[pAC
->Index
],"Off")==0) {
3518 } else if (strcmp(AutoNeg_B
[pAC
->Index
],"Sense")==0) {
3521 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3522 AutoNeg_B
[pAC
->Index
]);
3526 DuplexCap
= DC_BOTH
;
3528 if (DupCap_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3529 DupCap_B
[pAC
->Index
] != NULL
) {
3531 if (strcmp(DupCap_B
[pAC
->Index
],"")==0) {
3533 } else if (strcmp(DupCap_B
[pAC
->Index
],"Both")==0) {
3534 DuplexCap
= DC_BOTH
;
3535 } else if (strcmp(DupCap_B
[pAC
->Index
],"Full")==0) {
3536 DuplexCap
= DC_FULL
;
3537 } else if (strcmp(DupCap_B
[pAC
->Index
],"Half")==0) {
3538 DuplexCap
= DC_HALF
;
3540 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3541 DupCap_B
[pAC
->Index
]);
3547 ** Check for illegal combinations
3549 if ((LinkSpeed
== SK_LSPEED_1000MBPS
) &&
3550 ((DuplexCap
== SK_LMODE_STAT_AUTOHALF
) ||
3551 (DuplexCap
== SK_LMODE_STAT_HALF
)) &&
3552 (pAC
->ChipsetType
)) {
3553 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3554 " Using Full Duplex.\n");
3555 DuplexCap
= DC_FULL
;
3558 if (AutoSet
&& AutoNeg
==AN_SENS
&& DupSet
) {
3559 printk("sk98lin, Port B: DuplexCapabilities"
3560 " ignored using Sense mode\n");
3563 if (AutoSet
&& AutoNeg
==AN_OFF
&& DupSet
&& DuplexCap
==DC_BOTH
){
3564 printk("sk98lin: Port B: Illegal combination"
3565 " of values AutoNeg. and DuplexCap.\n Using "
3567 DuplexCap
= DC_FULL
;
3570 if (AutoSet
&& AutoNeg
==AN_OFF
&& !DupSet
) {
3571 DuplexCap
= DC_FULL
;
3574 if (!AutoSet
&& DupSet
) {
3575 printk("sk98lin: Port B: Duplex setting not"
3576 " possible in\n default AutoNegotiation mode"
3577 " (Sense).\n Using AutoNegotiation On\n");
3582 ** set the desired mode
3584 if (AutoSet
|| DupSet
) {
3585 pAC
->GIni
.GP
[1].PLinkModeConf
= Capabilities
[AutoNeg
][DuplexCap
];
3589 ** c) Any FlowCtrl parameter set?
3591 if (FlowCtrl_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3592 FlowCtrl_B
[pAC
->Index
] != NULL
) {
3593 if (strcmp(FlowCtrl_B
[pAC
->Index
],"") == 0) {
3594 IsFlowCtrlDefined
= SK_FALSE
;
3595 } else if (strcmp(FlowCtrl_B
[pAC
->Index
],"SymOrRem") == 0) {
3596 FlowCtrl
= SK_FLOW_MODE_SYM_OR_REM
;
3597 } else if (strcmp(FlowCtrl_B
[pAC
->Index
],"Sym")==0) {
3598 FlowCtrl
= SK_FLOW_MODE_SYMMETRIC
;
3599 } else if (strcmp(FlowCtrl_B
[pAC
->Index
],"LocSend")==0) {
3600 FlowCtrl
= SK_FLOW_MODE_LOC_SEND
;
3601 } else if (strcmp(FlowCtrl_B
[pAC
->Index
],"None")==0) {
3602 FlowCtrl
= SK_FLOW_MODE_NONE
;
3604 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3605 FlowCtrl_B
[pAC
->Index
]);
3606 IsFlowCtrlDefined
= SK_FALSE
;
3609 IsFlowCtrlDefined
= SK_FALSE
;
3612 if (IsFlowCtrlDefined
) {
3613 if ((AutoNeg
== AN_OFF
) && (FlowCtrl
!= SK_FLOW_MODE_NONE
)) {
3614 printk("sk98lin: Port B: FlowControl"
3615 " impossible without AutoNegotiation,"
3617 FlowCtrl
= SK_FLOW_MODE_NONE
;
3619 pAC
->GIni
.GP
[1].PFlowCtrlMode
= FlowCtrl
;
3623 ** d) What is the RoleParameter?
3625 if (Role_B
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3626 Role_B
[pAC
->Index
] != NULL
) {
3627 if (strcmp(Role_B
[pAC
->Index
],"")==0) {
3628 IsRoleDefined
= SK_FALSE
;
3629 } else if (strcmp(Role_B
[pAC
->Index
],"Auto")==0) {
3630 MSMode
= SK_MS_MODE_AUTO
;
3631 } else if (strcmp(Role_B
[pAC
->Index
],"Master")==0) {
3632 MSMode
= SK_MS_MODE_MASTER
;
3633 } else if (strcmp(Role_B
[pAC
->Index
],"Slave")==0) {
3634 MSMode
= SK_MS_MODE_SLAVE
;
3636 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3637 Role_B
[pAC
->Index
]);
3638 IsRoleDefined
= SK_FALSE
;
3641 IsRoleDefined
= SK_FALSE
;
3644 if (IsRoleDefined
) {
3645 pAC
->GIni
.GP
[1].PMSMode
= MSMode
;
3649 ** Evaluate settings for both ports
3651 pAC
->ActivePort
= 0;
3652 if (PrefPort
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3653 PrefPort
[pAC
->Index
] != NULL
) {
3654 if (strcmp(PrefPort
[pAC
->Index
],"") == 0) { /* Auto */
3655 pAC
->ActivePort
= 0;
3656 pAC
->Rlmt
.Net
[0].Preference
= -1; /* auto */
3657 pAC
->Rlmt
.Net
[0].PrefPort
= 0;
3658 } else if (strcmp(PrefPort
[pAC
->Index
],"A") == 0) {
3660 ** do not set ActivePort here, thus a port
3661 ** switch is issued after net up.
3664 pAC
->Rlmt
.Net
[0].Preference
= Port
;
3665 pAC
->Rlmt
.Net
[0].PrefPort
= Port
;
3666 } else if (strcmp(PrefPort
[pAC
->Index
],"B") == 0) {
3668 ** do not set ActivePort here, thus a port
3669 ** switch is issued after net up.
3671 if (pAC
->GIni
.GIMacsFound
== 1) {
3672 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3673 " Port B not available on single port adapters.\n");
3675 pAC
->ActivePort
= 0;
3676 pAC
->Rlmt
.Net
[0].Preference
= -1; /* auto */
3677 pAC
->Rlmt
.Net
[0].PrefPort
= 0;
3680 pAC
->Rlmt
.Net
[0].Preference
= Port
;
3681 pAC
->Rlmt
.Net
[0].PrefPort
= Port
;
3684 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3685 PrefPort
[pAC
->Index
]);
3691 if (RlmtMode
!= NULL
&& pAC
->Index
<SK_MAX_CARD_PARAM
&&
3692 RlmtMode
[pAC
->Index
] != NULL
) {
3693 if (strcmp(RlmtMode
[pAC
->Index
], "") == 0) {
3695 } else if (strcmp(RlmtMode
[pAC
->Index
], "CheckLinkState") == 0) {
3696 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
;
3697 } else if (strcmp(RlmtMode
[pAC
->Index
], "CheckLocalPort") == 0) {
3698 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
|
3699 SK_RLMT_CHECK_LOC_LINK
;
3700 } else if (strcmp(RlmtMode
[pAC
->Index
], "CheckSeg") == 0) {
3701 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
|
3702 SK_RLMT_CHECK_LOC_LINK
|
3704 } else if ((strcmp(RlmtMode
[pAC
->Index
], "DualNet") == 0) &&
3705 (pAC
->GIni
.GIMacsFound
== 2)) {
3706 pAC
->RlmtMode
= SK_RLMT_CHECK_LINK
;
3709 printk("sk98lin: Illegal value \"%s\" for"
3710 " RlmtMode, using default\n",
3711 RlmtMode
[pAC
->Index
]);
3719 ** Check the interrupt moderation parameters
3721 if (Moderation
[pAC
->Index
] != NULL
) {
3722 if (strcmp(Moderation
[pAC
->Index
], "") == 0) {
3723 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_NONE
;
3724 } else if (strcmp(Moderation
[pAC
->Index
], "Static") == 0) {
3725 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_STATIC
;
3726 } else if (strcmp(Moderation
[pAC
->Index
], "Dynamic") == 0) {
3727 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_DYNAMIC
;
3728 } else if (strcmp(Moderation
[pAC
->Index
], "None") == 0) {
3729 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_NONE
;
3731 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3732 " Disable interrupt moderation.\n",
3733 Moderation
[pAC
->Index
]);
3734 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_NONE
;
3737 pAC
->DynIrqModInfo
.IntModTypeSelect
= C_INT_MOD_NONE
;
3740 if (Stats
[pAC
->Index
] != NULL
) {
3741 if (strcmp(Stats
[pAC
->Index
], "Yes") == 0) {
3742 pAC
->DynIrqModInfo
.DisplayStats
= SK_TRUE
;
3744 pAC
->DynIrqModInfo
.DisplayStats
= SK_FALSE
;
3747 pAC
->DynIrqModInfo
.DisplayStats
= SK_FALSE
;
3750 if (ModerationMask
[pAC
->Index
] != NULL
) {
3751 if (strcmp(ModerationMask
[pAC
->Index
], "Rx") == 0) {
3752 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_ONLY
;
3753 } else if (strcmp(ModerationMask
[pAC
->Index
], "Tx") == 0) {
3754 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_TX_ONLY
;
3755 } else if (strcmp(ModerationMask
[pAC
->Index
], "Sp") == 0) {
3756 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_SP_ONLY
;
3757 } else if (strcmp(ModerationMask
[pAC
->Index
], "RxSp") == 0) {
3758 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_SP_RX
;
3759 } else if (strcmp(ModerationMask
[pAC
->Index
], "SpRx") == 0) {
3760 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_SP_RX
;
3761 } else if (strcmp(ModerationMask
[pAC
->Index
], "RxTx") == 0) {
3762 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_TX_RX
;
3763 } else if (strcmp(ModerationMask
[pAC
->Index
], "TxRx") == 0) {
3764 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_TX_RX
;
3765 } else if (strcmp(ModerationMask
[pAC
->Index
], "TxSp") == 0) {
3766 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_SP_TX
;
3767 } else if (strcmp(ModerationMask
[pAC
->Index
], "SpTx") == 0) {
3768 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_SP_TX
;
3769 } else if (strcmp(ModerationMask
[pAC
->Index
], "RxTxSp") == 0) {
3770 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3771 } else if (strcmp(ModerationMask
[pAC
->Index
], "RxSpTx") == 0) {
3772 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3773 } else if (strcmp(ModerationMask
[pAC
->Index
], "TxRxSp") == 0) {
3774 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3775 } else if (strcmp(ModerationMask
[pAC
->Index
], "TxSpRx") == 0) {
3776 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3777 } else if (strcmp(ModerationMask
[pAC
->Index
], "SpTxRx") == 0) {
3778 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3779 } else if (strcmp(ModerationMask
[pAC
->Index
], "SpRxTx") == 0) {
3780 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_TX_SP
;
3781 } else { /* some rubbish */
3782 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_RX_ONLY
;
3784 } else { /* operator has stated nothing */
3785 pAC
->DynIrqModInfo
.MaskIrqModeration
= IRQ_MASK_TX_RX
;
3788 if (AutoSizing
[pAC
->Index
] != NULL
) {
3789 if (strcmp(AutoSizing
[pAC
->Index
], "On") == 0) {
3790 pAC
->DynIrqModInfo
.AutoSizing
= SK_FALSE
;
3792 pAC
->DynIrqModInfo
.AutoSizing
= SK_FALSE
;
3794 } else { /* operator has stated nothing */
3795 pAC
->DynIrqModInfo
.AutoSizing
= SK_FALSE
;
3798 if (IntsPerSec
[pAC
->Index
] != 0) {
3799 if ((IntsPerSec
[pAC
->Index
]< C_INT_MOD_IPS_LOWER_RANGE
) ||
3800 (IntsPerSec
[pAC
->Index
] > C_INT_MOD_IPS_UPPER_RANGE
)) {
3801 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3802 " Using default value of %i.\n",
3803 IntsPerSec
[pAC
->Index
],
3804 C_INT_MOD_IPS_LOWER_RANGE
,
3805 C_INT_MOD_IPS_UPPER_RANGE
,
3806 C_INTS_PER_SEC_DEFAULT
);
3807 pAC
->DynIrqModInfo
.MaxModIntsPerSec
= C_INTS_PER_SEC_DEFAULT
;
3809 pAC
->DynIrqModInfo
.MaxModIntsPerSec
= IntsPerSec
[pAC
->Index
];
3812 pAC
->DynIrqModInfo
.MaxModIntsPerSec
= C_INTS_PER_SEC_DEFAULT
;
3816 ** Evaluate upper and lower moderation threshold
3818 pAC
->DynIrqModInfo
.MaxModIntsPerSecUpperLimit
=
3819 pAC
->DynIrqModInfo
.MaxModIntsPerSec
+
3820 (pAC
->DynIrqModInfo
.MaxModIntsPerSec
/ 2);
3822 pAC
->DynIrqModInfo
.MaxModIntsPerSecLowerLimit
=
3823 pAC
->DynIrqModInfo
.MaxModIntsPerSec
-
3824 (pAC
->DynIrqModInfo
.MaxModIntsPerSec
/ 2);
3826 pAC
->DynIrqModInfo
.PrevTimeVal
= jiffies
; /* initial value */
3829 } /* GetConfiguration */
3832 /*****************************************************************************
3834 * ProductStr - return a adapter identification string from vpd
3837 * This function reads the product name string from the vpd area
3838 * and puts it the field pAC->DeviceString.
3842 static void ProductStr(
3843 SK_AC
*pAC
/* pointer to adapter context */
3846 int StrLen
= 80; /* length of the string, defined in SK_AC */
3847 char Keyword
[] = VPD_NAME
; /* vpd productname identifier */
3848 int ReturnCode
; /* return code from vpd_read */
3849 unsigned long Flags
;
3851 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
3852 ReturnCode
= VpdRead(pAC
, pAC
->IoBase
, Keyword
, pAC
->DeviceStr
,
3854 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
3855 if (ReturnCode
!= 0) {
3856 /* there was an error reading the vpd data */
3857 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_ERROR
,
3858 ("Error reading VPD data: %d\n", ReturnCode
));
3859 pAC
->DeviceStr
[0] = '\0';
3863 /*****************************************************************************
3865 * StartDrvCleanupTimer - Start timer to check for descriptors which
3866 * might be placed in descriptor ring, but
3867 * havent been handled up to now
3870 * This function requests a HW-timer fo the Yukon card. The actions to
3871 * perform when this timer expires, are located in the SkDrvEvent().
3876 StartDrvCleanupTimer(SK_AC
*pAC
) {
3877 SK_EVPARA EventParam
; /* Event struct for timer event */
3879 SK_MEMSET((char *) &EventParam
, 0, sizeof(EventParam
));
3880 EventParam
.Para32
[0] = SK_DRV_RX_CLEANUP_TIMER
;
3881 SkTimerStart(pAC
, pAC
->IoBase
, &pAC
->DrvCleanupTimer
,
3882 SK_DRV_RX_CLEANUP_TIMER_LENGTH
,
3883 SKGE_DRV
, SK_DRV_TIMER
, EventParam
);
3886 /*****************************************************************************
3888 * StopDrvCleanupTimer - Stop timer to check for descriptors
3891 * This function requests a HW-timer fo the Yukon card. The actions to
3892 * perform when this timer expires, are located in the SkDrvEvent().
3897 StopDrvCleanupTimer(SK_AC
*pAC
) {
3898 SkTimerStop(pAC
, pAC
->IoBase
, &pAC
->DrvCleanupTimer
);
3899 SK_MEMSET((char *) &pAC
->DrvCleanupTimer
, 0, sizeof(SK_TIMER
));
3902 /****************************************************************************/
3903 /* functions for common modules *********************************************/
3904 /****************************************************************************/
3907 /*****************************************************************************
3909 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3912 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3913 * is embedded into a socket buff data area.
3919 * NULL or pointer to Mbuf.
3921 SK_MBUF
*SkDrvAllocRlmtMbuf(
3922 SK_AC
*pAC
, /* pointer to adapter context */
3923 SK_IOC IoC
, /* the IO-context */
3924 unsigned BufferSize
) /* size of the requested buffer */
3926 SK_MBUF
*pRlmtMbuf
; /* pointer to a new rlmt-mbuf structure */
3927 struct sk_buff
*pMsgBlock
; /* pointer to a new message block */
3929 pMsgBlock
= alloc_skb(BufferSize
+ sizeof(SK_MBUF
), GFP_ATOMIC
);
3930 if (pMsgBlock
== NULL
) {
3933 pRlmtMbuf
= (SK_MBUF
*) pMsgBlock
->data
;
3934 skb_reserve(pMsgBlock
, sizeof(SK_MBUF
));
3935 pRlmtMbuf
->pNext
= NULL
;
3936 pRlmtMbuf
->pOs
= pMsgBlock
;
3937 pRlmtMbuf
->pData
= pMsgBlock
->data
; /* Data buffer. */
3938 pRlmtMbuf
->Size
= BufferSize
; /* Data buffer size. */
3939 pRlmtMbuf
->Length
= 0; /* Length of packet (<= Size). */
3942 } /* SkDrvAllocRlmtMbuf */
3945 /*****************************************************************************
3947 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3950 * This routine frees one or more RLMT mbuf(s).
3958 void SkDrvFreeRlmtMbuf(
3959 SK_AC
*pAC
, /* pointer to adapter context */
3960 SK_IOC IoC
, /* the IO-context */
3961 SK_MBUF
*pMbuf
) /* size of the requested buffer */
3968 pNextMbuf
= pFreeMbuf
->pNext
;
3969 DEV_KFREE_SKB_ANY(pFreeMbuf
->pOs
);
3970 pFreeMbuf
= pNextMbuf
;
3971 } while ( pFreeMbuf
!= NULL
);
3972 } /* SkDrvFreeRlmtMbuf */
3975 /*****************************************************************************
3977 * SkOsGetTime - provide a time value
3980 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3981 * It is not used for absolute time, but only for time differences.
3987 SK_U64
SkOsGetTime(SK_AC
*pAC
)
3989 SK_U64 PrivateJiffies
;
3990 SkOsGetTimeCurrent(pAC
, &PrivateJiffies
);
3991 return PrivateJiffies
;
3995 /*****************************************************************************
3997 * SkPciReadCfgDWord - read a 32 bit value from pci config space
4000 * This routine reads a 32 bit value from the pci configuration
4004 * 0 - indicate everything worked ok.
4005 * != 0 - error indication
4007 int SkPciReadCfgDWord(
4008 SK_AC
*pAC
, /* Adapter Control structure pointer */
4009 int PciAddr
, /* PCI register address */
4010 SK_U32
*pVal
) /* pointer to store the read value */
4012 pci_read_config_dword(pAC
->PciDev
, PciAddr
, pVal
);
4014 } /* SkPciReadCfgDWord */
4017 /*****************************************************************************
4019 * SkPciReadCfgWord - read a 16 bit value from pci config space
4022 * This routine reads a 16 bit value from the pci configuration
4026 * 0 - indicate everything worked ok.
4027 * != 0 - error indication
4029 int SkPciReadCfgWord(
4030 SK_AC
*pAC
, /* Adapter Control structure pointer */
4031 int PciAddr
, /* PCI register address */
4032 SK_U16
*pVal
) /* pointer to store the read value */
4034 pci_read_config_word(pAC
->PciDev
, PciAddr
, pVal
);
4036 } /* SkPciReadCfgWord */
4039 /*****************************************************************************
4041 * SkPciReadCfgByte - read a 8 bit value from pci config space
4044 * This routine reads a 8 bit value from the pci configuration
4048 * 0 - indicate everything worked ok.
4049 * != 0 - error indication
4051 int SkPciReadCfgByte(
4052 SK_AC
*pAC
, /* Adapter Control structure pointer */
4053 int PciAddr
, /* PCI register address */
4054 SK_U8
*pVal
) /* pointer to store the read value */
4056 pci_read_config_byte(pAC
->PciDev
, PciAddr
, pVal
);
4058 } /* SkPciReadCfgByte */
4061 /*****************************************************************************
4063 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4066 * This routine writes a 32 bit value to the pci configuration
4070 * 0 - indicate everything worked ok.
4071 * != 0 - error indication
4073 int SkPciWriteCfgDWord(
4074 SK_AC
*pAC
, /* Adapter Control structure pointer */
4075 int PciAddr
, /* PCI register address */
4076 SK_U32 Val
) /* pointer to store the read value */
4078 pci_write_config_dword(pAC
->PciDev
, PciAddr
, Val
);
4080 } /* SkPciWriteCfgDWord */
4083 /*****************************************************************************
4085 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4088 * This routine writes a 16 bit value to the pci configuration
4089 * space. The flag PciConfigUp indicates whether the config space
4090 * is accesible or must be set up first.
4093 * 0 - indicate everything worked ok.
4094 * != 0 - error indication
4096 int SkPciWriteCfgWord(
4097 SK_AC
*pAC
, /* Adapter Control structure pointer */
4098 int PciAddr
, /* PCI register address */
4099 SK_U16 Val
) /* pointer to store the read value */
4101 pci_write_config_word(pAC
->PciDev
, PciAddr
, Val
);
4103 } /* SkPciWriteCfgWord */
4106 /*****************************************************************************
4108 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4111 * This routine writes a 8 bit value to the pci configuration
4112 * space. The flag PciConfigUp indicates whether the config space
4113 * is accesible or must be set up first.
4116 * 0 - indicate everything worked ok.
4117 * != 0 - error indication
4119 int SkPciWriteCfgByte(
4120 SK_AC
*pAC
, /* Adapter Control structure pointer */
4121 int PciAddr
, /* PCI register address */
4122 SK_U8 Val
) /* pointer to store the read value */
4124 pci_write_config_byte(pAC
->PciDev
, PciAddr
, Val
);
4126 } /* SkPciWriteCfgByte */
4129 /*****************************************************************************
4131 * SkDrvEvent - handle driver events
4134 * This function handles events from all modules directed to the driver
4137 * Is called under protection of slow path lock.
4140 * 0 if everything ok
4145 SK_AC
*pAC
, /* pointer to adapter context */
4146 SK_IOC IoC
, /* io-context */
4147 SK_U32 Event
, /* event-id */
4148 SK_EVPARA Param
) /* event-parameter */
4150 SK_MBUF
*pRlmtMbuf
; /* pointer to a rlmt-mbuf structure */
4151 struct sk_buff
*pMsg
; /* pointer to a message block */
4152 int FromPort
; /* the port from which we switch away */
4153 int ToPort
; /* the port we switch to */
4154 SK_EVPARA NewPara
; /* parameter for further events */
4156 unsigned long Flags
;
4160 case SK_DRV_ADAP_FAIL
:
4161 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4162 ("ADAPTER FAIL EVENT\n"));
4163 printk("%s: Adapter failed.\n", pAC
->dev
[0]->name
);
4164 /* disable interrupts */
4165 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
4168 case SK_DRV_PORT_FAIL
:
4169 FromPort
= Param
.Para32
[0];
4170 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4171 ("PORT FAIL EVENT, Port: %d\n", FromPort
));
4172 if (FromPort
== 0) {
4173 printk("%s: Port A failed.\n", pAC
->dev
[0]->name
);
4175 printk("%s: Port B failed.\n", pAC
->dev
[1]->name
);
4179 case SK_DRV_PORT_RESET
: /* SK_U32 PortIdx */
4181 FromPort
= Param
.Para32
[0];
4182 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4183 ("PORT RESET EVENT, Port: %d ", FromPort
));
4184 NewPara
.Para64
= FromPort
;
4185 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
4187 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4190 SkGeStopPort(pAC
, IoC
, FromPort
, SK_STOP_ALL
, SK_HARD_RST
);
4191 pAC
->dev
[Param
.Para32
[0]]->flags
&= ~IFF_RUNNING
;
4192 spin_unlock_irqrestore(
4193 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4196 /* clear rx ring from received frames */
4197 ReceiveIrq(pAC
, &pAC
->RxPort
[FromPort
], SK_FALSE
);
4199 ClearTxRing(pAC
, &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
]);
4201 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4204 /* tschilling: Handling of return value inserted. */
4205 if (SkGeInitPort(pAC
, IoC
, FromPort
)) {
4206 if (FromPort
== 0) {
4207 printk("%s: SkGeInitPort A failed.\n", pAC
->dev
[0]->name
);
4209 printk("%s: SkGeInitPort B failed.\n", pAC
->dev
[1]->name
);
4212 SkAddrMcUpdate(pAC
,IoC
, FromPort
);
4213 PortReInitBmu(pAC
, FromPort
);
4214 SkGePollTxD(pAC
, IoC
, FromPort
, SK_TRUE
);
4215 ClearAndStartRx(pAC
, FromPort
);
4216 spin_unlock_irqrestore(
4217 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4220 case SK_DRV_NET_UP
: /* SK_U32 PortIdx */
4222 FromPort
= Param
.Para32
[0];
4223 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4224 ("NET UP EVENT, Port: %d ", Param
.Para32
[0]));
4226 SkAddrMcUpdate(pAC
,IoC
, FromPort
);
4228 if (DoPrintInterfaceChange
) {
4229 printk("%s: network connection up using"
4230 " port %c\n", pAC
->dev
[Param
.Para32
[0]]->name
, 'A'+Param
.Para32
[0]);
4232 /* tschilling: Values changed according to LinkSpeedUsed. */
4233 Stat
= pAC
->GIni
.GP
[FromPort
].PLinkSpeedUsed
;
4234 if (Stat
== SK_LSPEED_STAT_10MBPS
) {
4235 printk(" speed: 10\n");
4236 } else if (Stat
== SK_LSPEED_STAT_100MBPS
) {
4237 printk(" speed: 100\n");
4238 } else if (Stat
== SK_LSPEED_STAT_1000MBPS
) {
4239 printk(" speed: 1000\n");
4241 printk(" speed: unknown\n");
4245 Stat
= pAC
->GIni
.GP
[FromPort
].PLinkModeStatus
;
4246 if (Stat
== SK_LMODE_STAT_AUTOHALF
||
4247 Stat
== SK_LMODE_STAT_AUTOFULL
) {
4248 printk(" autonegotiation: yes\n");
4251 printk(" autonegotiation: no\n");
4253 if (Stat
== SK_LMODE_STAT_AUTOHALF
||
4254 Stat
== SK_LMODE_STAT_HALF
) {
4255 printk(" duplex mode: half\n");
4258 printk(" duplex mode: full\n");
4260 Stat
= pAC
->GIni
.GP
[FromPort
].PFlowCtrlStatus
;
4261 if (Stat
== SK_FLOW_STAT_REM_SEND
) {
4262 printk(" flowctrl: remote send\n");
4264 else if (Stat
== SK_FLOW_STAT_LOC_SEND
){
4265 printk(" flowctrl: local send\n");
4267 else if (Stat
== SK_FLOW_STAT_SYMMETRIC
){
4268 printk(" flowctrl: symmetric\n");
4271 printk(" flowctrl: none\n");
4274 /* tschilling: Check against CopperType now. */
4275 if ((pAC
->GIni
.GICopperType
== SK_TRUE
) &&
4276 (pAC
->GIni
.GP
[FromPort
].PLinkSpeedUsed
==
4277 SK_LSPEED_STAT_1000MBPS
)) {
4278 Stat
= pAC
->GIni
.GP
[FromPort
].PMSStatus
;
4279 if (Stat
== SK_MS_STAT_MASTER
) {
4280 printk(" role: master\n");
4282 else if (Stat
== SK_MS_STAT_SLAVE
) {
4283 printk(" role: slave\n");
4286 printk(" role: ???\n");
4291 Display dim (dynamic interrupt moderation)
4294 if (pAC
->DynIrqModInfo
.IntModTypeSelect
== C_INT_MOD_STATIC
)
4295 printk(" irq moderation: static (%d ints/sec)\n",
4296 pAC
->DynIrqModInfo
.MaxModIntsPerSec
);
4297 else if (pAC
->DynIrqModInfo
.IntModTypeSelect
== C_INT_MOD_DYNAMIC
)
4298 printk(" irq moderation: dynamic (%d ints/sec)\n",
4299 pAC
->DynIrqModInfo
.MaxModIntsPerSec
);
4301 printk(" irq moderation: disabled\n");
4305 if (pAC
->ChipsetType
)
4306 #ifdef USE_SK_TX_CHECKSUM
4307 printk(" scatter-gather: enabled\n");
4309 printk(" tx-checksum: disabled\n");
4312 printk(" scatter-gather: disabled\n");
4314 printk(" scatter-gather: disabled\n");
4317 #ifndef USE_SK_RX_CHECKSUM
4318 printk(" rx-checksum: disabled\n");
4322 DoPrintInterfaceChange
= SK_TRUE
;
4325 if ((Param
.Para32
[0] != pAC
->ActivePort
) &&
4326 (pAC
->RlmtNets
== 1)) {
4327 NewPara
.Para32
[0] = pAC
->ActivePort
;
4328 NewPara
.Para32
[1] = Param
.Para32
[0];
4329 SkEventQueue(pAC
, SKGE_DRV
, SK_DRV_SWITCH_INTERN
,
4333 /* Inform the world that link protocol is up. */
4334 pAC
->dev
[Param
.Para32
[0]]->flags
|= IFF_RUNNING
;
4337 case SK_DRV_NET_DOWN
: /* SK_U32 Reason */
4339 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4340 ("NET DOWN EVENT "));
4341 if (DoPrintInterfaceChange
) {
4342 printk("%s: network connection down\n",
4343 pAC
->dev
[Param
.Para32
[1]]->name
);
4345 DoPrintInterfaceChange
= SK_TRUE
;
4347 pAC
->dev
[Param
.Para32
[1]]->flags
&= ~IFF_RUNNING
;
4349 case SK_DRV_SWITCH_HARD
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4350 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4351 ("PORT SWITCH HARD "));
4352 case SK_DRV_SWITCH_SOFT
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4354 printk("%s: switching to port %c\n", pAC
->dev
[0]->name
,
4355 'A'+Param
.Para32
[1]);
4356 case SK_DRV_SWITCH_INTERN
: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4357 FromPort
= Param
.Para32
[0];
4358 ToPort
= Param
.Para32
[1];
4359 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4360 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4361 FromPort
, ToPort
, pAC
->Rlmt
.Net
[0].PrefPort
));
4362 NewPara
.Para64
= FromPort
;
4363 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
4364 NewPara
.Para64
= ToPort
;
4365 SkPnmiEvent(pAC
, IoC
, SK_PNMI_EVT_XMAC_RESET
, NewPara
);
4367 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4369 spin_lock(&pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
);
4370 SkGeStopPort(pAC
, IoC
, FromPort
, SK_STOP_ALL
, SK_SOFT_RST
);
4371 SkGeStopPort(pAC
, IoC
, ToPort
, SK_STOP_ALL
, SK_SOFT_RST
);
4372 spin_unlock(&pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
);
4373 spin_unlock_irqrestore(
4374 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4377 ReceiveIrq(pAC
, &pAC
->RxPort
[FromPort
], SK_FALSE
); /* clears rx ring */
4378 ReceiveIrq(pAC
, &pAC
->RxPort
[ToPort
], SK_FALSE
); /* clears rx ring */
4380 ClearTxRing(pAC
, &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
]);
4381 ClearTxRing(pAC
, &pAC
->TxPort
[ToPort
][TX_PRIO_LOW
]);
4383 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4385 spin_lock(&pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
);
4386 pAC
->ActivePort
= ToPort
;
4390 /* tschilling: New common function with minimum size check. */
4392 if (pAC
->RlmtNets
== 2) {
4396 if (SkGeInitAssignRamToQueues(
4400 spin_unlock(&pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
);
4401 spin_unlock_irqrestore(
4402 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4404 printk("SkGeInitAssignRamToQueues failed.\n");
4408 /* tschilling: Handling of return values inserted. */
4409 if (SkGeInitPort(pAC
, IoC
, FromPort
) ||
4410 SkGeInitPort(pAC
, IoC
, ToPort
)) {
4411 printk("%s: SkGeInitPort failed.\n", pAC
->dev
[0]->name
);
4413 if (Event
== SK_DRV_SWITCH_SOFT
) {
4414 SkMacRxTxEnable(pAC
, IoC
, FromPort
);
4416 SkMacRxTxEnable(pAC
, IoC
, ToPort
);
4417 SkAddrSwap(pAC
, IoC
, FromPort
, ToPort
);
4418 SkAddrMcUpdate(pAC
, IoC
, FromPort
);
4419 SkAddrMcUpdate(pAC
, IoC
, ToPort
);
4420 PortReInitBmu(pAC
, FromPort
);
4421 PortReInitBmu(pAC
, ToPort
);
4422 SkGePollTxD(pAC
, IoC
, FromPort
, SK_TRUE
);
4423 SkGePollTxD(pAC
, IoC
, ToPort
, SK_TRUE
);
4424 ClearAndStartRx(pAC
, FromPort
);
4425 ClearAndStartRx(pAC
, ToPort
);
4426 spin_unlock(&pAC
->TxPort
[ToPort
][TX_PRIO_LOW
].TxDesRingLock
);
4427 spin_unlock_irqrestore(
4428 &pAC
->TxPort
[FromPort
][TX_PRIO_LOW
].TxDesRingLock
,
4431 case SK_DRV_RLMT_SEND
: /* SK_MBUF *pMb */
4432 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4434 pRlmtMbuf
= (SK_MBUF
*) Param
.pParaPtr
;
4435 pMsg
= (struct sk_buff
*) pRlmtMbuf
->pOs
;
4436 skb_put(pMsg
, pRlmtMbuf
->Length
);
4437 if (XmitFrame(pAC
, &pAC
->TxPort
[pRlmtMbuf
->PortIdx
][TX_PRIO_LOW
],
4440 DEV_KFREE_SKB_ANY(pMsg
);
4443 if (Param
.Para32
[0] == SK_DRV_MODERATION_TIMER
) {
4445 ** expiration of the moderation timer implies that
4446 ** dynamic moderation is to be applied
4448 SkDimStartModerationTimer(pAC
);
4450 if (pAC
->DynIrqModInfo
.DisplayStats
) {
4451 SkDimDisplayModerationSettings(pAC
);
4453 } else if (Param
.Para32
[0] == SK_DRV_RX_CLEANUP_TIMER
) {
4455 ** check if we need to check for descriptors which
4456 ** haven't been handled the last millisecs
4458 StartDrvCleanupTimer(pAC
);
4459 if (pAC
->GIni
.GIMacsFound
== 2) {
4460 ReceiveIrq(pAC
, &pAC
->RxPort
[1], SK_FALSE
);
4462 ReceiveIrq(pAC
, &pAC
->RxPort
[0], SK_FALSE
);
4464 printk("Expiration of unknown timer\n");
4470 SK_DBG_MSG(NULL
, SK_DBGMOD_DRV
, SK_DBGCAT_DRV_EVENT
,
4477 /*****************************************************************************
4479 * SkErrorLog - log errors
4482 * This function logs errors to the system buffer and to the console
4485 * 0 if everything ok
4498 case SK_ERRCL_OTHER
:
4499 strcpy(ClassStr
, "Other error");
4501 case SK_ERRCL_CONFIG
:
4502 strcpy(ClassStr
, "Configuration error");
4505 strcpy(ClassStr
, "Initialization error");
4507 case SK_ERRCL_NORES
:
4508 strcpy(ClassStr
, "Out of resources error");
4511 strcpy(ClassStr
, "internal Software error");
4514 strcpy(ClassStr
, "Hardware failure");
4517 strcpy(ClassStr
, "Communication error");
4520 printk(KERN_INFO
"%s: -- ERROR --\n Class: %s\n"
4521 " Nr: 0x%x\n Msg: %s\n", pAC
->dev
[0]->name
,
4522 ClassStr
, ErrNum
, pErrorMsg
);
4526 #ifdef SK_DIAG_SUPPORT
4528 /*****************************************************************************
4530 * SkDrvEnterDiagMode - handles DIAG attach request
4533 * Notify the kernel to NOT access the card any longer due to DIAG
4534 * Deinitialize the Card
4539 int SkDrvEnterDiagMode(
4540 SK_AC
*pAc
) /* pointer to adapter context */
4543 DEV_NET
*pNet
= NULL
;
4545 pNet
= (DEV_NET
*) pAc
->dev
[0]->priv
;
4548 SK_MEMCPY(&(pAc
->PnmiBackup
), &(pAc
->PnmiStruct
),
4549 sizeof(SK_PNMI_STRUCT_DATA
));
4551 pAC
->DiagModeActive
= DIAG_ACTIVE
;
4552 if (pAC
->BoardLevel
> SK_INIT_DATA
) {
4554 pAC
->WasIfUp
[0] = SK_TRUE
;
4555 pAC
->DiagFlowCtrl
= SK_TRUE
; /* for SkGeClose */
4556 DoPrintInterfaceChange
= SK_FALSE
;
4557 SkDrvDeInitAdapter(pAC
, 0); /* performs SkGeClose */
4559 pAC
->WasIfUp
[0] = SK_FALSE
;
4561 if (pNet
!= (DEV_NET
*) pAc
->dev
[1]->priv
) {
4562 pNet
= (DEV_NET
*) pAc
->dev
[1]->priv
;
4564 pAC
->WasIfUp
[1] = SK_TRUE
;
4565 pAC
->DiagFlowCtrl
= SK_TRUE
; /* for SkGeClose */
4566 DoPrintInterfaceChange
= SK_FALSE
;
4567 SkDrvDeInitAdapter(pAC
, 1); /* do SkGeClose */
4569 pAC
->WasIfUp
[1] = SK_FALSE
;
4572 pAC
->BoardLevel
= SK_INIT_DATA
;
4577 /*****************************************************************************
4579 * SkDrvLeaveDiagMode - handles DIAG detach request
4582 * Notify the kernel to may access the card again after use by DIAG
4583 * Initialize the Card
4588 int SkDrvLeaveDiagMode(
4589 SK_AC
*pAc
) /* pointer to adapter control context */
4591 SK_MEMCPY(&(pAc
->PnmiStruct
), &(pAc
->PnmiBackup
),
4592 sizeof(SK_PNMI_STRUCT_DATA
));
4593 pAc
->DiagModeActive
= DIAG_NOTACTIVE
;
4594 pAc
->Pnmi
.DiagAttached
= SK_DIAG_IDLE
;
4595 if (pAc
->WasIfUp
[0] == SK_TRUE
) {
4596 pAc
->DiagFlowCtrl
= SK_TRUE
; /* for SkGeClose */
4597 DoPrintInterfaceChange
= SK_FALSE
;
4598 SkDrvInitAdapter(pAc
, 0); /* first device */
4600 if (pAc
->WasIfUp
[1] == SK_TRUE
) {
4601 pAc
->DiagFlowCtrl
= SK_TRUE
; /* for SkGeClose */
4602 DoPrintInterfaceChange
= SK_FALSE
;
4603 SkDrvInitAdapter(pAc
, 1); /* second device */
4608 /*****************************************************************************
4610 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4613 * This function parses the PCI slot name information string and will
4614 * retrieve the devcie number out of it. The slot_name maintianed by
4615 * linux is in the form of '02:0a.0', whereas the first two characters
4616 * represent the bus number in hex (in the sample above this is
4617 * pci bus 0x02) and the next two characters the device number (0x0a).
4620 * SK_U32: The device number from the PCI slot name
4623 static SK_U32
ParseDeviceNbrFromSlotName(
4624 const char *SlotName
) /* pointer to pci slot name eg. '02:0a.0' */
4626 char *CurrCharPos
= (char *) SlotName
;
4627 int FirstNibble
= -1;
4628 int SecondNibble
= -1;
4631 while (*CurrCharPos
!= '\0') {
4632 if (*CurrCharPos
== ':') {
4633 while (*CurrCharPos
!= '.') {
4635 if ( (*CurrCharPos
>= '0') &&
4636 (*CurrCharPos
<= '9')) {
4637 if (FirstNibble
== -1) {
4638 /* dec. value for '0' */
4639 FirstNibble
= *CurrCharPos
- 48;
4641 SecondNibble
= *CurrCharPos
- 48;
4643 } else if ( (*CurrCharPos
>= 'a') &&
4644 (*CurrCharPos
<= 'f') ) {
4645 if (FirstNibble
== -1) {
4646 FirstNibble
= *CurrCharPos
- 87;
4648 SecondNibble
= *CurrCharPos
- 87;
4655 Result
= FirstNibble
;
4656 Result
= Result
<< 4; /* first nibble is higher one */
4657 Result
= Result
| SecondNibble
;
4659 CurrCharPos
++; /* next character */
4664 /****************************************************************************
4666 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4667 * called if Diag attaches to that card)
4670 * Close initialized adapter.
4674 * error code - on error
4676 static int SkDrvDeInitAdapter(
4677 SK_AC
*pAC
, /* pointer to adapter context */
4678 int devNbr
) /* what device is to be handled */
4680 struct SK_NET_DEVICE
*dev
;
4682 dev
= pAC
->dev
[devNbr
];
4685 ** Function SkGeClose() uses MOD_DEC_USE_COUNT (2.2/2.4)
4686 ** or module_put() (2.6) to decrease the number of users for
4687 ** a device, but if a device is to be put under control of
4688 ** the DIAG, that count is OK already and does not need to
4689 ** be adapted! Hence the opposite MOD_INC_USE_COUNT or
4690 ** try_module_get() needs to be used again to correct that.
4692 if (!try_module_get(THIS_MODULE
)) {
4696 if (SkGeClose(dev
) != 0) {
4697 module_put(THIS_MODULE
);
4702 } /* SkDrvDeInitAdapter() */
4704 /****************************************************************************
4706 * SkDrvInitAdapter - Initialize adapter (this function is only
4707 * called if Diag deattaches from that card)
4710 * Close initialized adapter.
4714 * error code - on error
4716 static int SkDrvInitAdapter(
4717 SK_AC
*pAC
, /* pointer to adapter context */
4718 int devNbr
) /* what device is to be handled */
4720 struct SK_NET_DEVICE
*dev
;
4722 dev
= pAC
->dev
[devNbr
];
4724 if (SkGeOpen(dev
) != 0) {
4728 ** Function SkGeOpen() uses MOD_INC_USE_COUNT (2.2/2.4)
4729 ** or try_module_get() (2.6) to increase the number of
4730 ** users for a device, but if a device was just under
4731 ** control of the DIAG, that count is OK already and
4732 ** does not need to be adapted! Hence the opposite
4733 ** MOD_DEC_USE_COUNT or module_put() needs to be used
4734 ** again to correct that.
4736 module_put(THIS_MODULE
);
4740 ** Use correct MTU size and indicate to kernel TX queue can be started
4742 if (SkGeChangeMtu(dev
, dev
->mtu
) != 0) {
4747 } /* SkDrvInitAdapter */
4752 /****************************************************************************/
4753 /* "debug only" section *****************************************************/
4754 /****************************************************************************/
4757 /*****************************************************************************
4759 * DumpMsg - print a frame
4762 * This function prints frames to the system logfile/to the console.
4767 static void DumpMsg(struct sk_buff
*skb
, char *str
)
4772 printk("DumpMsg(): NULL-Message\n");
4776 if (skb
->data
== NULL
) {
4777 printk("DumpMsg(): Message empty\n");
4785 printk("--- Begin of message from %s , len %d (from %d) ----\n", str
, msglen
, skb
->len
);
4787 DumpData((char *)skb
->data
, msglen
);
4789 printk("------- End of message ---------\n");
4794 /*****************************************************************************
4796 * DumpData - print a data area
4799 * This function prints a area of data to the system logfile/to the
4805 static void DumpData(char *p
, int size
)
4809 char hex_buffer
[180];
4810 char asc_buffer
[180];
4811 char HEXCHAR
[] = "0123456789ABCDEF";
4817 for (i
=0; i
< size
; ) {
4818 if (*p
>= '0' && *p
<='z')
4819 asc_buffer
[addr
] = *p
;
4821 asc_buffer
[addr
] = '.';
4823 asc_buffer
[addr
] = 0;
4824 hex_buffer
[haddr
] = HEXCHAR
[(*p
& 0xf0) >> 4];
4826 hex_buffer
[haddr
] = HEXCHAR
[*p
& 0x0f];
4828 hex_buffer
[haddr
] = ' ';
4830 hex_buffer
[haddr
] = 0;
4834 printk("%s %s\n", hex_buffer
, asc_buffer
);
4842 /*****************************************************************************
4844 * DumpLong - print a data area as long values
4847 * This function prints a area of data to the system logfile/to the
4853 static void DumpLong(char *pc
, int size
)
4857 char hex_buffer
[180];
4858 char asc_buffer
[180];
4859 char HEXCHAR
[] = "0123456789ABCDEF";
4868 for (i
=0; i
< size
; ) {
4870 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 28) & 0xf];
4872 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 24) & 0xf];
4874 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 20) & 0xf];
4876 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 16) & 0xf];
4878 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 12) & 0xf];
4880 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 8) & 0xf];
4882 hex_buffer
[haddr
] = HEXCHAR
[(l
>> 4) & 0xf];
4884 hex_buffer
[haddr
] = HEXCHAR
[l
& 0x0f];
4886 hex_buffer
[haddr
] = ' ';
4888 hex_buffer
[haddr
] = 0;
4892 printk("%4x %s\n", (i
-8)*4, hex_buffer
);
4896 printk("------------------------\n");
4901 static int __devinit
skge_probe_one(struct pci_dev
*pdev
,
4902 const struct pci_device_id
*ent
)
4905 DEV_NET
*pNet
= NULL
;
4906 struct net_device
*dev
= NULL
;
4907 #ifdef CONFIG_PROC_FS
4908 struct proc_dir_entry
*pProcFile
;
4910 static int boards_found
= 0;
4911 int error
= -ENODEV
;
4913 if (pci_enable_device(pdev
))
4916 /* Configure DMA attributes. */
4917 if (pci_set_dma_mask(pdev
, (u64
) 0xffffffffffffffffULL
) &&
4918 pci_set_dma_mask(pdev
, (u64
) 0xffffffff))
4919 goto out_disable_device
;
4922 if ((dev
= alloc_etherdev(sizeof(DEV_NET
))) == NULL
) {
4923 printk(KERN_ERR
"Unable to allocate etherdev "
4925 goto out_disable_device
;
4929 pNet
->pAC
= kmalloc(sizeof(SK_AC
), GFP_KERNEL
);
4931 printk(KERN_ERR
"Unable to allocate adapter "
4933 goto out_free_netdev
;
4936 memset(pNet
->pAC
, 0, sizeof(SK_AC
));
4939 pAC
->PciDevId
= pdev
->device
;
4942 sprintf(pAC
->Name
, "SysKonnect SK-98xx");
4943 pAC
->CheckQueue
= SK_FALSE
;
4947 dev
->irq
= pdev
->irq
;
4948 error
= SkGeInitPCI(pAC
);
4950 printk("SKGE: PCI setup failed: %i\n", error
);
4951 goto out_free_netdev
;
4954 SET_MODULE_OWNER(dev
);
4955 dev
->open
= &SkGeOpen
;
4956 dev
->stop
= &SkGeClose
;
4957 dev
->hard_start_xmit
= &SkGeXmit
;
4958 dev
->get_stats
= &SkGeStats
;
4959 dev
->set_multicast_list
= &SkGeSetRxMode
;
4960 dev
->set_mac_address
= &SkGeSetMacAddr
;
4961 dev
->do_ioctl
= &SkGeIoctl
;
4962 dev
->change_mtu
= &SkGeChangeMtu
;
4963 dev
->flags
&= ~IFF_RUNNING
;
4964 SET_NETDEV_DEV(dev
, &pdev
->dev
);
4967 #ifdef USE_SK_TX_CHECKSUM
4968 if (pAC
->ChipsetType
) {
4969 /* Use only if yukon hardware */
4970 /* SK and ZEROCOPY - fly baby... */
4971 dev
->features
|= NETIF_F_SG
| NETIF_F_IP_CSUM
;
4976 pAC
->Index
= boards_found
++;
4978 if (SkGeBoardInit(dev
, pAC
))
4979 goto out_free_netdev
;
4981 /* Register net device */
4982 if (register_netdev(dev
)) {
4983 printk(KERN_ERR
"SKGE: Could not register device.\n");
4984 goto out_free_resources
;
4987 /* Print adapter specific string from vpd */
4989 printk("%s: %s\n", dev
->name
, pAC
->DeviceStr
);
4991 /* Print configuration settings */
4992 printk(" PrefPort:%c RlmtMode:%s\n",
4993 'A' + pAC
->Rlmt
.Net
[0].Port
[pAC
->Rlmt
.Net
[0].PrefPort
]->PortNumber
,
4994 (pAC
->RlmtMode
==0) ? "Check Link State" :
4995 ((pAC
->RlmtMode
==1) ? "Check Link State" :
4996 ((pAC
->RlmtMode
==3) ? "Check Local Port" :
4997 ((pAC
->RlmtMode
==7) ? "Check Segmentation" :
4998 ((pAC
->RlmtMode
==17) ? "Dual Check Link State" :"Error")))));
5000 SkGeYellowLED(pAC
, pAC
->IoBase
, 1);
5003 memcpy(&dev
->dev_addr
, &pAC
->Addr
.Net
[0].CurrentMacAddress
, 6);
5005 #ifdef CONFIG_PROC_FS
5006 pProcFile
= create_proc_entry(dev
->name
, S_IRUGO
, pSkRootDir
);
5008 pProcFile
->proc_fops
= &sk_proc_fops
;
5009 pProcFile
->data
= dev
;
5010 pProcFile
->owner
= THIS_MODULE
;
5019 /* More then one port found */
5020 if ((pAC
->GIni
.GIMacsFound
== 2 ) && (pAC
->RlmtNets
== 2)) {
5021 if ((dev
= alloc_etherdev(sizeof(DEV_NET
))) == 0) {
5022 printk(KERN_ERR
"Unable to allocate etherdev "
5035 dev
->open
= &SkGeOpen
;
5036 dev
->stop
= &SkGeClose
;
5037 dev
->hard_start_xmit
= &SkGeXmit
;
5038 dev
->get_stats
= &SkGeStats
;
5039 dev
->set_multicast_list
= &SkGeSetRxMode
;
5040 dev
->set_mac_address
= &SkGeSetMacAddr
;
5041 dev
->do_ioctl
= &SkGeIoctl
;
5042 dev
->change_mtu
= &SkGeChangeMtu
;
5043 dev
->flags
&= ~IFF_RUNNING
;
5046 #ifdef USE_SK_TX_CHECKSUM
5047 if (pAC
->ChipsetType
) {
5048 /* SG and ZEROCOPY - fly baby... */
5049 dev
->features
|= NETIF_F_SG
| NETIF_F_IP_CSUM
;
5054 if (register_netdev(dev
)) {
5055 printk(KERN_ERR
"SKGE: Could not register device.\n");
5057 pAC
->dev
[1] = pAC
->dev
[0];
5059 #ifdef CONFIG_PROC_FS
5060 pProcFile
= create_proc_entry(dev
->name
, S_IRUGO
,
5063 pProcFile
->proc_fops
= &sk_proc_fops
;
5064 pProcFile
->data
= dev
;
5065 pProcFile
->owner
= THIS_MODULE
;
5069 memcpy(&dev
->dev_addr
,
5070 &pAC
->Addr
.Net
[1].CurrentMacAddress
, 6);
5072 printk("%s: %s\n", dev
->name
, pAC
->DeviceStr
);
5073 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
5077 /* Save the hardware revision */
5078 pAC
->HWRevision
= (((pAC
->GIni
.GIPciHwRev
>> 4) & 0x0F)*10) +
5079 (pAC
->GIni
.GIPciHwRev
& 0x0F);
5081 /* Set driver globals */
5082 pAC
->Pnmi
.pDriverFileName
= DRIVER_FILE_NAME
;
5083 pAC
->Pnmi
.pDriverReleaseDate
= DRIVER_REL_DATE
;
5085 memset(&pAC
->PnmiBackup
, 0, sizeof(SK_PNMI_STRUCT_DATA
));
5086 memcpy(&pAC
->PnmiBackup
, &pAC
->PnmiStruct
, sizeof(SK_PNMI_STRUCT_DATA
));
5088 pci_set_drvdata(pdev
, dev
);
5096 pci_disable_device(pdev
);
5101 static void __devexit
skge_remove_one(struct pci_dev
*pdev
)
5103 struct net_device
*dev
= pci_get_drvdata(pdev
);
5104 DEV_NET
*pNet
= (DEV_NET
*) dev
->priv
;
5105 SK_AC
*pAC
= pNet
->pAC
;
5106 int have_second_mac
= 0;
5108 if ((pAC
->GIni
.GIMacsFound
== 2) && pAC
->RlmtNets
== 2)
5109 have_second_mac
= 1;
5111 remove_proc_entry(dev
->name
, pSkRootDir
);
5112 unregister_netdev(dev
);
5113 if (have_second_mac
) {
5114 remove_proc_entry(pAC
->dev
[1]->name
, pSkRootDir
);
5115 unregister_netdev(pAC
->dev
[1]);
5118 SkGeYellowLED(pAC
, pAC
->IoBase
, 0);
5120 if (pAC
->BoardLevel
== SK_INIT_RUN
) {
5122 unsigned long Flags
;
5124 /* board is still alive */
5125 spin_lock_irqsave(&pAC
->SlowPathLock
, Flags
);
5126 EvPara
.Para32
[0] = 0;
5127 EvPara
.Para32
[1] = -1;
5128 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
5129 EvPara
.Para32
[0] = 1;
5130 EvPara
.Para32
[1] = -1;
5131 SkEventQueue(pAC
, SKGE_RLMT
, SK_RLMT_STOP
, EvPara
);
5132 SkEventDispatcher(pAC
, pAC
->IoBase
);
5133 /* disable interrupts */
5134 SK_OUT32(pAC
->IoBase
, B0_IMSK
, 0);
5135 SkGeDeInit(pAC
, pAC
->IoBase
);
5136 spin_unlock_irqrestore(&pAC
->SlowPathLock
, Flags
);
5137 pAC
->BoardLevel
= SK_INIT_DATA
;
5138 /* We do NOT check here, if IRQ was pending, of course*/
5141 if (pAC
->BoardLevel
== SK_INIT_IO
) {
5142 /* board is still alive */
5143 SkGeDeInit(pAC
, pAC
->IoBase
);
5144 pAC
->BoardLevel
= SK_INIT_DATA
;
5149 if (have_second_mac
)
5150 free_netdev(pAC
->dev
[1]);
5154 static struct pci_device_id skge_pci_tbl
[] = {
5155 { PCI_VENDOR_ID_3COM
, 0x1700, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5156 { PCI_VENDOR_ID_3COM
, 0x80eb, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5157 { PCI_VENDOR_ID_SYSKONNECT
, 0x4300, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5158 { PCI_VENDOR_ID_SYSKONNECT
, 0x4320, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5159 { PCI_VENDOR_ID_DLINK
, 0x4c00, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5160 { PCI_VENDOR_ID_MARVELL
, 0x4320, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5161 #if 0 /* don't handle Yukon2 cards at the moment -- mlindner@syskonnect.de */
5162 { PCI_VENDOR_ID_MARVELL
, 0x4360, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5163 { PCI_VENDOR_ID_MARVELL
, 0x4361, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5165 { PCI_VENDOR_ID_MARVELL
, 0x5005, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5166 { PCI_VENDOR_ID_CNET
, 0x434e, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5167 { PCI_VENDOR_ID_LINKSYS
, 0x1032, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5168 { PCI_VENDOR_ID_LINKSYS
, 0x1064, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
5172 static struct pci_driver skge_driver
= {
5174 .id_table
= skge_pci_tbl
,
5175 .probe
= skge_probe_one
,
5176 .remove
= __devexit_p(skge_remove_one
),
5179 static int __init
skge_init(void)
5183 #ifdef CONFIG_PROC_FS
5184 memcpy(&SK_Root_Dir_entry
, BOOT_STRING
, sizeof(SK_Root_Dir_entry
) - 1);
5186 pSkRootDir
= proc_mkdir(SK_Root_Dir_entry
, proc_net
);
5188 printk(KERN_WARNING
"Unable to create /proc/net/%s",
5192 pSkRootDir
->owner
= THIS_MODULE
;
5195 error
= pci_module_init(&skge_driver
);
5197 #ifdef CONFIG_PROC_FS
5198 remove_proc_entry(pSkRootDir
->name
, proc_net
);
5205 static void __exit
skge_exit(void)
5207 pci_unregister_driver(&skge_driver
);
5208 #ifdef CONFIG_PROC_FS
5209 remove_proc_entry(pSkRootDir
->name
, proc_net
);
5213 module_init(skge_init
);
5214 module_exit(skge_exit
);