1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.45 $
6 * Date: $Date: 2004/02/12 14:41:02 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
19 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
20 * SysKonnects GEnesis Solaris driver
21 * Author: Christoph Goos (cgoos@syskonnect.de)
22 * Mirko Lindner (mlindner@syskonnect.de)
24 * Address all question to: linux@syskonnect.de
26 * The technical manual for the adapters is available from SysKonnect's
27 * web pages: www.syskonnect.com
28 * Goto "Support" and search Knowledge Base for "manual".
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * The information in this file is provided "AS IS" without warranty.
37 ******************************************************************************/
39 /******************************************************************************
41 * Possible compiler options (#define xxx / -Dxxx):
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
46 ******************************************************************************/
48 /******************************************************************************
52 * This is the main module of the Linux GE driver.
54 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
55 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
56 * Those are used for drivers on multiple OS', so some thing may seem
57 * unnecessary complicated on Linux. Please do not try to 'clean up'
58 * them without VERY good reasons, because this will make it more
59 * difficult to keep the Linux driver in synchronisation with the
62 * Include file hierarchy:
79 * <linux/etherdevice.h>
81 * those three depending on kernel version used:
106 ******************************************************************************/
108 #include "h/skversion.h"
110 #include <linux/module.h>
111 #include <linux/moduleparam.h>
112 #include <linux/init.h>
113 #include <linux/dma-mapping.h>
114 #include <linux/ip.h>
116 #include "h/skdrv1st.h"
117 #include "h/skdrv2nd.h"
119 /*******************************************************************************
123 ******************************************************************************/
125 /* for debuging on x86 only */
126 /* #define BREAKPOINT() asm(" int $3"); */
128 /* use the transmit hw checksum driver functionality */
129 #define USE_SK_TX_CHECKSUM
131 /* use the receive hw checksum driver functionality */
132 #define USE_SK_RX_CHECKSUM
134 /* use the scatter-gather functionality with sendfile() */
137 /* use of a transmit complete interrupt */
138 #define USE_TX_COMPLETE
141 * threshold for copying small receive frames
142 * set to 0 to avoid copying, set to 9001 to copy all frames
144 #define SK_COPY_THRESHOLD 50
146 /* number of adapters that can be configured via command line params */
147 #define SK_MAX_CARD_PARAM 16
152 * use those defines for a compile-in version of the driver instead
153 * of command line parameters
155 // #define LINK_SPEED_A {"Auto", }
156 // #define LINK_SPEED_B {"Auto", }
157 // #define AUTO_NEG_A {"Sense", }
158 // #define AUTO_NEG_B {"Sense", }
159 // #define DUP_CAP_A {"Both", }
160 // #define DUP_CAP_B {"Both", }
161 // #define FLOW_CTRL_A {"SymOrRem", }
162 // #define FLOW_CTRL_B {"SymOrRem", }
163 // #define ROLE_A {"Auto", }
164 // #define ROLE_B {"Auto", }
165 // #define PREF_PORT {"A", }
166 // #define CON_TYPE {"Auto", }
167 // #define RLMT_MODE {"CheckLinkState", }
169 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
170 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
171 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
175 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
176 SK_DUP_LED_NORMAL | \
180 /* Isr return value */
181 #define SkIsrRetVar irqreturn_t
182 #define SkIsrRetNone IRQ_NONE
183 #define SkIsrRetHandled IRQ_HANDLED
186 /*******************************************************************************
188 * Local Function Prototypes
190 ******************************************************************************/
192 static void FreeResources(struct SK_NET_DEVICE *dev);
193 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
194 static SK_BOOL BoardAllocMem(SK_AC *pAC);
195 static void BoardFreeMem(SK_AC *pAC);
196 static void BoardInitMem(SK_AC *pAC);
197 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
198 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
199 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
200 static int SkGeOpen(struct SK_NET_DEVICE *dev);
201 static int SkGeClose(struct SK_NET_DEVICE *dev);
202 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
203 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
204 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
205 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
206 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
207 static void GetConfiguration(SK_AC*);
208 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
209 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
210 static void FillRxRing(SK_AC*, RX_PORT*);
211 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
212 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
213 static void ClearAndStartRx(SK_AC*, int);
214 static void ClearTxIrq(SK_AC*, int, int);
215 static void ClearRxRing(SK_AC*, RX_PORT*);
216 static void ClearTxRing(SK_AC*, TX_PORT*);
217 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
218 static void PortReInitBmu(SK_AC*, int);
219 static int SkGeIocMib(DEV_NET*, unsigned int, int);
220 static int SkGeInitPCI(SK_AC *pAC);
221 static void StartDrvCleanupTimer(SK_AC *pAC);
222 static void StopDrvCleanupTimer(SK_AC *pAC);
223 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
225 #ifdef SK_DIAG_SUPPORT
226 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
227 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
228 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
231 /*******************************************************************************
233 * Extern Function Prototypes
235 ******************************************************************************/
236 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
237 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
238 extern void SkDimStartModerationTimer(SK_AC *pAC);
239 extern void SkDimModerate(SK_AC *pAC);
240 extern void SkGeBlinkTimer(unsigned long data);
243 static void DumpMsg(struct sk_buff*, char*);
244 static void DumpData(char*, int);
245 static void DumpLong(char*, int);
248 /* global variables *********************************************************/
249 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
250 extern struct ethtool_ops SkGeEthtoolOps;
252 /* local variables **********************************************************/
253 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
254 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
256 /*****************************************************************************
258 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
261 * This routine writes a 32 bit value to the pci configuration
265 * 0 - indicate everything worked ok.
266 * != 0 - error indication
268 static inline int SkPciWriteCfgDWord(
269 SK_AC *pAC, /* Adapter Control structure pointer */
270 int PciAddr, /* PCI register address */
271 SK_U32 Val) /* pointer to store the read value */
273 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
275 } /* SkPciWriteCfgDWord */
277 /*****************************************************************************
279 * SkGeInitPCI - Init the PCI resources
282 * This function initialize the PCI resources and IO
287 int SkGeInitPCI(SK_AC *pAC)
289 struct SK_NET_DEVICE *dev = pAC->dev[0];
290 struct pci_dev *pdev = pAC->PciDev;
293 if (pci_enable_device(pdev) != 0) {
297 dev->mem_start = pci_resource_start (pdev, 0);
298 pci_set_master(pdev);
300 if (pci_request_regions(pdev, "sk98lin") != 0) {
307 * On big endian machines, we use the adapter's aibility of
308 * reading the descriptors as big endian.
312 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
313 our2 |= PCI_REV_DESC;
314 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
319 * Remap the regs into kernel space.
321 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
331 pci_release_regions(pdev);
333 pci_disable_device(pdev);
338 /*****************************************************************************
340 * FreeResources - release resources allocated for adapter
343 * This function releases the IRQ, unmaps the IO and
344 * frees the desriptor ring.
349 static void FreeResources(struct SK_NET_DEVICE *dev)
355 pNet = netdev_priv(dev);
357 AllocFlag = pAC->AllocFlag;
359 pci_release_regions(pAC->PciDev);
361 if (AllocFlag & SK_ALLOC_IRQ) {
362 free_irq(dev->irq, dev);
365 iounmap(pAC->IoBase);
367 if (pAC->pDescrMem) {
371 } /* FreeResources */
373 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
374 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
375 MODULE_LICENSE("GPL");
378 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
380 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
384 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
386 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
390 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
392 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
396 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
398 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
402 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
404 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
408 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
410 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
414 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
416 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
420 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
422 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
426 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
428 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
432 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
434 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
438 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
440 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
444 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
446 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
450 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
452 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
455 static int IntsPerSec[SK_MAX_CARD_PARAM];
456 static char *Moderation[SK_MAX_CARD_PARAM];
457 static char *ModerationMask[SK_MAX_CARD_PARAM];
458 static char *AutoSizing[SK_MAX_CARD_PARAM];
459 static char *Stats[SK_MAX_CARD_PARAM];
461 module_param_array(Speed_A, charp, NULL, 0);
462 module_param_array(Speed_B, charp, NULL, 0);
463 module_param_array(AutoNeg_A, charp, NULL, 0);
464 module_param_array(AutoNeg_B, charp, NULL, 0);
465 module_param_array(DupCap_A, charp, NULL, 0);
466 module_param_array(DupCap_B, charp, NULL, 0);
467 module_param_array(FlowCtrl_A, charp, NULL, 0);
468 module_param_array(FlowCtrl_B, charp, NULL, 0);
469 module_param_array(Role_A, charp, NULL, 0);
470 module_param_array(Role_B, charp, NULL, 0);
471 module_param_array(ConType, charp, NULL, 0);
472 module_param_array(PrefPort, charp, NULL, 0);
473 module_param_array(RlmtMode, charp, NULL, 0);
474 /* used for interrupt moderation */
475 module_param_array(IntsPerSec, int, NULL, 0);
476 module_param_array(Moderation, charp, NULL, 0);
477 module_param_array(Stats, charp, NULL, 0);
478 module_param_array(ModerationMask, charp, NULL, 0);
479 module_param_array(AutoSizing, charp, NULL, 0);
481 /*****************************************************************************
483 * SkGeBoardInit - do level 0 and 1 initialization
486 * This function prepares the board hardware for running. The desriptor
487 * ring is set up, the IRQ is allocated and the configuration settings
491 * 0, if everything is ok
494 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
498 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
499 char *VerStr = VER_STRING;
500 int Ret; /* return code of request_irq */
503 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
504 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
505 for (i=0; i<SK_MAX_MACS; i++) {
506 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
507 pAC->TxPort[i][0].PortIndex = i;
508 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
509 pAC->RxPort[i].PortIndex = i;
512 /* Initialize the mutexes */
513 for (i=0; i<SK_MAX_MACS; i++) {
514 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
515 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
517 spin_lock_init(&pAC->SlowPathLock);
519 /* setup phy_id blink timer */
520 pAC->BlinkTimer.function = SkGeBlinkTimer;
521 pAC->BlinkTimer.data = (unsigned long) dev;
522 init_timer(&pAC->BlinkTimer);
524 /* level 0 init common modules here */
526 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
527 /* Does a RESET on board ...*/
528 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
529 printk("HWInit (0) failed.\n");
530 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
533 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
534 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
535 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
536 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
537 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
538 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
540 pAC->BoardLevel = SK_INIT_DATA;
541 pAC->RxBufSize = ETH_BUF_SIZE;
543 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
544 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
546 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
548 /* level 1 init common modules here (HW init) */
549 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
550 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
551 printk("sk98lin: HWInit (1) failed.\n");
552 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
555 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
556 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
557 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
558 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
559 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
560 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
562 /* Set chipset type support */
563 pAC->ChipsetType = 0;
564 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
565 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
566 pAC->ChipsetType = 1;
569 GetConfiguration(pAC);
570 if (pAC->RlmtNets == 2) {
571 pAC->GIni.GIPortUsage = SK_MUL_LINK;
574 pAC->BoardLevel = SK_INIT_IO;
575 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
577 if (pAC->GIni.GIMacsFound == 2) {
578 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
579 } else if (pAC->GIni.GIMacsFound == 1) {
580 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
583 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
584 pAC->GIni.GIMacsFound);
589 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
593 pAC->AllocFlag |= SK_ALLOC_IRQ;
595 /* Alloc memory for this board (Mem for RxD/TxD) : */
596 if(!BoardAllocMem(pAC)) {
597 printk("No memory for descriptor rings.\n");
602 /* tschilling: New common function with minimum size check. */
604 if (pAC->RlmtNets == 2) {
608 if (SkGeInitAssignRamToQueues(
613 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
618 } /* SkGeBoardInit */
621 /*****************************************************************************
623 * BoardAllocMem - allocate the memory for the descriptor rings
626 * This function allocates the memory for all descriptor rings.
627 * Each ring is aligned for the desriptor alignment and no ring
628 * has a 4 GByte boundary in it (because the upper 32 bit must
629 * be constant for all descriptiors in one rings).
632 * SK_TRUE, if all memory could be allocated
635 static SK_BOOL BoardAllocMem(
638 caddr_t pDescrMem; /* pointer to descriptor memory area */
639 size_t AllocLength; /* length of complete descriptor area */
640 int i; /* loop counter */
641 unsigned long BusAddr;
644 /* rings plus one for alignment (do not cross 4 GB boundary) */
645 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
646 #if (BITS_PER_LONG == 32)
647 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
649 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
653 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
656 if (pDescrMem == NULL) {
659 pAC->pDescrMem = pDescrMem;
660 BusAddr = (unsigned long) pAC->pDescrMemDMA;
662 /* Descriptors need 8 byte alignment, and this is ensured
663 * by pci_alloc_consistent.
665 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
666 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
667 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
668 i, (unsigned long) pDescrMem,
670 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
671 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
672 pDescrMem += TX_RING_SIZE;
673 BusAddr += TX_RING_SIZE;
675 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
676 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
677 i, (unsigned long) pDescrMem,
678 (unsigned long)BusAddr));
679 pAC->RxPort[i].pRxDescrRing = pDescrMem;
680 pAC->RxPort[i].VRxDescrRing = BusAddr;
681 pDescrMem += RX_RING_SIZE;
682 BusAddr += RX_RING_SIZE;
686 } /* BoardAllocMem */
689 /****************************************************************************
691 * BoardFreeMem - reverse of BoardAllocMem
694 * Free all memory allocated in BoardAllocMem: adapter context,
695 * descriptor rings, locks.
699 static void BoardFreeMem(
702 size_t AllocLength; /* length of complete descriptor area */
704 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
706 #if (BITS_PER_LONG == 32)
707 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
709 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
713 pci_free_consistent(pAC->PciDev, AllocLength,
714 pAC->pDescrMem, pAC->pDescrMemDMA);
715 pAC->pDescrMem = NULL;
719 /*****************************************************************************
721 * BoardInitMem - initiate the descriptor rings
724 * This function sets the descriptor rings up in memory.
725 * The adapter is initialized with the descriptor start addresses.
729 static void BoardInitMem(
730 SK_AC *pAC) /* pointer to adapter context */
732 int i; /* loop counter */
733 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
734 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
736 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
739 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
740 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
741 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
742 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
744 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
747 pAC->TxPort[i][0].pTxDescrRing,
748 pAC->TxPort[i][0].VTxDescrRing,
749 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
750 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
751 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
752 &pAC->TxPort[i][0].TxdRingFree,
756 pAC->RxPort[i].pRxDescrRing,
757 pAC->RxPort[i].VRxDescrRing,
758 &pAC->RxPort[i].pRxdRingHead,
759 &pAC->RxPort[i].pRxdRingTail,
760 &pAC->RxPort[i].pRxdRingPrev,
761 &pAC->RxPort[i].RxdRingFree,
767 /*****************************************************************************
769 * SetupRing - create one descriptor ring
772 * This function creates one descriptor ring in the given memory area.
773 * The head, tail and number of free descriptors in the ring are set.
778 static void SetupRing(
780 void *pMemArea, /* a pointer to the memory area for the ring */
781 uintptr_t VMemArea, /* the virtual bus address of the memory area */
782 RXD **ppRingHead, /* address where the head should be written */
783 RXD **ppRingTail, /* address where the tail should be written */
784 RXD **ppRingPrev, /* address where the tail should be written */
785 int *pRingFree, /* address where the # of free descr. goes */
786 SK_BOOL IsTx) /* flag: is this a tx ring */
788 int i; /* loop counter */
789 int DescrSize; /* the size of a descriptor rounded up to alignment*/
790 int DescrNum; /* number of descriptors per ring */
791 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
792 RXD *pNextDescr; /* pointer to the next descriptor */
793 RXD *pPrevDescr; /* pointer to the previous descriptor */
794 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
796 if (IsTx == SK_TRUE) {
797 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
799 DescrNum = TX_RING_SIZE / DescrSize;
801 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
803 DescrNum = RX_RING_SIZE / DescrSize;
806 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
807 ("Descriptor size: %d Descriptor Number: %d\n",
808 DescrSize,DescrNum));
810 pDescr = (RXD*) pMemArea;
812 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
813 VNextDescr = VMemArea + DescrSize;
814 for(i=0; i<DescrNum; i++) {
815 /* set the pointers right */
816 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
817 pDescr->pNextRxd = pNextDescr;
818 pDescr->TcpSumStarts = 0;
820 /* advance one step */
823 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
824 VNextDescr += DescrSize;
826 pPrevDescr->pNextRxd = (RXD*) pMemArea;
827 pPrevDescr->VNextRxd = VMemArea;
828 pDescr = (RXD*) pMemArea;
829 *ppRingHead = (RXD*) pMemArea;
830 *ppRingTail = *ppRingHead;
831 *ppRingPrev = pPrevDescr;
832 *pRingFree = DescrNum;
836 /*****************************************************************************
838 * PortReInitBmu - re-initiate the descriptor rings for one port
841 * This function reinitializes the descriptor rings of one port
842 * in memory. The port must be stopped before.
843 * The HW is initialized with the descriptor start addresses.
848 static void PortReInitBmu(
849 SK_AC *pAC, /* pointer to adapter context */
850 int PortIndex) /* index of the port for which to re-init */
852 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
855 /* set address of first descriptor of ring in BMU */
856 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
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) &
862 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
863 (uint32_t)(((caddr_t)
864 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
865 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
866 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
867 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
868 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
869 pAC->RxPort[PortIndex].pRxDescrRing +
870 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
871 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
872 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
873 pAC->RxPort[PortIndex].pRxDescrRing +
874 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
875 } /* PortReInitBmu */
878 /****************************************************************************
880 * SkGeIsr - handle adapter interrupts
883 * The interrupt routine is called when the network adapter
884 * generates an interrupt. It may also be called if another device
885 * shares this interrupt vector with the driver.
890 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
892 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
895 SK_U32 IntSrc; /* interrupts source register contents */
897 pNet = netdev_priv(dev);
901 * Check and process if its our interrupt
903 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
908 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
909 #if 0 /* software irq currently not used */
910 if (IntSrc & IS_IRQ_SW) {
911 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
912 SK_DBGCAT_DRV_INT_SRC,
916 if (IntSrc & IS_R1_F) {
917 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
918 SK_DBGCAT_DRV_INT_SRC,
920 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
921 SK_PNMI_CNT_RX_INTR(pAC, 0);
923 if (IntSrc & IS_R2_F) {
924 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
925 SK_DBGCAT_DRV_INT_SRC,
927 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
928 SK_PNMI_CNT_RX_INTR(pAC, 1);
930 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
931 if (IntSrc & IS_XA1_F) {
932 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
933 SK_DBGCAT_DRV_INT_SRC,
934 ("EOF AS TX1 IRQ\n"));
935 SK_PNMI_CNT_TX_INTR(pAC, 0);
936 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
937 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
938 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
940 if (IntSrc & IS_XA2_F) {
941 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
942 SK_DBGCAT_DRV_INT_SRC,
943 ("EOF AS TX2 IRQ\n"));
944 SK_PNMI_CNT_TX_INTR(pAC, 1);
945 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
946 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
947 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
949 #if 0 /* only if sync. queues used */
950 if (IntSrc & IS_XS1_F) {
951 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
952 SK_DBGCAT_DRV_INT_SRC,
953 ("EOF SY TX1 IRQ\n"));
954 SK_PNMI_CNT_TX_INTR(pAC, 1);
955 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
956 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
957 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
958 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
960 if (IntSrc & IS_XS2_F) {
961 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
962 SK_DBGCAT_DRV_INT_SRC,
963 ("EOF SY TX2 IRQ\n"));
964 SK_PNMI_CNT_TX_INTR(pAC, 1);
965 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
966 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
967 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
968 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
973 /* do all IO at once */
974 if (IntSrc & IS_R1_F)
975 ClearAndStartRx(pAC, 0);
976 if (IntSrc & IS_R2_F)
977 ClearAndStartRx(pAC, 1);
978 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
979 if (IntSrc & IS_XA1_F)
980 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
981 if (IntSrc & IS_XA2_F)
982 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
984 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
985 } /* while (IntSrc & IRQ_MASK != 0) */
987 IntSrc &= pAC->GIni.GIValIrqMask;
988 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
989 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
990 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
991 pAC->CheckQueue = SK_FALSE;
992 spin_lock(&pAC->SlowPathLock);
993 if (IntSrc & SPECIAL_IRQS)
994 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
996 SkEventDispatcher(pAC, pAC->IoBase);
997 spin_unlock(&pAC->SlowPathLock);
1000 * do it all again is case we cleared an interrupt that
1001 * came in after handling the ring (OUTs may be delayed
1002 * in hardware buffers, but are through after IN)
1004 * rroesler: has been commented out and shifted to
1005 * SkGeDrvEvent(), because it is timer
1008 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1009 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1012 if (pAC->CheckQueue) {
1013 pAC->CheckQueue = SK_FALSE;
1014 spin_lock(&pAC->SlowPathLock);
1015 SkEventDispatcher(pAC, pAC->IoBase);
1016 spin_unlock(&pAC->SlowPathLock);
1019 /* IRQ is processed - Enable IRQs again*/
1020 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1022 return SkIsrRetHandled;
1026 /****************************************************************************
1028 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1031 * The interrupt routine is called when the network adapter
1032 * generates an interrupt. It may also be called if another device
1033 * shares this interrupt vector with the driver.
1034 * This is the same as above, but handles only one port.
1039 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1041 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1044 SK_U32 IntSrc; /* interrupts source register contents */
1046 pNet = netdev_priv(dev);
1050 * Check and process if its our interrupt
1052 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1054 return SkIsrRetNone;
1057 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1058 #if 0 /* software irq currently not used */
1059 if (IntSrc & IS_IRQ_SW) {
1060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1061 SK_DBGCAT_DRV_INT_SRC,
1062 ("Software IRQ\n"));
1065 if (IntSrc & IS_R1_F) {
1066 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1067 SK_DBGCAT_DRV_INT_SRC,
1069 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1070 SK_PNMI_CNT_RX_INTR(pAC, 0);
1072 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1073 if (IntSrc & IS_XA1_F) {
1074 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1075 SK_DBGCAT_DRV_INT_SRC,
1076 ("EOF AS TX1 IRQ\n"));
1077 SK_PNMI_CNT_TX_INTR(pAC, 0);
1078 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1079 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1080 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1082 #if 0 /* only if sync. queues used */
1083 if (IntSrc & IS_XS1_F) {
1084 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1085 SK_DBGCAT_DRV_INT_SRC,
1086 ("EOF SY TX1 IRQ\n"));
1087 SK_PNMI_CNT_TX_INTR(pAC, 0);
1088 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1089 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1090 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1091 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1096 /* do all IO at once */
1097 if (IntSrc & IS_R1_F)
1098 ClearAndStartRx(pAC, 0);
1099 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1100 if (IntSrc & IS_XA1_F)
1101 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1103 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1104 } /* while (IntSrc & IRQ_MASK != 0) */
1106 IntSrc &= pAC->GIni.GIValIrqMask;
1107 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1108 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1109 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1110 pAC->CheckQueue = SK_FALSE;
1111 spin_lock(&pAC->SlowPathLock);
1112 if (IntSrc & SPECIAL_IRQS)
1113 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1115 SkEventDispatcher(pAC, pAC->IoBase);
1116 spin_unlock(&pAC->SlowPathLock);
1119 * do it all again is case we cleared an interrupt that
1120 * came in after handling the ring (OUTs may be delayed
1121 * in hardware buffers, but are through after IN)
1123 * rroesler: has been commented out and shifted to
1124 * SkGeDrvEvent(), because it is timer
1127 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1130 /* IRQ is processed - Enable IRQs again*/
1131 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1133 return SkIsrRetHandled;
1134 } /* SkGeIsrOnePort */
1136 #ifdef CONFIG_NET_POLL_CONTROLLER
1137 /****************************************************************************
1139 * SkGePollController - polling receive, for netconsole
1142 * Polling receive - used by netconsole and other diagnostic tools
1143 * to allow network i/o with interrupts disabled.
1147 static void SkGePollController(struct net_device *dev)
1149 disable_irq(dev->irq);
1150 SkGeIsr(dev->irq, dev, NULL);
1151 enable_irq(dev->irq);
1155 /****************************************************************************
1157 * SkGeOpen - handle start of initialized adapter
1160 * This function starts the initialized adapter.
1161 * The board level variable is set and the adapter is
1162 * brought to full functionality.
1163 * The device flags are set for operation.
1164 * Do all necessary level 2 initialization, enable interrupts and
1165 * give start command to RLMT.
1171 static int SkGeOpen(
1172 struct SK_NET_DEVICE *dev)
1176 unsigned long Flags; /* for spin lock */
1178 SK_EVPARA EvPara; /* an event parameter union */
1180 pNet = netdev_priv(dev);
1183 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1184 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1186 #ifdef SK_DIAG_SUPPORT
1187 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1188 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1189 return (-1); /* still in use by diag; deny actions */
1194 /* Set blink mode */
1195 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1196 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1198 if (pAC->BoardLevel == SK_INIT_DATA) {
1199 /* level 1 init common modules here */
1200 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1201 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1204 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1205 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1206 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1207 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1208 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1209 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1210 pAC->BoardLevel = SK_INIT_IO;
1213 if (pAC->BoardLevel != SK_INIT_RUN) {
1214 /* tschilling: Level 2 init modules here, check return value. */
1215 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1216 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1219 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1220 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1221 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1222 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1223 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1224 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1225 pAC->BoardLevel = SK_INIT_RUN;
1228 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1229 /* Enable transmit descriptor polling. */
1230 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1231 FillRxRing(pAC, &pAC->RxPort[i]);
1233 SkGeYellowLED(pAC, pAC->IoBase, 1);
1235 StartDrvCleanupTimer(pAC);
1236 SkDimEnableModerationIfNeeded(pAC);
1237 SkDimDisplayModerationSettings(pAC);
1239 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1241 /* enable Interrupts */
1242 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1243 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1245 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1247 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1248 EvPara.Para32[0] = pAC->RlmtNets;
1249 EvPara.Para32[1] = -1;
1250 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1252 EvPara.Para32[0] = pAC->RlmtMode;
1253 EvPara.Para32[1] = 0;
1254 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1258 EvPara.Para32[0] = pNet->NetNr;
1259 EvPara.Para32[1] = -1;
1260 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1261 SkEventDispatcher(pAC, pAC->IoBase);
1262 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1267 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1268 ("SkGeOpen suceeded\n"));
1274 /****************************************************************************
1276 * SkGeClose - Stop initialized adapter
1279 * Close initialized adapter.
1283 * error code - on error
1285 static int SkGeClose(
1286 struct SK_NET_DEVICE *dev)
1292 unsigned long Flags; /* for spin lock */
1297 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1298 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1300 pNet = netdev_priv(dev);
1303 #ifdef SK_DIAG_SUPPORT
1304 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1305 if (pAC->DiagFlowCtrl == SK_FALSE) {
1307 ** notify that the interface which has been closed
1308 ** by operator interaction must not be started up
1309 ** again when the DIAG has finished.
1311 newPtrNet = netdev_priv(pAC->dev[0]);
1312 if (newPtrNet == pNet) {
1313 pAC->WasIfUp[0] = SK_FALSE;
1315 pAC->WasIfUp[1] = SK_FALSE;
1317 return 0; /* return to system everything is fine... */
1319 pAC->DiagFlowCtrl = SK_FALSE;
1324 netif_stop_queue(dev);
1326 if (pAC->RlmtNets == 1)
1327 PortIdx = pAC->ActivePort;
1329 PortIdx = pNet->NetNr;
1331 StopDrvCleanupTimer(pAC);
1334 * Clear multicast table, promiscuous mode ....
1336 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1337 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1340 if (pAC->MaxPorts == 1) {
1341 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1342 /* disable interrupts */
1343 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1344 EvPara.Para32[0] = pNet->NetNr;
1345 EvPara.Para32[1] = -1;
1346 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1347 SkEventDispatcher(pAC, pAC->IoBase);
1348 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1349 /* stop the hardware */
1350 SkGeDeInit(pAC, pAC->IoBase);
1351 pAC->BoardLevel = SK_INIT_DATA;
1352 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1355 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1356 EvPara.Para32[0] = pNet->NetNr;
1357 EvPara.Para32[1] = -1;
1358 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1359 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1360 SkEventDispatcher(pAC, pAC->IoBase);
1361 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1364 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1365 [TX_PRIO_LOW].TxDesRingLock, Flags);
1366 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1367 SK_STOP_ALL, SK_HARD_RST);
1368 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1369 [TX_PRIO_LOW].TxDesRingLock, Flags);
1372 if (pAC->RlmtNets == 1) {
1373 /* clear all descriptor rings */
1374 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1375 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1376 ClearRxRing(pAC, &pAC->RxPort[i]);
1377 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1380 /* clear port descriptor rings */
1381 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1382 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1383 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1386 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1387 ("SkGeClose: done "));
1389 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1390 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1391 sizeof(SK_PNMI_STRUCT_DATA));
1399 /*****************************************************************************
1401 * SkGeXmit - Linux frame transmit function
1404 * The system calls this function to send frames onto the wire.
1405 * It puts the frame in the tx descriptor ring. If the ring is
1406 * full then, the 'tbusy' flag is set.
1409 * 0, if everything is ok
1411 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1412 * allocated skb's) !!!
1414 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1418 int Rc; /* return code of XmitFrame */
1420 pNet = netdev_priv(dev);
1423 if ((!skb_shinfo(skb)->nr_frags) ||
1424 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1425 /* Don't activate scatter-gather and hardware checksum */
1427 if (pAC->RlmtNets == 2)
1430 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1435 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1438 /* scatter-gather and hardware TCP checksumming anabled*/
1439 if (pAC->RlmtNets == 2)
1442 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1447 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1451 /* Transmitter out of resources? */
1453 netif_stop_queue(dev);
1456 /* If not taken, give buffer ownership back to the
1462 dev->trans_start = jiffies;
1467 /*****************************************************************************
1469 * XmitFrame - fill one socket buffer into the transmit ring
1472 * This function puts a message into the transmit descriptor ring
1473 * if there is a descriptors left.
1474 * Linux skb's consist of only one continuous buffer.
1475 * The first step locks the ring. It is held locked
1476 * all time to avoid problems with SWITCH_../PORT_RESET.
1477 * Then the descriptoris allocated.
1478 * The second part is linking the buffer to the descriptor.
1479 * At the very last, the Control field of the descriptor
1480 * is made valid for the BMU and a start TX command is given
1484 * > 0 - on succes: the number of bytes in the message
1485 * = 0 - on resource shortage: this frame sent or dropped, now
1486 * the ring is full ( -> set tbusy)
1487 * < 0 - on failure: other problems ( -> return failure to upper layers)
1489 static int XmitFrame(
1490 SK_AC *pAC, /* pointer to adapter context */
1491 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1492 struct sk_buff *pMessage) /* pointer to send-message */
1494 TXD *pTxd; /* the rxd to fill */
1496 unsigned long Flags;
1498 int BytesSend = pMessage->len;
1500 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1502 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1503 #ifndef USE_TX_COMPLETE
1504 FreeTxDescriptors(pAC, pTxPort);
1506 if (pTxPort->TxdRingFree == 0) {
1508 ** no enough free descriptors in ring at the moment.
1509 ** Maybe free'ing some old one help?
1511 FreeTxDescriptors(pAC, pTxPort);
1512 if (pTxPort->TxdRingFree == 0) {
1513 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1514 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1515 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1516 SK_DBGCAT_DRV_TX_PROGRESS,
1517 ("XmitFrame failed\n"));
1519 ** the desired message can not be sent
1520 ** Because tbusy seems to be set, the message
1521 ** should not be freed here. It will be used
1522 ** by the scheduler of the ethernet handler
1529 ** If the passed socket buffer is of smaller MTU-size than 60,
1530 ** copy everything into new buffer and fill all bytes between
1531 ** the original packet end and the new packet end of 60 with 0x00.
1532 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1534 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1535 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1536 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1539 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1543 ** advance head counter behind descriptor needed for this frame,
1544 ** so that needed descriptor is reserved from that on. The next
1545 ** action will be to add the passed buffer to the TX-descriptor
1547 pTxd = pTxPort->pTxdRingHead;
1548 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1549 pTxPort->TxdRingFree--;
1552 DumpMsg(pMessage, "XmitFrame");
1556 ** First step is to map the data to be sent via the adapter onto
1557 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1558 ** and 2.6 need to use pci_map_page() for that mapping.
1560 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1561 virt_to_page(pMessage->data),
1562 ((unsigned long) pMessage->data & ~PAGE_MASK),
1565 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1566 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1567 pTxd->pMBuf = pMessage;
1569 if (pMessage->ip_summed == CHECKSUM_HW) {
1570 u16 hdrlen = pMessage->h.raw - pMessage->data;
1571 u16 offset = hdrlen + pMessage->csum;
1573 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1574 (pAC->GIni.GIChipRev == 0) &&
1575 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1576 pTxd->TBControl = BMU_TCP_CHECK;
1578 pTxd->TBControl = BMU_UDP_CHECK;
1581 pTxd->TcpSumOfs = 0;
1582 pTxd->TcpSumSt = hdrlen;
1583 pTxd->TcpSumWr = offset;
1585 pTxd->TBControl |= BMU_OWN | BMU_STF |
1587 #ifdef USE_TX_COMPLETE
1592 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1594 #ifdef USE_TX_COMPLETE
1601 ** If previous descriptor already done, give TX start cmd
1603 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1604 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1605 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1609 ** after releasing the lock, the skb may immediately be free'd
1611 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1612 if (pTxPort->TxdRingFree != 0) {
1620 /*****************************************************************************
1622 * XmitFrameSG - fill one socket buffer into the transmit ring
1623 * (use SG and TCP/UDP hardware checksumming)
1626 * This function puts a message into the transmit descriptor ring
1627 * if there is a descriptors left.
1630 * > 0 - on succes: the number of bytes in the message
1631 * = 0 - on resource shortage: this frame sent or dropped, now
1632 * the ring is full ( -> set tbusy)
1633 * < 0 - on failure: other problems ( -> return failure to upper layers)
1635 static int XmitFrameSG(
1636 SK_AC *pAC, /* pointer to adapter context */
1637 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1638 struct sk_buff *pMessage) /* pointer to send-message */
1646 skb_frag_t *sk_frag;
1648 unsigned long Flags;
1651 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1652 #ifndef USE_TX_COMPLETE
1653 FreeTxDescriptors(pAC, pTxPort);
1655 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1656 FreeTxDescriptors(pAC, pTxPort);
1657 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1658 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1659 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1660 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1661 SK_DBGCAT_DRV_TX_PROGRESS,
1662 ("XmitFrameSG failed - Ring full\n"));
1663 /* this message can not be sent now */
1668 pTxd = pTxPort->pTxdRingHead;
1674 ** Map the first fragment (header) into the DMA-space
1676 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1677 virt_to_page(pMessage->data),
1678 ((unsigned long) pMessage->data & ~PAGE_MASK),
1679 skb_headlen(pMessage),
1682 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1683 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1686 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1688 if (pMessage->ip_summed == CHECKSUM_HW) {
1689 u16 hdrlen = pMessage->h.raw - pMessage->data;
1690 u16 offset = hdrlen + pMessage->csum;
1692 Control = BMU_STFWD;
1695 ** We have to use the opcode for tcp here, because the
1696 ** opcode for udp is not working in the hardware yet
1699 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1700 (pAC->GIni.GIChipRev == 0) &&
1701 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1702 Control |= BMU_TCP_CHECK;
1704 Control |= BMU_UDP_CHECK;
1707 pTxd->TcpSumOfs = 0;
1708 pTxd->TcpSumSt = hdrlen;
1709 pTxd->TcpSumWr = offset;
1711 Control = BMU_CHECK | BMU_SW;
1713 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1715 pTxd = pTxd->pNextTxd;
1716 pTxPort->TxdRingFree--;
1717 BytesSend += skb_headlen(pMessage);
1720 ** Browse over all SG fragments and map each of them into the DMA space
1722 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1723 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1725 ** we already have the proper value in entry
1727 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1729 sk_frag->page_offset,
1733 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1734 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1735 pTxd->pMBuf = pMessage;
1737 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;;
1740 ** Do we have the last fragment?
1742 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1743 #ifdef USE_TX_COMPLETE
1744 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1746 pTxd->TBControl |= BMU_EOF;
1748 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1751 pTxd = pTxd->pNextTxd;
1752 pTxPort->TxdRingFree--;
1753 BytesSend += sk_frag->size;
1757 ** If previous descriptor already done, give TX start cmd
1759 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1760 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1763 pTxPort->pTxdRingPrev = pTxdLst;
1764 pTxPort->pTxdRingHead = pTxd;
1766 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1768 if (pTxPort->TxdRingFree > 0) {
1775 /*****************************************************************************
1777 * FreeTxDescriptors - release descriptors from the descriptor ring
1780 * This function releases descriptors from a transmit ring if they
1781 * have been sent by the BMU.
1782 * If a descriptors is sent, it can be freed and the message can
1784 * The SOFTWARE controllable bit is used to prevent running around a
1785 * completely free ring for ever. If this bit is no set in the
1786 * frame (by XmitFrame), this frame has never been sent or is
1788 * The Tx descriptor ring lock must be held while calling this function !!!
1793 static void FreeTxDescriptors(
1794 SK_AC *pAC, /* pointer to the adapter context */
1795 TX_PORT *pTxPort) /* pointer to destination port structure */
1797 TXD *pTxd; /* pointer to the checked descriptor */
1798 TXD *pNewTail; /* pointer to 'end' of the ring */
1799 SK_U32 Control; /* TBControl field of descriptor */
1800 SK_U64 PhysAddr; /* address of DMA mapping */
1802 pNewTail = pTxPort->pTxdRingTail;
1805 ** loop forever; exits if BMU_SW bit not set in start frame
1806 ** or BMU_OWN bit set in any frame
1809 Control = pTxd->TBControl;
1810 if ((Control & BMU_SW) == 0) {
1812 ** software controllable bit is set in first
1813 ** fragment when given to BMU. Not set means that
1814 ** this fragment was never sent or is already
1815 ** freed ( -> ring completely free now).
1817 pTxPort->pTxdRingTail = pTxd;
1818 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1821 if (Control & BMU_OWN) {
1822 pTxPort->pTxdRingTail = pTxd;
1823 if (pTxPort->TxdRingFree > 0) {
1824 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1830 ** release the DMA mapping, because until not unmapped
1831 ** this buffer is considered being under control of the
1834 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1835 PhysAddr |= (SK_U64) pTxd->VDataLow;
1836 pci_unmap_page(pAC->PciDev, PhysAddr,
1840 if (Control & BMU_EOF)
1841 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1843 pTxPort->TxdRingFree++;
1844 pTxd->TBControl &= ~BMU_SW;
1845 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1846 } /* while(forever) */
1847 } /* FreeTxDescriptors */
1849 /*****************************************************************************
1851 * FillRxRing - fill the receive ring with valid descriptors
1854 * This function fills the receive ring descriptors with data
1855 * segments and makes them valid for the BMU.
1856 * The active ring is filled completely, if possible.
1857 * The non-active ring is filled only partial to save memory.
1859 * Description of rx ring structure:
1860 * head - points to the descriptor which will be used next by the BMU
1861 * tail - points to the next descriptor to give to the BMU
1865 static void FillRxRing(
1866 SK_AC *pAC, /* pointer to the adapter context */
1867 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1870 unsigned long Flags;
1872 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1873 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1874 if(!FillRxDescriptor(pAC, pRxPort))
1877 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1881 /*****************************************************************************
1883 * FillRxDescriptor - fill one buffer into the receive ring
1886 * The function allocates a new receive buffer and
1887 * puts it into the next descriptor.
1890 * SK_TRUE - a buffer was added to the ring
1891 * SK_FALSE - a buffer could not be added
1893 static SK_BOOL FillRxDescriptor(
1894 SK_AC *pAC, /* pointer to the adapter context struct */
1895 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1897 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1898 RXD *pRxd; /* the rxd to fill */
1899 SK_U16 Length; /* data fragment length */
1900 SK_U64 PhysAddr; /* physical address of a rx buffer */
1902 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1903 if (pMsgBlock == NULL) {
1904 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1905 SK_DBGCAT_DRV_ENTRY,
1906 ("%s: Allocation of rx buffer failed !\n",
1907 pAC->dev[pRxPort->PortIndex]->name));
1908 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1911 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1912 /* skb allocated ok, so add buffer */
1913 pRxd = pRxPort->pRxdRingTail;
1914 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1915 pRxPort->RxdRingFree--;
1916 Length = pAC->RxBufSize;
1917 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1918 virt_to_page(pMsgBlock->data),
1919 ((unsigned long) pMsgBlock->data &
1922 PCI_DMA_FROMDEVICE);
1924 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1925 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1926 pRxd->pMBuf = pMsgBlock;
1927 pRxd->RBControl = BMU_OWN |
1934 } /* FillRxDescriptor */
1937 /*****************************************************************************
1939 * ReQueueRxBuffer - fill one buffer back into the receive ring
1942 * Fill a given buffer back into the rx ring. The buffer
1943 * has been previously allocated and aligned, and its phys.
1944 * address calculated, so this is no more necessary.
1948 static void ReQueueRxBuffer(
1949 SK_AC *pAC, /* pointer to the adapter context struct */
1950 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1951 struct sk_buff *pMsg, /* pointer to the buffer */
1952 SK_U32 PhysHigh, /* phys address high dword */
1953 SK_U32 PhysLow) /* phys address low dword */
1955 RXD *pRxd; /* the rxd to fill */
1956 SK_U16 Length; /* data fragment length */
1958 pRxd = pRxPort->pRxdRingTail;
1959 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1960 pRxPort->RxdRingFree--;
1961 Length = pAC->RxBufSize;
1963 pRxd->VDataLow = PhysLow;
1964 pRxd->VDataHigh = PhysHigh;
1966 pRxd->RBControl = BMU_OWN |
1972 } /* ReQueueRxBuffer */
1974 /*****************************************************************************
1976 * ReceiveIrq - handle a receive IRQ
1979 * This function is called when a receive IRQ is set.
1980 * It walks the receive descriptor ring and sends up all
1981 * frames that are complete.
1985 static void ReceiveIrq(
1986 SK_AC *pAC, /* pointer to adapter context */
1987 RX_PORT *pRxPort, /* pointer to receive port struct */
1988 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
1990 RXD *pRxd; /* pointer to receive descriptors */
1991 SK_U32 Control; /* control field of descriptor */
1992 struct sk_buff *pMsg; /* pointer to message holding frame */
1993 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
1994 int FrameLength; /* total length of received frame */
1995 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
1996 SK_EVPARA EvPara; /* an event parameter union */
1997 unsigned long Flags; /* for spin lock */
1998 int PortIndex = pRxPort->PortIndex;
1999 unsigned int Offset;
2000 unsigned int NumBytes;
2001 unsigned int ForRlmt;
2004 SK_BOOL IsBadFrame; /* Bad frame */
2010 /* do forever; exit if BMU_OWN found */
2011 for ( pRxd = pRxPort->pRxdRingHead ;
2012 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2013 pRxd = pRxd->pNextRxd,
2014 pRxPort->pRxdRingHead = pRxd,
2015 pRxPort->RxdRingFree ++) {
2018 * For a better understanding of this loop
2019 * Go through every descriptor beginning at the head
2020 * Please note: the ring might be completely received so the OWN bit
2021 * set is not a good crirteria to leave that loop.
2022 * Therefore the RingFree counter is used.
2023 * On entry of this loop pRxd is a pointer to the Rxd that needs
2024 * to be checked next.
2027 Control = pRxd->RBControl;
2029 /* check if this descriptor is ready */
2030 if ((Control & BMU_OWN) != 0) {
2031 /* this descriptor is not yet ready */
2032 /* This is the usual end of the loop */
2033 /* We don't need to start the ring again */
2034 FillRxRing(pAC, pRxPort);
2037 pAC->DynIrqModInfo.NbrProcessedDescr++;
2039 /* get length of frame and check it */
2040 FrameLength = Control & BMU_BBC;
2041 if (FrameLength > pAC->RxBufSize) {
2045 /* check for STF and EOF */
2046 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2050 /* here we have a complete frame in the ring */
2053 FrameStat = pRxd->FrameStat;
2055 /* check for frame length mismatch */
2056 #define XMR_FS_LEN_SHIFT 18
2057 #define GMR_FS_LEN_SHIFT 16
2058 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2059 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2061 SK_DBGCAT_DRV_RX_PROGRESS,
2062 ("skge: Frame length mismatch (%u/%u).\n",
2064 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2069 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2070 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2071 SK_DBGCAT_DRV_RX_PROGRESS,
2072 ("skge: Frame length mismatch (%u/%u).\n",
2074 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2080 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2081 IsBc = (FrameStat & XMR_FS_BC) != 0;
2082 IsMc = (FrameStat & XMR_FS_MC) != 0;
2083 IsBadFrame = (FrameStat &
2084 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2086 IsBc = (FrameStat & GMR_FS_BC) != 0;
2087 IsMc = (FrameStat & GMR_FS_MC) != 0;
2088 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2089 ((FrameStat & GMR_FS_RX_OK) == 0));
2092 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2093 ("Received frame of length %d on port %d\n",
2094 FrameLength, PortIndex));
2095 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2096 ("Number of free rx descriptors: %d\n",
2097 pRxPort->RxdRingFree));
2098 /* DumpMsg(pMsg, "Rx"); */
2100 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2102 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2104 /* there is a receive error in this frame */
2105 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2106 SK_DBGCAT_DRV_RX_PROGRESS,
2107 ("skge: Error in received frame, dropped!\n"
2108 "Control: %x\nRxStat: %x\n",
2109 Control, FrameStat));
2111 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2112 pRxd->VDataHigh, pRxd->VDataLow);
2118 * if short frame then copy data to reduce memory waste
2120 if ((FrameLength < SK_COPY_THRESHOLD) &&
2121 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2123 * Short frame detected and allocation successfull
2125 /* use new skb and copy data */
2126 skb_reserve(pNewMsg, 2);
2127 skb_put(pNewMsg, FrameLength);
2128 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2129 PhysAddr |= (SK_U64) pRxd->VDataLow;
2131 pci_dma_sync_single_for_cpu(pAC->PciDev,
2132 (dma_addr_t) PhysAddr,
2134 PCI_DMA_FROMDEVICE);
2135 memcpy(pNewMsg->data, pMsg, FrameLength);
2137 pci_dma_sync_single_for_device(pAC->PciDev,
2138 (dma_addr_t) PhysAddr,
2140 PCI_DMA_FROMDEVICE);
2141 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2142 pRxd->VDataHigh, pRxd->VDataLow);
2149 * if large frame, or SKB allocation failed, pass
2150 * the SKB directly to the networking
2153 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2154 PhysAddr |= (SK_U64) pRxd->VDataLow;
2156 /* release the DMA mapping */
2157 pci_unmap_single(pAC->PciDev,
2160 PCI_DMA_FROMDEVICE);
2162 /* set length in message */
2163 skb_put(pMsg, FrameLength);
2164 } /* frame > SK_COPY_TRESHOLD */
2166 if (pRxPort->RxCsum) {
2167 pMsg->csum = pRxd->TcpSums;
2168 pMsg->ip_summed = CHECKSUM_HW;
2171 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2172 ForRlmt = SK_RLMT_RX_PROTOCOL;
2174 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2176 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2177 IsBc, &Offset, &NumBytes);
2178 if (NumBytes != 0) {
2180 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2182 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2183 &pMsg->data[Offset],
2184 IsBc, IsMc, &ForRlmt);
2186 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2187 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2188 /* send up only frames from active port */
2189 if ((PortIndex == pAC->ActivePort) ||
2190 (pAC->RlmtNets == 2)) {
2191 /* frame for upper layer */
2192 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2194 DumpMsg(pMsg, "Rx");
2196 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2197 FrameLength, pRxPort->PortIndex);
2199 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2200 pMsg->protocol = eth_type_trans(pMsg,
2201 pAC->dev[pRxPort->PortIndex]);
2203 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2207 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2208 SK_DBGCAT_DRV_RX_PROGRESS,
2210 DEV_KFREE_SKB(pMsg);
2213 } /* if not for rlmt */
2215 /* packet for rlmt */
2216 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2217 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2218 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2219 pAC->IoBase, FrameLength);
2220 if (pRlmtMbuf != NULL) {
2221 pRlmtMbuf->pNext = NULL;
2222 pRlmtMbuf->Length = FrameLength;
2223 pRlmtMbuf->PortIdx = PortIndex;
2224 EvPara.pParaPtr = pRlmtMbuf;
2225 memcpy((char*)(pRlmtMbuf->pData),
2226 (char*)(pMsg->data),
2229 /* SlowPathLock needed? */
2230 if (SlowPathLock == SK_TRUE) {
2231 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2232 SkEventQueue(pAC, SKGE_RLMT,
2233 SK_RLMT_PACKET_RECEIVED,
2235 pAC->CheckQueue = SK_TRUE;
2236 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2238 SkEventQueue(pAC, SKGE_RLMT,
2239 SK_RLMT_PACKET_RECEIVED,
2241 pAC->CheckQueue = SK_TRUE;
2244 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2245 SK_DBGCAT_DRV_RX_PROGRESS,
2248 if ((pAC->dev[pRxPort->PortIndex]->flags &
2249 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2250 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2251 SK_RLMT_RX_PROTOCOL) {
2252 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2253 pMsg->protocol = eth_type_trans(pMsg,
2254 pAC->dev[pRxPort->PortIndex]);
2256 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2259 DEV_KFREE_SKB(pMsg);
2262 } /* if packet for rlmt */
2263 } /* for ... scanning the RXD ring */
2265 /* RXD ring is empty -> fill and restart */
2266 FillRxRing(pAC, pRxPort);
2267 /* do not start if called from Close */
2268 if (pAC->BoardLevel > SK_INIT_DATA) {
2269 ClearAndStartRx(pAC, PortIndex);
2274 /* remove error frame */
2275 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2276 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2278 /* release the DMA mapping */
2280 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2281 PhysAddr |= (SK_U64) pRxd->VDataLow;
2282 pci_unmap_page(pAC->PciDev,
2285 PCI_DMA_FROMDEVICE);
2286 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2288 pRxPort->RxdRingFree++;
2289 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2295 /*****************************************************************************
2297 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2300 * This function sends a start command and a clear interrupt
2301 * command for one receive queue to the BMU.
2306 static void ClearAndStartRx(
2307 SK_AC *pAC, /* pointer to the adapter context */
2308 int PortIndex) /* index of the receive port (XMAC) */
2310 SK_OUT8(pAC->IoBase,
2311 RxQueueAddr[PortIndex]+Q_CSR,
2312 CSR_START | CSR_IRQ_CL_F);
2313 } /* ClearAndStartRx */
2316 /*****************************************************************************
2318 * ClearTxIrq - give a clear transmit IRQ command to BMU
2321 * This function sends a clear tx IRQ command for one
2322 * transmit queue to the BMU.
2326 static void ClearTxIrq(
2327 SK_AC *pAC, /* pointer to the adapter context */
2328 int PortIndex, /* index of the transmit port (XMAC) */
2329 int Prio) /* priority or normal queue */
2331 SK_OUT8(pAC->IoBase,
2332 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2337 /*****************************************************************************
2339 * ClearRxRing - remove all buffers from the receive ring
2342 * This function removes all receive buffers from the ring.
2343 * The receive BMU must be stopped before calling this function.
2347 static void ClearRxRing(
2348 SK_AC *pAC, /* pointer to adapter context */
2349 RX_PORT *pRxPort) /* pointer to rx port struct */
2351 RXD *pRxd; /* pointer to the current descriptor */
2352 unsigned long Flags;
2355 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2358 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2359 pRxd = pRxPort->pRxdRingHead;
2361 if (pRxd->pMBuf != NULL) {
2363 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2364 PhysAddr |= (SK_U64) pRxd->VDataLow;
2365 pci_unmap_page(pAC->PciDev,
2368 PCI_DMA_FROMDEVICE);
2369 DEV_KFREE_SKB(pRxd->pMBuf);
2372 pRxd->RBControl &= BMU_OWN;
2373 pRxd = pRxd->pNextRxd;
2374 pRxPort->RxdRingFree++;
2375 } while (pRxd != pRxPort->pRxdRingTail);
2376 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2377 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2380 /*****************************************************************************
2382 * ClearTxRing - remove all buffers from the transmit ring
2385 * This function removes all transmit buffers from the ring.
2386 * The transmit BMU must be stopped before calling this function
2387 * and transmitting at the upper level must be disabled.
2388 * The BMU own bit of all descriptors is cleared, the rest is
2389 * done by calling FreeTxDescriptors.
2393 static void ClearTxRing(
2394 SK_AC *pAC, /* pointer to adapter context */
2395 TX_PORT *pTxPort) /* pointer to tx prt struct */
2397 TXD *pTxd; /* pointer to the current descriptor */
2399 unsigned long Flags;
2401 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2402 pTxd = pTxPort->pTxdRingHead;
2403 for (i=0; i<pAC->TxDescrPerRing; i++) {
2404 pTxd->TBControl &= ~BMU_OWN;
2405 pTxd = pTxd->pNextTxd;
2407 FreeTxDescriptors(pAC, pTxPort);
2408 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2411 /*****************************************************************************
2413 * SkGeSetMacAddr - Set the hardware MAC address
2416 * This function sets the MAC address used by the adapter.
2419 * 0, if everything is ok
2422 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2425 DEV_NET *pNet = netdev_priv(dev);
2426 SK_AC *pAC = pNet->pAC;
2428 struct sockaddr *addr = p;
2429 unsigned long Flags;
2431 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2432 ("SkGeSetMacAddr starts now...\n"));
2433 if(netif_running(dev))
2436 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2438 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2440 if (pAC->RlmtNets == 2)
2441 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2442 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2444 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2445 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2449 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2451 } /* SkGeSetMacAddr */
2454 /*****************************************************************************
2456 * SkGeSetRxMode - set receive mode
2459 * This function sets the receive mode of an adapter. The adapter
2460 * supports promiscuous mode, allmulticast mode and a number of
2461 * multicast addresses. If more multicast addresses the available
2462 * are selected, a hash function in the hardware is used.
2465 * 0, if everything is ok
2468 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2474 struct dev_mc_list *pMcList;
2477 unsigned long Flags;
2479 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2480 ("SkGeSetRxMode starts now... "));
2482 pNet = netdev_priv(dev);
2484 if (pAC->RlmtNets == 1)
2485 PortIdx = pAC->ActivePort;
2487 PortIdx = pNet->NetNr;
2489 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2490 if (dev->flags & IFF_PROMISC) {
2491 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2492 ("PROMISCUOUS mode\n"));
2493 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2495 } else if (dev->flags & IFF_ALLMULTI) {
2496 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2497 ("ALLMULTI mode\n"));
2498 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2499 SK_PROM_MODE_ALL_MC);
2501 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2503 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2505 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2506 ("Number of MC entries: %d ", dev->mc_count));
2508 pMcList = dev->mc_list;
2509 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2510 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2511 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2512 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2513 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2514 pMcList->dmi_addr[0],
2515 pMcList->dmi_addr[1],
2516 pMcList->dmi_addr[2],
2517 pMcList->dmi_addr[3],
2518 pMcList->dmi_addr[4],
2519 pMcList->dmi_addr[5]));
2521 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2523 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2526 } /* SkGeSetRxMode */
2529 /*****************************************************************************
2531 * SkGeChangeMtu - set the MTU to another value
2534 * This function sets is called whenever the MTU size is changed
2535 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2536 * ethernet MTU size, long frame support is activated.
2539 * 0, if everything is ok
2542 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2545 struct net_device *pOtherDev;
2547 unsigned long Flags;
2551 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2552 ("SkGeChangeMtu starts now...\n"));
2554 pNet = netdev_priv(dev);
2557 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2561 if(pAC->BoardLevel != SK_INIT_RUN) {
2565 #ifdef SK_DIAG_SUPPORT
2566 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2567 if (pAC->DiagFlowCtrl == SK_FALSE) {
2568 return -1; /* still in use, deny any actions of MTU */
2570 pAC->DiagFlowCtrl = SK_FALSE;
2575 pOtherDev = pAC->dev[1 - pNet->NetNr];
2577 if ( netif_running(pOtherDev) && (pOtherDev->mtu > 1500)
2578 && (NewMtu <= 1500))
2581 pAC->RxBufSize = NewMtu + 32;
2584 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2585 ("New MTU: %d\n", NewMtu));
2588 ** Prevent any reconfiguration while changing the MTU
2589 ** by disabling any interrupts
2591 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2592 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2595 ** Notify RLMT that any ports are to be stopped
2597 EvPara.Para32[0] = 0;
2598 EvPara.Para32[1] = -1;
2599 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2600 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2601 EvPara.Para32[0] = 1;
2602 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2604 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2608 ** After calling the SkEventDispatcher(), RLMT is aware about
2609 ** the stopped ports -> configuration can take place!
2611 SkEventDispatcher(pAC, pAC->IoBase);
2613 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2614 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2615 netif_stop_queue(pAC->dev[i]);
2620 ** Depending on the desired MTU size change, a different number of
2621 ** RX buffers need to be allocated
2623 if (NewMtu > 1500) {
2625 ** Use less rx buffers
2627 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2628 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2629 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2630 (pAC->RxDescrPerRing / 4);
2632 if (i == pAC->ActivePort) {
2633 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2634 (pAC->RxDescrPerRing / 4);
2636 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2637 (pAC->RxDescrPerRing / 10);
2643 ** Use the normal amount of rx buffers
2645 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2646 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2647 pAC->RxPort[i].RxFillLimit = 1;
2649 if (i == pAC->ActivePort) {
2650 pAC->RxPort[i].RxFillLimit = 1;
2652 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2653 (pAC->RxDescrPerRing / 4);
2659 SkGeDeInit(pAC, pAC->IoBase);
2662 ** enable/disable hardware support for long frames
2664 if (NewMtu > 1500) {
2665 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2666 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2668 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2669 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2671 pAC->GIni.GIPortUsage = SK_RED_LINK;
2675 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2676 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2677 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2678 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2679 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2680 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2681 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2685 ** Speed and others are set back to default in level 1 init!
2687 GetConfiguration(pAC);
2689 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2690 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2691 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2692 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2693 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2694 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2695 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2698 ** clear and reinit the rx rings here
2700 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2701 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2702 ClearRxRing(pAC, &pAC->RxPort[i]);
2703 FillRxRing(pAC, &pAC->RxPort[i]);
2706 ** Enable transmit descriptor polling
2708 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2709 FillRxRing(pAC, &pAC->RxPort[i]);
2712 SkGeYellowLED(pAC, pAC->IoBase, 1);
2713 SkDimEnableModerationIfNeeded(pAC);
2714 SkDimDisplayModerationSettings(pAC);
2716 netif_start_queue(pAC->dev[pNet->PortNr]);
2717 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2718 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2722 ** Enable Interrupts again
2724 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2725 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2727 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2728 SkEventDispatcher(pAC, pAC->IoBase);
2731 ** Notify RLMT about the changing and restarting one (or more) ports
2733 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2734 EvPara.Para32[0] = pAC->RlmtNets;
2735 EvPara.Para32[1] = -1;
2736 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2737 EvPara.Para32[0] = pNet->PortNr;
2738 EvPara.Para32[1] = -1;
2739 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2741 if (netif_running(pOtherDev)) {
2742 DEV_NET *pOtherNet = netdev_priv(pOtherDev);
2743 EvPara.Para32[0] = pOtherNet->PortNr;
2744 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2747 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2750 SkEventDispatcher(pAC, pAC->IoBase);
2751 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2754 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2755 ** seems as if upper layers have a problem to handle a successful
2756 ** return value of '0'. If such a zero is returned, the complete
2757 ** system hangs for several minutes (!), which is in acceptable.
2759 ** Currently it is not clear, what the exact reason for this problem
2760 ** is. The implemented workaround for 2.5 is to return the desired
2761 ** new MTU size if all needed changes for the new MTU size where
2762 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2763 ** which indicates the successful change of the mtu-size.
2767 } /* SkGeChangeMtu */
2770 /*****************************************************************************
2772 * SkGeStats - return ethernet device statistics
2775 * This function return statistic data about the ethernet device
2776 * to the operating system.
2779 * pointer to the statistic structure.
2781 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2783 DEV_NET *pNet = netdev_priv(dev);
2784 SK_AC *pAC = pNet->pAC;
2785 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2786 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2787 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2788 unsigned int Size; /* size of pnmi struct */
2789 unsigned long Flags; /* for spin lock */
2791 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2792 ("SkGeStats starts now...\n"));
2793 pPnmiStruct = &pAC->PnmiStruct;
2795 #ifdef SK_DIAG_SUPPORT
2796 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2797 (pAC->BoardLevel == SK_INIT_RUN)) {
2799 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2800 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2801 Size = SK_PNMI_STRUCT_SIZE;
2802 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2803 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2804 #ifdef SK_DIAG_SUPPORT
2808 pPnmiStat = &pPnmiStruct->Stat[0];
2809 pPnmiConf = &pPnmiStruct->Conf[0];
2811 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2812 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2813 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2814 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2816 if (dev->mtu <= 1500) {
2817 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2819 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2820 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2824 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2825 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2827 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2828 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2829 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2830 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2831 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2833 /* detailed rx_errors: */
2834 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2835 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2836 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2837 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2838 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2839 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2841 /* detailed tx_errors */
2842 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2843 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2844 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2845 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2846 pAC->stats.tx_window_errors = (SK_U32) 0;
2848 return(&pAC->stats);
2852 /*****************************************************************************
2854 * SkGeIoctl - IO-control function
2857 * This function is called if an ioctl is issued on the device.
2858 * There are three subfunction for reading, writing and test-writing
2859 * the private MIB data structure (usefull for SysKonnect-internal tools).
2862 * 0, if everything is ok
2865 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2870 struct pci_dev *pdev = NULL;
2872 unsigned int Err = 0;
2875 unsigned int Length = 0;
2876 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2878 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2879 ("SkGeIoctl starts now...\n"));
2881 pNet = netdev_priv(dev);
2884 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2889 case SK_IOCTL_SETMIB:
2890 case SK_IOCTL_PRESETMIB:
2891 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2892 case SK_IOCTL_GETMIB:
2893 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2894 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2895 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2898 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2899 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2900 Ioctl.Len<Size? Ioctl.Len : Size)) {
2904 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2909 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2912 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2914 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2917 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2921 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2925 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2930 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2935 kfree(pMemBuf); /* cleanup everything */
2937 #ifdef SK_DIAG_SUPPORT
2939 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2940 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2943 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2945 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2948 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2953 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2955 ** While coding this new IOCTL interface, only a few lines of code
2956 ** are to to be added. Therefore no dedicated function has been
2957 ** added. If more functionality is added, a separate function
2958 ** should be used...
2960 * ((SK_U32 *)pMemBuf) = 0;
2961 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2962 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2963 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2968 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2973 kfree(pMemBuf); /* cleanup everything */
2985 /*****************************************************************************
2987 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2990 * This function reads/writes the MIB data using PNMI (Private Network
2991 * Management Interface).
2992 * The destination for the data must be provided with the
2993 * ioctl call and is given to the driver in the form of
2994 * a user space address.
2995 * Copying from the user-provided data area into kernel messages
2996 * and back is done by copy_from_user and copy_to_user calls in
3000 * returned size from PNMI call
3002 static int SkGeIocMib(
3003 DEV_NET *pNet, /* pointer to the adapter context */
3004 unsigned int Size, /* length of ioctl data */
3005 int mode) /* flag for set/preset */
3007 unsigned long Flags; /* for spin lock */
3010 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3011 ("SkGeIocMib starts now...\n"));
3014 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3016 case SK_IOCTL_GETMIB:
3017 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3020 case SK_IOCTL_PRESETMIB:
3021 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3024 case SK_IOCTL_SETMIB:
3025 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3031 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3032 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3033 ("MIB data access succeeded\n"));
3038 /*****************************************************************************
3040 * GetConfiguration - read configuration information
3043 * This function reads per-adapter configuration information from
3044 * the options provided on the command line.
3049 static void GetConfiguration(
3050 SK_AC *pAC) /* pointer to the adapter context structure */
3052 SK_I32 Port; /* preferred port */
3055 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3056 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3057 int DuplexCap = 0; /* 0=both,1=full,2=half */
3058 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3059 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3061 SK_BOOL IsConTypeDefined = SK_TRUE;
3062 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3063 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3064 SK_BOOL IsRoleDefined = SK_TRUE;
3065 SK_BOOL IsModeDefined = SK_TRUE;
3067 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3068 * parameter. The mapping is described by this table:
3069 * DuplexCap -> | both | full | half |
3071 * -----------------------------------------------------------------
3072 * Off | illegal | Full | Half |
3073 * -----------------------------------------------------------------
3074 * On | AutoBoth | AutoFull | AutoHalf |
3075 * -----------------------------------------------------------------
3076 * Sense | AutoSense | AutoSense | AutoSense |
3078 int Capabilities[3][3] =
3079 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3080 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3081 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3089 #define M_CurrPort pAC->GIni.GP[Port]
3093 ** Set the default values first for both ports!
3095 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3096 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3097 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3098 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3099 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3103 ** Check merged parameter ConType. If it has not been used,
3104 ** verify any other parameter (e.g. AutoNeg) and use default values.
3106 ** Stating both ConType and other lowlevel link parameters is also
3107 ** possible. If this is the case, the passed ConType-parameter is
3108 ** overwritten by the lowlevel link parameter.
3110 ** The following settings are used for a merged ConType-parameter:
3112 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3113 ** ------- ------ ------- -------- ---------- -----
3114 ** Auto Both On SymOrRem Auto Auto
3115 ** 100FD Full Off None <ignored> 100
3116 ** 100HD Half Off None <ignored> 100
3117 ** 10FD Full Off None <ignored> 10
3118 ** 10HD Half Off None <ignored> 10
3120 ** This ConType parameter is used for all ports of the adapter!
3122 if ( (ConType != NULL) &&
3123 (pAC->Index < SK_MAX_CARD_PARAM) &&
3124 (ConType[pAC->Index] != NULL) ) {
3126 /* Check chipset family */
3127 if ((!pAC->ChipsetType) &&
3128 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3129 (strcmp(ConType[pAC->Index],"")!=0)) {
3130 /* Set the speed parameter back */
3131 printk("sk98lin: Illegal value \"%s\" "
3134 ConType[pAC->Index]);
3136 sprintf(ConType[pAC->Index], "Auto");
3139 if (strcmp(ConType[pAC->Index],"")==0) {
3140 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3141 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3142 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3143 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3144 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3145 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3146 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3148 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3149 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3150 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3151 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3152 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3153 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3155 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3156 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3157 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3158 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3159 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3160 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3162 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3163 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3164 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3165 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3166 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3167 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3169 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3170 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3171 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3172 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3173 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3174 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3177 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3178 ConType[pAC->Index]);
3179 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3182 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3186 ** Parse any parameter settings for port A:
3187 ** a) any LinkSpeed stated?
3189 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3190 Speed_A[pAC->Index] != NULL) {
3191 if (strcmp(Speed_A[pAC->Index],"")==0) {
3192 IsLinkSpeedDefined = SK_FALSE;
3193 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3194 LinkSpeed = SK_LSPEED_AUTO;
3195 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3196 LinkSpeed = SK_LSPEED_10MBPS;
3197 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3198 LinkSpeed = SK_LSPEED_100MBPS;
3199 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3200 LinkSpeed = SK_LSPEED_1000MBPS;
3202 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3203 Speed_A[pAC->Index]);
3204 IsLinkSpeedDefined = SK_FALSE;
3207 IsLinkSpeedDefined = SK_FALSE;
3211 ** Check speed parameter:
3212 ** Only copper type adapter and GE V2 cards
3214 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3215 ((LinkSpeed != SK_LSPEED_AUTO) &&
3216 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3217 printk("sk98lin: Illegal value for Speed_A. "
3218 "Not a copper card or GE V2 card\n Using "
3220 LinkSpeed = SK_LSPEED_1000MBPS;
3224 ** Decide whether to set new config value if somethig valid has
3227 if (IsLinkSpeedDefined) {
3228 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3232 ** b) Any Autonegotiation and DuplexCapabilities set?
3233 ** Please note that both belong together...
3235 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3237 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3238 AutoNeg_A[pAC->Index] != NULL) {
3240 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3242 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3244 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3246 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3249 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3250 AutoNeg_A[pAC->Index]);
3254 DuplexCap = DC_BOTH;
3256 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3257 DupCap_A[pAC->Index] != NULL) {
3259 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3261 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3262 DuplexCap = DC_BOTH;
3263 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3264 DuplexCap = DC_FULL;
3265 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3266 DuplexCap = DC_HALF;
3268 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3269 DupCap_A[pAC->Index]);
3274 ** Check for illegal combinations
3276 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3277 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3278 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3279 (pAC->ChipsetType)) {
3280 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3281 " Using Full Duplex.\n");
3282 DuplexCap = DC_FULL;
3285 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3286 printk("sk98lin, Port A: DuplexCapabilities"
3287 " ignored using Sense mode\n");
3290 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3291 printk("sk98lin: Port A: Illegal combination"
3292 " of values AutoNeg. and DuplexCap.\n Using "
3294 DuplexCap = DC_FULL;
3297 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3298 DuplexCap = DC_FULL;
3301 if (!AutoSet && DupSet) {
3302 printk("sk98lin: Port A: Duplex setting not"
3303 " possible in\n default AutoNegotiation mode"
3304 " (Sense).\n Using AutoNegotiation On\n");
3309 ** set the desired mode
3311 if (AutoSet || DupSet) {
3312 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3316 ** c) Any Flowcontrol-parameter set?
3318 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3319 FlowCtrl_A[pAC->Index] != NULL) {
3320 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3321 IsFlowCtrlDefined = SK_FALSE;
3322 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3323 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3324 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3325 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3326 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3327 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3328 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3329 FlowCtrl = SK_FLOW_MODE_NONE;
3331 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3332 FlowCtrl_A[pAC->Index]);
3333 IsFlowCtrlDefined = SK_FALSE;
3336 IsFlowCtrlDefined = SK_FALSE;
3339 if (IsFlowCtrlDefined) {
3340 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3341 printk("sk98lin: Port A: FlowControl"
3342 " impossible without AutoNegotiation,"
3344 FlowCtrl = SK_FLOW_MODE_NONE;
3346 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3350 ** d) What is with the RoleParameter?
3352 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3353 Role_A[pAC->Index] != NULL) {
3354 if (strcmp(Role_A[pAC->Index],"")==0) {
3355 IsRoleDefined = SK_FALSE;
3356 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3357 MSMode = SK_MS_MODE_AUTO;
3358 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3359 MSMode = SK_MS_MODE_MASTER;
3360 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3361 MSMode = SK_MS_MODE_SLAVE;
3363 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3364 Role_A[pAC->Index]);
3365 IsRoleDefined = SK_FALSE;
3368 IsRoleDefined = SK_FALSE;
3371 if (IsRoleDefined == SK_TRUE) {
3372 pAC->GIni.GP[0].PMSMode = MSMode;
3378 ** Parse any parameter settings for port B:
3379 ** a) any LinkSpeed stated?
3381 IsConTypeDefined = SK_TRUE;
3382 IsLinkSpeedDefined = SK_TRUE;
3383 IsFlowCtrlDefined = SK_TRUE;
3384 IsModeDefined = SK_TRUE;
3386 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3387 Speed_B[pAC->Index] != NULL) {
3388 if (strcmp(Speed_B[pAC->Index],"")==0) {
3389 IsLinkSpeedDefined = SK_FALSE;
3390 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3391 LinkSpeed = SK_LSPEED_AUTO;
3392 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3393 LinkSpeed = SK_LSPEED_10MBPS;
3394 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3395 LinkSpeed = SK_LSPEED_100MBPS;
3396 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3397 LinkSpeed = SK_LSPEED_1000MBPS;
3399 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3400 Speed_B[pAC->Index]);
3401 IsLinkSpeedDefined = SK_FALSE;
3404 IsLinkSpeedDefined = SK_FALSE;
3408 ** Check speed parameter:
3409 ** Only copper type adapter and GE V2 cards
3411 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3412 ((LinkSpeed != SK_LSPEED_AUTO) &&
3413 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3414 printk("sk98lin: Illegal value for Speed_B. "
3415 "Not a copper card or GE V2 card\n Using "
3417 LinkSpeed = SK_LSPEED_1000MBPS;
3421 ** Decide whether to set new config value if somethig valid has
3424 if (IsLinkSpeedDefined) {
3425 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3429 ** b) Any Autonegotiation and DuplexCapabilities set?
3430 ** Please note that both belong together...
3432 AutoNeg = AN_SENS; /* default: do auto Sense */
3434 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3435 AutoNeg_B[pAC->Index] != NULL) {
3437 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3439 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3441 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3443 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3446 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3447 AutoNeg_B[pAC->Index]);
3451 DuplexCap = DC_BOTH;
3453 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3454 DupCap_B[pAC->Index] != NULL) {
3456 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3458 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3459 DuplexCap = DC_BOTH;
3460 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3461 DuplexCap = DC_FULL;
3462 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3463 DuplexCap = DC_HALF;
3465 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3466 DupCap_B[pAC->Index]);
3472 ** Check for illegal combinations
3474 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3475 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3476 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3477 (pAC->ChipsetType)) {
3478 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3479 " Using Full Duplex.\n");
3480 DuplexCap = DC_FULL;
3483 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3484 printk("sk98lin, Port B: DuplexCapabilities"
3485 " ignored using Sense mode\n");
3488 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3489 printk("sk98lin: Port B: Illegal combination"
3490 " of values AutoNeg. and DuplexCap.\n Using "
3492 DuplexCap = DC_FULL;
3495 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3496 DuplexCap = DC_FULL;
3499 if (!AutoSet && DupSet) {
3500 printk("sk98lin: Port B: Duplex setting not"
3501 " possible in\n default AutoNegotiation mode"
3502 " (Sense).\n Using AutoNegotiation On\n");
3507 ** set the desired mode
3509 if (AutoSet || DupSet) {
3510 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3514 ** c) Any FlowCtrl parameter set?
3516 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3517 FlowCtrl_B[pAC->Index] != NULL) {
3518 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3519 IsFlowCtrlDefined = SK_FALSE;
3520 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3521 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3522 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3523 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3524 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3525 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3526 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3527 FlowCtrl = SK_FLOW_MODE_NONE;
3529 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3530 FlowCtrl_B[pAC->Index]);
3531 IsFlowCtrlDefined = SK_FALSE;
3534 IsFlowCtrlDefined = SK_FALSE;
3537 if (IsFlowCtrlDefined) {
3538 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3539 printk("sk98lin: Port B: FlowControl"
3540 " impossible without AutoNegotiation,"
3542 FlowCtrl = SK_FLOW_MODE_NONE;
3544 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3548 ** d) What is the RoleParameter?
3550 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3551 Role_B[pAC->Index] != NULL) {
3552 if (strcmp(Role_B[pAC->Index],"")==0) {
3553 IsRoleDefined = SK_FALSE;
3554 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3555 MSMode = SK_MS_MODE_AUTO;
3556 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3557 MSMode = SK_MS_MODE_MASTER;
3558 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3559 MSMode = SK_MS_MODE_SLAVE;
3561 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3562 Role_B[pAC->Index]);
3563 IsRoleDefined = SK_FALSE;
3566 IsRoleDefined = SK_FALSE;
3569 if (IsRoleDefined) {
3570 pAC->GIni.GP[1].PMSMode = MSMode;
3574 ** Evaluate settings for both ports
3576 pAC->ActivePort = 0;
3577 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3578 PrefPort[pAC->Index] != NULL) {
3579 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3580 pAC->ActivePort = 0;
3581 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3582 pAC->Rlmt.Net[0].PrefPort = 0;
3583 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3585 ** do not set ActivePort here, thus a port
3586 ** switch is issued after net up.
3589 pAC->Rlmt.Net[0].Preference = Port;
3590 pAC->Rlmt.Net[0].PrefPort = Port;
3591 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3593 ** do not set ActivePort here, thus a port
3594 ** switch is issued after net up.
3596 if (pAC->GIni.GIMacsFound == 1) {
3597 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3598 " Port B not available on single port adapters.\n");
3600 pAC->ActivePort = 0;
3601 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3602 pAC->Rlmt.Net[0].PrefPort = 0;
3605 pAC->Rlmt.Net[0].Preference = Port;
3606 pAC->Rlmt.Net[0].PrefPort = Port;
3609 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3610 PrefPort[pAC->Index]);
3616 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3617 RlmtMode[pAC->Index] != NULL) {
3618 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3620 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3621 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3622 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3623 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3624 SK_RLMT_CHECK_LOC_LINK;
3625 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3626 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3627 SK_RLMT_CHECK_LOC_LINK |
3629 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3630 (pAC->GIni.GIMacsFound == 2)) {
3631 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3634 printk("sk98lin: Illegal value \"%s\" for"
3635 " RlmtMode, using default\n",
3636 RlmtMode[pAC->Index]);
3644 ** Check the interrupt moderation parameters
3646 if (Moderation[pAC->Index] != NULL) {
3647 if (strcmp(Moderation[pAC->Index], "") == 0) {
3648 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3649 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3650 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3651 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3652 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3653 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3654 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3656 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3657 " Disable interrupt moderation.\n",
3658 Moderation[pAC->Index]);
3659 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3662 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3665 if (Stats[pAC->Index] != NULL) {
3666 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3667 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3669 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3672 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3675 if (ModerationMask[pAC->Index] != NULL) {
3676 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3677 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3678 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3679 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3680 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3681 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3682 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3683 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3684 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3685 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3686 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3687 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3688 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3689 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3690 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3691 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3692 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3693 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3694 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3695 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3696 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3697 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3698 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3699 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3700 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3701 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3702 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3703 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3704 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3705 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3706 } else { /* some rubbish */
3707 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3709 } else { /* operator has stated nothing */
3710 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3713 if (AutoSizing[pAC->Index] != NULL) {
3714 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3715 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3717 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3719 } else { /* operator has stated nothing */
3720 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3723 if (IntsPerSec[pAC->Index] != 0) {
3724 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3725 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3726 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3727 " Using default value of %i.\n",
3728 IntsPerSec[pAC->Index],
3729 C_INT_MOD_IPS_LOWER_RANGE,
3730 C_INT_MOD_IPS_UPPER_RANGE,
3731 C_INTS_PER_SEC_DEFAULT);
3732 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3734 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3737 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3741 ** Evaluate upper and lower moderation threshold
3743 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3744 pAC->DynIrqModInfo.MaxModIntsPerSec +
3745 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3747 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3748 pAC->DynIrqModInfo.MaxModIntsPerSec -
3749 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3751 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3754 } /* GetConfiguration */
3757 /*****************************************************************************
3759 * ProductStr - return a adapter identification string from vpd
3762 * This function reads the product name string from the vpd area
3763 * and puts it the field pAC->DeviceString.
3767 static inline int ProductStr(
3768 SK_AC *pAC, /* pointer to adapter context */
3769 char *DeviceStr, /* result string */
3770 int StrLen /* length of the string */
3773 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3774 int ReturnCode; /* return code from vpd_read */
3775 unsigned long Flags;
3777 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3778 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, DeviceStr, &StrLen);
3779 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3784 /*****************************************************************************
3786 * StartDrvCleanupTimer - Start timer to check for descriptors which
3787 * might be placed in descriptor ring, but
3788 * havent been handled up to now
3791 * This function requests a HW-timer fo the Yukon card. The actions to
3792 * perform when this timer expires, are located in the SkDrvEvent().
3797 StartDrvCleanupTimer(SK_AC *pAC) {
3798 SK_EVPARA EventParam; /* Event struct for timer event */
3800 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3801 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3802 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3803 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3804 SKGE_DRV, SK_DRV_TIMER, EventParam);
3807 /*****************************************************************************
3809 * StopDrvCleanupTimer - Stop timer to check for descriptors
3812 * This function requests a HW-timer fo the Yukon card. The actions to
3813 * perform when this timer expires, are located in the SkDrvEvent().
3818 StopDrvCleanupTimer(SK_AC *pAC) {
3819 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3820 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3823 /****************************************************************************/
3824 /* functions for common modules *********************************************/
3825 /****************************************************************************/
3828 /*****************************************************************************
3830 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3833 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3834 * is embedded into a socket buff data area.
3840 * NULL or pointer to Mbuf.
3842 SK_MBUF *SkDrvAllocRlmtMbuf(
3843 SK_AC *pAC, /* pointer to adapter context */
3844 SK_IOC IoC, /* the IO-context */
3845 unsigned BufferSize) /* size of the requested buffer */
3847 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3848 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3850 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3851 if (pMsgBlock == NULL) {
3854 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3855 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3856 pRlmtMbuf->pNext = NULL;
3857 pRlmtMbuf->pOs = pMsgBlock;
3858 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3859 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3860 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3863 } /* SkDrvAllocRlmtMbuf */
3866 /*****************************************************************************
3868 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3871 * This routine frees one or more RLMT mbuf(s).
3879 void SkDrvFreeRlmtMbuf(
3880 SK_AC *pAC, /* pointer to adapter context */
3881 SK_IOC IoC, /* the IO-context */
3882 SK_MBUF *pMbuf) /* size of the requested buffer */
3889 pNextMbuf = pFreeMbuf->pNext;
3890 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3891 pFreeMbuf = pNextMbuf;
3892 } while ( pFreeMbuf != NULL );
3893 } /* SkDrvFreeRlmtMbuf */
3896 /*****************************************************************************
3898 * SkOsGetTime - provide a time value
3901 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3902 * It is not used for absolute time, but only for time differences.
3908 SK_U64 SkOsGetTime(SK_AC *pAC)
3910 SK_U64 PrivateJiffies;
3911 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3912 return PrivateJiffies;
3916 /*****************************************************************************
3918 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3921 * This routine reads a 32 bit value from the pci configuration
3925 * 0 - indicate everything worked ok.
3926 * != 0 - error indication
3928 int SkPciReadCfgDWord(
3929 SK_AC *pAC, /* Adapter Control structure pointer */
3930 int PciAddr, /* PCI register address */
3931 SK_U32 *pVal) /* pointer to store the read value */
3933 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3935 } /* SkPciReadCfgDWord */
3938 /*****************************************************************************
3940 * SkPciReadCfgWord - read a 16 bit value from pci config space
3943 * This routine reads a 16 bit value from the pci configuration
3947 * 0 - indicate everything worked ok.
3948 * != 0 - error indication
3950 int SkPciReadCfgWord(
3951 SK_AC *pAC, /* Adapter Control structure pointer */
3952 int PciAddr, /* PCI register address */
3953 SK_U16 *pVal) /* pointer to store the read value */
3955 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3957 } /* SkPciReadCfgWord */
3960 /*****************************************************************************
3962 * SkPciReadCfgByte - read a 8 bit value from pci config space
3965 * This routine reads a 8 bit value from the pci configuration
3969 * 0 - indicate everything worked ok.
3970 * != 0 - error indication
3972 int SkPciReadCfgByte(
3973 SK_AC *pAC, /* Adapter Control structure pointer */
3974 int PciAddr, /* PCI register address */
3975 SK_U8 *pVal) /* pointer to store the read value */
3977 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
3979 } /* SkPciReadCfgByte */
3982 /*****************************************************************************
3984 * SkPciWriteCfgWord - write a 16 bit value to pci config space
3987 * This routine writes a 16 bit value to the pci configuration
3988 * space. The flag PciConfigUp indicates whether the config space
3989 * is accesible or must be set up first.
3992 * 0 - indicate everything worked ok.
3993 * != 0 - error indication
3995 int SkPciWriteCfgWord(
3996 SK_AC *pAC, /* Adapter Control structure pointer */
3997 int PciAddr, /* PCI register address */
3998 SK_U16 Val) /* pointer to store the read value */
4000 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4002 } /* SkPciWriteCfgWord */
4005 /*****************************************************************************
4007 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4010 * This routine writes a 8 bit value to the pci configuration
4011 * space. The flag PciConfigUp indicates whether the config space
4012 * is accesible or must be set up first.
4015 * 0 - indicate everything worked ok.
4016 * != 0 - error indication
4018 int SkPciWriteCfgByte(
4019 SK_AC *pAC, /* Adapter Control structure pointer */
4020 int PciAddr, /* PCI register address */
4021 SK_U8 Val) /* pointer to store the read value */
4023 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4025 } /* SkPciWriteCfgByte */
4028 /*****************************************************************************
4030 * SkDrvEvent - handle driver events
4033 * This function handles events from all modules directed to the driver
4036 * Is called under protection of slow path lock.
4039 * 0 if everything ok
4044 SK_AC *pAC, /* pointer to adapter context */
4045 SK_IOC IoC, /* io-context */
4046 SK_U32 Event, /* event-id */
4047 SK_EVPARA Param) /* event-parameter */
4049 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4050 struct sk_buff *pMsg; /* pointer to a message block */
4051 int FromPort; /* the port from which we switch away */
4052 int ToPort; /* the port we switch to */
4053 SK_EVPARA NewPara; /* parameter for further events */
4055 unsigned long Flags;
4059 case SK_DRV_ADAP_FAIL:
4060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4061 ("ADAPTER FAIL EVENT\n"));
4062 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4063 /* disable interrupts */
4064 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4067 case SK_DRV_PORT_FAIL:
4068 FromPort = Param.Para32[0];
4069 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4070 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4071 if (FromPort == 0) {
4072 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4074 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4078 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4080 FromPort = Param.Para32[0];
4081 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4082 ("PORT RESET EVENT, Port: %d ", FromPort));
4083 NewPara.Para64 = FromPort;
4084 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4086 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4089 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4090 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4091 spin_unlock_irqrestore(
4092 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4095 /* clear rx ring from received frames */
4096 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4098 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4100 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4103 /* tschilling: Handling of return value inserted. */
4104 if (SkGeInitPort(pAC, IoC, FromPort)) {
4105 if (FromPort == 0) {
4106 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4108 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4111 SkAddrMcUpdate(pAC,IoC, FromPort);
4112 PortReInitBmu(pAC, FromPort);
4113 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4114 ClearAndStartRx(pAC, FromPort);
4115 spin_unlock_irqrestore(
4116 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4119 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4120 { struct net_device *dev = pAC->dev[Param.Para32[0]];
4122 FromPort = Param.Para32[0];
4123 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4124 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4126 SkAddrMcUpdate(pAC,IoC, FromPort);
4128 if (DoPrintInterfaceChange) {
4129 printk("%s: network connection up using"
4130 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4132 /* tschilling: Values changed according to LinkSpeedUsed. */
4133 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4134 if (Stat == SK_LSPEED_STAT_10MBPS) {
4135 printk(" speed: 10\n");
4136 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4137 printk(" speed: 100\n");
4138 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4139 printk(" speed: 1000\n");
4141 printk(" speed: unknown\n");
4145 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4146 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4147 Stat == SK_LMODE_STAT_AUTOFULL) {
4148 printk(" autonegotiation: yes\n");
4151 printk(" autonegotiation: no\n");
4153 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4154 Stat == SK_LMODE_STAT_HALF) {
4155 printk(" duplex mode: half\n");
4158 printk(" duplex mode: full\n");
4160 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4161 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4162 printk(" flowctrl: remote send\n");
4164 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4165 printk(" flowctrl: local send\n");
4167 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4168 printk(" flowctrl: symmetric\n");
4171 printk(" flowctrl: none\n");
4174 /* tschilling: Check against CopperType now. */
4175 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4176 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4177 SK_LSPEED_STAT_1000MBPS)) {
4178 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4179 if (Stat == SK_MS_STAT_MASTER ) {
4180 printk(" role: master\n");
4182 else if (Stat == SK_MS_STAT_SLAVE ) {
4183 printk(" role: slave\n");
4186 printk(" role: ???\n");
4191 Display dim (dynamic interrupt moderation)
4194 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4195 printk(" irq moderation: static (%d ints/sec)\n",
4196 pAC->DynIrqModInfo.MaxModIntsPerSec);
4197 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4198 printk(" irq moderation: dynamic (%d ints/sec)\n",
4199 pAC->DynIrqModInfo.MaxModIntsPerSec);
4201 printk(" irq moderation: disabled\n");
4204 printk(" scatter-gather: %s\n",
4205 (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4206 printk(" tx-checksum: %s\n",
4207 (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4208 printk(" rx-checksum: %s\n",
4209 pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4212 DoPrintInterfaceChange = SK_TRUE;
4215 if ((Param.Para32[0] != pAC->ActivePort) &&
4216 (pAC->RlmtNets == 1)) {
4217 NewPara.Para32[0] = pAC->ActivePort;
4218 NewPara.Para32[1] = Param.Para32[0];
4219 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4223 /* Inform the world that link protocol is up. */
4224 netif_carrier_on(dev);
4227 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4229 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4230 ("NET DOWN EVENT "));
4231 if (DoPrintInterfaceChange) {
4232 printk("%s: network connection down\n",
4233 pAC->dev[Param.Para32[1]]->name);
4235 DoPrintInterfaceChange = SK_TRUE;
4237 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4239 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4240 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4241 ("PORT SWITCH HARD "));
4242 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4244 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4245 'A'+Param.Para32[1]);
4246 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4247 FromPort = Param.Para32[0];
4248 ToPort = Param.Para32[1];
4249 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4250 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4251 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4252 NewPara.Para64 = FromPort;
4253 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4254 NewPara.Para64 = ToPort;
4255 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4257 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4259 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4260 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4261 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4262 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4263 spin_unlock_irqrestore(
4264 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4267 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4268 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4270 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4271 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4273 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4275 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4276 pAC->ActivePort = ToPort;
4280 /* tschilling: New common function with minimum size check. */
4282 if (pAC->RlmtNets == 2) {
4286 if (SkGeInitAssignRamToQueues(
4290 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4291 spin_unlock_irqrestore(
4292 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4294 printk("SkGeInitAssignRamToQueues failed.\n");
4298 /* tschilling: Handling of return values inserted. */
4299 if (SkGeInitPort(pAC, IoC, FromPort) ||
4300 SkGeInitPort(pAC, IoC, ToPort)) {
4301 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4303 if (Event == SK_DRV_SWITCH_SOFT) {
4304 SkMacRxTxEnable(pAC, IoC, FromPort);
4306 SkMacRxTxEnable(pAC, IoC, ToPort);
4307 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4308 SkAddrMcUpdate(pAC, IoC, FromPort);
4309 SkAddrMcUpdate(pAC, IoC, ToPort);
4310 PortReInitBmu(pAC, FromPort);
4311 PortReInitBmu(pAC, ToPort);
4312 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4313 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4314 ClearAndStartRx(pAC, FromPort);
4315 ClearAndStartRx(pAC, ToPort);
4316 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4317 spin_unlock_irqrestore(
4318 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4321 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4322 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4324 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4325 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4326 skb_put(pMsg, pRlmtMbuf->Length);
4327 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4330 DEV_KFREE_SKB_ANY(pMsg);
4333 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4335 ** expiration of the moderation timer implies that
4336 ** dynamic moderation is to be applied
4338 SkDimStartModerationTimer(pAC);
4340 if (pAC->DynIrqModInfo.DisplayStats) {
4341 SkDimDisplayModerationSettings(pAC);
4343 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4345 ** check if we need to check for descriptors which
4346 ** haven't been handled the last millisecs
4348 StartDrvCleanupTimer(pAC);
4349 if (pAC->GIni.GIMacsFound == 2) {
4350 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4352 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4354 printk("Expiration of unknown timer\n");
4360 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4367 /*****************************************************************************
4369 * SkErrorLog - log errors
4372 * This function logs errors to the system buffer and to the console
4375 * 0 if everything ok
4388 case SK_ERRCL_OTHER:
4389 strcpy(ClassStr, "Other error");
4391 case SK_ERRCL_CONFIG:
4392 strcpy(ClassStr, "Configuration error");
4395 strcpy(ClassStr, "Initialization error");
4397 case SK_ERRCL_NORES:
4398 strcpy(ClassStr, "Out of resources error");
4401 strcpy(ClassStr, "internal Software error");
4404 strcpy(ClassStr, "Hardware failure");
4407 strcpy(ClassStr, "Communication error");
4410 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4411 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4412 ClassStr, ErrNum, pErrorMsg);
4416 #ifdef SK_DIAG_SUPPORT
4418 /*****************************************************************************
4420 * SkDrvEnterDiagMode - handles DIAG attach request
4423 * Notify the kernel to NOT access the card any longer due to DIAG
4424 * Deinitialize the Card
4429 int SkDrvEnterDiagMode(
4430 SK_AC *pAc) /* pointer to adapter context */
4432 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4433 SK_AC *pAC = pNet->pAC;
4435 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4436 sizeof(SK_PNMI_STRUCT_DATA));
4438 pAC->DiagModeActive = DIAG_ACTIVE;
4439 if (pAC->BoardLevel > SK_INIT_DATA) {
4440 if (netif_running(pAC->dev[0])) {
4441 pAC->WasIfUp[0] = SK_TRUE;
4442 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4443 DoPrintInterfaceChange = SK_FALSE;
4444 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4446 pAC->WasIfUp[0] = SK_FALSE;
4448 if (pNet != netdev_priv(pAC->dev[1])) {
4449 pNet = netdev_priv(pAC->dev[1]);
4450 if (netif_running(pAC->dev[1])) {
4451 pAC->WasIfUp[1] = SK_TRUE;
4452 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4453 DoPrintInterfaceChange = SK_FALSE;
4454 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4456 pAC->WasIfUp[1] = SK_FALSE;
4459 pAC->BoardLevel = SK_INIT_DATA;
4464 /*****************************************************************************
4466 * SkDrvLeaveDiagMode - handles DIAG detach request
4469 * Notify the kernel to may access the card again after use by DIAG
4470 * Initialize the Card
4475 int SkDrvLeaveDiagMode(
4476 SK_AC *pAc) /* pointer to adapter control context */
4478 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4479 sizeof(SK_PNMI_STRUCT_DATA));
4480 pAc->DiagModeActive = DIAG_NOTACTIVE;
4481 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4482 if (pAc->WasIfUp[0] == SK_TRUE) {
4483 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4484 DoPrintInterfaceChange = SK_FALSE;
4485 SkDrvInitAdapter(pAc, 0); /* first device */
4487 if (pAc->WasIfUp[1] == SK_TRUE) {
4488 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4489 DoPrintInterfaceChange = SK_FALSE;
4490 SkDrvInitAdapter(pAc, 1); /* second device */
4495 /*****************************************************************************
4497 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4500 * This function parses the PCI slot name information string and will
4501 * retrieve the devcie number out of it. The slot_name maintianed by
4502 * linux is in the form of '02:0a.0', whereas the first two characters
4503 * represent the bus number in hex (in the sample above this is
4504 * pci bus 0x02) and the next two characters the device number (0x0a).
4507 * SK_U32: The device number from the PCI slot name
4510 static SK_U32 ParseDeviceNbrFromSlotName(
4511 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4513 char *CurrCharPos = (char *) SlotName;
4514 int FirstNibble = -1;
4515 int SecondNibble = -1;
4518 while (*CurrCharPos != '\0') {
4519 if (*CurrCharPos == ':') {
4520 while (*CurrCharPos != '.') {
4522 if ( (*CurrCharPos >= '0') &&
4523 (*CurrCharPos <= '9')) {
4524 if (FirstNibble == -1) {
4525 /* dec. value for '0' */
4526 FirstNibble = *CurrCharPos - 48;
4528 SecondNibble = *CurrCharPos - 48;
4530 } else if ( (*CurrCharPos >= 'a') &&
4531 (*CurrCharPos <= 'f') ) {
4532 if (FirstNibble == -1) {
4533 FirstNibble = *CurrCharPos - 87;
4535 SecondNibble = *CurrCharPos - 87;
4542 Result = FirstNibble;
4543 Result = Result << 4; /* first nibble is higher one */
4544 Result = Result | SecondNibble;
4546 CurrCharPos++; /* next character */
4551 /****************************************************************************
4553 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4554 * called if Diag attaches to that card)
4557 * Close initialized adapter.
4561 * error code - on error
4563 static int SkDrvDeInitAdapter(
4564 SK_AC *pAC, /* pointer to adapter context */
4565 int devNbr) /* what device is to be handled */
4567 struct SK_NET_DEVICE *dev;
4569 dev = pAC->dev[devNbr];
4571 /* On Linux 2.6 the network driver does NOT mess with reference
4572 ** counts. The driver MUST be able to be unloaded at any time
4573 ** due to the possibility of hotplug.
4575 if (SkGeClose(dev) != 0) {
4580 } /* SkDrvDeInitAdapter() */
4582 /****************************************************************************
4584 * SkDrvInitAdapter - Initialize adapter (this function is only
4585 * called if Diag deattaches from that card)
4588 * Close initialized adapter.
4592 * error code - on error
4594 static int SkDrvInitAdapter(
4595 SK_AC *pAC, /* pointer to adapter context */
4596 int devNbr) /* what device is to be handled */
4598 struct SK_NET_DEVICE *dev;
4600 dev = pAC->dev[devNbr];
4602 if (SkGeOpen(dev) != 0) {
4607 ** Use correct MTU size and indicate to kernel TX queue can be started
4609 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4614 } /* SkDrvInitAdapter */
4619 /****************************************************************************/
4620 /* "debug only" section *****************************************************/
4621 /****************************************************************************/
4624 /*****************************************************************************
4626 * DumpMsg - print a frame
4629 * This function prints frames to the system logfile/to the console.
4634 static void DumpMsg(struct sk_buff *skb, char *str)
4639 printk("DumpMsg(): NULL-Message\n");
4643 if (skb->data == NULL) {
4644 printk("DumpMsg(): Message empty\n");
4652 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4654 DumpData((char *)skb->data, msglen);
4656 printk("------- End of message ---------\n");
4661 /*****************************************************************************
4663 * DumpData - print a data area
4666 * This function prints a area of data to the system logfile/to the
4672 static void DumpData(char *p, int size)
4676 char hex_buffer[180];
4677 char asc_buffer[180];
4678 char HEXCHAR[] = "0123456789ABCDEF";
4684 for (i=0; i < size; ) {
4685 if (*p >= '0' && *p <='z')
4686 asc_buffer[addr] = *p;
4688 asc_buffer[addr] = '.';
4690 asc_buffer[addr] = 0;
4691 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4693 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4695 hex_buffer[haddr] = ' ';
4697 hex_buffer[haddr] = 0;
4701 printk("%s %s\n", hex_buffer, asc_buffer);
4709 /*****************************************************************************
4711 * DumpLong - print a data area as long values
4714 * This function prints a area of data to the system logfile/to the
4720 static void DumpLong(char *pc, int size)
4724 char hex_buffer[180];
4725 char asc_buffer[180];
4726 char HEXCHAR[] = "0123456789ABCDEF";
4735 for (i=0; i < size; ) {
4737 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4739 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4741 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4743 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4745 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4747 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4749 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4751 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4753 hex_buffer[haddr] = ' ';
4755 hex_buffer[haddr] = 0;
4759 printk("%4x %s\n", (i-8)*4, hex_buffer);
4763 printk("------------------------\n");
4768 static int __devinit skge_probe_one(struct pci_dev *pdev,
4769 const struct pci_device_id *ent)
4772 DEV_NET *pNet = NULL;
4773 struct net_device *dev = NULL;
4774 static int boards_found = 0;
4775 int error = -ENODEV;
4778 if (pci_enable_device(pdev))
4781 /* Configure DMA attributes. */
4782 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4783 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4784 goto out_disable_device;
4787 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4788 printk(KERN_ERR "Unable to allocate etherdev "
4790 goto out_disable_device;
4793 pNet = netdev_priv(dev);
4794 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4796 printk(KERN_ERR "Unable to allocate adapter "
4798 goto out_free_netdev;
4801 memset(pNet->pAC, 0, sizeof(SK_AC));
4807 pAC->CheckQueue = SK_FALSE;
4809 dev->irq = pdev->irq;
4810 error = SkGeInitPCI(pAC);
4812 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4813 goto out_free_netdev;
4816 SET_MODULE_OWNER(dev);
4817 dev->open = &SkGeOpen;
4818 dev->stop = &SkGeClose;
4819 dev->hard_start_xmit = &SkGeXmit;
4820 dev->get_stats = &SkGeStats;
4821 dev->set_multicast_list = &SkGeSetRxMode;
4822 dev->set_mac_address = &SkGeSetMacAddr;
4823 dev->do_ioctl = &SkGeIoctl;
4824 dev->change_mtu = &SkGeChangeMtu;
4825 #ifdef CONFIG_NET_POLL_CONTROLLER
4826 dev->poll_controller = &SkGePollController;
4828 SET_NETDEV_DEV(dev, &pdev->dev);
4829 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4831 /* Use only if yukon hardware */
4832 if (pAC->ChipsetType) {
4833 #ifdef USE_SK_TX_CHECKSUM
4834 dev->features |= NETIF_F_IP_CSUM;
4837 dev->features |= NETIF_F_SG;
4839 #ifdef USE_SK_RX_CHECKSUM
4840 pAC->RxPort[0].RxCsum = 1;
4844 pAC->Index = boards_found++;
4846 if (SkGeBoardInit(dev, pAC))
4847 goto out_free_netdev;
4849 /* Read Adapter name from VPD */
4850 if (ProductStr(pAC, DeviceStr, sizeof(DeviceStr)) != 0) {
4851 printk(KERN_ERR "sk98lin: Could not read VPD data.\n");
4852 goto out_free_resources;
4855 /* Register net device */
4856 if (register_netdev(dev)) {
4857 printk(KERN_ERR "sk98lin: Could not register device.\n");
4858 goto out_free_resources;
4861 /* Print adapter specific string from vpd */
4862 printk("%s: %s\n", dev->name, DeviceStr);
4864 /* Print configuration settings */
4865 printk(" PrefPort:%c RlmtMode:%s\n",
4866 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4867 (pAC->RlmtMode==0) ? "Check Link State" :
4868 ((pAC->RlmtMode==1) ? "Check Link State" :
4869 ((pAC->RlmtMode==3) ? "Check Local Port" :
4870 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4871 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4873 SkGeYellowLED(pAC, pAC->IoBase, 1);
4875 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4876 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4883 /* More then one port found */
4884 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4885 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4886 printk(KERN_ERR "Unable to allocate etherdev "
4892 pNet = netdev_priv(dev);
4897 dev->open = &SkGeOpen;
4898 dev->stop = &SkGeClose;
4899 dev->hard_start_xmit = &SkGeXmit;
4900 dev->get_stats = &SkGeStats;
4901 dev->set_multicast_list = &SkGeSetRxMode;
4902 dev->set_mac_address = &SkGeSetMacAddr;
4903 dev->do_ioctl = &SkGeIoctl;
4904 dev->change_mtu = &SkGeChangeMtu;
4905 SET_NETDEV_DEV(dev, &pdev->dev);
4906 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4908 if (pAC->ChipsetType) {
4909 #ifdef USE_SK_TX_CHECKSUM
4910 dev->features |= NETIF_F_IP_CSUM;
4913 dev->features |= NETIF_F_SG;
4915 #ifdef USE_SK_RX_CHECKSUM
4916 pAC->RxPort[1].RxCsum = 1;
4920 if (register_netdev(dev)) {
4921 printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4923 pAC->dev[1] = pAC->dev[0];
4925 memcpy(&dev->dev_addr,
4926 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4927 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4929 printk("%s: %s\n", dev->name, DeviceStr);
4930 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4934 /* Save the hardware revision */
4935 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4936 (pAC->GIni.GIPciHwRev & 0x0F);
4938 /* Set driver globals */
4939 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4940 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4942 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4943 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4945 pci_set_drvdata(pdev, dev);
4953 pci_disable_device(pdev);
4958 static void __devexit skge_remove_one(struct pci_dev *pdev)
4960 struct net_device *dev = pci_get_drvdata(pdev);
4961 DEV_NET *pNet = netdev_priv(dev);
4962 SK_AC *pAC = pNet->pAC;
4963 struct net_device *otherdev = pAC->dev[1];
4965 unregister_netdev(dev);
4967 SkGeYellowLED(pAC, pAC->IoBase, 0);
4969 if (pAC->BoardLevel == SK_INIT_RUN) {
4971 unsigned long Flags;
4973 /* board is still alive */
4974 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
4975 EvPara.Para32[0] = 0;
4976 EvPara.Para32[1] = -1;
4977 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
4978 EvPara.Para32[0] = 1;
4979 EvPara.Para32[1] = -1;
4980 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
4981 SkEventDispatcher(pAC, pAC->IoBase);
4982 /* disable interrupts */
4983 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4984 SkGeDeInit(pAC, pAC->IoBase);
4985 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
4986 pAC->BoardLevel = SK_INIT_DATA;
4987 /* We do NOT check here, if IRQ was pending, of course*/
4990 if (pAC->BoardLevel == SK_INIT_IO) {
4991 /* board is still alive */
4992 SkGeDeInit(pAC, pAC->IoBase);
4993 pAC->BoardLevel = SK_INIT_DATA;
4998 if (otherdev != dev)
4999 free_netdev(otherdev);
5004 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5006 struct net_device *dev = pci_get_drvdata(pdev);
5007 DEV_NET *pNet = netdev_priv(dev);
5008 SK_AC *pAC = pNet->pAC;
5009 struct net_device *otherdev = pAC->dev[1];
5011 if (netif_running(dev)) {
5012 netif_carrier_off(dev);
5013 DoPrintInterfaceChange = SK_FALSE;
5014 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5015 netif_device_detach(dev);
5017 if (otherdev != dev) {
5018 if (netif_running(otherdev)) {
5019 netif_carrier_off(otherdev);
5020 DoPrintInterfaceChange = SK_FALSE;
5021 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5022 netif_device_detach(otherdev);
5026 pci_save_state(pdev);
5027 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5028 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5029 free_irq(dev->irq, dev);
5031 pci_disable_device(pdev);
5032 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5037 static int skge_resume(struct pci_dev *pdev)
5039 struct net_device *dev = pci_get_drvdata(pdev);
5040 DEV_NET *pNet = netdev_priv(dev);
5041 SK_AC *pAC = pNet->pAC;
5042 struct net_device *otherdev = pAC->dev[1];
5045 pci_set_power_state(pdev, PCI_D0);
5046 pci_restore_state(pdev);
5047 pci_enable_device(pdev);
5048 pci_set_master(pdev);
5049 if (pAC->GIni.GIMacsFound == 2)
5050 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
5052 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, "sk98lin", dev);
5054 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5055 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5057 pci_disable_device(pdev);
5061 netif_device_attach(dev);
5062 if (netif_running(dev)) {
5063 DoPrintInterfaceChange = SK_FALSE;
5064 SkDrvInitAdapter(pAC, 0); /* first device */
5066 if (otherdev != dev) {
5067 netif_device_attach(otherdev);
5068 if (netif_running(otherdev)) {
5069 DoPrintInterfaceChange = SK_FALSE;
5070 SkDrvInitAdapter(pAC, 1); /* second device */
5077 #define skge_suspend NULL
5078 #define skge_resume NULL
5081 static struct pci_device_id skge_pci_tbl[] = {
5082 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5083 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5084 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5085 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5086 /* DLink card does not have valid VPD so this driver gags
5087 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5089 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5090 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5091 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5092 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5093 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5097 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5099 static struct pci_driver skge_driver = {
5101 .id_table = skge_pci_tbl,
5102 .probe = skge_probe_one,
5103 .remove = __devexit_p(skge_remove_one),
5104 .suspend = skge_suspend,
5105 .resume = skge_resume,
5108 static int __init skge_init(void)
5110 return pci_module_init(&skge_driver);
5113 static void __exit skge_exit(void)
5115 pci_unregister_driver(&skge_driver);
5118 module_init(skge_init);
5119 module_exit(skge_exit);