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/in.h>
111 #include <linux/module.h>
112 #include <linux/moduleparam.h>
113 #include <linux/init.h>
114 #include <linux/dma-mapping.h>
115 #include <linux/ip.h>
116 #include <linux/mii.h>
118 #include "h/skdrv1st.h"
119 #include "h/skdrv2nd.h"
121 /*******************************************************************************
125 ******************************************************************************/
127 /* for debuging on x86 only */
128 /* #define BREAKPOINT() asm(" int $3"); */
130 /* use the transmit hw checksum driver functionality */
131 #define USE_SK_TX_CHECKSUM
133 /* use the receive hw checksum driver functionality */
134 #define USE_SK_RX_CHECKSUM
136 /* use the scatter-gather functionality with sendfile() */
139 /* use of a transmit complete interrupt */
140 #define USE_TX_COMPLETE
143 * threshold for copying small receive frames
144 * set to 0 to avoid copying, set to 9001 to copy all frames
146 #define SK_COPY_THRESHOLD 50
148 /* number of adapters that can be configured via command line params */
149 #define SK_MAX_CARD_PARAM 16
154 * use those defines for a compile-in version of the driver instead
155 * of command line parameters
157 // #define LINK_SPEED_A {"Auto", }
158 // #define LINK_SPEED_B {"Auto", }
159 // #define AUTO_NEG_A {"Sense", }
160 // #define AUTO_NEG_B {"Sense", }
161 // #define DUP_CAP_A {"Both", }
162 // #define DUP_CAP_B {"Both", }
163 // #define FLOW_CTRL_A {"SymOrRem", }
164 // #define FLOW_CTRL_B {"SymOrRem", }
165 // #define ROLE_A {"Auto", }
166 // #define ROLE_B {"Auto", }
167 // #define PREF_PORT {"A", }
168 // #define CON_TYPE {"Auto", }
169 // #define RLMT_MODE {"CheckLinkState", }
171 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
172 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
173 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
177 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
178 SK_DUP_LED_NORMAL | \
182 /* Isr return value */
183 #define SkIsrRetVar irqreturn_t
184 #define SkIsrRetNone IRQ_NONE
185 #define SkIsrRetHandled IRQ_HANDLED
188 /*******************************************************************************
190 * Local Function Prototypes
192 ******************************************************************************/
194 static void FreeResources(struct SK_NET_DEVICE *dev);
195 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
196 static SK_BOOL BoardAllocMem(SK_AC *pAC);
197 static void BoardFreeMem(SK_AC *pAC);
198 static void BoardInitMem(SK_AC *pAC);
199 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
200 static SkIsrRetVar SkGeIsr(int irq, void *dev_id);
201 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id);
202 static int SkGeOpen(struct SK_NET_DEVICE *dev);
203 static int SkGeClose(struct SK_NET_DEVICE *dev);
204 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
205 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
206 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
207 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
208 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
209 static void GetConfiguration(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 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
239 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
240 extern void SkDimStartModerationTimer(SK_AC *pAC);
241 extern void SkDimModerate(SK_AC *pAC);
242 extern void SkGeBlinkTimer(unsigned long data);
245 static void DumpMsg(struct sk_buff*, char*);
246 static void DumpData(char*, int);
247 static void DumpLong(char*, int);
250 /* global variables *********************************************************/
251 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
252 extern const struct ethtool_ops SkGeEthtoolOps;
254 /* local variables **********************************************************/
255 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
256 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
258 /*****************************************************************************
260 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
263 * This routine writes a 32 bit value to the pci configuration
267 * 0 - indicate everything worked ok.
268 * != 0 - error indication
270 static inline int SkPciWriteCfgDWord(
271 SK_AC *pAC, /* Adapter Control structure pointer */
272 int PciAddr, /* PCI register address */
273 SK_U32 Val) /* pointer to store the read value */
275 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
277 } /* SkPciWriteCfgDWord */
279 /*****************************************************************************
281 * SkGeInitPCI - Init the PCI resources
284 * This function initialize the PCI resources and IO
287 * 0 - indicate everything worked ok.
288 * != 0 - error indication
290 static __devinit int SkGeInitPCI(SK_AC *pAC)
292 struct SK_NET_DEVICE *dev = pAC->dev[0];
293 struct pci_dev *pdev = pAC->PciDev;
296 dev->mem_start = pci_resource_start (pdev, 0);
297 pci_set_master(pdev);
299 retval = pci_request_regions(pdev, "sk98lin");
305 * On big endian machines, we use the adapter's aibility of
306 * reading the descriptors as big endian.
310 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
311 our2 |= PCI_REV_DESC;
312 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
317 * Remap the regs into kernel space.
319 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
328 pci_release_regions(pdev);
334 /*****************************************************************************
336 * FreeResources - release resources allocated for adapter
339 * This function releases the IRQ, unmaps the IO and
340 * frees the desriptor ring.
345 static void FreeResources(struct SK_NET_DEVICE *dev)
351 pNet = netdev_priv(dev);
353 AllocFlag = pAC->AllocFlag;
355 pci_release_regions(pAC->PciDev);
357 if (AllocFlag & SK_ALLOC_IRQ) {
358 free_irq(dev->irq, dev);
361 iounmap(pAC->IoBase);
363 if (pAC->pDescrMem) {
367 } /* FreeResources */
369 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
370 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
371 MODULE_LICENSE("GPL");
374 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
376 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
380 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
382 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
386 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
388 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
392 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
394 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
398 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
400 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
404 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
406 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
410 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
412 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
416 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
418 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
422 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
424 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
428 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
430 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
434 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
436 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
440 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
442 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
446 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
448 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
451 static int IntsPerSec[SK_MAX_CARD_PARAM];
452 static char *Moderation[SK_MAX_CARD_PARAM];
453 static char *ModerationMask[SK_MAX_CARD_PARAM];
454 static char *AutoSizing[SK_MAX_CARD_PARAM];
455 static char *Stats[SK_MAX_CARD_PARAM];
457 module_param_array(Speed_A, charp, NULL, 0);
458 module_param_array(Speed_B, charp, NULL, 0);
459 module_param_array(AutoNeg_A, charp, NULL, 0);
460 module_param_array(AutoNeg_B, charp, NULL, 0);
461 module_param_array(DupCap_A, charp, NULL, 0);
462 module_param_array(DupCap_B, charp, NULL, 0);
463 module_param_array(FlowCtrl_A, charp, NULL, 0);
464 module_param_array(FlowCtrl_B, charp, NULL, 0);
465 module_param_array(Role_A, charp, NULL, 0);
466 module_param_array(Role_B, charp, NULL, 0);
467 module_param_array(ConType, charp, NULL, 0);
468 module_param_array(PrefPort, charp, NULL, 0);
469 module_param_array(RlmtMode, charp, NULL, 0);
470 /* used for interrupt moderation */
471 module_param_array(IntsPerSec, int, NULL, 0);
472 module_param_array(Moderation, charp, NULL, 0);
473 module_param_array(Stats, charp, NULL, 0);
474 module_param_array(ModerationMask, charp, NULL, 0);
475 module_param_array(AutoSizing, charp, NULL, 0);
477 /*****************************************************************************
479 * SkGeBoardInit - do level 0 and 1 initialization
482 * This function prepares the board hardware for running. The desriptor
483 * ring is set up, the IRQ is allocated and the configuration settings
487 * 0, if everything is ok
490 static int __devinit SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
494 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
495 char *VerStr = VER_STRING;
496 int Ret; /* return code of request_irq */
499 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
500 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
501 for (i=0; i<SK_MAX_MACS; i++) {
502 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
503 pAC->TxPort[i][0].PortIndex = i;
504 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
505 pAC->RxPort[i].PortIndex = i;
508 /* Initialize the mutexes */
509 for (i=0; i<SK_MAX_MACS; i++) {
510 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
511 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
513 spin_lock_init(&pAC->SlowPathLock);
515 /* setup phy_id blink timer */
516 pAC->BlinkTimer.function = SkGeBlinkTimer;
517 pAC->BlinkTimer.data = (unsigned long) dev;
518 init_timer(&pAC->BlinkTimer);
520 /* level 0 init common modules here */
522 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
523 /* Does a RESET on board ...*/
524 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
525 printk("HWInit (0) failed.\n");
526 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
529 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
530 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
531 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
532 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
533 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
534 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
536 pAC->BoardLevel = SK_INIT_DATA;
537 pAC->RxBufSize = ETH_BUF_SIZE;
539 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
540 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
542 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
544 /* level 1 init common modules here (HW init) */
545 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
546 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
547 printk("sk98lin: HWInit (1) failed.\n");
548 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
551 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
552 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
553 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
554 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
555 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
556 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
558 /* Set chipset type support */
559 pAC->ChipsetType = 0;
560 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
561 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
562 pAC->ChipsetType = 1;
565 GetConfiguration(pAC);
566 if (pAC->RlmtNets == 2) {
567 pAC->GIni.GIPortUsage = SK_MUL_LINK;
570 pAC->BoardLevel = SK_INIT_IO;
571 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
573 if (pAC->GIni.GIMacsFound == 2) {
574 Ret = request_irq(dev->irq, SkGeIsr, IRQF_SHARED, "sk98lin", dev);
575 } else if (pAC->GIni.GIMacsFound == 1) {
576 Ret = request_irq(dev->irq, SkGeIsrOnePort, IRQF_SHARED,
579 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
580 pAC->GIni.GIMacsFound);
585 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
589 pAC->AllocFlag |= SK_ALLOC_IRQ;
591 /* Alloc memory for this board (Mem for RxD/TxD) : */
592 if(!BoardAllocMem(pAC)) {
593 printk("No memory for descriptor rings.\n");
598 /* tschilling: New common function with minimum size check. */
600 if (pAC->RlmtNets == 2) {
604 if (SkGeInitAssignRamToQueues(
609 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
614 } /* SkGeBoardInit */
617 /*****************************************************************************
619 * BoardAllocMem - allocate the memory for the descriptor rings
622 * This function allocates the memory for all descriptor rings.
623 * Each ring is aligned for the desriptor alignment and no ring
624 * has a 4 GByte boundary in it (because the upper 32 bit must
625 * be constant for all descriptiors in one rings).
628 * SK_TRUE, if all memory could be allocated
631 static __devinit SK_BOOL BoardAllocMem(SK_AC *pAC)
633 caddr_t pDescrMem; /* pointer to descriptor memory area */
634 size_t AllocLength; /* length of complete descriptor area */
635 int i; /* loop counter */
636 unsigned long BusAddr;
639 /* rings plus one for alignment (do not cross 4 GB boundary) */
640 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
641 #if (BITS_PER_LONG == 32)
642 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
644 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
648 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
651 if (pDescrMem == NULL) {
654 pAC->pDescrMem = pDescrMem;
655 BusAddr = (unsigned long) pAC->pDescrMemDMA;
657 /* Descriptors need 8 byte alignment, and this is ensured
658 * by pci_alloc_consistent.
660 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
661 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
662 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
663 i, (unsigned long) pDescrMem,
665 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
666 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
667 pDescrMem += TX_RING_SIZE;
668 BusAddr += TX_RING_SIZE;
670 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
671 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
672 i, (unsigned long) pDescrMem,
673 (unsigned long)BusAddr));
674 pAC->RxPort[i].pRxDescrRing = pDescrMem;
675 pAC->RxPort[i].VRxDescrRing = BusAddr;
676 pDescrMem += RX_RING_SIZE;
677 BusAddr += RX_RING_SIZE;
681 } /* BoardAllocMem */
684 /****************************************************************************
686 * BoardFreeMem - reverse of BoardAllocMem
689 * Free all memory allocated in BoardAllocMem: adapter context,
690 * descriptor rings, locks.
694 static void BoardFreeMem(
697 size_t AllocLength; /* length of complete descriptor area */
699 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
701 #if (BITS_PER_LONG == 32)
702 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
704 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
708 pci_free_consistent(pAC->PciDev, AllocLength,
709 pAC->pDescrMem, pAC->pDescrMemDMA);
710 pAC->pDescrMem = NULL;
714 /*****************************************************************************
716 * BoardInitMem - initiate the descriptor rings
719 * This function sets the descriptor rings up in memory.
720 * The adapter is initialized with the descriptor start addresses.
724 static __devinit void BoardInitMem(SK_AC *pAC)
726 int i; /* loop counter */
727 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
728 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
730 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
733 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
734 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
735 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
736 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
738 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
741 pAC->TxPort[i][0].pTxDescrRing,
742 pAC->TxPort[i][0].VTxDescrRing,
743 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
744 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
745 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
746 &pAC->TxPort[i][0].TxdRingFree,
750 pAC->RxPort[i].pRxDescrRing,
751 pAC->RxPort[i].VRxDescrRing,
752 &pAC->RxPort[i].pRxdRingHead,
753 &pAC->RxPort[i].pRxdRingTail,
754 &pAC->RxPort[i].pRxdRingPrev,
755 &pAC->RxPort[i].RxdRingFree,
761 /*****************************************************************************
763 * SetupRing - create one descriptor ring
766 * This function creates one descriptor ring in the given memory area.
767 * The head, tail and number of free descriptors in the ring are set.
772 static void SetupRing(
774 void *pMemArea, /* a pointer to the memory area for the ring */
775 uintptr_t VMemArea, /* the virtual bus address of the memory area */
776 RXD **ppRingHead, /* address where the head should be written */
777 RXD **ppRingTail, /* address where the tail should be written */
778 RXD **ppRingPrev, /* address where the tail should be written */
779 int *pRingFree, /* address where the # of free descr. goes */
780 SK_BOOL IsTx) /* flag: is this a tx ring */
782 int i; /* loop counter */
783 int DescrSize; /* the size of a descriptor rounded up to alignment*/
784 int DescrNum; /* number of descriptors per ring */
785 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
786 RXD *pNextDescr; /* pointer to the next descriptor */
787 RXD *pPrevDescr; /* pointer to the previous descriptor */
788 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
790 if (IsTx == SK_TRUE) {
791 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
793 DescrNum = TX_RING_SIZE / DescrSize;
795 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
797 DescrNum = RX_RING_SIZE / DescrSize;
800 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
801 ("Descriptor size: %d Descriptor Number: %d\n",
802 DescrSize,DescrNum));
804 pDescr = (RXD*) pMemArea;
806 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
807 VNextDescr = VMemArea + DescrSize;
808 for(i=0; i<DescrNum; i++) {
809 /* set the pointers right */
810 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
811 pDescr->pNextRxd = pNextDescr;
812 if (!IsTx) pDescr->TcpSumStarts = ETH_HLEN << 16 | ETH_HLEN;
814 /* advance one step */
817 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
818 VNextDescr += DescrSize;
820 pPrevDescr->pNextRxd = (RXD*) pMemArea;
821 pPrevDescr->VNextRxd = VMemArea;
822 pDescr = (RXD*) pMemArea;
823 *ppRingHead = (RXD*) pMemArea;
824 *ppRingTail = *ppRingHead;
825 *ppRingPrev = pPrevDescr;
826 *pRingFree = DescrNum;
830 /*****************************************************************************
832 * PortReInitBmu - re-initiate the descriptor rings for one port
835 * This function reinitializes the descriptor rings of one port
836 * in memory. The port must be stopped before.
837 * The HW is initialized with the descriptor start addresses.
842 static void PortReInitBmu(
843 SK_AC *pAC, /* pointer to adapter context */
844 int PortIndex) /* index of the port for which to re-init */
846 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
849 /* set address of first descriptor of ring in BMU */
850 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
851 (uint32_t)(((caddr_t)
852 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
853 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
854 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
856 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
857 (uint32_t)(((caddr_t)
858 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
859 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
860 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
861 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
862 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
863 pAC->RxPort[PortIndex].pRxDescrRing +
864 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
865 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
866 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
867 pAC->RxPort[PortIndex].pRxDescrRing +
868 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
869 } /* PortReInitBmu */
872 /****************************************************************************
874 * SkGeIsr - handle adapter interrupts
877 * The interrupt routine is called when the network adapter
878 * generates an interrupt. It may also be called if another device
879 * shares this interrupt vector with the driver.
884 static SkIsrRetVar SkGeIsr(int irq, void *dev_id)
886 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
889 SK_U32 IntSrc; /* interrupts source register contents */
891 pNet = netdev_priv(dev);
895 * Check and process if its our interrupt
897 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
902 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
903 #if 0 /* software irq currently not used */
904 if (IntSrc & IS_IRQ_SW) {
905 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
906 SK_DBGCAT_DRV_INT_SRC,
910 if (IntSrc & IS_R1_F) {
911 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
912 SK_DBGCAT_DRV_INT_SRC,
914 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
915 SK_PNMI_CNT_RX_INTR(pAC, 0);
917 if (IntSrc & IS_R2_F) {
918 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
919 SK_DBGCAT_DRV_INT_SRC,
921 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
922 SK_PNMI_CNT_RX_INTR(pAC, 1);
924 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
925 if (IntSrc & IS_XA1_F) {
926 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
927 SK_DBGCAT_DRV_INT_SRC,
928 ("EOF AS TX1 IRQ\n"));
929 SK_PNMI_CNT_TX_INTR(pAC, 0);
930 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
931 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
932 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
934 if (IntSrc & IS_XA2_F) {
935 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
936 SK_DBGCAT_DRV_INT_SRC,
937 ("EOF AS TX2 IRQ\n"));
938 SK_PNMI_CNT_TX_INTR(pAC, 1);
939 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
940 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
941 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
943 #if 0 /* only if sync. queues used */
944 if (IntSrc & IS_XS1_F) {
945 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
946 SK_DBGCAT_DRV_INT_SRC,
947 ("EOF SY TX1 IRQ\n"));
948 SK_PNMI_CNT_TX_INTR(pAC, 1);
949 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
950 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
951 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
952 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
954 if (IntSrc & IS_XS2_F) {
955 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
956 SK_DBGCAT_DRV_INT_SRC,
957 ("EOF SY TX2 IRQ\n"));
958 SK_PNMI_CNT_TX_INTR(pAC, 1);
959 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
960 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
961 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
962 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
967 /* do all IO at once */
968 if (IntSrc & IS_R1_F)
969 ClearAndStartRx(pAC, 0);
970 if (IntSrc & IS_R2_F)
971 ClearAndStartRx(pAC, 1);
972 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
973 if (IntSrc & IS_XA1_F)
974 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
975 if (IntSrc & IS_XA2_F)
976 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
978 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
979 } /* while (IntSrc & IRQ_MASK != 0) */
981 IntSrc &= pAC->GIni.GIValIrqMask;
982 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
983 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
984 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
985 pAC->CheckQueue = SK_FALSE;
986 spin_lock(&pAC->SlowPathLock);
987 if (IntSrc & SPECIAL_IRQS)
988 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
990 SkEventDispatcher(pAC, pAC->IoBase);
991 spin_unlock(&pAC->SlowPathLock);
994 * do it all again is case we cleared an interrupt that
995 * came in after handling the ring (OUTs may be delayed
996 * in hardware buffers, but are through after IN)
998 * rroesler: has been commented out and shifted to
999 * SkGeDrvEvent(), because it is timer
1002 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1003 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1006 if (pAC->CheckQueue) {
1007 pAC->CheckQueue = SK_FALSE;
1008 spin_lock(&pAC->SlowPathLock);
1009 SkEventDispatcher(pAC, pAC->IoBase);
1010 spin_unlock(&pAC->SlowPathLock);
1013 /* IRQ is processed - Enable IRQs again*/
1014 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1016 return SkIsrRetHandled;
1020 /****************************************************************************
1022 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1025 * The interrupt routine is called when the network adapter
1026 * generates an interrupt. It may also be called if another device
1027 * shares this interrupt vector with the driver.
1028 * This is the same as above, but handles only one port.
1033 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id)
1035 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1038 SK_U32 IntSrc; /* interrupts source register contents */
1040 pNet = netdev_priv(dev);
1044 * Check and process if its our interrupt
1046 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1048 return SkIsrRetNone;
1051 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1052 #if 0 /* software irq currently not used */
1053 if (IntSrc & IS_IRQ_SW) {
1054 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1055 SK_DBGCAT_DRV_INT_SRC,
1056 ("Software IRQ\n"));
1059 if (IntSrc & IS_R1_F) {
1060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1061 SK_DBGCAT_DRV_INT_SRC,
1063 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1064 SK_PNMI_CNT_RX_INTR(pAC, 0);
1066 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1067 if (IntSrc & IS_XA1_F) {
1068 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1069 SK_DBGCAT_DRV_INT_SRC,
1070 ("EOF AS TX1 IRQ\n"));
1071 SK_PNMI_CNT_TX_INTR(pAC, 0);
1072 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1073 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1074 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1076 #if 0 /* only if sync. queues used */
1077 if (IntSrc & IS_XS1_F) {
1078 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1079 SK_DBGCAT_DRV_INT_SRC,
1080 ("EOF SY TX1 IRQ\n"));
1081 SK_PNMI_CNT_TX_INTR(pAC, 0);
1082 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1083 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1084 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1085 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1090 /* do all IO at once */
1091 if (IntSrc & IS_R1_F)
1092 ClearAndStartRx(pAC, 0);
1093 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1094 if (IntSrc & IS_XA1_F)
1095 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1097 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1098 } /* while (IntSrc & IRQ_MASK != 0) */
1100 IntSrc &= pAC->GIni.GIValIrqMask;
1101 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1102 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1103 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1104 pAC->CheckQueue = SK_FALSE;
1105 spin_lock(&pAC->SlowPathLock);
1106 if (IntSrc & SPECIAL_IRQS)
1107 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1109 SkEventDispatcher(pAC, pAC->IoBase);
1110 spin_unlock(&pAC->SlowPathLock);
1113 * do it all again is case we cleared an interrupt that
1114 * came in after handling the ring (OUTs may be delayed
1115 * in hardware buffers, but are through after IN)
1117 * rroesler: has been commented out and shifted to
1118 * SkGeDrvEvent(), because it is timer
1121 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1124 /* IRQ is processed - Enable IRQs again*/
1125 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1127 return SkIsrRetHandled;
1128 } /* SkGeIsrOnePort */
1130 #ifdef CONFIG_NET_POLL_CONTROLLER
1131 /****************************************************************************
1133 * SkGePollController - polling receive, for netconsole
1136 * Polling receive - used by netconsole and other diagnostic tools
1137 * to allow network i/o with interrupts disabled.
1141 static void SkGePollController(struct net_device *dev)
1143 disable_irq(dev->irq);
1144 SkGeIsr(dev->irq, dev);
1145 enable_irq(dev->irq);
1149 /****************************************************************************
1151 * SkGeOpen - handle start of initialized adapter
1154 * This function starts the initialized adapter.
1155 * The board level variable is set and the adapter is
1156 * brought to full functionality.
1157 * The device flags are set for operation.
1158 * Do all necessary level 2 initialization, enable interrupts and
1159 * give start command to RLMT.
1165 static int SkGeOpen(
1166 struct SK_NET_DEVICE *dev)
1170 unsigned long Flags; /* for spin lock */
1172 SK_EVPARA EvPara; /* an event parameter union */
1174 pNet = netdev_priv(dev);
1177 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1178 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1180 #ifdef SK_DIAG_SUPPORT
1181 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1182 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1183 return (-1); /* still in use by diag; deny actions */
1188 /* Set blink mode */
1189 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1190 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1192 if (pAC->BoardLevel == SK_INIT_DATA) {
1193 /* level 1 init common modules here */
1194 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1195 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1198 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1199 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1200 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1201 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1202 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1203 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1204 pAC->BoardLevel = SK_INIT_IO;
1207 if (pAC->BoardLevel != SK_INIT_RUN) {
1208 /* tschilling: Level 2 init modules here, check return value. */
1209 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1210 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1213 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1214 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1215 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1216 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1217 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1218 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1219 pAC->BoardLevel = SK_INIT_RUN;
1222 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1223 /* Enable transmit descriptor polling. */
1224 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1225 FillRxRing(pAC, &pAC->RxPort[i]);
1227 SkGeYellowLED(pAC, pAC->IoBase, 1);
1229 StartDrvCleanupTimer(pAC);
1230 SkDimEnableModerationIfNeeded(pAC);
1231 SkDimDisplayModerationSettings(pAC);
1233 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1235 /* enable Interrupts */
1236 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1237 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1239 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1241 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1242 EvPara.Para32[0] = pAC->RlmtNets;
1243 EvPara.Para32[1] = -1;
1244 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1246 EvPara.Para32[0] = pAC->RlmtMode;
1247 EvPara.Para32[1] = 0;
1248 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1252 EvPara.Para32[0] = pNet->NetNr;
1253 EvPara.Para32[1] = -1;
1254 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1255 SkEventDispatcher(pAC, pAC->IoBase);
1256 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1261 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1262 ("SkGeOpen suceeded\n"));
1268 /****************************************************************************
1270 * SkGeClose - Stop initialized adapter
1273 * Close initialized adapter.
1277 * error code - on error
1279 static int SkGeClose(
1280 struct SK_NET_DEVICE *dev)
1286 unsigned long Flags; /* for spin lock */
1291 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1292 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1294 pNet = netdev_priv(dev);
1297 #ifdef SK_DIAG_SUPPORT
1298 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1299 if (pAC->DiagFlowCtrl == SK_FALSE) {
1301 ** notify that the interface which has been closed
1302 ** by operator interaction must not be started up
1303 ** again when the DIAG has finished.
1305 newPtrNet = netdev_priv(pAC->dev[0]);
1306 if (newPtrNet == pNet) {
1307 pAC->WasIfUp[0] = SK_FALSE;
1309 pAC->WasIfUp[1] = SK_FALSE;
1311 return 0; /* return to system everything is fine... */
1313 pAC->DiagFlowCtrl = SK_FALSE;
1318 netif_stop_queue(dev);
1320 if (pAC->RlmtNets == 1)
1321 PortIdx = pAC->ActivePort;
1323 PortIdx = pNet->NetNr;
1325 StopDrvCleanupTimer(pAC);
1328 * Clear multicast table, promiscuous mode ....
1330 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1331 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1334 if (pAC->MaxPorts == 1) {
1335 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1336 /* disable interrupts */
1337 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1338 EvPara.Para32[0] = pNet->NetNr;
1339 EvPara.Para32[1] = -1;
1340 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1341 SkEventDispatcher(pAC, pAC->IoBase);
1342 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1343 /* stop the hardware */
1344 SkGeDeInit(pAC, pAC->IoBase);
1345 pAC->BoardLevel = SK_INIT_DATA;
1346 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1349 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1350 EvPara.Para32[0] = pNet->NetNr;
1351 EvPara.Para32[1] = -1;
1352 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1353 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1354 SkEventDispatcher(pAC, pAC->IoBase);
1355 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1358 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1359 [TX_PRIO_LOW].TxDesRingLock, Flags);
1360 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1361 SK_STOP_ALL, SK_HARD_RST);
1362 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1363 [TX_PRIO_LOW].TxDesRingLock, Flags);
1366 if (pAC->RlmtNets == 1) {
1367 /* clear all descriptor rings */
1368 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1369 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1370 ClearRxRing(pAC, &pAC->RxPort[i]);
1371 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1374 /* clear port descriptor rings */
1375 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1376 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1377 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1380 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1381 ("SkGeClose: done "));
1383 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1384 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1385 sizeof(SK_PNMI_STRUCT_DATA));
1393 /*****************************************************************************
1395 * SkGeXmit - Linux frame transmit function
1398 * The system calls this function to send frames onto the wire.
1399 * It puts the frame in the tx descriptor ring. If the ring is
1400 * full then, the 'tbusy' flag is set.
1403 * 0, if everything is ok
1405 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1406 * allocated skb's) !!!
1408 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1412 int Rc; /* return code of XmitFrame */
1414 pNet = netdev_priv(dev);
1417 if ((!skb_shinfo(skb)->nr_frags) ||
1418 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1419 /* Don't activate scatter-gather and hardware checksum */
1421 if (pAC->RlmtNets == 2)
1424 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1429 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1432 /* scatter-gather and hardware TCP checksumming anabled*/
1433 if (pAC->RlmtNets == 2)
1436 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1441 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1445 /* Transmitter out of resources? */
1447 netif_stop_queue(dev);
1450 /* If not taken, give buffer ownership back to the
1456 dev->trans_start = jiffies;
1461 /*****************************************************************************
1463 * XmitFrame - fill one socket buffer into the transmit ring
1466 * This function puts a message into the transmit descriptor ring
1467 * if there is a descriptors left.
1468 * Linux skb's consist of only one continuous buffer.
1469 * The first step locks the ring. It is held locked
1470 * all time to avoid problems with SWITCH_../PORT_RESET.
1471 * Then the descriptoris allocated.
1472 * The second part is linking the buffer to the descriptor.
1473 * At the very last, the Control field of the descriptor
1474 * is made valid for the BMU and a start TX command is given
1478 * > 0 - on succes: the number of bytes in the message
1479 * = 0 - on resource shortage: this frame sent or dropped, now
1480 * the ring is full ( -> set tbusy)
1481 * < 0 - on failure: other problems ( -> return failure to upper layers)
1483 static int XmitFrame(
1484 SK_AC *pAC, /* pointer to adapter context */
1485 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1486 struct sk_buff *pMessage) /* pointer to send-message */
1488 TXD *pTxd; /* the rxd to fill */
1490 unsigned long Flags;
1492 int BytesSend = pMessage->len;
1494 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1496 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1497 #ifndef USE_TX_COMPLETE
1498 FreeTxDescriptors(pAC, pTxPort);
1500 if (pTxPort->TxdRingFree == 0) {
1502 ** no enough free descriptors in ring at the moment.
1503 ** Maybe free'ing some old one help?
1505 FreeTxDescriptors(pAC, pTxPort);
1506 if (pTxPort->TxdRingFree == 0) {
1507 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1508 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1509 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1510 SK_DBGCAT_DRV_TX_PROGRESS,
1511 ("XmitFrame failed\n"));
1513 ** the desired message can not be sent
1514 ** Because tbusy seems to be set, the message
1515 ** should not be freed here. It will be used
1516 ** by the scheduler of the ethernet handler
1523 ** If the passed socket buffer is of smaller MTU-size than 60,
1524 ** copy everything into new buffer and fill all bytes between
1525 ** the original packet end and the new packet end of 60 with 0x00.
1526 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1528 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1529 if (skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) {
1530 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1533 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1537 ** advance head counter behind descriptor needed for this frame,
1538 ** so that needed descriptor is reserved from that on. The next
1539 ** action will be to add the passed buffer to the TX-descriptor
1541 pTxd = pTxPort->pTxdRingHead;
1542 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1543 pTxPort->TxdRingFree--;
1546 DumpMsg(pMessage, "XmitFrame");
1550 ** First step is to map the data to be sent via the adapter onto
1551 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1552 ** and 2.6 need to use pci_map_page() for that mapping.
1554 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1555 virt_to_page(pMessage->data),
1556 ((unsigned long) pMessage->data & ~PAGE_MASK),
1559 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1560 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1561 pTxd->pMBuf = pMessage;
1563 if (pMessage->ip_summed == CHECKSUM_PARTIAL) {
1564 u16 hdrlen = pMessage->h.raw - pMessage->data;
1565 u16 offset = hdrlen + pMessage->csum_offset;
1567 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1568 (pAC->GIni.GIChipRev == 0) &&
1569 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1570 pTxd->TBControl = BMU_TCP_CHECK;
1572 pTxd->TBControl = BMU_UDP_CHECK;
1575 pTxd->TcpSumOfs = 0;
1576 pTxd->TcpSumSt = hdrlen;
1577 pTxd->TcpSumWr = offset;
1579 pTxd->TBControl |= BMU_OWN | BMU_STF |
1581 #ifdef USE_TX_COMPLETE
1586 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1588 #ifdef USE_TX_COMPLETE
1595 ** If previous descriptor already done, give TX start cmd
1597 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1598 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1599 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1603 ** after releasing the lock, the skb may immediately be free'd
1605 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1606 if (pTxPort->TxdRingFree != 0) {
1614 /*****************************************************************************
1616 * XmitFrameSG - fill one socket buffer into the transmit ring
1617 * (use SG and TCP/UDP hardware checksumming)
1620 * This function puts a message into the transmit descriptor ring
1621 * if there is a descriptors left.
1624 * > 0 - on succes: the number of bytes in the message
1625 * = 0 - on resource shortage: this frame sent or dropped, now
1626 * the ring is full ( -> set tbusy)
1627 * < 0 - on failure: other problems ( -> return failure to upper layers)
1629 static int XmitFrameSG(
1630 SK_AC *pAC, /* pointer to adapter context */
1631 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1632 struct sk_buff *pMessage) /* pointer to send-message */
1640 skb_frag_t *sk_frag;
1642 unsigned long Flags;
1645 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1646 #ifndef USE_TX_COMPLETE
1647 FreeTxDescriptors(pAC, pTxPort);
1649 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1650 FreeTxDescriptors(pAC, pTxPort);
1651 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1652 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1653 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1654 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1655 SK_DBGCAT_DRV_TX_PROGRESS,
1656 ("XmitFrameSG failed - Ring full\n"));
1657 /* this message can not be sent now */
1662 pTxd = pTxPort->pTxdRingHead;
1668 ** Map the first fragment (header) into the DMA-space
1670 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1671 virt_to_page(pMessage->data),
1672 ((unsigned long) pMessage->data & ~PAGE_MASK),
1673 skb_headlen(pMessage),
1676 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1677 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1680 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1682 if (pMessage->ip_summed == CHECKSUM_PARTIAL) {
1683 u16 hdrlen = pMessage->h.raw - pMessage->data;
1684 u16 offset = hdrlen + pMessage->csum_offset;
1686 Control = BMU_STFWD;
1689 ** We have to use the opcode for tcp here, because the
1690 ** opcode for udp is not working in the hardware yet
1693 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1694 (pAC->GIni.GIChipRev == 0) &&
1695 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1696 Control |= BMU_TCP_CHECK;
1698 Control |= BMU_UDP_CHECK;
1701 pTxd->TcpSumOfs = 0;
1702 pTxd->TcpSumSt = hdrlen;
1703 pTxd->TcpSumWr = offset;
1705 Control = BMU_CHECK | BMU_SW;
1707 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1709 pTxd = pTxd->pNextTxd;
1710 pTxPort->TxdRingFree--;
1711 BytesSend += skb_headlen(pMessage);
1714 ** Browse over all SG fragments and map each of them into the DMA space
1716 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1717 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1719 ** we already have the proper value in entry
1721 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1723 sk_frag->page_offset,
1727 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1728 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1729 pTxd->pMBuf = pMessage;
1731 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;
1734 ** Do we have the last fragment?
1736 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1737 #ifdef USE_TX_COMPLETE
1738 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1740 pTxd->TBControl |= BMU_EOF;
1742 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1745 pTxd = pTxd->pNextTxd;
1746 pTxPort->TxdRingFree--;
1747 BytesSend += sk_frag->size;
1751 ** If previous descriptor already done, give TX start cmd
1753 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1754 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1757 pTxPort->pTxdRingPrev = pTxdLst;
1758 pTxPort->pTxdRingHead = pTxd;
1760 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1762 if (pTxPort->TxdRingFree > 0) {
1769 /*****************************************************************************
1771 * FreeTxDescriptors - release descriptors from the descriptor ring
1774 * This function releases descriptors from a transmit ring if they
1775 * have been sent by the BMU.
1776 * If a descriptors is sent, it can be freed and the message can
1778 * The SOFTWARE controllable bit is used to prevent running around a
1779 * completely free ring for ever. If this bit is no set in the
1780 * frame (by XmitFrame), this frame has never been sent or is
1782 * The Tx descriptor ring lock must be held while calling this function !!!
1787 static void FreeTxDescriptors(
1788 SK_AC *pAC, /* pointer to the adapter context */
1789 TX_PORT *pTxPort) /* pointer to destination port structure */
1791 TXD *pTxd; /* pointer to the checked descriptor */
1792 TXD *pNewTail; /* pointer to 'end' of the ring */
1793 SK_U32 Control; /* TBControl field of descriptor */
1794 SK_U64 PhysAddr; /* address of DMA mapping */
1796 pNewTail = pTxPort->pTxdRingTail;
1799 ** loop forever; exits if BMU_SW bit not set in start frame
1800 ** or BMU_OWN bit set in any frame
1803 Control = pTxd->TBControl;
1804 if ((Control & BMU_SW) == 0) {
1806 ** software controllable bit is set in first
1807 ** fragment when given to BMU. Not set means that
1808 ** this fragment was never sent or is already
1809 ** freed ( -> ring completely free now).
1811 pTxPort->pTxdRingTail = pTxd;
1812 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1815 if (Control & BMU_OWN) {
1816 pTxPort->pTxdRingTail = pTxd;
1817 if (pTxPort->TxdRingFree > 0) {
1818 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1824 ** release the DMA mapping, because until not unmapped
1825 ** this buffer is considered being under control of the
1828 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1829 PhysAddr |= (SK_U64) pTxd->VDataLow;
1830 pci_unmap_page(pAC->PciDev, PhysAddr,
1834 if (Control & BMU_EOF)
1835 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1837 pTxPort->TxdRingFree++;
1838 pTxd->TBControl &= ~BMU_SW;
1839 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1840 } /* while(forever) */
1841 } /* FreeTxDescriptors */
1843 /*****************************************************************************
1845 * FillRxRing - fill the receive ring with valid descriptors
1848 * This function fills the receive ring descriptors with data
1849 * segments and makes them valid for the BMU.
1850 * The active ring is filled completely, if possible.
1851 * The non-active ring is filled only partial to save memory.
1853 * Description of rx ring structure:
1854 * head - points to the descriptor which will be used next by the BMU
1855 * tail - points to the next descriptor to give to the BMU
1859 static void FillRxRing(
1860 SK_AC *pAC, /* pointer to the adapter context */
1861 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1864 unsigned long Flags;
1866 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1867 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1868 if(!FillRxDescriptor(pAC, pRxPort))
1871 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1875 /*****************************************************************************
1877 * FillRxDescriptor - fill one buffer into the receive ring
1880 * The function allocates a new receive buffer and
1881 * puts it into the next descriptor.
1884 * SK_TRUE - a buffer was added to the ring
1885 * SK_FALSE - a buffer could not be added
1887 static SK_BOOL FillRxDescriptor(
1888 SK_AC *pAC, /* pointer to the adapter context struct */
1889 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1891 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1892 RXD *pRxd; /* the rxd to fill */
1893 SK_U16 Length; /* data fragment length */
1894 SK_U64 PhysAddr; /* physical address of a rx buffer */
1896 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1897 if (pMsgBlock == NULL) {
1898 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1899 SK_DBGCAT_DRV_ENTRY,
1900 ("%s: Allocation of rx buffer failed !\n",
1901 pAC->dev[pRxPort->PortIndex]->name));
1902 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1905 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1906 /* skb allocated ok, so add buffer */
1907 pRxd = pRxPort->pRxdRingTail;
1908 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1909 pRxPort->RxdRingFree--;
1910 Length = pAC->RxBufSize;
1911 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1912 virt_to_page(pMsgBlock->data),
1913 ((unsigned long) pMsgBlock->data &
1916 PCI_DMA_FROMDEVICE);
1918 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1919 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1920 pRxd->pMBuf = pMsgBlock;
1921 pRxd->RBControl = BMU_OWN |
1928 } /* FillRxDescriptor */
1931 /*****************************************************************************
1933 * ReQueueRxBuffer - fill one buffer back into the receive ring
1936 * Fill a given buffer back into the rx ring. The buffer
1937 * has been previously allocated and aligned, and its phys.
1938 * address calculated, so this is no more necessary.
1942 static void ReQueueRxBuffer(
1943 SK_AC *pAC, /* pointer to the adapter context struct */
1944 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1945 struct sk_buff *pMsg, /* pointer to the buffer */
1946 SK_U32 PhysHigh, /* phys address high dword */
1947 SK_U32 PhysLow) /* phys address low dword */
1949 RXD *pRxd; /* the rxd to fill */
1950 SK_U16 Length; /* data fragment length */
1952 pRxd = pRxPort->pRxdRingTail;
1953 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1954 pRxPort->RxdRingFree--;
1955 Length = pAC->RxBufSize;
1957 pRxd->VDataLow = PhysLow;
1958 pRxd->VDataHigh = PhysHigh;
1960 pRxd->RBControl = BMU_OWN |
1966 } /* ReQueueRxBuffer */
1968 /*****************************************************************************
1970 * ReceiveIrq - handle a receive IRQ
1973 * This function is called when a receive IRQ is set.
1974 * It walks the receive descriptor ring and sends up all
1975 * frames that are complete.
1979 static void ReceiveIrq(
1980 SK_AC *pAC, /* pointer to adapter context */
1981 RX_PORT *pRxPort, /* pointer to receive port struct */
1982 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
1984 RXD *pRxd; /* pointer to receive descriptors */
1985 SK_U32 Control; /* control field of descriptor */
1986 struct sk_buff *pMsg; /* pointer to message holding frame */
1987 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
1988 int FrameLength; /* total length of received frame */
1989 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
1990 SK_EVPARA EvPara; /* an event parameter union */
1991 unsigned long Flags; /* for spin lock */
1992 int PortIndex = pRxPort->PortIndex;
1993 unsigned int Offset;
1994 unsigned int NumBytes;
1995 unsigned int ForRlmt;
1998 SK_BOOL IsBadFrame; /* Bad frame */
2004 /* do forever; exit if BMU_OWN found */
2005 for ( pRxd = pRxPort->pRxdRingHead ;
2006 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2007 pRxd = pRxd->pNextRxd,
2008 pRxPort->pRxdRingHead = pRxd,
2009 pRxPort->RxdRingFree ++) {
2012 * For a better understanding of this loop
2013 * Go through every descriptor beginning at the head
2014 * Please note: the ring might be completely received so the OWN bit
2015 * set is not a good crirteria to leave that loop.
2016 * Therefore the RingFree counter is used.
2017 * On entry of this loop pRxd is a pointer to the Rxd that needs
2018 * to be checked next.
2021 Control = pRxd->RBControl;
2023 /* check if this descriptor is ready */
2024 if ((Control & BMU_OWN) != 0) {
2025 /* this descriptor is not yet ready */
2026 /* This is the usual end of the loop */
2027 /* We don't need to start the ring again */
2028 FillRxRing(pAC, pRxPort);
2031 pAC->DynIrqModInfo.NbrProcessedDescr++;
2033 /* get length of frame and check it */
2034 FrameLength = Control & BMU_BBC;
2035 if (FrameLength > pAC->RxBufSize) {
2039 /* check for STF and EOF */
2040 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2044 /* here we have a complete frame in the ring */
2047 FrameStat = pRxd->FrameStat;
2049 /* check for frame length mismatch */
2050 #define XMR_FS_LEN_SHIFT 18
2051 #define GMR_FS_LEN_SHIFT 16
2052 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2053 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2054 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2055 SK_DBGCAT_DRV_RX_PROGRESS,
2056 ("skge: Frame length mismatch (%u/%u).\n",
2058 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2063 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2064 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2065 SK_DBGCAT_DRV_RX_PROGRESS,
2066 ("skge: Frame length mismatch (%u/%u).\n",
2068 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2074 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2075 IsBc = (FrameStat & XMR_FS_BC) != 0;
2076 IsMc = (FrameStat & XMR_FS_MC) != 0;
2077 IsBadFrame = (FrameStat &
2078 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2080 IsBc = (FrameStat & GMR_FS_BC) != 0;
2081 IsMc = (FrameStat & GMR_FS_MC) != 0;
2082 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2083 ((FrameStat & GMR_FS_RX_OK) == 0));
2086 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2087 ("Received frame of length %d on port %d\n",
2088 FrameLength, PortIndex));
2089 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2090 ("Number of free rx descriptors: %d\n",
2091 pRxPort->RxdRingFree));
2092 /* DumpMsg(pMsg, "Rx"); */
2094 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2096 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2098 /* there is a receive error in this frame */
2099 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2100 SK_DBGCAT_DRV_RX_PROGRESS,
2101 ("skge: Error in received frame, dropped!\n"
2102 "Control: %x\nRxStat: %x\n",
2103 Control, FrameStat));
2105 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2106 pRxd->VDataHigh, pRxd->VDataLow);
2112 * if short frame then copy data to reduce memory waste
2114 if ((FrameLength < SK_COPY_THRESHOLD) &&
2115 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2117 * Short frame detected and allocation successfull
2119 /* use new skb and copy data */
2120 skb_reserve(pNewMsg, 2);
2121 skb_put(pNewMsg, FrameLength);
2122 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2123 PhysAddr |= (SK_U64) pRxd->VDataLow;
2125 pci_dma_sync_single_for_cpu(pAC->PciDev,
2126 (dma_addr_t) PhysAddr,
2128 PCI_DMA_FROMDEVICE);
2129 memcpy(pNewMsg->data, pMsg, FrameLength);
2131 pci_dma_sync_single_for_device(pAC->PciDev,
2132 (dma_addr_t) PhysAddr,
2134 PCI_DMA_FROMDEVICE);
2135 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2136 pRxd->VDataHigh, pRxd->VDataLow);
2143 * if large frame, or SKB allocation failed, pass
2144 * the SKB directly to the networking
2147 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2148 PhysAddr |= (SK_U64) pRxd->VDataLow;
2150 /* release the DMA mapping */
2151 pci_unmap_single(pAC->PciDev,
2154 PCI_DMA_FROMDEVICE);
2156 /* set length in message */
2157 skb_put(pMsg, FrameLength);
2158 } /* frame > SK_COPY_TRESHOLD */
2160 #ifdef USE_SK_RX_CHECKSUM
2161 pMsg->csum = pRxd->TcpSums & 0xffff;
2162 pMsg->ip_summed = CHECKSUM_COMPLETE;
2164 pMsg->ip_summed = CHECKSUM_NONE;
2167 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2168 ForRlmt = SK_RLMT_RX_PROTOCOL;
2170 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2172 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2173 IsBc, &Offset, &NumBytes);
2174 if (NumBytes != 0) {
2176 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2178 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2179 &pMsg->data[Offset],
2180 IsBc, IsMc, &ForRlmt);
2182 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2183 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2184 /* send up only frames from active port */
2185 if ((PortIndex == pAC->ActivePort) ||
2186 (pAC->RlmtNets == 2)) {
2187 /* frame for upper layer */
2188 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2190 DumpMsg(pMsg, "Rx");
2192 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2193 FrameLength, pRxPort->PortIndex);
2195 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2196 pMsg->protocol = eth_type_trans(pMsg,
2197 pAC->dev[pRxPort->PortIndex]);
2199 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2203 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2204 SK_DBGCAT_DRV_RX_PROGRESS,
2206 DEV_KFREE_SKB(pMsg);
2209 } /* if not for rlmt */
2211 /* packet for rlmt */
2212 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2213 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2214 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2215 pAC->IoBase, FrameLength);
2216 if (pRlmtMbuf != NULL) {
2217 pRlmtMbuf->pNext = NULL;
2218 pRlmtMbuf->Length = FrameLength;
2219 pRlmtMbuf->PortIdx = PortIndex;
2220 EvPara.pParaPtr = pRlmtMbuf;
2221 memcpy((char*)(pRlmtMbuf->pData),
2222 (char*)(pMsg->data),
2225 /* SlowPathLock needed? */
2226 if (SlowPathLock == SK_TRUE) {
2227 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2228 SkEventQueue(pAC, SKGE_RLMT,
2229 SK_RLMT_PACKET_RECEIVED,
2231 pAC->CheckQueue = SK_TRUE;
2232 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2234 SkEventQueue(pAC, SKGE_RLMT,
2235 SK_RLMT_PACKET_RECEIVED,
2237 pAC->CheckQueue = SK_TRUE;
2240 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2241 SK_DBGCAT_DRV_RX_PROGRESS,
2244 if ((pAC->dev[pRxPort->PortIndex]->flags &
2245 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2246 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2247 SK_RLMT_RX_PROTOCOL) {
2248 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2249 pMsg->protocol = eth_type_trans(pMsg,
2250 pAC->dev[pRxPort->PortIndex]);
2252 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2255 DEV_KFREE_SKB(pMsg);
2258 } /* if packet for rlmt */
2259 } /* for ... scanning the RXD ring */
2261 /* RXD ring is empty -> fill and restart */
2262 FillRxRing(pAC, pRxPort);
2263 /* do not start if called from Close */
2264 if (pAC->BoardLevel > SK_INIT_DATA) {
2265 ClearAndStartRx(pAC, PortIndex);
2270 /* remove error frame */
2271 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2272 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2274 /* release the DMA mapping */
2276 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2277 PhysAddr |= (SK_U64) pRxd->VDataLow;
2278 pci_unmap_page(pAC->PciDev,
2281 PCI_DMA_FROMDEVICE);
2282 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2284 pRxPort->RxdRingFree++;
2285 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2291 /*****************************************************************************
2293 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2296 * This function sends a start command and a clear interrupt
2297 * command for one receive queue to the BMU.
2302 static void ClearAndStartRx(
2303 SK_AC *pAC, /* pointer to the adapter context */
2304 int PortIndex) /* index of the receive port (XMAC) */
2306 SK_OUT8(pAC->IoBase,
2307 RxQueueAddr[PortIndex]+Q_CSR,
2308 CSR_START | CSR_IRQ_CL_F);
2309 } /* ClearAndStartRx */
2312 /*****************************************************************************
2314 * ClearTxIrq - give a clear transmit IRQ command to BMU
2317 * This function sends a clear tx IRQ command for one
2318 * transmit queue to the BMU.
2322 static void ClearTxIrq(
2323 SK_AC *pAC, /* pointer to the adapter context */
2324 int PortIndex, /* index of the transmit port (XMAC) */
2325 int Prio) /* priority or normal queue */
2327 SK_OUT8(pAC->IoBase,
2328 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2333 /*****************************************************************************
2335 * ClearRxRing - remove all buffers from the receive ring
2338 * This function removes all receive buffers from the ring.
2339 * The receive BMU must be stopped before calling this function.
2343 static void ClearRxRing(
2344 SK_AC *pAC, /* pointer to adapter context */
2345 RX_PORT *pRxPort) /* pointer to rx port struct */
2347 RXD *pRxd; /* pointer to the current descriptor */
2348 unsigned long Flags;
2351 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2354 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2355 pRxd = pRxPort->pRxdRingHead;
2357 if (pRxd->pMBuf != NULL) {
2359 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2360 PhysAddr |= (SK_U64) pRxd->VDataLow;
2361 pci_unmap_page(pAC->PciDev,
2364 PCI_DMA_FROMDEVICE);
2365 DEV_KFREE_SKB(pRxd->pMBuf);
2368 pRxd->RBControl &= BMU_OWN;
2369 pRxd = pRxd->pNextRxd;
2370 pRxPort->RxdRingFree++;
2371 } while (pRxd != pRxPort->pRxdRingTail);
2372 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2373 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2376 /*****************************************************************************
2378 * ClearTxRing - remove all buffers from the transmit ring
2381 * This function removes all transmit buffers from the ring.
2382 * The transmit BMU must be stopped before calling this function
2383 * and transmitting at the upper level must be disabled.
2384 * The BMU own bit of all descriptors is cleared, the rest is
2385 * done by calling FreeTxDescriptors.
2389 static void ClearTxRing(
2390 SK_AC *pAC, /* pointer to adapter context */
2391 TX_PORT *pTxPort) /* pointer to tx prt struct */
2393 TXD *pTxd; /* pointer to the current descriptor */
2395 unsigned long Flags;
2397 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2398 pTxd = pTxPort->pTxdRingHead;
2399 for (i=0; i<pAC->TxDescrPerRing; i++) {
2400 pTxd->TBControl &= ~BMU_OWN;
2401 pTxd = pTxd->pNextTxd;
2403 FreeTxDescriptors(pAC, pTxPort);
2404 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2407 /*****************************************************************************
2409 * SkGeSetMacAddr - Set the hardware MAC address
2412 * This function sets the MAC address used by the adapter.
2415 * 0, if everything is ok
2418 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2421 DEV_NET *pNet = netdev_priv(dev);
2422 SK_AC *pAC = pNet->pAC;
2424 struct sockaddr *addr = p;
2425 unsigned long Flags;
2427 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2428 ("SkGeSetMacAddr starts now...\n"));
2429 if(netif_running(dev))
2432 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2434 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2436 if (pAC->RlmtNets == 2)
2437 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2438 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2440 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2441 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2445 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2447 } /* SkGeSetMacAddr */
2450 /*****************************************************************************
2452 * SkGeSetRxMode - set receive mode
2455 * This function sets the receive mode of an adapter. The adapter
2456 * supports promiscuous mode, allmulticast mode and a number of
2457 * multicast addresses. If more multicast addresses the available
2458 * are selected, a hash function in the hardware is used.
2461 * 0, if everything is ok
2464 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2470 struct dev_mc_list *pMcList;
2473 unsigned long Flags;
2475 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2476 ("SkGeSetRxMode starts now... "));
2478 pNet = netdev_priv(dev);
2480 if (pAC->RlmtNets == 1)
2481 PortIdx = pAC->ActivePort;
2483 PortIdx = pNet->NetNr;
2485 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2486 if (dev->flags & IFF_PROMISC) {
2487 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2488 ("PROMISCUOUS mode\n"));
2489 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2491 } else if (dev->flags & IFF_ALLMULTI) {
2492 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2493 ("ALLMULTI mode\n"));
2494 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2495 SK_PROM_MODE_ALL_MC);
2497 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2499 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2501 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2502 ("Number of MC entries: %d ", dev->mc_count));
2504 pMcList = dev->mc_list;
2505 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2506 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2507 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2509 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2510 pMcList->dmi_addr[0],
2511 pMcList->dmi_addr[1],
2512 pMcList->dmi_addr[2],
2513 pMcList->dmi_addr[3],
2514 pMcList->dmi_addr[4],
2515 pMcList->dmi_addr[5]));
2517 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2519 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2522 } /* SkGeSetRxMode */
2525 /*****************************************************************************
2527 * SkGeChangeMtu - set the MTU to another value
2530 * This function sets is called whenever the MTU size is changed
2531 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2532 * ethernet MTU size, long frame support is activated.
2535 * 0, if everything is ok
2538 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2541 struct net_device *pOtherDev;
2543 unsigned long Flags;
2547 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2548 ("SkGeChangeMtu starts now...\n"));
2550 pNet = netdev_priv(dev);
2553 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2557 if(pAC->BoardLevel != SK_INIT_RUN) {
2561 #ifdef SK_DIAG_SUPPORT
2562 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2563 if (pAC->DiagFlowCtrl == SK_FALSE) {
2564 return -1; /* still in use, deny any actions of MTU */
2566 pAC->DiagFlowCtrl = SK_FALSE;
2571 pOtherDev = pAC->dev[1 - pNet->NetNr];
2573 if ( netif_running(pOtherDev) && (pOtherDev->mtu > 1500)
2574 && (NewMtu <= 1500))
2577 pAC->RxBufSize = NewMtu + 32;
2580 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2581 ("New MTU: %d\n", NewMtu));
2584 ** Prevent any reconfiguration while changing the MTU
2585 ** by disabling any interrupts
2587 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2588 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2591 ** Notify RLMT that any ports are to be stopped
2593 EvPara.Para32[0] = 0;
2594 EvPara.Para32[1] = -1;
2595 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2596 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2597 EvPara.Para32[0] = 1;
2598 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2600 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2604 ** After calling the SkEventDispatcher(), RLMT is aware about
2605 ** the stopped ports -> configuration can take place!
2607 SkEventDispatcher(pAC, pAC->IoBase);
2609 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2610 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2611 netif_stop_queue(pAC->dev[i]);
2616 ** Depending on the desired MTU size change, a different number of
2617 ** RX buffers need to be allocated
2619 if (NewMtu > 1500) {
2621 ** Use less rx buffers
2623 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2624 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2625 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2626 (pAC->RxDescrPerRing / 4);
2628 if (i == pAC->ActivePort) {
2629 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2630 (pAC->RxDescrPerRing / 4);
2632 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2633 (pAC->RxDescrPerRing / 10);
2639 ** Use the normal amount of rx buffers
2641 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2642 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2643 pAC->RxPort[i].RxFillLimit = 1;
2645 if (i == pAC->ActivePort) {
2646 pAC->RxPort[i].RxFillLimit = 1;
2648 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2649 (pAC->RxDescrPerRing / 4);
2655 SkGeDeInit(pAC, pAC->IoBase);
2658 ** enable/disable hardware support for long frames
2660 if (NewMtu > 1500) {
2661 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2662 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2664 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2665 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2667 pAC->GIni.GIPortUsage = SK_RED_LINK;
2671 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2672 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2673 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2674 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2675 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2676 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2677 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2681 ** Speed and others are set back to default in level 1 init!
2683 GetConfiguration(pAC);
2685 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2686 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2687 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2688 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2689 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2690 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2691 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2694 ** clear and reinit the rx rings here
2696 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2697 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2698 ClearRxRing(pAC, &pAC->RxPort[i]);
2699 FillRxRing(pAC, &pAC->RxPort[i]);
2702 ** Enable transmit descriptor polling
2704 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2705 FillRxRing(pAC, &pAC->RxPort[i]);
2708 SkGeYellowLED(pAC, pAC->IoBase, 1);
2709 SkDimEnableModerationIfNeeded(pAC);
2710 SkDimDisplayModerationSettings(pAC);
2712 netif_start_queue(pAC->dev[pNet->PortNr]);
2713 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2714 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2718 ** Enable Interrupts again
2720 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2721 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2723 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2724 SkEventDispatcher(pAC, pAC->IoBase);
2727 ** Notify RLMT about the changing and restarting one (or more) ports
2729 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2730 EvPara.Para32[0] = pAC->RlmtNets;
2731 EvPara.Para32[1] = -1;
2732 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2733 EvPara.Para32[0] = pNet->PortNr;
2734 EvPara.Para32[1] = -1;
2735 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2737 if (netif_running(pOtherDev)) {
2738 DEV_NET *pOtherNet = netdev_priv(pOtherDev);
2739 EvPara.Para32[0] = pOtherNet->PortNr;
2740 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2743 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2746 SkEventDispatcher(pAC, pAC->IoBase);
2747 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2750 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2751 ** seems as if upper layers have a problem to handle a successful
2752 ** return value of '0'. If such a zero is returned, the complete
2753 ** system hangs for several minutes (!), which is in acceptable.
2755 ** Currently it is not clear, what the exact reason for this problem
2756 ** is. The implemented workaround for 2.5 is to return the desired
2757 ** new MTU size if all needed changes for the new MTU size where
2758 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2759 ** which indicates the successful change of the mtu-size.
2763 } /* SkGeChangeMtu */
2766 /*****************************************************************************
2768 * SkGeStats - return ethernet device statistics
2771 * This function return statistic data about the ethernet device
2772 * to the operating system.
2775 * pointer to the statistic structure.
2777 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2779 DEV_NET *pNet = netdev_priv(dev);
2780 SK_AC *pAC = pNet->pAC;
2781 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2782 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2783 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2784 unsigned int Size; /* size of pnmi struct */
2785 unsigned long Flags; /* for spin lock */
2787 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2788 ("SkGeStats starts now...\n"));
2789 pPnmiStruct = &pAC->PnmiStruct;
2791 #ifdef SK_DIAG_SUPPORT
2792 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2793 (pAC->BoardLevel == SK_INIT_RUN)) {
2795 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2796 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2797 Size = SK_PNMI_STRUCT_SIZE;
2798 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2799 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2800 #ifdef SK_DIAG_SUPPORT
2804 pPnmiStat = &pPnmiStruct->Stat[0];
2805 pPnmiConf = &pPnmiStruct->Conf[0];
2807 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2808 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2809 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2810 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2812 if (dev->mtu <= 1500) {
2813 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2815 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2816 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2820 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2821 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2823 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2824 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2825 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2826 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2827 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2829 /* detailed rx_errors: */
2830 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2831 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2832 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2833 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2834 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2835 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2837 /* detailed tx_errors */
2838 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2839 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2840 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2841 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2842 pAC->stats.tx_window_errors = (SK_U32) 0;
2844 return(&pAC->stats);
2848 * Basic MII register access
2850 static int SkGeMiiIoctl(struct net_device *dev,
2851 struct mii_ioctl_data *data, int cmd)
2853 DEV_NET *pNet = netdev_priv(dev);
2854 SK_AC *pAC = pNet->pAC;
2855 SK_IOC IoC = pAC->IoBase;
2856 int Port = pNet->PortNr;
2857 SK_GEPORT *pPrt = &pAC->GIni.GP[Port];
2858 unsigned long Flags;
2860 int reg = data->reg_num & 0x1f;
2861 SK_U16 val = data->val_in;
2863 if (!netif_running(dev))
2864 return -ENODEV; /* Phy still in reset */
2866 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2869 data->phy_id = pPrt->PhyAddr;
2873 if (pAC->GIni.GIGenesis)
2874 SkXmPhyRead(pAC, IoC, Port, reg, &val);
2876 SkGmPhyRead(pAC, IoC, Port, reg, &val);
2878 data->val_out = val;
2882 if (!capable(CAP_NET_ADMIN))
2885 else if (pAC->GIni.GIGenesis)
2886 SkXmPhyWrite(pAC, IoC, Port, reg, val);
2888 SkGmPhyWrite(pAC, IoC, Port, reg, val);
2893 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2898 /*****************************************************************************
2900 * SkGeIoctl - IO-control function
2903 * This function is called if an ioctl is issued on the device.
2904 * There are three subfunction for reading, writing and test-writing
2905 * the private MIB data structure (useful for SysKonnect-internal tools).
2908 * 0, if everything is ok
2911 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2916 struct pci_dev *pdev = NULL;
2918 unsigned int Err = 0;
2921 unsigned int Length = 0;
2922 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2924 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2925 ("SkGeIoctl starts now...\n"));
2927 pNet = netdev_priv(dev);
2930 if (cmd == SIOCGMIIPHY || cmd == SIOCSMIIREG || cmd == SIOCGMIIREG)
2931 return SkGeMiiIoctl(dev, if_mii(rq), cmd);
2933 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2938 case SK_IOCTL_SETMIB:
2939 case SK_IOCTL_PRESETMIB:
2940 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2941 case SK_IOCTL_GETMIB:
2942 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2943 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2944 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2947 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2948 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2949 Ioctl.Len<Size? Ioctl.Len : Size)) {
2953 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2958 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2961 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2963 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2966 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2970 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2974 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2979 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2984 kfree(pMemBuf); /* cleanup everything */
2986 #ifdef SK_DIAG_SUPPORT
2988 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2989 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2992 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2994 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2997 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3002 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3004 ** While coding this new IOCTL interface, only a few lines of code
3005 ** are to to be added. Therefore no dedicated function has been
3006 ** added. If more functionality is added, a separate function
3007 ** should be used...
3009 * ((SK_U32 *)pMemBuf) = 0;
3010 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3011 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
3012 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3017 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3022 kfree(pMemBuf); /* cleanup everything */
3034 /*****************************************************************************
3036 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3039 * This function reads/writes the MIB data using PNMI (Private Network
3040 * Management Interface).
3041 * The destination for the data must be provided with the
3042 * ioctl call and is given to the driver in the form of
3043 * a user space address.
3044 * Copying from the user-provided data area into kernel messages
3045 * and back is done by copy_from_user and copy_to_user calls in
3049 * returned size from PNMI call
3051 static int SkGeIocMib(
3052 DEV_NET *pNet, /* pointer to the adapter context */
3053 unsigned int Size, /* length of ioctl data */
3054 int mode) /* flag for set/preset */
3056 unsigned long Flags; /* for spin lock */
3059 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3060 ("SkGeIocMib starts now...\n"));
3063 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3065 case SK_IOCTL_GETMIB:
3066 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3069 case SK_IOCTL_PRESETMIB:
3070 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3073 case SK_IOCTL_SETMIB:
3074 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3080 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3081 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3082 ("MIB data access succeeded\n"));
3087 /*****************************************************************************
3089 * GetConfiguration - read configuration information
3092 * This function reads per-adapter configuration information from
3093 * the options provided on the command line.
3098 static void GetConfiguration(
3099 SK_AC *pAC) /* pointer to the adapter context structure */
3101 SK_I32 Port; /* preferred port */
3104 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3105 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3106 int DuplexCap = 0; /* 0=both,1=full,2=half */
3107 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3108 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3110 SK_BOOL IsConTypeDefined = SK_TRUE;
3111 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3112 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3113 SK_BOOL IsRoleDefined = SK_TRUE;
3114 SK_BOOL IsModeDefined = SK_TRUE;
3116 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3117 * parameter. The mapping is described by this table:
3118 * DuplexCap -> | both | full | half |
3120 * -----------------------------------------------------------------
3121 * Off | illegal | Full | Half |
3122 * -----------------------------------------------------------------
3123 * On | AutoBoth | AutoFull | AutoHalf |
3124 * -----------------------------------------------------------------
3125 * Sense | AutoSense | AutoSense | AutoSense |
3127 int Capabilities[3][3] =
3128 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3129 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3130 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3138 #define M_CurrPort pAC->GIni.GP[Port]
3142 ** Set the default values first for both ports!
3144 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3145 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3146 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3147 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3148 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3152 ** Check merged parameter ConType. If it has not been used,
3153 ** verify any other parameter (e.g. AutoNeg) and use default values.
3155 ** Stating both ConType and other lowlevel link parameters is also
3156 ** possible. If this is the case, the passed ConType-parameter is
3157 ** overwritten by the lowlevel link parameter.
3159 ** The following settings are used for a merged ConType-parameter:
3161 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3162 ** ------- ------ ------- -------- ---------- -----
3163 ** Auto Both On SymOrRem Auto Auto
3164 ** 100FD Full Off None <ignored> 100
3165 ** 100HD Half Off None <ignored> 100
3166 ** 10FD Full Off None <ignored> 10
3167 ** 10HD Half Off None <ignored> 10
3169 ** This ConType parameter is used for all ports of the adapter!
3171 if ( (ConType != NULL) &&
3172 (pAC->Index < SK_MAX_CARD_PARAM) &&
3173 (ConType[pAC->Index] != NULL) ) {
3175 /* Check chipset family */
3176 if ((!pAC->ChipsetType) &&
3177 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3178 (strcmp(ConType[pAC->Index],"")!=0)) {
3179 /* Set the speed parameter back */
3180 printk("sk98lin: Illegal value \"%s\" "
3183 ConType[pAC->Index]);
3185 sprintf(ConType[pAC->Index], "Auto");
3188 if (strcmp(ConType[pAC->Index],"")==0) {
3189 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3190 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3191 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3192 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3193 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3194 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3195 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3197 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3198 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3199 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3200 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3201 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3202 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3204 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3205 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3206 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3207 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3208 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3209 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3211 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3212 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3213 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3214 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3215 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3216 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3218 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3219 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3220 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3221 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3222 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3223 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3226 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3227 ConType[pAC->Index]);
3228 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3231 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3235 ** Parse any parameter settings for port A:
3236 ** a) any LinkSpeed stated?
3238 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3239 Speed_A[pAC->Index] != NULL) {
3240 if (strcmp(Speed_A[pAC->Index],"")==0) {
3241 IsLinkSpeedDefined = SK_FALSE;
3242 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3243 LinkSpeed = SK_LSPEED_AUTO;
3244 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3245 LinkSpeed = SK_LSPEED_10MBPS;
3246 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3247 LinkSpeed = SK_LSPEED_100MBPS;
3248 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3249 LinkSpeed = SK_LSPEED_1000MBPS;
3251 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3252 Speed_A[pAC->Index]);
3253 IsLinkSpeedDefined = SK_FALSE;
3256 IsLinkSpeedDefined = SK_FALSE;
3260 ** Check speed parameter:
3261 ** Only copper type adapter and GE V2 cards
3263 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3264 ((LinkSpeed != SK_LSPEED_AUTO) &&
3265 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3266 printk("sk98lin: Illegal value for Speed_A. "
3267 "Not a copper card or GE V2 card\n Using "
3269 LinkSpeed = SK_LSPEED_1000MBPS;
3273 ** Decide whether to set new config value if somethig valid has
3276 if (IsLinkSpeedDefined) {
3277 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3281 ** b) Any Autonegotiation and DuplexCapabilities set?
3282 ** Please note that both belong together...
3284 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3286 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3287 AutoNeg_A[pAC->Index] != NULL) {
3289 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3291 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3293 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3295 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3298 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3299 AutoNeg_A[pAC->Index]);
3303 DuplexCap = DC_BOTH;
3305 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3306 DupCap_A[pAC->Index] != NULL) {
3308 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3310 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3311 DuplexCap = DC_BOTH;
3312 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3313 DuplexCap = DC_FULL;
3314 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3315 DuplexCap = DC_HALF;
3317 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3318 DupCap_A[pAC->Index]);
3323 ** Check for illegal combinations
3325 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3326 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3327 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3328 (pAC->ChipsetType)) {
3329 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3330 " Using Full Duplex.\n");
3331 DuplexCap = DC_FULL;
3334 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3335 printk("sk98lin, Port A: DuplexCapabilities"
3336 " ignored using Sense mode\n");
3339 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3340 printk("sk98lin: Port A: Illegal combination"
3341 " of values AutoNeg. and DuplexCap.\n Using "
3343 DuplexCap = DC_FULL;
3346 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3347 DuplexCap = DC_FULL;
3350 if (!AutoSet && DupSet) {
3351 printk("sk98lin: Port A: Duplex setting not"
3352 " possible in\n default AutoNegotiation mode"
3353 " (Sense).\n Using AutoNegotiation On\n");
3358 ** set the desired mode
3360 if (AutoSet || DupSet) {
3361 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3365 ** c) Any Flowcontrol-parameter set?
3367 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3368 FlowCtrl_A[pAC->Index] != NULL) {
3369 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3370 IsFlowCtrlDefined = SK_FALSE;
3371 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3372 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3373 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3374 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3375 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3376 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3377 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3378 FlowCtrl = SK_FLOW_MODE_NONE;
3380 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3381 FlowCtrl_A[pAC->Index]);
3382 IsFlowCtrlDefined = SK_FALSE;
3385 IsFlowCtrlDefined = SK_FALSE;
3388 if (IsFlowCtrlDefined) {
3389 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3390 printk("sk98lin: Port A: FlowControl"
3391 " impossible without AutoNegotiation,"
3393 FlowCtrl = SK_FLOW_MODE_NONE;
3395 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3399 ** d) What is with the RoleParameter?
3401 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3402 Role_A[pAC->Index] != NULL) {
3403 if (strcmp(Role_A[pAC->Index],"")==0) {
3404 IsRoleDefined = SK_FALSE;
3405 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3406 MSMode = SK_MS_MODE_AUTO;
3407 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3408 MSMode = SK_MS_MODE_MASTER;
3409 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3410 MSMode = SK_MS_MODE_SLAVE;
3412 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3413 Role_A[pAC->Index]);
3414 IsRoleDefined = SK_FALSE;
3417 IsRoleDefined = SK_FALSE;
3420 if (IsRoleDefined == SK_TRUE) {
3421 pAC->GIni.GP[0].PMSMode = MSMode;
3427 ** Parse any parameter settings for port B:
3428 ** a) any LinkSpeed stated?
3430 IsConTypeDefined = SK_TRUE;
3431 IsLinkSpeedDefined = SK_TRUE;
3432 IsFlowCtrlDefined = SK_TRUE;
3433 IsModeDefined = SK_TRUE;
3435 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3436 Speed_B[pAC->Index] != NULL) {
3437 if (strcmp(Speed_B[pAC->Index],"")==0) {
3438 IsLinkSpeedDefined = SK_FALSE;
3439 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3440 LinkSpeed = SK_LSPEED_AUTO;
3441 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3442 LinkSpeed = SK_LSPEED_10MBPS;
3443 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3444 LinkSpeed = SK_LSPEED_100MBPS;
3445 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3446 LinkSpeed = SK_LSPEED_1000MBPS;
3448 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3449 Speed_B[pAC->Index]);
3450 IsLinkSpeedDefined = SK_FALSE;
3453 IsLinkSpeedDefined = SK_FALSE;
3457 ** Check speed parameter:
3458 ** Only copper type adapter and GE V2 cards
3460 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3461 ((LinkSpeed != SK_LSPEED_AUTO) &&
3462 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3463 printk("sk98lin: Illegal value for Speed_B. "
3464 "Not a copper card or GE V2 card\n Using "
3466 LinkSpeed = SK_LSPEED_1000MBPS;
3470 ** Decide whether to set new config value if somethig valid has
3473 if (IsLinkSpeedDefined) {
3474 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3478 ** b) Any Autonegotiation and DuplexCapabilities set?
3479 ** Please note that both belong together...
3481 AutoNeg = AN_SENS; /* default: do auto Sense */
3483 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3484 AutoNeg_B[pAC->Index] != NULL) {
3486 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3488 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3490 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3492 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3495 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3496 AutoNeg_B[pAC->Index]);
3500 DuplexCap = DC_BOTH;
3502 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3503 DupCap_B[pAC->Index] != NULL) {
3505 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3507 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3508 DuplexCap = DC_BOTH;
3509 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3510 DuplexCap = DC_FULL;
3511 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3512 DuplexCap = DC_HALF;
3514 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3515 DupCap_B[pAC->Index]);
3521 ** Check for illegal combinations
3523 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3524 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3525 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3526 (pAC->ChipsetType)) {
3527 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3528 " Using Full Duplex.\n");
3529 DuplexCap = DC_FULL;
3532 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3533 printk("sk98lin, Port B: DuplexCapabilities"
3534 " ignored using Sense mode\n");
3537 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3538 printk("sk98lin: Port B: Illegal combination"
3539 " of values AutoNeg. and DuplexCap.\n Using "
3541 DuplexCap = DC_FULL;
3544 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3545 DuplexCap = DC_FULL;
3548 if (!AutoSet && DupSet) {
3549 printk("sk98lin: Port B: Duplex setting not"
3550 " possible in\n default AutoNegotiation mode"
3551 " (Sense).\n Using AutoNegotiation On\n");
3556 ** set the desired mode
3558 if (AutoSet || DupSet) {
3559 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3563 ** c) Any FlowCtrl parameter set?
3565 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3566 FlowCtrl_B[pAC->Index] != NULL) {
3567 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3568 IsFlowCtrlDefined = SK_FALSE;
3569 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3570 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3571 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3572 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3573 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3574 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3575 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3576 FlowCtrl = SK_FLOW_MODE_NONE;
3578 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3579 FlowCtrl_B[pAC->Index]);
3580 IsFlowCtrlDefined = SK_FALSE;
3583 IsFlowCtrlDefined = SK_FALSE;
3586 if (IsFlowCtrlDefined) {
3587 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3588 printk("sk98lin: Port B: FlowControl"
3589 " impossible without AutoNegotiation,"
3591 FlowCtrl = SK_FLOW_MODE_NONE;
3593 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3597 ** d) What is the RoleParameter?
3599 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3600 Role_B[pAC->Index] != NULL) {
3601 if (strcmp(Role_B[pAC->Index],"")==0) {
3602 IsRoleDefined = SK_FALSE;
3603 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3604 MSMode = SK_MS_MODE_AUTO;
3605 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3606 MSMode = SK_MS_MODE_MASTER;
3607 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3608 MSMode = SK_MS_MODE_SLAVE;
3610 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3611 Role_B[pAC->Index]);
3612 IsRoleDefined = SK_FALSE;
3615 IsRoleDefined = SK_FALSE;
3618 if (IsRoleDefined) {
3619 pAC->GIni.GP[1].PMSMode = MSMode;
3623 ** Evaluate settings for both ports
3625 pAC->ActivePort = 0;
3626 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3627 PrefPort[pAC->Index] != NULL) {
3628 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3629 pAC->ActivePort = 0;
3630 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3631 pAC->Rlmt.Net[0].PrefPort = 0;
3632 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3634 ** do not set ActivePort here, thus a port
3635 ** switch is issued after net up.
3638 pAC->Rlmt.Net[0].Preference = Port;
3639 pAC->Rlmt.Net[0].PrefPort = Port;
3640 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3642 ** do not set ActivePort here, thus a port
3643 ** switch is issued after net up.
3645 if (pAC->GIni.GIMacsFound == 1) {
3646 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3647 " Port B not available on single port adapters.\n");
3649 pAC->ActivePort = 0;
3650 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3651 pAC->Rlmt.Net[0].PrefPort = 0;
3654 pAC->Rlmt.Net[0].Preference = Port;
3655 pAC->Rlmt.Net[0].PrefPort = Port;
3658 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3659 PrefPort[pAC->Index]);
3665 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3666 RlmtMode[pAC->Index] != NULL) {
3667 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3669 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3670 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3671 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3672 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3673 SK_RLMT_CHECK_LOC_LINK;
3674 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3675 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3676 SK_RLMT_CHECK_LOC_LINK |
3678 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3679 (pAC->GIni.GIMacsFound == 2)) {
3680 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3683 printk("sk98lin: Illegal value \"%s\" for"
3684 " RlmtMode, using default\n",
3685 RlmtMode[pAC->Index]);
3693 ** Check the interrupt moderation parameters
3695 if (Moderation[pAC->Index] != NULL) {
3696 if (strcmp(Moderation[pAC->Index], "") == 0) {
3697 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3698 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3699 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3700 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3701 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3702 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3703 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3705 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3706 " Disable interrupt moderation.\n",
3707 Moderation[pAC->Index]);
3708 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3711 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3714 if (Stats[pAC->Index] != NULL) {
3715 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3716 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3718 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3721 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3724 if (ModerationMask[pAC->Index] != NULL) {
3725 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3726 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3727 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3728 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3729 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3730 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3731 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3732 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3733 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3734 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3735 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3736 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3737 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3738 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3739 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3740 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3741 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3742 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3743 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3744 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3745 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3746 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3747 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3748 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3749 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3750 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3751 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3752 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3753 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3754 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3755 } else { /* some rubbish */
3756 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3758 } else { /* operator has stated nothing */
3759 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3762 if (AutoSizing[pAC->Index] != NULL) {
3763 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3764 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3766 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3768 } else { /* operator has stated nothing */
3769 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3772 if (IntsPerSec[pAC->Index] != 0) {
3773 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3774 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3775 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3776 " Using default value of %i.\n",
3777 IntsPerSec[pAC->Index],
3778 C_INT_MOD_IPS_LOWER_RANGE,
3779 C_INT_MOD_IPS_UPPER_RANGE,
3780 C_INTS_PER_SEC_DEFAULT);
3781 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3783 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3786 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3790 ** Evaluate upper and lower moderation threshold
3792 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3793 pAC->DynIrqModInfo.MaxModIntsPerSec +
3794 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3796 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3797 pAC->DynIrqModInfo.MaxModIntsPerSec -
3798 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3800 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3803 } /* GetConfiguration */
3806 /*****************************************************************************
3808 * ProductStr - return a adapter identification string from vpd
3811 * This function reads the product name string from the vpd area
3812 * and puts it the field pAC->DeviceString.
3816 static inline int ProductStr(
3817 SK_AC *pAC, /* pointer to adapter context */
3818 char *DeviceStr, /* result string */
3819 int StrLen /* length of the string */
3822 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3823 int ReturnCode; /* return code from vpd_read */
3824 unsigned long Flags;
3826 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3827 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, DeviceStr, &StrLen);
3828 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3833 /*****************************************************************************
3835 * StartDrvCleanupTimer - Start timer to check for descriptors which
3836 * might be placed in descriptor ring, but
3837 * havent been handled up to now
3840 * This function requests a HW-timer fo the Yukon card. The actions to
3841 * perform when this timer expires, are located in the SkDrvEvent().
3846 StartDrvCleanupTimer(SK_AC *pAC) {
3847 SK_EVPARA EventParam; /* Event struct for timer event */
3849 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3850 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3851 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3852 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3853 SKGE_DRV, SK_DRV_TIMER, EventParam);
3856 /*****************************************************************************
3858 * StopDrvCleanupTimer - Stop timer to check for descriptors
3861 * This function requests a HW-timer fo the Yukon card. The actions to
3862 * perform when this timer expires, are located in the SkDrvEvent().
3867 StopDrvCleanupTimer(SK_AC *pAC) {
3868 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3869 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3872 /****************************************************************************/
3873 /* functions for common modules *********************************************/
3874 /****************************************************************************/
3877 /*****************************************************************************
3879 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3882 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3883 * is embedded into a socket buff data area.
3889 * NULL or pointer to Mbuf.
3891 SK_MBUF *SkDrvAllocRlmtMbuf(
3892 SK_AC *pAC, /* pointer to adapter context */
3893 SK_IOC IoC, /* the IO-context */
3894 unsigned BufferSize) /* size of the requested buffer */
3896 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3897 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3899 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3900 if (pMsgBlock == NULL) {
3903 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3904 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3905 pRlmtMbuf->pNext = NULL;
3906 pRlmtMbuf->pOs = pMsgBlock;
3907 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3908 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3909 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3912 } /* SkDrvAllocRlmtMbuf */
3915 /*****************************************************************************
3917 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3920 * This routine frees one or more RLMT mbuf(s).
3928 void SkDrvFreeRlmtMbuf(
3929 SK_AC *pAC, /* pointer to adapter context */
3930 SK_IOC IoC, /* the IO-context */
3931 SK_MBUF *pMbuf) /* size of the requested buffer */
3938 pNextMbuf = pFreeMbuf->pNext;
3939 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3940 pFreeMbuf = pNextMbuf;
3941 } while ( pFreeMbuf != NULL );
3942 } /* SkDrvFreeRlmtMbuf */
3945 /*****************************************************************************
3947 * SkOsGetTime - provide a time value
3950 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3951 * It is not used for absolute time, but only for time differences.
3957 SK_U64 SkOsGetTime(SK_AC *pAC)
3959 SK_U64 PrivateJiffies;
3960 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3961 return PrivateJiffies;
3965 /*****************************************************************************
3967 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3970 * This routine reads a 32 bit value from the pci configuration
3974 * 0 - indicate everything worked ok.
3975 * != 0 - error indication
3977 int SkPciReadCfgDWord(
3978 SK_AC *pAC, /* Adapter Control structure pointer */
3979 int PciAddr, /* PCI register address */
3980 SK_U32 *pVal) /* pointer to store the read value */
3982 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3984 } /* SkPciReadCfgDWord */
3987 /*****************************************************************************
3989 * SkPciReadCfgWord - read a 16 bit value from pci config space
3992 * This routine reads a 16 bit value from the pci configuration
3996 * 0 - indicate everything worked ok.
3997 * != 0 - error indication
3999 int SkPciReadCfgWord(
4000 SK_AC *pAC, /* Adapter Control structure pointer */
4001 int PciAddr, /* PCI register address */
4002 SK_U16 *pVal) /* pointer to store the read value */
4004 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4006 } /* SkPciReadCfgWord */
4009 /*****************************************************************************
4011 * SkPciReadCfgByte - read a 8 bit value from pci config space
4014 * This routine reads a 8 bit value from the pci configuration
4018 * 0 - indicate everything worked ok.
4019 * != 0 - error indication
4021 int SkPciReadCfgByte(
4022 SK_AC *pAC, /* Adapter Control structure pointer */
4023 int PciAddr, /* PCI register address */
4024 SK_U8 *pVal) /* pointer to store the read value */
4026 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4028 } /* SkPciReadCfgByte */
4031 /*****************************************************************************
4033 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4036 * This routine writes a 16 bit value to the pci configuration
4037 * space. The flag PciConfigUp indicates whether the config space
4038 * is accesible or must be set up first.
4041 * 0 - indicate everything worked ok.
4042 * != 0 - error indication
4044 int SkPciWriteCfgWord(
4045 SK_AC *pAC, /* Adapter Control structure pointer */
4046 int PciAddr, /* PCI register address */
4047 SK_U16 Val) /* pointer to store the read value */
4049 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4051 } /* SkPciWriteCfgWord */
4054 /*****************************************************************************
4056 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4059 * This routine writes a 8 bit value to the pci configuration
4060 * space. The flag PciConfigUp indicates whether the config space
4061 * is accesible or must be set up first.
4064 * 0 - indicate everything worked ok.
4065 * != 0 - error indication
4067 int SkPciWriteCfgByte(
4068 SK_AC *pAC, /* Adapter Control structure pointer */
4069 int PciAddr, /* PCI register address */
4070 SK_U8 Val) /* pointer to store the read value */
4072 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4074 } /* SkPciWriteCfgByte */
4077 /*****************************************************************************
4079 * SkDrvEvent - handle driver events
4082 * This function handles events from all modules directed to the driver
4085 * Is called under protection of slow path lock.
4088 * 0 if everything ok
4093 SK_AC *pAC, /* pointer to adapter context */
4094 SK_IOC IoC, /* io-context */
4095 SK_U32 Event, /* event-id */
4096 SK_EVPARA Param) /* event-parameter */
4098 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4099 struct sk_buff *pMsg; /* pointer to a message block */
4100 int FromPort; /* the port from which we switch away */
4101 int ToPort; /* the port we switch to */
4102 SK_EVPARA NewPara; /* parameter for further events */
4104 unsigned long Flags;
4108 case SK_DRV_ADAP_FAIL:
4109 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4110 ("ADAPTER FAIL EVENT\n"));
4111 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4112 /* disable interrupts */
4113 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4116 case SK_DRV_PORT_FAIL:
4117 FromPort = Param.Para32[0];
4118 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4119 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4120 if (FromPort == 0) {
4121 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4123 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4127 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4129 FromPort = Param.Para32[0];
4130 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4131 ("PORT RESET EVENT, Port: %d ", FromPort));
4132 NewPara.Para64 = FromPort;
4133 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4135 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4138 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4139 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4140 spin_unlock_irqrestore(
4141 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4144 /* clear rx ring from received frames */
4145 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4147 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4149 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4152 /* tschilling: Handling of return value inserted. */
4153 if (SkGeInitPort(pAC, IoC, FromPort)) {
4154 if (FromPort == 0) {
4155 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4157 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4160 SkAddrMcUpdate(pAC,IoC, FromPort);
4161 PortReInitBmu(pAC, FromPort);
4162 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4163 ClearAndStartRx(pAC, FromPort);
4164 spin_unlock_irqrestore(
4165 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4168 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4169 { struct net_device *dev = pAC->dev[Param.Para32[0]];
4171 FromPort = Param.Para32[0];
4172 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4173 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4175 SkAddrMcUpdate(pAC,IoC, FromPort);
4177 if (DoPrintInterfaceChange) {
4178 printk("%s: network connection up using"
4179 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4181 /* tschilling: Values changed according to LinkSpeedUsed. */
4182 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4183 if (Stat == SK_LSPEED_STAT_10MBPS) {
4184 printk(" speed: 10\n");
4185 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4186 printk(" speed: 100\n");
4187 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4188 printk(" speed: 1000\n");
4190 printk(" speed: unknown\n");
4194 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4195 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4196 Stat == SK_LMODE_STAT_AUTOFULL) {
4197 printk(" autonegotiation: yes\n");
4200 printk(" autonegotiation: no\n");
4202 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4203 Stat == SK_LMODE_STAT_HALF) {
4204 printk(" duplex mode: half\n");
4207 printk(" duplex mode: full\n");
4209 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4210 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4211 printk(" flowctrl: remote send\n");
4213 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4214 printk(" flowctrl: local send\n");
4216 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4217 printk(" flowctrl: symmetric\n");
4220 printk(" flowctrl: none\n");
4223 /* tschilling: Check against CopperType now. */
4224 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4225 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4226 SK_LSPEED_STAT_1000MBPS)) {
4227 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4228 if (Stat == SK_MS_STAT_MASTER ) {
4229 printk(" role: master\n");
4231 else if (Stat == SK_MS_STAT_SLAVE ) {
4232 printk(" role: slave\n");
4235 printk(" role: ???\n");
4240 Display dim (dynamic interrupt moderation)
4243 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4244 printk(" irq moderation: static (%d ints/sec)\n",
4245 pAC->DynIrqModInfo.MaxModIntsPerSec);
4246 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4247 printk(" irq moderation: dynamic (%d ints/sec)\n",
4248 pAC->DynIrqModInfo.MaxModIntsPerSec);
4250 printk(" irq moderation: disabled\n");
4253 printk(" scatter-gather: %s\n",
4254 (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4255 printk(" tx-checksum: %s\n",
4256 (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4257 printk(" rx-checksum: %s\n",
4258 pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4261 DoPrintInterfaceChange = SK_TRUE;
4264 if ((Param.Para32[0] != pAC->ActivePort) &&
4265 (pAC->RlmtNets == 1)) {
4266 NewPara.Para32[0] = pAC->ActivePort;
4267 NewPara.Para32[1] = Param.Para32[0];
4268 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4272 /* Inform the world that link protocol is up. */
4273 netif_carrier_on(dev);
4276 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4278 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4279 ("NET DOWN EVENT "));
4280 if (DoPrintInterfaceChange) {
4281 printk("%s: network connection down\n",
4282 pAC->dev[Param.Para32[1]]->name);
4284 DoPrintInterfaceChange = SK_TRUE;
4286 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4288 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4289 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4290 ("PORT SWITCH HARD "));
4291 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4293 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4294 'A'+Param.Para32[1]);
4295 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4296 FromPort = Param.Para32[0];
4297 ToPort = Param.Para32[1];
4298 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4299 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4300 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4301 NewPara.Para64 = FromPort;
4302 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4303 NewPara.Para64 = ToPort;
4304 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4306 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4308 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4309 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4310 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4311 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4312 spin_unlock_irqrestore(
4313 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4316 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4317 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4319 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4320 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4322 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4324 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4325 pAC->ActivePort = ToPort;
4329 /* tschilling: New common function with minimum size check. */
4331 if (pAC->RlmtNets == 2) {
4335 if (SkGeInitAssignRamToQueues(
4339 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4340 spin_unlock_irqrestore(
4341 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4343 printk("SkGeInitAssignRamToQueues failed.\n");
4347 /* tschilling: Handling of return values inserted. */
4348 if (SkGeInitPort(pAC, IoC, FromPort) ||
4349 SkGeInitPort(pAC, IoC, ToPort)) {
4350 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4352 if (Event == SK_DRV_SWITCH_SOFT) {
4353 SkMacRxTxEnable(pAC, IoC, FromPort);
4355 SkMacRxTxEnable(pAC, IoC, ToPort);
4356 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4357 SkAddrMcUpdate(pAC, IoC, FromPort);
4358 SkAddrMcUpdate(pAC, IoC, ToPort);
4359 PortReInitBmu(pAC, FromPort);
4360 PortReInitBmu(pAC, ToPort);
4361 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4362 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4363 ClearAndStartRx(pAC, FromPort);
4364 ClearAndStartRx(pAC, ToPort);
4365 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4366 spin_unlock_irqrestore(
4367 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4370 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4371 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4373 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4374 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4375 skb_put(pMsg, pRlmtMbuf->Length);
4376 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4379 DEV_KFREE_SKB_ANY(pMsg);
4382 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4384 ** expiration of the moderation timer implies that
4385 ** dynamic moderation is to be applied
4387 SkDimStartModerationTimer(pAC);
4389 if (pAC->DynIrqModInfo.DisplayStats) {
4390 SkDimDisplayModerationSettings(pAC);
4392 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4394 ** check if we need to check for descriptors which
4395 ** haven't been handled the last millisecs
4397 StartDrvCleanupTimer(pAC);
4398 if (pAC->GIni.GIMacsFound == 2) {
4399 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4401 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4403 printk("Expiration of unknown timer\n");
4409 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4416 /*****************************************************************************
4418 * SkErrorLog - log errors
4421 * This function logs errors to the system buffer and to the console
4424 * 0 if everything ok
4437 case SK_ERRCL_OTHER:
4438 strcpy(ClassStr, "Other error");
4440 case SK_ERRCL_CONFIG:
4441 strcpy(ClassStr, "Configuration error");
4444 strcpy(ClassStr, "Initialization error");
4446 case SK_ERRCL_NORES:
4447 strcpy(ClassStr, "Out of resources error");
4450 strcpy(ClassStr, "internal Software error");
4453 strcpy(ClassStr, "Hardware failure");
4456 strcpy(ClassStr, "Communication error");
4459 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4460 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4461 ClassStr, ErrNum, pErrorMsg);
4465 #ifdef SK_DIAG_SUPPORT
4467 /*****************************************************************************
4469 * SkDrvEnterDiagMode - handles DIAG attach request
4472 * Notify the kernel to NOT access the card any longer due to DIAG
4473 * Deinitialize the Card
4478 int SkDrvEnterDiagMode(
4479 SK_AC *pAc) /* pointer to adapter context */
4481 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4482 SK_AC *pAC = pNet->pAC;
4484 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4485 sizeof(SK_PNMI_STRUCT_DATA));
4487 pAC->DiagModeActive = DIAG_ACTIVE;
4488 if (pAC->BoardLevel > SK_INIT_DATA) {
4489 if (netif_running(pAC->dev[0])) {
4490 pAC->WasIfUp[0] = SK_TRUE;
4491 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4492 DoPrintInterfaceChange = SK_FALSE;
4493 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4495 pAC->WasIfUp[0] = SK_FALSE;
4497 if (pNet != netdev_priv(pAC->dev[1])) {
4498 pNet = netdev_priv(pAC->dev[1]);
4499 if (netif_running(pAC->dev[1])) {
4500 pAC->WasIfUp[1] = SK_TRUE;
4501 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4502 DoPrintInterfaceChange = SK_FALSE;
4503 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4505 pAC->WasIfUp[1] = SK_FALSE;
4508 pAC->BoardLevel = SK_INIT_DATA;
4513 /*****************************************************************************
4515 * SkDrvLeaveDiagMode - handles DIAG detach request
4518 * Notify the kernel to may access the card again after use by DIAG
4519 * Initialize the Card
4524 int SkDrvLeaveDiagMode(
4525 SK_AC *pAc) /* pointer to adapter control context */
4527 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4528 sizeof(SK_PNMI_STRUCT_DATA));
4529 pAc->DiagModeActive = DIAG_NOTACTIVE;
4530 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4531 if (pAc->WasIfUp[0] == SK_TRUE) {
4532 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4533 DoPrintInterfaceChange = SK_FALSE;
4534 SkDrvInitAdapter(pAc, 0); /* first device */
4536 if (pAc->WasIfUp[1] == SK_TRUE) {
4537 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4538 DoPrintInterfaceChange = SK_FALSE;
4539 SkDrvInitAdapter(pAc, 1); /* second device */
4544 /*****************************************************************************
4546 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4549 * This function parses the PCI slot name information string and will
4550 * retrieve the devcie number out of it. The slot_name maintianed by
4551 * linux is in the form of '02:0a.0', whereas the first two characters
4552 * represent the bus number in hex (in the sample above this is
4553 * pci bus 0x02) and the next two characters the device number (0x0a).
4556 * SK_U32: The device number from the PCI slot name
4559 static SK_U32 ParseDeviceNbrFromSlotName(
4560 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4562 char *CurrCharPos = (char *) SlotName;
4563 int FirstNibble = -1;
4564 int SecondNibble = -1;
4567 while (*CurrCharPos != '\0') {
4568 if (*CurrCharPos == ':') {
4569 while (*CurrCharPos != '.') {
4571 if ( (*CurrCharPos >= '0') &&
4572 (*CurrCharPos <= '9')) {
4573 if (FirstNibble == -1) {
4574 /* dec. value for '0' */
4575 FirstNibble = *CurrCharPos - 48;
4577 SecondNibble = *CurrCharPos - 48;
4579 } else if ( (*CurrCharPos >= 'a') &&
4580 (*CurrCharPos <= 'f') ) {
4581 if (FirstNibble == -1) {
4582 FirstNibble = *CurrCharPos - 87;
4584 SecondNibble = *CurrCharPos - 87;
4591 Result = FirstNibble;
4592 Result = Result << 4; /* first nibble is higher one */
4593 Result = Result | SecondNibble;
4595 CurrCharPos++; /* next character */
4600 /****************************************************************************
4602 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4603 * called if Diag attaches to that card)
4606 * Close initialized adapter.
4610 * error code - on error
4612 static int SkDrvDeInitAdapter(
4613 SK_AC *pAC, /* pointer to adapter context */
4614 int devNbr) /* what device is to be handled */
4616 struct SK_NET_DEVICE *dev;
4618 dev = pAC->dev[devNbr];
4620 /* On Linux 2.6 the network driver does NOT mess with reference
4621 ** counts. The driver MUST be able to be unloaded at any time
4622 ** due to the possibility of hotplug.
4624 if (SkGeClose(dev) != 0) {
4629 } /* SkDrvDeInitAdapter() */
4631 /****************************************************************************
4633 * SkDrvInitAdapter - Initialize adapter (this function is only
4634 * called if Diag deattaches from that card)
4637 * Close initialized adapter.
4641 * error code - on error
4643 static int SkDrvInitAdapter(
4644 SK_AC *pAC, /* pointer to adapter context */
4645 int devNbr) /* what device is to be handled */
4647 struct SK_NET_DEVICE *dev;
4649 dev = pAC->dev[devNbr];
4651 if (SkGeOpen(dev) != 0) {
4656 ** Use correct MTU size and indicate to kernel TX queue can be started
4658 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4663 } /* SkDrvInitAdapter */
4668 /****************************************************************************/
4669 /* "debug only" section *****************************************************/
4670 /****************************************************************************/
4673 /*****************************************************************************
4675 * DumpMsg - print a frame
4678 * This function prints frames to the system logfile/to the console.
4683 static void DumpMsg(struct sk_buff *skb, char *str)
4688 printk("DumpMsg(): NULL-Message\n");
4692 if (skb->data == NULL) {
4693 printk("DumpMsg(): Message empty\n");
4701 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4703 DumpData((char *)skb->data, msglen);
4705 printk("------- End of message ---------\n");
4710 /*****************************************************************************
4712 * DumpData - print a data area
4715 * This function prints a area of data to the system logfile/to the
4721 static void DumpData(char *p, int size)
4725 char hex_buffer[180];
4726 char asc_buffer[180];
4727 char HEXCHAR[] = "0123456789ABCDEF";
4733 for (i=0; i < size; ) {
4734 if (*p >= '0' && *p <='z')
4735 asc_buffer[addr] = *p;
4737 asc_buffer[addr] = '.';
4739 asc_buffer[addr] = 0;
4740 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4742 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4744 hex_buffer[haddr] = ' ';
4746 hex_buffer[haddr] = 0;
4750 printk("%s %s\n", hex_buffer, asc_buffer);
4758 /*****************************************************************************
4760 * DumpLong - print a data area as long values
4763 * This function prints a area of data to the system logfile/to the
4769 static void DumpLong(char *pc, int size)
4773 char hex_buffer[180];
4774 char asc_buffer[180];
4775 char HEXCHAR[] = "0123456789ABCDEF";
4784 for (i=0; i < size; ) {
4786 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4788 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4790 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4792 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4794 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4796 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4798 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4800 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4802 hex_buffer[haddr] = ' ';
4804 hex_buffer[haddr] = 0;
4808 printk("%4x %s\n", (i-8)*4, hex_buffer);
4812 printk("------------------------\n");
4817 static int __devinit skge_probe_one(struct pci_dev *pdev,
4818 const struct pci_device_id *ent)
4821 DEV_NET *pNet = NULL;
4822 struct net_device *dev = NULL;
4823 static int boards_found = 0;
4824 int error = -ENODEV;
4828 if (pci_enable_device(pdev))
4831 /* Configure DMA attributes. */
4832 if (sizeof(dma_addr_t) > sizeof(u32) &&
4833 !(error = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
4835 error = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4837 printk(KERN_ERR "sk98lin %s unable to obtain 64 bit DMA "
4838 "for consistent allocations\n", pci_name(pdev));
4839 goto out_disable_device;
4842 error = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4844 printk(KERN_ERR "sk98lin %s no usable DMA configuration\n",
4846 goto out_disable_device;
4851 dev = alloc_etherdev(sizeof(DEV_NET));
4853 printk(KERN_ERR "sk98lin: unable to allocate etherdev "
4855 goto out_disable_device;
4858 pNet = netdev_priv(dev);
4859 pNet->pAC = kzalloc(sizeof(SK_AC), GFP_KERNEL);
4861 printk(KERN_ERR "sk98lin: unable to allocate adapter "
4863 goto out_free_netdev;
4871 pAC->CheckQueue = SK_FALSE;
4873 dev->irq = pdev->irq;
4875 error = SkGeInitPCI(pAC);
4877 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4878 goto out_free_netdev;
4881 SET_MODULE_OWNER(dev);
4882 dev->open = &SkGeOpen;
4883 dev->stop = &SkGeClose;
4884 dev->hard_start_xmit = &SkGeXmit;
4885 dev->get_stats = &SkGeStats;
4886 dev->set_multicast_list = &SkGeSetRxMode;
4887 dev->set_mac_address = &SkGeSetMacAddr;
4888 dev->do_ioctl = &SkGeIoctl;
4889 dev->change_mtu = &SkGeChangeMtu;
4890 #ifdef CONFIG_NET_POLL_CONTROLLER
4891 dev->poll_controller = &SkGePollController;
4893 SET_NETDEV_DEV(dev, &pdev->dev);
4894 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4896 /* Use only if yukon hardware */
4897 if (pAC->ChipsetType) {
4898 #ifdef USE_SK_TX_CHECKSUM
4899 dev->features |= NETIF_F_IP_CSUM;
4902 dev->features |= NETIF_F_SG;
4904 #ifdef USE_SK_RX_CHECKSUM
4905 pAC->RxPort[0].RxCsum = 1;
4910 dev->features |= NETIF_F_HIGHDMA;
4912 pAC->Index = boards_found++;
4914 error = SkGeBoardInit(dev, pAC);
4916 goto out_free_netdev;
4918 /* Read Adapter name from VPD */
4919 if (ProductStr(pAC, DeviceStr, sizeof(DeviceStr)) != 0) {
4921 printk(KERN_ERR "sk98lin: Could not read VPD data.\n");
4922 goto out_free_resources;
4925 /* Register net device */
4926 error = register_netdev(dev);
4928 printk(KERN_ERR "sk98lin: Could not register device.\n");
4929 goto out_free_resources;
4932 /* Print adapter specific string from vpd */
4933 printk("%s: %s\n", dev->name, DeviceStr);
4935 /* Print configuration settings */
4936 printk(" PrefPort:%c RlmtMode:%s\n",
4937 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4938 (pAC->RlmtMode==0) ? "Check Link State" :
4939 ((pAC->RlmtMode==1) ? "Check Link State" :
4940 ((pAC->RlmtMode==3) ? "Check Local Port" :
4941 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4942 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4944 SkGeYellowLED(pAC, pAC->IoBase, 1);
4946 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4947 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4954 pci_set_drvdata(pdev, dev);
4956 /* More then one port found */
4957 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4958 dev = alloc_etherdev(sizeof(DEV_NET));
4960 printk(KERN_ERR "sk98lin: unable to allocate etherdev "
4965 pNet = netdev_priv(dev);
4970 dev->open = &SkGeOpen;
4971 dev->stop = &SkGeClose;
4972 dev->hard_start_xmit = &SkGeXmit;
4973 dev->get_stats = &SkGeStats;
4974 dev->set_multicast_list = &SkGeSetRxMode;
4975 dev->set_mac_address = &SkGeSetMacAddr;
4976 dev->do_ioctl = &SkGeIoctl;
4977 dev->change_mtu = &SkGeChangeMtu;
4978 SET_NETDEV_DEV(dev, &pdev->dev);
4979 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4981 if (pAC->ChipsetType) {
4982 #ifdef USE_SK_TX_CHECKSUM
4983 dev->features |= NETIF_F_IP_CSUM;
4986 dev->features |= NETIF_F_SG;
4988 #ifdef USE_SK_RX_CHECKSUM
4989 pAC->RxPort[1].RxCsum = 1;
4994 dev->features |= NETIF_F_HIGHDMA;
4996 error = register_netdev(dev);
4998 printk(KERN_ERR "sk98lin: Could not register device"
4999 " for second port. (%d)\n", error);
5005 memcpy(&dev->dev_addr,
5006 &pAC->Addr.Net[1].CurrentMacAddress, 6);
5007 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
5009 printk("%s: %s\n", dev->name, DeviceStr);
5010 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
5015 /* Save the hardware revision */
5016 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
5017 (pAC->GIni.GIPciHwRev & 0x0F);
5019 /* Set driver globals */
5020 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
5021 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
5023 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
5024 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
5033 pci_disable_device(pdev);
5038 static void __devexit skge_remove_one(struct pci_dev *pdev)
5040 struct net_device *dev = pci_get_drvdata(pdev);
5041 DEV_NET *pNet = netdev_priv(dev);
5042 SK_AC *pAC = pNet->pAC;
5043 struct net_device *otherdev = pAC->dev[1];
5045 unregister_netdev(dev);
5047 SkGeYellowLED(pAC, pAC->IoBase, 0);
5049 if (pAC->BoardLevel == SK_INIT_RUN) {
5051 unsigned long Flags;
5053 /* board is still alive */
5054 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5055 EvPara.Para32[0] = 0;
5056 EvPara.Para32[1] = -1;
5057 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5058 EvPara.Para32[0] = 1;
5059 EvPara.Para32[1] = -1;
5060 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5061 SkEventDispatcher(pAC, pAC->IoBase);
5062 /* disable interrupts */
5063 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5064 SkGeDeInit(pAC, pAC->IoBase);
5065 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5066 pAC->BoardLevel = SK_INIT_DATA;
5067 /* We do NOT check here, if IRQ was pending, of course*/
5070 if (pAC->BoardLevel == SK_INIT_IO) {
5071 /* board is still alive */
5072 SkGeDeInit(pAC, pAC->IoBase);
5073 pAC->BoardLevel = SK_INIT_DATA;
5078 if (otherdev != dev)
5079 free_netdev(otherdev);
5084 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5086 struct net_device *dev = pci_get_drvdata(pdev);
5087 DEV_NET *pNet = netdev_priv(dev);
5088 SK_AC *pAC = pNet->pAC;
5089 struct net_device *otherdev = pAC->dev[1];
5091 if (netif_running(dev)) {
5092 netif_carrier_off(dev);
5093 DoPrintInterfaceChange = SK_FALSE;
5094 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5095 netif_device_detach(dev);
5097 if (otherdev != dev) {
5098 if (netif_running(otherdev)) {
5099 netif_carrier_off(otherdev);
5100 DoPrintInterfaceChange = SK_FALSE;
5101 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5102 netif_device_detach(otherdev);
5106 pci_save_state(pdev);
5107 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5108 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5109 free_irq(dev->irq, dev);
5111 pci_disable_device(pdev);
5112 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5117 static int skge_resume(struct pci_dev *pdev)
5119 struct net_device *dev = pci_get_drvdata(pdev);
5120 DEV_NET *pNet = netdev_priv(dev);
5121 SK_AC *pAC = pNet->pAC;
5122 struct net_device *otherdev = pAC->dev[1];
5125 pci_set_power_state(pdev, PCI_D0);
5126 pci_restore_state(pdev);
5127 pci_enable_device(pdev);
5128 pci_set_master(pdev);
5129 if (pAC->GIni.GIMacsFound == 2)
5130 ret = request_irq(dev->irq, SkGeIsr, IRQF_SHARED, "sk98lin", dev);
5132 ret = request_irq(dev->irq, SkGeIsrOnePort, IRQF_SHARED, "sk98lin", dev);
5134 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5135 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5137 pci_disable_device(pdev);
5141 netif_device_attach(dev);
5142 if (netif_running(dev)) {
5143 DoPrintInterfaceChange = SK_FALSE;
5144 SkDrvInitAdapter(pAC, 0); /* first device */
5146 if (otherdev != dev) {
5147 netif_device_attach(otherdev);
5148 if (netif_running(otherdev)) {
5149 DoPrintInterfaceChange = SK_FALSE;
5150 SkDrvInitAdapter(pAC, 1); /* second device */
5157 #define skge_suspend NULL
5158 #define skge_resume NULL
5161 static struct pci_device_id skge_pci_tbl[] = {
5162 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5163 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5164 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5165 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5166 /* DLink card does not have valid VPD so this driver gags
5167 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5169 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5170 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5171 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5172 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5173 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5177 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5179 static struct pci_driver skge_driver = {
5181 .id_table = skge_pci_tbl,
5182 .probe = skge_probe_one,
5183 .remove = __devexit_p(skge_remove_one),
5184 .suspend = skge_suspend,
5185 .resume = skge_resume,
5188 static int __init skge_init(void)
5190 return pci_register_driver(&skge_driver);
5193 static void __exit skge_exit(void)
5195 pci_unregister_driver(&skge_driver);
5198 module_init(skge_init);
5199 module_exit(skge_exit);