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 int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
210 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
211 static void FillRxRing(SK_AC*, RX_PORT*);
212 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
213 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
214 static void ClearAndStartRx(SK_AC*, int);
215 static void ClearTxIrq(SK_AC*, int, int);
216 static void ClearRxRing(SK_AC*, RX_PORT*);
217 static void ClearTxRing(SK_AC*, TX_PORT*);
218 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
219 static void PortReInitBmu(SK_AC*, int);
220 static int SkGeIocMib(DEV_NET*, unsigned int, int);
221 static int SkGeInitPCI(SK_AC *pAC);
222 static void StartDrvCleanupTimer(SK_AC *pAC);
223 static void StopDrvCleanupTimer(SK_AC *pAC);
224 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
226 #ifdef SK_DIAG_SUPPORT
227 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
228 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
229 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
232 /*******************************************************************************
234 * Extern Function Prototypes
236 ******************************************************************************/
237 static const char SKRootName[] = "net/sk98lin";
238 static struct proc_dir_entry *pSkRootDir;
239 extern struct file_operations sk_proc_fops;
241 static inline void SkGeProcCreate(struct net_device *dev)
243 struct proc_dir_entry *pe;
246 (pe = create_proc_entry(dev->name, S_IRUGO, pSkRootDir))) {
247 pe->proc_fops = &sk_proc_fops;
249 pe->owner = THIS_MODULE;
253 static inline void SkGeProcRemove(struct net_device *dev)
256 remove_proc_entry(dev->name, pSkRootDir);
259 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
260 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
261 extern void SkDimStartModerationTimer(SK_AC *pAC);
262 extern void SkDimModerate(SK_AC *pAC);
263 extern void SkGeBlinkTimer(unsigned long data);
266 static void DumpMsg(struct sk_buff*, char*);
267 static void DumpData(char*, int);
268 static void DumpLong(char*, int);
271 /* global variables *********************************************************/
272 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
273 extern struct ethtool_ops SkGeEthtoolOps;
275 /* local variables **********************************************************/
276 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
277 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
279 /*****************************************************************************
281 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
284 * This routine writes a 32 bit value to the pci configuration
288 * 0 - indicate everything worked ok.
289 * != 0 - error indication
291 static inline int SkPciWriteCfgDWord(
292 SK_AC *pAC, /* Adapter Control structure pointer */
293 int PciAddr, /* PCI register address */
294 SK_U32 Val) /* pointer to store the read value */
296 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
298 } /* SkPciWriteCfgDWord */
300 /*****************************************************************************
302 * SkGeInitPCI - Init the PCI resources
305 * This function initialize the PCI resources and IO
310 int SkGeInitPCI(SK_AC *pAC)
312 struct SK_NET_DEVICE *dev = pAC->dev[0];
313 struct pci_dev *pdev = pAC->PciDev;
316 if (pci_enable_device(pdev) != 0) {
320 dev->mem_start = pci_resource_start (pdev, 0);
321 pci_set_master(pdev);
323 if (pci_request_regions(pdev, "sk98lin") != 0) {
330 * On big endian machines, we use the adapter's aibility of
331 * reading the descriptors as big endian.
335 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
336 our2 |= PCI_REV_DESC;
337 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
342 * Remap the regs into kernel space.
344 pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
354 pci_release_regions(pdev);
356 pci_disable_device(pdev);
361 /*****************************************************************************
363 * FreeResources - release resources allocated for adapter
366 * This function releases the IRQ, unmaps the IO and
367 * frees the desriptor ring.
372 static void FreeResources(struct SK_NET_DEVICE *dev)
378 pNet = netdev_priv(dev);
380 AllocFlag = pAC->AllocFlag;
382 pci_release_regions(pAC->PciDev);
384 if (AllocFlag & SK_ALLOC_IRQ) {
385 free_irq(dev->irq, dev);
388 iounmap(pAC->IoBase);
390 if (pAC->pDescrMem) {
394 } /* FreeResources */
396 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
397 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
398 MODULE_LICENSE("GPL");
401 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
403 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
407 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
409 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
413 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
415 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
419 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
421 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
425 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
427 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
431 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
433 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
437 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
439 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
443 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
445 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
449 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
451 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
455 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
457 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
461 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
463 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
467 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
469 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
473 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
475 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
478 static int IntsPerSec[SK_MAX_CARD_PARAM];
479 static char *Moderation[SK_MAX_CARD_PARAM];
480 static char *ModerationMask[SK_MAX_CARD_PARAM];
481 static char *AutoSizing[SK_MAX_CARD_PARAM];
482 static char *Stats[SK_MAX_CARD_PARAM];
484 module_param_array(Speed_A, charp, NULL, 0);
485 module_param_array(Speed_B, charp, NULL, 0);
486 module_param_array(AutoNeg_A, charp, NULL, 0);
487 module_param_array(AutoNeg_B, charp, NULL, 0);
488 module_param_array(DupCap_A, charp, NULL, 0);
489 module_param_array(DupCap_B, charp, NULL, 0);
490 module_param_array(FlowCtrl_A, charp, NULL, 0);
491 module_param_array(FlowCtrl_B, charp, NULL, 0);
492 module_param_array(Role_A, charp, NULL, 0);
493 module_param_array(Role_B, charp, NULL, 0);
494 module_param_array(ConType, charp, NULL, 0);
495 module_param_array(PrefPort, charp, NULL, 0);
496 module_param_array(RlmtMode, charp, NULL, 0);
497 /* used for interrupt moderation */
498 module_param_array(IntsPerSec, int, NULL, 0);
499 module_param_array(Moderation, charp, NULL, 0);
500 module_param_array(Stats, charp, NULL, 0);
501 module_param_array(ModerationMask, charp, NULL, 0);
502 module_param_array(AutoSizing, charp, NULL, 0);
504 /*****************************************************************************
506 * SkGeBoardInit - do level 0 and 1 initialization
509 * This function prepares the board hardware for running. The desriptor
510 * ring is set up, the IRQ is allocated and the configuration settings
514 * 0, if everything is ok
517 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
521 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
522 char *VerStr = VER_STRING;
523 int Ret; /* return code of request_irq */
526 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
527 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
528 for (i=0; i<SK_MAX_MACS; i++) {
529 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
530 pAC->TxPort[i][0].PortIndex = i;
531 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
532 pAC->RxPort[i].PortIndex = i;
535 /* Initialize the mutexes */
536 for (i=0; i<SK_MAX_MACS; i++) {
537 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
538 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
540 spin_lock_init(&pAC->SlowPathLock);
542 /* setup phy_id blink timer */
543 pAC->BlinkTimer.function = SkGeBlinkTimer;
544 pAC->BlinkTimer.data = (unsigned long) dev;
545 init_timer(&pAC->BlinkTimer);
547 /* level 0 init common modules here */
549 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
550 /* Does a RESET on board ...*/
551 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
552 printk("HWInit (0) failed.\n");
553 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
556 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
557 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
558 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
559 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
560 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
561 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
563 pAC->BoardLevel = SK_INIT_DATA;
564 pAC->RxBufSize = ETH_BUF_SIZE;
566 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
567 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
569 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
571 /* level 1 init common modules here (HW init) */
572 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
573 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
574 printk("sk98lin: HWInit (1) failed.\n");
575 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
578 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
579 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
580 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
581 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
582 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
583 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
585 /* Set chipset type support */
586 pAC->ChipsetType = 0;
587 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
588 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
589 pAC->ChipsetType = 1;
592 GetConfiguration(pAC);
593 if (pAC->RlmtNets == 2) {
594 pAC->GIni.GIPortUsage = SK_MUL_LINK;
597 pAC->BoardLevel = SK_INIT_IO;
598 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
600 if (pAC->GIni.GIMacsFound == 2) {
601 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
602 } else if (pAC->GIni.GIMacsFound == 1) {
603 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
606 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
607 pAC->GIni.GIMacsFound);
612 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
616 pAC->AllocFlag |= SK_ALLOC_IRQ;
618 /* Alloc memory for this board (Mem for RxD/TxD) : */
619 if(!BoardAllocMem(pAC)) {
620 printk("No memory for descriptor rings.\n");
625 /* tschilling: New common function with minimum size check. */
627 if (pAC->RlmtNets == 2) {
631 if (SkGeInitAssignRamToQueues(
636 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
641 } /* SkGeBoardInit */
644 /*****************************************************************************
646 * BoardAllocMem - allocate the memory for the descriptor rings
649 * This function allocates the memory for all descriptor rings.
650 * Each ring is aligned for the desriptor alignment and no ring
651 * has a 4 GByte boundary in it (because the upper 32 bit must
652 * be constant for all descriptiors in one rings).
655 * SK_TRUE, if all memory could be allocated
658 static SK_BOOL BoardAllocMem(
661 caddr_t pDescrMem; /* pointer to descriptor memory area */
662 size_t AllocLength; /* length of complete descriptor area */
663 int i; /* loop counter */
664 unsigned long BusAddr;
667 /* rings plus one for alignment (do not cross 4 GB boundary) */
668 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
669 #if (BITS_PER_LONG == 32)
670 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
672 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
676 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
679 if (pDescrMem == NULL) {
682 pAC->pDescrMem = pDescrMem;
683 BusAddr = (unsigned long) pAC->pDescrMemDMA;
685 /* Descriptors need 8 byte alignment, and this is ensured
686 * by pci_alloc_consistent.
688 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
689 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
690 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
691 i, (unsigned long) pDescrMem,
693 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
694 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
695 pDescrMem += TX_RING_SIZE;
696 BusAddr += TX_RING_SIZE;
698 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
699 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
700 i, (unsigned long) pDescrMem,
701 (unsigned long)BusAddr));
702 pAC->RxPort[i].pRxDescrRing = pDescrMem;
703 pAC->RxPort[i].VRxDescrRing = BusAddr;
704 pDescrMem += RX_RING_SIZE;
705 BusAddr += RX_RING_SIZE;
709 } /* BoardAllocMem */
712 /****************************************************************************
714 * BoardFreeMem - reverse of BoardAllocMem
717 * Free all memory allocated in BoardAllocMem: adapter context,
718 * descriptor rings, locks.
722 static void BoardFreeMem(
725 size_t AllocLength; /* length of complete descriptor area */
727 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
729 #if (BITS_PER_LONG == 32)
730 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
732 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
736 pci_free_consistent(pAC->PciDev, AllocLength,
737 pAC->pDescrMem, pAC->pDescrMemDMA);
738 pAC->pDescrMem = NULL;
742 /*****************************************************************************
744 * BoardInitMem - initiate the descriptor rings
747 * This function sets the descriptor rings up in memory.
748 * The adapter is initialized with the descriptor start addresses.
752 static void BoardInitMem(
753 SK_AC *pAC) /* pointer to adapter context */
755 int i; /* loop counter */
756 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
757 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
759 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
762 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
763 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
764 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
765 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
767 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
770 pAC->TxPort[i][0].pTxDescrRing,
771 pAC->TxPort[i][0].VTxDescrRing,
772 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
773 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
774 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
775 &pAC->TxPort[i][0].TxdRingFree,
779 pAC->RxPort[i].pRxDescrRing,
780 pAC->RxPort[i].VRxDescrRing,
781 &pAC->RxPort[i].pRxdRingHead,
782 &pAC->RxPort[i].pRxdRingTail,
783 &pAC->RxPort[i].pRxdRingPrev,
784 &pAC->RxPort[i].RxdRingFree,
790 /*****************************************************************************
792 * SetupRing - create one descriptor ring
795 * This function creates one descriptor ring in the given memory area.
796 * The head, tail and number of free descriptors in the ring are set.
801 static void SetupRing(
803 void *pMemArea, /* a pointer to the memory area for the ring */
804 uintptr_t VMemArea, /* the virtual bus address of the memory area */
805 RXD **ppRingHead, /* address where the head should be written */
806 RXD **ppRingTail, /* address where the tail should be written */
807 RXD **ppRingPrev, /* address where the tail should be written */
808 int *pRingFree, /* address where the # of free descr. goes */
809 SK_BOOL IsTx) /* flag: is this a tx ring */
811 int i; /* loop counter */
812 int DescrSize; /* the size of a descriptor rounded up to alignment*/
813 int DescrNum; /* number of descriptors per ring */
814 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
815 RXD *pNextDescr; /* pointer to the next descriptor */
816 RXD *pPrevDescr; /* pointer to the previous descriptor */
817 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
819 if (IsTx == SK_TRUE) {
820 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
822 DescrNum = TX_RING_SIZE / DescrSize;
824 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
826 DescrNum = RX_RING_SIZE / DescrSize;
829 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
830 ("Descriptor size: %d Descriptor Number: %d\n",
831 DescrSize,DescrNum));
833 pDescr = (RXD*) pMemArea;
835 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
836 VNextDescr = VMemArea + DescrSize;
837 for(i=0; i<DescrNum; i++) {
838 /* set the pointers right */
839 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
840 pDescr->pNextRxd = pNextDescr;
841 pDescr->TcpSumStarts = 0;
843 /* advance one step */
846 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
847 VNextDescr += DescrSize;
849 pPrevDescr->pNextRxd = (RXD*) pMemArea;
850 pPrevDescr->VNextRxd = VMemArea;
851 pDescr = (RXD*) pMemArea;
852 *ppRingHead = (RXD*) pMemArea;
853 *ppRingTail = *ppRingHead;
854 *ppRingPrev = pPrevDescr;
855 *pRingFree = DescrNum;
859 /*****************************************************************************
861 * PortReInitBmu - re-initiate the descriptor rings for one port
864 * This function reinitializes the descriptor rings of one port
865 * in memory. The port must be stopped before.
866 * The HW is initialized with the descriptor start addresses.
871 static void PortReInitBmu(
872 SK_AC *pAC, /* pointer to adapter context */
873 int PortIndex) /* index of the port for which to re-init */
875 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
878 /* set address of first descriptor of ring in BMU */
879 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
880 (uint32_t)(((caddr_t)
881 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
882 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
883 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
885 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
886 (uint32_t)(((caddr_t)
887 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
888 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
889 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
890 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
891 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
892 pAC->RxPort[PortIndex].pRxDescrRing +
893 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
894 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
895 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
896 pAC->RxPort[PortIndex].pRxDescrRing +
897 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
898 } /* PortReInitBmu */
901 /****************************************************************************
903 * SkGeIsr - handle adapter interrupts
906 * The interrupt routine is called when the network adapter
907 * generates an interrupt. It may also be called if another device
908 * shares this interrupt vector with the driver.
913 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
915 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
918 SK_U32 IntSrc; /* interrupts source register contents */
920 pNet = netdev_priv(dev);
924 * Check and process if its our interrupt
926 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
931 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
932 #if 0 /* software irq currently not used */
933 if (IntSrc & IS_IRQ_SW) {
934 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
935 SK_DBGCAT_DRV_INT_SRC,
939 if (IntSrc & IS_R1_F) {
940 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
941 SK_DBGCAT_DRV_INT_SRC,
943 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
944 SK_PNMI_CNT_RX_INTR(pAC, 0);
946 if (IntSrc & IS_R2_F) {
947 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
948 SK_DBGCAT_DRV_INT_SRC,
950 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
951 SK_PNMI_CNT_RX_INTR(pAC, 1);
953 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
954 if (IntSrc & IS_XA1_F) {
955 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
956 SK_DBGCAT_DRV_INT_SRC,
957 ("EOF AS TX1 IRQ\n"));
958 SK_PNMI_CNT_TX_INTR(pAC, 0);
959 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
960 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
961 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
963 if (IntSrc & IS_XA2_F) {
964 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
965 SK_DBGCAT_DRV_INT_SRC,
966 ("EOF AS TX2 IRQ\n"));
967 SK_PNMI_CNT_TX_INTR(pAC, 1);
968 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
969 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
970 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
972 #if 0 /* only if sync. queues used */
973 if (IntSrc & IS_XS1_F) {
974 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
975 SK_DBGCAT_DRV_INT_SRC,
976 ("EOF SY TX1 IRQ\n"));
977 SK_PNMI_CNT_TX_INTR(pAC, 1);
978 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
979 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
980 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
981 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
983 if (IntSrc & IS_XS2_F) {
984 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
985 SK_DBGCAT_DRV_INT_SRC,
986 ("EOF SY TX2 IRQ\n"));
987 SK_PNMI_CNT_TX_INTR(pAC, 1);
988 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
989 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
990 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
991 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
996 /* do all IO at once */
997 if (IntSrc & IS_R1_F)
998 ClearAndStartRx(pAC, 0);
999 if (IntSrc & IS_R2_F)
1000 ClearAndStartRx(pAC, 1);
1001 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1002 if (IntSrc & IS_XA1_F)
1003 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1004 if (IntSrc & IS_XA2_F)
1005 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1007 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1008 } /* while (IntSrc & IRQ_MASK != 0) */
1010 IntSrc &= pAC->GIni.GIValIrqMask;
1011 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1012 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1013 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1014 pAC->CheckQueue = SK_FALSE;
1015 spin_lock(&pAC->SlowPathLock);
1016 if (IntSrc & SPECIAL_IRQS)
1017 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1019 SkEventDispatcher(pAC, pAC->IoBase);
1020 spin_unlock(&pAC->SlowPathLock);
1023 * do it all again is case we cleared an interrupt that
1024 * came in after handling the ring (OUTs may be delayed
1025 * in hardware buffers, but are through after IN)
1027 * rroesler: has been commented out and shifted to
1028 * SkGeDrvEvent(), because it is timer
1031 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1032 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1035 if (pAC->CheckQueue) {
1036 pAC->CheckQueue = SK_FALSE;
1037 spin_lock(&pAC->SlowPathLock);
1038 SkEventDispatcher(pAC, pAC->IoBase);
1039 spin_unlock(&pAC->SlowPathLock);
1042 /* IRQ is processed - Enable IRQs again*/
1043 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1045 return SkIsrRetHandled;
1049 /****************************************************************************
1051 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1054 * The interrupt routine is called when the network adapter
1055 * generates an interrupt. It may also be called if another device
1056 * shares this interrupt vector with the driver.
1057 * This is the same as above, but handles only one port.
1062 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1064 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1067 SK_U32 IntSrc; /* interrupts source register contents */
1069 pNet = netdev_priv(dev);
1073 * Check and process if its our interrupt
1075 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1077 return SkIsrRetNone;
1080 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1081 #if 0 /* software irq currently not used */
1082 if (IntSrc & IS_IRQ_SW) {
1083 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1084 SK_DBGCAT_DRV_INT_SRC,
1085 ("Software IRQ\n"));
1088 if (IntSrc & IS_R1_F) {
1089 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1090 SK_DBGCAT_DRV_INT_SRC,
1092 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1093 SK_PNMI_CNT_RX_INTR(pAC, 0);
1095 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1096 if (IntSrc & IS_XA1_F) {
1097 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1098 SK_DBGCAT_DRV_INT_SRC,
1099 ("EOF AS TX1 IRQ\n"));
1100 SK_PNMI_CNT_TX_INTR(pAC, 0);
1101 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1102 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1103 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1105 #if 0 /* only if sync. queues used */
1106 if (IntSrc & IS_XS1_F) {
1107 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1108 SK_DBGCAT_DRV_INT_SRC,
1109 ("EOF SY TX1 IRQ\n"));
1110 SK_PNMI_CNT_TX_INTR(pAC, 0);
1111 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1112 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1113 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1114 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1119 /* do all IO at once */
1120 if (IntSrc & IS_R1_F)
1121 ClearAndStartRx(pAC, 0);
1122 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1123 if (IntSrc & IS_XA1_F)
1124 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1126 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1127 } /* while (IntSrc & IRQ_MASK != 0) */
1129 IntSrc &= pAC->GIni.GIValIrqMask;
1130 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1131 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1132 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1133 pAC->CheckQueue = SK_FALSE;
1134 spin_lock(&pAC->SlowPathLock);
1135 if (IntSrc & SPECIAL_IRQS)
1136 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1138 SkEventDispatcher(pAC, pAC->IoBase);
1139 spin_unlock(&pAC->SlowPathLock);
1142 * do it all again is case we cleared an interrupt that
1143 * came in after handling the ring (OUTs may be delayed
1144 * in hardware buffers, but are through after IN)
1146 * rroesler: has been commented out and shifted to
1147 * SkGeDrvEvent(), because it is timer
1150 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1153 /* IRQ is processed - Enable IRQs again*/
1154 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1156 return SkIsrRetHandled;
1157 } /* SkGeIsrOnePort */
1159 #ifdef CONFIG_NET_POLL_CONTROLLER
1160 /****************************************************************************
1162 * SkGePollController - polling receive, for netconsole
1165 * Polling receive - used by netconsole and other diagnostic tools
1166 * to allow network i/o with interrupts disabled.
1170 static void SkGePollController(struct net_device *dev)
1172 disable_irq(dev->irq);
1173 SkGeIsr(dev->irq, dev, NULL);
1174 enable_irq(dev->irq);
1178 /****************************************************************************
1180 * SkGeOpen - handle start of initialized adapter
1183 * This function starts the initialized adapter.
1184 * The board level variable is set and the adapter is
1185 * brought to full functionality.
1186 * The device flags are set for operation.
1187 * Do all necessary level 2 initialization, enable interrupts and
1188 * give start command to RLMT.
1194 static int SkGeOpen(
1195 struct SK_NET_DEVICE *dev)
1199 unsigned long Flags; /* for spin lock */
1201 SK_EVPARA EvPara; /* an event parameter union */
1203 pNet = netdev_priv(dev);
1206 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1207 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1209 #ifdef SK_DIAG_SUPPORT
1210 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1211 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1212 return (-1); /* still in use by diag; deny actions */
1217 /* Set blink mode */
1218 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1219 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1221 if (pAC->BoardLevel == SK_INIT_DATA) {
1222 /* level 1 init common modules here */
1223 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1224 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1227 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1228 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1229 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1230 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1231 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1232 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1233 pAC->BoardLevel = SK_INIT_IO;
1236 if (pAC->BoardLevel != SK_INIT_RUN) {
1237 /* tschilling: Level 2 init modules here, check return value. */
1238 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1239 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1242 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1243 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1244 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1245 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1246 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1247 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1248 pAC->BoardLevel = SK_INIT_RUN;
1251 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1252 /* Enable transmit descriptor polling. */
1253 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1254 FillRxRing(pAC, &pAC->RxPort[i]);
1256 SkGeYellowLED(pAC, pAC->IoBase, 1);
1258 StartDrvCleanupTimer(pAC);
1259 SkDimEnableModerationIfNeeded(pAC);
1260 SkDimDisplayModerationSettings(pAC);
1262 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1264 /* enable Interrupts */
1265 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1266 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1268 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1270 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1271 EvPara.Para32[0] = pAC->RlmtNets;
1272 EvPara.Para32[1] = -1;
1273 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1275 EvPara.Para32[0] = pAC->RlmtMode;
1276 EvPara.Para32[1] = 0;
1277 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1281 EvPara.Para32[0] = pNet->NetNr;
1282 EvPara.Para32[1] = -1;
1283 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1284 SkEventDispatcher(pAC, pAC->IoBase);
1285 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1290 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1291 ("SkGeOpen suceeded\n"));
1297 /****************************************************************************
1299 * SkGeClose - Stop initialized adapter
1302 * Close initialized adapter.
1306 * error code - on error
1308 static int SkGeClose(
1309 struct SK_NET_DEVICE *dev)
1315 unsigned long Flags; /* for spin lock */
1320 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1321 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1323 pNet = netdev_priv(dev);
1326 #ifdef SK_DIAG_SUPPORT
1327 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1328 if (pAC->DiagFlowCtrl == SK_FALSE) {
1330 ** notify that the interface which has been closed
1331 ** by operator interaction must not be started up
1332 ** again when the DIAG has finished.
1334 newPtrNet = netdev_priv(pAC->dev[0]);
1335 if (newPtrNet == pNet) {
1336 pAC->WasIfUp[0] = SK_FALSE;
1338 pAC->WasIfUp[1] = SK_FALSE;
1340 return 0; /* return to system everything is fine... */
1342 pAC->DiagFlowCtrl = SK_FALSE;
1347 netif_stop_queue(dev);
1349 if (pAC->RlmtNets == 1)
1350 PortIdx = pAC->ActivePort;
1352 PortIdx = pNet->NetNr;
1354 StopDrvCleanupTimer(pAC);
1357 * Clear multicast table, promiscuous mode ....
1359 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1360 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1363 if (pAC->MaxPorts == 1) {
1364 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1365 /* disable interrupts */
1366 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1367 EvPara.Para32[0] = pNet->NetNr;
1368 EvPara.Para32[1] = -1;
1369 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1370 SkEventDispatcher(pAC, pAC->IoBase);
1371 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1372 /* stop the hardware */
1373 SkGeDeInit(pAC, pAC->IoBase);
1374 pAC->BoardLevel = SK_INIT_DATA;
1375 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1378 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1379 EvPara.Para32[0] = pNet->NetNr;
1380 EvPara.Para32[1] = -1;
1381 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1382 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1383 SkEventDispatcher(pAC, pAC->IoBase);
1384 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1387 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1388 [TX_PRIO_LOW].TxDesRingLock, Flags);
1389 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1390 SK_STOP_ALL, SK_HARD_RST);
1391 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1392 [TX_PRIO_LOW].TxDesRingLock, Flags);
1395 if (pAC->RlmtNets == 1) {
1396 /* clear all descriptor rings */
1397 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1398 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1399 ClearRxRing(pAC, &pAC->RxPort[i]);
1400 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1403 /* clear port descriptor rings */
1404 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1405 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1406 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1409 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1410 ("SkGeClose: done "));
1412 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1413 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1414 sizeof(SK_PNMI_STRUCT_DATA));
1422 /*****************************************************************************
1424 * SkGeXmit - Linux frame transmit function
1427 * The system calls this function to send frames onto the wire.
1428 * It puts the frame in the tx descriptor ring. If the ring is
1429 * full then, the 'tbusy' flag is set.
1432 * 0, if everything is ok
1434 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1435 * allocated skb's) !!!
1437 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1441 int Rc; /* return code of XmitFrame */
1443 pNet = netdev_priv(dev);
1446 if ((!skb_shinfo(skb)->nr_frags) ||
1447 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1448 /* Don't activate scatter-gather and hardware checksum */
1450 if (pAC->RlmtNets == 2)
1453 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1458 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1461 /* scatter-gather and hardware TCP checksumming anabled*/
1462 if (pAC->RlmtNets == 2)
1465 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1470 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1474 /* Transmitter out of resources? */
1476 netif_stop_queue(dev);
1479 /* If not taken, give buffer ownership back to the
1485 dev->trans_start = jiffies;
1490 /*****************************************************************************
1492 * XmitFrame - fill one socket buffer into the transmit ring
1495 * This function puts a message into the transmit descriptor ring
1496 * if there is a descriptors left.
1497 * Linux skb's consist of only one continuous buffer.
1498 * The first step locks the ring. It is held locked
1499 * all time to avoid problems with SWITCH_../PORT_RESET.
1500 * Then the descriptoris allocated.
1501 * The second part is linking the buffer to the descriptor.
1502 * At the very last, the Control field of the descriptor
1503 * is made valid for the BMU and a start TX command is given
1507 * > 0 - on succes: the number of bytes in the message
1508 * = 0 - on resource shortage: this frame sent or dropped, now
1509 * the ring is full ( -> set tbusy)
1510 * < 0 - on failure: other problems ( -> return failure to upper layers)
1512 static int XmitFrame(
1513 SK_AC *pAC, /* pointer to adapter context */
1514 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1515 struct sk_buff *pMessage) /* pointer to send-message */
1517 TXD *pTxd; /* the rxd to fill */
1519 unsigned long Flags;
1521 int BytesSend = pMessage->len;
1523 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1525 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1526 #ifndef USE_TX_COMPLETE
1527 FreeTxDescriptors(pAC, pTxPort);
1529 if (pTxPort->TxdRingFree == 0) {
1531 ** no enough free descriptors in ring at the moment.
1532 ** Maybe free'ing some old one help?
1534 FreeTxDescriptors(pAC, pTxPort);
1535 if (pTxPort->TxdRingFree == 0) {
1536 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1537 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1538 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1539 SK_DBGCAT_DRV_TX_PROGRESS,
1540 ("XmitFrame failed\n"));
1542 ** the desired message can not be sent
1543 ** Because tbusy seems to be set, the message
1544 ** should not be freed here. It will be used
1545 ** by the scheduler of the ethernet handler
1552 ** If the passed socket buffer is of smaller MTU-size than 60,
1553 ** copy everything into new buffer and fill all bytes between
1554 ** the original packet end and the new packet end of 60 with 0x00.
1555 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1557 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1558 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1559 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1562 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1566 ** advance head counter behind descriptor needed for this frame,
1567 ** so that needed descriptor is reserved from that on. The next
1568 ** action will be to add the passed buffer to the TX-descriptor
1570 pTxd = pTxPort->pTxdRingHead;
1571 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1572 pTxPort->TxdRingFree--;
1575 DumpMsg(pMessage, "XmitFrame");
1579 ** First step is to map the data to be sent via the adapter onto
1580 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1581 ** and 2.6 need to use pci_map_page() for that mapping.
1583 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1584 virt_to_page(pMessage->data),
1585 ((unsigned long) pMessage->data & ~PAGE_MASK),
1588 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1589 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1590 pTxd->pMBuf = pMessage;
1592 if (pMessage->ip_summed == CHECKSUM_HW) {
1593 u16 hdrlen = pMessage->h.raw - pMessage->data;
1594 u16 offset = hdrlen + pMessage->csum;
1596 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1597 (pAC->GIni.GIChipRev == 0) &&
1598 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1599 pTxd->TBControl = BMU_TCP_CHECK;
1601 pTxd->TBControl = BMU_UDP_CHECK;
1604 pTxd->TcpSumOfs = 0;
1605 pTxd->TcpSumSt = hdrlen;
1606 pTxd->TcpSumWr = offset;
1608 pTxd->TBControl |= BMU_OWN | BMU_STF |
1610 #ifdef USE_TX_COMPLETE
1615 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1617 #ifdef USE_TX_COMPLETE
1624 ** If previous descriptor already done, give TX start cmd
1626 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1627 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1628 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1632 ** after releasing the lock, the skb may immediately be free'd
1634 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1635 if (pTxPort->TxdRingFree != 0) {
1643 /*****************************************************************************
1645 * XmitFrameSG - fill one socket buffer into the transmit ring
1646 * (use SG and TCP/UDP hardware checksumming)
1649 * This function puts a message into the transmit descriptor ring
1650 * if there is a descriptors left.
1653 * > 0 - on succes: the number of bytes in the message
1654 * = 0 - on resource shortage: this frame sent or dropped, now
1655 * the ring is full ( -> set tbusy)
1656 * < 0 - on failure: other problems ( -> return failure to upper layers)
1658 static int XmitFrameSG(
1659 SK_AC *pAC, /* pointer to adapter context */
1660 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1661 struct sk_buff *pMessage) /* pointer to send-message */
1669 skb_frag_t *sk_frag;
1671 unsigned long Flags;
1674 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1675 #ifndef USE_TX_COMPLETE
1676 FreeTxDescriptors(pAC, pTxPort);
1678 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
1679 FreeTxDescriptors(pAC, pTxPort);
1680 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
1681 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1682 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1683 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1684 SK_DBGCAT_DRV_TX_PROGRESS,
1685 ("XmitFrameSG failed - Ring full\n"));
1686 /* this message can not be sent now */
1691 pTxd = pTxPort->pTxdRingHead;
1697 ** Map the first fragment (header) into the DMA-space
1699 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1700 virt_to_page(pMessage->data),
1701 ((unsigned long) pMessage->data & ~PAGE_MASK),
1702 skb_headlen(pMessage),
1705 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1706 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1709 ** Does the HW need to evaluate checksum for TCP or UDP packets?
1711 if (pMessage->ip_summed == CHECKSUM_HW) {
1712 u16 hdrlen = pMessage->h.raw - pMessage->data;
1713 u16 offset = hdrlen + pMessage->csum;
1715 Control = BMU_STFWD;
1718 ** We have to use the opcode for tcp here, because the
1719 ** opcode for udp is not working in the hardware yet
1722 if ((pMessage->h.ipiph->protocol == IPPROTO_UDP ) &&
1723 (pAC->GIni.GIChipRev == 0) &&
1724 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1725 Control |= BMU_TCP_CHECK;
1727 Control |= BMU_UDP_CHECK;
1730 pTxd->TcpSumOfs = 0;
1731 pTxd->TcpSumSt = hdrlen;
1732 pTxd->TcpSumWr = offset;
1734 Control = BMU_CHECK | BMU_SW;
1736 pTxd->TBControl = BMU_STF | Control | skb_headlen(pMessage);
1738 pTxd = pTxd->pNextTxd;
1739 pTxPort->TxdRingFree--;
1740 BytesSend += skb_headlen(pMessage);
1743 ** Browse over all SG fragments and map each of them into the DMA space
1745 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
1746 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
1748 ** we already have the proper value in entry
1750 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1752 sk_frag->page_offset,
1756 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1757 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1758 pTxd->pMBuf = pMessage;
1760 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;;
1763 ** Do we have the last fragment?
1765 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
1766 #ifdef USE_TX_COMPLETE
1767 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF;
1769 pTxd->TBControl |= BMU_EOF;
1771 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
1774 pTxd = pTxd->pNextTxd;
1775 pTxPort->TxdRingFree--;
1776 BytesSend += sk_frag->size;
1780 ** If previous descriptor already done, give TX start cmd
1782 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
1783 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1786 pTxPort->pTxdRingPrev = pTxdLst;
1787 pTxPort->pTxdRingHead = pTxd;
1789 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1791 if (pTxPort->TxdRingFree > 0) {
1798 /*****************************************************************************
1800 * FreeTxDescriptors - release descriptors from the descriptor ring
1803 * This function releases descriptors from a transmit ring if they
1804 * have been sent by the BMU.
1805 * If a descriptors is sent, it can be freed and the message can
1807 * The SOFTWARE controllable bit is used to prevent running around a
1808 * completely free ring for ever. If this bit is no set in the
1809 * frame (by XmitFrame), this frame has never been sent or is
1811 * The Tx descriptor ring lock must be held while calling this function !!!
1816 static void FreeTxDescriptors(
1817 SK_AC *pAC, /* pointer to the adapter context */
1818 TX_PORT *pTxPort) /* pointer to destination port structure */
1820 TXD *pTxd; /* pointer to the checked descriptor */
1821 TXD *pNewTail; /* pointer to 'end' of the ring */
1822 SK_U32 Control; /* TBControl field of descriptor */
1823 SK_U64 PhysAddr; /* address of DMA mapping */
1825 pNewTail = pTxPort->pTxdRingTail;
1828 ** loop forever; exits if BMU_SW bit not set in start frame
1829 ** or BMU_OWN bit set in any frame
1832 Control = pTxd->TBControl;
1833 if ((Control & BMU_SW) == 0) {
1835 ** software controllable bit is set in first
1836 ** fragment when given to BMU. Not set means that
1837 ** this fragment was never sent or is already
1838 ** freed ( -> ring completely free now).
1840 pTxPort->pTxdRingTail = pTxd;
1841 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1844 if (Control & BMU_OWN) {
1845 pTxPort->pTxdRingTail = pTxd;
1846 if (pTxPort->TxdRingFree > 0) {
1847 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
1853 ** release the DMA mapping, because until not unmapped
1854 ** this buffer is considered being under control of the
1857 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
1858 PhysAddr |= (SK_U64) pTxd->VDataLow;
1859 pci_unmap_page(pAC->PciDev, PhysAddr,
1863 if (Control & BMU_EOF)
1864 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
1866 pTxPort->TxdRingFree++;
1867 pTxd->TBControl &= ~BMU_SW;
1868 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
1869 } /* while(forever) */
1870 } /* FreeTxDescriptors */
1872 /*****************************************************************************
1874 * FillRxRing - fill the receive ring with valid descriptors
1877 * This function fills the receive ring descriptors with data
1878 * segments and makes them valid for the BMU.
1879 * The active ring is filled completely, if possible.
1880 * The non-active ring is filled only partial to save memory.
1882 * Description of rx ring structure:
1883 * head - points to the descriptor which will be used next by the BMU
1884 * tail - points to the next descriptor to give to the BMU
1888 static void FillRxRing(
1889 SK_AC *pAC, /* pointer to the adapter context */
1890 RX_PORT *pRxPort) /* ptr to port struct for which the ring
1893 unsigned long Flags;
1895 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
1896 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
1897 if(!FillRxDescriptor(pAC, pRxPort))
1900 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
1904 /*****************************************************************************
1906 * FillRxDescriptor - fill one buffer into the receive ring
1909 * The function allocates a new receive buffer and
1910 * puts it into the next descriptor.
1913 * SK_TRUE - a buffer was added to the ring
1914 * SK_FALSE - a buffer could not be added
1916 static SK_BOOL FillRxDescriptor(
1917 SK_AC *pAC, /* pointer to the adapter context struct */
1918 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
1920 struct sk_buff *pMsgBlock; /* pointer to a new message block */
1921 RXD *pRxd; /* the rxd to fill */
1922 SK_U16 Length; /* data fragment length */
1923 SK_U64 PhysAddr; /* physical address of a rx buffer */
1925 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
1926 if (pMsgBlock == NULL) {
1927 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1928 SK_DBGCAT_DRV_ENTRY,
1929 ("%s: Allocation of rx buffer failed !\n",
1930 pAC->dev[pRxPort->PortIndex]->name));
1931 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
1934 skb_reserve(pMsgBlock, 2); /* to align IP frames */
1935 /* skb allocated ok, so add buffer */
1936 pRxd = pRxPort->pRxdRingTail;
1937 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1938 pRxPort->RxdRingFree--;
1939 Length = pAC->RxBufSize;
1940 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1941 virt_to_page(pMsgBlock->data),
1942 ((unsigned long) pMsgBlock->data &
1945 PCI_DMA_FROMDEVICE);
1947 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1948 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1949 pRxd->pMBuf = pMsgBlock;
1950 pRxd->RBControl = BMU_OWN |
1957 } /* FillRxDescriptor */
1960 /*****************************************************************************
1962 * ReQueueRxBuffer - fill one buffer back into the receive ring
1965 * Fill a given buffer back into the rx ring. The buffer
1966 * has been previously allocated and aligned, and its phys.
1967 * address calculated, so this is no more necessary.
1971 static void ReQueueRxBuffer(
1972 SK_AC *pAC, /* pointer to the adapter context struct */
1973 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
1974 struct sk_buff *pMsg, /* pointer to the buffer */
1975 SK_U32 PhysHigh, /* phys address high dword */
1976 SK_U32 PhysLow) /* phys address low dword */
1978 RXD *pRxd; /* the rxd to fill */
1979 SK_U16 Length; /* data fragment length */
1981 pRxd = pRxPort->pRxdRingTail;
1982 pRxPort->pRxdRingTail = pRxd->pNextRxd;
1983 pRxPort->RxdRingFree--;
1984 Length = pAC->RxBufSize;
1986 pRxd->VDataLow = PhysLow;
1987 pRxd->VDataHigh = PhysHigh;
1989 pRxd->RBControl = BMU_OWN |
1995 } /* ReQueueRxBuffer */
1997 /*****************************************************************************
1999 * ReceiveIrq - handle a receive IRQ
2002 * This function is called when a receive IRQ is set.
2003 * It walks the receive descriptor ring and sends up all
2004 * frames that are complete.
2008 static void ReceiveIrq(
2009 SK_AC *pAC, /* pointer to adapter context */
2010 RX_PORT *pRxPort, /* pointer to receive port struct */
2011 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2013 RXD *pRxd; /* pointer to receive descriptors */
2014 SK_U32 Control; /* control field of descriptor */
2015 struct sk_buff *pMsg; /* pointer to message holding frame */
2016 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2017 int FrameLength; /* total length of received frame */
2018 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2019 SK_EVPARA EvPara; /* an event parameter union */
2020 unsigned long Flags; /* for spin lock */
2021 int PortIndex = pRxPort->PortIndex;
2022 unsigned int Offset;
2023 unsigned int NumBytes;
2024 unsigned int ForRlmt;
2027 SK_BOOL IsBadFrame; /* Bad frame */
2033 /* do forever; exit if BMU_OWN found */
2034 for ( pRxd = pRxPort->pRxdRingHead ;
2035 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2036 pRxd = pRxd->pNextRxd,
2037 pRxPort->pRxdRingHead = pRxd,
2038 pRxPort->RxdRingFree ++) {
2041 * For a better understanding of this loop
2042 * Go through every descriptor beginning at the head
2043 * Please note: the ring might be completely received so the OWN bit
2044 * set is not a good crirteria to leave that loop.
2045 * Therefore the RingFree counter is used.
2046 * On entry of this loop pRxd is a pointer to the Rxd that needs
2047 * to be checked next.
2050 Control = pRxd->RBControl;
2052 /* check if this descriptor is ready */
2053 if ((Control & BMU_OWN) != 0) {
2054 /* this descriptor is not yet ready */
2055 /* This is the usual end of the loop */
2056 /* We don't need to start the ring again */
2057 FillRxRing(pAC, pRxPort);
2060 pAC->DynIrqModInfo.NbrProcessedDescr++;
2062 /* get length of frame and check it */
2063 FrameLength = Control & BMU_BBC;
2064 if (FrameLength > pAC->RxBufSize) {
2068 /* check for STF and EOF */
2069 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2073 /* here we have a complete frame in the ring */
2076 FrameStat = pRxd->FrameStat;
2078 /* check for frame length mismatch */
2079 #define XMR_FS_LEN_SHIFT 18
2080 #define GMR_FS_LEN_SHIFT 16
2081 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2082 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2083 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2084 SK_DBGCAT_DRV_RX_PROGRESS,
2085 ("skge: Frame length mismatch (%u/%u).\n",
2087 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2092 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2093 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2094 SK_DBGCAT_DRV_RX_PROGRESS,
2095 ("skge: Frame length mismatch (%u/%u).\n",
2097 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2103 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2104 IsBc = (FrameStat & XMR_FS_BC) != 0;
2105 IsMc = (FrameStat & XMR_FS_MC) != 0;
2106 IsBadFrame = (FrameStat &
2107 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2109 IsBc = (FrameStat & GMR_FS_BC) != 0;
2110 IsMc = (FrameStat & GMR_FS_MC) != 0;
2111 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2112 ((FrameStat & GMR_FS_RX_OK) == 0));
2115 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2116 ("Received frame of length %d on port %d\n",
2117 FrameLength, PortIndex));
2118 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2119 ("Number of free rx descriptors: %d\n",
2120 pRxPort->RxdRingFree));
2121 /* DumpMsg(pMsg, "Rx"); */
2123 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2125 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2127 /* there is a receive error in this frame */
2128 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2129 SK_DBGCAT_DRV_RX_PROGRESS,
2130 ("skge: Error in received frame, dropped!\n"
2131 "Control: %x\nRxStat: %x\n",
2132 Control, FrameStat));
2134 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2135 pRxd->VDataHigh, pRxd->VDataLow);
2141 * if short frame then copy data to reduce memory waste
2143 if ((FrameLength < SK_COPY_THRESHOLD) &&
2144 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2146 * Short frame detected and allocation successfull
2148 /* use new skb and copy data */
2149 skb_reserve(pNewMsg, 2);
2150 skb_put(pNewMsg, FrameLength);
2151 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2152 PhysAddr |= (SK_U64) pRxd->VDataLow;
2154 pci_dma_sync_single_for_cpu(pAC->PciDev,
2155 (dma_addr_t) PhysAddr,
2157 PCI_DMA_FROMDEVICE);
2158 memcpy(pNewMsg->data, pMsg, FrameLength);
2160 pci_dma_sync_single_for_device(pAC->PciDev,
2161 (dma_addr_t) PhysAddr,
2163 PCI_DMA_FROMDEVICE);
2164 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2165 pRxd->VDataHigh, pRxd->VDataLow);
2172 * if large frame, or SKB allocation failed, pass
2173 * the SKB directly to the networking
2176 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2177 PhysAddr |= (SK_U64) pRxd->VDataLow;
2179 /* release the DMA mapping */
2180 pci_unmap_single(pAC->PciDev,
2183 PCI_DMA_FROMDEVICE);
2185 /* set length in message */
2186 skb_put(pMsg, FrameLength);
2187 } /* frame > SK_COPY_TRESHOLD */
2189 if (pRxPort->RxCsum) {
2190 pMsg->csum = pRxd->TcpSums;
2191 pMsg->ip_summed = CHECKSUM_HW;
2194 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2195 ForRlmt = SK_RLMT_RX_PROTOCOL;
2197 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2199 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2200 IsBc, &Offset, &NumBytes);
2201 if (NumBytes != 0) {
2203 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2205 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2206 &pMsg->data[Offset],
2207 IsBc, IsMc, &ForRlmt);
2209 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2210 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2211 /* send up only frames from active port */
2212 if ((PortIndex == pAC->ActivePort) ||
2213 (pAC->RlmtNets == 2)) {
2214 /* frame for upper layer */
2215 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2217 DumpMsg(pMsg, "Rx");
2219 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2220 FrameLength, pRxPort->PortIndex);
2222 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2223 pMsg->protocol = eth_type_trans(pMsg,
2224 pAC->dev[pRxPort->PortIndex]);
2226 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2230 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2231 SK_DBGCAT_DRV_RX_PROGRESS,
2233 DEV_KFREE_SKB(pMsg);
2236 } /* if not for rlmt */
2238 /* packet for rlmt */
2239 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2240 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2241 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2242 pAC->IoBase, FrameLength);
2243 if (pRlmtMbuf != NULL) {
2244 pRlmtMbuf->pNext = NULL;
2245 pRlmtMbuf->Length = FrameLength;
2246 pRlmtMbuf->PortIdx = PortIndex;
2247 EvPara.pParaPtr = pRlmtMbuf;
2248 memcpy((char*)(pRlmtMbuf->pData),
2249 (char*)(pMsg->data),
2252 /* SlowPathLock needed? */
2253 if (SlowPathLock == SK_TRUE) {
2254 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2255 SkEventQueue(pAC, SKGE_RLMT,
2256 SK_RLMT_PACKET_RECEIVED,
2258 pAC->CheckQueue = SK_TRUE;
2259 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2261 SkEventQueue(pAC, SKGE_RLMT,
2262 SK_RLMT_PACKET_RECEIVED,
2264 pAC->CheckQueue = SK_TRUE;
2267 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2268 SK_DBGCAT_DRV_RX_PROGRESS,
2271 if ((pAC->dev[pRxPort->PortIndex]->flags &
2272 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2273 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2274 SK_RLMT_RX_PROTOCOL) {
2275 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2276 pMsg->protocol = eth_type_trans(pMsg,
2277 pAC->dev[pRxPort->PortIndex]);
2279 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2282 DEV_KFREE_SKB(pMsg);
2285 } /* if packet for rlmt */
2286 } /* for ... scanning the RXD ring */
2288 /* RXD ring is empty -> fill and restart */
2289 FillRxRing(pAC, pRxPort);
2290 /* do not start if called from Close */
2291 if (pAC->BoardLevel > SK_INIT_DATA) {
2292 ClearAndStartRx(pAC, PortIndex);
2297 /* remove error frame */
2298 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2299 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2301 /* release the DMA mapping */
2303 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2304 PhysAddr |= (SK_U64) pRxd->VDataLow;
2305 pci_unmap_page(pAC->PciDev,
2308 PCI_DMA_FROMDEVICE);
2309 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2311 pRxPort->RxdRingFree++;
2312 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2318 /*****************************************************************************
2320 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2323 * This function sends a start command and a clear interrupt
2324 * command for one receive queue to the BMU.
2329 static void ClearAndStartRx(
2330 SK_AC *pAC, /* pointer to the adapter context */
2331 int PortIndex) /* index of the receive port (XMAC) */
2333 SK_OUT8(pAC->IoBase,
2334 RxQueueAddr[PortIndex]+Q_CSR,
2335 CSR_START | CSR_IRQ_CL_F);
2336 } /* ClearAndStartRx */
2339 /*****************************************************************************
2341 * ClearTxIrq - give a clear transmit IRQ command to BMU
2344 * This function sends a clear tx IRQ command for one
2345 * transmit queue to the BMU.
2349 static void ClearTxIrq(
2350 SK_AC *pAC, /* pointer to the adapter context */
2351 int PortIndex, /* index of the transmit port (XMAC) */
2352 int Prio) /* priority or normal queue */
2354 SK_OUT8(pAC->IoBase,
2355 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2360 /*****************************************************************************
2362 * ClearRxRing - remove all buffers from the receive ring
2365 * This function removes all receive buffers from the ring.
2366 * The receive BMU must be stopped before calling this function.
2370 static void ClearRxRing(
2371 SK_AC *pAC, /* pointer to adapter context */
2372 RX_PORT *pRxPort) /* pointer to rx port struct */
2374 RXD *pRxd; /* pointer to the current descriptor */
2375 unsigned long Flags;
2378 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2381 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2382 pRxd = pRxPort->pRxdRingHead;
2384 if (pRxd->pMBuf != NULL) {
2386 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2387 PhysAddr |= (SK_U64) pRxd->VDataLow;
2388 pci_unmap_page(pAC->PciDev,
2391 PCI_DMA_FROMDEVICE);
2392 DEV_KFREE_SKB(pRxd->pMBuf);
2395 pRxd->RBControl &= BMU_OWN;
2396 pRxd = pRxd->pNextRxd;
2397 pRxPort->RxdRingFree++;
2398 } while (pRxd != pRxPort->pRxdRingTail);
2399 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2400 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2403 /*****************************************************************************
2405 * ClearTxRing - remove all buffers from the transmit ring
2408 * This function removes all transmit buffers from the ring.
2409 * The transmit BMU must be stopped before calling this function
2410 * and transmitting at the upper level must be disabled.
2411 * The BMU own bit of all descriptors is cleared, the rest is
2412 * done by calling FreeTxDescriptors.
2416 static void ClearTxRing(
2417 SK_AC *pAC, /* pointer to adapter context */
2418 TX_PORT *pTxPort) /* pointer to tx prt struct */
2420 TXD *pTxd; /* pointer to the current descriptor */
2422 unsigned long Flags;
2424 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2425 pTxd = pTxPort->pTxdRingHead;
2426 for (i=0; i<pAC->TxDescrPerRing; i++) {
2427 pTxd->TBControl &= ~BMU_OWN;
2428 pTxd = pTxd->pNextTxd;
2430 FreeTxDescriptors(pAC, pTxPort);
2431 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2434 /*****************************************************************************
2436 * SkGeSetMacAddr - Set the hardware MAC address
2439 * This function sets the MAC address used by the adapter.
2442 * 0, if everything is ok
2445 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2448 DEV_NET *pNet = netdev_priv(dev);
2449 SK_AC *pAC = pNet->pAC;
2451 struct sockaddr *addr = p;
2452 unsigned long Flags;
2454 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2455 ("SkGeSetMacAddr starts now...\n"));
2456 if(netif_running(dev))
2459 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2461 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2463 if (pAC->RlmtNets == 2)
2464 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2465 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2467 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2468 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2472 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2474 } /* SkGeSetMacAddr */
2477 /*****************************************************************************
2479 * SkGeSetRxMode - set receive mode
2482 * This function sets the receive mode of an adapter. The adapter
2483 * supports promiscuous mode, allmulticast mode and a number of
2484 * multicast addresses. If more multicast addresses the available
2485 * are selected, a hash function in the hardware is used.
2488 * 0, if everything is ok
2491 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2497 struct dev_mc_list *pMcList;
2500 unsigned long Flags;
2502 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2503 ("SkGeSetRxMode starts now... "));
2505 pNet = netdev_priv(dev);
2507 if (pAC->RlmtNets == 1)
2508 PortIdx = pAC->ActivePort;
2510 PortIdx = pNet->NetNr;
2512 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2513 if (dev->flags & IFF_PROMISC) {
2514 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2515 ("PROMISCUOUS mode\n"));
2516 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2518 } else if (dev->flags & IFF_ALLMULTI) {
2519 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2520 ("ALLMULTI mode\n"));
2521 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2522 SK_PROM_MODE_ALL_MC);
2524 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2526 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2528 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2529 ("Number of MC entries: %d ", dev->mc_count));
2531 pMcList = dev->mc_list;
2532 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2533 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2534 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2535 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2536 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2537 pMcList->dmi_addr[0],
2538 pMcList->dmi_addr[1],
2539 pMcList->dmi_addr[2],
2540 pMcList->dmi_addr[3],
2541 pMcList->dmi_addr[4],
2542 pMcList->dmi_addr[5]));
2544 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2546 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2549 } /* SkGeSetRxMode */
2552 /*****************************************************************************
2554 * SkGeChangeMtu - set the MTU to another value
2557 * This function sets is called whenever the MTU size is changed
2558 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
2559 * ethernet MTU size, long frame support is activated.
2562 * 0, if everything is ok
2565 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
2568 struct net_device *pOtherDev;
2570 unsigned long Flags;
2574 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2575 ("SkGeChangeMtu starts now...\n"));
2577 pNet = netdev_priv(dev);
2580 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
2584 if(pAC->BoardLevel != SK_INIT_RUN) {
2588 #ifdef SK_DIAG_SUPPORT
2589 if (pAC->DiagModeActive == DIAG_ACTIVE) {
2590 if (pAC->DiagFlowCtrl == SK_FALSE) {
2591 return -1; /* still in use, deny any actions of MTU */
2593 pAC->DiagFlowCtrl = SK_FALSE;
2598 pOtherDev = pAC->dev[1 - pNet->NetNr];
2600 if ( netif_running(pOtherDev) && (pOtherDev->mtu > 1500)
2601 && (NewMtu <= 1500))
2604 pAC->RxBufSize = NewMtu + 32;
2607 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2608 ("New MTU: %d\n", NewMtu));
2611 ** Prevent any reconfiguration while changing the MTU
2612 ** by disabling any interrupts
2614 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
2615 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2618 ** Notify RLMT that any ports are to be stopped
2620 EvPara.Para32[0] = 0;
2621 EvPara.Para32[1] = -1;
2622 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2623 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2624 EvPara.Para32[0] = 1;
2625 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2627 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
2631 ** After calling the SkEventDispatcher(), RLMT is aware about
2632 ** the stopped ports -> configuration can take place!
2634 SkEventDispatcher(pAC, pAC->IoBase);
2636 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2637 spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2638 netif_stop_queue(pAC->dev[i]);
2643 ** Depending on the desired MTU size change, a different number of
2644 ** RX buffers need to be allocated
2646 if (NewMtu > 1500) {
2648 ** Use less rx buffers
2650 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2651 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2652 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2653 (pAC->RxDescrPerRing / 4);
2655 if (i == pAC->ActivePort) {
2656 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2657 (pAC->RxDescrPerRing / 4);
2659 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2660 (pAC->RxDescrPerRing / 10);
2666 ** Use the normal amount of rx buffers
2668 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2669 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2670 pAC->RxPort[i].RxFillLimit = 1;
2672 if (i == pAC->ActivePort) {
2673 pAC->RxPort[i].RxFillLimit = 1;
2675 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
2676 (pAC->RxDescrPerRing / 4);
2682 SkGeDeInit(pAC, pAC->IoBase);
2685 ** enable/disable hardware support for long frames
2687 if (NewMtu > 1500) {
2688 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
2689 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
2691 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2692 pAC->GIni.GIPortUsage = SK_MUL_LINK;
2694 pAC->GIni.GIPortUsage = SK_RED_LINK;
2698 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
2699 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
2700 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
2701 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
2702 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
2703 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
2704 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
2708 ** Speed and others are set back to default in level 1 init!
2710 GetConfiguration(pAC);
2712 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
2713 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
2714 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
2715 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
2716 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
2717 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
2718 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
2721 ** clear and reinit the rx rings here
2723 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
2724 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
2725 ClearRxRing(pAC, &pAC->RxPort[i]);
2726 FillRxRing(pAC, &pAC->RxPort[i]);
2729 ** Enable transmit descriptor polling
2731 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
2732 FillRxRing(pAC, &pAC->RxPort[i]);
2735 SkGeYellowLED(pAC, pAC->IoBase, 1);
2736 SkDimEnableModerationIfNeeded(pAC);
2737 SkDimDisplayModerationSettings(pAC);
2739 netif_start_queue(pAC->dev[pNet->PortNr]);
2740 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
2741 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
2745 ** Enable Interrupts again
2747 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
2748 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
2750 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2751 SkEventDispatcher(pAC, pAC->IoBase);
2754 ** Notify RLMT about the changing and restarting one (or more) ports
2756 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
2757 EvPara.Para32[0] = pAC->RlmtNets;
2758 EvPara.Para32[1] = -1;
2759 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
2760 EvPara.Para32[0] = pNet->PortNr;
2761 EvPara.Para32[1] = -1;
2762 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2764 if (netif_running(pOtherDev)) {
2765 DEV_NET *pOtherNet = netdev_priv(pOtherDev);
2766 EvPara.Para32[0] = pOtherNet->PortNr;
2767 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2770 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
2773 SkEventDispatcher(pAC, pAC->IoBase);
2774 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2777 ** While testing this driver with latest kernel 2.5 (2.5.70), it
2778 ** seems as if upper layers have a problem to handle a successful
2779 ** return value of '0'. If such a zero is returned, the complete
2780 ** system hangs for several minutes (!), which is in acceptable.
2782 ** Currently it is not clear, what the exact reason for this problem
2783 ** is. The implemented workaround for 2.5 is to return the desired
2784 ** new MTU size if all needed changes for the new MTU size where
2785 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
2786 ** which indicates the successful change of the mtu-size.
2790 } /* SkGeChangeMtu */
2793 /*****************************************************************************
2795 * SkGeStats - return ethernet device statistics
2798 * This function return statistic data about the ethernet device
2799 * to the operating system.
2802 * pointer to the statistic structure.
2804 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
2806 DEV_NET *pNet = netdev_priv(dev);
2807 SK_AC *pAC = pNet->pAC;
2808 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
2809 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
2810 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
2811 unsigned int Size; /* size of pnmi struct */
2812 unsigned long Flags; /* for spin lock */
2814 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2815 ("SkGeStats starts now...\n"));
2816 pPnmiStruct = &pAC->PnmiStruct;
2818 #ifdef SK_DIAG_SUPPORT
2819 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
2820 (pAC->BoardLevel == SK_INIT_RUN)) {
2822 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
2823 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2824 Size = SK_PNMI_STRUCT_SIZE;
2825 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
2826 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2827 #ifdef SK_DIAG_SUPPORT
2831 pPnmiStat = &pPnmiStruct->Stat[0];
2832 pPnmiConf = &pPnmiStruct->Conf[0];
2834 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
2835 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
2836 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
2837 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
2839 if (dev->mtu <= 1500) {
2840 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
2842 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
2843 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
2847 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
2848 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
2850 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2851 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
2852 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
2853 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
2854 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
2856 /* detailed rx_errors: */
2857 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
2858 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2859 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
2860 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
2861 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
2862 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
2864 /* detailed tx_errors */
2865 pAC->stats.tx_aborted_errors = (SK_U32) 0;
2866 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2867 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
2868 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
2869 pAC->stats.tx_window_errors = (SK_U32) 0;
2871 return(&pAC->stats);
2875 /*****************************************************************************
2877 * SkGeIoctl - IO-control function
2880 * This function is called if an ioctl is issued on the device.
2881 * There are three subfunction for reading, writing and test-writing
2882 * the private MIB data structure (usefull for SysKonnect-internal tools).
2885 * 0, if everything is ok
2888 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
2893 struct pci_dev *pdev = NULL;
2895 unsigned int Err = 0;
2898 unsigned int Length = 0;
2899 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
2901 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2902 ("SkGeIoctl starts now...\n"));
2904 pNet = netdev_priv(dev);
2907 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
2912 case SK_IOCTL_SETMIB:
2913 case SK_IOCTL_PRESETMIB:
2914 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2915 case SK_IOCTL_GETMIB:
2916 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
2917 Ioctl.Len<sizeof(pAC->PnmiStruct)?
2918 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
2921 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
2922 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
2923 Ioctl.Len<Size? Ioctl.Len : Size)) {
2927 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2932 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2935 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2937 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2940 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2944 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
2948 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2953 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2958 kfree(pMemBuf); /* cleanup everything */
2960 #ifdef SK_DIAG_SUPPORT
2962 if (!capable(CAP_NET_ADMIN)) return -EPERM;
2963 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
2966 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
2968 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
2971 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
2976 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
2978 ** While coding this new IOCTL interface, only a few lines of code
2979 ** are to to be added. Therefore no dedicated function has been
2980 ** added. If more functionality is added, a separate function
2981 ** should be used...
2983 * ((SK_U32 *)pMemBuf) = 0;
2984 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
2985 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
2986 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
2991 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
2996 kfree(pMemBuf); /* cleanup everything */
3008 /*****************************************************************************
3010 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3013 * This function reads/writes the MIB data using PNMI (Private Network
3014 * Management Interface).
3015 * The destination for the data must be provided with the
3016 * ioctl call and is given to the driver in the form of
3017 * a user space address.
3018 * Copying from the user-provided data area into kernel messages
3019 * and back is done by copy_from_user and copy_to_user calls in
3023 * returned size from PNMI call
3025 static int SkGeIocMib(
3026 DEV_NET *pNet, /* pointer to the adapter context */
3027 unsigned int Size, /* length of ioctl data */
3028 int mode) /* flag for set/preset */
3030 unsigned long Flags; /* for spin lock */
3033 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3034 ("SkGeIocMib starts now...\n"));
3037 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3039 case SK_IOCTL_GETMIB:
3040 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3043 case SK_IOCTL_PRESETMIB:
3044 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3047 case SK_IOCTL_SETMIB:
3048 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3054 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3055 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3056 ("MIB data access succeeded\n"));
3061 /*****************************************************************************
3063 * GetConfiguration - read configuration information
3066 * This function reads per-adapter configuration information from
3067 * the options provided on the command line.
3072 static void GetConfiguration(
3073 SK_AC *pAC) /* pointer to the adapter context structure */
3075 SK_I32 Port; /* preferred port */
3078 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3079 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3080 int DuplexCap = 0; /* 0=both,1=full,2=half */
3081 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3082 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3084 SK_BOOL IsConTypeDefined = SK_TRUE;
3085 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3086 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3087 SK_BOOL IsRoleDefined = SK_TRUE;
3088 SK_BOOL IsModeDefined = SK_TRUE;
3090 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3091 * parameter. The mapping is described by this table:
3092 * DuplexCap -> | both | full | half |
3094 * -----------------------------------------------------------------
3095 * Off | illegal | Full | Half |
3096 * -----------------------------------------------------------------
3097 * On | AutoBoth | AutoFull | AutoHalf |
3098 * -----------------------------------------------------------------
3099 * Sense | AutoSense | AutoSense | AutoSense |
3101 int Capabilities[3][3] =
3102 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3103 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3104 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3112 #define M_CurrPort pAC->GIni.GP[Port]
3116 ** Set the default values first for both ports!
3118 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3119 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3120 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3121 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3122 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3126 ** Check merged parameter ConType. If it has not been used,
3127 ** verify any other parameter (e.g. AutoNeg) and use default values.
3129 ** Stating both ConType and other lowlevel link parameters is also
3130 ** possible. If this is the case, the passed ConType-parameter is
3131 ** overwritten by the lowlevel link parameter.
3133 ** The following settings are used for a merged ConType-parameter:
3135 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3136 ** ------- ------ ------- -------- ---------- -----
3137 ** Auto Both On SymOrRem Auto Auto
3138 ** 100FD Full Off None <ignored> 100
3139 ** 100HD Half Off None <ignored> 100
3140 ** 10FD Full Off None <ignored> 10
3141 ** 10HD Half Off None <ignored> 10
3143 ** This ConType parameter is used for all ports of the adapter!
3145 if ( (ConType != NULL) &&
3146 (pAC->Index < SK_MAX_CARD_PARAM) &&
3147 (ConType[pAC->Index] != NULL) ) {
3149 /* Check chipset family */
3150 if ((!pAC->ChipsetType) &&
3151 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3152 (strcmp(ConType[pAC->Index],"")!=0)) {
3153 /* Set the speed parameter back */
3154 printk("sk98lin: Illegal value \"%s\" "
3157 ConType[pAC->Index]);
3159 sprintf(ConType[pAC->Index], "Auto");
3162 if (strcmp(ConType[pAC->Index],"")==0) {
3163 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3164 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3165 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3166 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3167 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3168 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3169 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3171 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3172 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3173 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3174 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3175 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3176 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3178 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3179 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3180 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3181 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3182 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3183 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3185 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3186 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3187 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3188 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3189 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3190 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3192 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3193 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3194 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3195 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3196 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3197 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3200 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3201 ConType[pAC->Index]);
3202 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3205 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3209 ** Parse any parameter settings for port A:
3210 ** a) any LinkSpeed stated?
3212 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3213 Speed_A[pAC->Index] != NULL) {
3214 if (strcmp(Speed_A[pAC->Index],"")==0) {
3215 IsLinkSpeedDefined = SK_FALSE;
3216 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3217 LinkSpeed = SK_LSPEED_AUTO;
3218 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3219 LinkSpeed = SK_LSPEED_10MBPS;
3220 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3221 LinkSpeed = SK_LSPEED_100MBPS;
3222 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3223 LinkSpeed = SK_LSPEED_1000MBPS;
3225 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3226 Speed_A[pAC->Index]);
3227 IsLinkSpeedDefined = SK_FALSE;
3230 IsLinkSpeedDefined = SK_FALSE;
3234 ** Check speed parameter:
3235 ** Only copper type adapter and GE V2 cards
3237 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3238 ((LinkSpeed != SK_LSPEED_AUTO) &&
3239 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3240 printk("sk98lin: Illegal value for Speed_A. "
3241 "Not a copper card or GE V2 card\n Using "
3243 LinkSpeed = SK_LSPEED_1000MBPS;
3247 ** Decide whether to set new config value if somethig valid has
3250 if (IsLinkSpeedDefined) {
3251 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3255 ** b) Any Autonegotiation and DuplexCapabilities set?
3256 ** Please note that both belong together...
3258 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3260 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3261 AutoNeg_A[pAC->Index] != NULL) {
3263 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3265 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3267 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3269 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3272 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3273 AutoNeg_A[pAC->Index]);
3277 DuplexCap = DC_BOTH;
3279 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3280 DupCap_A[pAC->Index] != NULL) {
3282 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3284 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3285 DuplexCap = DC_BOTH;
3286 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3287 DuplexCap = DC_FULL;
3288 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3289 DuplexCap = DC_HALF;
3291 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3292 DupCap_A[pAC->Index]);
3297 ** Check for illegal combinations
3299 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3300 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3301 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3302 (pAC->ChipsetType)) {
3303 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3304 " Using Full Duplex.\n");
3305 DuplexCap = DC_FULL;
3308 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3309 printk("sk98lin, Port A: DuplexCapabilities"
3310 " ignored using Sense mode\n");
3313 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3314 printk("sk98lin: Port A: Illegal combination"
3315 " of values AutoNeg. and DuplexCap.\n Using "
3317 DuplexCap = DC_FULL;
3320 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3321 DuplexCap = DC_FULL;
3324 if (!AutoSet && DupSet) {
3325 printk("sk98lin: Port A: Duplex setting not"
3326 " possible in\n default AutoNegotiation mode"
3327 " (Sense).\n Using AutoNegotiation On\n");
3332 ** set the desired mode
3334 if (AutoSet || DupSet) {
3335 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3339 ** c) Any Flowcontrol-parameter set?
3341 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3342 FlowCtrl_A[pAC->Index] != NULL) {
3343 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3344 IsFlowCtrlDefined = SK_FALSE;
3345 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3346 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3347 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3348 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3349 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3350 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3351 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3352 FlowCtrl = SK_FLOW_MODE_NONE;
3354 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3355 FlowCtrl_A[pAC->Index]);
3356 IsFlowCtrlDefined = SK_FALSE;
3359 IsFlowCtrlDefined = SK_FALSE;
3362 if (IsFlowCtrlDefined) {
3363 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3364 printk("sk98lin: Port A: FlowControl"
3365 " impossible without AutoNegotiation,"
3367 FlowCtrl = SK_FLOW_MODE_NONE;
3369 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3373 ** d) What is with the RoleParameter?
3375 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3376 Role_A[pAC->Index] != NULL) {
3377 if (strcmp(Role_A[pAC->Index],"")==0) {
3378 IsRoleDefined = SK_FALSE;
3379 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3380 MSMode = SK_MS_MODE_AUTO;
3381 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3382 MSMode = SK_MS_MODE_MASTER;
3383 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3384 MSMode = SK_MS_MODE_SLAVE;
3386 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3387 Role_A[pAC->Index]);
3388 IsRoleDefined = SK_FALSE;
3391 IsRoleDefined = SK_FALSE;
3394 if (IsRoleDefined == SK_TRUE) {
3395 pAC->GIni.GP[0].PMSMode = MSMode;
3401 ** Parse any parameter settings for port B:
3402 ** a) any LinkSpeed stated?
3404 IsConTypeDefined = SK_TRUE;
3405 IsLinkSpeedDefined = SK_TRUE;
3406 IsFlowCtrlDefined = SK_TRUE;
3407 IsModeDefined = SK_TRUE;
3409 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3410 Speed_B[pAC->Index] != NULL) {
3411 if (strcmp(Speed_B[pAC->Index],"")==0) {
3412 IsLinkSpeedDefined = SK_FALSE;
3413 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3414 LinkSpeed = SK_LSPEED_AUTO;
3415 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3416 LinkSpeed = SK_LSPEED_10MBPS;
3417 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3418 LinkSpeed = SK_LSPEED_100MBPS;
3419 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3420 LinkSpeed = SK_LSPEED_1000MBPS;
3422 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3423 Speed_B[pAC->Index]);
3424 IsLinkSpeedDefined = SK_FALSE;
3427 IsLinkSpeedDefined = SK_FALSE;
3431 ** Check speed parameter:
3432 ** Only copper type adapter and GE V2 cards
3434 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3435 ((LinkSpeed != SK_LSPEED_AUTO) &&
3436 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3437 printk("sk98lin: Illegal value for Speed_B. "
3438 "Not a copper card or GE V2 card\n Using "
3440 LinkSpeed = SK_LSPEED_1000MBPS;
3444 ** Decide whether to set new config value if somethig valid has
3447 if (IsLinkSpeedDefined) {
3448 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3452 ** b) Any Autonegotiation and DuplexCapabilities set?
3453 ** Please note that both belong together...
3455 AutoNeg = AN_SENS; /* default: do auto Sense */
3457 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3458 AutoNeg_B[pAC->Index] != NULL) {
3460 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3462 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3464 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3466 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3469 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3470 AutoNeg_B[pAC->Index]);
3474 DuplexCap = DC_BOTH;
3476 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3477 DupCap_B[pAC->Index] != NULL) {
3479 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3481 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3482 DuplexCap = DC_BOTH;
3483 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3484 DuplexCap = DC_FULL;
3485 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3486 DuplexCap = DC_HALF;
3488 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3489 DupCap_B[pAC->Index]);
3495 ** Check for illegal combinations
3497 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3498 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3499 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3500 (pAC->ChipsetType)) {
3501 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3502 " Using Full Duplex.\n");
3503 DuplexCap = DC_FULL;
3506 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3507 printk("sk98lin, Port B: DuplexCapabilities"
3508 " ignored using Sense mode\n");
3511 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3512 printk("sk98lin: Port B: Illegal combination"
3513 " of values AutoNeg. and DuplexCap.\n Using "
3515 DuplexCap = DC_FULL;
3518 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3519 DuplexCap = DC_FULL;
3522 if (!AutoSet && DupSet) {
3523 printk("sk98lin: Port B: Duplex setting not"
3524 " possible in\n default AutoNegotiation mode"
3525 " (Sense).\n Using AutoNegotiation On\n");
3530 ** set the desired mode
3532 if (AutoSet || DupSet) {
3533 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3537 ** c) Any FlowCtrl parameter set?
3539 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3540 FlowCtrl_B[pAC->Index] != NULL) {
3541 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3542 IsFlowCtrlDefined = SK_FALSE;
3543 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3544 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3545 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3546 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3547 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
3548 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3549 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
3550 FlowCtrl = SK_FLOW_MODE_NONE;
3552 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
3553 FlowCtrl_B[pAC->Index]);
3554 IsFlowCtrlDefined = SK_FALSE;
3557 IsFlowCtrlDefined = SK_FALSE;
3560 if (IsFlowCtrlDefined) {
3561 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3562 printk("sk98lin: Port B: FlowControl"
3563 " impossible without AutoNegotiation,"
3565 FlowCtrl = SK_FLOW_MODE_NONE;
3567 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
3571 ** d) What is the RoleParameter?
3573 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3574 Role_B[pAC->Index] != NULL) {
3575 if (strcmp(Role_B[pAC->Index],"")==0) {
3576 IsRoleDefined = SK_FALSE;
3577 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
3578 MSMode = SK_MS_MODE_AUTO;
3579 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
3580 MSMode = SK_MS_MODE_MASTER;
3581 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
3582 MSMode = SK_MS_MODE_SLAVE;
3584 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
3585 Role_B[pAC->Index]);
3586 IsRoleDefined = SK_FALSE;
3589 IsRoleDefined = SK_FALSE;
3592 if (IsRoleDefined) {
3593 pAC->GIni.GP[1].PMSMode = MSMode;
3597 ** Evaluate settings for both ports
3599 pAC->ActivePort = 0;
3600 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3601 PrefPort[pAC->Index] != NULL) {
3602 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
3603 pAC->ActivePort = 0;
3604 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3605 pAC->Rlmt.Net[0].PrefPort = 0;
3606 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
3608 ** do not set ActivePort here, thus a port
3609 ** switch is issued after net up.
3612 pAC->Rlmt.Net[0].Preference = Port;
3613 pAC->Rlmt.Net[0].PrefPort = Port;
3614 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
3616 ** do not set ActivePort here, thus a port
3617 ** switch is issued after net up.
3619 if (pAC->GIni.GIMacsFound == 1) {
3620 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
3621 " Port B not available on single port adapters.\n");
3623 pAC->ActivePort = 0;
3624 pAC->Rlmt.Net[0].Preference = -1; /* auto */
3625 pAC->Rlmt.Net[0].PrefPort = 0;
3628 pAC->Rlmt.Net[0].Preference = Port;
3629 pAC->Rlmt.Net[0].PrefPort = Port;
3632 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
3633 PrefPort[pAC->Index]);
3639 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3640 RlmtMode[pAC->Index] != NULL) {
3641 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
3643 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
3644 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3645 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
3646 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3647 SK_RLMT_CHECK_LOC_LINK;
3648 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
3649 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
3650 SK_RLMT_CHECK_LOC_LINK |
3652 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
3653 (pAC->GIni.GIMacsFound == 2)) {
3654 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
3657 printk("sk98lin: Illegal value \"%s\" for"
3658 " RlmtMode, using default\n",
3659 RlmtMode[pAC->Index]);
3667 ** Check the interrupt moderation parameters
3669 if (Moderation[pAC->Index] != NULL) {
3670 if (strcmp(Moderation[pAC->Index], "") == 0) {
3671 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3672 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
3673 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
3674 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
3675 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
3676 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
3677 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3679 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
3680 " Disable interrupt moderation.\n",
3681 Moderation[pAC->Index]);
3682 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3685 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
3688 if (Stats[pAC->Index] != NULL) {
3689 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
3690 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
3692 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3695 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
3698 if (ModerationMask[pAC->Index] != NULL) {
3699 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
3700 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3701 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
3702 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
3703 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
3704 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
3705 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
3706 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3707 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
3708 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
3709 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
3710 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3711 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
3712 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3713 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
3714 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3715 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
3716 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
3717 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
3718 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3719 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
3720 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3721 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
3722 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3723 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
3724 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3725 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
3726 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3727 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
3728 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
3729 } else { /* some rubbish */
3730 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
3732 } else { /* operator has stated nothing */
3733 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
3736 if (AutoSizing[pAC->Index] != NULL) {
3737 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
3738 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3740 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3742 } else { /* operator has stated nothing */
3743 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
3746 if (IntsPerSec[pAC->Index] != 0) {
3747 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
3748 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
3749 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
3750 " Using default value of %i.\n",
3751 IntsPerSec[pAC->Index],
3752 C_INT_MOD_IPS_LOWER_RANGE,
3753 C_INT_MOD_IPS_UPPER_RANGE,
3754 C_INTS_PER_SEC_DEFAULT);
3755 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3757 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
3760 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
3764 ** Evaluate upper and lower moderation threshold
3766 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
3767 pAC->DynIrqModInfo.MaxModIntsPerSec +
3768 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3770 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
3771 pAC->DynIrqModInfo.MaxModIntsPerSec -
3772 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
3774 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
3777 } /* GetConfiguration */
3780 /*****************************************************************************
3782 * ProductStr - return a adapter identification string from vpd
3785 * This function reads the product name string from the vpd area
3786 * and puts it the field pAC->DeviceString.
3790 static inline int ProductStr(
3791 SK_AC *pAC, /* pointer to adapter context */
3792 char *DeviceStr, /* result string */
3793 int StrLen /* length of the string */
3796 char Keyword[] = VPD_NAME; /* vpd productname identifier */
3797 int ReturnCode; /* return code from vpd_read */
3798 unsigned long Flags;
3800 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3801 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, DeviceStr, &StrLen);
3802 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3807 /*****************************************************************************
3809 * StartDrvCleanupTimer - Start timer to check for descriptors which
3810 * might be placed in descriptor ring, but
3811 * havent been handled up to now
3814 * This function requests a HW-timer fo the Yukon card. The actions to
3815 * perform when this timer expires, are located in the SkDrvEvent().
3820 StartDrvCleanupTimer(SK_AC *pAC) {
3821 SK_EVPARA EventParam; /* Event struct for timer event */
3823 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
3824 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
3825 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
3826 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
3827 SKGE_DRV, SK_DRV_TIMER, EventParam);
3830 /*****************************************************************************
3832 * StopDrvCleanupTimer - Stop timer to check for descriptors
3835 * This function requests a HW-timer fo the Yukon card. The actions to
3836 * perform when this timer expires, are located in the SkDrvEvent().
3841 StopDrvCleanupTimer(SK_AC *pAC) {
3842 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
3843 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
3846 /****************************************************************************/
3847 /* functions for common modules *********************************************/
3848 /****************************************************************************/
3851 /*****************************************************************************
3853 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
3856 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
3857 * is embedded into a socket buff data area.
3863 * NULL or pointer to Mbuf.
3865 SK_MBUF *SkDrvAllocRlmtMbuf(
3866 SK_AC *pAC, /* pointer to adapter context */
3867 SK_IOC IoC, /* the IO-context */
3868 unsigned BufferSize) /* size of the requested buffer */
3870 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
3871 struct sk_buff *pMsgBlock; /* pointer to a new message block */
3873 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
3874 if (pMsgBlock == NULL) {
3877 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
3878 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
3879 pRlmtMbuf->pNext = NULL;
3880 pRlmtMbuf->pOs = pMsgBlock;
3881 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
3882 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
3883 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
3886 } /* SkDrvAllocRlmtMbuf */
3889 /*****************************************************************************
3891 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
3894 * This routine frees one or more RLMT mbuf(s).
3902 void SkDrvFreeRlmtMbuf(
3903 SK_AC *pAC, /* pointer to adapter context */
3904 SK_IOC IoC, /* the IO-context */
3905 SK_MBUF *pMbuf) /* size of the requested buffer */
3912 pNextMbuf = pFreeMbuf->pNext;
3913 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
3914 pFreeMbuf = pNextMbuf;
3915 } while ( pFreeMbuf != NULL );
3916 } /* SkDrvFreeRlmtMbuf */
3919 /*****************************************************************************
3921 * SkOsGetTime - provide a time value
3924 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
3925 * It is not used for absolute time, but only for time differences.
3931 SK_U64 SkOsGetTime(SK_AC *pAC)
3933 SK_U64 PrivateJiffies;
3934 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
3935 return PrivateJiffies;
3939 /*****************************************************************************
3941 * SkPciReadCfgDWord - read a 32 bit value from pci config space
3944 * This routine reads a 32 bit value from the pci configuration
3948 * 0 - indicate everything worked ok.
3949 * != 0 - error indication
3951 int SkPciReadCfgDWord(
3952 SK_AC *pAC, /* Adapter Control structure pointer */
3953 int PciAddr, /* PCI register address */
3954 SK_U32 *pVal) /* pointer to store the read value */
3956 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
3958 } /* SkPciReadCfgDWord */
3961 /*****************************************************************************
3963 * SkPciReadCfgWord - read a 16 bit value from pci config space
3966 * This routine reads a 16 bit value from the pci configuration
3970 * 0 - indicate everything worked ok.
3971 * != 0 - error indication
3973 int SkPciReadCfgWord(
3974 SK_AC *pAC, /* Adapter Control structure pointer */
3975 int PciAddr, /* PCI register address */
3976 SK_U16 *pVal) /* pointer to store the read value */
3978 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
3980 } /* SkPciReadCfgWord */
3983 /*****************************************************************************
3985 * SkPciReadCfgByte - read a 8 bit value from pci config space
3988 * This routine reads a 8 bit value from the pci configuration
3992 * 0 - indicate everything worked ok.
3993 * != 0 - error indication
3995 int SkPciReadCfgByte(
3996 SK_AC *pAC, /* Adapter Control structure pointer */
3997 int PciAddr, /* PCI register address */
3998 SK_U8 *pVal) /* pointer to store the read value */
4000 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4002 } /* SkPciReadCfgByte */
4005 /*****************************************************************************
4007 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4010 * This routine writes a 16 bit value to the pci configuration
4011 * space. The flag PciConfigUp indicates whether the config space
4012 * is accesible or must be set up first.
4015 * 0 - indicate everything worked ok.
4016 * != 0 - error indication
4018 int SkPciWriteCfgWord(
4019 SK_AC *pAC, /* Adapter Control structure pointer */
4020 int PciAddr, /* PCI register address */
4021 SK_U16 Val) /* pointer to store the read value */
4023 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4025 } /* SkPciWriteCfgWord */
4028 /*****************************************************************************
4030 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4033 * This routine writes a 8 bit value to the pci configuration
4034 * space. The flag PciConfigUp indicates whether the config space
4035 * is accesible or must be set up first.
4038 * 0 - indicate everything worked ok.
4039 * != 0 - error indication
4041 int SkPciWriteCfgByte(
4042 SK_AC *pAC, /* Adapter Control structure pointer */
4043 int PciAddr, /* PCI register address */
4044 SK_U8 Val) /* pointer to store the read value */
4046 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4048 } /* SkPciWriteCfgByte */
4051 /*****************************************************************************
4053 * SkDrvEvent - handle driver events
4056 * This function handles events from all modules directed to the driver
4059 * Is called under protection of slow path lock.
4062 * 0 if everything ok
4067 SK_AC *pAC, /* pointer to adapter context */
4068 SK_IOC IoC, /* io-context */
4069 SK_U32 Event, /* event-id */
4070 SK_EVPARA Param) /* event-parameter */
4072 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4073 struct sk_buff *pMsg; /* pointer to a message block */
4074 int FromPort; /* the port from which we switch away */
4075 int ToPort; /* the port we switch to */
4076 SK_EVPARA NewPara; /* parameter for further events */
4078 unsigned long Flags;
4082 case SK_DRV_ADAP_FAIL:
4083 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4084 ("ADAPTER FAIL EVENT\n"));
4085 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4086 /* disable interrupts */
4087 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4090 case SK_DRV_PORT_FAIL:
4091 FromPort = Param.Para32[0];
4092 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4093 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4094 if (FromPort == 0) {
4095 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4097 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4101 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4103 FromPort = Param.Para32[0];
4104 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4105 ("PORT RESET EVENT, Port: %d ", FromPort));
4106 NewPara.Para64 = FromPort;
4107 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4109 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4112 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4113 netif_carrier_off(pAC->dev[Param.Para32[0]]);
4114 spin_unlock_irqrestore(
4115 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4118 /* clear rx ring from received frames */
4119 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4121 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4123 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4126 /* tschilling: Handling of return value inserted. */
4127 if (SkGeInitPort(pAC, IoC, FromPort)) {
4128 if (FromPort == 0) {
4129 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4131 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4134 SkAddrMcUpdate(pAC,IoC, FromPort);
4135 PortReInitBmu(pAC, FromPort);
4136 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4137 ClearAndStartRx(pAC, FromPort);
4138 spin_unlock_irqrestore(
4139 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4142 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4143 { struct net_device *dev = pAC->dev[Param.Para32[0]];
4145 FromPort = Param.Para32[0];
4146 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4147 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4149 SkAddrMcUpdate(pAC,IoC, FromPort);
4151 if (DoPrintInterfaceChange) {
4152 printk("%s: network connection up using"
4153 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4155 /* tschilling: Values changed according to LinkSpeedUsed. */
4156 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4157 if (Stat == SK_LSPEED_STAT_10MBPS) {
4158 printk(" speed: 10\n");
4159 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4160 printk(" speed: 100\n");
4161 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4162 printk(" speed: 1000\n");
4164 printk(" speed: unknown\n");
4168 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4169 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4170 Stat == SK_LMODE_STAT_AUTOFULL) {
4171 printk(" autonegotiation: yes\n");
4174 printk(" autonegotiation: no\n");
4176 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4177 Stat == SK_LMODE_STAT_HALF) {
4178 printk(" duplex mode: half\n");
4181 printk(" duplex mode: full\n");
4183 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4184 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4185 printk(" flowctrl: remote send\n");
4187 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4188 printk(" flowctrl: local send\n");
4190 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4191 printk(" flowctrl: symmetric\n");
4194 printk(" flowctrl: none\n");
4197 /* tschilling: Check against CopperType now. */
4198 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4199 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4200 SK_LSPEED_STAT_1000MBPS)) {
4201 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4202 if (Stat == SK_MS_STAT_MASTER ) {
4203 printk(" role: master\n");
4205 else if (Stat == SK_MS_STAT_SLAVE ) {
4206 printk(" role: slave\n");
4209 printk(" role: ???\n");
4214 Display dim (dynamic interrupt moderation)
4217 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4218 printk(" irq moderation: static (%d ints/sec)\n",
4219 pAC->DynIrqModInfo.MaxModIntsPerSec);
4220 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4221 printk(" irq moderation: dynamic (%d ints/sec)\n",
4222 pAC->DynIrqModInfo.MaxModIntsPerSec);
4224 printk(" irq moderation: disabled\n");
4227 printk(" scatter-gather: %s\n",
4228 (dev->features & NETIF_F_SG) ? "enabled" : "disabled");
4229 printk(" tx-checksum: %s\n",
4230 (dev->features & NETIF_F_IP_CSUM) ? "enabled" : "disabled");
4231 printk(" rx-checksum: %s\n",
4232 pAC->RxPort[Param.Para32[0]].RxCsum ? "enabled" : "disabled");
4235 DoPrintInterfaceChange = SK_TRUE;
4238 if ((Param.Para32[0] != pAC->ActivePort) &&
4239 (pAC->RlmtNets == 1)) {
4240 NewPara.Para32[0] = pAC->ActivePort;
4241 NewPara.Para32[1] = Param.Para32[0];
4242 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4246 /* Inform the world that link protocol is up. */
4247 netif_carrier_on(dev);
4250 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4252 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4253 ("NET DOWN EVENT "));
4254 if (DoPrintInterfaceChange) {
4255 printk("%s: network connection down\n",
4256 pAC->dev[Param.Para32[1]]->name);
4258 DoPrintInterfaceChange = SK_TRUE;
4260 netif_carrier_off(pAC->dev[Param.Para32[1]]);
4262 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4263 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4264 ("PORT SWITCH HARD "));
4265 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4267 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4268 'A'+Param.Para32[1]);
4269 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4270 FromPort = Param.Para32[0];
4271 ToPort = Param.Para32[1];
4272 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4273 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4274 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4275 NewPara.Para64 = FromPort;
4276 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4277 NewPara.Para64 = ToPort;
4278 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4280 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4282 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4283 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4284 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4285 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4286 spin_unlock_irqrestore(
4287 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4290 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4291 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4293 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4294 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4296 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4298 spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4299 pAC->ActivePort = ToPort;
4303 /* tschilling: New common function with minimum size check. */
4305 if (pAC->RlmtNets == 2) {
4309 if (SkGeInitAssignRamToQueues(
4313 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4314 spin_unlock_irqrestore(
4315 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4317 printk("SkGeInitAssignRamToQueues failed.\n");
4321 /* tschilling: Handling of return values inserted. */
4322 if (SkGeInitPort(pAC, IoC, FromPort) ||
4323 SkGeInitPort(pAC, IoC, ToPort)) {
4324 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4326 if (Event == SK_DRV_SWITCH_SOFT) {
4327 SkMacRxTxEnable(pAC, IoC, FromPort);
4329 SkMacRxTxEnable(pAC, IoC, ToPort);
4330 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4331 SkAddrMcUpdate(pAC, IoC, FromPort);
4332 SkAddrMcUpdate(pAC, IoC, ToPort);
4333 PortReInitBmu(pAC, FromPort);
4334 PortReInitBmu(pAC, ToPort);
4335 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4336 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4337 ClearAndStartRx(pAC, FromPort);
4338 ClearAndStartRx(pAC, ToPort);
4339 spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
4340 spin_unlock_irqrestore(
4341 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4344 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4345 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4347 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4348 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4349 skb_put(pMsg, pRlmtMbuf->Length);
4350 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4353 DEV_KFREE_SKB_ANY(pMsg);
4356 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4358 ** expiration of the moderation timer implies that
4359 ** dynamic moderation is to be applied
4361 SkDimStartModerationTimer(pAC);
4363 if (pAC->DynIrqModInfo.DisplayStats) {
4364 SkDimDisplayModerationSettings(pAC);
4366 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4368 ** check if we need to check for descriptors which
4369 ** haven't been handled the last millisecs
4371 StartDrvCleanupTimer(pAC);
4372 if (pAC->GIni.GIMacsFound == 2) {
4373 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4375 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4377 printk("Expiration of unknown timer\n");
4383 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4390 /*****************************************************************************
4392 * SkErrorLog - log errors
4395 * This function logs errors to the system buffer and to the console
4398 * 0 if everything ok
4411 case SK_ERRCL_OTHER:
4412 strcpy(ClassStr, "Other error");
4414 case SK_ERRCL_CONFIG:
4415 strcpy(ClassStr, "Configuration error");
4418 strcpy(ClassStr, "Initialization error");
4420 case SK_ERRCL_NORES:
4421 strcpy(ClassStr, "Out of resources error");
4424 strcpy(ClassStr, "internal Software error");
4427 strcpy(ClassStr, "Hardware failure");
4430 strcpy(ClassStr, "Communication error");
4433 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4434 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4435 ClassStr, ErrNum, pErrorMsg);
4439 #ifdef SK_DIAG_SUPPORT
4441 /*****************************************************************************
4443 * SkDrvEnterDiagMode - handles DIAG attach request
4446 * Notify the kernel to NOT access the card any longer due to DIAG
4447 * Deinitialize the Card
4452 int SkDrvEnterDiagMode(
4453 SK_AC *pAc) /* pointer to adapter context */
4455 DEV_NET *pNet = netdev_priv(pAc->dev[0]);
4456 SK_AC *pAC = pNet->pAC;
4458 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4459 sizeof(SK_PNMI_STRUCT_DATA));
4461 pAC->DiagModeActive = DIAG_ACTIVE;
4462 if (pAC->BoardLevel > SK_INIT_DATA) {
4463 if (netif_running(pAC->dev[0])) {
4464 pAC->WasIfUp[0] = SK_TRUE;
4465 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4466 DoPrintInterfaceChange = SK_FALSE;
4467 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4469 pAC->WasIfUp[0] = SK_FALSE;
4471 if (pNet != netdev_priv(pAC->dev[1])) {
4472 pNet = netdev_priv(pAC->dev[1]);
4473 if (netif_running(pAC->dev[1])) {
4474 pAC->WasIfUp[1] = SK_TRUE;
4475 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4476 DoPrintInterfaceChange = SK_FALSE;
4477 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4479 pAC->WasIfUp[1] = SK_FALSE;
4482 pAC->BoardLevel = SK_INIT_DATA;
4487 /*****************************************************************************
4489 * SkDrvLeaveDiagMode - handles DIAG detach request
4492 * Notify the kernel to may access the card again after use by DIAG
4493 * Initialize the Card
4498 int SkDrvLeaveDiagMode(
4499 SK_AC *pAc) /* pointer to adapter control context */
4501 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4502 sizeof(SK_PNMI_STRUCT_DATA));
4503 pAc->DiagModeActive = DIAG_NOTACTIVE;
4504 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
4505 if (pAc->WasIfUp[0] == SK_TRUE) {
4506 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4507 DoPrintInterfaceChange = SK_FALSE;
4508 SkDrvInitAdapter(pAc, 0); /* first device */
4510 if (pAc->WasIfUp[1] == SK_TRUE) {
4511 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4512 DoPrintInterfaceChange = SK_FALSE;
4513 SkDrvInitAdapter(pAc, 1); /* second device */
4518 /*****************************************************************************
4520 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
4523 * This function parses the PCI slot name information string and will
4524 * retrieve the devcie number out of it. The slot_name maintianed by
4525 * linux is in the form of '02:0a.0', whereas the first two characters
4526 * represent the bus number in hex (in the sample above this is
4527 * pci bus 0x02) and the next two characters the device number (0x0a).
4530 * SK_U32: The device number from the PCI slot name
4533 static SK_U32 ParseDeviceNbrFromSlotName(
4534 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
4536 char *CurrCharPos = (char *) SlotName;
4537 int FirstNibble = -1;
4538 int SecondNibble = -1;
4541 while (*CurrCharPos != '\0') {
4542 if (*CurrCharPos == ':') {
4543 while (*CurrCharPos != '.') {
4545 if ( (*CurrCharPos >= '0') &&
4546 (*CurrCharPos <= '9')) {
4547 if (FirstNibble == -1) {
4548 /* dec. value for '0' */
4549 FirstNibble = *CurrCharPos - 48;
4551 SecondNibble = *CurrCharPos - 48;
4553 } else if ( (*CurrCharPos >= 'a') &&
4554 (*CurrCharPos <= 'f') ) {
4555 if (FirstNibble == -1) {
4556 FirstNibble = *CurrCharPos - 87;
4558 SecondNibble = *CurrCharPos - 87;
4565 Result = FirstNibble;
4566 Result = Result << 4; /* first nibble is higher one */
4567 Result = Result | SecondNibble;
4569 CurrCharPos++; /* next character */
4574 /****************************************************************************
4576 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
4577 * called if Diag attaches to that card)
4580 * Close initialized adapter.
4584 * error code - on error
4586 static int SkDrvDeInitAdapter(
4587 SK_AC *pAC, /* pointer to adapter context */
4588 int devNbr) /* what device is to be handled */
4590 struct SK_NET_DEVICE *dev;
4592 dev = pAC->dev[devNbr];
4594 /* On Linux 2.6 the network driver does NOT mess with reference
4595 ** counts. The driver MUST be able to be unloaded at any time
4596 ** due to the possibility of hotplug.
4598 if (SkGeClose(dev) != 0) {
4603 } /* SkDrvDeInitAdapter() */
4605 /****************************************************************************
4607 * SkDrvInitAdapter - Initialize adapter (this function is only
4608 * called if Diag deattaches from that card)
4611 * Close initialized adapter.
4615 * error code - on error
4617 static int SkDrvInitAdapter(
4618 SK_AC *pAC, /* pointer to adapter context */
4619 int devNbr) /* what device is to be handled */
4621 struct SK_NET_DEVICE *dev;
4623 dev = pAC->dev[devNbr];
4625 if (SkGeOpen(dev) != 0) {
4630 ** Use correct MTU size and indicate to kernel TX queue can be started
4632 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
4637 } /* SkDrvInitAdapter */
4642 /****************************************************************************/
4643 /* "debug only" section *****************************************************/
4644 /****************************************************************************/
4647 /*****************************************************************************
4649 * DumpMsg - print a frame
4652 * This function prints frames to the system logfile/to the console.
4657 static void DumpMsg(struct sk_buff *skb, char *str)
4662 printk("DumpMsg(): NULL-Message\n");
4666 if (skb->data == NULL) {
4667 printk("DumpMsg(): Message empty\n");
4675 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
4677 DumpData((char *)skb->data, msglen);
4679 printk("------- End of message ---------\n");
4684 /*****************************************************************************
4686 * DumpData - print a data area
4689 * This function prints a area of data to the system logfile/to the
4695 static void DumpData(char *p, int size)
4699 char hex_buffer[180];
4700 char asc_buffer[180];
4701 char HEXCHAR[] = "0123456789ABCDEF";
4707 for (i=0; i < size; ) {
4708 if (*p >= '0' && *p <='z')
4709 asc_buffer[addr] = *p;
4711 asc_buffer[addr] = '.';
4713 asc_buffer[addr] = 0;
4714 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
4716 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
4718 hex_buffer[haddr] = ' ';
4720 hex_buffer[haddr] = 0;
4724 printk("%s %s\n", hex_buffer, asc_buffer);
4732 /*****************************************************************************
4734 * DumpLong - print a data area as long values
4737 * This function prints a area of data to the system logfile/to the
4743 static void DumpLong(char *pc, int size)
4747 char hex_buffer[180];
4748 char asc_buffer[180];
4749 char HEXCHAR[] = "0123456789ABCDEF";
4758 for (i=0; i < size; ) {
4760 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
4762 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
4764 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
4766 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
4768 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
4770 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
4772 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
4774 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
4776 hex_buffer[haddr] = ' ';
4778 hex_buffer[haddr] = 0;
4782 printk("%4x %s\n", (i-8)*4, hex_buffer);
4786 printk("------------------------\n");
4791 static int __devinit skge_probe_one(struct pci_dev *pdev,
4792 const struct pci_device_id *ent)
4795 DEV_NET *pNet = NULL;
4796 struct net_device *dev = NULL;
4797 static int boards_found = 0;
4798 int error = -ENODEV;
4801 if (pci_enable_device(pdev))
4804 /* Configure DMA attributes. */
4805 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4806 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4807 goto out_disable_device;
4810 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
4811 printk(KERN_ERR "Unable to allocate etherdev "
4813 goto out_disable_device;
4816 pNet = netdev_priv(dev);
4817 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
4819 printk(KERN_ERR "Unable to allocate adapter "
4821 goto out_free_netdev;
4824 memset(pNet->pAC, 0, sizeof(SK_AC));
4830 pAC->CheckQueue = SK_FALSE;
4832 dev->irq = pdev->irq;
4833 error = SkGeInitPCI(pAC);
4835 printk(KERN_ERR "sk98lin: PCI setup failed: %i\n", error);
4836 goto out_free_netdev;
4839 SET_MODULE_OWNER(dev);
4840 dev->open = &SkGeOpen;
4841 dev->stop = &SkGeClose;
4842 dev->hard_start_xmit = &SkGeXmit;
4843 dev->get_stats = &SkGeStats;
4844 dev->set_multicast_list = &SkGeSetRxMode;
4845 dev->set_mac_address = &SkGeSetMacAddr;
4846 dev->do_ioctl = &SkGeIoctl;
4847 dev->change_mtu = &SkGeChangeMtu;
4848 #ifdef CONFIG_NET_POLL_CONTROLLER
4849 dev->poll_controller = &SkGePollController;
4851 SET_NETDEV_DEV(dev, &pdev->dev);
4852 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4854 /* Use only if yukon hardware */
4855 if (pAC->ChipsetType) {
4856 #ifdef USE_SK_TX_CHECKSUM
4857 dev->features |= NETIF_F_IP_CSUM;
4860 dev->features |= NETIF_F_SG;
4862 #ifdef USE_SK_RX_CHECKSUM
4863 pAC->RxPort[0].RxCsum = 1;
4867 pAC->Index = boards_found++;
4869 if (SkGeBoardInit(dev, pAC))
4870 goto out_free_netdev;
4872 /* Read Adapter name from VPD */
4873 if (ProductStr(pAC, DeviceStr, sizeof(DeviceStr)) != 0) {
4874 printk(KERN_ERR "sk98lin: Could not read VPD data.\n");
4875 goto out_free_resources;
4878 /* Register net device */
4879 if (register_netdev(dev)) {
4880 printk(KERN_ERR "sk98lin: Could not register device.\n");
4881 goto out_free_resources;
4884 /* Print adapter specific string from vpd */
4885 printk("%s: %s\n", dev->name, DeviceStr);
4887 /* Print configuration settings */
4888 printk(" PrefPort:%c RlmtMode:%s\n",
4889 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
4890 (pAC->RlmtMode==0) ? "Check Link State" :
4891 ((pAC->RlmtMode==1) ? "Check Link State" :
4892 ((pAC->RlmtMode==3) ? "Check Local Port" :
4893 ((pAC->RlmtMode==7) ? "Check Segmentation" :
4894 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
4896 SkGeYellowLED(pAC, pAC->IoBase, 1);
4898 memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
4899 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4901 SkGeProcCreate(dev);
4908 /* More then one port found */
4909 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
4910 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
4911 printk(KERN_ERR "Unable to allocate etherdev "
4917 pNet = netdev_priv(dev);
4922 dev->open = &SkGeOpen;
4923 dev->stop = &SkGeClose;
4924 dev->hard_start_xmit = &SkGeXmit;
4925 dev->get_stats = &SkGeStats;
4926 dev->set_multicast_list = &SkGeSetRxMode;
4927 dev->set_mac_address = &SkGeSetMacAddr;
4928 dev->do_ioctl = &SkGeIoctl;
4929 dev->change_mtu = &SkGeChangeMtu;
4930 SET_NETDEV_DEV(dev, &pdev->dev);
4931 SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
4933 if (pAC->ChipsetType) {
4934 #ifdef USE_SK_TX_CHECKSUM
4935 dev->features |= NETIF_F_IP_CSUM;
4938 dev->features |= NETIF_F_SG;
4940 #ifdef USE_SK_RX_CHECKSUM
4941 pAC->RxPort[1].RxCsum = 1;
4945 if (register_netdev(dev)) {
4946 printk(KERN_ERR "sk98lin: Could not register device for seconf port.\n");
4948 pAC->dev[1] = pAC->dev[0];
4950 SkGeProcCreate(dev);
4951 memcpy(&dev->dev_addr,
4952 &pAC->Addr.Net[1].CurrentMacAddress, 6);
4953 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4955 printk("%s: %s\n", dev->name, DeviceStr);
4956 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
4960 /* Save the hardware revision */
4961 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
4962 (pAC->GIni.GIPciHwRev & 0x0F);
4964 /* Set driver globals */
4965 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
4966 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
4968 memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
4969 memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
4971 pci_set_drvdata(pdev, dev);
4979 pci_disable_device(pdev);
4984 static void __devexit skge_remove_one(struct pci_dev *pdev)
4986 struct net_device *dev = pci_get_drvdata(pdev);
4987 DEV_NET *pNet = netdev_priv(dev);
4988 SK_AC *pAC = pNet->pAC;
4989 struct net_device *otherdev = pAC->dev[1];
4991 SkGeProcRemove(dev);
4992 unregister_netdev(dev);
4993 if (otherdev != dev)
4994 SkGeProcRemove(otherdev);
4996 SkGeYellowLED(pAC, pAC->IoBase, 0);
4998 if (pAC->BoardLevel == SK_INIT_RUN) {
5000 unsigned long Flags;
5002 /* board is still alive */
5003 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
5004 EvPara.Para32[0] = 0;
5005 EvPara.Para32[1] = -1;
5006 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5007 EvPara.Para32[0] = 1;
5008 EvPara.Para32[1] = -1;
5009 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
5010 SkEventDispatcher(pAC, pAC->IoBase);
5011 /* disable interrupts */
5012 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
5013 SkGeDeInit(pAC, pAC->IoBase);
5014 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
5015 pAC->BoardLevel = SK_INIT_DATA;
5016 /* We do NOT check here, if IRQ was pending, of course*/
5019 if (pAC->BoardLevel == SK_INIT_IO) {
5020 /* board is still alive */
5021 SkGeDeInit(pAC, pAC->IoBase);
5022 pAC->BoardLevel = SK_INIT_DATA;
5027 if (otherdev != dev)
5028 free_netdev(otherdev);
5033 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5035 struct net_device *dev = pci_get_drvdata(pdev);
5036 DEV_NET *pNet = netdev_priv(dev);
5037 SK_AC *pAC = pNet->pAC;
5038 struct net_device *otherdev = pAC->dev[1];
5040 if (netif_running(dev)) {
5041 netif_carrier_off(dev);
5042 DoPrintInterfaceChange = SK_FALSE;
5043 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5044 netif_device_detach(dev);
5046 if (otherdev != dev) {
5047 if (netif_running(otherdev)) {
5048 netif_carrier_off(otherdev);
5049 DoPrintInterfaceChange = SK_FALSE;
5050 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5051 netif_device_detach(otherdev);
5055 pci_save_state(pdev);
5056 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5057 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5058 free_irq(dev->irq, dev);
5060 pci_disable_device(pdev);
5061 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5066 static int skge_resume(struct pci_dev *pdev)
5068 struct net_device *dev = pci_get_drvdata(pdev);
5069 DEV_NET *pNet = netdev_priv(dev);
5070 SK_AC *pAC = pNet->pAC;
5071 struct net_device *otherdev = pAC->dev[1];
5074 pci_set_power_state(pdev, PCI_D0);
5075 pci_restore_state(pdev);
5076 pci_enable_device(pdev);
5077 pci_set_master(pdev);
5078 if (pAC->GIni.GIMacsFound == 2)
5079 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, "sk98lin", dev);
5081 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, "sk98lin", dev);
5083 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5084 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5086 pci_disable_device(pdev);
5090 netif_device_attach(dev);
5091 if (netif_running(dev)) {
5092 DoPrintInterfaceChange = SK_FALSE;
5093 SkDrvInitAdapter(pAC, 0); /* first device */
5095 if (otherdev != dev) {
5096 netif_device_attach(otherdev);
5097 if (netif_running(otherdev)) {
5098 DoPrintInterfaceChange = SK_FALSE;
5099 SkDrvInitAdapter(pAC, 1); /* second device */
5106 #define skge_suspend NULL
5107 #define skge_resume NULL
5110 static struct pci_device_id skge_pci_tbl[] = {
5111 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5112 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5113 { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5114 { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5115 /* DLink card does not have valid VPD so this driver gags
5116 * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5118 { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5119 { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5120 { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5121 { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
5122 { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5126 MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
5128 static struct pci_driver skge_driver = {
5130 .id_table = skge_pci_tbl,
5131 .probe = skge_probe_one,
5132 .remove = __devexit_p(skge_remove_one),
5133 .suspend = skge_suspend,
5134 .resume = skge_resume,
5137 static int __init skge_init(void)
5141 pSkRootDir = proc_mkdir(SKRootName, NULL);
5143 pSkRootDir->owner = THIS_MODULE;
5145 error = pci_register_driver(&skge_driver);
5147 remove_proc_entry(SKRootName, NULL);
5151 static void __exit skge_exit(void)
5153 pci_unregister_driver(&skge_driver);
5154 remove_proc_entry(SKRootName, NULL);
5158 module_init(skge_init);
5159 module_exit(skge_exit);