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:
106 ******************************************************************************/
108 #include "h/skversion.h"
110 #include <linux/module.h>
111 #include <linux/moduleparam.h>
112 #include <linux/init.h>
113 #include <linux/proc_fs.h>
114 #include <linux/dma-mapping.h>
115 #include <linux/ip.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[] = "net/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");
605 /* tschilling: New common function with minimum size check. */
607 if (pAC->RlmtNets == 2) {
611 if (SkGeInitAssignRamToQueues(
616 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
621 } /* SkGeBoardInit */
624 /*****************************************************************************
626 * BoardAllocMem - allocate the memory for the descriptor rings
629 * This function allocates the memory for all descriptor rings.
630 * Each ring is aligned for the desriptor alignment and no ring
631 * has a 4 GByte boundary in it (because the upper 32 bit must
632 * be constant for all descriptiors in one rings).
635 * SK_TRUE, if all memory could be allocated
638 static SK_BOOL BoardAllocMem(
641 caddr_t pDescrMem; /* pointer to descriptor memory area */
642 size_t AllocLength; /* length of complete descriptor area */
643 int i; /* loop counter */
644 unsigned long BusAddr;
647 /* rings plus one for alignment (do not cross 4 GB boundary) */
648 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
649 #if (BITS_PER_LONG == 32)
650 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
652 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
656 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
659 if (pDescrMem == NULL) {
662 pAC->pDescrMem = pDescrMem;
663 BusAddr = (unsigned long) pAC->pDescrMemDMA;
665 /* Descriptors need 8 byte alignment, and this is ensured
666 * by pci_alloc_consistent.
668 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
669 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
670 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
671 i, (unsigned long) pDescrMem,
673 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
674 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
675 pDescrMem += TX_RING_SIZE;
676 BusAddr += TX_RING_SIZE;
678 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
679 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
680 i, (unsigned long) pDescrMem,
681 (unsigned long)BusAddr));
682 pAC->RxPort[i].pRxDescrRing = pDescrMem;
683 pAC->RxPort[i].VRxDescrRing = BusAddr;
684 pDescrMem += RX_RING_SIZE;
685 BusAddr += RX_RING_SIZE;
689 } /* BoardAllocMem */
692 /****************************************************************************
694 * BoardFreeMem - reverse of BoardAllocMem
697 * Free all memory allocated in BoardAllocMem: adapter context,
698 * descriptor rings, locks.
702 static void BoardFreeMem(
705 size_t AllocLength; /* length of complete descriptor area */
707 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
709 #if (BITS_PER_LONG == 32)
710 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
712 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
716 pci_free_consistent(pAC->PciDev, AllocLength,
717 pAC->pDescrMem, pAC->pDescrMemDMA);
718 pAC->pDescrMem = NULL;
722 /*****************************************************************************
724 * BoardInitMem - initiate the descriptor rings
727 * This function sets the descriptor rings up in memory.
728 * The adapter is initialized with the descriptor start addresses.
732 static void BoardInitMem(
733 SK_AC *pAC) /* pointer to adapter context */
735 int i; /* loop counter */
736 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
737 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
739 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
742 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
743 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
744 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
745 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
747 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
750 pAC->TxPort[i][0].pTxDescrRing,
751 pAC->TxPort[i][0].VTxDescrRing,
752 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
753 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
754 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
755 &pAC->TxPort[i][0].TxdRingFree,
759 pAC->RxPort[i].pRxDescrRing,
760 pAC->RxPort[i].VRxDescrRing,
761 &pAC->RxPort[i].pRxdRingHead,
762 &pAC->RxPort[i].pRxdRingTail,
763 &pAC->RxPort[i].pRxdRingPrev,
764 &pAC->RxPort[i].RxdRingFree,
770 /*****************************************************************************
772 * SetupRing - create one descriptor ring
775 * This function creates one descriptor ring in the given memory area.
776 * The head, tail and number of free descriptors in the ring are set.
781 static void SetupRing(
783 void *pMemArea, /* a pointer to the memory area for the ring */
784 uintptr_t VMemArea, /* the virtual bus address of the memory area */
785 RXD **ppRingHead, /* address where the head should be written */
786 RXD **ppRingTail, /* address where the tail should be written */
787 RXD **ppRingPrev, /* address where the tail should be written */
788 int *pRingFree, /* address where the # of free descr. goes */
789 SK_BOOL IsTx) /* flag: is this a tx ring */
791 int i; /* loop counter */
792 int DescrSize; /* the size of a descriptor rounded up to alignment*/
793 int DescrNum; /* number of descriptors per ring */
794 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
795 RXD *pNextDescr; /* pointer to the next descriptor */
796 RXD *pPrevDescr; /* pointer to the previous descriptor */
797 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
799 if (IsTx == SK_TRUE) {
800 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
802 DescrNum = TX_RING_SIZE / DescrSize;
804 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
806 DescrNum = RX_RING_SIZE / DescrSize;
809 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
810 ("Descriptor size: %d Descriptor Number: %d\n",
811 DescrSize,DescrNum));
813 pDescr = (RXD*) pMemArea;
815 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
816 VNextDescr = VMemArea + DescrSize;
817 for(i=0; i<DescrNum; i++) {
818 /* set the pointers right */
819 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
820 pDescr->pNextRxd = pNextDescr;
821 pDescr->TcpSumStarts = 0;
823 /* advance one step */
826 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
827 VNextDescr += DescrSize;
829 pPrevDescr->pNextRxd = (RXD*) pMemArea;
830 pPrevDescr->VNextRxd = VMemArea;
831 pDescr = (RXD*) pMemArea;
832 *ppRingHead = (RXD*) pMemArea;
833 *ppRingTail = *ppRingHead;
834 *ppRingPrev = pPrevDescr;
835 *pRingFree = DescrNum;
839 /*****************************************************************************
841 * PortReInitBmu - re-initiate the descriptor rings for one port
844 * This function reinitializes the descriptor rings of one port
845 * in memory. The port must be stopped before.
846 * The HW is initialized with the descriptor start addresses.
851 static void PortReInitBmu(
852 SK_AC *pAC, /* pointer to adapter context */
853 int PortIndex) /* index of the port for which to re-init */
855 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
858 /* set address of first descriptor of ring in BMU */
859 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
860 (uint32_t)(((caddr_t)
861 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
862 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
863 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
865 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
866 (uint32_t)(((caddr_t)
867 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
868 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
869 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
870 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
871 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
872 pAC->RxPort[PortIndex].pRxDescrRing +
873 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
874 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
875 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
876 pAC->RxPort[PortIndex].pRxDescrRing +
877 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
878 } /* PortReInitBmu */
881 /****************************************************************************
883 * SkGeIsr - handle adapter interrupts
886 * The interrupt routine is called when the network adapter
887 * generates an interrupt. It may also be called if another device
888 * shares this interrupt vector with the driver.
893 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
895 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
898 SK_U32 IntSrc; /* interrupts source register contents */
900 pNet = netdev_priv(dev);
904 * Check and process if its our interrupt
906 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
911 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
912 #if 0 /* software irq currently not used */
913 if (IntSrc & IS_IRQ_SW) {
914 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
915 SK_DBGCAT_DRV_INT_SRC,
919 if (IntSrc & IS_R1_F) {
920 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
921 SK_DBGCAT_DRV_INT_SRC,
923 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
924 SK_PNMI_CNT_RX_INTR(pAC, 0);
926 if (IntSrc & IS_R2_F) {
927 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
928 SK_DBGCAT_DRV_INT_SRC,
930 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
931 SK_PNMI_CNT_RX_INTR(pAC, 1);
933 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
934 if (IntSrc & IS_XA1_F) {
935 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
936 SK_DBGCAT_DRV_INT_SRC,
937 ("EOF AS TX1 IRQ\n"));
938 SK_PNMI_CNT_TX_INTR(pAC, 0);
939 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
940 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
941 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
943 if (IntSrc & IS_XA2_F) {
944 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
945 SK_DBGCAT_DRV_INT_SRC,
946 ("EOF AS TX2 IRQ\n"));
947 SK_PNMI_CNT_TX_INTR(pAC, 1);
948 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
949 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
950 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
952 #if 0 /* only if sync. queues used */
953 if (IntSrc & IS_XS1_F) {
954 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
955 SK_DBGCAT_DRV_INT_SRC,
956 ("EOF SY TX1 IRQ\n"));
957 SK_PNMI_CNT_TX_INTR(pAC, 1);
958 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
959 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
960 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
961 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
963 if (IntSrc & IS_XS2_F) {
964 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
965 SK_DBGCAT_DRV_INT_SRC,
966 ("EOF SY TX2 IRQ\n"));
967 SK_PNMI_CNT_TX_INTR(pAC, 1);
968 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
969 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
970 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
971 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
976 /* do all IO at once */
977 if (IntSrc & IS_R1_F)
978 ClearAndStartRx(pAC, 0);
979 if (IntSrc & IS_R2_F)
980 ClearAndStartRx(pAC, 1);
981 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
982 if (IntSrc & IS_XA1_F)
983 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
984 if (IntSrc & IS_XA2_F)
985 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
987 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
988 } /* while (IntSrc & IRQ_MASK != 0) */
990 IntSrc &= pAC->GIni.GIValIrqMask;
991 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
992 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
993 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
994 pAC->CheckQueue = SK_FALSE;
995 spin_lock(&pAC->SlowPathLock);
996 if (IntSrc & SPECIAL_IRQS)
997 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
999 SkEventDispatcher(pAC, pAC->IoBase);
1000 spin_unlock(&pAC->SlowPathLock);
1003 * do it all again is case we cleared an interrupt that
1004 * came in after handling the ring (OUTs may be delayed
1005 * in hardware buffers, but are through after IN)
1007 * rroesler: has been commented out and shifted to
1008 * SkGeDrvEvent(), because it is timer
1011 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1012 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1015 if (pAC->CheckQueue) {
1016 pAC->CheckQueue = SK_FALSE;
1017 spin_lock(&pAC->SlowPathLock);
1018 SkEventDispatcher(pAC, pAC->IoBase);
1019 spin_unlock(&pAC->SlowPathLock);
1022 /* IRQ is processed - Enable IRQs again*/
1023 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1025 return SkIsrRetHandled;
1029 /****************************************************************************
1031 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1034 * The interrupt routine is called when the network adapter
1035 * generates an interrupt. It may also be called if another device
1036 * shares this interrupt vector with the driver.
1037 * This is the same as above, but handles only one port.
1042 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1044 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1047 SK_U32 IntSrc; /* interrupts source register contents */
1049 pNet = netdev_priv(dev);
1053 * Check and process if its our interrupt
1055 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1057 return SkIsrRetNone;
1060 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1061 #if 0 /* software irq currently not used */
1062 if (IntSrc & IS_IRQ_SW) {
1063 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1064 SK_DBGCAT_DRV_INT_SRC,
1065 ("Software IRQ\n"));
1068 if (IntSrc & IS_R1_F) {
1069 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1070 SK_DBGCAT_DRV_INT_SRC,
1072 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1073 SK_PNMI_CNT_RX_INTR(pAC, 0);
1075 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1076 if (IntSrc & IS_XA1_F) {
1077 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1078 SK_DBGCAT_DRV_INT_SRC,
1079 ("EOF AS TX1 IRQ\n"));
1080 SK_PNMI_CNT_TX_INTR(pAC, 0);
1081 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1082 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1083 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1085 #if 0 /* only if sync. queues used */
1086 if (IntSrc & IS_XS1_F) {
1087 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1088 SK_DBGCAT_DRV_INT_SRC,
1089 ("EOF SY TX1 IRQ\n"));
1090 SK_PNMI_CNT_TX_INTR(pAC, 0);
1091 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1092 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1093 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1094 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1099 /* do all IO at once */
1100 if (IntSrc & IS_R1_F)
1101 ClearAndStartRx(pAC, 0);
1102 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1103 if (IntSrc & IS_XA1_F)
1104 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1106 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1107 } /* while (IntSrc & IRQ_MASK != 0) */
1109 IntSrc &= pAC->GIni.GIValIrqMask;
1110 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1111 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1112 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1113 pAC->CheckQueue = SK_FALSE;
1114 spin_lock(&pAC->SlowPathLock);
1115 if (IntSrc & SPECIAL_IRQS)
1116 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1118 SkEventDispatcher(pAC, pAC->IoBase);
1119 spin_unlock(&pAC->SlowPathLock);
1122 * do it all again is case we cleared an interrupt that
1123 * came in after handling the ring (OUTs may be delayed
1124 * in hardware buffers, but are through after IN)
1126 * rroesler: has been commented out and shifted to
1127 * SkGeDrvEvent(), because it is timer
1130 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1133 /* IRQ is processed - Enable IRQs again*/
1134 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1136 return SkIsrRetHandled;
1137 } /* SkGeIsrOnePort */
1139 #ifdef CONFIG_NET_POLL_CONTROLLER
1140 /****************************************************************************
1142 * SkGePollController - polling receive, for netconsole
1145 * Polling receive - used by netconsole and other diagnostic tools
1146 * to allow network i/o with interrupts disabled.
1150 static void SkGePollController(struct net_device *dev)
1152 disable_irq(dev->irq);
1153 SkGeIsr(dev->irq, dev, NULL);
1154 enable_irq(dev->irq);
1158 /****************************************************************************
1160 * SkGeOpen - handle start of initialized adapter
1163 * This function starts the initialized adapter.
1164 * The board level variable is set and the adapter is
1165 * brought to full functionality.
1166 * The device flags are set for operation.
1167 * Do all necessary level 2 initialization, enable interrupts and
1168 * give start command to RLMT.
1174 static int SkGeOpen(
1175 struct SK_NET_DEVICE *dev)
1179 unsigned long Flags; /* for spin lock */
1181 SK_EVPARA EvPara; /* an event parameter union */
1183 pNet = netdev_priv(dev);
1186 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1187 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1189 #ifdef SK_DIAG_SUPPORT
1190 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1191 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1192 return (-1); /* still in use by diag; deny actions */
1197 /* Set blink mode */
1198 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1199 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1201 if (pAC->BoardLevel == SK_INIT_DATA) {
1202 /* level 1 init common modules here */
1203 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1204 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1207 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1208 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1209 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1210 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1211 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1212 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1213 pAC->BoardLevel = SK_INIT_IO;
1216 if (pAC->BoardLevel != SK_INIT_RUN) {
1217 /* tschilling: Level 2 init modules here, check return value. */
1218 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1219 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1222 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1223 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1224 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1225 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1226 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1227 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1228 pAC->BoardLevel = SK_INIT_RUN;
1231 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1232 /* Enable transmit descriptor polling. */
1233 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1234 FillRxRing(pAC, &pAC->RxPort[i]);
1236 SkGeYellowLED(pAC, pAC->IoBase, 1);
1238 StartDrvCleanupTimer(pAC);
1239 SkDimEnableModerationIfNeeded(pAC);
1240 SkDimDisplayModerationSettings(pAC);
1242 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1244 /* enable Interrupts */
1245 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1246 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1248 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1250 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1251 EvPara.Para32[0] = pAC->RlmtNets;
1252 EvPara.Para32[1] = -1;
1253 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1255 EvPara.Para32[0] = pAC->RlmtMode;
1256 EvPara.Para32[1] = 0;
1257 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1261 EvPara.Para32[0] = pNet->NetNr;
1262 EvPara.Para32[1] = -1;
1263 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1264 SkEventDispatcher(pAC, pAC->IoBase);
1265 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1271 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1272 ("SkGeOpen suceeded\n"));
1278 /****************************************************************************
1280 * SkGeClose - Stop initialized adapter
1283 * Close initialized adapter.
1287 * error code - on error
1289 static int SkGeClose(
1290 struct SK_NET_DEVICE *dev)
1296 unsigned long Flags; /* for spin lock */
1301 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1302 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1304 pNet = netdev_priv(dev);
1307 #ifdef SK_DIAG_SUPPORT
1308 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1309 if (pAC->DiagFlowCtrl == SK_FALSE) {
1311 ** notify that the interface which has been closed
1312 ** by operator interaction must not be started up
1313 ** again when the DIAG has finished.
1315 newPtrNet = netdev_priv(pAC->dev[0]);
1316 if (newPtrNet == pNet) {
1317 pAC->WasIfUp[0] = SK_FALSE;
1319 pAC->WasIfUp[1] = SK_FALSE;
1321 return 0; /* return to system everything is fine... */
1323 pAC->DiagFlowCtrl = SK_FALSE;
1328 netif_stop_queue(dev);
1330 if (pAC->RlmtNets == 1)
1331 PortIdx = pAC->ActivePort;
1333 PortIdx = pNet->NetNr;
1335 StopDrvCleanupTimer(pAC);
1338 * Clear multicast table, promiscuous mode ....
1340 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1341 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1344 if (pAC->MaxPorts == 1) {
1345 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1346 /* disable interrupts */
1347 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1348 EvPara.Para32[0] = pNet->NetNr;
1349 EvPara.Para32[1] = -1;
1350 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1351 SkEventDispatcher(pAC, pAC->IoBase);
1352 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1353 /* stop the hardware */
1354 SkGeDeInit(pAC, pAC->IoBase);
1355 pAC->BoardLevel = SK_INIT_DATA;
1356 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1359 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1360 EvPara.Para32[0] = pNet->NetNr;
1361 EvPara.Para32[1] = -1;
1362 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1363 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1364 SkEventDispatcher(pAC, pAC->IoBase);
1365 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1368 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1369 [TX_PRIO_LOW].TxDesRingLock, Flags);
1370 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1371 SK_STOP_ALL, SK_HARD_RST);
1372 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1373 [TX_PRIO_LOW].TxDesRingLock, Flags);
1376 if (pAC->RlmtNets == 1) {
1377 /* clear all descriptor rings */
1378 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1379 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1380 ClearRxRing(pAC, &pAC->RxPort[i]);
1381 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1384 /* clear port descriptor rings */
1385 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1386 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1387 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1390 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1391 ("SkGeClose: done "));
1393 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1394 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1395 sizeof(SK_PNMI_STRUCT_DATA));
1404 /*****************************************************************************
1406 * SkGeXmit - Linux frame transmit function
1409 * The system calls this function to send frames onto the wire.
1410 * It puts the frame in the tx descriptor ring. If the ring is
1411 * full then, the 'tbusy' flag is set.
1414 * 0, if everything is ok
1416 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1417 * allocated skb's) !!!
1419 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1423 int Rc; /* return code of XmitFrame */
1425 pNet = netdev_priv(dev);
1428 if ((!skb_shinfo(skb)->nr_frags) ||
1429 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1430 /* Don't activate scatter-gather and hardware checksum */
1432 if (pAC->RlmtNets == 2)
1435 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1440 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1443 /* scatter-gather and hardware TCP checksumming anabled*/
1444 if (pAC->RlmtNets == 2)
1447 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1452 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1456 /* Transmitter out of resources? */
1458 netif_stop_queue(dev);
1461 /* If not taken, give buffer ownership back to the
1467 dev->trans_start = jiffies;
1472 /*****************************************************************************
1474 * XmitFrame - fill one socket buffer into the transmit ring
1477 * This function puts a message into the transmit descriptor ring
1478 * if there is a descriptors left.
1479 * Linux skb's consist of only one continuous buffer.
1480 * The first step locks the ring. It is held locked
1481 * all time to avoid problems with SWITCH_../PORT_RESET.
1482 * Then the descriptoris allocated.
1483 * The second part is linking the buffer to the descriptor.
1484 * At the very last, the Control field of the descriptor
1485 * is made valid for the BMU and a start TX command is given
1489 * > 0 - on succes: the number of bytes in the message
1490 * = 0 - on resource shortage: this frame sent or dropped, now
1491 * the ring is full ( -> set tbusy)
1492 * < 0 - on failure: other problems ( -> return failure to upper layers)
1494 static int XmitFrame(
1495 SK_AC *pAC, /* pointer to adapter context */
1496 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1497 struct sk_buff *pMessage) /* pointer to send-message */
1499 TXD *pTxd; /* the rxd to fill */
1501 unsigned long Flags;
1503 int BytesSend = pMessage->len;
1505 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1507 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1508 #ifndef USE_TX_COMPLETE
1509 FreeTxDescriptors(pAC, pTxPort);
1511 if (pTxPort->TxdRingFree == 0) {
1513 ** no enough free descriptors in ring at the moment.
1514 ** Maybe free'ing some old one help?
1516 FreeTxDescriptors(pAC, pTxPort);
1517 if (pTxPort->TxdRingFree == 0) {
1518 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1519 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1520 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1521 SK_DBGCAT_DRV_TX_PROGRESS,
1522 ("XmitFrame failed\n"));
1524 ** the desired message can not be sent
1525 ** Because tbusy seems to be set, the message
1526 ** should not be freed here. It will be used
1527 ** by the scheduler of the ethernet handler
1534 ** If the passed socket buffer is of smaller MTU-size than 60,
1535 ** copy everything into new buffer and fill all bytes between
1536 ** the original packet end and the new packet end of 60 with 0x00.
1537 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1539 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1540 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1541 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1544 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1548 ** advance head counter behind descriptor needed for this frame,
1549 ** so that needed descriptor is reserved from that on. The next
1550 ** action will be to add the passed buffer to the TX-descriptor
1552 pTxd = pTxPort->pTxdRingHead;
1553 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1554 pTxPort->TxdRingFree--;
1557 DumpMsg(pMessage, "XmitFrame");
1561 ** First step is to map the data to be sent via the adapter onto
1562 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1563 ** and 2.6 need to use pci_map_page() for that mapping.
1565 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1566 virt_to_page(pMessage->data),
1567 ((unsigned long) pMessage->data & ~PAGE_MASK),
1570 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1571 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1572 pTxd->pMBuf = pMessage;
1574 if (pMessage->ip_summed == CHECKSUM_HW) {
1575 u16 hdrlen = pMessage->h.raw - pMessage->data;
1576 u16 offset = hdrlen + pMessage->csum;
1578 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1579 (pAC->GIni.GIChipRev == 0) &&
1580 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1581 pTxd->TBControl = BMU_TCP_CHECK;
1583 pTxd->TBControl = BMU_UDP_CHECK;
1586 pTxd->TcpSumOfs = 0;
1587 pTxd->TcpSumSt = hdrlen;
1588 pTxd->TcpSumWr = offset;
1590 pTxd->TBControl |= BMU_OWN | BMU_STF |
1592 #ifdef USE_TX_COMPLETE
1597 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1599 #ifdef USE_TX_COMPLETE
1606 ** If previous descriptor already done, give TX start cmd
1608 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1609 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1610 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1614 ** after releasing the lock, the skb may immediately be free'd
1616 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1617 if (pTxPort->TxdRingFree != 0) {
1625 /*****************************************************************************
1627 * XmitFrameSG - fill one socket buffer into the transmit ring
1628 * (use SG and TCP/UDP hardware checksumming)
1631 * This function puts a message into the transmit descriptor ring
1632 * if there is a descriptors left.
1635 * > 0 - on succes: the number of bytes in the message
1636 * = 0 - on resource shortage: this frame sent or dropped, now
1637 * the ring is full ( -> set tbusy)
1638 * < 0 - on failure: other problems ( -> return failure to upper layers)
1640 static int XmitFrameSG(
1641 SK_AC *pAC, /* pointer to adapter context */
1642 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1643 struct sk_buff *pMessage) /* pointer to send-message */
1651 skb_frag_t *sk_frag;
1653 unsigned long Flags;
1656 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1657 #ifndef USE_TX_COMPLETE
1658 FreeTxDescriptors(pAC, pTxPort);
1660 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1661 FreeTxDescriptors(pAC, pTxPort);
1662 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1663 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1664 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1665 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1666 SK_DBGCAT_DRV_TX_PROGRESS,
1667 ("XmitFrameSG failed - Ring full\n"));
1668 /* this message can not be sent now */
1673 pTxd = pTxPort->pTxdRingHead;
1679 ** Map the first fragment (header) into the DMA-space
1681 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1682 virt_to_page(pMessage->data),
1683 ((unsigned long) pMessage->data & ~PAGE_MASK),
1684 skb_headlen(pMessage),
1687 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1688 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1691 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1693 if (pMessage->ip_summed == CHECKSUM_HW) {
1694 u16 hdrlen = pMessage->h.raw - pMessage->data;
1695 u16 offset = hdrlen + pMessage->csum;
1697 Control = BMU_STFWD;
1700 ** We have to use the opcode for tcp here, because the
1701 ** opcode for udp is not working in the hardware yet
1704 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1705 (pAC->GIni.GIChipRev == 0) &&
1706 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1707 Control |= BMU_TCP_CHECK;
1709 Control |= BMU_UDP_CHECK;
1712 pTxd->TcpSumOfs = 0;
1713 pTxd->TcpSumSt = hdrlen;
1714 pTxd->TcpSumWr = offset;
1716 Control = BMU_CHECK | BMU_SW;
1718 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1720 pTxd = pTxd->pNextTxd;
1721 pTxPort->TxdRingFree--;
1722 BytesSend += skb_headlen(pMessage);
1725 ** Browse over all SG fragments and map each of them into the DMA space
1727 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1728 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1730 ** we already have the proper value in entry
1732 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1734 sk_frag->page_offset,
1738 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1739 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1740 pTxd->pMBuf = pMessage;
1742 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;;
1745 ** Do we have the last fragment?
1747 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1748 #ifdef USE_TX_COMPLETE
1749 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1751 pTxd->TBControl |= BMU_EOF;
1753 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1756 pTxd = pTxd->pNextTxd;
1757 pTxPort->TxdRingFree--;
1758 BytesSend += sk_frag->size;
1762 ** If previous descriptor already done, give TX start cmd
1764 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1765 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1768 pTxPort->pTxdRingPrev = pTxdLst;
1769 pTxPort->pTxdRingHead = pTxd;
1771 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1773 if (pTxPort->TxdRingFree > 0) {
1780 /*****************************************************************************
1782 * FreeTxDescriptors - release descriptors from the descriptor ring
1785 * This function releases descriptors from a transmit ring if they
1786 * have been sent by the BMU.
1787 * If a descriptors is sent, it can be freed and the message can
1789 * The SOFTWARE controllable bit is used to prevent running around a
1790 * completely free ring for ever. If this bit is no set in the
1791 * frame (by XmitFrame), this frame has never been sent or is
1793 * The Tx descriptor ring lock must be held while calling this function !!!
1798 static void FreeTxDescriptors(
1799 SK_AC *pAC, /* pointer to the adapter context */
1800 TX_PORT *pTxPort) /* pointer to destination port structure */
1802 TXD *pTxd; /* pointer to the checked descriptor */
1803 TXD *pNewTail; /* pointer to 'end' of the ring */
1804 SK_U32 Control; /* TBControl field of descriptor */
1805 SK_U64 PhysAddr; /* address of DMA mapping */
1807 pNewTail = pTxPort->pTxdRingTail;
1810 ** loop forever; exits if BMU_SW bit not set in start frame
1811 ** or BMU_OWN bit set in any frame
1814 Control = pTxd->TBControl;
1815 if ((Control & BMU_SW) == 0) {
1817 ** software controllable bit is set in first
1818 ** fragment when given to BMU. Not set means that
1819 ** this fragment was never sent or is already
1820 ** freed ( -> ring completely free now).
1822 pTxPort->pTxdRingTail = pTxd;
1823 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1826 if (Control & BMU_OWN) {
1827 pTxPort->pTxdRingTail = pTxd;
1828 if (pTxPort->TxdRingFree > 0) {
1829 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1835 ** release the DMA mapping, because until not unmapped
1836 ** this buffer is considered being under control of the
1839 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1840 PhysAddr |= (SK_U64) pTxd->VDataLow;
1841 pci_unmap_page(pAC->PciDev, PhysAddr,
1845 if (Control & BMU_EOF)
1846 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1848 pTxPort->TxdRingFree++;
1849 pTxd->TBControl &= ~BMU_SW;
1850 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1851 } /* while(forever) */
1852 } /* FreeTxDescriptors */
1854 /*****************************************************************************
1856 * FillRxRing - fill the receive ring with valid descriptors
1859 * This function fills the receive ring descriptors with data
1860 * segments and makes them valid for the BMU.
1861 * The active ring is filled completely, if possible.
1862 * The non-active ring is filled only partial to save memory.
1864 * Description of rx ring structure:
1865 * head - points to the descriptor which will be used next by the BMU
1866 * tail - points to the next descriptor to give to the BMU
1870 static void FillRxRing(
1871 SK_AC *pAC, /* pointer to the adapter context */
1872 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1875 unsigned long Flags;
1877 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1878 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1879 if(!FillRxDescriptor(pAC, pRxPort))
1882 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1886 /*****************************************************************************
1888 * FillRxDescriptor - fill one buffer into the receive ring
1891 * The function allocates a new receive buffer and
1892 * puts it into the next descriptor.
1895 * SK_TRUE - a buffer was added to the ring
1896 * SK_FALSE - a buffer could not be added
1898 static SK_BOOL FillRxDescriptor(
1899 SK_AC *pAC, /* pointer to the adapter context struct */
1900 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1902 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1903 RXD *pRxd; /* the rxd to fill */
1904 SK_U16 Length; /* data fragment length */
1905 SK_U64 PhysAddr; /* physical address of a rx buffer */
1907 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1908 if (pMsgBlock == NULL) {
1909 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1910 SK_DBGCAT_DRV_ENTRY,
1911 ("%s: Allocation of rx buffer failed !\n",
1912 pAC->dev[pRxPort->PortIndex]->name));
1913 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1916 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1917 /* skb allocated ok, so add buffer */
1918 pRxd = pRxPort->pRxdRingTail;
1919 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1920 pRxPort->RxdRingFree--;
1921 Length = pAC->RxBufSize;
1922 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1923 virt_to_page(pMsgBlock->data),
1924 ((unsigned long) pMsgBlock->data &
1927 PCI_DMA_FROMDEVICE);
1929 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1930 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1931 pRxd->pMBuf = pMsgBlock;
1932 pRxd->RBControl = BMU_OWN |
1939 } /* FillRxDescriptor */
1942 /*****************************************************************************
1944 * ReQueueRxBuffer - fill one buffer back into the receive ring
1947 * Fill a given buffer back into the rx ring. The buffer
1948 * has been previously allocated and aligned, and its phys.
1949 * address calculated, so this is no more necessary.
1953 static void ReQueueRxBuffer(
1954 SK_AC *pAC, /* pointer to the adapter context struct */
1955 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1956 struct sk_buff *pMsg, /* pointer to the buffer */
1957 SK_U32 PhysHigh, /* phys address high dword */
1958 SK_U32 PhysLow) /* phys address low dword */
1960 RXD *pRxd; /* the rxd to fill */
1961 SK_U16 Length; /* data fragment length */
1963 pRxd = pRxPort->pRxdRingTail;
1964 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1965 pRxPort->RxdRingFree--;
1966 Length = pAC->RxBufSize;
1968 pRxd->VDataLow = PhysLow;
1969 pRxd->VDataHigh = PhysHigh;
1971 pRxd->RBControl = BMU_OWN |
1977 } /* ReQueueRxBuffer */
1979 /*****************************************************************************
1981 * ReceiveIrq - handle a receive IRQ
1984 * This function is called when a receive IRQ is set.
1985 * It walks the receive descriptor ring and sends up all
1986 * frames that are complete.
1990 static void ReceiveIrq(
1991 SK_AC *pAC, /* pointer to adapter context */
1992 RX_PORT *pRxPort, /* pointer to receive port struct */
1993 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
1995 RXD *pRxd; /* pointer to receive descriptors */
1996 SK_U32 Control; /* control field of descriptor */
1997 struct sk_buff *pMsg; /* pointer to message holding frame */
1998 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
1999 int FrameLength; /* total length of received frame */
2000 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2001 SK_EVPARA EvPara; /* an event parameter union */
2002 unsigned long Flags; /* for spin lock */
2003 int PortIndex = pRxPort->PortIndex;
2004 unsigned int Offset;
2005 unsigned int NumBytes;
2006 unsigned int ForRlmt;
2009 SK_BOOL IsBadFrame; /* Bad frame */
2015 /* do forever; exit if BMU_OWN found */
2016 for ( pRxd = pRxPort->pRxdRingHead ;
2017 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2018 pRxd = pRxd->pNextRxd,
2019 pRxPort->pRxdRingHead = pRxd,
2020 pRxPort->RxdRingFree ++) {
2023 * For a better understanding of this loop
2024 * Go through every descriptor beginning at the head
2025 * Please note: the ring might be completely received so the OWN bit
2026 * set is not a good crirteria to leave that loop.
2027 * Therefore the RingFree counter is used.
2028 * On entry of this loop pRxd is a pointer to the Rxd that needs
2029 * to be checked next.
2032 Control = pRxd->RBControl;
2034 /* check if this descriptor is ready */
2035 if ((Control & BMU_OWN) != 0) {
2036 /* this descriptor is not yet ready */
2037 /* This is the usual end of the loop */
2038 /* We don't need to start the ring again */
2039 FillRxRing(pAC, pRxPort);
2042 pAC->DynIrqModInfo.NbrProcessedDescr++;
2044 /* get length of frame and check it */
2045 FrameLength = Control & BMU_BBC;
2046 if (FrameLength > pAC->RxBufSize) {
2050 /* check for STF and EOF */
2051 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2055 /* here we have a complete frame in the ring */
2058 FrameStat = pRxd->FrameStat;
2060 /* check for frame length mismatch */
2061 #define XMR_FS_LEN_SHIFT 18
2062 #define GMR_FS_LEN_SHIFT 16
2063 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2064 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2065 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2066 SK_DBGCAT_DRV_RX_PROGRESS,
2067 ("skge: Frame length mismatch (%u/%u).\n",
2069 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2074 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2075 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2076 SK_DBGCAT_DRV_RX_PROGRESS,
2077 ("skge: Frame length mismatch (%u/%u).\n",
2079 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2085 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2086 IsBc = (FrameStat & XMR_FS_BC) != 0;
2087 IsMc = (FrameStat & XMR_FS_MC) != 0;
2088 IsBadFrame = (FrameStat &
2089 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2091 IsBc = (FrameStat & GMR_FS_BC) != 0;
2092 IsMc = (FrameStat & GMR_FS_MC) != 0;
2093 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2094 ((FrameStat & GMR_FS_RX_OK) == 0));
2097 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2098 ("Received frame of length %d on port %d\n",
2099 FrameLength, PortIndex));
2100 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2101 ("Number of free rx descriptors: %d\n",
2102 pRxPort->RxdRingFree));
2103 /* DumpMsg(pMsg, "Rx"); */
2105 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2107 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2109 /* there is a receive error in this frame */
2110 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2111 SK_DBGCAT_DRV_RX_PROGRESS,
2112 ("skge: Error in received frame, dropped!\n"
2113 "Control: %x\nRxStat: %x\n",
2114 Control, FrameStat));
2116 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2117 pRxd->VDataHigh, pRxd->VDataLow);
2123 * if short frame then copy data to reduce memory waste
2125 if ((FrameLength < SK_COPY_THRESHOLD) &&
2126 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2128 * Short frame detected and allocation successfull
2130 /* use new skb and copy data */
2131 skb_reserve(pNewMsg, 2);
2132 skb_put(pNewMsg, FrameLength);
2133 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2134 PhysAddr |= (SK_U64) pRxd->VDataLow;
2136 pci_dma_sync_single_for_cpu(pAC->PciDev,
2137 (dma_addr_t) PhysAddr,
2139 PCI_DMA_FROMDEVICE);
2140 memcpy(pNewMsg->data, pMsg, FrameLength);
2142 pci_dma_sync_single_for_device(pAC->PciDev,
2143 (dma_addr_t) PhysAddr,
2145 PCI_DMA_FROMDEVICE);
2146 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2147 pRxd->VDataHigh, pRxd->VDataLow);
2154 * if large frame, or SKB allocation failed, pass
2155 * the SKB directly to the networking
2158 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2159 PhysAddr |= (SK_U64) pRxd->VDataLow;
2161 /* release the DMA mapping */
2162 pci_unmap_single(pAC->PciDev,
2165 PCI_DMA_FROMDEVICE);
2167 /* set length in message */
2168 skb_put(pMsg, FrameLength);
2169 } /* frame > SK_COPY_TRESHOLD */
2171 #ifdef USE_SK_RX_CHECKSUM
2172 pMsg->csum = pRxd->TcpSums;
2173 pMsg->ip_summed = CHECKSUM_HW;
2175 pMsg->ip_summed = CHECKSUM_NONE;
2179 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2180 ForRlmt = SK_RLMT_RX_PROTOCOL;
2182 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2184 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2185 IsBc, &Offset, &NumBytes);
2186 if (NumBytes != 0) {
2188 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2190 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2191 &pMsg->data[Offset],
2192 IsBc, IsMc, &ForRlmt);
2194 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2195 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2196 /* send up only frames from active port */
2197 if ((PortIndex == pAC->ActivePort) ||
2198 (pAC->RlmtNets == 2)) {
2199 /* frame for upper layer */
2200 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2202 DumpMsg(pMsg, "Rx");
2204 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2205 FrameLength, pRxPort->PortIndex);
2207 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2208 pMsg->protocol = eth_type_trans(pMsg,
2209 pAC->dev[pRxPort->PortIndex]);
2211 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2215 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2216 SK_DBGCAT_DRV_RX_PROGRESS,
2218 DEV_KFREE_SKB(pMsg);
2221 } /* if not for rlmt */
2223 /* packet for rlmt */
2224 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2225 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2226 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2227 pAC->IoBase, FrameLength);
2228 if (pRlmtMbuf != NULL) {
2229 pRlmtMbuf->pNext = NULL;
2230 pRlmtMbuf->Length = FrameLength;
2231 pRlmtMbuf->PortIdx = PortIndex;
2232 EvPara.pParaPtr = pRlmtMbuf;
2233 memcpy((char*)(pRlmtMbuf->pData),
2234 (char*)(pMsg->data),
2237 /* SlowPathLock needed? */
2238 if (SlowPathLock == SK_TRUE) {
2239 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2240 SkEventQueue(pAC, SKGE_RLMT,
2241 SK_RLMT_PACKET_RECEIVED,
2243 pAC->CheckQueue = SK_TRUE;
2244 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2246 SkEventQueue(pAC, SKGE_RLMT,
2247 SK_RLMT_PACKET_RECEIVED,
2249 pAC->CheckQueue = SK_TRUE;
2252 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2253 SK_DBGCAT_DRV_RX_PROGRESS,
2256 if ((pAC->dev[pRxPort->PortIndex]->flags &
2257 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2258 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2259 SK_RLMT_RX_PROTOCOL) {
2260 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2261 pMsg->protocol = eth_type_trans(pMsg,
2262 pAC->dev[pRxPort->PortIndex]);
2264 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2267 DEV_KFREE_SKB(pMsg);
2270 } /* if packet for rlmt */
2271 } /* for ... scanning the RXD ring */
2273 /* RXD ring is empty -> fill and restart */
2274 FillRxRing(pAC, pRxPort);
2275 /* do not start if called from Close */
2276 if (pAC->BoardLevel > SK_INIT_DATA) {
2277 ClearAndStartRx(pAC, PortIndex);
2282 /* remove error frame */
2283 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2284 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2286 /* release the DMA mapping */
2288 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2289 PhysAddr |= (SK_U64) pRxd->VDataLow;
2290 pci_unmap_page(pAC->PciDev,
2293 PCI_DMA_FROMDEVICE);
2294 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2296 pRxPort->RxdRingFree++;
2297 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2303 /*****************************************************************************
2305 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2308 * This function sends a start command and a clear interrupt
2309 * command for one receive queue to the BMU.
2314 static void ClearAndStartRx(
2315 SK_AC *pAC, /* pointer to the adapter context */
2316 int PortIndex) /* index of the receive port (XMAC) */
2318 SK_OUT8(pAC->IoBase,
2319 RxQueueAddr[PortIndex]+Q_CSR,
2320 CSR_START | CSR_IRQ_CL_F);
2321 } /* ClearAndStartRx */
2324 /*****************************************************************************
2326 * ClearTxIrq - give a clear transmit IRQ command to BMU
2329 * This function sends a clear tx IRQ command for one
2330 * transmit queue to the BMU.
2334 static void ClearTxIrq(
2335 SK_AC *pAC, /* pointer to the adapter context */
2336 int PortIndex, /* index of the transmit port (XMAC) */
2337 int Prio) /* priority or normal queue */
2339 SK_OUT8(pAC->IoBase,
2340 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2345 /*****************************************************************************
2347 * ClearRxRing - remove all buffers from the receive ring
2350 * This function removes all receive buffers from the ring.
2351 * The receive BMU must be stopped before calling this function.
2355 static void ClearRxRing(
2356 SK_AC *pAC, /* pointer to adapter context */
2357 RX_PORT *pRxPort) /* pointer to rx port struct */
2359 RXD *pRxd; /* pointer to the current descriptor */
2360 unsigned long Flags;
2363 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2366 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2367 pRxd = pRxPort->pRxdRingHead;
2369 if (pRxd->pMBuf != NULL) {
2371 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2372 PhysAddr |= (SK_U64) pRxd->VDataLow;
2373 pci_unmap_page(pAC->PciDev,
2376 PCI_DMA_FROMDEVICE);
2377 DEV_KFREE_SKB(pRxd->pMBuf);
2380 pRxd->RBControl &= BMU_OWN;
2381 pRxd = pRxd->pNextRxd;
2382 pRxPort->RxdRingFree++;
2383 } while (pRxd != pRxPort->pRxdRingTail);
2384 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2385 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2388 /*****************************************************************************
2390 * ClearTxRing - remove all buffers from the transmit ring
2393 * This function removes all transmit buffers from the ring.
2394 * The transmit BMU must be stopped before calling this function
2395 * and transmitting at the upper level must be disabled.
2396 * The BMU own bit of all descriptors is cleared, the rest is
2397 * done by calling FreeTxDescriptors.
2401 static void ClearTxRing(
2402 SK_AC *pAC, /* pointer to adapter context */
2403 TX_PORT *pTxPort) /* pointer to tx prt struct */
2405 TXD *pTxd; /* pointer to the current descriptor */
2407 unsigned long Flags;
2409 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2410 pTxd = pTxPort->pTxdRingHead;
2411 for (i=0; i<pAC->TxDescrPerRing; i++) {
2412 pTxd->TBControl &= ~BMU_OWN;
2413 pTxd = pTxd->pNextTxd;
2415 FreeTxDescriptors(pAC, pTxPort);
2416 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2419 /*****************************************************************************
2421 * SkGeSetMacAddr - Set the hardware MAC address
2424 * This function sets the MAC address used by the adapter.
2427 * 0, if everything is ok
2430 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2433 DEV_NET *pNet = netdev_priv(dev);
2434 SK_AC *pAC = pNet->pAC;
2436 struct sockaddr *addr = p;
2437 unsigned long Flags;
2439 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2440 ("SkGeSetMacAddr starts now...\n"));
2441 if(netif_running(dev))
2444 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2446 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2448 if (pAC->RlmtNets == 2)
2449 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2450 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2452 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2453 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2457 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2459 } /* SkGeSetMacAddr */
2462 /*****************************************************************************
2464 * SkGeSetRxMode - set receive mode
2467 * This function sets the receive mode of an adapter. The adapter
2468 * supports promiscuous mode, allmulticast mode and a number of
2469 * multicast addresses. If more multicast addresses the available
2470 * are selected, a hash function in the hardware is used.
2473 * 0, if everything is ok
2476 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2482 struct dev_mc_list *pMcList;
2485 unsigned long Flags;
2487 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2488 ("SkGeSetRxMode starts now... "));
2490 pNet = netdev_priv(dev);
2492 if (pAC->RlmtNets == 1)
2493 PortIdx = pAC->ActivePort;
2495 PortIdx = pNet->NetNr;
2497 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2498 if (dev->flags & IFF_PROMISC) {
2499 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2500 ("PROMISCUOUS mode\n"));
2501 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2503 } else if (dev->flags & IFF_ALLMULTI) {
2504 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2505 ("ALLMULTI mode\n"));
2506 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2507 SK_PROM_MODE_ALL_MC);
2509 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2511 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2513 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2514 ("Number of MC entries: %d ", dev->mc_count));
2516 pMcList = dev->mc_list;
2517 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2518 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2519 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2520 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2521 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2522 pMcList->dmi_addr[0],
2523 pMcList->dmi_addr[1],
2524 pMcList->dmi_addr[2],
2525 pMcList->dmi_addr[3],
2526 pMcList->dmi_addr[4],
2527 pMcList->dmi_addr[5]));
2529 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2531 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2534 } /* SkGeSetRxMode */
2537 /*****************************************************************************
2539 * SkGeChangeMtu - set the MTU to another value
2542 * This function sets is called whenever the MTU size is changed
2543 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2544 * ethernet MTU size, long frame support is activated.
2547 * 0, if everything is ok
2550 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2555 unsigned long Flags;
2559 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2560 ("SkGeChangeMtu starts now...\n"));
2562 pNet = netdev_priv(dev);
2565 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2569 if(pAC->BoardLevel != SK_INIT_RUN) {
2573 #ifdef SK_DIAG_SUPPORT
2574 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2575 if (pAC->DiagFlowCtrl == SK_FALSE) {
2576 return -1; /* still in use, deny any actions of MTU */
2578 pAC->DiagFlowCtrl = SK_FALSE;
2584 pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2585 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2589 pAC->RxBufSize = NewMtu + 32;
2592 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2593 ("New MTU: %d\n", NewMtu));
2596 ** Prevent any reconfiguration while changing the MTU
2597 ** by disabling any interrupts
2599 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2600 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2603 ** Notify RLMT that any ports are to be stopped
2605 EvPara.Para32[0] = 0;
2606 EvPara.Para32[1] = -1;
2607 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2608 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2609 EvPara.Para32[0] = 1;
2610 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2612 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2616 ** After calling the SkEventDispatcher(), RLMT is aware about
2617 ** the stopped ports -> configuration can take place!
2619 SkEventDispatcher(pAC, pAC->IoBase);
2621 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2622 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2623 netif_stop_queue(pAC->dev[i]);
2628 ** Depending on the desired MTU size change, a different number of
2629 ** RX buffers need to be allocated
2631 if (NewMtu > 1500) {
2633 ** Use less rx buffers
2635 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2636 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2637 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2638 (pAC->RxDescrPerRing / 4);
2640 if (i == pAC->ActivePort) {
2641 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2642 (pAC->RxDescrPerRing / 4);
2644 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2645 (pAC->RxDescrPerRing / 10);
2651 ** Use the normal amount of rx buffers
2653 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2654 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2655 pAC->RxPort[i].RxFillLimit = 1;
2657 if (i == pAC->ActivePort) {
2658 pAC->RxPort[i].RxFillLimit = 1;
2660 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2661 (pAC->RxDescrPerRing / 4);
2667 SkGeDeInit(pAC, pAC->IoBase);
2670 ** enable/disable hardware support for long frames
2672 if (NewMtu > 1500) {
2673 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2674 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2676 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2677 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2679 pAC->GIni.GIPortUsage = SK_RED_LINK;
2683 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2684 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2685 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2686 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2687 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2688 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2689 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2693 ** Speed and others are set back to default in level 1 init!
2695 GetConfiguration(pAC);
2697 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2698 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2699 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2700 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2701 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2702 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2703 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2706 ** clear and reinit the rx rings here
2708 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2709 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2710 ClearRxRing(pAC, &pAC->RxPort[i]);
2711 FillRxRing(pAC, &pAC->RxPort[i]);
2714 ** Enable transmit descriptor polling
2716 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2717 FillRxRing(pAC, &pAC->RxPort[i]);
2720 SkGeYellowLED(pAC, pAC->IoBase, 1);
2721 SkDimEnableModerationIfNeeded(pAC);
2722 SkDimDisplayModerationSettings(pAC);
2724 netif_start_queue(pAC->dev[pNet->PortNr]);
2725 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2726 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2730 ** Enable Interrupts again
2732 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2733 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2735 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2736 SkEventDispatcher(pAC, pAC->IoBase);
2739 ** Notify RLMT about the changing and restarting one (or more) ports
2741 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2742 EvPara.Para32[0] = pAC->RlmtNets;
2743 EvPara.Para32[1] = -1;
2744 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2745 EvPara.Para32[0] = pNet->PortNr;
2746 EvPara.Para32[1] = -1;
2747 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2749 if (pOtherNet->Up) {
2750 EvPara.Para32[0] = pOtherNet->PortNr;
2751 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2754 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2757 SkEventDispatcher(pAC, pAC->IoBase);
2758 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2761 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2762 ** seems as if upper layers have a problem to handle a successful
2763 ** return value of '0'. If such a zero is returned, the complete
2764 ** system hangs for several minutes (!), which is in acceptable.
2766 ** Currently it is not clear, what the exact reason for this problem
2767 ** is. The implemented workaround for 2.5 is to return the desired
2768 ** new MTU size if all needed changes for the new MTU size where
2769 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2770 ** which indicates the successful change of the mtu-size.
2774 } /* SkGeChangeMtu */
2777 /*****************************************************************************
2779 * SkGeStats - return ethernet device statistics
2782 * This function return statistic data about the ethernet device
2783 * to the operating system.
2786 * pointer to the statistic structure.
2788 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2790 DEV_NET *pNet = netdev_priv(dev);
2791 SK_AC *pAC = pNet->pAC;
2792 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2793 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2794 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2795 unsigned int Size; /* size of pnmi struct */
2796 unsigned long Flags; /* for spin lock */
2798 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2799 ("SkGeStats starts now...\n"));
2800 pPnmiStruct = &pAC->PnmiStruct;
2802 #ifdef SK_DIAG_SUPPORT
2803 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2804 (pAC->BoardLevel == SK_INIT_RUN)) {
2806 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2807 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2808 Size = SK_PNMI_STRUCT_SIZE;
2809 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2810 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2811 #ifdef SK_DIAG_SUPPORT
2815 pPnmiStat = &pPnmiStruct->Stat[0];
2816 pPnmiConf = &pPnmiStruct->Conf[0];
2818 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2819 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2820 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2821 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2823 if (pNet->Mtu <= 1500) {
2824 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2826 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2827 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2831 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2832 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2834 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2835 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2836 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2837 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2838 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2840 /* detailed rx_errors: */
2841 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2842 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2843 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2844 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2845 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2846 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2848 /* detailed tx_errors */
2849 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2850 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2851 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2852 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2853 pAC->stats.tx_window_errors = (SK_U32) 0;
2855 return(&pAC->stats);
2859 /*****************************************************************************
2861 * SkGeIoctl - IO-control function
2864 * This function is called if an ioctl is issued on the device.
2865 * There are three subfunction for reading, writing and test-writing
2866 * the private MIB data structure (usefull for SysKonnect-internal tools).
2869 * 0, if everything is ok
2872 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2877 struct pci_dev *pdev = NULL;
2879 unsigned int Err = 0;
2882 unsigned int Length = 0;
2883 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2885 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2886 ("SkGeIoctl starts now...\n"));
2888 pNet = netdev_priv(dev);
2891 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2896 case SK_IOCTL_SETMIB:
2897 case SK_IOCTL_PRESETMIB:
2898 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2899 case SK_IOCTL_GETMIB:
2900 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2901 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2902 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2905 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2906 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2907 Ioctl.Len<Size? Ioctl.Len : Size)) {
2911 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2916 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2919 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2921 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2924 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2928 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2932 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2937 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2942 kfree(pMemBuf); /* cleanup everything */
2944 #ifdef SK_DIAG_SUPPORT
2946 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2947 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2950 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2952 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2955 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2960 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2962 ** While coding this new IOCTL interface, only a few lines of code
2963 ** are to to be added. Therefore no dedicated function has been
2964 ** added. If more functionality is added, a separate function
2965 ** should be used...
2967 * ((SK_U32 *)pMemBuf) = 0;
2968 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2969 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2970 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2975 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2980 kfree(pMemBuf); /* cleanup everything */
2992 /*****************************************************************************
2994 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2997 * This function reads/writes the MIB data using PNMI (Private Network
2998 * Management Interface).
2999 * The destination for the data must be provided with the
3000 * ioctl call and is given to the driver in the form of
3001 * a user space address.
3002 * Copying from the user-provided data area into kernel messages
3003 * and back is done by copy_from_user and copy_to_user calls in
3007 * returned size from PNMI call
3009 static int SkGeIocMib(
3010 DEV_NET *pNet, /* pointer to the adapter context */
3011 unsigned int Size, /* length of ioctl data */
3012 int mode) /* flag for set/preset */
3014 unsigned long Flags; /* for spin lock */
3017 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3018 ("SkGeIocMib starts now...\n"));
3021 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3023 case SK_IOCTL_GETMIB:
3024 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3027 case SK_IOCTL_PRESETMIB:
3028 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3031 case SK_IOCTL_SETMIB:
3032 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3038 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3039 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3040 ("MIB data access succeeded\n"));
3045 /*****************************************************************************
3047 * GetConfiguration - read configuration information
3050 * This function reads per-adapter configuration information from
3051 * the options provided on the command line.
3056 static void GetConfiguration(
3057 SK_AC *pAC) /* pointer to the adapter context structure */
3059 SK_I32 Port; /* preferred port */
3062 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3063 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3064 int DuplexCap = 0; /* 0=both,1=full,2=half */
3065 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3066 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3068 SK_BOOL IsConTypeDefined = SK_TRUE;
3069 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3070 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3071 SK_BOOL IsRoleDefined = SK_TRUE;
3072 SK_BOOL IsModeDefined = SK_TRUE;
3074 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3075 * parameter. The mapping is described by this table:
3076 * DuplexCap -> | both | full | half |
3078 * -----------------------------------------------------------------
3079 * Off | illegal | Full | Half |
3080 * -----------------------------------------------------------------
3081 * On | AutoBoth | AutoFull | AutoHalf |
3082 * -----------------------------------------------------------------
3083 * Sense | AutoSense | AutoSense | AutoSense |
3085 int Capabilities[3][3] =
3086 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3087 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3088 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3096 #define M_CurrPort pAC->GIni.GP[Port]
3100 ** Set the default values first for both ports!
3102 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3103 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3104 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3105 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3106 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3110 ** Check merged parameter ConType. If it has not been used,
3111 ** verify any other parameter (e.g. AutoNeg) and use default values.
3113 ** Stating both ConType and other lowlevel link parameters is also
3114 ** possible. If this is the case, the passed ConType-parameter is
3115 ** overwritten by the lowlevel link parameter.
3117 ** The following settings are used for a merged ConType-parameter:
3119 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3120 ** ------- ------ ------- -------- ---------- -----
3121 ** Auto Both On SymOrRem Auto Auto
3122 ** 100FD Full Off None <ignored> 100
3123 ** 100HD Half Off None <ignored> 100
3124 ** 10FD Full Off None <ignored> 10
3125 ** 10HD Half Off None <ignored> 10
3127 ** This ConType parameter is used for all ports of the adapter!
3129 if ( (ConType != NULL) &&
3130 (pAC->Index < SK_MAX_CARD_PARAM) &&
3131 (ConType[pAC->Index] != NULL) ) {
3133 /* Check chipset family */
3134 if ((!pAC->ChipsetType) &&
3135 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3136 (strcmp(ConType[pAC->Index],"")!=0)) {
3137 /* Set the speed parameter back */
3138 printk("sk98lin: Illegal value \"%s\" "
3141 ConType[pAC->Index]);
3143 sprintf(ConType[pAC->Index], "Auto");
3146 if (strcmp(ConType[pAC->Index],"")==0) {
3147 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3148 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3149 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3150 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3151 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3152 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3153 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3155 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3156 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3157 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3158 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3159 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3160 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3162 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3163 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3164 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3165 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3166 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3167 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3169 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3170 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3171 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3172 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3173 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3174 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3176 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3177 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3178 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3179 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3180 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3181 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3184 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3185 ConType[pAC->Index]);
3186 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3189 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3193 ** Parse any parameter settings for port A:
3194 ** a) any LinkSpeed stated?
3196 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3197 Speed_A[pAC->Index] != NULL) {
3198 if (strcmp(Speed_A[pAC->Index],"")==0) {
3199 IsLinkSpeedDefined = SK_FALSE;
3200 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3201 LinkSpeed = SK_LSPEED_AUTO;
3202 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3203 LinkSpeed = SK_LSPEED_10MBPS;
3204 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3205 LinkSpeed = SK_LSPEED_100MBPS;
3206 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3207 LinkSpeed = SK_LSPEED_1000MBPS;
3209 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3210 Speed_A[pAC->Index]);
3211 IsLinkSpeedDefined = SK_FALSE;
3214 IsLinkSpeedDefined = SK_FALSE;
3218 ** Check speed parameter:
3219 ** Only copper type adapter and GE V2 cards
3221 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3222 ((LinkSpeed != SK_LSPEED_AUTO) &&
3223 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3224 printk("sk98lin: Illegal value for Speed_A. "
3225 "Not a copper card or GE V2 card\n Using "
3227 LinkSpeed = SK_LSPEED_1000MBPS;
3231 ** Decide whether to set new config value if somethig valid has
3234 if (IsLinkSpeedDefined) {
3235 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3239 ** b) Any Autonegotiation and DuplexCapabilities set?
3240 ** Please note that both belong together...
3242 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3244 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3245 AutoNeg_A[pAC->Index] != NULL) {
3247 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3249 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3251 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3253 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3256 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3257 AutoNeg_A[pAC->Index]);
3261 DuplexCap = DC_BOTH;
3263 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3264 DupCap_A[pAC->Index] != NULL) {
3266 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3268 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3269 DuplexCap = DC_BOTH;
3270 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3271 DuplexCap = DC_FULL;
3272 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3273 DuplexCap = DC_HALF;
3275 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3276 DupCap_A[pAC->Index]);
3281 ** Check for illegal combinations
3283 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3284 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3285 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3286 (pAC->ChipsetType)) {
3287 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3288 " Using Full Duplex.\n");
3289 DuplexCap = DC_FULL;
3292 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3293 printk("sk98lin, Port A: DuplexCapabilities"
3294 " ignored using Sense mode\n");
3297 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3298 printk("sk98lin: Port A: Illegal combination"
3299 " of values AutoNeg. and DuplexCap.\n Using "
3301 DuplexCap = DC_FULL;
3304 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3305 DuplexCap = DC_FULL;
3308 if (!AutoSet && DupSet) {
3309 printk("sk98lin: Port A: Duplex setting not"
3310 " possible in\n default AutoNegotiation mode"
3311 " (Sense).\n Using AutoNegotiation On\n");
3316 ** set the desired mode
3318 if (AutoSet || DupSet) {
3319 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3323 ** c) Any Flowcontrol-parameter set?
3325 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3326 FlowCtrl_A[pAC->Index] != NULL) {
3327 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3328 IsFlowCtrlDefined = SK_FALSE;
3329 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3330 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3331 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3332 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3333 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3334 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3335 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3336 FlowCtrl = SK_FLOW_MODE_NONE;
3338 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3339 FlowCtrl_A[pAC->Index]);
3340 IsFlowCtrlDefined = SK_FALSE;
3343 IsFlowCtrlDefined = SK_FALSE;
3346 if (IsFlowCtrlDefined) {
3347 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3348 printk("sk98lin: Port A: FlowControl"
3349 " impossible without AutoNegotiation,"
3351 FlowCtrl = SK_FLOW_MODE_NONE;
3353 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3357 ** d) What is with the RoleParameter?
3359 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3360 Role_A[pAC->Index] != NULL) {
3361 if (strcmp(Role_A[pAC->Index],"")==0) {
3362 IsRoleDefined = SK_FALSE;
3363 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3364 MSMode = SK_MS_MODE_AUTO;
3365 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3366 MSMode = SK_MS_MODE_MASTER;
3367 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3368 MSMode = SK_MS_MODE_SLAVE;
3370 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3371 Role_A[pAC->Index]);
3372 IsRoleDefined = SK_FALSE;
3375 IsRoleDefined = SK_FALSE;
3378 if (IsRoleDefined == SK_TRUE) {
3379 pAC->GIni.GP[0].PMSMode = MSMode;
3385 ** Parse any parameter settings for port B:
3386 ** a) any LinkSpeed stated?
3388 IsConTypeDefined = SK_TRUE;
3389 IsLinkSpeedDefined = SK_TRUE;
3390 IsFlowCtrlDefined = SK_TRUE;
3391 IsModeDefined = SK_TRUE;
3393 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3394 Speed_B[pAC->Index] != NULL) {
3395 if (strcmp(Speed_B[pAC->Index],"")==0) {
3396 IsLinkSpeedDefined = SK_FALSE;
3397 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3398 LinkSpeed = SK_LSPEED_AUTO;
3399 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3400 LinkSpeed = SK_LSPEED_10MBPS;
3401 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3402 LinkSpeed = SK_LSPEED_100MBPS;
3403 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3404 LinkSpeed = SK_LSPEED_1000MBPS;
3406 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3407 Speed_B[pAC->Index]);
3408 IsLinkSpeedDefined = SK_FALSE;
3411 IsLinkSpeedDefined = SK_FALSE;
3415 ** Check speed parameter:
3416 ** Only copper type adapter and GE V2 cards
3418 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3419 ((LinkSpeed != SK_LSPEED_AUTO) &&
3420 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3421 printk("sk98lin: Illegal value for Speed_B. "
3422 "Not a copper card or GE V2 card\n Using "
3424 LinkSpeed = SK_LSPEED_1000MBPS;
3428 ** Decide whether to set new config value if somethig valid has
3431 if (IsLinkSpeedDefined) {
3432 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3436 ** b) Any Autonegotiation and DuplexCapabilities set?
3437 ** Please note that both belong together...
3439 AutoNeg = AN_SENS; /* default: do auto Sense */
3441 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3442 AutoNeg_B[pAC->Index] != NULL) {
3444 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3446 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3448 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3450 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3453 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3454 AutoNeg_B[pAC->Index]);
3458 DuplexCap = DC_BOTH;
3460 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3461 DupCap_B[pAC->Index] != NULL) {
3463 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3465 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3466 DuplexCap = DC_BOTH;
3467 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3468 DuplexCap = DC_FULL;
3469 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3470 DuplexCap = DC_HALF;
3472 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3473 DupCap_B[pAC->Index]);
3479 ** Check for illegal combinations
3481 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3482 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3483 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3484 (pAC->ChipsetType)) {
3485 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3486 " Using Full Duplex.\n");
3487 DuplexCap = DC_FULL;
3490 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3491 printk("sk98lin, Port B: DuplexCapabilities"
3492 " ignored using Sense mode\n");
3495 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3496 printk("sk98lin: Port B: Illegal combination"
3497 " of values AutoNeg. and DuplexCap.\n Using "
3499 DuplexCap = DC_FULL;
3502 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3503 DuplexCap = DC_FULL;
3506 if (!AutoSet && DupSet) {
3507 printk("sk98lin: Port B: Duplex setting not"
3508 " possible in\n default AutoNegotiation mode"
3509 " (Sense).\n Using AutoNegotiation On\n");
3514 ** set the desired mode
3516 if (AutoSet || DupSet) {
3517 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3521 ** c) Any FlowCtrl parameter set?
3523 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3524 FlowCtrl_B[pAC->Index] != NULL) {
3525 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3526 IsFlowCtrlDefined = SK_FALSE;
3527 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3528 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3529 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3530 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3531 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3532 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3533 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3534 FlowCtrl = SK_FLOW_MODE_NONE;
3536 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3537 FlowCtrl_B[pAC->Index]);
3538 IsFlowCtrlDefined = SK_FALSE;
3541 IsFlowCtrlDefined = SK_FALSE;
3544 if (IsFlowCtrlDefined) {
3545 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3546 printk("sk98lin: Port B: FlowControl"
3547 " impossible without AutoNegotiation,"
3549 FlowCtrl = SK_FLOW_MODE_NONE;
3551 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3555 ** d) What is the RoleParameter?
3557 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3558 Role_B[pAC->Index] != NULL) {
3559 if (strcmp(Role_B[pAC->Index],"")==0) {
3560 IsRoleDefined = SK_FALSE;
3561 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3562 MSMode = SK_MS_MODE_AUTO;
3563 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3564 MSMode = SK_MS_MODE_MASTER;
3565 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3566 MSMode = SK_MS_MODE_SLAVE;
3568 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3569 Role_B[pAC->Index]);
3570 IsRoleDefined = SK_FALSE;
3573 IsRoleDefined = SK_FALSE;
3576 if (IsRoleDefined) {
3577 pAC->GIni.GP[1].PMSMode = MSMode;
3581 ** Evaluate settings for both ports
3583 pAC->ActivePort = 0;
3584 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3585 PrefPort[pAC->Index] != NULL) {
3586 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3587 pAC->ActivePort = 0;
3588 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3589 pAC->Rlmt.Net[0].PrefPort = 0;
3590 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3592 ** do not set ActivePort here, thus a port
3593 ** switch is issued after net up.
3596 pAC->Rlmt.Net[0].Preference = Port;
3597 pAC->Rlmt.Net[0].PrefPort = Port;
3598 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3600 ** do not set ActivePort here, thus a port
3601 ** switch is issued after net up.
3603 if (pAC->GIni.GIMacsFound == 1) {
3604 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3605 " Port B not available on single port adapters.\n");
3607 pAC->ActivePort = 0;
3608 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3609 pAC->Rlmt.Net[0].PrefPort = 0;
3612 pAC->Rlmt.Net[0].Preference = Port;
3613 pAC->Rlmt.Net[0].PrefPort = Port;
3616 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3617 PrefPort[pAC->Index]);
3623 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3624 RlmtMode[pAC->Index] != NULL) {
3625 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3627 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3628 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3629 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3630 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3631 SK_RLMT_CHECK_LOC_LINK;
3632 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3633 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3634 SK_RLMT_CHECK_LOC_LINK |
3636 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3637 (pAC->GIni.GIMacsFound == 2)) {
3638 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3641 printk("sk98lin: Illegal value \"%s\" for"
3642 " RlmtMode, using default\n",
3643 RlmtMode[pAC->Index]);
3651 ** Check the interrupt moderation parameters
3653 if (Moderation[pAC->Index] != NULL) {
3654 if (strcmp(Moderation[pAC->Index], "") == 0) {
3655 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3656 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3657 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3658 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3659 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3660 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3661 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3663 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3664 " Disable interrupt moderation.\n",
3665 Moderation[pAC->Index]);
3666 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3669 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3672 if (Stats[pAC->Index] != NULL) {
3673 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3674 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3676 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3679 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3682 if (ModerationMask[pAC->Index] != NULL) {
3683 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3684 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3685 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3686 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3687 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3688 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3689 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3690 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3691 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3692 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3693 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3694 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3695 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3696 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3697 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3698 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3699 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3700 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3701 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3702 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3703 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3704 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3705 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3706 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3707 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3708 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3709 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3710 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3711 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3712 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3713 } else { /* some rubbish */
3714 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3716 } else { /* operator has stated nothing */
3717 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3720 if (AutoSizing[pAC->Index] != NULL) {
3721 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3722 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3724 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3726 } else { /* operator has stated nothing */
3727 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3730 if (IntsPerSec[pAC->Index] != 0) {
3731 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3732 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3733 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3734 " Using default value of %i.\n",
3735 IntsPerSec[pAC->Index],
3736 C_INT_MOD_IPS_LOWER_RANGE,
3737 C_INT_MOD_IPS_UPPER_RANGE,
3738 C_INTS_PER_SEC_DEFAULT);
3739 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3741 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3744 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3748 ** Evaluate upper and lower moderation threshold
3750 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3751 pAC->DynIrqModInfo.MaxModIntsPerSec +
3752 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3754 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3755 pAC->DynIrqModInfo.MaxModIntsPerSec -
3756 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3758 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3761 } /* GetConfiguration */
3764 /*****************************************************************************
3766 * ProductStr - return a adapter identification string from vpd
3769 * This function reads the product name string from the vpd area
3770 * and puts it the field pAC->DeviceString.
3774 static void ProductStr(
3775 SK_AC *pAC /* pointer to adapter context */
3778 int StrLen = 80; /* length of the string, defined in SK_AC */
3779 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3780 int ReturnCode; /* return code from vpd_read */
3781 unsigned long Flags;
3783 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3784 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3786 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3787 if (ReturnCode != 0) {
3788 /* there was an error reading the vpd data */
3789 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3790 ("Error reading VPD data: %d\n", ReturnCode));
3791 pAC->DeviceStr[0] = '\0';
3795 /*****************************************************************************
3797 * StartDrvCleanupTimer - Start timer to check for descriptors which
3798 * might be placed in descriptor ring, but
3799 * havent been handled up to now
3802 * This function requests a HW-timer fo the Yukon card. The actions to
3803 * perform when this timer expires, are located in the SkDrvEvent().
3808 StartDrvCleanupTimer(SK_AC *pAC) {
3809 SK_EVPARA EventParam; /* Event struct for timer event */
3811 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3812 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3813 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3814 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3815 SKGE_DRV, SK_DRV_TIMER, EventParam);
3818 /*****************************************************************************
3820 * StopDrvCleanupTimer - Stop timer to check for descriptors
3823 * This function requests a HW-timer fo the Yukon card. The actions to
3824 * perform when this timer expires, are located in the SkDrvEvent().
3829 StopDrvCleanupTimer(SK_AC *pAC) {
3830 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3831 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3834 /****************************************************************************/
3835 /* functions for common modules *********************************************/
3836 /****************************************************************************/
3839 /*****************************************************************************
3841 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3844 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3845 * is embedded into a socket buff data area.
3851 * NULL or pointer to Mbuf.
3853 SK_MBUF *SkDrvAllocRlmtMbuf(
3854 SK_AC *pAC, /* pointer to adapter context */
3855 SK_IOC IoC, /* the IO-context */
3856 unsigned BufferSize) /* size of the requested buffer */
3858 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3859 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3861 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3862 if (pMsgBlock == NULL) {
3865 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3866 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3867 pRlmtMbuf->pNext = NULL;
3868 pRlmtMbuf->pOs = pMsgBlock;
3869 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3870 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3871 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3874 } /* SkDrvAllocRlmtMbuf */
3877 /*****************************************************************************
3879 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3882 * This routine frees one or more RLMT mbuf(s).
3890 void SkDrvFreeRlmtMbuf(
3891 SK_AC *pAC, /* pointer to adapter context */
3892 SK_IOC IoC, /* the IO-context */
3893 SK_MBUF *pMbuf) /* size of the requested buffer */
3900 pNextMbuf = pFreeMbuf->pNext;
3901 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3902 pFreeMbuf = pNextMbuf;
3903 } while ( pFreeMbuf != NULL );
3904 } /* SkDrvFreeRlmtMbuf */
3907 /*****************************************************************************
3909 * SkOsGetTime - provide a time value
3912 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3913 * It is not used for absolute time, but only for time differences.
3919 SK_U64 SkOsGetTime(SK_AC *pAC)
3921 SK_U64 PrivateJiffies;
3922 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3923 return PrivateJiffies;
3927 /*****************************************************************************
3929 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3932 * This routine reads a 32 bit value from the pci configuration
3936 * 0 - indicate everything worked ok.
3937 * != 0 - error indication
3939 int SkPciReadCfgDWord(
3940 SK_AC *pAC, /* Adapter Control structure pointer */
3941 int PciAddr, /* PCI register address */
3942 SK_U32 *pVal) /* pointer to store the read value */
3944 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3946 } /* SkPciReadCfgDWord */
3949 /*****************************************************************************
3951 * SkPciReadCfgWord - read a 16 bit value from pci config space
3954 * This routine reads a 16 bit value from the pci configuration
3958 * 0 - indicate everything worked ok.
3959 * != 0 - error indication
3961 int SkPciReadCfgWord(
3962 SK_AC *pAC, /* Adapter Control structure pointer */
3963 int PciAddr, /* PCI register address */
3964 SK_U16 *pVal) /* pointer to store the read value */
3966 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3968 } /* SkPciReadCfgWord */
3971 /*****************************************************************************
3973 * SkPciReadCfgByte - read a 8 bit value from pci config space
3976 * This routine reads a 8 bit value from the pci configuration
3980 * 0 - indicate everything worked ok.
3981 * != 0 - error indication
3983 int SkPciReadCfgByte(
3984 SK_AC *pAC, /* Adapter Control structure pointer */
3985 int PciAddr, /* PCI register address */
3986 SK_U8 *pVal) /* pointer to store the read value */
3988 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
3990 } /* SkPciReadCfgByte */
3993 /*****************************************************************************
3995 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
3998 * This routine writes a 32 bit value to the pci configuration
4002 * 0 - indicate everything worked ok.
4003 * != 0 - error indication
4005 int SkPciWriteCfgDWord(
4006 SK_AC *pAC, /* Adapter Control structure pointer */
4007 int PciAddr, /* PCI register address */
4008 SK_U32 Val) /* pointer to store the read value */
4010 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4012 } /* SkPciWriteCfgDWord */
4015 /*****************************************************************************
4017 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4020 * This routine writes a 16 bit value to the pci configuration
4021 * space. The flag PciConfigUp indicates whether the config space
4022 * is accesible or must be set up first.
4025 * 0 - indicate everything worked ok.
4026 * != 0 - error indication
4028 int SkPciWriteCfgWord(
4029 SK_AC *pAC, /* Adapter Control structure pointer */
4030 int PciAddr, /* PCI register address */
4031 SK_U16 Val) /* pointer to store the read value */
4033 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4035 } /* SkPciWriteCfgWord */
4038 /*****************************************************************************
4040 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4043 * This routine writes a 8 bit value to the pci configuration
4044 * space. The flag PciConfigUp indicates whether the config space
4045 * is accesible or must be set up first.
4048 * 0 - indicate everything worked ok.
4049 * != 0 - error indication
4051 int SkPciWriteCfgByte(
4052 SK_AC *pAC, /* Adapter Control structure pointer */
4053 int PciAddr, /* PCI register address */
4054 SK_U8 Val) /* pointer to store the read value */
4056 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4058 } /* SkPciWriteCfgByte */
4061 /*****************************************************************************
4063 * SkDrvEvent - handle driver events
4066 * This function handles events from all modules directed to the driver
4069 * Is called under protection of slow path lock.
4072 * 0 if everything ok
4077 SK_AC *pAC, /* pointer to adapter context */
4078 SK_IOC IoC, /* io-context */
4079 SK_U32 Event, /* event-id */
4080 SK_EVPARA Param) /* event-parameter */
4082 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4083 struct sk_buff *pMsg; /* pointer to a message block */
4084 int FromPort; /* the port from which we switch away */
4085 int ToPort; /* the port we switch to */
4086 SK_EVPARA NewPara; /* parameter for further events */
4088 unsigned long Flags;
4092 case SK_DRV_ADAP_FAIL:
4093 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4094 ("ADAPTER FAIL EVENT\n"));
4095 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4096 /* disable interrupts */
4097 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4100 case SK_DRV_PORT_FAIL:
4101 FromPort = Param.Para32[0];
4102 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4103 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4104 if (FromPort == 0) {
4105 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4107 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4111 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4113 FromPort = Param.Para32[0];
4114 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4115 ("PORT RESET EVENT, Port: %d ", FromPort));
4116 NewPara.Para64 = FromPort;
4117 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4119 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4122 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4123 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4124 spin_unlock_irqrestore(
4125 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4128 /* clear rx ring from received frames */
4129 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4131 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4133 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4136 /* tschilling: Handling of return value inserted. */
4137 if (SkGeInitPort(pAC, IoC, FromPort)) {
4138 if (FromPort == 0) {
4139 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4141 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4144 SkAddrMcUpdate(pAC,IoC, FromPort);
4145 PortReInitBmu(pAC, FromPort);
4146 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4147 ClearAndStartRx(pAC, FromPort);
4148 spin_unlock_irqrestore(
4149 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4152 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4154 FromPort = Param.Para32[0];
4155 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4156 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4158 SkAddrMcUpdate(pAC,IoC, FromPort);
4160 if (DoPrintInterfaceChange) {
4161 printk("%s: network connection up using"
4162 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4164 /* tschilling: Values changed according to LinkSpeedUsed. */
4165 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4166 if (Stat == SK_LSPEED_STAT_10MBPS) {
4167 printk(" speed: 10\n");
4168 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4169 printk(" speed: 100\n");
4170 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4171 printk(" speed: 1000\n");
4173 printk(" speed: unknown\n");
4177 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4178 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4179 Stat == SK_LMODE_STAT_AUTOFULL) {
4180 printk(" autonegotiation: yes\n");
4183 printk(" autonegotiation: no\n");
4185 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4186 Stat == SK_LMODE_STAT_HALF) {
4187 printk(" duplex mode: half\n");
4190 printk(" duplex mode: full\n");
4192 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4193 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4194 printk(" flowctrl: remote send\n");
4196 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4197 printk(" flowctrl: local send\n");
4199 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4200 printk(" flowctrl: symmetric\n");
4203 printk(" flowctrl: none\n");
4206 /* tschilling: Check against CopperType now. */
4207 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4208 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4209 SK_LSPEED_STAT_1000MBPS)) {
4210 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4211 if (Stat == SK_MS_STAT_MASTER ) {
4212 printk(" role: master\n");
4214 else if (Stat == SK_MS_STAT_SLAVE ) {
4215 printk(" role: slave\n");
4218 printk(" role: ???\n");
4223 Display dim (dynamic interrupt moderation)
4226 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4227 printk(" irq moderation: static (%d ints/sec)\n",
4228 pAC->DynIrqModInfo.MaxModIntsPerSec);
4229 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4230 printk(" irq moderation: dynamic (%d ints/sec)\n",
4231 pAC->DynIrqModInfo.MaxModIntsPerSec);
4233 printk(" irq moderation: disabled\n");
4237 if (pAC->ChipsetType)
4238 #ifdef USE_SK_TX_CHECKSUM
4239 printk(" scatter-gather: enabled\n");
4241 printk(" tx-checksum: disabled\n");
4244 printk(" scatter-gather: disabled\n");
4246 printk(" scatter-gather: disabled\n");
4249 #ifndef USE_SK_RX_CHECKSUM
4250 printk(" rx-checksum: disabled\n");
4254 DoPrintInterfaceChange = SK_TRUE;
4257 if ((Param.Para32[0] != pAC->ActivePort) &&
4258 (pAC->RlmtNets == 1)) {
4259 NewPara.Para32[0] = pAC->ActivePort;
4260 NewPara.Para32[1] = Param.Para32[0];
4261 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4265 /* Inform the world that link protocol is up. */
4266 netif_carrier_on(pAC->dev[Param.Para32[0]]);
4269 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4271 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4272 ("NET DOWN EVENT "));
4273 if (DoPrintInterfaceChange) {
4274 printk("%s: network connection down\n",
4275 pAC->dev[Param.Para32[1]]->name);
4277 DoPrintInterfaceChange = SK_TRUE;
4279 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4281 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4282 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4283 ("PORT SWITCH HARD "));
4284 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4286 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4287 'A'+Param.Para32[1]);
4288 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4289 FromPort = Param.Para32[0];
4290 ToPort = Param.Para32[1];
4291 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4292 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4293 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4294 NewPara.Para64 = FromPort;
4295 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4296 NewPara.Para64 = ToPort;
4297 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4299 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4301 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4302 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4303 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4304 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4305 spin_unlock_irqrestore(
4306 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4309 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4310 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4312 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4313 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4315 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4317 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4318 pAC->ActivePort = ToPort;
4322 /* tschilling: New common function with minimum size check. */
4324 if (pAC->RlmtNets == 2) {
4328 if (SkGeInitAssignRamToQueues(
4332 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4333 spin_unlock_irqrestore(
4334 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4336 printk("SkGeInitAssignRamToQueues failed.\n");
4340 /* tschilling: Handling of return values inserted. */
4341 if (SkGeInitPort(pAC, IoC, FromPort) ||
4342 SkGeInitPort(pAC, IoC, ToPort)) {
4343 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4345 if (Event == SK_DRV_SWITCH_SOFT) {
4346 SkMacRxTxEnable(pAC, IoC, FromPort);
4348 SkMacRxTxEnable(pAC, IoC, ToPort);
4349 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4350 SkAddrMcUpdate(pAC, IoC, FromPort);
4351 SkAddrMcUpdate(pAC, IoC, ToPort);
4352 PortReInitBmu(pAC, FromPort);
4353 PortReInitBmu(pAC, ToPort);
4354 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4355 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4356 ClearAndStartRx(pAC, FromPort);
4357 ClearAndStartRx(pAC, ToPort);
4358 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4359 spin_unlock_irqrestore(
4360 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4363 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4364 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4366 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4367 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4368 skb_put(pMsg, pRlmtMbuf->Length);
4369 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4372 DEV_KFREE_SKB_ANY(pMsg);
4375 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4377 ** expiration of the moderation timer implies that
4378 ** dynamic moderation is to be applied
4380 SkDimStartModerationTimer(pAC);
4382 if (pAC->DynIrqModInfo.DisplayStats) {
4383 SkDimDisplayModerationSettings(pAC);
4385 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4387 ** check if we need to check for descriptors which
4388 ** haven't been handled the last millisecs
4390 StartDrvCleanupTimer(pAC);
4391 if (pAC->GIni.GIMacsFound == 2) {
4392 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4394 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4396 printk("Expiration of unknown timer\n");
4402 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4409 /*****************************************************************************
4411 * SkErrorLog - log errors
4414 * This function logs errors to the system buffer and to the console
4417 * 0 if everything ok
4430 case SK_ERRCL_OTHER:
4431 strcpy(ClassStr, "Other error");
4433 case SK_ERRCL_CONFIG:
4434 strcpy(ClassStr, "Configuration error");
4437 strcpy(ClassStr, "Initialization error");
4439 case SK_ERRCL_NORES:
4440 strcpy(ClassStr, "Out of resources error");
4443 strcpy(ClassStr, "internal Software error");
4446 strcpy(ClassStr, "Hardware failure");
4449 strcpy(ClassStr, "Communication error");
4452 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4453 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4454 ClassStr, ErrNum, pErrorMsg);
4458 #ifdef SK_DIAG_SUPPORT
4460 /*****************************************************************************
4462 * SkDrvEnterDiagMode - handles DIAG attach request
4465 * Notify the kernel to NOT access the card any longer due to DIAG
4466 * Deinitialize the Card
4471 int SkDrvEnterDiagMode(
4472 SK_AC *pAc) /* pointer to adapter context */
4474 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4475 SK_AC *pAC = pNet->pAC;
4477 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4478 sizeof(SK_PNMI_STRUCT_DATA));
4480 pAC->DiagModeActive = DIAG_ACTIVE;
4481 if (pAC->BoardLevel > SK_INIT_DATA) {
4483 pAC->WasIfUp[0] = SK_TRUE;
4484 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4485 DoPrintInterfaceChange = SK_FALSE;
4486 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4488 pAC->WasIfUp[0] = SK_FALSE;
4490 if (pNet != netdev_priv(pAC->dev[1])) {
4491 pNet = netdev_priv(pAC->dev[1]);
4493 pAC->WasIfUp[1] = SK_TRUE;
4494 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4495 DoPrintInterfaceChange = SK_FALSE;
4496 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4498 pAC->WasIfUp[1] = SK_FALSE;
4501 pAC->BoardLevel = SK_INIT_DATA;
4506 /*****************************************************************************
4508 * SkDrvLeaveDiagMode - handles DIAG detach request
4511 * Notify the kernel to may access the card again after use by DIAG
4512 * Initialize the Card
4517 int SkDrvLeaveDiagMode(
4518 SK_AC *pAc) /* pointer to adapter control context */
4520 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4521 sizeof(SK_PNMI_STRUCT_DATA));
4522 pAc->DiagModeActive = DIAG_NOTACTIVE;
4523 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4524 if (pAc->WasIfUp[0] == SK_TRUE) {
4525 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4526 DoPrintInterfaceChange = SK_FALSE;
4527 SkDrvInitAdapter(pAc, 0); /* first device */
4529 if (pAc->WasIfUp[1] == SK_TRUE) {
4530 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4531 DoPrintInterfaceChange = SK_FALSE;
4532 SkDrvInitAdapter(pAc, 1); /* second device */
4537 /*****************************************************************************
4539 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4542 * This function parses the PCI slot name information string and will
4543 * retrieve the devcie number out of it. The slot_name maintianed by
4544 * linux is in the form of '02:0a.0', whereas the first two characters
4545 * represent the bus number in hex (in the sample above this is
4546 * pci bus 0x02) and the next two characters the device number (0x0a).
4549 * SK_U32: The device number from the PCI slot name
4552 static SK_U32 ParseDeviceNbrFromSlotName(
4553 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4555 char *CurrCharPos = (char *) SlotName;
4556 int FirstNibble = -1;
4557 int SecondNibble = -1;
4560 while (*CurrCharPos != '\0') {
4561 if (*CurrCharPos == ':') {
4562 while (*CurrCharPos != '.') {
4564 if ( (*CurrCharPos >= '0') &&
4565 (*CurrCharPos <= '9')) {
4566 if (FirstNibble == -1) {
4567 /* dec. value for '0' */
4568 FirstNibble = *CurrCharPos - 48;
4570 SecondNibble = *CurrCharPos - 48;
4572 } else if ( (*CurrCharPos >= 'a') &&
4573 (*CurrCharPos <= 'f') ) {
4574 if (FirstNibble == -1) {
4575 FirstNibble = *CurrCharPos - 87;
4577 SecondNibble = *CurrCharPos - 87;
4584 Result = FirstNibble;
4585 Result = Result << 4; /* first nibble is higher one */
4586 Result = Result | SecondNibble;
4588 CurrCharPos++; /* next character */
4593 /****************************************************************************
4595 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4596 * called if Diag attaches to that card)
4599 * Close initialized adapter.
4603 * error code - on error
4605 static int SkDrvDeInitAdapter(
4606 SK_AC *pAC, /* pointer to adapter context */
4607 int devNbr) /* what device is to be handled */
4609 struct SK_NET_DEVICE *dev;
4611 dev = pAC->dev[devNbr];
4613 /* On Linux 2.6 the network driver does NOT mess with reference
4614 ** counts. The driver MUST be able to be unloaded at any time
4615 ** due to the possibility of hotplug.
4617 if (SkGeClose(dev) != 0) {
4622 } /* SkDrvDeInitAdapter() */
4624 /****************************************************************************
4626 * SkDrvInitAdapter - Initialize adapter (this function is only
4627 * called if Diag deattaches from that card)
4630 * Close initialized adapter.
4634 * error code - on error
4636 static int SkDrvInitAdapter(
4637 SK_AC *pAC, /* pointer to adapter context */
4638 int devNbr) /* what device is to be handled */
4640 struct SK_NET_DEVICE *dev;
4642 dev = pAC->dev[devNbr];
4644 if (SkGeOpen(dev) != 0) {
4649 ** Use correct MTU size and indicate to kernel TX queue can be started
4651 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4656 } /* SkDrvInitAdapter */
4661 /****************************************************************************/
4662 /* "debug only" section *****************************************************/
4663 /****************************************************************************/
4666 /*****************************************************************************
4668 * DumpMsg - print a frame
4671 * This function prints frames to the system logfile/to the console.
4676 static void DumpMsg(struct sk_buff *skb, char *str)
4681 printk("DumpMsg(): NULL-Message\n");
4685 if (skb->data == NULL) {
4686 printk("DumpMsg(): Message empty\n");
4694 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4696 DumpData((char *)skb->data, msglen);
4698 printk("------- End of message ---------\n");
4703 /*****************************************************************************
4705 * DumpData - print a data area
4708 * This function prints a area of data to the system logfile/to the
4714 static void DumpData(char *p, int size)
4718 char hex_buffer[180];
4719 char asc_buffer[180];
4720 char HEXCHAR[] = "0123456789ABCDEF";
4726 for (i=0; i < size; ) {
4727 if (*p >= '0' && *p <='z')
4728 asc_buffer[addr] = *p;
4730 asc_buffer[addr] = '.';
4732 asc_buffer[addr] = 0;
4733 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4735 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4737 hex_buffer[haddr] = ' ';
4739 hex_buffer[haddr] = 0;
4743 printk("%s %s\n", hex_buffer, asc_buffer);
4751 /*****************************************************************************
4753 * DumpLong - print a data area as long values
4756 * This function prints a area of data to the system logfile/to the
4762 static void DumpLong(char *pc, int size)
4766 char hex_buffer[180];
4767 char asc_buffer[180];
4768 char HEXCHAR[] = "0123456789ABCDEF";
4777 for (i=0; i < size; ) {
4779 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4781 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4783 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4785 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4787 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4789 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4791 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4793 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4795 hex_buffer[haddr] = ' ';
4797 hex_buffer[haddr] = 0;
4801 printk("%4x %s\n", (i-8)*4, hex_buffer);
4805 printk("------------------------\n");
4810 static int __devinit skge_probe_one(struct pci_dev *pdev,
4811 const struct pci_device_id *ent)
4814 DEV_NET *pNet = NULL;
4815 struct net_device *dev = NULL;
4816 static int boards_found = 0;
4817 int error = -ENODEV;
4819 if (pci_enable_device(pdev))
4822 /* Configure DMA attributes. */
4823 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4824 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4825 goto out_disable_device;
4828 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4829 printk(KERN_ERR "Unable to allocate etherdev "
4831 goto out_disable_device;
4834 pNet = netdev_priv(dev);
4835 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4837 printk(KERN_ERR "Unable to allocate adapter "
4839 goto out_free_netdev;
4842 memset(pNet->pAC, 0, sizeof(SK_AC));
4845 pAC->PciDevId = pdev->device;
4848 sprintf(pAC->Name, "SysKonnect SK-98xx");
4849 pAC->CheckQueue = SK_FALSE;
4853 dev->irq = pdev->irq;
4854 error = SkGeInitPCI(pAC);
4856 printk("SKGE: PCI setup failed: %i\n", error);
4857 goto out_free_netdev;
4860 SET_MODULE_OWNER(dev);
4861 dev->open = &SkGeOpen;
4862 dev->stop = &SkGeClose;
4863 dev->hard_start_xmit = &SkGeXmit;
4864 dev->get_stats = &SkGeStats;
4865 dev->set_multicast_list = &SkGeSetRxMode;
4866 dev->set_mac_address = &SkGeSetMacAddr;
4867 dev->do_ioctl = &SkGeIoctl;
4868 dev->change_mtu = &SkGeChangeMtu;
4869 #ifdef CONFIG_NET_POLL_CONTROLLER
4870 dev->poll_controller = &SkGePollController;
4872 SET_NETDEV_DEV(dev, &pdev->dev);
4873 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4876 #ifdef USE_SK_TX_CHECKSUM
4877 if (pAC->ChipsetType) {
4878 /* Use only if yukon hardware */
4879 /* SK and ZEROCOPY - fly baby... */
4880 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4885 pAC->Index = boards_found++;
4887 if (SkGeBoardInit(dev, pAC))
4888 goto out_free_netdev;
4890 /* Register net device */
4891 if (register_netdev(dev)) {
4892 printk(KERN_ERR "SKGE: Could not register device.\n");
4893 goto out_free_resources;
4896 /* Print adapter specific string from vpd */
4898 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4900 /* Print configuration settings */
4901 printk(" PrefPort:%c RlmtMode:%s\n",
4902 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4903 (pAC->RlmtMode==0) ? "Check Link State" :
4904 ((pAC->RlmtMode==1) ? "Check Link State" :
4905 ((pAC->RlmtMode==3) ? "Check Local Port" :
4906 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4907 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4909 SkGeYellowLED(pAC, pAC->IoBase, 1);
4911 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4912 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4914 SkGeProcCreate(dev);
4921 /* More then one port found */
4922 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4923 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4924 printk(KERN_ERR "Unable to allocate etherdev "
4930 pNet = netdev_priv(dev);
4937 dev->open = &SkGeOpen;
4938 dev->stop = &SkGeClose;
4939 dev->hard_start_xmit = &SkGeXmit;
4940 dev->get_stats = &SkGeStats;
4941 dev->set_multicast_list = &SkGeSetRxMode;
4942 dev->set_mac_address = &SkGeSetMacAddr;
4943 dev->do_ioctl = &SkGeIoctl;
4944 dev->change_mtu = &SkGeChangeMtu;
4945 SET_NETDEV_DEV(dev, &pdev->dev);
4946 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4949 #ifdef USE_SK_TX_CHECKSUM
4950 if (pAC->ChipsetType) {
4951 /* SG and ZEROCOPY - fly baby... */
4952 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4957 if (register_netdev(dev)) {
4958 printk(KERN_ERR "SKGE: Could not register device.\n");
4960 pAC->dev[1] = pAC->dev[0];
4962 SkGeProcCreate(dev);
4963 memcpy(&dev->dev_addr,
4964 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4965 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4967 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4968 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4972 /* Save the hardware revision */
4973 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4974 (pAC->GIni.GIPciHwRev & 0x0F);
4976 /* Set driver globals */
4977 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4978 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4980 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4981 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4983 pci_set_drvdata(pdev, dev);
4991 pci_disable_device(pdev);
4996 static void __devexit skge_remove_one(struct pci_dev *pdev)
4998 struct net_device *dev = pci_get_drvdata(pdev);
4999 DEV_NET *pNet = netdev_priv(dev);
5000 SK_AC *pAC = pNet->pAC;
5001 struct net_device *otherdev = pAC->dev[1];
5003 SkGeProcRemove(dev);
5004 unregister_netdev(dev);
5005 if (otherdev != dev)
5006 SkGeProcRemove(otherdev);
5008 SkGeYellowLED(pAC, pAC->IoBase, 0);
5010 if (pAC->BoardLevel == SK_INIT_RUN) {
5012 unsigned long Flags;
5014 /* board is still alive */
5015 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5016 EvPara.Para32[0] = 0;
5017 EvPara.Para32[1] = -1;
5018 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5019 EvPara.Para32[0] = 1;
5020 EvPara.Para32[1] = -1;
5021 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5022 SkEventDispatcher(pAC, pAC->IoBase);
5023 /* disable interrupts */
5024 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5025 SkGeDeInit(pAC, pAC->IoBase);
5026 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5027 pAC->BoardLevel = SK_INIT_DATA;
5028 /* We do NOT check here, if IRQ was pending, of course*/
5031 if (pAC->BoardLevel == SK_INIT_IO) {
5032 /* board is still alive */
5033 SkGeDeInit(pAC, pAC->IoBase);
5034 pAC->BoardLevel = SK_INIT_DATA;
5039 if (otherdev != dev)
5040 free_netdev(otherdev);
5045 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5047 struct net_device *dev = pci_get_drvdata(pdev);
5048 DEV_NET *pNet = netdev_priv(dev);
5049 SK_AC *pAC = pNet->pAC;
5050 struct net_device *otherdev = pAC->dev[1];
5052 if (netif_running(dev)) {
5053 netif_carrier_off(dev);
5054 DoPrintInterfaceChange = SK_FALSE;
5055 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5056 netif_device_detach(dev);
5058 if (otherdev != dev) {
5059 if (netif_running(otherdev)) {
5060 netif_carrier_off(otherdev);
5061 DoPrintInterfaceChange = SK_FALSE;
5062 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5063 netif_device_detach(otherdev);
5067 pci_save_state(pdev);
5068 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5069 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5070 free_irq(dev->irq, dev);
5072 pci_disable_device(pdev);
5073 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5078 static int skge_resume(struct pci_dev *pdev)
5080 struct net_device *dev = pci_get_drvdata(pdev);
5081 DEV_NET *pNet = netdev_priv(dev);
5082 SK_AC *pAC = pNet->pAC;
5083 struct net_device *otherdev = pAC->dev[1];
5086 pci_set_power_state(pdev, PCI_D0);
5087 pci_restore_state(pdev);
5088 pci_enable_device(pdev);
5089 pci_set_master(pdev);
5090 if (pAC->GIni.GIMacsFound == 2)
5091 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5093 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5095 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5096 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5098 pci_disable_device(pdev);
5102 netif_device_attach(dev);
5103 if (netif_running(dev)) {
5104 DoPrintInterfaceChange = SK_FALSE;
5105 SkDrvInitAdapter(pAC, 0); /* first device */
5107 if (otherdev != dev) {
5108 netif_device_attach(otherdev);
5109 if (netif_running(otherdev)) {
5110 DoPrintInterfaceChange = SK_FALSE;
5111 SkDrvInitAdapter(pAC, 1); /* second device */
5118 #define skge_suspend NULL
5119 #define skge_resume NULL
5122 static struct pci_device_id skge_pci_tbl[] = {
5123 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5124 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5125 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5126 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5127 /* DLink card does not have valid VPD so this driver gags
5128 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5130 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5131 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5132 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5133 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5134 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5138 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5140 static struct pci_driver skge_driver = {
5142 .id_table = skge_pci_tbl,
5143 .probe = skge_probe_one,
5144 .remove = __devexit_p(skge_remove_one),
5145 .suspend = skge_suspend,
5146 .resume = skge_resume,
5149 static int __init skge_init(void)
5153 pSkRootDir = proc_mkdir(SKRootName, NULL);
5155 pSkRootDir->owner = THIS_MODULE;
5157 error = pci_register_driver(&skge_driver);
5159 remove_proc_entry(SKRootName, NULL);
5163 static void __exit skge_exit(void)
5165 pci_unregister_driver(&skge_driver);
5166 remove_proc_entry(SKRootName, NULL);
5170 module_init(skge_init);
5171 module_exit(skge_exit);