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;
385 SET_NETDEV_DEV(dev, &pdev->dev);
388 #ifdef USE_SK_TX_CHECKSUM
390 if (pAC->ChipsetType) {
391 /* Use only if yukon hardware */
392 /* SK and ZEROCOPY - fly baby... */
393 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
398 pAC->Index = boards_found;
400 if (SkGeBoardInit(dev, pAC)) {
405 /* Register net device */
406 if (register_netdev(dev)) {
407 printk(KERN_ERR "SKGE: Could not register device.\n");
413 /* Print adapter specific string from vpd */
415 printk("%s: %s\n", dev->name, pAC->DeviceStr);
417 /* Print configuration settings */
418 printk(" PrefPort:%c RlmtMode:%s\n",
419 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
420 (pAC->RlmtMode==0) ? "Check Link State" :
421 ((pAC->RlmtMode==1) ? "Check Link State" :
422 ((pAC->RlmtMode==3) ? "Check Local Port" :
423 ((pAC->RlmtMode==7) ? "Check Segmentation" :
424 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
426 SkGeYellowLED(pAC, pAC->IoBase, 1);
429 memcpy((caddr_t) &dev->dev_addr,
430 (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
432 /* First adapter... Create proc and print message */
433 #ifdef CONFIG_PROC_FS
435 DeviceFound = SK_TRUE;
436 SK_MEMCPY(&SK_Root_Dir_entry, BootString,
437 sizeof(SK_Root_Dir_entry) - 1);
439 /*Create proc (directory)*/
441 pSkRootDir = proc_mkdir(SK_Root_Dir_entry, proc_net);
443 printk(KERN_WARNING "%s: Unable to create /proc/net/%s",
444 dev->name, SK_Root_Dir_entry);
446 pSkRootDir->owner = THIS_MODULE;
451 /* Create proc file */
453 (pProcFile = create_proc_entry(dev->name, S_IRUGO,
455 pProcFile->proc_fops = &sk_proc_fops;
456 pProcFile->data = dev;
466 /* More then one port found */
467 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
468 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
469 printk(KERN_ERR "Unable to allocate etherdev "
482 dev->open = &SkGeOpen;
483 dev->stop = &SkGeClose;
484 dev->hard_start_xmit = &SkGeXmit;
485 dev->get_stats = &SkGeStats;
486 dev->last_stats = &SkGeStats;
487 dev->set_multicast_list = &SkGeSetRxMode;
488 dev->set_mac_address = &SkGeSetMacAddr;
489 dev->do_ioctl = &SkGeIoctl;
490 dev->change_mtu = &SkGeChangeMtu;
491 dev->flags &= ~IFF_RUNNING;
494 #ifdef USE_SK_TX_CHECKSUM
495 if (pAC->ChipsetType) {
496 /* SG and ZEROCOPY - fly baby... */
497 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
502 if (register_netdev(dev)) {
503 printk(KERN_ERR "SKGE: Could not register device.\n");
505 pAC->dev[1] = pAC->dev[0];
507 #ifdef CONFIG_PROC_FS
509 && (pProcFile = create_proc_entry(dev->name,
510 S_IRUGO, pSkRootDir))) {
511 pProcFile->proc_fops = &sk_proc_fops;
512 pProcFile->data = dev;
516 memcpy((caddr_t) &dev->dev_addr,
517 (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
519 printk("%s: %s\n", dev->name, pAC->DeviceStr);
520 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
524 /* Save the hardware revision */
525 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
526 (pAC->GIni.GIPciHwRev & 0x0F);
528 /* Set driver globals */
529 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
530 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
532 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
533 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
534 sizeof(SK_PNMI_STRUCT_DATA));
537 * This is bollocks, but we need to tell the net-init
538 * code that it shall go for the next device.
546 * If we're at this point we're going through skge_probe() for
547 * the first time. Return success (0) if we've initialized 1
548 * or more boards. Otherwise, return failure (-ENODEV).
555 /*****************************************************************************
557 * SkGeInitPCI - Init the PCI resources
560 * This function initialize the PCI resources and IO
565 int SkGeInitPCI(SK_AC *pAC)
567 struct SK_NET_DEVICE *dev = pAC->dev[0];
568 struct pci_dev *pdev = pAC->PciDev;
571 if (pci_enable_device(pdev) != 0) {
575 dev->mem_start = pci_resource_start (pdev, 0);
576 pci_set_master(pdev);
578 if (pci_request_regions(pdev, pAC->Name) != 0) {
585 * On big endian machines, we use the adapter's aibility of
586 * reading the descriptors as big endian.
590 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
591 our2 |= PCI_REV_DESC;
592 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
597 * Remap the regs into kernel space.
599 pAC->IoBase = (char*)ioremap_nocache(dev->mem_start, 0x4000);
609 pci_release_regions(pdev);
611 pci_disable_device(pdev);
616 /*****************************************************************************
618 * FreeResources - release resources allocated for adapter
621 * This function releases the IRQ, unmaps the IO and
622 * frees the desriptor ring.
627 static void FreeResources(struct SK_NET_DEVICE *dev)
634 pNet = (DEV_NET*) dev->priv;
636 AllocFlag = pAC->AllocFlag;
638 pci_release_regions(pAC->PciDev);
640 if (AllocFlag & SK_ALLOC_IRQ) {
641 free_irq(dev->irq, dev);
644 iounmap(pAC->IoBase);
646 if (pAC->pDescrMem) {
651 } /* FreeResources */
653 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
654 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
655 MODULE_LICENSE("GPL");
656 MODULE_PARM(Speed_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
657 MODULE_PARM(Speed_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
658 MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
659 MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
660 MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
661 MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
662 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
663 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
664 MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
665 MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
666 MODULE_PARM(ConType, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
667 MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
668 MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
669 /* not used, just there because every driver should have them: */
670 MODULE_PARM(options, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
671 MODULE_PARM(debug, "i");
672 /* used for interrupt moderation */
673 MODULE_PARM(IntsPerSec, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
674 MODULE_PARM(Moderation, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
675 MODULE_PARM(Stats, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
676 MODULE_PARM(ModerationMask, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
677 MODULE_PARM(AutoSizing, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
681 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
683 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
687 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
689 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
693 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
695 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
699 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
701 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
705 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
707 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
711 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
713 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
717 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
719 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
723 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
725 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
729 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
731 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
735 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
737 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
741 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
743 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
747 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
749 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
753 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
755 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
758 static int debug = 0; /* not used */
759 static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
761 static int IntsPerSec[SK_MAX_CARD_PARAM];
762 static char *Moderation[SK_MAX_CARD_PARAM];
763 static char *ModerationMask[SK_MAX_CARD_PARAM];
764 static char *AutoSizing[SK_MAX_CARD_PARAM];
765 static char *Stats[SK_MAX_CARD_PARAM];
768 /*****************************************************************************
770 * skge_init_module - module initialization function
773 * Very simple, only call skge_probe and return approriate result.
776 * 0, if everything is ok
779 static int __init skge_init_module(void)
784 /* just to avoid warnings ... */
788 cards = skge_probe();
790 printk("sk98lin: No adapter found.\n");
792 return cards ? 0 : -ENODEV;
793 } /* skge_init_module */
796 /*****************************************************************************
798 * skge_cleanup_module - module unload function
801 * Disable adapter if it is still running, free resources,
802 * free device struct.
806 static void __exit skge_cleanup_module(void)
810 struct SK_NET_DEVICE *next;
814 while (SkGeRootDev) {
815 pNet = (DEV_NET*) SkGeRootDev->priv;
819 netif_stop_queue(SkGeRootDev);
820 SkGeYellowLED(pAC, pAC->IoBase, 0);
822 if(pAC->BoardLevel == SK_INIT_RUN) {
823 /* board is still alive */
824 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
825 EvPara.Para32[0] = 0;
826 EvPara.Para32[1] = -1;
827 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
828 EvPara.Para32[0] = 1;
829 EvPara.Para32[1] = -1;
830 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
831 SkEventDispatcher(pAC, pAC->IoBase);
832 /* disable interrupts */
833 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
834 SkGeDeInit(pAC, pAC->IoBase);
835 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
836 pAC->BoardLevel = SK_INIT_DATA;
837 /* We do NOT check here, if IRQ was pending, of course*/
840 if(pAC->BoardLevel == SK_INIT_IO) {
841 /* board is still alive */
842 SkGeDeInit(pAC, pAC->IoBase);
843 pAC->BoardLevel = SK_INIT_DATA;
846 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
847 unregister_netdev(pAC->dev[1]);
848 free_netdev(pAC->dev[1]);
851 FreeResources(SkGeRootDev);
853 SkGeRootDev->get_stats = NULL;
855 * otherwise unregister_netdev calls get_stats with
858 unregister_netdev(SkGeRootDev);
859 free_netdev(SkGeRootDev);
864 #ifdef CONFIG_PROC_FS
866 remove_proc_entry(pSkRootDir->name, proc_net);
869 } /* skge_cleanup_module */
871 module_init(skge_init_module);
872 module_exit(skge_cleanup_module);
875 /*****************************************************************************
877 * SkGeBoardInit - do level 0 and 1 initialization
880 * This function prepares the board hardware for running. The desriptor
881 * ring is set up, the IRQ is allocated and the configuration settings
885 * 0, if everything is ok
888 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
892 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
893 char *VerStr = VER_STRING;
894 int Ret; /* return code of request_irq */
897 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
898 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
899 for (i=0; i<SK_MAX_MACS; i++) {
900 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
901 pAC->TxPort[i][0].PortIndex = i;
902 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
903 pAC->RxPort[i].PortIndex = i;
906 /* Initialize the mutexes */
907 for (i=0; i<SK_MAX_MACS; i++) {
908 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
909 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
911 spin_lock_init(&pAC->SlowPathLock);
913 /* level 0 init common modules here */
915 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
916 /* Does a RESET on board ...*/
917 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
918 printk("HWInit (0) failed.\n");
919 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
922 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
923 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
924 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
925 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
926 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
927 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
929 pAC->BoardLevel = SK_INIT_DATA;
930 pAC->RxBufSize = ETH_BUF_SIZE;
932 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
933 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
935 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
937 /* level 1 init common modules here (HW init) */
938 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
939 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
940 printk("sk98lin: HWInit (1) failed.\n");
941 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
944 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
945 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
946 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
947 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
948 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
949 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
951 /* Set chipset type support */
952 pAC->ChipsetType = 0;
953 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
954 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
955 pAC->ChipsetType = 1;
958 GetConfiguration(pAC);
959 if (pAC->RlmtNets == 2) {
960 pAC->GIni.GIPortUsage = SK_MUL_LINK;
963 pAC->BoardLevel = SK_INIT_IO;
964 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
966 if (pAC->GIni.GIMacsFound == 2) {
967 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
968 } else if (pAC->GIni.GIMacsFound == 1) {
969 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
972 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
973 pAC->GIni.GIMacsFound);
978 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
982 pAC->AllocFlag |= SK_ALLOC_IRQ;
984 /* Alloc memory for this board (Mem for RxD/TxD) : */
985 if(!BoardAllocMem(pAC)) {
986 printk("No memory for descriptor rings.\n");
990 SkCsSetReceiveFlags(pAC,
991 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
992 &pAC->CsOfs1, &pAC->CsOfs2, 0);
993 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
996 /* tschilling: New common function with minimum size check. */
998 if (pAC->RlmtNets == 2) {
1002 if (SkGeInitAssignRamToQueues(
1007 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
1012 * Register the device here
1014 pAC->Next = SkGeRootDev;
1018 } /* SkGeBoardInit */
1021 /*****************************************************************************
1023 * BoardAllocMem - allocate the memory for the descriptor rings
1026 * This function allocates the memory for all descriptor rings.
1027 * Each ring is aligned for the desriptor alignment and no ring
1028 * has a 4 GByte boundary in it (because the upper 32 bit must
1029 * be constant for all descriptiors in one rings).
1032 * SK_TRUE, if all memory could be allocated
1035 static SK_BOOL BoardAllocMem(
1038 caddr_t pDescrMem; /* pointer to descriptor memory area */
1039 size_t AllocLength; /* length of complete descriptor area */
1040 int i; /* loop counter */
1041 unsigned long BusAddr;
1044 /* rings plus one for alignment (do not cross 4 GB boundary) */
1045 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
1046 #if (BITS_PER_LONG == 32)
1047 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1049 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1053 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
1054 &pAC->pDescrMemDMA);
1056 if (pDescrMem == NULL) {
1059 pAC->pDescrMem = pDescrMem;
1060 BusAddr = (unsigned long) pAC->pDescrMemDMA;
1062 /* Descriptors need 8 byte alignment, and this is ensured
1063 * by pci_alloc_consistent.
1065 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1066 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1067 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
1068 i, (unsigned long) pDescrMem,
1070 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
1071 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
1072 pDescrMem += TX_RING_SIZE;
1073 BusAddr += TX_RING_SIZE;
1075 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1076 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
1077 i, (unsigned long) pDescrMem,
1078 (unsigned long)BusAddr));
1079 pAC->RxPort[i].pRxDescrRing = pDescrMem;
1080 pAC->RxPort[i].VRxDescrRing = BusAddr;
1081 pDescrMem += RX_RING_SIZE;
1082 BusAddr += RX_RING_SIZE;
1086 } /* BoardAllocMem */
1089 /****************************************************************************
1091 * BoardFreeMem - reverse of BoardAllocMem
1094 * Free all memory allocated in BoardAllocMem: adapter context,
1095 * descriptor rings, locks.
1099 static void BoardFreeMem(
1102 size_t AllocLength; /* length of complete descriptor area */
1104 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1105 ("BoardFreeMem\n"));
1106 #if (BITS_PER_LONG == 32)
1107 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1109 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1113 pci_free_consistent(pAC->PciDev, AllocLength,
1114 pAC->pDescrMem, pAC->pDescrMemDMA);
1115 pAC->pDescrMem = NULL;
1116 } /* BoardFreeMem */
1119 /*****************************************************************************
1121 * BoardInitMem - initiate the descriptor rings
1124 * This function sets the descriptor rings up in memory.
1125 * The adapter is initialized with the descriptor start addresses.
1129 static void BoardInitMem(
1130 SK_AC *pAC) /* pointer to adapter context */
1132 int i; /* loop counter */
1133 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
1134 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
1136 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1137 ("BoardInitMem\n"));
1139 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1140 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
1141 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1142 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
1144 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1147 pAC->TxPort[i][0].pTxDescrRing,
1148 pAC->TxPort[i][0].VTxDescrRing,
1149 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
1150 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
1151 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
1152 &pAC->TxPort[i][0].TxdRingFree,
1156 pAC->RxPort[i].pRxDescrRing,
1157 pAC->RxPort[i].VRxDescrRing,
1158 &pAC->RxPort[i].pRxdRingHead,
1159 &pAC->RxPort[i].pRxdRingTail,
1160 &pAC->RxPort[i].pRxdRingPrev,
1161 &pAC->RxPort[i].RxdRingFree,
1164 } /* BoardInitMem */
1167 /*****************************************************************************
1169 * SetupRing - create one descriptor ring
1172 * This function creates one descriptor ring in the given memory area.
1173 * The head, tail and number of free descriptors in the ring are set.
1178 static void SetupRing(
1180 void *pMemArea, /* a pointer to the memory area for the ring */
1181 uintptr_t VMemArea, /* the virtual bus address of the memory area */
1182 RXD **ppRingHead, /* address where the head should be written */
1183 RXD **ppRingTail, /* address where the tail should be written */
1184 RXD **ppRingPrev, /* address where the tail should be written */
1185 int *pRingFree, /* address where the # of free descr. goes */
1186 SK_BOOL IsTx) /* flag: is this a tx ring */
1188 int i; /* loop counter */
1189 int DescrSize; /* the size of a descriptor rounded up to alignment*/
1190 int DescrNum; /* number of descriptors per ring */
1191 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
1192 RXD *pNextDescr; /* pointer to the next descriptor */
1193 RXD *pPrevDescr; /* pointer to the previous descriptor */
1194 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
1196 if (IsTx == SK_TRUE) {
1197 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
1199 DescrNum = TX_RING_SIZE / DescrSize;
1201 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1203 DescrNum = RX_RING_SIZE / DescrSize;
1206 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1207 ("Descriptor size: %d Descriptor Number: %d\n",
1208 DescrSize,DescrNum));
1210 pDescr = (RXD*) pMemArea;
1212 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1213 VNextDescr = VMemArea + DescrSize;
1214 for(i=0; i<DescrNum; i++) {
1215 /* set the pointers right */
1216 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1217 pDescr->pNextRxd = pNextDescr;
1218 pDescr->TcpSumStarts = pAC->CsOfs;
1220 /* advance one step */
1221 pPrevDescr = pDescr;
1222 pDescr = pNextDescr;
1223 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1224 VNextDescr += DescrSize;
1226 pPrevDescr->pNextRxd = (RXD*) pMemArea;
1227 pPrevDescr->VNextRxd = VMemArea;
1228 pDescr = (RXD*) pMemArea;
1229 *ppRingHead = (RXD*) pMemArea;
1230 *ppRingTail = *ppRingHead;
1231 *ppRingPrev = pPrevDescr;
1232 *pRingFree = DescrNum;
1236 /*****************************************************************************
1238 * PortReInitBmu - re-initiate the descriptor rings for one port
1241 * This function reinitializes the descriptor rings of one port
1242 * in memory. The port must be stopped before.
1243 * The HW is initialized with the descriptor start addresses.
1248 static void PortReInitBmu(
1249 SK_AC *pAC, /* pointer to adapter context */
1250 int PortIndex) /* index of the port for which to re-init */
1252 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1253 ("PortReInitBmu "));
1255 /* set address of first descriptor of ring in BMU */
1256 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
1257 (uint32_t)(((caddr_t)
1258 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1259 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1260 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1262 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
1263 (uint32_t)(((caddr_t)
1264 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1265 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1266 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1267 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
1268 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1269 pAC->RxPort[PortIndex].pRxDescrRing +
1270 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1271 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
1272 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1273 pAC->RxPort[PortIndex].pRxDescrRing +
1274 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1275 } /* PortReInitBmu */
1278 /****************************************************************************
1280 * SkGeIsr - handle adapter interrupts
1283 * The interrupt routine is called when the network adapter
1284 * generates an interrupt. It may also be called if another device
1285 * shares this interrupt vector with the driver.
1290 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1292 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1295 SK_U32 IntSrc; /* interrupts source register contents */
1297 pNet = (DEV_NET*) dev->priv;
1301 * Check and process if its our interrupt
1303 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1305 return SkIsrRetNone;
1308 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1309 #if 0 /* software irq currently not used */
1310 if (IntSrc & IS_IRQ_SW) {
1311 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1312 SK_DBGCAT_DRV_INT_SRC,
1313 ("Software IRQ\n"));
1316 if (IntSrc & IS_R1_F) {
1317 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1318 SK_DBGCAT_DRV_INT_SRC,
1320 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1321 SK_PNMI_CNT_RX_INTR(pAC, 0);
1323 if (IntSrc & IS_R2_F) {
1324 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1325 SK_DBGCAT_DRV_INT_SRC,
1327 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1328 SK_PNMI_CNT_RX_INTR(pAC, 1);
1330 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1331 if (IntSrc & IS_XA1_F) {
1332 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1333 SK_DBGCAT_DRV_INT_SRC,
1334 ("EOF AS TX1 IRQ\n"));
1335 SK_PNMI_CNT_TX_INTR(pAC, 0);
1336 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1337 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1338 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1340 if (IntSrc & IS_XA2_F) {
1341 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1342 SK_DBGCAT_DRV_INT_SRC,
1343 ("EOF AS TX2 IRQ\n"));
1344 SK_PNMI_CNT_TX_INTR(pAC, 1);
1345 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1346 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1347 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1349 #if 0 /* only if sync. queues used */
1350 if (IntSrc & IS_XS1_F) {
1351 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1352 SK_DBGCAT_DRV_INT_SRC,
1353 ("EOF SY TX1 IRQ\n"));
1354 SK_PNMI_CNT_TX_INTR(pAC, 1);
1355 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1356 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1357 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1358 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1360 if (IntSrc & IS_XS2_F) {
1361 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1362 SK_DBGCAT_DRV_INT_SRC,
1363 ("EOF SY TX2 IRQ\n"));
1364 SK_PNMI_CNT_TX_INTR(pAC, 1);
1365 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1366 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1367 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1368 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1373 /* do all IO at once */
1374 if (IntSrc & IS_R1_F)
1375 ClearAndStartRx(pAC, 0);
1376 if (IntSrc & IS_R2_F)
1377 ClearAndStartRx(pAC, 1);
1378 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1379 if (IntSrc & IS_XA1_F)
1380 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1381 if (IntSrc & IS_XA2_F)
1382 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1384 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1385 } /* while (IntSrc & IRQ_MASK != 0) */
1387 IntSrc &= pAC->GIni.GIValIrqMask;
1388 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1389 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1390 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1391 pAC->CheckQueue = SK_FALSE;
1392 spin_lock(&pAC->SlowPathLock);
1393 if (IntSrc & SPECIAL_IRQS)
1394 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1396 SkEventDispatcher(pAC, pAC->IoBase);
1397 spin_unlock(&pAC->SlowPathLock);
1400 * do it all again is case we cleared an interrupt that
1401 * came in after handling the ring (OUTs may be delayed
1402 * in hardware buffers, but are through after IN)
1404 * rroesler: has been commented out and shifted to
1405 * SkGeDrvEvent(), because it is timer
1408 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1409 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1412 if (pAC->CheckQueue) {
1413 pAC->CheckQueue = SK_FALSE;
1414 spin_lock(&pAC->SlowPathLock);
1415 SkEventDispatcher(pAC, pAC->IoBase);
1416 spin_unlock(&pAC->SlowPathLock);
1419 /* IRQ is processed - Enable IRQs again*/
1420 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1422 return SkIsrRetHandled;
1426 /****************************************************************************
1428 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1431 * The interrupt routine is called when the network adapter
1432 * generates an interrupt. It may also be called if another device
1433 * shares this interrupt vector with the driver.
1434 * This is the same as above, but handles only one port.
1439 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1441 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1444 SK_U32 IntSrc; /* interrupts source register contents */
1446 pNet = (DEV_NET*) dev->priv;
1450 * Check and process if its our interrupt
1452 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1454 return SkIsrRetNone;
1457 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1458 #if 0 /* software irq currently not used */
1459 if (IntSrc & IS_IRQ_SW) {
1460 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1461 SK_DBGCAT_DRV_INT_SRC,
1462 ("Software IRQ\n"));
1465 if (IntSrc & IS_R1_F) {
1466 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1467 SK_DBGCAT_DRV_INT_SRC,
1469 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1470 SK_PNMI_CNT_RX_INTR(pAC, 0);
1472 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1473 if (IntSrc & IS_XA1_F) {
1474 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1475 SK_DBGCAT_DRV_INT_SRC,
1476 ("EOF AS TX1 IRQ\n"));
1477 SK_PNMI_CNT_TX_INTR(pAC, 0);
1478 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1479 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1480 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1482 #if 0 /* only if sync. queues used */
1483 if (IntSrc & IS_XS1_F) {
1484 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1485 SK_DBGCAT_DRV_INT_SRC,
1486 ("EOF SY TX1 IRQ\n"));
1487 SK_PNMI_CNT_TX_INTR(pAC, 0);
1488 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1489 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1490 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1491 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1496 /* do all IO at once */
1497 if (IntSrc & IS_R1_F)
1498 ClearAndStartRx(pAC, 0);
1499 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1500 if (IntSrc & IS_XA1_F)
1501 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1503 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1504 } /* while (IntSrc & IRQ_MASK != 0) */
1506 IntSrc &= pAC->GIni.GIValIrqMask;
1507 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1509 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1510 pAC->CheckQueue = SK_FALSE;
1511 spin_lock(&pAC->SlowPathLock);
1512 if (IntSrc & SPECIAL_IRQS)
1513 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1515 SkEventDispatcher(pAC, pAC->IoBase);
1516 spin_unlock(&pAC->SlowPathLock);
1519 * do it all again is case we cleared an interrupt that
1520 * came in after handling the ring (OUTs may be delayed
1521 * in hardware buffers, but are through after IN)
1523 * rroesler: has been commented out and shifted to
1524 * SkGeDrvEvent(), because it is timer
1527 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1530 /* IRQ is processed - Enable IRQs again*/
1531 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1533 return SkIsrRetHandled;
1534 } /* SkGeIsrOnePort */
1537 /****************************************************************************
1539 * SkGeOpen - handle start of initialized adapter
1542 * This function starts the initialized adapter.
1543 * The board level variable is set and the adapter is
1544 * brought to full functionality.
1545 * The device flags are set for operation.
1546 * Do all necessary level 2 initialization, enable interrupts and
1547 * give start command to RLMT.
1553 static int SkGeOpen(
1554 struct SK_NET_DEVICE *dev)
1558 unsigned long Flags; /* for spin lock */
1560 SK_EVPARA EvPara; /* an event parameter union */
1562 pNet = (DEV_NET*) dev->priv;
1565 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1566 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1568 #ifdef SK_DIAG_SUPPORT
1569 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1570 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1571 return (-1); /* still in use by diag; deny actions */
1576 if (!try_module_get(THIS_MODULE)) {
1577 return (-1); /* increase of usage count not possible */
1580 /* Set blink mode */
1581 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1582 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1584 if (pAC->BoardLevel == SK_INIT_DATA) {
1585 /* level 1 init common modules here */
1586 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1587 module_put(THIS_MODULE); /* decrease usage count */
1588 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1591 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1592 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1593 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1594 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1595 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1596 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1597 pAC->BoardLevel = SK_INIT_IO;
1600 if (pAC->BoardLevel != SK_INIT_RUN) {
1601 /* tschilling: Level 2 init modules here, check return value. */
1602 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1603 module_put(THIS_MODULE); /* decrease usage count */
1604 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1607 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1608 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1609 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1610 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1611 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1612 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1613 pAC->BoardLevel = SK_INIT_RUN;
1616 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1617 /* Enable transmit descriptor polling. */
1618 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1619 FillRxRing(pAC, &pAC->RxPort[i]);
1621 SkGeYellowLED(pAC, pAC->IoBase, 1);
1623 StartDrvCleanupTimer(pAC);
1624 SkDimEnableModerationIfNeeded(pAC);
1625 SkDimDisplayModerationSettings(pAC);
1627 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1629 /* enable Interrupts */
1630 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1631 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1633 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1635 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1636 EvPara.Para32[0] = pAC->RlmtNets;
1637 EvPara.Para32[1] = -1;
1638 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1640 EvPara.Para32[0] = pAC->RlmtMode;
1641 EvPara.Para32[1] = 0;
1642 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1646 EvPara.Para32[0] = pNet->NetNr;
1647 EvPara.Para32[1] = -1;
1648 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1649 SkEventDispatcher(pAC, pAC->IoBase);
1650 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1656 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1657 ("SkGeOpen suceeded\n"));
1663 /****************************************************************************
1665 * SkGeClose - Stop initialized adapter
1668 * Close initialized adapter.
1672 * error code - on error
1674 static int SkGeClose(
1675 struct SK_NET_DEVICE *dev)
1681 unsigned long Flags; /* for spin lock */
1686 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1687 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1689 pNet = (DEV_NET*) dev->priv;
1692 #ifdef SK_DIAG_SUPPORT
1693 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1694 if (pAC->DiagFlowCtrl == SK_FALSE) {
1695 module_put(THIS_MODULE);
1697 ** notify that the interface which has been closed
1698 ** by operator interaction must not be started up
1699 ** again when the DIAG has finished.
1701 newPtrNet = (DEV_NET *) pAC->dev[0]->priv;
1702 if (newPtrNet == pNet) {
1703 pAC->WasIfUp[0] = SK_FALSE;
1705 pAC->WasIfUp[1] = SK_FALSE;
1707 return 0; /* return to system everything is fine... */
1709 pAC->DiagFlowCtrl = SK_FALSE;
1714 netif_stop_queue(dev);
1716 if (pAC->RlmtNets == 1)
1717 PortIdx = pAC->ActivePort;
1719 PortIdx = pNet->NetNr;
1721 StopDrvCleanupTimer(pAC);
1724 * Clear multicast table, promiscuous mode ....
1726 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1727 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1730 if (pAC->MaxPorts == 1) {
1731 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1732 /* disable interrupts */
1733 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1734 EvPara.Para32[0] = pNet->NetNr;
1735 EvPara.Para32[1] = -1;
1736 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1737 SkEventDispatcher(pAC, pAC->IoBase);
1738 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1739 /* stop the hardware */
1740 SkGeDeInit(pAC, pAC->IoBase);
1741 pAC->BoardLevel = SK_INIT_DATA;
1742 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1745 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1746 EvPara.Para32[0] = pNet->NetNr;
1747 EvPara.Para32[1] = -1;
1748 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1749 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1750 SkEventDispatcher(pAC, pAC->IoBase);
1751 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1754 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1755 [TX_PRIO_LOW].TxDesRingLock, Flags);
1756 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1757 SK_STOP_ALL, SK_HARD_RST);
1758 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1759 [TX_PRIO_LOW].TxDesRingLock, Flags);
1762 if (pAC->RlmtNets == 1) {
1763 /* clear all descriptor rings */
1764 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1765 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1766 ClearRxRing(pAC, &pAC->RxPort[i]);
1767 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1770 /* clear port descriptor rings */
1771 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1772 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1773 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1776 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1777 ("SkGeClose: done "));
1779 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1780 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1781 sizeof(SK_PNMI_STRUCT_DATA));
1786 module_put(THIS_MODULE);
1791 /*****************************************************************************
1793 * SkGeXmit - Linux frame transmit function
1796 * The system calls this function to send frames onto the wire.
1797 * It puts the frame in the tx descriptor ring. If the ring is
1798 * full then, the 'tbusy' flag is set.
1801 * 0, if everything is ok
1803 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1804 * allocated skb's) !!!
1806 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1810 int Rc; /* return code of XmitFrame */
1812 pNet = (DEV_NET*) dev->priv;
1815 if ((!skb_shinfo(skb)->nr_frags) ||
1816 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1817 /* Don't activate scatter-gather and hardware checksum */
1819 if (pAC->RlmtNets == 2)
1822 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1827 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1830 /* scatter-gather and hardware TCP checksumming anabled*/
1831 if (pAC->RlmtNets == 2)
1834 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1839 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1843 /* Transmitter out of resources? */
1845 netif_stop_queue(dev);
1848 /* If not taken, give buffer ownership back to the
1854 dev->trans_start = jiffies;
1859 /*****************************************************************************
1861 * XmitFrame - fill one socket buffer into the transmit ring
1864 * This function puts a message into the transmit descriptor ring
1865 * if there is a descriptors left.
1866 * Linux skb's consist of only one continuous buffer.
1867 * The first step locks the ring. It is held locked
1868 * all time to avoid problems with SWITCH_../PORT_RESET.
1869 * Then the descriptoris allocated.
1870 * The second part is linking the buffer to the descriptor.
1871 * At the very last, the Control field of the descriptor
1872 * is made valid for the BMU and a start TX command is given
1876 * > 0 - on succes: the number of bytes in the message
1877 * = 0 - on resource shortage: this frame sent or dropped, now
1878 * the ring is full ( -> set tbusy)
1879 * < 0 - on failure: other problems ( -> return failure to upper layers)
1881 static int XmitFrame(
1882 SK_AC *pAC, /* pointer to adapter context */
1883 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1884 struct sk_buff *pMessage) /* pointer to send-message */
1886 TXD *pTxd; /* the rxd to fill */
1888 unsigned long Flags;
1892 int BytesSend = pMessage->len;
1894 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1896 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1897 #ifndef USE_TX_COMPLETE
1898 FreeTxDescriptors(pAC, pTxPort);
1900 if (pTxPort->TxdRingFree == 0) {
1902 ** no enough free descriptors in ring at the moment.
1903 ** Maybe free'ing some old one help?
1905 FreeTxDescriptors(pAC, pTxPort);
1906 if (pTxPort->TxdRingFree == 0) {
1907 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1908 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1909 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1910 SK_DBGCAT_DRV_TX_PROGRESS,
1911 ("XmitFrame failed\n"));
1913 ** the desired message can not be sent
1914 ** Because tbusy seems to be set, the message
1915 ** should not be freed here. It will be used
1916 ** by the scheduler of the ethernet handler
1923 ** If the passed socket buffer is of smaller MTU-size than 60,
1924 ** copy everything into new buffer and fill all bytes between
1925 ** the original packet end and the new packet end of 60 with 0x00.
1926 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1928 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1929 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1930 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1933 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1937 ** advance head counter behind descriptor needed for this frame,
1938 ** so that needed descriptor is reserved from that on. The next
1939 ** action will be to add the passed buffer to the TX-descriptor
1941 pTxd = pTxPort->pTxdRingHead;
1942 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1943 pTxPort->TxdRingFree--;
1946 DumpMsg(pMessage, "XmitFrame");
1950 ** First step is to map the data to be sent via the adapter onto
1951 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1952 ** and 2.6 need to use pci_map_page() for that mapping.
1954 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1955 virt_to_page(pMessage->data),
1956 ((unsigned long) pMessage->data & ~PAGE_MASK),
1959 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1960 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1961 pTxd->pMBuf = pMessage;
1963 if (pMessage->ip_summed == CHECKSUM_HW) {
1964 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1965 if ((Protocol == C_PROTO_ID_UDP) &&
1966 (pAC->GIni.GIChipRev == 0) &&
1967 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1968 pTxd->TBControl = BMU_TCP_CHECK;
1970 pTxd->TBControl = BMU_UDP_CHECK;
1973 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1974 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1975 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1976 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1977 (Protocol == C_PROTO_ID_UDP ?
1978 C_OFFSET_UDPHEADER_UDPCS :
1979 C_OFFSET_TCPHEADER_TCPCS);
1980 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1982 pTxd->TBControl |= BMU_OWN | BMU_STF |
1984 #ifdef USE_TX_COMPLETE
1989 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1991 #ifdef USE_TX_COMPLETE
1998 ** If previous descriptor already done, give TX start cmd
2000 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
2001 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
2002 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
2006 ** after releasing the lock, the skb may immediately be free'd
2008 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2009 if (pTxPort->TxdRingFree != 0) {
2017 /*****************************************************************************
2019 * XmitFrameSG - fill one socket buffer into the transmit ring
2020 * (use SG and TCP/UDP hardware checksumming)
2023 * This function puts a message into the transmit descriptor ring
2024 * if there is a descriptors left.
2027 * > 0 - on succes: the number of bytes in the message
2028 * = 0 - on resource shortage: this frame sent or dropped, now
2029 * the ring is full ( -> set tbusy)
2030 * < 0 - on failure: other problems ( -> return failure to upper layers)
2032 static int XmitFrameSG(
2033 SK_AC *pAC, /* pointer to adapter context */
2034 TX_PORT *pTxPort, /* pointer to struct of port to send to */
2035 struct sk_buff *pMessage) /* pointer to send-message */
2045 skb_frag_t *sk_frag;
2047 unsigned long Flags;
2049 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2050 #ifndef USE_TX_COMPLETE
2051 FreeTxDescriptors(pAC, pTxPort);
2053 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
2054 FreeTxDescriptors(pAC, pTxPort);
2055 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
2056 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2057 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
2058 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2059 SK_DBGCAT_DRV_TX_PROGRESS,
2060 ("XmitFrameSG failed - Ring full\n"));
2061 /* this message can not be sent now */
2066 pTxd = pTxPort->pTxdRingHead;
2073 ** Map the first fragment (header) into the DMA-space
2075 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2076 virt_to_page(pMessage->data),
2077 ((unsigned long) pMessage->data & ~PAGE_MASK),
2078 skb_headlen(pMessage),
2081 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2082 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2085 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2087 if (pMessage->ip_summed == CHECKSUM_HW) {
2088 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
2090 ** We have to use the opcode for tcp here, because the
2091 ** opcode for udp is not working in the hardware yet
2094 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
2095 if ((Protocol == C_PROTO_ID_UDP) &&
2096 (pAC->GIni.GIChipRev == 0) &&
2097 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2098 pTxd->TBControl |= BMU_TCP_CHECK;
2100 pTxd->TBControl |= BMU_UDP_CHECK;
2103 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
2104 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
2105 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
2106 (Protocol == C_PROTO_ID_UDP ?
2107 C_OFFSET_UDPHEADER_UDPCS :
2108 C_OFFSET_TCPHEADER_TCPCS);
2109 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
2111 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
2112 skb_headlen(pMessage);
2115 pTxd = pTxd->pNextTxd;
2116 pTxPort->TxdRingFree--;
2117 BytesSend += skb_headlen(pMessage);
2120 ** Browse over all SG fragments and map each of them into the DMA space
2122 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
2123 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
2125 ** we already have the proper value in entry
2127 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2129 sk_frag->page_offset,
2133 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2134 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2135 pTxd->pMBuf = pMessage;
2138 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2140 if (pMessage->ip_summed == CHECKSUM_HW) {
2141 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
2143 ** We have to use the opcode for tcp here because the
2144 ** opcode for udp is not working in the hardware yet
2147 if ((Protocol == C_PROTO_ID_UDP) &&
2148 (pAC->GIni.GIChipRev == 0) &&
2149 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2150 pTxd->TBControl |= BMU_TCP_CHECK;
2152 pTxd->TBControl |= BMU_UDP_CHECK;
2155 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
2159 ** Do we have the last fragment?
2161 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
2162 #ifdef USE_TX_COMPLETE
2163 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
2165 pTxd->TBControl |= BMU_EOF | sk_frag->size;
2167 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
2170 pTxd->TBControl |= sk_frag->size;
2173 pTxd = pTxd->pNextTxd;
2174 pTxPort->TxdRingFree--;
2175 BytesSend += sk_frag->size;
2179 ** If previous descriptor already done, give TX start cmd
2181 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
2182 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
2185 pTxPort->pTxdRingPrev = pTxdLst;
2186 pTxPort->pTxdRingHead = pTxd;
2188 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2190 if (pTxPort->TxdRingFree > 0) {
2197 /*****************************************************************************
2199 * FreeTxDescriptors - release descriptors from the descriptor ring
2202 * This function releases descriptors from a transmit ring if they
2203 * have been sent by the BMU.
2204 * If a descriptors is sent, it can be freed and the message can
2206 * The SOFTWARE controllable bit is used to prevent running around a
2207 * completely free ring for ever. If this bit is no set in the
2208 * frame (by XmitFrame), this frame has never been sent or is
2210 * The Tx descriptor ring lock must be held while calling this function !!!
2215 static void FreeTxDescriptors(
2216 SK_AC *pAC, /* pointer to the adapter context */
2217 TX_PORT *pTxPort) /* pointer to destination port structure */
2219 TXD *pTxd; /* pointer to the checked descriptor */
2220 TXD *pNewTail; /* pointer to 'end' of the ring */
2221 SK_U32 Control; /* TBControl field of descriptor */
2222 SK_U64 PhysAddr; /* address of DMA mapping */
2224 pNewTail = pTxPort->pTxdRingTail;
2227 ** loop forever; exits if BMU_SW bit not set in start frame
2228 ** or BMU_OWN bit set in any frame
2231 Control = pTxd->TBControl;
2232 if ((Control & BMU_SW) == 0) {
2234 ** software controllable bit is set in first
2235 ** fragment when given to BMU. Not set means that
2236 ** this fragment was never sent or is already
2237 ** freed ( -> ring completely free now).
2239 pTxPort->pTxdRingTail = pTxd;
2240 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2243 if (Control & BMU_OWN) {
2244 pTxPort->pTxdRingTail = pTxd;
2245 if (pTxPort->TxdRingFree > 0) {
2246 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2252 ** release the DMA mapping, because until not unmapped
2253 ** this buffer is considered being under control of the
2256 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
2257 PhysAddr |= (SK_U64) pTxd->VDataLow;
2258 pci_unmap_page(pAC->PciDev, PhysAddr,
2262 if (Control & BMU_EOF)
2263 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
2265 pTxPort->TxdRingFree++;
2266 pTxd->TBControl &= ~BMU_SW;
2267 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
2268 } /* while(forever) */
2269 } /* FreeTxDescriptors */
2271 /*****************************************************************************
2273 * FillRxRing - fill the receive ring with valid descriptors
2276 * This function fills the receive ring descriptors with data
2277 * segments and makes them valid for the BMU.
2278 * The active ring is filled completely, if possible.
2279 * The non-active ring is filled only partial to save memory.
2281 * Description of rx ring structure:
2282 * head - points to the descriptor which will be used next by the BMU
2283 * tail - points to the next descriptor to give to the BMU
2287 static void FillRxRing(
2288 SK_AC *pAC, /* pointer to the adapter context */
2289 RX_PORT *pRxPort) /* ptr to port struct for which the ring
2292 unsigned long Flags;
2294 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2295 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
2296 if(!FillRxDescriptor(pAC, pRxPort))
2299 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2303 /*****************************************************************************
2305 * FillRxDescriptor - fill one buffer into the receive ring
2308 * The function allocates a new receive buffer and
2309 * puts it into the next descriptor.
2312 * SK_TRUE - a buffer was added to the ring
2313 * SK_FALSE - a buffer could not be added
2315 static SK_BOOL FillRxDescriptor(
2316 SK_AC *pAC, /* pointer to the adapter context struct */
2317 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
2319 struct sk_buff *pMsgBlock; /* pointer to a new message block */
2320 RXD *pRxd; /* the rxd to fill */
2321 SK_U16 Length; /* data fragment length */
2322 SK_U64 PhysAddr; /* physical address of a rx buffer */
2324 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
2325 if (pMsgBlock == NULL) {
2326 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2327 SK_DBGCAT_DRV_ENTRY,
2328 ("%s: Allocation of rx buffer failed !\n",
2329 pAC->dev[pRxPort->PortIndex]->name));
2330 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
2333 skb_reserve(pMsgBlock, 2); /* to align IP frames */
2334 /* skb allocated ok, so add buffer */
2335 pRxd = pRxPort->pRxdRingTail;
2336 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2337 pRxPort->RxdRingFree--;
2338 Length = pAC->RxBufSize;
2339 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2340 virt_to_page(pMsgBlock->data),
2341 ((unsigned long) pMsgBlock->data &
2344 PCI_DMA_FROMDEVICE);
2346 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2347 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2348 pRxd->pMBuf = pMsgBlock;
2349 pRxd->RBControl = BMU_OWN |
2356 } /* FillRxDescriptor */
2359 /*****************************************************************************
2361 * ReQueueRxBuffer - fill one buffer back into the receive ring
2364 * Fill a given buffer back into the rx ring. The buffer
2365 * has been previously allocated and aligned, and its phys.
2366 * address calculated, so this is no more necessary.
2370 static void ReQueueRxBuffer(
2371 SK_AC *pAC, /* pointer to the adapter context struct */
2372 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
2373 struct sk_buff *pMsg, /* pointer to the buffer */
2374 SK_U32 PhysHigh, /* phys address high dword */
2375 SK_U32 PhysLow) /* phys address low dword */
2377 RXD *pRxd; /* the rxd to fill */
2378 SK_U16 Length; /* data fragment length */
2380 pRxd = pRxPort->pRxdRingTail;
2381 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2382 pRxPort->RxdRingFree--;
2383 Length = pAC->RxBufSize;
2385 pRxd->VDataLow = PhysLow;
2386 pRxd->VDataHigh = PhysHigh;
2388 pRxd->RBControl = BMU_OWN |
2394 } /* ReQueueRxBuffer */
2396 /*****************************************************************************
2398 * ReceiveIrq - handle a receive IRQ
2401 * This function is called when a receive IRQ is set.
2402 * It walks the receive descriptor ring and sends up all
2403 * frames that are complete.
2407 static void ReceiveIrq(
2408 SK_AC *pAC, /* pointer to adapter context */
2409 RX_PORT *pRxPort, /* pointer to receive port struct */
2410 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2412 RXD *pRxd; /* pointer to receive descriptors */
2413 SK_U32 Control; /* control field of descriptor */
2414 struct sk_buff *pMsg; /* pointer to message holding frame */
2415 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2416 int FrameLength; /* total length of received frame */
2418 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2419 SK_EVPARA EvPara; /* an event parameter union */
2420 unsigned long Flags; /* for spin lock */
2421 int PortIndex = pRxPort->PortIndex;
2422 unsigned int Offset;
2423 unsigned int NumBytes;
2424 unsigned int ForRlmt;
2427 SK_BOOL IsBadFrame; /* Bad frame */
2430 unsigned short Csum1;
2431 unsigned short Csum2;
2432 unsigned short Type;
2437 /* do forever; exit if BMU_OWN found */
2438 for ( pRxd = pRxPort->pRxdRingHead ;
2439 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2440 pRxd = pRxd->pNextRxd,
2441 pRxPort->pRxdRingHead = pRxd,
2442 pRxPort->RxdRingFree ++) {
2445 * For a better understanding of this loop
2446 * Go through every descriptor beginning at the head
2447 * Please note: the ring might be completely received so the OWN bit
2448 * set is not a good crirteria to leave that loop.
2449 * Therefore the RingFree counter is used.
2450 * On entry of this loop pRxd is a pointer to the Rxd that needs
2451 * to be checked next.
2454 Control = pRxd->RBControl;
2456 /* check if this descriptor is ready */
2457 if ((Control & BMU_OWN) != 0) {
2458 /* this descriptor is not yet ready */
2459 /* This is the usual end of the loop */
2460 /* We don't need to start the ring again */
2461 FillRxRing(pAC, pRxPort);
2464 pAC->DynIrqModInfo.NbrProcessedDescr++;
2466 /* get length of frame and check it */
2467 FrameLength = Control & BMU_BBC;
2468 if (FrameLength > pAC->RxBufSize) {
2472 /* check for STF and EOF */
2473 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2477 /* here we have a complete frame in the ring */
2480 FrameStat = pRxd->FrameStat;
2482 /* check for frame length mismatch */
2483 #define XMR_FS_LEN_SHIFT 18
2484 #define GMR_FS_LEN_SHIFT 16
2485 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2486 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2487 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2488 SK_DBGCAT_DRV_RX_PROGRESS,
2489 ("skge: Frame length mismatch (%u/%u).\n",
2491 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2496 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2497 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2498 SK_DBGCAT_DRV_RX_PROGRESS,
2499 ("skge: Frame length mismatch (%u/%u).\n",
2501 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2507 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2508 IsBc = (FrameStat & XMR_FS_BC) != 0;
2509 IsMc = (FrameStat & XMR_FS_MC) != 0;
2510 IsBadFrame = (FrameStat &
2511 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2513 IsBc = (FrameStat & GMR_FS_BC) != 0;
2514 IsMc = (FrameStat & GMR_FS_MC) != 0;
2515 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2516 ((FrameStat & GMR_FS_RX_OK) == 0));
2519 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2520 ("Received frame of length %d on port %d\n",
2521 FrameLength, PortIndex));
2522 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2523 ("Number of free rx descriptors: %d\n",
2524 pRxPort->RxdRingFree));
2525 /* DumpMsg(pMsg, "Rx"); */
2527 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2529 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2531 /* there is a receive error in this frame */
2532 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2533 SK_DBGCAT_DRV_RX_PROGRESS,
2534 ("skge: Error in received frame, dropped!\n"
2535 "Control: %x\nRxStat: %x\n",
2536 Control, FrameStat));
2538 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2539 pRxd->VDataHigh, pRxd->VDataLow);
2545 * if short frame then copy data to reduce memory waste
2547 if ((FrameLength < SK_COPY_THRESHOLD) &&
2548 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2550 * Short frame detected and allocation successfull
2552 /* use new skb and copy data */
2553 skb_reserve(pNewMsg, 2);
2554 skb_put(pNewMsg, FrameLength);
2555 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2556 PhysAddr |= (SK_U64) pRxd->VDataLow;
2558 pci_dma_sync_single_for_cpu(pAC->PciDev,
2559 (dma_addr_t) PhysAddr,
2561 PCI_DMA_FROMDEVICE);
2562 eth_copy_and_sum(pNewMsg, pMsg->data,
2564 pci_dma_sync_single_for_device(pAC->PciDev,
2565 (dma_addr_t) PhysAddr,
2567 PCI_DMA_FROMDEVICE);
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 ******************************************************************************/