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/moduleparam.h>
113 #include <linux/init.h>
114 #include <linux/proc_fs.h>
115 #include <linux/dma-mapping.h>
117 #include "h/skdrv1st.h"
118 #include "h/skdrv2nd.h"
120 /*******************************************************************************
124 ******************************************************************************/
126 /* for debuging on x86 only */
127 /* #define BREAKPOINT() asm(" int $3"); */
129 /* use the transmit hw checksum driver functionality */
130 #define USE_SK_TX_CHECKSUM
132 /* use the receive hw checksum driver functionality */
133 #define USE_SK_RX_CHECKSUM
135 /* use the scatter-gather functionality with sendfile() */
138 /* use of a transmit complete interrupt */
139 #define USE_TX_COMPLETE
142 * threshold for copying small receive frames
143 * set to 0 to avoid copying, set to 9001 to copy all frames
145 #define SK_COPY_THRESHOLD 50
147 /* number of adapters that can be configured via command line params */
148 #define SK_MAX_CARD_PARAM 16
153 * use those defines for a compile-in version of the driver instead
154 * of command line parameters
156 // #define LINK_SPEED_A {"Auto", }
157 // #define LINK_SPEED_B {"Auto", }
158 // #define AUTO_NEG_A {"Sense", }
159 // #define AUTO_NEG_B {"Sense", }
160 // #define DUP_CAP_A {"Both", }
161 // #define DUP_CAP_B {"Both", }
162 // #define FLOW_CTRL_A {"SymOrRem", }
163 // #define FLOW_CTRL_B {"SymOrRem", }
164 // #define ROLE_A {"Auto", }
165 // #define ROLE_B {"Auto", }
166 // #define PREF_PORT {"A", }
167 // #define CON_TYPE {"Auto", }
168 // #define RLMT_MODE {"CheckLinkState", }
170 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
171 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
172 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
176 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
177 SK_DUP_LED_NORMAL | \
181 /* Isr return value */
182 #define SkIsrRetVar irqreturn_t
183 #define SkIsrRetNone IRQ_NONE
184 #define SkIsrRetHandled IRQ_HANDLED
187 /*******************************************************************************
189 * Local Function Prototypes
191 ******************************************************************************/
193 static void FreeResources(struct SK_NET_DEVICE *dev);
194 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
195 static SK_BOOL BoardAllocMem(SK_AC *pAC);
196 static void BoardFreeMem(SK_AC *pAC);
197 static void BoardInitMem(SK_AC *pAC);
198 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
199 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
200 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
201 static int SkGeOpen(struct SK_NET_DEVICE *dev);
202 static int SkGeClose(struct SK_NET_DEVICE *dev);
203 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
204 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
205 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
206 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
207 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
208 static void GetConfiguration(SK_AC*);
209 static void ProductStr(SK_AC*);
210 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
211 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
212 static void FillRxRing(SK_AC*, RX_PORT*);
213 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
214 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
215 static void ClearAndStartRx(SK_AC*, int);
216 static void ClearTxIrq(SK_AC*, int, int);
217 static void ClearRxRing(SK_AC*, RX_PORT*);
218 static void ClearTxRing(SK_AC*, TX_PORT*);
219 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
220 static void PortReInitBmu(SK_AC*, int);
221 static int SkGeIocMib(DEV_NET*, unsigned int, int);
222 static int SkGeInitPCI(SK_AC *pAC);
223 static void StartDrvCleanupTimer(SK_AC *pAC);
224 static void StopDrvCleanupTimer(SK_AC *pAC);
225 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
227 #ifdef SK_DIAG_SUPPORT
228 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
229 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
230 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
233 /*******************************************************************************
235 * Extern Function Prototypes
237 ******************************************************************************/
238 static const char SKRootName[] = "sk98lin";
239 static struct proc_dir_entry *pSkRootDir;
240 extern struct file_operations sk_proc_fops;
242 static inline void SkGeProcCreate(struct net_device *dev)
244 struct proc_dir_entry *pe;
247 (pe = create_proc_entry(dev->name, S_IRUGO, pSkRootDir))) {
248 pe->proc_fops = &sk_proc_fops;
250 pe->owner = THIS_MODULE;
254 static inline void SkGeProcRemove(struct net_device *dev)
257 remove_proc_entry(dev->name, pSkRootDir);
260 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
261 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
262 extern void SkDimStartModerationTimer(SK_AC *pAC);
263 extern void SkDimModerate(SK_AC *pAC);
264 extern void SkGeBlinkTimer(unsigned long data);
267 static void DumpMsg(struct sk_buff*, char*);
268 static void DumpData(char*, int);
269 static void DumpLong(char*, int);
272 /* global variables *********************************************************/
273 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
274 extern struct ethtool_ops SkGeEthtoolOps;
276 /* local variables **********************************************************/
277 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
278 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
280 /*****************************************************************************
282 * SkGeInitPCI - Init the PCI resources
285 * This function initialize the PCI resources and IO
290 int SkGeInitPCI(SK_AC *pAC)
292 struct SK_NET_DEVICE *dev = pAC->dev[0];
293 struct pci_dev *pdev = pAC->PciDev;
296 if (pci_enable_device(pdev) != 0) {
300 dev->mem_start = pci_resource_start (pdev, 0);
301 pci_set_master(pdev);
303 if (pci_request_regions(pdev, pAC->Name) != 0) {
310 * On big endian machines, we use the adapter's aibility of
311 * reading the descriptors as big endian.
315 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
316 our2 |= PCI_REV_DESC;
317 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
322 * Remap the regs into kernel space.
324 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
334 pci_release_regions(pdev);
336 pci_disable_device(pdev);
341 /*****************************************************************************
343 * FreeResources - release resources allocated for adapter
346 * This function releases the IRQ, unmaps the IO and
347 * frees the desriptor ring.
352 static void FreeResources(struct SK_NET_DEVICE *dev)
358 pNet = netdev_priv(dev);
360 AllocFlag = pAC->AllocFlag;
362 pci_release_regions(pAC->PciDev);
364 if (AllocFlag & SK_ALLOC_IRQ) {
365 free_irq(dev->irq, dev);
368 iounmap(pAC->IoBase);
370 if (pAC->pDescrMem) {
374 } /* FreeResources */
376 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
377 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
378 MODULE_LICENSE("GPL");
381 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
383 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
387 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
389 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
393 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
395 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
399 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
401 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
405 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
407 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
411 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
413 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
417 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
419 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
423 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
425 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
429 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
431 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
435 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
437 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
441 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
443 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
447 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
449 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
453 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
455 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
458 static int IntsPerSec[SK_MAX_CARD_PARAM];
459 static char *Moderation[SK_MAX_CARD_PARAM];
460 static char *ModerationMask[SK_MAX_CARD_PARAM];
461 static char *AutoSizing[SK_MAX_CARD_PARAM];
462 static char *Stats[SK_MAX_CARD_PARAM];
464 module_param_array(Speed_A, charp, NULL, 0);
465 module_param_array(Speed_B, charp, NULL, 0);
466 module_param_array(AutoNeg_A, charp, NULL, 0);
467 module_param_array(AutoNeg_B, charp, NULL, 0);
468 module_param_array(DupCap_A, charp, NULL, 0);
469 module_param_array(DupCap_B, charp, NULL, 0);
470 module_param_array(FlowCtrl_A, charp, NULL, 0);
471 module_param_array(FlowCtrl_B, charp, NULL, 0);
472 module_param_array(Role_A, charp, NULL, 0);
473 module_param_array(Role_B, charp, NULL, 0);
474 module_param_array(ConType, charp, NULL, 0);
475 module_param_array(PrefPort, charp, NULL, 0);
476 module_param_array(RlmtMode, charp, NULL, 0);
477 /* used for interrupt moderation */
478 module_param_array(IntsPerSec, int, NULL, 0);
479 module_param_array(Moderation, charp, NULL, 0);
480 module_param_array(Stats, charp, NULL, 0);
481 module_param_array(ModerationMask, charp, NULL, 0);
482 module_param_array(AutoSizing, charp, NULL, 0);
484 /*****************************************************************************
486 * SkGeBoardInit - do level 0 and 1 initialization
489 * This function prepares the board hardware for running. The desriptor
490 * ring is set up, the IRQ is allocated and the configuration settings
494 * 0, if everything is ok
497 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
501 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
502 char *VerStr = VER_STRING;
503 int Ret; /* return code of request_irq */
506 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
507 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
508 for (i=0; i<SK_MAX_MACS; i++) {
509 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
510 pAC->TxPort[i][0].PortIndex = i;
511 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
512 pAC->RxPort[i].PortIndex = i;
515 /* Initialize the mutexes */
516 for (i=0; i<SK_MAX_MACS; i++) {
517 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
518 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
520 spin_lock_init(&pAC->SlowPathLock);
522 /* setup phy_id blink timer */
523 pAC->BlinkTimer.function = SkGeBlinkTimer;
524 pAC->BlinkTimer.data = (unsigned long) dev;
525 init_timer(&pAC->BlinkTimer);
527 /* level 0 init common modules here */
529 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
530 /* Does a RESET on board ...*/
531 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
532 printk("HWInit (0) failed.\n");
533 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
536 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
537 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
538 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
539 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
540 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
541 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
543 pAC->BoardLevel = SK_INIT_DATA;
544 pAC->RxBufSize = ETH_BUF_SIZE;
546 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
547 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
549 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
551 /* level 1 init common modules here (HW init) */
552 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
553 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
554 printk("sk98lin: HWInit (1) failed.\n");
555 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
558 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
559 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
560 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
561 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
562 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
563 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
565 /* Set chipset type support */
566 pAC->ChipsetType = 0;
567 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
568 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
569 pAC->ChipsetType = 1;
572 GetConfiguration(pAC);
573 if (pAC->RlmtNets == 2) {
574 pAC->GIni.GIPortUsage = SK_MUL_LINK;
577 pAC->BoardLevel = SK_INIT_IO;
578 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
580 if (pAC->GIni.GIMacsFound == 2) {
581 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
582 } else if (pAC->GIni.GIMacsFound == 1) {
583 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
586 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
587 pAC->GIni.GIMacsFound);
592 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
596 pAC->AllocFlag |= SK_ALLOC_IRQ;
598 /* Alloc memory for this board (Mem for RxD/TxD) : */
599 if(!BoardAllocMem(pAC)) {
600 printk("No memory for descriptor rings.\n");
604 SkCsSetReceiveFlags(pAC,
605 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
606 &pAC->CsOfs1, &pAC->CsOfs2, 0);
607 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
610 /* tschilling: New common function with minimum size check. */
612 if (pAC->RlmtNets == 2) {
616 if (SkGeInitAssignRamToQueues(
621 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
626 } /* SkGeBoardInit */
629 /*****************************************************************************
631 * BoardAllocMem - allocate the memory for the descriptor rings
634 * This function allocates the memory for all descriptor rings.
635 * Each ring is aligned for the desriptor alignment and no ring
636 * has a 4 GByte boundary in it (because the upper 32 bit must
637 * be constant for all descriptiors in one rings).
640 * SK_TRUE, if all memory could be allocated
643 static SK_BOOL BoardAllocMem(
646 caddr_t pDescrMem; /* pointer to descriptor memory area */
647 size_t AllocLength; /* length of complete descriptor area */
648 int i; /* loop counter */
649 unsigned long BusAddr;
652 /* rings plus one for alignment (do not cross 4 GB boundary) */
653 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
654 #if (BITS_PER_LONG == 32)
655 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
657 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
661 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
664 if (pDescrMem == NULL) {
667 pAC->pDescrMem = pDescrMem;
668 BusAddr = (unsigned long) pAC->pDescrMemDMA;
670 /* Descriptors need 8 byte alignment, and this is ensured
671 * by pci_alloc_consistent.
673 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
674 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
675 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
676 i, (unsigned long) pDescrMem,
678 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
679 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
680 pDescrMem += TX_RING_SIZE;
681 BusAddr += TX_RING_SIZE;
683 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
684 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
685 i, (unsigned long) pDescrMem,
686 (unsigned long)BusAddr));
687 pAC->RxPort[i].pRxDescrRing = pDescrMem;
688 pAC->RxPort[i].VRxDescrRing = BusAddr;
689 pDescrMem += RX_RING_SIZE;
690 BusAddr += RX_RING_SIZE;
694 } /* BoardAllocMem */
697 /****************************************************************************
699 * BoardFreeMem - reverse of BoardAllocMem
702 * Free all memory allocated in BoardAllocMem: adapter context,
703 * descriptor rings, locks.
707 static void BoardFreeMem(
710 size_t AllocLength; /* length of complete descriptor area */
712 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
714 #if (BITS_PER_LONG == 32)
715 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
717 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
721 pci_free_consistent(pAC->PciDev, AllocLength,
722 pAC->pDescrMem, pAC->pDescrMemDMA);
723 pAC->pDescrMem = NULL;
727 /*****************************************************************************
729 * BoardInitMem - initiate the descriptor rings
732 * This function sets the descriptor rings up in memory.
733 * The adapter is initialized with the descriptor start addresses.
737 static void BoardInitMem(
738 SK_AC *pAC) /* pointer to adapter context */
740 int i; /* loop counter */
741 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
742 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
744 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
747 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
748 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
749 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
750 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
752 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
755 pAC->TxPort[i][0].pTxDescrRing,
756 pAC->TxPort[i][0].VTxDescrRing,
757 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
758 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
759 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
760 &pAC->TxPort[i][0].TxdRingFree,
764 pAC->RxPort[i].pRxDescrRing,
765 pAC->RxPort[i].VRxDescrRing,
766 &pAC->RxPort[i].pRxdRingHead,
767 &pAC->RxPort[i].pRxdRingTail,
768 &pAC->RxPort[i].pRxdRingPrev,
769 &pAC->RxPort[i].RxdRingFree,
775 /*****************************************************************************
777 * SetupRing - create one descriptor ring
780 * This function creates one descriptor ring in the given memory area.
781 * The head, tail and number of free descriptors in the ring are set.
786 static void SetupRing(
788 void *pMemArea, /* a pointer to the memory area for the ring */
789 uintptr_t VMemArea, /* the virtual bus address of the memory area */
790 RXD **ppRingHead, /* address where the head should be written */
791 RXD **ppRingTail, /* address where the tail should be written */
792 RXD **ppRingPrev, /* address where the tail should be written */
793 int *pRingFree, /* address where the # of free descr. goes */
794 SK_BOOL IsTx) /* flag: is this a tx ring */
796 int i; /* loop counter */
797 int DescrSize; /* the size of a descriptor rounded up to alignment*/
798 int DescrNum; /* number of descriptors per ring */
799 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
800 RXD *pNextDescr; /* pointer to the next descriptor */
801 RXD *pPrevDescr; /* pointer to the previous descriptor */
802 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
804 if (IsTx == SK_TRUE) {
805 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
807 DescrNum = TX_RING_SIZE / DescrSize;
809 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
811 DescrNum = RX_RING_SIZE / DescrSize;
814 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
815 ("Descriptor size: %d Descriptor Number: %d\n",
816 DescrSize,DescrNum));
818 pDescr = (RXD*) pMemArea;
820 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
821 VNextDescr = VMemArea + DescrSize;
822 for(i=0; i<DescrNum; i++) {
823 /* set the pointers right */
824 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
825 pDescr->pNextRxd = pNextDescr;
826 pDescr->TcpSumStarts = pAC->CsOfs;
828 /* advance one step */
831 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
832 VNextDescr += DescrSize;
834 pPrevDescr->pNextRxd = (RXD*) pMemArea;
835 pPrevDescr->VNextRxd = VMemArea;
836 pDescr = (RXD*) pMemArea;
837 *ppRingHead = (RXD*) pMemArea;
838 *ppRingTail = *ppRingHead;
839 *ppRingPrev = pPrevDescr;
840 *pRingFree = DescrNum;
844 /*****************************************************************************
846 * PortReInitBmu - re-initiate the descriptor rings for one port
849 * This function reinitializes the descriptor rings of one port
850 * in memory. The port must be stopped before.
851 * The HW is initialized with the descriptor start addresses.
856 static void PortReInitBmu(
857 SK_AC *pAC, /* pointer to adapter context */
858 int PortIndex) /* index of the port for which to re-init */
860 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
863 /* set address of first descriptor of ring in BMU */
864 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
865 (uint32_t)(((caddr_t)
866 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
867 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
868 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
870 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
871 (uint32_t)(((caddr_t)
872 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
873 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
874 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
875 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
876 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
877 pAC->RxPort[PortIndex].pRxDescrRing +
878 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
879 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
880 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
881 pAC->RxPort[PortIndex].pRxDescrRing +
882 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
883 } /* PortReInitBmu */
886 /****************************************************************************
888 * SkGeIsr - handle adapter interrupts
891 * The interrupt routine is called when the network adapter
892 * generates an interrupt. It may also be called if another device
893 * shares this interrupt vector with the driver.
898 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
900 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
903 SK_U32 IntSrc; /* interrupts source register contents */
905 pNet = netdev_priv(dev);
909 * Check and process if its our interrupt
911 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
916 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
917 #if 0 /* software irq currently not used */
918 if (IntSrc & IS_IRQ_SW) {
919 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
920 SK_DBGCAT_DRV_INT_SRC,
924 if (IntSrc & IS_R1_F) {
925 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
926 SK_DBGCAT_DRV_INT_SRC,
928 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
929 SK_PNMI_CNT_RX_INTR(pAC, 0);
931 if (IntSrc & IS_R2_F) {
932 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
933 SK_DBGCAT_DRV_INT_SRC,
935 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
936 SK_PNMI_CNT_RX_INTR(pAC, 1);
938 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
939 if (IntSrc & IS_XA1_F) {
940 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
941 SK_DBGCAT_DRV_INT_SRC,
942 ("EOF AS TX1 IRQ\n"));
943 SK_PNMI_CNT_TX_INTR(pAC, 0);
944 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
945 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
946 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
948 if (IntSrc & IS_XA2_F) {
949 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
950 SK_DBGCAT_DRV_INT_SRC,
951 ("EOF AS TX2 IRQ\n"));
952 SK_PNMI_CNT_TX_INTR(pAC, 1);
953 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
954 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
955 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
957 #if 0 /* only if sync. queues used */
958 if (IntSrc & IS_XS1_F) {
959 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
960 SK_DBGCAT_DRV_INT_SRC,
961 ("EOF SY TX1 IRQ\n"));
962 SK_PNMI_CNT_TX_INTR(pAC, 1);
963 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
964 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
965 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
966 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
968 if (IntSrc & IS_XS2_F) {
969 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
970 SK_DBGCAT_DRV_INT_SRC,
971 ("EOF SY TX2 IRQ\n"));
972 SK_PNMI_CNT_TX_INTR(pAC, 1);
973 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
974 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
975 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
976 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
981 /* do all IO at once */
982 if (IntSrc & IS_R1_F)
983 ClearAndStartRx(pAC, 0);
984 if (IntSrc & IS_R2_F)
985 ClearAndStartRx(pAC, 1);
986 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
987 if (IntSrc & IS_XA1_F)
988 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
989 if (IntSrc & IS_XA2_F)
990 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
992 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
993 } /* while (IntSrc & IRQ_MASK != 0) */
995 IntSrc &= pAC->GIni.GIValIrqMask;
996 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
997 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
998 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
999 pAC->CheckQueue = SK_FALSE;
1000 spin_lock(&pAC->SlowPathLock);
1001 if (IntSrc & SPECIAL_IRQS)
1002 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1004 SkEventDispatcher(pAC, pAC->IoBase);
1005 spin_unlock(&pAC->SlowPathLock);
1008 * do it all again is case we cleared an interrupt that
1009 * came in after handling the ring (OUTs may be delayed
1010 * in hardware buffers, but are through after IN)
1012 * rroesler: has been commented out and shifted to
1013 * SkGeDrvEvent(), because it is timer
1016 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1017 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1020 if (pAC->CheckQueue) {
1021 pAC->CheckQueue = SK_FALSE;
1022 spin_lock(&pAC->SlowPathLock);
1023 SkEventDispatcher(pAC, pAC->IoBase);
1024 spin_unlock(&pAC->SlowPathLock);
1027 /* IRQ is processed - Enable IRQs again*/
1028 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1030 return SkIsrRetHandled;
1034 /****************************************************************************
1036 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1039 * The interrupt routine is called when the network adapter
1040 * generates an interrupt. It may also be called if another device
1041 * shares this interrupt vector with the driver.
1042 * This is the same as above, but handles only one port.
1047 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1049 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1052 SK_U32 IntSrc; /* interrupts source register contents */
1054 pNet = netdev_priv(dev);
1058 * Check and process if its our interrupt
1060 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1062 return SkIsrRetNone;
1065 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1066 #if 0 /* software irq currently not used */
1067 if (IntSrc & IS_IRQ_SW) {
1068 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1069 SK_DBGCAT_DRV_INT_SRC,
1070 ("Software IRQ\n"));
1073 if (IntSrc & IS_R1_F) {
1074 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1075 SK_DBGCAT_DRV_INT_SRC,
1077 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1078 SK_PNMI_CNT_RX_INTR(pAC, 0);
1080 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1081 if (IntSrc & IS_XA1_F) {
1082 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1083 SK_DBGCAT_DRV_INT_SRC,
1084 ("EOF AS TX1 IRQ\n"));
1085 SK_PNMI_CNT_TX_INTR(pAC, 0);
1086 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1087 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1088 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1090 #if 0 /* only if sync. queues used */
1091 if (IntSrc & IS_XS1_F) {
1092 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1093 SK_DBGCAT_DRV_INT_SRC,
1094 ("EOF SY TX1 IRQ\n"));
1095 SK_PNMI_CNT_TX_INTR(pAC, 0);
1096 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1097 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1098 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1099 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1104 /* do all IO at once */
1105 if (IntSrc & IS_R1_F)
1106 ClearAndStartRx(pAC, 0);
1107 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1108 if (IntSrc & IS_XA1_F)
1109 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1111 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1112 } /* while (IntSrc & IRQ_MASK != 0) */
1114 IntSrc &= pAC->GIni.GIValIrqMask;
1115 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1116 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1117 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1118 pAC->CheckQueue = SK_FALSE;
1119 spin_lock(&pAC->SlowPathLock);
1120 if (IntSrc & SPECIAL_IRQS)
1121 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1123 SkEventDispatcher(pAC, pAC->IoBase);
1124 spin_unlock(&pAC->SlowPathLock);
1127 * do it all again is case we cleared an interrupt that
1128 * came in after handling the ring (OUTs may be delayed
1129 * in hardware buffers, but are through after IN)
1131 * rroesler: has been commented out and shifted to
1132 * SkGeDrvEvent(), because it is timer
1135 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1138 /* IRQ is processed - Enable IRQs again*/
1139 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1141 return SkIsrRetHandled;
1142 } /* SkGeIsrOnePort */
1144 #ifdef CONFIG_NET_POLL_CONTROLLER
1145 /****************************************************************************
1147 * SkGePollController - polling receive, for netconsole
1150 * Polling receive - used by netconsole and other diagnostic tools
1151 * to allow network i/o with interrupts disabled.
1155 static void SkGePollController(struct net_device *dev)
1157 disable_irq(dev->irq);
1158 SkGeIsr(dev->irq, dev, NULL);
1159 enable_irq(dev->irq);
1163 /****************************************************************************
1165 * SkGeOpen - handle start of initialized adapter
1168 * This function starts the initialized adapter.
1169 * The board level variable is set and the adapter is
1170 * brought to full functionality.
1171 * The device flags are set for operation.
1172 * Do all necessary level 2 initialization, enable interrupts and
1173 * give start command to RLMT.
1179 static int SkGeOpen(
1180 struct SK_NET_DEVICE *dev)
1184 unsigned long Flags; /* for spin lock */
1186 SK_EVPARA EvPara; /* an event parameter union */
1188 pNet = netdev_priv(dev);
1191 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1192 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1194 #ifdef SK_DIAG_SUPPORT
1195 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1196 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1197 return (-1); /* still in use by diag; deny actions */
1202 /* Set blink mode */
1203 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1204 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1206 if (pAC->BoardLevel == SK_INIT_DATA) {
1207 /* level 1 init common modules here */
1208 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1209 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1212 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1213 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1214 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1215 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1216 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1217 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1218 pAC->BoardLevel = SK_INIT_IO;
1221 if (pAC->BoardLevel != SK_INIT_RUN) {
1222 /* tschilling: Level 2 init modules here, check return value. */
1223 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1224 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1227 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1228 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1229 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1230 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1231 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1232 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1233 pAC->BoardLevel = SK_INIT_RUN;
1236 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1237 /* Enable transmit descriptor polling. */
1238 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1239 FillRxRing(pAC, &pAC->RxPort[i]);
1241 SkGeYellowLED(pAC, pAC->IoBase, 1);
1243 StartDrvCleanupTimer(pAC);
1244 SkDimEnableModerationIfNeeded(pAC);
1245 SkDimDisplayModerationSettings(pAC);
1247 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1249 /* enable Interrupts */
1250 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1251 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1253 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1255 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1256 EvPara.Para32[0] = pAC->RlmtNets;
1257 EvPara.Para32[1] = -1;
1258 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1260 EvPara.Para32[0] = pAC->RlmtMode;
1261 EvPara.Para32[1] = 0;
1262 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1266 EvPara.Para32[0] = pNet->NetNr;
1267 EvPara.Para32[1] = -1;
1268 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1269 SkEventDispatcher(pAC, pAC->IoBase);
1270 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1276 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1277 ("SkGeOpen suceeded\n"));
1283 /****************************************************************************
1285 * SkGeClose - Stop initialized adapter
1288 * Close initialized adapter.
1292 * error code - on error
1294 static int SkGeClose(
1295 struct SK_NET_DEVICE *dev)
1301 unsigned long Flags; /* for spin lock */
1306 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1307 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1309 pNet = netdev_priv(dev);
1312 #ifdef SK_DIAG_SUPPORT
1313 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1314 if (pAC->DiagFlowCtrl == SK_FALSE) {
1316 ** notify that the interface which has been closed
1317 ** by operator interaction must not be started up
1318 ** again when the DIAG has finished.
1320 newPtrNet = netdev_priv(pAC->dev[0]);
1321 if (newPtrNet == pNet) {
1322 pAC->WasIfUp[0] = SK_FALSE;
1324 pAC->WasIfUp[1] = SK_FALSE;
1326 return 0; /* return to system everything is fine... */
1328 pAC->DiagFlowCtrl = SK_FALSE;
1333 netif_stop_queue(dev);
1335 if (pAC->RlmtNets == 1)
1336 PortIdx = pAC->ActivePort;
1338 PortIdx = pNet->NetNr;
1340 StopDrvCleanupTimer(pAC);
1343 * Clear multicast table, promiscuous mode ....
1345 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1346 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1349 if (pAC->MaxPorts == 1) {
1350 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1351 /* disable interrupts */
1352 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1353 EvPara.Para32[0] = pNet->NetNr;
1354 EvPara.Para32[1] = -1;
1355 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1356 SkEventDispatcher(pAC, pAC->IoBase);
1357 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1358 /* stop the hardware */
1359 SkGeDeInit(pAC, pAC->IoBase);
1360 pAC->BoardLevel = SK_INIT_DATA;
1361 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1364 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1365 EvPara.Para32[0] = pNet->NetNr;
1366 EvPara.Para32[1] = -1;
1367 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1368 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1369 SkEventDispatcher(pAC, pAC->IoBase);
1370 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1373 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1374 [TX_PRIO_LOW].TxDesRingLock, Flags);
1375 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1376 SK_STOP_ALL, SK_HARD_RST);
1377 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1378 [TX_PRIO_LOW].TxDesRingLock, Flags);
1381 if (pAC->RlmtNets == 1) {
1382 /* clear all descriptor rings */
1383 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1384 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1385 ClearRxRing(pAC, &pAC->RxPort[i]);
1386 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1389 /* clear port descriptor rings */
1390 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1391 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1392 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1395 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1396 ("SkGeClose: done "));
1398 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1399 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1400 sizeof(SK_PNMI_STRUCT_DATA));
1409 /*****************************************************************************
1411 * SkGeXmit - Linux frame transmit function
1414 * The system calls this function to send frames onto the wire.
1415 * It puts the frame in the tx descriptor ring. If the ring is
1416 * full then, the 'tbusy' flag is set.
1419 * 0, if everything is ok
1421 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1422 * allocated skb's) !!!
1424 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1428 int Rc; /* return code of XmitFrame */
1430 pNet = netdev_priv(dev);
1433 if ((!skb_shinfo(skb)->nr_frags) ||
1434 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1435 /* Don't activate scatter-gather and hardware checksum */
1437 if (pAC->RlmtNets == 2)
1440 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1445 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1448 /* scatter-gather and hardware TCP checksumming anabled*/
1449 if (pAC->RlmtNets == 2)
1452 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1457 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1461 /* Transmitter out of resources? */
1463 netif_stop_queue(dev);
1466 /* If not taken, give buffer ownership back to the
1472 dev->trans_start = jiffies;
1477 /*****************************************************************************
1479 * XmitFrame - fill one socket buffer into the transmit ring
1482 * This function puts a message into the transmit descriptor ring
1483 * if there is a descriptors left.
1484 * Linux skb's consist of only one continuous buffer.
1485 * The first step locks the ring. It is held locked
1486 * all time to avoid problems with SWITCH_../PORT_RESET.
1487 * Then the descriptoris allocated.
1488 * The second part is linking the buffer to the descriptor.
1489 * At the very last, the Control field of the descriptor
1490 * is made valid for the BMU and a start TX command is given
1494 * > 0 - on succes: the number of bytes in the message
1495 * = 0 - on resource shortage: this frame sent or dropped, now
1496 * the ring is full ( -> set tbusy)
1497 * < 0 - on failure: other problems ( -> return failure to upper layers)
1499 static int XmitFrame(
1500 SK_AC *pAC, /* pointer to adapter context */
1501 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1502 struct sk_buff *pMessage) /* pointer to send-message */
1504 TXD *pTxd; /* the rxd to fill */
1506 unsigned long Flags;
1510 int BytesSend = pMessage->len;
1512 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1514 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1515 #ifndef USE_TX_COMPLETE
1516 FreeTxDescriptors(pAC, pTxPort);
1518 if (pTxPort->TxdRingFree == 0) {
1520 ** no enough free descriptors in ring at the moment.
1521 ** Maybe free'ing some old one help?
1523 FreeTxDescriptors(pAC, pTxPort);
1524 if (pTxPort->TxdRingFree == 0) {
1525 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1526 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1527 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1528 SK_DBGCAT_DRV_TX_PROGRESS,
1529 ("XmitFrame failed\n"));
1531 ** the desired message can not be sent
1532 ** Because tbusy seems to be set, the message
1533 ** should not be freed here. It will be used
1534 ** by the scheduler of the ethernet handler
1541 ** If the passed socket buffer is of smaller MTU-size than 60,
1542 ** copy everything into new buffer and fill all bytes between
1543 ** the original packet end and the new packet end of 60 with 0x00.
1544 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1546 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1547 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1548 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1551 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1555 ** advance head counter behind descriptor needed for this frame,
1556 ** so that needed descriptor is reserved from that on. The next
1557 ** action will be to add the passed buffer to the TX-descriptor
1559 pTxd = pTxPort->pTxdRingHead;
1560 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1561 pTxPort->TxdRingFree--;
1564 DumpMsg(pMessage, "XmitFrame");
1568 ** First step is to map the data to be sent via the adapter onto
1569 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1570 ** and 2.6 need to use pci_map_page() for that mapping.
1572 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1573 virt_to_page(pMessage->data),
1574 ((unsigned long) pMessage->data & ~PAGE_MASK),
1577 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1578 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1579 pTxd->pMBuf = pMessage;
1581 if (pMessage->ip_summed == CHECKSUM_HW) {
1582 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1583 if ((Protocol == C_PROTO_ID_UDP) &&
1584 (pAC->GIni.GIChipRev == 0) &&
1585 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1586 pTxd->TBControl = BMU_TCP_CHECK;
1588 pTxd->TBControl = BMU_UDP_CHECK;
1591 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1592 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1593 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1594 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1595 (Protocol == C_PROTO_ID_UDP ?
1596 C_OFFSET_UDPHEADER_UDPCS :
1597 C_OFFSET_TCPHEADER_TCPCS);
1598 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1600 pTxd->TBControl |= BMU_OWN | BMU_STF |
1602 #ifdef USE_TX_COMPLETE
1607 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1609 #ifdef USE_TX_COMPLETE
1616 ** If previous descriptor already done, give TX start cmd
1618 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1619 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1620 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1624 ** after releasing the lock, the skb may immediately be free'd
1626 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1627 if (pTxPort->TxdRingFree != 0) {
1635 /*****************************************************************************
1637 * XmitFrameSG - fill one socket buffer into the transmit ring
1638 * (use SG and TCP/UDP hardware checksumming)
1641 * This function puts a message into the transmit descriptor ring
1642 * if there is a descriptors left.
1645 * > 0 - on succes: the number of bytes in the message
1646 * = 0 - on resource shortage: this frame sent or dropped, now
1647 * the ring is full ( -> set tbusy)
1648 * < 0 - on failure: other problems ( -> return failure to upper layers)
1650 static int XmitFrameSG(
1651 SK_AC *pAC, /* pointer to adapter context */
1652 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1653 struct sk_buff *pMessage) /* pointer to send-message */
1663 skb_frag_t *sk_frag;
1665 unsigned long Flags;
1667 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1668 #ifndef USE_TX_COMPLETE
1669 FreeTxDescriptors(pAC, pTxPort);
1671 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1672 FreeTxDescriptors(pAC, pTxPort);
1673 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1674 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1675 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1676 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1677 SK_DBGCAT_DRV_TX_PROGRESS,
1678 ("XmitFrameSG failed - Ring full\n"));
1679 /* this message can not be sent now */
1684 pTxd = pTxPort->pTxdRingHead;
1691 ** Map the first fragment (header) into the DMA-space
1693 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1694 virt_to_page(pMessage->data),
1695 ((unsigned long) pMessage->data & ~PAGE_MASK),
1696 skb_headlen(pMessage),
1699 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1700 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1703 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1705 if (pMessage->ip_summed == CHECKSUM_HW) {
1706 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
1708 ** We have to use the opcode for tcp here, because the
1709 ** opcode for udp is not working in the hardware yet
1712 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1713 if ((Protocol == C_PROTO_ID_UDP) &&
1714 (pAC->GIni.GIChipRev == 0) &&
1715 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1716 pTxd->TBControl |= BMU_TCP_CHECK;
1718 pTxd->TBControl |= BMU_UDP_CHECK;
1721 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
1722 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
1723 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1724 (Protocol == C_PROTO_ID_UDP ?
1725 C_OFFSET_UDPHEADER_UDPCS :
1726 C_OFFSET_TCPHEADER_TCPCS);
1727 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1729 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
1730 skb_headlen(pMessage);
1733 pTxd = pTxd->pNextTxd;
1734 pTxPort->TxdRingFree--;
1735 BytesSend += skb_headlen(pMessage);
1738 ** Browse over all SG fragments and map each of them into the DMA space
1740 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1741 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1743 ** we already have the proper value in entry
1745 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1747 sk_frag->page_offset,
1751 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1752 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1753 pTxd->pMBuf = pMessage;
1756 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1758 if (pMessage->ip_summed == CHECKSUM_HW) {
1759 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
1761 ** We have to use the opcode for tcp here because the
1762 ** opcode for udp is not working in the hardware yet
1765 if ((Protocol == C_PROTO_ID_UDP) &&
1766 (pAC->GIni.GIChipRev == 0) &&
1767 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1768 pTxd->TBControl |= BMU_TCP_CHECK;
1770 pTxd->TBControl |= BMU_UDP_CHECK;
1773 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
1777 ** Do we have the last fragment?
1779 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1780 #ifdef USE_TX_COMPLETE
1781 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
1783 pTxd->TBControl |= BMU_EOF | sk_frag->size;
1785 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1788 pTxd->TBControl |= sk_frag->size;
1791 pTxd = pTxd->pNextTxd;
1792 pTxPort->TxdRingFree--;
1793 BytesSend += sk_frag->size;
1797 ** If previous descriptor already done, give TX start cmd
1799 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1800 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1803 pTxPort->pTxdRingPrev = pTxdLst;
1804 pTxPort->pTxdRingHead = pTxd;
1806 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1808 if (pTxPort->TxdRingFree > 0) {
1815 /*****************************************************************************
1817 * FreeTxDescriptors - release descriptors from the descriptor ring
1820 * This function releases descriptors from a transmit ring if they
1821 * have been sent by the BMU.
1822 * If a descriptors is sent, it can be freed and the message can
1824 * The SOFTWARE controllable bit is used to prevent running around a
1825 * completely free ring for ever. If this bit is no set in the
1826 * frame (by XmitFrame), this frame has never been sent or is
1828 * The Tx descriptor ring lock must be held while calling this function !!!
1833 static void FreeTxDescriptors(
1834 SK_AC *pAC, /* pointer to the adapter context */
1835 TX_PORT *pTxPort) /* pointer to destination port structure */
1837 TXD *pTxd; /* pointer to the checked descriptor */
1838 TXD *pNewTail; /* pointer to 'end' of the ring */
1839 SK_U32 Control; /* TBControl field of descriptor */
1840 SK_U64 PhysAddr; /* address of DMA mapping */
1842 pNewTail = pTxPort->pTxdRingTail;
1845 ** loop forever; exits if BMU_SW bit not set in start frame
1846 ** or BMU_OWN bit set in any frame
1849 Control = pTxd->TBControl;
1850 if ((Control & BMU_SW) == 0) {
1852 ** software controllable bit is set in first
1853 ** fragment when given to BMU. Not set means that
1854 ** this fragment was never sent or is already
1855 ** freed ( -> ring completely free now).
1857 pTxPort->pTxdRingTail = pTxd;
1858 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1861 if (Control & BMU_OWN) {
1862 pTxPort->pTxdRingTail = pTxd;
1863 if (pTxPort->TxdRingFree > 0) {
1864 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1870 ** release the DMA mapping, because until not unmapped
1871 ** this buffer is considered being under control of the
1874 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1875 PhysAddr |= (SK_U64) pTxd->VDataLow;
1876 pci_unmap_page(pAC->PciDev, PhysAddr,
1880 if (Control & BMU_EOF)
1881 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1883 pTxPort->TxdRingFree++;
1884 pTxd->TBControl &= ~BMU_SW;
1885 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1886 } /* while(forever) */
1887 } /* FreeTxDescriptors */
1889 /*****************************************************************************
1891 * FillRxRing - fill the receive ring with valid descriptors
1894 * This function fills the receive ring descriptors with data
1895 * segments and makes them valid for the BMU.
1896 * The active ring is filled completely, if possible.
1897 * The non-active ring is filled only partial to save memory.
1899 * Description of rx ring structure:
1900 * head - points to the descriptor which will be used next by the BMU
1901 * tail - points to the next descriptor to give to the BMU
1905 static void FillRxRing(
1906 SK_AC *pAC, /* pointer to the adapter context */
1907 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1910 unsigned long Flags;
1912 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1913 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1914 if(!FillRxDescriptor(pAC, pRxPort))
1917 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1921 /*****************************************************************************
1923 * FillRxDescriptor - fill one buffer into the receive ring
1926 * The function allocates a new receive buffer and
1927 * puts it into the next descriptor.
1930 * SK_TRUE - a buffer was added to the ring
1931 * SK_FALSE - a buffer could not be added
1933 static SK_BOOL FillRxDescriptor(
1934 SK_AC *pAC, /* pointer to the adapter context struct */
1935 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1937 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1938 RXD *pRxd; /* the rxd to fill */
1939 SK_U16 Length; /* data fragment length */
1940 SK_U64 PhysAddr; /* physical address of a rx buffer */
1942 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1943 if (pMsgBlock == NULL) {
1944 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1945 SK_DBGCAT_DRV_ENTRY,
1946 ("%s: Allocation of rx buffer failed !\n",
1947 pAC->dev[pRxPort->PortIndex]->name));
1948 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1951 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1952 /* skb allocated ok, so add buffer */
1953 pRxd = pRxPort->pRxdRingTail;
1954 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1955 pRxPort->RxdRingFree--;
1956 Length = pAC->RxBufSize;
1957 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1958 virt_to_page(pMsgBlock->data),
1959 ((unsigned long) pMsgBlock->data &
1962 PCI_DMA_FROMDEVICE);
1964 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1965 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1966 pRxd->pMBuf = pMsgBlock;
1967 pRxd->RBControl = BMU_OWN |
1974 } /* FillRxDescriptor */
1977 /*****************************************************************************
1979 * ReQueueRxBuffer - fill one buffer back into the receive ring
1982 * Fill a given buffer back into the rx ring. The buffer
1983 * has been previously allocated and aligned, and its phys.
1984 * address calculated, so this is no more necessary.
1988 static void ReQueueRxBuffer(
1989 SK_AC *pAC, /* pointer to the adapter context struct */
1990 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1991 struct sk_buff *pMsg, /* pointer to the buffer */
1992 SK_U32 PhysHigh, /* phys address high dword */
1993 SK_U32 PhysLow) /* phys address low dword */
1995 RXD *pRxd; /* the rxd to fill */
1996 SK_U16 Length; /* data fragment length */
1998 pRxd = pRxPort->pRxdRingTail;
1999 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2000 pRxPort->RxdRingFree--;
2001 Length = pAC->RxBufSize;
2003 pRxd->VDataLow = PhysLow;
2004 pRxd->VDataHigh = PhysHigh;
2006 pRxd->RBControl = BMU_OWN |
2012 } /* ReQueueRxBuffer */
2014 /*****************************************************************************
2016 * ReceiveIrq - handle a receive IRQ
2019 * This function is called when a receive IRQ is set.
2020 * It walks the receive descriptor ring and sends up all
2021 * frames that are complete.
2025 static void ReceiveIrq(
2026 SK_AC *pAC, /* pointer to adapter context */
2027 RX_PORT *pRxPort, /* pointer to receive port struct */
2028 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2030 RXD *pRxd; /* pointer to receive descriptors */
2031 SK_U32 Control; /* control field of descriptor */
2032 struct sk_buff *pMsg; /* pointer to message holding frame */
2033 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2034 int FrameLength; /* total length of received frame */
2036 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2037 SK_EVPARA EvPara; /* an event parameter union */
2038 unsigned long Flags; /* for spin lock */
2039 int PortIndex = pRxPort->PortIndex;
2040 unsigned int Offset;
2041 unsigned int NumBytes;
2042 unsigned int ForRlmt;
2045 SK_BOOL IsBadFrame; /* Bad frame */
2048 unsigned short Csum1;
2049 unsigned short Csum2;
2050 unsigned short Type;
2055 /* do forever; exit if BMU_OWN found */
2056 for ( pRxd = pRxPort->pRxdRingHead ;
2057 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2058 pRxd = pRxd->pNextRxd,
2059 pRxPort->pRxdRingHead = pRxd,
2060 pRxPort->RxdRingFree ++) {
2063 * For a better understanding of this loop
2064 * Go through every descriptor beginning at the head
2065 * Please note: the ring might be completely received so the OWN bit
2066 * set is not a good crirteria to leave that loop.
2067 * Therefore the RingFree counter is used.
2068 * On entry of this loop pRxd is a pointer to the Rxd that needs
2069 * to be checked next.
2072 Control = pRxd->RBControl;
2074 /* check if this descriptor is ready */
2075 if ((Control & BMU_OWN) != 0) {
2076 /* this descriptor is not yet ready */
2077 /* This is the usual end of the loop */
2078 /* We don't need to start the ring again */
2079 FillRxRing(pAC, pRxPort);
2082 pAC->DynIrqModInfo.NbrProcessedDescr++;
2084 /* get length of frame and check it */
2085 FrameLength = Control & BMU_BBC;
2086 if (FrameLength > pAC->RxBufSize) {
2090 /* check for STF and EOF */
2091 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2095 /* here we have a complete frame in the ring */
2098 FrameStat = pRxd->FrameStat;
2100 /* check for frame length mismatch */
2101 #define XMR_FS_LEN_SHIFT 18
2102 #define GMR_FS_LEN_SHIFT 16
2103 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2104 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2105 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2106 SK_DBGCAT_DRV_RX_PROGRESS,
2107 ("skge: Frame length mismatch (%u/%u).\n",
2109 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2114 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2115 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2116 SK_DBGCAT_DRV_RX_PROGRESS,
2117 ("skge: Frame length mismatch (%u/%u).\n",
2119 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2125 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2126 IsBc = (FrameStat & XMR_FS_BC) != 0;
2127 IsMc = (FrameStat & XMR_FS_MC) != 0;
2128 IsBadFrame = (FrameStat &
2129 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2131 IsBc = (FrameStat & GMR_FS_BC) != 0;
2132 IsMc = (FrameStat & GMR_FS_MC) != 0;
2133 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2134 ((FrameStat & GMR_FS_RX_OK) == 0));
2137 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2138 ("Received frame of length %d on port %d\n",
2139 FrameLength, PortIndex));
2140 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2141 ("Number of free rx descriptors: %d\n",
2142 pRxPort->RxdRingFree));
2143 /* DumpMsg(pMsg, "Rx"); */
2145 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2147 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2149 /* there is a receive error in this frame */
2150 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2151 SK_DBGCAT_DRV_RX_PROGRESS,
2152 ("skge: Error in received frame, dropped!\n"
2153 "Control: %x\nRxStat: %x\n",
2154 Control, FrameStat));
2156 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2157 pRxd->VDataHigh, pRxd->VDataLow);
2163 * if short frame then copy data to reduce memory waste
2165 if ((FrameLength < SK_COPY_THRESHOLD) &&
2166 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2168 * Short frame detected and allocation successfull
2170 /* use new skb and copy data */
2171 skb_reserve(pNewMsg, 2);
2172 skb_put(pNewMsg, FrameLength);
2173 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2174 PhysAddr |= (SK_U64) pRxd->VDataLow;
2176 pci_dma_sync_single_for_cpu(pAC->PciDev,
2177 (dma_addr_t) PhysAddr,
2179 PCI_DMA_FROMDEVICE);
2180 eth_copy_and_sum(pNewMsg, pMsg->data,
2182 pci_dma_sync_single_for_device(pAC->PciDev,
2183 (dma_addr_t) PhysAddr,
2185 PCI_DMA_FROMDEVICE);
2186 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2187 pRxd->VDataHigh, pRxd->VDataLow);
2194 * if large frame, or SKB allocation failed, pass
2195 * the SKB directly to the networking
2198 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2199 PhysAddr |= (SK_U64) pRxd->VDataLow;
2201 /* release the DMA mapping */
2202 pci_unmap_single(pAC->PciDev,
2205 PCI_DMA_FROMDEVICE);
2207 /* set length in message */
2208 skb_put(pMsg, FrameLength);
2209 /* hardware checksum */
2210 Type = ntohs(*((short*)&pMsg->data[12]));
2212 #ifdef USE_SK_RX_CHECKSUM
2213 if (Type == 0x800) {
2214 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2215 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2216 IpFrameLength = (int) ntohs((unsigned short)
2217 ((unsigned short *) pMsg->data)[8]);
2220 * Test: If frame is padded, a check is not possible!
2221 * Frame not padded? Length difference must be 14 (0xe)!
2223 if ((FrameLength - IpFrameLength) != 0xe) {
2224 /* Frame padded => TCP offload not possible! */
2225 pMsg->ip_summed = CHECKSUM_NONE;
2227 /* Frame not padded => TCP offload! */
2228 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2229 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2230 (pAC->ChipsetType)) {
2231 Result = SkCsGetReceiveInfo(pAC,
2233 Csum1, Csum2, pRxPort->PortIndex);
2235 SKCS_STATUS_IP_FRAGMENT ||
2237 SKCS_STATUS_IP_CSUM_OK ||
2239 SKCS_STATUS_TCP_CSUM_OK ||
2241 SKCS_STATUS_UDP_CSUM_OK) {
2243 CHECKSUM_UNNECESSARY;
2246 SKCS_STATUS_TCP_CSUM_ERROR ||
2248 SKCS_STATUS_UDP_CSUM_ERROR ||
2250 SKCS_STATUS_IP_CSUM_ERROR_UDP ||
2252 SKCS_STATUS_IP_CSUM_ERROR_TCP ||
2254 SKCS_STATUS_IP_CSUM_ERROR ) {
2255 /* HW Checksum error */
2256 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2257 SK_DBGCAT_DRV_RX_PROGRESS,
2258 ("skge: CRC error. Frame dropped!\n"));
2264 }/* checksumControl calculation valid */
2265 } /* Frame length check */
2268 pMsg->ip_summed = CHECKSUM_NONE;
2270 } /* frame > SK_COPY_TRESHOLD */
2272 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2273 ForRlmt = SK_RLMT_RX_PROTOCOL;
2275 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2277 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2278 IsBc, &Offset, &NumBytes);
2279 if (NumBytes != 0) {
2281 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2283 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2284 &pMsg->data[Offset],
2285 IsBc, IsMc, &ForRlmt);
2287 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2288 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2289 /* send up only frames from active port */
2290 if ((PortIndex == pAC->ActivePort) ||
2291 (pAC->RlmtNets == 2)) {
2292 /* frame for upper layer */
2293 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2295 DumpMsg(pMsg, "Rx");
2297 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2298 FrameLength, pRxPort->PortIndex);
2300 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2301 pMsg->protocol = eth_type_trans(pMsg,
2302 pAC->dev[pRxPort->PortIndex]);
2304 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2308 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2309 SK_DBGCAT_DRV_RX_PROGRESS,
2311 DEV_KFREE_SKB(pMsg);
2314 } /* if not for rlmt */
2316 /* packet for rlmt */
2317 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2318 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2319 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2320 pAC->IoBase, FrameLength);
2321 if (pRlmtMbuf != NULL) {
2322 pRlmtMbuf->pNext = NULL;
2323 pRlmtMbuf->Length = FrameLength;
2324 pRlmtMbuf->PortIdx = PortIndex;
2325 EvPara.pParaPtr = pRlmtMbuf;
2326 memcpy((char*)(pRlmtMbuf->pData),
2327 (char*)(pMsg->data),
2330 /* SlowPathLock needed? */
2331 if (SlowPathLock == SK_TRUE) {
2332 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2333 SkEventQueue(pAC, SKGE_RLMT,
2334 SK_RLMT_PACKET_RECEIVED,
2336 pAC->CheckQueue = SK_TRUE;
2337 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2339 SkEventQueue(pAC, SKGE_RLMT,
2340 SK_RLMT_PACKET_RECEIVED,
2342 pAC->CheckQueue = SK_TRUE;
2345 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2346 SK_DBGCAT_DRV_RX_PROGRESS,
2349 if ((pAC->dev[pRxPort->PortIndex]->flags &
2350 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2351 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2352 SK_RLMT_RX_PROTOCOL) {
2353 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2354 pMsg->protocol = eth_type_trans(pMsg,
2355 pAC->dev[pRxPort->PortIndex]);
2357 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2360 DEV_KFREE_SKB(pMsg);
2363 } /* if packet for rlmt */
2364 } /* for ... scanning the RXD ring */
2366 /* RXD ring is empty -> fill and restart */
2367 FillRxRing(pAC, pRxPort);
2368 /* do not start if called from Close */
2369 if (pAC->BoardLevel > SK_INIT_DATA) {
2370 ClearAndStartRx(pAC, PortIndex);
2375 /* remove error frame */
2376 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2377 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2379 /* release the DMA mapping */
2381 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2382 PhysAddr |= (SK_U64) pRxd->VDataLow;
2383 pci_unmap_page(pAC->PciDev,
2386 PCI_DMA_FROMDEVICE);
2387 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2389 pRxPort->RxdRingFree++;
2390 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2396 /*****************************************************************************
2398 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2401 * This function sends a start command and a clear interrupt
2402 * command for one receive queue to the BMU.
2407 static void ClearAndStartRx(
2408 SK_AC *pAC, /* pointer to the adapter context */
2409 int PortIndex) /* index of the receive port (XMAC) */
2411 SK_OUT8(pAC->IoBase,
2412 RxQueueAddr[PortIndex]+Q_CSR,
2413 CSR_START | CSR_IRQ_CL_F);
2414 } /* ClearAndStartRx */
2417 /*****************************************************************************
2419 * ClearTxIrq - give a clear transmit IRQ command to BMU
2422 * This function sends a clear tx IRQ command for one
2423 * transmit queue to the BMU.
2427 static void ClearTxIrq(
2428 SK_AC *pAC, /* pointer to the adapter context */
2429 int PortIndex, /* index of the transmit port (XMAC) */
2430 int Prio) /* priority or normal queue */
2432 SK_OUT8(pAC->IoBase,
2433 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2438 /*****************************************************************************
2440 * ClearRxRing - remove all buffers from the receive ring
2443 * This function removes all receive buffers from the ring.
2444 * The receive BMU must be stopped before calling this function.
2448 static void ClearRxRing(
2449 SK_AC *pAC, /* pointer to adapter context */
2450 RX_PORT *pRxPort) /* pointer to rx port struct */
2452 RXD *pRxd; /* pointer to the current descriptor */
2453 unsigned long Flags;
2456 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2459 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2460 pRxd = pRxPort->pRxdRingHead;
2462 if (pRxd->pMBuf != NULL) {
2464 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2465 PhysAddr |= (SK_U64) pRxd->VDataLow;
2466 pci_unmap_page(pAC->PciDev,
2469 PCI_DMA_FROMDEVICE);
2470 DEV_KFREE_SKB(pRxd->pMBuf);
2473 pRxd->RBControl &= BMU_OWN;
2474 pRxd = pRxd->pNextRxd;
2475 pRxPort->RxdRingFree++;
2476 } while (pRxd != pRxPort->pRxdRingTail);
2477 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2478 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2481 /*****************************************************************************
2483 * ClearTxRing - remove all buffers from the transmit ring
2486 * This function removes all transmit buffers from the ring.
2487 * The transmit BMU must be stopped before calling this function
2488 * and transmitting at the upper level must be disabled.
2489 * The BMU own bit of all descriptors is cleared, the rest is
2490 * done by calling FreeTxDescriptors.
2494 static void ClearTxRing(
2495 SK_AC *pAC, /* pointer to adapter context */
2496 TX_PORT *pTxPort) /* pointer to tx prt struct */
2498 TXD *pTxd; /* pointer to the current descriptor */
2500 unsigned long Flags;
2502 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2503 pTxd = pTxPort->pTxdRingHead;
2504 for (i=0; i<pAC->TxDescrPerRing; i++) {
2505 pTxd->TBControl &= ~BMU_OWN;
2506 pTxd = pTxd->pNextTxd;
2508 FreeTxDescriptors(pAC, pTxPort);
2509 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2512 /*****************************************************************************
2514 * SkGeSetMacAddr - Set the hardware MAC address
2517 * This function sets the MAC address used by the adapter.
2520 * 0, if everything is ok
2523 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2526 DEV_NET *pNet = netdev_priv(dev);
2527 SK_AC *pAC = pNet->pAC;
2529 struct sockaddr *addr = p;
2530 unsigned long Flags;
2532 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2533 ("SkGeSetMacAddr starts now...\n"));
2534 if(netif_running(dev))
2537 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2539 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2541 if (pAC->RlmtNets == 2)
2542 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2543 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2545 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2546 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2550 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2552 } /* SkGeSetMacAddr */
2555 /*****************************************************************************
2557 * SkGeSetRxMode - set receive mode
2560 * This function sets the receive mode of an adapter. The adapter
2561 * supports promiscuous mode, allmulticast mode and a number of
2562 * multicast addresses. If more multicast addresses the available
2563 * are selected, a hash function in the hardware is used.
2566 * 0, if everything is ok
2569 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2575 struct dev_mc_list *pMcList;
2578 unsigned long Flags;
2580 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2581 ("SkGeSetRxMode starts now... "));
2583 pNet = netdev_priv(dev);
2585 if (pAC->RlmtNets == 1)
2586 PortIdx = pAC->ActivePort;
2588 PortIdx = pNet->NetNr;
2590 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2591 if (dev->flags & IFF_PROMISC) {
2592 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2593 ("PROMISCUOUS mode\n"));
2594 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2596 } else if (dev->flags & IFF_ALLMULTI) {
2597 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2598 ("ALLMULTI mode\n"));
2599 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2600 SK_PROM_MODE_ALL_MC);
2602 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2604 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2606 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2607 ("Number of MC entries: %d ", dev->mc_count));
2609 pMcList = dev->mc_list;
2610 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2611 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2612 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2613 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2614 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2615 pMcList->dmi_addr[0],
2616 pMcList->dmi_addr[1],
2617 pMcList->dmi_addr[2],
2618 pMcList->dmi_addr[3],
2619 pMcList->dmi_addr[4],
2620 pMcList->dmi_addr[5]));
2622 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2624 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2627 } /* SkGeSetRxMode */
2630 /*****************************************************************************
2632 * SkGeChangeMtu - set the MTU to another value
2635 * This function sets is called whenever the MTU size is changed
2636 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2637 * ethernet MTU size, long frame support is activated.
2640 * 0, if everything is ok
2643 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2648 unsigned long Flags;
2652 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2653 ("SkGeChangeMtu starts now...\n"));
2655 pNet = netdev_priv(dev);
2658 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2662 if(pAC->BoardLevel != SK_INIT_RUN) {
2666 #ifdef SK_DIAG_SUPPORT
2667 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2668 if (pAC->DiagFlowCtrl == SK_FALSE) {
2669 return -1; /* still in use, deny any actions of MTU */
2671 pAC->DiagFlowCtrl = SK_FALSE;
2677 pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2678 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2682 pAC->RxBufSize = NewMtu + 32;
2685 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2686 ("New MTU: %d\n", NewMtu));
2689 ** Prevent any reconfiguration while changing the MTU
2690 ** by disabling any interrupts
2692 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2693 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2696 ** Notify RLMT that any ports are to be stopped
2698 EvPara.Para32[0] = 0;
2699 EvPara.Para32[1] = -1;
2700 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2701 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2702 EvPara.Para32[0] = 1;
2703 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2705 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2709 ** After calling the SkEventDispatcher(), RLMT is aware about
2710 ** the stopped ports -> configuration can take place!
2712 SkEventDispatcher(pAC, pAC->IoBase);
2714 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2715 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2716 netif_stop_queue(pAC->dev[i]);
2721 ** Depending on the desired MTU size change, a different number of
2722 ** RX buffers need to be allocated
2724 if (NewMtu > 1500) {
2726 ** Use less rx buffers
2728 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2729 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2730 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2731 (pAC->RxDescrPerRing / 4);
2733 if (i == pAC->ActivePort) {
2734 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2735 (pAC->RxDescrPerRing / 4);
2737 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2738 (pAC->RxDescrPerRing / 10);
2744 ** Use the normal amount of rx buffers
2746 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2747 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2748 pAC->RxPort[i].RxFillLimit = 1;
2750 if (i == pAC->ActivePort) {
2751 pAC->RxPort[i].RxFillLimit = 1;
2753 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2754 (pAC->RxDescrPerRing / 4);
2760 SkGeDeInit(pAC, pAC->IoBase);
2763 ** enable/disable hardware support for long frames
2765 if (NewMtu > 1500) {
2766 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2767 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2769 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2770 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2772 pAC->GIni.GIPortUsage = SK_RED_LINK;
2776 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2777 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2778 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2779 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2780 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2781 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2782 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2786 ** Speed and others are set back to default in level 1 init!
2788 GetConfiguration(pAC);
2790 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2791 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2792 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2793 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2794 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2795 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2796 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2799 ** clear and reinit the rx rings here
2801 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2802 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2803 ClearRxRing(pAC, &pAC->RxPort[i]);
2804 FillRxRing(pAC, &pAC->RxPort[i]);
2807 ** Enable transmit descriptor polling
2809 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2810 FillRxRing(pAC, &pAC->RxPort[i]);
2813 SkGeYellowLED(pAC, pAC->IoBase, 1);
2814 SkDimEnableModerationIfNeeded(pAC);
2815 SkDimDisplayModerationSettings(pAC);
2817 netif_start_queue(pAC->dev[pNet->PortNr]);
2818 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2819 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2823 ** Enable Interrupts again
2825 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2826 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2828 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2829 SkEventDispatcher(pAC, pAC->IoBase);
2832 ** Notify RLMT about the changing and restarting one (or more) ports
2834 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2835 EvPara.Para32[0] = pAC->RlmtNets;
2836 EvPara.Para32[1] = -1;
2837 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2838 EvPara.Para32[0] = pNet->PortNr;
2839 EvPara.Para32[1] = -1;
2840 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2842 if (pOtherNet->Up) {
2843 EvPara.Para32[0] = pOtherNet->PortNr;
2844 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2847 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2850 SkEventDispatcher(pAC, pAC->IoBase);
2851 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2854 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2855 ** seems as if upper layers have a problem to handle a successful
2856 ** return value of '0'. If such a zero is returned, the complete
2857 ** system hangs for several minutes (!), which is in acceptable.
2859 ** Currently it is not clear, what the exact reason for this problem
2860 ** is. The implemented workaround for 2.5 is to return the desired
2861 ** new MTU size if all needed changes for the new MTU size where
2862 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2863 ** which indicates the successful change of the mtu-size.
2867 } /* SkGeChangeMtu */
2870 /*****************************************************************************
2872 * SkGeStats - return ethernet device statistics
2875 * This function return statistic data about the ethernet device
2876 * to the operating system.
2879 * pointer to the statistic structure.
2881 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2883 DEV_NET *pNet = netdev_priv(dev);
2884 SK_AC *pAC = pNet->pAC;
2885 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2886 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2887 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2888 unsigned int Size; /* size of pnmi struct */
2889 unsigned long Flags; /* for spin lock */
2891 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2892 ("SkGeStats starts now...\n"));
2893 pPnmiStruct = &pAC->PnmiStruct;
2895 #ifdef SK_DIAG_SUPPORT
2896 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2897 (pAC->BoardLevel == SK_INIT_RUN)) {
2899 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2900 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2901 Size = SK_PNMI_STRUCT_SIZE;
2902 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2903 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2904 #ifdef SK_DIAG_SUPPORT
2908 pPnmiStat = &pPnmiStruct->Stat[0];
2909 pPnmiConf = &pPnmiStruct->Conf[0];
2911 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2912 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2913 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2914 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2916 if (pNet->Mtu <= 1500) {
2917 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2919 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2920 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2924 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2925 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2927 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2928 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2929 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2930 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2931 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2933 /* detailed rx_errors: */
2934 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2935 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2936 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2937 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2938 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2939 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2941 /* detailed tx_errors */
2942 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2943 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2944 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2945 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2946 pAC->stats.tx_window_errors = (SK_U32) 0;
2948 return(&pAC->stats);
2952 /*****************************************************************************
2954 * SkGeIoctl - IO-control function
2957 * This function is called if an ioctl is issued on the device.
2958 * There are three subfunction for reading, writing and test-writing
2959 * the private MIB data structure (usefull for SysKonnect-internal tools).
2962 * 0, if everything is ok
2965 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2970 struct pci_dev *pdev = NULL;
2972 unsigned int Err = 0;
2975 unsigned int Length = 0;
2976 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2978 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2979 ("SkGeIoctl starts now...\n"));
2981 pNet = netdev_priv(dev);
2984 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2989 case SK_IOCTL_SETMIB:
2990 case SK_IOCTL_PRESETMIB:
2991 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2992 case SK_IOCTL_GETMIB:
2993 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2994 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2995 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2998 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2999 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
3000 Ioctl.Len<Size? Ioctl.Len : Size)) {
3004 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3009 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3012 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3014 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3017 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3021 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
3025 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3030 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3035 kfree(pMemBuf); /* cleanup everything */
3037 #ifdef SK_DIAG_SUPPORT
3039 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3040 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3043 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3045 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3048 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3053 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3055 ** While coding this new IOCTL interface, only a few lines of code
3056 ** are to to be added. Therefore no dedicated function has been
3057 ** added. If more functionality is added, a separate function
3058 ** should be used...
3060 * ((SK_U32 *)pMemBuf) = 0;
3061 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3062 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
3063 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3068 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3073 kfree(pMemBuf); /* cleanup everything */
3085 /*****************************************************************************
3087 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3090 * This function reads/writes the MIB data using PNMI (Private Network
3091 * Management Interface).
3092 * The destination for the data must be provided with the
3093 * ioctl call and is given to the driver in the form of
3094 * a user space address.
3095 * Copying from the user-provided data area into kernel messages
3096 * and back is done by copy_from_user and copy_to_user calls in
3100 * returned size from PNMI call
3102 static int SkGeIocMib(
3103 DEV_NET *pNet, /* pointer to the adapter context */
3104 unsigned int Size, /* length of ioctl data */
3105 int mode) /* flag for set/preset */
3107 unsigned long Flags; /* for spin lock */
3110 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3111 ("SkGeIocMib starts now...\n"));
3114 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3116 case SK_IOCTL_GETMIB:
3117 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3120 case SK_IOCTL_PRESETMIB:
3121 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3124 case SK_IOCTL_SETMIB:
3125 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3131 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3132 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3133 ("MIB data access succeeded\n"));
3138 /*****************************************************************************
3140 * GetConfiguration - read configuration information
3143 * This function reads per-adapter configuration information from
3144 * the options provided on the command line.
3149 static void GetConfiguration(
3150 SK_AC *pAC) /* pointer to the adapter context structure */
3152 SK_I32 Port; /* preferred port */
3155 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3156 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3157 int DuplexCap = 0; /* 0=both,1=full,2=half */
3158 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3159 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3161 SK_BOOL IsConTypeDefined = SK_TRUE;
3162 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3163 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3164 SK_BOOL IsRoleDefined = SK_TRUE;
3165 SK_BOOL IsModeDefined = SK_TRUE;
3167 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3168 * parameter. The mapping is described by this table:
3169 * DuplexCap -> | both | full | half |
3171 * -----------------------------------------------------------------
3172 * Off | illegal | Full | Half |
3173 * -----------------------------------------------------------------
3174 * On | AutoBoth | AutoFull | AutoHalf |
3175 * -----------------------------------------------------------------
3176 * Sense | AutoSense | AutoSense | AutoSense |
3178 int Capabilities[3][3] =
3179 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3180 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3181 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3189 #define M_CurrPort pAC->GIni.GP[Port]
3193 ** Set the default values first for both ports!
3195 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3196 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3197 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3198 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3199 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3203 ** Check merged parameter ConType. If it has not been used,
3204 ** verify any other parameter (e.g. AutoNeg) and use default values.
3206 ** Stating both ConType and other lowlevel link parameters is also
3207 ** possible. If this is the case, the passed ConType-parameter is
3208 ** overwritten by the lowlevel link parameter.
3210 ** The following settings are used for a merged ConType-parameter:
3212 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3213 ** ------- ------ ------- -------- ---------- -----
3214 ** Auto Both On SymOrRem Auto Auto
3215 ** 100FD Full Off None <ignored> 100
3216 ** 100HD Half Off None <ignored> 100
3217 ** 10FD Full Off None <ignored> 10
3218 ** 10HD Half Off None <ignored> 10
3220 ** This ConType parameter is used for all ports of the adapter!
3222 if ( (ConType != NULL) &&
3223 (pAC->Index < SK_MAX_CARD_PARAM) &&
3224 (ConType[pAC->Index] != NULL) ) {
3226 /* Check chipset family */
3227 if ((!pAC->ChipsetType) &&
3228 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3229 (strcmp(ConType[pAC->Index],"")!=0)) {
3230 /* Set the speed parameter back */
3231 printk("sk98lin: Illegal value \"%s\" "
3234 ConType[pAC->Index]);
3236 sprintf(ConType[pAC->Index], "Auto");
3239 if (strcmp(ConType[pAC->Index],"")==0) {
3240 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3241 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3242 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3243 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3244 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3245 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3246 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3248 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3249 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3250 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3251 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3252 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3253 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3255 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3256 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3257 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3258 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3259 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3260 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3262 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3263 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3264 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3265 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3266 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3267 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3269 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3270 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3271 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3272 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3273 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3274 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3277 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3278 ConType[pAC->Index]);
3279 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3282 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3286 ** Parse any parameter settings for port A:
3287 ** a) any LinkSpeed stated?
3289 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3290 Speed_A[pAC->Index] != NULL) {
3291 if (strcmp(Speed_A[pAC->Index],"")==0) {
3292 IsLinkSpeedDefined = SK_FALSE;
3293 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3294 LinkSpeed = SK_LSPEED_AUTO;
3295 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3296 LinkSpeed = SK_LSPEED_10MBPS;
3297 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3298 LinkSpeed = SK_LSPEED_100MBPS;
3299 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3300 LinkSpeed = SK_LSPEED_1000MBPS;
3302 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3303 Speed_A[pAC->Index]);
3304 IsLinkSpeedDefined = SK_FALSE;
3307 IsLinkSpeedDefined = SK_FALSE;
3311 ** Check speed parameter:
3312 ** Only copper type adapter and GE V2 cards
3314 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3315 ((LinkSpeed != SK_LSPEED_AUTO) &&
3316 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3317 printk("sk98lin: Illegal value for Speed_A. "
3318 "Not a copper card or GE V2 card\n Using "
3320 LinkSpeed = SK_LSPEED_1000MBPS;
3324 ** Decide whether to set new config value if somethig valid has
3327 if (IsLinkSpeedDefined) {
3328 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3332 ** b) Any Autonegotiation and DuplexCapabilities set?
3333 ** Please note that both belong together...
3335 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3337 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3338 AutoNeg_A[pAC->Index] != NULL) {
3340 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3342 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3344 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3346 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3349 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3350 AutoNeg_A[pAC->Index]);
3354 DuplexCap = DC_BOTH;
3356 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3357 DupCap_A[pAC->Index] != NULL) {
3359 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3361 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3362 DuplexCap = DC_BOTH;
3363 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3364 DuplexCap = DC_FULL;
3365 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3366 DuplexCap = DC_HALF;
3368 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3369 DupCap_A[pAC->Index]);
3374 ** Check for illegal combinations
3376 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3377 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3378 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3379 (pAC->ChipsetType)) {
3380 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3381 " Using Full Duplex.\n");
3382 DuplexCap = DC_FULL;
3385 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3386 printk("sk98lin, Port A: DuplexCapabilities"
3387 " ignored using Sense mode\n");
3390 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3391 printk("sk98lin: Port A: Illegal combination"
3392 " of values AutoNeg. and DuplexCap.\n Using "
3394 DuplexCap = DC_FULL;
3397 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3398 DuplexCap = DC_FULL;
3401 if (!AutoSet && DupSet) {
3402 printk("sk98lin: Port A: Duplex setting not"
3403 " possible in\n default AutoNegotiation mode"
3404 " (Sense).\n Using AutoNegotiation On\n");
3409 ** set the desired mode
3411 if (AutoSet || DupSet) {
3412 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3416 ** c) Any Flowcontrol-parameter set?
3418 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3419 FlowCtrl_A[pAC->Index] != NULL) {
3420 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3421 IsFlowCtrlDefined = SK_FALSE;
3422 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3423 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3424 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3425 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3426 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3427 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3428 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3429 FlowCtrl = SK_FLOW_MODE_NONE;
3431 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3432 FlowCtrl_A[pAC->Index]);
3433 IsFlowCtrlDefined = SK_FALSE;
3436 IsFlowCtrlDefined = SK_FALSE;
3439 if (IsFlowCtrlDefined) {
3440 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3441 printk("sk98lin: Port A: FlowControl"
3442 " impossible without AutoNegotiation,"
3444 FlowCtrl = SK_FLOW_MODE_NONE;
3446 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3450 ** d) What is with the RoleParameter?
3452 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3453 Role_A[pAC->Index] != NULL) {
3454 if (strcmp(Role_A[pAC->Index],"")==0) {
3455 IsRoleDefined = SK_FALSE;
3456 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3457 MSMode = SK_MS_MODE_AUTO;
3458 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3459 MSMode = SK_MS_MODE_MASTER;
3460 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3461 MSMode = SK_MS_MODE_SLAVE;
3463 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3464 Role_A[pAC->Index]);
3465 IsRoleDefined = SK_FALSE;
3468 IsRoleDefined = SK_FALSE;
3471 if (IsRoleDefined == SK_TRUE) {
3472 pAC->GIni.GP[0].PMSMode = MSMode;
3478 ** Parse any parameter settings for port B:
3479 ** a) any LinkSpeed stated?
3481 IsConTypeDefined = SK_TRUE;
3482 IsLinkSpeedDefined = SK_TRUE;
3483 IsFlowCtrlDefined = SK_TRUE;
3484 IsModeDefined = SK_TRUE;
3486 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3487 Speed_B[pAC->Index] != NULL) {
3488 if (strcmp(Speed_B[pAC->Index],"")==0) {
3489 IsLinkSpeedDefined = SK_FALSE;
3490 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3491 LinkSpeed = SK_LSPEED_AUTO;
3492 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3493 LinkSpeed = SK_LSPEED_10MBPS;
3494 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3495 LinkSpeed = SK_LSPEED_100MBPS;
3496 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3497 LinkSpeed = SK_LSPEED_1000MBPS;
3499 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3500 Speed_B[pAC->Index]);
3501 IsLinkSpeedDefined = SK_FALSE;
3504 IsLinkSpeedDefined = SK_FALSE;
3508 ** Check speed parameter:
3509 ** Only copper type adapter and GE V2 cards
3511 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3512 ((LinkSpeed != SK_LSPEED_AUTO) &&
3513 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3514 printk("sk98lin: Illegal value for Speed_B. "
3515 "Not a copper card or GE V2 card\n Using "
3517 LinkSpeed = SK_LSPEED_1000MBPS;
3521 ** Decide whether to set new config value if somethig valid has
3524 if (IsLinkSpeedDefined) {
3525 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3529 ** b) Any Autonegotiation and DuplexCapabilities set?
3530 ** Please note that both belong together...
3532 AutoNeg = AN_SENS; /* default: do auto Sense */
3534 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3535 AutoNeg_B[pAC->Index] != NULL) {
3537 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3539 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3541 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3543 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3546 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3547 AutoNeg_B[pAC->Index]);
3551 DuplexCap = DC_BOTH;
3553 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3554 DupCap_B[pAC->Index] != NULL) {
3556 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3558 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3559 DuplexCap = DC_BOTH;
3560 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3561 DuplexCap = DC_FULL;
3562 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3563 DuplexCap = DC_HALF;
3565 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3566 DupCap_B[pAC->Index]);
3572 ** Check for illegal combinations
3574 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3575 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3576 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3577 (pAC->ChipsetType)) {
3578 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3579 " Using Full Duplex.\n");
3580 DuplexCap = DC_FULL;
3583 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3584 printk("sk98lin, Port B: DuplexCapabilities"
3585 " ignored using Sense mode\n");
3588 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3589 printk("sk98lin: Port B: Illegal combination"
3590 " of values AutoNeg. and DuplexCap.\n Using "
3592 DuplexCap = DC_FULL;
3595 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3596 DuplexCap = DC_FULL;
3599 if (!AutoSet && DupSet) {
3600 printk("sk98lin: Port B: Duplex setting not"
3601 " possible in\n default AutoNegotiation mode"
3602 " (Sense).\n Using AutoNegotiation On\n");
3607 ** set the desired mode
3609 if (AutoSet || DupSet) {
3610 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3614 ** c) Any FlowCtrl parameter set?
3616 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3617 FlowCtrl_B[pAC->Index] != NULL) {
3618 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3619 IsFlowCtrlDefined = SK_FALSE;
3620 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3621 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3622 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3623 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3624 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3625 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3626 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3627 FlowCtrl = SK_FLOW_MODE_NONE;
3629 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3630 FlowCtrl_B[pAC->Index]);
3631 IsFlowCtrlDefined = SK_FALSE;
3634 IsFlowCtrlDefined = SK_FALSE;
3637 if (IsFlowCtrlDefined) {
3638 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3639 printk("sk98lin: Port B: FlowControl"
3640 " impossible without AutoNegotiation,"
3642 FlowCtrl = SK_FLOW_MODE_NONE;
3644 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3648 ** d) What is the RoleParameter?
3650 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3651 Role_B[pAC->Index] != NULL) {
3652 if (strcmp(Role_B[pAC->Index],"")==0) {
3653 IsRoleDefined = SK_FALSE;
3654 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3655 MSMode = SK_MS_MODE_AUTO;
3656 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3657 MSMode = SK_MS_MODE_MASTER;
3658 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3659 MSMode = SK_MS_MODE_SLAVE;
3661 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3662 Role_B[pAC->Index]);
3663 IsRoleDefined = SK_FALSE;
3666 IsRoleDefined = SK_FALSE;
3669 if (IsRoleDefined) {
3670 pAC->GIni.GP[1].PMSMode = MSMode;
3674 ** Evaluate settings for both ports
3676 pAC->ActivePort = 0;
3677 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3678 PrefPort[pAC->Index] != NULL) {
3679 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3680 pAC->ActivePort = 0;
3681 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3682 pAC->Rlmt.Net[0].PrefPort = 0;
3683 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3685 ** do not set ActivePort here, thus a port
3686 ** switch is issued after net up.
3689 pAC->Rlmt.Net[0].Preference = Port;
3690 pAC->Rlmt.Net[0].PrefPort = Port;
3691 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3693 ** do not set ActivePort here, thus a port
3694 ** switch is issued after net up.
3696 if (pAC->GIni.GIMacsFound == 1) {
3697 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3698 " Port B not available on single port adapters.\n");
3700 pAC->ActivePort = 0;
3701 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3702 pAC->Rlmt.Net[0].PrefPort = 0;
3705 pAC->Rlmt.Net[0].Preference = Port;
3706 pAC->Rlmt.Net[0].PrefPort = Port;
3709 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3710 PrefPort[pAC->Index]);
3716 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3717 RlmtMode[pAC->Index] != NULL) {
3718 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3720 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3721 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3722 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3723 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3724 SK_RLMT_CHECK_LOC_LINK;
3725 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3726 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3727 SK_RLMT_CHECK_LOC_LINK |
3729 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3730 (pAC->GIni.GIMacsFound == 2)) {
3731 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3734 printk("sk98lin: Illegal value \"%s\" for"
3735 " RlmtMode, using default\n",
3736 RlmtMode[pAC->Index]);
3744 ** Check the interrupt moderation parameters
3746 if (Moderation[pAC->Index] != NULL) {
3747 if (strcmp(Moderation[pAC->Index], "") == 0) {
3748 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3749 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3750 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3751 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3752 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3753 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3754 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3756 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3757 " Disable interrupt moderation.\n",
3758 Moderation[pAC->Index]);
3759 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3762 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3765 if (Stats[pAC->Index] != NULL) {
3766 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3767 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3769 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3772 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3775 if (ModerationMask[pAC->Index] != NULL) {
3776 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3777 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3778 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3779 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3780 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3781 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3782 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3783 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3784 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3785 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3786 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3787 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3788 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3789 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3790 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3791 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3792 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3793 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3794 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3795 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3796 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3797 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3798 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3799 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3800 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3801 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3802 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3803 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3804 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3805 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3806 } else { /* some rubbish */
3807 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3809 } else { /* operator has stated nothing */
3810 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3813 if (AutoSizing[pAC->Index] != NULL) {
3814 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3815 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3817 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3819 } else { /* operator has stated nothing */
3820 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3823 if (IntsPerSec[pAC->Index] != 0) {
3824 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3825 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3826 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3827 " Using default value of %i.\n",
3828 IntsPerSec[pAC->Index],
3829 C_INT_MOD_IPS_LOWER_RANGE,
3830 C_INT_MOD_IPS_UPPER_RANGE,
3831 C_INTS_PER_SEC_DEFAULT);
3832 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3834 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3837 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3841 ** Evaluate upper and lower moderation threshold
3843 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3844 pAC->DynIrqModInfo.MaxModIntsPerSec +
3845 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3847 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3848 pAC->DynIrqModInfo.MaxModIntsPerSec -
3849 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3851 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3854 } /* GetConfiguration */
3857 /*****************************************************************************
3859 * ProductStr - return a adapter identification string from vpd
3862 * This function reads the product name string from the vpd area
3863 * and puts it the field pAC->DeviceString.
3867 static void ProductStr(
3868 SK_AC *pAC /* pointer to adapter context */
3871 int StrLen = 80; /* length of the string, defined in SK_AC */
3872 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3873 int ReturnCode; /* return code from vpd_read */
3874 unsigned long Flags;
3876 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3877 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3879 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3880 if (ReturnCode != 0) {
3881 /* there was an error reading the vpd data */
3882 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3883 ("Error reading VPD data: %d\n", ReturnCode));
3884 pAC->DeviceStr[0] = '\0';
3888 /*****************************************************************************
3890 * StartDrvCleanupTimer - Start timer to check for descriptors which
3891 * might be placed in descriptor ring, but
3892 * havent been handled up to now
3895 * This function requests a HW-timer fo the Yukon card. The actions to
3896 * perform when this timer expires, are located in the SkDrvEvent().
3901 StartDrvCleanupTimer(SK_AC *pAC) {
3902 SK_EVPARA EventParam; /* Event struct for timer event */
3904 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3905 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3906 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3907 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3908 SKGE_DRV, SK_DRV_TIMER, EventParam);
3911 /*****************************************************************************
3913 * StopDrvCleanupTimer - Stop timer to check for descriptors
3916 * This function requests a HW-timer fo the Yukon card. The actions to
3917 * perform when this timer expires, are located in the SkDrvEvent().
3922 StopDrvCleanupTimer(SK_AC *pAC) {
3923 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3924 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3927 /****************************************************************************/
3928 /* functions for common modules *********************************************/
3929 /****************************************************************************/
3932 /*****************************************************************************
3934 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3937 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3938 * is embedded into a socket buff data area.
3944 * NULL or pointer to Mbuf.
3946 SK_MBUF *SkDrvAllocRlmtMbuf(
3947 SK_AC *pAC, /* pointer to adapter context */
3948 SK_IOC IoC, /* the IO-context */
3949 unsigned BufferSize) /* size of the requested buffer */
3951 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3952 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3954 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3955 if (pMsgBlock == NULL) {
3958 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3959 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3960 pRlmtMbuf->pNext = NULL;
3961 pRlmtMbuf->pOs = pMsgBlock;
3962 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3963 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3964 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3967 } /* SkDrvAllocRlmtMbuf */
3970 /*****************************************************************************
3972 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3975 * This routine frees one or more RLMT mbuf(s).
3983 void SkDrvFreeRlmtMbuf(
3984 SK_AC *pAC, /* pointer to adapter context */
3985 SK_IOC IoC, /* the IO-context */
3986 SK_MBUF *pMbuf) /* size of the requested buffer */
3993 pNextMbuf = pFreeMbuf->pNext;
3994 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3995 pFreeMbuf = pNextMbuf;
3996 } while ( pFreeMbuf != NULL );
3997 } /* SkDrvFreeRlmtMbuf */
4000 /*****************************************************************************
4002 * SkOsGetTime - provide a time value
4005 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
4006 * It is not used for absolute time, but only for time differences.
4012 SK_U64 SkOsGetTime(SK_AC *pAC)
4014 SK_U64 PrivateJiffies;
4015 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
4016 return PrivateJiffies;
4020 /*****************************************************************************
4022 * SkPciReadCfgDWord - read a 32 bit value from pci config space
4025 * This routine reads a 32 bit value from the pci configuration
4029 * 0 - indicate everything worked ok.
4030 * != 0 - error indication
4032 int SkPciReadCfgDWord(
4033 SK_AC *pAC, /* Adapter Control structure pointer */
4034 int PciAddr, /* PCI register address */
4035 SK_U32 *pVal) /* pointer to store the read value */
4037 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4039 } /* SkPciReadCfgDWord */
4042 /*****************************************************************************
4044 * SkPciReadCfgWord - read a 16 bit value from pci config space
4047 * This routine reads a 16 bit value from the pci configuration
4051 * 0 - indicate everything worked ok.
4052 * != 0 - error indication
4054 int SkPciReadCfgWord(
4055 SK_AC *pAC, /* Adapter Control structure pointer */
4056 int PciAddr, /* PCI register address */
4057 SK_U16 *pVal) /* pointer to store the read value */
4059 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4061 } /* SkPciReadCfgWord */
4064 /*****************************************************************************
4066 * SkPciReadCfgByte - read a 8 bit value from pci config space
4069 * This routine reads a 8 bit value from the pci configuration
4073 * 0 - indicate everything worked ok.
4074 * != 0 - error indication
4076 int SkPciReadCfgByte(
4077 SK_AC *pAC, /* Adapter Control structure pointer */
4078 int PciAddr, /* PCI register address */
4079 SK_U8 *pVal) /* pointer to store the read value */
4081 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4083 } /* SkPciReadCfgByte */
4086 /*****************************************************************************
4088 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4091 * This routine writes a 32 bit value to the pci configuration
4095 * 0 - indicate everything worked ok.
4096 * != 0 - error indication
4098 int SkPciWriteCfgDWord(
4099 SK_AC *pAC, /* Adapter Control structure pointer */
4100 int PciAddr, /* PCI register address */
4101 SK_U32 Val) /* pointer to store the read value */
4103 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4105 } /* SkPciWriteCfgDWord */
4108 /*****************************************************************************
4110 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4113 * This routine writes a 16 bit value to the pci configuration
4114 * space. The flag PciConfigUp indicates whether the config space
4115 * is accesible or must be set up first.
4118 * 0 - indicate everything worked ok.
4119 * != 0 - error indication
4121 int SkPciWriteCfgWord(
4122 SK_AC *pAC, /* Adapter Control structure pointer */
4123 int PciAddr, /* PCI register address */
4124 SK_U16 Val) /* pointer to store the read value */
4126 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4128 } /* SkPciWriteCfgWord */
4131 /*****************************************************************************
4133 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4136 * This routine writes a 8 bit value to the pci configuration
4137 * space. The flag PciConfigUp indicates whether the config space
4138 * is accesible or must be set up first.
4141 * 0 - indicate everything worked ok.
4142 * != 0 - error indication
4144 int SkPciWriteCfgByte(
4145 SK_AC *pAC, /* Adapter Control structure pointer */
4146 int PciAddr, /* PCI register address */
4147 SK_U8 Val) /* pointer to store the read value */
4149 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4151 } /* SkPciWriteCfgByte */
4154 /*****************************************************************************
4156 * SkDrvEvent - handle driver events
4159 * This function handles events from all modules directed to the driver
4162 * Is called under protection of slow path lock.
4165 * 0 if everything ok
4170 SK_AC *pAC, /* pointer to adapter context */
4171 SK_IOC IoC, /* io-context */
4172 SK_U32 Event, /* event-id */
4173 SK_EVPARA Param) /* event-parameter */
4175 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4176 struct sk_buff *pMsg; /* pointer to a message block */
4177 int FromPort; /* the port from which we switch away */
4178 int ToPort; /* the port we switch to */
4179 SK_EVPARA NewPara; /* parameter for further events */
4181 unsigned long Flags;
4185 case SK_DRV_ADAP_FAIL:
4186 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4187 ("ADAPTER FAIL EVENT\n"));
4188 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4189 /* disable interrupts */
4190 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4193 case SK_DRV_PORT_FAIL:
4194 FromPort = Param.Para32[0];
4195 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4196 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4197 if (FromPort == 0) {
4198 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4200 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4204 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4206 FromPort = Param.Para32[0];
4207 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4208 ("PORT RESET EVENT, Port: %d ", FromPort));
4209 NewPara.Para64 = FromPort;
4210 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4212 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4215 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4216 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4217 spin_unlock_irqrestore(
4218 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4221 /* clear rx ring from received frames */
4222 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4224 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4226 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4229 /* tschilling: Handling of return value inserted. */
4230 if (SkGeInitPort(pAC, IoC, FromPort)) {
4231 if (FromPort == 0) {
4232 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4234 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4237 SkAddrMcUpdate(pAC,IoC, FromPort);
4238 PortReInitBmu(pAC, FromPort);
4239 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4240 ClearAndStartRx(pAC, FromPort);
4241 spin_unlock_irqrestore(
4242 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4245 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4247 FromPort = Param.Para32[0];
4248 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4249 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4251 SkAddrMcUpdate(pAC,IoC, FromPort);
4253 if (DoPrintInterfaceChange) {
4254 printk("%s: network connection up using"
4255 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4257 /* tschilling: Values changed according to LinkSpeedUsed. */
4258 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4259 if (Stat == SK_LSPEED_STAT_10MBPS) {
4260 printk(" speed: 10\n");
4261 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4262 printk(" speed: 100\n");
4263 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4264 printk(" speed: 1000\n");
4266 printk(" speed: unknown\n");
4270 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4271 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4272 Stat == SK_LMODE_STAT_AUTOFULL) {
4273 printk(" autonegotiation: yes\n");
4276 printk(" autonegotiation: no\n");
4278 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4279 Stat == SK_LMODE_STAT_HALF) {
4280 printk(" duplex mode: half\n");
4283 printk(" duplex mode: full\n");
4285 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4286 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4287 printk(" flowctrl: remote send\n");
4289 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4290 printk(" flowctrl: local send\n");
4292 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4293 printk(" flowctrl: symmetric\n");
4296 printk(" flowctrl: none\n");
4299 /* tschilling: Check against CopperType now. */
4300 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4301 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4302 SK_LSPEED_STAT_1000MBPS)) {
4303 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4304 if (Stat == SK_MS_STAT_MASTER ) {
4305 printk(" role: master\n");
4307 else if (Stat == SK_MS_STAT_SLAVE ) {
4308 printk(" role: slave\n");
4311 printk(" role: ???\n");
4316 Display dim (dynamic interrupt moderation)
4319 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4320 printk(" irq moderation: static (%d ints/sec)\n",
4321 pAC->DynIrqModInfo.MaxModIntsPerSec);
4322 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4323 printk(" irq moderation: dynamic (%d ints/sec)\n",
4324 pAC->DynIrqModInfo.MaxModIntsPerSec);
4326 printk(" irq moderation: disabled\n");
4330 if (pAC->ChipsetType)
4331 #ifdef USE_SK_TX_CHECKSUM
4332 printk(" scatter-gather: enabled\n");
4334 printk(" tx-checksum: disabled\n");
4337 printk(" scatter-gather: disabled\n");
4339 printk(" scatter-gather: disabled\n");
4342 #ifndef USE_SK_RX_CHECKSUM
4343 printk(" rx-checksum: disabled\n");
4347 DoPrintInterfaceChange = SK_TRUE;
4350 if ((Param.Para32[0] != pAC->ActivePort) &&
4351 (pAC->RlmtNets == 1)) {
4352 NewPara.Para32[0] = pAC->ActivePort;
4353 NewPara.Para32[1] = Param.Para32[0];
4354 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4358 /* Inform the world that link protocol is up. */
4359 netif_carrier_on(pAC->dev[Param.Para32[0]]);
4362 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4364 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4365 ("NET DOWN EVENT "));
4366 if (DoPrintInterfaceChange) {
4367 printk("%s: network connection down\n",
4368 pAC->dev[Param.Para32[1]]->name);
4370 DoPrintInterfaceChange = SK_TRUE;
4372 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4374 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4375 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4376 ("PORT SWITCH HARD "));
4377 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4379 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4380 'A'+Param.Para32[1]);
4381 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4382 FromPort = Param.Para32[0];
4383 ToPort = Param.Para32[1];
4384 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4385 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4386 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4387 NewPara.Para64 = FromPort;
4388 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4389 NewPara.Para64 = ToPort;
4390 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4392 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4394 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4395 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4396 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4397 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4398 spin_unlock_irqrestore(
4399 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4402 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4403 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4405 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4406 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4408 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4410 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4411 pAC->ActivePort = ToPort;
4415 /* tschilling: New common function with minimum size check. */
4417 if (pAC->RlmtNets == 2) {
4421 if (SkGeInitAssignRamToQueues(
4425 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4426 spin_unlock_irqrestore(
4427 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4429 printk("SkGeInitAssignRamToQueues failed.\n");
4433 /* tschilling: Handling of return values inserted. */
4434 if (SkGeInitPort(pAC, IoC, FromPort) ||
4435 SkGeInitPort(pAC, IoC, ToPort)) {
4436 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4438 if (Event == SK_DRV_SWITCH_SOFT) {
4439 SkMacRxTxEnable(pAC, IoC, FromPort);
4441 SkMacRxTxEnable(pAC, IoC, ToPort);
4442 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4443 SkAddrMcUpdate(pAC, IoC, FromPort);
4444 SkAddrMcUpdate(pAC, IoC, ToPort);
4445 PortReInitBmu(pAC, FromPort);
4446 PortReInitBmu(pAC, ToPort);
4447 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4448 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4449 ClearAndStartRx(pAC, FromPort);
4450 ClearAndStartRx(pAC, ToPort);
4451 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4452 spin_unlock_irqrestore(
4453 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4456 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4457 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4459 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4460 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4461 skb_put(pMsg, pRlmtMbuf->Length);
4462 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4465 DEV_KFREE_SKB_ANY(pMsg);
4468 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4470 ** expiration of the moderation timer implies that
4471 ** dynamic moderation is to be applied
4473 SkDimStartModerationTimer(pAC);
4475 if (pAC->DynIrqModInfo.DisplayStats) {
4476 SkDimDisplayModerationSettings(pAC);
4478 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4480 ** check if we need to check for descriptors which
4481 ** haven't been handled the last millisecs
4483 StartDrvCleanupTimer(pAC);
4484 if (pAC->GIni.GIMacsFound == 2) {
4485 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4487 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4489 printk("Expiration of unknown timer\n");
4495 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4502 /*****************************************************************************
4504 * SkErrorLog - log errors
4507 * This function logs errors to the system buffer and to the console
4510 * 0 if everything ok
4523 case SK_ERRCL_OTHER:
4524 strcpy(ClassStr, "Other error");
4526 case SK_ERRCL_CONFIG:
4527 strcpy(ClassStr, "Configuration error");
4530 strcpy(ClassStr, "Initialization error");
4532 case SK_ERRCL_NORES:
4533 strcpy(ClassStr, "Out of resources error");
4536 strcpy(ClassStr, "internal Software error");
4539 strcpy(ClassStr, "Hardware failure");
4542 strcpy(ClassStr, "Communication error");
4545 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4546 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4547 ClassStr, ErrNum, pErrorMsg);
4551 #ifdef SK_DIAG_SUPPORT
4553 /*****************************************************************************
4555 * SkDrvEnterDiagMode - handles DIAG attach request
4558 * Notify the kernel to NOT access the card any longer due to DIAG
4559 * Deinitialize the Card
4564 int SkDrvEnterDiagMode(
4565 SK_AC *pAc) /* pointer to adapter context */
4567 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4568 SK_AC *pAC = pNet->pAC;
4570 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4571 sizeof(SK_PNMI_STRUCT_DATA));
4573 pAC->DiagModeActive = DIAG_ACTIVE;
4574 if (pAC->BoardLevel > SK_INIT_DATA) {
4576 pAC->WasIfUp[0] = SK_TRUE;
4577 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4578 DoPrintInterfaceChange = SK_FALSE;
4579 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4581 pAC->WasIfUp[0] = SK_FALSE;
4583 if (pNet != netdev_priv(pAC->dev[1])) {
4584 pNet = netdev_priv(pAC->dev[1]);
4586 pAC->WasIfUp[1] = SK_TRUE;
4587 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4588 DoPrintInterfaceChange = SK_FALSE;
4589 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4591 pAC->WasIfUp[1] = SK_FALSE;
4594 pAC->BoardLevel = SK_INIT_DATA;
4599 /*****************************************************************************
4601 * SkDrvLeaveDiagMode - handles DIAG detach request
4604 * Notify the kernel to may access the card again after use by DIAG
4605 * Initialize the Card
4610 int SkDrvLeaveDiagMode(
4611 SK_AC *pAc) /* pointer to adapter control context */
4613 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4614 sizeof(SK_PNMI_STRUCT_DATA));
4615 pAc->DiagModeActive = DIAG_NOTACTIVE;
4616 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4617 if (pAc->WasIfUp[0] == SK_TRUE) {
4618 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4619 DoPrintInterfaceChange = SK_FALSE;
4620 SkDrvInitAdapter(pAc, 0); /* first device */
4622 if (pAc->WasIfUp[1] == SK_TRUE) {
4623 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4624 DoPrintInterfaceChange = SK_FALSE;
4625 SkDrvInitAdapter(pAc, 1); /* second device */
4630 /*****************************************************************************
4632 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4635 * This function parses the PCI slot name information string and will
4636 * retrieve the devcie number out of it. The slot_name maintianed by
4637 * linux is in the form of '02:0a.0', whereas the first two characters
4638 * represent the bus number in hex (in the sample above this is
4639 * pci bus 0x02) and the next two characters the device number (0x0a).
4642 * SK_U32: The device number from the PCI slot name
4645 static SK_U32 ParseDeviceNbrFromSlotName(
4646 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4648 char *CurrCharPos = (char *) SlotName;
4649 int FirstNibble = -1;
4650 int SecondNibble = -1;
4653 while (*CurrCharPos != '\0') {
4654 if (*CurrCharPos == ':') {
4655 while (*CurrCharPos != '.') {
4657 if ( (*CurrCharPos >= '0') &&
4658 (*CurrCharPos <= '9')) {
4659 if (FirstNibble == -1) {
4660 /* dec. value for '0' */
4661 FirstNibble = *CurrCharPos - 48;
4663 SecondNibble = *CurrCharPos - 48;
4665 } else if ( (*CurrCharPos >= 'a') &&
4666 (*CurrCharPos <= 'f') ) {
4667 if (FirstNibble == -1) {
4668 FirstNibble = *CurrCharPos - 87;
4670 SecondNibble = *CurrCharPos - 87;
4677 Result = FirstNibble;
4678 Result = Result << 4; /* first nibble is higher one */
4679 Result = Result | SecondNibble;
4681 CurrCharPos++; /* next character */
4686 /****************************************************************************
4688 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4689 * called if Diag attaches to that card)
4692 * Close initialized adapter.
4696 * error code - on error
4698 static int SkDrvDeInitAdapter(
4699 SK_AC *pAC, /* pointer to adapter context */
4700 int devNbr) /* what device is to be handled */
4702 struct SK_NET_DEVICE *dev;
4704 dev = pAC->dev[devNbr];
4706 /* On Linux 2.6 the network driver does NOT mess with reference
4707 ** counts. The driver MUST be able to be unloaded at any time
4708 ** due to the possibility of hotplug.
4710 if (SkGeClose(dev) != 0) {
4715 } /* SkDrvDeInitAdapter() */
4717 /****************************************************************************
4719 * SkDrvInitAdapter - Initialize adapter (this function is only
4720 * called if Diag deattaches from that card)
4723 * Close initialized adapter.
4727 * error code - on error
4729 static int SkDrvInitAdapter(
4730 SK_AC *pAC, /* pointer to adapter context */
4731 int devNbr) /* what device is to be handled */
4733 struct SK_NET_DEVICE *dev;
4735 dev = pAC->dev[devNbr];
4737 if (SkGeOpen(dev) != 0) {
4742 ** Use correct MTU size and indicate to kernel TX queue can be started
4744 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4749 } /* SkDrvInitAdapter */
4754 /****************************************************************************/
4755 /* "debug only" section *****************************************************/
4756 /****************************************************************************/
4759 /*****************************************************************************
4761 * DumpMsg - print a frame
4764 * This function prints frames to the system logfile/to the console.
4769 static void DumpMsg(struct sk_buff *skb, char *str)
4774 printk("DumpMsg(): NULL-Message\n");
4778 if (skb->data == NULL) {
4779 printk("DumpMsg(): Message empty\n");
4787 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4789 DumpData((char *)skb->data, msglen);
4791 printk("------- End of message ---------\n");
4796 /*****************************************************************************
4798 * DumpData - print a data area
4801 * This function prints a area of data to the system logfile/to the
4807 static void DumpData(char *p, int size)
4811 char hex_buffer[180];
4812 char asc_buffer[180];
4813 char HEXCHAR[] = "0123456789ABCDEF";
4819 for (i=0; i < size; ) {
4820 if (*p >= '0' && *p <='z')
4821 asc_buffer[addr] = *p;
4823 asc_buffer[addr] = '.';
4825 asc_buffer[addr] = 0;
4826 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4828 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4830 hex_buffer[haddr] = ' ';
4832 hex_buffer[haddr] = 0;
4836 printk("%s %s\n", hex_buffer, asc_buffer);
4844 /*****************************************************************************
4846 * DumpLong - print a data area as long values
4849 * This function prints a area of data to the system logfile/to the
4855 static void DumpLong(char *pc, int size)
4859 char hex_buffer[180];
4860 char asc_buffer[180];
4861 char HEXCHAR[] = "0123456789ABCDEF";
4870 for (i=0; i < size; ) {
4872 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4874 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4876 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4878 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4880 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4882 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4884 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4886 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4888 hex_buffer[haddr] = ' ';
4890 hex_buffer[haddr] = 0;
4894 printk("%4x %s\n", (i-8)*4, hex_buffer);
4898 printk("------------------------\n");
4903 static int __devinit skge_probe_one(struct pci_dev *pdev,
4904 const struct pci_device_id *ent)
4907 DEV_NET *pNet = NULL;
4908 struct net_device *dev = NULL;
4909 static int boards_found = 0;
4910 int error = -ENODEV;
4912 if (pci_enable_device(pdev))
4915 /* Configure DMA attributes. */
4916 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4917 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4918 goto out_disable_device;
4921 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4922 printk(KERN_ERR "Unable to allocate etherdev "
4924 goto out_disable_device;
4927 pNet = netdev_priv(dev);
4928 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4930 printk(KERN_ERR "Unable to allocate adapter "
4932 goto out_free_netdev;
4935 memset(pNet->pAC, 0, sizeof(SK_AC));
4938 pAC->PciDevId = pdev->device;
4941 sprintf(pAC->Name, "SysKonnect SK-98xx");
4942 pAC->CheckQueue = SK_FALSE;
4946 dev->irq = pdev->irq;
4947 error = SkGeInitPCI(pAC);
4949 printk("SKGE: PCI setup failed: %i\n", error);
4950 goto out_free_netdev;
4953 SET_MODULE_OWNER(dev);
4954 dev->open = &SkGeOpen;
4955 dev->stop = &SkGeClose;
4956 dev->hard_start_xmit = &SkGeXmit;
4957 dev->get_stats = &SkGeStats;
4958 dev->set_multicast_list = &SkGeSetRxMode;
4959 dev->set_mac_address = &SkGeSetMacAddr;
4960 dev->do_ioctl = &SkGeIoctl;
4961 dev->change_mtu = &SkGeChangeMtu;
4962 #ifdef CONFIG_NET_POLL_CONTROLLER
4963 dev->poll_controller = &SkGePollController;
4965 SET_NETDEV_DEV(dev, &pdev->dev);
4966 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4969 #ifdef USE_SK_TX_CHECKSUM
4970 if (pAC->ChipsetType) {
4971 /* Use only if yukon hardware */
4972 /* SK and ZEROCOPY - fly baby... */
4973 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4978 pAC->Index = boards_found++;
4980 if (SkGeBoardInit(dev, pAC))
4981 goto out_free_netdev;
4983 /* Register net device */
4984 if (register_netdev(dev)) {
4985 printk(KERN_ERR "SKGE: Could not register device.\n");
4986 goto out_free_resources;
4989 /* Print adapter specific string from vpd */
4991 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4993 /* Print configuration settings */
4994 printk(" PrefPort:%c RlmtMode:%s\n",
4995 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4996 (pAC->RlmtMode==0) ? "Check Link State" :
4997 ((pAC->RlmtMode==1) ? "Check Link State" :
4998 ((pAC->RlmtMode==3) ? "Check Local Port" :
4999 ((pAC->RlmtMode==7) ? "Check Segmentation" :
5000 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
5002 SkGeYellowLED(pAC, pAC->IoBase, 1);
5005 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
5007 SkGeProcCreate(dev);
5014 /* More then one port found */
5015 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
5016 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
5017 printk(KERN_ERR "Unable to allocate etherdev "
5023 pNet = netdev_priv(dev);
5030 dev->open = &SkGeOpen;
5031 dev->stop = &SkGeClose;
5032 dev->hard_start_xmit = &SkGeXmit;
5033 dev->get_stats = &SkGeStats;
5034 dev->set_multicast_list = &SkGeSetRxMode;
5035 dev->set_mac_address = &SkGeSetMacAddr;
5036 dev->do_ioctl = &SkGeIoctl;
5037 dev->change_mtu = &SkGeChangeMtu;
5038 SET_NETDEV_DEV(dev, &pdev->dev);
5039 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
5042 #ifdef USE_SK_TX_CHECKSUM
5043 if (pAC->ChipsetType) {
5044 /* SG and ZEROCOPY - fly baby... */
5045 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
5050 if (register_netdev(dev)) {
5051 printk(KERN_ERR "SKGE: Could not register device.\n");
5053 pAC->dev[1] = pAC->dev[0];
5055 SkGeProcCreate(dev);
5056 memcpy(&dev->dev_addr,
5057 &pAC->Addr.Net[1].CurrentMacAddress, 6);
5059 printk("%s: %s\n", dev->name, pAC->DeviceStr);
5060 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
5064 /* Save the hardware revision */
5065 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
5066 (pAC->GIni.GIPciHwRev & 0x0F);
5068 /* Set driver globals */
5069 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
5070 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
5072 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
5073 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
5075 pci_set_drvdata(pdev, dev);
5083 pci_disable_device(pdev);
5088 static void __devexit skge_remove_one(struct pci_dev *pdev)
5090 struct net_device *dev = pci_get_drvdata(pdev);
5091 DEV_NET *pNet = netdev_priv(dev);
5092 SK_AC *pAC = pNet->pAC;
5093 struct net_device *otherdev = pAC->dev[1];
5095 SkGeProcRemove(dev);
5096 unregister_netdev(dev);
5097 if (otherdev != dev)
5098 SkGeProcRemove(otherdev);
5100 SkGeYellowLED(pAC, pAC->IoBase, 0);
5102 if (pAC->BoardLevel == SK_INIT_RUN) {
5104 unsigned long Flags;
5106 /* board is still alive */
5107 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5108 EvPara.Para32[0] = 0;
5109 EvPara.Para32[1] = -1;
5110 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5111 EvPara.Para32[0] = 1;
5112 EvPara.Para32[1] = -1;
5113 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5114 SkEventDispatcher(pAC, pAC->IoBase);
5115 /* disable interrupts */
5116 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5117 SkGeDeInit(pAC, pAC->IoBase);
5118 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5119 pAC->BoardLevel = SK_INIT_DATA;
5120 /* We do NOT check here, if IRQ was pending, of course*/
5123 if (pAC->BoardLevel == SK_INIT_IO) {
5124 /* board is still alive */
5125 SkGeDeInit(pAC, pAC->IoBase);
5126 pAC->BoardLevel = SK_INIT_DATA;
5131 if (otherdev != dev)
5132 free_netdev(otherdev);
5137 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5139 struct net_device *dev = pci_get_drvdata(pdev);
5140 DEV_NET *pNet = netdev_priv(dev);
5141 SK_AC *pAC = pNet->pAC;
5142 struct net_device *otherdev = pAC->dev[1];
5144 if (netif_running(dev)) {
5145 netif_carrier_off(dev);
5146 DoPrintInterfaceChange = SK_FALSE;
5147 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5148 netif_device_detach(dev);
5150 if (otherdev != dev) {
5151 if (netif_running(otherdev)) {
5152 netif_carrier_off(otherdev);
5153 DoPrintInterfaceChange = SK_FALSE;
5154 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5155 netif_device_detach(otherdev);
5159 pci_save_state(pdev);
5160 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5161 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5162 free_irq(dev->irq, dev);
5164 pci_disable_device(pdev);
5165 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5170 static int skge_resume(struct pci_dev *pdev)
5172 struct net_device *dev = pci_get_drvdata(pdev);
5173 DEV_NET *pNet = netdev_priv(dev);
5174 SK_AC *pAC = pNet->pAC;
5175 struct net_device *otherdev = pAC->dev[1];
5178 pci_set_power_state(pdev, PCI_D0);
5179 pci_restore_state(pdev);
5180 pci_enable_device(pdev);
5181 pci_set_master(pdev);
5182 if (pAC->GIni.GIMacsFound == 2)
5183 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5185 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5187 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5188 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5190 pci_disable_device(pdev);
5194 netif_device_attach(dev);
5195 if (netif_running(dev)) {
5196 DoPrintInterfaceChange = SK_FALSE;
5197 SkDrvInitAdapter(pAC, 0); /* first device */
5199 if (otherdev != dev) {
5200 netif_device_attach(otherdev);
5201 if (netif_running(otherdev)) {
5202 DoPrintInterfaceChange = SK_FALSE;
5203 SkDrvInitAdapter(pAC, 1); /* second device */
5210 #define skge_suspend NULL
5211 #define skge_resume NULL
5214 static struct pci_device_id skge_pci_tbl[] = {
5215 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5216 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5217 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5218 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5219 { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5220 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5221 #if 0 /* don't handle Yukon2 cards at the moment -- mlindner@syskonnect.de */
5222 { PCI_VENDOR_ID_MARVELL, 0x4360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5223 { PCI_VENDOR_ID_MARVELL, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5225 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5226 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5227 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5228 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5232 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5234 static struct pci_driver skge_driver = {
5236 .id_table = skge_pci_tbl,
5237 .probe = skge_probe_one,
5238 .remove = __devexit_p(skge_remove_one),
5239 .suspend = skge_suspend,
5240 .resume = skge_resume,
5243 static int __init skge_init(void)
5247 pSkRootDir = proc_mkdir(SKRootName, proc_net);
5249 pSkRootDir->owner = THIS_MODULE;
5251 error = pci_register_driver(&skge_driver);
5253 proc_net_remove(SKRootName);
5257 static void __exit skge_exit(void)
5259 pci_unregister_driver(&skge_driver);
5260 proc_net_remove(SKRootName);
5264 module_init(skge_init);
5265 module_exit(skge_exit);