1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Purpose: The main driver source module
7 ******************************************************************************/
9 /******************************************************************************
11 * (C)Copyright 1998-2002 SysKonnect GmbH.
12 * (C)Copyright 2002-2003 Marvell.
14 * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
17 * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
18 * SysKonnects GEnesis Solaris driver
19 * Author: Christoph Goos (cgoos@syskonnect.de)
20 * Mirko Lindner (mlindner@syskonnect.de)
22 * Address all question to: linux@syskonnect.de
24 * The technical manual for the adapters is available from SysKonnect's
25 * web pages: www.syskonnect.com
26 * Goto "Support" and search Knowledge Base for "manual".
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
33 * The information in this file is provided "AS IS" without warranty.
35 ******************************************************************************/
37 /******************************************************************************
39 * Possible compiler options (#define xxx / -Dxxx):
41 * debugging can be enable by changing SK_DEBUG_CHKMOD and
42 * SK_DEBUG_CHKCAT in makefile (described there).
44 ******************************************************************************/
46 /******************************************************************************
50 * This is the main module of the Linux GE driver.
52 * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
53 * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
54 * Those are used for drivers on multiple OS', so some thing may seem
55 * unnecessary complicated on Linux. Please do not try to 'clean up'
56 * them without VERY good reasons, because this will make it more
57 * difficult to keep the Linux driver in synchronisation with the
60 * Include file hierarchy:
77 * <linux/etherdevice.h>
79 * those three depending on kernel version used:
105 ******************************************************************************/
107 #include "h/skversion.h"
109 #include <linux/module.h>
110 #include <linux/init.h>
112 #ifdef CONFIG_PROC_FS
113 #include <linux/proc_fs.h>
116 #include "h/skdrv1st.h"
117 #include "h/skdrv2nd.h"
119 /*******************************************************************************
123 ******************************************************************************/
125 /* for debuging on x86 only */
126 /* #define BREAKPOINT() asm(" int $3"); */
128 /* use the transmit hw checksum driver functionality */
129 #define USE_SK_TX_CHECKSUM
131 /* use the receive hw checksum driver functionality */
132 #define USE_SK_RX_CHECKSUM
134 /* use the scatter-gather functionality with sendfile() */
137 /* use of a transmit complete interrupt */
138 #define USE_TX_COMPLETE
141 * threshold for copying small receive frames
142 * set to 0 to avoid copying, set to 9001 to copy all frames
144 #define SK_COPY_THRESHOLD 50
146 /* number of adapters that can be configured via command line params */
147 #define SK_MAX_CARD_PARAM 16
152 * use those defines for a compile-in version of the driver instead
153 * of command line parameters
155 // #define LINK_SPEED_A {"Auto", }
156 // #define LINK_SPEED_B {"Auto", }
157 // #define AUTO_NEG_A {"Sense", }
158 // #define AUTO_NEG_B {"Sense", }
159 // #define DUP_CAP_A {"Both", }
160 // #define DUP_CAP_B {"Both", }
161 // #define FLOW_CTRL_A {"SymOrRem", }
162 // #define FLOW_CTRL_B {"SymOrRem", }
163 // #define ROLE_A {"Auto", }
164 // #define ROLE_B {"Auto", }
165 // #define PREF_PORT {"A", }
166 // #define CON_TYPE {"Auto", }
167 // #define RLMT_MODE {"CheckLinkState", }
169 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
170 #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
171 #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
175 #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
176 SK_DUP_LED_NORMAL | \
180 /* Isr return value */
181 #define SkIsrRetVar irqreturn_t
182 #define SkIsrRetNone IRQ_NONE
183 #define SkIsrRetHandled IRQ_HANDLED
186 /*******************************************************************************
188 * Local Function Prototypes
190 ******************************************************************************/
192 static void FreeResources(struct SK_NET_DEVICE *dev);
193 static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
194 static SK_BOOL BoardAllocMem(SK_AC *pAC);
195 static void BoardFreeMem(SK_AC *pAC);
196 static void BoardInitMem(SK_AC *pAC);
197 static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
198 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
199 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
200 static int SkGeOpen(struct SK_NET_DEVICE *dev);
201 static int SkGeClose(struct SK_NET_DEVICE *dev);
202 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
203 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
204 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
205 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
206 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
207 static void GetConfiguration(SK_AC*);
208 static void ProductStr(SK_AC*);
209 static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
210 static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
211 static void FillRxRing(SK_AC*, RX_PORT*);
212 static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
213 static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
214 static void ClearAndStartRx(SK_AC*, int);
215 static void ClearTxIrq(SK_AC*, int, int);
216 static void ClearRxRing(SK_AC*, RX_PORT*);
217 static void ClearTxRing(SK_AC*, TX_PORT*);
218 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
219 static void PortReInitBmu(SK_AC*, int);
220 static int SkGeIocMib(DEV_NET*, unsigned int, int);
221 static int SkGeInitPCI(SK_AC *pAC);
222 static void StartDrvCleanupTimer(SK_AC *pAC);
223 static void StopDrvCleanupTimer(SK_AC *pAC);
224 static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
226 #ifdef SK_DIAG_SUPPORT
227 static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
228 static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
229 static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
232 /*******************************************************************************
234 * Extern Function Prototypes
236 ******************************************************************************/
238 #ifdef CONFIG_PROC_FS
239 static const char SK_Root_Dir_entry[] = "sk98lin";
240 static struct proc_dir_entry *pSkRootDir = NULL;
241 extern struct file_operations sk_proc_fops;
244 extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
245 extern void SkDimDisplayModerationSettings(SK_AC *pAC);
246 extern void SkDimStartModerationTimer(SK_AC *pAC);
247 extern void SkDimModerate(SK_AC *pAC);
250 static void DumpMsg(struct sk_buff*, char*);
251 static void DumpData(char*, int);
252 static void DumpLong(char*, int);
255 /* global variables *********************************************************/
256 static const char *BootString = BOOT_STRING;
257 struct SK_NET_DEVICE *SkGeRootDev = NULL;
258 static int probed __initdata = 0;
259 static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
261 /* local variables **********************************************************/
262 static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
263 static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
266 #ifdef CONFIG_PROC_FS
267 static struct proc_dir_entry *pSkRootDir;
272 /*****************************************************************************
274 * skge_probe - find all SK-98xx adapters
277 * This function scans the PCI bus for SK-98xx adapters. Resources for
278 * each adapter are allocated and the adapter is brought into Init 1
282 * 0, if everything is ok
285 static int __init skge_probe (void)
287 int boards_found = 0;
288 int vendor_flag = SK_FALSE;
290 DEV_NET *pNet = NULL;
291 struct pci_dev *pdev = NULL;
292 struct SK_NET_DEVICE *dev = NULL;
293 SK_BOOL DeviceFound = SK_FALSE;
294 SK_BOOL BootStringCount = SK_FALSE;
296 #ifdef CONFIG_PROC_FS
297 int proc_root_initialized = 0;
298 struct proc_dir_entry *pProcFile;
306 while((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev))) {
308 if (pci_enable_device(pdev)) {
315 SK_PCI_ISCOMPLIANT(vendor_flag, pdev);
319 /* Configure DMA attributes. */
320 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) &&
321 pci_set_dma_mask(pdev, (u64) 0xffffffff))
325 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
326 printk(KERN_ERR "Unable to allocate etherdev "
332 pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
333 if (pNet->pAC == NULL){
335 printk(KERN_ERR "Unable to allocate adapter "
341 if (!BootStringCount) {
342 /* set display flag to TRUE so that */
343 /* we only display this string ONCE */
344 BootStringCount = SK_TRUE;
345 printk("%s\n", BootString);
348 memset(pNet->pAC, 0, sizeof(SK_AC));
351 pAC->PciDevId = pdev->device;
354 sprintf(pAC->Name, "SysKonnect SK-98xx");
355 pAC->CheckQueue = SK_FALSE;
359 dev->irq = pdev->irq;
360 retval = SkGeInitPCI(pAC);
362 printk("SKGE: PCI setup failed: %i\n", retval);
367 SET_MODULE_OWNER(dev);
368 dev->open = &SkGeOpen;
369 dev->stop = &SkGeClose;
370 dev->hard_start_xmit = &SkGeXmit;
371 dev->get_stats = &SkGeStats;
372 dev->last_stats = &SkGeStats;
373 dev->set_multicast_list = &SkGeSetRxMode;
374 dev->set_mac_address = &SkGeSetMacAddr;
375 dev->do_ioctl = &SkGeIoctl;
376 dev->change_mtu = &SkGeChangeMtu;
377 dev->flags &= ~IFF_RUNNING;
380 #ifdef USE_SK_TX_CHECKSUM
382 if (pAC->ChipsetType) {
383 /* Use only if yukon hardware */
384 /* SK and ZEROCOPY - fly baby... */
385 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
390 pAC->Index = boards_found;
392 if (SkGeBoardInit(dev, pAC)) {
397 /* Register net device */
398 if (register_netdev(dev)) {
399 printk(KERN_ERR "SKGE: Could not register device.\n");
405 /* Print adapter specific string from vpd */
407 printk("%s: %s\n", dev->name, pAC->DeviceStr);
409 /* Print configuration settings */
410 printk(" PrefPort:%c RlmtMode:%s\n",
411 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
412 (pAC->RlmtMode==0) ? "Check Link State" :
413 ((pAC->RlmtMode==1) ? "Check Link State" :
414 ((pAC->RlmtMode==3) ? "Check Local Port" :
415 ((pAC->RlmtMode==7) ? "Check Segmentation" :
416 ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
418 SkGeYellowLED(pAC, pAC->IoBase, 1);
421 memcpy((caddr_t) &dev->dev_addr,
422 (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
424 /* First adapter... Create proc and print message */
425 #ifdef CONFIG_PROC_FS
427 DeviceFound = SK_TRUE;
428 SK_MEMCPY(&SK_Root_Dir_entry, BootString,
429 sizeof(SK_Root_Dir_entry) - 1);
431 /*Create proc (directory)*/
433 pSkRootDir = proc_mkdir(SK_Root_Dir_entry, proc_net);
435 printk(KERN_WARNING "%s: Unable to create /proc/net/%s",
436 dev->name, SK_Root_Dir_entry);
438 pSkRootDir->owner = THIS_MODULE;
443 /* Create proc file */
445 (pProcFile = create_proc_entry(dev->name, S_IRUGO,
447 pProcFile->proc_fops = &sk_proc_fops;
448 pProcFile->data = dev;
458 /* More then one port found */
459 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
460 if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
461 printk(KERN_ERR "Unable to allocate etherdev "
474 dev->open = &SkGeOpen;
475 dev->stop = &SkGeClose;
476 dev->hard_start_xmit = &SkGeXmit;
477 dev->get_stats = &SkGeStats;
478 dev->last_stats = &SkGeStats;
479 dev->set_multicast_list = &SkGeSetRxMode;
480 dev->set_mac_address = &SkGeSetMacAddr;
481 dev->do_ioctl = &SkGeIoctl;
482 dev->change_mtu = &SkGeChangeMtu;
483 dev->flags &= ~IFF_RUNNING;
486 #ifdef USE_SK_TX_CHECKSUM
487 if (pAC->ChipsetType) {
488 /* SG and ZEROCOPY - fly baby... */
489 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
494 if (register_netdev(dev)) {
495 printk(KERN_ERR "SKGE: Could not register device.\n");
497 pAC->dev[1] = pAC->dev[0];
499 #ifdef CONFIG_PROC_FS
501 && (pProcFile = create_proc_entry(dev->name,
502 S_IRUGO, pSkRootDir))) {
503 pProcFile->proc_fops = &sk_proc_fops;
504 pProcFile->data = dev;
508 memcpy((caddr_t) &dev->dev_addr,
509 (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
511 printk("%s: %s\n", dev->name, pAC->DeviceStr);
512 printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
516 /* Save the hardware revision */
517 pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
518 (pAC->GIni.GIPciHwRev & 0x0F);
520 /* Set driver globals */
521 pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
522 pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
524 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
525 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
526 sizeof(SK_PNMI_STRUCT_DATA));
529 * This is bollocks, but we need to tell the net-init
530 * code that it shall go for the next device.
538 * If we're at this point we're going through skge_probe() for
539 * the first time. Return success (0) if we've initialized 1
540 * or more boards. Otherwise, return failure (-ENODEV).
547 /*****************************************************************************
549 * SkGeInitPCI - Init the PCI resources
552 * This function initialize the PCI resources and IO
557 int SkGeInitPCI(SK_AC *pAC)
559 struct SK_NET_DEVICE *dev = pAC->dev[0];
560 struct pci_dev *pdev = pAC->PciDev;
563 if (pci_enable_device(pdev) != 0) {
567 dev->mem_start = pci_resource_start (pdev, 0);
568 pci_set_master(pdev);
570 if (pci_request_regions(pdev, pAC->Name) != 0) {
577 * On big endian machines, we use the adapter's aibility of
578 * reading the descriptors as big endian.
582 SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
583 our2 |= PCI_REV_DESC;
584 SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
589 * Remap the regs into kernel space.
591 pAC->IoBase = (char*)ioremap_nocache(dev->mem_start, 0x4000);
601 pci_release_regions(pdev);
603 pci_disable_device(pdev);
608 /*****************************************************************************
610 * FreeResources - release resources allocated for adapter
613 * This function releases the IRQ, unmaps the IO and
614 * frees the desriptor ring.
619 static void FreeResources(struct SK_NET_DEVICE *dev)
626 pNet = (DEV_NET*) dev->priv;
628 AllocFlag = pAC->AllocFlag;
630 pci_release_regions(pAC->PciDev);
632 if (AllocFlag & SK_ALLOC_IRQ) {
633 free_irq(dev->irq, dev);
636 iounmap(pAC->IoBase);
638 if (pAC->pDescrMem) {
643 } /* FreeResources */
645 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
646 MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
647 MODULE_LICENSE("GPL");
648 MODULE_PARM(Speed_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
649 MODULE_PARM(Speed_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
650 MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
651 MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
652 MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
653 MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
654 MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
655 MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
656 MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
657 MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
658 MODULE_PARM(ConType, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
659 MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
660 MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
661 /* not used, just there because every driver should have them: */
662 MODULE_PARM(options, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
663 MODULE_PARM(debug, "i");
664 /* used for interrupt moderation */
665 MODULE_PARM(IntsPerSec, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
666 MODULE_PARM(Moderation, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
667 MODULE_PARM(Stats, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
668 MODULE_PARM(ModerationMask, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
669 MODULE_PARM(AutoSizing, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
673 static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
675 static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
679 static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
681 static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
685 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
687 static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
691 static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
693 static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
697 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
699 static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
703 static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
705 static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
709 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
711 static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
715 static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
717 static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
721 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
723 static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
727 static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
729 static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
733 static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
735 static char *ConType[SK_MAX_CARD_PARAM] = {"", };
739 static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
741 static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
745 static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
747 static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
750 static int debug = 0; /* not used */
751 static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
753 static int IntsPerSec[SK_MAX_CARD_PARAM];
754 static char *Moderation[SK_MAX_CARD_PARAM];
755 static char *ModerationMask[SK_MAX_CARD_PARAM];
756 static char *AutoSizing[SK_MAX_CARD_PARAM];
757 static char *Stats[SK_MAX_CARD_PARAM];
760 /*****************************************************************************
762 * skge_init_module - module initialization function
765 * Very simple, only call skge_probe and return approriate result.
768 * 0, if everything is ok
771 static int __init skge_init_module(void)
776 /* just to avoid warnings ... */
780 cards = skge_probe();
782 printk("sk98lin: No adapter found.\n");
784 return cards ? 0 : -ENODEV;
785 } /* skge_init_module */
788 /*****************************************************************************
790 * skge_cleanup_module - module unload function
793 * Disable adapter if it is still running, free resources,
794 * free device struct.
798 static void __exit skge_cleanup_module(void)
802 struct SK_NET_DEVICE *next;
806 while (SkGeRootDev) {
807 pNet = (DEV_NET*) SkGeRootDev->priv;
811 netif_stop_queue(SkGeRootDev);
812 SkGeYellowLED(pAC, pAC->IoBase, 0);
814 if(pAC->BoardLevel == SK_INIT_RUN) {
815 /* board is still alive */
816 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
817 EvPara.Para32[0] = 0;
818 EvPara.Para32[1] = -1;
819 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
820 EvPara.Para32[0] = 1;
821 EvPara.Para32[1] = -1;
822 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
823 SkEventDispatcher(pAC, pAC->IoBase);
824 /* disable interrupts */
825 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
826 SkGeDeInit(pAC, pAC->IoBase);
827 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
828 pAC->BoardLevel = SK_INIT_DATA;
829 /* We do NOT check here, if IRQ was pending, of course*/
832 if(pAC->BoardLevel == SK_INIT_IO) {
833 /* board is still alive */
834 SkGeDeInit(pAC, pAC->IoBase);
835 pAC->BoardLevel = SK_INIT_DATA;
838 if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
839 unregister_netdev(pAC->dev[1]);
840 free_netdev(pAC->dev[1]);
843 FreeResources(SkGeRootDev);
845 SkGeRootDev->get_stats = NULL;
847 * otherwise unregister_netdev calls get_stats with
850 unregister_netdev(SkGeRootDev);
851 free_netdev(SkGeRootDev);
856 #ifdef CONFIG_PROC_FS
858 remove_proc_entry(pSkRootDir->name, proc_net);
861 } /* skge_cleanup_module */
863 module_init(skge_init_module);
864 module_exit(skge_cleanup_module);
867 /*****************************************************************************
869 * SkGeBoardInit - do level 0 and 1 initialization
872 * This function prepares the board hardware for running. The desriptor
873 * ring is set up, the IRQ is allocated and the configuration settings
877 * 0, if everything is ok
880 static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
884 char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
885 char *VerStr = VER_STRING;
886 int Ret; /* return code of request_irq */
889 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
890 ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
891 for (i=0; i<SK_MAX_MACS; i++) {
892 pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
893 pAC->TxPort[i][0].PortIndex = i;
894 pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
895 pAC->RxPort[i].PortIndex = i;
898 /* Initialize the mutexes */
899 for (i=0; i<SK_MAX_MACS; i++) {
900 spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
901 spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
903 spin_lock_init(&pAC->SlowPathLock);
905 /* level 0 init common modules here */
907 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
908 /* Does a RESET on board ...*/
909 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
910 printk("HWInit (0) failed.\n");
911 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
914 SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
915 SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
916 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
917 SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
918 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
919 SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
921 pAC->BoardLevel = SK_INIT_DATA;
922 pAC->RxBufSize = ETH_BUF_SIZE;
924 SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
925 SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
927 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
929 /* level 1 init common modules here (HW init) */
930 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
931 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
932 printk("sk98lin: HWInit (1) failed.\n");
933 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
936 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
937 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
938 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
939 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
940 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
941 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
943 /* Set chipset type support */
944 pAC->ChipsetType = 0;
945 if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
946 (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
947 pAC->ChipsetType = 1;
950 GetConfiguration(pAC);
951 if (pAC->RlmtNets == 2) {
952 pAC->GIni.GIPortUsage = SK_MUL_LINK;
955 pAC->BoardLevel = SK_INIT_IO;
956 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
958 if (pAC->GIni.GIMacsFound == 2) {
959 Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
960 } else if (pAC->GIni.GIMacsFound == 1) {
961 Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
964 printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
965 pAC->GIni.GIMacsFound);
970 printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
974 pAC->AllocFlag |= SK_ALLOC_IRQ;
976 /* Alloc memory for this board (Mem for RxD/TxD) : */
977 if(!BoardAllocMem(pAC)) {
978 printk("No memory for descriptor rings.\n");
982 SkCsSetReceiveFlags(pAC,
983 SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
984 &pAC->CsOfs1, &pAC->CsOfs2, 0);
985 pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
988 /* tschilling: New common function with minimum size check. */
990 if (pAC->RlmtNets == 2) {
994 if (SkGeInitAssignRamToQueues(
999 printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
1004 * Register the device here
1006 pAC->Next = SkGeRootDev;
1010 } /* SkGeBoardInit */
1013 /*****************************************************************************
1015 * BoardAllocMem - allocate the memory for the descriptor rings
1018 * This function allocates the memory for all descriptor rings.
1019 * Each ring is aligned for the desriptor alignment and no ring
1020 * has a 4 GByte boundary in it (because the upper 32 bit must
1021 * be constant for all descriptiors in one rings).
1024 * SK_TRUE, if all memory could be allocated
1027 static SK_BOOL BoardAllocMem(
1030 caddr_t pDescrMem; /* pointer to descriptor memory area */
1031 size_t AllocLength; /* length of complete descriptor area */
1032 int i; /* loop counter */
1033 unsigned long BusAddr;
1036 /* rings plus one for alignment (do not cross 4 GB boundary) */
1037 /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
1038 #if (BITS_PER_LONG == 32)
1039 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1041 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1045 pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
1046 &pAC->pDescrMemDMA);
1048 if (pDescrMem == NULL) {
1051 pAC->pDescrMem = pDescrMem;
1052 BusAddr = (unsigned long) pAC->pDescrMemDMA;
1054 /* Descriptors need 8 byte alignment, and this is ensured
1055 * by pci_alloc_consistent.
1057 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1058 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1059 ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
1060 i, (unsigned long) pDescrMem,
1062 pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
1063 pAC->TxPort[i][0].VTxDescrRing = BusAddr;
1064 pDescrMem += TX_RING_SIZE;
1065 BusAddr += TX_RING_SIZE;
1067 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1068 ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
1069 i, (unsigned long) pDescrMem,
1070 (unsigned long)BusAddr));
1071 pAC->RxPort[i].pRxDescrRing = pDescrMem;
1072 pAC->RxPort[i].VRxDescrRing = BusAddr;
1073 pDescrMem += RX_RING_SIZE;
1074 BusAddr += RX_RING_SIZE;
1078 } /* BoardAllocMem */
1081 /****************************************************************************
1083 * BoardFreeMem - reverse of BoardAllocMem
1086 * Free all memory allocated in BoardAllocMem: adapter context,
1087 * descriptor rings, locks.
1091 static void BoardFreeMem(
1094 size_t AllocLength; /* length of complete descriptor area */
1096 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1097 ("BoardFreeMem\n"));
1098 #if (BITS_PER_LONG == 32)
1099 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
1101 AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
1105 pci_free_consistent(pAC->PciDev, AllocLength,
1106 pAC->pDescrMem, pAC->pDescrMemDMA);
1107 pAC->pDescrMem = NULL;
1108 } /* BoardFreeMem */
1111 /*****************************************************************************
1113 * BoardInitMem - initiate the descriptor rings
1116 * This function sets the descriptor rings up in memory.
1117 * The adapter is initialized with the descriptor start addresses.
1121 static void BoardInitMem(
1122 SK_AC *pAC) /* pointer to adapter context */
1124 int i; /* loop counter */
1125 int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
1126 int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
1128 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1129 ("BoardInitMem\n"));
1131 RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1132 pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
1133 TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
1134 pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
1136 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1139 pAC->TxPort[i][0].pTxDescrRing,
1140 pAC->TxPort[i][0].VTxDescrRing,
1141 (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
1142 (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
1143 (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
1144 &pAC->TxPort[i][0].TxdRingFree,
1148 pAC->RxPort[i].pRxDescrRing,
1149 pAC->RxPort[i].VRxDescrRing,
1150 &pAC->RxPort[i].pRxdRingHead,
1151 &pAC->RxPort[i].pRxdRingTail,
1152 &pAC->RxPort[i].pRxdRingPrev,
1153 &pAC->RxPort[i].RxdRingFree,
1156 } /* BoardInitMem */
1159 /*****************************************************************************
1161 * SetupRing - create one descriptor ring
1164 * This function creates one descriptor ring in the given memory area.
1165 * The head, tail and number of free descriptors in the ring are set.
1170 static void SetupRing(
1172 void *pMemArea, /* a pointer to the memory area for the ring */
1173 uintptr_t VMemArea, /* the virtual bus address of the memory area */
1174 RXD **ppRingHead, /* address where the head should be written */
1175 RXD **ppRingTail, /* address where the tail should be written */
1176 RXD **ppRingPrev, /* address where the tail should be written */
1177 int *pRingFree, /* address where the # of free descr. goes */
1178 SK_BOOL IsTx) /* flag: is this a tx ring */
1180 int i; /* loop counter */
1181 int DescrSize; /* the size of a descriptor rounded up to alignment*/
1182 int DescrNum; /* number of descriptors per ring */
1183 RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
1184 RXD *pNextDescr; /* pointer to the next descriptor */
1185 RXD *pPrevDescr; /* pointer to the previous descriptor */
1186 uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
1188 if (IsTx == SK_TRUE) {
1189 DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
1191 DescrNum = TX_RING_SIZE / DescrSize;
1193 DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
1195 DescrNum = RX_RING_SIZE / DescrSize;
1198 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
1199 ("Descriptor size: %d Descriptor Number: %d\n",
1200 DescrSize,DescrNum));
1202 pDescr = (RXD*) pMemArea;
1204 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1205 VNextDescr = VMemArea + DescrSize;
1206 for(i=0; i<DescrNum; i++) {
1207 /* set the pointers right */
1208 pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
1209 pDescr->pNextRxd = pNextDescr;
1210 pDescr->TcpSumStarts = pAC->CsOfs;
1212 /* advance one step */
1213 pPrevDescr = pDescr;
1214 pDescr = pNextDescr;
1215 pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
1216 VNextDescr += DescrSize;
1218 pPrevDescr->pNextRxd = (RXD*) pMemArea;
1219 pPrevDescr->VNextRxd = VMemArea;
1220 pDescr = (RXD*) pMemArea;
1221 *ppRingHead = (RXD*) pMemArea;
1222 *ppRingTail = *ppRingHead;
1223 *ppRingPrev = pPrevDescr;
1224 *pRingFree = DescrNum;
1228 /*****************************************************************************
1230 * PortReInitBmu - re-initiate the descriptor rings for one port
1233 * This function reinitializes the descriptor rings of one port
1234 * in memory. The port must be stopped before.
1235 * The HW is initialized with the descriptor start addresses.
1240 static void PortReInitBmu(
1241 SK_AC *pAC, /* pointer to adapter context */
1242 int PortIndex) /* index of the port for which to re-init */
1244 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1245 ("PortReInitBmu "));
1247 /* set address of first descriptor of ring in BMU */
1248 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
1249 (uint32_t)(((caddr_t)
1250 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1251 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1252 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
1254 SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
1255 (uint32_t)(((caddr_t)
1256 (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
1257 pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
1258 pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
1259 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
1260 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1261 pAC->RxPort[PortIndex].pRxDescrRing +
1262 pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
1263 SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
1264 (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
1265 pAC->RxPort[PortIndex].pRxDescrRing +
1266 pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
1267 } /* PortReInitBmu */
1270 /****************************************************************************
1272 * SkGeIsr - handle adapter interrupts
1275 * The interrupt routine is called when the network adapter
1276 * generates an interrupt. It may also be called if another device
1277 * shares this interrupt vector with the driver.
1282 static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
1284 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1287 SK_U32 IntSrc; /* interrupts source register contents */
1289 pNet = (DEV_NET*) dev->priv;
1293 * Check and process if its our interrupt
1295 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1297 return SkIsrRetNone;
1300 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1301 #if 0 /* software irq currently not used */
1302 if (IntSrc & IS_IRQ_SW) {
1303 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1304 SK_DBGCAT_DRV_INT_SRC,
1305 ("Software IRQ\n"));
1308 if (IntSrc & IS_R1_F) {
1309 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1310 SK_DBGCAT_DRV_INT_SRC,
1312 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1313 SK_PNMI_CNT_RX_INTR(pAC, 0);
1315 if (IntSrc & IS_R2_F) {
1316 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1317 SK_DBGCAT_DRV_INT_SRC,
1319 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1320 SK_PNMI_CNT_RX_INTR(pAC, 1);
1322 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1323 if (IntSrc & IS_XA1_F) {
1324 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1325 SK_DBGCAT_DRV_INT_SRC,
1326 ("EOF AS TX1 IRQ\n"));
1327 SK_PNMI_CNT_TX_INTR(pAC, 0);
1328 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1329 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1330 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1332 if (IntSrc & IS_XA2_F) {
1333 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1334 SK_DBGCAT_DRV_INT_SRC,
1335 ("EOF AS TX2 IRQ\n"));
1336 SK_PNMI_CNT_TX_INTR(pAC, 1);
1337 spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1338 FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
1339 spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
1341 #if 0 /* only if sync. queues used */
1342 if (IntSrc & IS_XS1_F) {
1343 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1344 SK_DBGCAT_DRV_INT_SRC,
1345 ("EOF SY TX1 IRQ\n"));
1346 SK_PNMI_CNT_TX_INTR(pAC, 1);
1347 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1348 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1349 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1350 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1352 if (IntSrc & IS_XS2_F) {
1353 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1354 SK_DBGCAT_DRV_INT_SRC,
1355 ("EOF SY TX2 IRQ\n"));
1356 SK_PNMI_CNT_TX_INTR(pAC, 1);
1357 spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1358 FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
1359 spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
1360 ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
1365 /* do all IO at once */
1366 if (IntSrc & IS_R1_F)
1367 ClearAndStartRx(pAC, 0);
1368 if (IntSrc & IS_R2_F)
1369 ClearAndStartRx(pAC, 1);
1370 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1371 if (IntSrc & IS_XA1_F)
1372 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1373 if (IntSrc & IS_XA2_F)
1374 ClearTxIrq(pAC, 1, TX_PRIO_LOW);
1376 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1377 } /* while (IntSrc & IRQ_MASK != 0) */
1379 IntSrc &= pAC->GIni.GIValIrqMask;
1380 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1381 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1382 ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
1383 pAC->CheckQueue = SK_FALSE;
1384 spin_lock(&pAC->SlowPathLock);
1385 if (IntSrc & SPECIAL_IRQS)
1386 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1388 SkEventDispatcher(pAC, pAC->IoBase);
1389 spin_unlock(&pAC->SlowPathLock);
1392 * do it all again is case we cleared an interrupt that
1393 * came in after handling the ring (OUTs may be delayed
1394 * in hardware buffers, but are through after IN)
1396 * rroesler: has been commented out and shifted to
1397 * SkGeDrvEvent(), because it is timer
1400 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1401 ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
1404 if (pAC->CheckQueue) {
1405 pAC->CheckQueue = SK_FALSE;
1406 spin_lock(&pAC->SlowPathLock);
1407 SkEventDispatcher(pAC, pAC->IoBase);
1408 spin_unlock(&pAC->SlowPathLock);
1411 /* IRQ is processed - Enable IRQs again*/
1412 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1414 return SkIsrRetHandled;
1418 /****************************************************************************
1420 * SkGeIsrOnePort - handle adapter interrupts for single port adapter
1423 * The interrupt routine is called when the network adapter
1424 * generates an interrupt. It may also be called if another device
1425 * shares this interrupt vector with the driver.
1426 * This is the same as above, but handles only one port.
1431 static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
1433 struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
1436 SK_U32 IntSrc; /* interrupts source register contents */
1438 pNet = (DEV_NET*) dev->priv;
1442 * Check and process if its our interrupt
1444 SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
1446 return SkIsrRetNone;
1449 while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
1450 #if 0 /* software irq currently not used */
1451 if (IntSrc & IS_IRQ_SW) {
1452 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1453 SK_DBGCAT_DRV_INT_SRC,
1454 ("Software IRQ\n"));
1457 if (IntSrc & IS_R1_F) {
1458 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1459 SK_DBGCAT_DRV_INT_SRC,
1461 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1462 SK_PNMI_CNT_RX_INTR(pAC, 0);
1464 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1465 if (IntSrc & IS_XA1_F) {
1466 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1467 SK_DBGCAT_DRV_INT_SRC,
1468 ("EOF AS TX1 IRQ\n"));
1469 SK_PNMI_CNT_TX_INTR(pAC, 0);
1470 spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1471 FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
1472 spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
1474 #if 0 /* only if sync. queues used */
1475 if (IntSrc & IS_XS1_F) {
1476 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1477 SK_DBGCAT_DRV_INT_SRC,
1478 ("EOF SY TX1 IRQ\n"));
1479 SK_PNMI_CNT_TX_INTR(pAC, 0);
1480 spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1481 FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
1482 spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
1483 ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
1488 /* do all IO at once */
1489 if (IntSrc & IS_R1_F)
1490 ClearAndStartRx(pAC, 0);
1491 #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
1492 if (IntSrc & IS_XA1_F)
1493 ClearTxIrq(pAC, 0, TX_PRIO_LOW);
1495 SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
1496 } /* while (IntSrc & IRQ_MASK != 0) */
1498 IntSrc &= pAC->GIni.GIValIrqMask;
1499 if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
1500 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
1501 ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
1502 pAC->CheckQueue = SK_FALSE;
1503 spin_lock(&pAC->SlowPathLock);
1504 if (IntSrc & SPECIAL_IRQS)
1505 SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
1507 SkEventDispatcher(pAC, pAC->IoBase);
1508 spin_unlock(&pAC->SlowPathLock);
1511 * do it all again is case we cleared an interrupt that
1512 * came in after handling the ring (OUTs may be delayed
1513 * in hardware buffers, but are through after IN)
1515 * rroesler: has been commented out and shifted to
1516 * SkGeDrvEvent(), because it is timer
1519 ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
1522 /* IRQ is processed - Enable IRQs again*/
1523 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1525 return SkIsrRetHandled;
1526 } /* SkGeIsrOnePort */
1529 /****************************************************************************
1531 * SkGeOpen - handle start of initialized adapter
1534 * This function starts the initialized adapter.
1535 * The board level variable is set and the adapter is
1536 * brought to full functionality.
1537 * The device flags are set for operation.
1538 * Do all necessary level 2 initialization, enable interrupts and
1539 * give start command to RLMT.
1545 static int SkGeOpen(
1546 struct SK_NET_DEVICE *dev)
1550 unsigned long Flags; /* for spin lock */
1552 SK_EVPARA EvPara; /* an event parameter union */
1554 pNet = (DEV_NET*) dev->priv;
1557 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1558 ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
1560 #ifdef SK_DIAG_SUPPORT
1561 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1562 if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
1563 return (-1); /* still in use by diag; deny actions */
1568 if (!try_module_get(THIS_MODULE)) {
1569 return (-1); /* increase of usage count not possible */
1572 /* Set blink mode */
1573 if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
1574 pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
1576 if (pAC->BoardLevel == SK_INIT_DATA) {
1577 /* level 1 init common modules here */
1578 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
1579 module_put(THIS_MODULE); /* decrease usage count */
1580 printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
1583 SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
1584 SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
1585 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
1586 SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
1587 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
1588 SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
1589 pAC->BoardLevel = SK_INIT_IO;
1592 if (pAC->BoardLevel != SK_INIT_RUN) {
1593 /* tschilling: Level 2 init modules here, check return value. */
1594 if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
1595 module_put(THIS_MODULE); /* decrease usage count */
1596 printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
1599 SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
1600 SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
1601 SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
1602 SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
1603 SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
1604 SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
1605 pAC->BoardLevel = SK_INIT_RUN;
1608 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1609 /* Enable transmit descriptor polling. */
1610 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
1611 FillRxRing(pAC, &pAC->RxPort[i]);
1613 SkGeYellowLED(pAC, pAC->IoBase, 1);
1615 StartDrvCleanupTimer(pAC);
1616 SkDimEnableModerationIfNeeded(pAC);
1617 SkDimDisplayModerationSettings(pAC);
1619 pAC->GIni.GIValIrqMask &= IRQ_MASK;
1621 /* enable Interrupts */
1622 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
1623 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
1625 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1627 if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
1628 EvPara.Para32[0] = pAC->RlmtNets;
1629 EvPara.Para32[1] = -1;
1630 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
1632 EvPara.Para32[0] = pAC->RlmtMode;
1633 EvPara.Para32[1] = 0;
1634 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
1638 EvPara.Para32[0] = pNet->NetNr;
1639 EvPara.Para32[1] = -1;
1640 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
1641 SkEventDispatcher(pAC, pAC->IoBase);
1642 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1648 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1649 ("SkGeOpen suceeded\n"));
1655 /****************************************************************************
1657 * SkGeClose - Stop initialized adapter
1660 * Close initialized adapter.
1664 * error code - on error
1666 static int SkGeClose(
1667 struct SK_NET_DEVICE *dev)
1673 unsigned long Flags; /* for spin lock */
1678 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1679 ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
1681 pNet = (DEV_NET*) dev->priv;
1684 #ifdef SK_DIAG_SUPPORT
1685 if (pAC->DiagModeActive == DIAG_ACTIVE) {
1686 if (pAC->DiagFlowCtrl == SK_FALSE) {
1687 module_put(THIS_MODULE);
1689 ** notify that the interface which has been closed
1690 ** by operator interaction must not be started up
1691 ** again when the DIAG has finished.
1693 newPtrNet = (DEV_NET *) pAC->dev[0]->priv;
1694 if (newPtrNet == pNet) {
1695 pAC->WasIfUp[0] = SK_FALSE;
1697 pAC->WasIfUp[1] = SK_FALSE;
1699 return 0; /* return to system everything is fine... */
1701 pAC->DiagFlowCtrl = SK_FALSE;
1706 netif_stop_queue(dev);
1708 if (pAC->RlmtNets == 1)
1709 PortIdx = pAC->ActivePort;
1711 PortIdx = pNet->NetNr;
1713 StopDrvCleanupTimer(pAC);
1716 * Clear multicast table, promiscuous mode ....
1718 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
1719 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
1722 if (pAC->MaxPorts == 1) {
1723 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1724 /* disable interrupts */
1725 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1726 EvPara.Para32[0] = pNet->NetNr;
1727 EvPara.Para32[1] = -1;
1728 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1729 SkEventDispatcher(pAC, pAC->IoBase);
1730 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
1731 /* stop the hardware */
1732 SkGeDeInit(pAC, pAC->IoBase);
1733 pAC->BoardLevel = SK_INIT_DATA;
1734 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1737 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
1738 EvPara.Para32[0] = pNet->NetNr;
1739 EvPara.Para32[1] = -1;
1740 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
1741 SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
1742 SkEventDispatcher(pAC, pAC->IoBase);
1743 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
1746 spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
1747 [TX_PRIO_LOW].TxDesRingLock, Flags);
1748 SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
1749 SK_STOP_ALL, SK_HARD_RST);
1750 spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
1751 [TX_PRIO_LOW].TxDesRingLock, Flags);
1754 if (pAC->RlmtNets == 1) {
1755 /* clear all descriptor rings */
1756 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
1757 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
1758 ClearRxRing(pAC, &pAC->RxPort[i]);
1759 ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
1762 /* clear port descriptor rings */
1763 ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
1764 ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
1765 ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
1768 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
1769 ("SkGeClose: done "));
1771 SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
1772 SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
1773 sizeof(SK_PNMI_STRUCT_DATA));
1778 module_put(THIS_MODULE);
1783 /*****************************************************************************
1785 * SkGeXmit - Linux frame transmit function
1788 * The system calls this function to send frames onto the wire.
1789 * It puts the frame in the tx descriptor ring. If the ring is
1790 * full then, the 'tbusy' flag is set.
1793 * 0, if everything is ok
1795 * WARNING: returning 1 in 'tbusy' case caused system crashes (double
1796 * allocated skb's) !!!
1798 static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
1802 int Rc; /* return code of XmitFrame */
1804 pNet = (DEV_NET*) dev->priv;
1807 if ((!skb_shinfo(skb)->nr_frags) ||
1808 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
1809 /* Don't activate scatter-gather and hardware checksum */
1811 if (pAC->RlmtNets == 2)
1814 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1819 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1822 /* scatter-gather and hardware TCP checksumming anabled*/
1823 if (pAC->RlmtNets == 2)
1826 &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
1831 &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
1835 /* Transmitter out of resources? */
1837 netif_stop_queue(dev);
1840 /* If not taken, give buffer ownership back to the
1846 dev->trans_start = jiffies;
1851 /*****************************************************************************
1853 * XmitFrame - fill one socket buffer into the transmit ring
1856 * This function puts a message into the transmit descriptor ring
1857 * if there is a descriptors left.
1858 * Linux skb's consist of only one continuous buffer.
1859 * The first step locks the ring. It is held locked
1860 * all time to avoid problems with SWITCH_../PORT_RESET.
1861 * Then the descriptoris allocated.
1862 * The second part is linking the buffer to the descriptor.
1863 * At the very last, the Control field of the descriptor
1864 * is made valid for the BMU and a start TX command is given
1868 * > 0 - on succes: the number of bytes in the message
1869 * = 0 - on resource shortage: this frame sent or dropped, now
1870 * the ring is full ( -> set tbusy)
1871 * < 0 - on failure: other problems ( -> return failure to upper layers)
1873 static int XmitFrame(
1874 SK_AC *pAC, /* pointer to adapter context */
1875 TX_PORT *pTxPort, /* pointer to struct of port to send to */
1876 struct sk_buff *pMessage) /* pointer to send-message */
1878 TXD *pTxd; /* the rxd to fill */
1880 unsigned long Flags;
1884 int BytesSend = pMessage->len;
1886 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
1888 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
1889 #ifndef USE_TX_COMPLETE
1890 FreeTxDescriptors(pAC, pTxPort);
1892 if (pTxPort->TxdRingFree == 0) {
1894 ** no enough free descriptors in ring at the moment.
1895 ** Maybe free'ing some old one help?
1897 FreeTxDescriptors(pAC, pTxPort);
1898 if (pTxPort->TxdRingFree == 0) {
1899 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
1900 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
1901 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
1902 SK_DBGCAT_DRV_TX_PROGRESS,
1903 ("XmitFrame failed\n"));
1905 ** the desired message can not be sent
1906 ** Because tbusy seems to be set, the message
1907 ** should not be freed here. It will be used
1908 ** by the scheduler of the ethernet handler
1915 ** If the passed socket buffer is of smaller MTU-size than 60,
1916 ** copy everything into new buffer and fill all bytes between
1917 ** the original packet end and the new packet end of 60 with 0x00.
1918 ** This is to resolve faulty padding by the HW with 0xaa bytes.
1920 if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
1921 if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
1924 pMessage->len = C_LEN_ETHERNET_MINSIZE;
1928 ** advance head counter behind descriptor needed for this frame,
1929 ** so that needed descriptor is reserved from that on. The next
1930 ** action will be to add the passed buffer to the TX-descriptor
1932 pTxd = pTxPort->pTxdRingHead;
1933 pTxPort->pTxdRingHead = pTxd->pNextTxd;
1934 pTxPort->TxdRingFree--;
1937 DumpMsg(pMessage, "XmitFrame");
1941 ** First step is to map the data to be sent via the adapter onto
1942 ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
1943 ** and 2.6 need to use pci_map_page() for that mapping.
1945 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
1946 virt_to_page(pMessage->data),
1947 ((unsigned long) pMessage->data & ~PAGE_MASK),
1950 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
1951 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1952 pTxd->pMBuf = pMessage;
1954 if (pMessage->ip_summed == CHECKSUM_HW) {
1955 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
1956 if ((Protocol == C_PROTO_ID_UDP) &&
1957 (pAC->GIni.GIChipRev == 0) &&
1958 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
1959 pTxd->TBControl = BMU_TCP_CHECK;
1961 pTxd->TBControl = BMU_UDP_CHECK;
1964 IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
1965 IpHeaderLength = (IpHeaderLength & 0xf) * 4;
1966 pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
1967 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
1968 (Protocol == C_PROTO_ID_UDP ?
1969 C_OFFSET_UDPHEADER_UDPCS :
1970 C_OFFSET_TCPHEADER_TCPCS);
1971 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
1973 pTxd->TBControl |= BMU_OWN | BMU_STF |
1975 #ifdef USE_TX_COMPLETE
1980 pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
1982 #ifdef USE_TX_COMPLETE
1989 ** If previous descriptor already done, give TX start cmd
1991 pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
1992 if ((pOldTxd->TBControl & BMU_OWN) == 0) {
1993 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
1997 ** after releasing the lock, the skb may immediately be free'd
1999 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2000 if (pTxPort->TxdRingFree != 0) {
2008 /*****************************************************************************
2010 * XmitFrameSG - fill one socket buffer into the transmit ring
2011 * (use SG and TCP/UDP hardware checksumming)
2014 * This function puts a message into the transmit descriptor ring
2015 * if there is a descriptors left.
2018 * > 0 - on succes: the number of bytes in the message
2019 * = 0 - on resource shortage: this frame sent or dropped, now
2020 * the ring is full ( -> set tbusy)
2021 * < 0 - on failure: other problems ( -> return failure to upper layers)
2023 static int XmitFrameSG(
2024 SK_AC *pAC, /* pointer to adapter context */
2025 TX_PORT *pTxPort, /* pointer to struct of port to send to */
2026 struct sk_buff *pMessage) /* pointer to send-message */
2036 skb_frag_t *sk_frag;
2038 unsigned long Flags;
2040 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2041 #ifndef USE_TX_COMPLETE
2042 FreeTxDescriptors(pAC, pTxPort);
2044 if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
2045 FreeTxDescriptors(pAC, pTxPort);
2046 if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
2047 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2048 SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
2049 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2050 SK_DBGCAT_DRV_TX_PROGRESS,
2051 ("XmitFrameSG failed - Ring full\n"));
2052 /* this message can not be sent now */
2057 pTxd = pTxPort->pTxdRingHead;
2064 ** Map the first fragment (header) into the DMA-space
2066 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2067 virt_to_page(pMessage->data),
2068 ((unsigned long) pMessage->data & ~PAGE_MASK),
2069 skb_headlen(pMessage),
2072 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2073 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2076 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2078 if (pMessage->ip_summed == CHECKSUM_HW) {
2079 pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
2081 ** We have to use the opcode for tcp here, because the
2082 ** opcode for udp is not working in the hardware yet
2085 Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
2086 if ((Protocol == C_PROTO_ID_UDP) &&
2087 (pAC->GIni.GIChipRev == 0) &&
2088 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2089 pTxd->TBControl |= BMU_TCP_CHECK;
2091 pTxd->TBControl |= BMU_UDP_CHECK;
2094 IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
2095 pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
2096 pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
2097 (Protocol == C_PROTO_ID_UDP ?
2098 C_OFFSET_UDPHEADER_UDPCS :
2099 C_OFFSET_TCPHEADER_TCPCS);
2100 pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
2102 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
2103 skb_headlen(pMessage);
2106 pTxd = pTxd->pNextTxd;
2107 pTxPort->TxdRingFree--;
2108 BytesSend += skb_headlen(pMessage);
2111 ** Browse over all SG fragments and map each of them into the DMA space
2113 for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
2114 sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
2116 ** we already have the proper value in entry
2118 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2120 sk_frag->page_offset,
2124 pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2125 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2126 pTxd->pMBuf = pMessage;
2129 ** Does the HW need to evaluate checksum for TCP or UDP packets?
2131 if (pMessage->ip_summed == CHECKSUM_HW) {
2132 pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
2134 ** We have to use the opcode for tcp here because the
2135 ** opcode for udp is not working in the hardware yet
2138 if ((Protocol == C_PROTO_ID_UDP) &&
2139 (pAC->GIni.GIChipRev == 0) &&
2140 (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
2141 pTxd->TBControl |= BMU_TCP_CHECK;
2143 pTxd->TBControl |= BMU_UDP_CHECK;
2146 pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
2150 ** Do we have the last fragment?
2152 if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
2153 #ifdef USE_TX_COMPLETE
2154 pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
2156 pTxd->TBControl |= BMU_EOF | sk_frag->size;
2158 pTxdFst->TBControl |= BMU_OWN | BMU_SW;
2161 pTxd->TBControl |= sk_frag->size;
2164 pTxd = pTxd->pNextTxd;
2165 pTxPort->TxdRingFree--;
2166 BytesSend += sk_frag->size;
2170 ** If previous descriptor already done, give TX start cmd
2172 if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
2173 SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
2176 pTxPort->pTxdRingPrev = pTxdLst;
2177 pTxPort->pTxdRingHead = pTxd;
2179 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2181 if (pTxPort->TxdRingFree > 0) {
2188 /*****************************************************************************
2190 * FreeTxDescriptors - release descriptors from the descriptor ring
2193 * This function releases descriptors from a transmit ring if they
2194 * have been sent by the BMU.
2195 * If a descriptors is sent, it can be freed and the message can
2197 * The SOFTWARE controllable bit is used to prevent running around a
2198 * completely free ring for ever. If this bit is no set in the
2199 * frame (by XmitFrame), this frame has never been sent or is
2201 * The Tx descriptor ring lock must be held while calling this function !!!
2206 static void FreeTxDescriptors(
2207 SK_AC *pAC, /* pointer to the adapter context */
2208 TX_PORT *pTxPort) /* pointer to destination port structure */
2210 TXD *pTxd; /* pointer to the checked descriptor */
2211 TXD *pNewTail; /* pointer to 'end' of the ring */
2212 SK_U32 Control; /* TBControl field of descriptor */
2213 SK_U64 PhysAddr; /* address of DMA mapping */
2215 pNewTail = pTxPort->pTxdRingTail;
2218 ** loop forever; exits if BMU_SW bit not set in start frame
2219 ** or BMU_OWN bit set in any frame
2222 Control = pTxd->TBControl;
2223 if ((Control & BMU_SW) == 0) {
2225 ** software controllable bit is set in first
2226 ** fragment when given to BMU. Not set means that
2227 ** this fragment was never sent or is already
2228 ** freed ( -> ring completely free now).
2230 pTxPort->pTxdRingTail = pTxd;
2231 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2234 if (Control & BMU_OWN) {
2235 pTxPort->pTxdRingTail = pTxd;
2236 if (pTxPort->TxdRingFree > 0) {
2237 netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
2243 ** release the DMA mapping, because until not unmapped
2244 ** this buffer is considered being under control of the
2247 PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
2248 PhysAddr |= (SK_U64) pTxd->VDataLow;
2249 pci_unmap_page(pAC->PciDev, PhysAddr,
2253 if (Control & BMU_EOF)
2254 DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
2256 pTxPort->TxdRingFree++;
2257 pTxd->TBControl &= ~BMU_SW;
2258 pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
2259 } /* while(forever) */
2260 } /* FreeTxDescriptors */
2262 /*****************************************************************************
2264 * FillRxRing - fill the receive ring with valid descriptors
2267 * This function fills the receive ring descriptors with data
2268 * segments and makes them valid for the BMU.
2269 * The active ring is filled completely, if possible.
2270 * The non-active ring is filled only partial to save memory.
2272 * Description of rx ring structure:
2273 * head - points to the descriptor which will be used next by the BMU
2274 * tail - points to the next descriptor to give to the BMU
2278 static void FillRxRing(
2279 SK_AC *pAC, /* pointer to the adapter context */
2280 RX_PORT *pRxPort) /* ptr to port struct for which the ring
2283 unsigned long Flags;
2285 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2286 while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
2287 if(!FillRxDescriptor(pAC, pRxPort))
2290 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2294 /*****************************************************************************
2296 * FillRxDescriptor - fill one buffer into the receive ring
2299 * The function allocates a new receive buffer and
2300 * puts it into the next descriptor.
2303 * SK_TRUE - a buffer was added to the ring
2304 * SK_FALSE - a buffer could not be added
2306 static SK_BOOL FillRxDescriptor(
2307 SK_AC *pAC, /* pointer to the adapter context struct */
2308 RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
2310 struct sk_buff *pMsgBlock; /* pointer to a new message block */
2311 RXD *pRxd; /* the rxd to fill */
2312 SK_U16 Length; /* data fragment length */
2313 SK_U64 PhysAddr; /* physical address of a rx buffer */
2315 pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
2316 if (pMsgBlock == NULL) {
2317 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2318 SK_DBGCAT_DRV_ENTRY,
2319 ("%s: Allocation of rx buffer failed !\n",
2320 pAC->dev[pRxPort->PortIndex]->name));
2321 SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
2324 skb_reserve(pMsgBlock, 2); /* to align IP frames */
2325 /* skb allocated ok, so add buffer */
2326 pRxd = pRxPort->pRxdRingTail;
2327 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2328 pRxPort->RxdRingFree--;
2329 Length = pAC->RxBufSize;
2330 PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
2331 virt_to_page(pMsgBlock->data),
2332 ((unsigned long) pMsgBlock->data &
2335 PCI_DMA_FROMDEVICE);
2337 pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
2338 pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
2339 pRxd->pMBuf = pMsgBlock;
2340 pRxd->RBControl = BMU_OWN |
2347 } /* FillRxDescriptor */
2350 /*****************************************************************************
2352 * ReQueueRxBuffer - fill one buffer back into the receive ring
2355 * Fill a given buffer back into the rx ring. The buffer
2356 * has been previously allocated and aligned, and its phys.
2357 * address calculated, so this is no more necessary.
2361 static void ReQueueRxBuffer(
2362 SK_AC *pAC, /* pointer to the adapter context struct */
2363 RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
2364 struct sk_buff *pMsg, /* pointer to the buffer */
2365 SK_U32 PhysHigh, /* phys address high dword */
2366 SK_U32 PhysLow) /* phys address low dword */
2368 RXD *pRxd; /* the rxd to fill */
2369 SK_U16 Length; /* data fragment length */
2371 pRxd = pRxPort->pRxdRingTail;
2372 pRxPort->pRxdRingTail = pRxd->pNextRxd;
2373 pRxPort->RxdRingFree--;
2374 Length = pAC->RxBufSize;
2376 pRxd->VDataLow = PhysLow;
2377 pRxd->VDataHigh = PhysHigh;
2379 pRxd->RBControl = BMU_OWN |
2385 } /* ReQueueRxBuffer */
2387 /*****************************************************************************
2389 * ReceiveIrq - handle a receive IRQ
2392 * This function is called when a receive IRQ is set.
2393 * It walks the receive descriptor ring and sends up all
2394 * frames that are complete.
2398 static void ReceiveIrq(
2399 SK_AC *pAC, /* pointer to adapter context */
2400 RX_PORT *pRxPort, /* pointer to receive port struct */
2401 SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
2403 RXD *pRxd; /* pointer to receive descriptors */
2404 SK_U32 Control; /* control field of descriptor */
2405 struct sk_buff *pMsg; /* pointer to message holding frame */
2406 struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
2407 int FrameLength; /* total length of received frame */
2409 SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
2410 SK_EVPARA EvPara; /* an event parameter union */
2411 unsigned long Flags; /* for spin lock */
2412 int PortIndex = pRxPort->PortIndex;
2413 unsigned int Offset;
2414 unsigned int NumBytes;
2415 unsigned int ForRlmt;
2418 SK_BOOL IsBadFrame; /* Bad frame */
2421 unsigned short Csum1;
2422 unsigned short Csum2;
2423 unsigned short Type;
2428 /* do forever; exit if BMU_OWN found */
2429 for ( pRxd = pRxPort->pRxdRingHead ;
2430 pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
2431 pRxd = pRxd->pNextRxd,
2432 pRxPort->pRxdRingHead = pRxd,
2433 pRxPort->RxdRingFree ++) {
2436 * For a better understanding of this loop
2437 * Go through every descriptor beginning at the head
2438 * Please note: the ring might be completely received so the OWN bit
2439 * set is not a good crirteria to leave that loop.
2440 * Therefore the RingFree counter is used.
2441 * On entry of this loop pRxd is a pointer to the Rxd that needs
2442 * to be checked next.
2445 Control = pRxd->RBControl;
2447 /* check if this descriptor is ready */
2448 if ((Control & BMU_OWN) != 0) {
2449 /* this descriptor is not yet ready */
2450 /* This is the usual end of the loop */
2451 /* We don't need to start the ring again */
2452 FillRxRing(pAC, pRxPort);
2455 pAC->DynIrqModInfo.NbrProcessedDescr++;
2457 /* get length of frame and check it */
2458 FrameLength = Control & BMU_BBC;
2459 if (FrameLength > pAC->RxBufSize) {
2463 /* check for STF and EOF */
2464 if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
2468 /* here we have a complete frame in the ring */
2471 FrameStat = pRxd->FrameStat;
2473 /* check for frame length mismatch */
2474 #define XMR_FS_LEN_SHIFT 18
2475 #define GMR_FS_LEN_SHIFT 16
2476 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2477 if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
2478 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2479 SK_DBGCAT_DRV_RX_PROGRESS,
2480 ("skge: Frame length mismatch (%u/%u).\n",
2482 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2487 if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
2488 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2489 SK_DBGCAT_DRV_RX_PROGRESS,
2490 ("skge: Frame length mismatch (%u/%u).\n",
2492 (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
2498 if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
2499 IsBc = (FrameStat & XMR_FS_BC) != 0;
2500 IsMc = (FrameStat & XMR_FS_MC) != 0;
2501 IsBadFrame = (FrameStat &
2502 (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
2504 IsBc = (FrameStat & GMR_FS_BC) != 0;
2505 IsMc = (FrameStat & GMR_FS_MC) != 0;
2506 IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
2507 ((FrameStat & GMR_FS_RX_OK) == 0));
2510 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2511 ("Received frame of length %d on port %d\n",
2512 FrameLength, PortIndex));
2513 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
2514 ("Number of free rx descriptors: %d\n",
2515 pRxPort->RxdRingFree));
2516 /* DumpMsg(pMsg, "Rx"); */
2518 if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
2520 (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
2522 /* there is a receive error in this frame */
2523 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2524 SK_DBGCAT_DRV_RX_PROGRESS,
2525 ("skge: Error in received frame, dropped!\n"
2526 "Control: %x\nRxStat: %x\n",
2527 Control, FrameStat));
2529 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2530 PhysAddr |= (SK_U64) pRxd->VDataLow;
2531 pci_dma_sync_single(pAC->PciDev,
2532 (dma_addr_t) PhysAddr,
2534 PCI_DMA_FROMDEVICE);
2535 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2536 pRxd->VDataHigh, pRxd->VDataLow);
2542 * if short frame then copy data to reduce memory waste
2544 if ((FrameLength < SK_COPY_THRESHOLD) &&
2545 ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
2547 * Short frame detected and allocation successfull
2549 /* use new skb and copy data */
2550 skb_reserve(pNewMsg, 2);
2551 skb_put(pNewMsg, FrameLength);
2552 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2553 PhysAddr |= (SK_U64) pRxd->VDataLow;
2555 pci_dma_sync_single(pAC->PciDev,
2556 (dma_addr_t) PhysAddr,
2558 PCI_DMA_FROMDEVICE);
2559 eth_copy_and_sum(pNewMsg, pMsg->data,
2561 ReQueueRxBuffer(pAC, pRxPort, pMsg,
2562 pRxd->VDataHigh, pRxd->VDataLow);
2569 * if large frame, or SKB allocation failed, pass
2570 * the SKB directly to the networking
2573 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2574 PhysAddr |= (SK_U64) pRxd->VDataLow;
2576 /* release the DMA mapping */
2577 pci_unmap_single(pAC->PciDev,
2580 PCI_DMA_FROMDEVICE);
2582 /* set length in message */
2583 skb_put(pMsg, FrameLength);
2584 /* hardware checksum */
2585 Type = ntohs(*((short*)&pMsg->data[12]));
2587 #ifdef USE_SK_RX_CHECKSUM
2588 if (Type == 0x800) {
2589 Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
2590 Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
2591 IpFrameLength = (int) ntohs((unsigned short)
2592 ((unsigned short *) pMsg->data)[8]);
2595 * Test: If frame is padded, a check is not possible!
2596 * Frame not padded? Length difference must be 14 (0xe)!
2598 if ((FrameLength - IpFrameLength) != 0xe) {
2599 /* Frame padded => TCP offload not possible! */
2600 pMsg->ip_summed = CHECKSUM_NONE;
2602 /* Frame not padded => TCP offload! */
2603 if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
2604 (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
2605 (pAC->ChipsetType)) {
2606 Result = SkCsGetReceiveInfo(pAC,
2608 Csum1, Csum2, pRxPort->PortIndex);
2610 SKCS_STATUS_IP_FRAGMENT ||
2612 SKCS_STATUS_IP_CSUM_OK ||
2614 SKCS_STATUS_TCP_CSUM_OK ||
2616 SKCS_STATUS_UDP_CSUM_OK) {
2618 CHECKSUM_UNNECESSARY;
2621 SKCS_STATUS_TCP_CSUM_ERROR ||
2623 SKCS_STATUS_UDP_CSUM_ERROR ||
2625 SKCS_STATUS_IP_CSUM_ERROR_UDP ||
2627 SKCS_STATUS_IP_CSUM_ERROR_TCP ||
2629 SKCS_STATUS_IP_CSUM_ERROR ) {
2630 /* HW Checksum error */
2631 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2632 SK_DBGCAT_DRV_RX_PROGRESS,
2633 ("skge: CRC error. Frame dropped!\n"));
2639 }/* checksumControl calculation valid */
2640 } /* Frame length check */
2643 pMsg->ip_summed = CHECKSUM_NONE;
2645 } /* frame > SK_COPY_TRESHOLD */
2647 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
2648 ForRlmt = SK_RLMT_RX_PROTOCOL;
2650 IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
2652 SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
2653 IsBc, &Offset, &NumBytes);
2654 if (NumBytes != 0) {
2656 IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
2658 SK_RLMT_LOOKAHEAD(pAC, PortIndex,
2659 &pMsg->data[Offset],
2660 IsBc, IsMc, &ForRlmt);
2662 if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
2663 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
2664 /* send up only frames from active port */
2665 if ((PortIndex == pAC->ActivePort) ||
2666 (pAC->RlmtNets == 2)) {
2667 /* frame for upper layer */
2668 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
2670 DumpMsg(pMsg, "Rx");
2672 SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
2673 FrameLength, pRxPort->PortIndex);
2675 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2676 pMsg->protocol = eth_type_trans(pMsg,
2677 pAC->dev[pRxPort->PortIndex]);
2679 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2683 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2684 SK_DBGCAT_DRV_RX_PROGRESS,
2686 DEV_KFREE_SKB(pMsg);
2689 } /* if not for rlmt */
2691 /* packet for rlmt */
2692 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2693 SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
2694 pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
2695 pAC->IoBase, FrameLength);
2696 if (pRlmtMbuf != NULL) {
2697 pRlmtMbuf->pNext = NULL;
2698 pRlmtMbuf->Length = FrameLength;
2699 pRlmtMbuf->PortIdx = PortIndex;
2700 EvPara.pParaPtr = pRlmtMbuf;
2701 memcpy((char*)(pRlmtMbuf->pData),
2702 (char*)(pMsg->data),
2705 /* SlowPathLock needed? */
2706 if (SlowPathLock == SK_TRUE) {
2707 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2708 SkEventQueue(pAC, SKGE_RLMT,
2709 SK_RLMT_PACKET_RECEIVED,
2711 pAC->CheckQueue = SK_TRUE;
2712 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2714 SkEventQueue(pAC, SKGE_RLMT,
2715 SK_RLMT_PACKET_RECEIVED,
2717 pAC->CheckQueue = SK_TRUE;
2720 SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
2721 SK_DBGCAT_DRV_RX_PROGRESS,
2724 if ((pAC->dev[pRxPort->PortIndex]->flags &
2725 (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
2726 (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
2727 SK_RLMT_RX_PROTOCOL) {
2728 pMsg->dev = pAC->dev[pRxPort->PortIndex];
2729 pMsg->protocol = eth_type_trans(pMsg,
2730 pAC->dev[pRxPort->PortIndex]);
2732 pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
2735 DEV_KFREE_SKB(pMsg);
2738 } /* if packet for rlmt */
2739 } /* for ... scanning the RXD ring */
2741 /* RXD ring is empty -> fill and restart */
2742 FillRxRing(pAC, pRxPort);
2743 /* do not start if called from Close */
2744 if (pAC->BoardLevel > SK_INIT_DATA) {
2745 ClearAndStartRx(pAC, PortIndex);
2750 /* remove error frame */
2751 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
2752 ("Schrottdescriptor, length: 0x%x\n", FrameLength));
2754 /* release the DMA mapping */
2756 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2757 PhysAddr |= (SK_U64) pRxd->VDataLow;
2758 pci_unmap_page(pAC->PciDev,
2761 PCI_DMA_FROMDEVICE);
2762 DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
2764 pRxPort->RxdRingFree++;
2765 pRxPort->pRxdRingHead = pRxd->pNextRxd;
2771 /*****************************************************************************
2773 * ClearAndStartRx - give a start receive command to BMU, clear IRQ
2776 * This function sends a start command and a clear interrupt
2777 * command for one receive queue to the BMU.
2782 static void ClearAndStartRx(
2783 SK_AC *pAC, /* pointer to the adapter context */
2784 int PortIndex) /* index of the receive port (XMAC) */
2786 SK_OUT8(pAC->IoBase,
2787 RxQueueAddr[PortIndex]+Q_CSR,
2788 CSR_START | CSR_IRQ_CL_F);
2789 } /* ClearAndStartRx */
2792 /*****************************************************************************
2794 * ClearTxIrq - give a clear transmit IRQ command to BMU
2797 * This function sends a clear tx IRQ command for one
2798 * transmit queue to the BMU.
2802 static void ClearTxIrq(
2803 SK_AC *pAC, /* pointer to the adapter context */
2804 int PortIndex, /* index of the transmit port (XMAC) */
2805 int Prio) /* priority or normal queue */
2807 SK_OUT8(pAC->IoBase,
2808 TxQueueAddr[PortIndex][Prio]+Q_CSR,
2813 /*****************************************************************************
2815 * ClearRxRing - remove all buffers from the receive ring
2818 * This function removes all receive buffers from the ring.
2819 * The receive BMU must be stopped before calling this function.
2823 static void ClearRxRing(
2824 SK_AC *pAC, /* pointer to adapter context */
2825 RX_PORT *pRxPort) /* pointer to rx port struct */
2827 RXD *pRxd; /* pointer to the current descriptor */
2828 unsigned long Flags;
2831 if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
2834 spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
2835 pRxd = pRxPort->pRxdRingHead;
2837 if (pRxd->pMBuf != NULL) {
2839 PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
2840 PhysAddr |= (SK_U64) pRxd->VDataLow;
2841 pci_unmap_page(pAC->PciDev,
2844 PCI_DMA_FROMDEVICE);
2845 DEV_KFREE_SKB(pRxd->pMBuf);
2848 pRxd->RBControl &= BMU_OWN;
2849 pRxd = pRxd->pNextRxd;
2850 pRxPort->RxdRingFree++;
2851 } while (pRxd != pRxPort->pRxdRingTail);
2852 pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
2853 spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
2856 /*****************************************************************************
2858 * ClearTxRing - remove all buffers from the transmit ring
2861 * This function removes all transmit buffers from the ring.
2862 * The transmit BMU must be stopped before calling this function
2863 * and transmitting at the upper level must be disabled.
2864 * The BMU own bit of all descriptors is cleared, the rest is
2865 * done by calling FreeTxDescriptors.
2869 static void ClearTxRing(
2870 SK_AC *pAC, /* pointer to adapter context */
2871 TX_PORT *pTxPort) /* pointer to tx prt struct */
2873 TXD *pTxd; /* pointer to the current descriptor */
2875 unsigned long Flags;
2877 spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
2878 pTxd = pTxPort->pTxdRingHead;
2879 for (i=0; i<pAC->TxDescrPerRing; i++) {
2880 pTxd->TBControl &= ~BMU_OWN;
2881 pTxd = pTxd->pNextTxd;
2883 FreeTxDescriptors(pAC, pTxPort);
2884 spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
2887 /*****************************************************************************
2889 * SkGeSetMacAddr - Set the hardware MAC address
2892 * This function sets the MAC address used by the adapter.
2895 * 0, if everything is ok
2898 static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
2901 DEV_NET *pNet = (DEV_NET*) dev->priv;
2902 SK_AC *pAC = pNet->pAC;
2904 struct sockaddr *addr = p;
2905 unsigned long Flags;
2907 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2908 ("SkGeSetMacAddr starts now...\n"));
2909 if(netif_running(dev))
2912 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
2914 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2916 if (pAC->RlmtNets == 2)
2917 SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
2918 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2920 SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
2921 (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
2925 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
2927 } /* SkGeSetMacAddr */
2930 /*****************************************************************************
2932 * SkGeSetRxMode - set receive mode
2935 * This function sets the receive mode of an adapter. The adapter
2936 * supports promiscuous mode, allmulticast mode and a number of
2937 * multicast addresses. If more multicast addresses the available
2938 * are selected, a hash function in the hardware is used.
2941 * 0, if everything is ok
2944 static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
2950 struct dev_mc_list *pMcList;
2953 unsigned long Flags;
2955 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2956 ("SkGeSetRxMode starts now... "));
2958 pNet = (DEV_NET*) dev->priv;
2960 if (pAC->RlmtNets == 1)
2961 PortIdx = pAC->ActivePort;
2963 PortIdx = pNet->NetNr;
2965 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
2966 if (dev->flags & IFF_PROMISC) {
2967 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2968 ("PROMISCUOUS mode\n"));
2969 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2971 } else if (dev->flags & IFF_ALLMULTI) {
2972 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2973 ("ALLMULTI mode\n"));
2974 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2975 SK_PROM_MODE_ALL_MC);
2977 SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
2979 SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
2981 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
2982 ("Number of MC entries: %d ", dev->mc_count));
2984 pMcList = dev->mc_list;
2985 for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
2986 SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
2987 (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
2988 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
2989 ("%02x:%02x:%02x:%02x:%02x:%02x\n",
2990 pMcList->dmi_addr[0],
2991 pMcList->dmi_addr[1],
2992 pMcList->dmi_addr[2],
2993 pMcList->dmi_addr[3],
2994 pMcList->dmi_addr[4],
2995 pMcList->dmi_addr[5]));
2997 SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
2999 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3002 } /* SkGeSetRxMode */
3005 /*****************************************************************************
3007 * SkGeChangeMtu - set the MTU to another value
3010 * This function sets is called whenever the MTU size is changed
3011 * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
3012 * ethernet MTU size, long frame support is activated.
3015 * 0, if everything is ok
3018 static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
3023 unsigned long Flags;
3027 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3028 ("SkGeChangeMtu starts now...\n"));
3030 pNet = (DEV_NET*) dev->priv;
3033 if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
3037 if(pAC->BoardLevel != SK_INIT_RUN) {
3041 #ifdef SK_DIAG_SUPPORT
3042 if (pAC->DiagModeActive == DIAG_ACTIVE) {
3043 if (pAC->DiagFlowCtrl == SK_FALSE) {
3044 return -1; /* still in use, deny any actions of MTU */
3046 pAC->DiagFlowCtrl = SK_FALSE;
3052 pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
3053 if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
3057 pAC->RxBufSize = NewMtu + 32;
3060 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3061 ("New MTU: %d\n", NewMtu));
3064 ** Prevent any reconfiguration while changing the MTU
3065 ** by disabling any interrupts
3067 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
3068 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3071 ** Notify RLMT that any ports are to be stopped
3073 EvPara.Para32[0] = 0;
3074 EvPara.Para32[1] = -1;
3075 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3076 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3077 EvPara.Para32[0] = 1;
3078 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3080 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
3084 ** After calling the SkEventDispatcher(), RLMT is aware about
3085 ** the stopped ports -> configuration can take place!
3087 SkEventDispatcher(pAC, pAC->IoBase);
3089 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3091 &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
3092 netif_stop_queue(pAC->dev[i]);
3097 ** Depending on the desired MTU size change, a different number of
3098 ** RX buffers need to be allocated
3100 if (NewMtu > 1500) {
3102 ** Use less rx buffers
3104 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3105 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3106 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3107 (pAC->RxDescrPerRing / 4);
3109 if (i == pAC->ActivePort) {
3110 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3111 (pAC->RxDescrPerRing / 4);
3113 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3114 (pAC->RxDescrPerRing / 10);
3120 ** Use the normal amount of rx buffers
3122 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3123 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3124 pAC->RxPort[i].RxFillLimit = 1;
3126 if (i == pAC->ActivePort) {
3127 pAC->RxPort[i].RxFillLimit = 1;
3129 pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
3130 (pAC->RxDescrPerRing / 4);
3136 SkGeDeInit(pAC, pAC->IoBase);
3139 ** enable/disable hardware support for long frames
3141 if (NewMtu > 1500) {
3142 // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
3143 pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
3145 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3146 pAC->GIni.GIPortUsage = SK_MUL_LINK;
3148 pAC->GIni.GIPortUsage = SK_RED_LINK;
3152 SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
3153 SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
3154 SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
3155 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
3156 SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
3157 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
3158 SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
3162 ** Speed and others are set back to default in level 1 init!
3164 GetConfiguration(pAC);
3166 SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
3167 SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
3168 SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
3169 SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
3170 SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
3171 SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
3172 SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
3175 ** clear and reinit the rx rings here
3177 for (i=0; i<pAC->GIni.GIMacsFound; i++) {
3178 ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
3179 ClearRxRing(pAC, &pAC->RxPort[i]);
3180 FillRxRing(pAC, &pAC->RxPort[i]);
3183 ** Enable transmit descriptor polling
3185 SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
3186 FillRxRing(pAC, &pAC->RxPort[i]);
3189 SkGeYellowLED(pAC, pAC->IoBase, 1);
3190 SkDimEnableModerationIfNeeded(pAC);
3191 SkDimDisplayModerationSettings(pAC);
3193 netif_start_queue(pAC->dev[pNet->PortNr]);
3194 for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
3195 spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
3199 ** Enable Interrupts again
3201 SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
3202 SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
3204 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3205 SkEventDispatcher(pAC, pAC->IoBase);
3208 ** Notify RLMT about the changing and restarting one (or more) ports
3210 if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
3211 EvPara.Para32[0] = pAC->RlmtNets;
3212 EvPara.Para32[1] = -1;
3213 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
3214 EvPara.Para32[0] = pNet->PortNr;
3215 EvPara.Para32[1] = -1;
3216 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3218 if (pOtherNet->Up) {
3219 EvPara.Para32[0] = pOtherNet->PortNr;
3220 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3223 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
3226 SkEventDispatcher(pAC, pAC->IoBase);
3227 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3230 ** While testing this driver with latest kernel 2.5 (2.5.70), it
3231 ** seems as if upper layers have a problem to handle a successful
3232 ** return value of '0'. If such a zero is returned, the complete
3233 ** system hangs for several minutes (!), which is in acceptable.
3235 ** Currently it is not clear, what the exact reason for this problem
3236 ** is. The implemented workaround for 2.5 is to return the desired
3237 ** new MTU size if all needed changes for the new MTU size where
3238 ** performed. In kernels 2.2 and 2.4, a zero value is returned,
3239 ** which indicates the successful change of the mtu-size.
3243 } /* SkGeChangeMtu */
3246 /*****************************************************************************
3248 * SkGeStats - return ethernet device statistics
3251 * This function return statistic data about the ethernet device
3252 * to the operating system.
3255 * pointer to the statistic structure.
3257 static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
3259 DEV_NET *pNet = (DEV_NET*) dev->priv;
3260 SK_AC *pAC = pNet->pAC;
3261 SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
3262 SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
3263 SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
3264 unsigned int Size; /* size of pnmi struct */
3265 unsigned long Flags; /* for spin lock */
3267 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3268 ("SkGeStats starts now...\n"));
3269 pPnmiStruct = &pAC->PnmiStruct;
3271 #ifdef SK_DIAG_SUPPORT
3272 if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
3273 (pAC->BoardLevel == SK_INIT_RUN)) {
3275 SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
3276 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3277 Size = SK_PNMI_STRUCT_SIZE;
3278 SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
3279 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3280 #ifdef SK_DIAG_SUPPORT
3284 pPnmiStat = &pPnmiStruct->Stat[0];
3285 pPnmiConf = &pPnmiStruct->Conf[0];
3287 pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
3288 pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
3289 pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
3290 pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
3292 if (pNet->Mtu <= 1500) {
3293 pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
3295 pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
3296 pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
3300 if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
3301 pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
3303 pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3304 pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
3305 pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
3306 pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
3307 pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
3309 /* detailed rx_errors: */
3310 pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
3311 pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3312 pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
3313 pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
3314 pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
3315 pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
3317 /* detailed tx_errors */
3318 pAC->stats.tx_aborted_errors = (SK_U32) 0;
3319 pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3320 pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
3321 pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
3322 pAC->stats.tx_window_errors = (SK_U32) 0;
3324 return(&pAC->stats);
3328 /*****************************************************************************
3330 * SkGeIoctl - IO-control function
3333 * This function is called if an ioctl is issued on the device.
3334 * There are three subfunction for reading, writing and test-writing
3335 * the private MIB data structure (usefull for SysKonnect-internal tools).
3338 * 0, if everything is ok
3341 static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
3346 struct pci_dev *pdev = NULL;
3348 unsigned int Err = 0;
3351 unsigned int Length = 0;
3352 int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
3354 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3355 ("SkGeIoctl starts now...\n"));
3357 pNet = (DEV_NET*) dev->priv;
3360 if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
3365 case SK_IOCTL_SETMIB:
3366 case SK_IOCTL_PRESETMIB:
3367 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3368 case SK_IOCTL_GETMIB:
3369 if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
3370 Ioctl.Len<sizeof(pAC->PnmiStruct)?
3371 Ioctl.Len : sizeof(pAC->PnmiStruct))) {
3374 Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
3375 if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
3376 Ioctl.Len<Size? Ioctl.Len : Size)) {
3380 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3385 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3388 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3390 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3393 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3397 if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
3401 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3406 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3411 kfree(pMemBuf); /* cleanup everything */
3413 #ifdef SK_DIAG_SUPPORT
3415 if (!capable(CAP_NET_ADMIN)) return -EPERM;
3416 if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
3419 Length = sizeof(pAC->PnmiStruct) + HeaderLength;
3421 if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
3424 if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
3429 Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
3431 ** While coding this new IOCTL interface, only a few lines of code
3432 ** are to to be added. Therefore no dedicated function has been
3433 ** added. If more functionality is added, a separate function
3434 ** should be used...
3436 * ((SK_U32 *)pMemBuf) = 0;
3437 * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
3438 * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pdev->slot_name);
3439 if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
3444 if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
3449 kfree(pMemBuf); /* cleanup everything */
3461 /*****************************************************************************
3463 * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
3466 * This function reads/writes the MIB data using PNMI (Private Network
3467 * Management Interface).
3468 * The destination for the data must be provided with the
3469 * ioctl call and is given to the driver in the form of
3470 * a user space address.
3471 * Copying from the user-provided data area into kernel messages
3472 * and back is done by copy_from_user and copy_to_user calls in
3476 * returned size from PNMI call
3478 static int SkGeIocMib(
3479 DEV_NET *pNet, /* pointer to the adapter context */
3480 unsigned int Size, /* length of ioctl data */
3481 int mode) /* flag for set/preset */
3483 unsigned long Flags; /* for spin lock */
3486 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3487 ("SkGeIocMib starts now...\n"));
3490 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
3492 case SK_IOCTL_GETMIB:
3493 SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3496 case SK_IOCTL_PRESETMIB:
3497 SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3500 case SK_IOCTL_SETMIB:
3501 SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
3507 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
3508 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
3509 ("MIB data access succeeded\n"));
3514 /*****************************************************************************
3516 * GetConfiguration - read configuration information
3519 * This function reads per-adapter configuration information from
3520 * the options provided on the command line.
3525 static void GetConfiguration(
3526 SK_AC *pAC) /* pointer to the adapter context structure */
3528 SK_I32 Port; /* preferred port */
3531 int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
3532 int AutoNeg = 1; /* autoneg off (0) or on (1) */
3533 int DuplexCap = 0; /* 0=both,1=full,2=half */
3534 int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
3535 int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
3537 SK_BOOL IsConTypeDefined = SK_TRUE;
3538 SK_BOOL IsLinkSpeedDefined = SK_TRUE;
3539 SK_BOOL IsFlowCtrlDefined = SK_TRUE;
3540 SK_BOOL IsRoleDefined = SK_TRUE;
3541 SK_BOOL IsModeDefined = SK_TRUE;
3543 * The two parameters AutoNeg. and DuplexCap. map to one configuration
3544 * parameter. The mapping is described by this table:
3545 * DuplexCap -> | both | full | half |
3547 * -----------------------------------------------------------------
3548 * Off | illegal | Full | Half |
3549 * -----------------------------------------------------------------
3550 * On | AutoBoth | AutoFull | AutoHalf |
3551 * -----------------------------------------------------------------
3552 * Sense | AutoSense | AutoSense | AutoSense |
3554 int Capabilities[3][3] =
3555 { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
3556 {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
3557 {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
3565 #define M_CurrPort pAC->GIni.GP[Port]
3569 ** Set the default values first for both ports!
3571 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3572 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3573 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3574 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3575 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3579 ** Check merged parameter ConType. If it has not been used,
3580 ** verify any other parameter (e.g. AutoNeg) and use default values.
3582 ** Stating both ConType and other lowlevel link parameters is also
3583 ** possible. If this is the case, the passed ConType-parameter is
3584 ** overwritten by the lowlevel link parameter.
3586 ** The following settings are used for a merged ConType-parameter:
3588 ** ConType DupCap AutoNeg FlowCtrl Role Speed
3589 ** ------- ------ ------- -------- ---------- -----
3590 ** Auto Both On SymOrRem Auto Auto
3591 ** 100FD Full Off None <ignored> 100
3592 ** 100HD Half Off None <ignored> 100
3593 ** 10FD Full Off None <ignored> 10
3594 ** 10HD Half Off None <ignored> 10
3596 ** This ConType parameter is used for all ports of the adapter!
3598 if ( (ConType != NULL) &&
3599 (pAC->Index < SK_MAX_CARD_PARAM) &&
3600 (ConType[pAC->Index] != NULL) ) {
3602 /* Check chipset family */
3603 if ((!pAC->ChipsetType) &&
3604 (strcmp(ConType[pAC->Index],"Auto")!=0) &&
3605 (strcmp(ConType[pAC->Index],"")!=0)) {
3606 /* Set the speed parameter back */
3607 printk("sk98lin: Illegal value \"%s\" "
3610 ConType[pAC->Index]);
3612 sprintf(ConType[pAC->Index], "Auto");
3615 if (strcmp(ConType[pAC->Index],"")==0) {
3616 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3617 } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
3618 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3619 M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
3620 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
3621 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3622 M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
3624 } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
3625 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3626 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3627 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3628 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3629 M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
3631 } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
3632 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3633 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
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],"10FD")==0) {
3639 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3640 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
3641 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3642 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3643 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3645 } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
3646 for (Port = 0; Port < SK_MAX_MACS; Port++) {
3647 M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
3648 M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
3649 M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
3650 M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
3653 printk("sk98lin: Illegal value \"%s\" for ConType\n",
3654 ConType[pAC->Index]);
3655 IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
3658 IsConTypeDefined = SK_FALSE; /* No ConType defined */
3662 ** Parse any parameter settings for port A:
3663 ** a) any LinkSpeed stated?
3665 if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3666 Speed_A[pAC->Index] != NULL) {
3667 if (strcmp(Speed_A[pAC->Index],"")==0) {
3668 IsLinkSpeedDefined = SK_FALSE;
3669 } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
3670 LinkSpeed = SK_LSPEED_AUTO;
3671 } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
3672 LinkSpeed = SK_LSPEED_10MBPS;
3673 } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
3674 LinkSpeed = SK_LSPEED_100MBPS;
3675 } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
3676 LinkSpeed = SK_LSPEED_1000MBPS;
3678 printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
3679 Speed_A[pAC->Index]);
3680 IsLinkSpeedDefined = SK_FALSE;
3683 IsLinkSpeedDefined = SK_FALSE;
3687 ** Check speed parameter:
3688 ** Only copper type adapter and GE V2 cards
3690 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3691 ((LinkSpeed != SK_LSPEED_AUTO) &&
3692 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3693 printk("sk98lin: Illegal value for Speed_A. "
3694 "Not a copper card or GE V2 card\n Using "
3696 LinkSpeed = SK_LSPEED_1000MBPS;
3700 ** Decide whether to set new config value if somethig valid has
3703 if (IsLinkSpeedDefined) {
3704 pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
3708 ** b) Any Autonegotiation and DuplexCapabilities set?
3709 ** Please note that both belong together...
3711 AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
3713 if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3714 AutoNeg_A[pAC->Index] != NULL) {
3716 if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
3718 } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
3720 } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
3722 } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
3725 printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
3726 AutoNeg_A[pAC->Index]);
3730 DuplexCap = DC_BOTH;
3732 if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3733 DupCap_A[pAC->Index] != NULL) {
3735 if (strcmp(DupCap_A[pAC->Index],"")==0) {
3737 } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
3738 DuplexCap = DC_BOTH;
3739 } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
3740 DuplexCap = DC_FULL;
3741 } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
3742 DuplexCap = DC_HALF;
3744 printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
3745 DupCap_A[pAC->Index]);
3750 ** Check for illegal combinations
3752 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3753 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3754 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3755 (pAC->ChipsetType)) {
3756 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3757 " Using Full Duplex.\n");
3758 DuplexCap = DC_FULL;
3761 if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
3762 printk("sk98lin, Port A: DuplexCapabilities"
3763 " ignored using Sense mode\n");
3766 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3767 printk("sk98lin: Port A: Illegal combination"
3768 " of values AutoNeg. and DuplexCap.\n Using "
3770 DuplexCap = DC_FULL;
3773 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3774 DuplexCap = DC_FULL;
3777 if (!AutoSet && DupSet) {
3778 printk("sk98lin: Port A: Duplex setting not"
3779 " possible in\n default AutoNegotiation mode"
3780 " (Sense).\n Using AutoNegotiation On\n");
3785 ** set the desired mode
3787 if (AutoSet || DupSet) {
3788 pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3792 ** c) Any Flowcontrol-parameter set?
3794 if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3795 FlowCtrl_A[pAC->Index] != NULL) {
3796 if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
3797 IsFlowCtrlDefined = SK_FALSE;
3798 } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
3799 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3800 } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
3801 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
3802 } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
3803 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
3804 } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
3805 FlowCtrl = SK_FLOW_MODE_NONE;
3807 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
3808 FlowCtrl_A[pAC->Index]);
3809 IsFlowCtrlDefined = SK_FALSE;
3812 IsFlowCtrlDefined = SK_FALSE;
3815 if (IsFlowCtrlDefined) {
3816 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
3817 printk("sk98lin: Port A: FlowControl"
3818 " impossible without AutoNegotiation,"
3820 FlowCtrl = SK_FLOW_MODE_NONE;
3822 pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
3826 ** d) What is with the RoleParameter?
3828 if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3829 Role_A[pAC->Index] != NULL) {
3830 if (strcmp(Role_A[pAC->Index],"")==0) {
3831 IsRoleDefined = SK_FALSE;
3832 } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
3833 MSMode = SK_MS_MODE_AUTO;
3834 } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
3835 MSMode = SK_MS_MODE_MASTER;
3836 } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
3837 MSMode = SK_MS_MODE_SLAVE;
3839 printk("sk98lin: Illegal value \"%s\" for Role_A\n",
3840 Role_A[pAC->Index]);
3841 IsRoleDefined = SK_FALSE;
3844 IsRoleDefined = SK_FALSE;
3847 if (IsRoleDefined == SK_TRUE) {
3848 pAC->GIni.GP[0].PMSMode = MSMode;
3854 ** Parse any parameter settings for port B:
3855 ** a) any LinkSpeed stated?
3857 IsConTypeDefined = SK_TRUE;
3858 IsLinkSpeedDefined = SK_TRUE;
3859 IsFlowCtrlDefined = SK_TRUE;
3860 IsModeDefined = SK_TRUE;
3862 if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3863 Speed_B[pAC->Index] != NULL) {
3864 if (strcmp(Speed_B[pAC->Index],"")==0) {
3865 IsLinkSpeedDefined = SK_FALSE;
3866 } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
3867 LinkSpeed = SK_LSPEED_AUTO;
3868 } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
3869 LinkSpeed = SK_LSPEED_10MBPS;
3870 } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
3871 LinkSpeed = SK_LSPEED_100MBPS;
3872 } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
3873 LinkSpeed = SK_LSPEED_1000MBPS;
3875 printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
3876 Speed_B[pAC->Index]);
3877 IsLinkSpeedDefined = SK_FALSE;
3880 IsLinkSpeedDefined = SK_FALSE;
3884 ** Check speed parameter:
3885 ** Only copper type adapter and GE V2 cards
3887 if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
3888 ((LinkSpeed != SK_LSPEED_AUTO) &&
3889 (LinkSpeed != SK_LSPEED_1000MBPS))) {
3890 printk("sk98lin: Illegal value for Speed_B. "
3891 "Not a copper card or GE V2 card\n Using "
3893 LinkSpeed = SK_LSPEED_1000MBPS;
3897 ** Decide whether to set new config value if somethig valid has
3900 if (IsLinkSpeedDefined) {
3901 pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
3905 ** b) Any Autonegotiation and DuplexCapabilities set?
3906 ** Please note that both belong together...
3908 AutoNeg = AN_SENS; /* default: do auto Sense */
3910 if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3911 AutoNeg_B[pAC->Index] != NULL) {
3913 if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
3915 } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
3917 } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
3919 } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
3922 printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
3923 AutoNeg_B[pAC->Index]);
3927 DuplexCap = DC_BOTH;
3929 if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3930 DupCap_B[pAC->Index] != NULL) {
3932 if (strcmp(DupCap_B[pAC->Index],"")==0) {
3934 } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
3935 DuplexCap = DC_BOTH;
3936 } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
3937 DuplexCap = DC_FULL;
3938 } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
3939 DuplexCap = DC_HALF;
3941 printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
3942 DupCap_B[pAC->Index]);
3948 ** Check for illegal combinations
3950 if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
3951 ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
3952 (DuplexCap == SK_LMODE_STAT_HALF)) &&
3953 (pAC->ChipsetType)) {
3954 printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
3955 " Using Full Duplex.\n");
3956 DuplexCap = DC_FULL;
3959 if (AutoSet && AutoNeg==AN_SENS && DupSet) {
3960 printk("sk98lin, Port B: DuplexCapabilities"
3961 " ignored using Sense mode\n");
3964 if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
3965 printk("sk98lin: Port B: Illegal combination"
3966 " of values AutoNeg. and DuplexCap.\n Using "
3968 DuplexCap = DC_FULL;
3971 if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
3972 DuplexCap = DC_FULL;
3975 if (!AutoSet && DupSet) {
3976 printk("sk98lin: Port B: Duplex setting not"
3977 " possible in\n default AutoNegotiation mode"
3978 " (Sense).\n Using AutoNegotiation On\n");
3983 ** set the desired mode
3985 if (AutoSet || DupSet) {
3986 pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
3990 ** c) Any FlowCtrl parameter set?
3992 if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
3993 FlowCtrl_B[pAC->Index] != NULL) {
3994 if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
3995 IsFlowCtrlDefined = SK_FALSE;
3996 } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
3997 FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
3998 } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
3999 FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
4000 } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
4001 FlowCtrl = SK_FLOW_MODE_LOC_SEND;
4002 } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
4003 FlowCtrl = SK_FLOW_MODE_NONE;
4005 printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
4006 FlowCtrl_B[pAC->Index]);
4007 IsFlowCtrlDefined = SK_FALSE;
4010 IsFlowCtrlDefined = SK_FALSE;
4013 if (IsFlowCtrlDefined) {
4014 if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
4015 printk("sk98lin: Port B: FlowControl"
4016 " impossible without AutoNegotiation,"
4018 FlowCtrl = SK_FLOW_MODE_NONE;
4020 pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
4024 ** d) What is the RoleParameter?
4026 if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4027 Role_B[pAC->Index] != NULL) {
4028 if (strcmp(Role_B[pAC->Index],"")==0) {
4029 IsRoleDefined = SK_FALSE;
4030 } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
4031 MSMode = SK_MS_MODE_AUTO;
4032 } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
4033 MSMode = SK_MS_MODE_MASTER;
4034 } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
4035 MSMode = SK_MS_MODE_SLAVE;
4037 printk("sk98lin: Illegal value \"%s\" for Role_B\n",
4038 Role_B[pAC->Index]);
4039 IsRoleDefined = SK_FALSE;
4042 IsRoleDefined = SK_FALSE;
4045 if (IsRoleDefined) {
4046 pAC->GIni.GP[1].PMSMode = MSMode;
4050 ** Evaluate settings for both ports
4052 pAC->ActivePort = 0;
4053 if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4054 PrefPort[pAC->Index] != NULL) {
4055 if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
4056 pAC->ActivePort = 0;
4057 pAC->Rlmt.Net[0].Preference = -1; /* auto */
4058 pAC->Rlmt.Net[0].PrefPort = 0;
4059 } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
4061 ** do not set ActivePort here, thus a port
4062 ** switch is issued after net up.
4065 pAC->Rlmt.Net[0].Preference = Port;
4066 pAC->Rlmt.Net[0].PrefPort = Port;
4067 } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
4069 ** do not set ActivePort here, thus a port
4070 ** switch is issued after net up.
4072 if (pAC->GIni.GIMacsFound == 1) {
4073 printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
4074 " Port B not available on single port adapters.\n");
4076 pAC->ActivePort = 0;
4077 pAC->Rlmt.Net[0].Preference = -1; /* auto */
4078 pAC->Rlmt.Net[0].PrefPort = 0;
4081 pAC->Rlmt.Net[0].Preference = Port;
4082 pAC->Rlmt.Net[0].PrefPort = Port;
4085 printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
4086 PrefPort[pAC->Index]);
4092 if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
4093 RlmtMode[pAC->Index] != NULL) {
4094 if (strcmp(RlmtMode[pAC->Index], "") == 0) {
4096 } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
4097 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4098 } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
4099 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4100 SK_RLMT_CHECK_LOC_LINK;
4101 } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
4102 pAC->RlmtMode = SK_RLMT_CHECK_LINK |
4103 SK_RLMT_CHECK_LOC_LINK |
4105 } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
4106 (pAC->GIni.GIMacsFound == 2)) {
4107 pAC->RlmtMode = SK_RLMT_CHECK_LINK;
4110 printk("sk98lin: Illegal value \"%s\" for"
4111 " RlmtMode, using default\n",
4112 RlmtMode[pAC->Index]);
4120 ** Check the interrupt moderation parameters
4122 if (Moderation[pAC->Index] != NULL) {
4123 if (strcmp(Moderation[pAC->Index], "") == 0) {
4124 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4125 } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
4126 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
4127 } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
4128 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
4129 } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
4130 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4132 printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
4133 " Disable interrupt moderation.\n",
4134 Moderation[pAC->Index]);
4135 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4138 pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
4141 if (Stats[pAC->Index] != NULL) {
4142 if (strcmp(Stats[pAC->Index], "Yes") == 0) {
4143 pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
4145 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
4148 pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
4151 if (ModerationMask[pAC->Index] != NULL) {
4152 if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
4153 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
4154 } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
4155 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
4156 } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
4157 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
4158 } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
4159 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
4160 } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
4161 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
4162 } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
4163 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4164 } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
4165 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4166 } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
4167 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
4168 } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
4169 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
4170 } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
4171 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4172 } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
4173 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4174 } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
4175 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4176 } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
4177 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4178 } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
4179 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4180 } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
4181 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
4182 } else { /* some rubbish */
4183 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
4185 } else { /* operator has stated nothing */
4186 pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
4189 if (AutoSizing[pAC->Index] != NULL) {
4190 if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
4191 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4193 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4195 } else { /* operator has stated nothing */
4196 pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
4199 if (IntsPerSec[pAC->Index] != 0) {
4200 if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
4201 (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
4202 printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
4203 " Using default value of %i.\n",
4204 IntsPerSec[pAC->Index],
4205 C_INT_MOD_IPS_LOWER_RANGE,
4206 C_INT_MOD_IPS_UPPER_RANGE,
4207 C_INTS_PER_SEC_DEFAULT);
4208 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
4210 pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
4213 pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
4217 ** Evaluate upper and lower moderation threshold
4219 pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
4220 pAC->DynIrqModInfo.MaxModIntsPerSec +
4221 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
4223 pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
4224 pAC->DynIrqModInfo.MaxModIntsPerSec -
4225 (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
4227 pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
4230 } /* GetConfiguration */
4233 /*****************************************************************************
4235 * ProductStr - return a adapter identification string from vpd
4238 * This function reads the product name string from the vpd area
4239 * and puts it the field pAC->DeviceString.
4243 static void ProductStr(
4244 SK_AC *pAC /* pointer to adapter context */
4247 int StrLen = 80; /* length of the string, defined in SK_AC */
4248 char Keyword[] = VPD_NAME; /* vpd productname identifier */
4249 int ReturnCode; /* return code from vpd_read */
4250 unsigned long Flags;
4252 spin_lock_irqsave(&pAC->SlowPathLock, Flags);
4253 ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
4255 spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
4256 if (ReturnCode != 0) {
4257 /* there was an error reading the vpd data */
4258 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
4259 ("Error reading VPD data: %d\n", ReturnCode));
4260 pAC->DeviceStr[0] = '\0';
4264 /*****************************************************************************
4266 * StartDrvCleanupTimer - Start timer to check for descriptors which
4267 * might be placed in descriptor ring, but
4268 * havent been handled up to now
4271 * This function requests a HW-timer fo the Yukon card. The actions to
4272 * perform when this timer expires, are located in the SkDrvEvent().
4277 StartDrvCleanupTimer(SK_AC *pAC) {
4278 SK_EVPARA EventParam; /* Event struct for timer event */
4280 SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
4281 EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
4282 SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
4283 SK_DRV_RX_CLEANUP_TIMER_LENGTH,
4284 SKGE_DRV, SK_DRV_TIMER, EventParam);
4287 /*****************************************************************************
4289 * StopDrvCleanupTimer - Stop timer to check for descriptors
4292 * This function requests a HW-timer fo the Yukon card. The actions to
4293 * perform when this timer expires, are located in the SkDrvEvent().
4298 StopDrvCleanupTimer(SK_AC *pAC) {
4299 SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
4300 SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
4303 /****************************************************************************/
4304 /* functions for common modules *********************************************/
4305 /****************************************************************************/
4308 /*****************************************************************************
4310 * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
4313 * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
4314 * is embedded into a socket buff data area.
4320 * NULL or pointer to Mbuf.
4322 SK_MBUF *SkDrvAllocRlmtMbuf(
4323 SK_AC *pAC, /* pointer to adapter context */
4324 SK_IOC IoC, /* the IO-context */
4325 unsigned BufferSize) /* size of the requested buffer */
4327 SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
4328 struct sk_buff *pMsgBlock; /* pointer to a new message block */
4330 pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
4331 if (pMsgBlock == NULL) {
4334 pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
4335 skb_reserve(pMsgBlock, sizeof(SK_MBUF));
4336 pRlmtMbuf->pNext = NULL;
4337 pRlmtMbuf->pOs = pMsgBlock;
4338 pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
4339 pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
4340 pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
4343 } /* SkDrvAllocRlmtMbuf */
4346 /*****************************************************************************
4348 * SkDrvFreeRlmtMbuf - free an RLMT mbuf
4351 * This routine frees one or more RLMT mbuf(s).
4359 void SkDrvFreeRlmtMbuf(
4360 SK_AC *pAC, /* pointer to adapter context */
4361 SK_IOC IoC, /* the IO-context */
4362 SK_MBUF *pMbuf) /* size of the requested buffer */
4369 pNextMbuf = pFreeMbuf->pNext;
4370 DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
4371 pFreeMbuf = pNextMbuf;
4372 } while ( pFreeMbuf != NULL );
4373 } /* SkDrvFreeRlmtMbuf */
4376 /*****************************************************************************
4378 * SkOsGetTime - provide a time value
4381 * This routine provides a time value. The unit is 1/HZ (defined by Linux).
4382 * It is not used for absolute time, but only for time differences.
4388 SK_U64 SkOsGetTime(SK_AC *pAC)
4390 SK_U64 PrivateJiffies;
4391 SkOsGetTimeCurrent(pAC, &PrivateJiffies);
4392 return PrivateJiffies;
4396 /*****************************************************************************
4398 * SkPciReadCfgDWord - read a 32 bit value from pci config space
4401 * This routine reads a 32 bit value from the pci configuration
4405 * 0 - indicate everything worked ok.
4406 * != 0 - error indication
4408 int SkPciReadCfgDWord(
4409 SK_AC *pAC, /* Adapter Control structure pointer */
4410 int PciAddr, /* PCI register address */
4411 SK_U32 *pVal) /* pointer to store the read value */
4413 pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
4415 } /* SkPciReadCfgDWord */
4418 /*****************************************************************************
4420 * SkPciReadCfgWord - read a 16 bit value from pci config space
4423 * This routine reads a 16 bit value from the pci configuration
4427 * 0 - indicate everything worked ok.
4428 * != 0 - error indication
4430 int SkPciReadCfgWord(
4431 SK_AC *pAC, /* Adapter Control structure pointer */
4432 int PciAddr, /* PCI register address */
4433 SK_U16 *pVal) /* pointer to store the read value */
4435 pci_read_config_word(pAC->PciDev, PciAddr, pVal);
4437 } /* SkPciReadCfgWord */
4440 /*****************************************************************************
4442 * SkPciReadCfgByte - read a 8 bit value from pci config space
4445 * This routine reads a 8 bit value from the pci configuration
4449 * 0 - indicate everything worked ok.
4450 * != 0 - error indication
4452 int SkPciReadCfgByte(
4453 SK_AC *pAC, /* Adapter Control structure pointer */
4454 int PciAddr, /* PCI register address */
4455 SK_U8 *pVal) /* pointer to store the read value */
4457 pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
4459 } /* SkPciReadCfgByte */
4462 /*****************************************************************************
4464 * SkPciWriteCfgDWord - write a 32 bit value to pci config space
4467 * This routine writes a 32 bit value to the pci configuration
4471 * 0 - indicate everything worked ok.
4472 * != 0 - error indication
4474 int SkPciWriteCfgDWord(
4475 SK_AC *pAC, /* Adapter Control structure pointer */
4476 int PciAddr, /* PCI register address */
4477 SK_U32 Val) /* pointer to store the read value */
4479 pci_write_config_dword(pAC->PciDev, PciAddr, Val);
4481 } /* SkPciWriteCfgDWord */
4484 /*****************************************************************************
4486 * SkPciWriteCfgWord - write a 16 bit value to pci config space
4489 * This routine writes a 16 bit value to the pci configuration
4490 * space. The flag PciConfigUp indicates whether the config space
4491 * is accesible or must be set up first.
4494 * 0 - indicate everything worked ok.
4495 * != 0 - error indication
4497 int SkPciWriteCfgWord(
4498 SK_AC *pAC, /* Adapter Control structure pointer */
4499 int PciAddr, /* PCI register address */
4500 SK_U16 Val) /* pointer to store the read value */
4502 pci_write_config_word(pAC->PciDev, PciAddr, Val);
4504 } /* SkPciWriteCfgWord */
4507 /*****************************************************************************
4509 * SkPciWriteCfgWord - write a 8 bit value to pci config space
4512 * This routine writes a 8 bit value to the pci configuration
4513 * space. The flag PciConfigUp indicates whether the config space
4514 * is accesible or must be set up first.
4517 * 0 - indicate everything worked ok.
4518 * != 0 - error indication
4520 int SkPciWriteCfgByte(
4521 SK_AC *pAC, /* Adapter Control structure pointer */
4522 int PciAddr, /* PCI register address */
4523 SK_U8 Val) /* pointer to store the read value */
4525 pci_write_config_byte(pAC->PciDev, PciAddr, Val);
4527 } /* SkPciWriteCfgByte */
4530 /*****************************************************************************
4532 * SkDrvEvent - handle driver events
4535 * This function handles events from all modules directed to the driver
4538 * Is called under protection of slow path lock.
4541 * 0 if everything ok
4546 SK_AC *pAC, /* pointer to adapter context */
4547 SK_IOC IoC, /* io-context */
4548 SK_U32 Event, /* event-id */
4549 SK_EVPARA Param) /* event-parameter */
4551 SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
4552 struct sk_buff *pMsg; /* pointer to a message block */
4553 int FromPort; /* the port from which we switch away */
4554 int ToPort; /* the port we switch to */
4555 SK_EVPARA NewPara; /* parameter for further events */
4557 unsigned long Flags;
4561 case SK_DRV_ADAP_FAIL:
4562 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4563 ("ADAPTER FAIL EVENT\n"));
4564 printk("%s: Adapter failed.\n", pAC->dev[0]->name);
4565 /* disable interrupts */
4566 SK_OUT32(pAC->IoBase, B0_IMSK, 0);
4569 case SK_DRV_PORT_FAIL:
4570 FromPort = Param.Para32[0];
4571 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4572 ("PORT FAIL EVENT, Port: %d\n", FromPort));
4573 if (FromPort == 0) {
4574 printk("%s: Port A failed.\n", pAC->dev[0]->name);
4576 printk("%s: Port B failed.\n", pAC->dev[1]->name);
4580 case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
4582 FromPort = Param.Para32[0];
4583 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4584 ("PORT RESET EVENT, Port: %d ", FromPort));
4585 NewPara.Para64 = FromPort;
4586 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4588 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4591 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
4592 pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
4593 spin_unlock_irqrestore(
4594 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4597 /* clear rx ring from received frames */
4598 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
4600 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4602 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4605 /* tschilling: Handling of return value inserted. */
4606 if (SkGeInitPort(pAC, IoC, FromPort)) {
4607 if (FromPort == 0) {
4608 printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
4610 printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
4613 SkAddrMcUpdate(pAC,IoC, FromPort);
4614 PortReInitBmu(pAC, FromPort);
4615 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4616 ClearAndStartRx(pAC, FromPort);
4617 spin_unlock_irqrestore(
4618 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4621 case SK_DRV_NET_UP: /* SK_U32 PortIdx */
4623 FromPort = Param.Para32[0];
4624 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4625 ("NET UP EVENT, Port: %d ", Param.Para32[0]));
4627 SkAddrMcUpdate(pAC,IoC, FromPort);
4629 if (DoPrintInterfaceChange) {
4630 printk("%s: network connection up using"
4631 " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
4633 /* tschilling: Values changed according to LinkSpeedUsed. */
4634 Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
4635 if (Stat == SK_LSPEED_STAT_10MBPS) {
4636 printk(" speed: 10\n");
4637 } else if (Stat == SK_LSPEED_STAT_100MBPS) {
4638 printk(" speed: 100\n");
4639 } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
4640 printk(" speed: 1000\n");
4642 printk(" speed: unknown\n");
4646 Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
4647 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4648 Stat == SK_LMODE_STAT_AUTOFULL) {
4649 printk(" autonegotiation: yes\n");
4652 printk(" autonegotiation: no\n");
4654 if (Stat == SK_LMODE_STAT_AUTOHALF ||
4655 Stat == SK_LMODE_STAT_HALF) {
4656 printk(" duplex mode: half\n");
4659 printk(" duplex mode: full\n");
4661 Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
4662 if (Stat == SK_FLOW_STAT_REM_SEND ) {
4663 printk(" flowctrl: remote send\n");
4665 else if (Stat == SK_FLOW_STAT_LOC_SEND ){
4666 printk(" flowctrl: local send\n");
4668 else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
4669 printk(" flowctrl: symmetric\n");
4672 printk(" flowctrl: none\n");
4675 /* tschilling: Check against CopperType now. */
4676 if ((pAC->GIni.GICopperType == SK_TRUE) &&
4677 (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
4678 SK_LSPEED_STAT_1000MBPS)) {
4679 Stat = pAC->GIni.GP[FromPort].PMSStatus;
4680 if (Stat == SK_MS_STAT_MASTER ) {
4681 printk(" role: master\n");
4683 else if (Stat == SK_MS_STAT_SLAVE ) {
4684 printk(" role: slave\n");
4687 printk(" role: ???\n");
4692 Display dim (dynamic interrupt moderation)
4695 if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
4696 printk(" irq moderation: static (%d ints/sec)\n",
4697 pAC->DynIrqModInfo.MaxModIntsPerSec);
4698 else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
4699 printk(" irq moderation: dynamic (%d ints/sec)\n",
4700 pAC->DynIrqModInfo.MaxModIntsPerSec);
4702 printk(" irq moderation: disabled\n");
4706 if (pAC->ChipsetType)
4707 #ifdef USE_SK_TX_CHECKSUM
4708 printk(" scatter-gather: enabled\n");
4710 printk(" tx-checksum: disabled\n");
4713 printk(" scatter-gather: disabled\n");
4715 printk(" scatter-gather: disabled\n");
4718 #ifndef USE_SK_RX_CHECKSUM
4719 printk(" rx-checksum: disabled\n");
4723 DoPrintInterfaceChange = SK_TRUE;
4726 if ((Param.Para32[0] != pAC->ActivePort) &&
4727 (pAC->RlmtNets == 1)) {
4728 NewPara.Para32[0] = pAC->ActivePort;
4729 NewPara.Para32[1] = Param.Para32[0];
4730 SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
4734 /* Inform the world that link protocol is up. */
4735 pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
4738 case SK_DRV_NET_DOWN: /* SK_U32 Reason */
4740 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4741 ("NET DOWN EVENT "));
4742 if (DoPrintInterfaceChange) {
4743 printk("%s: network connection down\n",
4744 pAC->dev[Param.Para32[1]]->name);
4746 DoPrintInterfaceChange = SK_TRUE;
4748 pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
4750 case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4751 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4752 ("PORT SWITCH HARD "));
4753 case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4755 printk("%s: switching to port %c\n", pAC->dev[0]->name,
4756 'A'+Param.Para32[1]);
4757 case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
4758 FromPort = Param.Para32[0];
4759 ToPort = Param.Para32[1];
4760 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4761 ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
4762 FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
4763 NewPara.Para64 = FromPort;
4764 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4765 NewPara.Para64 = ToPort;
4766 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
4768 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4771 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4772 SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
4773 SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
4774 spin_unlock_irqrestore(
4775 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4776 spin_unlock_irqrestore(
4777 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4780 ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
4781 ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
4783 ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
4784 ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
4786 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4789 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4790 pAC->ActivePort = ToPort;
4794 /* tschilling: New common function with minimum size check. */
4796 if (pAC->RlmtNets == 2) {
4800 if (SkGeInitAssignRamToQueues(
4804 spin_unlock_irqrestore(
4805 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4806 spin_unlock_irqrestore(
4807 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4809 printk("SkGeInitAssignRamToQueues failed.\n");
4813 /* tschilling: Handling of return values inserted. */
4814 if (SkGeInitPort(pAC, IoC, FromPort) ||
4815 SkGeInitPort(pAC, IoC, ToPort)) {
4816 printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
4818 if (Event == SK_DRV_SWITCH_SOFT) {
4819 SkMacRxTxEnable(pAC, IoC, FromPort);
4821 SkMacRxTxEnable(pAC, IoC, ToPort);
4822 SkAddrSwap(pAC, IoC, FromPort, ToPort);
4823 SkAddrMcUpdate(pAC, IoC, FromPort);
4824 SkAddrMcUpdate(pAC, IoC, ToPort);
4825 PortReInitBmu(pAC, FromPort);
4826 PortReInitBmu(pAC, ToPort);
4827 SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
4828 SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
4829 ClearAndStartRx(pAC, FromPort);
4830 ClearAndStartRx(pAC, ToPort);
4831 spin_unlock_irqrestore(
4832 &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
4833 spin_unlock_irqrestore(
4834 &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
4837 case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
4838 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4840 pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
4841 pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
4842 skb_put(pMsg, pRlmtMbuf->Length);
4843 if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
4846 DEV_KFREE_SKB_ANY(pMsg);
4849 if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
4851 ** expiration of the moderation timer implies that
4852 ** dynamic moderation is to be applied
4854 SkDimStartModerationTimer(pAC);
4856 if (pAC->DynIrqModInfo.DisplayStats) {
4857 SkDimDisplayModerationSettings(pAC);
4859 } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
4861 ** check if we need to check for descriptors which
4862 ** haven't been handled the last millisecs
4864 StartDrvCleanupTimer(pAC);
4865 if (pAC->GIni.GIMacsFound == 2) {
4866 ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
4868 ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
4870 printk("Expiration of unknown timer\n");
4876 SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
4883 /*****************************************************************************
4885 * SkErrorLog - log errors
4888 * This function logs errors to the system buffer and to the console
4891 * 0 if everything ok
4904 case SK_ERRCL_OTHER:
4905 strcpy(ClassStr, "Other error");
4907 case SK_ERRCL_CONFIG:
4908 strcpy(ClassStr, "Configuration error");
4911 strcpy(ClassStr, "Initialization error");
4913 case SK_ERRCL_NORES:
4914 strcpy(ClassStr, "Out of resources error");
4917 strcpy(ClassStr, "internal Software error");
4920 strcpy(ClassStr, "Hardware failure");
4923 strcpy(ClassStr, "Communication error");
4926 printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
4927 " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
4928 ClassStr, ErrNum, pErrorMsg);
4932 #ifdef SK_DIAG_SUPPORT
4934 /*****************************************************************************
4936 * SkDrvEnterDiagMode - handles DIAG attach request
4939 * Notify the kernel to NOT access the card any longer due to DIAG
4940 * Deinitialize the Card
4945 int SkDrvEnterDiagMode(
4946 SK_AC *pAc) /* pointer to adapter context */
4949 DEV_NET *pNet = NULL;
4951 pNet = (DEV_NET *) pAc->dev[0]->priv;
4954 SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
4955 sizeof(SK_PNMI_STRUCT_DATA));
4957 pAC->DiagModeActive = DIAG_ACTIVE;
4958 if (pAC->BoardLevel > SK_INIT_DATA) {
4960 pAC->WasIfUp[0] = SK_TRUE;
4961 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4962 DoPrintInterfaceChange = SK_FALSE;
4963 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
4965 pAC->WasIfUp[0] = SK_FALSE;
4967 if (pNet != (DEV_NET *) pAc->dev[1]->priv) {
4968 pNet = (DEV_NET *) pAc->dev[1]->priv;
4970 pAC->WasIfUp[1] = SK_TRUE;
4971 pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
4972 DoPrintInterfaceChange = SK_FALSE;
4973 SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
4975 pAC->WasIfUp[1] = SK_FALSE;
4978 pAC->BoardLevel = SK_INIT_DATA;
4983 /*****************************************************************************
4985 * SkDrvLeaveDiagMode - handles DIAG detach request
4988 * Notify the kernel to may access the card again after use by DIAG
4989 * Initialize the Card
4994 int SkDrvLeaveDiagMode(
4995 SK_AC *pAc) /* pointer to adapter control context */
4997 SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
4998 sizeof(SK_PNMI_STRUCT_DATA));
4999 pAc->DiagModeActive = DIAG_NOTACTIVE;
5000 pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
5001 if (pAc->WasIfUp[0] == SK_TRUE) {
5002 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
5003 DoPrintInterfaceChange = SK_FALSE;
5004 SkDrvInitAdapter(pAc, 0); /* first device */
5006 if (pAc->WasIfUp[1] == SK_TRUE) {
5007 pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
5008 DoPrintInterfaceChange = SK_FALSE;
5009 SkDrvInitAdapter(pAc, 1); /* second device */
5014 /*****************************************************************************
5016 * ParseDeviceNbrFromSlotName - Evaluate PCI device number
5019 * This function parses the PCI slot name information string and will
5020 * retrieve the devcie number out of it. The slot_name maintianed by
5021 * linux is in the form of '02:0a.0', whereas the first two characters
5022 * represent the bus number in hex (in the sample above this is
5023 * pci bus 0x02) and the next two characters the device number (0x0a).
5026 * SK_U32: The device number from the PCI slot name
5029 static SK_U32 ParseDeviceNbrFromSlotName(
5030 const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
5032 char *CurrCharPos = (char *) SlotName;
5033 int FirstNibble = -1;
5034 int SecondNibble = -1;
5037 while (*CurrCharPos != '\0') {
5038 if (*CurrCharPos == ':') {
5039 while (*CurrCharPos != '.') {
5041 if ( (*CurrCharPos >= '0') &&
5042 (*CurrCharPos <= '9')) {
5043 if (FirstNibble == -1) {
5044 /* dec. value for '0' */
5045 FirstNibble = *CurrCharPos - 48;
5047 SecondNibble = *CurrCharPos - 48;
5049 } else if ( (*CurrCharPos >= 'a') &&
5050 (*CurrCharPos <= 'f') ) {
5051 if (FirstNibble == -1) {
5052 FirstNibble = *CurrCharPos - 87;
5054 SecondNibble = *CurrCharPos - 87;
5061 Result = FirstNibble;
5062 Result = Result << 4; /* first nibble is higher one */
5063 Result = Result | SecondNibble;
5065 CurrCharPos++; /* next character */
5070 /****************************************************************************
5072 * SkDrvDeInitAdapter - deinitialize adapter (this function is only
5073 * called if Diag attaches to that card)
5076 * Close initialized adapter.
5080 * error code - on error
5082 static int SkDrvDeInitAdapter(
5083 SK_AC *pAC, /* pointer to adapter context */
5084 int devNbr) /* what device is to be handled */
5086 struct SK_NET_DEVICE *dev;
5088 dev = pAC->dev[devNbr];
5091 ** Function SkGeClose() uses MOD_DEC_USE_COUNT (2.2/2.4)
5092 ** or module_put() (2.6) to decrease the number of users for
5093 ** a device, but if a device is to be put under control of
5094 ** the DIAG, that count is OK already and does not need to
5095 ** be adapted! Hence the opposite MOD_INC_USE_COUNT or
5096 ** try_module_get() needs to be used again to correct that.
5098 if (!try_module_get(THIS_MODULE)) {
5102 if (SkGeClose(dev) != 0) {
5103 module_put(THIS_MODULE);
5108 } /* SkDrvDeInitAdapter() */
5110 /****************************************************************************
5112 * SkDrvInitAdapter - Initialize adapter (this function is only
5113 * called if Diag deattaches from that card)
5116 * Close initialized adapter.
5120 * error code - on error
5122 static int SkDrvInitAdapter(
5123 SK_AC *pAC, /* pointer to adapter context */
5124 int devNbr) /* what device is to be handled */
5126 struct SK_NET_DEVICE *dev;
5128 dev = pAC->dev[devNbr];
5130 if (SkGeOpen(dev) != 0) {
5134 ** Function SkGeOpen() uses MOD_INC_USE_COUNT (2.2/2.4)
5135 ** or try_module_get() (2.6) to increase the number of
5136 ** users for a device, but if a device was just under
5137 ** control of the DIAG, that count is OK already and
5138 ** does not need to be adapted! Hence the opposite
5139 ** MOD_DEC_USE_COUNT or module_put() needs to be used
5140 ** again to correct that.
5142 module_put(THIS_MODULE);
5146 ** Use correct MTU size and indicate to kernel TX queue can be started
5148 if (SkGeChangeMtu(dev, dev->mtu) != 0) {
5153 } /* SkDrvInitAdapter */
5158 /****************************************************************************/
5159 /* "debug only" section *****************************************************/
5160 /****************************************************************************/
5163 /*****************************************************************************
5165 * DumpMsg - print a frame
5168 * This function prints frames to the system logfile/to the console.
5173 static void DumpMsg(struct sk_buff *skb, char *str)
5178 printk("DumpMsg(): NULL-Message\n");
5182 if (skb->data == NULL) {
5183 printk("DumpMsg(): Message empty\n");
5191 printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
5193 DumpData((char *)skb->data, msglen);
5195 printk("------- End of message ---------\n");
5200 /*****************************************************************************
5202 * DumpData - print a data area
5205 * This function prints a area of data to the system logfile/to the
5211 static void DumpData(char *p, int size)
5215 char hex_buffer[180];
5216 char asc_buffer[180];
5217 char HEXCHAR[] = "0123456789ABCDEF";
5223 for (i=0; i < size; ) {
5224 if (*p >= '0' && *p <='z')
5225 asc_buffer[addr] = *p;
5227 asc_buffer[addr] = '.';
5229 asc_buffer[addr] = 0;
5230 hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
5232 hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
5234 hex_buffer[haddr] = ' ';
5236 hex_buffer[haddr] = 0;
5240 printk("%s %s\n", hex_buffer, asc_buffer);
5248 /*****************************************************************************
5250 * DumpLong - print a data area as long values
5253 * This function prints a area of data to the system logfile/to the
5259 static void DumpLong(char *pc, int size)
5263 char hex_buffer[180];
5264 char asc_buffer[180];
5265 char HEXCHAR[] = "0123456789ABCDEF";
5274 for (i=0; i < size; ) {
5276 hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
5278 hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
5280 hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
5282 hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
5284 hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
5286 hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
5288 hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
5290 hex_buffer[haddr] = HEXCHAR[l & 0x0f];
5292 hex_buffer[haddr] = ' ';
5294 hex_buffer[haddr] = 0;
5298 printk("%4x %s\n", (i-8)*4, hex_buffer);
5302 printk("------------------------\n");
5307 /*******************************************************************************
5311 ******************************************************************************/