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 #ifdef USE_SK_RX_CHECKSUM
2193 pMsg->csum = pRxd->TcpSums;
2194 pMsg->ip_summed = CHECKSUM_HW;
2196 pMsg->ip_summed = CHECKSUM_NONE;
2200 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2201 ForRlmt = SK_RLMT_RX_PROTOCOL;
2203 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2205 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2206 IsBc, &Offset, &NumBytes);
2207 if (NumBytes != 0) {
2209 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2211 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2212 &pMsg->data[Offset],
2213 IsBc, IsMc, &ForRlmt);
2215 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2216 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2217 /* send up only frames from active port */
2218 if ((PortIndex == pAC->ActivePort) ||
2219 (pAC->RlmtNets == 2)) {
2220 /* frame for upper layer */
2221 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2223 DumpMsg(pMsg, "Rx");
2225 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2226 FrameLength, pRxPort->PortIndex);
2228 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2229 pMsg->protocol = eth_type_trans(pMsg,
2230 pAC->dev[pRxPort->PortIndex]);
2232 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2236 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2237 SK_DBGCAT_DRV_RX_PROGRESS,
2239 DEV_KFREE_SKB(pMsg);
2242 } /* if not for rlmt */
2244 /* packet for rlmt */
2245 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2246 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2247 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2248 pAC->IoBase, FrameLength);
2249 if (pRlmtMbuf != NULL) {
2250 pRlmtMbuf->pNext = NULL;
2251 pRlmtMbuf->Length = FrameLength;
2252 pRlmtMbuf->PortIdx = PortIndex;
2253 EvPara.pParaPtr = pRlmtMbuf;
2254 memcpy((char*)(pRlmtMbuf->pData),
2255 (char*)(pMsg->data),
2258 /* SlowPathLock needed? */
2259 if (SlowPathLock == SK_TRUE) {
2260 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2261 SkEventQueue(pAC, SKGE_RLMT,
2262 SK_RLMT_PACKET_RECEIVED,
2264 pAC->CheckQueue = SK_TRUE;
2265 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2267 SkEventQueue(pAC, SKGE_RLMT,
2268 SK_RLMT_PACKET_RECEIVED,
2270 pAC->CheckQueue = SK_TRUE;
2273 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2274 SK_DBGCAT_DRV_RX_PROGRESS,
2277 if ((pAC->dev[pRxPort->PortIndex]->flags &
2278 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2279 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2280 SK_RLMT_RX_PROTOCOL) {
2281 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2282 pMsg->protocol = eth_type_trans(pMsg,
2283 pAC->dev[pRxPort->PortIndex]);
2285 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2288 DEV_KFREE_SKB(pMsg);
2291 } /* if packet for rlmt */
2292 } /* for ... scanning the RXD ring */
2294 /* RXD ring is empty -> fill and restart */
2295 FillRxRing(pAC, pRxPort);
2296 /* do not start if called from Close */
2297 if (pAC->BoardLevel > SK_INIT_DATA) {
2298 ClearAndStartRx(pAC, PortIndex);
2303 /* remove error frame */
2304 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2305 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2307 /* release the DMA mapping */
2309 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2310 PhysAddr |= (SK_U64) pRxd->VDataLow;
2311 pci_unmap_page(pAC->PciDev,
2314 PCI_DMA_FROMDEVICE);
2315 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2317 pRxPort->RxdRingFree++;
2318 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2324 /*****************************************************************************
2326 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2329 * This function sends a start command and a clear interrupt
2330 * command for one receive queue to the BMU.
2335 static void ClearAndStartRx(
2336 SK_AC *pAC, /* pointer to the adapter context */
2337 int PortIndex) /* index of the receive port (XMAC) */
2339 SK_OUT8(pAC->IoBase,
2340 RxQueueAddr[PortIndex]+Q_CSR,
2341 CSR_START | CSR_IRQ_CL_F);
2342 } /* ClearAndStartRx */
2345 /*****************************************************************************
2347 * ClearTxIrq - give a clear transmit IRQ command to BMU
2350 * This function sends a clear tx IRQ command for one
2351 * transmit queue to the BMU.
2355 static void ClearTxIrq(
2356 SK_AC *pAC, /* pointer to the adapter context */
2357 int PortIndex, /* index of the transmit port (XMAC) */
2358 int Prio) /* priority or normal queue */
2360 SK_OUT8(pAC->IoBase,
2361 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2366 /*****************************************************************************
2368 * ClearRxRing - remove all buffers from the receive ring
2371 * This function removes all receive buffers from the ring.
2372 * The receive BMU must be stopped before calling this function.
2376 static void ClearRxRing(
2377 SK_AC *pAC, /* pointer to adapter context */
2378 RX_PORT *pRxPort) /* pointer to rx port struct */
2380 RXD *pRxd; /* pointer to the current descriptor */
2381 unsigned long Flags;
2384 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2387 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2388 pRxd = pRxPort->pRxdRingHead;
2390 if (pRxd->pMBuf != NULL) {
2392 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2393 PhysAddr |= (SK_U64) pRxd->VDataLow;
2394 pci_unmap_page(pAC->PciDev,
2397 PCI_DMA_FROMDEVICE);
2398 DEV_KFREE_SKB(pRxd->pMBuf);
2401 pRxd->RBControl &= BMU_OWN;
2402 pRxd = pRxd->pNextRxd;
2403 pRxPort->RxdRingFree++;
2404 } while (pRxd != pRxPort->pRxdRingTail);
2405 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2406 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2409 /*****************************************************************************
2411 * ClearTxRing - remove all buffers from the transmit ring
2414 * This function removes all transmit buffers from the ring.
2415 * The transmit BMU must be stopped before calling this function
2416 * and transmitting at the upper level must be disabled.
2417 * The BMU own bit of all descriptors is cleared, the rest is
2418 * done by calling FreeTxDescriptors.
2422 static void ClearTxRing(
2423 SK_AC *pAC, /* pointer to adapter context */
2424 TX_PORT *pTxPort) /* pointer to tx prt struct */
2426 TXD *pTxd; /* pointer to the current descriptor */
2428 unsigned long Flags;
2430 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2431 pTxd = pTxPort->pTxdRingHead;
2432 for (i=0; i<pAC->TxDescrPerRing; i++) {
2433 pTxd->TBControl &= ~BMU_OWN;
2434 pTxd = pTxd->pNextTxd;
2436 FreeTxDescriptors(pAC, pTxPort);
2437 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2440 /*****************************************************************************
2442 * SkGeSetMacAddr - Set the hardware MAC address
2445 * This function sets the MAC address used by the adapter.
2448 * 0, if everything is ok
2451 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2454 DEV_NET *pNet = netdev_priv(dev);
2455 SK_AC *pAC = pNet->pAC;
2457 struct sockaddr *addr = p;
2458 unsigned long Flags;
2460 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2461 ("SkGeSetMacAddr starts now...\n"));
2462 if(netif_running(dev))
2465 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2467 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2469 if (pAC->RlmtNets == 2)
2470 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2471 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2473 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2474 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2478 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2480 } /* SkGeSetMacAddr */
2483 /*****************************************************************************
2485 * SkGeSetRxMode - set receive mode
2488 * This function sets the receive mode of an adapter. The adapter
2489 * supports promiscuous mode, allmulticast mode and a number of
2490 * multicast addresses. If more multicast addresses the available
2491 * are selected, a hash function in the hardware is used.
2494 * 0, if everything is ok
2497 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2503 struct dev_mc_list *pMcList;
2506 unsigned long Flags;
2508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2509 ("SkGeSetRxMode starts now... "));
2511 pNet = netdev_priv(dev);
2513 if (pAC->RlmtNets == 1)
2514 PortIdx = pAC->ActivePort;
2516 PortIdx = pNet->NetNr;
2518 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2519 if (dev->flags & IFF_PROMISC) {
2520 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2521 ("PROMISCUOUS mode\n"));
2522 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2524 } else if (dev->flags & IFF_ALLMULTI) {
2525 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2526 ("ALLMULTI mode\n"));
2527 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2528 SK_PROM_MODE_ALL_MC);
2530 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2532 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2534 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2535 ("Number of MC entries: %d ", dev->mc_count));
2537 pMcList = dev->mc_list;
2538 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2539 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2540 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2541 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2542 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2543 pMcList->dmi_addr[0],
2544 pMcList->dmi_addr[1],
2545 pMcList->dmi_addr[2],
2546 pMcList->dmi_addr[3],
2547 pMcList->dmi_addr[4],
2548 pMcList->dmi_addr[5]));
2550 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2552 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2555 } /* SkGeSetRxMode */
2558 /*****************************************************************************
2560 * SkGeChangeMtu - set the MTU to another value
2563 * This function sets is called whenever the MTU size is changed
2564 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2565 * ethernet MTU size, long frame support is activated.
2568 * 0, if everything is ok
2571 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2576 unsigned long Flags;
2580 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2581 ("SkGeChangeMtu starts now...\n"));
2583 pNet = netdev_priv(dev);
2586 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2590 if(pAC->BoardLevel != SK_INIT_RUN) {
2594 #ifdef SK_DIAG_SUPPORT
2595 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2596 if (pAC->DiagFlowCtrl == SK_FALSE) {
2597 return -1; /* still in use, deny any actions of MTU */
2599 pAC->DiagFlowCtrl = SK_FALSE;
2605 pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
2606 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
2610 pAC->RxBufSize = NewMtu + 32;
2613 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2614 ("New MTU: %d\n", NewMtu));
2617 ** Prevent any reconfiguration while changing the MTU
2618 ** by disabling any interrupts
2620 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2621 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2624 ** Notify RLMT that any ports are to be stopped
2626 EvPara.Para32[0] = 0;
2627 EvPara.Para32[1] = -1;
2628 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2629 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2630 EvPara.Para32[0] = 1;
2631 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2633 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2637 ** After calling the SkEventDispatcher(), RLMT is aware about
2638 ** the stopped ports -> configuration can take place!
2640 SkEventDispatcher(pAC, pAC->IoBase);
2642 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2643 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2644 netif_stop_queue(pAC->dev[i]);
2649 ** Depending on the desired MTU size change, a different number of
2650 ** RX buffers need to be allocated
2652 if (NewMtu > 1500) {
2654 ** Use less rx buffers
2656 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2657 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2658 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2659 (pAC->RxDescrPerRing / 4);
2661 if (i == pAC->ActivePort) {
2662 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2663 (pAC->RxDescrPerRing / 4);
2665 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2666 (pAC->RxDescrPerRing / 10);
2672 ** Use the normal amount of rx buffers
2674 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2675 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2676 pAC->RxPort[i].RxFillLimit = 1;
2678 if (i == pAC->ActivePort) {
2679 pAC->RxPort[i].RxFillLimit = 1;
2681 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2682 (pAC->RxDescrPerRing / 4);
2688 SkGeDeInit(pAC, pAC->IoBase);
2691 ** enable/disable hardware support for long frames
2693 if (NewMtu > 1500) {
2694 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2695 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2697 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2698 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2700 pAC->GIni.GIPortUsage = SK_RED_LINK;
2704 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2705 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2706 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2707 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2708 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2709 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2710 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2714 ** Speed and others are set back to default in level 1 init!
2716 GetConfiguration(pAC);
2718 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2719 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2720 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2721 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2722 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2723 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2724 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2727 ** clear and reinit the rx rings here
2729 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2730 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2731 ClearRxRing(pAC, &pAC->RxPort[i]);
2732 FillRxRing(pAC, &pAC->RxPort[i]);
2735 ** Enable transmit descriptor polling
2737 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2738 FillRxRing(pAC, &pAC->RxPort[i]);
2741 SkGeYellowLED(pAC, pAC->IoBase, 1);
2742 SkDimEnableModerationIfNeeded(pAC);
2743 SkDimDisplayModerationSettings(pAC);
2745 netif_start_queue(pAC->dev[pNet->PortNr]);
2746 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2747 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2751 ** Enable Interrupts again
2753 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2754 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2756 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2757 SkEventDispatcher(pAC, pAC->IoBase);
2760 ** Notify RLMT about the changing and restarting one (or more) ports
2762 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2763 EvPara.Para32[0] = pAC->RlmtNets;
2764 EvPara.Para32[1] = -1;
2765 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2766 EvPara.Para32[0] = pNet->PortNr;
2767 EvPara.Para32[1] = -1;
2768 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2770 if (pOtherNet->Up) {
2771 EvPara.Para32[0] = pOtherNet->PortNr;
2772 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2775 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2778 SkEventDispatcher(pAC, pAC->IoBase);
2779 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2782 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2783 ** seems as if upper layers have a problem to handle a successful
2784 ** return value of '0'. If such a zero is returned, the complete
2785 ** system hangs for several minutes (!), which is in acceptable.
2787 ** Currently it is not clear, what the exact reason for this problem
2788 ** is. The implemented workaround for 2.5 is to return the desired
2789 ** new MTU size if all needed changes for the new MTU size where
2790 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2791 ** which indicates the successful change of the mtu-size.
2795 } /* SkGeChangeMtu */
2798 /*****************************************************************************
2800 * SkGeStats - return ethernet device statistics
2803 * This function return statistic data about the ethernet device
2804 * to the operating system.
2807 * pointer to the statistic structure.
2809 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2811 DEV_NET *pNet = netdev_priv(dev);
2812 SK_AC *pAC = pNet->pAC;
2813 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2814 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2815 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2816 unsigned int Size; /* size of pnmi struct */
2817 unsigned long Flags; /* for spin lock */
2819 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2820 ("SkGeStats starts now...\n"));
2821 pPnmiStruct = &pAC->PnmiStruct;
2823 #ifdef SK_DIAG_SUPPORT
2824 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2825 (pAC->BoardLevel == SK_INIT_RUN)) {
2827 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2828 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2829 Size = SK_PNMI_STRUCT_SIZE;
2830 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2831 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2832 #ifdef SK_DIAG_SUPPORT
2836 pPnmiStat = &pPnmiStruct->Stat[0];
2837 pPnmiConf = &pPnmiStruct->Conf[0];
2839 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2840 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2841 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2842 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2844 if (pNet->Mtu <= 1500) {
2845 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2847 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2848 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2852 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2853 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2855 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2856 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2857 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2858 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2859 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2861 /* detailed rx_errors: */
2862 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2863 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2864 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2865 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2866 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2867 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2869 /* detailed tx_errors */
2870 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2871 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2872 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2873 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2874 pAC->stats.tx_window_errors = (SK_U32) 0;
2876 return(&pAC->stats);
2880 /*****************************************************************************
2882 * SkGeIoctl - IO-control function
2885 * This function is called if an ioctl is issued on the device.
2886 * There are three subfunction for reading, writing and test-writing
2887 * the private MIB data structure (usefull for SysKonnect-internal tools).
2890 * 0, if everything is ok
2893 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2898 struct pci_dev *pdev = NULL;
2900 unsigned int Err = 0;
2903 unsigned int Length = 0;
2904 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2906 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2907 ("SkGeIoctl starts now...\n"));
2909 pNet = netdev_priv(dev);
2912 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2917 case SK_IOCTL_SETMIB:
2918 case SK_IOCTL_PRESETMIB:
2919 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2920 case SK_IOCTL_GETMIB:
2921 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2922 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2923 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2926 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2927 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2928 Ioctl.Len<Size? Ioctl.Len : Size)) {
2932 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2937 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2940 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2942 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2945 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2949 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2953 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2958 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2963 kfree(pMemBuf); /* cleanup everything */
2965 #ifdef SK_DIAG_SUPPORT
2967 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2968 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2971 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2973 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2976 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2981 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2983 ** While coding this new IOCTL interface, only a few lines of code
2984 ** are to to be added. Therefore no dedicated function has been
2985 ** added. If more functionality is added, a separate function
2986 ** should be used...
2988 * ((SK_U32 *)pMemBuf) = 0;
2989 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2990 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2991 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2996 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3001 kfree(pMemBuf); /* cleanup everything */
3013 /*****************************************************************************
3015 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3018 * This function reads/writes the MIB data using PNMI (Private Network
3019 * Management Interface).
3020 * The destination for the data must be provided with the
3021 * ioctl call and is given to the driver in the form of
3022 * a user space address.
3023 * Copying from the user-provided data area into kernel messages
3024 * and back is done by copy_from_user and copy_to_user calls in
3028 * returned size from PNMI call
3030 static int SkGeIocMib(
3031 DEV_NET *pNet, /* pointer to the adapter context */
3032 unsigned int Size, /* length of ioctl data */
3033 int mode) /* flag for set/preset */
3035 unsigned long Flags; /* for spin lock */
3038 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3039 ("SkGeIocMib starts now...\n"));
3042 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3044 case SK_IOCTL_GETMIB:
3045 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3048 case SK_IOCTL_PRESETMIB:
3049 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3052 case SK_IOCTL_SETMIB:
3053 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3059 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3061 ("MIB data access succeeded\n"));
3066 /*****************************************************************************
3068 * GetConfiguration - read configuration information
3071 * This function reads per-adapter configuration information from
3072 * the options provided on the command line.
3077 static void GetConfiguration(
3078 SK_AC *pAC) /* pointer to the adapter context structure */
3080 SK_I32 Port; /* preferred port */
3083 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3084 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3085 int DuplexCap = 0; /* 0=both,1=full,2=half */
3086 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3087 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3089 SK_BOOL IsConTypeDefined = SK_TRUE;
3090 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3091 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3092 SK_BOOL IsRoleDefined = SK_TRUE;
3093 SK_BOOL IsModeDefined = SK_TRUE;
3095 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3096 * parameter. The mapping is described by this table:
3097 * DuplexCap -> | both | full | half |
3099 * -----------------------------------------------------------------
3100 * Off | illegal | Full | Half |
3101 * -----------------------------------------------------------------
3102 * On | AutoBoth | AutoFull | AutoHalf |
3103 * -----------------------------------------------------------------
3104 * Sense | AutoSense | AutoSense | AutoSense |
3106 int Capabilities[3][3] =
3107 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3108 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3109 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3117 #define M_CurrPort pAC->GIni.GP[Port]
3121 ** Set the default values first for both ports!
3123 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3124 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3125 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3126 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3127 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3131 ** Check merged parameter ConType. If it has not been used,
3132 ** verify any other parameter (e.g. AutoNeg) and use default values.
3134 ** Stating both ConType and other lowlevel link parameters is also
3135 ** possible. If this is the case, the passed ConType-parameter is
3136 ** overwritten by the lowlevel link parameter.
3138 ** The following settings are used for a merged ConType-parameter:
3140 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3141 ** ------- ------ ------- -------- ---------- -----
3142 ** Auto Both On SymOrRem Auto Auto
3143 ** 100FD Full Off None <ignored> 100
3144 ** 100HD Half Off None <ignored> 100
3145 ** 10FD Full Off None <ignored> 10
3146 ** 10HD Half Off None <ignored> 10
3148 ** This ConType parameter is used for all ports of the adapter!
3150 if ( (ConType != NULL) &&
3151 (pAC->Index < SK_MAX_CARD_PARAM) &&
3152 (ConType[pAC->Index] != NULL) ) {
3154 /* Check chipset family */
3155 if ((!pAC->ChipsetType) &&
3156 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3157 (strcmp(ConType[pAC->Index],"")!=0)) {
3158 /* Set the speed parameter back */
3159 printk("sk98lin: Illegal value \"%s\" "
3162 ConType[pAC->Index]);
3164 sprintf(ConType[pAC->Index], "Auto");
3167 if (strcmp(ConType[pAC->Index],"")==0) {
3168 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3169 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3170 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3171 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3172 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3173 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3174 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3176 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3177 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3178 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3179 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3180 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3181 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3183 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3184 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3185 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3186 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3187 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3188 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3190 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3191 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3192 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3193 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3194 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3195 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3197 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3198 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3199 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3200 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3201 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3202 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3205 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3206 ConType[pAC->Index]);
3207 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3210 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3214 ** Parse any parameter settings for port A:
3215 ** a) any LinkSpeed stated?
3217 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3218 Speed_A[pAC->Index] != NULL) {
3219 if (strcmp(Speed_A[pAC->Index],"")==0) {
3220 IsLinkSpeedDefined = SK_FALSE;
3221 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3222 LinkSpeed = SK_LSPEED_AUTO;
3223 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3224 LinkSpeed = SK_LSPEED_10MBPS;
3225 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3226 LinkSpeed = SK_LSPEED_100MBPS;
3227 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3228 LinkSpeed = SK_LSPEED_1000MBPS;
3230 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3231 Speed_A[pAC->Index]);
3232 IsLinkSpeedDefined = SK_FALSE;
3235 IsLinkSpeedDefined = SK_FALSE;
3239 ** Check speed parameter:
3240 ** Only copper type adapter and GE V2 cards
3242 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3243 ((LinkSpeed != SK_LSPEED_AUTO) &&
3244 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3245 printk("sk98lin: Illegal value for Speed_A. "
3246 "Not a copper card or GE V2 card\n Using "
3248 LinkSpeed = SK_LSPEED_1000MBPS;
3252 ** Decide whether to set new config value if somethig valid has
3255 if (IsLinkSpeedDefined) {
3256 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3260 ** b) Any Autonegotiation and DuplexCapabilities set?
3261 ** Please note that both belong together...
3263 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3265 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3266 AutoNeg_A[pAC->Index] != NULL) {
3268 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3270 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3272 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3274 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3277 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3278 AutoNeg_A[pAC->Index]);
3282 DuplexCap = DC_BOTH;
3284 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3285 DupCap_A[pAC->Index] != NULL) {
3287 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3289 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3290 DuplexCap = DC_BOTH;
3291 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3292 DuplexCap = DC_FULL;
3293 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3294 DuplexCap = DC_HALF;
3296 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3297 DupCap_A[pAC->Index]);
3302 ** Check for illegal combinations
3304 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3305 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3306 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3307 (pAC->ChipsetType)) {
3308 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3309 " Using Full Duplex.\n");
3310 DuplexCap = DC_FULL;
3313 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3314 printk("sk98lin, Port A: DuplexCapabilities"
3315 " ignored using Sense mode\n");
3318 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3319 printk("sk98lin: Port A: Illegal combination"
3320 " of values AutoNeg. and DuplexCap.\n Using "
3322 DuplexCap = DC_FULL;
3325 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3326 DuplexCap = DC_FULL;
3329 if (!AutoSet && DupSet) {
3330 printk("sk98lin: Port A: Duplex setting not"
3331 " possible in\n default AutoNegotiation mode"
3332 " (Sense).\n Using AutoNegotiation On\n");
3337 ** set the desired mode
3339 if (AutoSet || DupSet) {
3340 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3344 ** c) Any Flowcontrol-parameter set?
3346 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3347 FlowCtrl_A[pAC->Index] != NULL) {
3348 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3349 IsFlowCtrlDefined = SK_FALSE;
3350 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3351 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3352 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3353 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3354 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3355 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3356 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3357 FlowCtrl = SK_FLOW_MODE_NONE;
3359 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3360 FlowCtrl_A[pAC->Index]);
3361 IsFlowCtrlDefined = SK_FALSE;
3364 IsFlowCtrlDefined = SK_FALSE;
3367 if (IsFlowCtrlDefined) {
3368 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3369 printk("sk98lin: Port A: FlowControl"
3370 " impossible without AutoNegotiation,"
3372 FlowCtrl = SK_FLOW_MODE_NONE;
3374 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3378 ** d) What is with the RoleParameter?
3380 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3381 Role_A[pAC->Index] != NULL) {
3382 if (strcmp(Role_A[pAC->Index],"")==0) {
3383 IsRoleDefined = SK_FALSE;
3384 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3385 MSMode = SK_MS_MODE_AUTO;
3386 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3387 MSMode = SK_MS_MODE_MASTER;
3388 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3389 MSMode = SK_MS_MODE_SLAVE;
3391 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3392 Role_A[pAC->Index]);
3393 IsRoleDefined = SK_FALSE;
3396 IsRoleDefined = SK_FALSE;
3399 if (IsRoleDefined == SK_TRUE) {
3400 pAC->GIni.GP[0].PMSMode = MSMode;
3406 ** Parse any parameter settings for port B:
3407 ** a) any LinkSpeed stated?
3409 IsConTypeDefined = SK_TRUE;
3410 IsLinkSpeedDefined = SK_TRUE;
3411 IsFlowCtrlDefined = SK_TRUE;
3412 IsModeDefined = SK_TRUE;
3414 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3415 Speed_B[pAC->Index] != NULL) {
3416 if (strcmp(Speed_B[pAC->Index],"")==0) {
3417 IsLinkSpeedDefined = SK_FALSE;
3418 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3419 LinkSpeed = SK_LSPEED_AUTO;
3420 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3421 LinkSpeed = SK_LSPEED_10MBPS;
3422 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3423 LinkSpeed = SK_LSPEED_100MBPS;
3424 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3425 LinkSpeed = SK_LSPEED_1000MBPS;
3427 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3428 Speed_B[pAC->Index]);
3429 IsLinkSpeedDefined = SK_FALSE;
3432 IsLinkSpeedDefined = SK_FALSE;
3436 ** Check speed parameter:
3437 ** Only copper type adapter and GE V2 cards
3439 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3440 ((LinkSpeed != SK_LSPEED_AUTO) &&
3441 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3442 printk("sk98lin: Illegal value for Speed_B. "
3443 "Not a copper card or GE V2 card\n Using "
3445 LinkSpeed = SK_LSPEED_1000MBPS;
3449 ** Decide whether to set new config value if somethig valid has
3452 if (IsLinkSpeedDefined) {
3453 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3457 ** b) Any Autonegotiation and DuplexCapabilities set?
3458 ** Please note that both belong together...
3460 AutoNeg = AN_SENS; /* default: do auto Sense */
3462 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3463 AutoNeg_B[pAC->Index] != NULL) {
3465 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3467 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3469 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3471 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3474 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3475 AutoNeg_B[pAC->Index]);
3479 DuplexCap = DC_BOTH;
3481 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3482 DupCap_B[pAC->Index] != NULL) {
3484 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3486 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3487 DuplexCap = DC_BOTH;
3488 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3489 DuplexCap = DC_FULL;
3490 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3491 DuplexCap = DC_HALF;
3493 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3494 DupCap_B[pAC->Index]);
3500 ** Check for illegal combinations
3502 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3503 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3504 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3505 (pAC->ChipsetType)) {
3506 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3507 " Using Full Duplex.\n");
3508 DuplexCap = DC_FULL;
3511 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3512 printk("sk98lin, Port B: DuplexCapabilities"
3513 " ignored using Sense mode\n");
3516 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3517 printk("sk98lin: Port B: Illegal combination"
3518 " of values AutoNeg. and DuplexCap.\n Using "
3520 DuplexCap = DC_FULL;
3523 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3524 DuplexCap = DC_FULL;
3527 if (!AutoSet && DupSet) {
3528 printk("sk98lin: Port B: Duplex setting not"
3529 " possible in\n default AutoNegotiation mode"
3530 " (Sense).\n Using AutoNegotiation On\n");
3535 ** set the desired mode
3537 if (AutoSet || DupSet) {
3538 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3542 ** c) Any FlowCtrl parameter set?
3544 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3545 FlowCtrl_B[pAC->Index] != NULL) {
3546 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3547 IsFlowCtrlDefined = SK_FALSE;
3548 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3549 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3550 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3551 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3552 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3553 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3554 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3555 FlowCtrl = SK_FLOW_MODE_NONE;
3557 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3558 FlowCtrl_B[pAC->Index]);
3559 IsFlowCtrlDefined = SK_FALSE;
3562 IsFlowCtrlDefined = SK_FALSE;
3565 if (IsFlowCtrlDefined) {
3566 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3567 printk("sk98lin: Port B: FlowControl"
3568 " impossible without AutoNegotiation,"
3570 FlowCtrl = SK_FLOW_MODE_NONE;
3572 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3576 ** d) What is the RoleParameter?
3578 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3579 Role_B[pAC->Index] != NULL) {
3580 if (strcmp(Role_B[pAC->Index],"")==0) {
3581 IsRoleDefined = SK_FALSE;
3582 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3583 MSMode = SK_MS_MODE_AUTO;
3584 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3585 MSMode = SK_MS_MODE_MASTER;
3586 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3587 MSMode = SK_MS_MODE_SLAVE;
3589 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3590 Role_B[pAC->Index]);
3591 IsRoleDefined = SK_FALSE;
3594 IsRoleDefined = SK_FALSE;
3597 if (IsRoleDefined) {
3598 pAC->GIni.GP[1].PMSMode = MSMode;
3602 ** Evaluate settings for both ports
3604 pAC->ActivePort = 0;
3605 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3606 PrefPort[pAC->Index] != NULL) {
3607 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3608 pAC->ActivePort = 0;
3609 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3610 pAC->Rlmt.Net[0].PrefPort = 0;
3611 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3613 ** do not set ActivePort here, thus a port
3614 ** switch is issued after net up.
3617 pAC->Rlmt.Net[0].Preference = Port;
3618 pAC->Rlmt.Net[0].PrefPort = Port;
3619 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3621 ** do not set ActivePort here, thus a port
3622 ** switch is issued after net up.
3624 if (pAC->GIni.GIMacsFound == 1) {
3625 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3626 " Port B not available on single port adapters.\n");
3628 pAC->ActivePort = 0;
3629 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3630 pAC->Rlmt.Net[0].PrefPort = 0;
3633 pAC->Rlmt.Net[0].Preference = Port;
3634 pAC->Rlmt.Net[0].PrefPort = Port;
3637 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3638 PrefPort[pAC->Index]);
3644 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3645 RlmtMode[pAC->Index] != NULL) {
3646 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3648 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3649 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3650 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3651 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3652 SK_RLMT_CHECK_LOC_LINK;
3653 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3654 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3655 SK_RLMT_CHECK_LOC_LINK |
3657 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3658 (pAC->GIni.GIMacsFound == 2)) {
3659 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3662 printk("sk98lin: Illegal value \"%s\" for"
3663 " RlmtMode, using default\n",
3664 RlmtMode[pAC->Index]);
3672 ** Check the interrupt moderation parameters
3674 if (Moderation[pAC->Index] != NULL) {
3675 if (strcmp(Moderation[pAC->Index], "") == 0) {
3676 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3677 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3678 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3679 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3680 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3681 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3682 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3684 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3685 " Disable interrupt moderation.\n",
3686 Moderation[pAC->Index]);
3687 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3690 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3693 if (Stats[pAC->Index] != NULL) {
3694 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3695 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3697 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3700 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3703 if (ModerationMask[pAC->Index] != NULL) {
3704 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3705 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3706 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3707 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3708 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3709 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3710 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3711 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3712 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3713 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3714 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3715 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3716 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3717 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3718 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3719 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3720 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3721 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3722 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3723 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3724 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3725 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3726 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3727 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3728 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3729 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3730 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3731 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3732 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3733 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3734 } else { /* some rubbish */
3735 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3737 } else { /* operator has stated nothing */
3738 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3741 if (AutoSizing[pAC->Index] != NULL) {
3742 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3743 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3745 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3747 } else { /* operator has stated nothing */
3748 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3751 if (IntsPerSec[pAC->Index] != 0) {
3752 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3753 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3754 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3755 " Using default value of %i.\n",
3756 IntsPerSec[pAC->Index],
3757 C_INT_MOD_IPS_LOWER_RANGE,
3758 C_INT_MOD_IPS_UPPER_RANGE,
3759 C_INTS_PER_SEC_DEFAULT);
3760 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3762 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3765 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3769 ** Evaluate upper and lower moderation threshold
3771 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3772 pAC->DynIrqModInfo.MaxModIntsPerSec +
3773 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3775 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3776 pAC->DynIrqModInfo.MaxModIntsPerSec -
3777 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3779 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3782 } /* GetConfiguration */
3785 /*****************************************************************************
3787 * ProductStr - return a adapter identification string from vpd
3790 * This function reads the product name string from the vpd area
3791 * and puts it the field pAC->DeviceString.
3795 static void ProductStr(
3796 SK_AC *pAC /* pointer to adapter context */
3799 int StrLen = 80; /* length of the string, defined in SK_AC */
3800 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3801 int ReturnCode; /* return code from vpd_read */
3802 unsigned long Flags;
3804 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3805 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
3807 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3808 if (ReturnCode != 0) {
3809 /* there was an error reading the vpd data */
3810 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
3811 ("Error reading VPD data: %d\n", ReturnCode));
3812 pAC->DeviceStr[0] = '\0';
3816 /*****************************************************************************
3818 * StartDrvCleanupTimer - Start timer to check for descriptors which
3819 * might be placed in descriptor ring, but
3820 * havent been handled up to now
3823 * This function requests a HW-timer fo the Yukon card. The actions to
3824 * perform when this timer expires, are located in the SkDrvEvent().
3829 StartDrvCleanupTimer(SK_AC *pAC) {
3830 SK_EVPARA EventParam; /* Event struct for timer event */
3832 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3833 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3834 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3835 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3836 SKGE_DRV, SK_DRV_TIMER, EventParam);
3839 /*****************************************************************************
3841 * StopDrvCleanupTimer - Stop timer to check for descriptors
3844 * This function requests a HW-timer fo the Yukon card. The actions to
3845 * perform when this timer expires, are located in the SkDrvEvent().
3850 StopDrvCleanupTimer(SK_AC *pAC) {
3851 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3852 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3855 /****************************************************************************/
3856 /* functions for common modules *********************************************/
3857 /****************************************************************************/
3860 /*****************************************************************************
3862 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3865 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3866 * is embedded into a socket buff data area.
3872 * NULL or pointer to Mbuf.
3874 SK_MBUF *SkDrvAllocRlmtMbuf(
3875 SK_AC *pAC, /* pointer to adapter context */
3876 SK_IOC IoC, /* the IO-context */
3877 unsigned BufferSize) /* size of the requested buffer */
3879 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3880 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3882 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3883 if (pMsgBlock == NULL) {
3886 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3887 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3888 pRlmtMbuf->pNext = NULL;
3889 pRlmtMbuf->pOs = pMsgBlock;
3890 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3891 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3892 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3895 } /* SkDrvAllocRlmtMbuf */
3898 /*****************************************************************************
3900 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3903 * This routine frees one or more RLMT mbuf(s).
3911 void SkDrvFreeRlmtMbuf(
3912 SK_AC *pAC, /* pointer to adapter context */
3913 SK_IOC IoC, /* the IO-context */
3914 SK_MBUF *pMbuf) /* size of the requested buffer */
3921 pNextMbuf = pFreeMbuf->pNext;
3922 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3923 pFreeMbuf = pNextMbuf;
3924 } while ( pFreeMbuf != NULL );
3925 } /* SkDrvFreeRlmtMbuf */
3928 /*****************************************************************************
3930 * SkOsGetTime - provide a time value
3933 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3934 * It is not used for absolute time, but only for time differences.
3940 SK_U64 SkOsGetTime(SK_AC *pAC)
3942 SK_U64 PrivateJiffies;
3943 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3944 return PrivateJiffies;
3948 /*****************************************************************************
3950 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3953 * This routine reads a 32 bit value from the pci configuration
3957 * 0 - indicate everything worked ok.
3958 * != 0 - error indication
3960 int SkPciReadCfgDWord(
3961 SK_AC *pAC, /* Adapter Control structure pointer */
3962 int PciAddr, /* PCI register address */
3963 SK_U32 *pVal) /* pointer to store the read value */
3965 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3967 } /* SkPciReadCfgDWord */
3970 /*****************************************************************************
3972 * SkPciReadCfgWord - read a 16 bit value from pci config space
3975 * This routine reads a 16 bit value from the pci configuration
3979 * 0 - indicate everything worked ok.
3980 * != 0 - error indication
3982 int SkPciReadCfgWord(
3983 SK_AC *pAC, /* Adapter Control structure pointer */
3984 int PciAddr, /* PCI register address */
3985 SK_U16 *pVal) /* pointer to store the read value */
3987 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3989 } /* SkPciReadCfgWord */
3992 /*****************************************************************************
3994 * SkPciReadCfgByte - read a 8 bit value from pci config space
3997 * This routine reads a 8 bit value from the pci configuration
4001 * 0 - indicate everything worked ok.
4002 * != 0 - error indication
4004 int SkPciReadCfgByte(
4005 SK_AC *pAC, /* Adapter Control structure pointer */
4006 int PciAddr, /* PCI register address */
4007 SK_U8 *pVal) /* pointer to store the read value */
4009 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4011 } /* SkPciReadCfgByte */
4014 /*****************************************************************************
4016 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4019 * This routine writes a 16 bit value to the pci configuration
4020 * space. The flag PciConfigUp indicates whether the config space
4021 * is accesible or must be set up first.
4024 * 0 - indicate everything worked ok.
4025 * != 0 - error indication
4027 int SkPciWriteCfgWord(
4028 SK_AC *pAC, /* Adapter Control structure pointer */
4029 int PciAddr, /* PCI register address */
4030 SK_U16 Val) /* pointer to store the read value */
4032 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4034 } /* SkPciWriteCfgWord */
4037 /*****************************************************************************
4039 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4042 * This routine writes a 8 bit value to the pci configuration
4043 * space. The flag PciConfigUp indicates whether the config space
4044 * is accesible or must be set up first.
4047 * 0 - indicate everything worked ok.
4048 * != 0 - error indication
4050 int SkPciWriteCfgByte(
4051 SK_AC *pAC, /* Adapter Control structure pointer */
4052 int PciAddr, /* PCI register address */
4053 SK_U8 Val) /* pointer to store the read value */
4055 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4057 } /* SkPciWriteCfgByte */
4060 /*****************************************************************************
4062 * SkDrvEvent - handle driver events
4065 * This function handles events from all modules directed to the driver
4068 * Is called under protection of slow path lock.
4071 * 0 if everything ok
4076 SK_AC *pAC, /* pointer to adapter context */
4077 SK_IOC IoC, /* io-context */
4078 SK_U32 Event, /* event-id */
4079 SK_EVPARA Param) /* event-parameter */
4081 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4082 struct sk_buff *pMsg; /* pointer to a message block */
4083 int FromPort; /* the port from which we switch away */
4084 int ToPort; /* the port we switch to */
4085 SK_EVPARA NewPara; /* parameter for further events */
4087 unsigned long Flags;
4091 case SK_DRV_ADAP_FAIL:
4092 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4093 ("ADAPTER FAIL EVENT\n"));
4094 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4095 /* disable interrupts */
4096 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4099 case SK_DRV_PORT_FAIL:
4100 FromPort = Param.Para32[0];
4101 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4102 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4103 if (FromPort == 0) {
4104 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4106 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4110 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4112 FromPort = Param.Para32[0];
4113 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4114 ("PORT RESET EVENT, Port: %d ", FromPort));
4115 NewPara.Para64 = FromPort;
4116 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4118 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4121 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4122 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4123 spin_unlock_irqrestore(
4124 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4127 /* clear rx ring from received frames */
4128 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4130 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4132 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4135 /* tschilling: Handling of return value inserted. */
4136 if (SkGeInitPort(pAC, IoC, FromPort)) {
4137 if (FromPort == 0) {
4138 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4140 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4143 SkAddrMcUpdate(pAC,IoC, FromPort);
4144 PortReInitBmu(pAC, FromPort);
4145 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4146 ClearAndStartRx(pAC, FromPort);
4147 spin_unlock_irqrestore(
4148 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4151 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4153 FromPort = Param.Para32[0];
4154 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4155 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4157 SkAddrMcUpdate(pAC,IoC, FromPort);
4159 if (DoPrintInterfaceChange) {
4160 printk("%s: network connection up using"
4161 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4163 /* tschilling: Values changed according to LinkSpeedUsed. */
4164 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4165 if (Stat == SK_LSPEED_STAT_10MBPS) {
4166 printk(" speed: 10\n");
4167 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4168 printk(" speed: 100\n");
4169 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4170 printk(" speed: 1000\n");
4172 printk(" speed: unknown\n");
4176 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4177 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4178 Stat == SK_LMODE_STAT_AUTOFULL) {
4179 printk(" autonegotiation: yes\n");
4182 printk(" autonegotiation: no\n");
4184 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4185 Stat == SK_LMODE_STAT_HALF) {
4186 printk(" duplex mode: half\n");
4189 printk(" duplex mode: full\n");
4191 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4192 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4193 printk(" flowctrl: remote send\n");
4195 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4196 printk(" flowctrl: local send\n");
4198 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4199 printk(" flowctrl: symmetric\n");
4202 printk(" flowctrl: none\n");
4205 /* tschilling: Check against CopperType now. */
4206 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4207 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4208 SK_LSPEED_STAT_1000MBPS)) {
4209 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4210 if (Stat == SK_MS_STAT_MASTER ) {
4211 printk(" role: master\n");
4213 else if (Stat == SK_MS_STAT_SLAVE ) {
4214 printk(" role: slave\n");
4217 printk(" role: ???\n");
4222 Display dim (dynamic interrupt moderation)
4225 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4226 printk(" irq moderation: static (%d ints/sec)\n",
4227 pAC->DynIrqModInfo.MaxModIntsPerSec);
4228 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4229 printk(" irq moderation: dynamic (%d ints/sec)\n",
4230 pAC->DynIrqModInfo.MaxModIntsPerSec);
4232 printk(" irq moderation: disabled\n");
4236 if (pAC->ChipsetType)
4237 #ifdef USE_SK_TX_CHECKSUM
4238 printk(" scatter-gather: enabled\n");
4240 printk(" tx-checksum: disabled\n");
4243 printk(" scatter-gather: disabled\n");
4245 printk(" scatter-gather: disabled\n");
4248 #ifndef USE_SK_RX_CHECKSUM
4249 printk(" rx-checksum: disabled\n");
4253 DoPrintInterfaceChange = SK_TRUE;
4256 if ((Param.Para32[0] != pAC->ActivePort) &&
4257 (pAC->RlmtNets == 1)) {
4258 NewPara.Para32[0] = pAC->ActivePort;
4259 NewPara.Para32[1] = Param.Para32[0];
4260 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4264 /* Inform the world that link protocol is up. */
4265 netif_carrier_on(pAC->dev[Param.Para32[0]]);
4268 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4270 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4271 ("NET DOWN EVENT "));
4272 if (DoPrintInterfaceChange) {
4273 printk("%s: network connection down\n",
4274 pAC->dev[Param.Para32[1]]->name);
4276 DoPrintInterfaceChange = SK_TRUE;
4278 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4280 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4281 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4282 ("PORT SWITCH HARD "));
4283 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4285 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4286 'A'+Param.Para32[1]);
4287 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4288 FromPort = Param.Para32[0];
4289 ToPort = Param.Para32[1];
4290 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4291 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4292 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4293 NewPara.Para64 = FromPort;
4294 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4295 NewPara.Para64 = ToPort;
4296 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4298 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4300 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4301 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4302 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4303 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4304 spin_unlock_irqrestore(
4305 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4308 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4309 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4311 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4312 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4314 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4316 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4317 pAC->ActivePort = ToPort;
4321 /* tschilling: New common function with minimum size check. */
4323 if (pAC->RlmtNets == 2) {
4327 if (SkGeInitAssignRamToQueues(
4331 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4332 spin_unlock_irqrestore(
4333 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4335 printk("SkGeInitAssignRamToQueues failed.\n");
4339 /* tschilling: Handling of return values inserted. */
4340 if (SkGeInitPort(pAC, IoC, FromPort) ||
4341 SkGeInitPort(pAC, IoC, ToPort)) {
4342 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4344 if (Event == SK_DRV_SWITCH_SOFT) {
4345 SkMacRxTxEnable(pAC, IoC, FromPort);
4347 SkMacRxTxEnable(pAC, IoC, ToPort);
4348 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4349 SkAddrMcUpdate(pAC, IoC, FromPort);
4350 SkAddrMcUpdate(pAC, IoC, ToPort);
4351 PortReInitBmu(pAC, FromPort);
4352 PortReInitBmu(pAC, ToPort);
4353 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4354 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4355 ClearAndStartRx(pAC, FromPort);
4356 ClearAndStartRx(pAC, ToPort);
4357 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4358 spin_unlock_irqrestore(
4359 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4362 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4363 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4365 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4366 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4367 skb_put(pMsg, pRlmtMbuf->Length);
4368 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4371 DEV_KFREE_SKB_ANY(pMsg);
4374 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4376 ** expiration of the moderation timer implies that
4377 ** dynamic moderation is to be applied
4379 SkDimStartModerationTimer(pAC);
4381 if (pAC->DynIrqModInfo.DisplayStats) {
4382 SkDimDisplayModerationSettings(pAC);
4384 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4386 ** check if we need to check for descriptors which
4387 ** haven't been handled the last millisecs
4389 StartDrvCleanupTimer(pAC);
4390 if (pAC->GIni.GIMacsFound == 2) {
4391 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4393 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4395 printk("Expiration of unknown timer\n");
4401 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4408 /*****************************************************************************
4410 * SkErrorLog - log errors
4413 * This function logs errors to the system buffer and to the console
4416 * 0 if everything ok
4429 case SK_ERRCL_OTHER:
4430 strcpy(ClassStr, "Other error");
4432 case SK_ERRCL_CONFIG:
4433 strcpy(ClassStr, "Configuration error");
4436 strcpy(ClassStr, "Initialization error");
4438 case SK_ERRCL_NORES:
4439 strcpy(ClassStr, "Out of resources error");
4442 strcpy(ClassStr, "internal Software error");
4445 strcpy(ClassStr, "Hardware failure");
4448 strcpy(ClassStr, "Communication error");
4451 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4452 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4453 ClassStr, ErrNum, pErrorMsg);
4457 #ifdef SK_DIAG_SUPPORT
4459 /*****************************************************************************
4461 * SkDrvEnterDiagMode - handles DIAG attach request
4464 * Notify the kernel to NOT access the card any longer due to DIAG
4465 * Deinitialize the Card
4470 int SkDrvEnterDiagMode(
4471 SK_AC *pAc) /* pointer to adapter context */
4473 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4474 SK_AC *pAC = pNet->pAC;
4476 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4477 sizeof(SK_PNMI_STRUCT_DATA));
4479 pAC->DiagModeActive = DIAG_ACTIVE;
4480 if (pAC->BoardLevel > SK_INIT_DATA) {
4482 pAC->WasIfUp[0] = SK_TRUE;
4483 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4484 DoPrintInterfaceChange = SK_FALSE;
4485 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4487 pAC->WasIfUp[0] = SK_FALSE;
4489 if (pNet != netdev_priv(pAC->dev[1])) {
4490 pNet = netdev_priv(pAC->dev[1]);
4492 pAC->WasIfUp[1] = SK_TRUE;
4493 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4494 DoPrintInterfaceChange = SK_FALSE;
4495 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4497 pAC->WasIfUp[1] = SK_FALSE;
4500 pAC->BoardLevel = SK_INIT_DATA;
4505 /*****************************************************************************
4507 * SkDrvLeaveDiagMode - handles DIAG detach request
4510 * Notify the kernel to may access the card again after use by DIAG
4511 * Initialize the Card
4516 int SkDrvLeaveDiagMode(
4517 SK_AC *pAc) /* pointer to adapter control context */
4519 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4520 sizeof(SK_PNMI_STRUCT_DATA));
4521 pAc->DiagModeActive = DIAG_NOTACTIVE;
4522 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4523 if (pAc->WasIfUp[0] == SK_TRUE) {
4524 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4525 DoPrintInterfaceChange = SK_FALSE;
4526 SkDrvInitAdapter(pAc, 0); /* first device */
4528 if (pAc->WasIfUp[1] == SK_TRUE) {
4529 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4530 DoPrintInterfaceChange = SK_FALSE;
4531 SkDrvInitAdapter(pAc, 1); /* second device */
4536 /*****************************************************************************
4538 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4541 * This function parses the PCI slot name information string and will
4542 * retrieve the devcie number out of it. The slot_name maintianed by
4543 * linux is in the form of '02:0a.0', whereas the first two characters
4544 * represent the bus number in hex (in the sample above this is
4545 * pci bus 0x02) and the next two characters the device number (0x0a).
4548 * SK_U32: The device number from the PCI slot name
4551 static SK_U32 ParseDeviceNbrFromSlotName(
4552 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4554 char *CurrCharPos = (char *) SlotName;
4555 int FirstNibble = -1;
4556 int SecondNibble = -1;
4559 while (*CurrCharPos != '\0') {
4560 if (*CurrCharPos == ':') {
4561 while (*CurrCharPos != '.') {
4563 if ( (*CurrCharPos >= '0') &&
4564 (*CurrCharPos <= '9')) {
4565 if (FirstNibble == -1) {
4566 /* dec. value for '0' */
4567 FirstNibble = *CurrCharPos - 48;
4569 SecondNibble = *CurrCharPos - 48;
4571 } else if ( (*CurrCharPos >= 'a') &&
4572 (*CurrCharPos <= 'f') ) {
4573 if (FirstNibble == -1) {
4574 FirstNibble = *CurrCharPos - 87;
4576 SecondNibble = *CurrCharPos - 87;
4583 Result = FirstNibble;
4584 Result = Result << 4; /* first nibble is higher one */
4585 Result = Result | SecondNibble;
4587 CurrCharPos++; /* next character */
4592 /****************************************************************************
4594 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4595 * called if Diag attaches to that card)
4598 * Close initialized adapter.
4602 * error code - on error
4604 static int SkDrvDeInitAdapter(
4605 SK_AC *pAC, /* pointer to adapter context */
4606 int devNbr) /* what device is to be handled */
4608 struct SK_NET_DEVICE *dev;
4610 dev = pAC->dev[devNbr];
4612 /* On Linux 2.6 the network driver does NOT mess with reference
4613 ** counts. The driver MUST be able to be unloaded at any time
4614 ** due to the possibility of hotplug.
4616 if (SkGeClose(dev) != 0) {
4621 } /* SkDrvDeInitAdapter() */
4623 /****************************************************************************
4625 * SkDrvInitAdapter - Initialize adapter (this function is only
4626 * called if Diag deattaches from that card)
4629 * Close initialized adapter.
4633 * error code - on error
4635 static int SkDrvInitAdapter(
4636 SK_AC *pAC, /* pointer to adapter context */
4637 int devNbr) /* what device is to be handled */
4639 struct SK_NET_DEVICE *dev;
4641 dev = pAC->dev[devNbr];
4643 if (SkGeOpen(dev) != 0) {
4648 ** Use correct MTU size and indicate to kernel TX queue can be started
4650 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4655 } /* SkDrvInitAdapter */
4660 /****************************************************************************/
4661 /* "debug only" section *****************************************************/
4662 /****************************************************************************/
4665 /*****************************************************************************
4667 * DumpMsg - print a frame
4670 * This function prints frames to the system logfile/to the console.
4675 static void DumpMsg(struct sk_buff *skb, char *str)
4680 printk("DumpMsg(): NULL-Message\n");
4684 if (skb->data == NULL) {
4685 printk("DumpMsg(): Message empty\n");
4693 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4695 DumpData((char *)skb->data, msglen);
4697 printk("------- End of message ---------\n");
4702 /*****************************************************************************
4704 * DumpData - print a data area
4707 * This function prints a area of data to the system logfile/to the
4713 static void DumpData(char *p, int size)
4717 char hex_buffer[180];
4718 char asc_buffer[180];
4719 char HEXCHAR[] = "0123456789ABCDEF";
4725 for (i=0; i < size; ) {
4726 if (*p >= '0' && *p <='z')
4727 asc_buffer[addr] = *p;
4729 asc_buffer[addr] = '.';
4731 asc_buffer[addr] = 0;
4732 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4734 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4736 hex_buffer[haddr] = ' ';
4738 hex_buffer[haddr] = 0;
4742 printk("%s %s\n", hex_buffer, asc_buffer);
4750 /*****************************************************************************
4752 * DumpLong - print a data area as long values
4755 * This function prints a area of data to the system logfile/to the
4761 static void DumpLong(char *pc, int size)
4765 char hex_buffer[180];
4766 char asc_buffer[180];
4767 char HEXCHAR[] = "0123456789ABCDEF";
4776 for (i=0; i < size; ) {
4778 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4780 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4782 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4784 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4786 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4788 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4790 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4792 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4794 hex_buffer[haddr] = ' ';
4796 hex_buffer[haddr] = 0;
4800 printk("%4x %s\n", (i-8)*4, hex_buffer);
4804 printk("------------------------\n");
4809 static int __devinit skge_probe_one(struct pci_dev *pdev,
4810 const struct pci_device_id *ent)
4813 DEV_NET *pNet = NULL;
4814 struct net_device *dev = NULL;
4815 static int boards_found = 0;
4816 int error = -ENODEV;
4818 if (pci_enable_device(pdev))
4821 /* Configure DMA attributes. */
4822 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4823 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4824 goto out_disable_device;
4827 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4828 printk(KERN_ERR "Unable to allocate etherdev "
4830 goto out_disable_device;
4833 pNet = netdev_priv(dev);
4834 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4836 printk(KERN_ERR "Unable to allocate adapter "
4838 goto out_free_netdev;
4841 memset(pNet->pAC, 0, sizeof(SK_AC));
4844 pAC->PciDevId = pdev->device;
4847 sprintf(pAC->Name, "SysKonnect SK-98xx");
4848 pAC->CheckQueue = SK_FALSE;
4852 dev->irq = pdev->irq;
4853 error = SkGeInitPCI(pAC);
4855 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4856 goto out_free_netdev;
4859 SET_MODULE_OWNER(dev);
4860 dev->open = &SkGeOpen;
4861 dev->stop = &SkGeClose;
4862 dev->hard_start_xmit = &SkGeXmit;
4863 dev->get_stats = &SkGeStats;
4864 dev->set_multicast_list = &SkGeSetRxMode;
4865 dev->set_mac_address = &SkGeSetMacAddr;
4866 dev->do_ioctl = &SkGeIoctl;
4867 dev->change_mtu = &SkGeChangeMtu;
4868 #ifdef CONFIG_NET_POLL_CONTROLLER
4869 dev->poll_controller = &SkGePollController;
4871 SET_NETDEV_DEV(dev, &pdev->dev);
4872 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4875 #ifdef USE_SK_TX_CHECKSUM
4876 if (pAC->ChipsetType) {
4877 /* Use only if yukon hardware */
4878 /* SK and ZEROCOPY - fly baby... */
4879 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4884 pAC->Index = boards_found++;
4886 if (SkGeBoardInit(dev, pAC))
4887 goto out_free_netdev;
4889 /* Register net device */
4890 if (register_netdev(dev)) {
4891 printk(KERN_ERR "sk98lin: Could not register device.\n");
4892 goto out_free_resources;
4895 /* Print adapter specific string from vpd */
4897 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4899 /* Print configuration settings */
4900 printk(" PrefPort:%c RlmtMode:%s\n",
4901 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4902 (pAC->RlmtMode==0) ? "Check Link State" :
4903 ((pAC->RlmtMode==1) ? "Check Link State" :
4904 ((pAC->RlmtMode==3) ? "Check Local Port" :
4905 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4906 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4908 SkGeYellowLED(pAC, pAC->IoBase, 1);
4910 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4911 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4913 SkGeProcCreate(dev);
4920 /* More then one port found */
4921 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4922 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4923 printk(KERN_ERR "Unable to allocate etherdev "
4929 pNet = netdev_priv(dev);
4936 dev->open = &SkGeOpen;
4937 dev->stop = &SkGeClose;
4938 dev->hard_start_xmit = &SkGeXmit;
4939 dev->get_stats = &SkGeStats;
4940 dev->set_multicast_list = &SkGeSetRxMode;
4941 dev->set_mac_address = &SkGeSetMacAddr;
4942 dev->do_ioctl = &SkGeIoctl;
4943 dev->change_mtu = &SkGeChangeMtu;
4944 SET_NETDEV_DEV(dev, &pdev->dev);
4945 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4948 #ifdef USE_SK_TX_CHECKSUM
4949 if (pAC->ChipsetType) {
4950 /* SG and ZEROCOPY - fly baby... */
4951 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
4956 if (register_netdev(dev)) {
4957 printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4959 pAC->dev[1] = pAC->dev[0];
4961 SkGeProcCreate(dev);
4962 memcpy(&dev->dev_addr,
4963 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4964 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4966 printk("%s: %s\n", dev->name, pAC->DeviceStr);
4967 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4971 /* Save the hardware revision */
4972 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4973 (pAC->GIni.GIPciHwRev & 0x0F);
4975 /* Set driver globals */
4976 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4977 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4979 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4980 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4982 pci_set_drvdata(pdev, dev);
4990 pci_disable_device(pdev);
4995 static void __devexit skge_remove_one(struct pci_dev *pdev)
4997 struct net_device *dev = pci_get_drvdata(pdev);
4998 DEV_NET *pNet = netdev_priv(dev);
4999 SK_AC *pAC = pNet->pAC;
5000 struct net_device *otherdev = pAC->dev[1];
5002 SkGeProcRemove(dev);
5003 unregister_netdev(dev);
5004 if (otherdev != dev)
5005 SkGeProcRemove(otherdev);
5007 SkGeYellowLED(pAC, pAC->IoBase, 0);
5009 if (pAC->BoardLevel == SK_INIT_RUN) {
5011 unsigned long Flags;
5013 /* board is still alive */
5014 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5015 EvPara.Para32[0] = 0;
5016 EvPara.Para32[1] = -1;
5017 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5018 EvPara.Para32[0] = 1;
5019 EvPara.Para32[1] = -1;
5020 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5021 SkEventDispatcher(pAC, pAC->IoBase);
5022 /* disable interrupts */
5023 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5024 SkGeDeInit(pAC, pAC->IoBase);
5025 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5026 pAC->BoardLevel = SK_INIT_DATA;
5027 /* We do NOT check here, if IRQ was pending, of course*/
5030 if (pAC->BoardLevel == SK_INIT_IO) {
5031 /* board is still alive */
5032 SkGeDeInit(pAC, pAC->IoBase);
5033 pAC->BoardLevel = SK_INIT_DATA;
5038 if (otherdev != dev)
5039 free_netdev(otherdev);
5044 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5046 struct net_device *dev = pci_get_drvdata(pdev);
5047 DEV_NET *pNet = netdev_priv(dev);
5048 SK_AC *pAC = pNet->pAC;
5049 struct net_device *otherdev = pAC->dev[1];
5051 if (netif_running(dev)) {
5052 netif_carrier_off(dev);
5053 DoPrintInterfaceChange = SK_FALSE;
5054 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5055 netif_device_detach(dev);
5057 if (otherdev != dev) {
5058 if (netif_running(otherdev)) {
5059 netif_carrier_off(otherdev);
5060 DoPrintInterfaceChange = SK_FALSE;
5061 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5062 netif_device_detach(otherdev);
5066 pci_save_state(pdev);
5067 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5068 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5069 free_irq(dev->irq, dev);
5071 pci_disable_device(pdev);
5072 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5077 static int skge_resume(struct pci_dev *pdev)
5079 struct net_device *dev = pci_get_drvdata(pdev);
5080 DEV_NET *pNet = netdev_priv(dev);
5081 SK_AC *pAC = pNet->pAC;
5082 struct net_device *otherdev = pAC->dev[1];
5085 pci_set_power_state(pdev, PCI_D0);
5086 pci_restore_state(pdev);
5087 pci_enable_device(pdev);
5088 pci_set_master(pdev);
5089 if (pAC->GIni.GIMacsFound == 2)
5090 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5092 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5094 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5095 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5097 pci_disable_device(pdev);
5101 netif_device_attach(dev);
5102 if (netif_running(dev)) {
5103 DoPrintInterfaceChange = SK_FALSE;
5104 SkDrvInitAdapter(pAC, 0); /* first device */
5106 if (otherdev != dev) {
5107 netif_device_attach(otherdev);
5108 if (netif_running(otherdev)) {
5109 DoPrintInterfaceChange = SK_FALSE;
5110 SkDrvInitAdapter(pAC, 1); /* second device */
5117 #define skge_suspend NULL
5118 #define skge_resume NULL
5121 static struct pci_device_id skge_pci_tbl[] = {
5122 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5123 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5124 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5125 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5126 /* DLink card does not have valid VPD so this driver gags
5127 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5129 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5130 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5131 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5132 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5133 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5137 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5139 static struct pci_driver skge_driver = {
5141 .id_table = skge_pci_tbl,
5142 .probe = skge_probe_one,
5143 .remove = __devexit_p(skge_remove_one),
5144 .suspend = skge_suspend,
5145 .resume = skge_resume,
5148 static int __init skge_init(void)
5152 pSkRootDir = proc_mkdir(SKRootName, NULL);
5154 pSkRootDir->owner = THIS_MODULE;
5156 error = pci_register_driver(&skge_driver);
5158 remove_proc_entry(SKRootName, NULL);
5162 static void __exit skge_exit(void)
5164 pci_unregister_driver(&skge_driver);
5165 remove_proc_entry(SKRootName, NULL);
5169 module_init(skge_init);
5170 module_exit(skge_exit);