1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.45 $
6 * Date: $Date: 2004/02/12 14:41:02 $
7 * Purpose: The main driver source module
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
19 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
20 * SysKonnects GEnesis Solaris driver
21 * Author: Christoph Goos (cgoos@syskonnect.de)
22 * Mirko Lindner (mlindner@syskonnect.de)
24 * Address all question to: linux@syskonnect.de
26 * The technical manual for the adapters is available from SysKonnect's
27 * web pages: www.syskonnect.com
28 * Goto "Support" and search Knowledge Base for "manual".
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * The information in this file is provided "AS IS" without warranty.
37 ******************************************************************************/
39 /******************************************************************************
41 * Possible compiler options (#define xxx / -Dxxx):
43 * debugging can be enable by changing SK_DEBUG_CHKMOD and
44 * SK_DEBUG_CHKCAT in makefile (described there).
46 ******************************************************************************/
48 /******************************************************************************
52 * This is the main module of the Linux GE driver.
54 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
55 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
56 * Those are used for drivers on multiple OS', so some thing may seem
57 * unnecessary complicated on Linux. Please do not try to 'clean up'
58 * them without VERY good reasons, because this will make it more
59 * difficult to keep the Linux driver in synchronisation with the
62 * Include file hierarchy:
79 * <linux/etherdevice.h>
81 * those three depending on kernel version used:
106 ******************************************************************************/
108 #include "h/skversion.h"
110 #include <linux/module.h>
111 #include <linux/moduleparam.h>
112 #include <linux/init.h>
113 #include <linux/proc_fs.h>
114 #include <linux/dma-mapping.h>
115 #include <linux/ip.h>
117 #include "h/skdrv1st.h"
118 #include "h/skdrv2nd.h"
120 /*******************************************************************************
124 ******************************************************************************/
126 /* for debuging on x86 only */
127 /* #define BREAKPOINT() asm(" int $3"); */
129 /* use the transmit hw checksum driver functionality */
130 #define USE_SK_TX_CHECKSUM
132 /* use the receive hw checksum driver functionality */
133 #define USE_SK_RX_CHECKSUM
135 /* use the scatter-gather functionality with sendfile() */
138 /* use of a transmit complete interrupt */
139 #define USE_TX_COMPLETE
142 * threshold for copying small receive frames
143 * set to 0 to avoid copying, set to 9001 to copy all frames
145 #define SK_COPY_THRESHOLD 50
147 /* number of adapters that can be configured via command line params */
148 #define SK_MAX_CARD_PARAM 16
153 * use those defines for a compile-in version of the driver instead
154 * of command line parameters
156 // #define LINK_SPEED_A {"Auto", }
157 // #define LINK_SPEED_B {"Auto", }
158 // #define AUTO_NEG_A {"Sense", }
159 // #define AUTO_NEG_B {"Sense", }
160 // #define DUP_CAP_A {"Both", }
161 // #define DUP_CAP_B {"Both", }
162 // #define FLOW_CTRL_A {"SymOrRem", }
163 // #define FLOW_CTRL_B {"SymOrRem", }
164 // #define ROLE_A {"Auto", }
165 // #define ROLE_B {"Auto", }
166 // #define PREF_PORT {"A", }
167 // #define CON_TYPE {"Auto", }
168 // #define RLMT_MODE {"CheckLinkState", }
170 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
171 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
172 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
176 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
177 SK_DUP_LED_NORMAL | \
181 /* Isr return value */
182 #define SkIsrRetVar irqreturn_t
183 #define SkIsrRetNone IRQ_NONE
184 #define SkIsrRetHandled IRQ_HANDLED
187 /*******************************************************************************
189 * Local Function Prototypes
191 ******************************************************************************/
193 static void FreeResources(struct SK_NET_DEVICE *dev);
194 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
195 static SK_BOOL BoardAllocMem(SK_AC *pAC);
196 static void BoardFreeMem(SK_AC *pAC);
197 static void BoardInitMem(SK_AC *pAC);
198 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
199 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
200 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
201 static int SkGeOpen(struct SK_NET_DEVICE *dev);
202 static int SkGeClose(struct SK_NET_DEVICE *dev);
203 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
204 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
205 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
206 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
207 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
208 static void GetConfiguration(SK_AC*);
209 static void ProductStr(SK_AC*);
210 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
211 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
212 static void FillRxRing(SK_AC*, RX_PORT*);
213 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
214 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
215 static void ClearAndStartRx(SK_AC*, int);
216 static void ClearTxIrq(SK_AC*, int, int);
217 static void ClearRxRing(SK_AC*, RX_PORT*);
218 static void ClearTxRing(SK_AC*, TX_PORT*);
219 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
220 static void PortReInitBmu(SK_AC*, int);
221 static int SkGeIocMib(DEV_NET*, unsigned int, int);
222 static int SkGeInitPCI(SK_AC *pAC);
223 static void StartDrvCleanupTimer(SK_AC *pAC);
224 static void StopDrvCleanupTimer(SK_AC *pAC);
225 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
227 #ifdef SK_DIAG_SUPPORT
228 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
229 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
230 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
233 /*******************************************************************************
235 * Extern Function Prototypes
237 ******************************************************************************/
238 static const char SKRootName[] = "net/sk98lin";
239 static struct proc_dir_entry *pSkRootDir;
240 extern struct file_operations sk_proc_fops;
242 static inline void SkGeProcCreate(struct net_device *dev)
244 struct proc_dir_entry *pe;
247 (pe = create_proc_entry(dev->name, S_IRUGO, pSkRootDir))) {
248 pe->proc_fops = &sk_proc_fops;
250 pe->owner = THIS_MODULE;
254 static inline void SkGeProcRemove(struct net_device *dev)
257 remove_proc_entry(dev->name, pSkRootDir);
260 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
261 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
262 extern void SkDimStartModerationTimer(SK_AC *pAC);
263 extern void SkDimModerate(SK_AC *pAC);
264 extern void SkGeBlinkTimer(unsigned long data);
267 static void DumpMsg(struct sk_buff*, char*);
268 static void DumpData(char*, int);
269 static void DumpLong(char*, int);
272 /* global variables *********************************************************/
273 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
274 extern struct ethtool_ops SkGeEthtoolOps;
276 /* local variables **********************************************************/
277 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
278 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
280 /*****************************************************************************
282 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
285 * This routine writes a 32 bit value to the pci configuration
289 * 0 - indicate everything worked ok.
290 * != 0 - error indication
292 static inline int SkPciWriteCfgDWord(
293 SK_AC *pAC, /* Adapter Control structure pointer */
294 int PciAddr, /* PCI register address */
295 SK_U32 Val) /* pointer to store the read value */
297 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
299 } /* SkPciWriteCfgDWord */
301 /*****************************************************************************
303 * SkGeInitPCI - Init the PCI resources
306 * This function initialize the PCI resources and IO
311 int SkGeInitPCI(SK_AC *pAC)
313 struct SK_NET_DEVICE *dev = pAC->dev[0];
314 struct pci_dev *pdev = pAC->PciDev;
317 if (pci_enable_device(pdev) != 0) {
321 dev->mem_start = pci_resource_start (pdev, 0);
322 pci_set_master(pdev);
324 if (pci_request_regions(pdev, pAC->Name) != 0) {
331 * On big endian machines, we use the adapter's aibility of
332 * reading the descriptors as big endian.
336 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
337 our2 |= PCI_REV_DESC;
338 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
343 * Remap the regs into kernel space.
345 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
355 pci_release_regions(pdev);
357 pci_disable_device(pdev);
362 /*****************************************************************************
364 * FreeResources - release resources allocated for adapter
367 * This function releases the IRQ, unmaps the IO and
368 * frees the desriptor ring.
373 static void FreeResources(struct SK_NET_DEVICE *dev)
379 pNet = netdev_priv(dev);
381 AllocFlag = pAC->AllocFlag;
383 pci_release_regions(pAC->PciDev);
385 if (AllocFlag & SK_ALLOC_IRQ) {
386 free_irq(dev->irq, dev);
389 iounmap(pAC->IoBase);
391 if (pAC->pDescrMem) {
395 } /* FreeResources */
397 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
398 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
399 MODULE_LICENSE("GPL");
402 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
404 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
408 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
410 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
414 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
416 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
420 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
422 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
426 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
428 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
432 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
434 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
438 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
440 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
444 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
446 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
450 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
452 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
456 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
458 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
462 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
464 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
468 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
470 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
474 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
476 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
479 static int IntsPerSec[SK_MAX_CARD_PARAM];
480 static char *Moderation[SK_MAX_CARD_PARAM];
481 static char *ModerationMask[SK_MAX_CARD_PARAM];
482 static char *AutoSizing[SK_MAX_CARD_PARAM];
483 static char *Stats[SK_MAX_CARD_PARAM];
485 module_param_array(Speed_A, charp, NULL, 0);
486 module_param_array(Speed_B, charp, NULL, 0);
487 module_param_array(AutoNeg_A, charp, NULL, 0);
488 module_param_array(AutoNeg_B, charp, NULL, 0);
489 module_param_array(DupCap_A, charp, NULL, 0);
490 module_param_array(DupCap_B, charp, NULL, 0);
491 module_param_array(FlowCtrl_A, charp, NULL, 0);
492 module_param_array(FlowCtrl_B, charp, NULL, 0);
493 module_param_array(Role_A, charp, NULL, 0);
494 module_param_array(Role_B, charp, NULL, 0);
495 module_param_array(ConType, charp, NULL, 0);
496 module_param_array(PrefPort, charp, NULL, 0);
497 module_param_array(RlmtMode, charp, NULL, 0);
498 /* used for interrupt moderation */
499 module_param_array(IntsPerSec, int, NULL, 0);
500 module_param_array(Moderation, charp, NULL, 0);
501 module_param_array(Stats, charp, NULL, 0);
502 module_param_array(ModerationMask, charp, NULL, 0);
503 module_param_array(AutoSizing, charp, NULL, 0);
505 /*****************************************************************************
507 * SkGeBoardInit - do level 0 and 1 initialization
510 * This function prepares the board hardware for running. The desriptor
511 * ring is set up, the IRQ is allocated and the configuration settings
515 * 0, if everything is ok
518 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
522 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
523 char *VerStr = VER_STRING;
524 int Ret; /* return code of request_irq */
527 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
528 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
529 for (i=0; i<SK_MAX_MACS; i++) {
530 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
531 pAC->TxPort[i][0].PortIndex = i;
532 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
533 pAC->RxPort[i].PortIndex = i;
536 /* Initialize the mutexes */
537 for (i=0; i<SK_MAX_MACS; i++) {
538 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
539 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
541 spin_lock_init(&pAC->SlowPathLock);
543 /* setup phy_id blink timer */
544 pAC->BlinkTimer.function = SkGeBlinkTimer;
545 pAC->BlinkTimer.data = (unsigned long) dev;
546 init_timer(&pAC->BlinkTimer);
548 /* level 0 init common modules here */
550 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
551 /* Does a RESET on board ...*/
552 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
553 printk("HWInit (0) failed.\n");
554 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
557 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
558 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
559 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
560 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
561 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
562 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
564 pAC->BoardLevel = SK_INIT_DATA;
565 pAC->RxBufSize = ETH_BUF_SIZE;
567 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
568 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
570 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
572 /* level 1 init common modules here (HW init) */
573 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
574 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
575 printk("sk98lin: HWInit (1) failed.\n");
576 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
579 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
580 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
581 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
582 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
583 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
584 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
586 /* Set chipset type support */
587 pAC->ChipsetType = 0;
588 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
589 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
590 pAC->ChipsetType = 1;
593 GetConfiguration(pAC);
594 if (pAC->RlmtNets == 2) {
595 pAC->GIni.GIPortUsage = SK_MUL_LINK;
598 pAC->BoardLevel = SK_INIT_IO;
599 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
601 if (pAC->GIni.GIMacsFound == 2) {
602 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
603 } else if (pAC->GIni.GIMacsFound == 1) {
604 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
607 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
608 pAC->GIni.GIMacsFound);
613 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
617 pAC->AllocFlag |= SK_ALLOC_IRQ;
619 /* Alloc memory for this board (Mem for RxD/TxD) : */
620 if(!BoardAllocMem(pAC)) {
621 printk("No memory for descriptor rings.\n");
626 /* tschilling: New common function with minimum size check. */
628 if (pAC->RlmtNets == 2) {
632 if (SkGeInitAssignRamToQueues(
637 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
642 } /* SkGeBoardInit */
645 /*****************************************************************************
647 * BoardAllocMem - allocate the memory for the descriptor rings
650 * This function allocates the memory for all descriptor rings.
651 * Each ring is aligned for the desriptor alignment and no ring
652 * has a 4 GByte boundary in it (because the upper 32 bit must
653 * be constant for all descriptiors in one rings).
656 * SK_TRUE, if all memory could be allocated
659 static SK_BOOL BoardAllocMem(
662 caddr_t pDescrMem; /* pointer to descriptor memory area */
663 size_t AllocLength; /* length of complete descriptor area */
664 int i; /* loop counter */
665 unsigned long BusAddr;
668 /* rings plus one for alignment (do not cross 4 GB boundary) */
669 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
670 #if (BITS_PER_LONG == 32)
671 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
673 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
677 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
680 if (pDescrMem == NULL) {
683 pAC->pDescrMem = pDescrMem;
684 BusAddr = (unsigned long) pAC->pDescrMemDMA;
686 /* Descriptors need 8 byte alignment, and this is ensured
687 * by pci_alloc_consistent.
689 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
690 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
691 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
692 i, (unsigned long) pDescrMem,
694 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
695 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
696 pDescrMem += TX_RING_SIZE;
697 BusAddr += TX_RING_SIZE;
699 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
700 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
701 i, (unsigned long) pDescrMem,
702 (unsigned long)BusAddr));
703 pAC->RxPort[i].pRxDescrRing = pDescrMem;
704 pAC->RxPort[i].VRxDescrRing = BusAddr;
705 pDescrMem += RX_RING_SIZE;
706 BusAddr += RX_RING_SIZE;
710 } /* BoardAllocMem */
713 /****************************************************************************
715 * BoardFreeMem - reverse of BoardAllocMem
718 * Free all memory allocated in BoardAllocMem: adapter context,
719 * descriptor rings, locks.
723 static void BoardFreeMem(
726 size_t AllocLength; /* length of complete descriptor area */
728 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
730 #if (BITS_PER_LONG == 32)
731 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
733 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
737 pci_free_consistent(pAC->PciDev, AllocLength,
738 pAC->pDescrMem, pAC->pDescrMemDMA);
739 pAC->pDescrMem = NULL;
743 /*****************************************************************************
745 * BoardInitMem - initiate the descriptor rings
748 * This function sets the descriptor rings up in memory.
749 * The adapter is initialized with the descriptor start addresses.
753 static void BoardInitMem(
754 SK_AC *pAC) /* pointer to adapter context */
756 int i; /* loop counter */
757 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
758 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
760 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
763 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
764 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
765 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
766 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
768 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
771 pAC->TxPort[i][0].pTxDescrRing,
772 pAC->TxPort[i][0].VTxDescrRing,
773 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
774 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
775 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
776 &pAC->TxPort[i][0].TxdRingFree,
780 pAC->RxPort[i].pRxDescrRing,
781 pAC->RxPort[i].VRxDescrRing,
782 &pAC->RxPort[i].pRxdRingHead,
783 &pAC->RxPort[i].pRxdRingTail,
784 &pAC->RxPort[i].pRxdRingPrev,
785 &pAC->RxPort[i].RxdRingFree,
791 /*****************************************************************************
793 * SetupRing - create one descriptor ring
796 * This function creates one descriptor ring in the given memory area.
797 * The head, tail and number of free descriptors in the ring are set.
802 static void SetupRing(
804 void *pMemArea, /* a pointer to the memory area for the ring */
805 uintptr_t VMemArea, /* the virtual bus address of the memory area */
806 RXD **ppRingHead, /* address where the head should be written */
807 RXD **ppRingTail, /* address where the tail should be written */
808 RXD **ppRingPrev, /* address where the tail should be written */
809 int *pRingFree, /* address where the # of free descr. goes */
810 SK_BOOL IsTx) /* flag: is this a tx ring */
812 int i; /* loop counter */
813 int DescrSize; /* the size of a descriptor rounded up to alignment*/
814 int DescrNum; /* number of descriptors per ring */
815 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
816 RXD *pNextDescr; /* pointer to the next descriptor */
817 RXD *pPrevDescr; /* pointer to the previous descriptor */
818 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
820 if (IsTx == SK_TRUE) {
821 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
823 DescrNum = TX_RING_SIZE / DescrSize;
825 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
827 DescrNum = RX_RING_SIZE / DescrSize;
830 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
831 ("Descriptor size: %d Descriptor Number: %d\n",
832 DescrSize,DescrNum));
834 pDescr = (RXD*) pMemArea;
836 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
837 VNextDescr = VMemArea + DescrSize;
838 for(i=0; i<DescrNum; i++) {
839 /* set the pointers right */
840 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
841 pDescr->pNextRxd = pNextDescr;
842 pDescr->TcpSumStarts = 0;
844 /* advance one step */
847 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
848 VNextDescr += DescrSize;
850 pPrevDescr->pNextRxd = (RXD*) pMemArea;
851 pPrevDescr->VNextRxd = VMemArea;
852 pDescr = (RXD*) pMemArea;
853 *ppRingHead = (RXD*) pMemArea;
854 *ppRingTail = *ppRingHead;
855 *ppRingPrev = pPrevDescr;
856 *pRingFree = DescrNum;
860 /*****************************************************************************
862 * PortReInitBmu - re-initiate the descriptor rings for one port
865 * This function reinitializes the descriptor rings of one port
866 * in memory. The port must be stopped before.
867 * The HW is initialized with the descriptor start addresses.
872 static void PortReInitBmu(
873 SK_AC *pAC, /* pointer to adapter context */
874 int PortIndex) /* index of the port for which to re-init */
876 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
879 /* set address of first descriptor of ring in BMU */
880 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
881 (uint32_t)(((caddr_t)
882 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
883 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
884 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
886 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
887 (uint32_t)(((caddr_t)
888 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
889 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
890 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
891 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
892 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
893 pAC->RxPort[PortIndex].pRxDescrRing +
894 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
895 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
896 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
897 pAC->RxPort[PortIndex].pRxDescrRing +
898 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
899 } /* PortReInitBmu */
902 /****************************************************************************
904 * SkGeIsr - handle adapter interrupts
907 * The interrupt routine is called when the network adapter
908 * generates an interrupt. It may also be called if another device
909 * shares this interrupt vector with the driver.
914 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
916 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
919 SK_U32 IntSrc; /* interrupts source register contents */
921 pNet = netdev_priv(dev);
925 * Check and process if its our interrupt
927 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
932 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
933 #if 0 /* software irq currently not used */
934 if (IntSrc & IS_IRQ_SW) {
935 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
936 SK_DBGCAT_DRV_INT_SRC,
940 if (IntSrc & IS_R1_F) {
941 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
942 SK_DBGCAT_DRV_INT_SRC,
944 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
945 SK_PNMI_CNT_RX_INTR(pAC, 0);
947 if (IntSrc & IS_R2_F) {
948 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
949 SK_DBGCAT_DRV_INT_SRC,
951 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
952 SK_PNMI_CNT_RX_INTR(pAC, 1);
954 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
955 if (IntSrc & IS_XA1_F) {
956 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
957 SK_DBGCAT_DRV_INT_SRC,
958 ("EOF AS TX1 IRQ\n"));
959 SK_PNMI_CNT_TX_INTR(pAC, 0);
960 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
961 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
962 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
964 if (IntSrc & IS_XA2_F) {
965 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
966 SK_DBGCAT_DRV_INT_SRC,
967 ("EOF AS TX2 IRQ\n"));
968 SK_PNMI_CNT_TX_INTR(pAC, 1);
969 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
970 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
971 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
973 #if 0 /* only if sync. queues used */
974 if (IntSrc & IS_XS1_F) {
975 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
976 SK_DBGCAT_DRV_INT_SRC,
977 ("EOF SY TX1 IRQ\n"));
978 SK_PNMI_CNT_TX_INTR(pAC, 1);
979 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
980 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
981 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
982 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
984 if (IntSrc & IS_XS2_F) {
985 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
986 SK_DBGCAT_DRV_INT_SRC,
987 ("EOF SY TX2 IRQ\n"));
988 SK_PNMI_CNT_TX_INTR(pAC, 1);
989 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
990 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
991 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
992 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
997 /* do all IO at once */
998 if (IntSrc & IS_R1_F)
999 ClearAndStartRx(pAC, 0);
1000 if (IntSrc & IS_R2_F)
1001 ClearAndStartRx(pAC, 1);
1002 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1003 if (IntSrc & IS_XA1_F)
1004 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1005 if (IntSrc & IS_XA2_F)
1006 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1008 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1009 } /* while (IntSrc & IRQ_MASK != 0) */
1011 IntSrc &= pAC->GIni.GIValIrqMask;
1012 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1013 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1014 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1015 pAC->CheckQueue = SK_FALSE;
1016 spin_lock(&pAC->SlowPathLock);
1017 if (IntSrc & SPECIAL_IRQS)
1018 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1020 SkEventDispatcher(pAC, pAC->IoBase);
1021 spin_unlock(&pAC->SlowPathLock);
1024 * do it all again is case we cleared an interrupt that
1025 * came in after handling the ring (OUTs may be delayed
1026 * in hardware buffers, but are through after IN)
1028 * rroesler: has been commented out and shifted to
1029 * SkGeDrvEvent(), because it is timer
1032 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1033 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1036 if (pAC->CheckQueue) {
1037 pAC->CheckQueue = SK_FALSE;
1038 spin_lock(&pAC->SlowPathLock);
1039 SkEventDispatcher(pAC, pAC->IoBase);
1040 spin_unlock(&pAC->SlowPathLock);
1043 /* IRQ is processed - Enable IRQs again*/
1044 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1046 return SkIsrRetHandled;
1050 /****************************************************************************
1052 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1055 * The interrupt routine is called when the network adapter
1056 * generates an interrupt. It may also be called if another device
1057 * shares this interrupt vector with the driver.
1058 * This is the same as above, but handles only one port.
1063 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1065 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1068 SK_U32 IntSrc; /* interrupts source register contents */
1070 pNet = netdev_priv(dev);
1074 * Check and process if its our interrupt
1076 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1078 return SkIsrRetNone;
1081 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1082 #if 0 /* software irq currently not used */
1083 if (IntSrc & IS_IRQ_SW) {
1084 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1085 SK_DBGCAT_DRV_INT_SRC,
1086 ("Software IRQ\n"));
1089 if (IntSrc & IS_R1_F) {
1090 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1091 SK_DBGCAT_DRV_INT_SRC,
1093 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1094 SK_PNMI_CNT_RX_INTR(pAC, 0);
1096 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1097 if (IntSrc & IS_XA1_F) {
1098 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1099 SK_DBGCAT_DRV_INT_SRC,
1100 ("EOF AS TX1 IRQ\n"));
1101 SK_PNMI_CNT_TX_INTR(pAC, 0);
1102 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1103 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1104 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1106 #if 0 /* only if sync. queues used */
1107 if (IntSrc & IS_XS1_F) {
1108 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1109 SK_DBGCAT_DRV_INT_SRC,
1110 ("EOF SY TX1 IRQ\n"));
1111 SK_PNMI_CNT_TX_INTR(pAC, 0);
1112 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1113 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1114 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1115 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1120 /* do all IO at once */
1121 if (IntSrc & IS_R1_F)
1122 ClearAndStartRx(pAC, 0);
1123 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1124 if (IntSrc & IS_XA1_F)
1125 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1127 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1128 } /* while (IntSrc & IRQ_MASK != 0) */
1130 IntSrc &= pAC->GIni.GIValIrqMask;
1131 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1132 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1133 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1134 pAC->CheckQueue = SK_FALSE;
1135 spin_lock(&pAC->SlowPathLock);
1136 if (IntSrc & SPECIAL_IRQS)
1137 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1139 SkEventDispatcher(pAC, pAC->IoBase);
1140 spin_unlock(&pAC->SlowPathLock);
1143 * do it all again is case we cleared an interrupt that
1144 * came in after handling the ring (OUTs may be delayed
1145 * in hardware buffers, but are through after IN)
1147 * rroesler: has been commented out and shifted to
1148 * SkGeDrvEvent(), because it is timer
1151 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1154 /* IRQ is processed - Enable IRQs again*/
1155 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1157 return SkIsrRetHandled;
1158 } /* SkGeIsrOnePort */
1160 #ifdef CONFIG_NET_POLL_CONTROLLER
1161 /****************************************************************************
1163 * SkGePollController - polling receive, for netconsole
1166 * Polling receive - used by netconsole and other diagnostic tools
1167 * to allow network i/o with interrupts disabled.
1171 static void SkGePollController(struct net_device *dev)
1173 disable_irq(dev->irq);
1174 SkGeIsr(dev->irq, dev, NULL);
1175 enable_irq(dev->irq);
1179 /****************************************************************************
1181 * SkGeOpen - handle start of initialized adapter
1184 * This function starts the initialized adapter.
1185 * The board level variable is set and the adapter is
1186 * brought to full functionality.
1187 * The device flags are set for operation.
1188 * Do all necessary level 2 initialization, enable interrupts and
1189 * give start command to RLMT.
1195 static int SkGeOpen(
1196 struct SK_NET_DEVICE *dev)
1200 unsigned long Flags; /* for spin lock */
1202 SK_EVPARA EvPara; /* an event parameter union */
1204 pNet = netdev_priv(dev);
1207 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1208 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1210 #ifdef SK_DIAG_SUPPORT
1211 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1212 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1213 return (-1); /* still in use by diag; deny actions */
1218 /* Set blink mode */
1219 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1220 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1222 if (pAC->BoardLevel == SK_INIT_DATA) {
1223 /* level 1 init common modules here */
1224 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1225 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1228 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1229 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1230 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1231 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1232 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1233 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1234 pAC->BoardLevel = SK_INIT_IO;
1237 if (pAC->BoardLevel != SK_INIT_RUN) {
1238 /* tschilling: Level 2 init modules here, check return value. */
1239 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1240 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1243 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1244 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1245 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1246 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1247 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1248 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1249 pAC->BoardLevel = SK_INIT_RUN;
1252 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1253 /* Enable transmit descriptor polling. */
1254 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1255 FillRxRing(pAC, &pAC->RxPort[i]);
1257 SkGeYellowLED(pAC, pAC->IoBase, 1);
1259 StartDrvCleanupTimer(pAC);
1260 SkDimEnableModerationIfNeeded(pAC);
1261 SkDimDisplayModerationSettings(pAC);
1263 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1265 /* enable Interrupts */
1266 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1267 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1269 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1271 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1272 EvPara.Para32[0] = pAC->RlmtNets;
1273 EvPara.Para32[1] = -1;
1274 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1276 EvPara.Para32[0] = pAC->RlmtMode;
1277 EvPara.Para32[1] = 0;
1278 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1282 EvPara.Para32[0] = pNet->NetNr;
1283 EvPara.Para32[1] = -1;
1284 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1285 SkEventDispatcher(pAC, pAC->IoBase);
1286 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1292 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1293 ("SkGeOpen suceeded\n"));
1299 /****************************************************************************
1301 * SkGeClose - Stop initialized adapter
1304 * Close initialized adapter.
1308 * error code - on error
1310 static int SkGeClose(
1311 struct SK_NET_DEVICE *dev)
1317 unsigned long Flags; /* for spin lock */
1322 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1323 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1325 pNet = netdev_priv(dev);
1328 #ifdef SK_DIAG_SUPPORT
1329 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1330 if (pAC->DiagFlowCtrl == SK_FALSE) {
1332 ** notify that the interface which has been closed
1333 ** by operator interaction must not be started up
1334 ** again when the DIAG has finished.
1336 newPtrNet = netdev_priv(pAC->dev[0]);
1337 if (newPtrNet == pNet) {
1338 pAC->WasIfUp[0] = SK_FALSE;
1340 pAC->WasIfUp[1] = SK_FALSE;
1342 return 0; /* return to system everything is fine... */
1344 pAC->DiagFlowCtrl = SK_FALSE;
1349 netif_stop_queue(dev);
1351 if (pAC->RlmtNets == 1)
1352 PortIdx = pAC->ActivePort;
1354 PortIdx = pNet->NetNr;
1356 StopDrvCleanupTimer(pAC);
1359 * Clear multicast table, promiscuous mode ....
1361 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1362 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1365 if (pAC->MaxPorts == 1) {
1366 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1367 /* disable interrupts */
1368 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1369 EvPara.Para32[0] = pNet->NetNr;
1370 EvPara.Para32[1] = -1;
1371 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1372 SkEventDispatcher(pAC, pAC->IoBase);
1373 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1374 /* stop the hardware */
1375 SkGeDeInit(pAC, pAC->IoBase);
1376 pAC->BoardLevel = SK_INIT_DATA;
1377 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1380 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1381 EvPara.Para32[0] = pNet->NetNr;
1382 EvPara.Para32[1] = -1;
1383 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1384 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1385 SkEventDispatcher(pAC, pAC->IoBase);
1386 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1389 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1390 [TX_PRIO_LOW].TxDesRingLock, Flags);
1391 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1392 SK_STOP_ALL, SK_HARD_RST);
1393 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1394 [TX_PRIO_LOW].TxDesRingLock, Flags);
1397 if (pAC->RlmtNets == 1) {
1398 /* clear all descriptor rings */
1399 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1400 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1401 ClearRxRing(pAC, &pAC->RxPort[i]);
1402 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1405 /* clear port descriptor rings */
1406 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1407 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1408 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1411 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1412 ("SkGeClose: done "));
1414 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1415 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1416 sizeof(SK_PNMI_STRUCT_DATA));
1425 /*****************************************************************************
1427 * SkGeXmit - Linux frame transmit function
1430 * The system calls this function to send frames onto the wire.
1431 * It puts the frame in the tx descriptor ring. If the ring is
1432 * full then, the 'tbusy' flag is set.
1435 * 0, if everything is ok
1437 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1438 * allocated skb's) !!!
1440 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1444 int Rc; /* return code of XmitFrame */
1446 pNet = netdev_priv(dev);
1449 if ((!skb_shinfo(skb)->nr_frags) ||
1450 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1451 /* Don't activate scatter-gather and hardware checksum */
1453 if (pAC->RlmtNets == 2)
1456 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1461 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1464 /* scatter-gather and hardware TCP checksumming anabled*/
1465 if (pAC->RlmtNets == 2)
1468 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1473 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1477 /* Transmitter out of resources? */
1479 netif_stop_queue(dev);
1482 /* If not taken, give buffer ownership back to the
1488 dev->trans_start = jiffies;
1493 /*****************************************************************************
1495 * XmitFrame - fill one socket buffer into the transmit ring
1498 * This function puts a message into the transmit descriptor ring
1499 * if there is a descriptors left.
1500 * Linux skb's consist of only one continuous buffer.
1501 * The first step locks the ring. It is held locked
1502 * all time to avoid problems with SWITCH_../PORT_RESET.
1503 * Then the descriptoris allocated.
1504 * The second part is linking the buffer to the descriptor.
1505 * At the very last, the Control field of the descriptor
1506 * is made valid for the BMU and a start TX command is given
1510 * > 0 - on succes: the number of bytes in the message
1511 * = 0 - on resource shortage: this frame sent or dropped, now
1512 * the ring is full ( -> set tbusy)
1513 * < 0 - on failure: other problems ( -> return failure to upper layers)
1515 static int XmitFrame(
1516 SK_AC *pAC, /* pointer to adapter context */
1517 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1518 struct sk_buff *pMessage) /* pointer to send-message */
1520 TXD *pTxd; /* the rxd to fill */
1522 unsigned long Flags;
1524 int BytesSend = pMessage->len;
1526 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1528 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1529 #ifndef USE_TX_COMPLETE
1530 FreeTxDescriptors(pAC, pTxPort);
1532 if (pTxPort->TxdRingFree == 0) {
1534 ** no enough free descriptors in ring at the moment.
1535 ** Maybe free'ing some old one help?
1537 FreeTxDescriptors(pAC, pTxPort);
1538 if (pTxPort->TxdRingFree == 0) {
1539 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1540 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1541 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1542 SK_DBGCAT_DRV_TX_PROGRESS,
1543 ("XmitFrame failed\n"));
1545 ** the desired message can not be sent
1546 ** Because tbusy seems to be set, the message
1547 ** should not be freed here. It will be used
1548 ** by the scheduler of the ethernet handler
1555 ** If the passed socket buffer is of smaller MTU-size than 60,
1556 ** copy everything into new buffer and fill all bytes between
1557 ** the original packet end and the new packet end of 60 with 0x00.
1558 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1560 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1561 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1562 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1565 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1569 ** advance head counter behind descriptor needed for this frame,
1570 ** so that needed descriptor is reserved from that on. The next
1571 ** action will be to add the passed buffer to the TX-descriptor
1573 pTxd = pTxPort->pTxdRingHead;
1574 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1575 pTxPort->TxdRingFree--;
1578 DumpMsg(pMessage, "XmitFrame");
1582 ** First step is to map the data to be sent via the adapter onto
1583 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1584 ** and 2.6 need to use pci_map_page() for that mapping.
1586 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1587 virt_to_page(pMessage->data),
1588 ((unsigned long) pMessage->data & ~PAGE_MASK),
1591 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1592 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1593 pTxd->pMBuf = pMessage;
1595 if (pMessage->ip_summed == CHECKSUM_HW) {
1596 u16 hdrlen = pMessage->h.raw - pMessage->data;
1597 u16 offset = hdrlen + pMessage->csum;
1599 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1600 (pAC->GIni.GIChipRev == 0) &&
1601 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1602 pTxd->TBControl = BMU_TCP_CHECK;
1604 pTxd->TBControl = BMU_UDP_CHECK;
1607 pTxd->TcpSumOfs = 0;
1608 pTxd->TcpSumSt = hdrlen;
1609 pTxd->TcpSumWr = offset;
1611 pTxd->TBControl |= BMU_OWN | BMU_STF |
1613 #ifdef USE_TX_COMPLETE
1618 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1620 #ifdef USE_TX_COMPLETE
1627 ** If previous descriptor already done, give TX start cmd
1629 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1630 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1631 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1635 ** after releasing the lock, the skb may immediately be free'd
1637 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1638 if (pTxPort->TxdRingFree != 0) {
1646 /*****************************************************************************
1648 * XmitFrameSG - fill one socket buffer into the transmit ring
1649 * (use SG and TCP/UDP hardware checksumming)
1652 * This function puts a message into the transmit descriptor ring
1653 * if there is a descriptors left.
1656 * > 0 - on succes: the number of bytes in the message
1657 * = 0 - on resource shortage: this frame sent or dropped, now
1658 * the ring is full ( -> set tbusy)
1659 * < 0 - on failure: other problems ( -> return failure to upper layers)
1661 static int XmitFrameSG(
1662 SK_AC *pAC, /* pointer to adapter context */
1663 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1664 struct sk_buff *pMessage) /* pointer to send-message */
1672 skb_frag_t *sk_frag;
1674 unsigned long Flags;
1677 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1678 #ifndef USE_TX_COMPLETE
1679 FreeTxDescriptors(pAC, pTxPort);
1681 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1682 FreeTxDescriptors(pAC, pTxPort);
1683 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1684 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1685 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1686 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1687 SK_DBGCAT_DRV_TX_PROGRESS,
1688 ("XmitFrameSG failed - Ring full\n"));
1689 /* this message can not be sent now */
1694 pTxd = pTxPort->pTxdRingHead;
1700 ** Map the first fragment (header) into the DMA-space
1702 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1703 virt_to_page(pMessage->data),
1704 ((unsigned long) pMessage->data & ~PAGE_MASK),
1705 skb_headlen(pMessage),
1708 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1709 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1712 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1714 if (pMessage->ip_summed == CHECKSUM_HW) {
1715 u16 hdrlen = pMessage->h.raw - pMessage->data;
1716 u16 offset = hdrlen + pMessage->csum;
1718 Control = BMU_STFWD;
1721 ** We have to use the opcode for tcp here, because the
1722 ** opcode for udp is not working in the hardware yet
1725 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1726 (pAC->GIni.GIChipRev == 0) &&
1727 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1728 Control |= BMU_TCP_CHECK;
1730 Control |= BMU_UDP_CHECK;
1733 pTxd->TcpSumOfs = 0;
1734 pTxd->TcpSumSt = hdrlen;
1735 pTxd->TcpSumWr = offset;
1737 Control = BMU_CHECK | BMU_SW;
1739 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1741 pTxd = pTxd->pNextTxd;
1742 pTxPort->TxdRingFree--;
1743 BytesSend += skb_headlen(pMessage);
1746 ** Browse over all SG fragments and map each of them into the DMA space
1748 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1749 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1751 ** we already have the proper value in entry
1753 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1755 sk_frag->page_offset,
1759 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1760 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1761 pTxd->pMBuf = pMessage;
1763 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;;
1766 ** Do we have the last fragment?
1768 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1769 #ifdef USE_TX_COMPLETE
1770 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1772 pTxd->TBControl |= BMU_EOF;
1774 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1777 pTxd = pTxd->pNextTxd;
1778 pTxPort->TxdRingFree--;
1779 BytesSend += sk_frag->size;
1783 ** If previous descriptor already done, give TX start cmd
1785 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1786 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1789 pTxPort->pTxdRingPrev = pTxdLst;
1790 pTxPort->pTxdRingHead = pTxd;
1792 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1794 if (pTxPort->TxdRingFree > 0) {
1801 /*****************************************************************************
1803 * FreeTxDescriptors - release descriptors from the descriptor ring
1806 * This function releases descriptors from a transmit ring if they
1807 * have been sent by the BMU.
1808 * If a descriptors is sent, it can be freed and the message can
1810 * The SOFTWARE controllable bit is used to prevent running around a
1811 * completely free ring for ever. If this bit is no set in the
1812 * frame (by XmitFrame), this frame has never been sent or is
1814 * The Tx descriptor ring lock must be held while calling this function !!!
1819 static void FreeTxDescriptors(
1820 SK_AC *pAC, /* pointer to the adapter context */
1821 TX_PORT *pTxPort) /* pointer to destination port structure */
1823 TXD *pTxd; /* pointer to the checked descriptor */
1824 TXD *pNewTail; /* pointer to 'end' of the ring */
1825 SK_U32 Control; /* TBControl field of descriptor */
1826 SK_U64 PhysAddr; /* address of DMA mapping */
1828 pNewTail = pTxPort->pTxdRingTail;
1831 ** loop forever; exits if BMU_SW bit not set in start frame
1832 ** or BMU_OWN bit set in any frame
1835 Control = pTxd->TBControl;
1836 if ((Control & BMU_SW) == 0) {
1838 ** software controllable bit is set in first
1839 ** fragment when given to BMU. Not set means that
1840 ** this fragment was never sent or is already
1841 ** freed ( -> ring completely free now).
1843 pTxPort->pTxdRingTail = pTxd;
1844 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1847 if (Control & BMU_OWN) {
1848 pTxPort->pTxdRingTail = pTxd;
1849 if (pTxPort->TxdRingFree > 0) {
1850 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1856 ** release the DMA mapping, because until not unmapped
1857 ** this buffer is considered being under control of the
1860 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1861 PhysAddr |= (SK_U64) pTxd->VDataLow;
1862 pci_unmap_page(pAC->PciDev, PhysAddr,
1866 if (Control & BMU_EOF)
1867 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1869 pTxPort->TxdRingFree++;
1870 pTxd->TBControl &= ~BMU_SW;
1871 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1872 } /* while(forever) */
1873 } /* FreeTxDescriptors */
1875 /*****************************************************************************
1877 * FillRxRing - fill the receive ring with valid descriptors
1880 * This function fills the receive ring descriptors with data
1881 * segments and makes them valid for the BMU.
1882 * The active ring is filled completely, if possible.
1883 * The non-active ring is filled only partial to save memory.
1885 * Description of rx ring structure:
1886 * head - points to the descriptor which will be used next by the BMU
1887 * tail - points to the next descriptor to give to the BMU
1891 static void FillRxRing(
1892 SK_AC *pAC, /* pointer to the adapter context */
1893 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1896 unsigned long Flags;
1898 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1899 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1900 if(!FillRxDescriptor(pAC, pRxPort))
1903 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1907 /*****************************************************************************
1909 * FillRxDescriptor - fill one buffer into the receive ring
1912 * The function allocates a new receive buffer and
1913 * puts it into the next descriptor.
1916 * SK_TRUE - a buffer was added to the ring
1917 * SK_FALSE - a buffer could not be added
1919 static SK_BOOL FillRxDescriptor(
1920 SK_AC *pAC, /* pointer to the adapter context struct */
1921 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1923 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1924 RXD *pRxd; /* the rxd to fill */
1925 SK_U16 Length; /* data fragment length */
1926 SK_U64 PhysAddr; /* physical address of a rx buffer */
1928 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1929 if (pMsgBlock == NULL) {
1930 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1931 SK_DBGCAT_DRV_ENTRY,
1932 ("%s: Allocation of rx buffer failed !\n",
1933 pAC->dev[pRxPort->PortIndex]->name));
1934 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1937 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1938 /* skb allocated ok, so add buffer */
1939 pRxd = pRxPort->pRxdRingTail;
1940 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1941 pRxPort->RxdRingFree--;
1942 Length = pAC->RxBufSize;
1943 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1944 virt_to_page(pMsgBlock->data),
1945 ((unsigned long) pMsgBlock->data &
1948 PCI_DMA_FROMDEVICE);
1950 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1951 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1952 pRxd->pMBuf = pMsgBlock;
1953 pRxd->RBControl = BMU_OWN |
1960 } /* FillRxDescriptor */
1963 /*****************************************************************************
1965 * ReQueueRxBuffer - fill one buffer back into the receive ring
1968 * Fill a given buffer back into the rx ring. The buffer
1969 * has been previously allocated and aligned, and its phys.
1970 * address calculated, so this is no more necessary.
1974 static void ReQueueRxBuffer(
1975 SK_AC *pAC, /* pointer to the adapter context struct */
1976 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1977 struct sk_buff *pMsg, /* pointer to the buffer */
1978 SK_U32 PhysHigh, /* phys address high dword */
1979 SK_U32 PhysLow) /* phys address low dword */
1981 RXD *pRxd; /* the rxd to fill */
1982 SK_U16 Length; /* data fragment length */
1984 pRxd = pRxPort->pRxdRingTail;
1985 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1986 pRxPort->RxdRingFree--;
1987 Length = pAC->RxBufSize;
1989 pRxd->VDataLow = PhysLow;
1990 pRxd->VDataHigh = PhysHigh;
1992 pRxd->RBControl = BMU_OWN |
1998 } /* ReQueueRxBuffer */
2000 /*****************************************************************************
2002 * ReceiveIrq - handle a receive IRQ
2005 * This function is called when a receive IRQ is set.
2006 * It walks the receive descriptor ring and sends up all
2007 * frames that are complete.
2011 static void ReceiveIrq(
2012 SK_AC *pAC, /* pointer to adapter context */
2013 RX_PORT *pRxPort, /* pointer to receive port struct */
2014 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2016 RXD *pRxd; /* pointer to receive descriptors */
2017 SK_U32 Control; /* control field of descriptor */
2018 struct sk_buff *pMsg; /* pointer to message holding frame */
2019 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2020 int FrameLength; /* total length of received frame */
2021 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2022 SK_EVPARA EvPara; /* an event parameter union */
2023 unsigned long Flags; /* for spin lock */
2024 int PortIndex = pRxPort->PortIndex;
2025 unsigned int Offset;
2026 unsigned int NumBytes;
2027 unsigned int ForRlmt;
2030 SK_BOOL IsBadFrame; /* Bad frame */
2036 /* do forever; exit if BMU_OWN found */
2037 for ( pRxd = pRxPort->pRxdRingHead ;
2038 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2039 pRxd = pRxd->pNextRxd,
2040 pRxPort->pRxdRingHead = pRxd,
2041 pRxPort->RxdRingFree ++) {
2044 * For a better understanding of this loop
2045 * Go through every descriptor beginning at the head
2046 * Please note: the ring might be completely received so the OWN bit
2047 * set is not a good crirteria to leave that loop.
2048 * Therefore the RingFree counter is used.
2049 * On entry of this loop pRxd is a pointer to the Rxd that needs
2050 * to be checked next.
2053 Control = pRxd->RBControl;
2055 /* check if this descriptor is ready */
2056 if ((Control & BMU_OWN) != 0) {
2057 /* this descriptor is not yet ready */
2058 /* This is the usual end of the loop */
2059 /* We don't need to start the ring again */
2060 FillRxRing(pAC, pRxPort);
2063 pAC->DynIrqModInfo.NbrProcessedDescr++;
2065 /* get length of frame and check it */
2066 FrameLength = Control & BMU_BBC;
2067 if (FrameLength > pAC->RxBufSize) {
2071 /* check for STF and EOF */
2072 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2076 /* here we have a complete frame in the ring */
2079 FrameStat = pRxd->FrameStat;
2081 /* check for frame length mismatch */
2082 #define XMR_FS_LEN_SHIFT 18
2083 #define GMR_FS_LEN_SHIFT 16
2084 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2085 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2086 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2087 SK_DBGCAT_DRV_RX_PROGRESS,
2088 ("skge: Frame length mismatch (%u/%u).\n",
2090 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2095 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2096 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2097 SK_DBGCAT_DRV_RX_PROGRESS,
2098 ("skge: Frame length mismatch (%u/%u).\n",
2100 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2106 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2107 IsBc = (FrameStat & XMR_FS_BC) != 0;
2108 IsMc = (FrameStat & XMR_FS_MC) != 0;
2109 IsBadFrame = (FrameStat &
2110 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2112 IsBc = (FrameStat & GMR_FS_BC) != 0;
2113 IsMc = (FrameStat & GMR_FS_MC) != 0;
2114 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2115 ((FrameStat & GMR_FS_RX_OK) == 0));
2118 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2119 ("Received frame of length %d on port %d\n",
2120 FrameLength, PortIndex));
2121 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2122 ("Number of free rx descriptors: %d\n",
2123 pRxPort->RxdRingFree));
2124 /* DumpMsg(pMsg, "Rx"); */
2126 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2128 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2130 /* there is a receive error in this frame */
2131 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2132 SK_DBGCAT_DRV_RX_PROGRESS,
2133 ("skge: Error in received frame, dropped!\n"
2134 "Control: %x\nRxStat: %x\n",
2135 Control, FrameStat));
2137 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2138 pRxd->VDataHigh, pRxd->VDataLow);
2144 * if short frame then copy data to reduce memory waste
2146 if ((FrameLength < SK_COPY_THRESHOLD) &&
2147 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2149 * Short frame detected and allocation successfull
2151 /* use new skb and copy data */
2152 skb_reserve(pNewMsg, 2);
2153 skb_put(pNewMsg, FrameLength);
2154 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2155 PhysAddr |= (SK_U64) pRxd->VDataLow;
2157 pci_dma_sync_single_for_cpu(pAC->PciDev,
2158 (dma_addr_t) PhysAddr,
2160 PCI_DMA_FROMDEVICE);
2161 memcpy(pNewMsg->data, pMsg, FrameLength);
2163 pci_dma_sync_single_for_device(pAC->PciDev,
2164 (dma_addr_t) PhysAddr,
2166 PCI_DMA_FROMDEVICE);
2167 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2168 pRxd->VDataHigh, pRxd->VDataLow);
2175 * if large frame, or SKB allocation failed, pass
2176 * the SKB directly to the networking
2179 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2180 PhysAddr |= (SK_U64) pRxd->VDataLow;
2182 /* release the DMA mapping */
2183 pci_unmap_single(pAC->PciDev,
2186 PCI_DMA_FROMDEVICE);
2188 /* set length in message */
2189 skb_put(pMsg, FrameLength);
2190 } /* frame > SK_COPY_TRESHOLD */
2192 if (pRxPort->RxCsum) {
2193 pMsg->csum = pRxd->TcpSums;
2194 pMsg->ip_summed = CHECKSUM_HW;
2197 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2198 ForRlmt = SK_RLMT_RX_PROTOCOL;
2200 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2202 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2203 IsBc, &Offset, &NumBytes);
2204 if (NumBytes != 0) {
2206 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2208 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2209 &pMsg->data[Offset],
2210 IsBc, IsMc, &ForRlmt);
2212 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2213 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2214 /* send up only frames from active port */
2215 if ((PortIndex == pAC->ActivePort) ||
2216 (pAC->RlmtNets == 2)) {
2217 /* frame for upper layer */
2218 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2220 DumpMsg(pMsg, "Rx");
2222 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2223 FrameLength, pRxPort->PortIndex);
2225 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2226 pMsg->protocol = eth_type_trans(pMsg,
2227 pAC->dev[pRxPort->PortIndex]);
2229 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2233 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2234 SK_DBGCAT_DRV_RX_PROGRESS,
2236 DEV_KFREE_SKB(pMsg);
2239 } /* if not for rlmt */
2241 /* packet for rlmt */
2242 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2243 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2244 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2245 pAC->IoBase, FrameLength);
2246 if (pRlmtMbuf != NULL) {
2247 pRlmtMbuf->pNext = NULL;
2248 pRlmtMbuf->Length = FrameLength;
2249 pRlmtMbuf->PortIdx = PortIndex;
2250 EvPara.pParaPtr = pRlmtMbuf;
2251 memcpy((char*)(pRlmtMbuf->pData),
2252 (char*)(pMsg->data),
2255 /* SlowPathLock needed? */
2256 if (SlowPathLock == SK_TRUE) {
2257 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2258 SkEventQueue(pAC, SKGE_RLMT,
2259 SK_RLMT_PACKET_RECEIVED,
2261 pAC->CheckQueue = SK_TRUE;
2262 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2264 SkEventQueue(pAC, SKGE_RLMT,
2265 SK_RLMT_PACKET_RECEIVED,
2267 pAC->CheckQueue = SK_TRUE;
2270 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2271 SK_DBGCAT_DRV_RX_PROGRESS,
2274 if ((pAC->dev[pRxPort->PortIndex]->flags &
2275 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2276 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2277 SK_RLMT_RX_PROTOCOL) {
2278 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2279 pMsg->protocol = eth_type_trans(pMsg,
2280 pAC->dev[pRxPort->PortIndex]);
2282 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2285 DEV_KFREE_SKB(pMsg);
2288 } /* if packet for rlmt */
2289 } /* for ... scanning the RXD ring */
2291 /* RXD ring is empty -> fill and restart */
2292 FillRxRing(pAC, pRxPort);
2293 /* do not start if called from Close */
2294 if (pAC->BoardLevel > SK_INIT_DATA) {
2295 ClearAndStartRx(pAC, PortIndex);
2300 /* remove error frame */
2301 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2302 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2304 /* release the DMA mapping */
2306 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2307 PhysAddr |= (SK_U64) pRxd->VDataLow;
2308 pci_unmap_page(pAC->PciDev,
2311 PCI_DMA_FROMDEVICE);
2312 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2314 pRxPort->RxdRingFree++;
2315 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2321 /*****************************************************************************
2323 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2326 * This function sends a start command and a clear interrupt
2327 * command for one receive queue to the BMU.
2332 static void ClearAndStartRx(
2333 SK_AC *pAC, /* pointer to the adapter context */
2334 int PortIndex) /* index of the receive port (XMAC) */
2336 SK_OUT8(pAC->IoBase,
2337 RxQueueAddr[PortIndex]+Q_CSR,
2338 CSR_START | CSR_IRQ_CL_F);
2339 } /* ClearAndStartRx */
2342 /*****************************************************************************
2344 * ClearTxIrq - give a clear transmit IRQ command to BMU
2347 * This function sends a clear tx IRQ command for one
2348 * transmit queue to the BMU.
2352 static void ClearTxIrq(
2353 SK_AC *pAC, /* pointer to the adapter context */
2354 int PortIndex, /* index of the transmit port (XMAC) */
2355 int Prio) /* priority or normal queue */
2357 SK_OUT8(pAC->IoBase,
2358 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2363 /*****************************************************************************
2365 * ClearRxRing - remove all buffers from the receive ring
2368 * This function removes all receive buffers from the ring.
2369 * The receive BMU must be stopped before calling this function.
2373 static void ClearRxRing(
2374 SK_AC *pAC, /* pointer to adapter context */
2375 RX_PORT *pRxPort) /* pointer to rx port struct */
2377 RXD *pRxd; /* pointer to the current descriptor */
2378 unsigned long Flags;
2381 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2384 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2385 pRxd = pRxPort->pRxdRingHead;
2387 if (pRxd->pMBuf != NULL) {
2389 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2390 PhysAddr |= (SK_U64) pRxd->VDataLow;
2391 pci_unmap_page(pAC->PciDev,
2394 PCI_DMA_FROMDEVICE);
2395 DEV_KFREE_SKB(pRxd->pMBuf);
2398 pRxd->RBControl &= BMU_OWN;
2399 pRxd = pRxd->pNextRxd;
2400 pRxPort->RxdRingFree++;
2401 } while (pRxd != pRxPort->pRxdRingTail);
2402 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2403 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2406 /*****************************************************************************
2408 * ClearTxRing - remove all buffers from the transmit ring
2411 * This function removes all transmit buffers from the ring.
2412 * The transmit BMU must be stopped before calling this function
2413 * and transmitting at the upper level must be disabled.
2414 * The BMU own bit of all descriptors is cleared, the rest is
2415 * done by calling FreeTxDescriptors.
2419 static void ClearTxRing(
2420 SK_AC *pAC, /* pointer to adapter context */
2421 TX_PORT *pTxPort) /* pointer to tx prt struct */
2423 TXD *pTxd; /* pointer to the current descriptor */
2425 unsigned long Flags;
2427 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2428 pTxd = pTxPort->pTxdRingHead;
2429 for (i=0; i<pAC->TxDescrPerRing; i++) {
2430 pTxd->TBControl &= ~BMU_OWN;
2431 pTxd = pTxd->pNextTxd;
2433 FreeTxDescriptors(pAC, pTxPort);
2434 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2437 /*****************************************************************************
2439 * SkGeSetMacAddr - Set the hardware MAC address
2442 * This function sets the MAC address used by the adapter.
2445 * 0, if everything is ok
2448 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2451 DEV_NET *pNet = netdev_priv(dev);
2452 SK_AC *pAC = pNet->pAC;
2454 struct sockaddr *addr = p;
2455 unsigned long Flags;
2457 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2458 ("SkGeSetMacAddr starts now...\n"));
2459 if(netif_running(dev))
2462 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2464 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2466 if (pAC->RlmtNets == 2)
2467 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2468 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2470 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2471 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2475 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2477 } /* SkGeSetMacAddr */
2480 /*****************************************************************************
2482 * SkGeSetRxMode - set receive mode
2485 * This function sets the receive mode of an adapter. The adapter
2486 * supports promiscuous mode, allmulticast mode and a number of
2487 * multicast addresses. If more multicast addresses the available
2488 * are selected, a hash function in the hardware is used.
2491 * 0, if everything is ok
2494 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2500 struct dev_mc_list *pMcList;
2503 unsigned long Flags;
2505 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2506 ("SkGeSetRxMode starts now... "));
2508 pNet = netdev_priv(dev);
2510 if (pAC->RlmtNets == 1)
2511 PortIdx = pAC->ActivePort;
2513 PortIdx = pNet->NetNr;
2515 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2516 if (dev->flags & IFF_PROMISC) {
2517 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2518 ("PROMISCUOUS mode\n"));
2519 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2521 } else if (dev->flags & IFF_ALLMULTI) {
2522 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2523 ("ALLMULTI mode\n"));
2524 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2525 SK_PROM_MODE_ALL_MC);
2527 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2529 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2531 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2532 ("Number of MC entries: %d ", dev->mc_count));
2534 pMcList = dev->mc_list;
2535 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2536 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2537 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2538 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2539 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2540 pMcList->dmi_addr[0],
2541 pMcList->dmi_addr[1],
2542 pMcList->dmi_addr[2],
2543 pMcList->dmi_addr[3],
2544 pMcList->dmi_addr[4],
2545 pMcList->dmi_addr[5]));
2547 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2549 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2552 } /* SkGeSetRxMode */
2555 /*****************************************************************************
2557 * SkGeChangeMtu - set the MTU to another value
2560 * This function sets is called whenever the MTU size is changed
2561 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2562 * ethernet MTU size, long frame support is activated.
2565 * 0, if everything is ok
2568 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2573 unsigned long Flags;
2577 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2578 ("SkGeChangeMtu starts now...\n"));
2580 pNet = netdev_priv(dev);
2583 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2587 if(pAC->BoardLevel != SK_INIT_RUN) {
2591 #ifdef SK_DIAG_SUPPORT
2592 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2593 if (pAC->DiagFlowCtrl == SK_FALSE) {
2594 return -1; /* still in use, deny any actions of MTU */
2596 pAC->DiagFlowCtrl = SK_FALSE;
2602 pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2603 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2607 pAC->RxBufSize = NewMtu + 32;
2610 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2611 ("New MTU: %d\n", NewMtu));
2614 ** Prevent any reconfiguration while changing the MTU
2615 ** by disabling any interrupts
2617 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2618 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2621 ** Notify RLMT that any ports are to be stopped
2623 EvPara.Para32[0] = 0;
2624 EvPara.Para32[1] = -1;
2625 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2626 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2627 EvPara.Para32[0] = 1;
2628 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2630 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2634 ** After calling the SkEventDispatcher(), RLMT is aware about
2635 ** the stopped ports -> configuration can take place!
2637 SkEventDispatcher(pAC, pAC->IoBase);
2639 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2640 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2641 netif_stop_queue(pAC->dev[i]);
2646 ** Depending on the desired MTU size change, a different number of
2647 ** RX buffers need to be allocated
2649 if (NewMtu > 1500) {
2651 ** Use less rx buffers
2653 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2654 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2655 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2656 (pAC->RxDescrPerRing / 4);
2658 if (i == pAC->ActivePort) {
2659 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2660 (pAC->RxDescrPerRing / 4);
2662 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2663 (pAC->RxDescrPerRing / 10);
2669 ** Use the normal amount of rx buffers
2671 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2672 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2673 pAC->RxPort[i].RxFillLimit = 1;
2675 if (i == pAC->ActivePort) {
2676 pAC->RxPort[i].RxFillLimit = 1;
2678 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2679 (pAC->RxDescrPerRing / 4);
2685 SkGeDeInit(pAC, pAC->IoBase);
2688 ** enable/disable hardware support for long frames
2690 if (NewMtu > 1500) {
2691 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2692 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2694 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2695 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2697 pAC->GIni.GIPortUsage = SK_RED_LINK;
2701 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2702 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2703 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2704 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2705 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2706 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2707 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2711 ** Speed and others are set back to default in level 1 init!
2713 GetConfiguration(pAC);
2715 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2716 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2717 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2718 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2719 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2720 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2721 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2724 ** clear and reinit the rx rings here
2726 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2727 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2728 ClearRxRing(pAC, &pAC->RxPort[i]);
2729 FillRxRing(pAC, &pAC->RxPort[i]);
2732 ** Enable transmit descriptor polling
2734 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2735 FillRxRing(pAC, &pAC->RxPort[i]);
2738 SkGeYellowLED(pAC, pAC->IoBase, 1);
2739 SkDimEnableModerationIfNeeded(pAC);
2740 SkDimDisplayModerationSettings(pAC);
2742 netif_start_queue(pAC->dev[pNet->PortNr]);
2743 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2744 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2748 ** Enable Interrupts again
2750 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2751 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2753 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2754 SkEventDispatcher(pAC, pAC->IoBase);
2757 ** Notify RLMT about the changing and restarting one (or more) ports
2759 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2760 EvPara.Para32[0] = pAC->RlmtNets;
2761 EvPara.Para32[1] = -1;
2762 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2763 EvPara.Para32[0] = pNet->PortNr;
2764 EvPara.Para32[1] = -1;
2765 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2767 if (pOtherNet->Up) {
2768 EvPara.Para32[0] = pOtherNet->PortNr;
2769 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2772 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2775 SkEventDispatcher(pAC, pAC->IoBase);
2776 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2779 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2780 ** seems as if upper layers have a problem to handle a successful
2781 ** return value of '0'. If such a zero is returned, the complete
2782 ** system hangs for several minutes (!), which is in acceptable.
2784 ** Currently it is not clear, what the exact reason for this problem
2785 ** is. The implemented workaround for 2.5 is to return the desired
2786 ** new MTU size if all needed changes for the new MTU size where
2787 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2788 ** which indicates the successful change of the mtu-size.
2792 } /* SkGeChangeMtu */
2795 /*****************************************************************************
2797 * SkGeStats - return ethernet device statistics
2800 * This function return statistic data about the ethernet device
2801 * to the operating system.
2804 * pointer to the statistic structure.
2806 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2808 DEV_NET *pNet = netdev_priv(dev);
2809 SK_AC *pAC = pNet->pAC;
2810 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2811 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2812 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2813 unsigned int Size; /* size of pnmi struct */
2814 unsigned long Flags; /* for spin lock */
2816 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2817 ("SkGeStats starts now...\n"));
2818 pPnmiStruct = &pAC->PnmiStruct;
2820 #ifdef SK_DIAG_SUPPORT
2821 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2822 (pAC->BoardLevel == SK_INIT_RUN)) {
2824 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2825 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2826 Size = SK_PNMI_STRUCT_SIZE;
2827 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2828 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2829 #ifdef SK_DIAG_SUPPORT
2833 pPnmiStat = &pPnmiStruct->Stat[0];
2834 pPnmiConf = &pPnmiStruct->Conf[0];
2836 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2837 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2838 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2839 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2841 if (pNet->Mtu <= 1500) {
2842 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2844 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2845 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2849 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2850 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2852 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2853 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2854 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2855 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2856 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2858 /* detailed rx_errors: */
2859 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2860 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2861 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2862 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2863 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2864 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2866 /* detailed tx_errors */
2867 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2868 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2869 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2870 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2871 pAC->stats.tx_window_errors = (SK_U32) 0;
2873 return(&pAC->stats);
2877 /*****************************************************************************
2879 * SkGeIoctl - IO-control function
2882 * This function is called if an ioctl is issued on the device.
2883 * There are three subfunction for reading, writing and test-writing
2884 * the private MIB data structure (usefull for SysKonnect-internal tools).
2887 * 0, if everything is ok
2890 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2895 struct pci_dev *pdev = NULL;
2897 unsigned int Err = 0;
2900 unsigned int Length = 0;
2901 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2903 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2904 ("SkGeIoctl starts now...\n"));
2906 pNet = netdev_priv(dev);
2909 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2914 case SK_IOCTL_SETMIB:
2915 case SK_IOCTL_PRESETMIB:
2916 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2917 case SK_IOCTL_GETMIB:
2918 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2919 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2920 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2923 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2924 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2925 Ioctl.Len<Size? Ioctl.Len : Size)) {
2929 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2934 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2937 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2939 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2942 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2946 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2950 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2955 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2960 kfree(pMemBuf); /* cleanup everything */
2962 #ifdef SK_DIAG_SUPPORT
2964 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2965 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2968 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2970 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2973 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2978 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2980 ** While coding this new IOCTL interface, only a few lines of code
2981 ** are to to be added. Therefore no dedicated function has been
2982 ** added. If more functionality is added, a separate function
2983 ** should be used...
2985 * ((SK_U32 *)pMemBuf) = 0;
2986 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2987 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2988 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2993 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2998 kfree(pMemBuf); /* cleanup everything */
3010 /*****************************************************************************
3012 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3015 * This function reads/writes the MIB data using PNMI (Private Network
3016 * Management Interface).
3017 * The destination for the data must be provided with the
3018 * ioctl call and is given to the driver in the form of
3019 * a user space address.
3020 * Copying from the user-provided data area into kernel messages
3021 * and back is done by copy_from_user and copy_to_user calls in
3025 * returned size from PNMI call
3027 static int SkGeIocMib(
3028 DEV_NET *pNet, /* pointer to the adapter context */
3029 unsigned int Size, /* length of ioctl data */
3030 int mode) /* flag for set/preset */
3032 unsigned long Flags; /* for spin lock */
3035 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3036 ("SkGeIocMib starts now...\n"));
3039 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3041 case SK_IOCTL_GETMIB:
3042 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3045 case SK_IOCTL_PRESETMIB:
3046 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3049 case SK_IOCTL_SETMIB:
3050 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3056 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3057 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3058 ("MIB data access succeeded\n"));
3063 /*****************************************************************************
3065 * GetConfiguration - read configuration information
3068 * This function reads per-adapter configuration information from
3069 * the options provided on the command line.
3074 static void GetConfiguration(
3075 SK_AC *pAC) /* pointer to the adapter context structure */
3077 SK_I32 Port; /* preferred port */
3080 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3081 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3082 int DuplexCap = 0; /* 0=both,1=full,2=half */
3083 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3084 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3086 SK_BOOL IsConTypeDefined = SK_TRUE;
3087 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3088 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3089 SK_BOOL IsRoleDefined = SK_TRUE;
3090 SK_BOOL IsModeDefined = SK_TRUE;
3092 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3093 * parameter. The mapping is described by this table:
3094 * DuplexCap -> | both | full | half |
3096 * -----------------------------------------------------------------
3097 * Off | illegal | Full | Half |
3098 * -----------------------------------------------------------------
3099 * On | AutoBoth | AutoFull | AutoHalf |
3100 * -----------------------------------------------------------------
3101 * Sense | AutoSense | AutoSense | AutoSense |
3103 int Capabilities[3][3] =
3104 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3105 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3106 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3114 #define M_CurrPort pAC->GIni.GP[Port]
3118 ** Set the default values first for both ports!
3120 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3121 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3122 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3123 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3124 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3128 ** Check merged parameter ConType. If it has not been used,
3129 ** verify any other parameter (e.g. AutoNeg) and use default values.
3131 ** Stating both ConType and other lowlevel link parameters is also
3132 ** possible. If this is the case, the passed ConType-parameter is
3133 ** overwritten by the lowlevel link parameter.
3135 ** The following settings are used for a merged ConType-parameter:
3137 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3138 ** ------- ------ ------- -------- ---------- -----
3139 ** Auto Both On SymOrRem Auto Auto
3140 ** 100FD Full Off None <ignored> 100
3141 ** 100HD Half Off None <ignored> 100
3142 ** 10FD Full Off None <ignored> 10
3143 ** 10HD Half Off None <ignored> 10
3145 ** This ConType parameter is used for all ports of the adapter!
3147 if ( (ConType != NULL) &&
3148 (pAC->Index < SK_MAX_CARD_PARAM) &&
3149 (ConType[pAC->Index] != NULL) ) {
3151 /* Check chipset family */
3152 if ((!pAC->ChipsetType) &&
3153 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3154 (strcmp(ConType[pAC->Index],"")!=0)) {
3155 /* Set the speed parameter back */
3156 printk("sk98lin: Illegal value \"%s\" "
3159 ConType[pAC->Index]);
3161 sprintf(ConType[pAC->Index], "Auto");
3164 if (strcmp(ConType[pAC->Index],"")==0) {
3165 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3166 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3167 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3168 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3169 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3170 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3171 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3173 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3174 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3175 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3176 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3177 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3178 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3180 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3181 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3182 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3183 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3184 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3185 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3187 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3188 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3189 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3190 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3191 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3192 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3194 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3195 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3196 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3197 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3198 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3199 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3202 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3203 ConType[pAC->Index]);
3204 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3207 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3211 ** Parse any parameter settings for port A:
3212 ** a) any LinkSpeed stated?
3214 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3215 Speed_A[pAC->Index] != NULL) {
3216 if (strcmp(Speed_A[pAC->Index],"")==0) {
3217 IsLinkSpeedDefined = SK_FALSE;
3218 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3219 LinkSpeed = SK_LSPEED_AUTO;
3220 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3221 LinkSpeed = SK_LSPEED_10MBPS;
3222 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3223 LinkSpeed = SK_LSPEED_100MBPS;
3224 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3225 LinkSpeed = SK_LSPEED_1000MBPS;
3227 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3228 Speed_A[pAC->Index]);
3229 IsLinkSpeedDefined = SK_FALSE;
3232 IsLinkSpeedDefined = SK_FALSE;
3236 ** Check speed parameter:
3237 ** Only copper type adapter and GE V2 cards
3239 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3240 ((LinkSpeed != SK_LSPEED_AUTO) &&
3241 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3242 printk("sk98lin: Illegal value for Speed_A. "
3243 "Not a copper card or GE V2 card\n Using "
3245 LinkSpeed = SK_LSPEED_1000MBPS;
3249 ** Decide whether to set new config value if somethig valid has
3252 if (IsLinkSpeedDefined) {
3253 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3257 ** b) Any Autonegotiation and DuplexCapabilities set?
3258 ** Please note that both belong together...
3260 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3262 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3263 AutoNeg_A[pAC->Index] != NULL) {
3265 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3267 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3269 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3271 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3274 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3275 AutoNeg_A[pAC->Index]);
3279 DuplexCap = DC_BOTH;
3281 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3282 DupCap_A[pAC->Index] != NULL) {
3284 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3286 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3287 DuplexCap = DC_BOTH;
3288 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3289 DuplexCap = DC_FULL;
3290 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3291 DuplexCap = DC_HALF;
3293 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3294 DupCap_A[pAC->Index]);
3299 ** Check for illegal combinations
3301 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3302 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3303 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3304 (pAC->ChipsetType)) {
3305 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3306 " Using Full Duplex.\n");
3307 DuplexCap = DC_FULL;
3310 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3311 printk("sk98lin, Port A: DuplexCapabilities"
3312 " ignored using Sense mode\n");
3315 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3316 printk("sk98lin: Port A: Illegal combination"
3317 " of values AutoNeg. and DuplexCap.\n Using "
3319 DuplexCap = DC_FULL;
3322 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3323 DuplexCap = DC_FULL;
3326 if (!AutoSet && DupSet) {
3327 printk("sk98lin: Port A: Duplex setting not"
3328 " possible in\n default AutoNegotiation mode"
3329 " (Sense).\n Using AutoNegotiation On\n");
3334 ** set the desired mode
3336 if (AutoSet || DupSet) {
3337 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3341 ** c) Any Flowcontrol-parameter set?
3343 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3344 FlowCtrl_A[pAC->Index] != NULL) {
3345 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3346 IsFlowCtrlDefined = SK_FALSE;
3347 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3348 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3349 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3350 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3351 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3352 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3353 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3354 FlowCtrl = SK_FLOW_MODE_NONE;
3356 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3357 FlowCtrl_A[pAC->Index]);
3358 IsFlowCtrlDefined = SK_FALSE;
3361 IsFlowCtrlDefined = SK_FALSE;
3364 if (IsFlowCtrlDefined) {
3365 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3366 printk("sk98lin: Port A: FlowControl"
3367 " impossible without AutoNegotiation,"
3369 FlowCtrl = SK_FLOW_MODE_NONE;
3371 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3375 ** d) What is with the RoleParameter?
3377 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3378 Role_A[pAC->Index] != NULL) {
3379 if (strcmp(Role_A[pAC->Index],"")==0) {
3380 IsRoleDefined = SK_FALSE;
3381 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3382 MSMode = SK_MS_MODE_AUTO;
3383 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3384 MSMode = SK_MS_MODE_MASTER;
3385 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3386 MSMode = SK_MS_MODE_SLAVE;
3388 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3389 Role_A[pAC->Index]);
3390 IsRoleDefined = SK_FALSE;
3393 IsRoleDefined = SK_FALSE;
3396 if (IsRoleDefined == SK_TRUE) {
3397 pAC->GIni.GP[0].PMSMode = MSMode;
3403 ** Parse any parameter settings for port B:
3404 ** a) any LinkSpeed stated?
3406 IsConTypeDefined = SK_TRUE;
3407 IsLinkSpeedDefined = SK_TRUE;
3408 IsFlowCtrlDefined = SK_TRUE;
3409 IsModeDefined = SK_TRUE;
3411 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3412 Speed_B[pAC->Index] != NULL) {
3413 if (strcmp(Speed_B[pAC->Index],"")==0) {
3414 IsLinkSpeedDefined = SK_FALSE;
3415 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3416 LinkSpeed = SK_LSPEED_AUTO;
3417 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3418 LinkSpeed = SK_LSPEED_10MBPS;
3419 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3420 LinkSpeed = SK_LSPEED_100MBPS;
3421 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3422 LinkSpeed = SK_LSPEED_1000MBPS;
3424 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3425 Speed_B[pAC->Index]);
3426 IsLinkSpeedDefined = SK_FALSE;
3429 IsLinkSpeedDefined = SK_FALSE;
3433 ** Check speed parameter:
3434 ** Only copper type adapter and GE V2 cards
3436 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3437 ((LinkSpeed != SK_LSPEED_AUTO) &&
3438 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3439 printk("sk98lin: Illegal value for Speed_B. "
3440 "Not a copper card or GE V2 card\n Using "
3442 LinkSpeed = SK_LSPEED_1000MBPS;
3446 ** Decide whether to set new config value if somethig valid has
3449 if (IsLinkSpeedDefined) {
3450 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3454 ** b) Any Autonegotiation and DuplexCapabilities set?
3455 ** Please note that both belong together...
3457 AutoNeg = AN_SENS; /* default: do auto Sense */
3459 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3460 AutoNeg_B[pAC->Index] != NULL) {
3462 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3464 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3466 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3468 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3471 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3472 AutoNeg_B[pAC->Index]);
3476 DuplexCap = DC_BOTH;
3478 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3479 DupCap_B[pAC->Index] != NULL) {
3481 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3483 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3484 DuplexCap = DC_BOTH;
3485 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3486 DuplexCap = DC_FULL;
3487 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3488 DuplexCap = DC_HALF;
3490 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3491 DupCap_B[pAC->Index]);
3497 ** Check for illegal combinations
3499 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3500 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3501 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3502 (pAC->ChipsetType)) {
3503 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3504 " Using Full Duplex.\n");
3505 DuplexCap = DC_FULL;
3508 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3509 printk("sk98lin, Port B: DuplexCapabilities"
3510 " ignored using Sense mode\n");
3513 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3514 printk("sk98lin: Port B: Illegal combination"
3515 " of values AutoNeg. and DuplexCap.\n Using "
3517 DuplexCap = DC_FULL;
3520 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3521 DuplexCap = DC_FULL;
3524 if (!AutoSet && DupSet) {
3525 printk("sk98lin: Port B: Duplex setting not"
3526 " possible in\n default AutoNegotiation mode"
3527 " (Sense).\n Using AutoNegotiation On\n");
3532 ** set the desired mode
3534 if (AutoSet || DupSet) {
3535 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3539 ** c) Any FlowCtrl parameter set?
3541 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3542 FlowCtrl_B[pAC->Index] != NULL) {
3543 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3544 IsFlowCtrlDefined = SK_FALSE;
3545 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3546 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3547 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3548 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3549 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3550 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3551 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3552 FlowCtrl = SK_FLOW_MODE_NONE;
3554 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3555 FlowCtrl_B[pAC->Index]);
3556 IsFlowCtrlDefined = SK_FALSE;
3559 IsFlowCtrlDefined = SK_FALSE;
3562 if (IsFlowCtrlDefined) {
3563 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3564 printk("sk98lin: Port B: FlowControl"
3565 " impossible without AutoNegotiation,"
3567 FlowCtrl = SK_FLOW_MODE_NONE;
3569 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3573 ** d) What is the RoleParameter?
3575 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3576 Role_B[pAC->Index] != NULL) {
3577 if (strcmp(Role_B[pAC->Index],"")==0) {
3578 IsRoleDefined = SK_FALSE;
3579 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3580 MSMode = SK_MS_MODE_AUTO;
3581 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3582 MSMode = SK_MS_MODE_MASTER;
3583 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3584 MSMode = SK_MS_MODE_SLAVE;
3586 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3587 Role_B[pAC->Index]);
3588 IsRoleDefined = SK_FALSE;
3591 IsRoleDefined = SK_FALSE;
3594 if (IsRoleDefined) {
3595 pAC->GIni.GP[1].PMSMode = MSMode;
3599 ** Evaluate settings for both ports
3601 pAC->ActivePort = 0;
3602 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3603 PrefPort[pAC->Index] != NULL) {
3604 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3605 pAC->ActivePort = 0;
3606 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3607 pAC->Rlmt.Net[0].PrefPort = 0;
3608 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3610 ** do not set ActivePort here, thus a port
3611 ** switch is issued after net up.
3614 pAC->Rlmt.Net[0].Preference = Port;
3615 pAC->Rlmt.Net[0].PrefPort = Port;
3616 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3618 ** do not set ActivePort here, thus a port
3619 ** switch is issued after net up.
3621 if (pAC->GIni.GIMacsFound == 1) {
3622 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3623 " Port B not available on single port adapters.\n");
3625 pAC->ActivePort = 0;
3626 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3627 pAC->Rlmt.Net[0].PrefPort = 0;
3630 pAC->Rlmt.Net[0].Preference = Port;
3631 pAC->Rlmt.Net[0].PrefPort = Port;
3634 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3635 PrefPort[pAC->Index]);
3641 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3642 RlmtMode[pAC->Index] != NULL) {
3643 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3645 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3646 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3647 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3648 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3649 SK_RLMT_CHECK_LOC_LINK;
3650 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3651 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3652 SK_RLMT_CHECK_LOC_LINK |
3654 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3655 (pAC->GIni.GIMacsFound == 2)) {
3656 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3659 printk("sk98lin: Illegal value \"%s\" for"
3660 " RlmtMode, using default\n",
3661 RlmtMode[pAC->Index]);
3669 ** Check the interrupt moderation parameters
3671 if (Moderation[pAC->Index] != NULL) {
3672 if (strcmp(Moderation[pAC->Index], "") == 0) {
3673 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3674 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3675 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3676 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3677 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3678 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3679 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3681 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3682 " Disable interrupt moderation.\n",
3683 Moderation[pAC->Index]);
3684 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3687 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3690 if (Stats[pAC->Index] != NULL) {
3691 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3692 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3694 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3697 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3700 if (ModerationMask[pAC->Index] != NULL) {
3701 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3702 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3703 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3704 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3705 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3706 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3707 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3708 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3709 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3710 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3711 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3712 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3713 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3714 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3715 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3716 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3717 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3718 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3719 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3720 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3721 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3722 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3723 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3724 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3725 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3726 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3727 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3728 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3729 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3730 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3731 } else { /* some rubbish */
3732 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3734 } else { /* operator has stated nothing */
3735 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3738 if (AutoSizing[pAC->Index] != NULL) {
3739 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3740 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3742 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3744 } else { /* operator has stated nothing */
3745 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3748 if (IntsPerSec[pAC->Index] != 0) {
3749 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3750 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3751 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3752 " Using default value of %i.\n",
3753 IntsPerSec[pAC->Index],
3754 C_INT_MOD_IPS_LOWER_RANGE,
3755 C_INT_MOD_IPS_UPPER_RANGE,
3756 C_INTS_PER_SEC_DEFAULT);
3757 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3759 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3762 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3766 ** Evaluate upper and lower moderation threshold
3768 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3769 pAC->DynIrqModInfo.MaxModIntsPerSec +
3770 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3772 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3773 pAC->DynIrqModInfo.MaxModIntsPerSec -
3774 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3776 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3779 } /* GetConfiguration */
3782 /*****************************************************************************
3784 * ProductStr - return a adapter identification string from vpd
3787 * This function reads the product name string from the vpd area
3788 * and puts it the field pAC->DeviceString.
3792 static void ProductStr(
3793 SK_AC *pAC /* pointer to adapter context */
3796 int StrLen = 80; /* length of the string, defined in SK_AC */
3797 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3798 int ReturnCode; /* return code from vpd_read */
3799 unsigned long Flags;
3801 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3802 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3804 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3805 if (ReturnCode != 0) {
3806 /* there was an error reading the vpd data */
3807 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3808 ("Error reading VPD data: %d\n", ReturnCode));
3809 pAC->DeviceStr[0] = '\0';
3813 /*****************************************************************************
3815 * StartDrvCleanupTimer - Start timer to check for descriptors which
3816 * might be placed in descriptor ring, but
3817 * havent been handled up to now
3820 * This function requests a HW-timer fo the Yukon card. The actions to
3821 * perform when this timer expires, are located in the SkDrvEvent().
3826 StartDrvCleanupTimer(SK_AC *pAC) {
3827 SK_EVPARA EventParam; /* Event struct for timer event */
3829 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3830 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3831 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3832 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3833 SKGE_DRV, SK_DRV_TIMER, EventParam);
3836 /*****************************************************************************
3838 * StopDrvCleanupTimer - Stop timer to check for descriptors
3841 * This function requests a HW-timer fo the Yukon card. The actions to
3842 * perform when this timer expires, are located in the SkDrvEvent().
3847 StopDrvCleanupTimer(SK_AC *pAC) {
3848 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3849 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3852 /****************************************************************************/
3853 /* functions for common modules *********************************************/
3854 /****************************************************************************/
3857 /*****************************************************************************
3859 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3862 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3863 * is embedded into a socket buff data area.
3869 * NULL or pointer to Mbuf.
3871 SK_MBUF *SkDrvAllocRlmtMbuf(
3872 SK_AC *pAC, /* pointer to adapter context */
3873 SK_IOC IoC, /* the IO-context */
3874 unsigned BufferSize) /* size of the requested buffer */
3876 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3877 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3879 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3880 if (pMsgBlock == NULL) {
3883 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3884 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3885 pRlmtMbuf->pNext = NULL;
3886 pRlmtMbuf->pOs = pMsgBlock;
3887 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3888 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3889 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3892 } /* SkDrvAllocRlmtMbuf */
3895 /*****************************************************************************
3897 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3900 * This routine frees one or more RLMT mbuf(s).
3908 void SkDrvFreeRlmtMbuf(
3909 SK_AC *pAC, /* pointer to adapter context */
3910 SK_IOC IoC, /* the IO-context */
3911 SK_MBUF *pMbuf) /* size of the requested buffer */
3918 pNextMbuf = pFreeMbuf->pNext;
3919 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3920 pFreeMbuf = pNextMbuf;
3921 } while ( pFreeMbuf != NULL );
3922 } /* SkDrvFreeRlmtMbuf */
3925 /*****************************************************************************
3927 * SkOsGetTime - provide a time value
3930 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3931 * It is not used for absolute time, but only for time differences.
3937 SK_U64 SkOsGetTime(SK_AC *pAC)
3939 SK_U64 PrivateJiffies;
3940 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3941 return PrivateJiffies;
3945 /*****************************************************************************
3947 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3950 * This routine reads a 32 bit value from the pci configuration
3954 * 0 - indicate everything worked ok.
3955 * != 0 - error indication
3957 int SkPciReadCfgDWord(
3958 SK_AC *pAC, /* Adapter Control structure pointer */
3959 int PciAddr, /* PCI register address */
3960 SK_U32 *pVal) /* pointer to store the read value */
3962 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3964 } /* SkPciReadCfgDWord */
3967 /*****************************************************************************
3969 * SkPciReadCfgWord - read a 16 bit value from pci config space
3972 * This routine reads a 16 bit value from the pci configuration
3976 * 0 - indicate everything worked ok.
3977 * != 0 - error indication
3979 int SkPciReadCfgWord(
3980 SK_AC *pAC, /* Adapter Control structure pointer */
3981 int PciAddr, /* PCI register address */
3982 SK_U16 *pVal) /* pointer to store the read value */
3984 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3986 } /* SkPciReadCfgWord */
3989 /*****************************************************************************
3991 * SkPciReadCfgByte - read a 8 bit value from pci config space
3994 * This routine reads a 8 bit value from the pci configuration
3998 * 0 - indicate everything worked ok.
3999 * != 0 - error indication
4001 int SkPciReadCfgByte(
4002 SK_AC *pAC, /* Adapter Control structure pointer */
4003 int PciAddr, /* PCI register address */
4004 SK_U8 *pVal) /* pointer to store the read value */
4006 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4008 } /* SkPciReadCfgByte */
4011 /*****************************************************************************
4013 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4016 * This routine writes a 16 bit value to the pci configuration
4017 * space. The flag PciConfigUp indicates whether the config space
4018 * is accesible or must be set up first.
4021 * 0 - indicate everything worked ok.
4022 * != 0 - error indication
4024 int SkPciWriteCfgWord(
4025 SK_AC *pAC, /* Adapter Control structure pointer */
4026 int PciAddr, /* PCI register address */
4027 SK_U16 Val) /* pointer to store the read value */
4029 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4031 } /* SkPciWriteCfgWord */
4034 /*****************************************************************************
4036 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4039 * This routine writes a 8 bit value to the pci configuration
4040 * space. The flag PciConfigUp indicates whether the config space
4041 * is accesible or must be set up first.
4044 * 0 - indicate everything worked ok.
4045 * != 0 - error indication
4047 int SkPciWriteCfgByte(
4048 SK_AC *pAC, /* Adapter Control structure pointer */
4049 int PciAddr, /* PCI register address */
4050 SK_U8 Val) /* pointer to store the read value */
4052 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4054 } /* SkPciWriteCfgByte */
4057 /*****************************************************************************
4059 * SkDrvEvent - handle driver events
4062 * This function handles events from all modules directed to the driver
4065 * Is called under protection of slow path lock.
4068 * 0 if everything ok
4073 SK_AC *pAC, /* pointer to adapter context */
4074 SK_IOC IoC, /* io-context */
4075 SK_U32 Event, /* event-id */
4076 SK_EVPARA Param) /* event-parameter */
4078 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4079 struct sk_buff *pMsg; /* pointer to a message block */
4080 int FromPort; /* the port from which we switch away */
4081 int ToPort; /* the port we switch to */
4082 SK_EVPARA NewPara; /* parameter for further events */
4084 unsigned long Flags;
4088 case SK_DRV_ADAP_FAIL:
4089 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4090 ("ADAPTER FAIL EVENT\n"));
4091 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4092 /* disable interrupts */
4093 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4096 case SK_DRV_PORT_FAIL:
4097 FromPort = Param.Para32[0];
4098 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4099 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4100 if (FromPort == 0) {
4101 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4103 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4107 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4109 FromPort = Param.Para32[0];
4110 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4111 ("PORT RESET EVENT, Port: %d ", FromPort));
4112 NewPara.Para64 = FromPort;
4113 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4115 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4118 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4119 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4120 spin_unlock_irqrestore(
4121 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4124 /* clear rx ring from received frames */
4125 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4127 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4129 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4132 /* tschilling: Handling of return value inserted. */
4133 if (SkGeInitPort(pAC, IoC, FromPort)) {
4134 if (FromPort == 0) {
4135 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4137 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4140 SkAddrMcUpdate(pAC,IoC, FromPort);
4141 PortReInitBmu(pAC, FromPort);
4142 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4143 ClearAndStartRx(pAC, FromPort);
4144 spin_unlock_irqrestore(
4145 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4148 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4149 { struct net_device *dev = pAC->dev[Param.Para32[0]];
4151 FromPort = Param.Para32[0];
4152 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4153 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4155 SkAddrMcUpdate(pAC,IoC, FromPort);
4157 if (DoPrintInterfaceChange) {
4158 printk("%s: network connection up using"
4159 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4161 /* tschilling: Values changed according to LinkSpeedUsed. */
4162 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4163 if (Stat == SK_LSPEED_STAT_10MBPS) {
4164 printk(" speed: 10\n");
4165 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4166 printk(" speed: 100\n");
4167 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4168 printk(" speed: 1000\n");
4170 printk(" speed: unknown\n");
4174 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4175 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4176 Stat == SK_LMODE_STAT_AUTOFULL) {
4177 printk(" autonegotiation: yes\n");
4180 printk(" autonegotiation: no\n");
4182 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4183 Stat == SK_LMODE_STAT_HALF) {
4184 printk(" duplex mode: half\n");
4187 printk(" duplex mode: full\n");
4189 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4190 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4191 printk(" flowctrl: remote send\n");
4193 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4194 printk(" flowctrl: local send\n");
4196 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4197 printk(" flowctrl: symmetric\n");
4200 printk(" flowctrl: none\n");
4203 /* tschilling: Check against CopperType now. */
4204 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4205 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4206 SK_LSPEED_STAT_1000MBPS)) {
4207 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4208 if (Stat == SK_MS_STAT_MASTER ) {
4209 printk(" role: master\n");
4211 else if (Stat == SK_MS_STAT_SLAVE ) {
4212 printk(" role: slave\n");
4215 printk(" role: ???\n");
4220 Display dim (dynamic interrupt moderation)
4223 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4224 printk(" irq moderation: static (%d ints/sec)\n",
4225 pAC->DynIrqModInfo.MaxModIntsPerSec);
4226 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4227 printk(" irq moderation: dynamic (%d ints/sec)\n",
4228 pAC->DynIrqModInfo.MaxModIntsPerSec);
4230 printk(" irq moderation: disabled\n");
4233 printk(" scatter-gather: %s\n",
4234 (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4235 printk(" tx-checksum: %s\n",
4236 (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4237 printk(" rx-checksum: %s\n",
4238 pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4241 DoPrintInterfaceChange = SK_TRUE;
4244 if ((Param.Para32[0] != pAC->ActivePort) &&
4245 (pAC->RlmtNets == 1)) {
4246 NewPara.Para32[0] = pAC->ActivePort;
4247 NewPara.Para32[1] = Param.Para32[0];
4248 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4252 /* Inform the world that link protocol is up. */
4253 netif_carrier_on(dev);
4256 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4258 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4259 ("NET DOWN EVENT "));
4260 if (DoPrintInterfaceChange) {
4261 printk("%s: network connection down\n",
4262 pAC->dev[Param.Para32[1]]->name);
4264 DoPrintInterfaceChange = SK_TRUE;
4266 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4268 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4269 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4270 ("PORT SWITCH HARD "));
4271 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4273 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4274 'A'+Param.Para32[1]);
4275 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4276 FromPort = Param.Para32[0];
4277 ToPort = Param.Para32[1];
4278 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4279 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4280 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4281 NewPara.Para64 = FromPort;
4282 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4283 NewPara.Para64 = ToPort;
4284 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4286 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4288 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4289 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4290 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4291 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4292 spin_unlock_irqrestore(
4293 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4296 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4297 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4299 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4300 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4302 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4304 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4305 pAC->ActivePort = ToPort;
4309 /* tschilling: New common function with minimum size check. */
4311 if (pAC->RlmtNets == 2) {
4315 if (SkGeInitAssignRamToQueues(
4319 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4320 spin_unlock_irqrestore(
4321 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4323 printk("SkGeInitAssignRamToQueues failed.\n");
4327 /* tschilling: Handling of return values inserted. */
4328 if (SkGeInitPort(pAC, IoC, FromPort) ||
4329 SkGeInitPort(pAC, IoC, ToPort)) {
4330 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4332 if (Event == SK_DRV_SWITCH_SOFT) {
4333 SkMacRxTxEnable(pAC, IoC, FromPort);
4335 SkMacRxTxEnable(pAC, IoC, ToPort);
4336 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4337 SkAddrMcUpdate(pAC, IoC, FromPort);
4338 SkAddrMcUpdate(pAC, IoC, ToPort);
4339 PortReInitBmu(pAC, FromPort);
4340 PortReInitBmu(pAC, ToPort);
4341 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4342 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4343 ClearAndStartRx(pAC, FromPort);
4344 ClearAndStartRx(pAC, ToPort);
4345 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4346 spin_unlock_irqrestore(
4347 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4350 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4351 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4353 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4354 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4355 skb_put(pMsg, pRlmtMbuf->Length);
4356 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4359 DEV_KFREE_SKB_ANY(pMsg);
4362 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4364 ** expiration of the moderation timer implies that
4365 ** dynamic moderation is to be applied
4367 SkDimStartModerationTimer(pAC);
4369 if (pAC->DynIrqModInfo.DisplayStats) {
4370 SkDimDisplayModerationSettings(pAC);
4372 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4374 ** check if we need to check for descriptors which
4375 ** haven't been handled the last millisecs
4377 StartDrvCleanupTimer(pAC);
4378 if (pAC->GIni.GIMacsFound == 2) {
4379 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4381 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4383 printk("Expiration of unknown timer\n");
4389 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4396 /*****************************************************************************
4398 * SkErrorLog - log errors
4401 * This function logs errors to the system buffer and to the console
4404 * 0 if everything ok
4417 case SK_ERRCL_OTHER:
4418 strcpy(ClassStr, "Other error");
4420 case SK_ERRCL_CONFIG:
4421 strcpy(ClassStr, "Configuration error");
4424 strcpy(ClassStr, "Initialization error");
4426 case SK_ERRCL_NORES:
4427 strcpy(ClassStr, "Out of resources error");
4430 strcpy(ClassStr, "internal Software error");
4433 strcpy(ClassStr, "Hardware failure");
4436 strcpy(ClassStr, "Communication error");
4439 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4440 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4441 ClassStr, ErrNum, pErrorMsg);
4445 #ifdef SK_DIAG_SUPPORT
4447 /*****************************************************************************
4449 * SkDrvEnterDiagMode - handles DIAG attach request
4452 * Notify the kernel to NOT access the card any longer due to DIAG
4453 * Deinitialize the Card
4458 int SkDrvEnterDiagMode(
4459 SK_AC *pAc) /* pointer to adapter context */
4461 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4462 SK_AC *pAC = pNet->pAC;
4464 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4465 sizeof(SK_PNMI_STRUCT_DATA));
4467 pAC->DiagModeActive = DIAG_ACTIVE;
4468 if (pAC->BoardLevel > SK_INIT_DATA) {
4470 pAC->WasIfUp[0] = SK_TRUE;
4471 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4472 DoPrintInterfaceChange = SK_FALSE;
4473 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4475 pAC->WasIfUp[0] = SK_FALSE;
4477 if (pNet != netdev_priv(pAC->dev[1])) {
4478 pNet = netdev_priv(pAC->dev[1]);
4480 pAC->WasIfUp[1] = SK_TRUE;
4481 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4482 DoPrintInterfaceChange = SK_FALSE;
4483 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4485 pAC->WasIfUp[1] = SK_FALSE;
4488 pAC->BoardLevel = SK_INIT_DATA;
4493 /*****************************************************************************
4495 * SkDrvLeaveDiagMode - handles DIAG detach request
4498 * Notify the kernel to may access the card again after use by DIAG
4499 * Initialize the Card
4504 int SkDrvLeaveDiagMode(
4505 SK_AC *pAc) /* pointer to adapter control context */
4507 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4508 sizeof(SK_PNMI_STRUCT_DATA));
4509 pAc->DiagModeActive = DIAG_NOTACTIVE;
4510 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4511 if (pAc->WasIfUp[0] == SK_TRUE) {
4512 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4513 DoPrintInterfaceChange = SK_FALSE;
4514 SkDrvInitAdapter(pAc, 0); /* first device */
4516 if (pAc->WasIfUp[1] == SK_TRUE) {
4517 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4518 DoPrintInterfaceChange = SK_FALSE;
4519 SkDrvInitAdapter(pAc, 1); /* second device */
4524 /*****************************************************************************
4526 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4529 * This function parses the PCI slot name information string and will
4530 * retrieve the devcie number out of it. The slot_name maintianed by
4531 * linux is in the form of '02:0a.0', whereas the first two characters
4532 * represent the bus number in hex (in the sample above this is
4533 * pci bus 0x02) and the next two characters the device number (0x0a).
4536 * SK_U32: The device number from the PCI slot name
4539 static SK_U32 ParseDeviceNbrFromSlotName(
4540 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4542 char *CurrCharPos = (char *) SlotName;
4543 int FirstNibble = -1;
4544 int SecondNibble = -1;
4547 while (*CurrCharPos != '\0') {
4548 if (*CurrCharPos == ':') {
4549 while (*CurrCharPos != '.') {
4551 if ( (*CurrCharPos >= '0') &&
4552 (*CurrCharPos <= '9')) {
4553 if (FirstNibble == -1) {
4554 /* dec. value for '0' */
4555 FirstNibble = *CurrCharPos - 48;
4557 SecondNibble = *CurrCharPos - 48;
4559 } else if ( (*CurrCharPos >= 'a') &&
4560 (*CurrCharPos <= 'f') ) {
4561 if (FirstNibble == -1) {
4562 FirstNibble = *CurrCharPos - 87;
4564 SecondNibble = *CurrCharPos - 87;
4571 Result = FirstNibble;
4572 Result = Result << 4; /* first nibble is higher one */
4573 Result = Result | SecondNibble;
4575 CurrCharPos++; /* next character */
4580 /****************************************************************************
4582 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4583 * called if Diag attaches to that card)
4586 * Close initialized adapter.
4590 * error code - on error
4592 static int SkDrvDeInitAdapter(
4593 SK_AC *pAC, /* pointer to adapter context */
4594 int devNbr) /* what device is to be handled */
4596 struct SK_NET_DEVICE *dev;
4598 dev = pAC->dev[devNbr];
4600 /* On Linux 2.6 the network driver does NOT mess with reference
4601 ** counts. The driver MUST be able to be unloaded at any time
4602 ** due to the possibility of hotplug.
4604 if (SkGeClose(dev) != 0) {
4609 } /* SkDrvDeInitAdapter() */
4611 /****************************************************************************
4613 * SkDrvInitAdapter - Initialize adapter (this function is only
4614 * called if Diag deattaches from that card)
4617 * Close initialized adapter.
4621 * error code - on error
4623 static int SkDrvInitAdapter(
4624 SK_AC *pAC, /* pointer to adapter context */
4625 int devNbr) /* what device is to be handled */
4627 struct SK_NET_DEVICE *dev;
4629 dev = pAC->dev[devNbr];
4631 if (SkGeOpen(dev) != 0) {
4636 ** Use correct MTU size and indicate to kernel TX queue can be started
4638 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4643 } /* SkDrvInitAdapter */
4648 /****************************************************************************/
4649 /* "debug only" section *****************************************************/
4650 /****************************************************************************/
4653 /*****************************************************************************
4655 * DumpMsg - print a frame
4658 * This function prints frames to the system logfile/to the console.
4663 static void DumpMsg(struct sk_buff *skb, char *str)
4668 printk("DumpMsg(): NULL-Message\n");
4672 if (skb->data == NULL) {
4673 printk("DumpMsg(): Message empty\n");
4681 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4683 DumpData((char *)skb->data, msglen);
4685 printk("------- End of message ---------\n");
4690 /*****************************************************************************
4692 * DumpData - print a data area
4695 * This function prints a area of data to the system logfile/to the
4701 static void DumpData(char *p, int size)
4705 char hex_buffer[180];
4706 char asc_buffer[180];
4707 char HEXCHAR[] = "0123456789ABCDEF";
4713 for (i=0; i < size; ) {
4714 if (*p >= '0' && *p <='z')
4715 asc_buffer[addr] = *p;
4717 asc_buffer[addr] = '.';
4719 asc_buffer[addr] = 0;
4720 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4722 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4724 hex_buffer[haddr] = ' ';
4726 hex_buffer[haddr] = 0;
4730 printk("%s %s\n", hex_buffer, asc_buffer);
4738 /*****************************************************************************
4740 * DumpLong - print a data area as long values
4743 * This function prints a area of data to the system logfile/to the
4749 static void DumpLong(char *pc, int size)
4753 char hex_buffer[180];
4754 char asc_buffer[180];
4755 char HEXCHAR[] = "0123456789ABCDEF";
4764 for (i=0; i < size; ) {
4766 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4768 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4770 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4772 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4774 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4776 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4778 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4780 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4782 hex_buffer[haddr] = ' ';
4784 hex_buffer[haddr] = 0;
4788 printk("%4x %s\n", (i-8)*4, hex_buffer);
4792 printk("------------------------\n");
4797 static int __devinit skge_probe_one(struct pci_dev *pdev,
4798 const struct pci_device_id *ent)
4801 DEV_NET *pNet = NULL;
4802 struct net_device *dev = NULL;
4803 static int boards_found = 0;
4804 int error = -ENODEV;
4806 if (pci_enable_device(pdev))
4809 /* Configure DMA attributes. */
4810 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4811 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4812 goto out_disable_device;
4815 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4816 printk(KERN_ERR "Unable to allocate etherdev "
4818 goto out_disable_device;
4821 pNet = netdev_priv(dev);
4822 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4824 printk(KERN_ERR "Unable to allocate adapter "
4826 goto out_free_netdev;
4829 memset(pNet->pAC, 0, sizeof(SK_AC));
4832 pAC->PciDevId = pdev->device;
4835 sprintf(pAC->Name, "SysKonnect SK-98xx");
4836 pAC->CheckQueue = SK_FALSE;
4840 dev->irq = pdev->irq;
4841 error = SkGeInitPCI(pAC);
4843 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4844 goto out_free_netdev;
4847 SET_MODULE_OWNER(dev);
4848 dev->open = &SkGeOpen;
4849 dev->stop = &SkGeClose;
4850 dev->hard_start_xmit = &SkGeXmit;
4851 dev->get_stats = &SkGeStats;
4852 dev->set_multicast_list = &SkGeSetRxMode;
4853 dev->set_mac_address = &SkGeSetMacAddr;
4854 dev->do_ioctl = &SkGeIoctl;
4855 dev->change_mtu = &SkGeChangeMtu;
4856 #ifdef CONFIG_NET_POLL_CONTROLLER
4857 dev->poll_controller = &SkGePollController;
4859 SET_NETDEV_DEV(dev, &pdev->dev);
4860 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4862 /* Use only if yukon hardware */
4863 if (pAC->ChipsetType) {
4864 #ifdef USE_SK_TX_CHECKSUM
4865 dev->features |= NETIF_F_IP_CSUM;
4868 dev->features |= NETIF_F_SG;
4870 #ifdef USE_SK_RX_CHECKSUM
4871 pAC->RxPort[0].RxCsum = 1;
4875 pAC->Index = boards_found++;
4877 if (SkGeBoardInit(dev, pAC))
4878 goto out_free_netdev;
4880 /* Register net device */
4881 if (register_netdev(dev)) {
4882 printk(KERN_ERR "sk98lin: Could not register device.\n");
4883 goto out_free_resources;
4886 /* Print adapter specific string from vpd */
4888 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4890 /* Print configuration settings */
4891 printk(" PrefPort:%c RlmtMode:%s\n",
4892 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4893 (pAC->RlmtMode==0) ? "Check Link State" :
4894 ((pAC->RlmtMode==1) ? "Check Link State" :
4895 ((pAC->RlmtMode==3) ? "Check Local Port" :
4896 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4897 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4899 SkGeYellowLED(pAC, pAC->IoBase, 1);
4901 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4902 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4904 SkGeProcCreate(dev);
4911 /* More then one port found */
4912 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4913 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4914 printk(KERN_ERR "Unable to allocate etherdev "
4920 pNet = netdev_priv(dev);
4927 dev->open = &SkGeOpen;
4928 dev->stop = &SkGeClose;
4929 dev->hard_start_xmit = &SkGeXmit;
4930 dev->get_stats = &SkGeStats;
4931 dev->set_multicast_list = &SkGeSetRxMode;
4932 dev->set_mac_address = &SkGeSetMacAddr;
4933 dev->do_ioctl = &SkGeIoctl;
4934 dev->change_mtu = &SkGeChangeMtu;
4935 SET_NETDEV_DEV(dev, &pdev->dev);
4936 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4938 if (pAC->ChipsetType) {
4939 #ifdef USE_SK_TX_CHECKSUM
4940 dev->features |= NETIF_F_IP_CSUM;
4943 dev->features |= NETIF_F_SG;
4945 #ifdef USE_SK_RX_CHECKSUM
4946 pAC->RxPort[1].RxCsum = 1;
4950 if (register_netdev(dev)) {
4951 printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4953 pAC->dev[1] = pAC->dev[0];
4955 SkGeProcCreate(dev);
4956 memcpy(&dev->dev_addr,
4957 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4958 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4960 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4961 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4965 /* Save the hardware revision */
4966 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4967 (pAC->GIni.GIPciHwRev & 0x0F);
4969 /* Set driver globals */
4970 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4971 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4973 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4974 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4976 pci_set_drvdata(pdev, dev);
4984 pci_disable_device(pdev);
4989 static void __devexit skge_remove_one(struct pci_dev *pdev)
4991 struct net_device *dev = pci_get_drvdata(pdev);
4992 DEV_NET *pNet = netdev_priv(dev);
4993 SK_AC *pAC = pNet->pAC;
4994 struct net_device *otherdev = pAC->dev[1];
4996 SkGeProcRemove(dev);
4997 unregister_netdev(dev);
4998 if (otherdev != dev)
4999 SkGeProcRemove(otherdev);
5001 SkGeYellowLED(pAC, pAC->IoBase, 0);
5003 if (pAC->BoardLevel == SK_INIT_RUN) {
5005 unsigned long Flags;
5007 /* board is still alive */
5008 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5009 EvPara.Para32[0] = 0;
5010 EvPara.Para32[1] = -1;
5011 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5012 EvPara.Para32[0] = 1;
5013 EvPara.Para32[1] = -1;
5014 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5015 SkEventDispatcher(pAC, pAC->IoBase);
5016 /* disable interrupts */
5017 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5018 SkGeDeInit(pAC, pAC->IoBase);
5019 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5020 pAC->BoardLevel = SK_INIT_DATA;
5021 /* We do NOT check here, if IRQ was pending, of course*/
5024 if (pAC->BoardLevel == SK_INIT_IO) {
5025 /* board is still alive */
5026 SkGeDeInit(pAC, pAC->IoBase);
5027 pAC->BoardLevel = SK_INIT_DATA;
5032 if (otherdev != dev)
5033 free_netdev(otherdev);
5038 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5040 struct net_device *dev = pci_get_drvdata(pdev);
5041 DEV_NET *pNet = netdev_priv(dev);
5042 SK_AC *pAC = pNet->pAC;
5043 struct net_device *otherdev = pAC->dev[1];
5045 if (netif_running(dev)) {
5046 netif_carrier_off(dev);
5047 DoPrintInterfaceChange = SK_FALSE;
5048 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5049 netif_device_detach(dev);
5051 if (otherdev != dev) {
5052 if (netif_running(otherdev)) {
5053 netif_carrier_off(otherdev);
5054 DoPrintInterfaceChange = SK_FALSE;
5055 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5056 netif_device_detach(otherdev);
5060 pci_save_state(pdev);
5061 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5062 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5063 free_irq(dev->irq, dev);
5065 pci_disable_device(pdev);
5066 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5071 static int skge_resume(struct pci_dev *pdev)
5073 struct net_device *dev = pci_get_drvdata(pdev);
5074 DEV_NET *pNet = netdev_priv(dev);
5075 SK_AC *pAC = pNet->pAC;
5076 struct net_device *otherdev = pAC->dev[1];
5079 pci_set_power_state(pdev, PCI_D0);
5080 pci_restore_state(pdev);
5081 pci_enable_device(pdev);
5082 pci_set_master(pdev);
5083 if (pAC->GIni.GIMacsFound == 2)
5084 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5086 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5088 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5089 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5091 pci_disable_device(pdev);
5095 netif_device_attach(dev);
5096 if (netif_running(dev)) {
5097 DoPrintInterfaceChange = SK_FALSE;
5098 SkDrvInitAdapter(pAC, 0); /* first device */
5100 if (otherdev != dev) {
5101 netif_device_attach(otherdev);
5102 if (netif_running(otherdev)) {
5103 DoPrintInterfaceChange = SK_FALSE;
5104 SkDrvInitAdapter(pAC, 1); /* second device */
5111 #define skge_suspend NULL
5112 #define skge_resume NULL
5115 static struct pci_device_id skge_pci_tbl[] = {
5116 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5117 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5118 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5119 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5120 /* DLink card does not have valid VPD so this driver gags
5121 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5123 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5124 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5125 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5126 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5127 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5131 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5133 static struct pci_driver skge_driver = {
5135 .id_table = skge_pci_tbl,
5136 .probe = skge_probe_one,
5137 .remove = __devexit_p(skge_remove_one),
5138 .suspend = skge_suspend,
5139 .resume = skge_resume,
5142 static int __init skge_init(void)
5146 pSkRootDir = proc_mkdir(SKRootName, NULL);
5148 pSkRootDir->owner = THIS_MODULE;
5150 error = pci_register_driver(&skge_driver);
5152 remove_proc_entry(SKRootName, NULL);
5156 static void __exit skge_exit(void)
5158 pci_unregister_driver(&skge_driver);
5159 remove_proc_entry(SKRootName, NULL);
5163 module_init(skge_init);
5164 module_exit(skge_exit);