1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.45 $
6 * Date: $Date: 2004/02/12 14:41:02 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
19 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
20 * SysKonnects GEnesis Solaris driver
21 * Author: Christoph Goos (cgoos@syskonnect.de)
22 * Mirko Lindner (mlindner@syskonnect.de)
24 * Address all question to: linux@syskonnect.de
26 * The technical manual for the adapters is available from SysKonnect's
27 * web pages: www.syskonnect.com
28 * Goto "Support" and search Knowledge Base for "manual".
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * The information in this file is provided "AS IS" without warranty.
37 ******************************************************************************/
39 /******************************************************************************
41 * Possible compiler options (#define xxx / -Dxxx):
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
46 ******************************************************************************/
48 /******************************************************************************
52 * This is the main module of the Linux GE driver.
54 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
55 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
56 * Those are used for drivers on multiple OS', so some thing may seem
57 * unnecessary complicated on Linux. Please do not try to 'clean up'
58 * them without VERY good reasons, because this will make it more
59 * difficult to keep the Linux driver in synchronisation with the
62 * Include file hierarchy:
79 * <linux/etherdevice.h>
81 * those three depending on kernel version used:
106 ******************************************************************************/
108 #include "h/skversion.h"
110 #include <linux/in.h>
111 #include <linux/module.h>
112 #include <linux/moduleparam.h>
113 #include <linux/init.h>
114 #include <linux/dma-mapping.h>
115 #include <linux/ip.h>
117 #include "h/skdrv1st.h"
118 #include "h/skdrv2nd.h"
120 /*******************************************************************************
124 ******************************************************************************/
126 /* for debuging on x86 only */
127 /* #define BREAKPOINT() asm(" int $3"); */
129 /* use the transmit hw checksum driver functionality */
130 #define USE_SK_TX_CHECKSUM
132 /* use the receive hw checksum driver functionality */
133 #define USE_SK_RX_CHECKSUM
135 /* use the scatter-gather functionality with sendfile() */
138 /* use of a transmit complete interrupt */
139 #define USE_TX_COMPLETE
142 * threshold for copying small receive frames
143 * set to 0 to avoid copying, set to 9001 to copy all frames
145 #define SK_COPY_THRESHOLD 50
147 /* number of adapters that can be configured via command line params */
148 #define SK_MAX_CARD_PARAM 16
153 * use those defines for a compile-in version of the driver instead
154 * of command line parameters
156 // #define LINK_SPEED_A {"Auto", }
157 // #define LINK_SPEED_B {"Auto", }
158 // #define AUTO_NEG_A {"Sense", }
159 // #define AUTO_NEG_B {"Sense", }
160 // #define DUP_CAP_A {"Both", }
161 // #define DUP_CAP_B {"Both", }
162 // #define FLOW_CTRL_A {"SymOrRem", }
163 // #define FLOW_CTRL_B {"SymOrRem", }
164 // #define ROLE_A {"Auto", }
165 // #define ROLE_B {"Auto", }
166 // #define PREF_PORT {"A", }
167 // #define CON_TYPE {"Auto", }
168 // #define RLMT_MODE {"CheckLinkState", }
170 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
171 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
172 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
176 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
177 SK_DUP_LED_NORMAL | \
181 /* Isr return value */
182 #define SkIsrRetVar irqreturn_t
183 #define SkIsrRetNone IRQ_NONE
184 #define SkIsrRetHandled IRQ_HANDLED
187 /*******************************************************************************
189 * Local Function Prototypes
191 ******************************************************************************/
193 static void FreeResources(struct SK_NET_DEVICE *dev);
194 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
195 static SK_BOOL BoardAllocMem(SK_AC *pAC);
196 static void BoardFreeMem(SK_AC *pAC);
197 static void BoardInitMem(SK_AC *pAC);
198 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
199 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
200 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
201 static int SkGeOpen(struct SK_NET_DEVICE *dev);
202 static int SkGeClose(struct SK_NET_DEVICE *dev);
203 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
204 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
205 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
206 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
207 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
208 static void GetConfiguration(SK_AC*);
209 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
210 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
211 static void FillRxRing(SK_AC*, RX_PORT*);
212 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
213 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
214 static void ClearAndStartRx(SK_AC*, int);
215 static void ClearTxIrq(SK_AC*, int, int);
216 static void ClearRxRing(SK_AC*, RX_PORT*);
217 static void ClearTxRing(SK_AC*, TX_PORT*);
218 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
219 static void PortReInitBmu(SK_AC*, int);
220 static int SkGeIocMib(DEV_NET*, unsigned int, int);
221 static int SkGeInitPCI(SK_AC *pAC);
222 static void StartDrvCleanupTimer(SK_AC *pAC);
223 static void StopDrvCleanupTimer(SK_AC *pAC);
224 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
226 #ifdef SK_DIAG_SUPPORT
227 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
228 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
229 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
232 /*******************************************************************************
234 * Extern Function Prototypes
236 ******************************************************************************/
237 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
238 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
239 extern void SkDimStartModerationTimer(SK_AC *pAC);
240 extern void SkDimModerate(SK_AC *pAC);
241 extern void SkGeBlinkTimer(unsigned long data);
244 static void DumpMsg(struct sk_buff*, char*);
245 static void DumpData(char*, int);
246 static void DumpLong(char*, int);
249 /* global variables *********************************************************/
250 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
251 extern struct ethtool_ops SkGeEthtoolOps;
253 /* local variables **********************************************************/
254 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
255 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
257 /*****************************************************************************
259 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
262 * This routine writes a 32 bit value to the pci configuration
266 * 0 - indicate everything worked ok.
267 * != 0 - error indication
269 static inline int SkPciWriteCfgDWord(
270 SK_AC *pAC, /* Adapter Control structure pointer */
271 int PciAddr, /* PCI register address */
272 SK_U32 Val) /* pointer to store the read value */
274 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
276 } /* SkPciWriteCfgDWord */
278 /*****************************************************************************
280 * SkGeInitPCI - Init the PCI resources
283 * This function initialize the PCI resources and IO
288 int SkGeInitPCI(SK_AC *pAC)
290 struct SK_NET_DEVICE *dev = pAC->dev[0];
291 struct pci_dev *pdev = pAC->PciDev;
294 if (pci_enable_device(pdev) != 0) {
298 dev->mem_start = pci_resource_start (pdev, 0);
299 pci_set_master(pdev);
301 if (pci_request_regions(pdev, "sk98lin") != 0) {
308 * On big endian machines, we use the adapter's aibility of
309 * reading the descriptors as big endian.
313 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
314 our2 |= PCI_REV_DESC;
315 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
320 * Remap the regs into kernel space.
322 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
332 pci_release_regions(pdev);
334 pci_disable_device(pdev);
339 /*****************************************************************************
341 * FreeResources - release resources allocated for adapter
344 * This function releases the IRQ, unmaps the IO and
345 * frees the desriptor ring.
350 static void FreeResources(struct SK_NET_DEVICE *dev)
356 pNet = netdev_priv(dev);
358 AllocFlag = pAC->AllocFlag;
360 pci_release_regions(pAC->PciDev);
362 if (AllocFlag & SK_ALLOC_IRQ) {
363 free_irq(dev->irq, dev);
366 iounmap(pAC->IoBase);
368 if (pAC->pDescrMem) {
372 } /* FreeResources */
374 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
375 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
376 MODULE_LICENSE("GPL");
379 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
381 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
385 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
387 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
391 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
393 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
397 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
399 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
403 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
405 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
409 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
411 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
415 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
417 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
421 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
423 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
427 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
429 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
433 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
435 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
439 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
441 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
445 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
447 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
451 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
453 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
456 static int IntsPerSec[SK_MAX_CARD_PARAM];
457 static char *Moderation[SK_MAX_CARD_PARAM];
458 static char *ModerationMask[SK_MAX_CARD_PARAM];
459 static char *AutoSizing[SK_MAX_CARD_PARAM];
460 static char *Stats[SK_MAX_CARD_PARAM];
462 module_param_array(Speed_A, charp, NULL, 0);
463 module_param_array(Speed_B, charp, NULL, 0);
464 module_param_array(AutoNeg_A, charp, NULL, 0);
465 module_param_array(AutoNeg_B, charp, NULL, 0);
466 module_param_array(DupCap_A, charp, NULL, 0);
467 module_param_array(DupCap_B, charp, NULL, 0);
468 module_param_array(FlowCtrl_A, charp, NULL, 0);
469 module_param_array(FlowCtrl_B, charp, NULL, 0);
470 module_param_array(Role_A, charp, NULL, 0);
471 module_param_array(Role_B, charp, NULL, 0);
472 module_param_array(ConType, charp, NULL, 0);
473 module_param_array(PrefPort, charp, NULL, 0);
474 module_param_array(RlmtMode, charp, NULL, 0);
475 /* used for interrupt moderation */
476 module_param_array(IntsPerSec, int, NULL, 0);
477 module_param_array(Moderation, charp, NULL, 0);
478 module_param_array(Stats, charp, NULL, 0);
479 module_param_array(ModerationMask, charp, NULL, 0);
480 module_param_array(AutoSizing, charp, NULL, 0);
482 /*****************************************************************************
484 * SkGeBoardInit - do level 0 and 1 initialization
487 * This function prepares the board hardware for running. The desriptor
488 * ring is set up, the IRQ is allocated and the configuration settings
492 * 0, if everything is ok
495 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
499 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
500 char *VerStr = VER_STRING;
501 int Ret; /* return code of request_irq */
504 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
505 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
506 for (i=0; i<SK_MAX_MACS; i++) {
507 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
508 pAC->TxPort[i][0].PortIndex = i;
509 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
510 pAC->RxPort[i].PortIndex = i;
513 /* Initialize the mutexes */
514 for (i=0; i<SK_MAX_MACS; i++) {
515 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
516 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
518 spin_lock_init(&pAC->SlowPathLock);
520 /* setup phy_id blink timer */
521 pAC->BlinkTimer.function = SkGeBlinkTimer;
522 pAC->BlinkTimer.data = (unsigned long) dev;
523 init_timer(&pAC->BlinkTimer);
525 /* level 0 init common modules here */
527 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
528 /* Does a RESET on board ...*/
529 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
530 printk("HWInit (0) failed.\n");
531 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
534 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
535 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
536 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
537 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
538 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
539 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
541 pAC->BoardLevel = SK_INIT_DATA;
542 pAC->RxBufSize = ETH_BUF_SIZE;
544 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
545 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
547 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
549 /* level 1 init common modules here (HW init) */
550 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
551 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
552 printk("sk98lin: HWInit (1) failed.\n");
553 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
556 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
557 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
558 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
559 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
560 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
561 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
563 /* Set chipset type support */
564 pAC->ChipsetType = 0;
565 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
566 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
567 pAC->ChipsetType = 1;
570 GetConfiguration(pAC);
571 if (pAC->RlmtNets == 2) {
572 pAC->GIni.GIPortUsage = SK_MUL_LINK;
575 pAC->BoardLevel = SK_INIT_IO;
576 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
578 if (pAC->GIni.GIMacsFound == 2) {
579 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
580 } else if (pAC->GIni.GIMacsFound == 1) {
581 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
584 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
585 pAC->GIni.GIMacsFound);
590 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
594 pAC->AllocFlag |= SK_ALLOC_IRQ;
596 /* Alloc memory for this board (Mem for RxD/TxD) : */
597 if(!BoardAllocMem(pAC)) {
598 printk("No memory for descriptor rings.\n");
603 /* tschilling: New common function with minimum size check. */
605 if (pAC->RlmtNets == 2) {
609 if (SkGeInitAssignRamToQueues(
614 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
619 } /* SkGeBoardInit */
622 /*****************************************************************************
624 * BoardAllocMem - allocate the memory for the descriptor rings
627 * This function allocates the memory for all descriptor rings.
628 * Each ring is aligned for the desriptor alignment and no ring
629 * has a 4 GByte boundary in it (because the upper 32 bit must
630 * be constant for all descriptiors in one rings).
633 * SK_TRUE, if all memory could be allocated
636 static SK_BOOL BoardAllocMem(
639 caddr_t pDescrMem; /* pointer to descriptor memory area */
640 size_t AllocLength; /* length of complete descriptor area */
641 int i; /* loop counter */
642 unsigned long BusAddr;
645 /* rings plus one for alignment (do not cross 4 GB boundary) */
646 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
647 #if (BITS_PER_LONG == 32)
648 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
650 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
654 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
657 if (pDescrMem == NULL) {
660 pAC->pDescrMem = pDescrMem;
661 BusAddr = (unsigned long) pAC->pDescrMemDMA;
663 /* Descriptors need 8 byte alignment, and this is ensured
664 * by pci_alloc_consistent.
666 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
667 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
668 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
669 i, (unsigned long) pDescrMem,
671 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
672 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
673 pDescrMem += TX_RING_SIZE;
674 BusAddr += TX_RING_SIZE;
676 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
677 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
678 i, (unsigned long) pDescrMem,
679 (unsigned long)BusAddr));
680 pAC->RxPort[i].pRxDescrRing = pDescrMem;
681 pAC->RxPort[i].VRxDescrRing = BusAddr;
682 pDescrMem += RX_RING_SIZE;
683 BusAddr += RX_RING_SIZE;
687 } /* BoardAllocMem */
690 /****************************************************************************
692 * BoardFreeMem - reverse of BoardAllocMem
695 * Free all memory allocated in BoardAllocMem: adapter context,
696 * descriptor rings, locks.
700 static void BoardFreeMem(
703 size_t AllocLength; /* length of complete descriptor area */
705 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
707 #if (BITS_PER_LONG == 32)
708 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
710 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
714 pci_free_consistent(pAC->PciDev, AllocLength,
715 pAC->pDescrMem, pAC->pDescrMemDMA);
716 pAC->pDescrMem = NULL;
720 /*****************************************************************************
722 * BoardInitMem - initiate the descriptor rings
725 * This function sets the descriptor rings up in memory.
726 * The adapter is initialized with the descriptor start addresses.
730 static void BoardInitMem(
731 SK_AC *pAC) /* pointer to adapter context */
733 int i; /* loop counter */
734 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
735 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
737 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
740 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
741 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
742 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
743 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
745 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
748 pAC->TxPort[i][0].pTxDescrRing,
749 pAC->TxPort[i][0].VTxDescrRing,
750 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
751 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
752 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
753 &pAC->TxPort[i][0].TxdRingFree,
757 pAC->RxPort[i].pRxDescrRing,
758 pAC->RxPort[i].VRxDescrRing,
759 &pAC->RxPort[i].pRxdRingHead,
760 &pAC->RxPort[i].pRxdRingTail,
761 &pAC->RxPort[i].pRxdRingPrev,
762 &pAC->RxPort[i].RxdRingFree,
768 /*****************************************************************************
770 * SetupRing - create one descriptor ring
773 * This function creates one descriptor ring in the given memory area.
774 * The head, tail and number of free descriptors in the ring are set.
779 static void SetupRing(
781 void *pMemArea, /* a pointer to the memory area for the ring */
782 uintptr_t VMemArea, /* the virtual bus address of the memory area */
783 RXD **ppRingHead, /* address where the head should be written */
784 RXD **ppRingTail, /* address where the tail should be written */
785 RXD **ppRingPrev, /* address where the tail should be written */
786 int *pRingFree, /* address where the # of free descr. goes */
787 SK_BOOL IsTx) /* flag: is this a tx ring */
789 int i; /* loop counter */
790 int DescrSize; /* the size of a descriptor rounded up to alignment*/
791 int DescrNum; /* number of descriptors per ring */
792 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
793 RXD *pNextDescr; /* pointer to the next descriptor */
794 RXD *pPrevDescr; /* pointer to the previous descriptor */
795 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
797 if (IsTx == SK_TRUE) {
798 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
800 DescrNum = TX_RING_SIZE / DescrSize;
802 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
804 DescrNum = RX_RING_SIZE / DescrSize;
807 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
808 ("Descriptor size: %d Descriptor Number: %d\n",
809 DescrSize,DescrNum));
811 pDescr = (RXD*) pMemArea;
813 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
814 VNextDescr = VMemArea + DescrSize;
815 for(i=0; i<DescrNum; i++) {
816 /* set the pointers right */
817 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
818 pDescr->pNextRxd = pNextDescr;
819 if (!IsTx) pDescr->TcpSumStarts = ETH_HLEN << 16 | ETH_HLEN;
821 /* advance one step */
824 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
825 VNextDescr += DescrSize;
827 pPrevDescr->pNextRxd = (RXD*) pMemArea;
828 pPrevDescr->VNextRxd = VMemArea;
829 pDescr = (RXD*) pMemArea;
830 *ppRingHead = (RXD*) pMemArea;
831 *ppRingTail = *ppRingHead;
832 *ppRingPrev = pPrevDescr;
833 *pRingFree = DescrNum;
837 /*****************************************************************************
839 * PortReInitBmu - re-initiate the descriptor rings for one port
842 * This function reinitializes the descriptor rings of one port
843 * in memory. The port must be stopped before.
844 * The HW is initialized with the descriptor start addresses.
849 static void PortReInitBmu(
850 SK_AC *pAC, /* pointer to adapter context */
851 int PortIndex) /* index of the port for which to re-init */
853 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
856 /* set address of first descriptor of ring in BMU */
857 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
858 (uint32_t)(((caddr_t)
859 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
860 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
861 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
863 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
864 (uint32_t)(((caddr_t)
865 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
866 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
867 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
868 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
869 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
870 pAC->RxPort[PortIndex].pRxDescrRing +
871 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
872 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
873 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
874 pAC->RxPort[PortIndex].pRxDescrRing +
875 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
876 } /* PortReInitBmu */
879 /****************************************************************************
881 * SkGeIsr - handle adapter interrupts
884 * The interrupt routine is called when the network adapter
885 * generates an interrupt. It may also be called if another device
886 * shares this interrupt vector with the driver.
891 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
893 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
896 SK_U32 IntSrc; /* interrupts source register contents */
898 pNet = netdev_priv(dev);
902 * Check and process if its our interrupt
904 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
909 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
910 #if 0 /* software irq currently not used */
911 if (IntSrc & IS_IRQ_SW) {
912 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
913 SK_DBGCAT_DRV_INT_SRC,
917 if (IntSrc & IS_R1_F) {
918 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
919 SK_DBGCAT_DRV_INT_SRC,
921 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
922 SK_PNMI_CNT_RX_INTR(pAC, 0);
924 if (IntSrc & IS_R2_F) {
925 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
926 SK_DBGCAT_DRV_INT_SRC,
928 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
929 SK_PNMI_CNT_RX_INTR(pAC, 1);
931 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
932 if (IntSrc & IS_XA1_F) {
933 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
934 SK_DBGCAT_DRV_INT_SRC,
935 ("EOF AS TX1 IRQ\n"));
936 SK_PNMI_CNT_TX_INTR(pAC, 0);
937 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
938 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
939 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
941 if (IntSrc & IS_XA2_F) {
942 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
943 SK_DBGCAT_DRV_INT_SRC,
944 ("EOF AS TX2 IRQ\n"));
945 SK_PNMI_CNT_TX_INTR(pAC, 1);
946 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
947 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
948 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
950 #if 0 /* only if sync. queues used */
951 if (IntSrc & IS_XS1_F) {
952 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
953 SK_DBGCAT_DRV_INT_SRC,
954 ("EOF SY TX1 IRQ\n"));
955 SK_PNMI_CNT_TX_INTR(pAC, 1);
956 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
957 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
958 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
959 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
961 if (IntSrc & IS_XS2_F) {
962 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
963 SK_DBGCAT_DRV_INT_SRC,
964 ("EOF SY TX2 IRQ\n"));
965 SK_PNMI_CNT_TX_INTR(pAC, 1);
966 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
967 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
968 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
969 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
974 /* do all IO at once */
975 if (IntSrc & IS_R1_F)
976 ClearAndStartRx(pAC, 0);
977 if (IntSrc & IS_R2_F)
978 ClearAndStartRx(pAC, 1);
979 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
980 if (IntSrc & IS_XA1_F)
981 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
982 if (IntSrc & IS_XA2_F)
983 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
985 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
986 } /* while (IntSrc & IRQ_MASK != 0) */
988 IntSrc &= pAC->GIni.GIValIrqMask;
989 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
990 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
991 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
992 pAC->CheckQueue = SK_FALSE;
993 spin_lock(&pAC->SlowPathLock);
994 if (IntSrc & SPECIAL_IRQS)
995 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
997 SkEventDispatcher(pAC, pAC->IoBase);
998 spin_unlock(&pAC->SlowPathLock);
1001 * do it all again is case we cleared an interrupt that
1002 * came in after handling the ring (OUTs may be delayed
1003 * in hardware buffers, but are through after IN)
1005 * rroesler: has been commented out and shifted to
1006 * SkGeDrvEvent(), because it is timer
1009 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1010 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1013 if (pAC->CheckQueue) {
1014 pAC->CheckQueue = SK_FALSE;
1015 spin_lock(&pAC->SlowPathLock);
1016 SkEventDispatcher(pAC, pAC->IoBase);
1017 spin_unlock(&pAC->SlowPathLock);
1020 /* IRQ is processed - Enable IRQs again*/
1021 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1023 return SkIsrRetHandled;
1027 /****************************************************************************
1029 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1032 * The interrupt routine is called when the network adapter
1033 * generates an interrupt. It may also be called if another device
1034 * shares this interrupt vector with the driver.
1035 * This is the same as above, but handles only one port.
1040 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1042 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1045 SK_U32 IntSrc; /* interrupts source register contents */
1047 pNet = netdev_priv(dev);
1051 * Check and process if its our interrupt
1053 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1055 return SkIsrRetNone;
1058 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1059 #if 0 /* software irq currently not used */
1060 if (IntSrc & IS_IRQ_SW) {
1061 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1062 SK_DBGCAT_DRV_INT_SRC,
1063 ("Software IRQ\n"));
1066 if (IntSrc & IS_R1_F) {
1067 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1068 SK_DBGCAT_DRV_INT_SRC,
1070 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1071 SK_PNMI_CNT_RX_INTR(pAC, 0);
1073 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1074 if (IntSrc & IS_XA1_F) {
1075 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1076 SK_DBGCAT_DRV_INT_SRC,
1077 ("EOF AS TX1 IRQ\n"));
1078 SK_PNMI_CNT_TX_INTR(pAC, 0);
1079 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1080 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1081 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1083 #if 0 /* only if sync. queues used */
1084 if (IntSrc & IS_XS1_F) {
1085 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1086 SK_DBGCAT_DRV_INT_SRC,
1087 ("EOF SY TX1 IRQ\n"));
1088 SK_PNMI_CNT_TX_INTR(pAC, 0);
1089 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1090 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1091 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1092 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1097 /* do all IO at once */
1098 if (IntSrc & IS_R1_F)
1099 ClearAndStartRx(pAC, 0);
1100 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1101 if (IntSrc & IS_XA1_F)
1102 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1104 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1105 } /* while (IntSrc & IRQ_MASK != 0) */
1107 IntSrc &= pAC->GIni.GIValIrqMask;
1108 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1109 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1110 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1111 pAC->CheckQueue = SK_FALSE;
1112 spin_lock(&pAC->SlowPathLock);
1113 if (IntSrc & SPECIAL_IRQS)
1114 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1116 SkEventDispatcher(pAC, pAC->IoBase);
1117 spin_unlock(&pAC->SlowPathLock);
1120 * do it all again is case we cleared an interrupt that
1121 * came in after handling the ring (OUTs may be delayed
1122 * in hardware buffers, but are through after IN)
1124 * rroesler: has been commented out and shifted to
1125 * SkGeDrvEvent(), because it is timer
1128 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1131 /* IRQ is processed - Enable IRQs again*/
1132 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1134 return SkIsrRetHandled;
1135 } /* SkGeIsrOnePort */
1137 #ifdef CONFIG_NET_POLL_CONTROLLER
1138 /****************************************************************************
1140 * SkGePollController - polling receive, for netconsole
1143 * Polling receive - used by netconsole and other diagnostic tools
1144 * to allow network i/o with interrupts disabled.
1148 static void SkGePollController(struct net_device *dev)
1150 disable_irq(dev->irq);
1151 SkGeIsr(dev->irq, dev, NULL);
1152 enable_irq(dev->irq);
1156 /****************************************************************************
1158 * SkGeOpen - handle start of initialized adapter
1161 * This function starts the initialized adapter.
1162 * The board level variable is set and the adapter is
1163 * brought to full functionality.
1164 * The device flags are set for operation.
1165 * Do all necessary level 2 initialization, enable interrupts and
1166 * give start command to RLMT.
1172 static int SkGeOpen(
1173 struct SK_NET_DEVICE *dev)
1177 unsigned long Flags; /* for spin lock */
1179 SK_EVPARA EvPara; /* an event parameter union */
1181 pNet = netdev_priv(dev);
1184 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1185 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1187 #ifdef SK_DIAG_SUPPORT
1188 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1189 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1190 return (-1); /* still in use by diag; deny actions */
1195 /* Set blink mode */
1196 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1197 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1199 if (pAC->BoardLevel == SK_INIT_DATA) {
1200 /* level 1 init common modules here */
1201 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1202 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1205 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1206 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1207 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1208 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1209 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1210 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1211 pAC->BoardLevel = SK_INIT_IO;
1214 if (pAC->BoardLevel != SK_INIT_RUN) {
1215 /* tschilling: Level 2 init modules here, check return value. */
1216 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1217 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1220 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1221 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1222 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1223 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1224 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1225 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1226 pAC->BoardLevel = SK_INIT_RUN;
1229 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1230 /* Enable transmit descriptor polling. */
1231 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1232 FillRxRing(pAC, &pAC->RxPort[i]);
1234 SkGeYellowLED(pAC, pAC->IoBase, 1);
1236 StartDrvCleanupTimer(pAC);
1237 SkDimEnableModerationIfNeeded(pAC);
1238 SkDimDisplayModerationSettings(pAC);
1240 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1242 /* enable Interrupts */
1243 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1244 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1246 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1248 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1249 EvPara.Para32[0] = pAC->RlmtNets;
1250 EvPara.Para32[1] = -1;
1251 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1253 EvPara.Para32[0] = pAC->RlmtMode;
1254 EvPara.Para32[1] = 0;
1255 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1259 EvPara.Para32[0] = pNet->NetNr;
1260 EvPara.Para32[1] = -1;
1261 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1262 SkEventDispatcher(pAC, pAC->IoBase);
1263 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1268 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1269 ("SkGeOpen suceeded\n"));
1275 /****************************************************************************
1277 * SkGeClose - Stop initialized adapter
1280 * Close initialized adapter.
1284 * error code - on error
1286 static int SkGeClose(
1287 struct SK_NET_DEVICE *dev)
1293 unsigned long Flags; /* for spin lock */
1298 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1299 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1301 pNet = netdev_priv(dev);
1304 #ifdef SK_DIAG_SUPPORT
1305 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1306 if (pAC->DiagFlowCtrl == SK_FALSE) {
1308 ** notify that the interface which has been closed
1309 ** by operator interaction must not be started up
1310 ** again when the DIAG has finished.
1312 newPtrNet = netdev_priv(pAC->dev[0]);
1313 if (newPtrNet == pNet) {
1314 pAC->WasIfUp[0] = SK_FALSE;
1316 pAC->WasIfUp[1] = SK_FALSE;
1318 return 0; /* return to system everything is fine... */
1320 pAC->DiagFlowCtrl = SK_FALSE;
1325 netif_stop_queue(dev);
1327 if (pAC->RlmtNets == 1)
1328 PortIdx = pAC->ActivePort;
1330 PortIdx = pNet->NetNr;
1332 StopDrvCleanupTimer(pAC);
1335 * Clear multicast table, promiscuous mode ....
1337 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1338 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1341 if (pAC->MaxPorts == 1) {
1342 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1343 /* disable interrupts */
1344 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1345 EvPara.Para32[0] = pNet->NetNr;
1346 EvPara.Para32[1] = -1;
1347 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1348 SkEventDispatcher(pAC, pAC->IoBase);
1349 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1350 /* stop the hardware */
1351 SkGeDeInit(pAC, pAC->IoBase);
1352 pAC->BoardLevel = SK_INIT_DATA;
1353 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1356 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1357 EvPara.Para32[0] = pNet->NetNr;
1358 EvPara.Para32[1] = -1;
1359 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1360 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1361 SkEventDispatcher(pAC, pAC->IoBase);
1362 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1365 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1366 [TX_PRIO_LOW].TxDesRingLock, Flags);
1367 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1368 SK_STOP_ALL, SK_HARD_RST);
1369 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1370 [TX_PRIO_LOW].TxDesRingLock, Flags);
1373 if (pAC->RlmtNets == 1) {
1374 /* clear all descriptor rings */
1375 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1376 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1377 ClearRxRing(pAC, &pAC->RxPort[i]);
1378 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1381 /* clear port descriptor rings */
1382 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1383 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1384 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1387 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1388 ("SkGeClose: done "));
1390 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1391 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1392 sizeof(SK_PNMI_STRUCT_DATA));
1400 /*****************************************************************************
1402 * SkGeXmit - Linux frame transmit function
1405 * The system calls this function to send frames onto the wire.
1406 * It puts the frame in the tx descriptor ring. If the ring is
1407 * full then, the 'tbusy' flag is set.
1410 * 0, if everything is ok
1412 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1413 * allocated skb's) !!!
1415 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1419 int Rc; /* return code of XmitFrame */
1421 pNet = netdev_priv(dev);
1424 if ((!skb_shinfo(skb)->nr_frags) ||
1425 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1426 /* Don't activate scatter-gather and hardware checksum */
1428 if (pAC->RlmtNets == 2)
1431 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1436 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1439 /* scatter-gather and hardware TCP checksumming anabled*/
1440 if (pAC->RlmtNets == 2)
1443 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1448 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1452 /* Transmitter out of resources? */
1454 netif_stop_queue(dev);
1457 /* If not taken, give buffer ownership back to the
1463 dev->trans_start = jiffies;
1468 /*****************************************************************************
1470 * XmitFrame - fill one socket buffer into the transmit ring
1473 * This function puts a message into the transmit descriptor ring
1474 * if there is a descriptors left.
1475 * Linux skb's consist of only one continuous buffer.
1476 * The first step locks the ring. It is held locked
1477 * all time to avoid problems with SWITCH_../PORT_RESET.
1478 * Then the descriptoris allocated.
1479 * The second part is linking the buffer to the descriptor.
1480 * At the very last, the Control field of the descriptor
1481 * is made valid for the BMU and a start TX command is given
1485 * > 0 - on succes: the number of bytes in the message
1486 * = 0 - on resource shortage: this frame sent or dropped, now
1487 * the ring is full ( -> set tbusy)
1488 * < 0 - on failure: other problems ( -> return failure to upper layers)
1490 static int XmitFrame(
1491 SK_AC *pAC, /* pointer to adapter context */
1492 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1493 struct sk_buff *pMessage) /* pointer to send-message */
1495 TXD *pTxd; /* the rxd to fill */
1497 unsigned long Flags;
1499 int BytesSend = pMessage->len;
1501 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1503 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1504 #ifndef USE_TX_COMPLETE
1505 FreeTxDescriptors(pAC, pTxPort);
1507 if (pTxPort->TxdRingFree == 0) {
1509 ** no enough free descriptors in ring at the moment.
1510 ** Maybe free'ing some old one help?
1512 FreeTxDescriptors(pAC, pTxPort);
1513 if (pTxPort->TxdRingFree == 0) {
1514 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1515 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1516 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1517 SK_DBGCAT_DRV_TX_PROGRESS,
1518 ("XmitFrame failed\n"));
1520 ** the desired message can not be sent
1521 ** Because tbusy seems to be set, the message
1522 ** should not be freed here. It will be used
1523 ** by the scheduler of the ethernet handler
1530 ** If the passed socket buffer is of smaller MTU-size than 60,
1531 ** copy everything into new buffer and fill all bytes between
1532 ** the original packet end and the new packet end of 60 with 0x00.
1533 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1535 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1536 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1537 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1540 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1544 ** advance head counter behind descriptor needed for this frame,
1545 ** so that needed descriptor is reserved from that on. The next
1546 ** action will be to add the passed buffer to the TX-descriptor
1548 pTxd = pTxPort->pTxdRingHead;
1549 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1550 pTxPort->TxdRingFree--;
1553 DumpMsg(pMessage, "XmitFrame");
1557 ** First step is to map the data to be sent via the adapter onto
1558 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1559 ** and 2.6 need to use pci_map_page() for that mapping.
1561 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1562 virt_to_page(pMessage->data),
1563 ((unsigned long) pMessage->data & ~PAGE_MASK),
1566 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1567 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1568 pTxd->pMBuf = pMessage;
1570 if (pMessage->ip_summed == CHECKSUM_HW) {
1571 u16 hdrlen = pMessage->h.raw - pMessage->data;
1572 u16 offset = hdrlen + pMessage->csum;
1574 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1575 (pAC->GIni.GIChipRev == 0) &&
1576 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1577 pTxd->TBControl = BMU_TCP_CHECK;
1579 pTxd->TBControl = BMU_UDP_CHECK;
1582 pTxd->TcpSumOfs = 0;
1583 pTxd->TcpSumSt = hdrlen;
1584 pTxd->TcpSumWr = offset;
1586 pTxd->TBControl |= BMU_OWN | BMU_STF |
1588 #ifdef USE_TX_COMPLETE
1593 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1595 #ifdef USE_TX_COMPLETE
1602 ** If previous descriptor already done, give TX start cmd
1604 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1605 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1606 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1610 ** after releasing the lock, the skb may immediately be free'd
1612 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1613 if (pTxPort->TxdRingFree != 0) {
1621 /*****************************************************************************
1623 * XmitFrameSG - fill one socket buffer into the transmit ring
1624 * (use SG and TCP/UDP hardware checksumming)
1627 * This function puts a message into the transmit descriptor ring
1628 * if there is a descriptors left.
1631 * > 0 - on succes: the number of bytes in the message
1632 * = 0 - on resource shortage: this frame sent or dropped, now
1633 * the ring is full ( -> set tbusy)
1634 * < 0 - on failure: other problems ( -> return failure to upper layers)
1636 static int XmitFrameSG(
1637 SK_AC *pAC, /* pointer to adapter context */
1638 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1639 struct sk_buff *pMessage) /* pointer to send-message */
1647 skb_frag_t *sk_frag;
1649 unsigned long Flags;
1652 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1653 #ifndef USE_TX_COMPLETE
1654 FreeTxDescriptors(pAC, pTxPort);
1656 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1657 FreeTxDescriptors(pAC, pTxPort);
1658 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1659 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1660 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1661 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1662 SK_DBGCAT_DRV_TX_PROGRESS,
1663 ("XmitFrameSG failed - Ring full\n"));
1664 /* this message can not be sent now */
1669 pTxd = pTxPort->pTxdRingHead;
1675 ** Map the first fragment (header) into the DMA-space
1677 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1678 virt_to_page(pMessage->data),
1679 ((unsigned long) pMessage->data & ~PAGE_MASK),
1680 skb_headlen(pMessage),
1683 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1684 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1687 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1689 if (pMessage->ip_summed == CHECKSUM_HW) {
1690 u16 hdrlen = pMessage->h.raw - pMessage->data;
1691 u16 offset = hdrlen + pMessage->csum;
1693 Control = BMU_STFWD;
1696 ** We have to use the opcode for tcp here, because the
1697 ** opcode for udp is not working in the hardware yet
1700 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1701 (pAC->GIni.GIChipRev == 0) &&
1702 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1703 Control |= BMU_TCP_CHECK;
1705 Control |= BMU_UDP_CHECK;
1708 pTxd->TcpSumOfs = 0;
1709 pTxd->TcpSumSt = hdrlen;
1710 pTxd->TcpSumWr = offset;
1712 Control = BMU_CHECK | BMU_SW;
1714 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1716 pTxd = pTxd->pNextTxd;
1717 pTxPort->TxdRingFree--;
1718 BytesSend += skb_headlen(pMessage);
1721 ** Browse over all SG fragments and map each of them into the DMA space
1723 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1724 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1726 ** we already have the proper value in entry
1728 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1730 sk_frag->page_offset,
1734 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1735 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1736 pTxd->pMBuf = pMessage;
1738 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;;
1741 ** Do we have the last fragment?
1743 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1744 #ifdef USE_TX_COMPLETE
1745 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1747 pTxd->TBControl |= BMU_EOF;
1749 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1752 pTxd = pTxd->pNextTxd;
1753 pTxPort->TxdRingFree--;
1754 BytesSend += sk_frag->size;
1758 ** If previous descriptor already done, give TX start cmd
1760 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1761 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1764 pTxPort->pTxdRingPrev = pTxdLst;
1765 pTxPort->pTxdRingHead = pTxd;
1767 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1769 if (pTxPort->TxdRingFree > 0) {
1776 /*****************************************************************************
1778 * FreeTxDescriptors - release descriptors from the descriptor ring
1781 * This function releases descriptors from a transmit ring if they
1782 * have been sent by the BMU.
1783 * If a descriptors is sent, it can be freed and the message can
1785 * The SOFTWARE controllable bit is used to prevent running around a
1786 * completely free ring for ever. If this bit is no set in the
1787 * frame (by XmitFrame), this frame has never been sent or is
1789 * The Tx descriptor ring lock must be held while calling this function !!!
1794 static void FreeTxDescriptors(
1795 SK_AC *pAC, /* pointer to the adapter context */
1796 TX_PORT *pTxPort) /* pointer to destination port structure */
1798 TXD *pTxd; /* pointer to the checked descriptor */
1799 TXD *pNewTail; /* pointer to 'end' of the ring */
1800 SK_U32 Control; /* TBControl field of descriptor */
1801 SK_U64 PhysAddr; /* address of DMA mapping */
1803 pNewTail = pTxPort->pTxdRingTail;
1806 ** loop forever; exits if BMU_SW bit not set in start frame
1807 ** or BMU_OWN bit set in any frame
1810 Control = pTxd->TBControl;
1811 if ((Control & BMU_SW) == 0) {
1813 ** software controllable bit is set in first
1814 ** fragment when given to BMU. Not set means that
1815 ** this fragment was never sent or is already
1816 ** freed ( -> ring completely free now).
1818 pTxPort->pTxdRingTail = pTxd;
1819 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1822 if (Control & BMU_OWN) {
1823 pTxPort->pTxdRingTail = pTxd;
1824 if (pTxPort->TxdRingFree > 0) {
1825 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1831 ** release the DMA mapping, because until not unmapped
1832 ** this buffer is considered being under control of the
1835 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1836 PhysAddr |= (SK_U64) pTxd->VDataLow;
1837 pci_unmap_page(pAC->PciDev, PhysAddr,
1841 if (Control & BMU_EOF)
1842 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1844 pTxPort->TxdRingFree++;
1845 pTxd->TBControl &= ~BMU_SW;
1846 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1847 } /* while(forever) */
1848 } /* FreeTxDescriptors */
1850 /*****************************************************************************
1852 * FillRxRing - fill the receive ring with valid descriptors
1855 * This function fills the receive ring descriptors with data
1856 * segments and makes them valid for the BMU.
1857 * The active ring is filled completely, if possible.
1858 * The non-active ring is filled only partial to save memory.
1860 * Description of rx ring structure:
1861 * head - points to the descriptor which will be used next by the BMU
1862 * tail - points to the next descriptor to give to the BMU
1866 static void FillRxRing(
1867 SK_AC *pAC, /* pointer to the adapter context */
1868 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1871 unsigned long Flags;
1873 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1874 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1875 if(!FillRxDescriptor(pAC, pRxPort))
1878 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1882 /*****************************************************************************
1884 * FillRxDescriptor - fill one buffer into the receive ring
1887 * The function allocates a new receive buffer and
1888 * puts it into the next descriptor.
1891 * SK_TRUE - a buffer was added to the ring
1892 * SK_FALSE - a buffer could not be added
1894 static SK_BOOL FillRxDescriptor(
1895 SK_AC *pAC, /* pointer to the adapter context struct */
1896 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1898 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1899 RXD *pRxd; /* the rxd to fill */
1900 SK_U16 Length; /* data fragment length */
1901 SK_U64 PhysAddr; /* physical address of a rx buffer */
1903 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1904 if (pMsgBlock == NULL) {
1905 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1906 SK_DBGCAT_DRV_ENTRY,
1907 ("%s: Allocation of rx buffer failed !\n",
1908 pAC->dev[pRxPort->PortIndex]->name));
1909 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1912 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1913 /* skb allocated ok, so add buffer */
1914 pRxd = pRxPort->pRxdRingTail;
1915 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1916 pRxPort->RxdRingFree--;
1917 Length = pAC->RxBufSize;
1918 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1919 virt_to_page(pMsgBlock->data),
1920 ((unsigned long) pMsgBlock->data &
1923 PCI_DMA_FROMDEVICE);
1925 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1926 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1927 pRxd->pMBuf = pMsgBlock;
1928 pRxd->RBControl = BMU_OWN |
1935 } /* FillRxDescriptor */
1938 /*****************************************************************************
1940 * ReQueueRxBuffer - fill one buffer back into the receive ring
1943 * Fill a given buffer back into the rx ring. The buffer
1944 * has been previously allocated and aligned, and its phys.
1945 * address calculated, so this is no more necessary.
1949 static void ReQueueRxBuffer(
1950 SK_AC *pAC, /* pointer to the adapter context struct */
1951 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1952 struct sk_buff *pMsg, /* pointer to the buffer */
1953 SK_U32 PhysHigh, /* phys address high dword */
1954 SK_U32 PhysLow) /* phys address low dword */
1956 RXD *pRxd; /* the rxd to fill */
1957 SK_U16 Length; /* data fragment length */
1959 pRxd = pRxPort->pRxdRingTail;
1960 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1961 pRxPort->RxdRingFree--;
1962 Length = pAC->RxBufSize;
1964 pRxd->VDataLow = PhysLow;
1965 pRxd->VDataHigh = PhysHigh;
1967 pRxd->RBControl = BMU_OWN |
1973 } /* ReQueueRxBuffer */
1975 /*****************************************************************************
1977 * ReceiveIrq - handle a receive IRQ
1980 * This function is called when a receive IRQ is set.
1981 * It walks the receive descriptor ring and sends up all
1982 * frames that are complete.
1986 static void ReceiveIrq(
1987 SK_AC *pAC, /* pointer to adapter context */
1988 RX_PORT *pRxPort, /* pointer to receive port struct */
1989 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
1991 RXD *pRxd; /* pointer to receive descriptors */
1992 SK_U32 Control; /* control field of descriptor */
1993 struct sk_buff *pMsg; /* pointer to message holding frame */
1994 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
1995 int FrameLength; /* total length of received frame */
1996 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
1997 SK_EVPARA EvPara; /* an event parameter union */
1998 unsigned long Flags; /* for spin lock */
1999 int PortIndex = pRxPort->PortIndex;
2000 unsigned int Offset;
2001 unsigned int NumBytes;
2002 unsigned int ForRlmt;
2005 SK_BOOL IsBadFrame; /* Bad frame */
2011 /* do forever; exit if BMU_OWN found */
2012 for ( pRxd = pRxPort->pRxdRingHead ;
2013 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2014 pRxd = pRxd->pNextRxd,
2015 pRxPort->pRxdRingHead = pRxd,
2016 pRxPort->RxdRingFree ++) {
2019 * For a better understanding of this loop
2020 * Go through every descriptor beginning at the head
2021 * Please note: the ring might be completely received so the OWN bit
2022 * set is not a good crirteria to leave that loop.
2023 * Therefore the RingFree counter is used.
2024 * On entry of this loop pRxd is a pointer to the Rxd that needs
2025 * to be checked next.
2028 Control = pRxd->RBControl;
2030 /* check if this descriptor is ready */
2031 if ((Control & BMU_OWN) != 0) {
2032 /* this descriptor is not yet ready */
2033 /* This is the usual end of the loop */
2034 /* We don't need to start the ring again */
2035 FillRxRing(pAC, pRxPort);
2038 pAC->DynIrqModInfo.NbrProcessedDescr++;
2040 /* get length of frame and check it */
2041 FrameLength = Control & BMU_BBC;
2042 if (FrameLength > pAC->RxBufSize) {
2046 /* check for STF and EOF */
2047 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2051 /* here we have a complete frame in the ring */
2054 FrameStat = pRxd->FrameStat;
2056 /* check for frame length mismatch */
2057 #define XMR_FS_LEN_SHIFT 18
2058 #define GMR_FS_LEN_SHIFT 16
2059 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2060 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2061 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2062 SK_DBGCAT_DRV_RX_PROGRESS,
2063 ("skge: Frame length mismatch (%u/%u).\n",
2065 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2070 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2071 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2072 SK_DBGCAT_DRV_RX_PROGRESS,
2073 ("skge: Frame length mismatch (%u/%u).\n",
2075 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2081 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2082 IsBc = (FrameStat & XMR_FS_BC) != 0;
2083 IsMc = (FrameStat & XMR_FS_MC) != 0;
2084 IsBadFrame = (FrameStat &
2085 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2087 IsBc = (FrameStat & GMR_FS_BC) != 0;
2088 IsMc = (FrameStat & GMR_FS_MC) != 0;
2089 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2090 ((FrameStat & GMR_FS_RX_OK) == 0));
2093 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2094 ("Received frame of length %d on port %d\n",
2095 FrameLength, PortIndex));
2096 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2097 ("Number of free rx descriptors: %d\n",
2098 pRxPort->RxdRingFree));
2099 /* DumpMsg(pMsg, "Rx"); */
2101 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2103 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2105 /* there is a receive error in this frame */
2106 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2107 SK_DBGCAT_DRV_RX_PROGRESS,
2108 ("skge: Error in received frame, dropped!\n"
2109 "Control: %x\nRxStat: %x\n",
2110 Control, FrameStat));
2112 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2113 pRxd->VDataHigh, pRxd->VDataLow);
2119 * if short frame then copy data to reduce memory waste
2121 if ((FrameLength < SK_COPY_THRESHOLD) &&
2122 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2124 * Short frame detected and allocation successfull
2126 /* use new skb and copy data */
2127 skb_reserve(pNewMsg, 2);
2128 skb_put(pNewMsg, FrameLength);
2129 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2130 PhysAddr |= (SK_U64) pRxd->VDataLow;
2132 pci_dma_sync_single_for_cpu(pAC->PciDev,
2133 (dma_addr_t) PhysAddr,
2135 PCI_DMA_FROMDEVICE);
2136 memcpy(pNewMsg->data, pMsg, FrameLength);
2138 pci_dma_sync_single_for_device(pAC->PciDev,
2139 (dma_addr_t) PhysAddr,
2141 PCI_DMA_FROMDEVICE);
2142 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2143 pRxd->VDataHigh, pRxd->VDataLow);
2150 * if large frame, or SKB allocation failed, pass
2151 * the SKB directly to the networking
2154 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2155 PhysAddr |= (SK_U64) pRxd->VDataLow;
2157 /* release the DMA mapping */
2158 pci_unmap_single(pAC->PciDev,
2161 PCI_DMA_FROMDEVICE);
2163 /* set length in message */
2164 skb_put(pMsg, FrameLength);
2165 } /* frame > SK_COPY_TRESHOLD */
2167 #ifdef USE_SK_RX_CHECKSUM
2168 pMsg->csum = pRxd->TcpSums & 0xffff;
2169 pMsg->ip_summed = CHECKSUM_HW;
2171 pMsg->ip_summed = CHECKSUM_NONE;
2174 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2175 ForRlmt = SK_RLMT_RX_PROTOCOL;
2177 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2179 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2180 IsBc, &Offset, &NumBytes);
2181 if (NumBytes != 0) {
2183 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2185 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2186 &pMsg->data[Offset],
2187 IsBc, IsMc, &ForRlmt);
2189 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2190 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2191 /* send up only frames from active port */
2192 if ((PortIndex == pAC->ActivePort) ||
2193 (pAC->RlmtNets == 2)) {
2194 /* frame for upper layer */
2195 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2197 DumpMsg(pMsg, "Rx");
2199 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2200 FrameLength, pRxPort->PortIndex);
2202 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2203 pMsg->protocol = eth_type_trans(pMsg,
2204 pAC->dev[pRxPort->PortIndex]);
2206 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2210 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2211 SK_DBGCAT_DRV_RX_PROGRESS,
2213 DEV_KFREE_SKB(pMsg);
2216 } /* if not for rlmt */
2218 /* packet for rlmt */
2219 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2220 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2221 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2222 pAC->IoBase, FrameLength);
2223 if (pRlmtMbuf != NULL) {
2224 pRlmtMbuf->pNext = NULL;
2225 pRlmtMbuf->Length = FrameLength;
2226 pRlmtMbuf->PortIdx = PortIndex;
2227 EvPara.pParaPtr = pRlmtMbuf;
2228 memcpy((char*)(pRlmtMbuf->pData),
2229 (char*)(pMsg->data),
2232 /* SlowPathLock needed? */
2233 if (SlowPathLock == SK_TRUE) {
2234 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2235 SkEventQueue(pAC, SKGE_RLMT,
2236 SK_RLMT_PACKET_RECEIVED,
2238 pAC->CheckQueue = SK_TRUE;
2239 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2241 SkEventQueue(pAC, SKGE_RLMT,
2242 SK_RLMT_PACKET_RECEIVED,
2244 pAC->CheckQueue = SK_TRUE;
2247 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2248 SK_DBGCAT_DRV_RX_PROGRESS,
2251 if ((pAC->dev[pRxPort->PortIndex]->flags &
2252 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2253 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2254 SK_RLMT_RX_PROTOCOL) {
2255 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2256 pMsg->protocol = eth_type_trans(pMsg,
2257 pAC->dev[pRxPort->PortIndex]);
2259 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2262 DEV_KFREE_SKB(pMsg);
2265 } /* if packet for rlmt */
2266 } /* for ... scanning the RXD ring */
2268 /* RXD ring is empty -> fill and restart */
2269 FillRxRing(pAC, pRxPort);
2270 /* do not start if called from Close */
2271 if (pAC->BoardLevel > SK_INIT_DATA) {
2272 ClearAndStartRx(pAC, PortIndex);
2277 /* remove error frame */
2278 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2279 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2281 /* release the DMA mapping */
2283 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2284 PhysAddr |= (SK_U64) pRxd->VDataLow;
2285 pci_unmap_page(pAC->PciDev,
2288 PCI_DMA_FROMDEVICE);
2289 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2291 pRxPort->RxdRingFree++;
2292 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2298 /*****************************************************************************
2300 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2303 * This function sends a start command and a clear interrupt
2304 * command for one receive queue to the BMU.
2309 static void ClearAndStartRx(
2310 SK_AC *pAC, /* pointer to the adapter context */
2311 int PortIndex) /* index of the receive port (XMAC) */
2313 SK_OUT8(pAC->IoBase,
2314 RxQueueAddr[PortIndex]+Q_CSR,
2315 CSR_START | CSR_IRQ_CL_F);
2316 } /* ClearAndStartRx */
2319 /*****************************************************************************
2321 * ClearTxIrq - give a clear transmit IRQ command to BMU
2324 * This function sends a clear tx IRQ command for one
2325 * transmit queue to the BMU.
2329 static void ClearTxIrq(
2330 SK_AC *pAC, /* pointer to the adapter context */
2331 int PortIndex, /* index of the transmit port (XMAC) */
2332 int Prio) /* priority or normal queue */
2334 SK_OUT8(pAC->IoBase,
2335 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2340 /*****************************************************************************
2342 * ClearRxRing - remove all buffers from the receive ring
2345 * This function removes all receive buffers from the ring.
2346 * The receive BMU must be stopped before calling this function.
2350 static void ClearRxRing(
2351 SK_AC *pAC, /* pointer to adapter context */
2352 RX_PORT *pRxPort) /* pointer to rx port struct */
2354 RXD *pRxd; /* pointer to the current descriptor */
2355 unsigned long Flags;
2358 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2361 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2362 pRxd = pRxPort->pRxdRingHead;
2364 if (pRxd->pMBuf != NULL) {
2366 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2367 PhysAddr |= (SK_U64) pRxd->VDataLow;
2368 pci_unmap_page(pAC->PciDev,
2371 PCI_DMA_FROMDEVICE);
2372 DEV_KFREE_SKB(pRxd->pMBuf);
2375 pRxd->RBControl &= BMU_OWN;
2376 pRxd = pRxd->pNextRxd;
2377 pRxPort->RxdRingFree++;
2378 } while (pRxd != pRxPort->pRxdRingTail);
2379 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2380 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2383 /*****************************************************************************
2385 * ClearTxRing - remove all buffers from the transmit ring
2388 * This function removes all transmit buffers from the ring.
2389 * The transmit BMU must be stopped before calling this function
2390 * and transmitting at the upper level must be disabled.
2391 * The BMU own bit of all descriptors is cleared, the rest is
2392 * done by calling FreeTxDescriptors.
2396 static void ClearTxRing(
2397 SK_AC *pAC, /* pointer to adapter context */
2398 TX_PORT *pTxPort) /* pointer to tx prt struct */
2400 TXD *pTxd; /* pointer to the current descriptor */
2402 unsigned long Flags;
2404 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2405 pTxd = pTxPort->pTxdRingHead;
2406 for (i=0; i<pAC->TxDescrPerRing; i++) {
2407 pTxd->TBControl &= ~BMU_OWN;
2408 pTxd = pTxd->pNextTxd;
2410 FreeTxDescriptors(pAC, pTxPort);
2411 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2414 /*****************************************************************************
2416 * SkGeSetMacAddr - Set the hardware MAC address
2419 * This function sets the MAC address used by the adapter.
2422 * 0, if everything is ok
2425 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2428 DEV_NET *pNet = netdev_priv(dev);
2429 SK_AC *pAC = pNet->pAC;
2431 struct sockaddr *addr = p;
2432 unsigned long Flags;
2434 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2435 ("SkGeSetMacAddr starts now...\n"));
2436 if(netif_running(dev))
2439 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2441 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2443 if (pAC->RlmtNets == 2)
2444 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2445 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2447 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2448 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2452 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2454 } /* SkGeSetMacAddr */
2457 /*****************************************************************************
2459 * SkGeSetRxMode - set receive mode
2462 * This function sets the receive mode of an adapter. The adapter
2463 * supports promiscuous mode, allmulticast mode and a number of
2464 * multicast addresses. If more multicast addresses the available
2465 * are selected, a hash function in the hardware is used.
2468 * 0, if everything is ok
2471 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2477 struct dev_mc_list *pMcList;
2480 unsigned long Flags;
2482 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2483 ("SkGeSetRxMode starts now... "));
2485 pNet = netdev_priv(dev);
2487 if (pAC->RlmtNets == 1)
2488 PortIdx = pAC->ActivePort;
2490 PortIdx = pNet->NetNr;
2492 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2493 if (dev->flags & IFF_PROMISC) {
2494 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2495 ("PROMISCUOUS mode\n"));
2496 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2498 } else if (dev->flags & IFF_ALLMULTI) {
2499 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2500 ("ALLMULTI mode\n"));
2501 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2502 SK_PROM_MODE_ALL_MC);
2504 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2506 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2509 ("Number of MC entries: %d ", dev->mc_count));
2511 pMcList = dev->mc_list;
2512 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2513 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2514 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2515 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2516 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2517 pMcList->dmi_addr[0],
2518 pMcList->dmi_addr[1],
2519 pMcList->dmi_addr[2],
2520 pMcList->dmi_addr[3],
2521 pMcList->dmi_addr[4],
2522 pMcList->dmi_addr[5]));
2524 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2526 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2529 } /* SkGeSetRxMode */
2532 /*****************************************************************************
2534 * SkGeChangeMtu - set the MTU to another value
2537 * This function sets is called whenever the MTU size is changed
2538 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2539 * ethernet MTU size, long frame support is activated.
2542 * 0, if everything is ok
2545 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2548 struct net_device *pOtherDev;
2550 unsigned long Flags;
2554 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2555 ("SkGeChangeMtu starts now...\n"));
2557 pNet = netdev_priv(dev);
2560 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2564 if(pAC->BoardLevel != SK_INIT_RUN) {
2568 #ifdef SK_DIAG_SUPPORT
2569 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2570 if (pAC->DiagFlowCtrl == SK_FALSE) {
2571 return -1; /* still in use, deny any actions of MTU */
2573 pAC->DiagFlowCtrl = SK_FALSE;
2578 pOtherDev = pAC->dev[1 - pNet->NetNr];
2580 if ( netif_running(pOtherDev) && (pOtherDev->mtu > 1500)
2581 && (NewMtu <= 1500))
2584 pAC->RxBufSize = NewMtu + 32;
2587 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2588 ("New MTU: %d\n", NewMtu));
2591 ** Prevent any reconfiguration while changing the MTU
2592 ** by disabling any interrupts
2594 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2595 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2598 ** Notify RLMT that any ports are to be stopped
2600 EvPara.Para32[0] = 0;
2601 EvPara.Para32[1] = -1;
2602 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2603 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2604 EvPara.Para32[0] = 1;
2605 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2607 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2611 ** After calling the SkEventDispatcher(), RLMT is aware about
2612 ** the stopped ports -> configuration can take place!
2614 SkEventDispatcher(pAC, pAC->IoBase);
2616 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2617 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2618 netif_stop_queue(pAC->dev[i]);
2623 ** Depending on the desired MTU size change, a different number of
2624 ** RX buffers need to be allocated
2626 if (NewMtu > 1500) {
2628 ** Use less rx buffers
2630 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2631 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2632 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2633 (pAC->RxDescrPerRing / 4);
2635 if (i == pAC->ActivePort) {
2636 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2637 (pAC->RxDescrPerRing / 4);
2639 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2640 (pAC->RxDescrPerRing / 10);
2646 ** Use the normal amount of rx buffers
2648 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2649 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2650 pAC->RxPort[i].RxFillLimit = 1;
2652 if (i == pAC->ActivePort) {
2653 pAC->RxPort[i].RxFillLimit = 1;
2655 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2656 (pAC->RxDescrPerRing / 4);
2662 SkGeDeInit(pAC, pAC->IoBase);
2665 ** enable/disable hardware support for long frames
2667 if (NewMtu > 1500) {
2668 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2669 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2671 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2672 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2674 pAC->GIni.GIPortUsage = SK_RED_LINK;
2678 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2679 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2680 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2681 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2682 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2683 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2684 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2688 ** Speed and others are set back to default in level 1 init!
2690 GetConfiguration(pAC);
2692 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2693 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2694 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2695 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2696 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2697 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2698 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2701 ** clear and reinit the rx rings here
2703 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2704 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2705 ClearRxRing(pAC, &pAC->RxPort[i]);
2706 FillRxRing(pAC, &pAC->RxPort[i]);
2709 ** Enable transmit descriptor polling
2711 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2712 FillRxRing(pAC, &pAC->RxPort[i]);
2715 SkGeYellowLED(pAC, pAC->IoBase, 1);
2716 SkDimEnableModerationIfNeeded(pAC);
2717 SkDimDisplayModerationSettings(pAC);
2719 netif_start_queue(pAC->dev[pNet->PortNr]);
2720 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2721 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2725 ** Enable Interrupts again
2727 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2728 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2730 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2731 SkEventDispatcher(pAC, pAC->IoBase);
2734 ** Notify RLMT about the changing and restarting one (or more) ports
2736 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2737 EvPara.Para32[0] = pAC->RlmtNets;
2738 EvPara.Para32[1] = -1;
2739 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2740 EvPara.Para32[0] = pNet->PortNr;
2741 EvPara.Para32[1] = -1;
2742 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2744 if (netif_running(pOtherDev)) {
2745 DEV_NET *pOtherNet = netdev_priv(pOtherDev);
2746 EvPara.Para32[0] = pOtherNet->PortNr;
2747 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2750 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2753 SkEventDispatcher(pAC, pAC->IoBase);
2754 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2757 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2758 ** seems as if upper layers have a problem to handle a successful
2759 ** return value of '0'. If such a zero is returned, the complete
2760 ** system hangs for several minutes (!), which is in acceptable.
2762 ** Currently it is not clear, what the exact reason for this problem
2763 ** is. The implemented workaround for 2.5 is to return the desired
2764 ** new MTU size if all needed changes for the new MTU size where
2765 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2766 ** which indicates the successful change of the mtu-size.
2770 } /* SkGeChangeMtu */
2773 /*****************************************************************************
2775 * SkGeStats - return ethernet device statistics
2778 * This function return statistic data about the ethernet device
2779 * to the operating system.
2782 * pointer to the statistic structure.
2784 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2786 DEV_NET *pNet = netdev_priv(dev);
2787 SK_AC *pAC = pNet->pAC;
2788 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2789 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2790 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2791 unsigned int Size; /* size of pnmi struct */
2792 unsigned long Flags; /* for spin lock */
2794 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2795 ("SkGeStats starts now...\n"));
2796 pPnmiStruct = &pAC->PnmiStruct;
2798 #ifdef SK_DIAG_SUPPORT
2799 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2800 (pAC->BoardLevel == SK_INIT_RUN)) {
2802 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2803 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2804 Size = SK_PNMI_STRUCT_SIZE;
2805 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2806 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2807 #ifdef SK_DIAG_SUPPORT
2811 pPnmiStat = &pPnmiStruct->Stat[0];
2812 pPnmiConf = &pPnmiStruct->Conf[0];
2814 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2815 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2816 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2817 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2819 if (dev->mtu <= 1500) {
2820 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2822 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2823 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2827 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2828 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2830 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2831 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2832 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2833 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2834 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2836 /* detailed rx_errors: */
2837 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2838 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2839 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2840 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2841 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2842 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2844 /* detailed tx_errors */
2845 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2846 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2847 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2848 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2849 pAC->stats.tx_window_errors = (SK_U32) 0;
2851 return(&pAC->stats);
2855 /*****************************************************************************
2857 * SkGeIoctl - IO-control function
2860 * This function is called if an ioctl is issued on the device.
2861 * There are three subfunction for reading, writing and test-writing
2862 * the private MIB data structure (usefull for SysKonnect-internal tools).
2865 * 0, if everything is ok
2868 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2873 struct pci_dev *pdev = NULL;
2875 unsigned int Err = 0;
2878 unsigned int Length = 0;
2879 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2881 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2882 ("SkGeIoctl starts now...\n"));
2884 pNet = netdev_priv(dev);
2887 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2892 case SK_IOCTL_SETMIB:
2893 case SK_IOCTL_PRESETMIB:
2894 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2895 case SK_IOCTL_GETMIB:
2896 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2897 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2898 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2901 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2902 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2903 Ioctl.Len<Size? Ioctl.Len : Size)) {
2907 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2912 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2915 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2917 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2920 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2924 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2928 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2933 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2938 kfree(pMemBuf); /* cleanup everything */
2940 #ifdef SK_DIAG_SUPPORT
2942 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2943 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2946 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2948 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2951 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2956 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2958 ** While coding this new IOCTL interface, only a few lines of code
2959 ** are to to be added. Therefore no dedicated function has been
2960 ** added. If more functionality is added, a separate function
2961 ** should be used...
2963 * ((SK_U32 *)pMemBuf) = 0;
2964 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2965 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2966 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2971 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2976 kfree(pMemBuf); /* cleanup everything */
2988 /*****************************************************************************
2990 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
2993 * This function reads/writes the MIB data using PNMI (Private Network
2994 * Management Interface).
2995 * The destination for the data must be provided with the
2996 * ioctl call and is given to the driver in the form of
2997 * a user space address.
2998 * Copying from the user-provided data area into kernel messages
2999 * and back is done by copy_from_user and copy_to_user calls in
3003 * returned size from PNMI call
3005 static int SkGeIocMib(
3006 DEV_NET *pNet, /* pointer to the adapter context */
3007 unsigned int Size, /* length of ioctl data */
3008 int mode) /* flag for set/preset */
3010 unsigned long Flags; /* for spin lock */
3013 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3014 ("SkGeIocMib starts now...\n"));
3017 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3019 case SK_IOCTL_GETMIB:
3020 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3023 case SK_IOCTL_PRESETMIB:
3024 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3027 case SK_IOCTL_SETMIB:
3028 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3034 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3035 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3036 ("MIB data access succeeded\n"));
3041 /*****************************************************************************
3043 * GetConfiguration - read configuration information
3046 * This function reads per-adapter configuration information from
3047 * the options provided on the command line.
3052 static void GetConfiguration(
3053 SK_AC *pAC) /* pointer to the adapter context structure */
3055 SK_I32 Port; /* preferred port */
3058 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3059 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3060 int DuplexCap = 0; /* 0=both,1=full,2=half */
3061 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3062 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3064 SK_BOOL IsConTypeDefined = SK_TRUE;
3065 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3066 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3067 SK_BOOL IsRoleDefined = SK_TRUE;
3068 SK_BOOL IsModeDefined = SK_TRUE;
3070 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3071 * parameter. The mapping is described by this table:
3072 * DuplexCap -> | both | full | half |
3074 * -----------------------------------------------------------------
3075 * Off | illegal | Full | Half |
3076 * -----------------------------------------------------------------
3077 * On | AutoBoth | AutoFull | AutoHalf |
3078 * -----------------------------------------------------------------
3079 * Sense | AutoSense | AutoSense | AutoSense |
3081 int Capabilities[3][3] =
3082 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3083 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3084 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3092 #define M_CurrPort pAC->GIni.GP[Port]
3096 ** Set the default values first for both ports!
3098 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3099 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3100 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3101 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3102 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3106 ** Check merged parameter ConType. If it has not been used,
3107 ** verify any other parameter (e.g. AutoNeg) and use default values.
3109 ** Stating both ConType and other lowlevel link parameters is also
3110 ** possible. If this is the case, the passed ConType-parameter is
3111 ** overwritten by the lowlevel link parameter.
3113 ** The following settings are used for a merged ConType-parameter:
3115 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3116 ** ------- ------ ------- -------- ---------- -----
3117 ** Auto Both On SymOrRem Auto Auto
3118 ** 100FD Full Off None <ignored> 100
3119 ** 100HD Half Off None <ignored> 100
3120 ** 10FD Full Off None <ignored> 10
3121 ** 10HD Half Off None <ignored> 10
3123 ** This ConType parameter is used for all ports of the adapter!
3125 if ( (ConType != NULL) &&
3126 (pAC->Index < SK_MAX_CARD_PARAM) &&
3127 (ConType[pAC->Index] != NULL) ) {
3129 /* Check chipset family */
3130 if ((!pAC->ChipsetType) &&
3131 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3132 (strcmp(ConType[pAC->Index],"")!=0)) {
3133 /* Set the speed parameter back */
3134 printk("sk98lin: Illegal value \"%s\" "
3137 ConType[pAC->Index]);
3139 sprintf(ConType[pAC->Index], "Auto");
3142 if (strcmp(ConType[pAC->Index],"")==0) {
3143 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3144 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3145 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3146 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3147 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3148 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3149 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3151 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3152 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3153 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3154 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3155 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3156 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3158 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3159 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3160 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3161 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3162 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3163 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3165 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3166 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3167 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3168 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3169 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3170 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3172 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3173 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3174 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3175 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3176 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3177 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3180 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3181 ConType[pAC->Index]);
3182 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3185 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3189 ** Parse any parameter settings for port A:
3190 ** a) any LinkSpeed stated?
3192 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3193 Speed_A[pAC->Index] != NULL) {
3194 if (strcmp(Speed_A[pAC->Index],"")==0) {
3195 IsLinkSpeedDefined = SK_FALSE;
3196 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3197 LinkSpeed = SK_LSPEED_AUTO;
3198 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3199 LinkSpeed = SK_LSPEED_10MBPS;
3200 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3201 LinkSpeed = SK_LSPEED_100MBPS;
3202 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3203 LinkSpeed = SK_LSPEED_1000MBPS;
3205 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3206 Speed_A[pAC->Index]);
3207 IsLinkSpeedDefined = SK_FALSE;
3210 IsLinkSpeedDefined = SK_FALSE;
3214 ** Check speed parameter:
3215 ** Only copper type adapter and GE V2 cards
3217 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3218 ((LinkSpeed != SK_LSPEED_AUTO) &&
3219 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3220 printk("sk98lin: Illegal value for Speed_A. "
3221 "Not a copper card or GE V2 card\n Using "
3223 LinkSpeed = SK_LSPEED_1000MBPS;
3227 ** Decide whether to set new config value if somethig valid has
3230 if (IsLinkSpeedDefined) {
3231 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3235 ** b) Any Autonegotiation and DuplexCapabilities set?
3236 ** Please note that both belong together...
3238 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3240 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3241 AutoNeg_A[pAC->Index] != NULL) {
3243 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3245 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3247 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3249 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3252 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3253 AutoNeg_A[pAC->Index]);
3257 DuplexCap = DC_BOTH;
3259 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3260 DupCap_A[pAC->Index] != NULL) {
3262 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3264 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3265 DuplexCap = DC_BOTH;
3266 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3267 DuplexCap = DC_FULL;
3268 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3269 DuplexCap = DC_HALF;
3271 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3272 DupCap_A[pAC->Index]);
3277 ** Check for illegal combinations
3279 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3280 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3281 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3282 (pAC->ChipsetType)) {
3283 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3284 " Using Full Duplex.\n");
3285 DuplexCap = DC_FULL;
3288 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3289 printk("sk98lin, Port A: DuplexCapabilities"
3290 " ignored using Sense mode\n");
3293 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3294 printk("sk98lin: Port A: Illegal combination"
3295 " of values AutoNeg. and DuplexCap.\n Using "
3297 DuplexCap = DC_FULL;
3300 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3301 DuplexCap = DC_FULL;
3304 if (!AutoSet && DupSet) {
3305 printk("sk98lin: Port A: Duplex setting not"
3306 " possible in\n default AutoNegotiation mode"
3307 " (Sense).\n Using AutoNegotiation On\n");
3312 ** set the desired mode
3314 if (AutoSet || DupSet) {
3315 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3319 ** c) Any Flowcontrol-parameter set?
3321 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3322 FlowCtrl_A[pAC->Index] != NULL) {
3323 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3324 IsFlowCtrlDefined = SK_FALSE;
3325 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3326 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3327 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3328 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3329 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3330 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3331 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3332 FlowCtrl = SK_FLOW_MODE_NONE;
3334 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3335 FlowCtrl_A[pAC->Index]);
3336 IsFlowCtrlDefined = SK_FALSE;
3339 IsFlowCtrlDefined = SK_FALSE;
3342 if (IsFlowCtrlDefined) {
3343 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3344 printk("sk98lin: Port A: FlowControl"
3345 " impossible without AutoNegotiation,"
3347 FlowCtrl = SK_FLOW_MODE_NONE;
3349 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3353 ** d) What is with the RoleParameter?
3355 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3356 Role_A[pAC->Index] != NULL) {
3357 if (strcmp(Role_A[pAC->Index],"")==0) {
3358 IsRoleDefined = SK_FALSE;
3359 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3360 MSMode = SK_MS_MODE_AUTO;
3361 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3362 MSMode = SK_MS_MODE_MASTER;
3363 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3364 MSMode = SK_MS_MODE_SLAVE;
3366 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3367 Role_A[pAC->Index]);
3368 IsRoleDefined = SK_FALSE;
3371 IsRoleDefined = SK_FALSE;
3374 if (IsRoleDefined == SK_TRUE) {
3375 pAC->GIni.GP[0].PMSMode = MSMode;
3381 ** Parse any parameter settings for port B:
3382 ** a) any LinkSpeed stated?
3384 IsConTypeDefined = SK_TRUE;
3385 IsLinkSpeedDefined = SK_TRUE;
3386 IsFlowCtrlDefined = SK_TRUE;
3387 IsModeDefined = SK_TRUE;
3389 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3390 Speed_B[pAC->Index] != NULL) {
3391 if (strcmp(Speed_B[pAC->Index],"")==0) {
3392 IsLinkSpeedDefined = SK_FALSE;
3393 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3394 LinkSpeed = SK_LSPEED_AUTO;
3395 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3396 LinkSpeed = SK_LSPEED_10MBPS;
3397 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3398 LinkSpeed = SK_LSPEED_100MBPS;
3399 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3400 LinkSpeed = SK_LSPEED_1000MBPS;
3402 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3403 Speed_B[pAC->Index]);
3404 IsLinkSpeedDefined = SK_FALSE;
3407 IsLinkSpeedDefined = SK_FALSE;
3411 ** Check speed parameter:
3412 ** Only copper type adapter and GE V2 cards
3414 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3415 ((LinkSpeed != SK_LSPEED_AUTO) &&
3416 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3417 printk("sk98lin: Illegal value for Speed_B. "
3418 "Not a copper card or GE V2 card\n Using "
3420 LinkSpeed = SK_LSPEED_1000MBPS;
3424 ** Decide whether to set new config value if somethig valid has
3427 if (IsLinkSpeedDefined) {
3428 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3432 ** b) Any Autonegotiation and DuplexCapabilities set?
3433 ** Please note that both belong together...
3435 AutoNeg = AN_SENS; /* default: do auto Sense */
3437 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3438 AutoNeg_B[pAC->Index] != NULL) {
3440 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3442 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3444 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3446 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3449 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3450 AutoNeg_B[pAC->Index]);
3454 DuplexCap = DC_BOTH;
3456 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3457 DupCap_B[pAC->Index] != NULL) {
3459 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3461 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3462 DuplexCap = DC_BOTH;
3463 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3464 DuplexCap = DC_FULL;
3465 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3466 DuplexCap = DC_HALF;
3468 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3469 DupCap_B[pAC->Index]);
3475 ** Check for illegal combinations
3477 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3478 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3479 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3480 (pAC->ChipsetType)) {
3481 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3482 " Using Full Duplex.\n");
3483 DuplexCap = DC_FULL;
3486 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3487 printk("sk98lin, Port B: DuplexCapabilities"
3488 " ignored using Sense mode\n");
3491 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3492 printk("sk98lin: Port B: Illegal combination"
3493 " of values AutoNeg. and DuplexCap.\n Using "
3495 DuplexCap = DC_FULL;
3498 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3499 DuplexCap = DC_FULL;
3502 if (!AutoSet && DupSet) {
3503 printk("sk98lin: Port B: Duplex setting not"
3504 " possible in\n default AutoNegotiation mode"
3505 " (Sense).\n Using AutoNegotiation On\n");
3510 ** set the desired mode
3512 if (AutoSet || DupSet) {
3513 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3517 ** c) Any FlowCtrl parameter set?
3519 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3520 FlowCtrl_B[pAC->Index] != NULL) {
3521 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3522 IsFlowCtrlDefined = SK_FALSE;
3523 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3524 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3525 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3526 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3527 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3528 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3529 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3530 FlowCtrl = SK_FLOW_MODE_NONE;
3532 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3533 FlowCtrl_B[pAC->Index]);
3534 IsFlowCtrlDefined = SK_FALSE;
3537 IsFlowCtrlDefined = SK_FALSE;
3540 if (IsFlowCtrlDefined) {
3541 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3542 printk("sk98lin: Port B: FlowControl"
3543 " impossible without AutoNegotiation,"
3545 FlowCtrl = SK_FLOW_MODE_NONE;
3547 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3551 ** d) What is the RoleParameter?
3553 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3554 Role_B[pAC->Index] != NULL) {
3555 if (strcmp(Role_B[pAC->Index],"")==0) {
3556 IsRoleDefined = SK_FALSE;
3557 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3558 MSMode = SK_MS_MODE_AUTO;
3559 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3560 MSMode = SK_MS_MODE_MASTER;
3561 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3562 MSMode = SK_MS_MODE_SLAVE;
3564 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3565 Role_B[pAC->Index]);
3566 IsRoleDefined = SK_FALSE;
3569 IsRoleDefined = SK_FALSE;
3572 if (IsRoleDefined) {
3573 pAC->GIni.GP[1].PMSMode = MSMode;
3577 ** Evaluate settings for both ports
3579 pAC->ActivePort = 0;
3580 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3581 PrefPort[pAC->Index] != NULL) {
3582 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3583 pAC->ActivePort = 0;
3584 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3585 pAC->Rlmt.Net[0].PrefPort = 0;
3586 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3588 ** do not set ActivePort here, thus a port
3589 ** switch is issued after net up.
3592 pAC->Rlmt.Net[0].Preference = Port;
3593 pAC->Rlmt.Net[0].PrefPort = Port;
3594 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3596 ** do not set ActivePort here, thus a port
3597 ** switch is issued after net up.
3599 if (pAC->GIni.GIMacsFound == 1) {
3600 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3601 " Port B not available on single port adapters.\n");
3603 pAC->ActivePort = 0;
3604 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3605 pAC->Rlmt.Net[0].PrefPort = 0;
3608 pAC->Rlmt.Net[0].Preference = Port;
3609 pAC->Rlmt.Net[0].PrefPort = Port;
3612 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3613 PrefPort[pAC->Index]);
3619 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3620 RlmtMode[pAC->Index] != NULL) {
3621 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3623 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3624 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3625 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3626 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3627 SK_RLMT_CHECK_LOC_LINK;
3628 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3629 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3630 SK_RLMT_CHECK_LOC_LINK |
3632 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3633 (pAC->GIni.GIMacsFound == 2)) {
3634 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3637 printk("sk98lin: Illegal value \"%s\" for"
3638 " RlmtMode, using default\n",
3639 RlmtMode[pAC->Index]);
3647 ** Check the interrupt moderation parameters
3649 if (Moderation[pAC->Index] != NULL) {
3650 if (strcmp(Moderation[pAC->Index], "") == 0) {
3651 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3652 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3653 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3654 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3655 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3656 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3657 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3659 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3660 " Disable interrupt moderation.\n",
3661 Moderation[pAC->Index]);
3662 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3665 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3668 if (Stats[pAC->Index] != NULL) {
3669 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3670 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3672 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3675 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3678 if (ModerationMask[pAC->Index] != NULL) {
3679 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3680 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3681 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3682 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3683 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3684 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3685 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3686 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3687 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3688 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3689 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3690 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3691 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3692 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3693 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3694 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3695 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3696 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3697 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3698 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3699 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3700 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3701 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3702 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3703 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3704 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3705 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3706 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3707 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3708 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3709 } else { /* some rubbish */
3710 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3712 } else { /* operator has stated nothing */
3713 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3716 if (AutoSizing[pAC->Index] != NULL) {
3717 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3718 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3720 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3722 } else { /* operator has stated nothing */
3723 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3726 if (IntsPerSec[pAC->Index] != 0) {
3727 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3728 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3729 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3730 " Using default value of %i.\n",
3731 IntsPerSec[pAC->Index],
3732 C_INT_MOD_IPS_LOWER_RANGE,
3733 C_INT_MOD_IPS_UPPER_RANGE,
3734 C_INTS_PER_SEC_DEFAULT);
3735 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3737 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3740 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3744 ** Evaluate upper and lower moderation threshold
3746 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3747 pAC->DynIrqModInfo.MaxModIntsPerSec +
3748 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3750 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3751 pAC->DynIrqModInfo.MaxModIntsPerSec -
3752 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3754 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3757 } /* GetConfiguration */
3760 /*****************************************************************************
3762 * ProductStr - return a adapter identification string from vpd
3765 * This function reads the product name string from the vpd area
3766 * and puts it the field pAC->DeviceString.
3770 static inline int ProductStr(
3771 SK_AC *pAC, /* pointer to adapter context */
3772 char *DeviceStr, /* result string */
3773 int StrLen /* length of the string */
3776 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3777 int ReturnCode; /* return code from vpd_read */
3778 unsigned long Flags;
3780 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3781 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, DeviceStr, &StrLen);
3782 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3787 /*****************************************************************************
3789 * StartDrvCleanupTimer - Start timer to check for descriptors which
3790 * might be placed in descriptor ring, but
3791 * havent been handled up to now
3794 * This function requests a HW-timer fo the Yukon card. The actions to
3795 * perform when this timer expires, are located in the SkDrvEvent().
3800 StartDrvCleanupTimer(SK_AC *pAC) {
3801 SK_EVPARA EventParam; /* Event struct for timer event */
3803 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3804 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3805 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3806 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3807 SKGE_DRV, SK_DRV_TIMER, EventParam);
3810 /*****************************************************************************
3812 * StopDrvCleanupTimer - Stop timer to check for descriptors
3815 * This function requests a HW-timer fo the Yukon card. The actions to
3816 * perform when this timer expires, are located in the SkDrvEvent().
3821 StopDrvCleanupTimer(SK_AC *pAC) {
3822 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3823 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3826 /****************************************************************************/
3827 /* functions for common modules *********************************************/
3828 /****************************************************************************/
3831 /*****************************************************************************
3833 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3836 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3837 * is embedded into a socket buff data area.
3843 * NULL or pointer to Mbuf.
3845 SK_MBUF *SkDrvAllocRlmtMbuf(
3846 SK_AC *pAC, /* pointer to adapter context */
3847 SK_IOC IoC, /* the IO-context */
3848 unsigned BufferSize) /* size of the requested buffer */
3850 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3851 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3853 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3854 if (pMsgBlock == NULL) {
3857 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3858 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3859 pRlmtMbuf->pNext = NULL;
3860 pRlmtMbuf->pOs = pMsgBlock;
3861 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3862 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3863 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3866 } /* SkDrvAllocRlmtMbuf */
3869 /*****************************************************************************
3871 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3874 * This routine frees one or more RLMT mbuf(s).
3882 void SkDrvFreeRlmtMbuf(
3883 SK_AC *pAC, /* pointer to adapter context */
3884 SK_IOC IoC, /* the IO-context */
3885 SK_MBUF *pMbuf) /* size of the requested buffer */
3892 pNextMbuf = pFreeMbuf->pNext;
3893 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3894 pFreeMbuf = pNextMbuf;
3895 } while ( pFreeMbuf != NULL );
3896 } /* SkDrvFreeRlmtMbuf */
3899 /*****************************************************************************
3901 * SkOsGetTime - provide a time value
3904 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3905 * It is not used for absolute time, but only for time differences.
3911 SK_U64 SkOsGetTime(SK_AC *pAC)
3913 SK_U64 PrivateJiffies;
3914 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3915 return PrivateJiffies;
3919 /*****************************************************************************
3921 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3924 * This routine reads a 32 bit value from the pci configuration
3928 * 0 - indicate everything worked ok.
3929 * != 0 - error indication
3931 int SkPciReadCfgDWord(
3932 SK_AC *pAC, /* Adapter Control structure pointer */
3933 int PciAddr, /* PCI register address */
3934 SK_U32 *pVal) /* pointer to store the read value */
3936 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3938 } /* SkPciReadCfgDWord */
3941 /*****************************************************************************
3943 * SkPciReadCfgWord - read a 16 bit value from pci config space
3946 * This routine reads a 16 bit value from the pci configuration
3950 * 0 - indicate everything worked ok.
3951 * != 0 - error indication
3953 int SkPciReadCfgWord(
3954 SK_AC *pAC, /* Adapter Control structure pointer */
3955 int PciAddr, /* PCI register address */
3956 SK_U16 *pVal) /* pointer to store the read value */
3958 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3960 } /* SkPciReadCfgWord */
3963 /*****************************************************************************
3965 * SkPciReadCfgByte - read a 8 bit value from pci config space
3968 * This routine reads a 8 bit value from the pci configuration
3972 * 0 - indicate everything worked ok.
3973 * != 0 - error indication
3975 int SkPciReadCfgByte(
3976 SK_AC *pAC, /* Adapter Control structure pointer */
3977 int PciAddr, /* PCI register address */
3978 SK_U8 *pVal) /* pointer to store the read value */
3980 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
3982 } /* SkPciReadCfgByte */
3985 /*****************************************************************************
3987 * SkPciWriteCfgWord - write a 16 bit value to pci config space
3990 * This routine writes a 16 bit value to the pci configuration
3991 * space. The flag PciConfigUp indicates whether the config space
3992 * is accesible or must be set up first.
3995 * 0 - indicate everything worked ok.
3996 * != 0 - error indication
3998 int SkPciWriteCfgWord(
3999 SK_AC *pAC, /* Adapter Control structure pointer */
4000 int PciAddr, /* PCI register address */
4001 SK_U16 Val) /* pointer to store the read value */
4003 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4005 } /* SkPciWriteCfgWord */
4008 /*****************************************************************************
4010 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4013 * This routine writes a 8 bit value to the pci configuration
4014 * space. The flag PciConfigUp indicates whether the config space
4015 * is accesible or must be set up first.
4018 * 0 - indicate everything worked ok.
4019 * != 0 - error indication
4021 int SkPciWriteCfgByte(
4022 SK_AC *pAC, /* Adapter Control structure pointer */
4023 int PciAddr, /* PCI register address */
4024 SK_U8 Val) /* pointer to store the read value */
4026 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4028 } /* SkPciWriteCfgByte */
4031 /*****************************************************************************
4033 * SkDrvEvent - handle driver events
4036 * This function handles events from all modules directed to the driver
4039 * Is called under protection of slow path lock.
4042 * 0 if everything ok
4047 SK_AC *pAC, /* pointer to adapter context */
4048 SK_IOC IoC, /* io-context */
4049 SK_U32 Event, /* event-id */
4050 SK_EVPARA Param) /* event-parameter */
4052 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4053 struct sk_buff *pMsg; /* pointer to a message block */
4054 int FromPort; /* the port from which we switch away */
4055 int ToPort; /* the port we switch to */
4056 SK_EVPARA NewPara; /* parameter for further events */
4058 unsigned long Flags;
4062 case SK_DRV_ADAP_FAIL:
4063 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4064 ("ADAPTER FAIL EVENT\n"));
4065 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4066 /* disable interrupts */
4067 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4070 case SK_DRV_PORT_FAIL:
4071 FromPort = Param.Para32[0];
4072 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4073 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4074 if (FromPort == 0) {
4075 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4077 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4081 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4083 FromPort = Param.Para32[0];
4084 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4085 ("PORT RESET EVENT, Port: %d ", FromPort));
4086 NewPara.Para64 = FromPort;
4087 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4089 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4092 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4093 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4094 spin_unlock_irqrestore(
4095 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4098 /* clear rx ring from received frames */
4099 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4101 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4103 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4106 /* tschilling: Handling of return value inserted. */
4107 if (SkGeInitPort(pAC, IoC, FromPort)) {
4108 if (FromPort == 0) {
4109 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4111 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4114 SkAddrMcUpdate(pAC,IoC, FromPort);
4115 PortReInitBmu(pAC, FromPort);
4116 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4117 ClearAndStartRx(pAC, FromPort);
4118 spin_unlock_irqrestore(
4119 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4122 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4123 { struct net_device *dev = pAC->dev[Param.Para32[0]];
4125 FromPort = Param.Para32[0];
4126 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4127 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4129 SkAddrMcUpdate(pAC,IoC, FromPort);
4131 if (DoPrintInterfaceChange) {
4132 printk("%s: network connection up using"
4133 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4135 /* tschilling: Values changed according to LinkSpeedUsed. */
4136 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4137 if (Stat == SK_LSPEED_STAT_10MBPS) {
4138 printk(" speed: 10\n");
4139 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4140 printk(" speed: 100\n");
4141 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4142 printk(" speed: 1000\n");
4144 printk(" speed: unknown\n");
4148 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4149 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4150 Stat == SK_LMODE_STAT_AUTOFULL) {
4151 printk(" autonegotiation: yes\n");
4154 printk(" autonegotiation: no\n");
4156 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4157 Stat == SK_LMODE_STAT_HALF) {
4158 printk(" duplex mode: half\n");
4161 printk(" duplex mode: full\n");
4163 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4164 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4165 printk(" flowctrl: remote send\n");
4167 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4168 printk(" flowctrl: local send\n");
4170 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4171 printk(" flowctrl: symmetric\n");
4174 printk(" flowctrl: none\n");
4177 /* tschilling: Check against CopperType now. */
4178 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4179 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4180 SK_LSPEED_STAT_1000MBPS)) {
4181 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4182 if (Stat == SK_MS_STAT_MASTER ) {
4183 printk(" role: master\n");
4185 else if (Stat == SK_MS_STAT_SLAVE ) {
4186 printk(" role: slave\n");
4189 printk(" role: ???\n");
4194 Display dim (dynamic interrupt moderation)
4197 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4198 printk(" irq moderation: static (%d ints/sec)\n",
4199 pAC->DynIrqModInfo.MaxModIntsPerSec);
4200 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4201 printk(" irq moderation: dynamic (%d ints/sec)\n",
4202 pAC->DynIrqModInfo.MaxModIntsPerSec);
4204 printk(" irq moderation: disabled\n");
4207 printk(" scatter-gather: %s\n",
4208 (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4209 printk(" tx-checksum: %s\n",
4210 (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4211 printk(" rx-checksum: %s\n",
4212 pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4215 DoPrintInterfaceChange = SK_TRUE;
4218 if ((Param.Para32[0] != pAC->ActivePort) &&
4219 (pAC->RlmtNets == 1)) {
4220 NewPara.Para32[0] = pAC->ActivePort;
4221 NewPara.Para32[1] = Param.Para32[0];
4222 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4226 /* Inform the world that link protocol is up. */
4227 netif_carrier_on(dev);
4230 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4232 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4233 ("NET DOWN EVENT "));
4234 if (DoPrintInterfaceChange) {
4235 printk("%s: network connection down\n",
4236 pAC->dev[Param.Para32[1]]->name);
4238 DoPrintInterfaceChange = SK_TRUE;
4240 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4242 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4243 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4244 ("PORT SWITCH HARD "));
4245 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4247 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4248 'A'+Param.Para32[1]);
4249 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4250 FromPort = Param.Para32[0];
4251 ToPort = Param.Para32[1];
4252 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4253 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4254 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4255 NewPara.Para64 = FromPort;
4256 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4257 NewPara.Para64 = ToPort;
4258 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4260 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4262 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4263 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4264 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4265 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4266 spin_unlock_irqrestore(
4267 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4270 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4271 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4273 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4274 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4276 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4278 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4279 pAC->ActivePort = ToPort;
4283 /* tschilling: New common function with minimum size check. */
4285 if (pAC->RlmtNets == 2) {
4289 if (SkGeInitAssignRamToQueues(
4293 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4294 spin_unlock_irqrestore(
4295 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4297 printk("SkGeInitAssignRamToQueues failed.\n");
4301 /* tschilling: Handling of return values inserted. */
4302 if (SkGeInitPort(pAC, IoC, FromPort) ||
4303 SkGeInitPort(pAC, IoC, ToPort)) {
4304 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4306 if (Event == SK_DRV_SWITCH_SOFT) {
4307 SkMacRxTxEnable(pAC, IoC, FromPort);
4309 SkMacRxTxEnable(pAC, IoC, ToPort);
4310 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4311 SkAddrMcUpdate(pAC, IoC, FromPort);
4312 SkAddrMcUpdate(pAC, IoC, ToPort);
4313 PortReInitBmu(pAC, FromPort);
4314 PortReInitBmu(pAC, ToPort);
4315 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4316 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4317 ClearAndStartRx(pAC, FromPort);
4318 ClearAndStartRx(pAC, ToPort);
4319 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4320 spin_unlock_irqrestore(
4321 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4324 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4325 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4327 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4328 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4329 skb_put(pMsg, pRlmtMbuf->Length);
4330 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4333 DEV_KFREE_SKB_ANY(pMsg);
4336 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4338 ** expiration of the moderation timer implies that
4339 ** dynamic moderation is to be applied
4341 SkDimStartModerationTimer(pAC);
4343 if (pAC->DynIrqModInfo.DisplayStats) {
4344 SkDimDisplayModerationSettings(pAC);
4346 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4348 ** check if we need to check for descriptors which
4349 ** haven't been handled the last millisecs
4351 StartDrvCleanupTimer(pAC);
4352 if (pAC->GIni.GIMacsFound == 2) {
4353 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4355 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4357 printk("Expiration of unknown timer\n");
4363 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4370 /*****************************************************************************
4372 * SkErrorLog - log errors
4375 * This function logs errors to the system buffer and to the console
4378 * 0 if everything ok
4391 case SK_ERRCL_OTHER:
4392 strcpy(ClassStr, "Other error");
4394 case SK_ERRCL_CONFIG:
4395 strcpy(ClassStr, "Configuration error");
4398 strcpy(ClassStr, "Initialization error");
4400 case SK_ERRCL_NORES:
4401 strcpy(ClassStr, "Out of resources error");
4404 strcpy(ClassStr, "internal Software error");
4407 strcpy(ClassStr, "Hardware failure");
4410 strcpy(ClassStr, "Communication error");
4413 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4414 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4415 ClassStr, ErrNum, pErrorMsg);
4419 #ifdef SK_DIAG_SUPPORT
4421 /*****************************************************************************
4423 * SkDrvEnterDiagMode - handles DIAG attach request
4426 * Notify the kernel to NOT access the card any longer due to DIAG
4427 * Deinitialize the Card
4432 int SkDrvEnterDiagMode(
4433 SK_AC *pAc) /* pointer to adapter context */
4435 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4436 SK_AC *pAC = pNet->pAC;
4438 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4439 sizeof(SK_PNMI_STRUCT_DATA));
4441 pAC->DiagModeActive = DIAG_ACTIVE;
4442 if (pAC->BoardLevel > SK_INIT_DATA) {
4443 if (netif_running(pAC->dev[0])) {
4444 pAC->WasIfUp[0] = SK_TRUE;
4445 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4446 DoPrintInterfaceChange = SK_FALSE;
4447 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4449 pAC->WasIfUp[0] = SK_FALSE;
4451 if (pNet != netdev_priv(pAC->dev[1])) {
4452 pNet = netdev_priv(pAC->dev[1]);
4453 if (netif_running(pAC->dev[1])) {
4454 pAC->WasIfUp[1] = SK_TRUE;
4455 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4456 DoPrintInterfaceChange = SK_FALSE;
4457 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4459 pAC->WasIfUp[1] = SK_FALSE;
4462 pAC->BoardLevel = SK_INIT_DATA;
4467 /*****************************************************************************
4469 * SkDrvLeaveDiagMode - handles DIAG detach request
4472 * Notify the kernel to may access the card again after use by DIAG
4473 * Initialize the Card
4478 int SkDrvLeaveDiagMode(
4479 SK_AC *pAc) /* pointer to adapter control context */
4481 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4482 sizeof(SK_PNMI_STRUCT_DATA));
4483 pAc->DiagModeActive = DIAG_NOTACTIVE;
4484 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4485 if (pAc->WasIfUp[0] == SK_TRUE) {
4486 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4487 DoPrintInterfaceChange = SK_FALSE;
4488 SkDrvInitAdapter(pAc, 0); /* first device */
4490 if (pAc->WasIfUp[1] == SK_TRUE) {
4491 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4492 DoPrintInterfaceChange = SK_FALSE;
4493 SkDrvInitAdapter(pAc, 1); /* second device */
4498 /*****************************************************************************
4500 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4503 * This function parses the PCI slot name information string and will
4504 * retrieve the devcie number out of it. The slot_name maintianed by
4505 * linux is in the form of '02:0a.0', whereas the first two characters
4506 * represent the bus number in hex (in the sample above this is
4507 * pci bus 0x02) and the next two characters the device number (0x0a).
4510 * SK_U32: The device number from the PCI slot name
4513 static SK_U32 ParseDeviceNbrFromSlotName(
4514 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4516 char *CurrCharPos = (char *) SlotName;
4517 int FirstNibble = -1;
4518 int SecondNibble = -1;
4521 while (*CurrCharPos != '\0') {
4522 if (*CurrCharPos == ':') {
4523 while (*CurrCharPos != '.') {
4525 if ( (*CurrCharPos >= '0') &&
4526 (*CurrCharPos <= '9')) {
4527 if (FirstNibble == -1) {
4528 /* dec. value for '0' */
4529 FirstNibble = *CurrCharPos - 48;
4531 SecondNibble = *CurrCharPos - 48;
4533 } else if ( (*CurrCharPos >= 'a') &&
4534 (*CurrCharPos <= 'f') ) {
4535 if (FirstNibble == -1) {
4536 FirstNibble = *CurrCharPos - 87;
4538 SecondNibble = *CurrCharPos - 87;
4545 Result = FirstNibble;
4546 Result = Result << 4; /* first nibble is higher one */
4547 Result = Result | SecondNibble;
4549 CurrCharPos++; /* next character */
4554 /****************************************************************************
4556 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4557 * called if Diag attaches to that card)
4560 * Close initialized adapter.
4564 * error code - on error
4566 static int SkDrvDeInitAdapter(
4567 SK_AC *pAC, /* pointer to adapter context */
4568 int devNbr) /* what device is to be handled */
4570 struct SK_NET_DEVICE *dev;
4572 dev = pAC->dev[devNbr];
4574 /* On Linux 2.6 the network driver does NOT mess with reference
4575 ** counts. The driver MUST be able to be unloaded at any time
4576 ** due to the possibility of hotplug.
4578 if (SkGeClose(dev) != 0) {
4583 } /* SkDrvDeInitAdapter() */
4585 /****************************************************************************
4587 * SkDrvInitAdapter - Initialize adapter (this function is only
4588 * called if Diag deattaches from that card)
4591 * Close initialized adapter.
4595 * error code - on error
4597 static int SkDrvInitAdapter(
4598 SK_AC *pAC, /* pointer to adapter context */
4599 int devNbr) /* what device is to be handled */
4601 struct SK_NET_DEVICE *dev;
4603 dev = pAC->dev[devNbr];
4605 if (SkGeOpen(dev) != 0) {
4610 ** Use correct MTU size and indicate to kernel TX queue can be started
4612 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4617 } /* SkDrvInitAdapter */
4622 /****************************************************************************/
4623 /* "debug only" section *****************************************************/
4624 /****************************************************************************/
4627 /*****************************************************************************
4629 * DumpMsg - print a frame
4632 * This function prints frames to the system logfile/to the console.
4637 static void DumpMsg(struct sk_buff *skb, char *str)
4642 printk("DumpMsg(): NULL-Message\n");
4646 if (skb->data == NULL) {
4647 printk("DumpMsg(): Message empty\n");
4655 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4657 DumpData((char *)skb->data, msglen);
4659 printk("------- End of message ---------\n");
4664 /*****************************************************************************
4666 * DumpData - print a data area
4669 * This function prints a area of data to the system logfile/to the
4675 static void DumpData(char *p, int size)
4679 char hex_buffer[180];
4680 char asc_buffer[180];
4681 char HEXCHAR[] = "0123456789ABCDEF";
4687 for (i=0; i < size; ) {
4688 if (*p >= '0' && *p <='z')
4689 asc_buffer[addr] = *p;
4691 asc_buffer[addr] = '.';
4693 asc_buffer[addr] = 0;
4694 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4696 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4698 hex_buffer[haddr] = ' ';
4700 hex_buffer[haddr] = 0;
4704 printk("%s %s\n", hex_buffer, asc_buffer);
4712 /*****************************************************************************
4714 * DumpLong - print a data area as long values
4717 * This function prints a area of data to the system logfile/to the
4723 static void DumpLong(char *pc, int size)
4727 char hex_buffer[180];
4728 char asc_buffer[180];
4729 char HEXCHAR[] = "0123456789ABCDEF";
4738 for (i=0; i < size; ) {
4740 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4742 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4744 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4746 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4748 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4750 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4752 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4754 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4756 hex_buffer[haddr] = ' ';
4758 hex_buffer[haddr] = 0;
4762 printk("%4x %s\n", (i-8)*4, hex_buffer);
4766 printk("------------------------\n");
4771 static int __devinit skge_probe_one(struct pci_dev *pdev,
4772 const struct pci_device_id *ent)
4775 DEV_NET *pNet = NULL;
4776 struct net_device *dev = NULL;
4777 static int boards_found = 0;
4778 int error = -ENODEV;
4781 if (pci_enable_device(pdev))
4784 /* Configure DMA attributes. */
4785 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4786 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4787 goto out_disable_device;
4790 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4791 printk(KERN_ERR "Unable to allocate etherdev "
4793 goto out_disable_device;
4796 pNet = netdev_priv(dev);
4797 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4799 printk(KERN_ERR "Unable to allocate adapter "
4801 goto out_free_netdev;
4804 memset(pNet->pAC, 0, sizeof(SK_AC));
4810 pAC->CheckQueue = SK_FALSE;
4812 dev->irq = pdev->irq;
4813 error = SkGeInitPCI(pAC);
4815 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4816 goto out_free_netdev;
4819 SET_MODULE_OWNER(dev);
4820 dev->open = &SkGeOpen;
4821 dev->stop = &SkGeClose;
4822 dev->hard_start_xmit = &SkGeXmit;
4823 dev->get_stats = &SkGeStats;
4824 dev->set_multicast_list = &SkGeSetRxMode;
4825 dev->set_mac_address = &SkGeSetMacAddr;
4826 dev->do_ioctl = &SkGeIoctl;
4827 dev->change_mtu = &SkGeChangeMtu;
4828 #ifdef CONFIG_NET_POLL_CONTROLLER
4829 dev->poll_controller = &SkGePollController;
4831 SET_NETDEV_DEV(dev, &pdev->dev);
4832 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4834 /* Use only if yukon hardware */
4835 if (pAC->ChipsetType) {
4836 #ifdef USE_SK_TX_CHECKSUM
4837 dev->features |= NETIF_F_IP_CSUM;
4840 dev->features |= NETIF_F_SG;
4842 #ifdef USE_SK_RX_CHECKSUM
4843 pAC->RxPort[0].RxCsum = 1;
4847 pAC->Index = boards_found++;
4849 if (SkGeBoardInit(dev, pAC))
4850 goto out_free_netdev;
4852 /* Read Adapter name from VPD */
4853 if (ProductStr(pAC, DeviceStr, sizeof(DeviceStr)) != 0) {
4854 printk(KERN_ERR "sk98lin: Could not read VPD data.\n");
4855 goto out_free_resources;
4858 /* Register net device */
4859 if (register_netdev(dev)) {
4860 printk(KERN_ERR "sk98lin: Could not register device.\n");
4861 goto out_free_resources;
4864 /* Print adapter specific string from vpd */
4865 printk("%s: %s\n", dev->name, DeviceStr);
4867 /* Print configuration settings */
4868 printk(" PrefPort:%c RlmtMode:%s\n",
4869 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4870 (pAC->RlmtMode==0) ? "Check Link State" :
4871 ((pAC->RlmtMode==1) ? "Check Link State" :
4872 ((pAC->RlmtMode==3) ? "Check Local Port" :
4873 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4874 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4876 SkGeYellowLED(pAC, pAC->IoBase, 1);
4878 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4879 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4886 /* More then one port found */
4887 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4888 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4889 printk(KERN_ERR "Unable to allocate etherdev "
4895 pNet = netdev_priv(dev);
4900 dev->open = &SkGeOpen;
4901 dev->stop = &SkGeClose;
4902 dev->hard_start_xmit = &SkGeXmit;
4903 dev->get_stats = &SkGeStats;
4904 dev->set_multicast_list = &SkGeSetRxMode;
4905 dev->set_mac_address = &SkGeSetMacAddr;
4906 dev->do_ioctl = &SkGeIoctl;
4907 dev->change_mtu = &SkGeChangeMtu;
4908 SET_NETDEV_DEV(dev, &pdev->dev);
4909 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4911 if (pAC->ChipsetType) {
4912 #ifdef USE_SK_TX_CHECKSUM
4913 dev->features |= NETIF_F_IP_CSUM;
4916 dev->features |= NETIF_F_SG;
4918 #ifdef USE_SK_RX_CHECKSUM
4919 pAC->RxPort[1].RxCsum = 1;
4923 if (register_netdev(dev)) {
4924 printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4926 pAC->dev[1] = pAC->dev[0];
4928 memcpy(&dev->dev_addr,
4929 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4930 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4932 printk("%s: %s\n", dev->name, DeviceStr);
4933 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4937 /* Save the hardware revision */
4938 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4939 (pAC->GIni.GIPciHwRev & 0x0F);
4941 /* Set driver globals */
4942 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4943 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4945 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4946 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4948 pci_set_drvdata(pdev, dev);
4956 pci_disable_device(pdev);
4961 static void __devexit skge_remove_one(struct pci_dev *pdev)
4963 struct net_device *dev = pci_get_drvdata(pdev);
4964 DEV_NET *pNet = netdev_priv(dev);
4965 SK_AC *pAC = pNet->pAC;
4966 struct net_device *otherdev = pAC->dev[1];
4968 unregister_netdev(dev);
4970 SkGeYellowLED(pAC, pAC->IoBase, 0);
4972 if (pAC->BoardLevel == SK_INIT_RUN) {
4974 unsigned long Flags;
4976 /* board is still alive */
4977 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
4978 EvPara.Para32[0] = 0;
4979 EvPara.Para32[1] = -1;
4980 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
4981 EvPara.Para32[0] = 1;
4982 EvPara.Para32[1] = -1;
4983 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
4984 SkEventDispatcher(pAC, pAC->IoBase);
4985 /* disable interrupts */
4986 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4987 SkGeDeInit(pAC, pAC->IoBase);
4988 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
4989 pAC->BoardLevel = SK_INIT_DATA;
4990 /* We do NOT check here, if IRQ was pending, of course*/
4993 if (pAC->BoardLevel == SK_INIT_IO) {
4994 /* board is still alive */
4995 SkGeDeInit(pAC, pAC->IoBase);
4996 pAC->BoardLevel = SK_INIT_DATA;
5001 if (otherdev != dev)
5002 free_netdev(otherdev);
5007 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5009 struct net_device *dev = pci_get_drvdata(pdev);
5010 DEV_NET *pNet = netdev_priv(dev);
5011 SK_AC *pAC = pNet->pAC;
5012 struct net_device *otherdev = pAC->dev[1];
5014 if (netif_running(dev)) {
5015 netif_carrier_off(dev);
5016 DoPrintInterfaceChange = SK_FALSE;
5017 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5018 netif_device_detach(dev);
5020 if (otherdev != dev) {
5021 if (netif_running(otherdev)) {
5022 netif_carrier_off(otherdev);
5023 DoPrintInterfaceChange = SK_FALSE;
5024 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5025 netif_device_detach(otherdev);
5029 pci_save_state(pdev);
5030 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5031 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5032 free_irq(dev->irq, dev);
5034 pci_disable_device(pdev);
5035 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5040 static int skge_resume(struct pci_dev *pdev)
5042 struct net_device *dev = pci_get_drvdata(pdev);
5043 DEV_NET *pNet = netdev_priv(dev);
5044 SK_AC *pAC = pNet->pAC;
5045 struct net_device *otherdev = pAC->dev[1];
5048 pci_set_power_state(pdev, PCI_D0);
5049 pci_restore_state(pdev);
5050 pci_enable_device(pdev);
5051 pci_set_master(pdev);
5052 if (pAC->GIni.GIMacsFound == 2)
5053 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
5055 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, "sk98lin", dev);
5057 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5058 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5060 pci_disable_device(pdev);
5064 netif_device_attach(dev);
5065 if (netif_running(dev)) {
5066 DoPrintInterfaceChange = SK_FALSE;
5067 SkDrvInitAdapter(pAC, 0); /* first device */
5069 if (otherdev != dev) {
5070 netif_device_attach(otherdev);
5071 if (netif_running(otherdev)) {
5072 DoPrintInterfaceChange = SK_FALSE;
5073 SkDrvInitAdapter(pAC, 1); /* second device */
5080 #define skge_suspend NULL
5081 #define skge_resume NULL
5084 static struct pci_device_id skge_pci_tbl[] = {
5085 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5086 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5087 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5088 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5089 /* DLink card does not have valid VPD so this driver gags
5090 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5092 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5093 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5094 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5095 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5096 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5100 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5102 static struct pci_driver skge_driver = {
5104 .id_table = skge_pci_tbl,
5105 .probe = skge_probe_one,
5106 .remove = __devexit_p(skge_remove_one),
5107 .suspend = skge_suspend,
5108 .resume = skge_resume,
5111 static int __init skge_init(void)
5113 return pci_module_init(&skge_driver);
5116 static void __exit skge_exit(void)
5118 pci_unregister_driver(&skge_driver);
5121 module_init(skge_init);
5122 module_exit(skge_exit);