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:
107 ******************************************************************************/
109 #include "h/skversion.h"
111 #include <linux/module.h>
112 #include <linux/init.h>
114 #ifdef CONFIG_PROC_FS
115 #include <linux/proc_fs.h>
118 #include "h/skdrv1st.h"
119 #include "h/skdrv2nd.h"
121 /*******************************************************************************
125 ******************************************************************************/
127 /* for debuging on x86 only */
128 /* #define BREAKPOINT() asm(" int $3"); */
130 /* use the transmit hw checksum driver functionality */
131 #define USE_SK_TX_CHECKSUM
133 /* use the receive hw checksum driver functionality */
134 #define USE_SK_RX_CHECKSUM
136 /* use the scatter-gather functionality with sendfile() */
139 /* use of a transmit complete interrupt */
140 #define USE_TX_COMPLETE
143 * threshold for copying small receive frames
144 * set to 0 to avoid copying, set to 9001 to copy all frames
146 #define SK_COPY_THRESHOLD 50
148 /* number of adapters that can be configured via command line params */
149 #define SK_MAX_CARD_PARAM 16
154 * use those defines for a compile-in version of the driver instead
155 * of command line parameters
157 // #define LINK_SPEED_A {"Auto", }
158 // #define LINK_SPEED_B {"Auto", }
159 // #define AUTO_NEG_A {"Sense", }
160 // #define AUTO_NEG_B {"Sense", }
161 // #define DUP_CAP_A {"Both", }
162 // #define DUP_CAP_B {"Both", }
163 // #define FLOW_CTRL_A {"SymOrRem", }
164 // #define FLOW_CTRL_B {"SymOrRem", }
165 // #define ROLE_A {"Auto", }
166 // #define ROLE_B {"Auto", }
167 // #define PREF_PORT {"A", }
168 // #define CON_TYPE {"Auto", }
169 // #define RLMT_MODE {"CheckLinkState", }
171 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
172 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
173 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
177 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
178 SK_DUP_LED_NORMAL | \
182 /* Isr return value */
183 #define SkIsrRetVar irqreturn_t
184 #define SkIsrRetNone IRQ_NONE
185 #define SkIsrRetHandled IRQ_HANDLED
188 /*******************************************************************************
190 * Local Function Prototypes
192 ******************************************************************************/
194 static void FreeResources(struct SK_NET_DEVICE *dev);
195 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
196 static SK_BOOL BoardAllocMem(SK_AC *pAC);
197 static void BoardFreeMem(SK_AC *pAC);
198 static void BoardInitMem(SK_AC *pAC);
199 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
200 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
201 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
202 static int SkGeOpen(struct SK_NET_DEVICE *dev);
203 static int SkGeClose(struct SK_NET_DEVICE *dev);
204 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
205 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
206 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
207 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
208 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
209 static void GetConfiguration(SK_AC*);
210 static void ProductStr(SK_AC*);
211 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
212 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
213 static void FillRxRing(SK_AC*, RX_PORT*);
214 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
215 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
216 static void ClearAndStartRx(SK_AC*, int);
217 static void ClearTxIrq(SK_AC*, int, int);
218 static void ClearRxRing(SK_AC*, RX_PORT*);
219 static void ClearTxRing(SK_AC*, TX_PORT*);
220 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
221 static void PortReInitBmu(SK_AC*, int);
222 static int SkGeIocMib(DEV_NET*, unsigned int, int);
223 static int SkGeInitPCI(SK_AC *pAC);
224 static void StartDrvCleanupTimer(SK_AC *pAC);
225 static void StopDrvCleanupTimer(SK_AC *pAC);
226 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
228 #ifdef SK_DIAG_SUPPORT
229 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
230 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
231 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
234 /*******************************************************************************
236 * Extern Function Prototypes
238 ******************************************************************************/
240 #ifdef CONFIG_PROC_FS
241 static const char SK_Root_Dir_entry[] = "sk98lin";
242 static struct proc_dir_entry *pSkRootDir = NULL;
243 extern struct file_operations sk_proc_fops;
246 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
247 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
248 extern void SkDimStartModerationTimer(SK_AC *pAC);
249 extern void SkDimModerate(SK_AC *pAC);
252 static void DumpMsg(struct sk_buff*, char*);
253 static void DumpData(char*, int);
254 static void DumpLong(char*, int);
257 /* global variables *********************************************************/
258 static const char *BootString = BOOT_STRING;
259 struct SK_NET_DEVICE *SkGeRootDev = NULL;
260 static int probed __initdata = 0;
261 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
263 /* local variables **********************************************************/
264 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
265 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
268 #ifdef CONFIG_PROC_FS
269 static struct proc_dir_entry *pSkRootDir;
274 /*****************************************************************************
276 * skge_probe - find all SK-98xx adapters
279 * This function scans the PCI bus for SK-98xx adapters. Resources for
280 * each adapter are allocated and the adapter is brought into Init 1
284 * 0, if everything is ok
287 static int __init skge_probe (void)
289 int boards_found = 0;
290 int vendor_flag = SK_FALSE;
292 DEV_NET *pNet = NULL;
293 struct pci_dev *pdev = NULL;
294 struct SK_NET_DEVICE *dev = NULL;
295 SK_BOOL DeviceFound = SK_FALSE;
296 SK_BOOL BootStringCount = SK_FALSE;
298 #ifdef CONFIG_PROC_FS
299 struct proc_dir_entry *pProcFile;
307 while((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev))) {
309 if (pci_enable_device(pdev)) {
315 /* Don't handle Yukon2 cards at the moment */
316 /* 12-feb-2004 ---- mlindner@syskonnect.de */
317 if (pdev->vendor == 0x11ab) {
318 if ( (pdev->device == 0x4360) || (pdev->device == 0x4361) )
322 SK_PCI_ISCOMPLIANT(vendor_flag, pdev);
326 /* Configure DMA attributes. */
327 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) &&
328 pci_set_dma_mask(pdev, (u64) 0xffffffff))
332 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
333 printk(KERN_ERR "Unable to allocate etherdev "
339 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
340 if (pNet->pAC == NULL){
342 printk(KERN_ERR "Unable to allocate adapter "
348 if (!BootStringCount) {
349 /* set display flag to TRUE so that */
350 /* we only display this string ONCE */
351 BootStringCount = SK_TRUE;
352 printk("%s\n", BootString);
355 memset(pNet->pAC, 0, sizeof(SK_AC));
358 pAC->PciDevId = pdev->device;
361 sprintf(pAC->Name, "SysKonnect SK-98xx");
362 pAC->CheckQueue = SK_FALSE;
366 dev->irq = pdev->irq;
367 retval = SkGeInitPCI(pAC);
369 printk("SKGE: PCI setup failed: %i\n", retval);
374 SET_MODULE_OWNER(dev);
375 dev->open = &SkGeOpen;
376 dev->stop = &SkGeClose;
377 dev->hard_start_xmit = &SkGeXmit;
378 dev->get_stats = &SkGeStats;
379 dev->last_stats = &SkGeStats;
380 dev->set_multicast_list = &SkGeSetRxMode;
381 dev->set_mac_address = &SkGeSetMacAddr;
382 dev->do_ioctl = &SkGeIoctl;
383 dev->change_mtu = &SkGeChangeMtu;
384 dev->flags &= ~IFF_RUNNING;
387 #ifdef USE_SK_TX_CHECKSUM
389 if (pAC->ChipsetType) {
390 /* Use only if yukon hardware */
391 /* SK and ZEROCOPY - fly baby... */
392 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
397 pAC->Index = boards_found;
399 if (SkGeBoardInit(dev, pAC)) {
404 /* Register net device */
405 if (register_netdev(dev)) {
406 printk(KERN_ERR "SKGE: Could not register device.\n");
412 /* Print adapter specific string from vpd */
414 printk("%s: %s\n", dev->name, pAC->DeviceStr);
416 /* Print configuration settings */
417 printk(" PrefPort:%c RlmtMode:%s\n",
418 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
419 (pAC->RlmtMode==0) ? "Check Link State" :
420 ((pAC->RlmtMode==1) ? "Check Link State" :
421 ((pAC->RlmtMode==3) ? "Check Local Port" :
422 ((pAC->RlmtMode==7) ? "Check Segmentation" :
423 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
425 SkGeYellowLED(pAC, pAC->IoBase, 1);
428 memcpy((caddr_t) &dev->dev_addr,
429 (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
431 /* First adapter... Create proc and print message */
432 #ifdef CONFIG_PROC_FS
434 DeviceFound = SK_TRUE;
435 SK_MEMCPY(&SK_Root_Dir_entry, BootString,
436 sizeof(SK_Root_Dir_entry) - 1);
438 /*Create proc (directory)*/
440 pSkRootDir = proc_mkdir(SK_Root_Dir_entry, proc_net);
442 printk(KERN_WARNING "%s: Unable to create /proc/net/%s",
443 dev->name, SK_Root_Dir_entry);
445 pSkRootDir->owner = THIS_MODULE;
450 /* Create proc file */
452 (pProcFile = create_proc_entry(dev->name, S_IRUGO,
454 pProcFile->proc_fops = &sk_proc_fops;
455 pProcFile->data = dev;
465 /* More then one port found */
466 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
467 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
468 printk(KERN_ERR "Unable to allocate etherdev "
481 dev->open = &SkGeOpen;
482 dev->stop = &SkGeClose;
483 dev->hard_start_xmit = &SkGeXmit;
484 dev->get_stats = &SkGeStats;
485 dev->last_stats = &SkGeStats;
486 dev->set_multicast_list = &SkGeSetRxMode;
487 dev->set_mac_address = &SkGeSetMacAddr;
488 dev->do_ioctl = &SkGeIoctl;
489 dev->change_mtu = &SkGeChangeMtu;
490 dev->flags &= ~IFF_RUNNING;
493 #ifdef USE_SK_TX_CHECKSUM
494 if (pAC->ChipsetType) {
495 /* SG and ZEROCOPY - fly baby... */
496 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
501 if (register_netdev(dev)) {
502 printk(KERN_ERR "SKGE: Could not register device.\n");
504 pAC->dev[1] = pAC->dev[0];
506 #ifdef CONFIG_PROC_FS
508 && (pProcFile = create_proc_entry(dev->name,
509 S_IRUGO, pSkRootDir))) {
510 pProcFile->proc_fops = &sk_proc_fops;
511 pProcFile->data = dev;
515 memcpy((caddr_t) &dev->dev_addr,
516 (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
518 printk("%s: %s\n", dev->name, pAC->DeviceStr);
519 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
523 /* Save the hardware revision */
524 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
525 (pAC->GIni.GIPciHwRev & 0x0F);
527 /* Set driver globals */
528 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
529 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
531 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
532 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
533 sizeof(SK_PNMI_STRUCT_DATA));
536 * This is bollocks, but we need to tell the net-init
537 * code that it shall go for the next device.
545 * If we're at this point we're going through skge_probe() for
546 * the first time. Return success (0) if we've initialized 1
547 * or more boards. Otherwise, return failure (-ENODEV).
554 /*****************************************************************************
556 * SkGeInitPCI - Init the PCI resources
559 * This function initialize the PCI resources and IO
564 int SkGeInitPCI(SK_AC *pAC)
566 struct SK_NET_DEVICE *dev = pAC->dev[0];
567 struct pci_dev *pdev = pAC->PciDev;
570 if (pci_enable_device(pdev) != 0) {
574 dev->mem_start = pci_resource_start (pdev, 0);
575 pci_set_master(pdev);
577 if (pci_request_regions(pdev, pAC->Name) != 0) {
584 * On big endian machines, we use the adapter's aibility of
585 * reading the descriptors as big endian.
589 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
590 our2 |= PCI_REV_DESC;
591 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
596 * Remap the regs into kernel space.
598 pAC->IoBase = (char*)ioremap_nocache(dev->mem_start, 0x4000);
608 pci_release_regions(pdev);
610 pci_disable_device(pdev);
615 /*****************************************************************************
617 * FreeResources - release resources allocated for adapter
620 * This function releases the IRQ, unmaps the IO and
621 * frees the desriptor ring.
626 static void FreeResources(struct SK_NET_DEVICE *dev)
633 pNet = (DEV_NET*) dev->priv;
635 AllocFlag = pAC->AllocFlag;
637 pci_release_regions(pAC->PciDev);
639 if (AllocFlag & SK_ALLOC_IRQ) {
640 free_irq(dev->irq, dev);
643 iounmap(pAC->IoBase);
645 if (pAC->pDescrMem) {
650 } /* FreeResources */
652 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
653 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
654 MODULE_LICENSE("GPL");
655 MODULE_PARM(Speed_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
656 MODULE_PARM(Speed_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
657 MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
658 MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
659 MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
660 MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
661 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
662 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
663 MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
664 MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
665 MODULE_PARM(ConType, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
666 MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
667 MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
668 /* not used, just there because every driver should have them: */
669 MODULE_PARM(options, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
670 MODULE_PARM(debug, "i");
671 /* used for interrupt moderation */
672 MODULE_PARM(IntsPerSec, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
673 MODULE_PARM(Moderation, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
674 MODULE_PARM(Stats, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
675 MODULE_PARM(ModerationMask, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
676 MODULE_PARM(AutoSizing, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
680 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
682 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
686 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
688 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
692 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
694 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
698 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
700 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
704 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
706 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
710 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
712 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
716 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
718 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
722 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
724 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
728 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
730 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
734 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
736 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
740 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
742 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
746 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
748 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
752 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
754 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
757 static int debug = 0; /* not used */
758 static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
760 static int IntsPerSec[SK_MAX_CARD_PARAM];
761 static char *Moderation[SK_MAX_CARD_PARAM];
762 static char *ModerationMask[SK_MAX_CARD_PARAM];
763 static char *AutoSizing[SK_MAX_CARD_PARAM];
764 static char *Stats[SK_MAX_CARD_PARAM];
767 /*****************************************************************************
769 * skge_init_module - module initialization function
772 * Very simple, only call skge_probe and return approriate result.
775 * 0, if everything is ok
778 static int __init skge_init_module(void)
783 /* just to avoid warnings ... */
787 cards = skge_probe();
789 printk("sk98lin: No adapter found.\n");
791 return cards ? 0 : -ENODEV;
792 } /* skge_init_module */
795 /*****************************************************************************
797 * skge_cleanup_module - module unload function
800 * Disable adapter if it is still running, free resources,
801 * free device struct.
805 static void __exit skge_cleanup_module(void)
809 struct SK_NET_DEVICE *next;
813 while (SkGeRootDev) {
814 pNet = (DEV_NET*) SkGeRootDev->priv;
818 netif_stop_queue(SkGeRootDev);
819 SkGeYellowLED(pAC, pAC->IoBase, 0);
821 if(pAC->BoardLevel == SK_INIT_RUN) {
822 /* board is still alive */
823 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
824 EvPara.Para32[0] = 0;
825 EvPara.Para32[1] = -1;
826 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
827 EvPara.Para32[0] = 1;
828 EvPara.Para32[1] = -1;
829 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
830 SkEventDispatcher(pAC, pAC->IoBase);
831 /* disable interrupts */
832 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
833 SkGeDeInit(pAC, pAC->IoBase);
834 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
835 pAC->BoardLevel = SK_INIT_DATA;
836 /* We do NOT check here, if IRQ was pending, of course*/
839 if(pAC->BoardLevel == SK_INIT_IO) {
840 /* board is still alive */
841 SkGeDeInit(pAC, pAC->IoBase);
842 pAC->BoardLevel = SK_INIT_DATA;
845 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
846 unregister_netdev(pAC->dev[1]);
847 free_netdev(pAC->dev[1]);
850 FreeResources(SkGeRootDev);
852 SkGeRootDev->get_stats = NULL;
854 * otherwise unregister_netdev calls get_stats with
857 unregister_netdev(SkGeRootDev);
858 free_netdev(SkGeRootDev);
863 #ifdef CONFIG_PROC_FS
865 remove_proc_entry(pSkRootDir->name, proc_net);
868 } /* skge_cleanup_module */
870 module_init(skge_init_module);
871 module_exit(skge_cleanup_module);
874 /*****************************************************************************
876 * SkGeBoardInit - do level 0 and 1 initialization
879 * This function prepares the board hardware for running. The desriptor
880 * ring is set up, the IRQ is allocated and the configuration settings
884 * 0, if everything is ok
887 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
891 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
892 char *VerStr = VER_STRING;
893 int Ret; /* return code of request_irq */
896 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
897 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
898 for (i=0; i<SK_MAX_MACS; i++) {
899 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
900 pAC->TxPort[i][0].PortIndex = i;
901 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
902 pAC->RxPort[i].PortIndex = i;
905 /* Initialize the mutexes */
906 for (i=0; i<SK_MAX_MACS; i++) {
907 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
908 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
910 spin_lock_init(&pAC->SlowPathLock);
912 /* level 0 init common modules here */
914 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
915 /* Does a RESET on board ...*/
916 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
917 printk("HWInit (0) failed.\n");
918 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
921 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
922 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
923 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
924 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
925 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
926 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
928 pAC->BoardLevel = SK_INIT_DATA;
929 pAC->RxBufSize = ETH_BUF_SIZE;
931 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
932 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
934 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
936 /* level 1 init common modules here (HW init) */
937 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
938 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
939 printk("sk98lin: HWInit (1) failed.\n");
940 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
943 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
944 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
945 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
946 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
947 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
948 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
950 /* Set chipset type support */
951 pAC->ChipsetType = 0;
952 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
953 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
954 pAC->ChipsetType = 1;
957 GetConfiguration(pAC);
958 if (pAC->RlmtNets == 2) {
959 pAC->GIni.GIPortUsage = SK_MUL_LINK;
962 pAC->BoardLevel = SK_INIT_IO;
963 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
965 if (pAC->GIni.GIMacsFound == 2) {
966 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
967 } else if (pAC->GIni.GIMacsFound == 1) {
968 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
971 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
972 pAC->GIni.GIMacsFound);
977 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
981 pAC->AllocFlag |= SK_ALLOC_IRQ;
983 /* Alloc memory for this board (Mem for RxD/TxD) : */
984 if(!BoardAllocMem(pAC)) {
985 printk("No memory for descriptor rings.\n");
989 SkCsSetReceiveFlags(pAC,
990 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
991 &pAC->CsOfs1, &pAC->CsOfs2, 0);
992 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
995 /* tschilling: New common function with minimum size check. */
997 if (pAC->RlmtNets == 2) {
1001 if (SkGeInitAssignRamToQueues(
1006 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
1011 * Register the device here
1013 pAC->Next = SkGeRootDev;
1017 } /* SkGeBoardInit */
1020 /*****************************************************************************
1022 * BoardAllocMem - allocate the memory for the descriptor rings
1025 * This function allocates the memory for all descriptor rings.
1026 * Each ring is aligned for the desriptor alignment and no ring
1027 * has a 4 GByte boundary in it (because the upper 32 bit must
1028 * be constant for all descriptiors in one rings).
1031 * SK_TRUE, if all memory could be allocated
1034 static SK_BOOL BoardAllocMem(
1037 caddr_t pDescrMem; /* pointer to descriptor memory area */
1038 size_t AllocLength; /* length of complete descriptor area */
1039 int i; /* loop counter */
1040 unsigned long BusAddr;
1043 /* rings plus one for alignment (do not cross 4 GB boundary) */
1044 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
1045 #if (BITS_PER_LONG == 32)
1046 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1048 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1052 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
1053 &pAC->pDescrMemDMA);
1055 if (pDescrMem == NULL) {
1058 pAC->pDescrMem = pDescrMem;
1059 BusAddr = (unsigned long) pAC->pDescrMemDMA;
1061 /* Descriptors need 8 byte alignment, and this is ensured
1062 * by pci_alloc_consistent.
1064 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1065 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1066 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
1067 i, (unsigned long) pDescrMem,
1069 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
1070 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
1071 pDescrMem += TX_RING_SIZE;
1072 BusAddr += TX_RING_SIZE;
1074 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1075 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
1076 i, (unsigned long) pDescrMem,
1077 (unsigned long)BusAddr));
1078 pAC->RxPort[i].pRxDescrRing = pDescrMem;
1079 pAC->RxPort[i].VRxDescrRing = BusAddr;
1080 pDescrMem += RX_RING_SIZE;
1081 BusAddr += RX_RING_SIZE;
1085 } /* BoardAllocMem */
1088 /****************************************************************************
1090 * BoardFreeMem - reverse of BoardAllocMem
1093 * Free all memory allocated in BoardAllocMem: adapter context,
1094 * descriptor rings, locks.
1098 static void BoardFreeMem(
1101 size_t AllocLength; /* length of complete descriptor area */
1103 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1104 ("BoardFreeMem\n"));
1105 #if (BITS_PER_LONG == 32)
1106 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1108 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1112 pci_free_consistent(pAC->PciDev, AllocLength,
1113 pAC->pDescrMem, pAC->pDescrMemDMA);
1114 pAC->pDescrMem = NULL;
1115 } /* BoardFreeMem */
1118 /*****************************************************************************
1120 * BoardInitMem - initiate the descriptor rings
1123 * This function sets the descriptor rings up in memory.
1124 * The adapter is initialized with the descriptor start addresses.
1128 static void BoardInitMem(
1129 SK_AC *pAC) /* pointer to adapter context */
1131 int i; /* loop counter */
1132 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
1133 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
1135 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1136 ("BoardInitMem\n"));
1138 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1139 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
1140 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1141 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
1143 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1146 pAC->TxPort[i][0].pTxDescrRing,
1147 pAC->TxPort[i][0].VTxDescrRing,
1148 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
1149 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
1150 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
1151 &pAC->TxPort[i][0].TxdRingFree,
1155 pAC->RxPort[i].pRxDescrRing,
1156 pAC->RxPort[i].VRxDescrRing,
1157 &pAC->RxPort[i].pRxdRingHead,
1158 &pAC->RxPort[i].pRxdRingTail,
1159 &pAC->RxPort[i].pRxdRingPrev,
1160 &pAC->RxPort[i].RxdRingFree,
1163 } /* BoardInitMem */
1166 /*****************************************************************************
1168 * SetupRing - create one descriptor ring
1171 * This function creates one descriptor ring in the given memory area.
1172 * The head, tail and number of free descriptors in the ring are set.
1177 static void SetupRing(
1179 void *pMemArea, /* a pointer to the memory area for the ring */
1180 uintptr_t VMemArea, /* the virtual bus address of the memory area */
1181 RXD **ppRingHead, /* address where the head should be written */
1182 RXD **ppRingTail, /* address where the tail should be written */
1183 RXD **ppRingPrev, /* address where the tail should be written */
1184 int *pRingFree, /* address where the # of free descr. goes */
1185 SK_BOOL IsTx) /* flag: is this a tx ring */
1187 int i; /* loop counter */
1188 int DescrSize; /* the size of a descriptor rounded up to alignment*/
1189 int DescrNum; /* number of descriptors per ring */
1190 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
1191 RXD *pNextDescr; /* pointer to the next descriptor */
1192 RXD *pPrevDescr; /* pointer to the previous descriptor */
1193 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
1195 if (IsTx == SK_TRUE) {
1196 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
1198 DescrNum = TX_RING_SIZE / DescrSize;
1200 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1202 DescrNum = RX_RING_SIZE / DescrSize;
1205 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1206 ("Descriptor size: %d Descriptor Number: %d\n",
1207 DescrSize,DescrNum));
1209 pDescr = (RXD*) pMemArea;
1211 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1212 VNextDescr = VMemArea + DescrSize;
1213 for(i=0; i<DescrNum; i++) {
1214 /* set the pointers right */
1215 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1216 pDescr->pNextRxd = pNextDescr;
1217 pDescr->TcpSumStarts = pAC->CsOfs;
1219 /* advance one step */
1220 pPrevDescr = pDescr;
1221 pDescr = pNextDescr;
1222 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1223 VNextDescr += DescrSize;
1225 pPrevDescr->pNextRxd = (RXD*) pMemArea;
1226 pPrevDescr->VNextRxd = VMemArea;
1227 pDescr = (RXD*) pMemArea;
1228 *ppRingHead = (RXD*) pMemArea;
1229 *ppRingTail = *ppRingHead;
1230 *ppRingPrev = pPrevDescr;
1231 *pRingFree = DescrNum;
1235 /*****************************************************************************
1237 * PortReInitBmu - re-initiate the descriptor rings for one port
1240 * This function reinitializes the descriptor rings of one port
1241 * in memory. The port must be stopped before.
1242 * The HW is initialized with the descriptor start addresses.
1247 static void PortReInitBmu(
1248 SK_AC *pAC, /* pointer to adapter context */
1249 int PortIndex) /* index of the port for which to re-init */
1251 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1252 ("PortReInitBmu "));
1254 /* set address of first descriptor of ring in BMU */
1255 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
1256 (uint32_t)(((caddr_t)
1257 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1258 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1259 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1261 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
1262 (uint32_t)(((caddr_t)
1263 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1264 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1265 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1266 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
1267 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1268 pAC->RxPort[PortIndex].pRxDescrRing +
1269 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1270 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
1271 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1272 pAC->RxPort[PortIndex].pRxDescrRing +
1273 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1274 } /* PortReInitBmu */
1277 /****************************************************************************
1279 * SkGeIsr - handle adapter interrupts
1282 * The interrupt routine is called when the network adapter
1283 * generates an interrupt. It may also be called if another device
1284 * shares this interrupt vector with the driver.
1289 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1291 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1294 SK_U32 IntSrc; /* interrupts source register contents */
1296 pNet = (DEV_NET*) dev->priv;
1300 * Check and process if its our interrupt
1302 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1304 return SkIsrRetNone;
1307 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1308 #if 0 /* software irq currently not used */
1309 if (IntSrc & IS_IRQ_SW) {
1310 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1311 SK_DBGCAT_DRV_INT_SRC,
1312 ("Software IRQ\n"));
1315 if (IntSrc & IS_R1_F) {
1316 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1317 SK_DBGCAT_DRV_INT_SRC,
1319 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1320 SK_PNMI_CNT_RX_INTR(pAC, 0);
1322 if (IntSrc & IS_R2_F) {
1323 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1324 SK_DBGCAT_DRV_INT_SRC,
1326 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1327 SK_PNMI_CNT_RX_INTR(pAC, 1);
1329 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1330 if (IntSrc & IS_XA1_F) {
1331 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1332 SK_DBGCAT_DRV_INT_SRC,
1333 ("EOF AS TX1 IRQ\n"));
1334 SK_PNMI_CNT_TX_INTR(pAC, 0);
1335 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1336 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1337 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1339 if (IntSrc & IS_XA2_F) {
1340 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1341 SK_DBGCAT_DRV_INT_SRC,
1342 ("EOF AS TX2 IRQ\n"));
1343 SK_PNMI_CNT_TX_INTR(pAC, 1);
1344 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1345 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1346 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1348 #if 0 /* only if sync. queues used */
1349 if (IntSrc & IS_XS1_F) {
1350 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1351 SK_DBGCAT_DRV_INT_SRC,
1352 ("EOF SY TX1 IRQ\n"));
1353 SK_PNMI_CNT_TX_INTR(pAC, 1);
1354 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1355 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1356 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1357 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1359 if (IntSrc & IS_XS2_F) {
1360 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1361 SK_DBGCAT_DRV_INT_SRC,
1362 ("EOF SY TX2 IRQ\n"));
1363 SK_PNMI_CNT_TX_INTR(pAC, 1);
1364 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1365 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1366 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1367 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1372 /* do all IO at once */
1373 if (IntSrc & IS_R1_F)
1374 ClearAndStartRx(pAC, 0);
1375 if (IntSrc & IS_R2_F)
1376 ClearAndStartRx(pAC, 1);
1377 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1378 if (IntSrc & IS_XA1_F)
1379 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1380 if (IntSrc & IS_XA2_F)
1381 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1383 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1384 } /* while (IntSrc & IRQ_MASK != 0) */
1386 IntSrc &= pAC->GIni.GIValIrqMask;
1387 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1388 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1389 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1390 pAC->CheckQueue = SK_FALSE;
1391 spin_lock(&pAC->SlowPathLock);
1392 if (IntSrc & SPECIAL_IRQS)
1393 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1395 SkEventDispatcher(pAC, pAC->IoBase);
1396 spin_unlock(&pAC->SlowPathLock);
1399 * do it all again is case we cleared an interrupt that
1400 * came in after handling the ring (OUTs may be delayed
1401 * in hardware buffers, but are through after IN)
1403 * rroesler: has been commented out and shifted to
1404 * SkGeDrvEvent(), because it is timer
1407 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1408 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1411 if (pAC->CheckQueue) {
1412 pAC->CheckQueue = SK_FALSE;
1413 spin_lock(&pAC->SlowPathLock);
1414 SkEventDispatcher(pAC, pAC->IoBase);
1415 spin_unlock(&pAC->SlowPathLock);
1418 /* IRQ is processed - Enable IRQs again*/
1419 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1421 return SkIsrRetHandled;
1425 /****************************************************************************
1427 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1430 * The interrupt routine is called when the network adapter
1431 * generates an interrupt. It may also be called if another device
1432 * shares this interrupt vector with the driver.
1433 * This is the same as above, but handles only one port.
1438 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1440 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1443 SK_U32 IntSrc; /* interrupts source register contents */
1445 pNet = (DEV_NET*) dev->priv;
1449 * Check and process if its our interrupt
1451 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1453 return SkIsrRetNone;
1456 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1457 #if 0 /* software irq currently not used */
1458 if (IntSrc & IS_IRQ_SW) {
1459 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1460 SK_DBGCAT_DRV_INT_SRC,
1461 ("Software IRQ\n"));
1464 if (IntSrc & IS_R1_F) {
1465 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1466 SK_DBGCAT_DRV_INT_SRC,
1468 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1469 SK_PNMI_CNT_RX_INTR(pAC, 0);
1471 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1472 if (IntSrc & IS_XA1_F) {
1473 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1474 SK_DBGCAT_DRV_INT_SRC,
1475 ("EOF AS TX1 IRQ\n"));
1476 SK_PNMI_CNT_TX_INTR(pAC, 0);
1477 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1478 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1479 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1481 #if 0 /* only if sync. queues used */
1482 if (IntSrc & IS_XS1_F) {
1483 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1484 SK_DBGCAT_DRV_INT_SRC,
1485 ("EOF SY TX1 IRQ\n"));
1486 SK_PNMI_CNT_TX_INTR(pAC, 0);
1487 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1488 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1489 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1490 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1495 /* do all IO at once */
1496 if (IntSrc & IS_R1_F)
1497 ClearAndStartRx(pAC, 0);
1498 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1499 if (IntSrc & IS_XA1_F)
1500 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1502 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1503 } /* while (IntSrc & IRQ_MASK != 0) */
1505 IntSrc &= pAC->GIni.GIValIrqMask;
1506 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1507 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1508 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1509 pAC->CheckQueue = SK_FALSE;
1510 spin_lock(&pAC->SlowPathLock);
1511 if (IntSrc & SPECIAL_IRQS)
1512 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1514 SkEventDispatcher(pAC, pAC->IoBase);
1515 spin_unlock(&pAC->SlowPathLock);
1518 * do it all again is case we cleared an interrupt that
1519 * came in after handling the ring (OUTs may be delayed
1520 * in hardware buffers, but are through after IN)
1522 * rroesler: has been commented out and shifted to
1523 * SkGeDrvEvent(), because it is timer
1526 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1529 /* IRQ is processed - Enable IRQs again*/
1530 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1532 return SkIsrRetHandled;
1533 } /* SkGeIsrOnePort */
1536 /****************************************************************************
1538 * SkGeOpen - handle start of initialized adapter
1541 * This function starts the initialized adapter.
1542 * The board level variable is set and the adapter is
1543 * brought to full functionality.
1544 * The device flags are set for operation.
1545 * Do all necessary level 2 initialization, enable interrupts and
1546 * give start command to RLMT.
1552 static int SkGeOpen(
1553 struct SK_NET_DEVICE *dev)
1557 unsigned long Flags; /* for spin lock */
1559 SK_EVPARA EvPara; /* an event parameter union */
1561 pNet = (DEV_NET*) dev->priv;
1564 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1565 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1567 #ifdef SK_DIAG_SUPPORT
1568 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1569 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1570 return (-1); /* still in use by diag; deny actions */
1575 if (!try_module_get(THIS_MODULE)) {
1576 return (-1); /* increase of usage count not possible */
1579 /* Set blink mode */
1580 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1581 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1583 if (pAC->BoardLevel == SK_INIT_DATA) {
1584 /* level 1 init common modules here */
1585 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1586 module_put(THIS_MODULE); /* decrease usage count */
1587 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1590 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1591 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1592 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1593 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1594 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1595 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1596 pAC->BoardLevel = SK_INIT_IO;
1599 if (pAC->BoardLevel != SK_INIT_RUN) {
1600 /* tschilling: Level 2 init modules here, check return value. */
1601 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1602 module_put(THIS_MODULE); /* decrease usage count */
1603 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1606 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1607 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1608 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1609 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1610 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1611 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1612 pAC->BoardLevel = SK_INIT_RUN;
1615 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1616 /* Enable transmit descriptor polling. */
1617 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1618 FillRxRing(pAC, &pAC->RxPort[i]);
1620 SkGeYellowLED(pAC, pAC->IoBase, 1);
1622 StartDrvCleanupTimer(pAC);
1623 SkDimEnableModerationIfNeeded(pAC);
1624 SkDimDisplayModerationSettings(pAC);
1626 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1628 /* enable Interrupts */
1629 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1630 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1632 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1634 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1635 EvPara.Para32[0] = pAC->RlmtNets;
1636 EvPara.Para32[1] = -1;
1637 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1639 EvPara.Para32[0] = pAC->RlmtMode;
1640 EvPara.Para32[1] = 0;
1641 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1645 EvPara.Para32[0] = pNet->NetNr;
1646 EvPara.Para32[1] = -1;
1647 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1648 SkEventDispatcher(pAC, pAC->IoBase);
1649 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1655 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1656 ("SkGeOpen suceeded\n"));
1662 /****************************************************************************
1664 * SkGeClose - Stop initialized adapter
1667 * Close initialized adapter.
1671 * error code - on error
1673 static int SkGeClose(
1674 struct SK_NET_DEVICE *dev)
1680 unsigned long Flags; /* for spin lock */
1685 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1686 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1688 pNet = (DEV_NET*) dev->priv;
1691 #ifdef SK_DIAG_SUPPORT
1692 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1693 if (pAC->DiagFlowCtrl == SK_FALSE) {
1694 module_put(THIS_MODULE);
1696 ** notify that the interface which has been closed
1697 ** by operator interaction must not be started up
1698 ** again when the DIAG has finished.
1700 newPtrNet = (DEV_NET *) pAC->dev[0]->priv;
1701 if (newPtrNet == pNet) {
1702 pAC->WasIfUp[0] = SK_FALSE;
1704 pAC->WasIfUp[1] = SK_FALSE;
1706 return 0; /* return to system everything is fine... */
1708 pAC->DiagFlowCtrl = SK_FALSE;
1713 netif_stop_queue(dev);
1715 if (pAC->RlmtNets == 1)
1716 PortIdx = pAC->ActivePort;
1718 PortIdx = pNet->NetNr;
1720 StopDrvCleanupTimer(pAC);
1723 * Clear multicast table, promiscuous mode ....
1725 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1726 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1729 if (pAC->MaxPorts == 1) {
1730 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1731 /* disable interrupts */
1732 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1733 EvPara.Para32[0] = pNet->NetNr;
1734 EvPara.Para32[1] = -1;
1735 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1736 SkEventDispatcher(pAC, pAC->IoBase);
1737 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1738 /* stop the hardware */
1739 SkGeDeInit(pAC, pAC->IoBase);
1740 pAC->BoardLevel = SK_INIT_DATA;
1741 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1744 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1745 EvPara.Para32[0] = pNet->NetNr;
1746 EvPara.Para32[1] = -1;
1747 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1748 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1749 SkEventDispatcher(pAC, pAC->IoBase);
1750 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1753 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1754 [TX_PRIO_LOW].TxDesRingLock, Flags);
1755 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1756 SK_STOP_ALL, SK_HARD_RST);
1757 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1758 [TX_PRIO_LOW].TxDesRingLock, Flags);
1761 if (pAC->RlmtNets == 1) {
1762 /* clear all descriptor rings */
1763 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1764 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1765 ClearRxRing(pAC, &pAC->RxPort[i]);
1766 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1769 /* clear port descriptor rings */
1770 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1771 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1772 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1775 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1776 ("SkGeClose: done "));
1778 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1779 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1780 sizeof(SK_PNMI_STRUCT_DATA));
1785 module_put(THIS_MODULE);
1790 /*****************************************************************************
1792 * SkGeXmit - Linux frame transmit function
1795 * The system calls this function to send frames onto the wire.
1796 * It puts the frame in the tx descriptor ring. If the ring is
1797 * full then, the 'tbusy' flag is set.
1800 * 0, if everything is ok
1802 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1803 * allocated skb's) !!!
1805 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1809 int Rc; /* return code of XmitFrame */
1811 pNet = (DEV_NET*) dev->priv;
1814 if ((!skb_shinfo(skb)->nr_frags) ||
1815 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1816 /* Don't activate scatter-gather and hardware checksum */
1818 if (pAC->RlmtNets == 2)
1821 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1826 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1829 /* scatter-gather and hardware TCP checksumming anabled*/
1830 if (pAC->RlmtNets == 2)
1833 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1838 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1842 /* Transmitter out of resources? */
1844 netif_stop_queue(dev);
1847 /* If not taken, give buffer ownership back to the
1853 dev->trans_start = jiffies;
1858 /*****************************************************************************
1860 * XmitFrame - fill one socket buffer into the transmit ring
1863 * This function puts a message into the transmit descriptor ring
1864 * if there is a descriptors left.
1865 * Linux skb's consist of only one continuous buffer.
1866 * The first step locks the ring. It is held locked
1867 * all time to avoid problems with SWITCH_../PORT_RESET.
1868 * Then the descriptoris allocated.
1869 * The second part is linking the buffer to the descriptor.
1870 * At the very last, the Control field of the descriptor
1871 * is made valid for the BMU and a start TX command is given
1875 * > 0 - on succes: the number of bytes in the message
1876 * = 0 - on resource shortage: this frame sent or dropped, now
1877 * the ring is full ( -> set tbusy)
1878 * < 0 - on failure: other problems ( -> return failure to upper layers)
1880 static int XmitFrame(
1881 SK_AC *pAC, /* pointer to adapter context */
1882 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1883 struct sk_buff *pMessage) /* pointer to send-message */
1885 TXD *pTxd; /* the rxd to fill */
1887 unsigned long Flags;
1891 int BytesSend = pMessage->len;
1893 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1895 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1896 #ifndef USE_TX_COMPLETE
1897 FreeTxDescriptors(pAC, pTxPort);
1899 if (pTxPort->TxdRingFree == 0) {
1901 ** no enough free descriptors in ring at the moment.
1902 ** Maybe free'ing some old one help?
1904 FreeTxDescriptors(pAC, pTxPort);
1905 if (pTxPort->TxdRingFree == 0) {
1906 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1907 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1908 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1909 SK_DBGCAT_DRV_TX_PROGRESS,
1910 ("XmitFrame failed\n"));
1912 ** the desired message can not be sent
1913 ** Because tbusy seems to be set, the message
1914 ** should not be freed here. It will be used
1915 ** by the scheduler of the ethernet handler
1922 ** If the passed socket buffer is of smaller MTU-size than 60,
1923 ** copy everything into new buffer and fill all bytes between
1924 ** the original packet end and the new packet end of 60 with 0x00.
1925 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1927 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1928 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1931 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1935 ** advance head counter behind descriptor needed for this frame,
1936 ** so that needed descriptor is reserved from that on. The next
1937 ** action will be to add the passed buffer to the TX-descriptor
1939 pTxd = pTxPort->pTxdRingHead;
1940 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1941 pTxPort->TxdRingFree--;
1944 DumpMsg(pMessage, "XmitFrame");
1948 ** First step is to map the data to be sent via the adapter onto
1949 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1950 ** and 2.6 need to use pci_map_page() for that mapping.
1952 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1953 virt_to_page(pMessage->data),
1954 ((unsigned long) pMessage->data & ~PAGE_MASK),
1957 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1958 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1959 pTxd->pMBuf = pMessage;
1961 if (pMessage->ip_summed == CHECKSUM_HW) {
1962 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1963 if ((Protocol == C_PROTO_ID_UDP) &&
1964 (pAC->GIni.GIChipRev == 0) &&
1965 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1966 pTxd->TBControl = BMU_TCP_CHECK;
1968 pTxd->TBControl = BMU_UDP_CHECK;
1971 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1972 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1973 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1974 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1975 (Protocol == C_PROTO_ID_UDP ?
1976 C_OFFSET_UDPHEADER_UDPCS :
1977 C_OFFSET_TCPHEADER_TCPCS);
1978 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1980 pTxd->TBControl |= BMU_OWN | BMU_STF |
1982 #ifdef USE_TX_COMPLETE
1987 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1989 #ifdef USE_TX_COMPLETE
1996 ** If previous descriptor already done, give TX start cmd
1998 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1999 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
2000 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
2004 ** after releasing the lock, the skb may immediately be free'd
2006 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2007 if (pTxPort->TxdRingFree != 0) {
2015 /*****************************************************************************
2017 * XmitFrameSG - fill one socket buffer into the transmit ring
2018 * (use SG and TCP/UDP hardware checksumming)
2021 * This function puts a message into the transmit descriptor ring
2022 * if there is a descriptors left.
2025 * > 0 - on succes: the number of bytes in the message
2026 * = 0 - on resource shortage: this frame sent or dropped, now
2027 * the ring is full ( -> set tbusy)
2028 * < 0 - on failure: other problems ( -> return failure to upper layers)
2030 static int XmitFrameSG(
2031 SK_AC *pAC, /* pointer to adapter context */
2032 TX_PORT *pTxPort, /* pointer to struct of port to send to */
2033 struct sk_buff *pMessage) /* pointer to send-message */
2043 skb_frag_t *sk_frag;
2045 unsigned long Flags;
2047 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2048 #ifndef USE_TX_COMPLETE
2049 FreeTxDescriptors(pAC, pTxPort);
2051 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
2052 FreeTxDescriptors(pAC, pTxPort);
2053 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
2054 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2055 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
2056 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2057 SK_DBGCAT_DRV_TX_PROGRESS,
2058 ("XmitFrameSG failed - Ring full\n"));
2059 /* this message can not be sent now */
2064 pTxd = pTxPort->pTxdRingHead;
2071 ** Map the first fragment (header) into the DMA-space
2073 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2074 virt_to_page(pMessage->data),
2075 ((unsigned long) pMessage->data & ~PAGE_MASK),
2076 skb_headlen(pMessage),
2079 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2080 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2083 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2085 if (pMessage->ip_summed == CHECKSUM_HW) {
2086 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
2088 ** We have to use the opcode for tcp here, because the
2089 ** opcode for udp is not working in the hardware yet
2092 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
2093 if ((Protocol == C_PROTO_ID_UDP) &&
2094 (pAC->GIni.GIChipRev == 0) &&
2095 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2096 pTxd->TBControl |= BMU_TCP_CHECK;
2098 pTxd->TBControl |= BMU_UDP_CHECK;
2101 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
2102 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
2103 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
2104 (Protocol == C_PROTO_ID_UDP ?
2105 C_OFFSET_UDPHEADER_UDPCS :
2106 C_OFFSET_TCPHEADER_TCPCS);
2107 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
2109 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
2110 skb_headlen(pMessage);
2113 pTxd = pTxd->pNextTxd;
2114 pTxPort->TxdRingFree--;
2115 BytesSend += skb_headlen(pMessage);
2118 ** Browse over all SG fragments and map each of them into the DMA space
2120 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
2121 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
2123 ** we already have the proper value in entry
2125 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2127 sk_frag->page_offset,
2131 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2132 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2133 pTxd->pMBuf = pMessage;
2136 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2138 if (pMessage->ip_summed == CHECKSUM_HW) {
2139 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
2141 ** We have to use the opcode for tcp here because the
2142 ** opcode for udp is not working in the hardware yet
2145 if ((Protocol == C_PROTO_ID_UDP) &&
2146 (pAC->GIni.GIChipRev == 0) &&
2147 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2148 pTxd->TBControl |= BMU_TCP_CHECK;
2150 pTxd->TBControl |= BMU_UDP_CHECK;
2153 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
2157 ** Do we have the last fragment?
2159 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
2160 #ifdef USE_TX_COMPLETE
2161 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
2163 pTxd->TBControl |= BMU_EOF | sk_frag->size;
2165 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
2168 pTxd->TBControl |= sk_frag->size;
2171 pTxd = pTxd->pNextTxd;
2172 pTxPort->TxdRingFree--;
2173 BytesSend += sk_frag->size;
2177 ** If previous descriptor already done, give TX start cmd
2179 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
2180 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
2183 pTxPort->pTxdRingPrev = pTxdLst;
2184 pTxPort->pTxdRingHead = pTxd;
2186 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2188 if (pTxPort->TxdRingFree > 0) {
2195 /*****************************************************************************
2197 * FreeTxDescriptors - release descriptors from the descriptor ring
2200 * This function releases descriptors from a transmit ring if they
2201 * have been sent by the BMU.
2202 * If a descriptors is sent, it can be freed and the message can
2204 * The SOFTWARE controllable bit is used to prevent running around a
2205 * completely free ring for ever. If this bit is no set in the
2206 * frame (by XmitFrame), this frame has never been sent or is
2208 * The Tx descriptor ring lock must be held while calling this function !!!
2213 static void FreeTxDescriptors(
2214 SK_AC *pAC, /* pointer to the adapter context */
2215 TX_PORT *pTxPort) /* pointer to destination port structure */
2217 TXD *pTxd; /* pointer to the checked descriptor */
2218 TXD *pNewTail; /* pointer to 'end' of the ring */
2219 SK_U32 Control; /* TBControl field of descriptor */
2220 SK_U64 PhysAddr; /* address of DMA mapping */
2222 pNewTail = pTxPort->pTxdRingTail;
2225 ** loop forever; exits if BMU_SW bit not set in start frame
2226 ** or BMU_OWN bit set in any frame
2229 Control = pTxd->TBControl;
2230 if ((Control & BMU_SW) == 0) {
2232 ** software controllable bit is set in first
2233 ** fragment when given to BMU. Not set means that
2234 ** this fragment was never sent or is already
2235 ** freed ( -> ring completely free now).
2237 pTxPort->pTxdRingTail = pTxd;
2238 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2241 if (Control & BMU_OWN) {
2242 pTxPort->pTxdRingTail = pTxd;
2243 if (pTxPort->TxdRingFree > 0) {
2244 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2250 ** release the DMA mapping, because until not unmapped
2251 ** this buffer is considered being under control of the
2254 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
2255 PhysAddr |= (SK_U64) pTxd->VDataLow;
2256 pci_unmap_page(pAC->PciDev, PhysAddr,
2260 if (Control & BMU_EOF)
2261 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
2263 pTxPort->TxdRingFree++;
2264 pTxd->TBControl &= ~BMU_SW;
2265 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
2266 } /* while(forever) */
2267 } /* FreeTxDescriptors */
2269 /*****************************************************************************
2271 * FillRxRing - fill the receive ring with valid descriptors
2274 * This function fills the receive ring descriptors with data
2275 * segments and makes them valid for the BMU.
2276 * The active ring is filled completely, if possible.
2277 * The non-active ring is filled only partial to save memory.
2279 * Description of rx ring structure:
2280 * head - points to the descriptor which will be used next by the BMU
2281 * tail - points to the next descriptor to give to the BMU
2285 static void FillRxRing(
2286 SK_AC *pAC, /* pointer to the adapter context */
2287 RX_PORT *pRxPort) /* ptr to port struct for which the ring
2290 unsigned long Flags;
2292 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2293 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
2294 if(!FillRxDescriptor(pAC, pRxPort))
2297 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2301 /*****************************************************************************
2303 * FillRxDescriptor - fill one buffer into the receive ring
2306 * The function allocates a new receive buffer and
2307 * puts it into the next descriptor.
2310 * SK_TRUE - a buffer was added to the ring
2311 * SK_FALSE - a buffer could not be added
2313 static SK_BOOL FillRxDescriptor(
2314 SK_AC *pAC, /* pointer to the adapter context struct */
2315 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
2317 struct sk_buff *pMsgBlock; /* pointer to a new message block */
2318 RXD *pRxd; /* the rxd to fill */
2319 SK_U16 Length; /* data fragment length */
2320 SK_U64 PhysAddr; /* physical address of a rx buffer */
2322 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
2323 if (pMsgBlock == NULL) {
2324 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2325 SK_DBGCAT_DRV_ENTRY,
2326 ("%s: Allocation of rx buffer failed !\n",
2327 pAC->dev[pRxPort->PortIndex]->name));
2328 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
2331 skb_reserve(pMsgBlock, 2); /* to align IP frames */
2332 /* skb allocated ok, so add buffer */
2333 pRxd = pRxPort->pRxdRingTail;
2334 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2335 pRxPort->RxdRingFree--;
2336 Length = pAC->RxBufSize;
2337 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2338 virt_to_page(pMsgBlock->data),
2339 ((unsigned long) pMsgBlock->data &
2342 PCI_DMA_FROMDEVICE);
2344 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2345 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2346 pRxd->pMBuf = pMsgBlock;
2347 pRxd->RBControl = BMU_OWN |
2354 } /* FillRxDescriptor */
2357 /*****************************************************************************
2359 * ReQueueRxBuffer - fill one buffer back into the receive ring
2362 * Fill a given buffer back into the rx ring. The buffer
2363 * has been previously allocated and aligned, and its phys.
2364 * address calculated, so this is no more necessary.
2368 static void ReQueueRxBuffer(
2369 SK_AC *pAC, /* pointer to the adapter context struct */
2370 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
2371 struct sk_buff *pMsg, /* pointer to the buffer */
2372 SK_U32 PhysHigh, /* phys address high dword */
2373 SK_U32 PhysLow) /* phys address low dword */
2375 RXD *pRxd; /* the rxd to fill */
2376 SK_U16 Length; /* data fragment length */
2378 pRxd = pRxPort->pRxdRingTail;
2379 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2380 pRxPort->RxdRingFree--;
2381 Length = pAC->RxBufSize;
2383 pRxd->VDataLow = PhysLow;
2384 pRxd->VDataHigh = PhysHigh;
2386 pRxd->RBControl = BMU_OWN |
2392 } /* ReQueueRxBuffer */
2394 /*****************************************************************************
2396 * ReceiveIrq - handle a receive IRQ
2399 * This function is called when a receive IRQ is set.
2400 * It walks the receive descriptor ring and sends up all
2401 * frames that are complete.
2405 static void ReceiveIrq(
2406 SK_AC *pAC, /* pointer to adapter context */
2407 RX_PORT *pRxPort, /* pointer to receive port struct */
2408 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2410 RXD *pRxd; /* pointer to receive descriptors */
2411 SK_U32 Control; /* control field of descriptor */
2412 struct sk_buff *pMsg; /* pointer to message holding frame */
2413 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2414 int FrameLength; /* total length of received frame */
2416 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2417 SK_EVPARA EvPara; /* an event parameter union */
2418 unsigned long Flags; /* for spin lock */
2419 int PortIndex = pRxPort->PortIndex;
2420 unsigned int Offset;
2421 unsigned int NumBytes;
2422 unsigned int ForRlmt;
2425 SK_BOOL IsBadFrame; /* Bad frame */
2428 unsigned short Csum1;
2429 unsigned short Csum2;
2430 unsigned short Type;
2435 /* do forever; exit if BMU_OWN found */
2436 for ( pRxd = pRxPort->pRxdRingHead ;
2437 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2438 pRxd = pRxd->pNextRxd,
2439 pRxPort->pRxdRingHead = pRxd,
2440 pRxPort->RxdRingFree ++) {
2443 * For a better understanding of this loop
2444 * Go through every descriptor beginning at the head
2445 * Please note: the ring might be completely received so the OWN bit
2446 * set is not a good crirteria to leave that loop.
2447 * Therefore the RingFree counter is used.
2448 * On entry of this loop pRxd is a pointer to the Rxd that needs
2449 * to be checked next.
2452 Control = pRxd->RBControl;
2454 /* check if this descriptor is ready */
2455 if ((Control & BMU_OWN) != 0) {
2456 /* this descriptor is not yet ready */
2457 /* This is the usual end of the loop */
2458 /* We don't need to start the ring again */
2459 FillRxRing(pAC, pRxPort);
2462 pAC->DynIrqModInfo.NbrProcessedDescr++;
2464 /* get length of frame and check it */
2465 FrameLength = Control & BMU_BBC;
2466 if (FrameLength > pAC->RxBufSize) {
2470 /* check for STF and EOF */
2471 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2475 /* here we have a complete frame in the ring */
2478 FrameStat = pRxd->FrameStat;
2480 /* check for frame length mismatch */
2481 #define XMR_FS_LEN_SHIFT 18
2482 #define GMR_FS_LEN_SHIFT 16
2483 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2484 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2485 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2486 SK_DBGCAT_DRV_RX_PROGRESS,
2487 ("skge: Frame length mismatch (%u/%u).\n",
2489 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2494 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2495 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2496 SK_DBGCAT_DRV_RX_PROGRESS,
2497 ("skge: Frame length mismatch (%u/%u).\n",
2499 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2505 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2506 IsBc = (FrameStat & XMR_FS_BC) != 0;
2507 IsMc = (FrameStat & XMR_FS_MC) != 0;
2508 IsBadFrame = (FrameStat &
2509 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2511 IsBc = (FrameStat & GMR_FS_BC) != 0;
2512 IsMc = (FrameStat & GMR_FS_MC) != 0;
2513 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2514 ((FrameStat & GMR_FS_RX_OK) == 0));
2517 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2518 ("Received frame of length %d on port %d\n",
2519 FrameLength, PortIndex));
2520 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2521 ("Number of free rx descriptors: %d\n",
2522 pRxPort->RxdRingFree));
2523 /* DumpMsg(pMsg, "Rx"); */
2525 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2527 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2529 /* there is a receive error in this frame */
2530 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2531 SK_DBGCAT_DRV_RX_PROGRESS,
2532 ("skge: Error in received frame, dropped!\n"
2533 "Control: %x\nRxStat: %x\n",
2534 Control, FrameStat));
2536 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2537 PhysAddr |= (SK_U64) pRxd->VDataLow;
2538 pci_dma_sync_single(pAC->PciDev,
2539 (dma_addr_t) PhysAddr,
2541 PCI_DMA_FROMDEVICE);
2542 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2543 pRxd->VDataHigh, pRxd->VDataLow);
2549 * if short frame then copy data to reduce memory waste
2551 if ((FrameLength < SK_COPY_THRESHOLD) &&
2552 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2554 * Short frame detected and allocation successfull
2556 /* use new skb and copy data */
2557 skb_reserve(pNewMsg, 2);
2558 skb_put(pNewMsg, FrameLength);
2559 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2560 PhysAddr |= (SK_U64) pRxd->VDataLow;
2562 pci_dma_sync_single(pAC->PciDev,
2563 (dma_addr_t) PhysAddr,
2565 PCI_DMA_FROMDEVICE);
2566 eth_copy_and_sum(pNewMsg, pMsg->data,
2568 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2569 pRxd->VDataHigh, pRxd->VDataLow);
2576 * if large frame, or SKB allocation failed, pass
2577 * the SKB directly to the networking
2580 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2581 PhysAddr |= (SK_U64) pRxd->VDataLow;
2583 /* release the DMA mapping */
2584 pci_unmap_single(pAC->PciDev,
2587 PCI_DMA_FROMDEVICE);
2589 /* set length in message */
2590 skb_put(pMsg, FrameLength);
2591 /* hardware checksum */
2592 Type = ntohs(*((short*)&pMsg->data[12]));
2594 #ifdef USE_SK_RX_CHECKSUM
2595 if (Type == 0x800) {
2596 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2597 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2598 IpFrameLength = (int) ntohs((unsigned short)
2599 ((unsigned short *) pMsg->data)[8]);
2602 * Test: If frame is padded, a check is not possible!
2603 * Frame not padded? Length difference must be 14 (0xe)!
2605 if ((FrameLength - IpFrameLength) != 0xe) {
2606 /* Frame padded => TCP offload not possible! */
2607 pMsg->ip_summed = CHECKSUM_NONE;
2609 /* Frame not padded => TCP offload! */
2610 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2611 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2612 (pAC->ChipsetType)) {
2613 Result = SkCsGetReceiveInfo(pAC,
2615 Csum1, Csum2, pRxPort->PortIndex);
2617 SKCS_STATUS_IP_FRAGMENT ||
2619 SKCS_STATUS_IP_CSUM_OK ||
2621 SKCS_STATUS_TCP_CSUM_OK ||
2623 SKCS_STATUS_UDP_CSUM_OK) {
2625 CHECKSUM_UNNECESSARY;
2628 SKCS_STATUS_TCP_CSUM_ERROR ||
2630 SKCS_STATUS_UDP_CSUM_ERROR ||
2632 SKCS_STATUS_IP_CSUM_ERROR_UDP ||
2634 SKCS_STATUS_IP_CSUM_ERROR_TCP ||
2636 SKCS_STATUS_IP_CSUM_ERROR ) {
2637 /* HW Checksum error */
2638 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2639 SK_DBGCAT_DRV_RX_PROGRESS,
2640 ("skge: CRC error. Frame dropped!\n"));
2646 }/* checksumControl calculation valid */
2647 } /* Frame length check */
2650 pMsg->ip_summed = CHECKSUM_NONE;
2652 } /* frame > SK_COPY_TRESHOLD */
2654 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2655 ForRlmt = SK_RLMT_RX_PROTOCOL;
2657 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2659 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2660 IsBc, &Offset, &NumBytes);
2661 if (NumBytes != 0) {
2663 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2665 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2666 &pMsg->data[Offset],
2667 IsBc, IsMc, &ForRlmt);
2669 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2670 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2671 /* send up only frames from active port */
2672 if ((PortIndex == pAC->ActivePort) ||
2673 (pAC->RlmtNets == 2)) {
2674 /* frame for upper layer */
2675 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2677 DumpMsg(pMsg, "Rx");
2679 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2680 FrameLength, pRxPort->PortIndex);
2682 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2683 pMsg->protocol = eth_type_trans(pMsg,
2684 pAC->dev[pRxPort->PortIndex]);
2686 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2690 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2691 SK_DBGCAT_DRV_RX_PROGRESS,
2693 DEV_KFREE_SKB(pMsg);
2696 } /* if not for rlmt */
2698 /* packet for rlmt */
2699 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2700 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2701 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2702 pAC->IoBase, FrameLength);
2703 if (pRlmtMbuf != NULL) {
2704 pRlmtMbuf->pNext = NULL;
2705 pRlmtMbuf->Length = FrameLength;
2706 pRlmtMbuf->PortIdx = PortIndex;
2707 EvPara.pParaPtr = pRlmtMbuf;
2708 memcpy((char*)(pRlmtMbuf->pData),
2709 (char*)(pMsg->data),
2712 /* SlowPathLock needed? */
2713 if (SlowPathLock == SK_TRUE) {
2714 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2715 SkEventQueue(pAC, SKGE_RLMT,
2716 SK_RLMT_PACKET_RECEIVED,
2718 pAC->CheckQueue = SK_TRUE;
2719 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2721 SkEventQueue(pAC, SKGE_RLMT,
2722 SK_RLMT_PACKET_RECEIVED,
2724 pAC->CheckQueue = SK_TRUE;
2727 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2728 SK_DBGCAT_DRV_RX_PROGRESS,
2731 if ((pAC->dev[pRxPort->PortIndex]->flags &
2732 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2733 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2734 SK_RLMT_RX_PROTOCOL) {
2735 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2736 pMsg->protocol = eth_type_trans(pMsg,
2737 pAC->dev[pRxPort->PortIndex]);
2739 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2742 DEV_KFREE_SKB(pMsg);
2745 } /* if packet for rlmt */
2746 } /* for ... scanning the RXD ring */
2748 /* RXD ring is empty -> fill and restart */
2749 FillRxRing(pAC, pRxPort);
2750 /* do not start if called from Close */
2751 if (pAC->BoardLevel > SK_INIT_DATA) {
2752 ClearAndStartRx(pAC, PortIndex);
2757 /* remove error frame */
2758 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2759 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2761 /* release the DMA mapping */
2763 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2764 PhysAddr |= (SK_U64) pRxd->VDataLow;
2765 pci_unmap_page(pAC->PciDev,
2768 PCI_DMA_FROMDEVICE);
2769 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2771 pRxPort->RxdRingFree++;
2772 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2778 /*****************************************************************************
2780 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2783 * This function sends a start command and a clear interrupt
2784 * command for one receive queue to the BMU.
2789 static void ClearAndStartRx(
2790 SK_AC *pAC, /* pointer to the adapter context */
2791 int PortIndex) /* index of the receive port (XMAC) */
2793 SK_OUT8(pAC->IoBase,
2794 RxQueueAddr[PortIndex]+Q_CSR,
2795 CSR_START | CSR_IRQ_CL_F);
2796 } /* ClearAndStartRx */
2799 /*****************************************************************************
2801 * ClearTxIrq - give a clear transmit IRQ command to BMU
2804 * This function sends a clear tx IRQ command for one
2805 * transmit queue to the BMU.
2809 static void ClearTxIrq(
2810 SK_AC *pAC, /* pointer to the adapter context */
2811 int PortIndex, /* index of the transmit port (XMAC) */
2812 int Prio) /* priority or normal queue */
2814 SK_OUT8(pAC->IoBase,
2815 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2820 /*****************************************************************************
2822 * ClearRxRing - remove all buffers from the receive ring
2825 * This function removes all receive buffers from the ring.
2826 * The receive BMU must be stopped before calling this function.
2830 static void ClearRxRing(
2831 SK_AC *pAC, /* pointer to adapter context */
2832 RX_PORT *pRxPort) /* pointer to rx port struct */
2834 RXD *pRxd; /* pointer to the current descriptor */
2835 unsigned long Flags;
2838 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2841 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2842 pRxd = pRxPort->pRxdRingHead;
2844 if (pRxd->pMBuf != NULL) {
2846 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2847 PhysAddr |= (SK_U64) pRxd->VDataLow;
2848 pci_unmap_page(pAC->PciDev,
2851 PCI_DMA_FROMDEVICE);
2852 DEV_KFREE_SKB(pRxd->pMBuf);
2855 pRxd->RBControl &= BMU_OWN;
2856 pRxd = pRxd->pNextRxd;
2857 pRxPort->RxdRingFree++;
2858 } while (pRxd != pRxPort->pRxdRingTail);
2859 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2860 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2863 /*****************************************************************************
2865 * ClearTxRing - remove all buffers from the transmit ring
2868 * This function removes all transmit buffers from the ring.
2869 * The transmit BMU must be stopped before calling this function
2870 * and transmitting at the upper level must be disabled.
2871 * The BMU own bit of all descriptors is cleared, the rest is
2872 * done by calling FreeTxDescriptors.
2876 static void ClearTxRing(
2877 SK_AC *pAC, /* pointer to adapter context */
2878 TX_PORT *pTxPort) /* pointer to tx prt struct */
2880 TXD *pTxd; /* pointer to the current descriptor */
2882 unsigned long Flags;
2884 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2885 pTxd = pTxPort->pTxdRingHead;
2886 for (i=0; i<pAC->TxDescrPerRing; i++) {
2887 pTxd->TBControl &= ~BMU_OWN;
2888 pTxd = pTxd->pNextTxd;
2890 FreeTxDescriptors(pAC, pTxPort);
2891 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2894 /*****************************************************************************
2896 * SkGeSetMacAddr - Set the hardware MAC address
2899 * This function sets the MAC address used by the adapter.
2902 * 0, if everything is ok
2905 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2908 DEV_NET *pNet = (DEV_NET*) dev->priv;
2909 SK_AC *pAC = pNet->pAC;
2911 struct sockaddr *addr = p;
2912 unsigned long Flags;
2914 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2915 ("SkGeSetMacAddr starts now...\n"));
2916 if(netif_running(dev))
2919 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2921 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2923 if (pAC->RlmtNets == 2)
2924 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2925 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2927 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2928 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2932 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2934 } /* SkGeSetMacAddr */
2937 /*****************************************************************************
2939 * SkGeSetRxMode - set receive mode
2942 * This function sets the receive mode of an adapter. The adapter
2943 * supports promiscuous mode, allmulticast mode and a number of
2944 * multicast addresses. If more multicast addresses the available
2945 * are selected, a hash function in the hardware is used.
2948 * 0, if everything is ok
2951 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2957 struct dev_mc_list *pMcList;
2960 unsigned long Flags;
2962 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2963 ("SkGeSetRxMode starts now... "));
2965 pNet = (DEV_NET*) dev->priv;
2967 if (pAC->RlmtNets == 1)
2968 PortIdx = pAC->ActivePort;
2970 PortIdx = pNet->NetNr;
2972 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2973 if (dev->flags & IFF_PROMISC) {
2974 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2975 ("PROMISCUOUS mode\n"));
2976 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2978 } else if (dev->flags & IFF_ALLMULTI) {
2979 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2980 ("ALLMULTI mode\n"));
2981 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2982 SK_PROM_MODE_ALL_MC);
2984 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2986 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2988 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2989 ("Number of MC entries: %d ", dev->mc_count));
2991 pMcList = dev->mc_list;
2992 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2993 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2994 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2995 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2996 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2997 pMcList->dmi_addr[0],
2998 pMcList->dmi_addr[1],
2999 pMcList->dmi_addr[2],
3000 pMcList->dmi_addr[3],
3001 pMcList->dmi_addr[4],
3002 pMcList->dmi_addr[5]));
3004 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
3006 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3009 } /* SkGeSetRxMode */
3012 /*****************************************************************************
3014 * SkGeChangeMtu - set the MTU to another value
3017 * This function sets is called whenever the MTU size is changed
3018 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
3019 * ethernet MTU size, long frame support is activated.
3022 * 0, if everything is ok
3025 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
3030 unsigned long Flags;
3034 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3035 ("SkGeChangeMtu starts now...\n"));
3037 pNet = (DEV_NET*) dev->priv;
3040 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
3044 if(pAC->BoardLevel != SK_INIT_RUN) {
3048 #ifdef SK_DIAG_SUPPORT
3049 if (pAC->DiagModeActive == DIAG_ACTIVE) {
3050 if (pAC->DiagFlowCtrl == SK_FALSE) {
3051 return -1; /* still in use, deny any actions of MTU */
3053 pAC->DiagFlowCtrl = SK_FALSE;
3059 pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
3060 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
3064 pAC->RxBufSize = NewMtu + 32;
3067 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3068 ("New MTU: %d\n", NewMtu));
3071 ** Prevent any reconfiguration while changing the MTU
3072 ** by disabling any interrupts
3074 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
3075 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3078 ** Notify RLMT that any ports are to be stopped
3080 EvPara.Para32[0] = 0;
3081 EvPara.Para32[1] = -1;
3082 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3083 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3084 EvPara.Para32[0] = 1;
3085 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3087 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3091 ** After calling the SkEventDispatcher(), RLMT is aware about
3092 ** the stopped ports -> configuration can take place!
3094 SkEventDispatcher(pAC, pAC->IoBase);
3096 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3098 &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
3099 netif_stop_queue(pAC->dev[i]);
3104 ** Depending on the desired MTU size change, a different number of
3105 ** RX buffers need to be allocated
3107 if (NewMtu > 1500) {
3109 ** Use less rx buffers
3111 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3112 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3113 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3114 (pAC->RxDescrPerRing / 4);
3116 if (i == pAC->ActivePort) {
3117 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3118 (pAC->RxDescrPerRing / 4);
3120 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3121 (pAC->RxDescrPerRing / 10);
3127 ** Use the normal amount of rx buffers
3129 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3130 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3131 pAC->RxPort[i].RxFillLimit = 1;
3133 if (i == pAC->ActivePort) {
3134 pAC->RxPort[i].RxFillLimit = 1;
3136 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3137 (pAC->RxDescrPerRing / 4);
3143 SkGeDeInit(pAC, pAC->IoBase);
3146 ** enable/disable hardware support for long frames
3148 if (NewMtu > 1500) {
3149 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
3150 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
3152 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3153 pAC->GIni.GIPortUsage = SK_MUL_LINK;
3155 pAC->GIni.GIPortUsage = SK_RED_LINK;
3159 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
3160 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
3161 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
3162 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
3163 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
3164 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
3165 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
3169 ** Speed and others are set back to default in level 1 init!
3171 GetConfiguration(pAC);
3173 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
3174 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
3175 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
3176 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
3177 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
3178 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
3179 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
3182 ** clear and reinit the rx rings here
3184 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3185 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
3186 ClearRxRing(pAC, &pAC->RxPort[i]);
3187 FillRxRing(pAC, &pAC->RxPort[i]);
3190 ** Enable transmit descriptor polling
3192 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
3193 FillRxRing(pAC, &pAC->RxPort[i]);
3196 SkGeYellowLED(pAC, pAC->IoBase, 1);
3197 SkDimEnableModerationIfNeeded(pAC);
3198 SkDimDisplayModerationSettings(pAC);
3200 netif_start_queue(pAC->dev[pNet->PortNr]);
3201 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
3202 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
3206 ** Enable Interrupts again
3208 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
3209 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
3211 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3212 SkEventDispatcher(pAC, pAC->IoBase);
3215 ** Notify RLMT about the changing and restarting one (or more) ports
3217 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3218 EvPara.Para32[0] = pAC->RlmtNets;
3219 EvPara.Para32[1] = -1;
3220 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
3221 EvPara.Para32[0] = pNet->PortNr;
3222 EvPara.Para32[1] = -1;
3223 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3225 if (pOtherNet->Up) {
3226 EvPara.Para32[0] = pOtherNet->PortNr;
3227 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3230 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3233 SkEventDispatcher(pAC, pAC->IoBase);
3234 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3237 ** While testing this driver with latest kernel 2.5 (2.5.70), it
3238 ** seems as if upper layers have a problem to handle a successful
3239 ** return value of '0'. If such a zero is returned, the complete
3240 ** system hangs for several minutes (!), which is in acceptable.
3242 ** Currently it is not clear, what the exact reason for this problem
3243 ** is. The implemented workaround for 2.5 is to return the desired
3244 ** new MTU size if all needed changes for the new MTU size where
3245 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
3246 ** which indicates the successful change of the mtu-size.
3250 } /* SkGeChangeMtu */
3253 /*****************************************************************************
3255 * SkGeStats - return ethernet device statistics
3258 * This function return statistic data about the ethernet device
3259 * to the operating system.
3262 * pointer to the statistic structure.
3264 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
3266 DEV_NET *pNet = (DEV_NET*) dev->priv;
3267 SK_AC *pAC = pNet->pAC;
3268 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
3269 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
3270 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
3271 unsigned int Size; /* size of pnmi struct */
3272 unsigned long Flags; /* for spin lock */
3274 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3275 ("SkGeStats starts now...\n"));
3276 pPnmiStruct = &pAC->PnmiStruct;
3278 #ifdef SK_DIAG_SUPPORT
3279 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
3280 (pAC->BoardLevel == SK_INIT_RUN)) {
3282 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
3283 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3284 Size = SK_PNMI_STRUCT_SIZE;
3285 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
3286 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3287 #ifdef SK_DIAG_SUPPORT
3291 pPnmiStat = &pPnmiStruct->Stat[0];
3292 pPnmiConf = &pPnmiStruct->Conf[0];
3294 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
3295 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
3296 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
3297 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
3299 if (pNet->Mtu <= 1500) {
3300 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
3302 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
3303 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
3307 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
3308 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
3310 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3311 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
3312 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
3313 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
3314 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3316 /* detailed rx_errors: */
3317 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
3318 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3319 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
3320 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
3321 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3322 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
3324 /* detailed tx_errors */
3325 pAC->stats.tx_aborted_errors = (SK_U32) 0;
3326 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3327 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
3328 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3329 pAC->stats.tx_window_errors = (SK_U32) 0;
3331 return(&pAC->stats);
3335 /*****************************************************************************
3337 * SkGeIoctl - IO-control function
3340 * This function is called if an ioctl is issued on the device.
3341 * There are three subfunction for reading, writing and test-writing
3342 * the private MIB data structure (usefull for SysKonnect-internal tools).
3345 * 0, if everything is ok
3348 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
3353 struct pci_dev *pdev = NULL;
3355 unsigned int Err = 0;
3358 unsigned int Length = 0;
3359 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
3361 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3362 ("SkGeIoctl starts now...\n"));
3364 pNet = (DEV_NET*) dev->priv;
3367 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
3372 case SK_IOCTL_SETMIB:
3373 case SK_IOCTL_PRESETMIB:
3374 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3375 case SK_IOCTL_GETMIB:
3376 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
3377 Ioctl.Len<sizeof(pAC->PnmiStruct)?
3378 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
3381 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
3382 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
3383 Ioctl.Len<Size? Ioctl.Len : Size)) {
3387 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3392 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3395 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3397 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3400 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3404 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
3408 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3413 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3418 kfree(pMemBuf); /* cleanup everything */
3420 #ifdef SK_DIAG_SUPPORT
3422 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3423 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3426 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3428 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3431 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3436 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3438 ** While coding this new IOCTL interface, only a few lines of code
3439 ** are to to be added. Therefore no dedicated function has been
3440 ** added. If more functionality is added, a separate function
3441 ** should be used...
3443 * ((SK_U32 *)pMemBuf) = 0;
3444 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3445 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pdev->slot_name);
3446 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3451 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3456 kfree(pMemBuf); /* cleanup everything */
3468 /*****************************************************************************
3470 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3473 * This function reads/writes the MIB data using PNMI (Private Network
3474 * Management Interface).
3475 * The destination for the data must be provided with the
3476 * ioctl call and is given to the driver in the form of
3477 * a user space address.
3478 * Copying from the user-provided data area into kernel messages
3479 * and back is done by copy_from_user and copy_to_user calls in
3483 * returned size from PNMI call
3485 static int SkGeIocMib(
3486 DEV_NET *pNet, /* pointer to the adapter context */
3487 unsigned int Size, /* length of ioctl data */
3488 int mode) /* flag for set/preset */
3490 unsigned long Flags; /* for spin lock */
3493 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3494 ("SkGeIocMib starts now...\n"));
3497 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3499 case SK_IOCTL_GETMIB:
3500 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3503 case SK_IOCTL_PRESETMIB:
3504 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3507 case SK_IOCTL_SETMIB:
3508 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3514 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3515 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3516 ("MIB data access succeeded\n"));
3521 /*****************************************************************************
3523 * GetConfiguration - read configuration information
3526 * This function reads per-adapter configuration information from
3527 * the options provided on the command line.
3532 static void GetConfiguration(
3533 SK_AC *pAC) /* pointer to the adapter context structure */
3535 SK_I32 Port; /* preferred port */
3538 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3539 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3540 int DuplexCap = 0; /* 0=both,1=full,2=half */
3541 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3542 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3544 SK_BOOL IsConTypeDefined = SK_TRUE;
3545 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3546 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3547 SK_BOOL IsRoleDefined = SK_TRUE;
3548 SK_BOOL IsModeDefined = SK_TRUE;
3550 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3551 * parameter. The mapping is described by this table:
3552 * DuplexCap -> | both | full | half |
3554 * -----------------------------------------------------------------
3555 * Off | illegal | Full | Half |
3556 * -----------------------------------------------------------------
3557 * On | AutoBoth | AutoFull | AutoHalf |
3558 * -----------------------------------------------------------------
3559 * Sense | AutoSense | AutoSense | AutoSense |
3561 int Capabilities[3][3] =
3562 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3563 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3564 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3572 #define M_CurrPort pAC->GIni.GP[Port]
3576 ** Set the default values first for both ports!
3578 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3579 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3580 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3581 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3582 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3586 ** Check merged parameter ConType. If it has not been used,
3587 ** verify any other parameter (e.g. AutoNeg) and use default values.
3589 ** Stating both ConType and other lowlevel link parameters is also
3590 ** possible. If this is the case, the passed ConType-parameter is
3591 ** overwritten by the lowlevel link parameter.
3593 ** The following settings are used for a merged ConType-parameter:
3595 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3596 ** ------- ------ ------- -------- ---------- -----
3597 ** Auto Both On SymOrRem Auto Auto
3598 ** 100FD Full Off None <ignored> 100
3599 ** 100HD Half Off None <ignored> 100
3600 ** 10FD Full Off None <ignored> 10
3601 ** 10HD Half Off None <ignored> 10
3603 ** This ConType parameter is used for all ports of the adapter!
3605 if ( (ConType != NULL) &&
3606 (pAC->Index < SK_MAX_CARD_PARAM) &&
3607 (ConType[pAC->Index] != NULL) ) {
3609 /* Check chipset family */
3610 if ((!pAC->ChipsetType) &&
3611 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3612 (strcmp(ConType[pAC->Index],"")!=0)) {
3613 /* Set the speed parameter back */
3614 printk("sk98lin: Illegal value \"%s\" "
3617 ConType[pAC->Index]);
3619 sprintf(ConType[pAC->Index], "Auto");
3622 if (strcmp(ConType[pAC->Index],"")==0) {
3623 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3624 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3625 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3626 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3627 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3628 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3629 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3631 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3632 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3633 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3634 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3635 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3636 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3638 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3639 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3640 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3641 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3642 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3643 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3645 } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
3646 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3647 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3648 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3649 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3650 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3652 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3653 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3654 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3655 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3656 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3657 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3660 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3661 ConType[pAC->Index]);
3662 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3665 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3669 ** Parse any parameter settings for port A:
3670 ** a) any LinkSpeed stated?
3672 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3673 Speed_A[pAC->Index] != NULL) {
3674 if (strcmp(Speed_A[pAC->Index],"")==0) {
3675 IsLinkSpeedDefined = SK_FALSE;
3676 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3677 LinkSpeed = SK_LSPEED_AUTO;
3678 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3679 LinkSpeed = SK_LSPEED_10MBPS;
3680 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3681 LinkSpeed = SK_LSPEED_100MBPS;
3682 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3683 LinkSpeed = SK_LSPEED_1000MBPS;
3685 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3686 Speed_A[pAC->Index]);
3687 IsLinkSpeedDefined = SK_FALSE;
3690 IsLinkSpeedDefined = SK_FALSE;
3694 ** Check speed parameter:
3695 ** Only copper type adapter and GE V2 cards
3697 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3698 ((LinkSpeed != SK_LSPEED_AUTO) &&
3699 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3700 printk("sk98lin: Illegal value for Speed_A. "
3701 "Not a copper card or GE V2 card\n Using "
3703 LinkSpeed = SK_LSPEED_1000MBPS;
3707 ** Decide whether to set new config value if somethig valid has
3710 if (IsLinkSpeedDefined) {
3711 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3715 ** b) Any Autonegotiation and DuplexCapabilities set?
3716 ** Please note that both belong together...
3718 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3720 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3721 AutoNeg_A[pAC->Index] != NULL) {
3723 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3725 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3727 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3729 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3732 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3733 AutoNeg_A[pAC->Index]);
3737 DuplexCap = DC_BOTH;
3739 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3740 DupCap_A[pAC->Index] != NULL) {
3742 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3744 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3745 DuplexCap = DC_BOTH;
3746 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3747 DuplexCap = DC_FULL;
3748 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3749 DuplexCap = DC_HALF;
3751 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3752 DupCap_A[pAC->Index]);
3757 ** Check for illegal combinations
3759 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3760 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3761 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3762 (pAC->ChipsetType)) {
3763 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3764 " Using Full Duplex.\n");
3765 DuplexCap = DC_FULL;
3768 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3769 printk("sk98lin, Port A: DuplexCapabilities"
3770 " ignored using Sense mode\n");
3773 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3774 printk("sk98lin: Port A: Illegal combination"
3775 " of values AutoNeg. and DuplexCap.\n Using "
3777 DuplexCap = DC_FULL;
3780 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3781 DuplexCap = DC_FULL;
3784 if (!AutoSet && DupSet) {
3785 printk("sk98lin: Port A: Duplex setting not"
3786 " possible in\n default AutoNegotiation mode"
3787 " (Sense).\n Using AutoNegotiation On\n");
3792 ** set the desired mode
3794 if (AutoSet || DupSet) {
3795 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3799 ** c) Any Flowcontrol-parameter set?
3801 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3802 FlowCtrl_A[pAC->Index] != NULL) {
3803 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3804 IsFlowCtrlDefined = SK_FALSE;
3805 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3806 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3807 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3808 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3809 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3810 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3811 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3812 FlowCtrl = SK_FLOW_MODE_NONE;
3814 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3815 FlowCtrl_A[pAC->Index]);
3816 IsFlowCtrlDefined = SK_FALSE;
3819 IsFlowCtrlDefined = SK_FALSE;
3822 if (IsFlowCtrlDefined) {
3823 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3824 printk("sk98lin: Port A: FlowControl"
3825 " impossible without AutoNegotiation,"
3827 FlowCtrl = SK_FLOW_MODE_NONE;
3829 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3833 ** d) What is with the RoleParameter?
3835 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3836 Role_A[pAC->Index] != NULL) {
3837 if (strcmp(Role_A[pAC->Index],"")==0) {
3838 IsRoleDefined = SK_FALSE;
3839 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3840 MSMode = SK_MS_MODE_AUTO;
3841 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3842 MSMode = SK_MS_MODE_MASTER;
3843 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3844 MSMode = SK_MS_MODE_SLAVE;
3846 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3847 Role_A[pAC->Index]);
3848 IsRoleDefined = SK_FALSE;
3851 IsRoleDefined = SK_FALSE;
3854 if (IsRoleDefined == SK_TRUE) {
3855 pAC->GIni.GP[0].PMSMode = MSMode;
3861 ** Parse any parameter settings for port B:
3862 ** a) any LinkSpeed stated?
3864 IsConTypeDefined = SK_TRUE;
3865 IsLinkSpeedDefined = SK_TRUE;
3866 IsFlowCtrlDefined = SK_TRUE;
3867 IsModeDefined = SK_TRUE;
3869 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3870 Speed_B[pAC->Index] != NULL) {
3871 if (strcmp(Speed_B[pAC->Index],"")==0) {
3872 IsLinkSpeedDefined = SK_FALSE;
3873 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3874 LinkSpeed = SK_LSPEED_AUTO;
3875 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3876 LinkSpeed = SK_LSPEED_10MBPS;
3877 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3878 LinkSpeed = SK_LSPEED_100MBPS;
3879 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3880 LinkSpeed = SK_LSPEED_1000MBPS;
3882 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3883 Speed_B[pAC->Index]);
3884 IsLinkSpeedDefined = SK_FALSE;
3887 IsLinkSpeedDefined = SK_FALSE;
3891 ** Check speed parameter:
3892 ** Only copper type adapter and GE V2 cards
3894 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3895 ((LinkSpeed != SK_LSPEED_AUTO) &&
3896 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3897 printk("sk98lin: Illegal value for Speed_B. "
3898 "Not a copper card or GE V2 card\n Using "
3900 LinkSpeed = SK_LSPEED_1000MBPS;
3904 ** Decide whether to set new config value if somethig valid has
3907 if (IsLinkSpeedDefined) {
3908 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3912 ** b) Any Autonegotiation and DuplexCapabilities set?
3913 ** Please note that both belong together...
3915 AutoNeg = AN_SENS; /* default: do auto Sense */
3917 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3918 AutoNeg_B[pAC->Index] != NULL) {
3920 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3922 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3924 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3926 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3929 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3930 AutoNeg_B[pAC->Index]);
3934 DuplexCap = DC_BOTH;
3936 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3937 DupCap_B[pAC->Index] != NULL) {
3939 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3941 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3942 DuplexCap = DC_BOTH;
3943 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3944 DuplexCap = DC_FULL;
3945 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3946 DuplexCap = DC_HALF;
3948 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3949 DupCap_B[pAC->Index]);
3955 ** Check for illegal combinations
3957 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3958 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3959 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3960 (pAC->ChipsetType)) {
3961 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3962 " Using Full Duplex.\n");
3963 DuplexCap = DC_FULL;
3966 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3967 printk("sk98lin, Port B: DuplexCapabilities"
3968 " ignored using Sense mode\n");
3971 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3972 printk("sk98lin: Port B: Illegal combination"
3973 " of values AutoNeg. and DuplexCap.\n Using "
3975 DuplexCap = DC_FULL;
3978 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3979 DuplexCap = DC_FULL;
3982 if (!AutoSet && DupSet) {
3983 printk("sk98lin: Port B: Duplex setting not"
3984 " possible in\n default AutoNegotiation mode"
3985 " (Sense).\n Using AutoNegotiation On\n");
3990 ** set the desired mode
3992 if (AutoSet || DupSet) {
3993 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3997 ** c) Any FlowCtrl parameter set?
3999 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4000 FlowCtrl_B[pAC->Index] != NULL) {
4001 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
4002 IsFlowCtrlDefined = SK_FALSE;
4003 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
4004 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
4005 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
4006 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
4007 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
4008 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
4009 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
4010 FlowCtrl = SK_FLOW_MODE_NONE;
4012 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
4013 FlowCtrl_B[pAC->Index]);
4014 IsFlowCtrlDefined = SK_FALSE;
4017 IsFlowCtrlDefined = SK_FALSE;
4020 if (IsFlowCtrlDefined) {
4021 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
4022 printk("sk98lin: Port B: FlowControl"
4023 " impossible without AutoNegotiation,"
4025 FlowCtrl = SK_FLOW_MODE_NONE;
4027 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
4031 ** d) What is the RoleParameter?
4033 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4034 Role_B[pAC->Index] != NULL) {
4035 if (strcmp(Role_B[pAC->Index],"")==0) {
4036 IsRoleDefined = SK_FALSE;
4037 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
4038 MSMode = SK_MS_MODE_AUTO;
4039 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
4040 MSMode = SK_MS_MODE_MASTER;
4041 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
4042 MSMode = SK_MS_MODE_SLAVE;
4044 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
4045 Role_B[pAC->Index]);
4046 IsRoleDefined = SK_FALSE;
4049 IsRoleDefined = SK_FALSE;
4052 if (IsRoleDefined) {
4053 pAC->GIni.GP[1].PMSMode = MSMode;
4057 ** Evaluate settings for both ports
4059 pAC->ActivePort = 0;
4060 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4061 PrefPort[pAC->Index] != NULL) {
4062 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
4063 pAC->ActivePort = 0;
4064 pAC->Rlmt.Net[0].Preference = -1; /* auto */
4065 pAC->Rlmt.Net[0].PrefPort = 0;
4066 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
4068 ** do not set ActivePort here, thus a port
4069 ** switch is issued after net up.
4072 pAC->Rlmt.Net[0].Preference = Port;
4073 pAC->Rlmt.Net[0].PrefPort = Port;
4074 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
4076 ** do not set ActivePort here, thus a port
4077 ** switch is issued after net up.
4079 if (pAC->GIni.GIMacsFound == 1) {
4080 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
4081 " Port B not available on single port adapters.\n");
4083 pAC->ActivePort = 0;
4084 pAC->Rlmt.Net[0].Preference = -1; /* auto */
4085 pAC->Rlmt.Net[0].PrefPort = 0;
4088 pAC->Rlmt.Net[0].Preference = Port;
4089 pAC->Rlmt.Net[0].PrefPort = Port;
4092 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
4093 PrefPort[pAC->Index]);
4099 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4100 RlmtMode[pAC->Index] != NULL) {
4101 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
4103 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
4104 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4105 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
4106 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4107 SK_RLMT_CHECK_LOC_LINK;
4108 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
4109 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4110 SK_RLMT_CHECK_LOC_LINK |
4112 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
4113 (pAC->GIni.GIMacsFound == 2)) {
4114 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4117 printk("sk98lin: Illegal value \"%s\" for"
4118 " RlmtMode, using default\n",
4119 RlmtMode[pAC->Index]);
4127 ** Check the interrupt moderation parameters
4129 if (Moderation[pAC->Index] != NULL) {
4130 if (strcmp(Moderation[pAC->Index], "") == 0) {
4131 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4132 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
4133 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
4134 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
4135 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
4136 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
4137 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4139 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
4140 " Disable interrupt moderation.\n",
4141 Moderation[pAC->Index]);
4142 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4145 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4148 if (Stats[pAC->Index] != NULL) {
4149 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
4150 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
4152 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
4155 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
4158 if (ModerationMask[pAC->Index] != NULL) {
4159 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
4160 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
4161 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
4162 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
4163 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
4164 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
4165 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
4166 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
4167 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
4168 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
4169 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
4170 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4171 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
4172 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4173 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
4174 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
4175 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
4176 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
4177 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
4178 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4179 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
4180 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4181 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
4182 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4183 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
4184 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4185 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
4186 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4187 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
4188 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4189 } else { /* some rubbish */
4190 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
4192 } else { /* operator has stated nothing */
4193 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4196 if (AutoSizing[pAC->Index] != NULL) {
4197 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
4198 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4200 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4202 } else { /* operator has stated nothing */
4203 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4206 if (IntsPerSec[pAC->Index] != 0) {
4207 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
4208 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
4209 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
4210 " Using default value of %i.\n",
4211 IntsPerSec[pAC->Index],
4212 C_INT_MOD_IPS_LOWER_RANGE,
4213 C_INT_MOD_IPS_UPPER_RANGE,
4214 C_INTS_PER_SEC_DEFAULT);
4215 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
4217 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
4220 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
4224 ** Evaluate upper and lower moderation threshold
4226 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
4227 pAC->DynIrqModInfo.MaxModIntsPerSec +
4228 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
4230 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
4231 pAC->DynIrqModInfo.MaxModIntsPerSec -
4232 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
4234 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
4237 } /* GetConfiguration */
4240 /*****************************************************************************
4242 * ProductStr - return a adapter identification string from vpd
4245 * This function reads the product name string from the vpd area
4246 * and puts it the field pAC->DeviceString.
4250 static void ProductStr(
4251 SK_AC *pAC /* pointer to adapter context */
4254 int StrLen = 80; /* length of the string, defined in SK_AC */
4255 char Keyword[] = VPD_NAME; /* vpd productname identifier */
4256 int ReturnCode; /* return code from vpd_read */
4257 unsigned long Flags;
4259 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
4260 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
4262 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
4263 if (ReturnCode != 0) {
4264 /* there was an error reading the vpd data */
4265 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
4266 ("Error reading VPD data: %d\n", ReturnCode));
4267 pAC->DeviceStr[0] = '\0';
4271 /*****************************************************************************
4273 * StartDrvCleanupTimer - Start timer to check for descriptors which
4274 * might be placed in descriptor ring, but
4275 * havent been handled up to now
4278 * This function requests a HW-timer fo the Yukon card. The actions to
4279 * perform when this timer expires, are located in the SkDrvEvent().
4284 StartDrvCleanupTimer(SK_AC *pAC) {
4285 SK_EVPARA EventParam; /* Event struct for timer event */
4287 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
4288 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
4289 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
4290 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
4291 SKGE_DRV, SK_DRV_TIMER, EventParam);
4294 /*****************************************************************************
4296 * StopDrvCleanupTimer - Stop timer to check for descriptors
4299 * This function requests a HW-timer fo the Yukon card. The actions to
4300 * perform when this timer expires, are located in the SkDrvEvent().
4305 StopDrvCleanupTimer(SK_AC *pAC) {
4306 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
4307 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
4310 /****************************************************************************/
4311 /* functions for common modules *********************************************/
4312 /****************************************************************************/
4315 /*****************************************************************************
4317 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
4320 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
4321 * is embedded into a socket buff data area.
4327 * NULL or pointer to Mbuf.
4329 SK_MBUF *SkDrvAllocRlmtMbuf(
4330 SK_AC *pAC, /* pointer to adapter context */
4331 SK_IOC IoC, /* the IO-context */
4332 unsigned BufferSize) /* size of the requested buffer */
4334 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
4335 struct sk_buff *pMsgBlock; /* pointer to a new message block */
4337 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
4338 if (pMsgBlock == NULL) {
4341 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
4342 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
4343 pRlmtMbuf->pNext = NULL;
4344 pRlmtMbuf->pOs = pMsgBlock;
4345 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
4346 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
4347 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
4350 } /* SkDrvAllocRlmtMbuf */
4353 /*****************************************************************************
4355 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
4358 * This routine frees one or more RLMT mbuf(s).
4366 void SkDrvFreeRlmtMbuf(
4367 SK_AC *pAC, /* pointer to adapter context */
4368 SK_IOC IoC, /* the IO-context */
4369 SK_MBUF *pMbuf) /* size of the requested buffer */
4376 pNextMbuf = pFreeMbuf->pNext;
4377 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
4378 pFreeMbuf = pNextMbuf;
4379 } while ( pFreeMbuf != NULL );
4380 } /* SkDrvFreeRlmtMbuf */
4383 /*****************************************************************************
4385 * SkOsGetTime - provide a time value
4388 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
4389 * It is not used for absolute time, but only for time differences.
4395 SK_U64 SkOsGetTime(SK_AC *pAC)
4397 SK_U64 PrivateJiffies;
4398 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
4399 return PrivateJiffies;
4403 /*****************************************************************************
4405 * SkPciReadCfgDWord - read a 32 bit value from pci config space
4408 * This routine reads a 32 bit value from the pci configuration
4412 * 0 - indicate everything worked ok.
4413 * != 0 - error indication
4415 int SkPciReadCfgDWord(
4416 SK_AC *pAC, /* Adapter Control structure pointer */
4417 int PciAddr, /* PCI register address */
4418 SK_U32 *pVal) /* pointer to store the read value */
4420 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4422 } /* SkPciReadCfgDWord */
4425 /*****************************************************************************
4427 * SkPciReadCfgWord - read a 16 bit value from pci config space
4430 * This routine reads a 16 bit value from the pci configuration
4434 * 0 - indicate everything worked ok.
4435 * != 0 - error indication
4437 int SkPciReadCfgWord(
4438 SK_AC *pAC, /* Adapter Control structure pointer */
4439 int PciAddr, /* PCI register address */
4440 SK_U16 *pVal) /* pointer to store the read value */
4442 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4444 } /* SkPciReadCfgWord */
4447 /*****************************************************************************
4449 * SkPciReadCfgByte - read a 8 bit value from pci config space
4452 * This routine reads a 8 bit value from the pci configuration
4456 * 0 - indicate everything worked ok.
4457 * != 0 - error indication
4459 int SkPciReadCfgByte(
4460 SK_AC *pAC, /* Adapter Control structure pointer */
4461 int PciAddr, /* PCI register address */
4462 SK_U8 *pVal) /* pointer to store the read value */
4464 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4466 } /* SkPciReadCfgByte */
4469 /*****************************************************************************
4471 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4474 * This routine writes a 32 bit value to the pci configuration
4478 * 0 - indicate everything worked ok.
4479 * != 0 - error indication
4481 int SkPciWriteCfgDWord(
4482 SK_AC *pAC, /* Adapter Control structure pointer */
4483 int PciAddr, /* PCI register address */
4484 SK_U32 Val) /* pointer to store the read value */
4486 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4488 } /* SkPciWriteCfgDWord */
4491 /*****************************************************************************
4493 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4496 * This routine writes a 16 bit value to the pci configuration
4497 * space. The flag PciConfigUp indicates whether the config space
4498 * is accesible or must be set up first.
4501 * 0 - indicate everything worked ok.
4502 * != 0 - error indication
4504 int SkPciWriteCfgWord(
4505 SK_AC *pAC, /* Adapter Control structure pointer */
4506 int PciAddr, /* PCI register address */
4507 SK_U16 Val) /* pointer to store the read value */
4509 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4511 } /* SkPciWriteCfgWord */
4514 /*****************************************************************************
4516 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4519 * This routine writes a 8 bit value to the pci configuration
4520 * space. The flag PciConfigUp indicates whether the config space
4521 * is accesible or must be set up first.
4524 * 0 - indicate everything worked ok.
4525 * != 0 - error indication
4527 int SkPciWriteCfgByte(
4528 SK_AC *pAC, /* Adapter Control structure pointer */
4529 int PciAddr, /* PCI register address */
4530 SK_U8 Val) /* pointer to store the read value */
4532 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4534 } /* SkPciWriteCfgByte */
4537 /*****************************************************************************
4539 * SkDrvEvent - handle driver events
4542 * This function handles events from all modules directed to the driver
4545 * Is called under protection of slow path lock.
4548 * 0 if everything ok
4553 SK_AC *pAC, /* pointer to adapter context */
4554 SK_IOC IoC, /* io-context */
4555 SK_U32 Event, /* event-id */
4556 SK_EVPARA Param) /* event-parameter */
4558 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4559 struct sk_buff *pMsg; /* pointer to a message block */
4560 int FromPort; /* the port from which we switch away */
4561 int ToPort; /* the port we switch to */
4562 SK_EVPARA NewPara; /* parameter for further events */
4564 unsigned long Flags;
4568 case SK_DRV_ADAP_FAIL:
4569 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4570 ("ADAPTER FAIL EVENT\n"));
4571 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4572 /* disable interrupts */
4573 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4576 case SK_DRV_PORT_FAIL:
4577 FromPort = Param.Para32[0];
4578 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4579 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4580 if (FromPort == 0) {
4581 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4583 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4587 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4589 FromPort = Param.Para32[0];
4590 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4591 ("PORT RESET EVENT, Port: %d ", FromPort));
4592 NewPara.Para64 = FromPort;
4593 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4595 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4598 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4599 pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
4600 spin_unlock_irqrestore(
4601 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4604 /* clear rx ring from received frames */
4605 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4607 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4609 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4612 /* tschilling: Handling of return value inserted. */
4613 if (SkGeInitPort(pAC, IoC, FromPort)) {
4614 if (FromPort == 0) {
4615 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4617 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4620 SkAddrMcUpdate(pAC,IoC, FromPort);
4621 PortReInitBmu(pAC, FromPort);
4622 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4623 ClearAndStartRx(pAC, FromPort);
4624 spin_unlock_irqrestore(
4625 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4628 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4630 FromPort = Param.Para32[0];
4631 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4632 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4634 SkAddrMcUpdate(pAC,IoC, FromPort);
4636 if (DoPrintInterfaceChange) {
4637 printk("%s: network connection up using"
4638 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4640 /* tschilling: Values changed according to LinkSpeedUsed. */
4641 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4642 if (Stat == SK_LSPEED_STAT_10MBPS) {
4643 printk(" speed: 10\n");
4644 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4645 printk(" speed: 100\n");
4646 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4647 printk(" speed: 1000\n");
4649 printk(" speed: unknown\n");
4653 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4654 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4655 Stat == SK_LMODE_STAT_AUTOFULL) {
4656 printk(" autonegotiation: yes\n");
4659 printk(" autonegotiation: no\n");
4661 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4662 Stat == SK_LMODE_STAT_HALF) {
4663 printk(" duplex mode: half\n");
4666 printk(" duplex mode: full\n");
4668 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4669 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4670 printk(" flowctrl: remote send\n");
4672 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4673 printk(" flowctrl: local send\n");
4675 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4676 printk(" flowctrl: symmetric\n");
4679 printk(" flowctrl: none\n");
4682 /* tschilling: Check against CopperType now. */
4683 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4684 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4685 SK_LSPEED_STAT_1000MBPS)) {
4686 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4687 if (Stat == SK_MS_STAT_MASTER ) {
4688 printk(" role: master\n");
4690 else if (Stat == SK_MS_STAT_SLAVE ) {
4691 printk(" role: slave\n");
4694 printk(" role: ???\n");
4699 Display dim (dynamic interrupt moderation)
4702 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4703 printk(" irq moderation: static (%d ints/sec)\n",
4704 pAC->DynIrqModInfo.MaxModIntsPerSec);
4705 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4706 printk(" irq moderation: dynamic (%d ints/sec)\n",
4707 pAC->DynIrqModInfo.MaxModIntsPerSec);
4709 printk(" irq moderation: disabled\n");
4713 if (pAC->ChipsetType)
4714 #ifdef USE_SK_TX_CHECKSUM
4715 printk(" scatter-gather: enabled\n");
4717 printk(" tx-checksum: disabled\n");
4720 printk(" scatter-gather: disabled\n");
4722 printk(" scatter-gather: disabled\n");
4725 #ifndef USE_SK_RX_CHECKSUM
4726 printk(" rx-checksum: disabled\n");
4730 DoPrintInterfaceChange = SK_TRUE;
4733 if ((Param.Para32[0] != pAC->ActivePort) &&
4734 (pAC->RlmtNets == 1)) {
4735 NewPara.Para32[0] = pAC->ActivePort;
4736 NewPara.Para32[1] = Param.Para32[0];
4737 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4741 /* Inform the world that link protocol is up. */
4742 pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
4745 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4747 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4748 ("NET DOWN EVENT "));
4749 if (DoPrintInterfaceChange) {
4750 printk("%s: network connection down\n",
4751 pAC->dev[Param.Para32[1]]->name);
4753 DoPrintInterfaceChange = SK_TRUE;
4755 pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
4757 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4758 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4759 ("PORT SWITCH HARD "));
4760 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4762 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4763 'A'+Param.Para32[1]);
4764 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4765 FromPort = Param.Para32[0];
4766 ToPort = Param.Para32[1];
4767 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4768 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4769 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4770 NewPara.Para64 = FromPort;
4771 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4772 NewPara.Para64 = ToPort;
4773 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4775 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4778 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4779 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4780 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4781 spin_unlock_irqrestore(
4782 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4783 spin_unlock_irqrestore(
4784 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4787 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4788 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4790 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4791 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4793 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4796 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4797 pAC->ActivePort = ToPort;
4801 /* tschilling: New common function with minimum size check. */
4803 if (pAC->RlmtNets == 2) {
4807 if (SkGeInitAssignRamToQueues(
4811 spin_unlock_irqrestore(
4812 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4813 spin_unlock_irqrestore(
4814 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4816 printk("SkGeInitAssignRamToQueues failed.\n");
4820 /* tschilling: Handling of return values inserted. */
4821 if (SkGeInitPort(pAC, IoC, FromPort) ||
4822 SkGeInitPort(pAC, IoC, ToPort)) {
4823 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4825 if (Event == SK_DRV_SWITCH_SOFT) {
4826 SkMacRxTxEnable(pAC, IoC, FromPort);
4828 SkMacRxTxEnable(pAC, IoC, ToPort);
4829 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4830 SkAddrMcUpdate(pAC, IoC, FromPort);
4831 SkAddrMcUpdate(pAC, IoC, ToPort);
4832 PortReInitBmu(pAC, FromPort);
4833 PortReInitBmu(pAC, ToPort);
4834 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4835 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4836 ClearAndStartRx(pAC, FromPort);
4837 ClearAndStartRx(pAC, ToPort);
4838 spin_unlock_irqrestore(
4839 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4840 spin_unlock_irqrestore(
4841 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4844 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4845 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4847 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4848 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4849 skb_put(pMsg, pRlmtMbuf->Length);
4850 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4853 DEV_KFREE_SKB_ANY(pMsg);
4856 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4858 ** expiration of the moderation timer implies that
4859 ** dynamic moderation is to be applied
4861 SkDimStartModerationTimer(pAC);
4863 if (pAC->DynIrqModInfo.DisplayStats) {
4864 SkDimDisplayModerationSettings(pAC);
4866 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4868 ** check if we need to check for descriptors which
4869 ** haven't been handled the last millisecs
4871 StartDrvCleanupTimer(pAC);
4872 if (pAC->GIni.GIMacsFound == 2) {
4873 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4875 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4877 printk("Expiration of unknown timer\n");
4883 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4890 /*****************************************************************************
4892 * SkErrorLog - log errors
4895 * This function logs errors to the system buffer and to the console
4898 * 0 if everything ok
4911 case SK_ERRCL_OTHER:
4912 strcpy(ClassStr, "Other error");
4914 case SK_ERRCL_CONFIG:
4915 strcpy(ClassStr, "Configuration error");
4918 strcpy(ClassStr, "Initialization error");
4920 case SK_ERRCL_NORES:
4921 strcpy(ClassStr, "Out of resources error");
4924 strcpy(ClassStr, "internal Software error");
4927 strcpy(ClassStr, "Hardware failure");
4930 strcpy(ClassStr, "Communication error");
4933 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4934 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4935 ClassStr, ErrNum, pErrorMsg);
4939 #ifdef SK_DIAG_SUPPORT
4941 /*****************************************************************************
4943 * SkDrvEnterDiagMode - handles DIAG attach request
4946 * Notify the kernel to NOT access the card any longer due to DIAG
4947 * Deinitialize the Card
4952 int SkDrvEnterDiagMode(
4953 SK_AC *pAc) /* pointer to adapter context */
4956 DEV_NET *pNet = NULL;
4958 pNet = (DEV_NET *) pAc->dev[0]->priv;
4961 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4962 sizeof(SK_PNMI_STRUCT_DATA));
4964 pAC->DiagModeActive = DIAG_ACTIVE;
4965 if (pAC->BoardLevel > SK_INIT_DATA) {
4967 pAC->WasIfUp[0] = SK_TRUE;
4968 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4969 DoPrintInterfaceChange = SK_FALSE;
4970 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4972 pAC->WasIfUp[0] = SK_FALSE;
4974 if (pNet != (DEV_NET *) pAc->dev[1]->priv) {
4975 pNet = (DEV_NET *) pAc->dev[1]->priv;
4977 pAC->WasIfUp[1] = SK_TRUE;
4978 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4979 DoPrintInterfaceChange = SK_FALSE;
4980 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4982 pAC->WasIfUp[1] = SK_FALSE;
4985 pAC->BoardLevel = SK_INIT_DATA;
4990 /*****************************************************************************
4992 * SkDrvLeaveDiagMode - handles DIAG detach request
4995 * Notify the kernel to may access the card again after use by DIAG
4996 * Initialize the Card
5001 int SkDrvLeaveDiagMode(
5002 SK_AC *pAc) /* pointer to adapter control context */
5004 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
5005 sizeof(SK_PNMI_STRUCT_DATA));
5006 pAc->DiagModeActive = DIAG_NOTACTIVE;
5007 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
5008 if (pAc->WasIfUp[0] == SK_TRUE) {
5009 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
5010 DoPrintInterfaceChange = SK_FALSE;
5011 SkDrvInitAdapter(pAc, 0); /* first device */
5013 if (pAc->WasIfUp[1] == SK_TRUE) {
5014 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
5015 DoPrintInterfaceChange = SK_FALSE;
5016 SkDrvInitAdapter(pAc, 1); /* second device */
5021 /*****************************************************************************
5023 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
5026 * This function parses the PCI slot name information string and will
5027 * retrieve the devcie number out of it. The slot_name maintianed by
5028 * linux is in the form of '02:0a.0', whereas the first two characters
5029 * represent the bus number in hex (in the sample above this is
5030 * pci bus 0x02) and the next two characters the device number (0x0a).
5033 * SK_U32: The device number from the PCI slot name
5036 static SK_U32 ParseDeviceNbrFromSlotName(
5037 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
5039 char *CurrCharPos = (char *) SlotName;
5040 int FirstNibble = -1;
5041 int SecondNibble = -1;
5044 while (*CurrCharPos != '\0') {
5045 if (*CurrCharPos == ':') {
5046 while (*CurrCharPos != '.') {
5048 if ( (*CurrCharPos >= '0') &&
5049 (*CurrCharPos <= '9')) {
5050 if (FirstNibble == -1) {
5051 /* dec. value for '0' */
5052 FirstNibble = *CurrCharPos - 48;
5054 SecondNibble = *CurrCharPos - 48;
5056 } else if ( (*CurrCharPos >= 'a') &&
5057 (*CurrCharPos <= 'f') ) {
5058 if (FirstNibble == -1) {
5059 FirstNibble = *CurrCharPos - 87;
5061 SecondNibble = *CurrCharPos - 87;
5068 Result = FirstNibble;
5069 Result = Result << 4; /* first nibble is higher one */
5070 Result = Result | SecondNibble;
5072 CurrCharPos++; /* next character */
5077 /****************************************************************************
5079 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
5080 * called if Diag attaches to that card)
5083 * Close initialized adapter.
5087 * error code - on error
5089 static int SkDrvDeInitAdapter(
5090 SK_AC *pAC, /* pointer to adapter context */
5091 int devNbr) /* what device is to be handled */
5093 struct SK_NET_DEVICE *dev;
5095 dev = pAC->dev[devNbr];
5098 ** Function SkGeClose() uses MOD_DEC_USE_COUNT (2.2/2.4)
5099 ** or module_put() (2.6) to decrease the number of users for
5100 ** a device, but if a device is to be put under control of
5101 ** the DIAG, that count is OK already and does not need to
5102 ** be adapted! Hence the opposite MOD_INC_USE_COUNT or
5103 ** try_module_get() needs to be used again to correct that.
5105 if (!try_module_get(THIS_MODULE)) {
5109 if (SkGeClose(dev) != 0) {
5110 module_put(THIS_MODULE);
5115 } /* SkDrvDeInitAdapter() */
5117 /****************************************************************************
5119 * SkDrvInitAdapter - Initialize adapter (this function is only
5120 * called if Diag deattaches from that card)
5123 * Close initialized adapter.
5127 * error code - on error
5129 static int SkDrvInitAdapter(
5130 SK_AC *pAC, /* pointer to adapter context */
5131 int devNbr) /* what device is to be handled */
5133 struct SK_NET_DEVICE *dev;
5135 dev = pAC->dev[devNbr];
5137 if (SkGeOpen(dev) != 0) {
5141 ** Function SkGeOpen() uses MOD_INC_USE_COUNT (2.2/2.4)
5142 ** or try_module_get() (2.6) to increase the number of
5143 ** users for a device, but if a device was just under
5144 ** control of the DIAG, that count is OK already and
5145 ** does not need to be adapted! Hence the opposite
5146 ** MOD_DEC_USE_COUNT or module_put() needs to be used
5147 ** again to correct that.
5149 module_put(THIS_MODULE);
5153 ** Use correct MTU size and indicate to kernel TX queue can be started
5155 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
5160 } /* SkDrvInitAdapter */
5165 /****************************************************************************/
5166 /* "debug only" section *****************************************************/
5167 /****************************************************************************/
5170 /*****************************************************************************
5172 * DumpMsg - print a frame
5175 * This function prints frames to the system logfile/to the console.
5180 static void DumpMsg(struct sk_buff *skb, char *str)
5185 printk("DumpMsg(): NULL-Message\n");
5189 if (skb->data == NULL) {
5190 printk("DumpMsg(): Message empty\n");
5198 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
5200 DumpData((char *)skb->data, msglen);
5202 printk("------- End of message ---------\n");
5207 /*****************************************************************************
5209 * DumpData - print a data area
5212 * This function prints a area of data to the system logfile/to the
5218 static void DumpData(char *p, int size)
5222 char hex_buffer[180];
5223 char asc_buffer[180];
5224 char HEXCHAR[] = "0123456789ABCDEF";
5230 for (i=0; i < size; ) {
5231 if (*p >= '0' && *p <='z')
5232 asc_buffer[addr] = *p;
5234 asc_buffer[addr] = '.';
5236 asc_buffer[addr] = 0;
5237 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
5239 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
5241 hex_buffer[haddr] = ' ';
5243 hex_buffer[haddr] = 0;
5247 printk("%s %s\n", hex_buffer, asc_buffer);
5255 /*****************************************************************************
5257 * DumpLong - print a data area as long values
5260 * This function prints a area of data to the system logfile/to the
5266 static void DumpLong(char *pc, int size)
5270 char hex_buffer[180];
5271 char asc_buffer[180];
5272 char HEXCHAR[] = "0123456789ABCDEF";
5281 for (i=0; i < size; ) {
5283 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
5285 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
5287 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
5289 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
5291 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
5293 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
5295 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
5297 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
5299 hex_buffer[haddr] = ' ';
5301 hex_buffer[haddr] = 0;
5305 printk("%4x %s\n", (i-8)*4, hex_buffer);
5309 printk("------------------------\n");
5314 /*******************************************************************************
5318 ******************************************************************************/